Skip to content

Don't let reflection handle noncopyable types yet. #64295

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

Merged
merged 1 commit into from
Mar 14, 2023

Conversation

jckarter
Copy link
Contributor

We don't have any language or runtime support for noncopyable types as generic or dynamic types yet, and existing reflection code almost certainly assumes it can copy the values it's working with, and will trap or corrupt state if it does so with noncopyable types. But a class can have noncopyable fields while the type itself is copyable, and existing code assumes that it can use Mirror or other reflection mechanisms to safely traverse the contents of an arbitrary class.

Allow this sort of code to continue working, while still preparing for forward compatibility with future runtimes that do support noncopyable generics, by emitting the type references for fields using a function that probes the address of a new symbol in the Swift runtime. The symbol will either be missing or defined with an absolute address of zero in current or previous runtime versions, but can be changed to a non-null address in the future. If the symbol is missing or zero, then lie to the requester and say that the field has empty tuple type, so that they hopefully pass over the field without being able to do anything with the value.

@jckarter jckarter requested a review from mikeash March 10, 2023 22:40
@jckarter
Copy link
Contributor Author

@swift-ci Please test

@jckarter jckarter force-pushed the noncopyable-hide-field-types branch from 3872b69 to 9983b9d Compare March 13, 2023 16:01
@jckarter
Copy link
Contributor Author

@swift-ci Please test

@jckarter jckarter force-pushed the noncopyable-hide-field-types branch from 9983b9d to 7509453 Compare March 13, 2023 17:56
@jckarter
Copy link
Contributor Author

@swift-ci Please test

1 similar comment
@jckarter
Copy link
Contributor Author

@swift-ci Please test

We don't have any language or runtime support for noncopyable types as generic
or dynamic types yet, and existing reflection code almost certainly assumes it
can copy the values it's working with, and will trap or corrupt state if it does
so with noncopyable types. But a class can have noncopyable fields while the
type itself is copyable, and existing code assumes that it can use `Mirror` or
other reflection mechanisms to safely traverse the contents of an arbitrary
class.

Allow this sort of code to continue working, while still preparing for forward
compatibility with future runtimes that do support noncopyable generics, by
emitting the type references for fields using a function that probes the
address of a new symbol in the Swift runtime. The symbol will either be missing
or defined with an absolute address of zero in current or previous runtime
versions, but can be changed to a non-null address in the future.
@jckarter jckarter force-pushed the noncopyable-hide-field-types branch from 7509453 to 4d6d765 Compare March 13, 2023 18:50
@jckarter
Copy link
Contributor Author

@swift-ci Please test

@jckarter jckarter merged commit 730c5cf into swiftlang:main Mar 14, 2023
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