Add anon to query macro and move a query over

This commit is contained in:
John Kåre Alsaker 2019-03-20 17:13:44 +01:00
parent d060e7df44
commit 52374a6462
6 changed files with 44 additions and 27 deletions

View file

@ -614,14 +614,6 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
[input] UsedCrateSource(CrateNum),
[input] PostorderCnums,
// These queries are not expected to have inputs -- as a result, they
// are not good candidates for "replay" because they are essentially
// pure functions of their input (and hence the expectation is that
// no caller would be green **apart** from just these
// queries). Making them anonymous avoids hashing the result, which
// may save a bit of time.
[anon] EraseRegionsTy { ty: Ty<'tcx> },
[input] Freevars(DefId),
[input] MaybeUnusedTraitImport(DefId),
[input] MaybeUnusedExternCrates,

View file

@ -1,7 +1,6 @@
use crate::ty::query::QueryDescription;
use crate::ty::query::queries;
use crate::ty::TyCtxt;
use crate::ty;
use crate::ty::{self, Ty, TyCtxt};
use crate::hir::def_id::{DefId, CrateNum};
use crate::dep_graph::SerializedDepNodeIndex;
use crate::traits;
@ -109,6 +108,21 @@ rustc_queries! {
}
TypeChecking {
// Erases regions from `ty` to yield a new type.
// Normally you would just use `tcx.erase_regions(&value)`,
// however, which uses this query as a kind of cache.
query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
// This query is not expected to have input -- as a result, it
// is not a good candidates for "replay" because it is essentially a
// pure function of its input (and hence the expectation is that
// no caller would be green **apart** from just these
// queries). Making it anonymous avoids hashing the result, which
// may save a bit of time.
anon
no_force
desc { "erasing regions from `{:?}`", ty }
}
query program_clauses_for(_: DefId) -> Clauses<'tcx> {
desc { "generating chalk-style clauses" }
}

View file

@ -305,12 +305,6 @@ impl<'tcx> QueryDescription<'tcx> for queries::super_predicates_of<'tcx> {
}
}
impl<'tcx> QueryDescription<'tcx> for queries::erase_regions_ty<'tcx> {
fn describe(_tcx: TyCtxt<'_, '_, '_>, ty: Ty<'tcx>) -> Cow<'static, str> {
format!("erasing regions from `{:?}`", ty).into()
}
}
impl<'tcx> QueryDescription<'tcx> for queries::type_param_predicates<'tcx> {
fn describe(tcx: TyCtxt<'_, '_, '_>, (_, def_id): (DefId, DefId)) -> Cow<'static, str> {
let id = tcx.hir().as_local_hir_id(def_id).unwrap();

View file

@ -555,11 +555,6 @@ rustc_query_append! { [define_queries!][ <'tcx>
},
TypeChecking {
// Erases regions from `ty` to yield a new type.
// Normally you would just use `tcx.erase_regions(&value)`,
// however, which uses this query as a kind of cache.
[] fn erase_regions_ty: erase_regions_ty(Ty<'tcx>) -> Ty<'tcx>,
/// Do not call this query directly: invoke `normalize` instead.
[] fn normalize_projection_ty: NormalizeProjectionTy(
CanonicalProjectionGoal<'tcx>
@ -698,10 +693,6 @@ fn codegen_fn_attrs<'tcx>(id: DefId) -> DepConstructor<'tcx> {
DepConstructor::CodegenFnAttrs { 0: id }
}
fn erase_regions_ty<'tcx>(ty: Ty<'tcx>) -> DepConstructor<'tcx> {
DepConstructor::EraseRegionsTy { ty }
}
fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {
DepConstructor::TypeParamPredicates {
item_id,

View file

@ -1223,7 +1223,6 @@ pub fn force_from_dep_node<'tcx>(
DepKind::CompileCodegenUnit |
DepKind::FulfillObligation |
DepKind::VtableMethods |
DepKind::EraseRegionsTy |
DepKind::NormalizeProjectionTy |
DepKind::NormalizeTyAfterErasingRegions |
DepKind::ImpliedOutlivesBounds |

View file

@ -48,6 +48,9 @@ enum QueryModifier {
/// Don't force the query
NoForce,
/// Generate a dep node based on the dependencies of the query
Anon,
}
impl Parse for QueryModifier {
@ -99,6 +102,8 @@ impl Parse for QueryModifier {
Ok(QueryModifier::NoHash)
} else if modifier == "no_force" {
Ok(QueryModifier::NoForce)
} else if modifier == "anon" {
Ok(QueryModifier::Anon)
} else {
Err(Error::new(modifier.span(), "unknown query modifier"))
}
@ -202,6 +207,9 @@ struct QueryModifiers {
/// Don't force the query
no_force: bool,
/// Generate a dep node based on the dependencies of the query
anon: bool,
}
/// Process query modifiers into a struct, erroring on duplicates
@ -212,6 +220,7 @@ fn process_modifiers(query: &mut Query) -> QueryModifiers {
let mut fatal_cycle = false;
let mut no_hash = false;
let mut no_force = false;
let mut anon = false;
for modifier in query.modifiers.0.drain(..) {
match modifier {
QueryModifier::LoadCached(tcx, id, block) => {
@ -250,6 +259,12 @@ fn process_modifiers(query: &mut Query) -> QueryModifiers {
}
no_force = true;
}
QueryModifier::Anon => {
if anon {
panic!("duplicate modifier `anon` for query `{}`", query.name);
}
anon = true;
}
}
}
QueryModifiers {
@ -259,6 +274,7 @@ fn process_modifiers(query: &mut Query) -> QueryModifiers {
fatal_cycle,
no_hash,
no_force,
anon,
}
}
@ -381,9 +397,20 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
[#attribute_stream] fn #name: #name(#arg) #result,
});
let mut attributes = Vec::new();
// Pass on the anon modifier
if modifiers.anon {
attributes.push(quote! { anon });
};
let mut attribute_stream = quote! {};
for e in attributes.into_iter().intersperse(quote! {,}) {
attribute_stream.extend(e);
}
// Create a dep node for the query
dep_node_def_stream.extend(quote! {
[] #name(#arg),
[#attribute_stream] #name(#arg),
});
if modifiers.no_force {