Skip to content

Conversation

@kjvalencik
Copy link
Member

@kjvalencik kjvalencik commented Dec 2, 2021

Currently, it is possible to Copy and Clone Js* types which is unsafe. These types depend on being contained in a Handle to verify the lifetime. They should only exist as references outside of a Handle. Unfortunately, the ability to clone allows getting an owned copy from a reference.

This change attempts to minimize impact to users by making Handle<T> Copy, while making the inner T !Copy. This works by introducing a new marker trait TransparentWrapper which indicates a type is a transparent wrapper around a TransparentWrapper::Inner type--allowing transmutation between the two.

Using this trait, Handle actually stores a Copy inner type, while implementing Deref with a Target to the !Copy outer type.

Unfortunately, since Copy won't propagate upward from a Deref, all APIs that currently take self on a Value were changed to take &self to keep from requiring a manual clone(). This could still impact users in some places--for example when creating an Object with a circular reference.

@kjvalencik kjvalencik marked this pull request as ready for review December 2, 2021 19:24
Copy link
Collaborator

@dherman dherman left a comment

Choose a reason for hiding this comment

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

This looks like a great solution. I just found the explanation confusing which made it hard to review at first. Once we improve the presentation of the trait a little bit I think it’ll be manageable from a maintenance perspective.

@kjvalencik kjvalencik force-pushed the kv/copy-safety branch 2 times, most recently from 927bbc8 to 84a8497 Compare January 14, 2022 15:53
@kjvalencik kjvalencik merged commit f7ae61c into next/0.10 Jan 14, 2022
@kjvalencik kjvalencik deleted the kv/copy-safety branch January 14, 2022 18:06
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.

3 participants