Uh oh!
There was an error while loading. Please reload this page.
(Selectively) turn on validation in const eval - #95377
Conversation
rust-highfive
commented
Mar 27, 2022
Some changes occured to the CTFE / Miri engine cc @rust-lang/miri |
RalfJung
commented
Mar 27, 2022
@bors try @rust-timer queue |
rust-timer
commented
Mar 27, 2022
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
bors
commented
Mar 27, 2022
⌛ Trying commit 8ff27dec01384ec6769b77591e6cc8a01f9dd2dd with merge a5f01f22c3b8dccfe9fbeb6ae38c833309d3bf55... |
This comment has been minimized.
This comment has been minimized.
bors
commented
Mar 27, 2022
☀️ Try build successful - checks-actions |
rust-timer
commented
Mar 27, 2022
Queued a5f01f22c3b8dccfe9fbeb6ae38c833309d3bf55 with parent d7aca22, future comparison URL. |
rust-timer
commented
Mar 28, 2022
Finished benchmarking commit (a5f01f22c3b8dccfe9fbeb6ae38c833309d3bf55): comparison url. Summary: This benchmark run shows 82 relevant regressions 😿 to instruction counts.
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR led to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never |
oli-obk
commented
Mar 28, 2022
Just 50% isn't too bad 😆 I expected worse. |
saethlin
commented
Mar 28, 2022
Hah! I should have known to just grab the ctfe stress test and run it locally. I'll try out some ideas over the coming days, to see if I can knock that down to a reasonable number. |
saethlin
commented
Mar 29, 2022
🙈 don't look too closely at the code I'm just trying to see if this is in the domain of reasonable |
compiler-errors
commented
Mar 29, 2022
@bors try @rust-timer queue |
rust-timer
commented
Mar 29, 2022
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
bors
commented
Mar 29, 2022
⌛ Trying commit 27035bee70f89bfd0c6b753c0741439e24b11a95 with merge c0b2255faeb7c7432570244574d65ba1f5419512... |
bors
commented
Mar 29, 2022
☀️ Try build successful - checks-actions |
rust-timer
commented
Mar 29, 2022
Queued c0b2255faeb7c7432570244574d65ba1f5419512 with parent ee915c3, future comparison URL. |
rust-timer
commented
Mar 29, 2022
Finished benchmarking commit (c0b2255faeb7c7432570244574d65ba1f5419512): comparison url. Summary: This benchmark run shows 61 relevant regressions 😿 to instruction counts.
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR led to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never |
oli-obk
commented
Mar 30, 2022
@bors try @rust-timer queue |
rust-timer
commented
Mar 30, 2022
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
oli-obk
commented
Apr 30, 2022
Hmm... we could totally make validation errors print the memory dump, too. Not possible for things represented as immediate, but everything else at least |
saethlin
commented
May 12, 2022
@oli-obk Can you offer any guidance on how to add code to print the memory dump? Or is that something you are planning to land in a different PR before this one? |
We have the Basically we'd need to teach the validator to make This is a bit more involved and I'm fine regression those diagnostics for now and instead opening an issue about the above |
bors
commented
May 14, 2022
☔ The latest upstream changes (presumably #95826) made this pull request unmergeable. Please resolve the merge conflicts. |
29433d7 to
be9b70cComparebors
commented
May 20, 2022
☔ The latest upstream changes (presumably #97211) made this pull request unmergeable. Please resolve the merge conflicts. |
Instead of only validating values which actually get stored to a const, this PR attempts to turn on full validation in the presence of unsafe code, as detected by walking HIR when available.
saethlin
commented
May 21, 2022
@rustbot ready |
oli-obk
commented
May 24, 2022
I'm conflicted on this. On the one hand it catches a bit more UB, on the other, this is a perf regression even without unsafe code, and makes the code more complex. With unsafe code the regression is massive (+50%). Maybe we should really look into the lint direction: adding a lint and making the |
saethlin
commented
May 24, 2022
Do you mean something like |
oli-obk
commented
May 24, 2022
Yea, the only weird thing would be that we have no concept for |
clarfonthey
commented
May 27, 2022
So, I have an alternative idea I decided to turn into a PR: #97467 My change is comically simpler, which is why I don't have a lot of faith it's a good idea. But since proper UB detection is incredibly costly from the looks of it, might be worth exploring. |
saethlin
commented
Jun 2, 2022
@rustbot label +S-waiting-on-author -S-waiting-on-review |
bors
commented
Jun 6, 2022
☔ The latest upstream changes (presumably #97684) made this pull request unmergeable. Please resolve the merge conflicts. |
JohnCSimon
commented
Jul 3, 2022
Ping from triage: |
@JohnCSimon I think I will soon be rewriting this into a different PR. Does marking this as a draft at least get it out of triage for now? (this was not blocked on merge conflicts, it is blocked on me deciding what approach to take) |
JohnCSimon
commented
Jul 3, 2022
@saethlin Closing is preferable, but I try to triage anything that is over 15 days old |
Normally we tell people that CTFE may detect UB, but it doesn't have to. RFC 3016 documents this explicitly: https://rust-lang.github.io/rfcs/3016-const-ub.html. But until I dug into #95332 I didn't realize how limited the UB checks in CTFE actually are: Invalid bit patterns are not checked for until we create an actual
const. Thus, this code (from the linked issue) is not detected as UB:and that is because in the
Machinethat rustc uses for CTFE, we have this:The general idea of this PR is to add some state to
Machinewhich indicates whether or not we may be executingunsafecode, and if we are, returntrue.Since there is no
unsafein MIR, we're left analyzing HIR which is only available for the current crate. So currently this makes the defensive assumption that any MIR loaded from a non-local crate containsunsafe. This assumption could be inverted, I'm preferring the closer-to-sound option here but of course we have no obligation to detect UB here.In this PR, the
Machineused for CTFE detectsunsafein one of two ways. If there is a call toload_mir, we walk all the MIR looking for any unsafe blocks. But if theMachinesees a call toenforce_validitywithout a previous call toload_mir, it runs the same search but only on the current stack frame. This second case is very common when we are evaluating a trivialconst. EachMachineinstance will only search for unsafe blocks once.r? @oli-obk