Swift on POWER Linux

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.

 

Leave a Reply

Your email address will not be published. Required fields are marked *