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

Add Arc::into_inner for safely discarding Arcs without calling the destructor on the inner type. #106854

Merged
merged 1 commit into from
Jan 23, 2023

Conversation

steffahn
Copy link
Member

@steffahn steffahn commented Jan 14, 2023

ACP: rust-lang/libs-team#162

Reviving #79665.

I want to get this merged this time; this does not contain changes (apart from very minor changes in comments/docs).

See #79665 for further description of the PR. The only “unresolved” points that led to that PR being closed, AFAICT, were

  • The desire to also implement a Rc::into_inner function
    • however, this can very well also happen as a subsequent PR
  • Possible need for further discussion on the naming “into_inner” (?)
    • into_inner seems fine to me; also, this PR introduces unstable API, and names can be changed later, too
  • I don't know if a tracking issue for the feature flag is supposed to be opened before or after this PR gets merged (if before, then I can add the issue number to the #[unstable…] attribute) There is a tracking issue now.

I say “unresolved” in quotation marks because from my point of view, if reviewers agree, the PR can be merged immediately and as-is :-)

@rustbot
Copy link
Collaborator

rustbot commented Jan 14, 2023

r? @Mark-Simulacrum

(rustbot has picked a reviewer for you, use r? to override)

@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 Jan 14, 2023
@rustbot
Copy link
Collaborator

rustbot commented Jan 14, 2023

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@steffahn
Copy link
Member Author

@rustbot label +T-libs-api -T-libs

@rustbot rustbot added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 14, 2023
@steffahn steffahn changed the title Add Arc::into_inner for safely discarding Arcs without calling the destructor on the inner type. Add Arc::into_inner for safely discarding Arcs without calling the destructor on the inner type. Jan 14, 2023
@steffahn
Copy link
Member Author

ACP… that’s something new o.O

So I should open an ACP issue? I’d just copy the bottom section from #79665 with a new render of the documentation.

@m-ou-se
Copy link
Member

m-ou-se commented Jan 14, 2023

ACP… that’s something new o.O

Yeah that's something new we're trying out to separate the 'should we have this' discussion from the implementation review. (And to allow that discussion to happen before the implementation, in case you don't want to risk implementing something that won't be accepted.)

@steffahn
Copy link
Member Author

Added a remark as suggested in #79665 (comment)

@Mark-Simulacrum
Copy link
Member

r=me with commits squashed, thanks!

…structor on the inner type.

Mainly rebased and squashed from PR rust-lang#79665,
furthermore includes minor changes in comments.
@steffahn steffahn force-pushed the drop_linear_arc_rebased branch from 3eec330 to 33696fa Compare January 21, 2023 16:44
@steffahn
Copy link
Member Author

squashed

@Mark-Simulacrum
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jan 21, 2023

📌 Commit 33696fa has been approved by Mark-Simulacrum

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 Jan 21, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 23, 2023
Rollup of 7 pull requests

Successful merges:

 - rust-lang#104926 (Move relationships from FulfillmentContext to Inherited)
 - rust-lang#106854 (Add `Arc::into_inner` for safely discarding `Arc`s without calling the destructor on the inner type.)
 - rust-lang#107108 (Consider doc(alias) when providing typo suggestions)
 - rust-lang#107186 (rustdoc: Use correct pseudo-element selector)
 - rust-lang#107192 (Add myself to the mailmap)
 - rust-lang#107195 (Fix typo in universal_regions.rs comment)
 - rust-lang#107203 (Suggest remove deref for type mismatch)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 28081a6 into rust-lang:master Jan 23, 2023
@rustbot rustbot added this to the 1.69.0 milestone Jan 23, 2023
@kvark
Copy link
Contributor

kvark commented Jun 8, 2023

@steffahn congratulations to this being landed and stabilizing!
I find the functionality much needed. However, it misses one important case - what to do with Sized? types.
We'd very much still want this property to hold:

If Arc::into_inner is called on every clone of this Arc, it is guaranteed that exactly one of the calls returns the inner value. This means in particular that the inner value is not dropped.

Except that for the unsized types, only one call to a function will succeed, but it will not be able to return the inner value.
I considered the alternatives, and I don't think there is anything to help with this right now:

  • Arc::into_inner is only for T: Sized
  • Arc::get_mut isn't dropping, therefore multiple such arcs can return None if checked before destruction.

Maybe I'm missing something? Or maybe this discussion has already happened somewhere, excuse me for not finding it!

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-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants