2 ms·
> Rewrite the Swift compiler in Swift: This would be a lot of fun someday, but (unless you include rewriting all of LLVM) requires the ability to import C++ API
by masklinn 11y ago
> Rewrite the Swift compiler in Swift: This would be a lot of fun someday, but (unless you include rewriting all of LLVM) requires the ability to import C++ APIs into Swift.
Or write thin bindings exposing a C API to the bits of LLVM you need to invoke to drive the backend. I believe that's what Rust does[0], because you definitely can't import C++ in Rust, rustc is written in Rust, and yet it uses LLVM.
[0] might be in https://github.com/rust-lang/rust/tree/master/src/rustllvm https://github.com/rust-lang/rust/tree/master/src/rustllvm though I'm not quite sure
- cwzwarich 11y agoSwift's compiler uses a lot more functionality from LLVM than Rust's compiler. For example, Clang's C++ API is used to parse and type-check C / Objective-C headers. Potential interoperability with C++ in the future would make this API surface even larger.
- masklinn 11y agoC++ interop would make the whole issue moot since you wouldn't need most of the shim anymore: you'd only have to shim enough to interop with C++, then from that could call the LLVM API directly.
- cwzwarich 11y agoThat's a good point, although full C++ interoperability may be many years out, and it would probably have to include things like templates for that plan to work.
- nostrademons 11y agoLLVM already has a C API: http://llvm.org/docs/doxygen/html/group__LLVMC.html http://llvm.org/docs/doxygen/html/group__LLVMC.html It's less full-featured than the C++ API, though, and may not help Swift all that much. Swift interoperates seamlessly with Objective-C, but its C FFI requires a lot of awkward boilerplate to translate between types & calling conventions. LLVM can also parse serialized bitcode, so one option (in any language) is always to dump to serialized LLVM bitcode and then pipe it to llc on stdin. Performance will suffer, though, since you have to serialize & deserialize the bitcode.