Skip to content

[cxx-interop] Test std::optional with AddressableParameters #82809

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

egorzhdan
Copy link
Contributor

Please see each commit for details.

egorzhdan added 2 commits July 4, 2025 19:50
Enabling AddressableParameters feature resolves a miscompile with `var pointee` properties of `std::optional`.

rdar://154945438 / #82765
If we could not infer lifetime dependencies for a C++ method, let's cache the empty result. This prevents the compiler from trying to evaluate this request using Swift Sema's algorithm.

This change is meant to fix the following issue:

With AddressableParameters enabled, instantiations of `std::optional<T>` lack the conformance to `protocol CxxOptional`, despite the synthesized conformance being added correctly to each instantiation.

This happens because when importing `operator*()` of each instantiation, ClangImporter spins up a LifetimeDependenceInfoRequest for the incompletely imported C++ type. In particular, the synthesized protocol conformances aren't yet added at that point, since the conformance logic relies on type's members already being imported. The LifetimeDependenceInfoRequest triggers a ConformanceTable to be built and cached for the instantiation. Later, by the time the conformance synthesis logic runs, the ConformanceTable for the instantiation had already been populated, and won't be updated to add the new conformance.
@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Jul 4, 2025
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

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.

1 participant