d303d24b43
feat(joinir): Phase 188 JoinInlineBoundary + Pattern 1 working! 🎉
...
Major milestone: loop_min_while.hako outputs "0 1 2" correctly!
## JoinInlineBoundary (Option D from ChatGPT Pro design review)
- New struct for clean SSA boundary between JoinIR and host function
- JoinIR uses local ValueIds (0,1,2...) - no host ValueId dependency
- Copy injection at entry block connects host → JoinIR values
## Pattern 1 Simple While Loop
- Refactored to use pure local ValueIds
- Removed Pattern1Context dependency on host ValueIds
- Clean separation: lowerer generates, merger connects
## Key Design Principles (Box Theory)
- Box A: JoinIR Frontend (host-agnostic)
- Box B: Join→MIR Bridge (independent functions)
- Box C: JoinInlineBoundary (boundary info only)
- Box D: JoinMirInlineMerger (Copy injection)
## Files Changed
- NEW: inline_boundary.rs - JoinInlineBoundary struct
- control_flow.rs - merge with boundary, void return fix
- simple_while_minimal.rs - pure local ValueIds
- mod.rs - module export
Test: NYASH_DISABLE_PLUGINS=1 ./target/release/hakorune apps/tests/loop_min_while.hako
Output: 0\n1\n2 ✅
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-12-05 13:46:44 +09:00
5bc0fa861f
feat(joinir): Phase 188 Pattern 1 Core Implementation + Phase 189 Planning
...
Phase 188 Status: Planning & Foundation Complete (100%)
Completed Tasks:
✅ Task 188-1: Error Inventory (5 patterns identified)
✅ Task 188-2: Pattern Classification (3 patterns selected)
✅ Task 188-3: Design (51KB comprehensive blueprint)
✅ Task 188-4: Implementation Foundation (1,802 lines scaffolding)
✅ Task 188-5: Verification & Documentation
✅ Pattern 1 Core Implementation: Detection + Lowering + Routing
Pattern 1 Implementation (322 lines):
- Pattern Detection: is_simple_while_pattern() in loop_pattern_detection.rs
- JoinIR Lowering: lower_simple_while_to_joinir() in simple_while_minimal.rs (219 lines)
- Generates 3 functions: entry, loop_step (tail-recursive), k_exit
- Implements condition negation: exit_cond = !(i < 3)
- Tail-recursive Call pattern with state propagation
- Routing: Added "main" to function routing list in control_flow.rs
- Build: ✅ SUCCESS (0 errors, 34 warnings)
Infrastructure Blocker Identified:
- merge_joinir_mir_blocks() only handles single-function JoinIR modules
- Pattern 1 generates 3 functions (entry + loop_step + k_exit)
- Current implementation only merges first function → loop body never executes
- Root cause: control_flow.rs line ~850 takes only .next() function
Phase 189 Planning Complete:
- Goal: Refactor merge_joinir_mir_blocks() for multi-function support
- Strategy: Sequential Merge (Option A) - merge all functions in call order
- Effort estimate: 5.5-7.5 hours
- Deliverables: README.md (16KB), current-analysis.md (15KB), QUICKSTART.md (5.8KB)
Files Modified/Created:
- src/mir/loop_pattern_detection.rs (+50 lines) - Pattern detection
- src/mir/join_ir/lowering/simple_while_minimal.rs (+219 lines) - Lowering
- src/mir/join_ir/lowering/loop_patterns.rs (+803 lines) - Foundation skeleton
- src/mir/join_ir/lowering/mod.rs (+2 lines) - Module registration
- src/mir/builder/control_flow.rs (+1 line) - Routing fix
- src/mir/builder/loop_frontend_binding.rs (+20 lines) - Binding updates
- tools/test_phase188_foundation.sh (executable) - Foundation verification
- CURRENT_TASK.md (updated) - Phase 188/189 status
Next: Phase 189 implementation (merge_joinir_mir_blocks refactor)
🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com >
2025-12-05 07:47:22 +09:00
6561832545
feat(joinir): Phase 185 Strict Mode Semantics Cleanup
...
Remove redundant strict checks from If lowering (3 → 1 check point):
- mod.rs: Remove 2 strict panic blocks from try_lower_if_to_joinir()
- mod.rs: Comment out unused strict_on variable
- Keep single strict check at caller level (if_form.rs)
This aligns If lowering architecture with Loop lowering:
- Lowerers are thin Result-returning boxes (no policy decisions)
- Strict mode check happens at router/caller level (single source of truth)
- Fail-Fast principle: panic at ONE location when strict=ON
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-12-04 22:27:12 +09:00
7c68f710d3
feat(joinir): Phase 184 If lowering mainline & JOINIR_IF_TARGETS
...
Establish If lowering infrastructure with dedicated JOINIR_IF_TARGETS
table, separate from loop lowering (JOINIR_TARGETS).
Implementation:
- Add JOINIR_IF_TARGETS table with 6 representative functions
- Add is_if_lowered_function() for table-based lookup
- Update is_if_mainline_target() to use table (SSOT)
- Update is_joinir_if_toplevel_target() with table-first lookup
- Export via join_ir_vm_bridge_dispatch public API
Representative functions:
- IfSelectTest.test/1 (simple return pattern)
- IfSelectLocalTest.main/0 (local variable pattern)
- IfMergeTest.simple_true/0, simple_false/0 (multiple variables)
- JsonShapeToMap._read_value_from_pair/1 (Stage-1 production)
- Stage1JsonScannerBox.value_start_after_key_pos/2 (Stage-B production)
Architecture: Loop/If separation complete (1関数につき1 lowering)
Verification: All representative paths pass with NYASH_JOINIR_DEBUG=1
Phase 184 complete → Phase 185+ ready
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-12-04 21:58:45 +09:00
8ae1eabcfa
feat(lifecycle): Phase 83 P3-D MethodReturnHintBox implementation
...
ChatGPT Pro設計に基づき、既知メソッド戻り値型推論箱(P3-D)を実装。
## 変更内容
- method_return_hint.rs: MethodReturnHintBox 新規作成
- BoxCall/Call のメソッド名から戻り値型を推論
- TypeAnnotationBox と同等のマッピングを適用
- length/size/len → Integer, push → Void, str/substring → String
- lifecycle.rs: P3-D 経路を P3-C の前に挿入
- mod.rs: method_return_hint モジュール登録
## 成果
- Case D 削減: 20 → 16 (4件削減, 20%)
- Unit tests: 5/5 passed
## 設計原則
- 単一責務: P3-D 推論のみ
- TypeAnnotationBox 薄ラップ: 型マッピングの SSOT は TypeAnnotationBox
- 将来移行性: MethodRegistry 導入時も API 不変
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-12-02 18:09:04 +09:00
93f51e40ae
refactor(joinir): Phase 82 SSOT統一化 - テーブル化とヘルパー抽象化
...
Phase 82: JoinIR関数リストとExecルートの SSOT 統一化
## 変更内容
### 1. JOINIR_TARGETS テーブル統一化
**targets.rs**: vm_bridge_dispatch テーブルが唯一のSSO
- FuncScannerBox.append_defs/2 を Exec に追加
- is_loop_lowered_function() はここから参照
- コメントに Phase 82 SSOT マーク
**mod.rs**: is_loop_lowered_function() 簡素化
- JOINIR_TARGETS テーブルから参照に統一
- Exec/LowerOnly 両方を Loop lowered対象とする
- ハードコード関数リストを削除 ✅
### 2. Exec routes 統一ヘルパー
**exec_routes.rs**: run_generic_joinir_route() 追加
- try_run_skip_ws() / try_run_trim() の共通パターンを抽象化
- 入出力値フォーマッタ、終了コードエキスプレッサをコールバック化
- 後方互換性のため既存関数は保持
- 将来フェーズで統合可能 (#[allow(dead_code)])
## テスト結果
✅ test_is_loop_lowered_function PASS
✅ cargo build --release SUCCESS
## 重複排除の効果
- テーブル重複: ハードコード関数リスト完全排除
- ロジック重複: 統一ヘルパーで28行削減可能(将来)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-12-02 14:01:44 +09:00
c61f4bc742
feat(joinir): Phase 80 JoinIR Mainline Unification
...
Phase 80: JoinIR 本線化(Core ON 対応)
## 変更内容
### Phase 80-1: SSOT 関数群の追加 (mod.rs)
- `is_loop_mainline_target()`: Loop本線化対象判定
- `is_if_mainline_target()`: If本線化対象判定
- `should_try_joinir_mainline()`: Core ON時の本線試行判定
- `should_panic_on_joinir_failure()`: Strict時のパニック判定
### Phase 80-2: If本線化 (if_form.rs)
- Core ON (`joinir_core_enabled()`) 時に代表関数でJoinIRを本線として試行
- Strict mode (`joinir_strict_enabled()`) でパターン不一致時にパニック
### Phase 80-3: Loop本線化 (vm_bridge_dispatch/mod.rs)
- Core ON 時に本線対象関数でJoinIR VMブリッジを優先試行
- Strict mode で失敗時にパニック
## 対象関数
- Loop: Main.skip/1, FuncScannerBox.trim/1, etc. (6本)
- If: IfSelectTest.*, IfMergeTest.*, JsonShapeToMap.* etc.
## 環境変数
- NYASH_JOINIR_CORE=1: Core ON(本線化有効)
- NYASH_JOINIR_STRICT=1: Strict ON(フォールバック禁止)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-12-02 13:45:47 +09:00
8633224061
JoinIR/SSA/Stage-3: sync CURRENT_TASK and dev env
2025-12-01 11:10:46 +09:00
a3d5bacc55
Phase 30.1 & 73: Stage-3 features env and JoinIR flag cleanup
2025-11-30 14:30:28 +09:00
58c5d8c9bc
feat(joinir): Phase 66-68 GenericTypeResolver + JoinIR First Chapter Wrap
...
Phase 66: P3-C ジェネリック型推論箱化
- generic_type_resolver.rs 新設 (180行)
- is_generic_method(): ArrayBox.get/pop/first/last, MapBox.get 判定
- resolve_from_phi(): PHI解析によるジェネリック型推論
- TypeHintPolicy::is_p3c_target() 追加
- P1/P2/P3-A/P3-B 以外を P3-C 候補として判定
Phase 67: P3-C 実利用への一歩
- phase67_generic_type_resolver.rs テスト追加 (3テスト)
- lifecycle.rs に P3-C 経路フック追加
- GenericTypeResolver を P3-C 対象関数で優先使用
- A/B テストで旧経路との一致確認 (11 tests PASS)
Phase 68: JoinIR First Chapter Wrap (ドキュメント整理)
- 68-1: phase-30 README.md に Section 9 追加 (JoinIR 第1章完了サマリー)
- 68-2: README.md に JoinIR status セクション追加
- 68-3: CURRENT_TASK.md スリム化 (351→132行, 62%削減)
- 68-4: PHI_BOX_INVENTORY.md に Phase 66-67 完了セクション追加
Phase 69-1: Trio 棚卸し
- phase69-1-trio-inventory.md 作成
- Trio 使用箇所の完全棚卸し完了 (削減見込み 457-707行)
🐱 JoinIR 第1章完了!4つの柱確立:
- Structure (LoopForm)
- Scope (LoopScopeShape)
- JoinIR (Select/IfMerge/Loop)
- Type Hints (P1-P3-C)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-30 08:54:18 +09:00
74a6f0f93e
feat(joinir): Phase 65.5 TypeHintPolicy箱化モジュール化
...
## 目的
lifecycle.rs の型ヒント判定ロジックを箱化モジュール化し、
単一責務原則に基づいたクリーンなアーキテクチャを実現。
## 主な変更
### 新規ファイル
- **type_hint_policy.rs** (237行): 型ヒントポリシー専用モジュール
- `TypeHintPolicy` 構造体: 型ヒント対象関数の判定
- `is_target()`: P1/P2/P3-A/P3-B 統合判定
- `extract_phi_type_hint()`: PHI から型ヒント抽出
- 7つの単体テスト(パターン別カバレッジ)
### 既存ファイル修正
- **lifecycle.rs**: 60行削減
- `get_phi_type_hint()` 削除 → `TypeHintPolicy::extract_phi_type_hint()` に移行
- `is_type_hint_target()` 削除 → `TypeHintPolicy::is_target()` に移行
- 2箇所の呼び出し箇所を TypeHintPolicy 使用に更新
- **lowering/mod.rs**: type_hint_policy モジュール宣言追加
## 箱化の利点
- ✅ 単一責務:ポリシー判定のみを担当
- ✅ テスト可能:独立した単体テスト(7テスト)
- ✅ 拡張容易:Phase 66+ で P3-C 追加が簡単
- ✅ 可読性向上:関数型スタイル(flat_map/find_map)
## テスト結果
```
running 6 tests
test type_hint_policy::tests::test_is_p1_target ... ok
test type_hint_policy::tests::test_is_p2_target ... ok
test type_hint_policy::tests::test_is_p3a_target ... ok
test type_hint_policy::tests::test_is_p3b_target ... ok
test type_hint_policy::tests::test_is_target ... ok
test type_hint_policy::tests::test_p2_p3a_overlap ... ok
```
## Phase 65 完了状況
- ✅ Phase 65-1: 型マッピング設計文書作成
- ✅ Phase 65-2-A: StringBox メソッド型ヒント実装
- ✅ Phase 65-2-B: Box コンストラクタ型ヒント実装
- ✅ Phase 65-3: lifecycle.rs への P3-A/B 統合
- ✅ Phase 65-4/65-5: 削除条件 5/5 達成、if_phi.rs を P3-C フォールバックに位置づけ
- ✅ Phase 65.5: TypeHintPolicy 箱化モジュール化(今回)
🎉 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-30 06:37:34 +09:00
b4b6a01b92
feat(joinir): Phase 65-2-A StringBox メソッド型ヒント実装
...
Phase 65-2-A 完了:P3-A(StringBox メソッド)型ヒント実装
## 実装内容
### 1. type_inference.rs 新規作成
- `infer_method_return_type()`: StringBox/ArrayBox/MapBox メソッド型推論
- `infer_box_type()`: Box コンストラクタ型推論(Phase 65-2-B 用)
- 8 テスト全て PASS
### 2. JoinInst::MethodCall に type_hint 追加
- `src/mir/join_ir/mod.rs`: `type_hint: Option<MirType>` フィールド追加
- 段階的拡大のため Optional 設計(既存コード破壊なし)
### 3. read_quoted.rs で型ヒント設定
- substring() → String(4箇所)
- length() → Integer(1箇所)
- read_quoted 系関数で完全な型ヒント供給
### 4. 汎用経路は None で後方互換性維持
- expr.rs: 汎用 MethodCall は `type_hint: None`
- convert.rs: 型ヒント追加(Phase 65-3 で活用予定)
- json.rs: JSON シリアライズ対応
## テスト結果
- ✅ type_inference モジュール: 8/8 PASS
- ✅ ビルド: 0 エラー
## 次のステップ
- Phase 65-2-B: Box コンストラクタ型ヒント実装
---
🌟 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-30 06:10:58 +09:00
3194cc1e6c
feat(joinir): Phase 61-4-F ToplevelOps and production path integration
...
Phase 61-4-F: Loop-outside If JoinIR production path
Changes:
- F.1: Add ToplevelOps struct implementing PhiBuilderOps for MirBuilder
- Enables emit_toplevel_phis() to emit PHI instructions via MirBuilder
- Uses insert_phi_at_head_spanned for proper PHI placement
- ~70 lines, thin wrapper following box theory
- F.2: Integrate production path with emit_toplevel_phis
- Replace TODO with actual PHI emission call
- Build IfShape from branch blocks
- Log PHI count on dry-run
- Add IfToplevelTest.* to try_lower_if_to_joinir allowed list
- Fixes function name guard that blocked testing
Note: Pattern matching currently only supports return patterns
(IfMerge/IfSelect). Local variable assignment patterns fall back
to existing PHI generation, which correctly produces valid MIR.
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-29 15:32:40 +09:00
3439de0f65
feat(joinir): Phase 61-4-D/E function guard and toplevel emitter
...
Phase 61-4 追加実装:
1. Phase 61-4-D: 関数名ガード整理
- is_joinir_if_toplevel_target() ヘルパー追加
- IfSelectTest.*, IfToplevelTest.*, IfMergeTest.* 対応
- if_form.rs で関数名チェック統合
2. Phase 61-4-E: emit_toplevel_phis() 追加
- IfInLoopPhiEmitter に toplevel 用メソッド追加
- carrier_names 不要(PhiSpec の全変数を対象)
- HAKO_JOINIR_IF_TOPLEVEL_TRACE でトレース可能
現状:
- dry-run モードでパターンマッチング確認可能
- 本番経路のPHI生成統合は次フェーズ(MirBuilder PHI emit 方式検討必要)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-29 15:15:22 +09:00
68615e72fb
feat(joinir): Phase 61-2 If-in-loop JoinIR dry-run検証インフラ実装
...
## 実装内容
### 61-2.1: dry-runフラグ追加
- `src/config/env.rs`: joinir_if_in_loop_dryrun_enabled() 追加 (+11行)
- `HAKO_JOINIR_IF_IN_LOOP_DRYRUN=1` でdry-runモード有効化
### 61-2.2: loop_builder.rs dry-run統合
- `src/mir/loop_builder.rs`: JoinIR PhiSpec計算とA/B比較実装 (+47行)
- JoinInst取得時にPhiSpec保存、PhiBuilderBox実行後に比較
### 61-2.3: PhiSpec計算ロジック実装
- `src/mir/join_ir/lowering/if_phi_spec.rs`: 新規作成 (+203行)
- PhiSpec構造体(header_phis/exit_phis)
- compute_phi_spec_from_joinir(): JoinInstからPHI仕様計算
- extract_phi_spec_from_builder(): PhiBuilderBox結果抽出
- compare_and_log_phi_specs(): A/B比較とログ出力
- BTreeMap/BTreeSet使用(決定的イテレーション保証)
### 61-2.4: A/B比較テスト実装
- `src/tests/phase61_if_in_loop_dryrun.rs`: 新規作成 (+49行)
- phase61_2_dry_run_flag_available: フラグ動作確認
- phase61_2_phi_spec_creation: PhiSpec構造体テスト
- テスト結果: ✅ 2/2 PASS
## テスト結果
- Phase 61-2新規テスト: ✅ 2/2 PASS
- 既存loopformテスト: ✅ 14/14 PASS(退行なし)
- ビルド: ✅ 成功(エラー0件)
## コード変更量
+312行(env.rs: +11, if_phi_spec.rs: +203, loop_builder.rs: +47, tests: +49, その他: +2)
## 技術的成果
1. PhiSpec構造体完成(JoinIR/PhiBuilderBox統一表現)
2. dry-run検証インフラ(本番動作に影響なし)
3. BTreeMap統一(Option C知見活用)
## 次のステップ(Phase 61-3)
- dry-run → 本番経路への昇格
- PhiBuilderBox If側メソッド削除(-226行)
- JoinIR経路のみでif-in-loop PHI生成
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-29 12:26:02 +09:00
3ea397fd3e
feat(joinir): Phase 61-1 If-in-loop JoinIR化インフラ整備完了
...
## 実装内容
### 新規ファイル
- `if_phi_context.rs`: If-in-loop用PHIコンテキスト構造体 (135行)
- `IfPhiContext::for_loop_body()`: ループ内if用コンストラクタ
- `is_carrier()`: ループキャリア変数判定
- 単体テスト2個完全動作
### 既存ファイル拡張
- `if_select.rs`, `if_merge.rs`: context パラメータ追加 (+68行)
- `with_context()` コンストラクタ実装
- Pure If との完全互換性維持
- `mod.rs`: `try_lower_if_to_joinir()` シグネチャ拡張 (+25行)
- `context: Option<&IfPhiContext>` パラメータ追加
- 既存呼び出し箇所6箇所修正完了
- `loop_builder.rs`: JoinIR経路実装 (+43行)
- `NYASH_JOINIR_IF_SELECT=1` で試行
- フォールバック設計(PhiBuilderBox経路保持)
- デバッグログ完備
## テスト結果
- ✅ loopform テスト 14/14 PASS(退行なし)
- ✅ ビルド成功(エラー0件)
- ✅ Borrow Checker 問題解決
## コード変更量
- 新規: +135行
- 拡張: +136行
- 削除: -18行
- 純増: +253行(インフラ投資、Phase 61-3で-226行削減予定)
## 次のステップ
Phase 61-2: join_inst dry-run実装で実際のPHI生成を行う
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-29 11:53:57 +09:00
447bbec998
refactor(joinir): Split ast_lowerer and join_ir_vm_bridge into modules
...
ast_lowerer.rs → ast_lowerer/ (10 files):
- mod.rs: public surface + entry dispatch
- context.rs: ExtractCtx helpers
- expr.rs: expression-to-JoinIR extraction
- if_return.rs: simple if→Select lowering
- loop_patterns.rs: loop variants (simple/break/continue)
- read_quoted.rs: read_quoted_from lowering (Phase 45-46)
- nested_if.rs: NestedIfMerge lowering
- analysis.rs: loop if-var analysis + metadata helpers
- tests.rs: frontend lowering tests
- README.md: module documentation
join_ir_vm_bridge.rs → join_ir_vm_bridge/ (5 files):
- mod.rs: public surface + shared helpers
- convert.rs: JoinIR→MIR lowering
- runner.rs: VM execution entry (run_joinir_via_vm)
- meta.rs: experimental metadata-aware hooks
- tests.rs: bridge-specific unit tests
- README.md: module documentation
Benefits:
- Clear separation of concerns per pattern
- Easier navigation and maintenance
- Each file has single responsibility
- README documents module boundaries
Co-authored-by: ChatGPT <noreply@openai.com >
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-28 17:42:19 +09:00
588129db65
feat(joinir): Phase 34-6 MethodCall 構造と本物の substring 意味論
...
**Phase 34-6 実装完了**: MethodCall 構造を JoinIR に追加し、本物の substring
呼び出しを通すことに成功。
## 主要変更
### 1. MethodCall 構造追加 (34-6.1)
- `src/mir/join_ir/mod.rs`: JoinInst::MethodCall バリアント (+8 lines)
- 構造: `{ dst, receiver, method, args }`
- 設計原則: JoinIR は構造のみ、意味論は MIR レベル
### 2. extract_value 更新 (34-6.2)
- `src/mir/join_ir/frontend/ast_lowerer.rs`: Method 処理本物化 (+37 lines)
- receiver/args を extract_value で再帰処理
- ダミー Const(0) 削除 → 本物の MethodCall 生成
- cond 処理修正: ValueId(0) ハードコード → extract_value で取得
### 3. JoinIR→MIR 変換実装 (34-6.3)
- `src/mir/join_ir_vm_bridge.rs`: MethodCall → BoxCall 変換 (+12 lines)
- `src/mir/join_ir/json.rs`: MethodCall JSON シリアライゼーション (+16 lines)
- `src/mir/join_ir_runner.rs`: MethodCall 未対応エラー (+7 lines)
### 4. テスト更新 (34-6.4)
- `docs/.../fixtures/json_shape_read_value.program.json`: 本物の substring 構造
- `src/tests/joinir_frontend_if_select.rs`: run_joinir_via_vm 使用
- テスト成功: v="hello", at=3 → "hel" ✅
## 成果
- ✅ テスト全通過(1 passed; 0 failed)
- ✅ 設計原則確立: JoinIR = 構造 SSOT、意味論 = MIR レベル
- ✅ Phase 33-10 原則との整合性: Method でも同じ原則適用
**ドキュメント更新**: CURRENT_TASK.md + TASKS.md(Phase 34-6 完了記録)
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-27 17:05:46 +09:00
9e9e08eb84
feat(joinir): Phase 33-9.1 Loop/If lowering responsibility separation
...
Implement clear separation between Loop and If lowering responsibilities:
**Guard Implementation:**
- Add is_loop_lowered_function() to identify 6 Loop-dedicated functions
- Exclude Loop functions from If lowering path in try_lower_if_to_joinir()
- Enforce "1 function → 1 lowering" principle
**Documentation:**
- Add responsibility comments to loop_to_join.rs
- Add responsibility comments to if_select.rs and if_merge.rs
- Update if_joinir_design.md with Phase 33-9.1 section
**Testing:**
- Add unit test test_is_loop_lowered_function() (PASS)
- Verify no regression in existing JoinIR tests
**Loop-dedicated functions (6):**
- Main.skip/1
- FuncScannerBox.trim/1
- FuncScannerBox.append_defs/2
- Stage1UsingResolverBox.resolve_for_source/5
- StageBBodyExtractorBox.build_body_src/2
- StageBFuncScannerBox.scan_all_boxes/1
This prevents future conflicts when both Loop and If lowering expand.
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-27 10:58:56 +09:00
517b20fe88
feat(joinir): Phase 33-8 Stage-1 rollout infrastructure
...
Add environment variable controls and debug logging for JoinIR lowering rollout.
Changes:
- Add HAKO_JOINIR_STAGE1 env var for Stage-1 function rollout control
- Add HAKO_JOINIR_DEBUG (0-3) for granular debug logging
- Level 0: Silent (default)
- Level 1: Basic lowering info
- Level 2: Pattern matching details
- Level 3: Full variable/instruction dump
- Implement 3-tier whitelist system:
- Tier 1: Test functions (always enabled)
- Tier 2: Stage-1 rollout (env-controlled)
- Tier 3: Explicit approvals (validated in Phase 33-4)
- Add A/B test automation script (tools/joinir_ab_test.sh)
- Update if_merge.rs and if_select.rs with debug_level support
Environment variables (with NYASH_* fallback for compatibility):
- HAKO_JOINIR_IF_SELECT: Enable JoinIR lowering
- HAKO_JOINIR_STAGE1: Enable Stage-1 function rollout
- HAKO_JOINIR_DEBUG: Debug log level (0-3)
A/B test verification: PASSED on joinir_if_merge_{simple,multiple}.hako
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-27 09:30:54 +09:00
5b7818f5c9
feat(joinir): Phase 33-7 IfMerge lowering for multiple-variable PHI
...
Implements IfMerge instruction lowering to support multiple variables
merging from if/else branches (Phase 33-7: return pattern only).
## Changes
- Add src/mir/join_ir/lowering/if_merge.rs (232 lines)
- IfMergeLowerer with pattern matching for common variables
- extract_written_vars() / find_written_value() helpers
- Phase 33-7 constraint: return pattern only (k_next=None)
- Update src/mir/join_ir/lowering/mod.rs
- Unified entry point: try_lower_if_to_joinir()
- Priority: IfMerge → Select → if_phi fallback
- Add IfMergeTest.* to whitelist
- Add unit tests in src/tests/mir_joinir_if_select.rs
- test_if_merge_simple_pattern (2 variables)
- test_if_merge_multiple_pattern (3 variables)
- All 7/7 tests PASS ✅
- Add reference test cases
- apps/tests/joinir_if_merge_simple.hako (2-var pattern)
- apps/tests/joinir_if_merge_multiple.hako (3-var pattern)
## Test Results
✅ Simple pattern (2 vars): merges=2, k_next=None
✅ Multiple pattern (3 vars): merges=3, k_next=None
✅ test result: ok. 7 passed; 0 failed
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-27 08:18:09 +09:00
2d30277e97
fix(joinir): Correct JsonShapeToMap function name and add Phase 33-5 test whitelist
...
Changes:
1. **Naming fix**: JsonShapeParser → JsonShapeToMap
- Updated function name in whitelist to match actual static box name
- Affected: JsonShapeToMap._read_value_from_pair/1 (lang/src/runtime/meta/json_shape_parser.hako)
2. **Phase 33-5 test whitelist**: Added Stage1JsonScannerTestBox.* pattern
- Enables A/B testing for Stage-B if/else patterns
- Test verified: Route A (if_phi) and Route B (Select) both RC=0 ✅
Testing:
- Route A (NYASH_JOINIR_IF_SELECT=0): RC 0 ✓
- Route B (NYASH_JOINIR_IF_SELECT=1): RC 0 ✓
- Pattern: simple if/else return (Stage1JsonScannerBox.value_start_after_key_pos/2 style)
Phase 33-5: Stage-B if/Select A/B testing実施完了
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-27 05:39:29 +09:00
79cbf26f98
Phase 33-4: Stage-1/Stage-B expansion complete (33-4.1 to 33-4.3)
...
## Code Changes
- Extended function name whitelist in try_lower_if_to_joinir()
- Added: JsonShapeParser._read_value_from_pair/1 (Stage-1)
- Added: Stage1JsonScannerBox.value_start_after_key_pos/2 (Stage-B)
## Validation
- A/B testing: Route A (if_phi) vs Route B (Select) → identical results (RC 0)
- Test cases: joinir_if_select_simple.hako, joinir_if_select_local.hako
- Build: cargo build --release successful
## Documentation (docs/private submodule)
- TASKS.md: Phase 33-4.1 to 33-4.3 marked complete
- if_joinir_design.md: Section 9 added (candidate analysis)
## Next Steps
- Phase 33-4.4: CI/smoke test updates (pending)
2025-11-27 04:58:01 +09:00
5cfb0e1d5b
Phase 33-3: If/PHI MIR pattern matching + Select lowering (minimal patterns)
...
Implementation:
- Implement MIR pattern matching in if_select.rs (simple/local patterns)
- Add try_lower_if_to_joinir() entry point in lowering/mod.rs
- Create comprehensive integration tests (4/4 passing)
Pattern Support:
- Simple pattern: if cond { return 1 } else { return 2 }
- Both blocks must have Return only (no instructions)
- Local pattern: if cond { x = a } else { x = b }; return x
- Each branch has exactly 1 Copy instruction
- Both branches jump to same merge block
- Merge block Returns the assigned variable
Safety Mechanisms:
- Dev toggle: NYASH_JOINIR_IF_SELECT=1 required
- Function name filter: Only IfSelectTest.* functions
- Fallback: Returns None on pattern mismatch
- Zero breaking changes: Existing if_phi path untouched
Tests (4/4 PASS):
- test_if_select_simple_pattern
- test_if_select_local_pattern
- test_if_select_disabled_by_default
- test_if_select_wrong_function_name
Files:
- Modified: src/mir/join_ir/lowering/if_select.rs (pattern matching)
- Modified: src/mir/join_ir/lowering/mod.rs (entry point)
- New: src/tests/mir_joinir_if_select.rs (integration tests)
- Modified: src/tests/mod.rs (module registration)
Phase 33-3.2/3.3 (legacy removal) pending
🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-27 03:28:32 +09:00
35cd93a37a
Phase 33-2: JoinInst::Select implementation + minimal If JoinIR lowering
...
Implementation:
- Add JoinInst::Select variant to JoinIR schema
- Implement Select execution in JoinIR Runner (Bool/Int cond support)
- Add Select handling in JoinIR→MIR Bridge (4-block structure)
- Create test cases (joinir_if_select_simple/local.hako)
- Add dev toggle NYASH_JOINIR_IF_SELECT=1
- Create lowering infrastructure (if_select.rs, stub for Phase 33-3)
Tests:
- 3/3 unit tests pass (test_select_true/false/int_cond)
- Integration tests pass (RC: 0)
- A/B execution verified (existing if_phi vs JoinIR Select)
Files changed:
- New: apps/tests/joinir_if_select_{simple,local}.hako
- New: src/mir/join_ir/lowering/if_select.rs
- Modified: src/mir/join_ir/{mod,json,runner,vm_bridge}.rs
- Modified: src/config/env.rs (joinir_if_select_enabled)
- Modified: docs/reference/environment-variables.md
Phase 33-3 ready: MIR pattern recognition + auto-lowering pending
🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-27 02:58:38 +09:00
ef9fd4417a
feat(phase31): Add LoopToJoinLowerer unified box
...
Phase 31 Step 1 complete:
- Create src/mir/join_ir/lowering/loop_to_join.rs
- Add LoopToJoinLowerer struct with lower() method
- Implement lower_minimal_skip_ws_case_a() via generic_case_a
- Support for trim, append_defs, stage1 patterns
- Re-export from mod.rs
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-26 01:18:32 +09:00
a898ff3f83
refactor(joinir): Phase 30 F-2.0/F-3 - PHI箱インベントリと旧APIレガシー削除
...
F-3 レガシー削除:
- generic_case_a.rs: 旧API関数4個削除(_with_scope 移行完了)
- loop_scope_shape.rs: CaseAContext::new() 削除(from_scope() に統一)
- mod.rs: 不要な pub use 削除
- #[allow(dead_code)] 除去(5関数)
- 未使用import削除(コード削減約150行)
F-2.0 PHI箱インベントリ:
- PHI_BOX_INVENTORY.md 作成: 13箱+11補助構造体の棚卸し
- 削除順ポリシー: 早期/中期/最終の3段階
- TASKS.md/CURRENT_TASK.md 更新
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-25 23:25:39 +09:00
31e458e7fa
refactor(joinir): introduce CaseAContext to consolidate common lowering logic
...
- Add CaseAContext struct in loop_scope_shape.rs to centralize:
- LoopForm validation
- intake_loop_form invocation
- LoopScopeShape construction
- Variable name → ValueId mapping
- pinned_ids/carrier_ids/exit_args resolution
- Refactor all 4 generic_case_a.rs functions to use CaseAContext:
- lower_case_a_loop_to_joinir_for_minimal_skip_ws
- lower_case_a_loop_to_joinir_for_trim_minimal
- lower_case_a_loop_to_joinir_for_append_defs_minimal
- lower_case_a_loop_to_joinir_for_stage1_usingresolver_minimal
- Remove unused name_to_header_id field from LoopFormIntake
(was duplicate of header_snapshot)
Code reduction: ~200 lines of duplicated pattern → 4 lines
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-25 06:32:08 +09:00
466e636af6
Span trace utilities and runner source hint
2025-11-24 14:17:02 +09:00
b7c7e48526
feat(joinir): Phase 27.14 - FuncScannerBox._append_defs JoinIR lowering完了 + コード品質改善
...
## Phase 27.14: FuncScannerBox._append_defs/2 JoinIR lowering
- **新規実装**: `funcscanner_append_defs.rs` (322行)
- Shared Builder Pattern採用
- MIR-based lowering with CFG sanity checks
- ValueId range 9000-10999 割り当て
- **テスト**: `mir_joinir_funcscanner_append_defs.rs` (3テスト)
- type_sanity, empty_module_returns_none, auto_lowering (ignored)
- **最小.hako**: `funcscanner_append_defs_minimal.hako`
## コード品質改善 (5項目完了)
1. **CFG Sanity Checks強化** (`common.rs`)
- `has_array_method()`: ArrayBox操作検出
- `has_loop_increment()`: i+1パターン検出
2. **ValueIdテスト自動化** (`value_id_ranges.rs`)
- マクロ化 + 自動overlap検証で30→15行に削減
3. **モジュール名統一確認** (作業不要、既に統一済み)
4. **Shared Builder命名統一** (`funcscanner_trim.rs`)
- `build_trim_joinir` → `build_funcscanner_trim_joinir`
5. **全テストPASS確認**
- value_id_ranges, funcscanner_trim, funcscanner_append_defs全てPASS ✅
## 効果
- CFG検証関数: 1個 → 3個 (200%↑)
- テストコード: 50%削減 (保守性向上)
- 命名一貫性: 75% → 100%
- ビルド成功率: 100%維持
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-24 05:23:26 +09:00
a554109b8e
refactor(phase27.13): Introduce ValueId range management system
...
Introduce centralized ValueId range allocation to prevent ID conflicts
between lowering modules.
Changes:
1. New file: src/mir/join_ir/lowering/value_id_ranges.rs
- Base address constants for each lowering module
- Helper functions: entry(offset), loop_step(offset)
- Range validation test: test_value_id_ranges_no_overlap
2. Range allocation (resolved conflict):
- min_loop: 1000-2999 (entry: 1000+, loop: 2000+)
- skip_ws: 3000-4999 (entry: 3000+, loop: 4000+)
- funcscanner_trim: 5000-6999 (entry: 5000+, loop: 6000+)
- stage1_using_resolver: 7000-8999 (entry: 7000+, loop: 8000+) ← CHANGED
3. Updated stage1_using_resolver.rs to use value_id_ranges helpers
- ValueId(5000) → vid::entry(0) // 7000
- ValueId(6000) → vid::loop_step(0) // 8000
4. Updated lowering/mod.rs to include value_id_ranges module
Results:
- ✅ Build success (warnings only, no errors)
- ✅ Tests: 2/2 existing tests pass (type_sanity, empty_module_returns_none)
- ✅ value_id_ranges test pass (range overlap validation)
- ✅ ValueId conflict resolved (trim vs stage1_using_resolver)
Benefits:
- Centralized range management prevents conflicts
- Type-safe: const fn for compile-time calculation
- Self-documenting: comments clarify ranges
- Easy extension: future lowerings can use 9000+, 11000+, etc.
2025-11-24 03:58:30 +09:00
f257070668
feat(joinir): Phase 27.12 完了 - Stage1UsingResolver 骨格+テスト実装
...
Phase 27.12 実装内容:
- ✅ JoinIR lowering 骨格実装 (169行)
- stage1_using_resolver.rs 新規作成
- Shared Builder Pattern 適用
- MIR-based/handwritten 両経路対応
- ✅ テスト基盤整備 (3本)
- auto_lowering テスト (#[ignore] + トグル)
- type_sanity テスト (常時実行)
- no_panic テスト (軽量)
- ✅ ドキュメント更新
- 論文に Phase 27.12 完了記録
- IMPLEMENTATION_LOG.md 完了マーク
- TASKS.md チェックボックス更新
技術詳細:
- LoopForm Case A (loop(i < n))
- Pinned: entries/n/modules/seen
- Carrier: i/prefix
- Exit: prefix
- CFG sanity checks 骨格実装
- Graceful degradation 設計
ビルド: ✅ 成功 (0 エラー)
次: Phase 27.13 JoinIR 本実装
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-24 02:34:36 +09:00
ff9ea58e59
refactor(joinir): Phase 27.10 - CFG sanity checks + dispatcher pattern 共通化
...
- common.rs 新規作成(162行):
- CFG sanity check helpers: ensure_entry_has_succs, has_const_int, has_const_string, has_string_method, has_binop
- Logging helper: log_fallback
- Dispatcher: dispatch_lowering
- skip_ws.rs: CFG checks (-25行) + dispatcher (-2行) = -27行削減
- funcscanner_trim.rs: CFG checks (-25行) + dispatcher (-4行) = -29行削減
- mod.rs: pub mod common 追加
設計原則:
- 軽量パターンマッチング(命令の存在確認のみ)
- Graceful degradation(予期しない構造で即座にfallback)
- DRY原則(重複コード1箇所に集約)
🎉 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-23 22:51:30 +09:00
3d5979c78e
refactor(joinir): Phase 27.9 - Modular separation of join_ir.rs into directory structure
...
Phase 27.9 で join_ir.rs (~1,336行) を以下のモジュール構造に分離:
## 新規ディレクトリ構造:
```
src/mir/join_ir/
├── mod.rs # 型定義・共通ユーティリティ (~330行)
└── lowering/
├── mod.rs # lowering インターフェース
├── min_loop.rs # lower_min_loop_to_joinir (~140行)
├── skip_ws.rs # skip_ws lowering 3関数 (~390行)
└── funcscanner_trim.rs # trim lowering (~480行)
```
## 技術的変更:
- **型定義統一**: JoinFuncId, JoinInst, JoinModule 等を mod.rs に集約
- **lowering 分離**: 3つの lowering 関数を個別モジュールに移動
- **後方互換性**: pub use で lowering 関数を re-export(既存コード影響なし)
- **削除**: src/mir/join_ir.rs (旧単一ファイル)
## テスト結果:
- **385 passed** (+1 from 384)
- **9 failed** (-1 from 10)
- **ビルド成功**: 0 errors, 18 warnings (変化なし)
## 効果:
- **保守性向上**: 1,336行 → 4ファイル(各300-500行)で可読性向上
- **モジュール境界明確化**: 型定義 vs lowering 実装の責務分離
- **将来の拡張容易**: 新 lowering 関数追加が簡単に
Phase 27.8 で実装した MIR 自動解析 lowering の基盤整備完了。
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-23 16:49:49 +09:00