Skip to content

Add a query to get the promoteds for a mir::Body #62322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/librustc/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ rustc_queries! {
mir.map(|x| &*tcx.arena.alloc(x))
}
}

query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> { }
}

TypeChecking {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ pub fn const_eval_raw_provider<'tcx>(
// promoting runtime code is only allowed to error if it references broken constants
// any other kind of error will be reported to the user as a deny-by-default lint
_ => if let Some(p) = cid.promoted {
let span = tcx.optimized_mir(def_id).promoted[p].span;
let span = tcx.promoted_mir(def_id)[p].span;
if let InterpError::ReferencedConstant = err.error {
err.report_as_error(
tcx.at(span),
Expand Down
7 changes: 7 additions & 0 deletions src/librustc_mir/transform/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{build, shim};
use rustc_data_structures::indexed_vec::IndexVec;
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
use rustc::mir::{Body, MirPhase, Promoted};
use rustc::ty::{TyCtxt, InstanceDef};
Expand Down Expand Up @@ -46,6 +47,7 @@ pub(crate) fn provide(providers: &mut Providers<'_>) {
mir_validated,
optimized_mir,
is_mir_available,
promoted_mir,
..*providers
};
}
Expand Down Expand Up @@ -296,3 +298,8 @@ fn optimized_mir<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx Body<'tcx> {
]);
tcx.arena.alloc(body)
}

fn promoted_mir<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx IndexVec<Promoted, Body<'tcx>> {
let body = tcx.optimized_mir(def_id);
&body.promoted
}
2 changes: 1 addition & 1 deletion src/librustc_mir/util/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ pub fn write_mir_pretty<'tcx>(

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

for (i, body) in body.promoted.iter_enumerated() {
for (i, body) in tcx.promoted_mir(def_id).iter_enumerated() {
writeln!(w, "")?;
let src = MirSource {
instance: ty::InstanceDef::Item(def_id),
Expand Down