-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
collector: always consider all monomorphic functions to be 'mentioned'
- Loading branch information
Showing
9 changed files
with
232 additions
and
33 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
23 changes: 23 additions & 0 deletions
23
tests/ui/consts/required-consts/collect-roots-dead-fn.noopt.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,23 @@ | ||
error[E0080]: evaluation of `Fail::<i32>::C` failed | ||
--> $DIR/collect-roots-dead-fn.rs:12:19 | ||
| | ||
LL | const C: () = panic!(); | ||
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-roots-dead-fn.rs:12: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/collect-roots-dead-fn.rs:25:5 | ||
| | ||
LL | Fail::<T>::C; | ||
| ^^^^^^^^^^^^ | ||
|
||
note: the above error was encountered while instantiating `fn h::<i32>` | ||
--> $DIR/collect-roots-dead-fn.rs:21:5 | ||
| | ||
LL | h::<i32>() | ||
| ^^^^^^^^^^ | ||
|
||
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/collect-roots-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,17 @@ | ||
error[E0080]: evaluation of `Fail::<i32>::C` failed | ||
--> $DIR/collect-roots-dead-fn.rs:12:19 | ||
| | ||
LL | const C: () = panic!(); | ||
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-roots-dead-fn.rs:12: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/collect-roots-dead-fn.rs:25:5 | ||
| | ||
LL | Fail::<T>::C; | ||
| ^^^^^^^^^^^^ | ||
|
||
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,29 @@ | ||
//@revisions: noopt opt | ||
//@ build-fail | ||
//@[noopt] compile-flags: -Copt-level=0 | ||
//@[opt] compile-flags: -O | ||
|
||
//! This used to fail in optimized builds but pass in unoptimized builds. The reason is that in | ||
//! optimized builds, `f` gets marked as cross-crate-inlineable, so the functions it calls become | ||
//! reachable, and therefore `g` becomes a collection root. But in unoptimized builds, `g` is no | ||
//! root, and the call to `g` disappears in an early `SimplifyCfg` before "mentoned items" are | ||
//! gathered, so we never reach `g`. | ||
#![crate_type = "lib"] | ||
|
||
struct Fail<T>(T); | ||
impl<T> Fail<T> { | ||
const C: () = panic!(); //~ERROR: evaluation of `Fail::<i32>::C` failed | ||
} | ||
|
||
pub fn f() { | ||
loop {}; g() | ||
} | ||
|
||
#[inline(never)] | ||
fn g() { | ||
h::<i32>() | ||
} | ||
|
||
fn h<T>() { | ||
Fail::<T>::C; | ||
} |
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,23 @@ | ||
//@revisions: noopt opt | ||
//@ build-pass | ||
//@[noopt] compile-flags: -Copt-level=0 | ||
//@[opt] compile-flags: -O | ||
|
||
//! A slight variant of `collect-roots-in-dead-fn` where the dead call is itself generic. Now this | ||
//! *passes* in both optimized and unoptimized builds: the call to `h` always disappears in an early | ||
//! `SimplifyCfg`, and `h` is generic so it can never be a root. | ||
#![crate_type = "lib"] | ||
|
||
struct Fail<T>(T); | ||
impl<T> Fail<T> { | ||
const C: () = panic!(); | ||
} | ||
|
||
pub fn f() { | ||
loop {}; h::<i32>() | ||
} | ||
|
||
#[inline(never)] | ||
fn h<T>() { | ||
Fail::<T>::C; | ||
} |
23 changes: 23 additions & 0 deletions
23
tests/ui/consts/required-consts/collect-roots-inline-fn.noopt.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,23 @@ | ||
error[E0080]: evaluation of `Zst::<u32>::ASSERT` failed | ||
--> $DIR/collect-roots-inline-fn.rs:13:9 | ||
| | ||
LL | panic!(); | ||
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-roots-inline-fn.rs:13:9 | ||
| | ||
= 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/collect-roots-inline-fn.rs:18:5 | ||
| | ||
LL | Zst::<T>::ASSERT; | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
note: the above error was encountered while instantiating `fn f::<u32>` | ||
--> $DIR/collect-roots-inline-fn.rs:22:5 | ||
| | ||
LL | f::<u32>() | ||
| ^^^^^^^^^^ | ||
|
||
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/collect-roots-inline-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 `Zst::<u32>::ASSERT` failed | ||
--> $DIR/collect-roots-inline-fn.rs:13:9 | ||
| | ||
LL | panic!(); | ||
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-roots-inline-fn.rs:13:9 | ||
| | ||
= 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/collect-roots-inline-fn.rs:18:5 | ||
| | ||
LL | Zst::<T>::ASSERT; | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
23 changes: 23 additions & 0 deletions
23
tests/ui/consts/required-consts/collect-roots-inline-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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//@revisions: noopt opt | ||
//@ build-fail | ||
//@[noopt] compile-flags: -Copt-level=0 | ||
//@[opt] compile-flags: -O | ||
|
||
//! In optimized builds, the functions in this crate are all marked "inline" so none of them become | ||
//! collector roots. Ensure that we still evaluate the constants. | ||
#![crate_type = "lib"] | ||
|
||
struct Zst<T>(T); | ||
impl<T> Zst<T> { | ||
const ASSERT: () = if std::mem::size_of::<T>() != 0 { | ||
panic!(); //~ERROR: evaluation of `Zst::<u32>::ASSERT` failed | ||
}; | ||
} | ||
|
||
fn f<T>() { | ||
Zst::<T>::ASSERT; | ||
} | ||
|
||
pub fn g() { | ||
f::<u32>() | ||
} |