Files
hakorune/docs/development/current/main/phases/phase-285/P0-INSTRUCTIONS.md
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

2.2 KiB
Raw Blame History

Phase 285 P0docs-only: Box lifecycle / weakref / finalization / GC SSOT

目的: “実装が仕様” になっている Box の寿命・弱参照・最終化を、docs と smoke の SSOT に固定する。

1. このP0でやることコード変更なし

  1. 仕様SSOTを 1 ファイルにまとめる

    • docs/development/current/main/phases/phase-285/README.md を入口SSOTとして育てる。
  2. 用語と境界を固定する

    • strong/weak/roots/finalizer/collection の定義
    • weakref の APIupgrade/生存判定)
    • finalizer の禁止事項(再入・例外・順序)
  3. LLVM harness の扱いを明文化する

    • 未対応なら “未対応” を仕様として書く(差分を隠さない)。

2. README に必ず書く事項(チェックリスト)

  • “roots” は何かstack/local/global/handle/plugin 等)
  • strong/weak の意味upgrade の成否条件)
  • finalizer はあるか/いつ発火するか/何が禁止か
  • GC/解放のトリガ(自動/手動/閾値/テスト用)
  • VM と LLVM harness の差分(未対応の場合の方針)

3. 次P1/P2への導線箇条書きでOK

  • P1investigation: 棚卸し対象のファイル一覧と観測ポイント
  • P2smoke: fixture の仕様stdout/exitと LLVM 側の扱いPASS/SKIP

4. P1 調査チェックリスト(提案)

Rust VMSSOT

  • src/value.rs
    • NyashValue::WeakBox の生成箇所weak をどう作るか)
    • upgrade() 失敗時の観測方法(文字列化/判定API
    • unit test: test_weak_reference_drop の仕様(何を固定しているか)
  • src/finalization.rs
    • finalizer の存在(あれば: 登録、呼び出しタイミング、順序)
    • 禁止事項(再入/例外/I/O/allocをどこでガードするか
  • src/box_trait.rs / src/scope_tracker.rs
    • Box の所有モデルArc/Weakの境界、roots の形成点)

LLVM harness差分を SSOT 化)

  • src/llvm_py/
    • weakref/finalizer の相当機能があるか(まず “無いなら無い” を明文化)
    • 未対応の場合は smoke を SKIP にし、理由をログで固定する方針