-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 std::{rc,sync}::Weak::{weak_count, strong_count}
#65778
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @rkruppe (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
The diff looks good to me, but stabilizing requires a @rust-lang/libs FCP and that hasn't happened yet on the tracking issue. I don't think the bot will listen to me, so let's wait for a libs team member to show up. |
@rfcbot fcp merge Looks like this is stabilizing: mod rc {
impl Weak<T> {
pub fn strong_count(&self) -> usize;
pub fn weak_count(&self) -> Option<usize>;
}
}
mod sync {
impl Weak<T> {
pub fn strong_count(&self) -> usize;
pub fn weak_count(&self) -> Option<usize>;
}
} where |
Team member @alexcrichton 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. |
I assume this may have already been discussed, but why would a |
I believe it's "technically a lie" because you can clone a |
Ah right, that makes sense. |
@rfcbot concern is this the API we want? The motivation for this seems to be entirely focused around cheaply determining if If we do want this API as-is then I think the docs need a little more attention. |
I agree that having an additional |
Perhaps an |
@jonas-schievink Do you have any examples of such a datastructure that needs to assert on the count through a If not, I think I'd err towards stabilizing the semantically tighter |
My original use case for adding these methods was for unit tests in https://github.com/jonas-schievink/rcgc, which would've benefitted from the exact counts |
@rfcbot resolved is this the API we want? Ok, thanks for the follow-up @jonas-schievink! Modulo docs I'll call this concern resolved and not block stabilization. |
One of the problems with the current API is that it exposes certain internals which we might not keep forever. For example this program:
currently prints However, value is dropped, weak will never become strong. In particular, in However, when we intentionally specify that If we really need to expose counters (instead of |
An option would be to specify that |
@stepancheg any thoughts on the suggestion above - whether |
@bdonlan Good question. IMHO returning zero from weak count when strong is zero would be consistent. For the same reason: allow future optimizations without breaking compatibility. |
I'd be happy to update the semantics of weak_count to reflect that if it's desirable - not sure what the process would be for this though. Should I open a separate PR for that, or just add a commit here? Or do we need more consensus from the T-libs team members first? |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
💔 Test failed - checks-azure |
Looks like chocolatey is flaking again. Chocolatey v0.10.15
Installing the following packages:
msys2
By installing you accept licenses for the packages.
msys2 not installed. An error occurred during installation:
The remote server returned an error: (503) Server Unavailable. Service Unavailable
msys2 package files install completed. Performing other installation steps.
The install of msys2 was NOT successful.
msys2 not installed. An error occurred during installation:
The remote server returned an error: (503) Server Unavailable. Service Unavailable
Chocolatey installed 0/1 packages. 1 packages failed.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
Failures
- msys2 (exited 1) - msys2 not installed. An error occurred during installation:
The remote server returned an error: (503) Server Unavailable. Service Unavailable @bors retry |
Stabilize `std::{rc,sync}::Weak::{weak_count, strong_count}` * Original PR: rust-lang#56696 * Tracking issue: rust-lang#57977 Closes: rust-lang#57977 Supporting comments: > Although these were added for testing, it is occasionally useful to have a way to probe optimistically for whether a weak pointer has become dangling, without actually taking the overhead of manipulating atomics. Are there any plans to stabilize this? _Originally posted by @bdonlan in rust-lang#57977 (comment) > Having this stabilized would help. Currently, the only way to check if a weak pointer has become dangling is to call `upgrade`, which is by far expensive. _Originally posted by @glebpom in rust-lang#57977 (comment) Not sure if stabilizing these warrants a full RFC, so throwing this out here as a start for now. Note: per CONTRIBUTING.md, I ran the tidy checks, but they seem to be failing on unchanged files (primarily in `src/stdsimd`).
Stabilize `std::{rc,sync}::Weak::{weak_count, strong_count}` * Original PR: rust-lang#56696 * Tracking issue: rust-lang#57977 Closes: rust-lang#57977 Supporting comments: > Although these were added for testing, it is occasionally useful to have a way to probe optimistically for whether a weak pointer has become dangling, without actually taking the overhead of manipulating atomics. Are there any plans to stabilize this? _Originally posted by @bdonlan in rust-lang#57977 (comment) > Having this stabilized would help. Currently, the only way to check if a weak pointer has become dangling is to call `upgrade`, which is by far expensive. _Originally posted by @glebpom in rust-lang#57977 (comment) Not sure if stabilizing these warrants a full RFC, so throwing this out here as a start for now. Note: per CONTRIBUTING.md, I ran the tidy checks, but they seem to be failing on unchanged files (primarily in `src/stdsimd`).
Rollup of 6 pull requests Successful merges: - #65778 (Stabilize `std::{rc,sync}::Weak::{weak_count, strong_count}`) - #66570 (stabilize Result::map_or) - #67206 (Update cargo, books) - #67285 (Indicate origin of where type parameter for uninferred types ) - #67317 (fix type_name_of_val doc comment) - #67324 (Fix repetition in matches/mod.rs) Failed merges: r? @ghost
Stabilize `std::{rc,sync}::Weak::{weak_count, strong_count}` * Original PR: rust-lang#56696 * Tracking issue: rust-lang#57977 Closes: rust-lang#57977 Supporting comments: > Although these were added for testing, it is occasionally useful to have a way to probe optimistically for whether a weak pointer has become dangling, without actually taking the overhead of manipulating atomics. Are there any plans to stabilize this? _Originally posted by @bdonlan in rust-lang#57977 (comment) > Having this stabilized would help. Currently, the only way to check if a weak pointer has become dangling is to call `upgrade`, which is by far expensive. _Originally posted by @glebpom in rust-lang#57977 (comment) Not sure if stabilizing these warrants a full RFC, so throwing this out here as a start for now. Note: per CONTRIBUTING.md, I ran the tidy checks, but they seem to be failing on unchanged files (primarily in `src/stdsimd`).
⌛ Testing commit 9778e03 with merge da8b4f5d292f705c91fa120a8649a9f545518383... |
Your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
💔 Test failed - checks-azure |
Rollup of 7 pull requests Successful merges: - #65778 (Stabilize `std::{rc,sync}::Weak::{weak_count, strong_count}`) - #66570 (stabilize Result::map_or) - #66735 (Add str::strip_prefix and str::strip_suffix) - #66771 (Stabilize the `core::panic` module) - #67317 (fix type_name_of_val doc comment) - #67324 (Fix repetition in matches/mod.rs) - #67325 (cleanup with push_fake_read) Failed merges: r? @ghost
@bors retry |
Rollup of 7 pull requests Successful merges: - #65778 (Stabilize `std::{rc,sync}::Weak::{weak_count, strong_count}`) - #66570 (stabilize Result::map_or) - #66735 (Add str::strip_prefix and str::strip_suffix) - #66771 (Stabilize the `core::panic` module) - #67317 (fix type_name_of_val doc comment) - #67324 (Fix repetition in matches/mod.rs) - #67325 (cleanup with push_fake_read) Failed merges: r? @ghost
Closes: #57977
Supporting comments:
Originally posted by @bdonlan in #57977 (comment)
Originally posted by @glebpom in #57977 (comment)
Not sure if stabilizing these warrants a full RFC, so throwing this out here as a start for now.
Note: per CONTRIBUTING.md, I ran the tidy checks, but they seem to be failing on unchanged files (primarily in
src/stdsimd
).