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

Implement sound map value aliasing #83

Merged
merged 1 commit into from
Dec 6, 2020
Merged

Implement sound map value aliasing #83

merged 1 commit into from
Dec 6, 2020

Commits on Dec 6, 2020

  1. Implement sound map value aliasing

    This implementation gets rid of the unsound `ShallowCopy` trait (#74 &
    rust-lang/unsafe-code-guidelines#35 (comment)),
    and replaces it with a wrapper type around aliased values.
    
    The core mechanism is that the wrapper type holds a `MaybeUninit<T>`,
    and aliases it by doing a `ptr::read` of the whole `MaybeUninit<T>` to
    alias. It then takes care to only give out `&T`s, which is allowed to
    alias.
    
    To drop, the implementation casts between two different generic
    arguments of the new `Aliased` type, where one type causes the
    `Aliased<T>` to drop the inner `T` and the other does not. The
    documentation goes into more detail. The resulting cast _should_ be safe
    (unlike the old `ManuallyDrop` cast).
    
    The removal of `ShallowCopy` makes some of the API nicer by removing
    trait bounds, and obviates the need for `evmap-derive`. While I was
    going through, I also took the liberty of tidying up the external API of
    `evmap` a bit.
    
    The implementation passes all tests, and I _think_ it is sound (if you
    think it's not, please let me know!).
    
    Note that this does _not_ take care of #78.
    
    Fixes #74.
    Fixes #55 since `ShallowCopy` is no longer neeeded.
    Also fixes #72 for the same reason.
    jonhoo committed Dec 6, 2020
    Configuration menu
    Copy the full SHA
    416ccef View commit details
    Browse the repository at this point in the history