Hi all, with the new year starting we'd like to share an update to the current status of the C++ Interop (also being discussed in a separate topic - How developed is C++ interoperability?). With the great help from @zoecarver and a few others, with many interesting bugs fixed, the following is implemented in general:
- C++ structs, classes, and enums are imported (including nested types)
- Non-virtual and static methods are imported
- Both member and non-member operators are imported
- Constructors are imported (copy/move constructors are not yet used by Swift)
- Destructors are (or will be shortly) imported and used by Swift
- Imported members respect the source visibility
- Namespaces are imported
- extern variables are imported
- Static variables are imported
- C++ modules respect
@_implementationOnly
visibility - Glibc module map is compatible with the libc++ module map
- References are imported as
UnsafePointers
orUnsafeMutablePointers
- Class/Function templates are imported
- Fully specialized class templates behind a typedef are imported
- It is (or will be shortly) possible to instantiate C++ class templates from Swift (nested types cannot be used across module interface)
What is currently not supported, but very likely doable:
- Method calls work due to luck (even though we are not intentionally using the right ABI, it does not end up mattering on Itanium ABI)
- Move constructors are not imported.
- Copy constructors are not imported (but @zoecarver has a PR for that :)
- Dependent types.
- Importing the C++ standard library.
- specifically
std::string
is not yet imported due to bugs; we are currently not aware of any new feature work required.
- specifically
- Importing Swift code into C++.
And of course there are more challenging but interesting and rewarding topics such as instantiating C++ templates with Swift types, or instantiating Swift generics with C++ types, which we have not pursued.
In summary, from our experience we can confidently say that the C++ Interop is a good and viable way of integrating C++ and Swift programs in an ergonomic way. The implementation is already quite powerful and has a great further potential. We haven't found any unsolvable problems.
Having said that, after what we consider the successful proof of the viability of the current approach, priorities have shifted, and we will scale down our investment in C++ interop for now. We would be happy to pass our knowledge to whoever would be interested in continuing this work, and there is already a growing community of contributors (some of which put us to shame - right Zoe? :) And we're confident that the project is in good hands.
Thank you all!