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

Miri error reform #69839

Merged
merged 10 commits into from
Mar 19, 2020
Merged

Miri error reform #69839

merged 10 commits into from
Mar 19, 2020

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Mar 8, 2020

Some time ago we started moving Miri errors into a few distinct categories, but we never classified all the old errors. That's what this PR does.

This is on top of #69762; relative diff.

r? @oli-obk

Fixes rust-lang/const-eval#4

@rust-highfive

This comment has been minimized.

@RalfJung RalfJung changed the title Miri error cleanup Miri error reform Mar 9, 2020
@RalfJung RalfJung added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 9, 2020
@@ -4,7 +4,7 @@ error: any use of this value will cause an error
LL | const X: u64 = *wat(42);
| ---------------^^^^^^^^-
| |
| dangling pointer was dereferenced
| pointer to alloc2 was dereferenced after this allocation got freed
Copy link
Contributor

Choose a reason for hiding this comment

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

Exposing alloc IDs to users seems suboptimal

Copy link
Member Author

Choose a reason for hiding this comment

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

Note that other errors exposed alloc IDs already, now it's just more of them.
For Miri I actually find this quite helpful as you can then re-run with "track alloc ID" to figure out when it got deallocated. Maybe there is a way to use formatting flags (like {:?} vs {:#?}) to switch between two different outputs modes for errors?

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use it as pressure to make debugging const eval memory possible for users

@@ -11,7 +11,7 @@ LL | / const MUTATING_BEHIND_RAW: () = {
LL | | // Test that `MUTABLE_BEHIND_RAW` is actually immutable, by doing this at const time.
LL | | unsafe {
LL | | *MUTABLE_BEHIND_RAW = 99
| | ^^^^^^^^^^^^^^^^^^^^^^^^ tried to modify constant memory
| | ^^^^^^^^^^^^^^^^^^^^^^^^ writing to alloc1 which is read-only
Copy link
Contributor

Choose a reason for hiding this comment

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

Exposing alloc IDs to users without that being useful to them until we start dumping allocations, too

@rust-highfive

This comment has been minimized.

@oli-obk
Copy link
Contributor

oli-obk commented Mar 10, 2020

@bors r+

@bors
Copy link
Contributor

bors commented Mar 10, 2020

📌 Commit c0721934187d3ba9353a23454ef1afa068b7c3c4 has been approved by oli-obk

@bors
Copy link
Contributor

bors commented Mar 10, 2020

🌲 The tree is currently closed for pull requests below priority 1000, this pull request will be tested once the tree is reopened

@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 Mar 10, 2020
@bors

This comment has been minimized.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 11, 2020
@RalfJung
Copy link
Member Author

Cc @pietroalbini something seems off, we got a timeout from bors.

@bors retry

@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 Mar 18, 2020
@bors
Copy link
Contributor

bors commented Mar 18, 2020

⌛ Testing commit e219dd4 with merge ec4687af1762d7f369389051b065d4e41d04245a...

Centril added a commit to Centril/rust that referenced this pull request Mar 18, 2020
Miri error reform

Some time ago we started moving Miri errors into a few distinct categories, but we never classified all the old errors. That's what this PR does.

~~This is on top of rust-lang#69762; [relative diff](RalfJung/rust@validity-errors...RalfJung:miri-error-cleanup).~~

r? @oli-obk

Fixes rust-lang/const-eval#4
@Centril
Copy link
Contributor

Centril commented Mar 18, 2020

@bors retry rolled up

@bors
Copy link
Contributor

bors commented Mar 18, 2020

⌛ Testing commit e219dd4 with merge 4ef96cbb98281ba9dff672730026bafdd6bc5092...

Centril added a commit to Centril/rust that referenced this pull request Mar 18, 2020
Miri error reform

Some time ago we started moving Miri errors into a few distinct categories, but we never classified all the old errors. That's what this PR does.

~~This is on top of rust-lang#69762; [relative diff](RalfJung/rust@validity-errors...RalfJung:miri-error-cleanup).~~

r? @oli-obk

Fixes rust-lang/const-eval#4
@Centril
Copy link
Contributor

Centril commented Mar 18, 2020

@bors retry rolled up

pietroalbini added a commit to pietroalbini/rust that referenced this pull request Mar 18, 2020
Rollup of 10 pull requests

Successful merges:

 - rust-lang#67749 (keyword docs for else and inkeyword docs for else and in.)
 - rust-lang#69139 (clean up E0308 explanation)
 - rust-lang#69189 (Erase regions in writeback)
 - rust-lang#69837 (Use smaller discriminants for generators)
 - rust-lang#69838 (Expansion-driven outline module parsing)
 - rust-lang#69839 (Miri error reform)
 - rust-lang#69899 (Make methods declared by `newtype_index` macro `const`)
 - rust-lang#69920 (Remove some imports to the rustc crate)
 - rust-lang#70075 (Fix repr pretty display)
 - rust-lang#70106 (Tidy: fix running rustfmt twice)

Failed merges:

 - rust-lang#70051 (Allow `hir().find` to return `None`)
 - rust-lang#70074 (Expand: nix all fatal errors)

r? @ghost
@bors bors merged commit a958314 into rust-lang:master Mar 19, 2020
bors added a commit to rust-lang/miri that referenced this pull request Mar 19, 2020
rustup for error reform

This is the Miri side of rust-lang/rust#69839.
@@ -296,6 +294,8 @@ pub enum InvalidProgramInfo<'tcx> {
TypeckError,
/// An error occurred during layout computation.
Layout(layout::LayoutError<'tcx>),
/// An invalid transmute happened.
TransmuteSizeDiff(Ty<'tcx>, Ty<'tcx>),
Copy link
Member

Choose a reason for hiding this comment

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

Given transmute checking, can't this be an ICE instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was a bug! once and that was actually reachable, because Miri was run on invalid MIR. Also see

// FIXME: This should be an assert instead of an error, but if we transmute within an
// array length computation, `typeck` may not have yet been run and errored out. In fact
// most likey we *are* running `typeck` right now. Investigate whether we can bail out
// on `typeck_tables().has_errors` at all const eval entry points.
debug!("Size mismatch when transmuting!\nsrc: {:#?}\ndest: {:#?}", src, dest);
throw_inval!(TransmuteSizeDiff(src.layout.ty, dest.layout.ty));

Copy link
Member

@eddyb eddyb Mar 19, 2020

Choose a reason for hiding this comment

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

Oh I see, however:

  1. you can't have MIR built without typeck, it just doesn't stop the compilation (so that comment is somewhat misleading)
  2. I thought typeck_tables().has_errors being true resulted in a fake MIR body
  3. typeck is not at all responsible for this, the check is a MIR pass, which also doesn't stop the compilation I guess, and has no real way of indicating a transmute is bogus

And this is why we have delay_span_bug, for all your "this should error elsewhere, ICE if it never does" needs.

Copy link
Member Author

Choose a reason for hiding this comment

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

delay_span_bug doesn't help, we still need to raise some error to abort interpretation.

Copy link
Member

Choose a reason for hiding this comment

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

delay_span_bug doesn't help, we still need to raise some error to abort interpretation.

Fair enough, and better to be safe than sorry.

@RalfJung RalfJung deleted the miri-error-cleanup branch March 20, 2020 16:12
Centril added a commit to Centril/rust that referenced this pull request Mar 21, 2020
add delay_span_bug to TransmuteSizeDiff, just to be sure

See rust-lang#69839 (comment).

r? @eddyb
Centril added a commit to Centril/rust that referenced this pull request Mar 21, 2020
add delay_span_bug to TransmuteSizeDiff, just to be sure

See rust-lang#69839 (comment).

r? @eddyb
Centril added a commit to Centril/rust that referenced this pull request Mar 21, 2020
do not 'return' in 'throw_' macros

In rust-lang#69839 we turned a closure into a `try` block, but it turns out that does not work with our `throw_` macros, which `return` so they skip the `try`.

Here we fix that. For some reason that means we also have to remove some `;`.

r? @oli-obk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-miri Area: The miri tool 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.

Making enums more specific in src/librustc/mir/interpret/error.rs
6 participants