Skip to content

[cxx-interop] Mark C++ functions with unavailable return type as unav… #67235

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
Jul 12, 2023

Conversation

hyp
Copy link
Contributor

@hyp hyp commented Jul 11, 2023

…ailable

This prevents users from calling functions with unsupported or unavailable return types. This ensures that users don't for example call a function that returns a non-copyable and non-movable type

Fixes #64401

  • Explanation: Swift's clang importer imports functions without knowing their imported return type, sometimes. This is important as we must delay the evaluation of the C++ return type in some cases. When the imported return type is not known, it's imported and mapped into Swift later, during the evaluation of the function's return type request. However, not all C++ types can be imported, they're either unsupported (e.g. non-copyable) or unavailable (from an unexported module). In this case, clang importer sets the function's type to be Never. This works as a placeholder, but it doesn't produce errors to users in all cases. For instance, the user can still call a function and store its value into a let constant, even if it's Never. And then the underlying C++ type won't be correctly operated on, for instance, if it needs to be destroyed with a custom C++ destructor, causing potential leaks. This change plugs this hole by ensuring we at least mark such functions as unavailable when we know that their return type is unsupported. This specific fix is a compromise as it's not ideal to make such a change to the function when computing the return type, but the previous approach of determining this earlier ([5.9][interop] do not import functions whose return type is not imported #65105) didn't work out as it caused semantics issues with some C++ member functions.
  • Scope: C++ interop, function result type request.
  • Risk: Low, affects only the path of unsupported/unavailable C++ return type for an imported function.
  • Testing: Unit tests, adopter testing.
  • Original PR: [cxx-interop] Mark C++ functions with unavailable return type as unav… #67234

…ailable

This prevents users from calling functions with unsupported or unavailable return types. This ensures that users don't for example call a function that returns a non-copyable and non-movable type

Fixes swiftlang#64401
@hyp hyp added c++ interop Feature: Interoperability with C++ swift 5.9 labels Jul 11, 2023
@hyp hyp requested a review from a team as a code owner July 11, 2023 23:51
@hyp
Copy link
Contributor Author

hyp commented Jul 11, 2023

@swift-ci please test

@hyp
Copy link
Contributor Author

hyp commented Jul 11, 2023

@swift-ci please test source compatibility

@hyp hyp merged commit 678b0fc into swiftlang:release/5.9 Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ interop Feature: Interoperability with C++ swift 5.9
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants