Uh oh!
There was an error while loading. Please reload this page.
Stabilize arc_new_cyclic - #90666
Conversation
rust-highfive
commented
Nov 7, 2021
r? @dtolnay (rust-highfive has picked a reviewer for you, use r? to override) |
dtolnay
commented
Nov 26, 2021
I like these! @rust-lang/libs-api impl<T>Rc<T>{pubfnnew_cyclic(f:implFnOnce(&Weak<T>) -> T) -> Rc<T>;}impl<T>Arc<T>{pubfnnew_cyclic(f:implFnOnce(&Weak<T>) -> T) -> Arc<T>;} |
Team member @dtolnay has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
BurntSushi
commented
Dec 2, 2021
I think the docs for this API leave a lot to be desired. I can't figure out what this API is really supposed to do or, more importantly, why or when I should (or shouldn't) use it. Here are some points of confusion that I have after looking at this for a few minutes:
My suspicion is that this is a fine API to add, but I'd like to see the docs improved here a bit before signing off. |
yaahc
commented
Dec 2, 2021
It looks like the None is referring to calling |
I did some digging in the history of this API to see if I couldn't find any better explanations and found this comment which explicitly mentions being able to give out reference counted pointers to ones self. Perhaps the example just needs to additionally include a simple method on use std::sync::{Arc,Weak};structFoo{me:Weak<Foo>,}implFoo{/// Construct a reference counted Foo.fnnew() -> Arc<Self>{Arc::new_cyclic(|me| Foo{me: me.clone(),})}/// Return a reference counted pointer to Self.fnme(&self) -> Arc<Self>{self.me.upgrade()}} |
yaahc
commented
Dec 2, 2021
ogoffart
commented
Dec 3, 2021
That's similar to the current docs for Rc::new_cyclic: https://doc.rust-lang.org/std/rc/struct.Rc.html#method.new_cyclic |
Fair point, we should definitely also make sure all the docs on The necessary changes as I see them:
|
Regarding the doc example, I would like to propose the following alternative: use std::sync::{Arc,Weak};structRoot{left:Leaf,right:Leaf,}structLeaf{root:Weak<Root>,}let tree = Arc::new_cyclic(|me| {assert!(root.upgrade().is_none());Root{left:Leaf{root: me.clone()},right:Leaf{root: me.clone()},}});assert!(tree.left.root.upgrade().is_some());assert!(Arc::ptr_eq(&tree.right.root.upgrade().unwrap(),&tree));I noticed there was a section Breaking cycles with |
The description was amended as follows:
Since I am not a native English speaker, I would appreciate it if any suggestions could be made in order to make readers feel more idiomatic. 😊 |
@bdbai I edited a couple of the verb tenses in your updated doc comment but otherwise everything in your example looked correct grammatically. Am I correct in understanding that you've not made the mentioned changes in the PR itself? As for the example, I have a slight preference for the example that I suggested earlier since it seems closer to real world examples while still being relatively brief, where as I feel like the tree example you linked is a simplified form of what a real world tree structure would look like and is still a much longer example. That said, I'm fine with either example, so I'll leave it up to other libs team members to voice a stronger preference. I would still like to see the Rc and Arc docs updated to match regardless of which example we go with. |
bdbai
commented
Dec 7, 2021
Thanks!
I failed to mention that the changes of the text description would be committed into the PR once it got corrected and approved. Sorry about that.
Sure. I will update both while changing the codebase. For the sake of brevity, I would like to mention only one of them during discussion since the both does not differ in terms of this API. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bdbai
commented
Dec 13, 2021
@yaahc The documentation in btw why did rustbot add the |
yaahc
commented
Dec 14, 2021
bdbai
commented
Dec 30, 2021
@veber-alex fixed. |
rfcbot
commented
Jan 12, 2022
🔔 This is now entering its final comment period, as per the review above. 🔔 |
wx-csy
commented
Jan 14, 2022
Can't wait for the stabilization to build data structures with circular references! Currently, this function takes a closure to initialize the arc, but it operates badly with async programming. I think we can offer an API that returns a pair of |
@wx-csy good point! structArcBuilder<T>{ ... }impl<T>ArcBuilder<T>{fnnew() -> Self;fnget_weak(&self) -> &Weak<T>;fnwith_value(self,value:T) -> Arc<T>;}Once implemented, it will also address the need of fallible cyclic Since the pair of |
m-ou-se
commented
Jan 14, 2022
That sounds like a discussion to be had on the tracking issue, before stabilizing this: #75861 |
wx-csy
commented
Jan 16, 2022
Well, I think it's fine to move forward stabilizing Btw, we may additionally return an |
rfcbot
commented
Jan 22, 2022
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
m-ou-se
commented
Jan 22, 2022
Sounds good. Note that this |
m-ou-se
commented
Jan 22, 2022
@bors r+ |
bors
commented
Jan 22, 2022
📌 Commit 00e191c has been approved by |
Stabilize arc_new_cyclic This stabilizes feature `arc_new_cyclic` as the implementation has been merged for one year and there is no unresolved questions. The FCP is not started yet. Closesrust-lang#75861 . `@rustbot` label +T-libs-api
…askrgr Rollup of 8 pull requests Successful merges: - rust-lang#90666 (Stabilize arc_new_cyclic) - rust-lang#91122 (impl Not for !) - rust-lang#93068 (Fix spacing for `·` between stability and source) - rust-lang#93103 (Tweak `expr.await` desugaring `Span`) - rust-lang#93113 (Unify search input and buttons size) - rust-lang#93168 (update uclibc instructions for new toolchain, add link from platforms doc) - rust-lang#93185 (rustdoc: Make some `pub` items crate-private) - rust-lang#93196 (Remove dead code from build_helper) Failed merges: - rust-lang#93188 (rustdoc: fix bump down typing search on Safari) r? `@ghost` `@rustbot` modify labels: rollup
This stabilizes feature
arc_new_cyclicas the implementation has been merged for one year and there is no unresolved questions. The FCP is not started yet.Closes#75861 .
@rustbot label +T-libs-api