Skip to content

Commit 72f8d4e

Browse files
committed
Add no_hash to query macro and move some queries over
1 parent 0c8700b commit 72f8d4e

28 files changed

+241
-235
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2811,6 +2811,7 @@ dependencies = [
28112811
name = "rustc_macros"
28122812
version = "0.1.0"
28132813
dependencies = [
2814+
"itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
28142815
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
28152816
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
28162817
"syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)",

src/librustc/dep_graph/dep_node.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,6 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
461461

462462
// Represents the MIR for a fn; also used as the task node for
463463
// things read/modify that MIR.
464-
[] MirConstQualif(DefId),
465-
[] MirBuilt(DefId),
466-
[] MirConst(DefId),
467-
[] MirValidated(DefId),
468-
[] MirOptimized(DefId),
469464
[] MirShim { instance_def: InstanceDef<'tcx> },
470465

471466
[] BorrowCheckKrate,
@@ -485,7 +480,6 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
485480
[] CollectModItemTypes(DefId),
486481

487482
[] Reachability,
488-
[] MirKeys,
489483
[eval_always] CrateVariances,
490484

491485
// Nodes representing bits of computed IR in the tcx. Each shared

src/librustc/query/mod.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,47 @@ rustc_queries! {
6363
desc { "checking if the crate is_panic_runtime" }
6464
}
6565
}
66+
67+
Codegen {
68+
/// Set of all the `DefId`s in this crate that have MIR associated with
69+
/// them. This includes all the body owners, but also things like struct
70+
/// constructors.
71+
query mir_keys(_: CrateNum) -> Lrc<DefIdSet> {
72+
desc { "getting a list of all mir_keys" }
73+
}
74+
75+
/// Maps DefId's that have an associated Mir to the result
76+
/// of the MIR qualify_consts pass. The actual meaning of
77+
/// the value isn't known except to the pass itself.
78+
query mir_const_qualif(key: DefId) -> (u8, Lrc<BitSet<mir::Local>>) {
79+
cache { key.is_local() }
80+
}
81+
82+
/// Fetch the MIR for a given `DefId` right after it's built - this includes
83+
/// unreachable code.
84+
query mir_built(_: DefId) -> &'tcx Steal<mir::Mir<'tcx>> {}
85+
86+
/// Fetch the MIR for a given `DefId` up till the point where it is
87+
/// ready for const evaluation.
88+
///
89+
/// See the README for the `mir` module for details.
90+
query mir_const(_: DefId) -> &'tcx Steal<mir::Mir<'tcx>> {
91+
no_hash
92+
}
93+
94+
query mir_validated(_: DefId) -> &'tcx Steal<mir::Mir<'tcx>> {
95+
no_hash
96+
}
97+
98+
/// MIR after our optimization passes have run. This is MIR that is ready
99+
/// for codegen. This is also the only query that can fetch non-local MIR, at present.
100+
query optimized_mir(key: DefId) -> &'tcx mir::Mir<'tcx> {
101+
cache { key.is_local() }
102+
load_cached(tcx, id) {
103+
let mir: Option<crate::mir::Mir<'tcx>> = tcx.queries.on_disk_cache
104+
.try_load_query_result(tcx, id);
105+
mir.map(|x| tcx.alloc_mir(x))
106+
}
107+
}
108+
}
66109
}

src/librustc/ty/query/config.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -431,12 +431,6 @@ impl<'tcx> QueryDescription<'tcx> for queries::const_eval_raw<'tcx> {
431431
}
432432
}
433433

