about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-07-16 12:19:35 +0000
committerbors <bors@rust-lang.org>2019-07-16 12:19:35 +0000
commitd36b7f69448f7390fa9dfde75d58b914365acdab (patch)
tree777dfd3b160a9529f230dc7a5e0a6b117ecde730
parent02785dabad07d19b8c76a7f86763801d5d3497ff (diff)
parent57c98d3392405705e17cc87dee350c16aeb24b4f (diff)
downloadrust-d36b7f69448f7390fa9dfde75d58b914365acdab.tar.gz
rust-d36b7f69448f7390fa9dfde75d58b914365acdab.zip
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
-rw-r--r--src/librustc/query/mod.rs2
-rw-r--r--src/librustc_mir/const_eval.rs2
-rw-r--r--src/librustc_mir/transform/mod.rs7
-rw-r--r--src/librustc_mir/util/pretty.rs2
4 files changed, 11 insertions, 2 deletions
diff --git a/src/librustc/query/mod.rs b/src/librustc/query/mod.rs
index 442a90ab3f8..fba3e22ab1b 100644
--- a/src/librustc/query/mod.rs
+++ b/src/librustc/query/mod.rs
@@ -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 {
diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs
index 8f3364b1fba..37d4c5b2f09 100644
--- a/src/librustc_mir/const_eval.rs
+++ b/src/librustc_mir/const_eval.rs
@@ -697,7 +697,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),
diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs
index 15e2dc3261d..9e23d061453 100644
--- a/src/librustc_mir/transform/mod.rs
+++ b/src/librustc_mir/transform/mod.rs
@@ -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};
@@ -46,6 +47,7 @@ pub(crate) fn provide(providers: &mut Providers<'_>) {
         mir_validated,
         optimized_mir,
         is_mir_available,
+        promoted_mir,
         ..*providers
     };
 }
@@ -296,3 +298,8 @@ fn optimized_mir(tcx: TyCtxt<'_>, def_id: DefId) -> &Body<'_> {
     ]);
     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
+}
diff --git a/src/librustc_mir/util/pretty.rs b/src/librustc_mir/util/pretty.rs
index d66f35f82c6..68880fc345a 100644
--- a/src/librustc_mir/util/pretty.rs
+++ b/src/librustc_mir/util/pretty.rs
@@ -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),