Jacob’s Tech Tavern

Jacob’s Tech Tavern

Share this post

Jacob’s Tech Tavern
Jacob’s Tech Tavern
Swift Intermediate Language
Copy link
Facebook
Email
Notes
More

Swift Intermediate Language

The Swift compiler's secret sauce

Jacob Bartlett's avatar
Jacob Bartlett
Sep 16, 2024
∙ Paid
10

Share this post

Jacob’s Tech Tavern
Jacob’s Tech Tavern
Swift Intermediate Language
Copy link
Facebook
Email
Notes
More
Share

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 subscribers get full access to this article, plus my full Quick Hacks library. You’ll also get all my long-form content 3 weeks before anyone else.

Keep reading with a 7-day free trial

Subscribe to Jacob’s Tech Tavern to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Jacob Bartlett
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share

Copy link
Facebook
Email
Notes
More