Locic moves to GitHub + Travis

The Loci compiler is currently in the process of being moved to a GitHub repository and built by Travis CI (Continuous Integration). If you visit the second link you can see the latest build status of Locic. This is particularly useful because it verifies the compiler builds against all the supported LLVM versions (3.3, 3.4 and 3.5), and furthermore that Locic can be built by both Clang and GCC.

I’m keen to support multiple versions of LLVM because it makes it much easier for end users to build it on their system with whatever LLVM version is available. LLVM 3.6 is currently under development so it’s a moving target and hence they’re currently set as ‘Allowed failures’, but I hope to fix the builds at some point soon.

Easier local builds

As part of this I’ve also substantially improved the upstream dependency searching for LLVM and Clang. This means that it’s now possible to just install the normal llvm-dev and clang packages (e.g. via apt-get) and then when you build Locic the CMake script will just find those automatically. If you have your own local build of LLVM (you’d have to be quite keen…) then you can set the root directory of that build so it’s used instead.

Expanding platform support

All of this is likely to be paired with a greater focus on getting the compiler to build on Mac and Windows (currently only Linux), and adding support for more ABIs in llvm-abi. In fact I’d also like to push llvm-abi into its own repository so it’s usable for other LLVM-based compiler front-ends.

I expect I’ll explain this in more detail at some point and probably also add documentation for the project when it’s separated from Loci, because it’s a really interesting capability for other compiler developers to avoid re-implementing the ABI code manipulations required for LLVM. It’ll also make sense to mention it on the LLVM mailing lists so I can get some suggestions for improving it to handle some of the more exotic cases.

Locic 1.1 released!

So the second version of the Loci Compiler Tools is now available (see Loci Compiler), with the main new features being:

  • Switching from C++-like template expansion to use Template Generators (to allow templated APIs across module boundaries)
  • Module imports and exports
  • scope(success), scope(failure) and scope(exit)
  • noexcept
  • Type-templated functions/methods
  • Type aliases
  • assert and unreachable statements
  • Implicit and explicit casts between types using templated methods
  • Standard library memory allocators and smart pointers
  • Standard library containers
  • Standard library strings
  • Vastly improved performance, particularly for Code Generation.
  • A larger set of examples and updates to examples to demonstrate newly implemented features.
  • Significantly improved documentation in reStructuredText using Sphinx, which can generate multiple output formats including HTML and PDF.
  • A much larger set of integrated tests to check both accept and reject cases, as well as testing the standard library.

The release was delayed slightly from the mid-August estimate in order to add support for LLVM 3.5 (so that LLVM 3.3, 3.4 and 3.5 are all supported as backends for Locic), which was initially scheduled for release on the 25th August 2014.

LLVM 3.5’s release has since been re-scheduled for the start of September, so the Locic 1.1 release was modified and tested for compatibility with LLVM 3.5 RC3 (pulled from SVN), which is expected to be near-identical to the actual LLVM 3.5 release.

Locic 1.1 Soon

I’m currently working hard on the second release of ‘Locic’, the compiler tools for the Loci programming language. The initial target date was around mid-August and it looks likely that I will be able to release on schedule.

While 1.0 provides the key features of the language (classes, algebraic datatypes, templated types), this new release really fleshes out the language implementation (and the language itself!) to include lesser but nevertheless important features. The internal structure is also being improved thoroughly, to generate better error messages, better quality code, etc. Performance wise, the compiler is now around 50 times faster than 1.0 (tested on the Chain Reversi example), due mainly to optimisations focused on CodeGen. Testing is also much more thorough, with a much larger set of integration tests for accept/reject cases, and I’m planning to add some unit tests on top.

One of the most valuable improvements to the compiler in this release is the ‘template fix’. Specifically, you can now put a templated implementation in one module, a declaration in another module, and then just link* them together and everything will work nicely!

In other words, you can do this:

// ModuleA.loci
template <typename T>
interface Addable {
    T add(const T& other) const;

template <typename T: Addable<T>>
T addValues(T value0, T value1) {
    return value0 + value1;
// ModuleB.loci
template <typename T>
interface Addable {
    T add(const T& other) const;

template <typename T: Addable<T>>
T addValues(T value0, T value1);

void yourFunction() {
    int a = 1;
    int b = 2;
    int c = addValues<int>(a, b);
    // etc.

So the point here is that unlike C++ you can use a templated class or function without needing its implementation**. This is one of the many ground breaking features of Loci that enables:

  • No more avoiding Templated APIs; they can now be part of a stable API!
  • Switching between different implementations of a templated class/function by simply linking them together.
  • Much faster compile times.
  • Optimisations to more effectively balance trade-off of code size versus performance (i.e. it’s easier to generate multiple instantiations of a template than to merge them).
  • No need to release templated code to clients (in a commercial setting).

So now when users write templated constructs they don’t need to treat them any differently from normal constructs!

* You could generate object code and then use the platform linker. However, I’d strongly encourage the use of llvm-link followed by opt so that you can benefit from inter-procedural optimisation.

** Naturally some users will be interested in the implementation, and this will be explained fully in the language design document. To summarise, the compiler will generate vtables for each type and then effectively perform virtual calls as needed. If you then link two modules together and run opt on the result you’ll find that all the virtual calls are eliminated by inlining (unless the compiler determines it’s not beneficial, though currently it always inlines), generating similar (or better) code to what you’d write if you ‘manually’ instantiated the templates.

Locic Release

I recently made the first release of the Loci compiler, available to download here. This covers a very broad range of the language with extensive support for the key features, such as classes, templates, exceptions and algebraic datatypes; the website has more detail.

With this release I aim to provide a taste of the language, and as part of this it includes a full port of the Chain Reversi program I originally wrote in C++, by using SFML’s C binding (I’m now dropping the C++ implementation in favour of this). This example, along with the other examples and the suite of tests, demonstrates the simplicity and elegance of the language (as well as the short compile times).

There’s still a long way to go until the compiler and language are suitable for widespread production use, and the next release (v1.1, scheduled Summer 2014) will resolve a number of issues and complete the implementation of features introduced in this first release.

Loci Presentation

I recently gave a talk about Loci, that gives a quick insight into what the language offers. You can find the slides here: Loci Presentation