Files
hakorune/docs/development/current/main/10-Now.md

138 lines
8.3 KiB
Markdown
Raw Normal View History

# Self Current Task — Now (main)
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
## 20251215Phase 132 完了 ✅
**Phase 132: LLVM Exit PHI=0 根治修正 完了!**
- ループ exit PHI が 0 を返す問題を根治解決
- 原因2層: (1) JoinIR/Boundary が exit 値を境界に渡していない、(2) LLVM Python が PHI を落とす/上書きする
- 修正: Pattern 1 で exit 値を明示的に渡す + `predeclared_ret_phis` 使用 + `builder.vmap` の PHI 保護
- 結果: `/tmp/p1_return_i.hako` が 3 を返すVM 一致)
- 詳細: `investigations/phase132-llvm-exit-phi-wrong-result.md`
**追加Phase 132-P2: Case C の Exit PHI ValueId 衝突を修正**
- 原因: `exit_phi_builder.rs` が module-level allocator を使い、同一関数内で ValueId が衝突し得た
- 修正: `func.next_value_id()`function-levelへ統一`bd07b7f4`
- 結果: `apps/tests/llvm_stage3_loop_only.hako` が LLVM EXE でも `Result: 3`VM 一致)
- 詳細: `investigations/phase132-case-c-llvm-exe.md`
2025-12-15 06:08:19 +09:00
**追加Phase 132-P3: Exit PHI collision の早期検出debug-only**
- `verify_exit_phi_no_collision()``contract_checks.rs` に追加し、ValueId 衝突を JoinIR merge の段階で Fail-Fast する
2025-12-15 18:49:08 +09:00
## 20251215Phase 133135短報
- Phase 133: promoted carrierTrim`join_id` 解決を SSOT に寄せて修正smoke は compile-only
- Phase 134: plugin loader best-effort loading を導入(決定的順序 + failure 集約 + 継続)。
- Phase 135: ConditionLoweringBox が allocator SSOT を無視して ValueId 衝突を起こす問題を根治。
- 詳細: `docs/development/current/main/phases/phase-135/README.md`
## 20251214現状サマリ
補足docs が増えて迷子になったときの「置き場所ルールSSOT」:
- `docs/development/current/main/DOCS_LAYOUT.md`
### JoinIR / Loop / If ライン
- LoopBuilder は Phase 186187 で完全削除済み。**JoinIR が唯一の loop lowering 経路**。
- LoopPattern 系は Pattern14 まで実装・本線化済み:
- Pattern1: Simple While
- Pattern2: Loop with Break
- Pattern3: Loop with IfElse PHIbreak/continue なし)
- Pattern4: Loop with Continuemulticarrier 対応)
- Exit/Carrier/Boundary ラインは次の箱で SSOT 化:
- `CarrierInfo` / `ExitMeta` / `ExitBindingBuilder`
- `JoinInlineBoundary` + `LoopExitBinding`
- If lowering は IfSelectLowerer/IfMergeLowerer を中心に整理済み。Select/PHI の扱いも Phase 189 系で橋渡し済み。
- 残課題JoinIR ライン):
- JoinIR→MIR merge の一般化(複雑な Select/PHI パターンの統合)
- JsonParserBox など実アプリ側での長期運用テスト
- Phase 8690Loop frontendsまとめ1枚:
- `docs/development/current/main/phase86-90-loop-frontends-summary.md`
### Phase 8690: Loop frontends要約
- Phase 8690 は “dev-only fixtures + shape guard + fail-fast” で段階的に固定済み。
- 具体の fixture / shape / 未検証は `docs/development/current/main/phase86-90-loop-frontends-summary.md` を SSOT とする。
### Scope / BindingIddev-only の段階移行ライン)
- MIR builder 側で lexical scope / shadowing を実在化し、言語仕様の “local はブロック境界で分離” を SSOT に揃えた。
- JoinIR lowering 側は name-based から BindingId-based へ段階移行中:
- `ScopeManager.lookup_with_binding()` / `ConditionEnv.binding_id_map` を導入し、shadowing を壊さずに解決できる足場を作った。
- promoted carriersDigitPos/Trimについては `BindingId(original) → BindingId(promoted) → ValueId(join)` の鎖を dev-only で整備中。
- Phase 86 で `carrier_init_builder` / `error_tags` を SSOT 化し、段階移行ラインの基盤ValueId 生成とエラー語彙)が確立した。
- これにより、BindingId dual-path の拡張・統合時に「生成」と「表示」の責務が混ざらない構造が固定された。
- Phase 81 で Pattern2DigitPos/Trimの ExitLine 契約ConditionOnly を exit PHI から除外、LoopState のみを reconnectを E2E で固定した。
- 参照:
- `docs/development/current/main/phase73-scope-manager-design.md`
- `docs/development/current/main/phase78-bindingid-promoted-carriers.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`
### JsonParser / Selfhost depth2 ライン
- `selfhost_build.sh --json` で Program JSON v0 emit は安定。
`.hako` 側から env 経由で JSON を読む最小ループ(`program_read_min.hako`)は動作確認済み。
- JsonParserBox / BundleResolver のループ 21 本のうち:
- 18 本は Pattern14 で JoinIR 対応済みPhase 162165
- `_trim` を含む一部の複合ループは、ValueId 境界や Box 登録など残課題あり。
- BoolExprLowerer / condition_to_joinir で OR/AND/NOT 付き条件式の lowering は実装完了Phase 168169
- 残課題JsonParser/selfhost depth2
- JoinIR→MIR ValueId boundary の完全一般化(条件用 ValueId を含める)
- JsonParserBox の using / Box 登録Rust VM 側での認識)
- Program JSON v0 を JsonParserBox 経由でフル解析する line の仕上げ
### Ring0 / Runtime / CoreServices ライン
- Ring0Context + Ring0Registry で OS API 抽象化レイヤ完成:
- MemApi / IoApi / TimeApi / LogApi / FsApi / ThreadApi
- RuntimeProfile(Default / NoFs) で条件付き必須を制御。
- CoreServicesring1coreとして次を実装済み
- StringService / IntegerService / BoolService
- ArrayService / MapService / ConsoleService
- PluginHost 統合 + UnifiedBoxRegistry からの自動初期化
- FileBox / FileHandleBox ライン:
- Ring0FsFileIo 経由で read / write / append / metadata 完全対応
- Default プロファイルでは必須、NoFs プロファイルでは disabled。
- Logging ライン:
- ConsoleServiceuserfacing
- Ring0.loginternal/dev
- println!test 専用)
の 3 層が `logging_policy.md` で整理済み。JoinIR/Loop trace も同ドキュメントに集約。
- VM backend の Box 解決UnifiedBoxRegistry / BoxFactoryRegistryの経路図:
- `docs/development/current/main/phase131-2-box-resolution-map.md`
- LLVMPython llvmlitelowering の棚卸しPhase 131-3..10:
- `docs/development/current/main/phase131-3-llvm-lowering-inventory.md`
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
- 状態: Case BPattern1/loop_min_whileは EMIT/LINK/RUN まで復旧済み。Phase 132 で `return i` の VM/LLVM parity を固定。
- Case C は別途 “Case C docs” を SSOT にして追跡する(状況は更新されるので、この箇所では断定しない)
- Case C の調査と実装計画:
- `docs/development/current/main/phase131-11-case-c-summary.md`
- `docs/development/current/main/case-c-infinite-loop-analysis.md`
---
## 20250908旧スナップショット参考
- LLVM 側 P0 完了BitOps/Array/Echo/Map 緑。VInvoke(byname/byid vector) は戻り値マッピングの暫定課題を確認中Decisions 参照)。
- selfhosting-dev の作業を main に順次取り込み。VM/MIR 基盤は main で先に整える方針。
直近タスク(当時)
1) continue/break の loweringBuilder 修正のみで表現)
- ループ文脈スタック {head, exit} を導入。
- continue に遭遇 → headまたは latchへ br を emit し終端。
- break に遭遇 → exit へ br を emit し終端。
- postterminated 後に emit しない制御を徹底。
2) ループ CFG の厳密化
- 単一 exit ブロックの徹底。
- Phi はヘッダでキャリー変数を合流SSA/支配関係が崩れない形)。
3) 検証とスモーク
- Verifier 緑dominance/SSA
- VM のループ代表(単純/ネスト/早期継続・脱出)。
- LLVM/Cranelift EXE に綺麗に降りるbr/phi ベースで問題なし)。
代表コマンド(例)
- ビルド: `cargo build --release`
- LLVM smoke: `LLVM_SYS_180_PREFIX=$(llvm-config-18 --prefix) NYASH_LLVM_BITOPS_SMOKE=1 ./tools/llvm_smoke.sh release`
- VInvoke 調査: `NYASH_LLVM_VINVOKE_TRACE=1 NYASH_LLVM_VINVOKE_SMOKE=1 ./tools/llvm_smoke.sh release`