From c696d4c3238ed71f0acedad7c402924fb0bdde32 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 19 Feb 2024 16:58:18 +0000 Subject: [PATCH] Remove a use of feed_local_crate and make it fail if used within queries --- compiler/rustc_interface/src/passes.rs | 2 ++ compiler/rustc_middle/src/query/mod.rs | 1 - compiler/rustc_middle/src/ty/context.rs | 6 ++++++ compiler/rustc_middle/src/ty/mod.rs | 2 ++ compiler/rustc_resolve/src/lib.rs | 18 +++++++++++------- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 661401687593d..eba707a4938df 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -608,6 +608,8 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock = LazyLock::new(|| { providers.analysis = analysis; providers.hir_crate = rustc_ast_lowering::lower_to_hir; providers.resolver_for_lowering = resolver_for_lowering; + providers.stripped_cfg_items = + |tcx, _| tcx.arena.alloc_from_iter(tcx.resolutions(()).stripped_cfg_items.steal()); providers.early_lint_checks = early_lint_checks; proc_macro_decls::provide(providers); rustc_const_eval::provide(providers); diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index e87bc581e6eab..ef0ac52d7935e 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -2230,7 +2230,6 @@ rustc_queries! { /// Should not be called for the local crate before the resolver outputs are created, as it /// is only fed there. query stripped_cfg_items(cnum: CrateNum) -> &'tcx [StrippedCfgItem] { - feedable desc { "getting cfg-ed out item names" } separate_provide_extern } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index b568364517fc9..adb00bcd9bf1b 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -550,10 +550,16 @@ impl fmt::Debug for Feed<'_, T> { /// with T-compiler and making an analysis about why your addition /// does not cause incremental compilation issues. 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, ()> { 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> { + self.dep_graph.assert_ignored(); TyCtxtFeed { tcx: self, key: LOCAL_CRATE } } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 77444b74ccdb4..aa572b80a0193 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -31,6 +31,7 @@ pub use assoc::*; pub use generic_args::*; pub use generics::*; use rustc_ast as ast; +use rustc_ast::expand::StrippedCfgItem; use rustc_ast::node_id::NodeMap; pub use rustc_ast_ir::{Movability, Mutability}; use rustc_attr as attr; @@ -189,6 +190,7 @@ pub struct ResolverGlobalCtxt { pub doc_link_resolutions: FxHashMap, pub doc_link_traits_in_scope: FxHashMap>, pub all_macro_rules: FxHashMap>, + pub stripped_cfg_items: Steal>, } /// Resolutions that should only be used for lowering. diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 4135ae405c32b..35e1147b11d3e 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -1559,13 +1559,16 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { let confused_type_with_std_module = self.confused_type_with_std_module; let effective_visibilities = self.effective_visibilities; - self.tcx.feed_local_crate().stripped_cfg_items(self.tcx.arena.alloc_from_iter( - self.stripped_cfg_items.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 }) - }), - )); + let stripped_cfg_items = Steal::new( + self.stripped_cfg_items + .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 }) + }) + .collect(), + ); let global_ctxt = ResolverGlobalCtxt { expn_that_defined, @@ -1582,6 +1585,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { doc_link_resolutions: self.doc_link_resolutions, doc_link_traits_in_scope: self.doc_link_traits_in_scope, all_macro_rules: self.all_macro_rules, + stripped_cfg_items, }; let ast_lowering = ty::ResolverAstLowering { legacy_const_generic_args: self.legacy_const_generic_args,