Repository navigation
[Crater experiment] Adjust PlaceMention borrow checking for MIR move elimination semantics - #165046
Jules-Bertholet wants to merge 4 commits into
Conversation
Co-authored-by: dianne <diannes.gm@gmail.com>
|
@bors try |
This comment has been minimized.
This comment has been minimized.
…=<try> [Crater experiment] Adjust `PlaceMention` borrow checking for MIR move elimination semantics
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
@craterbot check |
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🎉 Experiment
Footnotes
|
|
Based on a quick skim of the crater results I don't think this is going to fly. We might have to simply define |
|
I don't see how a semantics like that could be coherent. We could say that PlaceMention is just always a NOP. That's still a bad semantics IMO since Or... I've seen worse than 270 regressions. They come from fairly few roots. Even most of the "root results" are not root results, they come from a single macro in "blobby". |
And in the non-root results, there are 115 failures from an obsolete alpha version of |
Cc @joshlf |
|
Feel free to disregard the zerocopy failures. They come from this function which did the following on to guard against an accidental type-alias change: let c = candidate.into_exclusive_or_post_monomorphization_error();
// ...
// Confirm that `Maybe` is a type alias for `Ptr` with the validity
// invariant `Initialized`. Our safety proof depends upon this
// invariant, and it might change at some point. If that happens, we
// want this function to stop compiling.
let _: Ptr<'_, UnsafeCell<T>, (_, _, invariant::Initialized)> = candidate;This wasn't control flow load-bearing; it was just meant as a sort of compile-time type assertion. AFAICT, it was never published outside of alpha releases (it was added in 0.8.0-alpha.6 in google/zerocopy#912 and then removed in 0.8.0-alpha.19 in google/zerocopy#1619). |
…cts` (#1588) The Rust project is considering a change to the language that would break `let $field: (); let _ = $field;`: rust-lang/rust#165046
|
I released blobby v0.4.1 with the fix. |
|
If it were necessary to keep accepting the same programs (as in #164812), there is also an alternative semantics where PlaceMention takes the role of StorageAlloc (when place has no deref projections). |
|
We should not have a semantics with ad-hoc special-cases like "do something different if there are no deref projections". |
This behavior would be consistent with MIR move elimination semantics, which indeed does make such a distinction. |
|
The behavior of MIR move semantics can be described by carrying a "mode" alongside place evaluation, indicating whether locals should be initialized. That's a compositional way to give rise to the desired semantics without ad-hoc syntactic checks. I don't think the same is possible here. Place evaluation must either return a place or raise UB. We should IMO not alter the return type of place evaluation to deal with this quirk in the borrow checker. |
|
I am perplexed by your comments. In MIR move elimination semantics are two modes of place evaluation. It is entirely trivial observation that one could use the other mode in PlaceMention. I don't understand why that wouldn't be possible. |
|
Please spell out a compositional model of place evaluation that achieves "PlaceMention takes the role of StorageAlloc (when place has no deref projections)". Maybe I am missing the obvious. |
|
In context of #163340, this would mean PlaceMention using |
|
Note that this makes |
|
What I had in mind instead was to explicitly skip place evaluation if the base local isn't allocated and there's no deref. So evaluation of a It is a hack, but a necessary one to maintain backwards-compatibility. We could maybe phase it out in the long term with a FCW. |
Oh I see.
Yeah that is indeed quite the hack. I'd prefer the "eval for write" option over this. Speaking of FCW... doing FCW in the borrow checker is challenging. Does anyone have an idea for how we could implement the semantics of this PR (require full initialization, not just #164812) as an FCW? |
|
My preference is actually in the opposite direction. I really want to minimize the number of operations that implicitly allocate a place since they make MIR optimizations more complicated, mainly because of the need to preserve side effects. I've already mentioned |
Yes, it'd be better to make PlaceMention a regular place eval. But the hack you suggested is IMO a lot worse than the "make it work like a write" hack. Such special cases will inevitably come back to bite us. |
View all comments
Adjust
PlaceMentionborrow checking for rust-lang/rfcs#3943.#164812 (comment)
I didn't bother adjusting all the UI tests, so they will fail.
@Amanieu can you confirm that
tests/ui/borrowck/placemention-mir-move-elim.rscorresponds to the behavior you want?