Skip to content

[cxx-interop] Fix lookup of class template instantiations #58543

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
May 3, 2022

Conversation

egorzhdan
Copy link
Contributor

To fix a crash during deserialization, we need to store the mangled names of C++ class template instantiations in the lookup table.

For example, std::string will be serialized as __CxxTemplateInstNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE, and when another instance of the Swift compiler will later attempt to deserialize a decl referencing this instantiation, it will query the SwiftLookupTable for a decl with this name. If this instantiation is not referenced from the module that is currently being compiled, Swift will not instantiate std::string during typechecking, and the mangled name will be missing from SwiftLookupTable, leading to a deserialization failure. This happens when compiling with cross-module optimization enabled, and the current module does not reference std::string, but one of its dependencies does.

To fix a crash during deserialization, we need to store the mangled names of C++ class template instantiations in the lookup table.

For example, `std::string` will be serialized as `__CxxTemplateInstNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE`, and when another instance of the Swift compiler will later attempt to deserialize a decl referencing this instantiation, it will query the `SwiftLookupTable` for a decl with this name. If this instantiation is not referenced from the module that is currently being compiled, Swift will not instantiate `std::string` during typechecking, and the mangled name will be missing from `SwiftLookupTable`, leading to a deserialization failure. This happens when compiling with cross-module optimization enabled, and the current module does not reference `std::string`, but one of its dependencies does.
@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Apr 29, 2022
@egorzhdan egorzhdan requested a review from zoecarver April 29, 2022 20:57
@egorzhdan
Copy link
Contributor Author

This is a requirement for #42297

@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan egorzhdan merged commit 4820838 into main May 3, 2022
@egorzhdan egorzhdan deleted the egorzhdan/cxx-template-inst-lookup branch May 3, 2022 18: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