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:
2025-12-23 14:21:27 +09:00
parent 41d92bedb9
commit 661bbe1ab7
22 changed files with 1123 additions and 131 deletions

View File

@ -21,6 +21,29 @@ Related:
- P0docs-onlyで “return の意味” と “Ok(None)/Err” の境界を固定
- P1+ で Rust/LLVM の実装を SSOT に収束pattern側に例外実装を増やさない
- **Phase 285planned, design-first: Box lifecycle / weakref / finalization / GC SSOT**
- 目的: Box の生存期間(強参照/弱参照/解放/最終化)を SSOT として固定し、「実装が仕様」になっている箇所を潰す
- ねらい:
- VM 側の weakref/finalization を仕様化(テストで固定)
- LLVM harness 側の未対応/差分を “仕様として明文化” し、将来の実装計画を切る
- 入口: `docs/development/current/main/phases/phase-285/README.md`
- スコープ案:
- P0docs-only: 仕様SSOT + 用語 + ルート集合roots+ 禁止事項finalizer内での再入などを固定
- P1investigation: Rust VM 実装の棚卸し + LLVM harness の現状差分を記録
- P2smoke: weakref の最小 fixture/smoke を VM/可能ならLLVM で固定
- 参考(現状の入口候補):
- weakref 表現: `src/value.rs``NyashValue::WeakBox`
- finalization: `src/finalization.rs`
- **Phase 286planned, design-first: JoinIR Line AbsorptionJoinIR→CorePlan/Frag 収束)**
- 目的: 移行期間に残っている「2本の loweringPlan line / JoinIR line」を、構造で 1 本に収束させる
- ねらい: `return/break/continue` のような “大きな出口語彙” の実装場所が揺れない状態にする
- 入口: `docs/development/current/main/phases/phase-286/README.md`
- P0docs-only: `docs/development/current/main/phases/phase-286/P0-INSTRUCTIONS.md`
- SSOT:
- Plan/Frag: `compose::*` + `emit_frag()`Phase 280/281
- JoinIR line 共通入口: `src/mir/builder/control_flow/joinir/patterns/conversion_pipeline.rs`
- (✅ done**Phase 282**: Router shrinkage + detection SSOT + extractor refactor
- 完了: `docs/development/current/main/phases/phase-282/README.md`