A short-term roadmap for C++ interop
This is a high-level roadmap of where I'm planning to take C++ interop over the next couple of months. If anyone would like to pitch in, or propose a change to this roadmap, feel free.
My primary goal over the next few months will be to fully import libc++ headers, LLVM headers, and Swift headers without crashing. This doesn't mean we'll necessarily be able to use any of these APIs, just that we'll be able to load the headers without crashing or having other errors. Ideally, we won't regress in terms of what C++ programs we can accept.
This should be mostly compiler bug fixes. However, there will be some larger projects, such as making all the headers we plan to use self-contained.
Other features and roadblocks
Here are the other two big features that I'd like to make some progress on in the near term:
- Improving template support, as discussed here. Currently, this is blocked on the ability to extend C++ types (patch here). This will allow us to more fully utilize the C++ APIs we import. For example, it will allow us to hack around inheritance for the time being (which will be a much more difficult feature to implement).
- Type conversions, mainly from Swift -> C++. I have a patch in the works (not yet finished) for importing Swift structs in C++; this will make templates much more useful in Swift. There is also a lot of potentials here for converting well-known types, such as
A lot of this work is actually pretty simple. The type conversion logic is a perfect example of this. There is a lot of low hanging fruit where the design and implementation is well known and relatively simple (there are still many things that aren't simple to design or implement, but we can worry about those later).
If anyone is interested in getting involved, I've marked a few good starter issues on Jira, but if there's something you're interested in, just do it! Additionally, please feel free to reach out to me. I'm happy to work with people in the community who want to get involved and push this forward.
Here are a few other things I have on the back burner related to C++ interop (that aren't necessarily in Jira, mainly because they're not yet well-defined):
- It would be great to find some source compatibility projects to ensure that we don't regress in terms of what we can import. Once we can import the standard library headers, this will become a lot easier.
- Some test suite improvements, such as running codegen tests on multiple targets locally.
- We need to figure out how to import things such as
operator->. (Maybe as a
- We should really, properly, add support for member functions. This includes fixing them on Windows and writing a bunch of tests. Here's a Jira bug in case anyone's interested.
So, after we are able to import the standard library headers, Swift headers, and LLVM headers... what's next?
Even with the current, limited APIs we're able to import, I think we can start writing the compiler in Swift. This will be a slow process. But I think it is a good idea to write some part of the compiler in Swift as soon as possible, for the same reason we should have source-compatibility projects: it will ensure that we don't regress.
There are two compelling candidates for the first compiler features to be written in Swift:
- A simple utility pass that we can put into the SIL Optimizer. There are several passes that aren't required to compile Swift code, and there are even some which aren't required to compile optimized Swift code. These passes are ideal candidates because we won't have to do any bootstrapping, and they are relatively simple.
- The textual SIL Parser is another compelling candidate. While it is currently a dependency of the Swift compiler, we might be able to fix that, so it too wouldn't require bootstrapping. (After all, why should the Swift compiler need to know how to parse SIL?)
Luckily it will, at the earliest, still be a few months before we have to worry about these types of issues. But sometimes it's still fun to imagine :)