about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authoroli <github35764891676564198441@oli-obk.de>2020-10-28 13:49:10 +0000
committeroli <github35764891676564198441@oli-obk.de>2021-01-04 21:40:38 +0000
commiteb4e94b2e5f479ac44bf8d4094cdcb73d5941b22 (patch)
tree657fd12f2a95d38d9a7c27ebe197945db541133c /compiler
parent1f5fb3e056428c3eb130ebb6fc95c7e1b7a2d20e (diff)
downloadrust-eb4e94b2e5f479ac44bf8d4094cdcb73d5941b22.tar.gz
rust-eb4e94b2e5f479ac44bf8d4094cdcb73d5941b22.zip
Simplify the `optimize_mir` query
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_middle/src/mir/query.rs2
-rw-r--r--compiler/rustc_middle/src/ty/mod.rs2
-rw-r--r--compiler/rustc_mir/src/transform/mod.rs26
3 files changed, 11 insertions, 19 deletions
diff --git a/compiler/rustc_middle/src/mir/query.rs b/compiler/rustc_middle/src/mir/query.rs
index 3e4490e4915..a7b847fc5e0 100644
--- a/compiler/rustc_middle/src/mir/query.rs
+++ b/compiler/rustc_middle/src/mir/query.rs
@@ -439,7 +439,7 @@ impl<'tcx> TyCtxt<'tcx> {
     }
 
     #[inline]
-    pub fn optimized_mir_opt_const_arg(
+    pub fn optimized_mir_or_const_arg_mir(
         self,
         def: ty::WithOptConstParam<DefId>,
     ) -> &'tcx Body<'tcx> {
diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs
index ca4db8abc0c..ccdec2bf89f 100644
--- a/compiler/rustc_middle/src/ty/mod.rs
+++ b/compiler/rustc_middle/src/ty/mod.rs
@@ -3018,7 +3018,7 @@ impl<'tcx> TyCtxt<'tcx> {
                 | DefKind::AnonConst => self.mir_for_ctfe_opt_const_arg(def),
                 // If the caller wants `mir_for_ctfe` they should not be using `instance_mir`, so
                 // we'll assume const fn also wants the optimized version.
-                _ => self.optimized_mir_opt_const_arg(def),
+                _ => self.optimized_mir_or_const_arg_mir(def),
             },
             ty::InstanceDef::VtableShim(..)
             | ty::InstanceDef::ReifyShim(..)
diff --git a/compiler/rustc_mir/src/transform/mod.rs b/compiler/rustc_mir/src/transform/mod.rs
index 8a4c5c1ef69..edf6fe2e0ef 100644
--- a/compiler/rustc_mir/src/transform/mod.rs
+++ b/compiler/rustc_mir/src/transform/mod.rs
@@ -517,34 +517,26 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
 
 fn optimized_mir<'tcx>(tcx: TyCtxt<'tcx>, did: DefId) -> &'tcx Body<'tcx> {
     let did = did.expect_local();
-    if let Some(def) = ty::WithOptConstParam::try_lookup(did, tcx) {
-        tcx.mir_for_ctfe_of_const_arg(def)
-    } else {
-        tcx.arena.alloc(inner_optimized_mir(tcx, ty::WithOptConstParam::unknown(did)))
-    }
+    assert_eq!(ty::WithOptConstParam::try_lookup(did, tcx), None);
+    tcx.arena.alloc(inner_optimized_mir(tcx, did))
 }
 
-fn inner_optimized_mir(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_> {
-    if tcx.is_constructor(def.did.to_def_id()) {
+fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> {
+    if tcx.is_constructor(did.to_def_id()) {
         // There's no reason to run all of the MIR passes on constructors when
         // we can just output the MIR we want directly. This also saves const
         // qualification and borrow checking the trouble of special casing
         // constructors.
-        return shim::build_adt_ctor(tcx, def.did.to_def_id());
+        return shim::build_adt_ctor(tcx, did.to_def_id());
     }
 
-    match tcx.hir().body_const_context(def.did) {
-        Some(hir::ConstContext::ConstFn) => {
-            if let Some((did, param_did)) = def.to_global().as_const_arg() {
-                tcx.ensure().mir_for_ctfe_of_const_arg((did, param_did))
-            } else {
-                tcx.ensure().mir_for_ctfe(def.did)
-            }
-        }
+    match tcx.hir().body_const_context(did) {
+        Some(hir::ConstContext::ConstFn) => tcx.ensure().mir_for_ctfe(did),
         None => {}
         Some(other) => panic!("do not use `optimized_mir` for constants: {:?}", other),
     }
-    let mut body = tcx.mir_drops_elaborated_and_const_checked(def).steal();
+    let mut body =
+        tcx.mir_drops_elaborated_and_const_checked(ty::WithOptConstParam::unknown(did)).steal();
     run_optimization_passes(tcx, &mut body);
 
     debug_assert!(!body.has_free_regions(), "Free regions in optimized MIR");