Skip to content

chore: Zig 0.17.1 and zwasm v2.12.1 - #140

Open
BuddhiLW wants to merge 16 commits into
stagingfrom
chore/zig-0.17.1
Open

BuddhiLW wants to merge 16 commits into
stagingfrom
chore/zig-0.17.1

Conversation

@BuddhiLW

@BuddhiLW BuddhiLW commented Dec 1, 2026

Copy link
Copy Markdown
Owner

What moved

The migration is mechanical. No behaviour changes except the three listed under "Visible changes".

Do not merge before #138

This PR must not be merged before the release PR #138 (staging to main, v1.15.9) lands. I will not merge it; the coordinator lands it.

Zig 0.16 to 0.17 API classes hit

Class 0.16 0.17.1 Sites
Optimize tags .Debug, .ReleaseSafe .debug, .safe (std.lang.Optimize) build.zig
Run-step args if (b.args) |a| addArgs(a) addPassthruArgs() build.zig
Array repetition [_]T{x} ** n @splat(x) (** removed) 36
Stack scratch std.heap.stackFallback(n, a) std.heap.BufferFirstAllocator with a caller-owned buffer 4
Reflection @typeInfo(T).@"enum".fields, std.meta.fields field_names / field_types / field_values 13
Int type std.meta.Int @Int 2
Sentinel dupe Allocator.dupeZ dupeSentinel(.., 0) 1
cwd currentPathAlloc returned []u8 returns [:0]u8; freeing it as []u8 aborts 1
Enum builtins (deprecated) @intFromEnum, @enumFromInt @backingInt, @fromBackingInt (exact backing width, so 10 @intCast) 408
Namespace (deprecated) std.builtin std.lang 2
Formatting (deprecated) std.fmt.allocPrint(A, ..), std.fmt.bufPrint A.print(..), std.mem.print 156
Search (deprecated) std.mem.indexOf* std.mem.find* 14
Paths (deprecated) std.fs.path, resolvePosix std.Io.Dir.path, resolveAllocPosix 6
Lazy deps (deprecated) b.lazyDependency b.dependencyLazy plus its LazyDependencyNeeded arm build.zig
std.http.Method 9 tags gained QUERY 1
--build-file a bare basename was honoured needs ./build-lint.zig, or zig build lint invokes itself without end build.zig

No API was removed without an equivalent. zlinter 0.17.x takes include_dirs / include_files in addPaths, and its stricter rules found 17 dead declarations and 5 empty arms, all cleared.

