Files
hakorune/src/mir/phi_core/mod.rs
nyash-codex 020fbc6740 refactor(phi_core): Phase 193 - Complete loopform modularization with 4-pass architecture
Phase 193: loopform_builder.rs modularization (1,166 → 102 lines, 91% reduction)

## Module Structure Created

```
src/mir/phi_core/loopform/
├── mod.rs                            (102 lines) - Public API coordinator
├── context.rs                        (148 lines) - ValueId management
├── variable_models.rs                (101 lines) - Variable types
├── utils.rs                          (112 lines) - Utilities
├── exit_phi.rs                       (96 lines) - Exit PHI builder
├── builder_core.rs                   (411 lines) - Core builder logic
├── passes/
│   ├── mod.rs                        (67 lines) - Pass coordinator
│   ├── pass1_discovery.rs            (156 lines) - Variable discovery
│   ├── pass2_preheader.rs            (70 lines) - Preheader copies
│   ├── pass3_header_phi.rs           (106 lines) - Header PHI construction
│   └── pass4_seal.rs                 (276 lines) - PHI completion
```

## 4-Pass Architecture Explicit

### Pass 1: Variable Discovery (pass1_discovery.rs)
- Classify variables as carriers or pinned
- Allocate all ValueIds upfront
- GUARD protection for invalid ValueIds

### Pass 2: Preheader Copy (pass2_preheader.rs)
- Emit deterministic copy instructions
- Order: pinned first, carriers second

### Pass 3: Header PHI Construction (pass3_header_phi.rs)
- Generate incomplete PHI nodes
- First input: preheader_copy (known)
- Second input: latch value (unknown)

### Pass 4: PHI Sealing (pass4_seal.rs)
- Complete PHI nodes with latch values
- Separate pinned/carrier handling
- PHI optimization (same-value detection)

## Size Comparison

Before:
- loopform_builder.rs: 1,166 lines (monolithic)
- loopform_passes.rs: 133 lines (documentation stub)
- Total: 1,299 lines in 2 files

After:
- 11 focused modules: 1,645 lines total
- Main file (mod.rs): 102 lines (91% reduction)
- Largest module: builder_core (411 lines)
- Average module size: 150 lines
- 4 pass modules: 608 lines (explicit structure)

## Success Criteria Met

 Directory structure created with 11 focused modules
 4-pass architecture explicit and clear
 cargo build --release succeeds
 Loop programs execute correctly
 Zero breaking changes (all APIs compatible)
 Module documentation comprehensive
 All visibility correct (pub/pub(crate) appropriate)

## Files Modified

- NEW: src/mir/phi_core/loopform/mod.rs (public API)
- NEW: src/mir/phi_core/loopform/builder_core.rs (core builder)
- NEW: src/mir/phi_core/loopform/passes/*.rs (4 pass modules)
- MOVED: loopform_*.rs → loopform/*.rs (5 files)
- DELETED: loopform_builder.rs, loopform_passes.rs
- UPDATED: phi_core/mod.rs (import structure)
- UPDATED: json_v0_bridge/lowering/loop_.rs (import path)

## Impact

- **Maintainability**: Each pass has clear responsibilities
- **Testability**: Individual passes can be tested independently
- **Documentation**: Comprehensive module and pass documentation
- **Modularity**: Clean separation of concerns
- **Readability**: No file exceeds 411 lines

Phase 1-3 modularization complete. Ready for new feature development.
2025-12-05 21:58:54 +09:00

54 lines
2.1 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*!
* phi_core Unified PHI management scaffold (Phase 1)
*
* Purpose:
* - Provide a single, stable entry point for PHI-related helpers.
* - Start with re-exports of existing, verified logic (zero behavior change).
* - Prepare ground for gradual consolidation of loop PHI handling.
*/
pub mod common;
pub mod conservative;
// Phase 84-5: if_phi 削除(レガシーフォールバック完全削除)
// Phase 30 F-2.1: loop_phi 削除LoopFormBuilder が SSOT
pub mod loop_snapshot_merge;
// Phase 191-193: LoopForm modularization - complete directory structure
pub mod loopform;
// Trio legacy boxes removed in Phase 70: LoopScopeShape now owns classification/liveness.
// Phase 26-B: Box-First Refactoring
// Phase 30 F-2.1: body_local_phi_builder 削除LoopScopeShape で代替)
// Phase 62: phi_input_collector 削除(インライン化完了)
// Phase 26-C: Loop Snapshot Management
// Phase 30 F-2.1: header_phi_builder 削除JoinIR loop_step で代替)
// Phase 30 F-2.2: loop_snapshot_manager 削除(テスト専用、外部呼び出しなし)
// Phase 26-D: Exit PHI Management
// Phase 30 F-2.1: exit_phi_builder 削除JoinIR k_exit で代替、バイパス関数は loopform_builder に移動)
// Phase 26-E: PHI SSOT Unification - PhiBuilderBox
pub mod phi_builder_box;
// Phase 84-2: Copy命令型伝播箱ChatGPT Pro設計
pub mod copy_type_propagator;
// Phase 84-3: PHI + Copy グラフ型推論箱ChatGPT Pro設計
pub mod phi_type_resolver;
// Phase 84-5: テスト専用ユーティリティif_phi.rs から移動)
pub mod test_utils;
// Phase 35-5: if_body_local_merge 削除PhiBuilderBoxに吸収済み
// Phase 35-5: phi_invariants 削除JoinIR Verifierに移譲済み
// Phase 61-7.0: Dead code 削除
// 削除された facade 関数:
// - build_if_phis(): 呼び出し元ゼロ、PhiBuilderBox::generate_phis() で代替
// - build_exit_phis_for_control(): 呼び出し元は loopform_builder:: を直接使用
//
// 直接呼び出し推奨:
// - If PHI: PhiBuilderBox::generate_phis() (if_lowering.rs)
// - Exit PHI: loopform_builder::build_exit_phis_for_control() (loop_form.rs)