Skip to content

Commit ec0b940

Browse files
authored
Rollup merge of rust-lang#59315 - Zoxc:move-query, r=oli-obk
Add no_hash to query macro and move some queries over r? @oli-obk
2 parents 62d8334 + 75677c4 commit ec0b940

29 files changed

+381
-339
lines changed

Cargo.lock

+1
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

-19
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
@@ -544,7 +538,6 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
544538
[anon] TraitSelect,
545539

546540
[] ParamEnv(DefId),
547-
[] Environment(DefId),
548541
[] DescribeDef(DefId),
549542

550543
// FIXME(mw): DefSpans are not really inputs since they are derived from
@@ -571,7 +564,6 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
571564
[] HasGlobalAllocator(CrateNum),
572565
[] HasPanicHandler(CrateNum),
573566
[input] ExternCrate(DefId),
574-
[eval_always] LintLevels,
575567
[] Specializes { impl1: DefId, impl2: DefId },
576568
[input] InScopeTraits(DefIndex),
577569
[input] ModuleExports(DefId),
@@ -621,14 +613,6 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
621613
[input] UsedCrateSource(CrateNum),
622614
[input] PostorderCnums,
623615

624-
// These queries are not expected to have inputs -- as a result, they
625-
// are not good candidates for "replay" because they are essentially
626-
// pure functions of their input (and hence the expectation is that
627-
// no caller would be green **apart** from just these
628-
// queries). Making them anonymous avoids hashing the result, which
629-
// may save a bit of time.
630-
[anon] EraseRegionsTy { ty: Ty<'tcx> },
631-
632616
[input] Freevars(DefId),
633617
[input] MaybeUnusedTraitImport(DefId),
634618
[input] MaybeUnusedExternCrates,
@@ -667,9 +651,6 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
667651

668652
[input] Features,
669653

670-
[] ProgramClausesFor(DefId),
671-
[] ProgramClausesForEnv(traits::Environment<'tcx>),
672-
[] WasmImportModuleMap(CrateNum),
673654
[] ForeignModules(CrateNum),
674655

675656
[] UpstreamMonomorphizations(CrateNum),

src/librustc/query/mod.rs

+88-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::ty::query::QueryDescription;
22
use crate::ty::query::queries;
3-
use crate::ty::TyCtxt;
4-
use crate::ty;
5-
use crate::hir::def_id::CrateNum;
3+
use crate::ty::{self, Ty, TyCtxt};
4+
use crate::hir::def_id::{DefId, CrateNum};
65
use crate::dep_graph::SerializedDepNodeIndex;
6+
use crate::traits;
77
use std::borrow::Cow;
88

99
// Each of these queries corresponds to a function pointer field in the
@@ -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 {
@@ -63,4 +68,84 @@ rustc_queries! {
6368
desc { "checking if the crate is_panic_runtime" }
6469
}
6570
}
71+
72+
Codegen {
73+
/// Set of all the `DefId`s in this crate that have MIR associated with
74+
/// them. This includes all the body owners, but also things like struct
75+
/// constructors.
76+
query mir_keys(_: CrateNum) -> Lrc<DefIdSet> {
77+
desc { "getting a list of all mir_keys" }
78+
}
79+
80+
/// Maps DefId's that have an associated Mir to the result
81+
/// of the MIR qualify_consts pass. The actual meaning of
82+
/// the value isn't known except to the pass itself.
83+
query mir_const_qualif(key: DefId) -> (u8, Lrc<BitSet<mir::Local>>) {
84+
cache { key.is_local() }
85+
}
86+
87+
/// Fetch the MIR for a given `DefId` right after it's built - this includes
88+
/// unreachable code.
89+
query mir_built(_: DefId) -> &'tcx Steal<mir::Mir<'tcx>> {}
90+
91+
/// Fetch the MIR for a given `DefId` up till the point where it is
92+
/// ready for const evaluation.
93+
///
94+
/// See the README for the `mir` module for details.
95+
query mir_const(_: DefId) -> &'tcx Steal<mir::Mir<'tcx>> {
96+
no_hash
97+
}
98+
99+
query mir_validated(_: DefId) -> &'tcx Steal<mir::Mir<'tcx>> {
100+
no_hash
101+
}
102+
103+
/// MIR after our optimization passes have run. This is MIR that is ready
104+
/// for codegen. This is also the only query that can fetch non-local MIR, at present.
105+
query optimized_mir(key: DefId) -> &'tcx mir::Mir<'tcx> {
106+
cache { key.is_local() }
107+
load_cached(tcx, id) {
108+
let mir: Option<crate::mir::Mir<'tcx>> = tcx.queries.on_disk_cache
109+
.try_load_query_result(tcx, id);
110+
mir.map(|x| tcx.alloc_mir(x))
111+
}
112+
}
113+
}
114+
115+
TypeChecking {
116+
// Erases regions from `ty` to yield a new type.
117+
// Normally you would just use `tcx.erase_regions(&value)`,
118+
// however, which uses this query as a kind of cache.
119+
query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
120+
// This query is not expected to have input -- as a result, it
121+
// is not a good candidates for "replay" because it is essentially a
122+
// pure function of its input (and hence the expectation is that
123+
// no caller would be green **apart** from just these
124+
// queries). Making it anonymous avoids hashing the result, which
125+
// may save a bit of time.
126+
anon
127+
no_force
128+
desc { "erasing regions from `{:?}`", ty }
129+
}
130+
131+
query program_clauses_for(_: DefId) -> Clauses<'tcx> {
132+
desc { "generating chalk-style clauses" }
133+
}
134+
135+
query program_clauses_for_env(_: traits::Environment<'tcx>) -> Clauses<'tcx> {
136+
no_force
137+
desc { "generating chalk-style clauses for environment" }
138+
}
139+
140+
// Get the chalk-style environment of the given item.
141+
query environment(_: DefId) -> traits::Environment<'tcx> {
142+
desc { "return a chalk-style environment" }
143+
}
144+
}
145+
146+
Linking {
147+
query wasm_import_module_map(_: CrateNum) -> Lrc<FxHashMap<DefId, String>> {
148+
desc { "wasm import module map" }
149+
}
150+
}
66151
}

src/librustc/ty/query/config.rs

+1-59
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();
@@ -431,12 +425,6 @@ impl<'tcx> QueryDescription<'tcx> for queries::const_eval_raw<'tcx> {
431425
}
432426
}
433427

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-
440428
impl<'tcx> QueryDescription<'tcx> for queries::symbol_name<'tcx> {
441429
fn describe(_tcx: TyCtxt<'_, '_, '_>, instance: ty::Instance<'tcx>) -> Cow<'static, str> {
442430
format!("computing the symbol for `{}`", instance).into()
@@ -617,12 +605,6 @@ impl<'tcx> QueryDescription<'tcx> for queries::analysis<'tcx> {
617605
}
618606
}
619607

620-
impl<'tcx> QueryDescription<'tcx> for queries::lint_levels<'tcx> {
621-
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: CrateNum) -> Cow<'static, str> {
622-
"computing the lint levels for items in this crate".into()
623-
}
624-
}
625-
626608
impl<'tcx> QueryDescription<'tcx> for queries::specializes<'tcx> {
627609
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: (DefId, DefId)) -> Cow<'static, str> {
628610
"computing whether impls specialize one another".into()
@@ -898,21 +880,6 @@ impl<'tcx> QueryDescription<'tcx> for queries::typeck_tables_of<'tcx> {
898880
}
899881
}
900882

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-
916883
impl<'tcx> QueryDescription<'tcx> for queries::substitute_normalize_and_test_predicates<'tcx> {
917884
fn describe(tcx: TyCtxt<'_, '_, '_>, key: (DefId, SubstsRef<'tcx>)) -> Cow<'static, str> {
918885
format!("testing substituted normalized predicates:`{}`", tcx.def_path_str(key.0)).into()
@@ -937,33 +904,9 @@ impl<'tcx> QueryDescription<'tcx> for queries::instance_def_size_estimate<'tcx>
937904
}
938905
}
939906

940-
impl<'tcx> QueryDescription<'tcx> for queries::program_clauses_for<'tcx> {
941-
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: DefId) -> Cow<'static, str> {
942-
"generating chalk-style clauses".into()
943-
}
944-
}
945-
946-
impl<'tcx> QueryDescription<'tcx> for queries::program_clauses_for_env<'tcx> {
947-
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: traits::Environment<'tcx>) -> Cow<'static, str> {
948-
"generating chalk-style clauses for environment".into()
949-
}
950-
}
951-
952-
impl<'tcx> QueryDescription<'tcx> for queries::environment<'tcx> {
953-
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: DefId) -> Cow<'static, str> {
954-
"return a chalk-style environment".into()
955-
}
956-
}
957-
958-
impl<'tcx> QueryDescription<'tcx> for queries::wasm_import_module_map<'tcx> {
959-
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: CrateNum) -> Cow<'static, str> {
960-
"wasm import module map".into()
961-
}
962-
}
963-
964907
impl<'tcx> QueryDescription<'tcx> for queries::dllimport_foreign_items<'tcx> {
965908
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: CrateNum) -> Cow<'static, str> {
966-
"wasm import module map".into()
909+
"dllimport_foreign_items".into()
967910
}
968911
}
969912

