[Manifesto] Interoperability between Swift and C++ - Evolution / Discussion - Swift Forums

생성일
Feb 19, 2020 07:42 AM
언어
Swift
분야
URL
 
notion imagenotion image
Interoperability between Swift and C++ has been previously discussed on the forums ([1] 12, [2] 6, [3] 4). The Swift for Tensorflow project has already started to build it out under the hidden -enable-cxx-interop flag. I have been trying to understand what interop will look like across all C++ features. I have summarized possible design options in a manifesto: Interoperability between Swift and C++ 439.
It is not a fully finalized design: many sections list multiple alternative options that we should discuss and evaluate their pros and cons. Some sections are missing, notably, calling Swift from C++. Nevertheless, this manifesto covers enough ground to show what Swift/C++ interop could look like, what will work well, and where the rough edges are.
I would like to invite everyone to provide feedback on the manifesto, discuss the design, evaluate alternative options explained in the doc, and brainstorm further alternatives that we didn’t think of. If there is lots of discussion on a particular topic, we will branch that discussion into a separate forum thread.
Interoperability with C++ is a broad topic, and the manifesto is quite long (more than 100KB!). I would like the discussion to focus on the most difficult and risky parts of the design, although you should feel free to comment on any topic. In particular, I think these are the most critical topics to discuss:
  • Mapping for C++ const reference parameters.
  • Mapping for C++ namespaces.
  • Mapping for move-only classes.
  • Mapping for non-movable classes.
  • Mapping for function and class templates.
  • Mapping for C++ enums, which are most often not annotated with NS_ENUM.
We will continue implementing Swift/C++ interoperability under the experimental flag -enable-cxx-interop. We will invoke the Swift evolution process if we need changes to the Swift language itself (as a hypothetical example, if we seriously considered adding namespaces as a feature to Swift).
I look forward to your input!