Files
hakorune/CURRENT_TASK.md
nyash-codex 447d4ea246 feat(llvm): Phase 132 - Pattern 1 exit value parity fix + Box-First refactoring
## Phase 132: Exit PHI Value Parity Fix

### Problem
Pattern 1 (Simple While) returned 0 instead of final loop variable value (3)
- VM: RC: 3  (correct)
- LLVM: Result: 0  (wrong)

### Root Cause (Two Layers)
1. **JoinIR/Boundary**: Missing exit_bindings → ExitLineReconnector not firing
2. **LLVM Python**: block_end_values snapshot dropping PHI values

### Fix
**JoinIR** (simple_while_minimal.rs):
- Jump(k_exit, [i_param]) passes exit value

**Boundary** (pattern1_minimal.rs):
- Added LoopExitBinding with carrier_name="i", role=LoopState
- Enables ExitLineReconnector to update variable_map

**LLVM** (block_lower.py):
- Use predeclared_ret_phis for reliable PHI filtering
- Protect builder.vmap PHIs from overwrites (SSOT principle)

### Result
-  VM: RC: 3
-  LLVM: Result: 3
-  VM/LLVM parity achieved

## Phase 132-Post: Box-First Refactoring

### Rust Side
**JoinModule::require_function()** (mod.rs):
- Encapsulate function search logic
- 10 lines → 1 line (90% reduction)
- Reusable for Pattern 2-5

### Python Side
**PhiManager Box** (phi_manager.py - new):
- Centralized PHI lifecycle management
- 47 lines → 8 lines (83% reduction)
- SSOT: builder.vmap owns PHIs
- Fail-Fast: No silent overwrites

**Integration**:
- LLVMBuilder: Added phi_manager
- block_lower.py: Delegated to PhiManager
- tagging.py: Register PHIs with manager

### Documentation
**New Files**:
- docs/development/architecture/exit-phi-design.md
- docs/development/current/main/investigations/phase132-llvm-exit-phi-wrong-result.md
- docs/development/current/main/phases/phase-132/

**Updated**:
- docs/development/current/main/10-Now.md
- docs/development/current/main/phase131-3-llvm-lowering-inventory.md

### Design Principles
- Box-First: Logic encapsulated in classes/methods
- SSOT: Single Source of Truth (builder.vmap for PHIs)
- Fail-Fast: Early explicit failures, no fallbacks
- Separation of Concerns: 3-layer architecture

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-15 03:17:31 +09:00

5.6 KiB
Raw Blame History

Current Task

このファイルは「いま何に集中しているか」と「次にやり得る候補」だけを書く軽量ビューだよ。
詳細は docs/development/current/main/ 以下の各 Phase 文書と、JoinIR の SSOT である
docs/development/current/main/joinir-architecture-overview.md を参照してね。

最終更新: 2025-12-15

過去ログ(肥大化した旧 CURRENT_TASKはここに退避したよ:

  • docs/development/current/main/CURRENT_TASK_ARCHIVE_2025-12-13.md

今の状態Phase 7490 まで到達)

  • Scope/BindingId の段階移行dev-onlyは Pattern2/3/4 まで配線済みdual-path 維持)。
  • Pattern2 の promoted carriersDigitPos/Trimについて ExitLine 契約ConditionOnly を exit PHI から除外)を E2E で固定済み。
  • debug flag SSOT / DebugOutputBox 移行 / error tags 集約 / carrier init builder まで整備済み。
  • LLVM exe line SSOT 確立: tools/build_llvm.sh を使用した .hako → executable パイプライン標準化完了。
  • LLVM AOTPython llvmliteループ復旧: apps/tests/loop_min_while.hako が EMIT/LINK/RUN まで到達Phase 131-3..10)。
    • Case Cloop(true) + break/continueは Phase 131-11 で Pattern/shape guard の基盤まで到達。残りは Case C の parity/仕上げSSOT を見ながら詰める)。
  • Phase 132 完了: Pattern 1Simple Whilereturn i が VM/LLVM で一致3 を返す)まで根治。
    • JoinIR/Boundary: exit 値を境界に明示的に渡す
    • LLVM Python: PHI を落とす/上書きする経路を除去PHI SSOT を保護)
  • Phase 88 完了: continue + 可変ステップi=i+const 差分)を dev-only fixture で固定、StepCalculator Box 抽出。
  • Phase 89 完了: P0ContinueReturn detector+ P1lowering 実装)完了。
  • Phase 90 完了: ParseStringComposite + Null literal + ContinueReturn同一値の複数 return-ifを dev-only fixture で固定。
  • cargo test --release --lib は PASS を維持993 passed、退行なし

