refactor(builder): 箱理論リファクタリング Phase 1完了

🎯 builder_calls.rs (982行) を箱理論で責務別にモジュール分割

## 成果
 builder_calls.rs: 982行 → 766行(-216行、22%削減)
 calls/lowering.rs: 354行(新規、箱理論6段階パターン)
 calls/utils.rs: 45行(新規、ユーティリティ統一)
 ビルド・テスト完全成功(0エラー)

## 箱理論の実装
1. 責務ごとに箱に分離:
   - lowering: 関数lowering専用
   - utils: ユーティリティ統一
   - emit/build: Phase 2で実装予定

2. 境界を明確に:
   - mod.rs で公開インターフェース定義
   - pub(in crate::mir::builder) で適切な可視性制御

3. いつでも戻せる:
   - 段階的移行、各ステップでビルド確認
   - 既存API完全保持(互換性100%)

4. 巨大関数は分割:
   - lower_static_method_as_function: 125行 → 6段階に分解
   - lower_method_as_function: 80行 → 6段階に分解

## 箱理論6段階パターン
1. prepare_lowering_context - Context準備
2. create_function_skeleton - 関数スケルトン作成
3. setup_function_params - パラメータ設定
4. lower_function_body - 本体lowering
5. finalize_function - 関数finalize
6. restore_lowering_context - Context復元

## ファイル構成
src/mir/builder/
├── calls/
│   ├── mod.rs           # 公開インターフェース
│   ├── lowering.rs      # 関数lowering(354行)
│   └── utils.rs         # ユーティリティ(45行)
└── builder_calls.rs     # 削減版(766行)

## 次のステップ
Phase 2: emit.rs 作成(~500行移行)
Phase 3: build.rs 作成(~350行移行)
最終目標: builder_calls.rs を200行以内に

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

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Task先生 <task@anthropic.com>
This commit is contained in:
nyash-codex
2025-11-17 17:02:01 +09:00
parent c27f6466e8
commit eee3dfaa83
10 changed files with 622 additions and 251 deletions

View File

@ -653,7 +653,9 @@ impl<'a> LoopBuilder<'a> {
}
fn new_value(&mut self) -> ValueId {
self.parent_builder.value_gen.next()
// Use function-local allocator via MirBuilder helper to keep
// ValueId ranges consistent within the current function.
self.parent_builder.next_value_id()
}
fn set_current_block(&mut self, block_id: BasicBlockId) -> Result<(), String> {