Skip to content

Commit c3bf396

Browse files
committed
Move assertion inwards.
`with_taks_impl` is only called from `with_eval_always_task` and `with_task` . The former is only used in query invocation, while the latter is also used to start the `tcx` and to trigger codegen. This move should not change significantly the number of calls to this assertion.
1 parent cd1cb34 commit c3bf396

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

compiler/rustc_query_system/src/dep_graph/graph.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
1111
use parking_lot::Mutex;
1212
use smallvec::{smallvec, SmallVec};
1313
use std::collections::hash_map::Entry;
14+
use std::fmt::Debug;
1415
use std::hash::Hash;
1516
use std::marker::PhantomData;
1617
use std::sync::atomic::Ordering::Relaxed;
@@ -208,7 +209,7 @@ impl<K: DepKind> DepGraph<K> {
208209
/// `arg` parameter.
209210
///
210211
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/incremental-compilation.html
211-
pub fn with_task<Ctxt: HasDepContext<DepKind = K>, A, R>(
212+
pub fn with_task<Ctxt: HasDepContext<DepKind = K>, A: Debug, R>(
212213
&self,
213214
key: DepNode<K>,
214215
cx: Ctxt,
@@ -234,7 +235,7 @@ impl<K: DepKind> DepGraph<K> {
234235
)
235236
}
236237

237-
fn with_task_impl<Ctxt: HasDepContext<DepKind = K>, A, R>(
238+
fn with_task_impl<Ctxt: HasDepContext<DepKind = K>, A: Debug, R>(
238239
&self,
239240
key: DepNode<K>,
240241
cx: Ctxt,
@@ -244,6 +245,20 @@ impl<K: DepKind> DepGraph<K> {
244245
hash_result: impl FnOnce(&mut Ctxt::StableHashingContext, &R) -> Option<Fingerprint>,
245246
) -> (R, DepNodeIndex) {
246247
if let Some(ref data) = self.data {
248+
// If the following assertion triggers, it can have two reasons:
249+
// 1. Something is wrong with DepNode creation, either here or
250+
// in `DepGraph::try_mark_green()`.
251+
// 2. Two distinct query keys get mapped to the same `DepNode`
252+
// (see for example #48923).
253+
assert!(
254+
!self.dep_node_exists(&key),
255+
"forcing query with already existing `DepNode`\n\
256+
- query-key: {:?}\n\
257+
- dep-node: {:?}",
258+
arg,
259+
key
260+
);
261+
247262
let dcx = cx.dep_context();
248263
let task_deps = create_task(key).map(Lock::new);
249264
let result = K::with_deps(task_deps.as_ref(), || task(cx, arg));
@@ -359,7 +374,7 @@ impl<K: DepKind> DepGraph<K> {
359374

360375
/// Executes something within an "eval-always" task which is a task
361376
/// that runs whenever anything changes.
362-
pub fn with_eval_always_task<Ctxt: HasDepContext<DepKind = K>, A, R>(
377+
pub fn with_eval_always_task<Ctxt: HasDepContext<DepKind = K>, A: Debug, R>(
363378
&self,
364379
key: DepNode<K>,
365380
cx: Ctxt,

compiler/rustc_query_system/src/query/plumbing.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -646,20 +646,6 @@ where
646646
C: QueryCache,
647647
CTX: QueryContext,
648648
{
649-
// If the following assertion triggers, it can have two reasons:
650-
// 1. Something is wrong with DepNode creation, either here or
651-
// in `DepGraph::try_mark_green()`.
652-
// 2. Two distinct query keys get mapped to the same `DepNode`
653-
// (see for example #48923).
654-
assert!(
655-
!tcx.dep_context().dep_graph().dep_node_exists(&dep_node),
656-
"forcing query with already existing `DepNode`\n\
657-
- query-key: {:?}\n\
658-
- dep-node: {:?}",
659-
key,
660-
dep_node
661-
);
662-
663649
let prof_timer = tcx.dep_context().profiler().query_provider();
664650

665651
let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| {

0 commit comments

Comments
 (0)