Swift Creator’s Company Builds New Programming Language ‘Mojo’ – a Python Superset
Read more of this story at Slashdot.
While working at Apple, Chris Lattner designed Swift to “fully leverage the power of LLVM,” and “led a team for a while at Google to try to move Swift out of its Apple comfort zone, to become a replacement for Python in AI model development.” That’s according to a blog post by Jeremy Howard, an advisor to Lattner’s Modular AI (which he co-founded in 2022 to build a next-generation AI platform for developers).
“But sadly,” Howard writes, Swift “did not receive the support it needed from either Apple or from Google, and it was not ultimately successful.” And yet…
[W]hilst at Google Chris did develop another project which became hugely successful: MLIR. MLIR is a replacement for LLVM’s intermediate representation [or IR] for the modern age of many-core computing and AI workloads. It’s critical for fully leveraging the power of hardware like GPUs, TPUs, and the vector units increasingly being added to server-class CPUs.
So, if Swift was “syntax sugar for LLVM”, what’s “syntax sugar for MLIR”? The answer is: Mojo! Mojo is a brand new language that’s designed to take full advantage of MLIR. And also Mojo is Python.
OK let me explain. Maybe it’s better to say Mojo is Python++. It will be (when complete) a strict superset of the Python language. But it also has additional functionality so we can write high performance code that takes advantage of modern accelerators…
Whereas Swift was a brand new language packing all kinds of cool features based on latest research in programming language design, Mojo is, at its heart, just Python. This seems wise, not just because Python is already well understood by millions of coders, but also because after decades of use its capabilities and limitations are now well understood. Relying on the latest programming language research is pretty cool, but its potentially-dangerous speculation because you never really know how things will turn out…
A key trick in Mojo is that you can opt in at any time to a faster “mode” as a developer, by using “fn” instead of “def” to create your function. In this mode, you have to declare exactly what the type of every variable is, and as a result Mojo can create optimised machine code to implement your function. Furthermore, if you use “struct” instead of “class”, your attributes will be tightly packed into memory, such that they can even be used in data structures without chasing pointers around. These are the kinds of features that allow languages like C to be so fast, and now they’re accessible to Python programmers too — just by learning a tiny bit of new syntax…
I can’t begin to describe all the little (and big!) ideas throughout Mojo’s design and implementation — it’s the result of Chris and his team’s decades of work on compiler and language design and includes all the tricks and hard-won experience from that time — but what I can describe is an amazing result that I saw with my own eyes.
Mojo hasn’t been released to the public yet, (other than an online “playground” with a waitlist where they’re “rolling out access slowly.”) But the blog post notes that creating a programming language’s syntax is usually complex, error-prone, and controversial — a problem Mojo neatly avoids by “outsourcing” its syntax to an existing language, “which also happens to be the most widely used language today.”
And “As a compiled language, Mojo’s deployment story is basically the same as C,” the post argues. [That is, “you can literally just make the compiled program available for direct download. It can be just 100k or so in size, and will launch and run quickly.”]
“This means that Mojo is far more than a language for AI/ML applications. It’s actually a version of Python that allows us to write fast, small, easily-deployed applications that take advantage of all available cores and accelerators!”