The Swift Compiler is a mysterious multi-headed hydra. It takes your code through a many-step journey from hello world to machine code:
First, it parses your code into tokens on an abstract syntax tree. It performs semantic analysis on this data structure in real-time, checking types and emitting compiler warnings.
Next, it generates SIL, Swift Intermediate Language, and optimises the result.
Finally, it’s converted into LLVM Intermediate Representation; which allows it to be handed off to the LLVM toolchain. This performs more optimisations and allows the resulting to machine code to be compiled for any chip architecture.
The Swift Intermediate Language generation step, and subsequent optimisations, makes Swift special, and goes a long way towards its eponymous speed.
The SIL optimisations might include:
Performing devirtualisation — this replaces table dispatch with faster static dispatch.
Specialisation — Generating specific versions of generic functions to further avoid dynamic dispatch.
Dead code elimination to prevent code that’s never executed from bloating the binary.
Paid members get lots of nice things:
⚓️ Access my full library of paywalled articles (including this one)
🚀 Read free articles a month before anyone else
🧵 Master concurrency with my full course and advanced training
🧑🚀 Get a free copy of my new eBook, “Land your iOS Tech Job”
❤️🩹 Support independent, sometimes funny, tech writing



