Skip to content

Commit d36b7f6

Browse files
committed
Auto merge of #62322 - wesleywiser:promoted_query, r=oli-obk
Add a query to get the `promoted`s for a `mir::Body` This is a builidng block toward removing a lot of duplicated code between miri and the cosnt-propagator pass. See this thread for more info: https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/Using.20.60InterpCx.60.20more/near/169030661 r? @spastorino but feel free to hand it off to somebody else
2 parents 02785da + 57c98d3 commit d36b7f6

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

src/librustc/query/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ rustc_queries! {
124124
mir.map(|x| &*tcx.arena.alloc(x))
125125
}
126126
}
127+
128+
query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> { }
127129
}
128130

129131
TypeChecking {

src/librustc_mir/const_eval.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ pub fn const_eval_raw_provider<'tcx>(
697697
// promoting runtime code is only allowed to error if it references broken constants
698698
// any other kind of error will be reported to the user as a deny-by-default lint
699699
_ => if let Some(p) = cid.promoted {
700-
let span = tcx.optimized_mir(def_id).promoted[p].span;
700+
let span = tcx.promoted_mir(def_id)[p].span;
701701
if let InterpError::ReferencedConstant = err.error {
702702
err.report_as_error(
703703
tcx.at(span),

src/librustc_mir/transform/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::{build, shim};
2+
use rustc_data_structures::indexed_vec::IndexVec;
23
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
34
use rustc::mir::{Body, MirPhase, Promoted};
45
use rustc::ty::{TyCtxt, InstanceDef};
@@ -46,6 +47,7 @@ pub(crate) fn provide(providers: &mut Providers<'_>) {
4647
mir_validated,
4748
optimized_mir,
4849
is_mir_available,
50+
promoted_mir,
4951
..*providers
5052
};
5153
}
@@ -296,3 +298,8 @@ fn optimized_mir(tcx: TyCtxt<'_>, def_id: DefId) -> &Body<'_> {
296298
]);
297299
tcx.arena.alloc(body)
298300
}
301+
302+
fn promoted_mir<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx IndexVec<Promoted, Body<'tcx>> {
303+
let body = tcx.optimized_mir(def_id);
304+
&body.promoted
305+
}

src/librustc_mir/util/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ pub fn write_mir_pretty<'tcx>(
263263

264264
write_mir_fn(tcx, MirSource::item(def_id), body, &mut |_, _| Ok(()), w)?;
265265

266-
for (i, body) in body.promoted.iter_enumerated() {
266+
for (i, body) in tcx.promoted_mir(def_id).iter_enumerated() {
267267
writeln!(w, "")?;
268268
let src = MirSource {
269269
instance: ty::InstanceDef::Item(def_id),

0 commit comments

Comments
 (0)