## Summary
Eliminates remaining `value_gen.next()` calls from function-context code paths,
unifying all ValueId allocation through `MirBuilder::next_value_id()` SSOT allocator.
## Changes
### 1. Fixed `new_typed_value()` (src/mir/builder.rs:1068)
**Before**: `let id = self.value_gen.next();` (bypasses function context)
**After**: `let id = self.next_value_id();` (respects function context)
This is a public API used in function context, so must use SSOT allocator
to avoid collisions with reserved PHI dsts and function params.
### 2. Fixed test code (src/mir/builder.rs)
**test_shadowing_binding_restore** (lines 1161, 1171):
- Simulates function scope with `push_lexical_scope()`
- Changed to `builder.next_value_id()` for function scope simulation
**test_valueid_binding_parallel_allocation** (lines 1196-1216):
- Tests ValueId/BindingId independence
- Changed to `builder.next_value_id()` with note that Module context fallback preserves test intent
### 3. Verified Module context fallbacks (OK, no change needed)
These already check `current_function.is_some()` and use `value_gen.next()` only as Module context fallback:
- `src/mir/builder/utils.rs:43` - next_value_id() SSOT implementation
- `src/mir/builder/utils.rs:436` - pin_to_slot()
- `src/mir/builder/utils.rs:467` - materialize_local()
- `src/mir/utils/phi_helpers.rs:69` - insert_phi_unified()
## Verification
```bash
rg -n "value_gen\.next\(" src/mir --type rust | grep -v "Module context" | grep -v "//"
# Result: Only comments/docs remain
```
## Acceptance
✅ cargo test --release --lib - 997 passed
✅ phase135_trim_mir_verify.sh - PASS
✅ phase132_exit_phi_parity.sh - 3/3 PASS
✅ All function-context `value_gen.next()` eliminated
## Effect
- **Collision prevention**: No more ValueId collisions between function-level allocations and reserved PHI dsts
- **SSOT compliance**: All ValueId allocation flows through single allocator
- **Contract enforcement**: Phase 135 P1 contract_checks will catch violations immediately
🤖 Generated with Claude Code
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
6.9 KiB
6.9 KiB
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 74–90 まで到達)
- Scope/BindingId の段階移行(dev-only)は Pattern2/3/4 まで配線済み(dual-path 維持)。
- Pattern2 の promoted carriers(DigitPos/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 AOT(Python llvmlite)ループ復旧:
apps/tests/loop_min_while.hakoが EMIT/LINK/RUN まで到達(Phase 131-3..10)。- Case C(
loop(true)+ break/continue)は Phase 131-11 で Pattern/shape guard を整備し、Phase 132-P2 で LLVM EXE まで parity(Result: 3)を確認。
- Case C(
- Phase 132 完了: ループ exit 値(exit PHI / boundary)の VM/LLVM parity を根治。
- JoinIR/Boundary: exit 値を境界に明示的に渡す
- LLVM Python: PHI を落とす/上書きする経路を除去(PHI SSOT を保護)
- JoinIR merge: exit PHI dst の allocator を function-level に統一(ValueId 衝突を排除)
- debug-only: Exit PHI collision を早期検出する verifier を追加(LLVM 実行時に壊れる前に Fail-Fast)
- Phase 133 完了: Promoted carrier の
join_id解決(Trim)を SSOT に寄せて根治(smoke は compile-only)。 - Phase 134 完了: Plugin loader best-effort loading(決定的順序 + failure 集約 + 継続)を導入。
- Phase 135 完了: ConditionLoweringBox allocator SSOT(P0: 根治修正 + P1: contract_checks Fail-Fast 強化)。
- Phase 136 完了: ValueId allocator SSOT 徹底(関数内経路から
value_gen.next()掃討完了)。 - Phase 88 完了: continue + 可変ステップ(i=i+const 差分)を dev-only fixture で固定、StepCalculator Box 抽出。
- Phase 89 完了: P0(ContinueReturn detector)+ P1(lowering 実装)完了。
- Phase 90 完了: ParseStringComposite +
Nullliteral + ContinueReturn(同一値の複数 return-if)を dev-only fixture で固定。 cargo test --release --libは PASS を維持(993 passed、退行なし)。
参照:
docs/development/current/main/10-Now.mddocs/development/current/main/phase86-90-loop-frontends-summary.mddocs/development/current/main/phase73-scope-manager-design.mddocs/development/current/main/phase80-bindingid-p3p4-plan.mddocs/development/current/main/phase81-pattern2-exitline-contract.mddocs/development/current/main/phase78-85-boxification-feedback.mddocs/development/current/main/phase87-selfhost-llvm-exe-line.mddocs/development/current/main/phase131-2-box-resolution-map.mddocs/development/current/main/phase131-3-llvm-lowering-inventory.mddocs/development/current/main/phase131-5-taglink-fix-summary.mddocs/development/current/main/phases/phase-132/README.mddocs/development/current/main/investigations/phase132-llvm-exit-phi-wrong-result.mddocs/development/current/main/investigations/phase132-case-c-llvm-exe.md
次の指示書(優先順位)
P0: Phase 135 検証(Trim fixture の --verify を緑に固定)
目的:
apps/tests/phase133_json_skip_whitespace_min.hakoで発生していた MIR SSA 破綻(ValueId 重複)を後戻りしない形で固定する。
やること:
./target/release/hakorune --verify apps/tests/phase133_json_skip_whitespace_min.hakoが PASS することを確認- 必要なら integration smoke を追加(quick は増やさない)
- Phase 文書を更新:
docs/development/current/main/phases/phase-135/README.md
受け入れ基準:
--verifyが PASS- 既存の Phase 132/133/134 の integration smoke が退行しない
P1: Docs 整備(数の増殖を止める)
目的: SSOT への集約と導線整備(Phase 86–90 の情報が散らばらない状態にする)
やること:
- Phase 86–90 の要約を 1 ファイルに集約(SSOT)
docs/development/current/main/phase86-90-loop-frontends-summary.md
- INDEX から要約へ導線を追加(迷子対策)
docs/development/current/main/01-JoinIR-Selfhost-INDEX.md
10-Now.md/CURRENT_TASK.mdの断定・重複を “要約へのリンク” に寄せる
受け入れ基準:
- 読み始め導線が
01-JoinIR-Selfhost-INDEX.mdから辿れる 10-Now.mdとCURRENT_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
やること(設計→実装の順):
- 候補ループの抽出(JsonParserBox or Lexer/ASTBuilder)
- Pattern 判定(Pattern 1-4 のいずれか、または新 Pattern 提案)
- JoinIR lowering 実装 + E2E テスト
受け入れ基準:
- 代表ケースが 1 コマンドで再現可能(CI は増やさない、quick を重くしない)。
P3: Ownership/Relay runtime 対応の再開(Phase 92 候補)
目的:
- multihop/merge relay を “runtime でも” 受理できるところまで契約を伸ばす(Fail-Fast の段階解除)。
受け入れ基準:
- dev-only 既定OFF のまま、既存ラインを壊さない。
Done: Phase 86–90(Loop frontends)
- まとめ(SSOT):
docs/development/current/main/phase86-90-loop-frontends-summary.md
すぐ走らせる確認コマンド
cargo test --release --libNYASH_JOINIR_NORMALIZED_DEV_RUN=1 cargo test --features normalized_dev --test normalized_joinir_min -- --nocapture