-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Use pointers in cell::{Ref,RefMut}
to avoid noalias
#97027
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
r? @thomcc (rust-highfive has picked a reviewer for you, use r? to override) |
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.
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.
library/core/src/cell.rs
Outdated
@@ -1548,23 +1557,20 @@ impl<'b, T: ?Sized> RefMut<'b, T> { | |||
/// ``` | |||
#[unstable(feature = "cell_filter_map", reason = "recently added", issue = "81061")] | |||
#[inline] | |||
pub fn filter_map<U: ?Sized, F>(orig: RefMut<'b, T>, f: F) -> Result<RefMut<'b, U>, Self> | |||
pub fn filter_map<U: ?Sized, F>(mut orig: RefMut<'b, T>, f: F) -> Result<RefMut<'b, U>, Self> | |||
where | |||
F: FnOnce(&mut T) -> Option<&mut U>, | |||
{ | |||
// FIXME(nll-rfc#40): fix borrow-check |
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.
I assume this no longer applies now?
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.
Maybe? I'm not really sure what needed fixing -- was it that orig
had to be destructured, then rebuilt in the Err
case?
@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. |
I think this is fine as-is, no need for additional PhantomData. @bors r+ |
📌 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.
⌛ Testing commit 15d8c00 with merge 0b2b6a751bfaaef94c621925159a481da0356b9d... |
💔 Test failed - checks-actions |
I took a stab at fixing natvis, but I'm just guessing... |
(I'm assuming I need to r+ this again) @bors r+ |
📌 Commit 1c3921f 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. |
☀️ 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).
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 |
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
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
Ref
andRefMut
were based on references, they would get LLVMnoalias
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. UsingNonNull
pointers inRef
andRefCell
avoidsnoalias
.Fixes the library side of #63787, but we still might want to explore language solutions there.