@@ -997,7 +940,6 @@ impl_disk_cacheable_query!(mir_borrowck, |tcx, def_id| {
997940

998941
impl_disk_cacheable_query!(unsafety_check_result, |_, def_id| def_id.is_local());
999942
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());
1001943
impl_disk_cacheable_query!(check_match, |_, def_id| def_id.is_local());
1002944
impl_disk_cacheable_query!(def_symbol_name, |_, _| true);
1003945
impl_disk_cacheable_query!(predicates_of, |_, def_id| def_id.is_local());

src/librustc/ty/query/mod.rs

-62
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,
@@ -442,7 +414,6 @@ rustc_query_append! { [define_queries!][ <'tcx>
442414

443415
Other {
444416
[] fn module_exports: ModuleExports(DefId) -> Option<Lrc<Vec<Export>>>,
445-
[] fn lint_levels: lint_levels_node(CrateNum) -> Lrc<lint::LintLevelMap>,
446417
},
447418

448419
TypeChecking {
@@ -582,11 +553,6 @@ rustc_query_append! { [define_queries!][ <'tcx>
582553
},
583554

584555
TypeChecking {
585-
// Erases regions from `ty` to yield a new type.
586-
// Normally you would just use `tcx.erase_regions(&value)`,
587-
// however, which uses this query as a kind of cache.
588-
[] fn erase_regions_ty: erase_regions_ty(Ty<'tcx>) -> Ty<'tcx>,
589-
590556
/// Do not call this query directly: invoke `normalize` instead.
591557
[] fn normalize_projection_ty: NormalizeProjectionTy(
592558
CanonicalProjectionGoal<'tcx>
@@ -710,22 +676,6 @@ rustc_query_append! { [define_queries!][ <'tcx>
710676

711677
[] fn features_query: features_node(CrateNum) -> Lrc<feature_gate::Features>,
712678
},
713-
714-
TypeChecking {
715-
[] fn program_clauses_for: ProgramClausesFor(DefId) -> Clauses<'tcx>,
716-
717-
[] fn program_clauses_for_env: ProgramClausesForEnv(
718-
traits::Environment<'tcx>
719-
) -> Clauses<'tcx>,
720-
721-
// Get the chalk-style environment of the given item.
722-
[] fn environment: Environment(DefId) -> traits::Environment<'tcx>,
723-
},
724-
725-
Linking {
726-
[] fn wasm_import_module_map: WasmImportModuleMap(CrateNum)
727-
-> Lrc<FxHashMap<DefId, String>>,
728-
},
729679
]}
730680

731681
//////////////////////////////////////////////////////////////////////
@@ -741,10 +691,6 @@ fn codegen_fn_attrs<'tcx>(id: DefId) -> DepConstructor<'tcx> {
741691
DepConstructor::CodegenFnAttrs { 0: id }
742692
}
743693

744-
fn erase_regions_ty<'tcx>(ty: Ty<'tcx>) -> DepConstructor<'tcx> {
745-
DepConstructor::EraseRegionsTy { ty }
746-
}
747-
748694
fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {
749695
DepConstructor::TypeParamPredicates {
750696
item_id,
@@ -795,10 +741,6 @@ fn const_eval_raw_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>
795741
DepConstructor::ConstEvalRaw { param_env }
796742
}
797743

798-
fn mir_keys<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
799-
DepConstructor::MirKeys
800-
}
801-
802744
fn crate_variances<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
803745
DepConstructor::CrateVariances
804746
}
@@ -823,10 +765,6 @@ fn layout_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConst
823765
DepConstructor::Layout { param_env }
824766
}
825767

826-
fn lint_levels_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
827-
DepConstructor::LintLevels
828-
}
829-
830768
fn specializes_node<'tcx>((a, b): (DefId, DefId)) -> DepConstructor<'tcx> {
831769
DepConstructor::Specializes { impl1: a, impl2: b }
832770
}

0 commit comments

Comments
 (0)