feat(opt): #70 six-pass chain composition + task.return shim peephole (v1.0.5 Track 2)#131
Merged
Merged
Conversation
… (v1.0.5 Track 2) Composes the remaining five steps of the v1.0.3 #70 roadmap on the post-detection IR produced by v1.0.4 (Track A, #125). ## Part A: orchestrator (component_optimizer.rs) New `run_async_chain_passes(module)` runs, in order: 2. crate::optimize::inline_functions (force-inline async-lift thunks) 3. crate::optimize::directize (const-slot call_indirect → direct) 4. crate::optimize::constant_folding (propagate EXIT_OK discriminant) 5. crate::optimize::eliminate_dead_code (drop unreachable slow-path arms) 5.5 crate::optimize::forward_global_shim (NEW — task.return forward, lib.rs) 6. crate::optimize::eliminate_dead_stores (kill start_task waitable init) Each constituent pass is no-op on functions that don't need it, so over-applying is safe. Every pass already carries its own Z3 `verify_or_revert` gate, so the orchestrator does NOT bypass verification — it just composes existing proven passes in the right order for the post-detection IR. Wiring in `optimize_core_module` mirrors the Phase 3 / Phase 4 save-and-revert pattern: encode + wasm-tools-validate after the chain; revert on mismatch. ## Part B: forward_global_shim peephole (lib.rs) New `optimize::forward_global_shim(module)` recognises global.set $g global.get $g ;; immediately follows and erases both. Soundness: - the global has EXACTLY ONE writer module-wide (verified via a pre-scan that recurses into Block/Loop/If bodies), - `global.get` immediately follows the matching `global.set` (any intervening instruction blocks the fold), - any function containing Instruction::Unknown disqualifies the module-wide pass. The fold is byte-for-byte equivalent to keeping the value on the stack when the global has a single writer — no observer can race the round-trip. ## Tests (8 new, all pass) forward_global_shim: - test_forward_global_shim_folds_simple_pair - test_forward_global_shim_skips_multiple_writers - test_forward_global_shim_skips_intervening_op - test_forward_global_shim_skips_mismatched_indices - test_forward_global_shim_no_op_on_plain_function - test_forward_global_shim_skips_unknown_instructions chain composition: - test_chain_compose_eliminates_full_adapter - test_chain_no_op_when_pattern_absent Targeted run (async_adapter forward_global chain_compose): 12 passed; 0 failed; 0 ignored. ## Scope The chain re-uses existing passes — no duplication, no Z3 bypass. Token cost: +601 LOC (orchestrator + peephole + tests + comments). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
avrabe
added a commit
that referenced
this pull request
May 19, 2026
…#68 fused + Rocq prep) (#133) Four v1.0.4 infrastructure pieces grew real consumers: #130 Track 1+4 ægraph pipeline integration + Rocq Roundtrip prep doc #131 Track 2 #70 six-pass chain composition + task.return shim peephole #132 Track 3 #68 Tier-1.1 scalar adapter inlining + Tier-2.2 body dedup +18 tests, 400+ total. Code-section bytes unchanged on the current corpus — Track 3 agent flagged 4 pre-existing observations worth tracking for v1.0.6+.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Composes the v1.0.4 async-adapter detector with inline + directize + const-fold + DCE + new forward_global_shim peephole + dead-stores. ~600 LOC across component_optimizer.rs + lib.rs. 8 new tests. Strict-shrink gate on the hand-built P3 adapter fixture.
🤖 Generated with Claude Code