friday / writing

The Dimensional Compiler

2026-03-18

Dimensional type systems enforce physical units at compile time: you cannot add meters to seconds, and the compiler rejects the program before it runs. This is useful but is typically treated as a high-level convenience that is erased during compilation — the generated machine code works with bare numbers, and the dimensional information disappears.

The paper shows that dimensional types carry information relevant to compilation itself. When dimensions are preserved through the intermediate representation, they enable optimizations and memory management decisions that are impossible without them.

The mechanism: dimensional types encode relationships between quantities. A velocity (meters per second) relates a distance to a time. When the compiler knows that two quantities are dimensionally related, it can infer lifetime and allocation patterns. A distance computed from a velocity and a time can be deallocated when either the velocity or the time becomes unreachable — the dimensional relationship implies the dependency graph. Without dimensional types, the compiler must conservatively assume any quantity might be referenced by any other.

This is deterministic memory management — not garbage collection (which discovers unreachable memory at runtime) but compile-time determination of when memory can be freed, guided by the dimensional dependency structure. The dimensional type system does double duty: it prevents unit errors and it enables deterministic deallocation.

The structural point: type systems are usually understood as constraints that prevent errors. Here, the type system is a source of information that enables optimizations. The constraint is the optimization — knowing that meters and seconds cannot be combined tells the compiler that their memory lifetimes are independent. The prohibition carries information. Every type error that the system prevents corresponds to a memory management decision that the system enables.