Skip to content

Commit d060e7d

Browse files
committed
Add no_force to query macro and move some queries over
1 parent b440041 commit d060e7d

File tree

6 files changed

+71
-65
lines changed

6 files changed

+71
-65
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,6 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
538538
[anon] TraitSelect,
539539

540540
[] ParamEnv(DefId),
541-
[] Environment(DefId),
542541
[] DescribeDef(DefId),
543542

544543
// FIXME(mw): DefSpans are not really inputs since they are derived from
@@ -661,9 +660,6 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
661660

662661
[input] Features,
663662

664-
[] ProgramClausesFor(DefId),
665-
[] ProgramClausesForEnv(traits::Environment<'tcx>),
666-
[] WasmImportModuleMap(CrateNum),
667663
[] ForeignModules(CrateNum),
668664

669665
[] UpstreamMonomorphizations(CrateNum),

src/librustc/query/mod.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ use crate::ty::query::QueryDescription;
22
use crate::ty::query::queries;
33
use crate::ty::TyCtxt;
44
use crate::ty;
5-
use crate::hir::def_id::CrateNum;
5+
use crate::hir::def_id::{DefId, CrateNum};
66
use crate::dep_graph::SerializedDepNodeIndex;
7+
use crate::traits;
78
use std::borrow::Cow;
89

910
// Each of these queries corresponds to a function pointer field in the
@@ -106,4 +107,26 @@ rustc_queries! {
106107
}
107108
}
108109
}
110+
111+
TypeChecking {
112+
query program_clauses_for(_: DefId) -> Clauses<'tcx> {
113+
desc { "generating chalk-style clauses" }
114+
}
115+
116+
query program_clauses_for_env(_: traits::Environment<'tcx>) -> Clauses<'tcx> {
117+
no_force
118+
desc { "generating chalk-style clauses for environment" }
119+
}
120+
121+
// Get the chalk-style environment of the given item.
122+
query environment(_: DefId) -> traits::Environment<'tcx> {
123+
desc { "return a chalk-style environment" }
124+
}
125+
}
126+
127+
Linking {
128+
query wasm_import_module_map(_: CrateNum) -> Lrc<FxHashMap<DefId, String>> {
129+
desc { "wasm import module map" }
130+
}
131+
}
109132
}

src/librustc/ty/query/config.rs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -916,33 +916,9 @@ impl<'tcx> QueryDescription<'tcx> for queries::instance_def_size_estimate<'tcx>
916916
}
917917
}
918918

919-
impl<'tcx> QueryDescription<'tcx> for queries::program_clauses_for<'tcx> {
920-
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: DefId) -> Cow<'static, str> {
921-
"generating chalk-style clauses".into()
922-
}
923-
}
924-
925-
impl<'tcx> QueryDescription<'tcx> for queries::program_clauses_for_env<'tcx> {
926-
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: traits::Environment<'tcx>) -> Cow<'static, str> {
927-
"generating chalk-style clauses for environment".into()
928-
}
929-
}
930-
931-
impl<'tcx> QueryDescription<'tcx> for queries::environment<'tcx> {
932-
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: DefId) -> Cow<'static, str> {
933-
"return a chalk-style environment".into()
934-
}
935-
}
936-
937-
impl<'tcx> QueryDescription<'tcx> for queries::wasm_import_module_map<'tcx> {
938-
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: CrateNum) -> Cow<'static, str> {
939-
"wasm import module map".into()
940-
}
941-
}
942-
943919
impl<'tcx> QueryDescription<'tcx> for queries::dllimport_foreign_items<'tcx> {
944920
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: CrateNum) -> Cow<'static, str> {
945-
"wasm import module map".into()
921+
"dllimport_foreign_items".into()
946922
}
947923
}
948924

src/librustc/ty/query/mod.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -683,22 +683,6 @@ rustc_query_append! { [define_queries!][ <'tcx>
683683

684684
[] fn features_query: features_node(CrateNum) -> Lrc<feature_gate::Features>,
685685
},
686-
687-
TypeChecking {
688-
[] fn program_clauses_for: ProgramClausesFor(DefId) -> Clauses<'tcx>,
689-
690-
[] fn program_clauses_for_env: ProgramClausesForEnv(
691-
traits::Environment<'tcx>
692-
) -> Clauses<'tcx>,
693-
694-
// Get the chalk-style environment of the given item.
695-
[] fn environment: Environment(DefId) -> traits::Environment<'tcx>,
696-
},
697-
698-
Linking {
699-
[] fn wasm_import_module_map: WasmImportModuleMap(CrateNum)
700-
-> Lrc<FxHashMap<DefId, String>>,
701-
},
702686
]}
703687

704688
//////////////////////////////////////////////////////////////////////

src/librustc/ty/query/plumbing.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,11 +1240,7 @@ pub fn force_from_dep_node<'tcx>(
12401240
DepKind::TypeOpNormalizeFnSig |
12411241
DepKind::SubstituteNormalizeAndTestPredicates |
12421242
DepKind::MethodAutoderefSteps |
1243-
DepKind::InstanceDefSizeEstimate |
1244-
DepKind::ProgramClausesForEnv |
1245-
1246-
// This one should never occur in this context
1247-
DepKind::Null => {
1243+
DepKind::InstanceDefSizeEstimate => {
12481244
bug!("force_from_dep_node() - Encountered {:?}", dep_node)
12491245
}
12501246

@@ -1311,7 +1307,6 @@ pub fn force_from_dep_node<'tcx>(
13111307
DepKind::CheckMatch => { force!(check_match, def_id!()); }
13121308

13131309
DepKind::ParamEnv => { force!(param_env, def_id!()); }
1314-
DepKind::Environment => { force!(environment, def_id!()); }
13151310
DepKind::DescribeDef => { force!(describe_def, def_id!()); }
13161311
DepKind::DefSpan => { force!(def_span, def_id!()); }
13171312
DepKind::LookupStability => { force!(lookup_stability, def_id!()); }
@@ -1419,8 +1414,6 @@ pub fn force_from_dep_node<'tcx>(
14191414

14201415
DepKind::Features => { force!(features_query, LOCAL_CRATE); }
14211416

1422-
DepKind::ProgramClausesFor => { force!(program_clauses_for, def_id!()); }
1423-
DepKind::WasmImportModuleMap => { force!(wasm_import_module_map, krate!()); }
14241417
DepKind::ForeignModules => { force!(foreign_modules, krate!()); }
14251418

14261419
DepKind::UpstreamMonomorphizations => {

src/librustc_macros/src/query.rs

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ enum QueryModifier {
4545

4646
/// Don't hash the result, instead just mark a query red if it runs
4747
NoHash,
48+
49+
/// Don't force the query
50+
NoForce,
4851
}
4952

5053
impl Parse for QueryModifier {
@@ -94,6 +97,8 @@ impl Parse for QueryModifier {
9497
Ok(QueryModifier::FatalCycle)
9598
} else if modifier == "no_hash" {
9699
Ok(QueryModifier::NoHash)
100+
} else if modifier == "no_force" {
101+
Ok(QueryModifier::NoForce)
97102
} else {
98103
Err(Error::new(modifier.span(), "unknown query modifier"))
99104
}
@@ -194,6 +199,9 @@ struct QueryModifiers {
194199

195200
/// Don't hash the result, instead just mark a query red if it runs
196201
no_hash: bool,
202+
203+
/// Don't force the query
204+
no_force: bool,
197205
}
198206

199207
/// Process query modifiers into a struct, erroring on duplicates
@@ -203,6 +211,7 @@ fn process_modifiers(query: &mut Query) -> QueryModifiers {
203211
let mut desc = None;
204212
let mut fatal_cycle = false;
205213
let mut no_hash = false;
214+
let mut no_force = false;
206215
for modifier in query.modifiers.0.drain(..) {
207216
match modifier {
208217
QueryModifier::LoadCached(tcx, id, block) => {
@@ -235,6 +244,12 @@ fn process_modifiers(query: &mut Query) -> QueryModifiers {
235244
}
236245
no_hash = true;
237246
}
247+
QueryModifier::NoForce => {
248+
if no_force {
249+
panic!("duplicate modifier `no_force` for query `{}`", query.name);
250+
}
251+
no_force = true;
252+
}
238253
}
239254
}
240255
QueryModifiers {
@@ -243,6 +258,7 @@ fn process_modifiers(query: &mut Query) -> QueryModifiers {
243258
desc,
244259
fatal_cycle,
245260
no_hash,
261+
no_force,
246262
}
247263
}
248264

@@ -329,6 +345,7 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
329345
let mut query_description_stream = quote! {};
330346
let mut dep_node_def_stream = quote! {};
331347
let mut dep_node_force_stream = quote! {};
348+
let mut no_force_queries = Vec::new();
332349

333350
for group in groups.0 {
334351
let mut group_stream = quote! {};
@@ -364,29 +381,46 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
364381
[#attribute_stream] fn #name: #name(#arg) #result,
365382
});
366383

367-
add_query_description_impl(&query, modifiers, &mut query_description_stream);
368-
369384
// Create a dep node for the query
370385
dep_node_def_stream.extend(quote! {
371386
[] #name(#arg),
372387
});
373388

374-
// Add a match arm to force the query given the dep node
375-
dep_node_force_stream.extend(quote! {
376-
DepKind::#name => {
377-
if let Some(key) = RecoverKey::recover($tcx, $dep_node) {
378-
force_ex!($tcx, #name, key);
379-
} else {
380-
return false;
389+
if modifiers.no_force {
390+
no_force_queries.push(name.clone());
391+
} else {
392+
// Add a match arm to force the query given the dep node
393+
dep_node_force_stream.extend(quote! {
394+
DepKind::#name => {
395+
if let Some(key) = RecoverKey::recover($tcx, $dep_node) {
396+
force_ex!($tcx, #name, key);
397+
} else {
398+
return false;
399+
}
381400
}
382-
}
383-
});
401+
});
402+
}
403+
404+
add_query_description_impl(&query, modifiers, &mut query_description_stream);
384405
}
385406
let name = &group.name;
386407
query_stream.extend(quote! {
387408
#name { #group_stream },
388409
});
389410
}
411+
412+
// Add an arm for the no force queries to panic when trying to force them
413+
for query in no_force_queries {
414+
dep_node_force_stream.extend(quote! {
415+
DepKind::#query |
416+
});
417+
}
418+
dep_node_force_stream.extend(quote! {
419+
DepKind::Null => {
420+
bug!("Cannot force dep node: {:?}", $dep_node)
421+
}
422+
});
423+
390424
TokenStream::from(quote! {
391425
macro_rules! rustc_query_append {
392426
([$($macro:tt)*][$($other:tt)*]) => {

0 commit comments

Comments
 (0)