Add no_force to query macro and move some queries over
This commit is contained in:
parent
b440041a19
commit
d060e7df44
@ -538,7 +538,6 @@ pub fn to_dep_node(self, tcx: TyCtxt<'_, '_, '_>, kind: DepKind) -> DepNode {
|
||||
[anon] TraitSelect,
|
||||
|
||||
[] ParamEnv(DefId),
|
||||
[] Environment(DefId),
|
||||
[] DescribeDef(DefId),
|
||||
|
||||
// FIXME(mw): DefSpans are not really inputs since they are derived from
|
||||
@ -661,9 +660,6 @@ pub fn to_dep_node(self, tcx: TyCtxt<'_, '_, '_>, kind: DepKind) -> DepNode {
|
||||
|
||||
[input] Features,
|
||||
|
||||
[] ProgramClausesFor(DefId),
|
||||
[] ProgramClausesForEnv(traits::Environment<'tcx>),
|
||||
[] WasmImportModuleMap(CrateNum),
|
||||
[] ForeignModules(CrateNum),
|
||||
|
||||
[] UpstreamMonomorphizations(CrateNum),
|
||||
|
@ -2,8 +2,9 @@
|
||||
use crate::ty::query::queries;
|
||||
use crate::ty::TyCtxt;
|
||||
use crate::ty;
|
||||
use crate::hir::def_id::CrateNum;
|
||||
use crate::hir::def_id::{DefId, CrateNum};
|
||||
use crate::dep_graph::SerializedDepNodeIndex;
|
||||
use crate::traits;
|
||||
use std::borrow::Cow;
|
||||
|
||||
// Each of these queries corresponds to a function pointer field in the
|
||||
@ -106,4 +107,26 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TypeChecking {
|
||||
query program_clauses_for(_: DefId) -> Clauses<'tcx> {
|
||||
desc { "generating chalk-style clauses" }
|
||||
}
|
||||
|
||||
query program_clauses_for_env(_: traits::Environment<'tcx>) -> Clauses<'tcx> {
|
||||
no_force
|
||||
desc { "generating chalk-style clauses for environment" }
|
||||
}
|
||||
|
||||
// Get the chalk-style environment of the given item.
|
||||
query environment(_: DefId) -> traits::Environment<'tcx> {
|
||||
desc { "return a chalk-style environment" }
|
||||
}
|
||||
}
|
||||
|
||||
Linking {
|
||||
query wasm_import_module_map(_: CrateNum) -> Lrc<FxHashMap<DefId, String>> {
|
||||
desc { "wasm import module map" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -916,33 +916,9 @@ fn describe(tcx: TyCtxt<'_, '_, '_>, def: ty::InstanceDef<'tcx>) -> Cow<'static,
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> QueryDescription<'tcx> for queries::program_clauses_for<'tcx> {
|
||||
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: DefId) -> Cow<'static, str> {
|
||||
"generating chalk-style clauses".into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> QueryDescription<'tcx> for queries::program_clauses_for_env<'tcx> {
|
||||
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: traits::Environment<'tcx>) -> Cow<'static, str> {
|
||||
"generating chalk-style clauses for environment".into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> QueryDescription<'tcx> for queries::environment<'tcx> {
|
||||
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: DefId) -> Cow<'static, str> {
|
||||
"return a chalk-style environment".into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> QueryDescription<'tcx> for queries::wasm_import_module_map<'tcx> {
|
||||
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: CrateNum) -> Cow<'static, str> {
|
||||
"wasm import module map".into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> QueryDescription<'tcx> for queries::dllimport_foreign_items<'tcx> {
|
||||
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: CrateNum) -> Cow<'static, str> {
|
||||
"wasm import module map".into()
|
||||
"dllimport_foreign_items".into()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -683,22 +683,6 @@
|
||||
|
||||
[] fn features_query: features_node(CrateNum) -> Lrc<feature_gate::Features>,
|
||||
},
|
||||
|
||||
TypeChecking {
|
||||
[] fn program_clauses_for: ProgramClausesFor(DefId) -> Clauses<'tcx>,
|
||||
|
||||
[] fn program_clauses_for_env: ProgramClausesForEnv(
|
||||
traits::Environment<'tcx>
|
||||
) -> Clauses<'tcx>,
|
||||
|
||||
// Get the chalk-style environment of the given item.
|
||||
[] fn environment: Environment(DefId) -> traits::Environment<'tcx>,
|
||||
},
|
||||
|
||||
Linking {
|
||||
[] fn wasm_import_module_map: WasmImportModuleMap(CrateNum)
|
||||
-> Lrc<FxHashMap<DefId, String>>,
|
||||
},
|
||||
]}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
@ -1240,11 +1240,7 @@ macro_rules! force {
|
||||
DepKind::TypeOpNormalizeFnSig |
|
||||
DepKind::SubstituteNormalizeAndTestPredicates |
|
||||
DepKind::MethodAutoderefSteps |
|
||||
DepKind::InstanceDefSizeEstimate |
|
||||
DepKind::ProgramClausesForEnv |
|
||||
|
||||
// This one should never occur in this context
|
||||
DepKind::Null => {
|
||||
DepKind::InstanceDefSizeEstimate => {
|
||||
bug!("force_from_dep_node() - Encountered {:?}", dep_node)
|
||||
}
|
||||
|
||||
@ -1311,7 +1307,6 @@ macro_rules! force {
|
||||
DepKind::CheckMatch => { force!(check_match, def_id!()); }
|
||||
|
||||
DepKind::ParamEnv => { force!(param_env, def_id!()); }
|
||||
DepKind::Environment => { force!(environment, def_id!()); }
|
||||
DepKind::DescribeDef => { force!(describe_def, def_id!()); }
|
||||
DepKind::DefSpan => { force!(def_span, def_id!()); }
|
||||
DepKind::LookupStability => { force!(lookup_stability, def_id!()); }
|
||||
@ -1419,8 +1414,6 @@ macro_rules! force {
|
||||
|
||||
DepKind::Features => { force!(features_query, LOCAL_CRATE); }
|
||||
|
||||
DepKind::ProgramClausesFor => { force!(program_clauses_for, def_id!()); }
|
||||
DepKind::WasmImportModuleMap => { force!(wasm_import_module_map, krate!()); }
|
||||
DepKind::ForeignModules => { force!(foreign_modules, krate!()); }
|
||||
|
||||
DepKind::UpstreamMonomorphizations => {
|
||||
|
@ -45,6 +45,9 @@ enum QueryModifier {
|
||||
|
||||
/// Don't hash the result, instead just mark a query red if it runs
|
||||
NoHash,
|
||||
|
||||
/// Don't force the query
|
||||
NoForce,
|
||||
}
|
||||
|
||||
impl Parse for QueryModifier {
|
||||
@ -94,6 +97,8 @@ fn parse(input: ParseStream<'_>) -> Result<Self> {
|
||||
Ok(QueryModifier::FatalCycle)
|
||||
} else if modifier == "no_hash" {
|
||||
Ok(QueryModifier::NoHash)
|
||||
} else if modifier == "no_force" {
|
||||
Ok(QueryModifier::NoForce)
|
||||
} else {
|
||||
Err(Error::new(modifier.span(), "unknown query modifier"))
|
||||
}
|
||||
@ -194,6 +199,9 @@ struct QueryModifiers {
|
||||
|
||||
/// Don't hash the result, instead just mark a query red if it runs
|
||||
no_hash: bool,
|
||||
|
||||
/// Don't force the query
|
||||
no_force: bool,
|
||||
}
|
||||
|
||||
/// Process query modifiers into a struct, erroring on duplicates
|
||||
@ -203,6 +211,7 @@ fn process_modifiers(query: &mut Query) -> QueryModifiers {
|
||||
let mut desc = None;
|
||||
let mut fatal_cycle = false;
|
||||
let mut no_hash = false;
|
||||
let mut no_force = false;
|
||||
for modifier in query.modifiers.0.drain(..) {
|
||||
match modifier {
|
||||
QueryModifier::LoadCached(tcx, id, block) => {
|
||||
@ -235,6 +244,12 @@ fn process_modifiers(query: &mut Query) -> QueryModifiers {
|
||||
}
|
||||
no_hash = true;
|
||||
}
|
||||
QueryModifier::NoForce => {
|
||||
if no_force {
|
||||
panic!("duplicate modifier `no_force` for query `{}`", query.name);
|
||||
}
|
||||
no_force = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
QueryModifiers {
|
||||
@ -243,6 +258,7 @@ fn process_modifiers(query: &mut Query) -> QueryModifiers {
|
||||
desc,
|
||||
fatal_cycle,
|
||||
no_hash,
|
||||
no_force,
|
||||
}
|
||||
}
|
||||
|
||||
@ -329,6 +345,7 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
|
||||
let mut query_description_stream = quote! {};
|
||||
let mut dep_node_def_stream = quote! {};
|
||||
let mut dep_node_force_stream = quote! {};
|
||||
let mut no_force_queries = Vec::new();
|
||||
|
||||
for group in groups.0 {
|
||||
let mut group_stream = quote! {};
|
||||
@ -364,29 +381,46 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
|
||||
[#attribute_stream] fn #name: #name(#arg) #result,
|
||||
});
|
||||
|
||||
add_query_description_impl(&query, modifiers, &mut query_description_stream);
|
||||
|
||||
// Create a dep node for the query
|
||||
dep_node_def_stream.extend(quote! {
|
||||
[] #name(#arg),
|
||||
});
|
||||
|
||||
// Add a match arm to force the query given the dep node
|
||||
dep_node_force_stream.extend(quote! {
|
||||
DepKind::#name => {
|
||||
if let Some(key) = RecoverKey::recover($tcx, $dep_node) {
|
||||
force_ex!($tcx, #name, key);
|
||||
} else {
|
||||
return false;
|
||||
if modifiers.no_force {
|
||||
no_force_queries.push(name.clone());
|
||||
} else {
|
||||
// Add a match arm to force the query given the dep node
|
||||
dep_node_force_stream.extend(quote! {
|
||||
DepKind::#name => {
|
||||
if let Some(key) = RecoverKey::recover($tcx, $dep_node) {
|
||||
force_ex!($tcx, #name, key);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
add_query_description_impl(&query, modifiers, &mut query_description_stream);
|
||||
}
|
||||
let name = &group.name;
|
||||
query_stream.extend(quote! {
|
||||
#name { #group_stream },
|
||||
});
|
||||
}
|
||||
|
||||
// Add an arm for the no force queries to panic when trying to force them
|
||||
for query in no_force_queries {
|
||||
dep_node_force_stream.extend(quote! {
|
||||
DepKind::#query |
|
||||
});
|
||||
}
|
||||
dep_node_force_stream.extend(quote! {
|
||||
DepKind::Null => {
|
||||
bug!("Cannot force dep node: {:?}", $dep_node)
|
||||
}
|
||||
});
|
||||
|
||||
TokenStream::from(quote! {
|
||||
macro_rules! rustc_query_append {
|
||||
([$($macro:tt)*][$($other:tt)*]) => {
|
||||
|
Loading…
Reference in New Issue
Block a user