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