From f2c8707abbedee2587b5653a42e0860a101f0ddf Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 30 Dec 2020 22:08:57 +0100 Subject: Remove force_query_with_job. --- compiler/rustc_query_system/src/query/plumbing.rs | 141 ++++++++-------------- 1 file changed, 53 insertions(+), 88 deletions(-) (limited to 'compiler/rustc_query_system') diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index 79fbde95850..e81a09d343d 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -17,7 +17,7 @@ use rustc_data_structures::profiling::TimingGuard; use rustc_data_structures::sharded::{get_shard_index_by_hash, Sharded}; use rustc_data_structures::sync::{Lock, LockGuard}; use rustc_data_structures::thin_vec::ThinVec; -use rustc_errors::{Diagnostic, DiagnosticBuilder, FatalError}; +use rustc_errors::{DiagnosticBuilder, FatalError}; use rustc_span::{Span, DUMMY_SP}; use std::cell::Cell; use std::collections::hash_map::Entry; @@ -304,15 +304,6 @@ where } } -fn with_diagnostics(f: F) -> (R, ThinVec) -where - F: FnOnce(Option<&Lock>>) -> R, -{ - let diagnostics = Lock::new(ThinVec::new()); - let result = f(Some(&diagnostics)); - (result, diagnostics.into_inner()) -} - impl<'tcx, D, K> Drop for JobOwner<'tcx, D, K> where D: Copy + Clone + Eq + Hash, @@ -452,7 +443,7 @@ where fn execute_job( tcx: CTX, key: K, - dep_node: Option>, + mut dep_node_opt: Option>, query: &QueryVtable, job_id: QueryJobId, compute: fn(CTX::DepContext, K) -> V, @@ -473,45 +464,66 @@ where return (result, dep_node_index); } - if query.anon { - let prof_timer = tcx.dep_context().profiler().query_provider(); - - let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| { - tcx.start_query(job_id, diagnostics, || { - dep_graph.with_anon_task(*tcx.dep_context(), query.dep_kind, || { - compute(*tcx.dep_context(), key) - }) - }) - }); + if !query.anon && !query.eval_always { + // `to_dep_node` is expensive for some `DepKind`s. + let dep_node = + dep_node_opt.get_or_insert_with(|| query.to_dep_node(*tcx.dep_context(), &key)); - prof_timer.finish_with_query_invocation_id(dep_node_index.into()); + // The diagnostics for this query will be promoted to the current session during + // `try_mark_green()`, so we can ignore them here. + if let Some(ret) = tcx.start_query(job_id, None, || { + try_load_from_disk_and_cache_in_memory(tcx, &key, &dep_node, query, compute) + }) { + return ret; + } + } - let side_effects = QuerySideEffects { diagnostics }; + let prof_timer = tcx.dep_context().profiler().query_provider(); + let diagnostics = Lock::new(ThinVec::new()); - if unlikely!(!side_effects.is_empty()) { - tcx.store_side_effects_for_anon_node(dep_node_index, side_effects); + let (result, dep_node_index) = tcx.start_query(job_id, Some(&diagnostics), || { + if query.anon { + return dep_graph.with_anon_task(*tcx.dep_context(), query.dep_kind, || { + compute(*tcx.dep_context(), key) + }); } - (result, dep_node_index) - } else if query.eval_always { // `to_dep_node` is expensive for some `DepKind`s. - let dep_node = dep_node.unwrap_or_else(|| query.to_dep_node(*tcx.dep_context(), &key)); - force_query_with_job(tcx, key, job_id, dep_node, query, compute) - } else { - // `to_dep_node` is expensive for some `DepKind`s. - let dep_node = dep_node.unwrap_or_else(|| query.to_dep_node(*tcx.dep_context(), &key)); - // The diagnostics for this query will be - // promoted to the current session during - // `try_mark_green()`, so we can ignore them here. - let loaded = tcx.start_query(job_id, None, || { - try_load_from_disk_and_cache_in_memory(tcx, &key, &dep_node, query, compute) - }); - if let Some((result, dep_node_index)) = loaded { - (result, dep_node_index) + let dep_node = dep_node_opt.unwrap_or_else(|| query.to_dep_node(*tcx.dep_context(), &key)); + + if query.eval_always { + tcx.dep_context().dep_graph().with_eval_always_task( + dep_node, + *tcx.dep_context(), + key, + compute, + query.hash_result, + ) + } else { + tcx.dep_context().dep_graph().with_task( + dep_node, + *tcx.dep_context(), + key, + compute, + query.hash_result, + ) + } + }); + + prof_timer.finish_with_query_invocation_id(dep_node_index.into()); + + let diagnostics = diagnostics.into_inner(); + let side_effects = QuerySideEffects { diagnostics }; + + if unlikely!(!side_effects.is_empty()) { + if query.anon { + tcx.store_side_effects_for_anon_node(dep_node_index, side_effects); } else { - force_query_with_job(tcx, key, job_id, dep_node, query, compute) + tcx.store_side_effects(dep_node_index, side_effects); } } + + (result, dep_node_index) } fn try_load_from_disk_and_cache_in_memory( @@ -641,53 +653,6 @@ fn incremental_verify_ich( } } -fn force_query_with_job( - tcx: CTX, - key: K, - job_id: QueryJobId, - dep_node: DepNode, - query: &QueryVtable, - compute: fn(CTX::DepContext, K) -> V, -) -> (V, DepNodeIndex) -where - CTX: QueryContext, - K: Debug, -{ - let prof_timer = tcx.dep_context().profiler().query_provider(); - - let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| { - tcx.start_query(job_id, diagnostics, || { - if query.eval_always { - tcx.dep_context().dep_graph().with_eval_always_task( - dep_node, - *tcx.dep_context(), - key, - compute, - query.hash_result, - ) - } else { - tcx.dep_context().dep_graph().with_task( - dep_node, - *tcx.dep_context(), - key, - compute, - query.hash_result, - ) - } - }) - }); - - prof_timer.finish_with_query_invocation_id(dep_node_index.into()); - - let side_effects = QuerySideEffects { diagnostics }; - - if unlikely!(!side_effects.is_empty()) && dep_node.kind != DepKind::NULL { - tcx.store_side_effects(dep_node_index, side_effects); - } - - (result, dep_node_index) -} - /// Ensure that either this query has all green inputs or been executed. /// Executing `query::ensure(D)` is considered a read of the dep-node `D`. /// Returns true if the query should still run. -- cgit 1.4.1-3-g733a5