Skip to content

Commit c891124

Browse files
committed
Split mir_promoted query again.
1 parent b192e70 commit c891124

6 files changed

Lines changed: 20 additions & 10 deletions

File tree

compiler/rustc_borrowck/src/root_cx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ impl<'tcx> BorrowCheckRootCtxt<'tcx> {
268268
for def_id in all_bodies {
269269
// The list of promoted from a given body is a flat list,
270270
// in topological order from innermost to outermost.
271-
let (_, promoted) = self.tcx.mir_promoted(def_id);
271+
let promoted = self.tcx.promoted_mir(def_id);
272272
for &promoted_def_id in promoted {
273273
let result = borrowck_collect_region_constraints(self, promoted_def_id);
274274
self.collect_region_constraints_results.insert(promoted_def_id, result);

compiler/rustc_interface/src/passes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
11461146
tcx.ensure_ok().mir_drops_elaborated_and_const_checked(def_id);
11471147

11481148
if tcx.trivial_const(def_id).is_none() {
1149-
for &promoted in tcx.mir_promoted(def_id).1 {
1149+
for &promoted in tcx.promoted_mir(def_id) {
11501150
tcx.ensure_ok().mir_drops_elaborated_and_const_checked(promoted);
11511151
}
11521152
}

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2313,7 +2313,7 @@ fn prefetch_mir(tcx: TyCtxt<'_>) {
23132313
tcx.ensure_done().optimized_mir(def_id);
23142314
}
23152315
if encode_opt || encode_const {
2316-
tcx.ensure_done().mir_promoted(def_id);
2316+
tcx.ensure_done().promoted_mir(def_id);
23172317
}
23182318
})
23192319
}

compiler/rustc_middle/src/mir/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ pub fn write_mir_pretty<'tcx>(
329329
writer.write_mir_fn(body, w)?;
330330

331331
if let Some(def_id) = def_id.as_local() {
332-
for body in tcx.mir_promoted(def_id).1 {
332+
for body in tcx.promoted_mir(def_id) {
333333
writeln!(w)?;
334334
let body = tcx.mir_for_ctfe(body.to_def_id());
335335
writer.write_mir_fn(body, w)?;

compiler/rustc_middle/src/queries.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -678,11 +678,8 @@ rustc_queries! {
678678
separate_provide_extern
679679
}
680680

681-
/// The `DefId` is the `DefId` of the containing MIR body. Promoteds do not have their own
682-
/// `DefId`. This function returns all promoteds in the specified body. The body references
683-
/// promoteds by the `DefId` and the `mir::Promoted` index. This is necessary, because
684-
/// after inlining a body may refer to promoteds from other bodies. In that case you still
685-
/// need to use the `DefId` of the original body.
681+
/// The `DefId` is the `DefId` of the containing MIR body.
682+
/// This query creates new `DefId`s for promoted-out constants.
686683
query mir_promoted(key: LocalDefId) -> (
687684
&'tcx Steal<mir::Body<'tcx>>,
688685
&'tcx IndexVec<mir::Promoted, LocalDefId>,
@@ -692,6 +689,12 @@ rustc_queries! {
692689
desc { "promoting constants in MIR for `{}`", tcx.def_path_str(key) }
693690
}
694691

692+
query promoted_mir(key: LocalDefId) -> &'tcx IndexVec<mir::Promoted, LocalDefId> {
693+
feedable
694+
cache_on_disk
695+
desc { "promoted constants in MIR for `{}`", tcx.def_path_str(key) }
696+
}
697+
695698
query closure_typeinfo(key: LocalDefId) -> ty::ClosureTypeInfo<'tcx> {
696699
desc {
697700
"finding symbols for captures of closure `{}`",

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ pub fn provide(providers: &mut Providers) {
229229
is_mir_available,
230230
mir_callgraph_cyclic: inline::cycle::mir_callgraph_cyclic,
231231
mir_inliner_callees: inline::cycle::mir_inliner_callees,
232+
promoted_mir,
232233
deduced_param_attrs: deduce_param_attrs::deduced_param_attrs,
233234
coroutine_by_move_body_def_id: coroutine::coroutine_by_move_body_def_id,
234235
trivial_const: trivial_const::trivial_const_provider,
@@ -353,7 +354,7 @@ fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LocalDefId> {
353354
let mut promoted = Vec::new();
354355
for &item in set.iter() {
355356
if tcx.trivial_const(item).is_none() {
356-
let (_, promoted_in_item) = tcx.mir_promoted(item);
357+
let promoted_in_item = tcx.promoted_mir(item);
357358
promoted.extend_from_slice(&promoted_in_item.raw);
358359
}
359360
}
@@ -848,3 +849,9 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> {
848849

849850
body
850851
}
852+
853+
/// Fetch all the promoteds of an item and prepare their MIR bodies to be ready for
854+
/// constant evaluation once all generic parameters become known.
855+
fn promoted_mir(tcx: TyCtxt<'_>, def: LocalDefId) -> &IndexVec<Promoted, LocalDefId> {
856+
tcx.mir_promoted(def).1
857+
}

0 commit comments

Comments
 (0)