Skip to content

Commit f5df26d

Browse files
committed
Unconditionally run RevealAll pass and run it earlier
1 parent ec6f554 commit f5df26d

File tree

8 files changed

+76
-22
lines changed

8 files changed

+76
-22
lines changed

compiler/rustc_mir_transform/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ fn run_runtime_lowering_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
480480
let passes: &[&dyn MirPass<'tcx>] = &[
481481
// These next passes must be executed together
482482
&add_call_guards::CriticalCallEdges,
483+
&reveal_all::RevealAll, // has to be done before drop elaboration, since we need to drop opaque types, too.
483484
&elaborate_drops::ElaborateDrops,
484485
// This will remove extraneous landing pads which are no longer
485486
// necessary as well as well as forcing any call in a non-unwinding
@@ -526,7 +527,6 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
526527
body,
527528
&[
528529
&check_alignment::CheckAlignment,
529-
&reveal_all::RevealAll, // has to be done before inlining, since inlined code is in RevealAll mode.
530530
&lower_slice_len::LowerSliceLenCalls, // has to be done before inlining, otherwise actual call will be almost always inlined. Also simple, so can just do first
531531
&unreachable_prop::UnreachablePropagation,
532532
&uninhabited_enum_branching::UninhabitedEnumBranching,

compiler/rustc_mir_transform/src/reveal_all.rs

-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ use rustc_middle::ty::{self, Ty, TyCtxt};
88
pub struct RevealAll;
99

1010
impl<'tcx> MirPass<'tcx> for RevealAll {
11-
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
12-
sess.mir_opt_level() >= 3 || super::inline::Inline.is_enabled(sess)
13-
}
14-
1511
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
1612
// Do not apply this transformation to generators.
1713
if body.generator.is_some() {

tests/incremental/hashes/function_interfaces.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ pub fn return_impl_trait() -> i32 {
302302
}
303303

304304
#[cfg(not(any(cfail1,cfail4)))]
305-
#[rustc_clean(cfg = "cfail2", except = "hir_owner, hir_owner_nodes, typeck, fn_sig, optimized_mir")]
305+
#[rustc_clean(cfg = "cfail2", except = "hir_owner, hir_owner_nodes, typeck, fn_sig")]
306306
#[rustc_clean(cfg = "cfail3")]
307307
#[rustc_clean(cfg = "cfail5", except = "hir_owner, hir_owner_nodes, typeck, fn_sig, optimized_mir")]
308308
#[rustc_clean(cfg = "cfail6")]

tests/mir-opt/inline/issue_78442.bar.RevealAll.panic-abort.diff

+21-5
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,44 @@
1515
StorageLive(_2);
1616
StorageLive(_3);
1717
StorageLive(_4);
18-
_4 = hide_foo() -> [return: bb1, unwind unreachable];
18+
_4 = hide_foo() -> [return: bb1, unwind: bb6];
1919
}
2020

2121
bb1: {
2222
_3 = &_4;
2323
StorageLive(_5);
2424
_5 = ();
25-
- _2 = <impl Fn() as Fn<()>>::call(move _3, move _5) -> [return: bb2, unwind unreachable];
26-
+ _2 = <fn() {foo} as Fn<()>>::call(move _3, move _5) -> [return: bb2, unwind unreachable];
25+
- _2 = <impl Fn() as Fn<()>>::call(move _3, move _5) -> [return: bb2, unwind: bb5];
26+
+ _2 = <fn() {foo} as Fn<()>>::call(move _3, move _5) -> [return: bb2, unwind: bb5];
2727
}
2828

2929
bb2: {
3030
StorageDead(_5);
3131
StorageDead(_3);
32+
drop(_4) -> [return: bb3, unwind: bb6];
33+
}
34+
35+
bb3: {
3236
StorageDead(_4);
3337
StorageDead(_2);
3438
_0 = const ();
35-
drop(_1) -> [return: bb3, unwind unreachable];
39+
drop(_1) -> [return: bb4, unwind: bb7];
3640
}
3741

38-
bb3: {
42+
bb4: {
3943
return;
4044
}
45+
46+
bb5 (cleanup): {
47+
drop(_4) -> [return: bb6, unwind terminate(cleanup)];
48+
}
49+
50+
bb6 (cleanup): {
51+
drop(_1) -> [return: bb7, unwind terminate(cleanup)];
52+
}
53+
54+
bb7 (cleanup): {
55+
resume;
56+
}
4157
}
4258

tests/mir-opt/inline/issue_78442.bar.RevealAll.panic-unwind.diff

+16-8
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,43 @@
1515
StorageLive(_2);
1616
StorageLive(_3);
1717
StorageLive(_4);
18-
_4 = hide_foo() -> [return: bb1, unwind: bb4];
18+
_4 = hide_foo() -> [return: bb1, unwind: bb6];
1919
}
2020

2121
bb1: {
2222
_3 = &_4;
2323
StorageLive(_5);
2424
_5 = ();
25-
- _2 = <impl Fn() as Fn<()>>::call(move _3, move _5) -> [return: bb2, unwind: bb4];
26-
+ _2 = <fn() {foo} as Fn<()>>::call(move _3, move _5) -> [return: bb2, unwind: bb4];
25+
- _2 = <impl Fn() as Fn<()>>::call(move _3, move _5) -> [return: bb2, unwind: bb5];
26+
+ _2 = <fn() {foo} as Fn<()>>::call(move _3, move _5) -> [return: bb2, unwind: bb5];
2727
}
2828

2929
bb2: {
3030
StorageDead(_5);
3131
StorageDead(_3);
32+
drop(_4) -> [return: bb3, unwind: bb6];
33+
}
34+
35+
bb3: {
3236
StorageDead(_4);
3337
StorageDead(_2);
3438
_0 = const ();
35-
drop(_1) -> [return: bb3, unwind: bb5];
39+
drop(_1) -> [return: bb4, unwind continue];
3640
}
3741

38-
bb3: {
42+
bb4: {
3943
return;
4044
}
4145

42-
bb4 (cleanup): {
43-
drop(_1) -> [return: bb5, unwind terminate(cleanup)];
46+
bb5 (cleanup): {
47+
drop(_4) -> [return: bb6, unwind terminate(cleanup)];
4448
}
4549

46-
bb5 (cleanup): {
50+
bb6 (cleanup): {
51+
drop(_1) -> [return: bb7, unwind terminate(cleanup)];
52+
}
53+
54+
bb7 (cleanup): {
4755
resume;
4856
}
4957
}

tests/ui/polymorphization/generators.rs

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ where
3232

3333
#[rustc_polymorphize_error]
3434
pub fn unused_type<T>() -> impl Generator<(), Yield = u32, Return = u32> + Unpin {
35+
//~^ ERROR item has unused generic parameters
3536
|| {
3637
//~^ ERROR item has unused generic parameters
3738
yield 1;
@@ -57,6 +58,7 @@ pub fn used_type_in_return<R: Default>() -> impl Generator<(), Yield = u32, Retu
5758

5859
#[rustc_polymorphize_error]
5960
pub fn unused_const<const T: u32>() -> impl Generator<(), Yield = u32, Return = u32> + Unpin {
61+
//~^ ERROR item has unused generic parameters
6062
|| {
6163
//~^ ERROR item has unused generic parameters
6264
yield 1;

tests/ui/polymorphization/generators.stderr

+17-3
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,34 @@ LL | #![feature(generic_const_exprs, generators, generator_trait, rustc_attrs)]
88
= note: `#[warn(incomplete_features)]` on by default
99

1010
error: item has unused generic parameters
11-
--> $DIR/generators.rs:35:5
11+
--> $DIR/generators.rs:36:5
1212
|
1313
LL | pub fn unused_type<T>() -> impl Generator<(), Yield = u32, Return = u32> + Unpin {
1414
| - generic parameter `T` is unused
15+
LL |
1516
LL | || {
1617
| ^^
1718

1819
error: item has unused generic parameters
19-
--> $DIR/generators.rs:60:5
20+
--> $DIR/generators.rs:34:8
21+
|
22+
LL | pub fn unused_type<T>() -> impl Generator<(), Yield = u32, Return = u32> + Unpin {
23+
| ^^^^^^^^^^^ - generic parameter `T` is unused
24+
25+
error: item has unused generic parameters
26+
--> $DIR/generators.rs:62:5
2027
|
2128
LL | pub fn unused_const<const T: u32>() -> impl Generator<(), Yield = u32, Return = u32> + Unpin {
2229
| ------------ generic parameter `T` is unused
30+
LL |
2331
LL | || {
2432
| ^^
2533

26-
error: aborting due to 2 previous errors; 1 warning emitted
34+
error: item has unused generic parameters
35+
--> $DIR/generators.rs:60:8
36+
|
37+
LL | pub fn unused_const<const T: u32>() -> impl Generator<(), Yield = u32, Return = u32> + Unpin {
38+
| ^^^^^^^^^^^^ ------------ generic parameter `T` is unused
39+
40+
error: aborting due to 4 previous errors; 1 warning emitted
2741

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// build-pass
2+
3+
#![feature(type_alias_impl_trait)]
4+
5+
pub struct Foo {
6+
/// This type must have nontrivial drop glue
7+
field: String,
8+
}
9+
10+
pub type Tait = impl Sized;
11+
12+
pub fn ice_cold(beverage: Tait) {
13+
// Must destructure at least one field of `Foo`
14+
let Foo { field } = beverage;
15+
_ = field;
16+
}
17+
18+
fn main() {}

0 commit comments

Comments
 (0)