The zwasm v2.7.0 to v2.12.1 embedding-API delta touched cljw in two places. WitType gained map (#611): component.zig prints it and scans it for resources, and a map param is refused with feature_not_supported until ADR-0135 gives it a Clojure shape. zwasm #597 moved the interpreter's refusal of a SIMD module from call time to load time, so four tests now assert it at wasm/load. The SIMD gap stays locked.

Visible changes

  • A Ring handler sees :request-method :query for an HTTP QUERY request, which 0.17's std.http parses and 0.16's did not.
  • wasm/load of a SIMD module with {:engine :interp} throws at load (zwasm #597), where the call used to trap.
  • A WIT map<k, v> component param throws feature_not_supported.

Evidence

The zwasm pin was first tried on the bare upstream tag v2.12.1 (db8a51b4). Both fork patches were missing there, and both regressions came back. The fork pin fixes both.

-Dwasm -Doptimize=ReleaseSafe, Linux amd64 upstream tag v2.12.1 fork main 7f21a997 (this PR)
test/clj/suites/wasm_thread_hop_test.clj 12 of 14 (the two :interp hops from a future trap) 14 of 14
bench/wasm_percall.clj, JIT, tiny module 1415 ns 1057 ns
same, JIT, 47 KB zigcool.wasm 5172 ns 996 ns

The bench ran n=20000 calls x 7 trials and reports medians; the host load average was 15 to 17.

  • zig build and zig build -Dwasm -Doptimize=ReleaseSafe are green.
  • zig build test -Dwasm -Doptimize=ReleaseSafe is green on vm and tree_walk (the full dual-backend diff oracle).
  • All 171 test/clj/suites pass: 1000 tests, 5393 assertions, 0 failures. That includes the 11 wasm suites (233 assertions) and native_transducer_test from perf(transduce): native map, filter, remove and take transducer stages (O-111) #133 (158 assertions), which also passes on a tree_walk binary.
  • zig fmt --check src build.zig build-lint.zig is clean, and zig build lint -- --max-warnings 0 is clean.
  • bash scripts/gen_placement.sh shows no placement drift.
  • bash test/run_all.sh --smoke e2e_phase16_wasm_ffi on c3302d4: 18 passed, 0 failed (vm and tree_walk unit tests, zig fmt, zlinter, corpus_regression 5515/5515, accepted_divergences, test_clj_suites, e2e_phase16_wasm_ffi).

I did not run the full gate (scripts/run_gate.sh), per the coordinator brief; CI runs it.

Every change here is one the 0.17.1 compiler refuses to build without:

- std.lang.Optimize renamed its tags: .Debug / .ReleaseSafe become
  .debug / .safe in build.zig.
- Run steps forward `zig build -- args` with addPassthruArgs (the
  b.args loop is gone): the `run` and `lint` steps.
- Array repetition `x ** n` is removed: a repeated fill is @Splat (36
  sites, all single-element fills of locals buffers, StackFrame and
  monitor tables, regex bitsets; the ffi signature tests build their
  arrays with @as([N]Type, @Splat(..))).
- std.heap.stackFallback is gone; std.heap.BufferFirstAllocator takes a
  caller-owned buffer (vm op_make_fn, BigDecimal printing, the
  component call scratch).
- @typeinfo's Struct / Enum carry parallel field_names / field_types /
  field_values slices instead of .fields; std.meta.fields is a
  compile error. Reflection sites read the new slices.
- std.meta.Int is @int; Allocator.dupeZ is dupeSentinel(.., 0).
- std.http.Method gained QUERY; the Ring :request-method switch maps it
  to :query (0.16's std could not parse a QUERY request at all).

Smell-audited: 1: mechanical stdlib migration, no behaviour change beyond the new QUERY tag the exhaustive switch now names
0.17.1's langref marks @intFromEnum and @enumFromInt deprecated in
favour of @backingInt and @fromBackingInt; std.builtin is a deprecated
alias of std.lang, and std.ArrayListUnmanaged of std.ArrayList. All
three still compile, so this is the finished-form step, kept apart from
the compile-error port: 348 @intFromEnum, 55 @enumFromInt and 2
std.builtin sites renamed token for token, one ArrayListUnmanaged.

@fromBackingInt takes exactly the backing integer, where @enumFromInt
narrowed implicitly, so the seven sites that passed a wider index
(a usize loop counter or a u8 phase byte) now @intcast it.

Smell-audited: 1: mechanical rename of deprecated builtins, no behaviour change
minimum_zig_version moves to 0.17.1. zlinter moves from its 0.16.x
branch to the head of 0.17.x (e1f92a11), still lazy.

zwasm returns to an upstream tag, zwasm/zwasm v2.12.1, peeled to
db8a51b4 (user direction 2026-12-01), from the BuddhiLW fork at
787bf6c9. v2.12.1 needs Zig 0.17.1. The dated comment says which fork
patches upstream carries and which two (fork PR #2, PR #3) it may not;
this pin is the experiment that measures them. Both hashes come from
`zig fetch` under 0.17.1.

Smell-audited: 0: version pins only
versions.lock ZIG_VERSION, the download URLs, cache keys and directory
names of ci, release, mutation and bench-vs-bb, flake.nix's
zig-overlay package, and flake.lock's zig-overlay moved to a revision
that carries 0.17.1 (6f4392dd).
The places that state the toolchain as a fact move to 0.17.1: the
README badge and build line, ROADMAP's opening, CLAUDE.md, CONTRIBUTING
and three script headers. Historic prose (ADR text, the 0.16 migration
notes, measured-with lines) stays as written. CHANGELOG records the
toolchain move, the zwasm pin and the new :query request method.
0.17.1's `zig fmt` rewrites the deprecated @intFromEnum to @backingInt;
the two wasm32 cpu-feature sites in build.zig were the only ones the
src rename did not cover. `zig fmt --check src build.zig
build-lint.zig` is now clean.

Smell-audited: 0: formatter output only
zwasm v2.12.1 resolves `map<k, v>` (#611) as WitType.map, where
v2.7.0 refused it as an unsupported type; it is the only change in the
v2.7.0 to v2.12.1 embedding API that the cljw build trips on. The three
exhaustive switches over WitType now name it:

- the introspection printer writes `map<k, v>`;
- the resource scan looks inside the key and value;
- `lower` refuses a map param with feature_not_supported, because
  ADR-0135 has no Clojure shape for it yet. A map RESULT lifts as zwasm
  despecialises it, a list of tuples, with no change here.

Smell-audited: 1: exhaustive switches extended for a new upstream variant; the param side fails loudly rather than guessing a shape
…_files

The 0.17.x branch replaced the single `include` list with directory
and file lists; src is a directory, build.zig and build-lint.zig are
files. Same lint scope as before.
zwasm v2.10.0 (#597) makes the interpreter refuse, at instantiation,
a module holding an op it does not execute; before, a SIMD body trapped
as `unreachable` only when called. Two zig tests and two clj tests loaded
the SIMD fixture on :interp to call its GPR export and failed with
InstantiateFailed.

The gap they lock is unchanged (SIMD stays JIT-only), only where it
surfaces moved, so each now asserts it where it now is:

- engine.zig: a GPR-only module (`gpr_only_wasm`, the `add` export alone)
  carries the interp side of the jit==interp check and the exportSig
  cache test; the SIMD module is asserted to be REFUSED on :interp, and
  the test still fails if zwasm ever runs interp SIMD.
- wasm_engine_select_test.clj: the interp GPR calls and `wasm/engine`
  load bench/wasm/ffi/add.wasm; `simd-interp` asserts the load throws.

Smell-audited: 1: tests follow an upstream behaviour change (trap at call to refusal at load); no assertion weakened, the SIMD gap is still locked
…ches

Operator decision 2026-12-01, after the upstream-tag experiment. On the
bare upstream tag v2.12.1 (db8a51b4) wasm_thread_hop_test fell to 12 of
14 and a JIT call cost 1415 ns on a tiny module against 5172 ns on the
47 KB one: the two fork-only patches are not upstream. Fork `main` at
7f21a997 (fork PR #11) is upstream main 25c9eb963 plus fork PR #2
(per-thread native-stack limit, upstream zwasm/zwasm#791, fixes #695),
fork PR #3 (by-name invoke from CompiledWasm.exports, upstream
zwasm/zwasm#792) and FORK.md. The dated pin comment records the
experiment and when the pin returns to an upstream tag. The hash comes
from `zig fetch` under 0.17.1.

Smell-audited: 0: version pin and its history comment
The two perf PRs were written for Zig 0.16. Ported here: their new
@intFromEnum / @enumFromInt sites become @backingInt / @fromBackingInt
(gc_heap_test, gc_types), and the AllocRecord alignment test's usize
loop counter is @intcast to Alignment's Log2Int backing type, which
@fromBackingInt requires exactly. gc_heap_test's conflict takes
staging's side (the record now reads `allocation.size`). CHANGELOG
keeps both sets of [Unreleased] entries.

Smell-audited: 1: forward merge plus the mechanical 0.17 port of the merged code
`zig build lint` never ran under 0.17.1 before this: the delegated step
passed `--build-file build-lint.zig`, and 0.17.1's build runner resolves
a bare basename to the default build.zig, so `lint` invoked itself
without end (thousands of build processes). `./build-lint.zig` fixes it.

zlinter's 0.17.x branch then reported 199 findings, none a behaviour
change; zwasm cleared the same classes in its own move (a06968705):

- no_deprecated (175): std.fmt.allocPrint(A, ..) -> A.print(..)
  (Allocator.print, 74), std.fmt.bufPrint -> std.mem.print (82),
  std.mem.indexOf / indexOfScalar / indexOfPos / indexOfScalarPos ->
  find / findScalar / findPos / findScalarPos (14), std.fs.path ->
  std.Io.Dir.path and resolvePosix -> resolveAllocPosix (6),
  b.lazyDependency -> b.dependencyLazy with its LazyDependencyNeeded arm.
- no_unused (17): private aliases and imports nothing reads, and
  JavaArray.Kind.default, a fn nothing calls.
- no_empty_block (5): the empty `if` / `else` arms in mvn_fetch and
  big_decimal say why they are empty.

`zig build lint -- --max-warnings 0` is clean.

Smell-audited: 1: deprecated-alias renames, dead declarations removed, empty arms documented; no behaviour change
…zig-0.17.1

#133 was written for Zig 0.16. Ported here: transducer.zig's
@intFromEnum / @enumFromInt become @backingInt / @fromBackingInt, and
the two `Kind` decodes of an i64 capture take @intcast, since
@fromBackingInt wants the exact backing integer. data/placement.yaml
takes staging's (gen_placement.sh shows no drift under 0.17.1).
native_transducer_test: 14 tests, 158 assertions, 0 failures on vm.

Smell-audited: 1: forward merge plus the mechanical 0.17 port of the merged code
Zig 0.17.1's std.process.currentPathAlloc returns a NUL-terminated
`[:0]u8`, one byte longer than its slice. cwdAlloc declared `[]u8`, so
`rt.gpa.free(cwd)` released len bytes of a len+1 allocation and the
debug allocator aborted the process (`free of len 74 mismatches
allocation of len 75`): .getAbsolutePath / .getCanonicalPath on a
relative path, caught by test_clj_suites (java-io-family-test). The
return type now keeps the sentinel, so free sees the real length.

Smell-audited: 1: return type follows the 0.17 std signature; fixes an allocator-length mismatch the port introduced
release_deps: `zig build` in 0.17.1 no longer takes --global-cache-dir
(it failed with "unrecognized argument"); the cold global cache is now
handed over through ZIG_GLOBAL_CACHE_DIR, with the same --system and
--cache-dir isolation as before.

fractal_kernel: the gate rebuilds kernel.wasm and kernel_simd.wasm from
the recipe in kernel.zig's header and requires the committed files to
match byte for byte. The committed files were built by Zig 0.16.0, and
0.17.1's codegen differs (scalar 3187 to 3206 bytes, simd128 3319 to
3300), so the recipe, not the kernel, changed. Both are regenerated
from that exact recipe under 0.17.1, and the header names 0.17.1. The
golden frames are untouched and still reproduce on all 8 engines with
the new artifacts; kernel_c.wasm (zig cc) is byte-identical under
0.17.1 and stays as committed. The expectation "committed artifact ==
the header recipe's output on the pinned Zig" is the gate's own rule,
so moving the pin moves the artifacts with it.
No textual conflicts. build.zig.zon takes staging's version 1.15.9 and
keeps this branch's minimum_zig_version, zlinter and zwasm pins.
CHANGELOG keeps staging's [1.15.9] section unchanged and its Unreleased
entries; the auto-merge had folded this branch's four Zig 0.17.1 /
zwasm v2.12.1 entries into [1.15.9], so they are moved back under
Unreleased, since they did not ship in 1.15.9.

The incoming regex (#139, #142) and require (#141) code uses no API
0.17.1 removed or deprecated, so it builds unchanged: the 0.17 rename
pass over src touches nothing, `zig fmt --check` is clean, and the
-Dwasm ReleaseSafe build is green. All 171 clj suites pass (1006 tests,
5420 assertions).

Smell-audited: 0: merge only; build.zig.zon takes staging's version, no Zig source changed by the resolution
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant