Skip to content

Commit

Permalink
Resolve worsened debug build codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleywiser committed Mar 22, 2020
1 parent 38114ff commit 4f40511
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 8 deletions.
9 changes: 1 addition & 8 deletions src/librustc_mir/transform/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
) -> ConstPropagator<'mir, 'tcx> {
let def_id = source.def_id();
let substs = &InternalSubsts::identity_for_item(tcx, def_id);
let mut param_env = tcx.param_env(def_id);

// If we're evaluating inside a monomorphic function, then use `Reveal::All` because
// we want to see the same instances that codegen will see. This allows us to `resolve()`
// specializations.
if !substs.needs_subst() {
param_env = param_env.with_reveal_all();
}
let param_env = tcx.param_env(def_id).with_reveal_all();

let span = tcx.def_span(def_id);
let mut ecx = InterpCx::new(tcx.at(span), param_env, ConstPropMachine, ());
Expand Down
64 changes: 64 additions & 0 deletions src/test/mir-opt/const_prop/control-flow-simplification.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// compile-flags: -Zmir-opt-level=1

trait NeedsDrop:Sized{
const NEEDS:bool=std::mem::needs_drop::<Self>();
}

impl<This> NeedsDrop for This{}

fn hello<T>(){
if <bool>::NEEDS {
panic!()
}
}

pub fn main() {
hello::<()>();
hello::<Vec<()>>();
}

// END RUST SOURCE
// START rustc.hello.ConstProp.before.mir
// let mut _0: ();
// let mut _1: bool;
// let mut _2: !;
// bb0: {
// StorageLive(_1);
// _1 = const <bool as NeedsDrop>::NEEDS;
// switchInt(_1) -> [false: bb1, otherwise: bb2];
// }
// bb1: {
// _0 = ();
// StorageDead(_1);
// return;
// }
// bb2: {
// StorageLive(_2);
// const std::rt::begin_panic::<&str>(const "explicit panic");
// }
// END rustc.hello.ConstProp.before.mir
// START rustc.hello.ConstProp.after.mir
// let mut _0: ();
// let mut _1: bool;
// let mut _2: !;
// bb0: {
// StorageLive(_1);
// _1 = const false;
// switchInt(const false) -> [false: bb1, otherwise: bb2];
// }
// bb1: {
// _0 = ();
// StorageDead(_1);
// return;
// }
// bb2: {
// StorageLive(_2);
// const std::rt::begin_panic::<&str>(const "explicit panic");
// }
// END rustc.hello.ConstProp.after.mir
// START rustc.hello.PreCodegen.before.mir
// let mut _0: ();
// bb0: {
// return;
// }
// END rustc.hello.PreCodegen.before.mir

0 comments on commit 4f40511

Please sign in to comment.