Skip to content

🍒[cxx-interop] Avoid circular reference errors when importing C++ structs #69365

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
Oct 26, 2023

Conversation

egorzhdan
Copy link
Contributor

@egorzhdan egorzhdan commented Oct 24, 2023

Explanation:
When importing a C++ struct, if its owning module requires cplusplus, Swift tried to auto-conform it to certain protocols from the Cxx module. This triggers name lookup in the clang struct, specifically for __beginUnsafe() and __endUnsafe() methods, which imports all of the base structs including their methods.
This moves the import of base structs out of the name lookup request, preventing cycles.
Scope: All of the code changes are on a C++ interop only code path.
Risk: Low, only takes effect when C++ interop is enabled.
Testing: Covered by LIT tests.
Original PR: #69327

rdar://116426238
(cherry picked from commit 4632d89)

When importing a C++ struct, if its owning module requires cplusplus, Swift tried to auto-conform it to certain protocols from the Cxx module. This triggers name lookup in the clang struct, specifically for `__beginUnsafe()` and `__endUnsafe()` methods, which imports all of the base structs including their methods.

This moves the import of base structs out of the name lookup request, preventing cycles.

rdar://116426238
(cherry picked from commit 4632d89)
@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Oct 24, 2023
@egorzhdan egorzhdan requested a review from hyp October 24, 2023 15:24
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

@egorzhdan egorzhdan marked this pull request as ready for review October 24, 2023 18:31
@egorzhdan egorzhdan requested a review from a team as a code owner October 24, 2023 18:31
@egorzhdan egorzhdan merged commit 8a1590d into release/5.10 Oct 26, 2023
@egorzhdan egorzhdan deleted the egorzhdan/5.10-circular-requests branch October 26, 2023 20:46
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.

2 participants