-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] Builtin functions should ignore return type nullability… #74494
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
[cxx-interop] Builtin functions should ignore return type nullability… #74494
Conversation
@swift-ci please smoke test |
ce9493d
to
5976241
Compare
@swift-ci please test |
@swift-ci please test source compatibility |
5976241
to
8426df1
Compare
@swift-ci please test source compatibility |
@swift-ci please test |
8426df1
to
5a28cdb
Compare
@swift-ci please test source compatibility |
@swift-ci please test |
5a28cdb
to
b92fcc2
Compare
@swift-ci please test |
@swift-ci please test source compatibility |
@swift-ci please test windows platform |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…re return type nullability to be compatible with C interop In C interop mode, the return type of builtin functions like 'memcpy' from headers like 'string.h' drops any nullability specifiers from their return type, and preserves it on the declared return type. Thus, in C mode the imported return type of such functions is always optional. However, in C++ interop mode, the return type of builtin functions can preseve the nullability specifiers on their return type, and thus the imported return type of such functions can be non-optional, if the type is annotated with `_Nonnull`. The difference between these two modes can break cross-module Swift serialization, as Swift will no longer be able to resolve an x-ref such as 'memcpy' from a Swift module that uses C interop, within a Swift context that uses C++ interop. In order to avoid the x-ref resolution failure, normalize the return type's nullability for builtin functions in C++ interop mode, to match the imported type in C interop mode. This fixed an issue when using 'memcpy' from the Android NDK in a x-module context, like between Foundation (that inlines it) and another user module.
b92fcc2
to
e4ad3c1
Compare
@swift-ci please test |
@swift-ci please test |
@swift-ci please test windows platform |
@swift-ci please test windows platform |
1 similar comment
@swift-ci please test windows platform |
@swift-ci please test |
… to be compatible with C interop
In C interop mode, the return type of builtin functions like 'memcpy' drops any nullability specifiers from their return type, and preserves it on the declared return type. Thus, in C mode the imported return type of such functions is always optional. However, in C++ interop mode, the return type of builtin functions can preseve the nullability specifiers on their return type, and thus the imported return type of such functions can be non-optional, if the type is annotated with
_Nonnull
. The difference between these two modes can break cross-module Swift serialization, as Swift will no longer be able to resolve an x-ref such as 'memcpy' from a Swift module that uses C interop, within a Swift context that uses C++ interop. In order to avoid the x-ref resolution failure, normalize the return type's nullability for builtin functions in C++ interop mode, to match the imported type in C interop mode.This fixed an issue when using 'memcpy' from the Android NDK in a x-module context, like between Foundation (that inlines it) and another user module.