Skip to content

Commit d7ea15a

Browse files
committed
Only assign dep node indices in non-incremental mode if self profiling is active
1 parent 34700c1 commit d7ea15a

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

src/librustc/dep_graph/graph.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_data_structures::sync::{AtomicU32, AtomicU64, Lock, Lrc, Ordering};
88
use rustc_errors::Diagnostic;
99
use rustc_hir::def_id::DefId;
1010
use rustc_index::vec::{Idx, IndexVec};
11+
use rustc_session::Session;
1112
use smallvec::SmallVec;
1213
use std::collections::hash_map::Entry;
1314
use std::env;
@@ -338,13 +339,19 @@ impl DepGraph {
338339

339340
(result, dep_node_index)
340341
} else {
341-
(task(cx, arg), self.next_virtual_depnode_index())
342+
let sess = cx.get_stable_hashing_context().sess();
343+
(task(cx, arg), self.next_virtual_depnode_index(sess))
342344
}
343345
}
344346

345347
/// Executes something within an "anonymous" task, that is, a task the
346348
/// `DepNode` of which is determined by the list of inputs it read from.
347-
pub fn with_anon_task<OP, R>(&self, dep_kind: DepKind, op: OP) -> (R, DepNodeIndex)
349+
pub fn with_anon_task<OP, R>(
350+
&self,
351+
sess: &Session,
352+
dep_kind: DepKind,
353+
op: OP,
354+
) -> (R, DepNodeIndex)
348355
where
349356
OP: FnOnce() -> R,
350357
{
@@ -368,7 +375,7 @@ impl DepGraph {
368375
let dep_node_index = data.current.complete_anon_task(dep_kind, task_deps);
369376
(result, dep_node_index)
370377
} else {
371-
(op(), self.next_virtual_depnode_index())
378+
(op(), self.next_virtual_depnode_index(sess))
372379
}
373380
}
374381

@@ -909,9 +916,13 @@ impl DepGraph {
909916
}
910917
}
911918

912-
fn next_virtual_depnode_index(&self) -> DepNodeIndex {
913-
let index = self.virtual_dep_node_index.fetch_add(1, Relaxed);
914-
DepNodeIndex::from_u32(index)
919+
fn next_virtual_depnode_index(&self, sess: &Session) -> DepNodeIndex {
920+
if unlikely!(sess.prof.enabled()) {
921+
let index = self.virtual_dep_node_index.fetch_add(1, Relaxed);
922+
DepNodeIndex::from_u32(index)
923+
} else {
924+
DepNodeIndex::INVALID
925+
}
915926
}
916927
}
917928

src/librustc/traits/select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12601260
OP: FnOnce(&mut Self) -> R,
12611261
{
12621262
let (result, dep_node) =
1263-
self.tcx().dep_graph.with_anon_task(DepKind::TraitSelect, || op(self));
1263+
self.tcx().dep_graph.with_anon_task(self.tcx().sess, DepKind::TraitSelect, || op(self));
12641264
self.tcx().dep_graph.read_index(dep_node);
12651265
(result, dep_node)
12661266
}

src/librustc/ty/query/plumbing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ impl<'tcx> TyCtxt<'tcx> {
385385

386386
let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| {
387387
self.start_query(job.job.clone(), diagnostics, |tcx| {
388-
tcx.dep_graph.with_anon_task(Q::dep_kind(), || Q::compute(tcx, key))
388+
tcx.dep_graph.with_anon_task(self.sess, Q::dep_kind(), || Q::compute(tcx, key))
389389
})
390390
});
391391

0 commit comments

Comments
 (0)