Files
hakorune/CURRENT_TASK.md

304 lines
23 KiB
Markdown
Raw Normal View History

# Current Task — JoinIR / PHI 削減スナップショット2025-11-29 時点)
> このファイルは「今どこまで終わっていて、次に何をやるか」を 1000 行以内でざっくり把握するためのスナップショットだよ。
> 過去の詳細ログは `docs/private/roadmap2/CURRENT_TASK_2025-11-29_full.md` や各 Phase の README/TASKS を見てね。
---
## 0. 現在地ざっくり
- **最終ゴール**
- 制御構造と PHI の意味論は **JoinIRLoopScopeShape/IfPhiContext 等の薄い箱)** に一本化する。
- 実行の SSOT は VM / LLVM ラインとし、JoinIR→MIR→VM/LLVM は「構造 SSOT → 実行 SSOT」への変換として扱う。
- 既存の PHI 箱if_phi.rs / PhiBuilderBox / conservative.rs / Trio 等は、JoinIR 側のカバレッジが十分になったところから順に削っていく。
- **JoinIR ライン**
- Phase 2731: Loop→JoinIR loweringskip_ws / trim / append_defs / Stage1 minimalで、ループの制御構造を関数継続だけで表現できることを実証済み。
- Phase 3334: IfSelect / IfMerge / JoinIR FrontendIf/Loop/Break/Continue実装。AST→JoinIR→MIR→VM まで tiny ケースが通る。
- **PHI 削減ライン**
- Phase 3536: HIGH/MEDIUM 安全度の PHI 箱if_body_local_merge / phi_invariants / LoopSnapshotMergeBoxの削除・縮退で 537 行削減。
- Phase 3740: If 側 PHIif_phi.rs / conservative.rsの Level 1/2 相当まで設計一部削減。array_ext.filter については JoinIR Frontend + JoinFuncMeta に移行し、collect_assigned_vars を削除済み。
- **これから**
- Phase 41: If 側 PHI Level 3本体ロジックの代表ケースを JoinIR 経路に載せる設計と最初の実装。
- 以降: If 側 PHI 本体削減 → Classifier Trio → AST→JoinIR Frontend 本線化 → LLVM / ny-llvmc の JoinIR 統合。
---
## 1. 最近の主戦場Phase 3341
### 1-00a. Phase 33 — IfSelect / IfMerge + PHI 設計原則
- IfSelect / IfMerge lowering 実装simple/local, 23 変数パターン)。
- VM ラインへの If lowering ドライランを `IfLoweringDryRunner` に箱化し、VM パイプラインと解析ロジックを分離。
- 「JoinIR は PHI 生成器SSOT、既存 PHI の変換器にはしない」原則をコードdocs で固定。
- docs: `docs/private/roadmap2/phases/phase-33-joinir-if-phi-cleanup/if_joinir_design.md`
### 1-00b. Phase 34 — JoinIR FrontendAST→JoinIR
- 目的: ASTProgram JSON v0→ JoinIR Frontend を設計・実装し、「PHI 意味論の SSOT を JoinIR 側に寄せる」。
- 実績:
- If: simple/local/json_shape パターンを Select に正規化(同じ JoinIR 出力)。
- Loop: tiny while / break / continue を 3 関数構造entry/loop_step/k_exit Jump/Call/Select で表現。
- MethodCall: substring などを JoinInst::MethodCall として構造化し、JoinIR→MIR Bridge で BoxCall に変換。
- docs: `docs/private/roadmap2/phases/phase-34-joinir-frontend/README.md`
### 1-00c. Phase 3536 — PHI 箱削減HIGH/MEDIUM
- Phase 35HIGH:
- `if_body_local_merge.rs` / `phi_invariants.rs` 削除(合計 430 行)。
- PHI_BOX_INVENTORY.md で PHI 箱の一覧と削除順を整理。
- Phase 36MEDIUM:
- LoopSnapshotMergeBox を「Exit PHI マージ専用の純粋静的ユーティリティ」に縮退470→363 行)。
- PhiBuilderBox に Loop/If/Common/Stub の責務マーカー追加(実装本体削減は Phase 38+)。
- docs:
- `docs/private/roadmap2/phases/phi-reduction-series/INDEX.md`
- `docs/private/roadmap2/phases/phase-36-phi-midrange/README.md`
### 1-00d. Phase 3739 — If 側 PHI Level 1/2 設計と準備
- Phase 37: If 側 PHI 全体設計docs-only
- if_phi.rs / conservative.rs の責務表、12 callsite の難易度分類。
- 削除基準Level 1/2/3の定義。
- Phase 38: if_phi.rs Level 1 削除90 行)。
- `merge_modified_with_control`dead code`extract_assigned_var`JoinIR AST lowering で代替)を削除。
- Phase 39: Level 2 準備array_ext.filter 選定と JoinIR 拡張設計)。
- array_ext.filter を代表 if-in-loop パターンに選定。
- JoinIR Frontend / JoinFuncMeta / Bridge 拡張と削除条件を設計。
- docs:
- `docs/private/roadmap2/phases/phase-37-if-phi-reduction/README.md`
- `docs/private/roadmap2/phases/phase-38-if-phi-level1/README.md`
- `docs/private/roadmap2/phases/phase-39-if-phi-level2/README.md`
### 1-00e. Phase 40 — If 側 PHI Level 2 実装array_ext.filter
- 目的: array_ext.filter の ifinloop PHI を JoinIR Frontend + JoinFuncMeta + Bridge 経由に移し、collect_assigned_vars を削除する。
- 実績:
- JoinFuncMeta / JoinFuncMetaMap / convert_join_module_to_mir_with_meta 実装。
- AST→JoinIR Frontend で ifinloop の modified 変数集合を解析し、JoinIR→MIR Bridge で PHI 生成。
- loop_builder.rs に HAKO_JOINIR_ARRAY_FILTER 経路を追加し、Route BJoinIR 経路)をデフォルト化。
- `collect_assigned_vars` を削除し、JSON ベースの `collect_assigned_vars_via_joinir` に置き換えPhase 40-4.1)。
- デッドな env フラグ等をクリーンアップ40-4.1.1)。
- 削減実績Phase 40 時点):
- 35 行collect_assigned_vars16 行(デッドコード)= 51 行純減。
- docs:
- `docs/private/roadmap2/phases/phase-40-if-phi-level2/README.md`
- `docs/private/roadmap2/phases/phi-reduction-series/INDEX.md`
### 1-00f. Phase 41 — If-Side PHI Level 3 Reduction ✅ 完了2025-11-28
- 目的:
- if_phi.rs / conservative.rs に残る「Level 3 本体ロジック」を JoinIR 経路に移すための設計と代表ケース実装。
- 実績:
- Level 3 関数の再インベントリとデッドコード 147 行削除。
- 代表 If 関数として `ParserControlBox.parse_loop()` を選定。
- NestedIfMerge JoinInst 設計実装mod.rs, json.rs
- AST→JoinIR Frontend に `lower_nested_if_pattern()` 追加dev flag: `HAKO_JOINIR_NESTED_IF=1`)。
- JoinIR→MIR Bridge に NestedIfMerge 展開ロジック追加(多段 Branch + Copy
- Route BNestedIfMerge 経由)の A/B テスト 7 ケース全 PASSparse_loop 代表ケース)。
- 実削除if_phi.rs / conservative.rs 本体の縮退・削除)は Phase 42 に繰り越し。
- docs:
- `docs/private/roadmap2/phases/phase-41-if-phi-level3/README.md`
- `docs/private/roadmap2/phases/phase-41-if-phi-level3/TASKS.md`
### 1-00g. Phase 45 — read_quoted_from JoinIR 実装 ✅ 完了2025-11-28
- 目的:
- `MiniJsonCur.read_quoted_from(s, pos)` を JoinIR Frontend/Bridge で実装し、Guard if + Loop with break + accumulator パターンの PHI 削減を実証。
- 実績:
- **45-1**: フィクスチャ `apps/tests/phase45_read_quoted_fixture.hako` 作成T1-T4 Route A で PASS
- **45-2**: AST→JoinIR Frontend `lower_read_quoted_pattern()` 実装(`ast_lowerer.rs`)。
- **45-3**: JoinIR→MIR Bridge 確認(既存 bridge で変更不要)。
- **45-4**: Route B E2E テスト `test_read_quoted_from_route_b_e2e()` 追加、T1-T4 全 PASS。
- **45-5**: PHI_BOX_INVENTORY.md / CURRENT_TASK.md 更新。
- 既知の制限:
- **T5エスケープ処理**: 変数再代入 inside if-block が PHI を生成しない問題 → **Phase 46 で解決済み**
- Dev Flag: `HAKO_JOINIR_READ_QUOTED=1`
- JoinIR 構造: entry → k_guard_fail / loop_step → k_exit4 関数構造)
- docs:
- `docs/private/roadmap2/phases/phase-30-final-joinir-world/PHI_BOX_INVENTORY.md` (Phase 45 セクション)
### 1-00h. Phase 46 — IfMerge 拡張(ループ内 if での変数再代入 PHI 問題)✅ 完了2025-11-28
- 目的:
- ループ内の `if (cond) { x = expr; }` パターンで、if-body での変数再代入が merge ブロックで PHI に反映されない問題を修正。
- 実績:
- **46-1**: 現状 MIR の問題点を CFG 図で固定T5 専用)。
- **46-2**: JoinIR レベルでの「正しい形」を IfMerge で設計Option A 採用)。
- **46-3**: `lower_read_quoted_pattern()` に IfMerge 拡張を設計・実装。
- **46-4**: Route B E2E テスト T1-T5 全 PASS。
- テスト結果:
- T1-T4: ✅ PASSPhase 45 と同じ)
- **T5エスケープ処理**: ✅ PASS`"a\"b"``a"b`
- Dev Flag: `HAKO_JOINIR_READ_QUOTED_IFMERGE=1`Phase 46 IfMerge 拡張有効化)
- 修正ファイル:
- `src/mir/join_ir/frontend/ast_lowerer.rs`: IfMerge による escape 処理追加
- `src/mir/join_ir_vm_bridge.rs`: T5 テストケース追加
- docs:
- `docs/private/roadmap2/phases/phase-46-ifmerge-loop-reassign/README.md`
### 1-00i. Phase 4956 — JoinIR Frontend 本線統合print_tokens / filter✅ 完了
feat(joinir): Phase 56 ArrayExtBox.filter JoinIR lowering完全実装 ## Summary ArrayExtBox.filter/2 の JoinIR Frontend lowering を完全実装し、 ConditionalMethodCall 命令を導入して filter パターンに対応。 56 JoinIR テスト全て PASS(退行なし)。 ## Technical Changes ### 1. ConditionalMethodCall 命令追加 - **新規命令**: `if pred(v) { acc.push(v) }` パターン用 - **構造**: cond が true なら method 実行、false なら no-op - **MIR 変換**: 4ブロック構造 (cond→then/else→merge) ### 2. AST JSON 拡張 - Break/Continue/FunctionCall に "type" フィールド追加 - ArrayLiteral/MapLiteral に "type" フィールド追加 - JoinIR Frontend 互換性向上 ### 3. Expression Handler 拡張 - Unary 演算子(not, 負号)サポート - Call(変数関数呼び出し)を MethodCall に変換 ### 4. Loop Pattern Binding 修正 - `BoundExpr::Variable("n")` 問題修正 - `MethodCall { receiver: "arr", method: "size" }` に変更 - external_refs (arr, pred) を step 関数に伝播 ### 5. If Statement Handler 拡張 - 条件付き側効果パターン(ケース4)追加 - MethodCall/Method 形式の statement を ConditionalMethodCall に変換 ## Files Modified (10 files, +456/-45 lines) - ast_json.rs: AST JSON "type" フィールド追加 - loop_frontend_binding.rs: n バインディング修正 - control_flow.rs: external_refs params 追加 - loop_patterns.rs: external_refs step 関数伝播 - expr.rs: Unary, Call handler 追加 - stmt_handlers.rs: ConditionalMethodCall パターン追加 - mod.rs: ConditionalMethodCall, UnaryOp 定義 - json.rs: ConditionalMethodCall, UnaryOp シリアライズ - join_ir_runner.rs: ConditionalMethodCall, UnaryOp スタブ - convert.rs: ConditionalMethodCall → MIR 変換 ## Test Results - 56 JoinIR tests: ✅ PASSED - Regression: ❌ None - ArrayExtBox.filter/2: ✅ JoinIR lowering 成功 ## Milestone JoinIR 2ループ完走達成: - ✅ JsonTokenizer.print_tokens/0 - ✅ ArrayExtBox.filter/2 (NEW!) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 06:51:43 +09:00
- Phase 4952: `cf_loop` に JoinIR Frontend ルートを追加しdev フラグ付き)、`LoopFrontendBinding` / JSON v0 / expr タイプField/NewBoxを整備。
- `HAKO_JOINIR_PRINT_TOKENS_MAIN` / `HAKO_JOINIR_ARRAY_FILTER_MAIN` で対象ループだけを Frontend 経由にルーティング。
- `merge_joinir_mir_blocks` で JoinIR→MIR のブロック/値 ID リマップと制御フロー接続を実装。
- Phase 5355: statement loweringLocal/Assignment/Print/Method/Ifと AST→JSON の `"type"`/`"expr"` 整備により、`JsonTokenizer.print_tokens/1` が JoinIR Frontend→Bridge→VM 経由で最後まで実行可能にRoute A/B 等価、dev フラグ ON 限定)。
- Phase 56: `ArrayExtBox.filter/2` 向けに `LoopFrontendBinding::for_array_filter` を MethodCall ベース(`arr.size()`)に修正し、外部参照 `arr/pred` を Binding 経由で渡す構造に統一。
- JoinIR に `ConditionalMethodCall` / Unary / Call を追加し、filter の「pred が true のときだけ push する」パターンを 4 ブロック構造で表現。
- `HAKO_JOINIR_ARRAY_FILTER_MAIN=1` で Route BJoinIR Frontend 経路)がフォールバックなし完走(テスト済み、既定は従来ルート)。
### 1-00j. Phase 5761 — If 側 PHI Level 3 本体conservative/if_phi 残り)✅ 仕上げ中
- Phase 57 では、新しい抽象を増やさずに既存の Conservative/IfPHI 本体のうち安全な部分を薄くした。
- `phi.rs` での冗長な `ConservativeMerge::analyze` 呼び出しを 2 回→1 回に削減し、軽量化。
- `PhiMergeOps` trait と loop_builder.rs 側の実装を完全削除し、Loop 側の PHI 生成責務を JoinIRLoopScopeShape 側に寄せた。
- `infer_type_from_phi` には「レガシー型推論箱であり、JoinIR 型情報導入後の削減候補」であることをコメントで明示し、将来の削除条件をドキュメント化。
- Phase 58 では ConservativeMerge 本体を `phi_merge.rs::merge_all_vars` にインライン化し、`conservative.rs` の多くをドキュメントコメント+最小限の補助関数だけに縮退。
- conservative.rs: 149 行 → 57 行(約 92 行削減、約 62% 削減)。
- ConservativeMerge struct 定義と付随テストコードを削除し、挙動差分がないことを phi_core / JoinIR テストで確認。
- Phase 61-1〜61-3 では If-in-loop 専用の箱化を進め、JoinIR 側に PHI 生成の SSOT を寄せた。
- IfPhiContext でループ内 If の CFG と変数スナップショットをまとめ、IfInLoopPhiEmitter で pre/then/else の snapshot と carrier 集合から必要な φ を構成する thin box を追加。
- dev フラグ `HAKO_JOINIR_IF_IN_LOOP_ENABLE=1` 有効時には、JoinIR パターンマッチ成功した if-in-loop について JoinIR + IfPhiContext + IfInLoopPhiEmitter 経路で PHI を生成できるようになったRoute A/B 互換、既定はまだ legacy
- Phase 61-4: **If Toplevel PHI (Fallthrough-Join) 実装** ✅ 完了2025-11-29
- ループ外 If の「then 直後に結合点がない」パターンtoplevel_returnを JoinIR で表現。
- IfInLoopPhiEmitter が IfPhiContext::pure_if() でループ外 If もサポート(統一インターフェース)。
- `toplevel_if_ret_explicit.hako` テストで toplevel_return パターン動作確認済み。
- docs: `docs/development/current/main/phase61-4-toplevel-if-design.md`
- Phase 61-5: **If PHI 削減計画策定** ✅ 完了2025-11-29
- 61-5.1: If PHI 関数リスト作成26関数、3カテゴリ
- 61-5.2: JoinIR カバレッジ調査in_loop/partial/none
- 61-5.3: 優先度表作成P1: 18関数、P2: 5関数、P3: 3関数
- 61-5.4: Phase 61-6 候補選定3個: set_if_context, dev フラグ, A/B テスト削除)
- docs: `docs/development/current/main/phase61-5-*.md`
- Phase P1: **If Handler 箱化モジュール化** ✅ 完了2025-11-29
- ループ内 If 処理の 5 パターンEmpty/SingleVarThen/SingleVarBoth/ConditionalEffect/Unsupported`IfInLoopPattern` enum で分類。
- `if_in_loop/` モジュール9 ファイル、~480 行)を新設し、`stmt_handlers.rs` から 154 行削減40% 削減達成)。
- 全 56 JoinIR tests PASS回帰なし、保守性・拡張性向上新パターン追加が容易に
- docs: `docs/development/refactoring/p1-if-handler-boxification-plan.md`
### 1-00g. Phase 61-6 — If PHI JoinIR 化 第2弾薄いラッパー削減
- 目的: If 側 PHI ラインから JoinIR と二重管理になっていた薄いラッパー観察専用ユーティリティを取り除き、PHI 仕様の SSOT を JoinIR 側に寄せる。
- 実績:
- `set_if_context` 薄いラッパーを削除し、callsite から直接 `IfPhiContext` を構築するよう統一。IfPhiContext の入口が一本化され、文脈箱IfPhiContextと emitter 箱IfInLoop/Toplevelの責務分離がより明確になった。
- PhiBuilderBox ベースの PhiSpec 観察用関数(`extract_phi_spec_from_builder`, `compare_and_log_phi_specs` などを削除し、PHI 仕様計算を JoinIR 起点の `compute_phi_spec_from_joinir` に一本化。
- 合計約 97 行削減(予想 76 行を超過。If 側 PHI の「観察・比較」は JoinIR 情報から復元する経路のみとなり、if_phi/PhiBuilderBox は本番ロジックに専念する構造に整理された。
feat(joinir): Phase 63-4 infer_type_from_phi degradation design Phase 63-4: infer_type_from_phi を『JoinIR 型ヒント優先+従来ロジックフォールバック』に縮退する仕様を設計(実装は Phase 63-5+) ## Changes ### Documentation Updates - **README.md**: Added complete Phase 63-4 design (63-4.1 through 63-4.5) - 63-4.1: Current state analysis (definition location, callsites, role, JoinIR preparation) - 63-4.2: Degradation spec (type_hint priority + fallback pattern) - 63-4.3: Representative cases and A/B testing strategy (P1/P2/P3) - 63-4.4: Deletion conditions (5 conditions, current: 2/5 = 40%) - 63-4.5: Phase 63-5 handoff (infer_type_from_phi_with_hint() implementation tasks) - **PHI_BOX_INVENTORY.md**: Updated if_phi.rs entry with Phase 63-4 deletion plan - Added: "Phase 63-4完了: infer_type_from_phi の JoinIR type_hint 優先への縮退案を設計(実装は Phase 63-5+)" - **CURRENT_TASK.md**: Added Phase 63-4 section with summary of design work ## Design Highlights ### Degradation Pattern ```rust pub fn infer_type_from_phi_with_hint( function: &MirFunction, ret_val: ValueId, types: &BTreeMap<ValueId, MirType>, type_hint: Option<MirType>, ) -> Option<MirType> { if let Some(hint) = type_hint { return Some(hint); // Route B: JoinIR priority (SSOT) } infer_type_from_phi(function, ret_val, types) // Route A: Fallback } ``` ### Representative Cases - **P1**: IfSelectTest.simple/local (Phase 63-5 target) - **P2**: read_quoted_from (Phase 63-6+ target) - **P3**: MethodCall/Box constructors (Phase 64+ expansion) ### Deletion Conditions (2/5 achieved) 1. ✅ JoinIR has type_hint field (Phase 63-3) 2. ✅ Type hints populated for representative cases (Phase 63-2) 3. ⏳ Degraded to type_hint priority (Phase 63-5) 4. ⏳ P1 cases determined by type_hint only (Phase 63-5) 5. ⏳ All functions use type hints (Phase 64+) ## Files Changed - docs/private/roadmap2/phases/phase-63-joinir-type-info/README.md - docs/private/roadmap2/phases/phase-30-final-joinir-world/PHI_BOX_INVENTORY.md - CURRENT_TASK.md ## Next Steps Phase 63-5: Implement degradation for P1 cases (IfSelectTest.simple/local) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 17:58:06 +09:00
### 1-00h. Phase 62 — PHI Core Cleanupphi_core 小箱クリーンアップ)
- 目的: PHI 箱のうち、既に機能が JoinIR/loopform/phi_merge 側に移っていて「殻だけ残っていた」小箱を片付け、phi_core 直下の実コードをさらに減らす。
- 実績:
- `phi_core/phi_input_collector.rs` を削除。Phase 59/59b で loopform_builder.rs / loop_builder.rs へのインライン化が完了しており、外部依存 0 であることを PHI_BOX_INVENTORY ベースで確認済み。
- `phi_core/conservative.rs` を 57 行すべてコメントのみの「歴史メモ」ファイルに縮退(実コードは Phase 58 で `phi_merge.rs::merge_all_vars` 側にインライン済み)。将来的に docs/ への移設候補として扱う。
- PHI_BOX_INVENTORY.md / phi-reduction-series/INDEX.md / CURRENT_TASK.md を更新し、「PhiInputCollector 削除済み」「ConservativeMerge 本体は inline 済みで conservative.rs は docs 専用」という現状を明示。
- JoinIR/phi_core 関連テストは全て PASS。既知の `local` キーワード問題を除き、新たな退行はなし。
feat(joinir): Phase 56 ArrayExtBox.filter JoinIR lowering完全実装 ## Summary ArrayExtBox.filter/2 の JoinIR Frontend lowering を完全実装し、 ConditionalMethodCall 命令を導入して filter パターンに対応。 56 JoinIR テスト全て PASS(退行なし)。 ## Technical Changes ### 1. ConditionalMethodCall 命令追加 - **新規命令**: `if pred(v) { acc.push(v) }` パターン用 - **構造**: cond が true なら method 実行、false なら no-op - **MIR 変換**: 4ブロック構造 (cond→then/else→merge) ### 2. AST JSON 拡張 - Break/Continue/FunctionCall に "type" フィールド追加 - ArrayLiteral/MapLiteral に "type" フィールド追加 - JoinIR Frontend 互換性向上 ### 3. Expression Handler 拡張 - Unary 演算子(not, 負号)サポート - Call(変数関数呼び出し)を MethodCall に変換 ### 4. Loop Pattern Binding 修正 - `BoundExpr::Variable("n")` 問題修正 - `MethodCall { receiver: "arr", method: "size" }` に変更 - external_refs (arr, pred) を step 関数に伝播 ### 5. If Statement Handler 拡張 - 条件付き側効果パターン(ケース4)追加 - MethodCall/Method 形式の statement を ConditionalMethodCall に変換 ## Files Modified (10 files, +456/-45 lines) - ast_json.rs: AST JSON "type" フィールド追加 - loop_frontend_binding.rs: n バインディング修正 - control_flow.rs: external_refs params 追加 - loop_patterns.rs: external_refs step 関数伝播 - expr.rs: Unary, Call handler 追加 - stmt_handlers.rs: ConditionalMethodCall パターン追加 - mod.rs: ConditionalMethodCall, UnaryOp 定義 - json.rs: ConditionalMethodCall, UnaryOp シリアライズ - join_ir_runner.rs: ConditionalMethodCall, UnaryOp スタブ - convert.rs: ConditionalMethodCall → MIR 変換 ## Test Results - 56 JoinIR tests: ✅ PASSED - Regression: ❌ None - ArrayExtBox.filter/2: ✅ JoinIR lowering 成功 ## Milestone JoinIR 2ループ完走達成: - ✅ JsonTokenizer.print_tokens/0 - ✅ ArrayExtBox.filter/2 (NEW!) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 06:51:43 +09:00
feat(joinir): Phase 63-4 infer_type_from_phi degradation design Phase 63-4: infer_type_from_phi を『JoinIR 型ヒント優先+従来ロジックフォールバック』に縮退する仕様を設計(実装は Phase 63-5+) ## Changes ### Documentation Updates - **README.md**: Added complete Phase 63-4 design (63-4.1 through 63-4.5) - 63-4.1: Current state analysis (definition location, callsites, role, JoinIR preparation) - 63-4.2: Degradation spec (type_hint priority + fallback pattern) - 63-4.3: Representative cases and A/B testing strategy (P1/P2/P3) - 63-4.4: Deletion conditions (5 conditions, current: 2/5 = 40%) - 63-4.5: Phase 63-5 handoff (infer_type_from_phi_with_hint() implementation tasks) - **PHI_BOX_INVENTORY.md**: Updated if_phi.rs entry with Phase 63-4 deletion plan - Added: "Phase 63-4完了: infer_type_from_phi の JoinIR type_hint 優先への縮退案を設計(実装は Phase 63-5+)" - **CURRENT_TASK.md**: Added Phase 63-4 section with summary of design work ## Design Highlights ### Degradation Pattern ```rust pub fn infer_type_from_phi_with_hint( function: &MirFunction, ret_val: ValueId, types: &BTreeMap<ValueId, MirType>, type_hint: Option<MirType>, ) -> Option<MirType> { if let Some(hint) = type_hint { return Some(hint); // Route B: JoinIR priority (SSOT) } infer_type_from_phi(function, ret_val, types) // Route A: Fallback } ``` ### Representative Cases - **P1**: IfSelectTest.simple/local (Phase 63-5 target) - **P2**: read_quoted_from (Phase 63-6+ target) - **P3**: MethodCall/Box constructors (Phase 64+ expansion) ### Deletion Conditions (2/5 achieved) 1. ✅ JoinIR has type_hint field (Phase 63-3) 2. ✅ Type hints populated for representative cases (Phase 63-2) 3. ⏳ Degraded to type_hint priority (Phase 63-5) 4. ⏳ P1 cases determined by type_hint only (Phase 63-5) 5. ⏳ All functions use type hints (Phase 64+) ## Files Changed - docs/private/roadmap2/phases/phase-63-joinir-type-info/README.md - docs/private/roadmap2/phases/phase-30-final-joinir-world/PHI_BOX_INVENTORY.md - CURRENT_TASK.md ## Next Steps Phase 63-5: Implement degradation for P1 cases (IfSelectTest.simple/local) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 17:58:06 +09:00
### 1-00i. Phase 63-3 — JoinIR 型ヒントの最小配線
- 目的: infer_type_from_phi を削る前に、「JoinIR 側で MirType をどこに持てばよいか」を決め、そのための schema 変更と最小限のコード更新を行う。
- 実績:
- `JoinInst::Select``MergePair``type_hint: Option<MirType>` を追加し、If PHI に関わる値まわりに型ヒントをぶら下げる足場を用意した。
- Select / MergePair を生成する全サイトif_select.rs / if_merge.rs / nested_if.rs / read_quoted.rs など 13 ファイル)を更新し、新フィールドを一旦 `type_hint: None` で埋めてビルドが通る状態に統一。
- JoinIR 関連テストIfSelect/IfMerge/Frontend 系)はすべて PASS。挙動は従来どおりだが、今後 AST/Frontend/Bridge から型ヒントを流し込む準備が整った。
### 1-00j. Phase 63-4 — infer_type_from_phi 縮退設計(設計のみ)
- 目的: infer_type_from_phi を『JoinIR 型ヒント優先+従来ロジックフォールバック』に縮退する仕様を docs に固定(実装は Phase 63-5+)。
- 実績:
- 63-4.1: infer_type_from_phi の現状整理(定義場所 / 呼び出し元 / 役割 / JoinIR 準備状況)を文書化。
- 63-4.2: 縮退後の仕様設計type_hint がある場合は優先、ない場合は従来ロジックへフォールバック)。
- 63-4.3: 代表ケースと A/B テスト方針P1: IfSelectTest.simple/local, P2: read_quoted_from, P3: MethodCall/Box コンストラクタ)を整理。
- 63-4.4: 削除条件の明確化5条件、現時点達成率 2/5 = 40%)。
- 63-4.5: Phase 63-5 への引き継ぎinfer_type_from_phi_with_hint() 実装タスク定義)。
- docs: `docs/private/roadmap2/phases/phase-63-joinir-type-info/README.md`, `PHI_BOX_INVENTORY.md` 更新済み
feat(joinir): Phase 63-5 infer_type_from_phi degradation implementation (infrastructure) Phase 63-5: 型ヒント優先のインターフェースを確立し、lifecycle.rs で呼び出し経路を統一 ## Changes ### Core Implementation 1. **`infer_type_from_phi_with_hint()` 実装** (if_phi.rs:92-105) - Route B: `type_hint` があれば優先的に返す(JoinIR SSOT) - Route A: なければ `infer_type_from_phi()` へフォールバック - Fail-fast 原則遵守:既存挙動を一切変更しない 2. **lifecycle.rs 呼び出し経路統一** (2箇所) - lifecycle.rs:284, 303 で `infer_type_from_phi_with_hint(None, ...)` を呼び出し - 現時点では `type_hint=None` でフォールバック動作(既存挙動維持) - 将来 Phase 63-6+ で JoinIR からの型ヒント取得を実装 ### Test Results - ✅ IfSelect 全 8 テスト PASS(test_type_hint_propagation_simple 含む) - ✅ JoinIR 全 57 テスト PASS - ✅ 退行なし確認 ### Documentation Updates - **README.md**: Phase 63-5 完了セクション追加(実装内容・テスト結果・次ステップ) - **README.md**: 削除条件チェックリスト更新(3/5 達成、60%) - **PHI_BOX_INVENTORY.md**: if_phi.rs 行に Phase 63-5 完了マーク追加 - **CURRENT_TASK.md**: Phase 63-5 セクション追加 ## Technical Achievements - 型ヒント優先インターフェース確立 - lifecycle.rs 呼び出し経路統一 - Phase 63-6+ での段階的型ヒント供給の準備完了 ## Deletion Condition Progress **削除条件達成率**: 2/5 (40%) → **3/5 (60%)** ← Phase 63-5 完了で +20% 1. ✅ JoinIR に `type_hint` 追加(Phase 63-3) 2. ✅ 代表ケースで `type_hint` 埋め込み(Phase 63-2) 3. ✅ 型ヒント優先に縮退(Phase 63-5)← NEW! 4. ⏳ P1 ケースで `type_hint` のみで型決定(Phase 63-6+) 5. ⏳ 全関数で型ヒント化完了(Phase 64+) ## Files Changed - src/mir/phi_core/if_phi.rs: +44行(infer_type_from_phi_with_hint() 追加) - src/mir/builder/lifecycle.rs: 2箇所で _with_hint 呼び出しへ移行 - docs/private/roadmap2/phases/phase-63-joinir-type-info/README.md - docs/private/roadmap2/phases/phase-30-final-joinir-world/PHI_BOX_INVENTORY.md - CURRENT_TASK.md ## Next Steps **Phase 63-6**: P1 ケース(IfSelectTest.simple/local)への型ヒント供給を実装 - JoinIR → MIR Bridge での型ヒント伝播 - lifecycle.rs で型ヒントを取得するパスの追加 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 18:07:38 +09:00
### 1-00k. Phase 63-5 — infer_type_from_phi 縮退実装(基盤整備)✅ 完了2025-11-29
- 目的: 型ヒント優先のインターフェースを確立し、lifecycle.rs で呼び出し経路を統一する。
- 実績:
- 63-5-1: `infer_type_from_phi_with_hint()` 関数実装if_phi.rs:92-105, +44行
- Route B: `type_hint` があれば優先的に返すJoinIR SSOT
- Route A: なければ `infer_type_from_phi()` へフォールバック
- Fail-fast 原則遵守:既存挙動を一切変更しない
- 63-5-2: lifecycle.rs で呼び出しを `_with_hint` に統一2箇所: lifecycle.rs:284, 303
- 現時点では `type_hint=None` でフォールバック動作(既存挙動維持)
- 将来 Phase 63-6+ で JoinIR からの型ヒント取得を実装
- 63-5-3: テスト検証完了(退行なし)
- IfSelect 全 8 テスト PASStest_type_hint_propagation_simple 含む)
- JoinIR 全 57 テスト PASS
- 削減実績: 0行縮退のみ、削除なし
- 削除条件達成率: 3/560%)← Phase 63-5 完了で +20%
- 技術的成果: 型ヒント優先インターフェース確立、lifecycle.rs 呼び出し経路統一
- 次のステップ: Phase 63-6 で P1 ケースIfSelectTest.simple/localへの型ヒント供給を実装
feat(mir): Phase 63-6-3/4/5 P1 type hint完全実装 & 削除条件4/5達成 Phase 63-6-3: lifecycle.rs で型ヒント取得・使用 - `get_phi_type_hint()` ヘルパー関数追加(lifecycle.rs:44-60) - P1 ケース(IfSelectTest.*)限定で PHI の type_hint を取得 - lifecycle.rs:313-316, 335-338 で型ヒント使用 - 関数名フィルタでガード、他は None(既存挙動維持) Phase 63-6-4: P1 ケーステスト追加(A/B 検証) - `test_p1_ab_type_inference()` 追加(mir_joinir_if_select.rs:684-721) - Route B(JoinIR 型ヒント経由)の動作確認 - Select type_hint = Some(Integer) 検証 - P1 function name filter 検証 Phase 63-6-5: ドキュメント更新(削除条件 4/5 達成) - Phase 63 README.md 更新:削除条件 4/5 を ✅ 完了に - 達成率 3/5(60%)→ 4/5(80%)に更新 - Phase 63-6 完了セクション追加(実装内容・成果・ファイル一覧) - CURRENT_TASK.md に Phase 63-6 完了記録追加 削減実績: 0行(段階的拡大のため削除なし) **削除条件達成率: 4/5(80%)← Phase 63-6 完了で +20%** 技術的成果: - **P1 ケースで JoinIR 型ヒントのみで型決定(削除条件 4/5 達成)** - JoinIR が If 系 PHI の型情報 SSOT として機能確立 - lifecycle.rs が型ヒント優先で推論する基盤完成 - Select → PHI → lifecycle.rs の全経路が動作 Modified files: - src/mir/builder/lifecycle.rs: get_phi_type_hint() 追加、P1 型ヒント使用 - src/tests/mir_joinir_if_select.rs: A/B テスト追加 - CURRENT_TASK.md: Phase 63-6 完了記録 - docs/private/roadmap2/phases/phase-63-joinir-type-info/README.md: 削除条件更新 Test results: - ✅ test_p1_ab_type_inference: PASS - ✅ test_if_select_pattern_matching: PASS - ✅ All if_select tests: 8/8 PASS 次のステップ: Phase 64 で P2/P3 ケースへ拡大、全関数で型ヒント化完了(削除条件 5/5) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-30 04:45:11 +09:00
### 1-00l. Phase 63-6 — P1 ケース型ヒント完全実装 ✅ 完了2025-11-30
- 目的: P1 ケースIfSelectTest.simple/localで JoinIR type_hint のみで型が決まる状態を達成
- 実績:
- 63-6-1: MirInstruction::Phi に `type_hint: Option<MirType>` 追加instruction.rs
- 21ファイル修正、25箇所のコンパイルエラー解決
- 全てのレガシーパスで `type_hint: None` 設定
- 63-6-2: JoinIR→MIR Bridge で型ヒント伝播実装convert.rs
- Select → PHI 変換で type_hint を伝播
- Copy 命令削除、PHI で値合流を直接実装
- テスト: test_type_hint_propagation_simple() で Some(Integer) 確認
- 63-6-3: lifecycle.rs で型ヒント取得・使用
- `get_phi_type_hint()` ヘルパー関数追加
- P1 ケースIfSelectTest.*)限定で型ヒント使用
- 関数名フィルタでガード、他は None既存挙動維持
- 63-6-4: P1 ケーステスト追加A/B 検証)
- test_p1_ab_type_inference() 追加で Route B 動作確認
- 削減実績: 0行段階的拡大のため削除なし
- **削除条件達成率: 4/580%)← Phase 63-6 完了で +20%**
- 技術的成果:
- **P1 ケースで JoinIR 型ヒントのみで型決定(削除条件 4/5 達成)**
- JoinIR が If 系 PHI の型情報 SSOT として機能
- lifecycle.rs が型ヒント優先で推論
- 次のステップ: Phase 64 で P2/P3 ケースへ拡大、全関数で型ヒント化完了(削除条件 5/5
---
## 2. 中期 TODOざっくり
- **Phase 42: PHI Workaround 条件付きスキップ** ✅ 完了2025-11-28
- ✅ 42-1: PHI workaround 内容の文書化完了README.md に記録)
- ✅ 42-2: `parser_control_box.hako:85-139` に条件付きスキップ実装
- Route Adefault: workaround 使用(後方互換性維持)
- Route B`HAKO_JOINIR_NESTED_IF=1`: workaround スキップ
- Route B テスト 3/3 PASS、Route A テスト 13/13 PASS
- ✅ 42-3: callsite 再分析・Phase 43 候補リスト作成完了
- if_phi.rs: 4残存関数全て parse_loop 以外からも呼ばれる)
- conservative.rs: ConservativeMerge::analyze が phi_merge.rs/phi.rs から使用中
- Phase 43 推奨: NestedIfMerge 適用範囲拡大 → phi_merge.rs JoinIR 移行
- docs: `docs/private/roadmap2/phases/phase-42-if-phi-level3-removal/README.md`
- **Phase 43+: If 側 PHI 本体削除**
- if_phi.rs / conservative.rs の残存関数は全て parse_loop 以外からも呼ばれている
- 他の関数print_tokens 等)も JoinIR 経路に乗せてから本体削除
- **Phase 61-7+: If PHI 大型統合P2 候補)**
- `compute_modified_names_if`: 変更変数検出を JoinIR の modified 変数集合解析に統合(~75行
- `get_conservative_if_values`: incoming 値解決を PhiSpec に移行、void fallback 削除(~70行
- 期待削減: 合計 145行
- **Classifier Trio**
- LoopVarClassBox / LoopExitLivenessBox / LocalScopeInspectorBox を LoopScopeShape に吸収し、JoinIR lowering / LoopForm 側から直接 LoopScopeShape を見る構造に整理。
- **Mir 決定性(小フェーズ予定)**
- 一部テスト(`loop_with_continue_and_break_edge_copy_merge` / `nested_loop_with_multi_continue_break_edge_copy_merge`)で、`MirFunction.blocks: HashMap` / `BasicBlock.predecessors: HashSet` に起因する非決定的な predecessor 順のフラッキーテストが残っている。
- 将来の小フェーズで Phase 25.1 と同様のパターン(`BTreeMap` / `BTreeSet` など決定的な順序構造、もしくはテスト側で sort 比較)に寄せて解消する予定。
---
## 3. 旧フェーズ(過去ログへのポインタ)
古いフェーズの詳細な経緯やログは、以下のドキュメントと
`docs/private/roadmap2/CURRENT_TASK_2025-11-29_full.md` を見てね。
- Phase 21.7 — Static Box Methodization
- StaticMethodId / NamingBox で BoxName.method/arity 名前解決の SSOT 化。
- docs: `docs/development/current/main/phase-21.7-naming-ssot-checklist.md` など。
- Phase 25.x / 26.x — LoopForm v2 / LoopSSA v2 / Exit PHI / ExitLiveness
- LoopForm v2 / LoopSSA v2 の整備と Exit PHI / ExitLiveness まわりの 4 箱構成。
- Phase 2732 — JoinIR 初期実験〜汎用化
- LoopToJoinLowerer / LoopScopeShape / JoinIR VM Bridge を minimal ケースから Stage1 / StageB へ広げていくライン。
- docs: `docs/private/roadmap2/phases/phase-27-joinir*`, `phase-31-looptojoin-lowerer`, `phase-32-joinir-complete-migration` など。
CURRENT_TASK.md 自体は「いまどこを触っているか」と「次に何をやるか」を
1 画面で把握できる軽さを維持する方針だよ。***