Skip to content
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

[SR-13261] [C++] Allow instantiating C++ templates from Swift #55701

Open
swift-ci opened this issue Jul 21, 2020 · 2 comments
Open

[SR-13261] [C++] Allow instantiating C++ templates from Swift #55701

swift-ci opened this issue Jul 21, 2020 · 2 comments
Labels
c++ interop Feature: Interoperability with C++ compiler The Swift compiler in itself new feature

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-13261
Radar rdar://problem/83423218
Original Reporter hlopko (JIRA User)
Type New Feature
Status In Progress
Resolution
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels New Feature, CxxInterop
Assignee scentini (JIRA)
Priority Medium

md5: 55b08f175ae8509127468b5b5b9af809

Issue Description:

I.e. allow using following C++ header:

template<class T>
struct Tpl {
  inline int callMethod() const {
    return T::method();
  }
};

struct Arg {
  static int method() { return 6; }
};

in Swift like:

print(Tpl<Arg>().callMethod())

In the initial version we'll only support passing C++ types as template arguments, plus a small hardcoded set of Swift primitive types (converted to corresponding C++ types behind the scenes).

@swift-ci
Copy link
Collaborator Author

Comment by Marcel Hlopko (JIRA)

PR #33284 implements basic support for instantiating C++ class templates from Swift.

What doesn't work is:

  • template template parameters - Currently C++ class templates are imported as generic structs, and Swift cannot substitute generic arguments with a generic struct with unsubstituted arguments.

  • non-type parameters - Currently, Swift only allows types as generic arguments.

  • variadic parameters - Currently clang importer will not notice the parameter is variadic and will expect that there is only one parameter. There's no way to use specializations with more or fewer parameters from Swift.

  • nested types of instantiated templates cannot be serialized/deserialized in modules (therefore they cannot be used across module interface)

@zoecarver
Copy link
Collaborator

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@zoecarver zoecarver added c++ interop Feature: Interoperability with C++ and removed CxxInterop labels Apr 25, 2022
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++ compiler The Swift compiler in itself new feature
Projects
None yet
Development

No branches or pull requests

2 participants