参照:

  • docs/development/current/main/10-Now.md
  • docs/development/current/main/phase86-90-loop-frontends-summary.md
  • docs/development/current/main/phase73-scope-manager-design.md
  • docs/development/current/main/phase80-bindingid-p3p4-plan.md
  • docs/development/current/main/phase81-pattern2-exitline-contract.md
  • docs/development/current/main/phase78-85-boxification-feedback.md
  • docs/development/current/main/phase87-selfhost-llvm-exe-line.md
  • docs/development/current/main/phase131-2-box-resolution-map.md
  • docs/development/current/main/phase131-3-llvm-lowering-inventory.md
  • docs/development/current/main/phase131-5-taglink-fix-summary.md
  • docs/development/current/main/phases/phase-132/README.md
  • docs/development/current/main/investigations/phase132-llvm-exit-phi-wrong-result.md

次の指示書(優先順位)

P0: Docs 整備(数の増殖を止める)

目的: SSOT への集約と導線整備Phase 8690 の情報が散らばらない状態にする)

やること:

  1. Phase 8690 の要約を 1 ファイルに集約SSOT
    • docs/development/current/main/phase86-90-loop-frontends-summary.md
  2. INDEX から要約へ導線を追加(迷子対策)
    • docs/development/current/main/01-JoinIR-Selfhost-INDEX.md
  3. 10-Now.md / CURRENT_TASK.md の断定・重複を “要約へのリンク” に寄せる

受け入れ基準:

  • 読み始め導線が 01-JoinIR-Selfhost-INDEX.md から辿れる
  • 10-Now.mdCURRENT_TASK.md は “最新の入口” として機能する(詳細は要約へ)

P1: Loop Canonicalizer の設計(設計待ち - 外部検討中)

状態: 🔶 設計中ChatGPT Pro と詰めている)

目的: ループ形状の組み合わせ爆発を抑えるための "前処理パス" を設計し、SSOT を定める

次に触るSSO:

  • Loop系の設計: docs/development/current/main/joinir-architecture-overview.md

注意:

  • 実装は急がず、設計SSOTを先に固める
  • 既定挙動は変えないdev-only で段階投入する)

P2: JoinIR / Selfhost depth-2 の前進(実装可能 - Phase 91 候補)

状態: 実装可能

目的:

  • JsonParserBox の残り複合ループを JoinIR 対応する。
  • または selfhost .hako コンパイラの他部分Lexer/ASTBuilder 等)で JoinIR 適用範囲を拡大する。

次に触るSSOT:

  • Loop系: docs/development/current/main/joinir-architecture-overview.md
  • VM Box系: docs/development/current/main/phase131-2-box-resolution-map.md

やること(設計→実装の順):

  1. 候補ループの抽出JsonParserBox or Lexer/ASTBuilder
  2. Pattern 判定Pattern 1-4 のいずれか、または新 Pattern 提案)
  3. JoinIR lowering 実装 + E2E テスト

受け入れ基準:

  • 代表ケースが 1 コマンドで再現可能CI は増やさない、quick を重くしない)。

P3: Ownership/Relay runtime 対応の再開Phase 92 候補)

目的:

  • multihop/merge relay を “runtime でも” 受理できるところまで契約を伸ばすFail-Fast の段階解除)。

受け入れ基準:

  • dev-only 既定OFF のまま、既存ラインを壊さない。

Done: Phase 8690Loop frontends

  • まとめSSOT: docs/development/current/main/phase86-90-loop-frontends-summary.md

すぐ走らせる確認コマンド

  • cargo test --release --lib
  • NYASH_JOINIR_NORMALIZED_DEV_RUN=1 cargo test --features normalized_dev --test normalized_joinir_min -- --nocapture