Skip to content

Commit 52374a6

Browse files
committed
Add anon to query macro and move a query over
1 parent d060e7d commit 52374a6

File tree

6 files changed

+44
-27
lines changed

6 files changed

+44
-27
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -614,14 +614,6 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
614614
[input] UsedCrateSource(CrateNum),
615615
[input] PostorderCnums,
616616

617-
// These queries are not expected to have inputs -- as a result, they
618-
// are not good candidates for "replay" because they are essentially
619-
// pure functions of their input (and hence the expectation is that
620-
// no caller would be green **apart** from just these
621-
// queries). Making them anonymous avoids hashing the result, which
622-
// may save a bit of time.
623-
[anon] EraseRegionsTy { ty: Ty<'tcx> },
624-
625617
[input] Freevars(DefId),
626618
[input] MaybeUnusedTraitImport(DefId),
627619
[input] MaybeUnusedExternCrates,

src/librustc/query/mod.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::ty::query::QueryDescription;
22
use crate::ty::query::queries;
3-
use crate::ty::TyCtxt;
4-
use crate::ty;
3+
use crate::ty::{self, Ty, TyCtxt};
54
use crate::hir::def_id::{DefId, CrateNum};
65
use crate::dep_graph::SerializedDepNodeIndex;
76
use crate::traits;
@@ -109,6 +108,21 @@ rustc_queries! {
109108
}
110109

111110
TypeChecking {
111+
// Erases regions from `ty` to yield a new type.
112+
// Normally you would just use `tcx.erase_regions(&value)`,
113+
// however, which uses this query as a kind of cache.
114+
query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
115+
// This query is not expected to have input -- as a result, it
116+
// is not a good candidates for "replay" because it is essentially a
117+
// pure function of its input (and hence the expectation is that
118+
// no caller would be green **apart** from just these
119+
// queries). Making it anonymous avoids hashing the result, which
120+
// may save a bit of time.
121+
anon
122+
no_force
123+
desc { "erasing regions from `{:?}`", ty }
124+
}
125+
112126
query program_clauses_for(_: DefId) -> Clauses<'tcx> {
113127
desc { "generating chalk-style clauses" }
114128
}

src/librustc/ty/query/config.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,6 @@ impl<'tcx> QueryDescription<'tcx> for queries::super_predicates_of<'tcx> {
305305
}
306306
}
307307

308-
impl<'tcx> QueryDescription<'tcx> for queries::erase_regions_ty<'tcx> {
309-
fn describe(_tcx: TyCtxt<'_, '_, '_>, ty: Ty<'tcx>) -> Cow<'static, str> {
310-
format!("erasing regions from `{:?}`", ty).into()
311-
}
312-
}
313-
314308
impl<'tcx> QueryDescription<'tcx> for queries::type_param_predicates<'tcx> {
315309
fn describe(tcx: TyCtxt<'_, '_, '_>, (_, def_id): (DefId, DefId)) -> Cow<'static, str> {
316310
let id = tcx.hir().as_local_hir_id(def_id).unwrap();

src/librustc/ty/query/mod.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -555,11 +555,6 @@ rustc_query_append! { [define_queries!][ <'tcx>
555555
},
556556

557557
TypeChecking {
558-
// Erases regions from `ty` to yield a new type.
559-
// Normally you would just use `tcx.erase_regions(&value)`,
560-
// however, which uses this query as a kind of cache.
561-
[] fn erase_regions_ty: erase_regions_ty(Ty<'tcx>) -> Ty<'tcx>,
562-
563558
/// Do not call this query directly: invoke `normalize` instead.
564559
[] fn normalize_projection_ty: NormalizeProjectionTy(
565560
CanonicalProjectionGoal<'tcx>
@@ -698,10 +693,6 @@ fn codegen_fn_attrs<'tcx>(id: DefId) -> DepConstructor<'tcx> {
698693
DepConstructor::CodegenFnAttrs { 0: id }
699694
}
700695

701-
fn erase_regions_ty<'tcx>(ty: Ty<'tcx>) -> DepConstructor<'tcx> {
702-
DepConstructor::EraseRegionsTy { ty }
703-
}
704-
705696
fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {
706697
DepConstructor::TypeParamPredicates {
707698
item_id,

src/librustc/ty/query/plumbing.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,6 @@ pub fn force_from_dep_node<'tcx>(
12231223
DepKind::CompileCodegenUnit |
12241224
DepKind::FulfillObligation |
12251225
DepKind::VtableMethods |
1226-
DepKind::EraseRegionsTy |
12271226
DepKind::NormalizeProjectionTy |
12281227
DepKind::NormalizeTyAfterErasingRegions |
12291228
DepKind::ImpliedOutlivesBounds |

src/librustc_macros/src/query.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ enum QueryModifier {
4848

4949
/// Don't force the query
5050
NoForce,
51+
52+
/// Generate a dep node based on the dependencies of the query
53+
Anon,
5154
}
5255

5356
impl Parse for QueryModifier {
@@ -99,6 +102,8 @@ impl Parse for QueryModifier {
99102
Ok(QueryModifier::NoHash)
100103
} else if modifier == "no_force" {
101104
Ok(QueryModifier::NoForce)
105+
} else if modifier == "anon" {
106+
Ok(QueryModifier::Anon)
102107
} else {
103108
Err(Error::new(modifier.span(), "unknown query modifier"))
104109
}
@@ -202,6 +207,9 @@ struct QueryModifiers {
202207

203208
/// Don't force the query
204209
no_force: bool,
210+
211+
/// Generate a dep node based on the dependencies of the query
212+
anon: bool,
205213
}
206214

207215
/// Process query modifiers into a struct, erroring on duplicates
@@ -212,6 +220,7 @@ fn process_modifiers(query: &mut Query) -> QueryModifiers {
212220
let mut fatal_cycle = false;
213221
let mut no_hash = false;
214222
let mut no_force = false;
223+
let mut anon = false;
215224
for modifier in query.modifiers.0.drain(..) {
216225
match modifier {
217226
QueryModifier::LoadCached(tcx, id, block) => {
@@ -250,6 +259,12 @@ fn process_modifiers(query: &mut Query) -> QueryModifiers {
250259
}
251260
no_force = true;
252261
}
262+
QueryModifier::Anon => {
263+
if anon {
264+
panic!("duplicate modifier `anon` for query `{}`", query.name);
265+
}
266+
anon = true;
267+
}
253268
}
254269
}
255270
QueryModifiers {
@@ -259,6 +274,7 @@ fn process_modifiers(query: &mut Query) -> QueryModifiers {
259274
fatal_cycle,
260275
no_hash,
261276
no_force,
277+
anon,
262278
}
263279
}
264280

@@ -381,9 +397,20 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
381397
[#attribute_stream] fn #name: #name(#arg) #result,
382398
});
383399

400+
let mut attributes = Vec::new();
401+
402+
// Pass on the anon modifier
403+
if modifiers.anon {
404+
attributes.push(quote! { anon });
405+
};
406+
407+
let mut attribute_stream = quote! {};
408+
for e in attributes.into_iter().intersperse(quote! {,}) {
409+
attribute_stream.extend(e);
410+
}
384411
// Create a dep node for the query
385412
dep_node_def_stream.extend(quote! {
386-
[] #name(#arg),
413+
[#attribute_stream] #name(#arg),
387414
});
388415

389416
if modifiers.no_force {

0 commit comments

Comments
 (0)