OptLevel
Type in Emit
A named optimization level, spelled like a C compiler's -O flag.
import type { OptLevel } from 'typeshade'
The signature, the description and the examples come from the compiler's own source at commit 26de7be8.
Syntax
type OptLevel = 'O0' | 'O1' | 'O2';Description
The distinction that
matters to a caller is between 'O1' and 'O2', and it concerns whether computed values can
change:
'O0': no pass runs. The module is emitted as authored, which makes it the size baseline to compare the other levels against.'O1': only the passes that move or remove values without changing which floating-point operations execute (constant and copy propagation, dead-branch removal, common-subexpression elimination, dead-code elimination). Every value an O1 build computes at runtime is bit-identical to the O0 build’s, on every target.'O2': the full pipeline, and the default for every emit function. Adds constant folding on floats, algebraic simplification and loop-invariant code motion. These passes can reorder or replace floating-point operations, so a computed value is not guaranteed to be bit-identical to the O0 build’s.
Choose 'O1' when a build must be provably value-identical to the unoptimized one, and
'O2' otherwise. Pass a level to emitModuleAt to emit WGSL at it, or to
lowerWgsl to get the optimized module without emitting text.
See also
Source
src/core/passes/opt/optimize.ts, line 297, at commit 26de7be8