Skip to content

Commit b306b1e

Browse files
authored
Rollup merge of rust-lang#70259 - wesleywiser:use_reveal_all, r=eddyb
Use Reveal::All in MIR optimizations Resolves some code review feedback in rust-lang#67662. Fixes rust-lang#68855 r? @eddyb
2 parents a62fd3a + 61d3be8 commit b306b1e

File tree

3 files changed

+68
-18
lines changed

3 files changed

+68
-18
lines changed

src/librustc_mir/transform/const_prop.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -337,14 +337,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
337337
) -> ConstPropagator<'mir, 'tcx> {
338338
let def_id = source.def_id();
339339
let substs = &InternalSubsts::identity_for_item(tcx, def_id);
340-
let mut param_env = tcx.param_env(def_id);
341-
342-
// If we're evaluating inside a monomorphic function, then use `Reveal::All` because
343-
// we want to see the same instances that codegen will see. This allows us to `resolve()`
344-
// specializations.
345-
if !substs.needs_subst() {
346-
param_env = param_env.with_reveal_all();
347-
}
340+
let param_env = tcx.param_env(def_id).with_reveal_all();
348341

349342
let span = tcx.def_span(def_id);
350343
let mut ecx = InterpCx::new(tcx.at(span), param_env, ConstPropMachine, ());

src/librustc_mir/transform/inline.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use rustc::middle::codegen_fn_attrs::CodegenFnAttrFlags;
44
use rustc::mir::visit::*;
55
use rustc::mir::*;
6-
use rustc::ty::subst::{InternalSubsts, Subst, SubstsRef};
7-
use rustc::ty::{self, Instance, InstanceDef, ParamEnv, Ty, TyCtxt, TypeFoldable};
6+
use rustc::ty::subst::{Subst, SubstsRef};
7+
use rustc::ty::{self, Instance, InstanceDef, ParamEnv, Ty, TyCtxt};
88
use rustc_attr as attr;
99
use rustc_hir::def_id::DefId;
1010
use rustc_index::bit_set::BitSet;
@@ -66,14 +66,7 @@ impl Inliner<'tcx> {
6666

6767
let mut callsites = VecDeque::new();
6868

69-
let mut param_env = self.tcx.param_env(self.source.def_id());
70-
71-
let substs = &InternalSubsts::identity_for_item(self.tcx, self.source.def_id());
72-
73-
// For monomorphic functions, we can use `Reveal::All` to resolve specialized instances.
74-
if !substs.needs_subst() {
75-
param_env = param_env.with_reveal_all();
76-
}
69+
let param_env = self.tcx.param_env(self.source.def_id()).with_reveal_all();
7770

7871
// Only do inlining into fn bodies.
7972
let id = self.tcx.hir().as_local_hir_id(self.source.def_id()).unwrap();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// compile-flags: -Zmir-opt-level=1
2+
3+
trait NeedsDrop:Sized{
4+
const NEEDS:bool=std::mem::needs_drop::<Self>();
5+
}
6+
7+
impl<This> NeedsDrop for This{}
8+
9+
fn hello<T>(){
10+
if <bool>::NEEDS {
11+
panic!()
12+
}
13+
}
14+
15+
pub fn main() {
16+
hello::<()>();
17+
hello::<Vec<()>>();
18+
}
19+
20+
// END RUST SOURCE
21+
// START rustc.hello.ConstProp.before.mir
22+
// let mut _0: ();
23+
// let mut _1: bool;
24+
// let mut _2: !;
25+
// bb0: {
26+
// StorageLive(_1);
27+
// _1 = const <bool as NeedsDrop>::NEEDS;
28+
// switchInt(_1) -> [false: bb1, otherwise: bb2];
29+
// }
30+
// bb1: {
31+
// _0 = ();
32+
// StorageDead(_1);
33+
// return;
34+
// }
35+
// bb2: {
36+
// StorageLive(_2);
37+
// const std::rt::begin_panic::<&str>(const "explicit panic");
38+
// }
39+
// END rustc.hello.ConstProp.before.mir
40+
// START rustc.hello.ConstProp.after.mir
41+
// let mut _0: ();
42+
// let mut _1: bool;
43+
// let mut _2: !;
44+
// bb0: {
45+
// StorageLive(_1);
46+
// _1 = const false;
47+
// switchInt(const false) -> [false: bb1, otherwise: bb2];
48+
// }
49+
// bb1: {
50+
// _0 = ();
51+
// StorageDead(_1);
52+
// return;
53+
// }
54+
// bb2: {
55+
// StorageLive(_2);
56+
// const std::rt::begin_panic::<&str>(const "explicit panic");
57+
// }
58+
// END rustc.hello.ConstProp.after.mir
59+
// START rustc.hello.PreCodegen.before.mir
60+
// let mut _0: ();
61+
// bb0: {
62+
// return;
63+
// }
64+
// END rustc.hello.PreCodegen.before.mir

0 commit comments

Comments
 (0)