-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] Import typedef
-ed template instantiations
#32950
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
Conversation
@swift-ci please test |
Build failed |
@swift-ci please test |
Build failed |
Co-authored-by: Dmitri Gribenko <gribozavr@gmail.com>
@swift-ci please test |
Build failed |
Build failed |
@swift-ci please test |
Build failed |
Build failed |
@swift-ci please test |
We are seeing following test failures:
https://ci.swift.org/job/oss-swift-incremental-RA-osx/12557/console |
I'm investigating, but it's getting late here in Europe, so the fix might get submitted tomorrow morning. Feel free to rollback if that's not soon enough. |
This is the error from the log:
Building on my mac in the meantime. |
### Class templates: Importing full class template instantiations | ||
|
||
A class template instantiation could be imported as a struct named | ||
`__CxxTemplateInst` plus Itanium mangled type of the instantiation (see the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of prefixing each declaration name, could we add another special module context like So
and SC
for ObjC/C synthesized declarations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we could. The benefit would be having shorter mangled names and smaller metadata. The downside is slight increase in implementation complexity. For my use cases, I'd definitely appreciate any shortening of mangled names I can get. However, we biased towards reducing implementation complexity.
What's your preference?
) This is a roll-forward of #32950, with explicit c++17 version removed from tests. This is not needed since C++17 is the default anyway. -- In this PR we teach `ClangImporter` to import typedef statements with template instantiation as its underlying type. ```c++ template<class T> struct MagicWrapper { T t; }; struct MagicNumber {}; typedef MagicWrapper<MagicNumber> WrappedMagicNumber; ``` will be made available in Swift as if `WrappedMagicNumber` is a regular struct. In C++, multiple distinct typedeffed instantiations resolve to the same canonical type. We implement this by creating a hidden intermediate struct that typedef aliasses. The struct is named as `__CxxTemplateInst` plus Itanium mangled type of the instantiation. For the example above the name of the hidden struct is `__CxxTemplateInst12MagicWrapperI11MagicNumberE`. Double underscore (denoting a reserved C++ identifier) is used to discourage direct usage. We chose Itanium mangling scheme because it produces valid Swift identifiers and covers all C++ edge cases. Imported module interface of the example above: ```swift struct __CxxTemplateInst12MagicWrapperI11MagicNumberE { var t: MagicNumber } struct MagicNumber {} typealias WrappedMagicNumber = __CxxTemplateInst12MagicWrapperI11MagicNumberE ``` We modified the `SwiftLookupTable` logic to show hidden structs in `swift_ide_test` for convenience. Co-authored-by: Rosica Dejanovska <rosica@google.com> Co-authored-by: Dmitri Gribenko <gribozavr@gmail.com> Co-authored-by: Robert Widmann <devteam.codafi@gmail.com>
…2950. Specifically: * class template with variadic parameter * class template with non-type parameter * class template with template template parameter
In this PR we teach
ClangImporter
to import typedef statements with template instantiation as its underlying type.will be made available in Swift as if
WrappedMagicNumber
is a regular struct.In C++, multiple distinct typedeffed instantiations resolve to the same canonical type. We implement this by creating a hidden intermediate struct that typedef aliasses.
The struct is named as
__CxxTemplateInst
plus Itanium mangled type of the instantiation. For the example above the name of the hidden struct is__CxxTemplateInst12MagicWrapperI11MagicNumberE
. Double underscore (denoting a reserved C++ identifier) is used to discourage direct usage. We chose Itanium mangling scheme because it produces valid Swift identifiers and covers all C++ edge cases.Imported module interface of the example above:
We modified the
SwiftLookupTable
logic to show hidden structs inswift_ide_test
for convenience.Resolves https://bugs.swift.org/browse/SR-12591.