You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
std.regex and std.zlib on wasm32: build the bundles for the target, link the target's bundle, carry them in the release #2131
Eric, 2026-10-04: PCRE2 regex running in a browser with no C anywhere in the build is the strongest demonstration of with migrate.
Today (installed compiler from main):
with build re.w --target wasm32
error: embedded bundle 'pcre2' was built for target darwin_aarch64 but this link targets wasm32 (this compiler embeds no pcre2 bundle for that target)
and hello world outside the repository: missing wasm32 runtime object: ./runtime/cross/wasm32/rt_core.o (run with build :cross-rt first).
Checked: with check --target wasm32 --no-prelude --bundle-corpus std.re lib/std/re/bundle.w is ok. build/wo.w already builds a bundle for a cross target (--target=<triple>, the Linux tags); wasm32 is not among them. :cross-rt-wasm builds the wasm32 program runtime.
Work:
wasm32 in the cross-bundle targets (pcre2, zlib, and the rest).
The link step selects the bundle of the target being linked.
The released compiler carries the wasm32 runtime and bundles (or builds them on demand), so --target wasm32 works outside the repository.
Run the PCRE2 and zlib suites as wasm32: the corpora were migrated against a 64-bit C model (D90 point 4: unsigned long, size_t), so 32-bit pointers are unproven.
A browser demonstration.
Also found: a bundle build invoked by hand with a bad argument exits with a bare error: build failed and no diagnostic.
Note (2026-10-07): D108 rules len() pointer-width (isize, 32 bits on wasm32; #2262). The wasm32 suites in item 4 are where that narrowing is proved, so #2262 lands before or with item 4.
Feasibility, main cab3b48, release compiler on the Mac: the pcre2 bundle builds for wasm32 with the bundle action's own argv (with build lib/std/re/bundle.w --emit-obj --no-prelude --target=wasm32-unknown-unknown --bundle-corpus std/re --emit-bundle-interface … --emit-bundle-manifest … --bundle-fingerprint … -O1 -o …): rc 0, bundle.o 1.2 MB, bundle.wi 120 KB, manifest target wasm32, the usual 35 corpus-internal generics omitted. (--bundle-corpus std.re is refused: the corpus is spelled as a path, std/re.) Layers: (1) build.w registers cross_wo_plans(ctx, &corpus_plans, "wasm32") beside the linux ones and :cross-rt-wasm builds them into out/wo/wasm32 and the store; (2) the native release compiler embeds the wasm32 bundles beside its own and Link.w's selection skips a same-named bundle whose target is not the link's instead of refusing, refusing only when none matches; (3) the release carries the wasm32 runtime objects (out/lib/cross/wasm32) so --target wasm32 works outside the repository; (4) the PCRE2 and zlib suites under node as wasm32 (the 32-bit model question, D90 point 4); (5) the browser demonstration.
Layers 1 and 2 verified on branch wasm-bundles (PR #2260): the native release carries the four wasm32 bundles beside its own (with_embedded_wo_<name>_wasm32_*, index entries <name>@wasm32), the link, interface registration and import resolution select a bundle by target, a native regex program links and runs unchanged, and --target wasm32 of a std.regex program selects the wasm32 pcre2 bundle. The corpus's thirteen libc externs (the ctype family and memchr) are provided by rt/wasm.w in With under their C names (FnAbi's wasm libc-provider list, ABI hash re-recorded). hello.w runs under node.
Item 4 now has a repro: with the bundle linked, every match returns false on wasm32 — Regex.compile("a") is Ok, then is_match("a"), is_match("xax") and [0-9]+ against x42 all print false (native: true false true / true). The engine runs without faulting; the systemic wrong answer is what D90 point 4 predicted for a corpus modeled with 64-bit size_t/unsigned long on 32-bit pointers. The route is the pcre2 suite itself as wasm32 (pcre2test under node), not a guess at a site; it is the next layer after the runtime objects (item 3).
Still needed before --target wasm32 works outside the repository: item 3, the release carrying the five wasm32 runtime objects (today WITH_RUNTIME_ROOT=out/lib after :cross-rt-wasm), and the SDK path resolving from the tree rather than the cwd (a link started from another directory reported wasm-ld missing "next to .deps/…" by a relative path).
Layers 1 and 2 merged in 645dc53 (PR #2260). Next: item 3 as its own PR — stage1 compiles the five wasm32 runtime objects beside the native ones, the stage and release embeds carry them as wasm32_<obj>_o blobs, and the link stage extracts them for a wasm32 link when no cross/wasm32 directory holds them (the native fallback's shape, same generation check); :wasm-tests then needs no WITH_RUNTIME_ROOT. Then the SDK path from the tree, then item 4 with the pcre2 suite as wasm32.
Layer 3 on branch wasm-rt-embed (draft PR opened from it): the native compiler carries the five wasm32 runtime objects (stage1's in the stage embed, stage2's in the release embed; empty slots in stage1 and the cross compilers) and the link stage extracts them for a wasm32 link when no cross/wasm32 directory holds them. Verified: with out/lib/cross/wasm32 moved aside, hello.w --target wasm32 from the tree extracted the embedded objects and ran under node; a std.regex program links with no WITH_RUNTIME_ROOT at all (and still returns false for every match: item 4, unchanged); :wasm-tests 6 ok on the stage2-built objects. Remaining for --target wasm32 outside the repository: the SDK path resolved relative to the cwd (a link started elsewhere reports wasm-ld missing by a relative .deps/… path). Then item 4 with the pcre2 suite as wasm32, then the browser demonstration.
The last piece of item 3 is a dependency question, not a path bug. The link stage reads the linker from the runtime root's recorded llvm_ld (a relative .deps/…/ld64.lld, valid only with the tree as cwd); the installed compiler has no runtime directory and links native user programs through the system cc; the SDK tools pack a cross compiler embeds (EmbeddedSysroot.w) carries cmake and ninja for with get, not lld. A wasm32 link outside the tree therefore has no linker at all. The honest fixes are #1915's: the shipped compiler carries the SDK's lld (one static binary, ~72 MB, which also removes cc from native links) or materializes it from an in-box source. An absolute path into a checkout's .deps would be the forbidden dependency. Leaving this to #1915's ruling; inside a tree, --target wasm32 now needs nothing but the release compiler.
Layer 3 merged in 7d729c2 (PR #2264). Inside a tree, --target wasm32 now needs only the release compiler: bundles and runtime both come from the binary. Open: the linker outside the tree (#1915's ruling, above), item 4 (every match false on wasm32; route: the pcre2 suite as wasm32), item 5.
Item 4 root cause, at the line. A direct probe through the std.re API (pcre2_compile_8 + pcre2_match_8, native vs wasm32 under node): compile succeeds, a against a returns rc=1 span 0..1 natively and rc=-1 "no match" on wasm32; memchr and the ctype family are correct on wasm32 (probed); PCRE2_NO_START_OPTIMIZE changes nothing. The matcher's frame arithmetic in lib/std/re/pcre2_match.w carries the migration host's folded offsets: line 790 frame_size = 136 + top_bracket*2*sizeof[usize]() … (136 = offsetof(heapframe, ovector) on a 64-bit host), line 967 memsets from heapframes + 136, line 4704 frame_size - 80 (offsetof(heapframe, eptr)). On wasm32 heapframe's pointer fields are 4 bytes, so the real offsets are smaller, the frames are addressed askew, and the matcher reports no match. This is D90 point 4 realized: the C migrator folds offsetof (and struct sizeof) into the host's literal rather than a layout query the target evaluates. The fix is in the migrator, and the corpus is regenerated, never hand-edited (#880 method).
The migrator line: src/CImport.w:3100 ci_try_translate_offsetof_expr resolves offsetof(T, f) with with_cimport_record_field_offset_by_name on the migration host and emits i64_to_string(offset) — a folded 64-bit literal, so every offsetof in every migrated corpus is wrong on wasm32 by construction (136 and 80 in pcre2_match.w; the same shape wherever zlib, c_algorithms and tommyds use offsetof or a struct sizeof). Route: (1) a target-evaluated field-offset reflection beside T.size() and T.align() (spelling to rule: T.offset(f) is the shape those two set; a Part IX-style delegated brief if no spec sentence exists), evaluated at comptime from TypeLayout for the target; (2) the migrator emits it instead of the literal, and folds a struct sizeof the same way; (3) regenerate the four corpora (never hand-edited; the drift lane proves it) and run the direct probe and the pcre2 suite as wasm32. Until then std.regex on wasm32 is wrong and must not be claimed; nothing in the shipped tests claims it.
Item 4 fixed in PR #2266 (draft until its battery is green). The migrated pcre2 carried host-folded offsetof values (136, 80, 120, 8, plus serialize offsets); D109 adds offsetof[T](field) beside sizeof, the migrator spells C's offsetof with it, and the regenerated corpora differ only at those 18 sites. On wasm32 under node, a on a now returns rc=1 span 0..1 and the std.regex probe prints the same as native. Remaining here: item 5 (browser) and the pcre2 suite as wasm32, which needs a WASI I/O surface for the harness.
Activity
ehartford commentedon Oct 7, 2026
Feasibility, main cab3b48, release compiler on the Mac: the pcre2 bundle builds for wasm32 with the bundle action's own argv (
with build lib/std/re/bundle.w --emit-obj --no-prelude --target=wasm32-unknown-unknown --bundle-corpus std/re --emit-bundle-interface … --emit-bundle-manifest … --bundle-fingerprint … -O1 -o …): rc 0, bundle.o 1.2 MB, bundle.wi 120 KB, manifesttarget wasm32, the usual 35 corpus-internal generics omitted. (--bundle-corpus std.reis refused: the corpus is spelled as a path,std/re.) Layers: (1) build.w registerscross_wo_plans(ctx, &corpus_plans, "wasm32")beside the linux ones and:cross-rt-wasmbuilds them into out/wo/wasm32 and the store; (2) the native release compiler embeds the wasm32 bundles beside its own and Link.w's selection skips a same-named bundle whose target is not the link's instead of refusing, refusing only when none matches; (3) the release carries the wasm32 runtime objects (out/lib/cross/wasm32) so--target wasm32works outside the repository; (4) the PCRE2 and zlib suites under node as wasm32 (the 32-bit model question, D90 point 4); (5) the browser demonstration.ehartford commentedon Oct 7, 2026
Layers 1 and 2 verified on branch wasm-bundles (PR #2260): the native release carries the four wasm32 bundles beside its own (
with_embedded_wo_<name>_wasm32_*, index entries<name>@wasm32), the link, interface registration and import resolution select a bundle by target, a native regex program links and runs unchanged, and--target wasm32of astd.regexprogram selects the wasm32 pcre2 bundle. The corpus's thirteen libc externs (the ctype family andmemchr) are provided by rt/wasm.w in With under their C names (FnAbi's wasm libc-provider list, ABI hash re-recorded).hello.wruns under node.Item 4 now has a repro: with the bundle linked, every match returns false on wasm32 —
Regex.compile("a")isOk, thenis_match("a"),is_match("xax")and[0-9]+againstx42all printfalse(native:true false true/true). The engine runs without faulting; the systemic wrong answer is what D90 point 4 predicted for a corpus modeled with 64-bitsize_t/unsigned longon 32-bit pointers. The route is the pcre2 suite itself as wasm32 (pcre2test under node), not a guess at a site; it is the next layer after the runtime objects (item 3).Still needed before
--target wasm32works outside the repository: item 3, the release carrying the five wasm32 runtime objects (todayWITH_RUNTIME_ROOT=out/libafter:cross-rt-wasm), and the SDK path resolving from the tree rather than the cwd (a link started from another directory reportedwasm-ldmissing "next to .deps/…" by a relative path).The native compiler carries the wasm32 bundles beside its own, select…
wasm32 bundles: built by stage1, embedded beside the host's, selected…
ehartford commentedon Oct 7, 2026
Layers 1 and 2 merged in 645dc53 (PR #2260). Next: item 3 as its own PR — stage1 compiles the five wasm32 runtime objects beside the native ones, the stage and release embeds carry them as
wasm32_<obj>_oblobs, and the link stage extracts them for a wasm32 link when no cross/wasm32 directory holds them (the native fallback's shape, same generation check);:wasm-teststhen needs no WITH_RUNTIME_ROOT. Then the SDK path from the tree, then item 4 with the pcre2 suite as wasm32.ehartford commentedon Oct 7, 2026
Layer 3 on branch wasm-rt-embed (draft PR opened from it): the native compiler carries the five wasm32 runtime objects (stage1's in the stage embed, stage2's in the release embed; empty slots in stage1 and the cross compilers) and the link stage extracts them for a wasm32 link when no cross/wasm32 directory holds them. Verified: with out/lib/cross/wasm32 moved aside,
hello.w --target wasm32from the tree extracted the embedded objects and ran under node; a std.regex program links with no WITH_RUNTIME_ROOT at all (and still returns false for every match: item 4, unchanged);:wasm-tests6 ok on the stage2-built objects. Remaining for--target wasm32outside the repository: the SDK path resolved relative to the cwd (a link started elsewhere reports wasm-ld missing by a relative.deps/…path). Then item 4 with the pcre2 suite as wasm32, then the browser demonstration.ehartford commentedon Oct 7, 2026
The last piece of item 3 is a dependency question, not a path bug. The link stage reads the linker from the runtime root's recorded
llvm_ld(a relative.deps/…/ld64.lld, valid only with the tree as cwd); the installed compiler has no runtime directory and links native user programs through the systemcc; the SDK tools pack a cross compiler embeds (EmbeddedSysroot.w) carries cmake and ninja forwith get, not lld. A wasm32 link outside the tree therefore has no linker at all. The honest fixes are #1915's: the shipped compiler carries the SDK's lld (one static binary, ~72 MB, which also removesccfrom native links) or materializes it from an in-box source. An absolute path into a checkout's .deps would be the forbidden dependency. Leaving this to #1915's ruling; inside a tree,--target wasm32now needs nothing but the release compiler.The native compiler carries the wasm32 runtime, so `--target wasm32` …
ehartford commentedon Oct 7, 2026
Layer 3 merged in 7d729c2 (PR #2264). Inside a tree,
--target wasm32now needs only the release compiler: bundles and runtime both come from the binary. Open: the linker outside the tree (#1915's ruling, above), item 4 (every match false on wasm32; route: the pcre2 suite as wasm32), item 5.ehartford commentedon Oct 7, 2026
Item 4 root cause, at the line. A direct probe through the std.re API (pcre2_compile_8 + pcre2_match_8, native vs wasm32 under node): compile succeeds,
aagainstareturns rc=1 span 0..1 natively and rc=-1 "no match" on wasm32; memchr and the ctype family are correct on wasm32 (probed); PCRE2_NO_START_OPTIMIZE changes nothing. The matcher's frame arithmetic in lib/std/re/pcre2_match.w carries the migration host's folded offsets: line 790frame_size = 136 + top_bracket*2*sizeof[usize]() …(136 = offsetof(heapframe, ovector) on a 64-bit host), line 967 memsets fromheapframes + 136, line 4704frame_size - 80(offsetof(heapframe, eptr)). On wasm32 heapframe's pointer fields are 4 bytes, so the real offsets are smaller, the frames are addressed askew, and the matcher reports no match. This is D90 point 4 realized: the C migrator foldsoffsetof(and structsizeof) into the host's literal rather than a layout query the target evaluates. The fix is in the migrator, and the corpus is regenerated, never hand-edited (#880 method).ehartford commentedon Oct 7, 2026
The migrator line: src/CImport.w:3100
ci_try_translate_offsetof_exprresolvesoffsetof(T, f)withwith_cimport_record_field_offset_by_nameon the migration host and emitsi64_to_string(offset)— a folded 64-bit literal, so every offsetof in every migrated corpus is wrong on wasm32 by construction (136 and 80 in pcre2_match.w; the same shape wherever zlib, c_algorithms and tommyds use offsetof or a struct sizeof). Route: (1) a target-evaluated field-offset reflection besideT.size()andT.align()(spelling to rule:T.offset(f)is the shape those two set; a Part IX-style delegated brief if no spec sentence exists), evaluated at comptime from TypeLayout for the target; (2) the migrator emits it instead of the literal, and folds a structsizeofthe same way; (3) regenerate the four corpora (never hand-edited; the drift lane proves it) and run the direct probe and the pcre2 suite as wasm32. Until thenstd.regexon wasm32 is wrong and must not be claimed; nothing in the shipped tests claims it.ehartford commentedon Oct 8, 2026
Item 4 fixed in PR #2266 (draft until its battery is green). The migrated pcre2 carried host-folded offsetof values (136, 80, 120, 8, plus serialize offsets); D109 adds
offsetof[T](field)besidesizeof, the migrator spells C's offsetof with it, and the regenerated corpora differ only at those 18 sites. On wasm32 under node,aonanow returns rc=1 span 0..1 and the std.regex probe prints the same as native. Remaining here: item 5 (browser) and the pcre2 suite as wasm32, which needs a WASI I/O surface for the harness.offsetof: Sema records the measured record; emit-c lowers it; the mig…
offsetof[T](field): target layout offsets; the migrator stops folding…
wasm32: link embedded lld driver and fix std.regex/std.zlib target wi…
windows-aarch64 SDK pin: the rebuilt asset with the WebAssembly backe…
build: the release carries every target's engine bundles, so a cross …