Skip to main content

Module monomorphize

Module monomorphize 

Source
Expand description

Monomorphization: a generic program rewritten into the concrete program it stands for, for the tiers with no generics of their own.

Every call of a generic function becomes a call of one INSTANCE — a copy of the function with its type parameters replaced by the call’s type arguments — and every applied generic type (Box of Int, Maybe of Text, core Result of Int and Text) becomes one registered concrete type. The type arguments come from the checker (crate::analysis::infer_instantiations), which solved each site once; a site inside a generic body names that function’s own type variables, substituted per instance. When the backend has no Option of its own, some x / none and Option of T lower to the core Option enum’s instances. An empty sequence literal whose element type the context fixes (and is not Int, the reading every backend already gives []) becomes a new Seq of X.

A program with no generic site is returned unchanged, statement for statement.

Structs§

Monomorphized
A monomorphic program: its statements, the registry with every instance type added, and each instance type’s origin (so a backend shows Box of Int’s instance as a Box).
Options
What the backend lacks natively and monomorphization must lower.
TypeInstance
One registered concrete type: the generic type it applies, and to what.

Functions§

monomorphize
Rewrite stmts into a program with no generic function, no applied generic type, and (under options.lower_option) no built-in Option.