Repository navigation
Description
Summary
During Phase 5 of the wasm simulation backend (src/simlin-engine/src/wasmgen/, array opcode lowering), two array-lowering coverage/limitation items surfaced that need explicit tracking before the Phase 8 full-corpus-parity goal. Both are internal backend coverage/limitation concerns, not user-facing bugs. They are distinct from #607, which is purely about a false documentation premise ("CompiledSimulation is fully un-fused") in the plan text; these two are about opcode reachability and an architectural limitation in the array lowering. Filed together because both are Phase 5 array-lowering findings with the same Phase 8 relevance.
Investigated and confirmed against the engine; file:line evidence below.
Finding 1: the broadcast-iteration opcode family is dead/speculative code (VM-wide, not just wasm)
The broadcast-iteration opcodes -- BeginBroadcastIter / LoadBroadcastElement / StoreBroadcastElement / NextBroadcastOrJump / EndBroadcastIter -- plus the broadcasting variant of LoadIterViewAt (source dims != iteration dims) are fully implemented and unit-tested in the wasm backend (src/simlin-engine/src/wasmgen/lower.rs:1292-1331, the build_broadcast_ctx helper at lower.rs:1483-1520, views.rs::iter_broadcast_offset at views.rs:356, and the broadcast_iter_* hand-built-bytecode unit tests at lower.rs:5765+). They are also a first-class part of the VM: defined in bytecode.rs:1168-1188, executed by vm.rs:2314-2373, and given a full symbolize/resolve round-trip in compiler/symbolic.rs.
But production codegen never emits any of them. Verified: rg '\.push\(Opcode::(BeginBroadcastIter|LoadBroadcastElement|StoreBroadcastElement|NextBroadcastOrJump|EndBroadcastIter)' src/simlin-engine/src/ returns nothing outside the symbolize/resolve plumbing and tests. Concretely:
- Arrayed / A2A elementwise assignment is scalar-unrolled at compile time, not broadcast-iterated.
compiler/mod.rs:1871-1903(standard per-element expansion) emits oneExpr::AssignCurr(off + i, ...)per element; the lookup-only A2A path atmod.rs:1931+does the same. There is noBeginBroadcastIteremission anywhere incompiler/codegen.rs. - The only iteration codegen emits is the non-broadcast
BeginIter(codegen.rs:1328, theNextIterOrJump/EndIterpair), used solely to fill anAssignTempfor an array-producing builtin's elementwise argument. That non-broadcast loop is reachable and is covered end-to-end by the wasm backend (module.rs:2296compile_simulation_hoisted_reducer_loop_matches_vm). - A mismatched-dim reducer argument (the other way a broadcast loop might be imagined to arise) fails the engine's own dimension check (
NotSimulatable) before codegen.
Provenance: the family was introduced as scaffolding in commit 5d282349 "engine: add bytecode infrastructure for array support (#135)" and the codegen never grew an emitter for it. This is consistent with tech-debt item #12 ("scaffolding types ... reserved for future strided array views").
The wasm backend documents the gap honestly (src/simlin-engine/src/wasmgen/module.rs:2285-2294): the broadcast paths are "not reachable through the current production codegen ... so those are pinned directly against the VM by hand-built-bytecode unit tests."
Why it matters / why track it. This is dead code in the VM and the wasm backend, carried by both. Two consequences:
- The wasm broadcast lowering has unit-test coverage but no end-to-end/corpus coverage, and cannot get any until/unless codegen emits these opcodes -- so it does not contribute to the Phase 8 full-corpus-parity signal and could silently rot.
- It is maintenance weight (a whole opcode family + broadcast view arithmetic mirrored in two execution engines) for a code path nothing produces.
Suggested resolution (pick one, needs a decision):
- (a) Treat it as genuinely dead and remove the broadcast-iteration family from the VM,
symbolic.rs, andwasmgen(simplest; matches "simple/general/maintainable over preserving an interface"). The arrayed-broadcast semantics it was meant to serve are already delivered by compile-time scalar unrolling. - (b) If broadcast iteration is intended to replace scalar unrolling later (e.g. to bound code size on large arrays), keep it but clearly mark it speculative/unreached in
bytecode.rsandwasmgen, and add a tracked task to either wire up a codegen emitter (which would then need corpus coverage) or delete it.
Either way the wasm side should not be expected to provide Phase 8 corpus parity for a construct codegen never emits; that expectation should be recorded.
Finding 2: ViewRangeDynamic (runtime range bounds) is Unsupported by design; no corpus model exercises it
A runtime range subscript -- arr[i:j] where i/j are not compile-time constants -- lowers to Opcode::ViewRangeDynamic (emitted at compiler/codegen.rs:436 from a non-constant SubscriptIndex::Range). The wasm backend returns WasmGenError::Unsupported for it (src/simlin-engine/src/wasmgen/lower.rs:1151-1156): the Phase 5 emitter fully unrolls every iteration body per compile-time index, so a range whose size is unknown at compile time cannot be unrolled. Such a model stays Skipped and is caught honestly by the parity floor gate.
A literal range is not affected: ast/expr3.rs:334-341 constant-folds IndexExpr2::Range(const, const) into IndexExpr3::StaticRange, which lowers to the static Opcode::ViewRange -- and the wasm backend supports that (lower.rs:1089, unit-tested at lower.rs:5041).
Corpus assessment (done): across all 495 model files under test/ (*.xmile/*.stmx/*.mdl/*.xml), there are zero genuine range subscripts of either form:
- No dynamic
arr[i:j]. - No static numeric
arr[1:3]either (rg '\[[0-9]+:[0-9]+\]'over the corpus is empty). - The only colon-in-bracket patterns in the corpus are
[*:SubDim]StarRange (e.g.MAX(x[*:SubX]),SUM(z[*:SubA]),SUM(Transition_Matrix[Cats, *:dummy]*...)intest/sdeverywhere/models/{vector,except,except2,sum}andtest/test-models/tests/subscript_switching). StarRange is a distinct construct (IndexExpr3::StarRange->Opcode::ViewStarRange) that the wasm backend does support (lower.rs:1096).
Severity / Phase 8 impact: low; does NOT block full-corpus parity. Runtime ranges are nonexistent in the corpus and rare in practice. This is a documented capability gap, not a regression: affected models stay Skipped and are surfaced by the floor gate rather than miscompiled.
Suggested resolution: document ViewRangeDynamic as a known wasm-backend limitation (the unrolling architecture cannot express a runtime-sized view), and revisit only if a real model is found to need it -- at which point the unrolling emitter would need a runtime-loop variant for the dynamic-range body. No action required for Phase 8 parity beyond recording the exclusion.
Components affected
src/simlin-engine/src/wasmgen/(lower.rs,views.rs,module.rs)src/simlin-engine/src/bytecode.rs,src/simlin-engine/src/vm.rs,src/simlin-engine/src/compiler/symbolic.rs(for Finding 1's dead-code removal/marking)
How discovered
Surfaced by the implementing agent during Phase 5 (array support) of the wasm-backend implementation plan (docs/implementation-plans/2026-05-20-wasm-backend/); the agent could not file these itself. Investigated and confirmed before filing. Related to #607 (false un-fused premise) only by shared epic; the concerns are independent.
Activity
doc: document the wasm simulation backend and its coverage
engine: WebAssembly simulation backend with full VM parity (#620)
bpowers commentedon Aug 26, 2026
Retired on the
compiler-unificationbranch (commit subjectengine: retire the unemitted opcode families, part (b) of Phase 2 ofdocs/design-plans/2026-08-25-compiler-unification.md). Finding 1 is resolved by deletion: the owner chose option (a).Deleted
SymbolicOpcodevariants and theirOpcodetwins -- the sixteen that carried#[allow(dead_code)]becauseCompilernever constructed them:PushTempView,ViewSubscriptConst,ViewRange,ViewStarRange,ViewWildcard,ViewTranspose,DupView,LoadTempDynamic,LoadIterElement,LoadIterTempElement,LoadIterViewTopBeginBroadcastIter,LoadBroadcastElement,StoreBroadcastElement,NextBroadcastOrJump,EndBroadcastIterDeleted with them, because they existed only for those opcodes:
compiler/symbolic.rs: theresolve_opcode,renumber_opcode,gf_runandjump_offsetarms; theSymbolicCompiledModule.arrays/.subdim_relationsfieldsbytecode.rs: thestack_effect/name/jump_offsetarms;ByteCodeContext.arraysand.subdim_relations(alwaysvec![]in production) with theArrayDefinitionandbytecode::SubdimensionRelationtypes;RuntimeView::for_temp,apply_range,apply_sparse,apply_sparse_with_dim_id,transpose(dimensions::SubdimensionRelation, the compiler-side relation, is untouched)vm.rs: the sixteeneval_bytecodearms,BroadcastState/BroadcastSourceInfo, thebroadcast_stackonVmandEvalState, andIterState.flat_offsetswith theBeginIterprecompute that filled it (its only reader wasLoadIterElement)compiler/codegen.rs:Compiler.subdim_relations,get_or_add_subdim_relation,find_dim_id_by_name, and theModuleCtx.dimensions_ctxfield only they readwasmgen/lower.rs: the lowering arms,BroadcastCtx,build_broadcast_ctx,emit_load_broadcast_element,IterKind(iter_spanisBeginIter-only),resolve_dim_list_dims,emit_load_temp_dynamic,current_iter_index;wasmgen/views.rs:ViewDesc::apply_single_subscript,apply_range,apply_sparse,transposelower_tests.rsview-transform /LoadTempDynamic/LoadIterElement/LoadIterTempElement/broadcast_iter_*,views.rstransform tests, thebytecode.rs/symbolic.rsfixtures,compiler/dimensions.rs::test_lazy_subdimension_relation), with the geometry they checked re-pinned on static views built the way codegen builds themWhat enforces it from here:
Compileris the only producer of aSymbolicOpcodeandresolve_opcodethe only producer of anOpcode, so a variant nothing emits is adead_codewarning on the lib target, and both the pre-commit hook (cargo clippy --all-targets --all-features -- -D warnings) and CI (cargo clippy --workspace -- -D warnings) deny it. The enum carries noallow(dead_code).ViewRangeDynamicis NOT part of this: codegen emits it for a runtimearr[i:j]range (compiler/codegen.rs), the VM executes it, and the wasm backend still returnsWasmGenError::Unsupportedfor it by design, exactly as Finding 2 describes. That limitation stands and is documented inwasmgen/lower.rs.Compiled artifacts are byte-identical on C-LEARN (nothing emitted changed); the engine suite, the wasm parity corpus, and the determinism suites are green.
Measured: on the run channel the identical C-LEARN artifact retires +0.9% instructions (dispatch-loop codegen in the smaller
eval_bytecode; the opcode stream is identical), accepted as a simplicity trade and recorded in the design plan's ledger.bpowers commentedon Sep 3, 2026
Closing with the two findings resolved as follows.
Finding 1 (the broadcast-iteration opcode family is unreached dead code): removed on main by
ca39c1c6(engine: retire the unemitted opcode families), which deletes the broadcast-iteration and incremental view-stack families and everything that existed only for them. The standing pin is structural:Compileris the only producer of aSymbolicOpcode, the enum carries noallow(dead_code), so a variant codegen does not emit is adead_codewarning thatclippy -D warningsrejects in the hook and CI.Finding 2 (
ViewRangeDynamicunsupported in wasmgen): this is the documented backend limitation (src/simlin-engine/src/wasmgen/mod.rsandmodule.rsmodule docs), not a defect of the compiler-unification work;wasmgen/lower.rsrefuses the opcode with an explicit error naming the dimension rather than mis-compiling it, and the VM remains wasmgen's oracle on every exposed slot. A wasm-side implementation of runtime view ranges would be its own issue against wasmgen.