`#insert NAME;` at file scope splices the text of a compile-time string
constant into the module where it stands: a literal, a #string body or
the result of `#run` on a pure procedure. The text is checked like the
rest of the file and shares its scope and #scope_file privacy, so a
compile-time procedure can write declarations generics cannot express.
Inserts are evaluated after discovery, under the #run rules and budget,
and their declarations are discovered before the file is parsed. Code
anywhere in the module can use them, including #if conditions and #run
calls above the #insert. The parser reads each insert as an in-memory
load frame. Every line of it keeps the #insert's line, so diagnostics
name the insertion site, and line numbers after the splice stay true.
A value that is not a compile-time string, #insert inside a procedure
body or an #if block, an insert in inserted text, and a misspelled
directive are rejected. The grammar lives in compiler_declaration.zi.
Saved IR holds only checked declarations, so no backend changes.
tests/insert_source_cases.zi builds a program whose Square, Cube and
helpers come from #insert. It runs from source and saved IR on C, Go,
the engine, native code and Wasm, with nine rejections.
A module declares parameters as its first declaration,
`#module_parameters(STB := false, CACHE: s32 = 8)`, and an import picks
their values, `#import "fonts"(STB = true)`. Each parameter is an
ordinary constant of the module, so `#if` keeps unchosen code out of C,
Go, ZX, Wasm and native code alike.
One program binds a module's parameters once. Every import has to give
every parameter the same value, so disagreeing imports fail with
module.parameter_conflict instead of compiling a second copy. Unknown
names and values that do not fit their type (integers by range) fail
with module.parameter_unknown and module.parameter_type at the import.
The grammar and literal rules live in compiler_declaration.zi. The
bindings are checked IR, ZirModule.parameters and ZirImport.parameters,
so they port with the checker to Ziran.
Saved .zir becomes version 65. It keeps each import's canonical list and
each module's types, defaults and bound values. A saved import that
disagrees with its module is rejected like source, and so is a bound
value that differs from the module's constant. The unused reserved
import slot is gone.
Also: a constant whose string holds `#import`, such as module source in
#string, is no longer parsed as an import. The C include path now lists
the IR headers first, so a stale copy that another generated module
keeps can't shadow them in an incremental build.
tests/module_parameters_cases.zi runs two programs that share one module
with different choices. They run from source and saved IR on C, Go, the
engine, native code and Wasm, along with the named rejections and edited
saved IR. Grammar cases are in tests/spec/compiler_declaration_test.zi.
Compare five real examples across four targets on three measured platforms, preserving raw samples, independent output verification and artifact provenance.
Complete the WebAssembly support needed by the examples, inspect ZX bundles, prune generated C dependencies while preserving C++ linkage, and validate native script execution. Optimize only the temporary bootstrap seed and retain fresh-build measurements and historical benchmark records under bench/results.
Local tests: all 522 cases passed across the full run and corrected header-test rerun; all 16 bootstrap modules match. Playground runtime, bundle runtime, private browser layouts and matrix controls, published artifacts and local site links passed.
Under TinyCC on x86-64 the 32-bit multiplies, rounding shifts, half
widening and the signed narrowings are SSE2 assembly macros, and a gather
reads its lanes straight from the table, two to a 64-bit word, instead
of four memcpy calls. Each result is stored as one 128-bit block: the
next operation's 64-bit half loads still forward from it. TinyCC's
assembler learns pmuludq and pshufd.
Where nothing inlines (TinyCC, unoptimized GCC and Clang), zi_simd_at,
zi_simd_gather_check and SliceRange check in place and call only to
report. A whole slice a[:] is the view itself in C, and a vector load,
store or gather of a whole named array addresses the array directly.
TinyCC zeroes small braced locals with stores instead of memset.
AV1's s32x4 self-guided restoration (tree-s3) against its scalar form
(tree-s2), `ziran run`, best of 3 on one core:
d352 cached 95 -> 76 ms (scalar 79 -> 71), uncached 356 -> 336 ms (scalar 328 -> 325)
d1080 cached 488 -> 408 ms (scalar 484 -> 408), uncached 793 -> 703 ms (scalar 802 -> 703)
The bootstrap C is regenerated.
Where a compiler never inlines (TinyCC, unoptimized GCC or Clang), checked
division and shifts (ZiDivS32 and the rest) and index reads (ZIRAN_INDEX,
SliceIndex, ZirVecIndex) are statement-expression macros. Their
temporaries were spelled zi__a, zi__index and the like, so an operand
named the same read the macro's own uninitialized local: ZiDivS32(zi__a,
zi__b, ...) divided garbage, and a slice index named zi__slice_index
aborted. They are now spelled __zi_*, which C reserves and the C emitter
renames in programs, as the std/simd macros already are.
tests/macro_temporaries.sh checks both spellings at -O0, -O2 and under
`ziran run`. The bootstrap C carries the new prelude.
A range over a computed bound was emitted as `while (i <= last)` with a
second exit, `if (i == last) break;`, before its step, so GCC refused to
vectorize it ("can't vectorize early exit"). When the counter and bound
are locals declared just before the loop, nothing takes their address and
every change of the counter is a step guarded by that last-value test, the
counter can never pass the bound, and C now writes
`if (i <= last) for (;;)`: one exit, which GCC can vectorize or turn into
memset, and TinyCC no longer tests the bound in every iteration.
AV1 1080p q40 decode (same hashes): gcc -O2 89 -> 86-88 ms, -O0 340 ->
335 ms, ziran run 609 -> 605 ms, -O3 unchanged at 77-79 ms.
TinyCC never inlines, so under `ziran run` every call of a tiny helper
paid a full call with all its locals on the stack. Generated C now writes
a call of a small straight-line procedure of the same module (no loops,
no module variables, scalars, pointers and small records only) as its
body in a block: arguments still run once, left to right, a return jumps
past the body, and the inlined call still costs the step its entry did.
Calls of foreign procedures stay out of inlined bodies, and private
procedures are declared ZIRAN_MAYBE_UNUSED for when every caller inlined
them.
A 1080p AV1 decode runs about 7% faster under `ziran run` and 4% faster
at -O0 with the same output; -O3 is unchanged. The bootstrap C is
regenerated. tests/call_site_inlining.sh covers argument order, name
clashes, early returns and the warning-free build.
TinyCC and unoptimized GCC or Clang never inline, so every bounds check,
checked shift and checked division in generated C cost a helper call.
Under those compilers the helpers are now statement-expression macros that
check in place and call out only to fail; optimized builds keep the
functions. A 1080p AV1 decode runs about 17% faster under `ziran run`
(TinyCC) and 24% faster at -O0, with the same output; -O3 is unchanged.
A foreign procedure marked #reads before #foreign only reads its string
and byte arguments during the call, so the Text checker treats it like a
Ziran procedure that only reads them. The marker lives in ZirImport's
former reserved slot, so ZIR format 61 is unchanged. #reads on a
procedure with a Ziran body is rejected.
Generated C leaves out the bounds check of an index such as
row * stride + column when a guard bounds it: an earlier if that returns,
breaks or continues, an enclosing if or while condition, or the earlier
operands of && and ||, until a value they compare changes. Indexes and
guard comparisons become polynomials over parameters, invariant locals
and slice counts; each loop counter is replaced by its upper bound, and
the index is proven below the count or length when every step is exact.
Guards that miss the read, values moved after the guard and else-if
exits keep their checks.
On the AV1 benchmark (fixed binaries, interleaved, one core) 1080p q20
drops from 185.1 to 182.2 ms and 720p 4:4:4 is unchanged, but 1080p
10-bit q30 rises from 201.5 to 212 ms. All of that comes from the one
check left out of FindCdefDirection's sample read; the function alone runs
faster without it (102 against 105 ns per call), so the loss is a layout
effect in the decoder's context.
Support New/free on Rust and Python, retain large Go enums, and move
procedure-type parameter normalization into the Ziran declaration module.
Preflight native callback signatures and publish fifteen tested feature
contracts with source/saved target checks.
Visit shared bundle re-exports once per reachability query and remove the
old depth cutoff. Verify six execution targets and reproducible seeds.