-
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
Tracking issue for Rc
/Arc
stabilization
#27718
Comments
Please consider #24789. Dunno if it belongs here or in the RFCs repo since it's a semantics change that wouldn't break much. |
Current plan:
Basically: stabilize the actually useful functionality, don't stabilize introspection pending more work. |
CC @SimonSapin |
Oh and maybe bikeshed naming? They seem perfectly cromulant to me, though |
I am currently drafting a PR to this affect. |
Is
It's not racy if you protect the Arc with a Mutex. I have a use case for this in namedlock-rs. |
@jethrogb this issue -- Arc is defined in That issue largely concerns the actual alloc::heap API |
Thanks for the clarifcation. |
@jethrogb it only needs that feature because you're accessing the functionality through the |
Of things that is still unstable but not deprecated in #27760:
|
@SimonSapin sounds like all you need is |
This feature is now entering its final comment period for stabilization. I believe that @gankro will post a PR soon with various tweaks to do the final prep for stabilization |
Building now and dealing with fallout. Changes proposed:
|
@gankro that sounds good to me, but I'd consider |
What's happening with
What about
I don't think strong_count/weak_count should be deprecated. Consider a data structure that opaquely owns some data (say, keys in a |
@jethrogb Oh whoops, I got make_unique and try_unwrap a bit mixed up. I'm not a fan of that argument -- if you want to intropsect uniqueness you can use try_unwrap/would_unwrap and get_mut. |
Except I just told you that those functions are not sufficient. |
@jethrogb Ah yes, I misread the example. Still, this seems extraordinarily niche. Also: that's not what |
Code example #![feature(arc_unique,arc_counts)]
use std::sync::Arc;
use std::hash::{Hash,Hasher};
use std::collections::HashMap;
#[derive(Clone)]
pub struct ArcHashKey<T>(pub Arc<T>);
impl<T: PartialEq> PartialEq for ArcHashKey<T> {
fn eq(&self, other: &ArcHashKey<T>) -> bool { self.0.eq(&other.0) }
}
impl<T: Eq> Eq for ArcHashKey<T> { }
impl<T: Hash> Hash for ArcHashKey<T> {
fn hash<H: Hasher>(&self, state: &mut H) { self.0.hash(state) }
}
fn main() {
let mut map=HashMap::new();
let mut key=ArcHashKey(Arc::new("key"));
map.insert(key.clone(),"value");
// hand out some references to key, thread some things
if Arc::strong_count(&key.0)==2 {
map.remove(&key);
println!("all threads are done with the arc: {:?}",Arc::get_mut(&mut key.0));
}
} |
@gankro Yes, |
One method that hasn't been proposed is a variant of get_mut() which only considers the number of strong references (and moves the contents to a new allocation if necessary); would that be useful? |
@eefriedman you need to consider the weak references in general because otherwise they can promote themselves to a strong reference and then access the supposedly unaliased &mut. Or am I misunderstanding? |
I think @eefriedman means something equivalent to |
* Add `Rc::would_unwrap(&Self) -> bool` to introspect whether try_unwrap would succeed, because it's destructive (unlike get_mut). * Move `rc.downgrade()` to `Rc::downgrade(&Self)` per conventions. * Deprecate `Rc::weak_count` and `Rc::strong_count` for questionable utility. * Deprecate `Rc::is_unique` for questionable semantics (there are two kinds of uniqueness with Weak pointers in play). * Rename `rc.make_unique()` to `Rc::make_mut(&mut Self)` per conventions, to avoid uniqueness terminology, and to clarify the relation to `Rc::get_mut`.
* Add previously omitted function `Arc::try_unwrap(Self) -> Result<T, Self>` * Move `arc.downgrade()` to `Arc::downgrade(&Self)` per conventions. * Deprecate `Arc::weak_count` and `Arc::strong_count` for raciness. It is almost impossible to correctly act on these results without a CAS loop on the actual fields. * Rename `Arc::make_unique` to `Arc::make_mut` to avoid uniqueness terminology and to clarify relation to `Arc::get_mut`.
This prepares both for the FCP of #27718 Arc: * Add previously omitted function `Arc::try_unwrap(Self) -> Result<T, Self>` * Move `arc.downgrade()` to `Arc::downgrade(&Self)` per conventions. * Deprecate `Arc::weak_count` and `Arc::strong_count` for raciness. It is almost impossible to correctly act on these results without a CAS loop on the actual fields. * Rename `Arc::make_unique` to `Arc::make_mut` to avoid uniqueness terminology and to clarify relation to `Arc::get_mut`. Rc: * Add `Rc::would_unwrap(&Self) -> bool` to introspect whether try_unwrap would succeed, because it's destructive (unlike get_mut). * Move `rc.downgrade()` to `Rc::downgrade(&Self)` per conventions. * Deprecate `Rc::weak_count` and `Rc::strong_count` for questionable utility. * Deprecate `Rc::is_unique` for questionable semantics (there are two kinds of uniqueness with Weak pointers in play). * Rename `rc.make_unique()` to `Rc::make_mut(&mut Self)` per conventions, to avoid uniqueness terminology, and to clarify the relation to `Rc::get_mut`. Notable omission: * Arc::would_unwrap is not added due to the fact that it's racy, and therefore doesn't provide much actionable information. (note: rc_would_unwrap is not proposed for FCP as it is truly experimental) r? @aturon (careful attention needs to be taken for the new Arc::try_unwrap, but intuitively it should "just work" by virtue of being semantically equivalent to Drop).
With #27837 landed this is looking pretty good to me. What’s the next step in the process? I think we can stabilize the |
Stabilize *_weak and *_unique is my proposal as well. rc_would_unwrap definitely needs more time to bake as unstable I'd like to deprecated *_counts, though there is some opposition to this (even arc_counts can arguably be used correctly if you're very careful). |
Nominating for discussion to move into FCP |
The libs team decided today to move this into FCP, specifically:
|
I'm not quite sure about the process here. You don't mention the count methods. Does that mean that they'll be deprecated, or that no decision is being made just yet? |
Ah yes, sorry, all other methods will remain unstable for now, and follow-up issues will be opened to track their unstable progress. |
The FCP is coming to a close and 1.4 is coming out soon, so this brings in the libs team decision for all library features this cycle. Stabilized APIs: * `<Box<str>>::into_string` * `Arc::downgrade` * `Arc::get_mut` * `Arc::make_mut` * `Arc::try_unwrap` * `Box::from_raw` * `Box::into_raw` * `CStr::to_str` * `CStr::to_string_lossy` * `CString::from_raw` * `CString::into_raw` * `IntoRawFd::into_raw_fd` * `IntoRawFd` * `IntoRawHandle::into_raw_handle` * `IntoRawHandle` * `IntoRawSocket::into_raw_socket` * `IntoRawSocket` * `Rc::downgrade` * `Rc::get_mut` * `Rc::make_mut` * `Rc::try_unwrap` * `Result::expect` * `String::into_boxed_slice` * `TcpSocket::read_timeout` * `TcpSocket::set_read_timeout` * `TcpSocket::set_write_timeout` * `TcpSocket::write_timeout` * `UdpSocket::read_timeout` * `UdpSocket::set_read_timeout` * `UdpSocket::set_write_timeout` * `UdpSocket::write_timeout` * `Vec::append` * `Vec::split_off` * `VecDeque::append` * `VecDeque::retain` * `VecDeque::split_off` * `rc::Weak::upgrade` * `rc::Weak` * `slice::Iter::as_slice` * `slice::IterMut::into_slice` * `str::CharIndices::as_str` * `str::Chars::as_str` * `str::split_at_mut` * `str::split_at` * `sync::Weak::upgrade` * `sync::Weak` * `thread::park_timeout` * `thread::sleep` Deprecated APIs * `BTreeMap::with_b` * `BTreeSet::with_b` * `Option::as_mut_slice` * `Option::as_slice` * `Result::as_mut_slice` * `Result::as_slice` * `f32::from_str_radix` * `f64::from_str_radix` Closes rust-lang#27277 Closes rust-lang#27718 Closes rust-lang#27736 Closes rust-lang#27764 Closes rust-lang#27765 Closes rust-lang#27766 Closes rust-lang#27767 Closes rust-lang#27768 Closes rust-lang#27769 Closes rust-lang#27771 Closes rust-lang#27773 Closes rust-lang#27775 Closes rust-lang#27776 Closes rust-lang#27785 Closes rust-lang#27792 Closes rust-lang#27795 Closes rust-lang#27797
The FCP is coming to a close and 1.4 is coming out soon, so this brings in the libs team decision for all library features this cycle. Stabilized APIs: * `<Box<str>>::into_string` * `Arc::downgrade` * `Arc::get_mut` * `Arc::make_mut` * `Arc::try_unwrap` * `Box::from_raw` * `Box::into_raw` * `CStr::to_str` * `CStr::to_string_lossy` * `CString::from_raw` * `CString::into_raw` * `IntoRawFd::into_raw_fd` * `IntoRawFd` * `IntoRawHandle::into_raw_handle` * `IntoRawHandle` * `IntoRawSocket::into_raw_socket` * `IntoRawSocket` * `Rc::downgrade` * `Rc::get_mut` * `Rc::make_mut` * `Rc::try_unwrap` * `Result::expect` * `String::into_boxed_slice` * `TcpSocket::read_timeout` * `TcpSocket::set_read_timeout` * `TcpSocket::set_write_timeout` * `TcpSocket::write_timeout` * `UdpSocket::read_timeout` * `UdpSocket::set_read_timeout` * `UdpSocket::set_write_timeout` * `UdpSocket::write_timeout` * `Vec::append` * `Vec::split_off` * `VecDeque::append` * `VecDeque::retain` * `VecDeque::split_off` * `rc::Weak::upgrade` * `rc::Weak` * `slice::Iter::as_slice` * `slice::IterMut::into_slice` * `str::CharIndices::as_str` * `str::Chars::as_str` * `str::split_at_mut` * `str::split_at` * `sync::Weak::upgrade` * `sync::Weak` * `thread::park_timeout` * `thread::sleep` Deprecated APIs * `BTreeMap::with_b` * `BTreeSet::with_b` * `Option::as_mut_slice` * `Option::as_slice` * `Result::as_mut_slice` * `Result::as_slice` * `f32::from_str_radix` * `f64::from_str_radix` Closes #27277 Closes #27718 Closes #27736 Closes #27764 Closes #27765 Closes #27766 Closes #27767 Closes #27768 Closes #27769 Closes #27771 Closes #27773 Closes #27775 Closes #27776 Closes #27785 Closes #27792 Closes #27795 Closes #27797
There are a number of unstable features related to
Rc
andArc
, including both weak references and uniqueness. An RFC to remove weak pointers failed, and the current consensus seems to be to stabilize these APIs after nailing down more precise semantics for uniqueness.cc @gankro
The text was updated successfully, but these errors were encountered: