Files
hakorune/docs/development/current/main/phases
tomoaki 661bbe1ab7 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
..
2025-12-17 04:26:23 +09:00
2025-12-17 04:26:23 +09:00
2025-12-17 04:26:23 +09:00
2025-12-17 23:30:13 +09:00
2025-12-17 23:30:13 +09:00
2025-12-17 23:45:55 +09:00
2025-12-18 02:39:44 +09:00
2025-12-18 02:55:14 +09:00
2025-12-18 05:50:29 +09:00
2025-12-18 06:47:43 +09:00

Phase ドキュメント

このフォルダは、実装フェーズPhase 131, Phase 33 等)ごとの詳細記録を保管します。

現在の Phase

  • Phase 139DONE: post-if post_k の return lowering を ReturnValueLowererBox に統一(出口 SSOT 完成)
  • Phase 140DONE: NormalizedExprLowererBox 初版pure expression のみ)
  • Phase 141 P0DONE: impure 拡張点contractを SSOT 化Call/MethodCall はまだ out-of-scope
  • Phase 141 P1DONE: “既知 intrinsic だけ” を許可して段階投入length0
  • Phase 141 P1.5DONE: known intrinsic registry + available_inputs 3-source merge + diagnostics
  • Phase 141 P2+planned: Call/MethodCall 対応effects + typing の段階投入)
  • Phase 142-loopstmt P0DONE: 正規化単位を statementloop 1個へ寄せるパターン爆発を止める
  • Phase 142-loopstmt P1DONE: LLVM EXE smoke同 fixtureを追加
  • Phase 143-loopvocabplanned: StepTree の語彙拡張loop 内 if/break/continue を「語彙追加」で吸収)
  • Phase 9192: Selfhost depth2 coverageP5b escape recognition → lowering
  • Phase 94100: P5b escape E2E / Trim policy / pinned + accumulatorVM/LLVM EXE parity
  • Phase 102: real-app read_quoted loop regressionVM + LLVM EXE
  • Phase 103: if-only regression baselineVM + LLVM EXE / plan
  • Phase 113: if-only partial assign parity片側代入の保持 merge
  • Phase 107109: real-app depth-scan / policy router SSOT / error hint SSOT
  • Phase 110112: ControlTree / StepTree構造SSOT, dev-only※設計SSOTは ../design/control-tree.md

Phase フォルダ構成(推奨)

phases/phase-131/
├── README.md                          (Phase 全体概要)
├── 131-03-llvm-lowering-inventory.md (LLVM 部分のテスト・検証)
├── 131-11-case-c-summary.md          (Case C 実装サマリー)
└── phase131-11-case-c-root-cause-analysis.md (根本原因分析)

参照方法

  1. 現在の Phase を知りたい../10-Now.md
  2. 該当 Phase を詳しく知りたい → フォルダを開く
  3. 設計背景を知りたい../design/
  4. 調査ログを見たい../investigations/

Phase 命名規則

  • ファイル名: phase-<N>-<title>/ (例: phase-131/)
  • 文書名: <N>-<NN>-<topic>.md (例: 131-11-case-c-summary.md)
    • Phase 番号で自然にソート可能
    • 同一 Phase 内で段階的に追跡可能

作成ルールSSOT

詳しくは ../DOCS_LAYOUT.md を参照。

  • 置き場所: phases/phase-<N>/ 配下のみ
  • 内容: Phase の実装記録・進捗・チェックリスト・検証結果
  • 避けるべき: 複数 Phase で参照される設計・アーキテクチャ(→ design/ へ)

最終更新: 2025-12-19