Files
hakorune/docs/development/current/main/phases/phase-286/README.md

62 lines
2.6 KiB
Markdown
Raw Normal View History

feat(phase284): P1 Complete - Return in Loop with Block Remap Fix ## Summary Completed Phase 284 P1: Enable return statements in Pattern4/5 loops via JoinInst::Ret infrastructure (100% pre-existing, no new infrastructure needed). **Critical Bug Fix**: Block ID remap priority - Fixed: local_block_map must take precedence over skipped_entry_redirects - Root cause: Function-local block IDs can collide with global remap entries (example: loop_step:bb4 vs k_exit:bb4 after merge allocation) - Impact: Conditional Jump else branches were incorrectly redirected to exit - Solution: Check local_block_map FIRST, then skipped_entry_redirects ## Implementation ### New Files - `src/mir/join_ir/lowering/return_collector.rs` - Return detection SSOT (top-level only, P1 scope) - `apps/tests/phase284_p1_return_in_loop_min.hako` - Test fixture (exit code 7) - Smoke test scripts (VM/LLVM) ### Modified Files - `loop_with_continue_minimal.rs`: Return condition check + Jump generation - `pattern4_with_continue.rs`: K_RETURN registration in continuation_funcs - `canonical_names.rs`: K_RETURN constant - `instruction_rewriter.rs`: Fixed Branch remap priority (P1 fix) - `terminator.rs`: Fixed Jump/Branch remap priority (P1 fix) - `conversion_pipeline.rs`: Return normalization support ## Testing ✅ VM: exit=7 PASS ✅ LLVM: exit=7 PASS ✅ Baseline: 46 PASS, 1 FAIL (pre-existing emit issue) ✅ Zero regression ## Design Notes - JoinInst::Ret infrastructure was 100% complete before P1 - Bridge automatically converts JoinInst::Ret → MIR Return terminator - Pattern4/5 now properly merge k_return as non-skippable continuation - Correct semantics: true condition → return, false → continue loop ## Next Phase (P2+) - Refactor: Block remap SSOT (block_remapper.rs) - Refactor: Return jump emitter extraction - Scope: Nested if/loop returns, multiple returns - Design: Standardize early exit pattern (return/break/continue as Jump with cond) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2025-12-23 14:21:27 +09:00
# Phase 286: JoinIR Line AbsorptionJoinIR→CorePlan/Frag 収束)
Status: Planned (design-first)
## Goal
移行期間に残っている「2本の lowering」を、構造で 1 本に収束させる。
- Plan linePattern6/7: `CorePlan → Frag(compose) → emit_frag()` が SSOT
- JoinIR linePattern15,9: `JoinIR → bridge → merge` が SSOT
Phase 286 では JoinIR line を “第2の lowerer” として放置せず、**Plan/Frag SSOT へ吸収**する道筋を固定する。
## Whyなぜ今
- `return` のような「大きな出口語彙」は、責務が分散すると実装場所が揺れて事故りやすい
- 移行期間の弱点は「同じASTでも経路により意味論が割れる可能性がある」こと
- pattern を溶かしていく思想の最後の壁が “JoinIR line の残存” になりやすい
## SSOTPhase 286 で守る憲法)
- **SSOT=extract**Phase 282: 検出は extract の成功でのみ決める。`pattern_kind` は O(1) safety valve のみ。
- **CFG/terminator SSOT**Phase 280/281: `Frag + compose::* + emit_frag()` が唯一の terminator 生成点。
- **Fail-Fast**: close-but-unsupported を `Ok(None)` で黙殺しないsilent reroute 禁止)。
## Responsibility Mapどこを触るか
- JoinIR line の共通入口(現状):
- `src/mir/builder/control_flow/joinir/patterns/conversion_pipeline.rs`
- `src/mir/join_ir_vm_bridge/bridge.rs`
- `src/mir/builder/control_flow/joinir/merge/mod.rs`
- Plan/Frag SSOT収束先:
- `src/mir/builder/control_flow/plan/*`
- `src/mir/builder/control_flow/edgecfg/api/compose.rs`
- `src/mir/builder/control_flow/edgecfg/api/emit.rs`
## Scope提案
### P0docs-only
- 「JoinIR line をどの粒度で吸収するか」を SSOT として決める
- 例: JoinIR は DomainPlan 生成の補助へ降格 / JoinIR→MIR merge を段階撤去
- “禁止事項” を明文化pattern 側への散布、二重 SSOT の再発)
### P1investigation
- JoinIR line が持っている「本当は SSOT に寄せたい責務」を棚卸し
- return/break/continue の扱い
- exit phi / boundary の責務
- optimizer/type propagation の入り口
### P2PoC
- 代表 1 パターン(例: Pattern4を “JoinIR 生成 → CorePlan/Frag” に変換する PoC
- 目的: merge を通さずに `emit_frag()` 経由で終端が生成できることの証明
## AcceptanceP0
- 2本の lowering が “設計として” どこで 1 本に収束するかが明文化されている
- Phase 284Return/ Phase 285GCと矛盾しない