Skip to content

Comment on Rc abort-guard strategy without naming unrelated fn #140483

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

Merged
merged 2 commits into from
May 7, 2025

Conversation

baumanj
Copy link
Contributor

@baumanj baumanj commented Apr 29, 2025

wrapped_add is used, not checked_add, so avoid mentioning specific fn calls that may vary slightly based on "whatever produces the best code" and focus on things that will remain constant into the future.

`wrapped_add` is used, not `checked_add`
@rustbot
Copy link
Collaborator

rustbot commented Apr 29, 2025

r? @workingjubilee

rustbot has assigned @workingjubilee.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 29, 2025
@@ -3536,7 +3536,7 @@ impl<T> Default for Weak<T> {
}
}

// NOTE: We checked_add here to deal with mem::forget safely. In particular
// NOTE: We wrapping_add here to deal with mem::forget safely. In particular
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is confusing in a different way: the wrapping_add does not offer the protection anymore, the strong == 0 conditional does.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at the very least, it should mention clearly what actually implements the guard that handles the mem::forget, if it's going to mention any code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you mean. The fact that it's wrapping_add rather than checked_add previously is merely a detail for the sake of code generation, and that's addressed in a more local comment. In that case, I think this comment is more about the higher level issue of a potential soundness hole and isn't enhanced by mentioning the particular implementation details. How about this?

// NOTE: If you mem::forget Rcs (or Weaks), drop is skipped and the ref-count
// is not decremented, meaning the ref-count can overflow, and then you can
// free the allocation while outstanding Rcs (or Weaks) exist, which would be
// unsound. We abort because this is such a degenerate scenario that we don't
// care about what happens -- no real program should ever experience this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, something like that seems good to me.

@workingjubilee
Copy link
Member

I think this requires more than a one-word change to make something that makes sense. At least in the current mistaken form it's obviously "checked_add by hand"

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 30, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 30, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

Update comment per review feedback
@baumanj
Copy link
Contributor Author

baumanj commented May 6, 2025

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 6, 2025
@workingjubilee workingjubilee changed the title Update rc.rs docs Comment on Rc abort-guard strategy without naming unrelated fn May 6, 2025
@workingjubilee
Copy link
Member

Thanks!

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented May 6, 2025

📌 Commit 6a4af82 has been approved by workingjubilee

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 6, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request May 7, 2025
Rollup of 9 pull requests

Successful merges:

 - rust-lang#134273 (de-stabilize bench attribute)
 - rust-lang#139534 (Added support for `apxf` target feature)
 - rust-lang#140419 (Move `in_external_macro` to `SyntaxContext`)
 - rust-lang#140483 (Comment on `Rc` abort-guard strategy without naming unrelated fn)
 - rust-lang#140607 (support duplicate entries in the opaque_type_storage)
 - rust-lang#140656 (collect all Fuchsia bindings into the `fuchsia` module)
 - rust-lang#140668 (Implement `VecDeque::truncate_front()`)
 - rust-lang#140709 (rustdoc: remove unportable markdown lint and old parser)
 - rust-lang#140713 (Structurally resolve in `check_ref_cast` in new solver)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 25631ff into rust-lang:master May 7, 2025
6 checks passed
@rustbot rustbot added this to the 1.88.0 milestone May 7, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 7, 2025
Rollup merge of rust-lang#140483 - baumanj:patch-1, r=workingjubilee

Comment on `Rc` abort-guard strategy without naming unrelated fn

`wrapped_add` is used, not `checked_add`, so avoid mentioning specific fn calls that may vary slightly based on "whatever produces the best code" and focus on things that will remain constant into the future.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants