Rename tcx to qcx when it's a QueryContext

This commit is contained in:
Nilstrieb 2022-11-05 20:58:10 +01:00
parent 91971f293c
commit 16558bd267
No known key found for this signature in database
3 changed files with 94 additions and 94 deletions

View File

@ -573,10 +573,10 @@ impl<K: DepKind> DepGraph<K> {
/// a node index can be found for that node. /// a node index can be found for that node.
pub fn try_mark_green<Ctxt: QueryContext<DepKind = K>>( pub fn try_mark_green<Ctxt: QueryContext<DepKind = K>>(
&self, &self,
tcx: Ctxt, qcx: Ctxt,
dep_node: &DepNode<K>, dep_node: &DepNode<K>,
) -> Option<(SerializedDepNodeIndex, DepNodeIndex)> { ) -> Option<(SerializedDepNodeIndex, DepNodeIndex)> {
debug_assert!(!tcx.dep_context().is_eval_always(dep_node.kind)); debug_assert!(!qcx.dep_context().is_eval_always(dep_node.kind));
// Return None if the dep graph is disabled // Return None if the dep graph is disabled
let data = self.data.as_ref()?; let data = self.data.as_ref()?;
@ -592,16 +592,16 @@ impl<K: DepKind> DepGraph<K> {
// in the previous compilation session too, so we can try to // in the previous compilation session too, so we can try to
// mark it as green by recursively marking all of its // mark it as green by recursively marking all of its
// dependencies green. // dependencies green.
self.try_mark_previous_green(tcx, data, prev_index, &dep_node) self.try_mark_previous_green(qcx, data, prev_index, &dep_node)
.map(|dep_node_index| (prev_index, dep_node_index)) .map(|dep_node_index| (prev_index, dep_node_index))
} }
} }
} }
#[instrument(skip(self, tcx, data, parent_dep_node_index), level = "debug")] #[instrument(skip(self, qcx, data, parent_dep_node_index), level = "debug")]
fn try_mark_parent_green<Ctxt: QueryContext<DepKind = K>>( fn try_mark_parent_green<Ctxt: QueryContext<DepKind = K>>(
&self, &self,
tcx: Ctxt, qcx: Ctxt,
data: &DepGraphData<K>, data: &DepGraphData<K>,
parent_dep_node_index: SerializedDepNodeIndex, parent_dep_node_index: SerializedDepNodeIndex,
dep_node: &DepNode<K>, dep_node: &DepNode<K>,
@ -630,14 +630,14 @@ impl<K: DepKind> DepGraph<K> {
// We don't know the state of this dependency. If it isn't // We don't know the state of this dependency. If it isn't
// an eval_always node, let's try to mark it green recursively. // an eval_always node, let's try to mark it green recursively.
if !tcx.dep_context().is_eval_always(dep_dep_node.kind) { if !qcx.dep_context().is_eval_always(dep_dep_node.kind) {
debug!( debug!(
"state of dependency {:?} ({}) is unknown, trying to mark it green", "state of dependency {:?} ({}) is unknown, trying to mark it green",
dep_dep_node, dep_dep_node.hash, dep_dep_node, dep_dep_node.hash,
); );
let node_index = let node_index =
self.try_mark_previous_green(tcx, data, parent_dep_node_index, dep_dep_node); self.try_mark_previous_green(qcx, data, parent_dep_node_index, dep_dep_node);
if node_index.is_some() { if node_index.is_some() {
debug!("managed to MARK dependency {dep_dep_node:?} as green",); debug!("managed to MARK dependency {dep_dep_node:?} as green",);
@ -647,7 +647,7 @@ impl<K: DepKind> DepGraph<K> {
// We failed to mark it green, so we try to force the query. // We failed to mark it green, so we try to force the query.
debug!("trying to force dependency {dep_dep_node:?}"); debug!("trying to force dependency {dep_dep_node:?}");
if !tcx.dep_context().try_force_from_dep_node(*dep_dep_node) { if !qcx.dep_context().try_force_from_dep_node(*dep_dep_node) {
// The DepNode could not be forced. // The DepNode could not be forced.
debug!("dependency {dep_dep_node:?} could not be forced"); debug!("dependency {dep_dep_node:?} could not be forced");
return None; return None;
@ -667,7 +667,7 @@ impl<K: DepKind> DepGraph<K> {
None => {} None => {}
} }
if !tcx.dep_context().sess().has_errors_or_delayed_span_bugs() { if !qcx.dep_context().sess().has_errors_or_delayed_span_bugs() {
panic!("try_mark_previous_green() - Forcing the DepNode should have set its color") panic!("try_mark_previous_green() - Forcing the DepNode should have set its color")
} }
@ -686,10 +686,10 @@ impl<K: DepKind> DepGraph<K> {
} }
/// Try to mark a dep-node which existed in the previous compilation session as green. /// Try to mark a dep-node which existed in the previous compilation session as green.
#[instrument(skip(self, tcx, data, prev_dep_node_index), level = "debug")] #[instrument(skip(self, qcx, data, prev_dep_node_index), level = "debug")]
fn try_mark_previous_green<Ctxt: QueryContext<DepKind = K>>( fn try_mark_previous_green<Ctxt: QueryContext<DepKind = K>>(
&self, &self,
tcx: Ctxt, qcx: Ctxt,
data: &DepGraphData<K>, data: &DepGraphData<K>,
prev_dep_node_index: SerializedDepNodeIndex, prev_dep_node_index: SerializedDepNodeIndex,
dep_node: &DepNode<K>, dep_node: &DepNode<K>,
@ -701,14 +701,14 @@ impl<K: DepKind> DepGraph<K> {
} }
// We never try to mark eval_always nodes as green // We never try to mark eval_always nodes as green
debug_assert!(!tcx.dep_context().is_eval_always(dep_node.kind)); debug_assert!(!qcx.dep_context().is_eval_always(dep_node.kind));
debug_assert_eq!(data.previous.index_to_node(prev_dep_node_index), *dep_node); debug_assert_eq!(data.previous.index_to_node(prev_dep_node_index), *dep_node);
let prev_deps = data.previous.edge_targets_from(prev_dep_node_index); let prev_deps = data.previous.edge_targets_from(prev_dep_node_index);
for &dep_dep_node_index in prev_deps { for &dep_dep_node_index in prev_deps {
self.try_mark_parent_green(tcx, data, dep_dep_node_index, dep_node)? self.try_mark_parent_green(qcx, data, dep_dep_node_index, dep_node)?
} }
// If we got here without hitting a `return` that means that all // If we got here without hitting a `return` that means that all
@ -720,7 +720,7 @@ impl<K: DepKind> DepGraph<K> {
// We allocating an entry for the node in the current dependency graph and // We allocating an entry for the node in the current dependency graph and
// adding all the appropriate edges imported from the previous graph // adding all the appropriate edges imported from the previous graph
let dep_node_index = data.current.promote_node_and_deps_to_current( let dep_node_index = data.current.promote_node_and_deps_to_current(
tcx.dep_context().profiler(), qcx.dep_context().profiler(),
&data.previous, &data.previous,
prev_dep_node_index, prev_dep_node_index,
); );
@ -729,7 +729,7 @@ impl<K: DepKind> DepGraph<K> {
// FIXME: Store the fact that a node has diagnostics in a bit in the dep graph somewhere // FIXME: Store the fact that a node has diagnostics in a bit in the dep graph somewhere
// Maybe store a list on disk and encode this fact in the DepNodeState // Maybe store a list on disk and encode this fact in the DepNodeState
let side_effects = tcx.load_side_effects(prev_dep_node_index); let side_effects = qcx.load_side_effects(prev_dep_node_index);
#[cfg(not(parallel_compiler))] #[cfg(not(parallel_compiler))]
debug_assert!( debug_assert!(
@ -740,7 +740,7 @@ impl<K: DepKind> DepGraph<K> {
); );
if !side_effects.is_empty() { if !side_effects.is_empty() {
self.emit_side_effects(tcx, data, dep_node_index, side_effects); self.emit_side_effects(qcx, data, dep_node_index, side_effects);
} }
// ... and finally storing a "Green" entry in the color map. // ... and finally storing a "Green" entry in the color map.
@ -757,7 +757,7 @@ impl<K: DepKind> DepGraph<K> {
#[inline(never)] #[inline(never)]
fn emit_side_effects<Ctxt: QueryContext<DepKind = K>>( fn emit_side_effects<Ctxt: QueryContext<DepKind = K>>(
&self, &self,
tcx: Ctxt, qcx: Ctxt,
data: &DepGraphData<K>, data: &DepGraphData<K>,
dep_node_index: DepNodeIndex, dep_node_index: DepNodeIndex,
side_effects: QuerySideEffects, side_effects: QuerySideEffects,
@ -769,9 +769,9 @@ impl<K: DepKind> DepGraph<K> {
// must process side effects // must process side effects
// Promote the previous diagnostics to the current session. // Promote the previous diagnostics to the current session.
tcx.store_side_effects(dep_node_index, side_effects.clone()); qcx.store_side_effects(dep_node_index, side_effects.clone());
let handle = tcx.dep_context().sess().diagnostic(); let handle = qcx.dep_context().sess().diagnostic();
for mut diagnostic in side_effects.diagnostics { for mut diagnostic in side_effects.diagnostics {
handle.emit_diagnostic(&mut diagnostic); handle.emit_diagnostic(&mut diagnostic);

View File

@ -597,7 +597,7 @@ pub(crate) fn report_cycle<'a>(
} }
pub fn print_query_stack<CTX: QueryContext>( pub fn print_query_stack<CTX: QueryContext>(
tcx: CTX, qcx: CTX,
mut current_query: Option<QueryJobId>, mut current_query: Option<QueryJobId>,
handler: &Handler, handler: &Handler,
num_frames: Option<usize>, num_frames: Option<usize>,
@ -606,7 +606,7 @@ pub fn print_query_stack<CTX: QueryContext>(
// a panic hook, which means that the global `Handler` may be in a weird // a panic hook, which means that the global `Handler` may be in a weird
// state if it was responsible for triggering the panic. // state if it was responsible for triggering the panic.
let mut i = 0; let mut i = 0;
let query_map = tcx.try_collect_active_jobs(); let query_map = qcx.try_collect_active_jobs();
while let Some(query) = current_query { while let Some(query) = current_query {
if Some(i) == num_frames { if Some(i) == num_frames {

View File

@ -64,7 +64,7 @@ where
pub fn try_collect_active_jobs<CTX: Copy>( pub fn try_collect_active_jobs<CTX: Copy>(
&self, &self,
tcx: CTX, qcx: CTX,
make_query: fn(CTX, K) -> QueryStackFrame, make_query: fn(CTX, K) -> QueryStackFrame,
jobs: &mut QueryMap, jobs: &mut QueryMap,
) -> Option<()> { ) -> Option<()> {
@ -76,7 +76,7 @@ where
for shard in shards.iter() { for shard in shards.iter() {
for (k, v) in shard.iter() { for (k, v) in shard.iter() {
if let QueryResult::Started(ref job) = *v { if let QueryResult::Started(ref job) = *v {
let query = make_query(tcx, k.clone()); let query = make_query(qcx, k.clone());
jobs.insert(job.id, QueryJobInfo { query, job: job.clone() }); jobs.insert(job.id, QueryJobInfo { query, job: job.clone() });
} }
} }
@ -90,7 +90,7 @@ where
// really hurt much.) // really hurt much.)
for (k, v) in self.active.try_lock()?.iter() { for (k, v) in self.active.try_lock()?.iter() {
if let QueryResult::Started(ref job) = *v { if let QueryResult::Started(ref job) = *v {
let query = make_query(tcx, k.clone()); let query = make_query(qcx, k.clone());
jobs.insert(job.id, QueryJobInfo { query, job: job.clone() }); jobs.insert(job.id, QueryJobInfo { query, job: job.clone() });
} }
} }
@ -120,7 +120,7 @@ where
#[cold] #[cold]
#[inline(never)] #[inline(never)]
fn mk_cycle<CTX, V, R>( fn mk_cycle<CTX, V, R>(
tcx: CTX, qcx: CTX,
cycle_error: CycleError, cycle_error: CycleError,
handler: HandleCycleError, handler: HandleCycleError,
cache: &dyn crate::query::QueryStorage<Value = V, Stored = R>, cache: &dyn crate::query::QueryStorage<Value = V, Stored = R>,
@ -130,8 +130,8 @@ where
V: std::fmt::Debug + Value<CTX::DepContext>, V: std::fmt::Debug + Value<CTX::DepContext>,
R: Clone, R: Clone,
{ {
let error = report_cycle(tcx.dep_context().sess(), &cycle_error); let error = report_cycle(qcx.dep_context().sess(), &cycle_error);
let value = handle_cycle_error(*tcx.dep_context(), &cycle_error, error, handler); let value = handle_cycle_error(*qcx.dep_context(), &cycle_error, error, handler);
cache.store_nocache(value) cache.store_nocache(value)
} }
@ -177,7 +177,7 @@ where
/// for some compile-time benchmarks. /// for some compile-time benchmarks.
#[inline(always)] #[inline(always)]
fn try_start<'b, CTX>( fn try_start<'b, CTX>(
tcx: &'b CTX, qcx: &'b CTX,
state: &'b QueryState<K>, state: &'b QueryState<K>,
span: Span, span: Span,
key: K, key: K,
@ -193,8 +193,8 @@ where
match lock.entry(key) { match lock.entry(key) {
Entry::Vacant(entry) => { Entry::Vacant(entry) => {
let id = tcx.next_job_id(); let id = qcx.next_job_id();
let job = tcx.current_query_job(); let job = qcx.current_query_job();
let job = QueryJob::new(id, span, job); let job = QueryJob::new(id, span, job);
let key = entry.key().clone(); let key = entry.key().clone();
@ -213,8 +213,8 @@ where
// If we are single-threaded we know that we have cycle error, // If we are single-threaded we know that we have cycle error,
// so we just return the error. // so we just return the error.
return TryGetJob::Cycle(id.find_cycle_in_stack( return TryGetJob::Cycle(id.find_cycle_in_stack(
tcx.try_collect_active_jobs().unwrap(), qcx.try_collect_active_jobs().unwrap(),
&tcx.current_query_job(), &qcx.current_query_job(),
span, span,
)); ));
} }
@ -223,7 +223,7 @@ where
// For parallel queries, we'll block and wait until the query running // For parallel queries, we'll block and wait until the query running
// in another thread has completed. Record how long we wait in the // in another thread has completed. Record how long we wait in the
// self-profiler. // self-profiler.
let query_blocked_prof_timer = tcx.dep_context().profiler().query_blocked(); let query_blocked_prof_timer = qcx.dep_context().profiler().query_blocked();
// Get the latch out // Get the latch out
let latch = job.latch(); let latch = job.latch();
@ -232,7 +232,7 @@ where
// With parallel queries we might just have to wait on some other // With parallel queries we might just have to wait on some other
// thread. // thread.
let result = latch.wait_on(tcx.current_query_job(), span); let result = latch.wait_on(qcx.current_query_job(), span);
match result { match result {
Ok(()) => TryGetJob::JobCompleted(query_blocked_prof_timer), Ok(()) => TryGetJob::JobCompleted(query_blocked_prof_timer),
@ -357,7 +357,7 @@ where
} }
fn try_execute_query<CTX, C>( fn try_execute_query<CTX, C>(
tcx: CTX, qcx: CTX,
state: &QueryState<C::Key>, state: &QueryState<C::Key>,
cache: &C, cache: &C,
span: Span, span: Span,
@ -371,14 +371,14 @@ where
C::Value: Value<CTX::DepContext>, C::Value: Value<CTX::DepContext>,
CTX: QueryContext, CTX: QueryContext,
{ {
match JobOwner::<'_, C::Key>::try_start(&tcx, state, span, key.clone()) { match JobOwner::<'_, C::Key>::try_start(&qcx, state, span, key.clone()) {
TryGetJob::NotYetStarted(job) => { TryGetJob::NotYetStarted(job) => {
let (result, dep_node_index) = execute_job(tcx, key, dep_node, query, job.id); let (result, dep_node_index) = execute_job(qcx, key, dep_node, query, job.id);
let result = job.complete(cache, result, dep_node_index); let result = job.complete(cache, result, dep_node_index);
(result, Some(dep_node_index)) (result, Some(dep_node_index))
} }
TryGetJob::Cycle(error) => { TryGetJob::Cycle(error) => {
let result = mk_cycle(tcx, error, query.handle_cycle_error, cache); let result = mk_cycle(qcx, error, query.handle_cycle_error, cache);
(result, None) (result, None)
} }
#[cfg(parallel_compiler)] #[cfg(parallel_compiler)]
@ -387,8 +387,8 @@ where
.lookup(&key, |value, index| (value.clone(), index)) .lookup(&key, |value, index| (value.clone(), index))
.unwrap_or_else(|_| panic!("value must be in cache after waiting")); .unwrap_or_else(|_| panic!("value must be in cache after waiting"));
if std::intrinsics::unlikely(tcx.dep_context().profiler().enabled()) { if std::intrinsics::unlikely(qcx.dep_context().profiler().enabled()) {
tcx.dep_context().profiler().query_cache_hit(index.into()); qcx.dep_context().profiler().query_cache_hit(index.into());
} }
query_blocked_prof_timer.finish_with_query_invocation_id(index.into()); query_blocked_prof_timer.finish_with_query_invocation_id(index.into());
@ -398,7 +398,7 @@ where
} }
fn execute_job<CTX, K, V>( fn execute_job<CTX, K, V>(
tcx: CTX, qcx: CTX,
key: K, key: K,
mut dep_node_opt: Option<DepNode<CTX::DepKind>>, mut dep_node_opt: Option<DepNode<CTX::DepKind>>,
query: &QueryVTable<CTX, K, V>, query: &QueryVTable<CTX, K, V>,
@ -409,13 +409,13 @@ where
V: Debug, V: Debug,
CTX: QueryContext, CTX: QueryContext,
{ {
let dep_graph = tcx.dep_context().dep_graph(); let dep_graph = qcx.dep_context().dep_graph();
// Fast path for when incr. comp. is off. // Fast path for when incr. comp. is off.
if !dep_graph.is_fully_enabled() { if !dep_graph.is_fully_enabled() {
let prof_timer = tcx.dep_context().profiler().query_provider(); let prof_timer = qcx.dep_context().profiler().query_provider();
let result = tcx.start_query(job_id, query.depth_limit, None, || { let result = qcx.start_query(job_id, query.depth_limit, None, || {
query.compute(*tcx.dep_context(), key) query.compute(*qcx.dep_context(), key)
}); });
let dep_node_index = dep_graph.next_virtual_depnode_index(); let dep_node_index = dep_graph.next_virtual_depnode_index();
prof_timer.finish_with_query_invocation_id(dep_node_index.into()); prof_timer.finish_with_query_invocation_id(dep_node_index.into());
@ -425,33 +425,33 @@ where
if !query.anon && !query.eval_always { if !query.anon && !query.eval_always {
// `to_dep_node` is expensive for some `DepKind`s. // `to_dep_node` is expensive for some `DepKind`s.
let dep_node = let dep_node =
dep_node_opt.get_or_insert_with(|| query.to_dep_node(*tcx.dep_context(), &key)); dep_node_opt.get_or_insert_with(|| query.to_dep_node(*qcx.dep_context(), &key));
// The diagnostics for this query will be promoted to the current session during // The diagnostics for this query will be promoted to the current session during
// `try_mark_green()`, so we can ignore them here. // `try_mark_green()`, so we can ignore them here.
if let Some(ret) = tcx.start_query(job_id, false, None, || { if let Some(ret) = qcx.start_query(job_id, false, None, || {
try_load_from_disk_and_cache_in_memory(tcx, &key, &dep_node, query) try_load_from_disk_and_cache_in_memory(qcx, &key, &dep_node, query)
}) { }) {
return ret; return ret;
} }
} }
let prof_timer = tcx.dep_context().profiler().query_provider(); let prof_timer = qcx.dep_context().profiler().query_provider();
let diagnostics = Lock::new(ThinVec::new()); let diagnostics = Lock::new(ThinVec::new());
let (result, dep_node_index) = let (result, dep_node_index) =
tcx.start_query(job_id, query.depth_limit, Some(&diagnostics), || { qcx.start_query(job_id, query.depth_limit, Some(&diagnostics), || {
if query.anon { if query.anon {
return dep_graph.with_anon_task(*tcx.dep_context(), query.dep_kind, || { return dep_graph.with_anon_task(*qcx.dep_context(), query.dep_kind, || {
query.compute(*tcx.dep_context(), key) query.compute(*qcx.dep_context(), key)
}); });
} }
// `to_dep_node` is expensive for some `DepKind`s. // `to_dep_node` is expensive for some `DepKind`s.
let dep_node = let dep_node =
dep_node_opt.unwrap_or_else(|| query.to_dep_node(*tcx.dep_context(), &key)); dep_node_opt.unwrap_or_else(|| query.to_dep_node(*qcx.dep_context(), &key));
dep_graph.with_task(dep_node, *tcx.dep_context(), key, query.compute, query.hash_result) dep_graph.with_task(dep_node, *qcx.dep_context(), key, query.compute, query.hash_result)
}); });
prof_timer.finish_with_query_invocation_id(dep_node_index.into()); prof_timer.finish_with_query_invocation_id(dep_node_index.into());
@ -461,9 +461,9 @@ where
if std::intrinsics::unlikely(!side_effects.is_empty()) { if std::intrinsics::unlikely(!side_effects.is_empty()) {
if query.anon { if query.anon {
tcx.store_side_effects_for_anon_node(dep_node_index, side_effects); qcx.store_side_effects_for_anon_node(dep_node_index, side_effects);
} else { } else {
tcx.store_side_effects(dep_node_index, side_effects); qcx.store_side_effects(dep_node_index, side_effects);
} }
} }
@ -471,7 +471,7 @@ where
} }
fn try_load_from_disk_and_cache_in_memory<CTX, K, V>( fn try_load_from_disk_and_cache_in_memory<CTX, K, V>(
tcx: CTX, qcx: CTX,
key: &K, key: &K,
dep_node: &DepNode<CTX::DepKind>, dep_node: &DepNode<CTX::DepKind>,
query: &QueryVTable<CTX, K, V>, query: &QueryVTable<CTX, K, V>,
@ -484,32 +484,32 @@ where
// Note this function can be called concurrently from the same query // Note this function can be called concurrently from the same query
// We must ensure that this is handled correctly. // We must ensure that this is handled correctly.
let dep_graph = tcx.dep_context().dep_graph(); let dep_graph = qcx.dep_context().dep_graph();
let (prev_dep_node_index, dep_node_index) = dep_graph.try_mark_green(tcx, &dep_node)?; let (prev_dep_node_index, dep_node_index) = dep_graph.try_mark_green(qcx, &dep_node)?;
debug_assert!(dep_graph.is_green(dep_node)); debug_assert!(dep_graph.is_green(dep_node));
// First we try to load the result from the on-disk cache. // First we try to load the result from the on-disk cache.
// Some things are never cached on disk. // Some things are never cached on disk.
if let Some(try_load_from_disk) = query.try_load_from_disk { if let Some(try_load_from_disk) = query.try_load_from_disk {
let prof_timer = tcx.dep_context().profiler().incr_cache_loading(); let prof_timer = qcx.dep_context().profiler().incr_cache_loading();
// The call to `with_query_deserialization` enforces that no new `DepNodes` // The call to `with_query_deserialization` enforces that no new `DepNodes`
// are created during deserialization. See the docs of that method for more // are created during deserialization. See the docs of that method for more
// details. // details.
let result = let result =
dep_graph.with_query_deserialization(|| try_load_from_disk(tcx, prev_dep_node_index)); dep_graph.with_query_deserialization(|| try_load_from_disk(qcx, prev_dep_node_index));
prof_timer.finish_with_query_invocation_id(dep_node_index.into()); prof_timer.finish_with_query_invocation_id(dep_node_index.into());
if let Some(result) = result { if let Some(result) = result {
if std::intrinsics::unlikely( if std::intrinsics::unlikely(
tcx.dep_context().sess().opts.unstable_opts.query_dep_graph, qcx.dep_context().sess().opts.unstable_opts.query_dep_graph,
) { ) {
dep_graph.mark_debug_loaded_from_disk(*dep_node) dep_graph.mark_debug_loaded_from_disk(*dep_node)
} }
let prev_fingerprint = tcx let prev_fingerprint = qcx
.dep_context() .dep_context()
.dep_graph() .dep_graph()
.prev_fingerprint_of(dep_node) .prev_fingerprint_of(dep_node)
@ -523,9 +523,9 @@ where
// give us some coverage of potential bugs though. // give us some coverage of potential bugs though.
let try_verify = prev_fingerprint.as_value().1 % 32 == 0; let try_verify = prev_fingerprint.as_value().1 % 32 == 0;
if std::intrinsics::unlikely( if std::intrinsics::unlikely(
try_verify || tcx.dep_context().sess().opts.unstable_opts.incremental_verify_ich, try_verify || qcx.dep_context().sess().opts.unstable_opts.incremental_verify_ich,
) { ) {
incremental_verify_ich(*tcx.dep_context(), &result, dep_node, query); incremental_verify_ich(*qcx.dep_context(), &result, dep_node, query);
} }
return Some((result, dep_node_index)); return Some((result, dep_node_index));
@ -534,7 +534,7 @@ where
// We always expect to find a cached result for things that // We always expect to find a cached result for things that
// can be forced from `DepNode`. // can be forced from `DepNode`.
debug_assert!( debug_assert!(
!tcx.dep_context().fingerprint_style(dep_node.kind).reconstructible(), !qcx.dep_context().fingerprint_style(dep_node.kind).reconstructible(),
"missing on-disk cache entry for {:?}", "missing on-disk cache entry for {:?}",
dep_node dep_node
); );
@ -542,10 +542,10 @@ where
// We could not load a result from the on-disk cache, so // We could not load a result from the on-disk cache, so
// recompute. // recompute.
let prof_timer = tcx.dep_context().profiler().query_provider(); let prof_timer = qcx.dep_context().profiler().query_provider();
// The dep-graph for this computation is already in-place. // The dep-graph for this computation is already in-place.
let result = dep_graph.with_ignore(|| query.compute(*tcx.dep_context(), key.clone())); let result = dep_graph.with_ignore(|| query.compute(*qcx.dep_context(), key.clone()));
prof_timer.finish_with_query_invocation_id(dep_node_index.into()); prof_timer.finish_with_query_invocation_id(dep_node_index.into());
@ -558,14 +558,14 @@ where
// //
// See issue #82920 for an example of a miscompilation that would get turned into // See issue #82920 for an example of a miscompilation that would get turned into
// an ICE by this check // an ICE by this check
incremental_verify_ich(*tcx.dep_context(), &result, dep_node, query); incremental_verify_ich(*qcx.dep_context(), &result, dep_node, query);
Some((result, dep_node_index)) Some((result, dep_node_index))
} }
#[instrument(skip(tcx, result, query), level = "debug")] #[instrument(skip(qcx, result, query), level = "debug")]
fn incremental_verify_ich<CTX, K, V: Debug>( fn incremental_verify_ich<CTX, K, V: Debug>(
tcx: CTX::DepContext, qcx: CTX::DepContext,
result: &V, result: &V,
dep_node: &DepNode<CTX::DepKind>, dep_node: &DepNode<CTX::DepKind>,
query: &QueryVTable<CTX, K, V>, query: &QueryVTable<CTX, K, V>,
@ -573,20 +573,20 @@ fn incremental_verify_ich<CTX, K, V: Debug>(
CTX: QueryContext, CTX: QueryContext,
{ {
assert!( assert!(
tcx.dep_graph().is_green(dep_node), qcx.dep_graph().is_green(dep_node),
"fingerprint for green query instance not loaded from cache: {:?}", "fingerprint for green query instance not loaded from cache: {:?}",
dep_node, dep_node,
); );
let new_hash = query.hash_result.map_or(Fingerprint::ZERO, |f| { let new_hash = query.hash_result.map_or(Fingerprint::ZERO, |f| {
tcx.with_stable_hashing_context(|mut hcx| f(&mut hcx, result)) qcx.with_stable_hashing_context(|mut hcx| f(&mut hcx, result))
}); });
let old_hash = tcx.dep_graph().prev_fingerprint_of(dep_node); let old_hash = qcx.dep_graph().prev_fingerprint_of(dep_node);
if Some(new_hash) != old_hash { if Some(new_hash) != old_hash {
incremental_verify_ich_failed( incremental_verify_ich_failed(
tcx.sess(), qcx.sess(),
DebugArg::from(&dep_node), DebugArg::from(&dep_node),
DebugArg::from(&result), DebugArg::from(&result),
); );
@ -677,7 +677,7 @@ fn incremental_verify_ich_failed(sess: &Session, dep_node: DebugArg<'_>, result:
/// Note: The optimization is only available during incr. comp. /// Note: The optimization is only available during incr. comp.
#[inline(never)] #[inline(never)]
fn ensure_must_run<CTX, K, V>( fn ensure_must_run<CTX, K, V>(
tcx: CTX, qcx: CTX,
key: &K, key: &K,
query: &QueryVTable<CTX, K, V>, query: &QueryVTable<CTX, K, V>,
) -> (bool, Option<DepNode<CTX::DepKind>>) ) -> (bool, Option<DepNode<CTX::DepKind>>)
@ -692,10 +692,10 @@ where
// Ensuring an anonymous query makes no sense // Ensuring an anonymous query makes no sense
assert!(!query.anon); assert!(!query.anon);
let dep_node = query.to_dep_node(*tcx.dep_context(), key); let dep_node = query.to_dep_node(*qcx.dep_context(), key);
let dep_graph = tcx.dep_context().dep_graph(); let dep_graph = qcx.dep_context().dep_graph();
match dep_graph.try_mark_green(tcx, &dep_node) { match dep_graph.try_mark_green(qcx, &dep_node) {
None => { None => {
// A None return from `try_mark_green` means that this is either // A None return from `try_mark_green` means that this is either
// a new dep node or that the dep node has already been marked red. // a new dep node or that the dep node has already been marked red.
@ -707,7 +707,7 @@ where
} }
Some((_, dep_node_index)) => { Some((_, dep_node_index)) => {
dep_graph.read_index(dep_node_index); dep_graph.read_index(dep_node_index);
tcx.dep_context().profiler().query_cache_hit(dep_node_index.into()); qcx.dep_context().profiler().query_cache_hit(dep_node_index.into());
(false, None) (false, None)
} }
} }
@ -719,16 +719,16 @@ pub enum QueryMode {
Ensure, Ensure,
} }
pub fn get_query<Q, CTX>(tcx: CTX, span: Span, key: Q::Key, mode: QueryMode) -> Option<Q::Stored> pub fn get_query<Q, CTX>(qcx: CTX, span: Span, key: Q::Key, mode: QueryMode) -> Option<Q::Stored>
where where
Q: QueryConfig<CTX>, Q: QueryConfig<CTX>,
Q::Key: DepNodeParams<CTX::DepContext>, Q::Key: DepNodeParams<CTX::DepContext>,
Q::Value: Value<CTX::DepContext>, Q::Value: Value<CTX::DepContext>,
CTX: QueryContext, CTX: QueryContext,
{ {
let query = Q::make_vtable(tcx, &key); let query = Q::make_vtable(qcx, &key);
let dep_node = if let QueryMode::Ensure = mode { let dep_node = if let QueryMode::Ensure = mode {
let (must_run, dep_node) = ensure_must_run(tcx, &key, &query); let (must_run, dep_node) = ensure_must_run(qcx, &key, &query);
if !must_run { if !must_run {
return None; return None;
} }
@ -738,21 +738,21 @@ where
}; };
let (result, dep_node_index) = try_execute_query( let (result, dep_node_index) = try_execute_query(
tcx, qcx,
Q::query_state(tcx), Q::query_state(qcx),
Q::query_cache(tcx), Q::query_cache(qcx),
span, span,
key, key,
dep_node, dep_node,
&query, &query,
); );
if let Some(dep_node_index) = dep_node_index { if let Some(dep_node_index) = dep_node_index {
tcx.dep_context().dep_graph().read_index(dep_node_index) qcx.dep_context().dep_graph().read_index(dep_node_index)
} }
Some(result) Some(result)
} }
pub fn force_query<Q, CTX>(tcx: CTX, key: Q::Key, dep_node: DepNode<CTX::DepKind>) pub fn force_query<Q, CTX>(qcx: CTX, key: Q::Key, dep_node: DepNode<CTX::DepKind>)
where where
Q: QueryConfig<CTX>, Q: QueryConfig<CTX>,
Q::Key: DepNodeParams<CTX::DepContext>, Q::Key: DepNodeParams<CTX::DepContext>,
@ -761,10 +761,10 @@ where
{ {
// We may be concurrently trying both execute and force a query. // We may be concurrently trying both execute and force a query.
// Ensure that only one of them runs the query. // Ensure that only one of them runs the query.
let cache = Q::query_cache(tcx); let cache = Q::query_cache(qcx);
let cached = cache.lookup(&key, |_, index| { let cached = cache.lookup(&key, |_, index| {
if std::intrinsics::unlikely(tcx.dep_context().profiler().enabled()) { if std::intrinsics::unlikely(qcx.dep_context().profiler().enabled()) {
tcx.dep_context().profiler().query_cache_hit(index.into()); qcx.dep_context().profiler().query_cache_hit(index.into());
} }
}); });
@ -773,9 +773,9 @@ where
Err(()) => {} Err(()) => {}
} }
let query = Q::make_vtable(tcx, &key); let query = Q::make_vtable(qcx, &key);
let state = Q::query_state(tcx); let state = Q::query_state(qcx);
debug_assert!(!query.anon); debug_assert!(!query.anon);
try_execute_query(tcx, state, cache, DUMMY_SP, key, Some(dep_node), &query); try_execute_query(qcx, state, cache, DUMMY_SP, key, Some(dep_node), &query);
} }