-
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
Stabilize Arc::{increment,decrement}_strong_count #79285
Stabilize Arc::{increment,decrement}_strong_count #79285
Conversation
I am forgetting now -- is there a reason we didn't add this on Rc? I don't quickly see any discussion about that, but it seems like they'd be equally useful there ergonomics wise, though it's somewhat rarer (I suspect) to be stashing away Rc's in atomics or whatever where you're hiding them. |
@Mark-Simulacrum I don't believe we discussed it, but there's no reason not to as far as I recall — I'm planning to add it to If there are no objections to stabilizing the |
This stabilizes the following methods on impl<T: ?Sized> Arc<T> {
pub unsafe fn incr_strong_count(ptr: *const T);
pub unsafe fn decr_strong_count(ptr: *const T);
} The only reason these APIs are unsafe is that we take r? @dtolnay to kick off libs FCP on this. |
Should |
@nagisa I find that |
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. |
RE naming: I do have a mild preference for RE docs: Would it be possible to add some clarity to the docs explaining specifically why someone might want to use these routines? |
Personally I found those functions to be rather underwhelming. They cater to relatively niche use-cases, while having a trivial implementation. Furthermore, their own implementation uses a pattern which is much more generally applicable:
|
I would call neither of those trivial or easy to follow -- if I see those in the wild, I'm definitely going to expect a comment on them explaining them. I also don't think we guarantee that they will work (there's not really a way we could break that even if we wanted to and ignoring stability guarantees); I've always been rather uncertain about the "clone to increment" pattern externally from std, while internally we can of course use it. |
I don't think there is anything contentious about |
@rfcbot concern naming See #79285 (comment). I agree not abbreviating the names would be a bit better. Registering it as a concern so we don't forget. |
I struggled with the pointer aspect of this API a bit. It seemed strange to combine two steps - offseting to get an arc, and then manipulating the strong count - into one function. Especially so because incrementing the strong count is safe. I was worried that these were overly-tailored to implementing a waker. What won me over to the current API was the drop problem: users who have a raw pointer have to make sure if they get an Arc from it that they know not to drop it. This is really tricky to get right because its all implicit; implementing it properly in std seems like the right choice. |
It seems everyone on the libs team has ticked their box! -- but the one outstanding concern is naming. So I'd like to ask: does anyone feel strongly against I've already expressed I prefer the short versions, but I don't feel strong enough about them to block this PR on that. So I want to check if anyone objects to the long-form instead. If not, I'll happily switch this PR over to use |
I've update the PR to use the |
@rfcbot resolve naming |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The RawWaker API would need to forget the resulting Arc rather than making use of it in the clone "method". I think most use cases for this API aren't actually creating Arcs directly. The uses I've had historically have also done similar things to the RawWaker API, for example across the FFI boundary where either side wants to increment the counter on a shared resource, due to cloning, but isn't actually going to pass back the Arc (because nothing is going to interact with the Arc directly). That said I don't disagree that the clone_from_raw API is in some cases a bit cleaner; I think I would rather add both though. These methods are largely aliases for 1-3 lines of code, we can expose more than one incrementing method if we want. But I think there are valid uses for both just incrementing and for incrementing and getting a reference. |
@SimonSapin I think you have to be on rfcbot's list to add concerns. @rfcbot concern clone_from_raw instead |
@SimonSapin Since this is blocked on your concern, can you respond to Mark's comment? Thanks! |
Ok, I didn’t realize that. This concern can be marked as resolved. |
@rfcbot resolve clone_from_raw instead |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
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. The RFC will be merged soon. |
@bors r+ rollup |
📌 Commit fe4ac95 has been approved by |
…as-schievink Rollup of 18 pull requests Successful merges: - rust-lang#78044 (Implement io::Seek for io::Empty) - rust-lang#79285 (Stabilize Arc::{increment,decrement}_strong_count) - rust-lang#80053 (stabilise `cargo test -- --include-ignored`) - rust-lang#80279 (Implement missing `AsMut<str>` for `str`) - rust-lang#80470 (Stabilize by-value `[T; N]` iterator `core::array::IntoIter`) - rust-lang#80945 (Add Box::downcast() for dyn Any + Send + Sync) - rust-lang#81048 (Stabilize `core::slice::fill_with`) - rust-lang#81198 (Remove requirement that forces symmetric and transitive PartialEq impls to exist) - rust-lang#81422 (Account for existing `_` field pattern when suggesting `..`) - rust-lang#81472 (Clone entire `TokenCursor` when collecting tokens) - rust-lang#81484 (Optimize decimal formatting of 128-bit integers) - rust-lang#81491 (Balance sidebar `Deref` cycle check with main content) - rust-lang#81509 (Add a regression test for ICE of bad_placeholder_type) - rust-lang#81547 (Edit rustc_typeck top-level docs) - rust-lang#81550 (Replace predecessor with range in collections documentation) - rust-lang#81558 (Fix ascii art text wrapping in mobile) - rust-lang#81562 (Clarify that InPlaceIterable guarantees extend to all advancing iterator methods.) - rust-lang#81563 (Improve docblock readability on small screen) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…ou-se Add strong_count mutation methods to Rc The corresponding methods were stabilized on `Arc` in rust-lang#79285 (tracking: rust-lang#71983). This patch implements and stabilizes identical methods on the `Rc` types as well.
Tracking issue: #71983
Stabilizes
Arc::{incr,decr}_strong_count
, enabling unsafely incrementing an decrementing the Arc strong count directly with fewer gotchas. This API was first introduced on nightly six months ago, and has not seen any changes since. The initial PR showed two existing pieces of code that would benefit from this API, and included a change inside the stdlib to use this.Given the small surface area, predictable use, and no changes since introduction, I'd like to propose we stabilize this.
closes #71983
r? @Mark-Simulacrum
Links