-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
std: Make atomics immutable. #11583 #12430
Conversation
Could you add some rationale to the commit message as well? I'm not entirely convinced just yet, but I'm getting to the point where I could be persuaded. |
@alexcrichton Done. |
The word 'immutable' is becoming increasingly incorrect. |
I'm curious, did you get an email saying that the travis build failed? I haven't been getting emails... |
No
|
Ah, it appears that there's an issue open about this: travis-ci/travis-ci#1417. I suppose we'll just have to be vigilant for now. |
Going to add a few more commits to fix additional type system violations with atomics. |
All the commits look fine other than the one I commented on, and I'm just curious about the clarification there. I'm getting more perturbed that we're saying |
@alexcrichton Indeed I believe it's accurate to say that nearly the only thing that |
I have been convinced, r=me. It appears travis has some problems with this, though. |
In Rust, the strongest guarantee that `&mut` provides is that the memory pointed to is *not aliased*, whereas `&`'s guarantees are much weaker: that the value can be aliased, and may be mutated under proper precautions (interior mutability). Our atomics though use `&mut` for mutation even while creating multiple aliases, so this changes them to use 'interior mutability', mutating through immutable references.
These mutate values behind references that are Freeze, which is not allowed.
I'm not comfortable exposing public functions that purport to do atomic operations on arbitrary T.
Support for this is less universal than for word-size things; it has no users; i'd rather play it safe.
pub static INIT_ATOMIC_INT : AtomicInt = AtomicInt { v: 0, nopod: marker::NoPod }; | ||
pub static INIT_ATOMIC_UINT : AtomicUint = AtomicUint { v: 0, nopod: marker::NoPod }; | ||
pub static INIT_ATOMIC_U64 : AtomicU64 = AtomicU64 { v: 0, nopod: marker::NoPod }; | ||
pub static INIT_ATOMIC_FLAG : AtomicFlag = AtomicFlag { |
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.
The new static constrains will complain about this, unless they're made mutable. Immutable static items values must be Freeze
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 see this as quite unfortunate, sadly. These are all just initializer patterns, none of them are meant to be used. Requiring them to be mut
means that you could in theory write INIT_ATOMIC_UINT.fetch_add(1)
which seems... bad.
@brson, I suppose for now these should be static mut
. cc @nikomatsakis, this is an unforseen case in statics that I didn't think of earlier sadly.
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.
Why not just make them functions? You're really asking for rvalues, that's what a function is for.
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.
These are all static initializers (for other static atomics), so they can't be functions sadly.
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.
Ah, yes, I see. It seems we need some kind of static rvalue to cover this case. constexpr ftw.
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 guess this also falls down into the re-definition of what Freeze actually means (ref).
I think our best way out of this issue is to make them static mut
for now (pls, add a FIXME)
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.
This seems to relate to the "dual role" -- a static both represents a constant value and a static bit of memory. It'd be nice if we could distinguish the two -- we could permit "constant values" to be non-freeze, since you wouldn't be able to take their address.
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.
ps the repetition of markers here would be so much nicer under the opt-in approach ;)
Closing in favor of #13036 |
minor: Remove unused code
…exendoo Fix dependency specifications As Clippy lacks `Cargo.lock`, it makes sense to test its dependency specifications with [direct-minimal-versions](https://doc.rust-lang.org/cargo/reference/unstable.html#direct-minimal-versions). This can be done with the following addition to `.cargo/config.toml`. ```toml [unstable] direct-minimal-versions = true ``` * `tempfile` 3.3 is required by `clippy_lints`. * `regex` 1.5.5 is required by `ui_test` 0.22.2. * `quote` 1.0.25 is required by `syn` 2.0.0. * `serde` 1.0.145 is required by `toml` 0.7.3. changelog: none
No description provided.