feat(mir): Phase 136 Step 2/7 - CoreContext extraction complete

Extract core ID generation fields from MirBuilder to improve organization:
- value_gen: ValueIdGenerator
- block_gen: BasicBlockIdGenerator
- next_binding_id: u32 (Phase 74)
- temp_slot_counter: u32
- debug_join_counter: u32

Implementation:
- Created src/mir/builder/core_context.rs (215 lines)
- Added core_ctx field to MirBuilder as SSOT
- Deprecated legacy fields with backward compat
- ID allocation methods use core_ctx and sync legacy fields
- Added next_block_id() helper, replaced 30+ block_gen.next() calls

Testing:
- cargo build --release: SUCCESS (193 warnings expected)
- cargo test --release --lib: 1004/1004 PASS (+7 tests)
- phase135_trim_mir_verify.sh: PASS
- phase132_exit_phi_parity.sh: 3/3 PASS

Progress: 2/7 Context extractions complete (TypeContext + CoreContext)

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-12-15 20:10:36 +09:00
parent 076f193f76
commit 81d79161e4
12 changed files with 325 additions and 61 deletions

View File

@ -4,7 +4,7 @@
builder.rs の 1219 行を責任ごとに Context Box に分割し、保守性・テスト容易性を向上させる段階的リファクタリング。
## 完了した Context (1/7)
## 完了した Context (2/7)
### ✅ TypeContext (Step 1) - 完了
@ -33,14 +33,41 @@ builder.rs の 1219 行を責任ごとに Context Box に分割し、保守性
- 16 ファイルで 113 箇所が deprecated フィールドを使用中
- 段階的移行により破壊的変更なし
**コミット**: 076f193f
### ✅ CoreContext (Step 2) - 完了
**実装日**: 2025-12-15
**抽出したフィールド** (5個):
- `value_gen: ValueIdGenerator` - SSA 値 ID 生成器
- `block_gen: BasicBlockIdGenerator` - 基本ブロック ID 生成器
- `next_binding_id: u32` - BindingId 割り当てカウンタ (Phase 74)
- `temp_slot_counter: u32` - 一時ピンスロットカウンタ
- `debug_join_counter: u32` - デバッグスコープ join ID カウンタ
**ファイル**:
- `/home/tomoaki/git/hakorune-selfhost/src/mir/builder/core_context.rs` (新規作成)
**統合方法**:
- `MirBuilder``core_ctx: CoreContext` フィールドを追加
- 既存フィールドは `#[deprecated]` でマーク(後方互換性維持)
- ID 割り当てメソッド (`next_value_id()`, `allocate_binding_id()`, `debug_next_join_id()`) が core_ctx を SSOT として使用し、legacy フィールドを同期
- 新規ヘルパー `next_block_id()` を追加し、30 箇所の `block_gen.next()` 呼び出しを置換
**テスト結果**:
-`cargo build --release` 成功 (警告のみ、193 warnings)
-`cargo test --release --lib` - 1004/1004 PASS (7 tests 追加)
-`phase135_trim_mir_verify.sh` - PASS
-`phase132_exit_phi_parity.sh` - 3/3 PASS
**影響範囲**:
- builder 内 30+ ファイルで `block_gen.next()``next_block_id()` に自動置換
- 段階的移行により破壊的変更なし
**コミット**: (次回コミット時に記載)
## 残りの Context (6/7)
### 2. CoreContext (計画中)
- `value_gen: ValueIdGenerator`
- `block_gen: BasicBlockIdGenerator`
- `next_fn_id: u32` (将来追加予定)
## 残りの Context (5/7)
### 3. ScopeContext (計画中)
- `lexical_scope_stack: Vec<LexicalScopeFrame>`
@ -79,10 +106,10 @@ builder.rs の 1219 行を責任ごとに Context Box に分割し、保守性
## 次のステップ
**優先順位 2**: CoreContext 抽出
- ValueId/BlockId 生成の中核部分
- 依存関係が少なく、分離が容易
- テスト影響範囲が小さい
**優先順位 3**: ScopeContext 抽出
- スコープスタック管理の集約
- 制御フロースタック (loop/if/try) の統合
- 関数コンテキスト管理の整理
## 参考資料