Skip to content

Commit

Permalink
move subtyper change reveal_all
Browse files Browse the repository at this point in the history
  • Loading branch information
ouz-a committed Oct 4, 2023
1 parent e3c631b commit 8bc1355
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ impl<'a, 'tcx> MutVisitor<'tcx> for SubTypeChecker<'a, 'tcx> {
rvalue: &mut Rvalue<'tcx>,
location: Location,
) {
if self.local_decls[place.local].internal {
return;
}
let mut place_ty = place.ty(self.local_decls, self.tcx).ty;
let mut rval_ty = rvalue.ty(self.local_decls, self.tcx);
// Not erasing this causes `Free Regions` errors in validator,
Expand All @@ -48,7 +51,6 @@ impl<'a, 'tcx> MutVisitor<'tcx> for SubTypeChecker<'a, 'tcx> {
// // gets transformed to
// let temp: rval_ty = rval;
// let place: place_ty = temp as place_ty;
//
pub fn subtype_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
let patch = MirPatch::new(body);
let mut checker = SubTypeChecker { tcx, patcher: patch, local_decls: &body.local_decls };
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,6 @@ pub fn run_analysis_to_runtime_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'
/// After this series of passes, no lifetime analysis based on borrowing can be done.
fn run_analysis_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
let passes: &[&dyn MirPass<'tcx>] = &[
&add_subtyping_projections::Subtyper,
&cleanup_post_borrowck::CleanupPostBorrowck,
&remove_noop_landing_pads::RemoveNoopLandingPads,
&simplify::SimplifyCfg::EarlyOpt,
Expand All @@ -483,6 +482,7 @@ fn run_runtime_lowering_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
// These next passes must be executed together
&add_call_guards::CriticalCallEdges,
&reveal_all::RevealAll, // has to be done before drop elaboration, since we need to drop opaque types, too.
&add_subtyping_projections::Subtyper,
&elaborate_drops::ElaborateDrops,
// This will remove extraneous landing pads which are no longer
// necessary as well as well as forcing any call in a non-unwinding
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_mir_transform/src/reveal_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl<'tcx> MutVisitor<'tcx> for RevealAllVisitor<'tcx> {
.filter(|elem| !matches!(elem, ProjectionElem::OpaqueCast(_)))
.collect::<Vec<_>>(),
);
self.super_place(place, _context, _location);
}

#[inline]
Expand Down
48 changes: 22 additions & 26 deletions tests/mir-opt/inline/inline_generator.main.Inline.panic-abort.diff
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
let mut _2: std::pin::Pin<&mut {generator@$DIR/inline_generator.rs:16:5: 16:8}>;
let mut _3: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8};
let mut _4: {generator@$DIR/inline_generator.rs:16:5: 16:8};
+ let mut _6: bool;
+ let mut _5: bool;
scope 1 {
debug _r => _1;
}
+ scope 2 (inlined g) {
+ let mut _5: {generator@$DIR/inline_generator.rs:16:5: 16:8};
+ }
+ scope 3 (inlined Pin::<&mut {generator@$DIR/inline_generator.rs:16:5: 16:8}>::new) {
+ debug pointer => _3;
Expand All @@ -23,10 +22,10 @@
+ }
+ }
+ scope 6 (inlined g::{closure#0}) {
+ debug a => _6;
+ let mut _7: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8};
+ let mut _8: u32;
+ let mut _9: i32;
+ debug a => _5;
+ let mut _6: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8};
+ let mut _7: u32;
+ let mut _8: i32;
+ }

bb0: {
Expand All @@ -35,24 +34,21 @@
StorageLive(_3);
StorageLive(_4);
- _4 = g() -> [return: bb1, unwind unreachable];
+ StorageLive(_5);
+ _5 = {generator@$DIR/inline_generator.rs:16:5: 16:8 (#0)};
+ _4 = move (_5 as subtype {generator@$DIR/inline_generator.rs:16:5: 16:8});
+ StorageDead(_5);
+ _4 = {generator@$DIR/inline_generator.rs:16:5: 16:8 (#0)};
+ _3 = &mut _4;
+ _2 = Pin::<&mut {generator@$DIR/inline_generator.rs:16:5: 16:8}> { pointer: move _3 };
+ StorageDead(_3);
+ StorageLive(_6);
+ _6 = const false;
+ _7 = (_2.0: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8});
+ _8 = discriminant((*_7));
+ switchInt(move _8) -> [0: bb3, 1: bb7, 3: bb8, otherwise: bb9];
+ StorageLive(_5);
+ _5 = const false;
+ _6 = (_2.0: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8});
+ _7 = discriminant((*_6));
+ switchInt(move _7) -> [0: bb3, 1: bb7, 3: bb8, otherwise: bb9];
}

bb1: {
- _3 = &mut _4;
- _2 = Pin::<&mut {generator@$DIR/inline_generator.rs:16:5: 16:8}>::new(move _3) -> [return: bb2, unwind unreachable];
+ StorageDead(_6);
+ StorageDead(_5);
+ StorageDead(_2);
+ drop(_4) -> [return: bb2, unwind unreachable];
}
Expand All @@ -69,27 +65,27 @@
bb3: {
- StorageDead(_2);
- drop(_4) -> [return: bb4, unwind unreachable];
+ StorageLive(_9);
+ switchInt(_6) -> [0: bb4, otherwise: bb5];
+ StorageLive(_8);
+ switchInt(_5) -> [0: bb4, otherwise: bb5];
}

bb4: {
- StorageDead(_4);
- _0 = const ();
- StorageDead(_1);
- return;
+ _9 = const 13_i32;
+ _8 = const 13_i32;
+ goto -> bb6;
+ }
+
+ bb5: {
+ _9 = const 7_i32;
+ _8 = const 7_i32;
+ goto -> bb6;
+ }
+
+ bb6: {
+ _1 = GeneratorState::<i32, bool>::Yielded(move _9);
+ discriminant((*_7)) = 3;
+ _1 = GeneratorState::<i32, bool>::Yielded(move _8);
+ discriminant((*_6)) = 3;
+ goto -> bb1;
+ }
+
Expand All @@ -98,10 +94,10 @@
+ }
+
+ bb8: {
+ StorageLive(_9);
+ StorageDead(_9);
+ _1 = GeneratorState::<i32, bool>::Complete(_6);
+ discriminant((*_7)) = 1;
+ StorageLive(_8);
+ StorageDead(_8);
+ _1 = GeneratorState::<i32, bool>::Complete(_5);
+ discriminant((*_6)) = 1;
+ goto -> bb1;
+ }
+
Expand Down
48 changes: 22 additions & 26 deletions tests/mir-opt/inline/inline_generator.main.Inline.panic-unwind.diff
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
let mut _2: std::pin::Pin<&mut {generator@$DIR/inline_generator.rs:16:5: 16:8}>;
let mut _3: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8};
let mut _4: {generator@$DIR/inline_generator.rs:16:5: 16:8};
+ let mut _6: bool;
+ let mut _5: bool;
scope 1 {
debug _r => _1;
}
+ scope 2 (inlined g) {
+ let mut _5: {generator@$DIR/inline_generator.rs:16:5: 16:8};
+ }
+ scope 3 (inlined Pin::<&mut {generator@$DIR/inline_generator.rs:16:5: 16:8}>::new) {
+ debug pointer => _3;
Expand All @@ -23,10 +22,10 @@
+ }
+ }
+ scope 6 (inlined g::{closure#0}) {
+ debug a => _6;
+ let mut _7: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8};
+ let mut _8: u32;
+ let mut _9: i32;
+ debug a => _5;
+ let mut _6: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8};
+ let mut _7: u32;
+ let mut _8: i32;
+ }

