Skip to content
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 Weak::{weak_count, strong_count} #57977

Closed
jonas-schievink opened this issue Jan 29, 2019 · 4 comments · Fixed by #65778
Closed

Tracking issue for Weak::{weak_count, strong_count} #57977

jonas-schievink opened this issue Jan 29, 2019 · 4 comments · Fixed by #65778
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@jonas-schievink
Copy link
Contributor

This issue tracks stabilization for 4 methods added in #56696:

  • std::rc::Weak::{strong_count, weak_count}
  • std::sync::Weak::{strong_count, weak_count}
@jonas-schievink jonas-schievink added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC labels Jan 29, 2019
bors added a commit that referenced this issue Jan 31, 2019
Implement Weak::{strong_count, weak_count}

The counters are also useful on `Weak`, not just on strong references (`Rc` or `Arc`).

In situations where there are still strong references around, you can also get these counts by temporarily upgrading and adjusting the values accordingly. Using the methods introduced here is simpler to do, less error-prone (since you can't forget to adjust the counts), can also be used when no strong references are around anymore, and might be more efficient due to not having to temporarily create an `Rc`.

This is mainly useful in assertions or tests of complex data structures. Data structures might have internal invariants that make them the sole owner of a `Weak` pointer, and an assertion on the weak count could be used to ensure that this indeed happens as expected. Due to the presence of `Weak::upgrade`, the `strong_count` becomes less useful, but it still seems worthwhile to mirror the API of `Rc`.

TODO:
* [X] Tracking issue - #57977

Closes #50158
@bdonlan
Copy link
Contributor

bdonlan commented Jul 31, 2019

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?

@glebpom
Copy link

glebpom commented Sep 1, 2019

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.

@stepancheg
Copy link
Contributor

Currently, the only way to check if a weak pointer has become dangling is to call upgrade, which is by far expensive

Exactly my thoughts. So instead of stabilizing strong_count and weak_count we probably want fn has_strong(&self) -> bool.

@alexcrichton
Copy link
Member

A concern has been listed for stabilization, so if those here interested in this would be willing to help out with that, that would be great!

Centril added a commit to Centril/rust that referenced this issue Dec 15, 2019
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`).
Centril added a commit to Centril/rust that referenced this issue Dec 15, 2019
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`).
Centril added a commit to Centril/rust that referenced this issue Dec 16, 2019
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`).
@bors bors closed this as completed in 91ee3d1 Dec 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants