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

[cxx-interop] Instantiate C++ class templates from Swift #33284

Merged
merged 42 commits into from Jan 27, 2021

Conversation

hlopko
Copy link
Collaborator

@hlopko hlopko commented Aug 4, 2020

This PR makes it possible to instantiate C++ class templates from Swift. Given a C++ header:

// C++ module `ClassTemplates`
template<class T>
struct MagicWrapper {
  T t;
};

struct MagicNumber {};

it is now possible to write in 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.

@hlopko
Copy link
Collaborator Author

hlopko commented Aug 4, 2020

This PR depends on #32950.

@gribozavr gribozavr added the c++ interop Feature: Interoperability with C++ label Aug 5, 2020
@hlopko
Copy link
Collaborator Author

hlopko commented Sep 18, 2020

@swift-ci please test

@hlopko hlopko changed the base branch from master to main September 28, 2020 09:20
@hlopko
Copy link
Collaborator Author

hlopko commented Sep 28, 2020

@swift-ci please test

@swift-ci
Copy link
Collaborator

Build failed
Swift Test OS X Platform
Git Sha - 45c63aa

@swift-ci
Copy link
Collaborator

Build failed
Swift Test Linux Platform
Git Sha - 45c63aa

@hlopko
Copy link
Collaborator Author

hlopko commented Sep 29, 2020

@swift-ci please test

1 similar comment
@hlopko
Copy link
Collaborator Author

hlopko commented Sep 29, 2020

@swift-ci please test

@swift-ci
Copy link
Collaborator

Build failed
Swift Test Linux Platform
Git Sha - 69ae243

@hlopko
Copy link
Collaborator Author

hlopko commented Sep 29, 2020

@swift-ci please test

1 similar comment
@hlopko
Copy link
Collaborator Author

hlopko commented Sep 29, 2020

@swift-ci please test

@swift-ci
Copy link
Collaborator

Build failed
Swift Test OS X Platform
Git Sha - 69ae243

@hlopko
Copy link
Collaborator Author

hlopko commented Sep 30, 2020

@swift-ci please test

@swift-ci
Copy link
Collaborator

Build failed
Swift Test Linux Platform
Git Sha - 69ae243

@swift-ci
Copy link
Collaborator

Build failed
Swift Test OS X Platform
Git Sha - 69ae243

@hlopko
Copy link
Collaborator Author

hlopko commented Sep 30, 2020

@swift-ci please test

@swift-ci
Copy link
Collaborator

Build failed
Swift Test Linux Platform
Git Sha - be2e706

@swift-ci
Copy link
Collaborator

Build failed
Swift Test OS X Platform
Git Sha - be2e706

@hlopko
Copy link
Collaborator Author

hlopko commented Oct 1, 2020

@swift-ci please test

@swift-ci
Copy link
Collaborator

swift-ci commented Oct 1, 2020

Build failed
Swift Test Linux Platform
Git Sha - 1ca883b

@swift-ci
Copy link
Collaborator

swift-ci commented Oct 1, 2020

Build failed
Swift Test OS X Platform
Git Sha - 1ca883b

@hlopko
Copy link
Collaborator Author

hlopko commented Oct 1, 2020

@swift-ci please test

@hlopko hlopko marked this pull request as ready for review October 1, 2020 08:48
@swift-ci
Copy link
Collaborator

swift-ci commented Oct 1, 2020

Build failed
Swift Test OS X Platform
Git Sha - 9eb0a1f

@hlopko
Copy link
Collaborator Author

hlopko commented Jan 25, 2021

@swift-ci please test.

@swift-ci
Copy link
Collaborator

Build failed
Swift Test OS X Platform
Git Sha - e9a44d4

@swift-ci
Copy link
Collaborator

Build failed
Swift Test Linux Platform
Git Sha - e9a44d4

@hlopko
Copy link
Collaborator Author

hlopko commented Jan 25, 2021

@swift-ci please test.

@swift-ci
Copy link
Collaborator

Build failed
Swift Test Linux Platform
Git Sha - 71a9065

@swift-ci
Copy link
Collaborator

Build failed
Swift Test OS X Platform
Git Sha - 71a9065

@hlopko
Copy link
Collaborator Author

hlopko commented Jan 25, 2021

@swift-ci please test.

@swift-ci
Copy link
Collaborator

Build failed
Swift Test OS X Platform
Git Sha - c082a8c

@hlopko
Copy link
Collaborator Author

hlopko commented Jan 26, 2021

(Failure on mac came from lldb, not related to this PR)

@hlopko
Copy link
Collaborator Author

hlopko commented Jan 26, 2021

@swift-ci please test.

@swift-ci
Copy link
Collaborator

Build failed
Swift Test OS X Platform
Git Sha - 3bfdce6

Marcel Hlopko and others added 3 commits January 26, 2021 13:42
Co-authored-by: Dmitri Gribenko <gribozavr@gmail.com>
…ng-specialization.swift

Co-authored-by: Dmitri Gribenko <gribozavr@gmail.com>
@hlopko
Copy link
Collaborator Author

hlopko commented Jan 26, 2021

@swift-ci please test.

@swift-ci
Copy link
Collaborator

Build failed
Swift Test OS X Platform
Git Sha - ff7cdc3

@hlopko
Copy link
Collaborator Author

hlopko commented Jan 27, 2021

@swift-ci please test macos platform.

@hlopko
Copy link
Collaborator Author

hlopko commented Jan 27, 2021

@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.

None yet

5 participants