Skip to content

Commit 29cc76f

Browse files
committed
Add a profiler reference to GraphEncoder
1 parent 62415e2 commit 29cc76f

File tree

3 files changed

+18
-33
lines changed

3 files changed

+18
-33
lines changed

compiler/rustc_middle/src/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ impl<'tcx> GlobalCtxt<'tcx> {
650650
}
651651

652652
pub fn finish(&self) -> FileEncodeResult {
653-
self.dep_graph.finish_encoding(&self.sess.prof)
653+
self.dep_graph.finish_encoding()
654654
}
655655
}
656656

compiler/rustc_query_system/src/dep_graph/graph.rs

+10-26
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ impl<D: Deps> DepGraph<D> {
134134

135135
// Instantiate a dependy-less node only once for anonymous queries.
136136
let _green_node_index = current.intern_new_node(
137-
profiler,
138137
DepNode { kind: D::DEP_KIND_NULL, hash: current.anon_id_seed.into() },
139138
EdgesVec::new(),
140139
Fingerprint::ZERO,
@@ -443,12 +442,7 @@ impl<D: Deps> DepGraphData<D> {
443442
hash: self.current.anon_id_seed.combine(hasher.finish()).into(),
444443
};
445444

446-
self.current.intern_new_node(
447-
cx.profiler(),
448-
target_dep_node,
449-
task_deps,
450-
Fingerprint::ZERO,
451-
)
445+
self.current.intern_new_node(target_dep_node, task_deps, Fingerprint::ZERO)
452446
}
453447
};
454448

@@ -871,11 +865,8 @@ impl<D: Deps> DepGraphData<D> {
871865

872866
// We allocating an entry for the node in the current dependency graph and
873867
// adding all the appropriate edges imported from the previous graph
874-
let dep_node_index = self.current.promote_node_and_deps_to_current(
875-
qcx.dep_context().profiler(),
876-
&self.previous,
877-
prev_dep_node_index,
878-
);
868+
let dep_node_index =
869+
self.current.promote_node_and_deps_to_current(&self.previous, prev_dep_node_index);
879870

880871
// ... emitting any stored diagnostic ...
881872

@@ -981,12 +972,8 @@ impl<D: Deps> DepGraph<D> {
981972
}
982973
}
983974

