Skip to content

fix: per-function Z3 rollback, async component model, stats overflow#80

Open
avrabe wants to merge 1 commit intomainfrom
fix/per-function-verification-rollback-async-stats
Open

fix: per-function Z3 rollback, async component model, stats overflow#80
avrabe wants to merge 1 commit intomainfrom
fix/per-function-verification-rollback-async-stats

Conversation

@avrabe
Copy link
Copy Markdown
Contributor

@avrabe avrabe commented Apr 14, 2026

Summary

Three fixes for real-world component optimization:

1. Per-function Z3 verification rollback (critical)

Previously, when Z3 found a counterexample for ONE function in constant_folding, the ? operator aborted the entire pass — all other functions in the module fell back to original bytes. Now, each function's instructions are saved before optimization and reverted individually on Z3 rejection, allowing other functions to still benefit from optimization.

2. Async component model support

Components using WASI async (task.return, task.wait, streams, futures) failed validation because wasmparser's Validator::new() doesn't enable async features by default. Now uses Validator::new_with_features() with cm_async, cm_async_stackful, and cm_async_builtins enabled. Applied to both the parser and all component optimizer validation calls.

3. Stats percentage overflow

(before - after) as f64 caused unsigned wraparound when output was larger than input (showing ~9829770584193684% reduction). Fixed by casting to f64 before subtraction.

Test plan

  • cargo test --release — 403 tests pass
  • All pre-commit hooks pass (fmt, clippy, test, build)
  • Test with async relay components (task.return)

🤖 Generated with Claude Code

@avrabe avrabe force-pushed the fix/per-function-verification-rollback-async-stats branch 2 times, most recently from 223419f to 6989cd8 Compare April 14, 2026 01:41
…sync support

Per-function Z3 verification rollback:
- constant_folding and optimize_advanced_instructions now revert
  individual functions on Z3 counterexample instead of aborting the
  entire pass.

Pure ISLE rewrites for control-flow functions:
- Functions with BrIf/BrTable are no longer skipped entirely.
- New rewrite_pure() applies structural ISLE rules (constant folding,
  algebraic identities, strength reduction) without dataflow env tracking.
- rewrite_with_dataflow() (formerly simplify_with_env) is used only for
  straight-line code where local/memory propagation is safe.
- Backward-compatible aliases simplify() and simplify_with_env() retained.

Async component model support:
- Enable cm_async, cm_async_stackful, cm_async_builtins in wasmparser
  Validator. Components with task.return now parse correctly.

Stats percentage overflow fix:
- Cast to f64 before subtraction to prevent unsigned wraparound.

Fixes: H-19
Trace: REQ-5, REQ-11, SC-8
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@avrabe avrabe force-pushed the fix/per-function-verification-rollback-async-stats branch from 6989cd8 to 58301c4 Compare April 14, 2026 02:25
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