forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
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 rust-lang#122258 - RalfJung:required-fns, r=<try>
Draft: monomorphize things from dead code, too This is another attempt at fixing rust-lang#107503. The previous attempt at rust-lang#112879 seems stuck in figuring out where the perf regression comes from. So here I want to take baby steps to see the impact of each step. r? `@ghost`
- Loading branch information
Showing
21 changed files
with
251 additions
and
70 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 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/monomorphization/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/monomorphization/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`. |
17 changes: 10 additions & 7 deletions
17
...ts/const-eval/unused-broken-const-late.rs → ...onomorphization/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,23 @@ | ||
//@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. | ||
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/monomorphization/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:16: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/monomorphization/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:16:9 | ||
| | ||
LL | Fail::<T>::C; | ||
| ^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
11 changes: 7 additions & 4 deletions
11
...s/ui/consts/const-eval/erroneous-const.rs → ...phization/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
13 changes: 13 additions & 0 deletions
13
tests/ui/consts/monomorphization/dead-code-in-dead-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-dead-fn.rs:9:19 | ||
| | ||
LL | const C: () = panic!(); | ||
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/dead-code-in-dead-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 not_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/monomorphization/dead-code-in-dead-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-dead-fn.rs:9:19 | ||
| | ||
LL | const C: () = panic!(); | ||
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/dead-code-in-dead-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 not_called::<i32>` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
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,28 @@ | ||
//@revisions: opt no-opt | ||
//@ build-fail | ||
//@[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 Fail<T>(T); | ||
impl<T> Fail<T> { | ||
const C: () = panic!(); //~ERROR evaluation of `Fail::<i32>::C` failed | ||
} | ||
|
||
// This function is not actually called, but it is mentioned in a function that is called. | ||
// Make sure we still find this error. | ||
#[inline(never)] | ||
fn not_called<T>() { | ||
let _ = Fail::<T>::C; | ||
} | ||
|
||
#[inline(never)] | ||
fn called<T>() { | ||
if false { | ||
not_called::<T>(); | ||
} | ||
} | ||
|
||
pub fn main() { | ||
called::<i32>(); | ||
} |
Oops, something went wrong.