Skip to content

Commit

Permalink
rescope temp lifetime in let-chain into IfElse
Browse files Browse the repository at this point in the history
  • Loading branch information
dingxiangfei2009 committed Oct 22, 2023
1 parent 6aeac60 commit 882adea
Show file tree
Hide file tree
Showing 19 changed files with 76 additions and 62 deletions.
9 changes: 8 additions & 1 deletion compiler/rustc_middle/src/ty/rvalue_scopes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ impl RvalueScopes {
debug!("temporary_scope({expr_id:?}) = {id:?} [enclosing]");
return Some(id);
}
_ => id = p,
ScopeData::IfThen => {
debug!("temporary_scope({expr_id:?}) = {p:?} [enclosing]");
return Some(p);
}
ScopeData::Node
| ScopeData::CallSite
| ScopeData::Arguments
| ScopeData::Remainder(_) => id = p,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn test_complex() -> () {
bb0: {
StorageLive(_1);
StorageLive(_2);
_2 = E::f() -> [return: bb1, unwind: bb31];
_2 = E::f() -> [return: bb1, unwind: bb32];
}

bb1: {
Expand All @@ -38,7 +38,7 @@ fn test_complex() -> () {

bb4: {
StorageLive(_4);
_4 = always_true() -> [return: bb5, unwind: bb31];
_4 = always_true() -> [return: bb5, unwind: bb32];
}

bb5: {
Expand All @@ -60,7 +60,7 @@ fn test_complex() -> () {
}

bb8: {
drop(_7) -> [return: bb10, unwind: bb31];
drop(_7) -> [return: bb10, unwind: bb32];
}

bb9: {
Expand All @@ -74,7 +74,7 @@ fn test_complex() -> () {
}

bb11: {
drop(_7) -> [return: bb12, unwind: bb31];
drop(_7) -> [return: bb12, unwind: bb32];
}

bb12: {
Expand All @@ -94,7 +94,7 @@ fn test_complex() -> () {
}

bb14: {
drop(_10) -> [return: bb16, unwind: bb31];
drop(_10) -> [return: bb16, unwind: bb32];
}

bb15: {
Expand All @@ -105,11 +105,12 @@ fn test_complex() -> () {
StorageDead(_10);
StorageDead(_9);
_1 = const ();
StorageDead(_2);
goto -> bb20;
}

bb17: {
drop(_10) -> [return: bb18, unwind: bb31];
drop(_10) -> [return: bb18, unwind: bb32];
}

bb18: {
Expand All @@ -119,6 +120,7 @@ fn test_complex() -> () {
}

bb19: {
StorageDead(_2);
_1 = const ();
goto -> bb20;
}
Expand All @@ -127,18 +129,17 @@ fn test_complex() -> () {
StorageDead(_8);
StorageDead(_5);
StorageDead(_4);
StorageDead(_2);
StorageDead(_1);
StorageLive(_11);
_11 = always_true() -> [return: bb21, unwind: bb31];
_11 = always_true() -> [return: bb21, unwind: bb32];
}

bb21: {
switchInt(move _11) -> [0: bb23, otherwise: bb22];
}

bb22: {
goto -> bb29;
goto -> bb30;
}

bb23: {
Expand All @@ -147,7 +148,7 @@ fn test_complex() -> () {

bb24: {
StorageLive(_12);
_12 = E::f() -> [return: bb25, unwind: bb31];
_12 = E::f() -> [return: bb25, unwind: bb32];
}

bb25: {
Expand All @@ -166,21 +167,26 @@ fn test_complex() -> () {

bb28: {
_0 = const ();
goto -> bb30;
StorageDead(_12);
goto -> bb31;
}

bb29: {
_0 = const ();
StorageDead(_12);
goto -> bb30;
}

bb30: {
_0 = const ();
goto -> bb31;
}

bb31: {
StorageDead(_11);
StorageDead(_12);
return;
}

bb31 (cleanup): {
bb32 (cleanup): {
resume;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,19 @@

bb2: {
_2 = const 42_i32;
StorageDead(_3);
goto -> bb4;
}

bb3: {
StorageDead(_3);
_2 = const 10_i32;
goto -> bb4;
}

bb4: {
_1 = Add(move _2, const 0_i32);
StorageDead(_2);
StorageDead(_3);
_0 = const ();
StorageDead(_1);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,19 @@

bb2: {
_2 = const 42_i32;
StorageDead(_3);
goto -> bb4;
}

bb3: {
StorageDead(_3);
_2 = const 10_i32;
goto -> bb4;
}

bb4: {
_1 = Add(move _2, const 0_i32);
StorageDead(_2);
StorageDead(_3);
_0 = const ();
StorageDead(_1);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,19 @@
bb2: {
_1 = const 1_i32;
_0 = const ();
StorageDead(_3);
goto -> bb4;
}

bb3: {
StorageDead(_3);
StorageLive(_7);
_0 = const ();
StorageDead(_7);
goto -> bb4;
}

bb4: {
StorageDead(_3);
StorageDead(_1);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@
bb5: {
StorageDead(_12);
StorageDead(_11);
StorageDead(_6);
goto -> bb8;
}

bb6: {
StorageDead(_6);
StorageLive(_18);
_18 = _5;
_0 = float_to_exponential_common_shortest::<T>(_1, _2, move _18, _3) -> [return: bb7, unwind unreachable];
Expand All @@ -104,7 +106,6 @@
bb8: {
StorageDead(_5);
StorageDead(_4);
StorageDead(_6);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@
bb5: {
StorageDead(_12);
StorageDead(_11);
StorageDead(_6);
goto -> bb8;
}

bb6: {
StorageDead(_6);
StorageLive(_18);
_18 = _5;
_0 = float_to_exponential_common_shortest::<T>(_1, _2, move _18, _3) -> [return: bb7, unwind continue];
Expand All @@ -104,7 +106,6 @@
bb8: {
StorageDead(_5);
StorageDead(_4);
StorageDead(_6);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,19 @@
StorageDead(_21);
StorageDead(_20);
StorageDead(_19);
- StorageDead(_12);
- StorageDead(_11);
goto -> bb8;
}

bb7: {
- StorageDead(_12);
- StorageDead(_11);
- _10 = const ();
goto -> bb8;
}

bb8: {
- StorageDead(_12);
- StorageDead(_11);
- StorageDead(_10);
StorageLive(_22);
StorageLive(_23);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
StorageLive(_6);
_6 = (((_1.0: std::option::Option<u8>) as Some).0: u8);
StorageDead(_6);
goto -> bb3;
drop(_1) -> [return: bb5, unwind unreachable];
}

bb3: {
Expand All @@ -44,6 +44,15 @@

bb4: {
StorageDead(_1);
goto -> bb6;
}

bb5: {
StorageDead(_1);
goto -> bb6;
}

bb6: {
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
StorageLive(_6);
_6 = (((_1.0: std::option::Option<u8>) as Some).0: u8);
StorageDead(_6);
goto -> bb3;
drop(_1) -> [return: bb5, unwind continue];
}

bb3: {
Expand All @@ -44,6 +44,15 @@

bb4: {
StorageDead(_1);
goto -> bb6;
}

bb5: {
StorageDead(_1);
goto -> bb6;
}

bb6: {
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@
_5 = ((_2 as Some).0: usize);
_0 = _5;
StorageDead(_5);
StorageDead(_2);
goto -> bb3;
}

bb2: {
StorageDead(_2);
_0 = const 0_usize;
goto -> bb3;
}

bb3: {
StorageDead(_2);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@

- bb6: {
+ bb3: {
_0 = const ();
StorageDead(_1);
_0 = const ();
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@

- bb6: {
+ bb3: {
_0 = const ();
StorageDead(_1);
_0 = const ();
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
}

bb6: {
StorageDead(_2);
_0 = const ();
StorageDead(_1);
StorageDead(_2);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
}

bb6: {
StorageDead(_2);
_0 = const ();
StorageDead(_1);
StorageDead(_2);
return;
}
}
Expand Down
Loading

0 comments on commit 882adea

Please sign in to comment.