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
b7a421acc8
fix(test): Update test_local_declarations_with_acc for Phase 56 MethodCall change
...
Phase 56 changed LoopFrontendBinding::for_array_filter() from
BoundExpr::Variable("n") to BoundExpr::MethodCall { arr, size }.
Updated test expectations:
- Changed from expecting Var type to Method type
- Added assertions for receiver structure (Var node with "arr")
- Added assertion for method name ("size")
Test result: All 8 loop_frontend_binding tests PASS
Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-12-04 10:33:47 +09:00
7a1a4bd964
refactor(mir): loop_builder.rs モジュール化 - 6ファイルに分割
...
## リファクタリング内容
### ファイル構造変更
- `src/mir/loop_builder.rs` (1515行) 削除
- `src/mir/loop_builder/` ディレクトリ新設(6ファイル、1529行)
### 新規モジュール構成
1. **mod.rs** (6,293行 → 実際は約150行)
- モジュール定義とre-export
- LoopBuilder構造体定義
2. **loop_form.rs** (25,988行 → 実際は約650行)
- メインループlowering pipeline
- デバッグ/実験フラグ集約
3. **if_lowering.rs** (15,600行 → 実際は約390行)
- In-loop if lowering with JoinIR/PHI bridge
- **Phase 61-2コード完全保持**:
- JoinIR dry-run検証モード
- PhiSpec計算とA/B比較
4. **phi_ops.rs** (12,844行 → 実際は約320行)
- PHI emit helpers
- LoopFormOps/PhiBuilderOps impls
5. **control.rs** (4,261行 → 実際は約107行)
- break/continue capture
- predecessor bookkeeping
6. **statements.rs** (1,673行 → 実際は約42行)
- loop-body statement lowering entry point
7. **README.md** (752行 → 実際は約19行)
- モジュール責務とサブモジュール説明
### 設計原則
- **責務分離**: CFG構築/PHI生成/制御フロー/文処理を分離
- **Phase 61-2保持**: if_lowering.rsにJoinIR dry-run完全移行
- **phi_core委譲**: PHI構築ロジックは`phi_core`に委譲
## テスト結果
- Phase 61-2テスト: ✅ 2/2 PASS(dry-runフラグ、PhiSpec)
- loopformテスト: ✅ 14/14 PASS(退行なし)
- ビルド: ✅ 成功(エラー0件)
## 統計
- **純削減**: -1,521行(25ファイル変更)
- **loop_builder**: 1515行 → 1529行(+14行、6ファイル化)
- **可読性**: 巨大単一ファイル → 責務別モジュール
## ChatGPT設計・Claude確認
大規模リファクタリングをChatGPTが実施、Claudeが検証完了。
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-29 12:44:40 +09:00
ad9daf37ac
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
e27934d91a
feat(joinir): Phase 52-53 LoopFrontendBinding JSON + Statement Handlers
...
Phase 52: LoopFrontendBinding JSON generation fixes
- Add receiver_to_json() for Field node structure (me.tokens)
- Add needs_me_receiver() for instance method detection
- Fix "condition" → "cond" key for JoinIR Frontend
- Add me parameter propagation in loop_patterns.rs
- Add JoinIR-compatible type fields in ast_json.rs
- Variable → "type": "Var"
- Literal → "type": "Int"/"Bool" (literal_to_joinir_json)
- BinaryOp → "type": "Binary"/"Compare" (is_compare_op)
- MethodCall → "type": "Method"
Phase 53: Statement Handler module for loop body
- NEW: stmt_handlers.rs with StatementEffect type
- Support: Local, Assignment, Print, Method, If statements
- If lowering: single variable update → Select instruction
- Remove hardcoded assert in loop_patterns.rs
- Replace with generic lower_statement() calls
Test results: 56 JoinIR tests PASS, 7 loop_frontend_binding tests PASS
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-29 04:42:16 +09:00
3dc691d39f
feat(joinir): Phase 50 Loop Frontend Binding layer
...
Phase 50 implements the Loop Frontend Binding layer that maps
actual loop variables to JoinIR Frontend's expected names (i, acc, n).
## Changes
- Add loop_frontend_binding.rs module with:
- LoopFrontendBinding struct for variable mapping
- for_print_tokens() and for_array_filter() factory methods
- generate_local_declarations() for JSON v0 format
- rename_body_variables() for out → acc renaming
- Integrate binding with cf_loop_joinir_impl:
- Create binding based on function name
- Inject i/acc/n Local declarations into JSON v0
- Use correct JoinIR Frontend type names (Int/Var/Method)
## Limitations Found
JoinIR Frontend doesn't support:
- Field access (me.tokens) - blocks print_tokens
- NewBox (new ArrayBox()) - blocks array_filter
These will be addressed in Phase 51.
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-11-28 20:59:54 +09:00