-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Miri error reform #69839
Conversation
This comment has been minimized.
This comment has been minimized.
1b89adc
to
37b355f
Compare
@@ -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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
This comment has been minimized.
This comment has been minimized.
593cde1
to
c072193
Compare
@bors r+ |
📌 Commit c0721934187d3ba9353a23454ef1afa068b7c3c4 has been approved by |
🌲 The tree is currently closed for pull requests below priority 1000, this pull request will be tested once the tree is reopened |
This comment has been minimized.
This comment has been minimized.
Also slightly refactor pointer bounds checks to avoid creating unnecessary temporary Errors
Cc @pietroalbini something seems off, we got a timeout from bors. @bors retry |
⌛ Testing commit e219dd4 with merge ec4687af1762d7f369389051b065d4e41d04245a... |
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
@bors retry rolled up |
⌛ Testing commit e219dd4 with merge 4ef96cbb98281ba9dff672730026bafdd6bc5092... |
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
@bors retry rolled up |
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
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>), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
rust/src/librustc_mir/interpret/place.rs
Lines 924 to 929 in 57e1da5
// 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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see, however:
- you can't have MIR built without typeck, it just doesn't stop the compilation (so that comment is somewhat misleading)
- I thought
typeck_tables().has_errors
beingtrue
resulted in a fake MIR body - 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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
add delay_span_bug to TransmuteSizeDiff, just to be sure See rust-lang#69839 (comment). r? @eddyb
add delay_span_bug to TransmuteSizeDiff, just to be sure See rust-lang#69839 (comment). r? @eddyb
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
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