From 29cc76f0fc45e8ec0da07c513296a9980db4b9b5 Mon Sep 17 00:00:00 2001 From: John Kåre Alsaker Date: Wed, 6 Mar 2024 04:17:17 +0100 Subject: Add a profiler reference to `GraphEncoder` --- compiler/rustc_query_system/src/dep_graph/graph.rs | 36 ++++++---------------- .../rustc_query_system/src/dep_graph/serialized.rs | 13 ++++---- 2 files changed, 17 insertions(+), 32 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 7dc1a1f7917..b0df0067b5b 100644 --- a/compiler/rustc_query_system/src/dep_graph/graph.rs +++ b/compiler/rustc_query_system/src/dep_graph/graph.rs @@ -134,7 +134,6 @@ impl DepGraph { // Instantiate a dependy-less node only once for anonymous queries. let _green_node_index = current.intern_new_node( - profiler, DepNode { kind: D::DEP_KIND_NULL, hash: current.anon_id_seed.into() }, EdgesVec::new(), Fingerprint::ZERO, @@ -443,12 +442,7 @@ impl DepGraphData { hash: self.current.anon_id_seed.combine(hasher.finish()).into(), }; - self.current.intern_new_node( - cx.profiler(), - target_dep_node, - task_deps, - Fingerprint::ZERO, - ) + self.current.intern_new_node(target_dep_node, task_deps, Fingerprint::ZERO) } }; @@ -871,11 +865,8 @@ impl DepGraphData { // We allocating an entry for the node in the current dependency graph and // adding all the appropriate edges imported from the previous graph - let dep_node_index = self.current.promote_node_and_deps_to_current( - qcx.dep_context().profiler(), - &self.previous, - prev_dep_node_index, - ); + let dep_node_index = + self.current.promote_node_and_deps_to_current(&self.previous, prev_dep_node_index); // ... emitting any stored diagnostic ... @@ -981,12 +972,8 @@ impl DepGraph { } } - pub fn finish_encoding(&self, profiler: &SelfProfilerRef) -> FileEncodeResult { - if let Some(data) = &self.data { - data.current.encoder.steal().finish(profiler) - } else { - Ok(0) - } + pub fn finish_encoding(&self) -> FileEncodeResult { + if let Some(data) = &self.data { data.current.encoder.steal().finish() } else { Ok(0) } } pub(crate) fn next_virtual_depnode_index(&self) -> DepNodeIndex { @@ -1150,6 +1137,7 @@ impl CurrentDepGraph { prev_graph_node_count, record_graph, record_stats, + profiler, )), new_node_to_index: Sharded::new(|| { FxHashMap::with_capacity_and_hasher( @@ -1183,7 +1171,6 @@ impl CurrentDepGraph { #[inline(always)] fn intern_new_node( &self, - profiler: &SelfProfilerRef, key: DepNode, edges: EdgesVec, current_fingerprint: Fingerprint, @@ -1191,8 +1178,7 @@ impl CurrentDepGraph { let dep_node_index = match self.new_node_to_index.lock_shard_by_value(&key).entry(key) { Entry::Occupied(entry) => *entry.get(), Entry::Vacant(entry) => { - let dep_node_index = - self.encoder.borrow().send(profiler, key, current_fingerprint, edges); + let dep_node_index = self.encoder.borrow().send(key, current_fingerprint, edges); entry.insert(dep_node_index); dep_node_index } @@ -1223,8 +1209,7 @@ impl CurrentDepGraph { let dep_node_index = match prev_index_to_index[prev_index] { Some(dep_node_index) => dep_node_index, None => { - let dep_node_index = - self.encoder.borrow().send(profiler, key, fingerprint, edges); + let dep_node_index = self.encoder.borrow().send(key, fingerprint, edges); prev_index_to_index[prev_index] = Some(dep_node_index); dep_node_index } @@ -1261,7 +1246,7 @@ impl CurrentDepGraph { let fingerprint = fingerprint.unwrap_or(Fingerprint::ZERO); // This is a new node: it didn't exist in the previous compilation session. - let dep_node_index = self.intern_new_node(profiler, key, edges, fingerprint); + let dep_node_index = self.intern_new_node(key, edges, fingerprint); (dep_node_index, None) } @@ -1269,7 +1254,6 @@ impl CurrentDepGraph { fn promote_node_and_deps_to_current( &self, - profiler: &SelfProfilerRef, prev_graph: &SerializedDepGraph, prev_index: SerializedDepNodeIndex, ) -> DepNodeIndex { @@ -1286,7 +1270,7 @@ impl CurrentDepGraph { .map(|i| prev_index_to_index[i].unwrap()) .collect(); let fingerprint = prev_graph.fingerprint_by_index(prev_index); - let dep_node_index = self.encoder.borrow().send(profiler, key, fingerprint, edges); + let dep_node_index = self.encoder.borrow().send(key, fingerprint, edges); prev_index_to_index[prev_index] = Some(dep_node_index); #[cfg(debug_assertions)] self.record_edge(dep_node_index, key, fingerprint); diff --git a/compiler/rustc_query_system/src/dep_graph/serialized.rs b/compiler/rustc_query_system/src/dep_graph/serialized.rs index 3272a0ed167..d8db94defbd 100644 --- a/compiler/rustc_query_system/src/dep_graph/serialized.rs +++ b/compiler/rustc_query_system/src/dep_graph/serialized.rs @@ -504,6 +504,7 @@ impl EncoderState { } pub struct GraphEncoder { + profiler: SelfProfilerRef, status: Lock>, record_graph: Option>, } @@ -514,10 +515,11 @@ impl GraphEncoder { prev_node_count: usize, record_graph: bool, record_stats: bool, + profiler: &SelfProfilerRef, ) -> Self { let record_graph = record_graph.then(|| Lock::new(DepGraphQuery::new(prev_node_count))); let status = Lock::new(EncoderState::new(encoder, record_stats)); - GraphEncoder { status, record_graph } + GraphEncoder { status, record_graph, profiler: profiler.clone() } } pub(crate) fn with_query(&self, f: impl Fn(&DepGraphQuery)) { @@ -580,18 +582,17 @@ impl GraphEncoder { pub(crate) fn send( &self, - profiler: &SelfProfilerRef, node: DepNode, fingerprint: Fingerprint, edges: EdgesVec, ) -> DepNodeIndex { - let _prof_timer = profiler.generic_activity("incr_comp_encode_dep_graph"); + let _prof_timer = self.profiler.generic_activity("incr_comp_encode_dep_graph"); let node = NodeInfo { node, fingerprint, edges }; self.status.lock().encode_node(&node, &self.record_graph) } - pub fn finish(self, profiler: &SelfProfilerRef) -> FileEncodeResult { - let _prof_timer = profiler.generic_activity("incr_comp_encode_dep_graph"); - self.status.into_inner().finish(profiler) + pub fn finish(self) -> FileEncodeResult { + let _prof_timer = self.profiler.generic_activity("incr_comp_encode_dep_graph"); + self.status.into_inner().finish(&self.profiler) } } -- cgit 1.4.1-3-g733a5