Skip to content

Commit a7d4880

Browse files
Turn debugger_visualizers from feed- into regular query.
1 parent 7f01893 commit a7d4880

File tree

6 files changed

+29
-13
lines changed

6 files changed

+29
-13
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use rustc_errors::{
5858
use rustc_fluent_macro::fluent_messages;
5959
use rustc_hir as hir;
6060
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
61-
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
61+
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID, LOCAL_CRATE};
6262
use rustc_hir::definitions::DefPathData;
6363
use rustc_hir::{ConstArg, GenericArg, ItemLocalId, ParamName, TraitCandidate};
6464
use rustc_index::{Idx, IndexSlice, IndexVec};
@@ -435,6 +435,7 @@ pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> hir::Crate<'_> {
435435
// Queries that borrow `resolver_for_lowering`.
436436
tcx.ensure_with_value().output_filenames(());
437437
tcx.ensure_with_value().early_lint_checks(());
438+
tcx.ensure_with_value().debugger_visualizers(LOCAL_CRATE);
438439
let (mut resolver, krate) = tcx.resolver_for_lowering(()).steal();
439440

440441
let ast_index = index_crate(&resolver.node_id_to_def_id, &krate);

compiler/rustc_interface/src/passes.rs

-6
Original file line numberDiff line numberDiff line change
@@ -572,12 +572,6 @@ fn resolver_for_lowering<'tcx>(
572572
// Make sure we don't mutate the cstore from here on.
573573
tcx.untracked().cstore.leak();
574574

575-
{
576-
let debugger_visualizers = rustc_passes::debugger_visualizer::collect(tcx.sess, &krate);
577-
let feed = tcx.feed_local_crate();
578-
feed.debugger_visualizers(debugger_visualizers);
579-
}
580-
581575
let ty::ResolverOutputs {
582576
global_ctxt: untracked_resolutions,
583577
ast_lowering: untracked_resolver_for_lowering,

compiler/rustc_middle/src/hir/map/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,11 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, _: LocalCrate) -> Svh {
11651165

11661166
source_file_names.sort_unstable();
11671167

1168+
// We have to take care of debugger visualizers explicitly. The HIR (and
1169+
// thus `hir_body_hash`) contains the #[debugger_visualizer] attributes but
1170+
// these attributes only store the file path to the visualizer file, not
1171+
// their content. Yet that content is exported into crate metadata, so any
1172+
// changes to it need to be reflected in the crate hash.
11681173
let debugger_visualizers: Vec<_> = tcx
11691174
.debugger_visualizers(LOCAL_CRATE)
11701175
.iter()

compiler/rustc_middle/src/query/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1790,13 +1790,18 @@ rustc_queries! {
17901790
desc { "looking at the source for a crate" }
17911791
separate_provide_extern
17921792
}
1793+
17931794
/// Returns the debugger visualizers defined for this crate.
1795+
/// NOTE: This query has to be marked `eval_always` because it reads data
1796+
/// directly from disk that is not tracked anywhere else. I.e. it
1797+
/// represents a genuine input to the query system.
17941798
query debugger_visualizers(_: CrateNum) -> &'tcx Vec<rustc_span::DebuggerVisualizerFile> {
17951799
arena_cache
17961800
desc { "looking up the debugger visualizers for this crate" }
17971801
separate_provide_extern
1798-
feedable
1802+
eval_always
17991803
}
1804+
18001805
query postorder_cnums(_: ()) -> &'tcx [CrateNum] {
18011806
eval_always
18021807
desc { "generating a postorder list of CrateNums" }

compiler/rustc_passes/src/debugger_visualizer.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
use rustc_ast::Attribute;
44
use rustc_data_structures::sync::Lrc;
55
use rustc_expand::base::resolve_path;
6+
use rustc_middle::{
7+
query::{LocalCrate, Providers},
8+
ty::TyCtxt,
9+
};
610
use rustc_session::Session;
711
use rustc_span::{sym, DebuggerVisualizerFile, DebuggerVisualizerType};
812

@@ -12,7 +16,7 @@ impl DebuggerVisualizerCollector<'_> {
1216
fn check_for_debugger_visualizer(&mut self, attr: &Attribute) {
1317
if attr.has_name(sym::debugger_visualizer) {
1418
let Some(hints) = attr.meta_item_list() else {
15-
self.sess.emit_err(DebugVisualizerInvalid { span: attr.span });
19+
self.sess.emit_err(DebugVisualizerInvalid { span: attr.span });
1620
return;
1721
};
1822

@@ -82,12 +86,18 @@ impl<'ast> rustc_ast::visit::Visitor<'ast> for DebuggerVisualizerCollector<'_> {
8286
}
8387

8488
/// Traverses and collects the debugger visualizers for a specific crate.
85-
pub fn collect(sess: &Session, krate: &rustc_ast::ast::Crate) -> Vec<DebuggerVisualizerFile> {
86-
// Initialize the collector.
87-
let mut visitor = DebuggerVisualizerCollector { sess, visualizers: Vec::new() };
89+
fn debugger_visualizers(tcx: TyCtxt<'_>, _: LocalCrate) -> Vec<DebuggerVisualizerFile> {
90+
let resolver_and_krate = tcx.resolver_for_lowering(()).borrow();
91+
let krate = &*resolver_and_krate.1;
92+
93+
let mut visitor = DebuggerVisualizerCollector { sess: tcx.sess, visualizers: Vec::new() };
8894
rustc_ast::visit::Visitor::visit_crate(&mut visitor, krate);
8995

9096
// Sort the visualizers so we always get a deterministic query result.
9197
visitor.visualizers.sort_unstable();
9298
visitor.visualizers
9399
}
100+
101+
pub fn provide(providers: &mut Providers) {
102+
providers.debugger_visualizers = debugger_visualizers;
103+
}

compiler/rustc_passes/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc_middle::query::Providers;
2727
mod check_attr;
2828
mod check_const;
2929
pub mod dead;
30-
pub mod debugger_visualizer;
30+
mod debugger_visualizer;
3131
mod diagnostic_items;
3232
pub mod entry;
3333
mod errors;
@@ -50,6 +50,7 @@ pub fn provide(providers: &mut Providers) {
5050
check_attr::provide(providers);
5151
check_const::provide(providers);
5252
dead::provide(providers);
53+
debugger_visualizer::provide(providers);
5354
diagnostic_items::provide(providers);
5455
entry::provide(providers);
5556
lang_items::provide(providers);

0 commit comments

Comments
 (0)