feat(phase143/r0): Contract SSOT extraction - loop-if-exit pattern refactoring
Phase 143 R0: Refactor P0 to prevent if-branch explosion in P1/P2 **Key Changes**: - New: loop_if_exit_contract.rs (LoopIfExitShape, LoopIfExitThen, OutOfScopeReason) - Contract SSOT for pattern shape detection and exit action discrimination - Separated unit tests to tests/phase143_loop_if_exit_contract.rs (8 tests) - Removed embedded tests from implementation file - Updated module declarations for contract and test modules **Benefits**: - Enum-driven pattern discrimination (no if-branch explosion) - P1 extension: Add Continue via 1 enum variant + 1 match arm - P2 extension: Add else via contract fields (linear growth, not exponential) - Improved maintainability and code discoverability **Verification**: - cargo check: ✅ 0 errors - Unit tests: ✅ 8/8 passed - Documentation: ✅ Updated 10-Now.md and 30-Backlog.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -3,9 +3,35 @@
|
||||
## Next (planned)
|
||||
|
||||
- Phase 141 P2+: Call/MethodCall 対応(effects + typing を分離して段階投入)
|
||||
- Phase 143-loopvocab: StepTree の語彙拡張(loop 内 if/break/continue を「新パターン追加」ではなく「語彙追加」で吸収)
|
||||
- Phase 143-loopvocab R0+: StepTree の語彙拡張(loop 内 if/break/continue を「新パターン追加」ではなく「語彙追加」で吸収)
|
||||
- R0: Contract SSOT 抽出(pattern shape と exit action の分離)
|
||||
- P1: continue 支援を追加
|
||||
- P2: else/対称branch 対応
|
||||
- 詳細: `docs/development/current/main/30-Backlog.md`
|
||||
|
||||
## 2025-12-19:Phase 143-loopvocab P0 完了 ✅
|
||||
|
||||
**Phase 143-loopvocab P0: Conditional Break Vocabulary Extension**
|
||||
- 目的: `loop(true) { if(cond_pure) break }` パターンを Normalized shadow で実装(Phase 131 の条件付き拡張)
|
||||
- 仕様:
|
||||
- Loop条件: `true` リテラルのみ
|
||||
- ループ本体: 単一 if statement(else なし)
|
||||
- If then: `break` のみ(no continue, no nested if)
|
||||
- 条件: pure expression のみ(変数/リテラル/算術/比較、Method call なし)
|
||||
- Out-of-scope は `Ok(None)` で graceful fallback
|
||||
- 実装 SSOT:
|
||||
- `src/mir/control_tree/normalized_shadow/loop_true_if_break_continue.rs`
|
||||
- 6-function JoinModule(main → loop_step → loop_cond_check → Jump/Call → k_exit → Ret)
|
||||
- Jump: if true → k_exit, if false → fall through to Call(loop_step)
|
||||
- Fixtures:
|
||||
- `apps/tests/phase143_loop_true_if_break_min.hako`(expected exit code 1)
|
||||
- Smoke tests:
|
||||
- VM: `tools/smokes/v2/profiles/integration/apps/phase143_loop_true_if_break_vm.sh` ✅ PASS
|
||||
- LLVM EXE: `tools/smokes/v2/profiles/integration/apps/phase143_loop_true_if_break_llvm_exe.sh` ✅ PASS
|
||||
- Regression: Phase 131-142 green(no regressions)
|
||||
- 統計: +400 lines(loop_true_if_break_continue.rs), 0 change to existing code
|
||||
- 入口: `docs/development/current/main/phases/phase-143-loopvocab/README.md`
|
||||
|
||||
## 2025-12-19:Phase 142-loopstmt P0 完了 ✅
|
||||
|
||||
**Phase 142-loopstmt P0: Statement-Level Loop Normalization**
|
||||
|
||||
@ -16,11 +16,37 @@ Related:
|
||||
- out-of-scope は `Ok(None)` でフォールバック(既定挙動不変)
|
||||
- effects の順序付けは SSOT で固定してから解禁(by-name 増殖禁止)
|
||||
|
||||
- **Phase 143-loopvocab(planned): “新パターン追加” ではなく “語彙追加” で吸収**
|
||||
- 対象: `loop(true){ if(cond) break/continue }` を StepTree/ControlTree の語彙として表現し、同じ lowering に流す
|
||||
- **Phase 143-loopvocab R0(planned): Contract SSOT 抽出(refactor P0 → modular components)**
|
||||
- 目的: loop_true_if_break_continue.rs を「検出/契約/変換」に分割し、P1/P2 での if分岐増殖を防ぐ
|
||||
- 実装:
|
||||
- 新ファイル: `src/mir/control_tree/normalized_shadow/common/loop_if_exit_contract.rs`
|
||||
- `enum LoopIfExitThen { Break, Continue }`
|
||||
- `struct LoopIfExitShape { has_else: bool, then: LoopIfExitThen, else_: Option<LoopIfExitThen>, cond_scope: ExprLoweringScope }`
|
||||
- `enum OutOfScopeReason { NotLoopTrue, BodyNotSingleIf, ThenNotExit, ElseNotSupported, CondOutOfScope(...) }`
|
||||
- Refactor: loop_true_if_break_continue.rs は「shape抽出 → lower」だけに縮退(SSOT は contract側)
|
||||
- Tests: unit test を dedicated module へ分離(test maintainability)
|
||||
- 受け入れ条件:
|
||||
- capability guard(Fail-Fast)でスコープ外を明確化
|
||||
- fixture/smoke を 1 本ずつ小さく固定(VM + LLVM EXE parity)
|
||||
- cargo check ✅(no errors)
|
||||
- P1/P2 での if分岐を防ぐ(contract で決定性を保証)
|
||||
- out-of-scope は `Ok(None)` で一貫(既定挙動不変)
|
||||
|
||||
- **Phase 143-loopvocab P1(planned): continue 語彙追加**
|
||||
- 対象: `loop(true) { if(cond_pure) continue }` を same lowering に通す
|
||||
- 実装:
|
||||
- LoopIfExitShape で `LoopIfExitThen::Continue` を許可
|
||||
- JoinModule: if true → loop_step (continue semantics)
|
||||
- Fixtures: `phase143_loop_true_if_continue_min.hako`
|
||||
- Smoke: VM + LLVM EXE
|
||||
- Out-of-scope は `Ok(None)` のまま
|
||||
|
||||
- **Phase 143-loopvocab P2(planned): else 対応(break/continue 対称化)**
|
||||
- 対象: `if(cond){break}else{continue}` と `if(cond){continue}else{break}` を追加
|
||||
- 実装:
|
||||
- LoopIfExitShape で `has_else=true` + symmetric `then/else_` を許可
|
||||
- Contract で 4パターンを明示(P0: no-else, P1: no-else+continue, P2: with-else)
|
||||
- Fixtures: 2本(対称ケース)
|
||||
- Smoke: VM/LLVM EXE
|
||||
- 完了で「語彙として完成」に寄せる
|
||||
|
||||
- **real-app loop regression の横展開(VM + LLVM EXE)**
|
||||
- ねらい: 実コード由来ループを 1 本ずつ最小抽出して fixture/smoke で固定する(段階投入)。
|
||||
|
||||
Reference in New Issue
Block a user