Skip to content

🍒[cxx-interop] Skip type metadata for C++ types that are only used in private C++ fields #78607

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
Jan 14, 2025

Conversation

egorzhdan
Copy link
Contributor

@egorzhdan egorzhdan commented Jan 13, 2025

Explanation: When importing C++ types that use pointer-to-implementation idiom, when the implementation type is forward-declared, the compiler would previously emit an error:

invalid application of 'sizeof' to an incomplete type

This was happening because Swift was trying to emit the value witness table for std::unique_ptr<IncompleteType>, which isn't possible, because the destructor cannot be instantiated for an incomplete pointee type.
Scope: This changes IRGen logic that emits Swift metadata for private fields. It now ignores private fields imported from Clang, since there is no way to use those from Swift.
Risk: Low, this only affects type metadata of private fields. Swift started importing C++ private fields very recently. Non-C++ imported types don't get private fields in Swift.
Testing: Added new compiler tests.
Issue: rdar://141960396
Reviewer: @Xazax-hun @rjmccall

Original PR: #78467

…private C++ fields

This fixes compiler errors for C++ types that use pimpl idiom:
```
invalid application of 'sizeof' to an incomplete type
```

rdar://141960396
(cherry picked from commit 738c8fb)
@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Jan 13, 2025
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

@egorzhdan egorzhdan marked this pull request as ready for review January 13, 2025 17:21
@egorzhdan egorzhdan requested a review from a team as a code owner January 13, 2025 17:21
@egorzhdan egorzhdan merged commit 9d95d2c into release/6.1 Jan 14, 2025
5 checks passed
@egorzhdan egorzhdan deleted the egorzhdan/6.1-sizeof-incomplete branch January 14, 2025 18:17
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++
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants