-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] Add class template tests #33420
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
(you can use hlopko/swift@typedefs...hlopko:add_template_tests to see the diffbase on typedefs PR) |
@swift-ci please test |
1 similar comment
@swift-ci please test |
Build failed |
Could you rebase? I can open the diff view that you linked, but I can't leave comments there. |
@gribozavr rebased, PTAL |
@swift-ci please test |
@swift-ci please test Windows platform |
@swift-ci please test |
Build failed |
@swift-ci please test |
Build failed |
@swift-ci please test Windows platform |
@swift-ci please test |
Build failed |
@swift-ci please test |
@swift-ci please test windows platform |
Skipping class-template-variadic test on Windows, the culprit is https://bugs.swift.org/browse/SR-13129. |
@swift-ci please test |
Build failed |
Build failed |
@swift-ci please test |
Build failed |
Build failed |
@swift-ci please test |
Build failed |
…2950. Specifically: * class template with variadic parameter * class template with non-type parameter * class template with template template parameter
3ec1658
to
96d51cc
Compare
… Swift. Given a C++ header: ```c++ // C++ module `ClassTemplates` template<class T> struct MagicWrapper { T t; }; struct MagicNumber {}; ``` it is now possible to write in Swift: ```c++ import ClassTemplates func x() -> MagicWrapper<MagicNumber> { return MagicWrapper<MagicNumber>() } ``` This is achieved by importing C++ class templates as generic structs, and then when Swift type checker calls applyGenericArguments we detect when the generic struct is backed by the C++ class template and call Clang to instantiate the template. In order to make it possible to put class instantiations such as MagicWrapper<MagicNumber> into Swift signatures, we have created a new XREF (XREF_CLANG_TEMPLATE_INSTANTIATION) into serialisation and deserialisation infrastructure. Depends on swiftlang#33420. Progress towards https://bugs.swift.org/browse/SR-13261.
@swift-ci please test |
@swift-ci please test windows platform |
The |
Sad, I'll prepare a revert. |
… Swift. Given a C++ header: ```c++ // C++ module `ClassTemplates` template<class T> struct MagicWrapper { T t; }; struct MagicNumber {}; ``` it is now possible to write in Swift: ```c++ import ClassTemplates func x() -> MagicWrapper<MagicNumber> { return MagicWrapper<MagicNumber>() } ``` This is achieved by importing C++ class templates as generic structs, and then when Swift type checker calls applyGenericArguments we detect when the generic struct is backed by the C++ class template and call Clang to instantiate the template. In order to make it possible to put class instantiations such as MagicWrapper<MagicNumber> into Swift signatures, we have created a new XREF (XREF_CLANG_TEMPLATE_INSTANTIATION) into serialisation and deserialisation infrastructure. Depends on swiftlang#33420. Progress towards https://bugs.swift.org/browse/SR-13261.
This PR makes it possible to instantiate C++ class templates from Swift. Given a C++ header: ```c++ // C++ module `ClassTemplates` template<class T> struct MagicWrapper { T t; }; struct MagicNumber {}; ``` it is now possible to write in Swift: ```swift import ClassTemplates func x() -> MagicWrapper<MagicNumber> { return MagicWrapper<MagicNumber>() } ``` This is achieved by importing C++ class templates as generic structs, and then when Swift type checker calls `applyGenericArguments` we detect when the generic struct is backed by the C++ class template and call Clang to instantiate the template. In order to make it possible to put class instantiations such as `MagicWrapper<MagicNumber>` into Swift signatures, we have created a new field in `StructDecl` named `TemplateInstantiationType` where the typechecker stores the `BoundGenericType` which we serialize. Deserializer then notices that the `BoundGenericType` is actually a C++ class template and performs the instantiation logic. Depends on #33420. Progress towards https://bugs.swift.org/browse/SR-13261. Fixes https://bugs.swift.org/browse/SR-13775. Co-authored-by: Dmitri Gribenko <gribozavr@gmail.com> Co-authored-by: Rosica Dejanovska <rosica@google.com>
In this PR we add tests testing more complicated template scenarios for #32950. Specifically:
This PR depends on #32950.