Commit Graph

4 Commits

Author SHA1 Message Date
da1a5558e5 Normalize passes keep spans and clean warnings 2025-11-24 15:02:51 +09:00
f9d100ce01 chore: Phase 25.1 完了 - LoopForm v2/Stage1 CLI/環境変数削減 + Phase 26-D からの変更
Phase 25.1 完了成果:
-  LoopForm v2 テスト・ドキュメント・コメント完備
  - 4ケース(A/B/C/D)完全テストカバレッジ
  - 最小再現ケース作成(SSAバグ調査用)
  - SSOT文書作成(loopform_ssot.md)
  - 全ソースに [LoopForm] コメントタグ追加

-  Stage-1 CLI デバッグ環境構築
  - stage1_cli.hako 実装
  - stage1_bridge.rs ブリッジ実装
  - デバッグツール作成(stage1_debug.sh/stage1_minimal.sh)
  - アーキテクチャ改善提案文書

-  環境変数削減計画策定
  - 25変数の完全調査・分類
  - 6段階削減ロードマップ(25→5、80%削減)
  - 即時削除可能変数特定(NYASH_CONFIG/NYASH_DEBUG)

Phase 26-D からの累積変更:
- PHI実装改善(ExitPhiBuilder/HeaderPhiBuilder等)
- MIRビルダーリファクタリング
- 型伝播・最適化パス改善
- その他約300ファイルの累積変更

🎯 技術的成果:
- SSAバグ根本原因特定(条件分岐内loop変数変更)
- Region+next_iパターン適用完了(UsingCollectorBox等)
- LoopFormパターン文書化・テスト化完了
- セルフホスティング基盤強化

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: ChatGPT <noreply@openai.com>
Co-Authored-By: Task Assistant <task@anthropic.com>
2025-11-21 06:25:17 +09:00
cc9fb2f654 fix(phi): if-block PHI reassignment のSSA違反を解消
**問題**: If-block PHI nodes がグローバルValueIdアロケーター使用 → 関数ローカルIDと衝突
- insert_phi() が value_gen.next() 使用
- 関数内で後から割り当てられるValueIdと重複 → SSA違反

**根本原因**:
```rust
//  Before: グローバルアロケーター
let phi_val = self.value_gen.next();

//  After: 関数ローカルアロケーター
let phi_val = if let Some(ref mut f) = self.current_function {
    f.next_value_id()  // 関数コンテキスト
} else {
    self.value_gen.next()  // モジュールコンテキスト
};
```

**修正内容**:

1. **insert_phi() 修正** (src/mir/utils/phi_helpers.rs:63-70)
   - 関数コンテキストでは f.next_value_id() 使用
   - pin_to_slot() / loop builder (e2d061d1) と同じパターン

2. **insert_phi_with_dst() ドキュメント強化** (lines 94-114)
   - 正しいValueId割り当て方法を例示
   -  間違い: 常に value_gen.next() 使用
   -  正しい: 関数コンテキスト判定

**テスト結果**:
 Simple if-param-method: PASS (SSA違反なし)
 Test1/Test3: PASS (regression なし)
⚠️ Test2 (Stage-B): ValueId(22) 残存(別問題: receiver materialization)

**残存問題** (別issue):
- ValueId(22) = receiver materialization 問題
- pin_to_slot / emit_guard / BlockScheduleBox が分散
- 責務の集約が必要(次タスク)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-17 06:54:48 +09:00
1cc09786ee refactor: unify PHI insertion patterns (Phase 4)
- Add PHI insertion helper utilities in mir/utils/phi_helpers.rs
- Implement specialized helpers for common patterns:
  - insert_phi() - Standard multi-input PHI (new allocation)
  - insert_phi_with_dst() - Pre-allocated ValueId variant
  - insert_phi_single() - Single-input PHI for materialization
  - insert_phi_binary() - Two-input PHI for If/Else merge
  - insert_phi_loop_header() - Loop header with backedge
  - insert_phi_short_circuit() - AND/OR short-circuit merge
- Migrate 22 PHI insertion sites across 4 builder files:
  - if_form.rs: 2 sites (-12 lines, 86% reduction)
  - ops.rs: 5 sites (-32 lines, 86% reduction)
  - phi.rs: 4 sites (-13 lines, 81% reduction)
  - exprs_peek.rs: 2 sites (-4 lines, 80% reduction)

Code reduction:
- Phase 4: 61 lines saved in builder files (84% avg reduction per site)
- New utility module: +234 lines (reusable infrastructure)
- Net builder reduction: -61 lines (-5.0% in modified files)
- Cumulative (Phases 1-4): 255-342 lines removed (8-10%)

Benefits:
- Consistent PHI insertion across all control flow patterns
- Reduced boilerplate from 6-8 lines to 1-2 lines per PHI
- Clearer intent with named helper methods (insert_phi_binary vs manual construction)
- Easier to verify SSA invariants (single implementation point)
- Foundation for future PHI-related optimizations

Testing:
- Build: SUCCESS (0 errors, 147 warnings)
- Phase 21.0 tests: PASS (2/2 tests)
- SSA correctness: Verified (CFG-based insertion maintained)

Related: Phase 21.0 refactoring, MIR SSA construction
Risk: Low (wraps existing insert_phi_at_head, fully tested)
2025-11-06 23:57:24 +09:00