Files
hakorune/docs/development/current/main/phases/phase-136
nyash-codex 905a2b97fe refactor(mir): Extract CompilationContext from MirBuilder (Phase 136 follow-up 7/7)
## Summary
Extracted compilation-related fields into dedicated CompilationContext struct,
completing all 7 steps of the Context Box refactoring plan. This is the final
major context extraction, consolidating 15 compilation-specific fields.

## Changes
- NEW: src/mir/builder/compilation_context.rs (435 lines, 15 fields)
- Modified: src/mir/builder.rs (added compilation_ctx field + sync helpers)
- Updated: phase-136-context-box-progress.md (7/7 complete)
- Created: step-7-compilation-context-summary.md (detailed documentation)

## Extracted Fields (15 total)
- compilation_context - Box compilation context
- current_static_box - Currently compiling static box name
- user_defined_boxes - User-defined box registry
- reserved_value_ids - Reserved ValueIds (for PHI nodes)
- fn_body_ast - Function body AST (for capture analysis)
- weak_fields_by_box - Weak field registry
- property_getters_by_box - Property getter registry
- field_origin_class - Field origin tracking
- field_origin_by_box - Class-level origin
- static_method_index - Static method index
- method_tail_index - Method tail fast lookup
- method_tail_index_source_len - Source size snapshot
- type_registry - Unified type information
- current_slot_registry - Function-scope SlotRegistry
- plugin_method_sigs - Plugin method signatures

## Tests
- cargo test --release --lib: 1029/1033 passed (4 pre-existing failures)
- phase135_trim_mir_verify.sh: PASS
- Backward compatibility: 100% maintained (deprecated fields synced)

## Phase 136 Context Extraction: Complete! 

Total: 7 contexts, 36 fields extracted, 1086 lines of new modules
-  Step 1: TypeContext (3 fields, 130 lines)
-  Step 2: CoreContext (5 fields, 112 lines)
-  Step 3: ScopeContext (7 fields, 141 lines)
-  Step 4: BindingContext (1 field, 63 lines)
-  Step 5: VariableContext (1 field, 85 lines)
-  Step 6: MetadataContext (4 fields, 120 lines)
-  Step 7: CompilationContext (15 fields, 435 lines)

## Next Phase: Legacy Field Removal
Phase 2 will remove all 36 deprecated fields from MirBuilder,
eliminating 469 deprecation warnings and reducing builder.rs from
1472 → ~800-900 lines (500-600 line reduction).

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

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2025-12-15 22:17:38 +09:00
..

Phase 136: ValueId allocator SSOT 徹底(残存 value_gen.next() 掃討)

Status

  • 状態: P0 完了
  • スコープ: 関数内 ValueId 発行を MirBuilder::next_value_id() に一本化し、予約PHI/引数/ローカルとの衝突余地を消す

Problem

Phase 135 で契約allocator SSOTは固まったが、一部のコードで builder.value_gen.next() を直接使用していた。 これは関数内で走る場合、予約PHI dst や関数引数との ValueId 衝突を引き起こす可能性がある。

Fix

SSOT 化対象

  1. src/mir/builder.rs:new_typed_value() - 型付きValueId発行API

    • Before: let id = self.value_gen.next();
    • After: let id = self.next_value_id(); (関数コンテキストを尊重)
  2. テストコード内の value_gen.next() - 関数スコープをシミュレート

    • test_shadowing_binding_restore: 関数スコープシミュレーションで next_value_id() を使用
    • test_valueid_binding_parallel_allocation: SSOT allocator を使用Module context フォールバック維持)

OKModule context フォールバック)

以下は既に if current_function.is_some() で関数コンテキストを判定しており、Module context のフォールバックとして value_gen.next() を使用OK

  • src/mir/builder/utils.rs:next_value_id() - SSOT allocator 自体43行目
  • src/mir/builder/utils.rs:pin_to_slot() - 436行目
  • src/mir/builder/utils.rs:materialize_local() - 467行目
  • src/mir/utils/phi_helpers.rs:insert_phi_unified() - 69行目

Acceptance

  • rg -n "value_gen\.next\(" src/mir で関数内経路から消える
  • cargo test --release --lib - 997 passed
  • phase135_trim_mir_verify.sh - PASS
  • phase132_exit_phi_parity.sh - 3/3 PASS

Remaining Tasks残課題

なし。全ての関数内経路から value_gen.next() を排除完了。Module context のフォールバックは意図的に残す。