Skip to content

🍒[cxx-interop] Treat un-instantiated templated types as unsafe #64918

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
Apr 7, 2023

Conversation

egorzhdan
Copy link
Contributor

@egorzhdan egorzhdan commented Apr 4, 2023

Explanation: This adjusts the C++ method importing logic to treat methods that return templated types as unsafe if the template was not instantiated. Previously such methods were treated as safe, even if the templated return type stores pointers in its fields.
Scope: This makes certain C++ methods unavailable that were previously available in Swift.
Risk: Low: C++ interop is an experimental feature that is not used in production.
Testing: Added LIT tests.

rdar://107609381
(cherry picked from commit c813254)

When determining whether a C++ method is safe to be imported, we look at its return type to see if it stores any pointers in its fields.

If the type is templated, we might not have its definition available yet. Unfortunately we cannot instantiate it on the spot, since the Clang AST would be read and written at the same time.

Let's stay on the safe side and treat such methods as unsafe.

rdar://107609381
(cherry picked from commit c813254)
@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Apr 4, 2023
@egorzhdan egorzhdan requested a review from a team as a code owner April 4, 2023 19:09
@egorzhdan egorzhdan changed the title [cxx-interop] Treat un-instantiated templated types as unsafe 🍒[cxx-interop] Treat un-instantiated templated types as unsafe Apr 4, 2023
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

@egorzhdan egorzhdan requested a review from hyp April 4, 2023 19:15
@egorzhdan
Copy link
Contributor Author

@swift-ci please test Windows

@egorzhdan
Copy link
Contributor Author

@swift-ci please test macOS

@egorzhdan egorzhdan merged commit 5fd4979 into release/5.9 Apr 7, 2023
@egorzhdan egorzhdan deleted the egorzhdan/5.9-pointy-is-scary branch April 7, 2023 15:51
@AnthonyLatsis AnthonyLatsis added the 🍒 release cherry pick Flag: Release branch cherry picks label May 3, 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++ 🍒 release cherry pick Flag: Release branch cherry picks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants