Rollup merge of #121089 - oli-obk:create_def_feed, r=petrochenkov
Remove `feed_local_def_id` best reviewed commit by commit Basically I returned `TyCtxtFeed` from `create_def` and then preserved that in the local caches based on https://github.com/rust-lang/rust/pull/121084 r? ````@petrochenkov````
This commit is contained in:
commit
4de78d2a8d
15 changed files with 181 additions and 86 deletions
|
@ -427,7 +427,7 @@ pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> hir::Crate<'_> {
|
||||||
tcx.ensure_with_value().early_lint_checks(());
|
tcx.ensure_with_value().early_lint_checks(());
|
||||||
tcx.ensure_with_value().debugger_visualizers(LOCAL_CRATE);
|
tcx.ensure_with_value().debugger_visualizers(LOCAL_CRATE);
|
||||||
tcx.ensure_with_value().get_lang_items(());
|
tcx.ensure_with_value().get_lang_items(());
|
||||||
let (mut resolver, krate) = tcx.resolver_for_lowering(()).steal();
|
let (mut resolver, krate) = tcx.resolver_for_lowering().steal();
|
||||||
|
|
||||||
let ast_index = index_crate(&resolver.node_id_to_def_id, &krate);
|
let ast_index = index_crate(&resolver.node_id_to_def_id, &krate);
|
||||||
let mut owners = IndexVec::from_fn_n(
|
let mut owners = IndexVec::from_fn_n(
|
||||||
|
|
|
@ -418,7 +418,7 @@ fn run_compiler(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure name resolution and macro expansion is run.
|
// Make sure name resolution and macro expansion is run.
|
||||||
queries.global_ctxt()?.enter(|tcx| tcx.resolver_for_lowering(()));
|
queries.global_ctxt()?.enter(|tcx| tcx.resolver_for_lowering());
|
||||||
|
|
||||||
if callbacks.after_expansion(compiler, queries) == Compilation::Stop {
|
if callbacks.after_expansion(compiler, queries) == Compilation::Stop {
|
||||||
return early_exit();
|
return early_exit();
|
||||||
|
|
|
@ -229,7 +229,7 @@ impl<'tcx> PrintExtra<'tcx> {
|
||||||
{
|
{
|
||||||
match self {
|
match self {
|
||||||
PrintExtra::AfterParsing { krate, .. } => f(krate),
|
PrintExtra::AfterParsing { krate, .. } => f(krate),
|
||||||
PrintExtra::NeedsAstMap { tcx } => f(&tcx.resolver_for_lowering(()).borrow().1),
|
PrintExtra::NeedsAstMap { tcx } => f(&tcx.resolver_for_lowering().borrow().1),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,7 +281,7 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
|
||||||
}
|
}
|
||||||
AstTreeExpanded => {
|
AstTreeExpanded => {
|
||||||
debug!("pretty-printing expanded AST");
|
debug!("pretty-printing expanded AST");
|
||||||
format!("{:#?}", ex.tcx().resolver_for_lowering(()).borrow().1)
|
format!("{:#?}", ex.tcx().resolver_for_lowering().borrow().1)
|
||||||
}
|
}
|
||||||
Hir(s) => {
|
Hir(s) => {
|
||||||
debug!("pretty printing HIR {:?}", s);
|
debug!("pretty printing HIR {:?}", s);
|
||||||
|
|
|
@ -280,7 +280,7 @@ fn configure_and_expand(
|
||||||
|
|
||||||
fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) {
|
fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) {
|
||||||
let sess = tcx.sess;
|
let sess = tcx.sess;
|
||||||
let (resolver, krate) = &*tcx.resolver_for_lowering(()).borrow();
|
let (resolver, krate) = &*tcx.resolver_for_lowering().borrow();
|
||||||
let mut lint_buffer = resolver.lint_buffer.steal();
|
let mut lint_buffer = resolver.lint_buffer.steal();
|
||||||
|
|
||||||
if sess.opts.unstable_opts.input_stats {
|
if sess.opts.unstable_opts.input_stats {
|
||||||
|
@ -531,10 +531,10 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolver_for_lowering<'tcx>(
|
fn resolver_for_lowering_raw<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
(): (),
|
(): (),
|
||||||
) -> &'tcx Steal<(ty::ResolverAstLowering, Lrc<ast::Crate>)> {
|
) -> (&'tcx Steal<(ty::ResolverAstLowering, Lrc<ast::Crate>)>, &'tcx ty::ResolverGlobalCtxt) {
|
||||||
let arenas = Resolver::arenas();
|
let arenas = Resolver::arenas();
|
||||||
let _ = tcx.registered_tools(()); // Uses `crate_for_resolver`.
|
let _ = tcx.registered_tools(()); // Uses `crate_for_resolver`.
|
||||||
let (krate, pre_configured_attrs) = tcx.crate_for_resolver(()).steal();
|
let (krate, pre_configured_attrs) = tcx.crate_for_resolver(()).steal();
|
||||||
|
@ -549,16 +549,15 @@ fn resolver_for_lowering<'tcx>(
|
||||||
ast_lowering: untracked_resolver_for_lowering,
|
ast_lowering: untracked_resolver_for_lowering,
|
||||||
} = resolver.into_outputs();
|
} = resolver.into_outputs();
|
||||||
|
|
||||||
let feed = tcx.feed_unit_query();
|
let resolutions = tcx.arena.alloc(untracked_resolutions);
|
||||||
feed.resolutions(tcx.arena.alloc(untracked_resolutions));
|
(tcx.arena.alloc(Steal::new((untracked_resolver_for_lowering, Lrc::new(krate)))), resolutions)
|
||||||
tcx.arena.alloc(Steal::new((untracked_resolver_for_lowering, Lrc::new(krate))))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn write_dep_info(tcx: TyCtxt<'_>) {
|
pub(crate) fn write_dep_info(tcx: TyCtxt<'_>) {
|
||||||
// Make sure name resolution and macro expansion is run for
|
// Make sure name resolution and macro expansion is run for
|
||||||
// the side-effect of providing a complete set of all
|
// the side-effect of providing a complete set of all
|
||||||
// accessed files and env vars.
|
// accessed files and env vars.
|
||||||
let _ = tcx.resolver_for_lowering(());
|
let _ = tcx.resolver_for_lowering();
|
||||||
|
|
||||||
let sess = tcx.sess;
|
let sess = tcx.sess;
|
||||||
let _timer = sess.timer("write_dep_info");
|
let _timer = sess.timer("write_dep_info");
|
||||||
|
@ -607,7 +606,10 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| {
|
||||||
let providers = &mut Providers::default();
|
let providers = &mut Providers::default();
|
||||||
providers.analysis = analysis;
|
providers.analysis = analysis;
|
||||||
providers.hir_crate = rustc_ast_lowering::lower_to_hir;
|
providers.hir_crate = rustc_ast_lowering::lower_to_hir;
|
||||||
providers.resolver_for_lowering = resolver_for_lowering;
|
providers.resolver_for_lowering_raw = resolver_for_lowering_raw;
|
||||||
|
providers.stripped_cfg_items =
|
||||||
|
|tcx, _| tcx.arena.alloc_from_iter(tcx.resolutions(()).stripped_cfg_items.steal());
|
||||||
|
providers.resolutions = |tcx, ()| tcx.resolver_for_lowering_raw(()).1;
|
||||||
providers.early_lint_checks = early_lint_checks;
|
providers.early_lint_checks = early_lint_checks;
|
||||||
proc_macro_decls::provide(providers);
|
proc_macro_decls::provide(providers);
|
||||||
rustc_const_eval::provide(providers);
|
rustc_const_eval::provide(providers);
|
||||||
|
|
|
@ -8,8 +8,7 @@ use rustc_codegen_ssa::CodegenResults;
|
||||||
use rustc_data_structures::steal::Steal;
|
use rustc_data_structures::steal::Steal;
|
||||||
use rustc_data_structures::svh::Svh;
|
use rustc_data_structures::svh::Svh;
|
||||||
use rustc_data_structures::sync::{AppendOnlyIndexVec, FreezeLock, OnceLock, WorkerLocal};
|
use rustc_data_structures::sync::{AppendOnlyIndexVec, FreezeLock, OnceLock, WorkerLocal};
|
||||||
use rustc_hir::def::DefKind;
|
use rustc_hir::def_id::{StableCrateId, LOCAL_CRATE};
|
||||||
use rustc_hir::def_id::{StableCrateId, CRATE_DEF_ID, LOCAL_CRATE};
|
|
||||||
use rustc_hir::definitions::Definitions;
|
use rustc_hir::definitions::Definitions;
|
||||||
use rustc_incremental::setup_dep_graph;
|
use rustc_incremental::setup_dep_graph;
|
||||||
use rustc_metadata::creader::CStore;
|
use rustc_metadata::creader::CStore;
|
||||||
|
@ -144,10 +143,8 @@ impl<'tcx> Queries<'tcx> {
|
||||||
stable_crate_id,
|
stable_crate_id,
|
||||||
)) as _);
|
)) as _);
|
||||||
let definitions = FreezeLock::new(Definitions::new(stable_crate_id));
|
let definitions = FreezeLock::new(Definitions::new(stable_crate_id));
|
||||||
let source_span = AppendOnlyIndexVec::new();
|
let untracked =
|
||||||
let _id = source_span.push(krate.spans.inner_span);
|
Untracked { cstore, source_span: AppendOnlyIndexVec::new(), definitions };
|
||||||
debug_assert_eq!(_id, CRATE_DEF_ID);
|
|
||||||
let untracked = Untracked { cstore, source_span, definitions };
|
|
||||||
|
|
||||||
let qcx = passes::create_global_ctxt(
|
let qcx = passes::create_global_ctxt(
|
||||||
self.compiler,
|
self.compiler,
|
||||||
|
@ -172,9 +169,6 @@ impl<'tcx> Queries<'tcx> {
|
||||||
)));
|
)));
|
||||||
feed.crate_for_resolver(tcx.arena.alloc(Steal::new((krate, pre_configured_attrs))));
|
feed.crate_for_resolver(tcx.arena.alloc(Steal::new((krate, pre_configured_attrs))));
|
||||||
feed.output_filenames(Arc::new(outputs));
|
feed.output_filenames(Arc::new(outputs));
|
||||||
|
|
||||||
let feed = tcx.feed_local_def_id(CRATE_DEF_ID);
|
|
||||||
feed.def_kind(DefKind::Mod);
|
|
||||||
});
|
});
|
||||||
Ok(qcx)
|
Ok(qcx)
|
||||||
})
|
})
|
||||||
|
|
|
@ -125,12 +125,11 @@ rustc_queries! {
|
||||||
}
|
}
|
||||||
|
|
||||||
query resolutions(_: ()) -> &'tcx ty::ResolverGlobalCtxt {
|
query resolutions(_: ()) -> &'tcx ty::ResolverGlobalCtxt {
|
||||||
feedable
|
|
||||||
no_hash
|
no_hash
|
||||||
desc { "getting the resolver outputs" }
|
desc { "getting the resolver outputs" }
|
||||||
}
|
}
|
||||||
|
|
||||||
query resolver_for_lowering(_: ()) -> &'tcx Steal<(ty::ResolverAstLowering, Lrc<ast::Crate>)> {
|
query resolver_for_lowering_raw(_: ()) -> (&'tcx Steal<(ty::ResolverAstLowering, Lrc<ast::Crate>)>, &'tcx ty::ResolverGlobalCtxt) {
|
||||||
eval_always
|
eval_always
|
||||||
no_hash
|
no_hash
|
||||||
desc { "getting the resolver for lowering" }
|
desc { "getting the resolver for lowering" }
|
||||||
|
@ -2216,7 +2215,6 @@ rustc_queries! {
|
||||||
/// Should not be called for the local crate before the resolver outputs are created, as it
|
/// Should not be called for the local crate before the resolver outputs are created, as it
|
||||||
/// is only fed there.
|
/// is only fed there.
|
||||||
query stripped_cfg_items(cnum: CrateNum) -> &'tcx [StrippedCfgItem] {
|
query stripped_cfg_items(cnum: CrateNum) -> &'tcx [StrippedCfgItem] {
|
||||||
feedable
|
|
||||||
desc { "getting cfg-ed out item names" }
|
desc { "getting cfg-ed out item names" }
|
||||||
separate_provide_extern
|
separate_provide_extern
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ use rustc_data_structures::profiling::SelfProfilerRef;
|
||||||
use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap};
|
use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap};
|
||||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||||
use rustc_data_structures::steal::Steal;
|
use rustc_data_structures::steal::Steal;
|
||||||
use rustc_data_structures::sync::{self, FreezeReadGuard, Lock, WorkerLocal};
|
use rustc_data_structures::sync::{self, FreezeReadGuard, Lock, Lrc, WorkerLocal};
|
||||||
#[cfg(parallel_compiler)]
|
#[cfg(parallel_compiler)]
|
||||||
use rustc_data_structures::sync::{DynSend, DynSync};
|
use rustc_data_structures::sync::{DynSend, DynSync};
|
||||||
use rustc_data_structures::unord::UnordSet;
|
use rustc_data_structures::unord::UnordSet;
|
||||||
|
@ -60,7 +60,7 @@ use rustc_session::config::CrateType;
|
||||||
use rustc_session::cstore::{CrateStoreDyn, Untracked};
|
use rustc_session::cstore::{CrateStoreDyn, Untracked};
|
||||||
use rustc_session::lint::Lint;
|
use rustc_session::lint::Lint;
|
||||||
use rustc_session::{Limit, MetadataKind, Session};
|
use rustc_session::{Limit, MetadataKind, Session};
|
||||||
use rustc_span::def_id::{DefPathHash, StableCrateId};
|
use rustc_span::def_id::{DefPathHash, StableCrateId, CRATE_DEF_ID};
|
||||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||||
use rustc_span::{Span, DUMMY_SP};
|
use rustc_span::{Span, DUMMY_SP};
|
||||||
use rustc_target::abi::{FieldIdx, Layout, LayoutS, TargetDataLayout, VariantIdx};
|
use rustc_target::abi::{FieldIdx, Layout, LayoutS, TargetDataLayout, VariantIdx};
|
||||||
|
@ -74,6 +74,7 @@ use std::cmp::Ordering;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
use std::marker::PhantomData;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ops::{Bound, Deref};
|
use std::ops::{Bound, Deref};
|
||||||
|
|
||||||
|
@ -498,14 +499,55 @@ pub struct TyCtxtFeed<'tcx, KEY: Copy> {
|
||||||
key: KEY,
|
key: KEY,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Never return a `Feed` from a query. Only queries that create a `DefId` are
|
||||||
|
/// allowed to feed queries for that `DefId`.
|
||||||
|
impl<KEY: Copy, CTX> !HashStable<CTX> for TyCtxtFeed<'_, KEY> {}
|
||||||
|
|
||||||
|
/// The same as `TyCtxtFeed`, but does not contain a `TyCtxt`.
|
||||||
|
/// Use this to pass around when you have a `TyCtxt` elsewhere.
|
||||||
|
/// Just an optimization to save space and not store hundreds of
|
||||||
|
/// `TyCtxtFeed` in the resolver.
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
pub struct Feed<'tcx, KEY: Copy> {
|
||||||
|
_tcx: PhantomData<TyCtxt<'tcx>>,
|
||||||
|
// Do not allow direct access, as downstream code must not mutate this field.
|
||||||
|
key: KEY,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Never return a `Feed` from a query. Only queries that create a `DefId` are
|
||||||
|
/// allowed to feed queries for that `DefId`.
|
||||||
|
impl<KEY: Copy, CTX> !HashStable<CTX> for Feed<'_, KEY> {}
|
||||||
|
|
||||||
|
impl<T: fmt::Debug + Copy> fmt::Debug for Feed<'_, T> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
self.key.fmt(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Some workarounds to use cases that cannot use `create_def`.
|
||||||
|
/// Do not add new ways to create `TyCtxtFeed` without consulting
|
||||||
|
/// with T-compiler and making an analysis about why your addition
|
||||||
|
/// does not cause incremental compilation issues.
|
||||||
impl<'tcx> TyCtxt<'tcx> {
|
impl<'tcx> TyCtxt<'tcx> {
|
||||||
|
/// Can only be fed before queries are run, and is thus exempt from any
|
||||||
|
/// incremental issues. Do not use except for the initial query feeding.
|
||||||
pub fn feed_unit_query(self) -> TyCtxtFeed<'tcx, ()> {
|
pub fn feed_unit_query(self) -> TyCtxtFeed<'tcx, ()> {
|
||||||
|
self.dep_graph.assert_ignored();
|
||||||
TyCtxtFeed { tcx: self, key: () }
|
TyCtxtFeed { tcx: self, key: () }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Can only be fed before queries are run, and is thus exempt from any
|
||||||
|
/// incremental issues. Do not use except for the initial query feeding.
|
||||||
pub fn feed_local_crate(self) -> TyCtxtFeed<'tcx, CrateNum> {
|
pub fn feed_local_crate(self) -> TyCtxtFeed<'tcx, CrateNum> {
|
||||||
|
self.dep_graph.assert_ignored();
|
||||||
TyCtxtFeed { tcx: self, key: LOCAL_CRATE }
|
TyCtxtFeed { tcx: self, key: LOCAL_CRATE }
|
||||||
}
|
}
|
||||||
pub fn feed_local_def_id(self, key: LocalDefId) -> TyCtxtFeed<'tcx, LocalDefId> {
|
|
||||||
|
/// Only used in the resolver to register the `CRATE_DEF_ID` `DefId` and feed
|
||||||
|
/// some queries for it. It will panic if used twice.
|
||||||
|
pub fn create_local_crate_def_id(self, span: Span) -> TyCtxtFeed<'tcx, LocalDefId> {
|
||||||
|
let key = self.untracked().source_span.push(span);
|
||||||
|
assert_eq!(key, CRATE_DEF_ID);
|
||||||
TyCtxtFeed { tcx: self, key }
|
TyCtxtFeed { tcx: self, key }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -523,6 +565,23 @@ impl<'tcx, KEY: Copy> TyCtxtFeed<'tcx, KEY> {
|
||||||
pub fn key(&self) -> KEY {
|
pub fn key(&self) -> KEY {
|
||||||
self.key
|
self.key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn downgrade(self) -> Feed<'tcx, KEY> {
|
||||||
|
Feed { _tcx: PhantomData, key: self.key }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'tcx, KEY: Copy> Feed<'tcx, KEY> {
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn key(&self) -> KEY {
|
||||||
|
self.key
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn upgrade(self, tcx: TyCtxt<'tcx>) -> TyCtxtFeed<'tcx, KEY> {
|
||||||
|
TyCtxtFeed { tcx, key: self.key }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TyCtxtFeed<'tcx, LocalDefId> {
|
impl<'tcx> TyCtxtFeed<'tcx, LocalDefId> {
|
||||||
|
@ -1067,7 +1126,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
// needs to be re-evaluated.
|
// needs to be re-evaluated.
|
||||||
self.dep_graph.read_index(DepNodeIndex::FOREVER_RED_NODE);
|
self.dep_graph.read_index(DepNodeIndex::FOREVER_RED_NODE);
|
||||||
|
|
||||||
let feed = self.feed_local_def_id(def_id);
|
let feed = TyCtxtFeed { tcx: self, key: def_id };
|
||||||
feed.def_kind(def_kind);
|
feed.def_kind(def_kind);
|
||||||
// Unique types created for closures participate in type privacy checking.
|
// Unique types created for closures participate in type privacy checking.
|
||||||
// They have visibilities inherited from the module they are defined in.
|
// They have visibilities inherited from the module they are defined in.
|
||||||
|
@ -2304,6 +2363,10 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
self.resolutions(()).module_children.get(&def_id).map_or(&[], |v| &v[..])
|
self.resolutions(()).module_children.get(&def_id).map_or(&[], |v| &v[..])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn resolver_for_lowering(self) -> &'tcx Steal<(ty::ResolverAstLowering, Lrc<ast::Crate>)> {
|
||||||
|
self.resolver_for_lowering_raw(()).0
|
||||||
|
}
|
||||||
|
|
||||||
/// Given an `impl_id`, return the trait it implements.
|
/// Given an `impl_id`, return the trait it implements.
|
||||||
/// Return `None` if this is an inherent impl.
|
/// Return `None` if this is an inherent impl.
|
||||||
pub fn impl_trait_ref(
|
pub fn impl_trait_ref(
|
||||||
|
|
|
@ -32,6 +32,7 @@ pub use generic_args::*;
|
||||||
pub use generics::*;
|
pub use generics::*;
|
||||||
pub use intrinsic::IntrinsicDef;
|
pub use intrinsic::IntrinsicDef;
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
|
use rustc_ast::expand::StrippedCfgItem;
|
||||||
use rustc_ast::node_id::NodeMap;
|
use rustc_ast::node_id::NodeMap;
|
||||||
pub use rustc_ast_ir::{try_visit, Movability, Mutability};
|
pub use rustc_ast_ir::{try_visit, Movability, Mutability};
|
||||||
use rustc_attr as attr;
|
use rustc_attr as attr;
|
||||||
|
@ -85,7 +86,8 @@ pub use self::consts::{
|
||||||
Const, ConstData, ConstInt, ConstKind, Expr, ScalarInt, UnevaluatedConst, ValTree,
|
Const, ConstData, ConstInt, ConstKind, Expr, ScalarInt, UnevaluatedConst, ValTree,
|
||||||
};
|
};
|
||||||
pub use self::context::{
|
pub use self::context::{
|
||||||
tls, CtxtInterners, DeducedParamAttrs, FreeRegionInfo, GlobalCtxt, Lift, TyCtxt, TyCtxtFeed,
|
tls, CtxtInterners, DeducedParamAttrs, Feed, FreeRegionInfo, GlobalCtxt, Lift, TyCtxt,
|
||||||
|
TyCtxtFeed,
|
||||||
};
|
};
|
||||||
pub use self::instance::{Instance, InstanceDef, ShortInstance, UnusedGenericParams};
|
pub use self::instance::{Instance, InstanceDef, ShortInstance, UnusedGenericParams};
|
||||||
pub use self::list::List;
|
pub use self::list::List;
|
||||||
|
@ -189,6 +191,7 @@ pub struct ResolverGlobalCtxt {
|
||||||
pub doc_link_resolutions: FxHashMap<LocalDefId, DocLinkResMap>,
|
pub doc_link_resolutions: FxHashMap<LocalDefId, DocLinkResMap>,
|
||||||
pub doc_link_traits_in_scope: FxHashMap<LocalDefId, Vec<DefId>>,
|
pub doc_link_traits_in_scope: FxHashMap<LocalDefId, Vec<DefId>>,
|
||||||
pub all_macro_rules: FxHashMap<Symbol, Res<ast::NodeId>>,
|
pub all_macro_rules: FxHashMap<Symbol, Res<ast::NodeId>>,
|
||||||
|
pub stripped_cfg_items: Steal<Vec<StrippedCfgItem>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resolutions that should only be used for lowering.
|
/// Resolutions that should only be used for lowering.
|
||||||
|
|
|
@ -87,7 +87,7 @@ impl<'ast> rustc_ast::visit::Visitor<'ast> for DebuggerVisualizerCollector<'_> {
|
||||||
|
|
||||||
/// Traverses and collects the debugger visualizers for a specific crate.
|
/// Traverses and collects the debugger visualizers for a specific crate.
|
||||||
fn debugger_visualizers(tcx: TyCtxt<'_>, _: LocalCrate) -> Vec<DebuggerVisualizerFile> {
|
fn debugger_visualizers(tcx: TyCtxt<'_>, _: LocalCrate) -> Vec<DebuggerVisualizerFile> {
|
||||||
let resolver_and_krate = tcx.resolver_for_lowering(()).borrow();
|
let resolver_and_krate = tcx.resolver_for_lowering().borrow();
|
||||||
let krate = &*resolver_and_krate.1;
|
let krate = &*resolver_and_krate.1;
|
||||||
|
|
||||||
let mut visitor = DebuggerVisualizerCollector { sess: tcx.sess, visualizers: Vec::new() };
|
let mut visitor = DebuggerVisualizerCollector { sess: tcx.sess, visualizers: Vec::new() };
|
||||||
|
|
|
@ -243,7 +243,7 @@ impl<'ast, 'tcx> LanguageItemCollector<'ast, 'tcx> {
|
||||||
|
|
||||||
/// Traverses and collects all the lang items in all crates.
|
/// Traverses and collects all the lang items in all crates.
|
||||||
fn get_lang_items(tcx: TyCtxt<'_>, (): ()) -> LanguageItems {
|
fn get_lang_items(tcx: TyCtxt<'_>, (): ()) -> LanguageItems {
|
||||||
let resolver = tcx.resolver_for_lowering(()).borrow();
|
let resolver = tcx.resolver_for_lowering().borrow();
|
||||||
let (resolver, krate) = &*resolver;
|
let (resolver, krate) = &*resolver;
|
||||||
|
|
||||||
// Initialize the collector.
|
// Initialize the collector.
|
||||||
|
|
|
@ -25,6 +25,7 @@ use rustc_hir::def::{self, *};
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
|
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
|
||||||
use rustc_metadata::creader::LoadedMacro;
|
use rustc_metadata::creader::LoadedMacro;
|
||||||
use rustc_middle::metadata::ModChild;
|
use rustc_middle::metadata::ModChild;
|
||||||
|
use rustc_middle::ty::Feed;
|
||||||
use rustc_middle::{bug, ty};
|
use rustc_middle::{bug, ty};
|
||||||
use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind};
|
use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind};
|
||||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||||
|
@ -407,7 +408,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
// Top level use tree reuses the item's id and list stems reuse their parent
|
// Top level use tree reuses the item's id and list stems reuse their parent
|
||||||
// use tree's ids, so in both cases their visibilities are already filled.
|
// use tree's ids, so in both cases their visibilities are already filled.
|
||||||
if nested && !list_stem {
|
if nested && !list_stem {
|
||||||
self.r.feed_visibility(self.r.local_def_id(id), vis);
|
self.r.feed_visibility(self.r.feed(id), vis);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut prefix_iter = parent_prefix
|
let mut prefix_iter = parent_prefix
|
||||||
|
@ -632,7 +633,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
&mut self,
|
&mut self,
|
||||||
fields: &[ast::FieldDef],
|
fields: &[ast::FieldDef],
|
||||||
ident: Ident,
|
ident: Ident,
|
||||||
def_id: LocalDefId,
|
feed: Feed<'tcx, LocalDefId>,
|
||||||
adt_res: Res,
|
adt_res: Res,
|
||||||
adt_vis: ty::Visibility,
|
adt_vis: ty::Visibility,
|
||||||
adt_span: Span,
|
adt_span: Span,
|
||||||
|
@ -643,7 +644,8 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
|
|
||||||
// Define a name in the type namespace if it is not anonymous.
|
// Define a name in the type namespace if it is not anonymous.
|
||||||
self.r.define(parent, ident, TypeNS, (adt_res, adt_vis, adt_span, expansion));
|
self.r.define(parent, ident, TypeNS, (adt_res, adt_vis, adt_span, expansion));
|
||||||
self.r.feed_visibility(def_id, adt_vis);
|
self.r.feed_visibility(feed, adt_vis);
|
||||||
|
let def_id = feed.key();
|
||||||
|
|
||||||
// Record field names for error reporting.
|
// Record field names for error reporting.
|
||||||
self.insert_field_def_ids(def_id, fields);
|
self.insert_field_def_ids(def_id, fields);
|
||||||
|
@ -653,14 +655,15 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
match &field.ty.kind {
|
match &field.ty.kind {
|
||||||
ast::TyKind::AnonStruct(id, nested_fields)
|
ast::TyKind::AnonStruct(id, nested_fields)
|
||||||
| ast::TyKind::AnonUnion(id, nested_fields) => {
|
| ast::TyKind::AnonUnion(id, nested_fields) => {
|
||||||
let local_def_id = self.r.local_def_id(*id);
|
let feed = self.r.feed(*id);
|
||||||
|
let local_def_id = feed.key();
|
||||||
let def_id = local_def_id.to_def_id();
|
let def_id = local_def_id.to_def_id();
|
||||||
let def_kind = self.r.tcx.def_kind(local_def_id);
|
let def_kind = self.r.tcx.def_kind(local_def_id);
|
||||||
let res = Res::Def(def_kind, def_id);
|
let res = Res::Def(def_kind, def_id);
|
||||||
self.build_reduced_graph_for_struct_variant(
|
self.build_reduced_graph_for_struct_variant(
|
||||||
&nested_fields,
|
&nested_fields,
|
||||||
Ident::empty(),
|
Ident::empty(),
|
||||||
local_def_id,
|
feed,
|
||||||
res,
|
res,
|
||||||
// Anonymous adts inherit visibility from their parent adts.
|
// Anonymous adts inherit visibility from their parent adts.
|
||||||
adt_vis,
|
adt_vis,
|
||||||
|
@ -680,12 +683,13 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
let ident = item.ident;
|
let ident = item.ident;
|
||||||
let sp = item.span;
|
let sp = item.span;
|
||||||
let vis = self.resolve_visibility(&item.vis);
|
let vis = self.resolve_visibility(&item.vis);
|
||||||
let local_def_id = self.r.local_def_id(item.id);
|
let feed = self.r.feed(item.id);
|
||||||
|
let local_def_id = feed.key();
|
||||||
let def_id = local_def_id.to_def_id();
|
let def_id = local_def_id.to_def_id();
|
||||||
let def_kind = self.r.tcx.def_kind(def_id);
|
let def_kind = self.r.tcx.def_kind(def_id);
|
||||||
let res = Res::Def(def_kind, def_id);
|
let res = Res::Def(def_kind, def_id);
|
||||||
|
|
||||||
self.r.feed_visibility(local_def_id, vis);
|
self.r.feed_visibility(feed, vis);
|
||||||
|
|
||||||
match item.kind {
|
match item.kind {
|
||||||
ItemKind::Use(ref use_tree) => {
|
ItemKind::Use(ref use_tree) => {
|
||||||
|
@ -762,7 +766,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
self.build_reduced_graph_for_struct_variant(
|
self.build_reduced_graph_for_struct_variant(
|
||||||
vdata.fields(),
|
vdata.fields(),
|
||||||
ident,
|
ident,
|
||||||
local_def_id,
|
feed,
|
||||||
res,
|
res,
|
||||||
vis,
|
vis,
|
||||||
sp,
|
sp,
|
||||||
|
@ -795,10 +799,11 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
}
|
}
|
||||||
ret_fields.push(field_vis.to_def_id());
|
ret_fields.push(field_vis.to_def_id());
|
||||||
}
|
}
|
||||||
let ctor_def_id = self.r.local_def_id(ctor_node_id);
|
let feed = self.r.feed(ctor_node_id);
|
||||||
|
let ctor_def_id = feed.key();
|
||||||
let ctor_res = self.res(ctor_def_id);
|
let ctor_res = self.res(ctor_def_id);
|
||||||
self.r.define(parent, ident, ValueNS, (ctor_res, ctor_vis, sp, expansion));
|
self.r.define(parent, ident, ValueNS, (ctor_res, ctor_vis, sp, expansion));
|
||||||
self.r.feed_visibility(ctor_def_id, ctor_vis);
|
self.r.feed_visibility(feed, ctor_vis);
|
||||||
// We need the field visibility spans also for the constructor for E0603.
|
// We need the field visibility spans also for the constructor for E0603.
|
||||||
self.insert_field_visibilities_local(ctor_def_id.to_def_id(), vdata.fields());
|
self.insert_field_visibilities_local(ctor_def_id.to_def_id(), vdata.fields());
|
||||||
|
|
||||||
|
@ -812,7 +817,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
self.build_reduced_graph_for_struct_variant(
|
self.build_reduced_graph_for_struct_variant(
|
||||||
vdata.fields(),
|
vdata.fields(),
|
||||||
ident,
|
ident,
|
||||||
local_def_id,
|
feed,
|
||||||
res,
|
res,
|
||||||
vis,
|
vis,
|
||||||
sp,
|
sp,
|
||||||
|
@ -919,7 +924,8 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
|
|
||||||
/// Constructs the reduced graph for one foreign item.
|
/// Constructs the reduced graph for one foreign item.
|
||||||
fn build_reduced_graph_for_foreign_item(&mut self, item: &ForeignItem) {
|
fn build_reduced_graph_for_foreign_item(&mut self, item: &ForeignItem) {
|
||||||
let local_def_id = self.r.local_def_id(item.id);
|
let feed = self.r.feed(item.id);
|
||||||
|
let local_def_id = feed.key();
|
||||||
let def_id = local_def_id.to_def_id();
|
let def_id = local_def_id.to_def_id();
|
||||||
let ns = match item.kind {
|
let ns = match item.kind {
|
||||||
ForeignItemKind::Fn(..) => ValueNS,
|
ForeignItemKind::Fn(..) => ValueNS,
|
||||||
|
@ -931,7 +937,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
let expansion = self.parent_scope.expansion;
|
let expansion = self.parent_scope.expansion;
|
||||||
let vis = self.resolve_visibility(&item.vis);
|
let vis = self.resolve_visibility(&item.vis);
|
||||||
self.r.define(parent, item.ident, ns, (self.res(def_id), vis, item.span, expansion));
|
self.r.define(parent, item.ident, ns, (self.res(def_id), vis, item.span, expansion));
|
||||||
self.r.feed_visibility(local_def_id, vis);
|
self.r.feed_visibility(feed, vis);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_reduced_graph_for_block(&mut self, block: &Block) {
|
fn build_reduced_graph_for_block(&mut self, block: &Block) {
|
||||||
|
@ -1218,7 +1224,8 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
fn define_macro(&mut self, item: &ast::Item) -> MacroRulesScopeRef<'a> {
|
fn define_macro(&mut self, item: &ast::Item) -> MacroRulesScopeRef<'a> {
|
||||||
let parent_scope = self.parent_scope;
|
let parent_scope = self.parent_scope;
|
||||||
let expansion = parent_scope.expansion;
|
let expansion = parent_scope.expansion;
|
||||||
let def_id = self.r.local_def_id(item.id);
|
let feed = self.r.feed(item.id);
|
||||||
|
let def_id = feed.key();
|
||||||
let (res, ident, span, macro_rules) = match &item.kind {
|
let (res, ident, span, macro_rules) = match &item.kind {
|
||||||
ItemKind::MacroDef(def) => (self.res(def_id), item.ident, item.span, def.macro_rules),
|
ItemKind::MacroDef(def) => (self.res(def_id), item.ident, item.span, def.macro_rules),
|
||||||
ItemKind::Fn(..) => match self.proc_macro_stub(item) {
|
ItemKind::Fn(..) => match self.proc_macro_stub(item) {
|
||||||
|
@ -1269,7 +1276,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
self.r.check_reserved_macro_name(ident, res);
|
self.r.check_reserved_macro_name(ident, res);
|
||||||
self.insert_unused_macro(ident, def_id, item.id);
|
self.insert_unused_macro(ident, def_id, item.id);
|
||||||
}
|
}
|
||||||
self.r.feed_visibility(def_id, vis);
|
self.r.feed_visibility(feed, vis);
|
||||||
let scope = self.r.arenas.alloc_macro_rules_scope(MacroRulesScope::Binding(
|
let scope = self.r.arenas.alloc_macro_rules_scope(MacroRulesScope::Binding(
|
||||||
self.r.arenas.alloc_macro_rules_binding(MacroRulesBinding {
|
self.r.arenas.alloc_macro_rules_binding(MacroRulesBinding {
|
||||||
parent_macro_rules_scope: parent_scope.macro_rules,
|
parent_macro_rules_scope: parent_scope.macro_rules,
|
||||||
|
@ -1293,7 +1300,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
self.insert_unused_macro(ident, def_id, item.id);
|
self.insert_unused_macro(ident, def_id, item.id);
|
||||||
}
|
}
|
||||||
self.r.define(module, ident, MacroNS, (res, vis, span, expansion));
|
self.r.define(module, ident, MacroNS, (res, vis, span, expansion));
|
||||||
self.r.feed_visibility(def_id, vis);
|
self.r.feed_visibility(feed, vis);
|
||||||
self.parent_scope.macro_rules
|
self.parent_scope.macro_rules
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1385,7 +1392,8 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let vis = self.resolve_visibility(&item.vis);
|
let vis = self.resolve_visibility(&item.vis);
|
||||||
let local_def_id = self.r.local_def_id(item.id);
|
let feed = self.r.feed(item.id);
|
||||||
|
let local_def_id = feed.key();
|
||||||
let def_id = local_def_id.to_def_id();
|
let def_id = local_def_id.to_def_id();
|
||||||
|
|
||||||
if !(ctxt == AssocCtxt::Impl
|
if !(ctxt == AssocCtxt::Impl
|
||||||
|
@ -1395,7 +1403,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
// Trait impl item visibility is inherited from its trait when not specified
|
// Trait impl item visibility is inherited from its trait when not specified
|
||||||
// explicitly. In that case we cannot determine it here in early resolve,
|
// explicitly. In that case we cannot determine it here in early resolve,
|
||||||
// so we leave a hole in the visibility table to be filled later.
|
// so we leave a hole in the visibility table to be filled later.
|
||||||
self.r.feed_visibility(local_def_id, vis);
|
self.r.feed_visibility(feed, vis);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctxt == AssocCtxt::Trait {
|
if ctxt == AssocCtxt::Trait {
|
||||||
|
@ -1469,7 +1477,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
self.visit_invoc(sf.id);
|
self.visit_invoc(sf.id);
|
||||||
} else {
|
} else {
|
||||||
let vis = self.resolve_visibility(&sf.vis);
|
let vis = self.resolve_visibility(&sf.vis);
|
||||||
self.r.feed_visibility(self.r.local_def_id(sf.id), vis);
|
self.r.feed_visibility(self.r.feed(sf.id), vis);
|
||||||
visit::walk_field_def(self, sf);
|
visit::walk_field_def(self, sf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1487,10 +1495,11 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
let ident = variant.ident;
|
let ident = variant.ident;
|
||||||
|
|
||||||
// Define a name in the type namespace.
|
// Define a name in the type namespace.
|
||||||
let def_id = self.r.local_def_id(variant.id);
|
let feed = self.r.feed(variant.id);
|
||||||
|
let def_id = feed.key();
|
||||||
let vis = self.resolve_visibility(&variant.vis);
|
let vis = self.resolve_visibility(&variant.vis);
|
||||||
self.r.define(parent, ident, TypeNS, (self.res(def_id), vis, variant.span, expn_id));
|
self.r.define(parent, ident, TypeNS, (self.res(def_id), vis, variant.span, expn_id));
|
||||||
self.r.feed_visibility(def_id, vis);
|
self.r.feed_visibility(feed, vis);
|
||||||
|
|
||||||
// If the variant is marked as non_exhaustive then lower the visibility to within the crate.
|
// If the variant is marked as non_exhaustive then lower the visibility to within the crate.
|
||||||
let ctor_vis =
|
let ctor_vis =
|
||||||
|
@ -1502,10 +1511,11 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
|
|
||||||
// Define a constructor name in the value namespace.
|
// Define a constructor name in the value namespace.
|
||||||
if let Some(ctor_node_id) = variant.data.ctor_node_id() {
|
if let Some(ctor_node_id) = variant.data.ctor_node_id() {
|
||||||
let ctor_def_id = self.r.local_def_id(ctor_node_id);
|
let feed = self.r.feed(ctor_node_id);
|
||||||
|
let ctor_def_id = feed.key();
|
||||||
let ctor_res = self.res(ctor_def_id);
|
let ctor_res = self.res(ctor_def_id);
|
||||||
self.r.define(parent, ident, ValueNS, (ctor_res, ctor_vis, variant.span, expn_id));
|
self.r.define(parent, ident, ValueNS, (ctor_res, ctor_vis, variant.span, expn_id));
|
||||||
self.r.feed_visibility(ctor_def_id, ctor_vis);
|
self.r.feed_visibility(feed, ctor_vis);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Record field names for error reporting.
|
// Record field names for error reporting.
|
||||||
|
|
|
@ -38,7 +38,8 @@ impl<'a, 'b, 'tcx> DefCollector<'a, 'b, 'tcx> {
|
||||||
"create_def(node_id={:?}, def_kind={:?}, parent_def={:?})",
|
"create_def(node_id={:?}, def_kind={:?}, parent_def={:?})",
|
||||||
node_id, def_kind, parent_def
|
node_id, def_kind, parent_def
|
||||||
);
|
);
|
||||||
self.resolver.create_def(
|
self.resolver
|
||||||
|
.create_def(
|
||||||
parent_def,
|
parent_def,
|
||||||
node_id,
|
node_id,
|
||||||
name,
|
name,
|
||||||
|
@ -46,6 +47,7 @@ impl<'a, 'b, 'tcx> DefCollector<'a, 'b, 'tcx> {
|
||||||
self.expansion.to_expn_id(),
|
self.expansion.to_expn_id(),
|
||||||
span.with_parent(None),
|
span.with_parent(None),
|
||||||
)
|
)
|
||||||
|
.def_id()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_parent<F: FnOnce(&mut Self)>(&mut self, parent_def: LocalDefId, f: F) {
|
fn with_parent<F: FnOnce(&mut Self)>(&mut self, parent_def: LocalDefId, f: F) {
|
||||||
|
|
|
@ -3121,7 +3121,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
);
|
);
|
||||||
rustc_middle::ty::Visibility::Public
|
rustc_middle::ty::Visibility::Public
|
||||||
};
|
};
|
||||||
this.r.feed_visibility(this.r.local_def_id(id), vis);
|
this.r.feed_visibility(this.r.feed(id), vis);
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(binding) = binding else {
|
let Some(binding) = binding else {
|
||||||
|
|
|
@ -52,8 +52,8 @@ use rustc_middle::metadata::ModChild;
|
||||||
use rustc_middle::middle::privacy::EffectiveVisibilities;
|
use rustc_middle::middle::privacy::EffectiveVisibilities;
|
||||||
use rustc_middle::query::Providers;
|
use rustc_middle::query::Providers;
|
||||||
use rustc_middle::span_bug;
|
use rustc_middle::span_bug;
|
||||||
use rustc_middle::ty::{self, MainDefinition, RegisteredTools, TyCtxt};
|
use rustc_middle::ty::{self, MainDefinition, RegisteredTools, TyCtxt, TyCtxtFeed};
|
||||||
use rustc_middle::ty::{ResolverGlobalCtxt, ResolverOutputs};
|
use rustc_middle::ty::{Feed, ResolverGlobalCtxt, ResolverOutputs};
|
||||||
use rustc_query_system::ich::StableHashingContext;
|
use rustc_query_system::ich::StableHashingContext;
|
||||||
use rustc_session::lint::builtin::PRIVATE_MACRO_USE;
|
use rustc_session::lint::builtin::PRIVATE_MACRO_USE;
|
||||||
use rustc_session::lint::LintBuffer;
|
use rustc_session::lint::LintBuffer;
|
||||||
|
@ -1117,7 +1117,7 @@ pub struct Resolver<'a, 'tcx> {
|
||||||
|
|
||||||
next_node_id: NodeId,
|
next_node_id: NodeId,
|
||||||
|
|
||||||
node_id_to_def_id: NodeMap<LocalDefId>,
|
node_id_to_def_id: NodeMap<Feed<'tcx, LocalDefId>>,
|
||||||
def_id_to_node_id: IndexVec<LocalDefId, ast::NodeId>,
|
def_id_to_node_id: IndexVec<LocalDefId, ast::NodeId>,
|
||||||
|
|
||||||
/// Indices of unnamed struct or variant fields with unresolved attributes.
|
/// Indices of unnamed struct or variant fields with unresolved attributes.
|
||||||
|
@ -1233,11 +1233,19 @@ impl<'a, 'tcx> AsMut<Resolver<'a, 'tcx>> for Resolver<'a, 'tcx> {
|
||||||
|
|
||||||
impl<'tcx> Resolver<'_, 'tcx> {
|
impl<'tcx> Resolver<'_, 'tcx> {
|
||||||
fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> {
|
fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> {
|
||||||
self.node_id_to_def_id.get(&node).copied()
|
self.opt_feed(node).map(|f| f.key())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn local_def_id(&self, node: NodeId) -> LocalDefId {
|
fn local_def_id(&self, node: NodeId) -> LocalDefId {
|
||||||
self.opt_local_def_id(node).unwrap_or_else(|| panic!("no entry for node id: `{node:?}`"))
|
self.feed(node).key()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn opt_feed(&self, node: NodeId) -> Option<Feed<'tcx, LocalDefId>> {
|
||||||
|
self.node_id_to_def_id.get(&node).copied()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn feed(&self, node: NodeId) -> Feed<'tcx, LocalDefId> {
|
||||||
|
self.opt_feed(node).unwrap_or_else(|| panic!("no entry for node id: `{node:?}`"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn local_def_kind(&self, node: NodeId) -> DefKind {
|
fn local_def_kind(&self, node: NodeId) -> DefKind {
|
||||||
|
@ -1253,18 +1261,19 @@ impl<'tcx> Resolver<'_, 'tcx> {
|
||||||
def_kind: DefKind,
|
def_kind: DefKind,
|
||||||
expn_id: ExpnId,
|
expn_id: ExpnId,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> LocalDefId {
|
) -> TyCtxtFeed<'tcx, LocalDefId> {
|
||||||
let data = def_kind.def_path_data(name);
|
let data = def_kind.def_path_data(name);
|
||||||
assert!(
|
assert!(
|
||||||
!self.node_id_to_def_id.contains_key(&node_id),
|
!self.node_id_to_def_id.contains_key(&node_id),
|
||||||
"adding a def'n for node-id {:?} and data {:?} but a previous def'n exists: {:?}",
|
"adding a def'n for node-id {:?} and data {:?} but a previous def'n exists: {:?}",
|
||||||
node_id,
|
node_id,
|
||||||
data,
|
data,
|
||||||
self.tcx.definitions_untracked().def_key(self.node_id_to_def_id[&node_id]),
|
self.tcx.definitions_untracked().def_key(self.node_id_to_def_id[&node_id].key()),
|
||||||
);
|
);
|
||||||
|
|
||||||
// FIXME: remove `def_span` body, pass in the right spans here and call `tcx.at().create_def()`
|
// FIXME: remove `def_span` body, pass in the right spans here and call `tcx.at().create_def()`
|
||||||
let def_id = self.tcx.create_def(parent, name, def_kind).def_id();
|
let feed = self.tcx.create_def(parent, name, def_kind);
|
||||||
|
let def_id = feed.def_id();
|
||||||
|
|
||||||
// Create the definition.
|
// Create the definition.
|
||||||
if expn_id != ExpnId::root() {
|
if expn_id != ExpnId::root() {
|
||||||
|
@ -1281,11 +1290,11 @@ impl<'tcx> Resolver<'_, 'tcx> {
|
||||||
// we don't need a mapping from `NodeId` to `LocalDefId`.
|
// we don't need a mapping from `NodeId` to `LocalDefId`.
|
||||||
if node_id != ast::DUMMY_NODE_ID {
|
if node_id != ast::DUMMY_NODE_ID {
|
||||||
debug!("create_def: def_id_to_node_id[{:?}] <-> {:?}", def_id, node_id);
|
debug!("create_def: def_id_to_node_id[{:?}] <-> {:?}", def_id, node_id);
|
||||||
self.node_id_to_def_id.insert(node_id, def_id);
|
self.node_id_to_def_id.insert(node_id, feed.downgrade());
|
||||||
}
|
}
|
||||||
assert_eq!(self.def_id_to_node_id.push(node_id), def_id);
|
assert_eq!(self.def_id_to_node_id.push(node_id), def_id);
|
||||||
|
|
||||||
def_id
|
feed
|
||||||
}
|
}
|
||||||
|
|
||||||
fn item_generics_num_lifetimes(&self, def_id: DefId) -> usize {
|
fn item_generics_num_lifetimes(&self, def_id: DefId) -> usize {
|
||||||
|
@ -1333,7 +1342,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
let mut def_id_to_node_id = IndexVec::default();
|
let mut def_id_to_node_id = IndexVec::default();
|
||||||
assert_eq!(def_id_to_node_id.push(CRATE_NODE_ID), CRATE_DEF_ID);
|
assert_eq!(def_id_to_node_id.push(CRATE_NODE_ID), CRATE_DEF_ID);
|
||||||
let mut node_id_to_def_id = NodeMap::default();
|
let mut node_id_to_def_id = NodeMap::default();
|
||||||
node_id_to_def_id.insert(CRATE_NODE_ID, CRATE_DEF_ID);
|
let crate_feed = tcx.create_local_crate_def_id(crate_span);
|
||||||
|
|
||||||
|
crate_feed.def_kind(DefKind::Mod);
|
||||||
|
let crate_feed = crate_feed.downgrade();
|
||||||
|
node_id_to_def_id.insert(CRATE_NODE_ID, crate_feed);
|
||||||
|
|
||||||
let mut invocation_parents = FxHashMap::default();
|
let mut invocation_parents = FxHashMap::default();
|
||||||
invocation_parents.insert(LocalExpnId::ROOT, (CRATE_DEF_ID, ImplTraitContext::Existential));
|
invocation_parents.insert(LocalExpnId::ROOT, (CRATE_DEF_ID, ImplTraitContext::Existential));
|
||||||
|
@ -1484,7 +1497,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
|
|
||||||
let root_parent_scope = ParentScope::module(graph_root, &resolver);
|
let root_parent_scope = ParentScope::module(graph_root, &resolver);
|
||||||
resolver.invocation_parent_scopes.insert(LocalExpnId::ROOT, root_parent_scope);
|
resolver.invocation_parent_scopes.insert(LocalExpnId::ROOT, root_parent_scope);
|
||||||
resolver.feed_visibility(CRATE_DEF_ID, ty::Visibility::Public);
|
resolver.feed_visibility(crate_feed, ty::Visibility::Public);
|
||||||
|
|
||||||
resolver
|
resolver
|
||||||
}
|
}
|
||||||
|
@ -1532,9 +1545,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
Default::default()
|
Default::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn feed_visibility(&mut self, def_id: LocalDefId, vis: ty::Visibility) {
|
fn feed_visibility(&mut self, feed: Feed<'tcx, LocalDefId>, vis: ty::Visibility) {
|
||||||
self.tcx.feed_local_def_id(def_id).visibility(vis.to_def_id());
|
let feed = feed.upgrade(self.tcx);
|
||||||
self.visibilities_for_hashing.push((def_id, vis));
|
feed.visibility(vis.to_def_id());
|
||||||
|
self.visibilities_for_hashing.push((feed.def_id(), vis));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_outputs(self) -> ResolverOutputs {
|
pub fn into_outputs(self) -> ResolverOutputs {
|
||||||
|
@ -1547,12 +1561,16 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
let confused_type_with_std_module = self.confused_type_with_std_module;
|
let confused_type_with_std_module = self.confused_type_with_std_module;
|
||||||
let effective_visibilities = self.effective_visibilities;
|
let effective_visibilities = self.effective_visibilities;
|
||||||
|
|
||||||
self.tcx.feed_local_crate().stripped_cfg_items(self.tcx.arena.alloc_from_iter(
|
let stripped_cfg_items = Steal::new(
|
||||||
self.stripped_cfg_items.into_iter().filter_map(|item| {
|
self.stripped_cfg_items
|
||||||
let parent_module = self.node_id_to_def_id.get(&item.parent_module)?.to_def_id();
|
.into_iter()
|
||||||
|
.filter_map(|item| {
|
||||||
|
let parent_module =
|
||||||
|
self.node_id_to_def_id.get(&item.parent_module)?.key().to_def_id();
|
||||||
Some(StrippedCfgItem { parent_module, name: item.name, cfg: item.cfg })
|
Some(StrippedCfgItem { parent_module, name: item.name, cfg: item.cfg })
|
||||||
}),
|
})
|
||||||
));
|
.collect(),
|
||||||
|
);
|
||||||
|
|
||||||
let global_ctxt = ResolverGlobalCtxt {
|
let global_ctxt = ResolverGlobalCtxt {
|
||||||
expn_that_defined,
|
expn_that_defined,
|
||||||
|
@ -1569,6 +1587,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
doc_link_resolutions: self.doc_link_resolutions,
|
doc_link_resolutions: self.doc_link_resolutions,
|
||||||
doc_link_traits_in_scope: self.doc_link_traits_in_scope,
|
doc_link_traits_in_scope: self.doc_link_traits_in_scope,
|
||||||
all_macro_rules: self.all_macro_rules,
|
all_macro_rules: self.all_macro_rules,
|
||||||
|
stripped_cfg_items,
|
||||||
};
|
};
|
||||||
let ast_lowering = ty::ResolverAstLowering {
|
let ast_lowering = ty::ResolverAstLowering {
|
||||||
legacy_const_generic_args: self.legacy_const_generic_args,
|
legacy_const_generic_args: self.legacy_const_generic_args,
|
||||||
|
@ -1578,7 +1597,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
lifetimes_res_map: self.lifetimes_res_map,
|
lifetimes_res_map: self.lifetimes_res_map,
|
||||||
extra_lifetime_params_map: self.extra_lifetime_params_map,
|
extra_lifetime_params_map: self.extra_lifetime_params_map,
|
||||||
next_node_id: self.next_node_id,
|
next_node_id: self.next_node_id,
|
||||||
node_id_to_def_id: self.node_id_to_def_id,
|
node_id_to_def_id: self
|
||||||
|
.node_id_to_def_id
|
||||||
|
.into_items()
|
||||||
|
.map(|(k, f)| (k, f.key()))
|
||||||
|
.collect(),
|
||||||
def_id_to_node_id: self.def_id_to_node_id,
|
def_id_to_node_id: self.def_id_to_node_id,
|
||||||
trait_map: self.trait_map,
|
trait_map: self.trait_map,
|
||||||
lifetime_elision_allowed: self.lifetime_elision_allowed,
|
lifetime_elision_allowed: self.lifetime_elision_allowed,
|
||||||
|
|
|
@ -21,5 +21,5 @@ error: the compiler unexpectedly panicked. this is a bug.
|
||||||
|
|
||||||
|
|
||||||
query stack during panic:
|
query stack during panic:
|
||||||
#0 [resolver_for_lowering] getting the resolver for lowering
|
#0 [resolver_for_lowering_raw] getting the resolver for lowering
|
||||||
end of query stack
|
end of query stack
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue