-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #122258 - RalfJung:required-fns, r=<try>
Draft: monomorphize things from dead code, too This is another attempt at fixing #107503. The previous attempt at #112879 seems stuck in figuring out where the [perf regression](https://perf.rust-lang.org/compare.html?start=c55d1ee8d4e3162187214692229a63c2cc5e0f31&end=ec8de1ebe0d698b109beeaaac83e60f4ef8bb7d1&stat=instructions:u) comes from. So here I want to take baby steps to see the impact of each step. r? `@ghost`
- Loading branch information
Showing
27 changed files
with
389 additions
and
73 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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
tests/ui/consts/const-eval/unused-broken-const-late.stderr
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
tests/ui/consts/required-consts/dead-code-in-called-fn.no-opt.stderr
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 @@ | ||
error[E0080]: evaluation of `Fail::<i32>::C` failed | ||
--> $DIR/dead-code-in-called-fn.rs:9:19 | ||
| | ||
LL | const C: () = panic!(); | ||
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/dead-code-in-called-fn.rs:9:19 | ||
| | ||
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
note: the above error was encountered while instantiating `fn called::<i32>` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
13 changes: 13 additions & 0 deletions
13
tests/ui/consts/required-consts/dead-code-in-called-fn.opt.stderr
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 @@ | ||
error[E0080]: evaluation of `Fail::<i32>::C` failed | ||
--> $DIR/dead-code-in-called-fn.rs:9:19 | ||
| | ||
LL | const C: () = panic!(); | ||
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/dead-code-in-called-fn.rs:9:19 | ||
| | ||
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
note: the above error was encountered while instantiating `fn called::<i32>` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
18 changes: 11 additions & 7 deletions
18
...ts/const-eval/unused-broken-const-late.rs → ...required-consts/dead-code-in-called-fn.rs
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 |
---|---|---|
@@ -1,20 +1,24 @@ | ||
//@revisions: opt no-opt | ||
//@ build-fail | ||
//@ compile-flags: -O | ||
//@[opt] compile-flags: -O | ||
//! Make sure we detect erroneous constants post-monomorphization even when they are unused. This is | ||
//! crucial, people rely on it for soundness. (https://github.com/rust-lang/rust/issues/112090) | ||
struct PrintName<T>(T); | ||
impl<T> PrintName<T> { | ||
const VOID: () = panic!(); //~ERROR evaluation of `PrintName::<i32>::VOID` failed | ||
struct Fail<T>(T); | ||
impl<T> Fail<T> { | ||
const C: () = panic!(); //~ERROR evaluation of `Fail::<i32>::C` failed | ||
} | ||
|
||
fn no_codegen<T>() { | ||
#[inline(never)] | ||
fn called<T>() { | ||
// Any function that is called is guaranteed to have all consts that syntactically | ||
// appear in its body evaluated, even if they only appear in dead code. | ||
// This relies on mono-item collection checking `required_consts` in collected functions. | ||
if false { | ||
let _ = PrintName::<T>::VOID; | ||
let _ = Fail::<T>::C; | ||
} | ||
} | ||
|
||
pub fn main() { | ||
no_codegen::<i32>(); | ||
called::<i32>(); | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/ui/consts/required-consts/dead-code-in-const-called-fn.no-opt.stderr
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,17 @@ | ||
error[E0080]: evaluation of `Fail::<i32>::C` failed | ||
--> $DIR/dead-code-in-const-called-fn.rs:8:19 | ||
| | ||
LL | const C: () = panic!(); | ||
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/dead-code-in-const-called-fn.rs:8:19 | ||
| | ||
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
note: erroneous constant encountered | ||
--> $DIR/dead-code-in-const-called-fn.rs:17:9 | ||
| | ||
LL | Fail::<T>::C; | ||
| ^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
17 changes: 17 additions & 0 deletions
17
tests/ui/consts/required-consts/dead-code-in-const-called-fn.opt.stderr
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,17 @@ | ||
error[E0080]: evaluation of `Fail::<i32>::C` failed | ||
--> $DIR/dead-code-in-const-called-fn.rs:8:19 | ||
| | ||
LL | const C: () = panic!(); | ||
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/dead-code-in-const-called-fn.rs:8:19 | ||
| | ||
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
note: erroneous constant encountered | ||
--> $DIR/dead-code-in-const-called-fn.rs:17:9 | ||
| | ||
LL | Fail::<T>::C; | ||
| ^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
12 changes: 8 additions & 4 deletions
12
...s/ui/consts/const-eval/erroneous-const.rs → ...ed-consts/dead-code-in-const-called-fn.rs
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
14 changes: 14 additions & 0 deletions
14
tests/ui/consts/required-consts/dead-code-in-dead-drop.no-opt.stderr
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,14 @@ | ||
error[E0080]: evaluation of `Fail::<i32>::C` failed | ||
--> $DIR/dead-code-in-dead-drop.rs:9:19 | ||
| | ||
LL | const C: () = panic!(); | ||
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/dead-code-in-dead-drop.rs:9:19 | ||
| | ||
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
note: the above error was encountered while instantiating `fn <Fail<i32> as std::ops::Drop>::drop` | ||
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
Oops, something went wrong.