Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

evaluate required_consts when pushing stack frame in Miri engine #75339

Merged
merged 4 commits into from
Aug 11, 2020

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Aug 9, 2020

Just like codegen, Miri needs to make sure all required_consts evaluate successfully, to catch post-monomorphization errors.

While at it I also moved the const_eval error reporting logic into rustc_mir::const_eval::error; there is no reason it should be in rustc_middle. I kept this in a separate commit for easier reviewing.

Helps with rust-lang/miri#1382. I will add a test on the Miri side (done now: rust-lang/miri#1504).
r? @oli-obk

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 9, 2020
let const_ =
self.subst_from_current_frame_and_normalize_erasing_regions(const_.literal);
self.const_to_op(const_, None)?;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the key new loop.

bors added a commit to rust-lang/miri that referenced this pull request Aug 10, 2020
accept some post-monomorphization errors

Miri test for rust-lang/rust#75339. We also need to allow `ReferencedConstant` post-monomorphization errors. The other post-monomorphization errors should still be impossible to trigger in Miri.

Fixes #1382.
bors added a commit to rust-lang/miri that referenced this pull request Aug 10, 2020
accept some post-monomorphization errors

For #1382, we also need to allow `ReferencedConstant` post-monomorphization errors. The other post-monomorphization errors should still be impossible to trigger in Miri. The fix is not complete though without rust-lang/rust#75339.
@oli-obk
Copy link
Contributor

oli-obk commented Aug 10, 2020

#![warn(const_err, unconditional_panic)]

struct PrintName<T>(T);
impl<T> PrintName<T> {
    const VOID: () = [()][2]; //~WARN any use of this value will cause an error
}

const fn no_codegen<T>() {
    if false {
        let _ = PrintName::<T>::VOID; //~ERROR referenced constant has errors
    }
}

pub static FOO: () = no_codegen::<i32>();

fn main() {
    FOO
}

works on beta, so we should probably beta backport this (and add the above as a test).

The beta backport should not contain the first commit though

@oli-obk oli-obk added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Aug 10, 2020
@RalfJung
Copy link
Member Author

I don't see why this should be beta-backported -- it's an ooold bug for that to work.

@oli-obk
Copy link
Contributor

oli-obk commented Aug 10, 2020

it's an ooold bug for that to work.

not really, before this beta there was no conditional execution. So the constant was always evaluated unless optimized out... ok... true, we used to optimize them out. So nevermind on the beta nomination, but the test should still be in this repo, not just in miri

@oli-obk oli-obk removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Aug 10, 2020
@oli-obk
Copy link
Contributor

oli-obk commented Aug 10, 2020

So this is a breaking change, but only if your code was UB anyway

@RalfJung
Copy link
Member Author

So this is a breaking change, but only if your code was UB anyway

It is, just like the corresponding change in codegen was a breaking change.
I am not sure if the old code was UB (dead code cannot cause UB), but it is a bug that we fixed for codegen and should likewise fix for CTFE.

the test should still be in this repo, not just in miri

Fair, I'll add it.

@RalfJung
Copy link
Member Author

@oli-obk I added a test.

@oli-obk
Copy link
Contributor

oli-obk commented Aug 10, 2020

@bors r+

@bors
Copy link
Contributor

bors commented Aug 10, 2020

📌 Commit fd3851a has been approved by oli-obk

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 10, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 11, 2020
Rollup of 10 pull requests

Successful merges:

 - rust-lang#75098 (Clippy pointer cast lint experiment)
 - rust-lang#75249 (Only add a border for the rust logo)
 - rust-lang#75315 (Avoid deleting temporary files on error)
 - rust-lang#75316 (Don't try to use wasm intrinsics on vectors)
 - rust-lang#75337 (instance: only polymorphize upvar substs)
 - rust-lang#75339 (evaluate required_consts when pushing stack frame in Miri engine)
 - rust-lang#75363 (Use existing `infcx` when emitting trait impl diagnostic)
 - rust-lang#75366 (Add help button)
 - rust-lang#75369 (Move to intra-doc links in /library/core/src/borrow.rs)
 - rust-lang#75379 (Use intra-doc links in /library/core/src/cmp.rs)

Failed merges:

r? @ghost
@bors bors merged commit 9edec57 into rust-lang:master Aug 11, 2020
@RalfJung RalfJung deleted the eval-required branch August 11, 2020 07:06
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 12, 2020
Miri: improve spans of required_const failures

In rust-lang#75339 I added a loop evaluating all consts required by a function body. Unfortunately, if one of their evaluations fails, then the span used for that was that of the first statement in the function body, which happened to work form some existing test but is not sensible in general.

This PR changes it to point to the whole function instead, which is at least not wrong.

r? @oli-obk
bors added a commit to rust-lang/miri that referenced this pull request Aug 13, 2020
add test for unused ill-formed constant

Once rust-lang/rust#75339 lands, this test should pass.

Fixes #1382.
@cuviper cuviper added this to the 1.47.0 milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants