Phase 131-3 完了: MIR→LLVM lowering 棚卸し テスト結果マトリックス: - Case A (phase87_llvm_exe_min.hako): ✅ PASS (baseline) - Case B (loop_min_while.hako): ❌ TAG-EMIT (PHI after terminator) - Case B2 (print(42) simple): ✅ PASS (BoxCall works) - Case C (llvm_stage3_loop_only.hako): ❌ TAG-EMIT (JoinIR pattern gap) Critical Bugs: 1. Bug #1: PHI After Terminator (Case B) - 原因: function_lower.py が terminator を PHI より先に emit - 修正: 4-pass block emission (2-3h) 2. Bug #2: JoinIR Pattern Gap (Case C) - 原因: loop(true) { break } パターンが JoinIR 未対応 - 修正: Pattern 5 設計・実装 (3-4h) Next Actions: - P1 (推奨): PHI ordering 修正 → 80% のループを有効化 - P2: JoinIR Pattern 5 → infinite loop 対応 ドキュメント: - phase131-3-llvm-lowering-inventory.md: 詳細棚卸し結果 - phase87-selfhost-llvm-exe-line.md: LLVM IR parsing error 追記 - CURRENT_TASK.md: phase131-3 参照追加 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
105 lines
6.3 KiB
Markdown
105 lines
6.3 KiB
Markdown
# Self Current Task — Now (main)
|
||
|
||
## 2025‑12‑14:現状サマリ
|
||
|
||
### JoinIR / Loop / If ライン
|
||
|
||
- LoopBuilder は Phase 186‑187 で完全削除済み。**JoinIR が唯一の loop lowering 経路**。
|
||
- LoopPattern 系は Pattern1–4 まで実装・本線化済み:
|
||
- Pattern1: Simple While
|
||
- Pattern2: Loop with Break
|
||
- Pattern3: Loop with If‑Else PHI(break/continue なし)
|
||
- Pattern4: Loop with Continue(multi‑carrier 対応)
|
||
- 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 86–90(Loop frontends)まとめ(1枚):
|
||
- `docs/development/current/main/phase86-90-loop-frontends-summary.md`
|
||
|
||
### Phase 86–90: Loop frontends(要約)
|
||
|
||
- Phase 86–90 は “dev-only fixtures + shape guard + fail-fast” で段階的に固定済み。
|
||
- 具体の fixture / shape / 未検証は `docs/development/current/main/phase86-90-loop-frontends-summary.md` を SSOT とする。
|
||
|
||
### Scope / BindingId(dev-only の段階移行ライン)
|
||
|
||
- MIR builder 側で lexical scope / shadowing を実在化し、言語仕様の “local はブロック境界で分離” を SSOT に揃えた。
|
||
- JoinIR lowering 側は name-based から BindingId-based へ段階移行中:
|
||
- `ScopeManager.lookup_with_binding()` / `ConditionEnv.binding_id_map` を導入し、shadowing を壊さずに解決できる足場を作った。
|
||
- promoted carriers(DigitPos/Trim)については `BindingId(original) → BindingId(promoted) → ValueId(join)` の鎖を dev-only で整備中。
|
||
- Phase 86 で `carrier_init_builder` / `error_tags` を SSOT 化し、段階移行ラインの基盤(ValueId 生成とエラー語彙)が確立した。
|
||
- これにより、BindingId dual-path の拡張・統合時に「生成」と「表示」の責務が混ざらない構造が固定された。
|
||
- Phase 81 で Pattern2(DigitPos/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 depth‑2 ライン
|
||
|
||
- `selfhost_build.sh --json` で Program JSON v0 emit は安定。
|
||
`.hako` 側から env 経由で JSON を読む最小ループ(`program_read_min.hako`)は動作確認済み。
|
||
- JsonParserBox / BundleResolver のループ 21 本のうち:
|
||
- 18 本は Pattern1–4 で JoinIR 対応済み(Phase 162–165)。
|
||
- `_trim` を含む一部の複合ループは、ValueId 境界や Box 登録など残課題あり。
|
||
- BoolExprLowerer / condition_to_joinir で OR/AND/NOT 付き条件式の lowering は実装完了(Phase 168–169)。
|
||
- 残課題(JsonParser/selfhost depth‑2):
|
||
- 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) で条件付き必須を制御。
|
||
- CoreServices(ring1‑core)として次を実装済み:
|
||
- StringService / IntegerService / BoolService
|
||
- ArrayService / MapService / ConsoleService
|
||
- PluginHost 統合 + UnifiedBoxRegistry からの自動初期化
|
||
- FileBox / FileHandleBox ライン:
|
||
- Ring0FsFileIo 経由で read / write / append / metadata 完全対応
|
||
- Default プロファイルでは必須、NoFs プロファイルでは disabled。
|
||
- Logging ライン:
|
||
- ConsoleService(user‑facing)
|
||
- Ring0.log(internal/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`
|
||
- LLVM(Python llvmlite)lowering の棚卸し(Phase 131-3):
|
||
- `docs/development/current/main/phase131-3-llvm-lowering-inventory.md`
|
||
- 現在の主要ブロッカー(要約): PHI の配置/順序で LLVM IR が invalid になるケース、JoinIR ループパターンの未対応ケース
|
||
|
||
---
|
||
|
||
## 2025‑09‑08:旧スナップショット(参考)
|
||
|
||
- LLVM 側 P0 完了(BitOps/Array/Echo/Map 緑)。VInvoke(by‑name/by‑id vector) は戻り値マッピングの暫定課題を確認中(Decisions 参照)。
|
||
- selfhosting-dev の作業を main に順次取り込み。VM/MIR 基盤は main で先に整える方針。
|
||
|
||
直近タスク(当時)
|
||
1) continue/break の lowering(Builder 修正のみで表現)
|
||
- ループ文脈スタック {head, exit} を導入。
|
||
- continue に遭遇 → head(または latch)へ br を emit し終端。
|
||
- break に遭遇 → exit へ br を emit し終端。
|
||
- post‑terminated 後に 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`
|