-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
const-prop: Restrict scalar pair propagation
We now only propagate a scalar pair if the Rvalue is a tuple with two scalars. This for example avoids propagating a (u8, u8) value when Rvalue has type `((), u8, u8)` (see the regression test). While this is a correct thing to do, implementation is tricky and will be done later. Fixes #66971 Fixes #66339 Fixes #67019
- Loading branch information
Showing
5 changed files
with
130 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// compile-flags: -Z mir-opt-level=2 | ||
|
||
// Due to a bug in propagating scalar pairs the assertion below used to fail. In the expected | ||
// outputs below, after ConstProp this is how _2 would look like with the bug: | ||
// | ||
// _2 = (const Scalar(0x00) : (), const 0u8); | ||
// | ||
// Which has the wrong type. | ||
|
||
fn encode(this: ((), u8, u8)) { | ||
assert!(this.2 == 0); | ||
} | ||
|
||
fn main() { | ||
encode(((), 0, 0)); | ||
} | ||
|
||
// END RUST SOURCE | ||
// START rustc.main.ConstProp.before.mir | ||
// bb0: { | ||
// ... | ||
// _3 = (); | ||
// _2 = (move _3, const 0u8, const 0u8); | ||
// ... | ||
// _1 = const encode(move _2) -> bb1; | ||
// ... | ||
// } | ||
// END rustc.main.ConstProp.before.mir | ||
// START rustc.main.ConstProp.after.mir | ||
// bb0: { | ||
// ... | ||
// _3 = const Scalar(<ZST>) : (); | ||
// _2 = (move _3, const 0u8, const 0u8); | ||
// ... | ||
// _1 = const encode(move _2) -> bb1; | ||
// ... | ||
// } | ||
// END rustc.main.ConstProp.after.mir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// compile-flags: -Z mir-opt-level=2 | ||
|
||
// This used to ICE in const-prop | ||
|
||
fn test(this: ((u8, u8),)) { | ||
assert!((this.0).0 == 1); | ||
} | ||
|
||
fn main() { | ||
test(((1, 2),)); | ||
} | ||
|
||
// Important bit is parameter passing so we only check that below | ||
// END RUST SOURCE | ||
// START rustc.main.ConstProp.before.mir | ||
// bb0: { | ||
// ... | ||
// _3 = (const 1u8, const 2u8); | ||
// _2 = (move _3,); | ||
// ... | ||
// _1 = const test(move _2) -> bb1; | ||
// ... | ||
// } | ||
// END rustc.main.ConstProp.before.mir | ||
// START rustc.main.ConstProp.after.mir | ||
// bb0: { | ||
// ... | ||
// _3 = (const 1u8, const 2u8); | ||
// _2 = (move _3,); | ||
// ... | ||
// _1 = const test(move _2) -> bb1; | ||
// ... | ||
// } | ||
// END rustc.main.ConstProp.after.mir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// compile-flags: -Z mir-opt-level=2 | ||
// build-pass | ||
|
||
// This used to ICE in const-prop | ||
|
||
fn foo() { | ||
let bar = |_| { }; | ||
let _ = bar("a"); | ||
} | ||
|
||
fn main() { | ||
foo(); | ||
} |