LLVM

A conversation with a colleague at work today about programming languages and programming tools has stuck with me. We talked about a wide range of things, hilariously prompted by the fact I’d ported some C-based software of ours to OS X, causing my colleague to fake astonishment at the fact I can still code; my need to (and ability) to hack professionally is almost zero now since I have an excellent programmer on my team.

The port was pretty trivial with most of the work surrounding correcting library locations for the linker, plus a high resolution timer implementation because certain POSIX time APIs aren’t available on OS X due to it’s BSD heritage. It went much faster because of LLVM and its integration into Xcode.

I knew up front that the timer would need to be rewritten because my programmer had written POSIX and Win32 implementations already and I’d investigated if the right POSIX API was there on OS X as well. I’ve learned over the last couple of years working on OS X not to assume everything’s there in that respect.

So I had a look at the documentation, included unistd.h and started typing. Straight away after a few lines of code, Xcode noticed a int-to-uint type conversion problem. Under all other C compilers that I’m aware of that’d be up to me to fix based on the compiler warning, but clang and LLVM underneath knew how to fix the code for me and offered up the change.

I move to some OpenCL code and the constant background compilation picks up some other issues in the kernel code Xcode and its compilers can correct itself, explaining very clearly what it’s going to do for me in plain English and not forcing the change upon me if I don’t want it. If you’re a programmer you’ll know instantly how valuable that is.

The combination of the clang front end, OpenCL front end and LLVM underneath it all is what makes that kind of technology possible. It’s a clear step on from predictive text, even one with baked-in type system knowledge like IntelliSense, since it’s helpfully assistive and, almost always correct. Apple’s hire of Chris Lattner is arguably one of the most astute things they’ve done in the last ten years, since his work underpins the greatest bits of their current developer offering.

That LLVM enables so much more including what it does on Apple’s platform in terms of language and compiler technology, for all modern computing platforms now, is fantastic. LLVM is the best thing to happen to programming language implementation since the first high-level languages were bootstrapped.