434-
impl<'tcx> QueryDescription<'tcx> for queries::mir_keys<'tcx> {
435-
fn describe(_: TyCtxt<'_, '_, '_>, _: CrateNum) -> Cow<'static, str> {
436-
"getting a list of all mir_keys".into()
437-
}
438-
}
439-
440434
impl<'tcx> QueryDescription<'tcx> for queries::symbol_name<'tcx> {
441435
fn describe(_tcx: TyCtxt<'_, '_, '_>, instance: ty::Instance<'tcx>) -> Cow<'static, str> {
442436
format!("computing the symbol for `{}`", instance).into()
@@ -898,21 +892,6 @@ impl<'tcx> QueryDescription<'tcx> for queries::typeck_tables_of<'tcx> {
898892
}
899893
}
900894

901-
impl<'tcx> QueryDescription<'tcx> for queries::optimized_mir<'tcx> {
902-
#[inline]
903-
fn cache_on_disk(_: TyCtxt<'_, 'tcx, 'tcx>, def_id: Self::Key) -> bool {
904-
def_id.is_local()
905-
}
906-
907-
fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
908-
id: SerializedDepNodeIndex)
909-
-> Option<Self::Value> {
910-
let mir: Option<crate::mir::Mir<'tcx>> = tcx.queries.on_disk_cache
911-
.try_load_query_result(tcx, id);
912-
mir.map(|x| tcx.alloc_mir(x))
913-
}
914-
}
915-
916895
impl<'tcx> QueryDescription<'tcx> for queries::substitute_normalize_and_test_predicates<'tcx> {
917896
fn describe(tcx: TyCtxt<'_, '_, '_>, key: (DefId, SubstsRef<'tcx>)) -> Cow<'static, str> {
918897
format!("testing substituted normalized predicates:`{}`", tcx.def_path_str(key.0)).into()
@@ -997,7 +976,6 @@ impl_disk_cacheable_query!(mir_borrowck, |tcx, def_id| {
997976

998977
impl_disk_cacheable_query!(unsafety_check_result, |_, def_id| def_id.is_local());
999978
impl_disk_cacheable_query!(borrowck, |_, def_id| def_id.is_local());
1000-
impl_disk_cacheable_query!(mir_const_qualif, |_, def_id| def_id.is_local());
1001979
impl_disk_cacheable_query!(check_match, |_, def_id| def_id.is_local());
1002980
impl_disk_cacheable_query!(def_symbol_name, |_, _| true);
1003981
impl_disk_cacheable_query!(predicates_of, |_, def_id| def_id.is_local());

src/librustc/ty/query/mod.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -205,34 +205,6 @@ rustc_query_append! { [define_queries!][ <'tcx>
205205
[] fn inherent_impls: InherentImpls(DefId) -> Lrc<Vec<DefId>>,
206206
},
207207

208-
Codegen {
209-
/// Set of all the `DefId`s in this crate that have MIR associated with
210-
/// them. This includes all the body owners, but also things like struct
211-
/// constructors.
212-
[] fn mir_keys: mir_keys(CrateNum) -> Lrc<DefIdSet>,
213-
214-
/// Maps DefId's that have an associated Mir to the result
215-
/// of the MIR qualify_consts pass. The actual meaning of
216-
/// the value isn't known except to the pass itself.
217-
[] fn mir_const_qualif: MirConstQualif(DefId) -> (u8, Lrc<BitSet<mir::Local>>),
218-
219-
/// Fetch the MIR for a given `DefId` right after it's built - this includes
220-
/// unreachable code.
221-
[] fn mir_built: MirBuilt(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
222-
223-
/// Fetch the MIR for a given `DefId` up till the point where it is
224-
/// ready for const evaluation.
225-
///
226-
/// See the README for the `mir` module for details.
227-
[no_hash] fn mir_const: MirConst(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
228-
229-
[no_hash] fn mir_validated: MirValidated(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,
230-
231-
/// MIR after our optimization passes have run. This is MIR that is ready
232-
/// for codegen. This is also the only query that can fetch non-local MIR, at present.
233-
[] fn optimized_mir: MirOptimized(DefId) -> &'tcx mir::Mir<'tcx>,
234-
},
235-
236208
TypeChecking {
237209
/// The result of unsafety-checking this `DefId`.
238210
[] fn unsafety_check_result: UnsafetyCheckResult(DefId) -> mir::UnsafetyCheckResult,
@@ -796,10 +768,6 @@ fn const_eval_raw_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>
796768
DepConstructor::ConstEvalRaw { param_env }
797769
}
798770

799-
fn mir_keys<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
800-
DepConstructor::MirKeys
801-
}
802-
803771
fn crate_variances<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
804772
DepConstructor::CrateVariances
805773
}

src/librustc/ty/query/plumbing.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,11 +1262,6 @@ pub fn force_from_dep_node<'tcx>(
12621262
},
12631263
DepKind::PrivacyAccessLevels => { force!(privacy_access_levels, LOCAL_CRATE); }
12641264
DepKind::CheckPrivateInPublic => { force!(check_private_in_public, LOCAL_CRATE); }
1265-
DepKind::MirBuilt => { force!(mir_built, def_id!()); }
1266-
DepKind::MirConstQualif => { force!(mir_const_qualif, def_id!()); }
1267-
DepKind::MirConst => { force!(mir_const, def_id!()); }
1268-
DepKind::MirValidated => { force!(mir_validated, def_id!()); }
1269-
DepKind::MirOptimized => { force!(optimized_mir, def_id!()); }
12701265

12711266
DepKind::BorrowCheck => { force!(borrowck, def_id!()); }
12721267
DepKind::MirBorrowCheck => { force!(mir_borrowck, def_id!()); }
@@ -1282,7 +1277,6 @@ pub fn force_from_dep_node<'tcx>(
12821277
DepKind::CheckModImplWf => { force!(check_mod_impl_wf, def_id!()); }
12831278
DepKind::CollectModItemTypes => { force!(collect_mod_item_types, def_id!()); }
12841279
DepKind::Reachability => { force!(reachable_set, LOCAL_CRATE); }
1285-
DepKind::MirKeys => { force!(mir_keys, LOCAL_CRATE); }
12861280
DepKind::CrateVariances => { force!(crate_variances, LOCAL_CRATE); }
12871281
DepKind::AssociatedItems => { force!(associated_item, def_id!()); }
12881282
DepKind::PredicatesDefinedOnItem => { force!(predicates_defined_on, def_id!()); }
@@ -1491,11 +1485,11 @@ macro_rules! impl_load_from_cache {
14911485

14921486
impl_load_from_cache!(
14931487
TypeckTables => typeck_tables_of,
1494-
MirOptimized => optimized_mir,
1488+
optimized_mir => optimized_mir,
14951489
UnsafetyCheckResult => unsafety_check_result,
14961490
BorrowCheck => borrowck,
14971491
MirBorrowCheck => mir_borrowck,
1498-
MirConstQualif => mir_const_qualif,
1492+
mir_const_qualif => mir_const_qualif,
14991493
SymbolName => def_symbol_name,
15001494
ConstIsRvaluePromotableToStatic => const_is_rvalue_promotable_to_static,
15011495
CheckMatch => check_match,

src/librustc_incremental/persist/dirty_clean.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ const BASE_IMPL: &[&str] = &[
6666
label_strs::ImplTraitRef,
6767
];
6868

69-
/// DepNodes for MirBuilt/Optimized, which is relevant in "executable"
69+
/// DepNodes for mir_built/Optimized, which is relevant in "executable"
7070
/// code, i.e., functions+methods
7171
const BASE_MIR: &[&str] = &[
72-
label_strs::MirOptimized,
73-
label_strs::MirBuilt,
72+
label_strs::optimized_mir,
73+
label_strs::mir_built,
7474
];
7575

7676
/// Struct, Enum and Union DepNodes

src/librustc_macros/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ synstructure = "0.10.1"
1212
syn = { version = "0.15.22", features = ["full"] }
1313
proc-macro2 = "0.4.24"
1414
quote = "0.6.10"
15+
itertools = "0.8"

src/librustc_macros/src/query.rs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use syn::parse::{Result, Parse, ParseStream};
88
use syn::punctuated::Punctuated;
99
use syn;
1010
use quote::quote;
11+
use itertools::Itertools;
1112

1213
#[allow(non_camel_case_types)]
1314
mod kw {
@@ -41,6 +42,9 @@ enum QueryModifier {
4142

4243
/// A cycle error for this query aborting the compilation with a fatal error.
4344
FatalCycle,
45+
46+
/// Don't hash the result, instead just mark a query red if it runs
47+
NoHash,
4448
}
4549

4650
impl Parse for QueryModifier {
@@ -88,6 +92,8 @@ impl Parse for QueryModifier {
8892
Ok(QueryModifier::LoadCached(tcx, id, block))
8993
} else if modifier == "fatal_cycle" {
9094
Ok(QueryModifier::FatalCycle)
95+
} else if modifier == "no_hash" {
96+
Ok(QueryModifier::NoHash)
9197
} else {
9298
Err(Error::new(modifier.span(), "unknown query modifier"))
9399
}
@@ -185,6 +191,9 @@ struct QueryModifiers {
185191

186192
/// A cycle error for this query aborting the compilation with a fatal error.
187193
fatal_cycle: bool,
194+
195+
/// Don't hash the result, instead just mark a query red if it runs
196+
no_hash: bool,
188197
}
189198

190199
/// Process query modifiers into a struct, erroring on duplicates
@@ -193,6 +202,7 @@ fn process_modifiers(query: &mut Query) -> QueryModifiers {
193202
let mut cache = None;
194203
let mut desc = None;
195204
let mut fatal_cycle = false;
205+
let mut no_hash = false;
196206
for modifier in query.modifiers.0.drain(..) {
197207
match modifier {
198208
QueryModifier::LoadCached(tcx, id, block) => {
@@ -219,13 +229,20 @@ fn process_modifiers(query: &mut Query) -> QueryModifiers {
219229
}
220230
fatal_cycle = true;
221231
}
232+
QueryModifier::NoHash => {
233+
if no_hash {
234+
panic!("duplicate modifier `no_hash` for query `{}`", query.name);
235+
}
236+
no_hash = true;
237+
}
222238
}
223239
}
224240
QueryModifiers {
225241
load_cached,
226242
cache,
227243
desc,
228244
fatal_cycle,
245+
no_hash,
229246
}
230247
}
231248

@@ -325,16 +342,26 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
325342
_ => quote! { #result_full },
326343
};
327344

345+
let mut attributes = Vec::new();
346+
328347
// Pass on the fatal_cycle modifier
329-
let fatal_cycle = if modifiers.fatal_cycle {
330-
quote! { fatal_cycle }
331-
} else {
332-
quote! {}
348+
if modifiers.fatal_cycle {
349+
attributes.push(quote! { fatal_cycle });
350+
};
351+
// Pass on the no_hash modifier
352+
if modifiers.no_hash {
353+
attributes.push(quote! { no_hash });
333354
};
334355

356+
let mut attribute_stream = quote! {};
357+
358+
for e in attributes.into_iter().intersperse(quote! {,}) {
359+
attribute_stream.extend(e);
360+
}
361+
335362
// Add the query to the group
336363
group_stream.extend(quote! {
337-
[#fatal_cycle] fn #name: #name(#arg) #result,
364+
[#attribute_stream] fn #name: #name(#arg) #result,
338365
});
339366

340367
add_query_description_impl(&query, modifiers, &mut query_description_stream);

src/test/incremental/hashes/call_expressions.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn change_callee_function() {
2525
}
2626

2727
#[cfg(not(cfail1))]
28-
#[rustc_clean(cfg="cfail2", except="HirBody,MirBuilt,MirOptimized,TypeckTables")]
28+
#[rustc_clean(cfg="cfail2", except="HirBody,mir_built,optimized_mir,TypeckTables")]
2929
#[rustc_clean(cfg="cfail3")]
3030
pub fn change_callee_function() {
3131
callee2(1, 2)
@@ -40,7 +40,7 @@ pub fn change_argument_function() {
4040
}
4141

4242
#[cfg(not(cfail1))]
43-
#[rustc_clean(cfg="cfail2", except="HirBody,MirBuilt,MirOptimized")]
43+
#[rustc_clean(cfg="cfail2", except="HirBody,mir_built,optimized_mir")]
4444
#[rustc_clean(cfg="cfail3")]
4545
pub fn change_argument_function() {
4646
callee1(1, 3)
@@ -81,7 +81,7 @@ pub fn change_callee_method() {
8181
}
8282

8383
#[cfg(not(cfail1))]
84-
#[rustc_clean(cfg="cfail2", except="HirBody,MirBuilt,MirOptimized,TypeckTables")]
84+
#[rustc_clean(cfg="cfail2", except="HirBody,mir_built,optimized_mir,TypeckTables")]
8585
#[rustc_clean(cfg="cfail3")]
8686
pub fn change_callee_method() {
8787
let s = Struct;
@@ -98,7 +98,7 @@ pub fn change_argument_method() {
9898
}
9999

100100
#[cfg(not(cfail1))]
101-
#[rustc_clean(cfg="cfail2", except="HirBody,MirBuilt,MirOptimized")]
101+
#[rustc_clean(cfg="cfail2", except="HirBody,mir_built,optimized_mir")]
102102
#[rustc_clean(cfg="cfail3")]
103103
pub fn change_argument_method() {
104104
let s = Struct;
@@ -115,7 +115,7 @@ pub fn change_ufcs_callee_method() {
115115
}
116116

117117
#[cfg(not(cfail1))]
118-
#[rustc_clean(cfg="cfail2", except="HirBody,MirBuilt,MirOptimized,TypeckTables")]
118+
#[rustc_clean(cfg="cfail2", except="HirBody,mir_built,optimized_mir,TypeckTables")]
119119
#[rustc_clean(cfg="cfail3")]
120120
pub fn change_ufcs_callee_method() {
121121
let s = Struct;
@@ -132,7 +132,7 @@ pub fn change_argument_method_ufcs() {
132132
}
133133

134134
#[cfg(not(cfail1))]
135-
#[rustc_clean(cfg="cfail2", except="HirBody,MirBuilt,MirOptimized")]
135+
#[rustc_clean(cfg="cfail2", except="HirBody,mir_built,optimized_mir")]
136136
#[rustc_clean(cfg="cfail3")]
137137
pub fn change_argument_method_ufcs() {
138138
let s = Struct;
@@ -149,7 +149,7 @@ pub fn change_to_ufcs() {
149149
}
150150

151151
#[cfg(not(cfail1))]
152-
#[rustc_clean(cfg="cfail2", except="HirBody,MirBuilt,MirOptimized,TypeckTables")]
152+
#[rustc_clean(cfg="cfail2", except="HirBody,mir_built,optimized_mir,TypeckTables")]
153153
#[rustc_clean(cfg="cfail3")]
154154
// One might think this would be expanded in the HirBody/Mir, but it actually
155155
// results in slightly different Hir/Mir.
@@ -171,7 +171,7 @@ pub mod change_ufcs_callee_indirectly {
171171
#[cfg(not(cfail1))]
172172
use super::Struct2 as Struct;
173173

174-
#[rustc_clean(cfg="cfail2", except="HirBody,MirBuilt,MirOptimized,TypeckTables")]
174+
#[rustc_clean(cfg="cfail2", except="HirBody,mir_built,optimized_mir,TypeckTables")]
175175
#[rustc_clean(cfg="cfail3")]
176176

177177

0 commit comments

Comments
 (0)