Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
f42ff24
doc: add wasm-backend implementation plan
bpowers May 21, 2026
4eb3e60
engine: checkpoint wasm-backend POC before bytecode restructure
bpowers May 21, 2026
c9f2dec
engine: wasmgen scalar-core opcode emitter over bytecode
bpowers May 21, 2026
1b6888e
engine: wasmgen compile_simulation (root, Euler) over CompiledSimulation
bpowers May 21, 2026
bdb885f
engine: route wasmgen through compile_simulation; drop Expr path
bpowers May 21, 2026
ae6b2ea
engine: re-gate monolithic compiler builder to test-only
bpowers May 21, 2026
58bcd3b
engine: add ensure_wasm_matches parity helper
bpowers May 21, 2026
7746b93
engine: run corpus through wasm backend with rising floor gate
bpowers May 21, 2026
3ed3d5f
engine: address Phase 1 wasm-backend review feedback
bpowers May 21, 2026
01a55c4
engine: wasmgen approx_eq helper + equality/truthiness routing
bpowers May 21, 2026
66767cf
engine: open-coded wasm transcendental helpers (exp/ln/sin/cos/atan +…
bpowers May 21, 2026
a3b8269
engine: wasmgen Op2 Exp (pow) and Mod (rem_euclid)
bpowers May 21, 2026
a81a846
engine: wasmgen Apply lowering for full scalar builtin set
bpowers May 21, 2026
2fbf824
engine: raise wasm parity floor after full scalar builtins
bpowers May 21, 2026
f9df36c
engine: address Phase 2 wasm-backend review feedback
bpowers May 21, 2026
d70b209
engine: emit graphical-function tables + directory into wasm memory
bpowers May 21, 2026
8b475c4
engine: wasm lookup_interp/forward/backward helpers matching the VM
bpowers May 21, 2026
8616556
engine: wasmgen Lookup opcode lowering + GF corpus parity
bpowers May 21, 2026
0bd8f8d
engine: address Phase 3 wasm-backend review feedback
bpowers May 21, 2026
4833993
engine: wasmgen PREVIOUS/INIT snapshot regions + LoadPrev/LoadInitial
bpowers May 21, 2026
0051865
engine: wasmgen RK2/RK4 integration loops
bpowers May 21, 2026
5c9351e
engine: raise wasm parity floor after RK + PREVIOUS/INIT
bpowers May 21, 2026
2bf738e
engine: address Phase 4 wasm-backend review feedback
bpowers May 21, 2026
728ed82
engine: wasmgen compile-time view-descriptor stack + static view ops
bpowers May 21, 2026
8281c70
engine: wasmgen array reducers (Sum/Max/Min/Mean/Stddev/Size)
bpowers May 21, 2026
5c12963
engine: wasmgen BeginIter/broadcast iteration loops
bpowers May 21, 2026
5eaf58d
engine: wasmgen dynamic subscripts with OOB->NaN
bpowers May 21, 2026
ad5641a
engine: raise wasm parity floor after array core
bpowers May 21, 2026
0fd6aec
engine: address Phase 5 wasm-backend review feedback
bpowers May 21, 2026
c91053b
engine: wasmgen VectorSelect + VectorElmMap
bpowers May 21, 2026
0873ace
engine: wasmgen VectorSortOrder + Rank with stable sort
bpowers May 21, 2026
ae5abae
engine: wasmgen LookupArray (per-element arrayed GF)
bpowers May 21, 2026
1a6967f
engine: wasmgen allocation (erfc/normal_cdf/alloc_curve/allocate_avai…
bpowers May 21, 2026
5c42869
engine: raise wasm parity floor after vector ops + allocation
bpowers May 21, 2026
3a544cf
engine: address Phase 6 wasm-backend review feedback
bpowers May 21, 2026
cdf2448
engine: wasmgen per-instance module functions (EvalModule/LoadModuleI…
bpowers May 22, 2026
3d3696f
engine: wasmgen blob set_value/reset override semantics
bpowers May 22, 2026
fb0707c
libsimlin: simlin_model_compile_to_wasm returns blob + WasmLayout
bpowers May 22, 2026
1c3a0d5
engine: raise wasm parity floor after modules + systems format
bpowers May 22, 2026
46f8fbb
engine: address Phase 7 wasm-backend review feedback
bpowers May 22, 2026
348d430
engine: close the wasm parity gate (Unsupported is a hard failure)
bpowers May 22, 2026
2e3340f
engine: C-LEARN wasm parity twin against Ref.vdf
bpowers May 22, 2026
c9c37e2
doc: document the wasm simulation backend and its coverage
bpowers May 22, 2026
8fc8762
doc: document wasm backend FFI and engine subsystem
bpowers May 22, 2026
43fdc9e
engine: correct stale wasmgen module doc comment
bpowers May 22, 2026
7ac8c69
docs: add test plan for wasm simulation backend
bpowers May 22, 2026
536bb36
engine: reset wasm PREVIOUS fallback at the start of each run
bpowers May 22, 2026
570ac5b
engine: thread RK stock offsets full-width (no u16 truncation)
bpowers May 22, 2026
70c1165
doc: ban "Last updated" lines in CLAUDE.md files
bpowers May 22, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ IMPORTANT: If feedback seems non-actionable, it means you need comments explaini
- Public Rust items and non-trivial internal functions should have concise rustdoc describing purpose, key assumptions, and side effects.
- When behavior changes, update nearby comments in the same commit so docs and code stay aligned.
- If you intentionally remove a comment block, replace it with an updated equivalent when the context is still non-obvious.
- NEVER add a "Last updated" (or "Last verified") line to a `CLAUDE.md`: it is a perpetual rebase/merge-conflict magnet and goes stale immediately. Describe current state in prose; rely on `git log` / `git blame` for history.

## Development Standards

Expand Down
49 changes: 47 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
- [design-plans/2026-05-11-ltm-arrays-hardening.md](design-plans/2026-05-11-ltm-arrays-hardening.md) -- Arrayed/cross-element LTM hardening: unify the reference-site walkers behind one classification IR (#520), then layer eight fixes (#487, #511, #510, #514, #515, #483, #502, #492)
- [design-plans/2026-05-13-macros.md](design-plans/2026-05-13-macros.md) -- Vensim macro support: macros as a data-driven generalization of the stdlib module mechanism, persisted via a `MacroSpec` marker on `Model`; 7 implementation phases
- [design-plans/2026-05-19-clearn-residual.md](design-plans/2026-05-19-clearn-residual.md) -- Close C-LEARN's residual (#590/#591) as general Vensim import/simulation primitives: arrayed inline graphical functions, import-time macro shadowing, user-macro INITIAL recurrence, residual attribution; 5 phases
- [design-plans/2026-05-20-wasm-backend.md](design-plans/2026-05-20-wasm-backend.md) -- WebAssembly code-generation backend: compile a model to one self-contained wasm module as an alternative to the bytecode VM (for fast interactive re-simulation), validated to full VM parity; 8 phases
- [plans/](plans/README.md) -- Implementation plans (active and completed)
- [test-plans/](test-plans/) -- Human verification plans for completed features
- [test-plans/2026-05-20-wasm-backend.md](test-plans/2026-05-20-wasm-backend.md) -- Manual verification for the WebAssembly simulation backend: the heavy `#[ignore]`d parity twins (C-LEARN vs `Ref.vdf`, WORLD3), driving the libsimlin FFI from a real host, and the AC3.3 deliberate-regression check (the bytecode VM is the automated oracle for everything else)
- `implementation-plans/` -- Detailed phase-by-phase implementation plans, created during plan execution

## Security
Expand Down
1 change: 1 addition & 0 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Core simulation engine. Compiles, type-checks, unit-checks, and simulates SD mod
- Primary compilation path is `db::compile_project_incremental()` using salsa tracked functions for fine-grained incrementality (`db.rs`, `db_analysis.rs`, `db_ltm.rs`, `db_ltm_ir.rs`)
- Equation text is parsed via recursive descent parser (`parser/mod.rs`)
- Simulations run on a stack-based bytecode VM (`vm.rs`) with `PREVIOUS`/`INIT` intrinsic opcodes
- An alternative WebAssembly code-generation backend (`wasmgen/`) lowers a compiled model to one self-contained wasm module (no host imports) for fast repeated re-simulation; the VM stays the correctness oracle (every emitted module is checked against it). Surfaced through libsimlin `simlin_model_compile_to_wasm`
- `builtins.rs` defines builtin functions (including `PREVIOUS`, `INIT`); stateful module functions (TREND, SMOOTH3) are model definitions in `stdlib/*.stmx`, generated into `stdlib.gen.rs`
- Native Vensim MDL parser in `mdl/` (replaces C++ xmutil); see [docs/design/mdl-parser.md](/docs/design/mdl-parser.md)

Expand Down
2 changes: 1 addition & 1 deletion docs/design-plans/2026-05-20-wasm-backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Turn the validated proof-of-concept (branch `wasm-backend-poc`) into a full, cor

## Architecture

The backend translates the engine's compiled bytecode into an equivalent WebAssembly module, mirroring the bytecode VM (`src/simlin-engine/src/vm.rs`) opcode-for-opcode. It consumes the public salsa output `compile_project_incremental(db, project, model) -> CompiledSimulation` (`vm.rs:134`) — the same value `Vm::new` consumes — so no salsa-internal queries are touched and all engine assembly (dependency ordering, model-global offset resolution, recurrence-SCC handling, graphical-function layout, module instantiation, implicit SMOOTH/DELAY variables) is inherited unchanged.
The backend translates the engine's compiled bytecode into an equivalent WebAssembly module, mirroring the bytecode VM (`src/simlin-engine/src/vm.rs`) opcode-for-opcode. It consumes the public salsa output `compile_project_incremental(db, project, model) -> CompiledSimulation` (`db.rs:5886`, returning the `CompiledSimulation` defined at `vm.rs:134`) — the same value `Vm::new` consumes — so no salsa-internal queries are touched and all engine assembly (dependency ordering, model-global offset resolution, recurrence-SCC handling, graphical-function layout, module instantiation, implicit SMOOTH/DELAY variables) is inherited unchanged.

`CompiledSimulation` is `{ modules: HashMap<ModuleKey, CompiledModule>, specs: Specs, root: ModuleKey, offsets: HashMap<Ident, usize> }`. Each `CompiledModule` (`bytecode.rs:4616`) holds three opcode programs (`compiled_initials`, `compiled_flows`, `compiled_stocks`), per-program `literals`, and a shared `ByteCodeContext` (`bytecode.rs:1585`: graphical-function tables, module declarations, dimensions, temp-array sizes, static array views). It is the *un-fused* form — the 3-address `fuse_three_address` pass runs later in `Vm::new` — so the backend translates the plain opcode set only.

Expand Down
Loading
Loading