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>
This commit is contained in:
@ -61,6 +61,36 @@ AST/Stmt → │ Plan Extractor Box (pure) │
|
||||
(terminator operand only)
|
||||
```
|
||||
|
||||
注記(名前の揺れを防ぐ):
|
||||
- **PlanFreeze** という呼び名を使う場合、意味は **Normalizer + Verifier の合成(凍結点)**。
|
||||
- 目的は「一致宣言(Ok(Some))した後は後戻りせず、**DomainPlan →(変換+検証)→ FrozenCorePlan** に確定する」こと。
|
||||
- 実装上は分割して持ってもよいが、会話や指示書では “凍結点” を **PlanFreeze** と呼ぶと迷子が減る。
|
||||
|
||||
PlanFreeze 版(同じ収束形、箱名だけ明確化):
|
||||
|
||||
```
|
||||
┌──────────────────────────────┐
|
||||
AST/Stmt → │ Plan Extractor (pure) │
|
||||
│ - Ok(None)/Ok(DomainPlan)/Err
|
||||
└──────────────┬───────────────┘
|
||||
│
|
||||
v
|
||||
┌──────────────────────────────┐
|
||||
│ PlanFreeze (=Normalizer+Verifier) │
|
||||
│ - DomainPlan → FrozenCorePlan │
|
||||
│ - close-but-unsupported => Err │
|
||||
└──────────────┬───────────────┘
|
||||
│
|
||||
v
|
||||
┌──────────────────────────────┐
|
||||
│ Plan Lowerer (only builder) │
|
||||
└──────────────┬───────────────┘
|
||||
v
|
||||
┌──────────────────────────────┐
|
||||
│ Frag + compose::* + emit_frag() │
|
||||
└──────────────────────────────┘
|
||||
```
|
||||
|
||||
### 0.0.2 「収束している」と呼ぶ条件(定義)
|
||||
|
||||
この定義を満たしている状態を、JoinIR/CFG 合成の「収束」と呼ぶ:
|
||||
@ -81,6 +111,24 @@ AST/Stmt → │ Plan Extractor Box (pure) │
|
||||
参照(相談メモ / 背景):
|
||||
- `docs/development/current/main/investigations/phase-272-frag-plan-architecture-consult.md`
|
||||
|
||||
### 0.0.3 現状の実装(2本の lowering line)
|
||||
|
||||
現状は移行期間のため、入口が 2 本ある(=「2本のコンパイラ」になりやすい状態)。ここを **Phase 286** で 1 本に収束させる。
|
||||
|
||||
- **Plan line(route=plan)**
|
||||
- 対象: Pattern6/7(Plan-based)
|
||||
- 入口: `src/mir/builder/control_flow/joinir/patterns/router.rs`(`route=plan ...`)
|
||||
- SSOT: `src/mir/builder/control_flow/plan/*` → `Frag + compose::* + emit_frag()`
|
||||
|
||||
- **JoinIR line(route=joinir)**
|
||||
- 対象: Pattern1–5,8–9(JoinIR table-based)
|
||||
- 入口: `src/mir/builder/control_flow/joinir/patterns/router.rs`(`route=joinir ...`)
|
||||
- 共通入口(変換/merge の集約点): `src/mir/builder/control_flow/joinir/patterns/conversion_pipeline.rs`
|
||||
|
||||
注意:
|
||||
- 「return/break/continue のような “大きい出口語彙”」を実装する時、どちらの line に効く修正かを先に固定しないと迷子が再発する。
|
||||
- Phase 284 は “ExitKind へ収束” を先に決め、Phase 286 で line 自体を吸収して 1 本化する。
|
||||
|
||||
## 0. 読み方ガイド(Reader's Guide)
|
||||
|
||||
このファイルは情報量が多いので、「何を知りたいか」で読む場所を分けると楽だよ:
|
||||
|
||||
Reference in New Issue
Block a user