Skip to content

Commit 4d0a1e4

Browse files
committed
Add eval_always to query macro and move a query over
1 parent 52374a6 commit 4d0a1e4

File tree

6 files changed

+25
-13
lines changed

6 files changed

+25
-13
lines changed

src/librustc/dep_graph/dep_node.rs

-1
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,6 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
564564
[] HasGlobalAllocator(CrateNum),
565565
[] HasPanicHandler(CrateNum),
566566
[input] ExternCrate(DefId),
567-
[eval_always] LintLevels,
568567
[] Specializes { impl1: DefId, impl2: DefId },
569568
[input] InScopeTraits(DefIndex),
570569
[input] ModuleExports(DefId),

src/librustc/query/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ rustc_queries! {
5555
query native_libraries(_: CrateNum) -> Lrc<Vec<NativeLibrary>> {
5656
desc { "looking up the native libraries of a linked crate" }
5757
}
58+
59+
query lint_levels(_: CrateNum) -> Lrc<lint::LintLevelMap> {
60+
eval_always
61+
desc { "computing the lint levels for items in this crate" }
62+
}
5863
}
5964

6065
Codegen {

src/librustc/ty/query/config.rs

-6
Original file line numberDiff line numberDiff line change
@@ -605,12 +605,6 @@ impl<'tcx> QueryDescription<'tcx> for queries::analysis<'tcx> {
605605
}
606606
}
607607

608-
impl<'tcx> QueryDescription<'tcx> for queries::lint_levels<'tcx> {
609-
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: CrateNum) -> Cow<'static, str> {
610-
"computing the lint levels for items in this crate".into()
611-
}
612-
}
613-
614608
impl<'tcx> QueryDescription<'tcx> for queries::specializes<'tcx> {
615609
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: (DefId, DefId)) -> Cow<'static, str> {
616610
"computing whether impls specialize one another".into()

src/librustc/ty/query/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,6 @@ rustc_query_append! { [define_queries!][ <'tcx>
415415

416416
Other {
417417
[] fn module_exports: ModuleExports(DefId) -> Option<Lrc<Vec<Export>>>,
418-
[] fn lint_levels: lint_levels_node(CrateNum) -> Lrc<lint::LintLevelMap>,
419418
},
420419

421420
TypeChecking {
@@ -767,10 +766,6 @@ fn layout_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConst
767766
DepConstructor::Layout { param_env }
768767
}
769768

770-
fn lint_levels_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
771-
DepConstructor::LintLevels
772-
}
773-
774769
fn specializes_node<'tcx>((a, b): (DefId, DefId)) -> DepConstructor<'tcx> {
775770
DepConstructor::Specializes { impl1: a, impl2: b }
776771
}

src/librustc/ty/query/plumbing.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,6 @@ pub fn force_from_dep_node<'tcx>(
13321332
DepKind::HasGlobalAllocator => { force!(has_global_allocator, krate!()); }
13331333
DepKind::HasPanicHandler => { force!(has_panic_handler, krate!()); }
13341334
DepKind::ExternCrate => { force!(extern_crate, def_id!()); }
1335-
DepKind::LintLevels => { force!(lint_levels, LOCAL_CRATE); }
13361335
DepKind::InScopeTraits => { force!(in_scope_traits_map, def_id!().index); }
13371336
DepKind::ModuleExports => { force!(module_exports, def_id!()); }
13381337
DepKind::IsSanitizerRuntime => { force!(is_sanitizer_runtime, krate!()); }

src/librustc_macros/src/query.rs

+20
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ enum QueryModifier {
5151

5252
/// Generate a dep node based on the dependencies of the query
5353
Anon,
54+
55+
// Always evaluate the query, ignoring its depdendencies
56+
EvalAlways,
5457
}
5558

5659
impl Parse for QueryModifier {
@@ -104,6 +107,8 @@ impl Parse for QueryModifier {
104107
Ok(QueryModifier::NoForce)
105108
} else if modifier == "anon" {
106109
Ok(QueryModifier::Anon)
110+
} else if modifier == "eval_always" {
111+
Ok(QueryModifier::EvalAlways)
107112
} else {
108113
Err(Error::new(modifier.span(), "unknown query modifier"))
109114
}
@@ -210,6 +215,9 @@ struct QueryModifiers {
210215

211216
/// Generate a dep node based on the dependencies of the query
212217
anon: bool,
218+
219+
// Always evaluate the query, ignoring its depdendencies
220+
eval_always: bool,
213221
}
214222

215223
/// Process query modifiers into a struct, erroring on duplicates
@@ -221,6 +229,7 @@ fn process_modifiers(query: &mut Query) -> QueryModifiers {
221229
let mut no_hash = false;
222230
let mut no_force = false;
223231
let mut anon = false;
232+
let mut eval_always = false;
224233
for modifier in query.modifiers.0.drain(..) {
225234
match modifier {
226235
QueryModifier::LoadCached(tcx, id, block) => {
@@ -265,6 +274,12 @@ fn process_modifiers(query: &mut Query) -> QueryModifiers {
265274
}
266275
anon = true;
267276
}
277+
QueryModifier::EvalAlways => {
278+
if eval_always {
279+
panic!("duplicate modifier `eval_always` for query `{}`", query.name);
280+
}
281+
eval_always = true;
282+
}
268283
}
269284
}
270285
QueryModifiers {
@@ -275,6 +290,7 @@ fn process_modifiers(query: &mut Query) -> QueryModifiers {
275290
no_hash,
276291
no_force,
277292
anon,
293+
eval_always,
278294
}
279295
}
280296

@@ -403,6 +419,10 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
403419
if modifiers.anon {
404420
attributes.push(quote! { anon });
405421
};
422+
// Pass on the eval_always modifier
423+
if modifiers.eval_always {
424+
attributes.push(quote! { eval_always });
425+
};
406426

407427
let mut attribute_stream = quote! {};
408428
for e in attributes.into_iter().intersperse(quote! {,}) {

0 commit comments

Comments
 (0)