Skip to content
pulseenginePublic

About

Weaves Wasm tighter, then checks the weave

Topics

Resources

Contributing

Security policy

Stars

6 stars

Watchers

0 watching

Forks

Latest commit

 

History

525 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Loom

WebAssembly optimizer with per-pass translation validation

 

CI Rust WebAssembly Translation validation License: Apache-2.0

 

Meld · Loom · Synth · Kiln · Sigil

 

Meld fuses. Loom weaves. Synth transpiles. Kiln fires. Sigil seals.

WebAssembly optimization pipeline built on Cranelift's ISLE pattern-matching engine. Constant folding, strength reduction, CSE, inlining, dead code elimination. After each pass a Z3 SMT translation validator compares each changed function with its previous version and keeps the change when the two are proven equivalent. The comparison is exact: return values, globals, every linear memory and its size, and traps, including the globals and memory a trap leaves behind. Each loop is paired with the loop in the same place in the other function and proven one iteration at a time; a change that alters a loop's structure (for example hoisting code out of it) cannot be proven this way and is not kept. A function with an instruction outside the model is not changed. Some transforms are kept without a proof; each reason is listed in safety/VALIDATOR_TRUST_LEDGER.txt (a body over the solver size threshold is one), and --stats counts them by reason. Floating-point arithmetic on non-constant operands is compared as uninterpreted functions, and a NaN result is taken to have one payload per operation and operands. Includes a fused mode purpose-built for Meld output.

Quick Start

# Build from source
git clone https://github.com/pulseengine/loom
cd loom
cargo build --release

# Optimize a WebAssembly module
loom optimize input.wasm -o output.wasm

# With statistics
loom optimize input.wasm -o output.wasm --stats

# With Z3 verification
loom optimize input.wasm -o output.wasm --verify

# Keep an output larger than the input (inlining for speed)
loom optimize input.wasm -o output.wasm --allow-growth

loom optimize writes the input unchanged when the optimized output would be larger, and says so on stdout and in --stats-json (size_gate). The CLI inliner works within a growth budget: a function with several call sites is copied only while the call overhead saved by moving single-site functions pays for it. --allow-growth lifts both limits.

Architecture

  • loom-core — Optimization pipeline implementation
  • loom-shared — Core ISLE definitions and WebAssembly IR (stable API)
  • loom-cli — Command-line interface
  • loom-testing — Differential testing framework

Two pipeline surfaces:

  • Library optimize_module() (loom-core) runs the canonical pipeline: Inline → Constant Folding → Advanced Instructions → Simplify Locals → DCE → Code Folding → LICM → Remove Unused Branches → Optimize Added Constants → DCE → Coalesce Locals.
  • CLI loom optimize --passes exposes selectable passes: inline, precompute, constant-folding, cse, advanced, branches, dce, merge-blocks, vacuum, simplify-locals.

See docs/architecture.md for the full pipeline design.

Features

  • Constant folding — Compile-time evaluation with cross-function propagation via inlining
  • Strength reduction — Replace expensive ops with cheaper equivalents (x * 8 becomes x << 3)
  • Common subexpression elimination — Deduplicate redundant computations
  • Function inlining — Inline small functions to expose cross-function optimizations
  • Dead code elimination — Remove unreachable code and unused locals
  • Loop-invariant code motion — Hoist invariant expressions out of loops (hoists are not yet provable under the validator, so they are reverted; #523)
  • Component Model support — wasm32-wasip2 build target
  • Stateful dataflow analysis — Track locals and memory state across passes
  • Idempotent passes — Safe to run multiple times without degradation

Translation Validation

Z3 SMT translation validation is on by default (default = ["verification", "attestation"] in loom-core / loom-cli Cargo.toml). After each optimization pass the validator asks for an input on which the original and the optimized function differ, and keeps the change when there is none; otherwise the function is reverted to its pre-pass state. The comparison is exact: return values, globals, every linear memory and its size, and traps, including the globals and memory a trap leaves behind. Each loop is paired with the loop in the same place in the other function and proven one iteration at a time; a change that alters a loop's structure (for example hoisting code out of it) cannot be proven this way and is not kept. A function with an instruction outside the model is not changed. Some transforms are kept without a proof; each reason is listed in safety/VALIDATOR_TRUST_LEDGER.txt (a body over the solver size threshold is one), and --stats counts them by reason. Floating-point arithmetic on non-constant operands is compared as uninterpreted functions, and a NaN result is taken to have one payload per operation and operands. --stats reports how many accepted transforms were proven and how many were kept without a proof, with the reason. It also splits the proven attempts by what decided them: unchanged (the pass left the function as it was), no_solver (both sides encoded to the same term), z3, or ordeal (certificate re-checked). --stats-json <file> writes the same data, with one record per attempt, as JSON.

# Default build — Z3 verification on
cargo build --release
loom optimize input.wasm -o output.wasm --verify

# Disable Z3 (faster, no translation validation)
cargo build --release --no-default-features

See docs/guides/formal-verification.md for details.

Note

Cross-cutting verification — Rocq mechanized proofs, Kani bounded model checking, Z3 SMT verification, and Verus Rust verification are used across the PulseEngine toolchain. Sigil attestation chains bind it all together.

Documentation

Building

cargo build --release                            # Standard build (Z3 on by default)
cargo build --release --no-default-features      # Without Z3 verification
cargo test                                       # Run tests
cargo bench                                      # Run benchmarks

# WASM build (CI uses these exact steps)
rustup target add wasm32-wasip2
cargo build --release --target wasm32-wasip2 --package loom-cli

License

Apache-2.0


Part of PulseEngine — a WebAssembly Component Model engine for safety-critical systems

About

Weaves Wasm tighter, then checks the weave

Topics

Resources

Contributing

Security policy

Stars

6 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages