Some cleanup

This commit is contained in:
Aaron Hill 2021-12-14 11:13:17 -05:00
parent 49560e9c49
commit ab168e69ac
No known key found for this signature in database
GPG Key ID: B4087E510E98B164
3 changed files with 6 additions and 17 deletions

View File

@ -83,17 +83,12 @@ fn start_query<R>(
&self, &self,
token: QueryJobId<Self::DepKind>, token: QueryJobId<Self::DepKind>,
diagnostics: Option<&Lock<ThinVec<Diagnostic>>>, diagnostics: Option<&Lock<ThinVec<Diagnostic>>>,
read_allowed: bool,
compute: impl FnOnce() -> R, compute: impl FnOnce() -> R,
) -> R { ) -> R {
// The `TyCtxt` stored in TLS has the same global interner lifetime // The `TyCtxt` stored in TLS has the same global interner lifetime
// as `self`, so we use `with_related_context` to relate the 'tcx lifetimes // as `self`, so we use `with_related_context` to relate the 'tcx lifetimes
// when accessing the `ImplicitCtxt`. // when accessing the `ImplicitCtxt`.
tls::with_related_context(**self, move |current_icx| { tls::with_related_context(**self, move |current_icx| {
let mut old_read_allowed = false;
if let Some(task_deps) = current_icx.task_deps {
old_read_allowed = std::mem::replace(&mut task_deps.lock().read_allowed, read_allowed);
}
// Update the `ImplicitCtxt` to point to our new query job. // Update the `ImplicitCtxt` to point to our new query job.
let new_icx = ImplicitCtxt { let new_icx = ImplicitCtxt {
tcx: **self, tcx: **self,
@ -104,14 +99,9 @@ fn start_query<R>(
}; };
// Use the `ImplicitCtxt` while we execute the query. // Use the `ImplicitCtxt` while we execute the query.
let res = tls::enter_context(&new_icx, |_| { tls::enter_context(&new_icx, |_| {
rustc_data_structures::stack::ensure_sufficient_stack(compute) rustc_data_structures::stack::ensure_sufficient_stack(compute)
}); })
if let Some(task_deps) = new_icx.task_deps {
task_deps.lock().read_allowed = old_read_allowed;
}
res
}) })
} }
} }

View File

@ -142,7 +142,6 @@ fn start_query<R>(
&self, &self,
token: QueryJobId<Self::DepKind>, token: QueryJobId<Self::DepKind>,
diagnostics: Option<&Lock<ThinVec<Diagnostic>>>, diagnostics: Option<&Lock<ThinVec<Diagnostic>>>,
read_allowed: bool,
compute: impl FnOnce() -> R, compute: impl FnOnce() -> R,
) -> R; ) -> R;
} }

View File

@ -2,6 +2,7 @@
//! generate the actual methods on tcx which find and execute the provider, //! generate the actual methods on tcx which find and execute the provider,
//! manage the caches, and so forth. //! manage the caches, and so forth.
use crate::dep_graph::DepKind;
use crate::dep_graph::{DepContext, DepNode, DepNodeIndex, DepNodeParams, TaskDeps}; use crate::dep_graph::{DepContext, DepNode, DepNodeIndex, DepNodeParams, TaskDeps};
use crate::query::caches::QueryCache; use crate::query::caches::QueryCache;
use crate::query::config::{QueryDescription, QueryVtable}; use crate::query::config::{QueryDescription, QueryVtable};
@ -9,7 +10,6 @@
report_cycle, QueryInfo, QueryJob, QueryJobId, QueryJobInfo, QueryShardJobId, report_cycle, QueryInfo, QueryJob, QueryJobId, QueryJobInfo, QueryShardJobId,
}; };
use crate::query::{QueryContext, QueryMap, QuerySideEffects, QueryStackFrame}; use crate::query::{QueryContext, QueryMap, QuerySideEffects, QueryStackFrame};
use crate::dep_graph::DepKind;
use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::{FxHashMap, FxHasher}; use rustc_data_structures::fx::{FxHashMap, FxHasher};
#[cfg(parallel_compiler)] #[cfg(parallel_compiler)]
@ -440,7 +440,7 @@ fn execute_job<CTX, K, V>(
// 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 = tcx.dep_context().profiler().query_provider();
let result = tcx.start_query(job_id, None, true, || query.compute(*tcx.dep_context(), key)); let result = tcx.start_query(job_id, None, || query.compute(*tcx.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());
return (result, dep_node_index); return (result, dep_node_index);
@ -453,7 +453,7 @@ fn execute_job<CTX, K, V>(
// 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, None, false, || { if let Some(ret) = tcx.start_query(job_id, None, || {
try_load_from_disk_and_cache_in_memory(tcx, &key, &dep_node, query) try_load_from_disk_and_cache_in_memory(tcx, &key, &dep_node, query)
}) { }) {
return ret; return ret;
@ -463,7 +463,7 @@ fn execute_job<CTX, K, V>(
let prof_timer = tcx.dep_context().profiler().query_provider(); let prof_timer = tcx.dep_context().profiler().query_provider();
let diagnostics = Lock::new(ThinVec::new()); let diagnostics = Lock::new(ThinVec::new());
let (result, dep_node_index) = tcx.start_query(job_id, Some(&diagnostics), true, || { let (result, dep_node_index) = tcx.start_query(job_id, 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(*tcx.dep_context(), query.dep_kind, || {
query.compute(*tcx.dep_context(), key) query.compute(*tcx.dep_context(), key)