Apple open sourced the Swift language recently, and I’ve been meaning to take a look at how much work it would be to port it to POWER Linux.
As with many languages that use LLVM, it turnedÂ out to be relatively straightforward. I submitted a patch a few days ago, and thanks to some great assistance fromÂ Dmitri Gribenko in reviewing my work, support for little endian PowerPC64 is alreadyÂ upstream.
A couple of things made the port go smoothly. Firstly the compiler is written in C++ and not Swift. It seemsÂ rewrite the Swift compiler in SwiftÂ is a common request, but sticking to C++ makes the bootstrap process so much easier. I’ve had to bootstrap other compilers (Rust) that are written in their target language, andÂ that requires a cross build from a supported architecture whichÂ never goes smoothly.
More often than not, languages need to link to C objects and libraries, so they need knowledge ofÂ the C calling convention rules. MuchÂ of this knowledge is not in LLVM (it’s in the Clang frontend), and as a resultÂ most LLVM based languages end up duplicating it (Rust, Julia).Â Uli Weigand pointed out to me thatÂ Swift pulls in ClangÂ to provide this, which really helps. With all the duplication across languages, it might make sense to move this logic into an LLVM library instead of Clang.
Even though the port is upstream, there is one required LLVM changeÂ hereÂ – Swift has some calling conventions that are different to C, and I’m hoping one of theÂ POWER LLVM team will take pity on me and sort it out.
Building Swift on POWERÂ is straightforward on Ubuntu 15.10, just remember to add the LLVM patch above after checkingÂ out the source.
The testsuite runs with only a couple of failures:
Failing Tests (2): Swift :: 1_stdlib/VarArgs.swift Swift :: IRGen/c_layout.sil Expected Passes : 7061 Expected Failures : 78 Unsupported Tests : 699 Unexpected Failures: 2
And more importantly, hello world works:
# uname -m ppc64le # cat hello.swift print("Hello, world!") # swift hello.swift Hello, world!
There is still work to be done to get big endian PowerPC64 going, but little endian seems solid for any of your hello world needs.