Avoid using feed_unit_query from within queries

This commit is contained in:
Oli Scherer 2024-02-19 17:25:01 +00:00
parent c696d4c323
commit ef00fae46d
9 changed files with 22 additions and 18 deletions

View File

@ -427,7 +427,7 @@ pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> hir::Crate<'_> {
tcx.ensure_with_value().early_lint_checks(());
tcx.ensure_with_value().debugger_visualizers(LOCAL_CRATE);
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 mut owners = IndexVec::from_fn_n(

View File

@ -417,7 +417,7 @@ fn run_compiler(
}
// 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 {
return early_exit();

View File

@ -229,7 +229,7 @@ impl<'tcx> PrintExtra<'tcx> {
{
match self {
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 => {
debug!("pretty-printing expanded AST");
format!("{:#?}", ex.tcx().resolver_for_lowering(()).borrow().1)
format!("{:#?}", ex.tcx().resolver_for_lowering().borrow().1)
}
Hir(s) => {
debug!("pretty printing HIR {:?}", s);

View File

@ -280,7 +280,7 @@ fn configure_and_expand(
fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) {
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();
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 Steal<(ty::ResolverAstLowering, Lrc<ast::Crate>)> {
) -> (&'tcx Steal<(ty::ResolverAstLowering, Lrc<ast::Crate>)>, &'tcx ty::ResolverGlobalCtxt) {
let arenas = Resolver::arenas();
let _ = tcx.registered_tools(()); // Uses `crate_for_resolver`.
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,
} = resolver.into_outputs();
let feed = tcx.feed_unit_query();
feed.resolutions(tcx.arena.alloc(untracked_resolutions));
tcx.arena.alloc(Steal::new((untracked_resolver_for_lowering, Lrc::new(krate))))
let resolutions = tcx.arena.alloc(untracked_resolutions);
(tcx.arena.alloc(Steal::new((untracked_resolver_for_lowering, Lrc::new(krate)))), resolutions)
}
pub(crate) fn write_dep_info(tcx: TyCtxt<'_>) {
// Make sure name resolution and macro expansion is run for
// the side-effect of providing a complete set of all
// accessed files and env vars.
let _ = tcx.resolver_for_lowering(());
let _ = tcx.resolver_for_lowering();
let sess = tcx.sess;
let _timer = sess.timer("write_dep_info");
@ -607,9 +606,10 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| {
let providers = &mut Providers::default();
providers.analysis = analysis;
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;
proc_macro_decls::provide(providers);
rustc_const_eval::provide(providers);

View File

@ -125,12 +125,11 @@ rustc_queries! {
}
query resolutions(_: ()) -> &'tcx ty::ResolverGlobalCtxt {
feedable
no_hash
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
no_hash
desc { "getting the resolver for lowering" }

View File

@ -39,7 +39,7 @@ use rustc_data_structures::profiling::SelfProfilerRef;
use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
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)]
use rustc_data_structures::sync::{DynSend, DynSync};
use rustc_data_structures::unord::UnordSet;
@ -553,6 +553,7 @@ 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, ()> {
self.dep_graph.assert_ignored();
TyCtxtFeed { tcx: self, key: () }
}
@ -2383,6 +2384,10 @@ impl<'tcx> TyCtxt<'tcx> {
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.
/// Return `None` if this is an inherent impl.
pub fn impl_trait_ref(

View File

@ -87,7 +87,7 @@ impl<'ast> rustc_ast::visit::Visitor<'ast> for DebuggerVisualizerCollector<'_> {
/// Traverses and collects the debugger visualizers for a specific crate.
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 mut visitor = DebuggerVisualizerCollector { sess: tcx.sess, visualizers: Vec::new() };

View File

@ -243,7 +243,7 @@ impl<'ast, 'tcx> LanguageItemCollector<'ast, 'tcx> {
/// Traverses and collects all the lang items in all crates.
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;
// Initialize the collector.

View File

@ -21,5 +21,5 @@ error: the compiler unexpectedly panicked. this is a bug.
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