From 75181dc22f6e25760a95fdc4ad92f9a054506486 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Mon, 13 Dec 2021 20:56:30 -0600 Subject: Error if we try to read dep during deserialization --- compiler/rustc_query_system/src/dep_graph/graph.rs | 8 ++++++++ compiler/rustc_query_system/src/query/mod.rs | 1 + compiler/rustc_query_system/src/query/plumbing.rs | 6 +++--- 3 files changed, 12 insertions(+), 3 deletions(-) (limited to 'compiler/rustc_query_system') diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs index a8be1ca34c0..64dcc6f37f1 100644 --- a/compiler/rustc_query_system/src/dep_graph/graph.rs +++ b/compiler/rustc_query_system/src/dep_graph/graph.rs @@ -251,6 +251,7 @@ impl DepGraph { reads: SmallVec::new(), read_set: Default::default(), phantom_data: PhantomData, + read_allowed: true, })) }; let result = K::with_deps(task_deps.as_ref(), || task(cx, arg)); @@ -362,6 +363,11 @@ impl DepGraph { if let Some(task_deps) = task_deps { let mut task_deps = task_deps.lock(); let task_deps = &mut *task_deps; + + if !task_deps.read_allowed { + panic!("Illegal read of: {:?}", dep_node_index); + } + if cfg!(debug_assertions) { data.current.total_read_count.fetch_add(1, Relaxed); } @@ -1115,6 +1121,7 @@ pub struct TaskDeps { reads: EdgesVec, read_set: FxHashSet, phantom_data: PhantomData>, + pub read_allowed: bool, } impl Default for TaskDeps { @@ -1125,6 +1132,7 @@ impl Default for TaskDeps { reads: EdgesVec::new(), read_set: FxHashSet::default(), phantom_data: PhantomData, + read_allowed: true, } } } diff --git a/compiler/rustc_query_system/src/query/mod.rs b/compiler/rustc_query_system/src/query/mod.rs index a2f7843baaa..265e0b80d7c 100644 --- a/compiler/rustc_query_system/src/query/mod.rs +++ b/compiler/rustc_query_system/src/query/mod.rs @@ -142,6 +142,7 @@ pub trait QueryContext: HasDepContext { &self, token: QueryJobId, diagnostics: Option<&Lock>>, + read_allowed: bool, compute: impl FnOnce() -> R, ) -> R; } diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index b08db39e245..e4a177cbffb 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -440,7 +440,7 @@ where // Fast path for when incr. comp. is off. if !dep_graph.is_fully_enabled() { let prof_timer = tcx.dep_context().profiler().query_provider(); - let result = tcx.start_query(job_id, None, || query.compute(*tcx.dep_context(), key)); + let result = tcx.start_query(job_id, None, true, || query.compute(*tcx.dep_context(), key)); let dep_node_index = dep_graph.next_virtual_depnode_index(); prof_timer.finish_with_query_invocation_id(dep_node_index.into()); return (result, dep_node_index); @@ -453,7 +453,7 @@ where // The diagnostics for this query will be promoted to the current session during // `try_mark_green()`, so we can ignore them here. - if let Some(ret) = tcx.start_query(job_id, None, || { + if let Some(ret) = tcx.start_query(job_id, None, false, || { try_load_from_disk_and_cache_in_memory(tcx, &key, &dep_node, query) }) { return ret; @@ -463,7 +463,7 @@ where let prof_timer = tcx.dep_context().profiler().query_provider(); let diagnostics = Lock::new(ThinVec::new()); - let (result, dep_node_index) = tcx.start_query(job_id, Some(&diagnostics), || { + let (result, dep_node_index) = tcx.start_query(job_id, Some(&diagnostics), true, || { if query.anon { return dep_graph.with_anon_task(*tcx.dep_context(), query.dep_kind, || { query.compute(*tcx.dep_context(), key) -- cgit 1.4.1-3-g733a5