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

Small owning ref refactoring #109948

Closed
wants to merge 7 commits into from

Conversation

WaffleLapkin
Copy link
Member

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 4, 2023
@@ -1117,41 +1111,41 @@ impl<T: 'static> ToHandleMut for RefCell<T> {
// about which handle creation to use (i.e., read() vs try_read()) as well as
// what to do with error results.

/// Typedef of an owning reference that uses a `Box` as the owner.
/// Type alias of an owning reference that uses a [`Box`] as the owner.
Copy link
Member

Choose a reason for hiding this comment

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

While we're at it, could you delete this impl for Box? It's unsound. If it's used we need to find a replacement. We can probably just use Arc without regressing perf.

Copy link
Member Author

Choose a reason for hiding this comment

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

What impl? This is a type alias...

Copy link
Member

Choose a reason for hiding this comment

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

Maybe the impl lives in the stable_deref_trait crate. But at least the type alias should be deleted, we should absolutely not be using an owning_ref with a Box, that's unsound because of boxes aliasing guarantees.

Copy link
Member Author

Choose a reason for hiding this comment

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

Would it be okay if we wrap the owner in MaybeUninit to hide the aliasing? 🤔

At least it convinces the miri I think:

Although I'm not sure if this is just a bug in MIRI...

Also/1: why do we have a copy of the owning_ref crate? 🤔
Also/2: wait owning_ref crate (same as with this module) is straight up unsound? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

MaybeUninit would work but that'd lose the niche and it's also kinda hacky. I'd prefer just deleting the Box and using an Arc, it's the easiest solution. If we really want a Box, then we can roll or own or use the one from ouroboros. Or we can make T-opsem give up on giving Box these bad and confusing rules :D

I think owning_ref had some unrelated unsoundnesses and is unmaintained which is why the fixed version is copied here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've searched for uses of (Owning|Box)Ref and we appear to only have 3 uses:

  • With Mmap (which is itself unsound 💀 ) in rustc_codegen_ssa::back::metadata::DefaultMetadataLoader (uses box to erase type)
  • With Mmap ( 💀 ) and Vec<u8> in rustc_metadata::locator (uses box to erase type)
  • With MetadataBlob in rustc_metadata::rmeta::def_path_hash_map

Given that all of these use T = [u8] and most erase U... maybe we can "just" yeet owning_ref with all it's unsoundness altogether and instead have something like this?

Copy link
Member

Choose a reason for hiding this comment

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

I tried an overcomplicated version of it in #97770. Your example sounds great, you should try it :).

@WaffleLapkin WaffleLapkin mentioned this pull request Apr 5, 2023
@WaffleLapkin
Copy link
Member Author

Closing in favor of #109971

@WaffleLapkin WaffleLapkin deleted the de_T_owning_ref branch April 5, 2023 13:55
Noratrieb added a commit to Noratrieb/rust that referenced this pull request Apr 7, 2023
…strieb

Yeet `owning_ref`

Based on the discussions from rust-lang#109948

This replaces `owning_ref` with a far simpler & safer abstraction.

Fixes rust-lang#109974
Noratrieb added a commit to Noratrieb/rust that referenced this pull request Apr 7, 2023
…strieb

Yeet `owning_ref`

Based on the discussions from rust-lang#109948

This replaces `owning_ref` with a far simpler & safer abstraction.

Fixes rust-lang#109974
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 8, 2023
…rieb

Yeet `owning_ref`

Based on the discussions from rust-lang#109948

This replaces `owning_ref` with a far simpler & safer abstraction.

Fixes rust-lang#109974
saethlin pushed a commit to saethlin/miri that referenced this pull request Apr 10, 2023
Yeet `owning_ref`

Based on the discussions from rust-lang/rust#109948

This replaces `owning_ref` with a far simpler & safer abstraction.

Fixes #109974
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants