Blog

Compiler Notes.

From IR to register allocation, from Rust to language servers: plain-spoken posts from inside compilers.

Archive

All Posts

Filter by topic.

Front End

From Text to Tree: How a Compiler Reads Code

Before a compiler can check or optimize anything, it turns characters into tokens and tokens into a tree. Here is what each step does.

Front End2 min read
Optimization

Constant Propagation: Computing Before the Program Runs

If a value can be proven to always be the same constant, the compiler computes it at compile time. What happens when branches get involved?

Optimization2 min read
Tooling

What Does a Linker Do? Symbols and Relocations

The compiler translates each file on its own; the linker is what combines them into one executable. It does this with symbol tables and relocation records.

Tooling2 min read
Rust

What Does Rust's Borrow Checker Actually Check?

Never two paths to the same data where one of them writes. The core rule of the borrow checker is that simple.

Rust2 min read
IR

SSA Form: One Assignment per Variable

Compilers such as LLVM and GCC turn code into SSA form before analysing it. A small example of why it works so well.

IR2 min read
Optimization

Hoisting Loop-Invariant Code

A computation that gives the same result on every iteration should not stay inside the loop. LICM does that for you.

Optimization2 min read
Tooling

Editor Support with the Language Server Protocol

Instead of a plugin for every editor, you write one server per language. The protocol boils down to a few JSON messages.

Tooling2 min read
Codegen

Register Allocation: Fitting into a Few Slots

An IR has unlimited variables, a CPU has a few dozen registers. Register allocation closes that gap.

Codegen2 min read