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 CartableOptionPointer and helpers to the yoke crate #4449

Merged
merged 16 commits into from
Dec 15, 2023

Conversation

sffc
Copy link
Member

@sffc sffc commented Dec 13, 2023

Split from #4442

I do think this is in scope for yoke because the type can be a "one-way" type that is a more efficient cart than either Option<Rc<T>> or Option<ErasedRcCart>.

Copy link
Member

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

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

I'm opposed to this, for a bunch of reasons

Firstly, I think the use case here is rather specific; I don't think it's something that makes a lot of sense for most yoke users overall. If we get asks for something like this I'd like to design it based on the asks rather than genericizing the thing that ICU4X needs in a particular direction and assuming that that direction is what is needed.

Secondly, the abstraction itself is incredibly generic in a way that is both rather hard to understand for users (IMO) and rather hard to grapple with the safety of. I think we're introducing a lot of concepts here that interact in subtle ways.

(For this to land it is going to need a lot more careful documentation of the safety needs)

@sffc
Copy link
Member Author

sffc commented Dec 13, 2023

Firstly, I think the use case here is rather specific; I don't think it's something that makes a lot of sense for most yoke users overall. If we get asks for something like this I'd like to design it based on the asks rather than genericizing the thing that ICU4X needs in a particular direction and assuming that that direction is what is needed.

I don't agree that it is ICU4X-specific. This new cart type OptionCartablePointer is another in-house cart abstraction, like ErasedRcCart, which is better than any of the other cart abstractions being offered. This is especially true because we already have a lot of code specializing over both Rc and Option carts, so we clearly have already put a stake in the ground that we expect Option<Rc> to be a cart we expect people to want when they are using Yoke.

Secondly, the abstraction itself is incredibly generic in a way that is both rather hard to understand for users (IMO) and rather hard to grapple with the safety of. I think we're introducing a lot of concepts here that interact in subtle ways.

Almost all of the unsafety is encapsulated in the new CartablePointerLike trait. I do not think it is too generic. In fact it turns out that there actually are not very many safety invariants at play; at the end of the day this type is just an efficient way to store the "raw" representation of pointer-like types (reference, Box, Rc, and Arc).

(For this to land it is going to need a lot more careful documentation of the safety needs)

Would like to pair with you today on writing the documentation.

@sffc sffc requested a review from Manishearth December 13, 2023 19:53
Copy link
Member

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

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

code looks good, minor issues around docs and examples

/// 1. The pointer MUST have been returned by this impl's `into_raw`.
/// 2. The pointer MUST NOT be dangling.
#[doc(hidden)]
unsafe fn clone_raw(pointer: NonNull<Self::Raw>);
Copy link
Member

Choose a reason for hiding this comment

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

nit (nb): I kinda prefer "addref" or something here

// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

//! Types for optional pointers that may be dropped with niche optimization.
Copy link
Member

Choose a reason for hiding this comment

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

issue: this should be expanded a bit, at the very least pointing to the main type from this crate (CartableOptionPointer)


/// A type with similar semantics as `Option<C<T>>` but with a niche.
///
/// Will panic on types with alignment 1.
Copy link
Member

Choose a reason for hiding this comment

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

issue: needs an example

}
}

// Safety: logically an Option<C>. Has same bounds as Option<C>
Copy link
Member

Choose a reason for hiding this comment

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

nit: with my other PR landing you can potentially relate to the invariants specified there

@sffc sffc merged commit 337d268 into unicode-org:main Dec 15, 2023
28 checks passed
@sffc sffc deleted the yoke-option-ref branch December 15, 2023 23:57
Manishearth added a commit that referenced this pull request Dec 18, 2023
Technically breaking, but I think this constness was a mistake and we
don't use it internally (and there's very little reason for someone to
use it externally, the static stuff exists).

This is useful for #4449 ; it
allows us to reference statics in the constructor of `DataPayload()`
which lets us reference a *proper* sentinel rather than a made-up value
that will not work in WASM.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants