Skip to content

Commit a0aeca0

Browse files
committed
Avoid using feed_unit_query from within queries
1 parent c6143a2 commit a0aeca0

File tree

7 files changed

+17
-13
lines changed

7 files changed

+17
-13
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> hir::Crate<'_> {
427427
tcx.ensure_with_value().early_lint_checks(());
428428
tcx.ensure_with_value().debugger_visualizers(LOCAL_CRATE);
429429
tcx.ensure_with_value().get_lang_items(());
430-
let (mut resolver, krate) = tcx.resolver_for_lowering(()).steal();
430+
let (mut resolver, krate) = tcx.resolver_for_lowering(()).0.steal();
431431

432432
let ast_index = index_crate(&resolver.node_id_to_def_id, &krate);
433433
let mut owners = IndexVec::from_fn_n(

compiler/rustc_driver_impl/src/pretty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl<'tcx> PrintExtra<'tcx> {
229229
{
230230
match self {
231231
PrintExtra::AfterParsing { krate, .. } => f(krate),
232-
PrintExtra::NeedsAstMap { tcx } => f(&tcx.resolver_for_lowering(()).borrow().1),
232+
PrintExtra::NeedsAstMap { tcx } => f(&tcx.resolver_for_lowering(()).0.borrow().1),
233233
}
234234
}
235235

@@ -279,7 +279,7 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
279279
}
280280
AstTreeExpanded => {
281281
debug!("pretty-printing expanded AST");
282-
format!("{:#?}", ex.tcx().resolver_for_lowering(()).borrow().1)
282+
format!("{:#?}", ex.tcx().resolver_for_lowering(()).0.borrow().1)
283283
}
284284
Hir(s) => {
285285
debug!("pretty printing HIR {:?}", s);

compiler/rustc_interface/src/passes.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ fn configure_and_expand(
282282

283283
fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) {
284284
let sess = tcx.sess;
285-
let (resolver, krate) = &*tcx.resolver_for_lowering(()).borrow();
285+
let (resolver, krate) = &*tcx.resolver_for_lowering(()).0.borrow();
286286
let mut lint_buffer = resolver.lint_buffer.steal();
287287

288288
if sess.opts.unstable_opts.input_stats {
@@ -536,7 +536,7 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P
536536
fn resolver_for_lowering<'tcx>(
537537
tcx: TyCtxt<'tcx>,
538538
(): (),
539-
) -> &'tcx Steal<(ty::ResolverAstLowering, Lrc<ast::Crate>)> {
539+
) -> (&'tcx Steal<(ty::ResolverAstLowering, Lrc<ast::Crate>)>, &'tcx ty::ResolverGlobalCtxt) {
540540
let arenas = Resolver::arenas();
541541
let _ = tcx.registered_tools(()); // Uses `crate_for_resolver`.
542542
let (krate, pre_configured_attrs) = tcx.crate_for_resolver(()).steal();
@@ -551,15 +551,18 @@ fn resolver_for_lowering<'tcx>(
551551
ast_lowering: untracked_resolver_for_lowering,
552552
} = resolver.into_outputs();
553553

554-
let feed = tcx.feed_unit_query();
555-
feed.resolutions(tcx.arena.alloc(untracked_resolutions));
556-
tcx.arena.alloc(Steal::new((untracked_resolver_for_lowering, Lrc::new(krate))))
554+
let resolutions = tcx.arena.alloc(untracked_resolutions);
555+
(tcx.arena.alloc(Steal::new((untracked_resolver_for_lowering, Lrc::new(krate)))), resolutions)
557556
}
558557

559-
fn stripped_cfg_items(tcx: TyCtxt<'_>, _: LocalCrate) -> &'_ [StrippedCfgItem] {
558+
fn stripped_cfg_items(tcx: TyCtxt<'_>, _: LocalCrate) -> &[StrippedCfgItem] {
560559
tcx.arena.alloc_from_iter(tcx.resolutions(()).stripped_cfg_items.steal())
561560
}
562561

562+
fn resolutions(tcx: TyCtxt<'_>, _: ()) -> &ty::ResolverGlobalCtxt {
563+
tcx.resolver_for_lowering(()).1
564+
}
565+
563566
pub(crate) fn write_dep_info(tcx: TyCtxt<'_>) {
564567
// Make sure name resolution and macro expansion is run for
565568
// the side-effect of providing a complete set of all
@@ -615,6 +618,7 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| {
615618
providers.hir_crate = rustc_ast_lowering::lower_to_hir;
616619
providers.resolver_for_lowering = resolver_for_lowering;
617620
providers.stripped_cfg_items = stripped_cfg_items;
621+
providers.resolutions = resolutions;
618622
providers.early_lint_checks = early_lint_checks;
619623
proc_macro_decls::provide(providers);
620624
rustc_const_eval::provide(providers);

compiler/rustc_middle/src/query/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,11 @@ rustc_queries! {
125125
}
126126

127127
query resolutions(_: ()) -> &'tcx ty::ResolverGlobalCtxt {
128-
feedable
129128
no_hash
130129
desc { "getting the resolver outputs" }
131130
}
132131

133-
query resolver_for_lowering(_: ()) -> &'tcx Steal<(ty::ResolverAstLowering, Lrc<ast::Crate>)> {
132+
query resolver_for_lowering(_: ()) -> (&'tcx Steal<(ty::ResolverAstLowering, Lrc<ast::Crate>)>, &'tcx ty::ResolverGlobalCtxt) {
134133
eval_always
135134
no_hash
136135
desc { "getting the resolver for lowering" }

compiler/rustc_middle/src/ty/context.rs

+1
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ impl<'tcx> TyCtxt<'tcx> {
556556
/// Can only be fed before queries are run, and is thus exempt from any
557557
/// incremental issues. Do not use except for the initial query feeding.
558558
pub fn feed_unit_query(self) -> TyCtxtFeed<'tcx, ()> {
559+
self.dep_graph.assert_ignored();
559560
TyCtxtFeed { tcx: self, key: () }
560561
}
561562

compiler/rustc_passes/src/debugger_visualizer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<'ast> rustc_ast::visit::Visitor<'ast> for DebuggerVisualizerCollector<'_> {
8787

8888
/// Traverses and collects the debugger visualizers for a specific crate.
8989
fn debugger_visualizers(tcx: TyCtxt<'_>, _: LocalCrate) -> Vec<DebuggerVisualizerFile> {
90-
let resolver_and_krate = tcx.resolver_for_lowering(()).borrow();
90+
let resolver_and_krate = tcx.resolver_for_lowering(()).0.borrow();
9191
let krate = &*resolver_and_krate.1;
9292

9393
let mut visitor = DebuggerVisualizerCollector { sess: tcx.sess, visualizers: Vec::new() };

compiler/rustc_passes/src/lang_items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl<'ast, 'tcx> LanguageItemCollector<'ast, 'tcx> {
243243

244244
/// Traverses and collects all the lang items in all crates.
245245
fn get_lang_items(tcx: TyCtxt<'_>, (): ()) -> LanguageItems {
246-
let resolver = tcx.resolver_for_lowering(()).borrow();
246+
let resolver = tcx.resolver_for_lowering(()).0.borrow();
247247
let (resolver, krate) = &*resolver;
248248

249249
// Initialize the collector.

0 commit comments

Comments
 (0)