984-
pub fn finish_encoding(&self, profiler: &SelfProfilerRef) -> FileEncodeResult {
985-
if let Some(data) = &self.data {
986-
data.current.encoder.steal().finish(profiler)
987-
} else {
988-
Ok(0)
989-
}
975+
pub fn finish_encoding(&self) -> FileEncodeResult {
976+
if let Some(data) = &self.data { data.current.encoder.steal().finish() } else { Ok(0) }
990977
}
991978

992979
pub(crate) fn next_virtual_depnode_index(&self) -> DepNodeIndex {
@@ -1150,6 +1137,7 @@ impl<D: Deps> CurrentDepGraph<D> {
11501137
prev_graph_node_count,
11511138
record_graph,
11521139
record_stats,
1140+
profiler,
11531141
)),
11541142
new_node_to_index: Sharded::new(|| {
11551143
FxHashMap::with_capacity_and_hasher(
@@ -1183,16 +1171,14 @@ impl<D: Deps> CurrentDepGraph<D> {
11831171
#[inline(always)]
11841172
fn intern_new_node(
11851173
&self,
1186-
profiler: &SelfProfilerRef,
11871174
key: DepNode,
11881175
edges: EdgesVec,
11891176
current_fingerprint: Fingerprint,
11901177
) -> DepNodeIndex {
11911178
let dep_node_index = match self.new_node_to_index.lock_shard_by_value(&key).entry(key) {
11921179
Entry::Occupied(entry) => *entry.get(),
11931180
Entry::Vacant(entry) => {
1194-
let dep_node_index =
1195-
self.encoder.borrow().send(profiler, key, current_fingerprint, edges);
1181+
let dep_node_index = self.encoder.borrow().send(key, current_fingerprint, edges);
11961182
entry.insert(dep_node_index);
11971183
dep_node_index
11981184
}
@@ -1223,8 +1209,7 @@ impl<D: Deps> CurrentDepGraph<D> {
12231209
let dep_node_index = match prev_index_to_index[prev_index] {
12241210
Some(dep_node_index) => dep_node_index,
12251211
None => {
1226-
let dep_node_index =
1227-
self.encoder.borrow().send(profiler, key, fingerprint, edges);
1212+
let dep_node_index = self.encoder.borrow().send(key, fingerprint, edges);
12281213
prev_index_to_index[prev_index] = Some(dep_node_index);
12291214
dep_node_index
12301215
}
@@ -1261,15 +1246,14 @@ impl<D: Deps> CurrentDepGraph<D> {
12611246
let fingerprint = fingerprint.unwrap_or(Fingerprint::ZERO);
12621247

12631248
// This is a new node: it didn't exist in the previous compilation session.
1264-
let dep_node_index = self.intern_new_node(profiler, key, edges, fingerprint);
1249+
let dep_node_index = self.intern_new_node(key, edges, fingerprint);
12651250

12661251
(dep_node_index, None)
12671252
}
12681253
}
12691254

12701255
fn promote_node_and_deps_to_current(
12711256
&self,
1272-
profiler: &SelfProfilerRef,
12731257
prev_graph: &SerializedDepGraph,
12741258
prev_index: SerializedDepNodeIndex,
12751259
) -> DepNodeIndex {
@@ -1286,7 +1270,7 @@ impl<D: Deps> CurrentDepGraph<D> {
12861270
.map(|i| prev_index_to_index[i].unwrap())
12871271
.collect();
12881272
let fingerprint = prev_graph.fingerprint_by_index(prev_index);
1289-
let dep_node_index = self.encoder.borrow().send(profiler, key, fingerprint, edges);
1273+
let dep_node_index = self.encoder.borrow().send(key, fingerprint, edges);
12901274
prev_index_to_index[prev_index] = Some(dep_node_index);
12911275
#[cfg(debug_assertions)]
12921276
self.record_edge(dep_node_index, key, fingerprint);

compiler/rustc_query_system/src/dep_graph/serialized.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ impl<D: Deps> EncoderState<D> {
504504
}
505505

506506
pub struct GraphEncoder<D: Deps> {
507+
profiler: SelfProfilerRef,
507508
status: Lock<EncoderState<D>>,
508509
record_graph: Option<Lock<DepGraphQuery>>,
509510
}
@@ -514,10 +515,11 @@ impl<D: Deps> GraphEncoder<D> {
514515
prev_node_count: usize,
515516
record_graph: bool,
516517
record_stats: bool,
518+
profiler: &SelfProfilerRef,
517519
) -> Self {
518520
let record_graph = record_graph.then(|| Lock::new(DepGraphQuery::new(prev_node_count)));
519521
let status = Lock::new(EncoderState::new(encoder, record_stats));
520-
GraphEncoder { status, record_graph }
522+
GraphEncoder { status, record_graph, profiler: profiler.clone() }
521523
}
522524

523525
pub(crate) fn with_query(&self, f: impl Fn(&DepGraphQuery)) {
@@ -580,18 +582,17 @@ impl<D: Deps> GraphEncoder<D> {
580582

581583
pub(crate) fn send(
582584
&self,
583-
profiler: &SelfProfilerRef,
584585
node: DepNode,
585586
fingerprint: Fingerprint,
586587
edges: EdgesVec,
587588
) -> DepNodeIndex {
588-
let _prof_timer = profiler.generic_activity("incr_comp_encode_dep_graph");
589+
let _prof_timer = self.profiler.generic_activity("incr_comp_encode_dep_graph");
589590
let node = NodeInfo { node, fingerprint, edges };
590591
self.status.lock().encode_node(&node, &self.record_graph)
591592
}
592593

593-
pub fn finish(self, profiler: &SelfProfilerRef) -> FileEncodeResult {
594-
let _prof_timer = profiler.generic_activity("incr_comp_encode_dep_graph");
595-
self.status.into_inner().finish(profiler)
594+
pub fn finish(self) -> FileEncodeResult {
595+
let _prof_timer = self.profiler.generic_activity("incr_comp_encode_dep_graph");
596+
self.status.into_inner().finish(&self.profiler)
596597
}
597598
}

0 commit comments

Comments
 (0)