Skip to content

Only assign dep node indices in non-incremental mode if self profiling is active #68687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/librustc/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use rustc_data_structures::sync::{AtomicU32, AtomicU64, Lock, Lrc, Ordering};
use rustc_errors::Diagnostic;
use rustc_hir::def_id::DefId;
use rustc_index::vec::{Idx, IndexVec};
use rustc_session::Session;
use smallvec::SmallVec;
use std::collections::hash_map::Entry;
use std::env;
Expand Down Expand Up @@ -338,13 +339,19 @@ impl DepGraph {

(result, dep_node_index)
} else {
(task(cx, arg), self.next_virtual_depnode_index())
let sess = cx.get_stable_hashing_context().sess();
(task(cx, arg), self.next_virtual_depnode_index(sess))
}
}

/// Executes something within an "anonymous" task, that is, a task the
/// `DepNode` of which is determined by the list of inputs it read from.
pub fn with_anon_task<OP, R>(&self, dep_kind: DepKind, op: OP) -> (R, DepNodeIndex)
pub fn with_anon_task<OP, R>(
&self,
sess: &Session,
dep_kind: DepKind,
op: OP,
) -> (R, DepNodeIndex)
where
OP: FnOnce() -> R,
{
Expand All @@ -368,7 +375,7 @@ impl DepGraph {
let dep_node_index = data.current.complete_anon_task(dep_kind, task_deps);
(result, dep_node_index)
} else {
(op(), self.next_virtual_depnode_index())
(op(), self.next_virtual_depnode_index(sess))
}
}

Expand Down Expand Up @@ -909,9 +916,13 @@ impl DepGraph {
}
}

fn next_virtual_depnode_index(&self) -> DepNodeIndex {
let index = self.virtual_dep_node_index.fetch_add(1, Relaxed);
DepNodeIndex::from_u32(index)
fn next_virtual_depnode_index(&self, sess: &Session) -> DepNodeIndex {
if unlikely!(sess.prof.enabled()) {
let index = self.virtual_dep_node_index.fetch_add(1, Relaxed);
DepNodeIndex::from_u32(index)
} else {
DepNodeIndex::INVALID
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
OP: FnOnce(&mut Self) -> R,
{
let (result, dep_node) =
self.tcx().dep_graph.with_anon_task(DepKind::TraitSelect, || op(self));
self.tcx().dep_graph.with_anon_task(self.tcx().sess, DepKind::TraitSelect, || op(self));
self.tcx().dep_graph.read_index(dep_node);
(result, dep_node)
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ impl<'tcx> TyCtxt<'tcx> {

let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| {
self.start_query(job.job.clone(), diagnostics, |tcx| {
tcx.dep_graph.with_anon_task(Q::dep_kind(), || Q::compute(tcx, key))
tcx.dep_graph.with_anon_task(self.sess, Q::dep_kind(), || Q::compute(tcx, key))
})
});

Expand Down