diff options
| author | bors <bors@rust-lang.org> | 2023-03-20 23:53:09 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-03-20 23:53:09 +0000 |
| commit | 822c10feb7d594f324d0160bef47ed999769a789 (patch) | |
| tree | 4696e45fe58ebacdbe727c69ed895aa7a648a1d2 | |
| parent | 44f5180584404d18058cbbf224c55255db4fdcbb (diff) | |
| parent | c4bcac628cd44e8585a7b45583ae702624d13d63 (diff) | |
| download | rust-822c10feb7d594f324d0160bef47ed999769a789.tar.gz rust-822c10feb7d594f324d0160bef47ed999769a789.zip | |
Auto merge of #109046 - Zoxc:split-execute-job, r=cjgillot,michaelwoerister
Split `execute_job` into `execute_job_incr` and `execute_job_non_incr` `execute_job` was a bit large, so this splits it in 2. Performance was neutral locally, but this may affect bootstrap times.
| -rw-r--r-- | compiler/rustc_query_system/src/dep_graph/graph.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_query_system/src/query/plumbing.rs | 71 |
2 files changed, 42 insertions, 30 deletions
diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs index 02cb9c452a8..3dbcc4d2e8a 100644 --- a/compiler/rustc_query_system/src/dep_graph/graph.rs +++ b/compiler/rustc_query_system/src/dep_graph/graph.rs @@ -969,6 +969,7 @@ impl<K: DepKind> DepGraph<K> { } pub(crate) fn next_virtual_depnode_index(&self) -> DepNodeIndex { + debug_assert!(self.data.is_none()); let index = self.virtual_dep_node_index.fetch_add(1, Relaxed); DepNodeIndex::from_u32(index) } diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index 005512cf53e..ba2f859ff0f 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -379,7 +379,11 @@ where match JobOwner::<'_, Q::Key, Qcx::DepKind>::try_start(&qcx, state, state_lock, span, key) { TryGetJob::NotYetStarted(job) => { - let (result, dep_node_index) = execute_job(query, qcx, key.clone(), dep_node, job.id); + let (result, dep_node_index) = match qcx.dep_context().dep_graph().data() { + None => execute_job_non_incr(query, qcx, key, job.id), + Some(data) => execute_job_incr(query, qcx, data, key, dep_node, job.id), + }; + let cache = query.query_cache(qcx); if query.feedable() { // We should not compute queries that also got a value via feeding. @@ -413,48 +417,55 @@ where } } +// Fast path for when incr. comp. is off. #[inline(always)] -fn execute_job<Q, Qcx>( +fn execute_job_non_incr<Q, Qcx>( query: Q, qcx: Qcx, key: Q::Key, - mut dep_node_opt: Option<DepNode<Qcx::DepKind>>, job_id: QueryJobId, ) -> (Q::Value, DepNodeIndex) where Q: QueryConfig<Qcx>, Qcx: QueryContext, { - let dep_graph = qcx.dep_context().dep_graph(); - let dep_graph_data = match dep_graph.data() { - // Fast path for when incr. comp. is off. - None => { - // Fingerprint the key, just to assert that it doesn't - // have anything we don't consider hashable - if cfg!(debug_assertions) { - let _ = key.to_fingerprint(*qcx.dep_context()); - } + debug_assert!(!qcx.dep_context().dep_graph().is_fully_enabled()); - let prof_timer = qcx.dep_context().profiler().query_provider(); - let result = - qcx.start_query(job_id, query.depth_limit(), None, || query.compute(qcx, key)); - let dep_node_index = dep_graph.next_virtual_depnode_index(); - prof_timer.finish_with_query_invocation_id(dep_node_index.into()); - - // Similarly, fingerprint the result to assert that - // it doesn't have anything not considered hashable. - if cfg!(debug_assertions) && let Some(hash_result) = query.hash_result() - { - qcx.dep_context().with_stable_hashing_context(|mut hcx| { - hash_result(&mut hcx, &result); - }); - } + // Fingerprint the key, just to assert that it doesn't + // have anything we don't consider hashable + if cfg!(debug_assertions) { + let _ = key.to_fingerprint(*qcx.dep_context()); + } - return (result, dep_node_index); - } - Some(data) => data, - }; + let prof_timer = qcx.dep_context().profiler().query_provider(); + let result = qcx.start_query(job_id, query.depth_limit(), None, || query.compute(qcx, key)); + let dep_node_index = qcx.dep_context().dep_graph().next_virtual_depnode_index(); + prof_timer.finish_with_query_invocation_id(dep_node_index.into()); + + // Similarly, fingerprint the result to assert that + // it doesn't have anything not considered hashable. + if cfg!(debug_assertions) && let Some(hash_result) = query.hash_result() { + qcx.dep_context().with_stable_hashing_context(|mut hcx| { + hash_result(&mut hcx, &result); + }); + } + (result, dep_node_index) +} + +#[inline(always)] +fn execute_job_incr<Q, Qcx>( + query: Q, + qcx: Qcx, + dep_graph_data: &DepGraphData<Qcx::DepKind>, + key: Q::Key, + mut dep_node_opt: Option<DepNode<Qcx::DepKind>>, + job_id: QueryJobId, +) -> (Q::Value, DepNodeIndex) +where + Q: QueryConfig<Qcx>, + Qcx: QueryContext, +{ if !query.anon() && !query.eval_always() { // `to_dep_node` is expensive for some `DepKind`s. let dep_node = |
