Search

# Lightweight modular staging

Last modified: Jan 5, 2023

A technique developed to support runtime code generation and specialization. One key idea is to organize compilation into two language stages: a “meta” stage (which runs at compile time, and is erased before runtime) and the “object” stage.

Abstract (Tiark Rompf, Martin Odersky, 2012)

Software engineering demands generality and abstraction, performance demands specialization and concretization. Generative programming can provide both, but developing high-quality program generators takes a large effort, even if a multi-stage programming language is used.

While partial evaluation and staging have been developed since the 1980s (c.f. History of multi-stage programming) - lightweight modular staging was developed with the intent to support existing language and compiler systems.

One prototype implementation is in Scala. Here, Rompf distinguishes the computation stages using a Repr[T] type. A type of kind Repr[T] describes a set of values which will be known at runtime, whereas a type of kind T is known at compile time, and can be safely erased before runtime.