Specialize query execution for incremental and non-incremental
This commit is contained in:
parent
eda41addfc
commit
882a9684f9
4 changed files with 76 additions and 17 deletions
|
@ -691,6 +691,8 @@ pub fn create_global_ctxt<'tcx>(
|
||||||
callback(sess, &mut local_providers, &mut extern_providers);
|
callback(sess, &mut local_providers, &mut extern_providers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let incremental = dep_graph.is_fully_enabled();
|
||||||
|
|
||||||
sess.time("setup_global_ctxt", || {
|
sess.time("setup_global_ctxt", || {
|
||||||
gcx_cell.get_or_init(move || {
|
gcx_cell.get_or_init(move || {
|
||||||
TyCtxt::create_global_ctxt(
|
TyCtxt::create_global_ctxt(
|
||||||
|
@ -705,6 +707,7 @@ pub fn create_global_ctxt<'tcx>(
|
||||||
local_providers,
|
local_providers,
|
||||||
extern_providers,
|
extern_providers,
|
||||||
query_result_on_disk_cache,
|
query_result_on_disk_cache,
|
||||||
|
incremental,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
@ -34,7 +34,8 @@ use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_query_system::dep_graph::SerializedDepNodeIndex;
|
use rustc_query_system::dep_graph::SerializedDepNodeIndex;
|
||||||
use rustc_query_system::ich::StableHashingContext;
|
use rustc_query_system::ich::StableHashingContext;
|
||||||
use rustc_query_system::query::{
|
use rustc_query_system::query::{
|
||||||
get_query, HashResult, QueryCache, QueryConfig, QueryInfo, QueryMap, QueryMode, QueryState,
|
get_query_incr, get_query_non_incr, HashResult, QueryCache, QueryConfig, QueryInfo, QueryMap,
|
||||||
|
QueryMode, QueryState,
|
||||||
};
|
};
|
||||||
use rustc_query_system::HandleCycleError;
|
use rustc_query_system::HandleCycleError;
|
||||||
use rustc_query_system::Value;
|
use rustc_query_system::Value;
|
||||||
|
@ -203,6 +204,7 @@ pub fn query_system<'tcx>(
|
||||||
local_providers: Providers,
|
local_providers: Providers,
|
||||||
extern_providers: ExternProviders,
|
extern_providers: ExternProviders,
|
||||||
on_disk_cache: Option<OnDiskCache<'tcx>>,
|
on_disk_cache: Option<OnDiskCache<'tcx>>,
|
||||||
|
incremental: bool,
|
||||||
) -> QuerySystem<'tcx> {
|
) -> QuerySystem<'tcx> {
|
||||||
QuerySystem {
|
QuerySystem {
|
||||||
states: Default::default(),
|
states: Default::default(),
|
||||||
|
@ -211,7 +213,7 @@ pub fn query_system<'tcx>(
|
||||||
dynamic_queries: dynamic_queries(),
|
dynamic_queries: dynamic_queries(),
|
||||||
on_disk_cache,
|
on_disk_cache,
|
||||||
fns: QuerySystemFns {
|
fns: QuerySystemFns {
|
||||||
engine: engine(),
|
engine: engine(incremental),
|
||||||
local_providers,
|
local_providers,
|
||||||
extern_providers,
|
extern_providers,
|
||||||
query_structs: make_dep_kind_array!(query_structs).to_vec(),
|
query_structs: make_dep_kind_array!(query_structs).to_vec(),
|
||||||
|
|
|
@ -494,7 +494,7 @@ macro_rules! define_queries {
|
||||||
(
|
(
|
||||||
$($(#[$attr:meta])*
|
$($(#[$attr:meta])*
|
||||||
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => {
|
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => {
|
||||||
mod get_query {
|
mod get_query_incr {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
$(
|
$(
|
||||||
|
@ -506,7 +506,7 @@ macro_rules! define_queries {
|
||||||
key: query_keys::$name<'tcx>,
|
key: query_keys::$name<'tcx>,
|
||||||
mode: QueryMode,
|
mode: QueryMode,
|
||||||
) -> Option<Erase<query_values::$name<'tcx>>> {
|
) -> Option<Erase<query_values::$name<'tcx>>> {
|
||||||
get_query(
|
get_query_incr(
|
||||||
queries::$name::config(tcx),
|
queries::$name::config(tcx),
|
||||||
QueryCtxt::new(tcx),
|
QueryCtxt::new(tcx),
|
||||||
span,
|
span,
|
||||||
|
@ -517,9 +517,37 @@ macro_rules! define_queries {
|
||||||
)*
|
)*
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn engine() -> QueryEngine {
|
mod get_query_non_incr {
|
||||||
QueryEngine {
|
use super::*;
|
||||||
$($name: get_query::$name,)*
|
|
||||||
|
$(
|
||||||
|
#[inline(always)]
|
||||||
|
#[tracing::instrument(level = "trace", skip(tcx))]
|
||||||
|
pub(super) fn $name<'tcx>(
|
||||||
|
tcx: TyCtxt<'tcx>,
|
||||||
|
span: Span,
|
||||||
|
key: query_keys::$name<'tcx>,
|
||||||
|
__mode: QueryMode,
|
||||||
|
) -> Option<Erase<query_values::$name<'tcx>>> {
|
||||||
|
Some(get_query_non_incr(
|
||||||
|
queries::$name::config(tcx),
|
||||||
|
QueryCtxt::new(tcx),
|
||||||
|
span,
|
||||||
|
key,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn engine(incremental: bool) -> QueryEngine {
|
||||||
|
if incremental {
|
||||||
|
QueryEngine {
|
||||||
|
$($name: get_query_incr::$name,)*
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
QueryEngine {
|
||||||
|
$($name: get_query_non_incr::$name,)*
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -312,7 +312,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
fn try_execute_query<Q, Qcx>(
|
fn try_execute_query<Q, Qcx, const INCR: bool>(
|
||||||
query: Q,
|
query: Q,
|
||||||
qcx: Qcx,
|
qcx: Qcx,
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -355,7 +355,7 @@ where
|
||||||
// Drop the lock before we start executing the query
|
// Drop the lock before we start executing the query
|
||||||
drop(state_lock);
|
drop(state_lock);
|
||||||
|
|
||||||
execute_job(query, qcx, state, key, id, dep_node)
|
execute_job::<_, _, INCR>(query, qcx, state, key, id, dep_node)
|
||||||
}
|
}
|
||||||
Entry::Occupied(mut entry) => {
|
Entry::Occupied(mut entry) => {
|
||||||
match entry.get_mut() {
|
match entry.get_mut() {
|
||||||
|
@ -383,7 +383,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn execute_job<Q, Qcx>(
|
fn execute_job<Q, Qcx, const INCR: bool>(
|
||||||
query: Q,
|
query: Q,
|
||||||
qcx: Qcx,
|
qcx: Qcx,
|
||||||
state: &QueryState<Q::Key, Qcx::DepKind>,
|
state: &QueryState<Q::Key, Qcx::DepKind>,
|
||||||
|
@ -398,9 +398,19 @@ where
|
||||||
// Use `JobOwner` so the query will be poisoned if executing it panics.
|
// Use `JobOwner` so the query will be poisoned if executing it panics.
|
||||||
let job_owner = JobOwner { state, key };
|
let job_owner = JobOwner { state, key };
|
||||||
|
|
||||||
let (result, dep_node_index) = match qcx.dep_context().dep_graph().data() {
|
debug_assert_eq!(qcx.dep_context().dep_graph().is_fully_enabled(), INCR);
|
||||||
None => execute_job_non_incr(query, qcx, key, id),
|
|
||||||
Some(data) => execute_job_incr(query, qcx, data, key, dep_node, id),
|
let (result, dep_node_index) = if INCR {
|
||||||
|
execute_job_incr(
|
||||||
|
query,
|
||||||
|
qcx,
|
||||||
|
qcx.dep_context().dep_graph().data().unwrap(),
|
||||||
|
key,
|
||||||
|
dep_node,
|
||||||
|
id,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
execute_job_non_incr(query, qcx, key, id)
|
||||||
};
|
};
|
||||||
|
|
||||||
let cache = query.query_cache(qcx);
|
let cache = query.query_cache(qcx);
|
||||||
|
@ -784,7 +794,18 @@ pub enum QueryMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn get_query<Q, Qcx>(
|
pub fn get_query_non_incr<Q, Qcx>(query: Q, qcx: Qcx, span: Span, key: Q::Key) -> Q::Value
|
||||||
|
where
|
||||||
|
Q: QueryConfig<Qcx>,
|
||||||
|
Qcx: QueryContext,
|
||||||
|
{
|
||||||
|
debug_assert!(!qcx.dep_context().dep_graph().is_fully_enabled());
|
||||||
|
|
||||||
|
ensure_sufficient_stack(|| try_execute_query::<Q, Qcx, false>(query, qcx, span, key, None).0)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn get_query_incr<Q, Qcx>(
|
||||||
query: Q,
|
query: Q,
|
||||||
qcx: Qcx,
|
qcx: Qcx,
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -795,6 +816,8 @@ where
|
||||||
Q: QueryConfig<Qcx>,
|
Q: QueryConfig<Qcx>,
|
||||||
Qcx: QueryContext,
|
Qcx: QueryContext,
|
||||||
{
|
{
|
||||||
|
debug_assert!(qcx.dep_context().dep_graph().is_fully_enabled());
|
||||||
|
|
||||||
let dep_node = if let QueryMode::Ensure { check_cache } = mode {
|
let dep_node = if let QueryMode::Ensure { check_cache } = mode {
|
||||||
let (must_run, dep_node) = ensure_must_run(query, qcx, &key, check_cache);
|
let (must_run, dep_node) = ensure_must_run(query, qcx, &key, check_cache);
|
||||||
if !must_run {
|
if !must_run {
|
||||||
|
@ -805,8 +828,9 @@ where
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let (result, dep_node_index) =
|
let (result, dep_node_index) = ensure_sufficient_stack(|| {
|
||||||
ensure_sufficient_stack(|| try_execute_query(query, qcx, span, key, dep_node));
|
try_execute_query::<_, _, true>(query, qcx, span, key, dep_node)
|
||||||
|
});
|
||||||
if let Some(dep_node_index) = dep_node_index {
|
if let Some(dep_node_index) = dep_node_index {
|
||||||
qcx.dep_context().dep_graph().read_index(dep_node_index)
|
qcx.dep_context().dep_graph().read_index(dep_node_index)
|
||||||
}
|
}
|
||||||
|
@ -831,5 +855,7 @@ pub fn force_query<Q, Qcx>(
|
||||||
|
|
||||||
debug_assert!(!query.anon());
|
debug_assert!(!query.anon());
|
||||||
|
|
||||||
ensure_sufficient_stack(|| try_execute_query(query, qcx, DUMMY_SP, key, Some(dep_node)));
|
ensure_sufficient_stack(|| {
|
||||||
|
try_execute_query::<_, _, true>(query, qcx, DUMMY_SP, key, Some(dep_node))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue