Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for `Rc`/`Arc` stabilization #27718
Comments
aturon
added
T-libs
B-unstable
labels
Aug 12, 2015
This comment has been minimized.
This comment has been minimized.
|
Please consider #24789. Dunno if it belongs here or in the RFCs repo since it's a semantics change that wouldn't break much. |
This comment has been minimized.
This comment has been minimized.
|
Current plan:
Basically: stabilize the actually useful functionality, don't stabilize introspection pending more work. |
This comment has been minimized.
This comment has been minimized.
|
CC @SimonSapin |
This comment has been minimized.
This comment has been minimized.
|
Oh and maybe bikeshed naming? They seem perfectly cromulant to me, though |
This comment has been minimized.
This comment has been minimized.
|
I am currently drafting a PR to this affect. |
This comment has been minimized.
This comment has been minimized.
|
Is
It's not racy if you protect the Arc with a Mutex. I have a use case for this in namedlock-rs. |
This comment has been minimized.
This comment has been minimized.
|
@jethrogb this issue -- Arc is defined in That issue largely concerns the actual alloc::heap API |
This comment has been minimized.
This comment has been minimized.
|
Thanks for the clarifcation. |
This comment has been minimized.
This comment has been minimized.
|
@jethrogb it only needs that feature because you're accessing the functionality through the |
Gankro
referenced this issue
Aug 12, 2015
Closed
Stabilize weak pointers on Rc and Arc, as well as the meaty uniqueness methods #27760
This comment has been minimized.
This comment has been minimized.
|
Of things that is still unstable but not deprecated in #27760:
|
This comment has been minimized.
This comment has been minimized.
|
@SimonSapin sounds like all you need is |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
Building now and dealing with fallout. Changes proposed:
|
This comment has been minimized.
This comment has been minimized.
|
@Gankro that sounds good to me, but I'd consider |
This comment has been minimized.
This comment has been minimized.
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 |
This comment has been minimized.
This comment has been minimized.
|
@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. |
This comment has been minimized.
This comment has been minimized.
Except I just told you that those functions are not sufficient. |
This comment has been minimized.
This comment has been minimized.
|
@jethrogb Ah yes, I misread the example. Still, this seems extraordinarily niche. Also: that's not what |
This comment has been minimized.
This comment has been minimized.
|
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
added a commit
to Gankro/rust
that referenced
this issue
Aug 14, 2015
Gankro
added a commit
to Gankro/rust
that referenced
this issue
Aug 14, 2015
This comment has been minimized.
This comment has been minimized.
|
@Gankro Yes, |
This comment has been minimized.
This comment has been minimized.
|
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? |
This comment has been minimized.
This comment has been minimized.
|
@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? |
This comment has been minimized.
This comment has been minimized.
|
I think @eefriedman means something equivalent to |
Gankro
added a commit
to Gankro/rust
that referenced
this issue
Aug 14, 2015
Gankro
added a commit
to Gankro/rust
that referenced
this issue
Aug 19, 2015
Gankro
added a commit
to Gankro/rust
that referenced
this issue
Aug 19, 2015
Gankro
added a commit
to Gankro/rust
that referenced
this issue
Aug 19, 2015
Gankro
added a commit
to Gankro/rust
that referenced
this issue
Aug 19, 2015
bors
added a commit
that referenced
this issue
Aug 21, 2015
This comment has been minimized.
This comment has been minimized.
|
With #27837 landed this is looking pretty good to me. What’s the next step in the process? I think we can stabilize the |
This comment has been minimized.
This comment has been minimized.
|
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). |
alexcrichton
added
the
I-nominated
label
Aug 22, 2015
This comment has been minimized.
This comment has been minimized.
|
Nominating for discussion to move into FCP |
This comment has been minimized.
This comment has been minimized.
|
The libs team decided today to move this into FCP, specifically:
|
alexcrichton
added
final-comment-period
and removed
I-nominated
labels
Aug 27, 2015
This comment has been minimized.
This comment has been minimized.
|
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? |
This comment has been minimized.
This comment has been minimized.
|
Ah yes, sorry, all other methods will remain unstable for now, and follow-up issues will be opened to track their unstable progress. |
aturon commentedAug 12, 2015
There are a number of unstable features related to
RcandArc, 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