Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Provisional API: This reference documents current compiler behavior. Compatibility is not yet promised.

src/cache.x

Cached literal slots and deferred file-static initializers.

Functions

FunctionSummary
Compiler.initialization_guardReturns the declaration of the file’s initialization guard, which starts at zero.
Compiler.setup_cache_initMaterializes cached literals and deferred file-static initialization.
Compiler.zero_initializerPreserves native initializer shape so C infers dimensions and checks designators before cached values are assigned during initialization.

Compiler

Compiler.initialization_guard

List Compiler.initialization_guard(Compiler c, List guard)

Returns the declaration of the file’s initialization guard, which starts at zero.

Source: src/cache.x:516

Compiler.setup_cache_init

List Compiler.setup_cache_init( Compiler c, List header, List source, String prefix, String guard_name, String initializer_name)

Materializes cached literals and deferred file-static initialization. header and source must be partitioned lowered AST regions from this compiler. Every (cache id) must index c.id_keys, and file-static dependency state from the full parse must be complete. prefix, guard_name, and initializer_name name the header’s private slots, guard, and initializer. Returns (header source bindings); bindings maps source cache ids to emitted slots. Appends initialization work to the <prepare>, <statics>, and <finish> initialization areas; the operation is not idempotent. Header cache storage remains private to each C translation unit that includes it.

Source: src/cache.x:64

Compiler.zero_initializer

List Compiler.zero_initializer(Compiler c, List value)

Preserves native initializer shape so C infers dimensions and checks designators before cached values are assigned during initialization.

Source: src/cache.x:279

Design notes

This module materializes a unit’s cached literals between lowering and C emission: it declares their static slots, initializes them in the unit’s initialization phases, and moves file-static initializers C cannot evaluate into generated helpers. Immutable values share generated storage; mutable collections are copied at use sites, so caching does not change identity.

Compiler.cache in compiler/literal-cache.x decides cache-key equality and assigns the (cache id) nodes whose ids index Compiler.id_keys; this module trusts that mapping. Header and source regions may materialize the same immutable value in separate static slots; String and List canonicalization preserves value identity across them.