bb0: {
Expand All @@ -38,10 +37,7 @@
- }
-
- bb1: {
+ StorageLive(_5);
+ _5 = {generator@$DIR/inline_generator.rs:16:5: 16:8 (#0)};
+ _4 = move (_5 as subtype {generator@$DIR/inline_generator.rs:16:5: 16:8});
+ StorageDead(_5);
+ _4 = {generator@$DIR/inline_generator.rs:16:5: 16:8 (#0)};
_3 = &mut _4;
- _2 = Pin::<&mut {generator@$DIR/inline_generator.rs:16:5: 16:8}>::new(move _3) -> [return: bb2, unwind: bb5];
- }
Expand All @@ -50,16 +46,16 @@
+ _2 = Pin::<&mut {generator@$DIR/inline_generator.rs:16:5: 16:8}> { pointer: move _3 };
StorageDead(_3);
- _1 = <{generator@$DIR/inline_generator.rs:16:5: 16:8} as Generator<bool>>::resume(move _2, const false) -> [return: bb3, unwind: bb5];
+ StorageLive(_6);
+ _6 = const false;
+ _7 = (_2.0: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8});
+ _8 = discriminant((*_7));
+ switchInt(move _8) -> [0: bb5, 1: bb9, 3: bb10, otherwise: bb11];
+ StorageLive(_5);
+ _5 = const false;
+ _6 = (_2.0: &mut {generator@$DIR/inline_generator.rs:16:5: 16:8});
+ _7 = discriminant((*_6));
+ switchInt(move _7) -> [0: bb5, 1: bb9, 3: bb10, otherwise: bb11];
}

- bb3: {
+ bb1: {
+ StorageDead(_6);
+ StorageDead(_5);
StorageDead(_2);
- drop(_4) -> [return: bb4, unwind: bb6];
+ drop(_4) -> [return: bb2, unwind: bb4];
Expand All @@ -85,23 +81,23 @@
+ }
+
+ bb5: {
+ StorageLive(_9);
+ switchInt(_6) -> [0: bb6, otherwise: bb7];
+ StorageLive(_8);
+ switchInt(_5) -> [0: bb6, otherwise: bb7];
+ }
+
+ bb6: {
+ _9 = const 13_i32;
+ _8 = const 13_i32;
+ goto -> bb8;
+ }
+
+ bb7: {
+ _9 = const 7_i32;
+ _8 = const 7_i32;
+ goto -> bb8;
+ }
+
+ bb8: {
+ _1 = GeneratorState::<i32, bool>::Yielded(move _9);
+ discriminant((*_7)) = 3;
+ _1 = GeneratorState::<i32, bool>::Yielded(move _8);
+ discriminant((*_6)) = 3;
+ goto -> bb1;
+ }
+
Expand All @@ -110,10 +106,10 @@
+ }
+
+ bb10: {
+ StorageLive(_9);
+ StorageDead(_9);
+ _1 = GeneratorState::<i32, bool>::Complete(_6);
+ discriminant((*_7)) = 1;
+ StorageLive(_8);
+ StorageDead(_8);
+ _1 = GeneratorState::<i32, bool>::Complete(_5);
+ discriminant((*_6)) = 1;
+ goto -> bb1;
+ }
+
Expand Down
32 changes: 32 additions & 0 deletions tests/ui/type-alias-impl-trait/normalize-alias-type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// check-pass
// compile-flags: -Z mir-opt-level=3
#![feature(type_alias_impl_trait)]
#![crate_type = "lib"]
pub trait Tr {
fn get(&self) -> u32;
}

impl Tr for (u32,) {
#[inline]
fn get(&self) -> u32 { self.0 }
}

pub fn tr1() -> impl Tr {
(32,)
}

pub fn tr2() -> impl Tr {
struct Inner {
x: X,
}
type X = impl Tr;
impl Tr for Inner {
fn get(&self) -> u32 {
self.x.get()
}
}

Inner {
x: tr1(),
}
}
14 changes: 14 additions & 0 deletions tests/ui/type-alias-impl-trait/tait-normalize.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// check-pass

#![feature(type_alias_impl_trait)]

fn enum_upvar() {
type T = impl Copy;
let foo: T = Some((1u32, 2u32));
let x = move || match foo {
None => (),
Some((a, b)) => (),
};
}

fn main(){}
19 changes: 19 additions & 0 deletions tests/ui/type/subtyping-opaque-type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// check-pass
// compile-flags: -Zvalidate-mir
trait Duh {}

impl Duh for i32 {}

trait Trait {
type Assoc: Duh;
}

impl<R: Duh, F: FnMut() -> R> Trait for F {
type Assoc = R;
}

fn foo() -> impl Trait<Assoc = impl Send> {
|| 42
}

fn main() {}

0 comments on commit 8bc1355

Please sign in to comment.