Uh oh!
There was an error while loading. Please reload this page.
Use pointers in cell::{Ref,RefMut} to avoid noalias - #97027
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
rust-highfive
commented
May 13, 2022
r? @thomcc (rust-highfive has picked a reviewer for you, use r? to override) |
CAD97
left a comment
There was a problem hiding this comment.
Ref doesn't need a PhantomData<&T> for correctness, but it might make sense to include it for explicitness / symmetry with RefMut?
Also, I forget how NonNull acts w.r.t. UnwindSafe; this is a reminder to someone to check that it's not changed by this PR.
| where | ||
| F: FnOnce(&mut T) -> Option<&mut U>, | ||
| { | ||
| // FIXME(nll-rfc#40): fix borrow-check |
There was a problem hiding this comment.
I assume this no longer applies now?
There was a problem hiding this comment.
Maybe? I'm not really sure what needed fixing -- was it that orig had to be destructured, then rebuilt in the Err case?
cuviper
commented
May 13, 2022
@CAD97 :
I could just add a comment addressing covariance, but are there more effects you want from
All of the auto traits are unchanged, at least according to rustdoc. |
thomcc
commented
May 14, 2022
I think this is fine as-is, no need for additional PhantomData. @bors r+ |
bors
commented
May 14, 2022
📌 Commit 15d8c00 has been approved by |
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
Use pointers in `cell::{Ref,RefMut}` to avoid `noalias`
When `Ref` and `RefMut` were based on references, they would get LLVM `noalias` attributes that were incorrect, because that alias guarantee is only true until the guard drops. A `&RefCell` on the same value can get a new borrow that aliases the previous guard, possibly leading to miscompilation. Using `NonNull` pointers in `Ref` and `RefCell` avoids `noalias`.
Fixes the library side of rust-lang#63787, but we still might want to explore language solutions there.Use pointers in `cell::{Ref,RefMut}` to avoid `noalias`
When `Ref` and `RefMut` were based on references, they would get LLVM `noalias` attributes that were incorrect, because that alias guarantee is only true until the guard drops. A `&RefCell` on the same value can get a new borrow that aliases the previous guard, possibly leading to miscompilation. Using `NonNull` pointers in `Ref` and `RefCell` avoids `noalias`.
Fixes the library side of rust-lang#63787, but we still might want to explore language solutions there.bors
commented
May 15, 2022
⌛ Testing commit 15d8c00 with merge 0b2b6a751bfaaef94c621925159a481da0356b9d... |
bors
commented
May 15, 2022
💔 Test failed - checks-actions |
cuviper
commented
May 17, 2022
I took a stab at fixing natvis, but I'm just guessing... |
thomcc
commented
May 19, 2022
(I'm assuming I need to r+ this again) @bors r+ |
bors
commented
May 19, 2022
📌 Commit 1c3921f has been approved by |
bors
commented
May 19, 2022
🌲 The tree is currently closed for pull requests below priority 1000. This pull request will be tested once the tree is reopened. |
bors
commented
May 20, 2022
bors
commented
May 20, 2022
☀️ Test successful - checks-actions |
Tested on commit rust-lang/rust@4d6992b. Direct link to PR: <rust-lang/rust#97027> 💔 miri on windows: test-pass → test-fail (cc @oli-obk@eddyb@RalfJung). 💔 miri on linux: test-pass → test-fail (cc @oli-obk@eddyb@RalfJung).
rust-timer
commented
May 20, 2022
Finished benchmarking commit (4d6992b): comparison url. Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results
CyclesResults
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression Footnotes |
RalfJung
commented
May 20, 2022
The Miri tests fail because this affects the |
rustup `Display` of `Ref`/`RefMut` was broken by rust-lang/rust#97027, let's deref them to use the underlying reference `Display`. Cc rust-lang/rust#97204
cuviper
commented
May 20, 2022
Ah, yes, I'll fix that. The |
These guards changed to pointers in rust-lang#97027, but their `Display` was formatting that field directly, which made it show the raw pointer value. Now we go through `Deref` to display the real value again.
Fix `Display` for `cell::{Ref,RefMut}`
These guards changed to pointers in rust-lang#97027, but their `Display` was
formatting that field directly, which made it show the raw pointer
value. Now we go through `Deref` to display the real value again.
Miri noticed this change, rust-lang#97204, so hopefully that will be fixed.
When
RefandRefMutwere based on references, they would get LLVMnoaliasattributes that were incorrect, because that alias guarantee is only true until the guard drops. A&RefCellon the same value can get a new borrow that aliases the previous guard, possibly leading to miscompilation. UsingNonNullpointers inRefandRefCellavoidsnoalias.Fixes the library side of #63787, but we still might want to explore language solutions there.