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

Constant caching for x2c code generation.

Functions

FunctionSummary
Compiler.setup_cache_initMaterializes cached literals and deferred file-static initialization.

Compiler

Compiler.setup_cache_init

List Compiler.setup_cache_init( Compiler compiler, 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 compiler.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) and appends source work to the compiler’s early, middle, and late initialization phases; the operation is not idempotent. Header cache storage remains private to each C translation unit that includes it.

Source: src/cache.x:547

Design notes

Discovers and materializes cached literals between lowering and C emission. Immutable values share generated storage; mutable collections are copied at use sites, so caching does not change identity.

Compiler.cache decides cache-key equality and assigns (cache id) nodes whose ids index Compiler.id_keys. Generation 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.