Files
hakorune/docs/development/current/main/phases/phase-136/README.md

45 lines
2.5 KiB
Markdown
Raw Normal View History

# Phase 136: MirBuilder Context SSOT 化(+ ValueId allocator 掃討)
feat(mir): Phase 136 P0 - ValueId allocator SSOT 徹底(関数内経路から value_gen.next() 掃討) ## Summary Eliminates remaining `value_gen.next()` calls from function-context code paths, unifying all ValueId allocation through `MirBuilder::next_value_id()` SSOT allocator. ## Changes ### 1. Fixed `new_typed_value()` (src/mir/builder.rs:1068) **Before**: `let id = self.value_gen.next();` (bypasses function context) **After**: `let id = self.next_value_id();` (respects function context) This is a public API used in function context, so must use SSOT allocator to avoid collisions with reserved PHI dsts and function params. ### 2. Fixed test code (src/mir/builder.rs) **test_shadowing_binding_restore** (lines 1161, 1171): - Simulates function scope with `push_lexical_scope()` - Changed to `builder.next_value_id()` for function scope simulation **test_valueid_binding_parallel_allocation** (lines 1196-1216): - Tests ValueId/BindingId independence - Changed to `builder.next_value_id()` with note that Module context fallback preserves test intent ### 3. Verified Module context fallbacks (OK, no change needed) These already check `current_function.is_some()` and use `value_gen.next()` only as Module context fallback: - `src/mir/builder/utils.rs:43` - next_value_id() SSOT implementation - `src/mir/builder/utils.rs:436` - pin_to_slot() - `src/mir/builder/utils.rs:467` - materialize_local() - `src/mir/utils/phi_helpers.rs:69` - insert_phi_unified() ## Verification ```bash rg -n "value_gen\.next\(" src/mir --type rust | grep -v "Module context" | grep -v "//" # Result: Only comments/docs remain ``` ## Acceptance ✅ cargo test --release --lib - 997 passed ✅ phase135_trim_mir_verify.sh - PASS ✅ phase132_exit_phi_parity.sh - 3/3 PASS ✅ All function-context `value_gen.next()` eliminated ## Effect - **Collision prevention**: No more ValueId collisions between function-level allocations and reserved PHI dsts - **SSOT compliance**: All ValueId allocation flows through single allocator - **Contract enforcement**: Phase 135 P1 contract_checks will catch violations immediately 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-15 19:37:30 +09:00
## Status
- 状態: ✅ Done
- スコープ:
- MirBuilder の状態を Contextへ分割し、状態の SSOT を Context に一本化する
- 併せて、関数内 ValueId 発行を `MirBuilder::next_value_id()` に一本化し、予約PHI/引数/ローカルとの衝突余地を消す
feat(mir): Phase 136 P0 - ValueId allocator SSOT 徹底(関数内経路から value_gen.next() 掃討) ## Summary Eliminates remaining `value_gen.next()` calls from function-context code paths, unifying all ValueId allocation through `MirBuilder::next_value_id()` SSOT allocator. ## Changes ### 1. Fixed `new_typed_value()` (src/mir/builder.rs:1068) **Before**: `let id = self.value_gen.next();` (bypasses function context) **After**: `let id = self.next_value_id();` (respects function context) This is a public API used in function context, so must use SSOT allocator to avoid collisions with reserved PHI dsts and function params. ### 2. Fixed test code (src/mir/builder.rs) **test_shadowing_binding_restore** (lines 1161, 1171): - Simulates function scope with `push_lexical_scope()` - Changed to `builder.next_value_id()` for function scope simulation **test_valueid_binding_parallel_allocation** (lines 1196-1216): - Tests ValueId/BindingId independence - Changed to `builder.next_value_id()` with note that Module context fallback preserves test intent ### 3. Verified Module context fallbacks (OK, no change needed) These already check `current_function.is_some()` and use `value_gen.next()` only as Module context fallback: - `src/mir/builder/utils.rs:43` - next_value_id() SSOT implementation - `src/mir/builder/utils.rs:436` - pin_to_slot() - `src/mir/builder/utils.rs:467` - materialize_local() - `src/mir/utils/phi_helpers.rs:69` - insert_phi_unified() ## Verification ```bash rg -n "value_gen\.next\(" src/mir --type rust | grep -v "Module context" | grep -v "//" # Result: Only comments/docs remain ``` ## Acceptance ✅ cargo test --release --lib - 997 passed ✅ phase135_trim_mir_verify.sh - PASS ✅ phase132_exit_phi_parity.sh - 3/3 PASS ✅ All function-context `value_gen.next()` eliminated ## Effect - **Collision prevention**: No more ValueId collisions between function-level allocations and reserved PHI dsts - **SSOT compliance**: All ValueId allocation flows through single allocator - **Contract enforcement**: Phase 135 P1 contract_checks will catch violations immediately 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-15 19:37:30 +09:00
## Problem
MirBuilder が肥大化し、以下が同時に起きやすい状態だった:
- 状態の置き場所が分散し、変更者が「何を触っているか」を追いづらい
- ValueId の発行が局所的に `value_gen.next()` へ逃げると、関数内で衝突しうるPhase 135 の契約を破りやすい)
feat(mir): Phase 136 P0 - ValueId allocator SSOT 徹底(関数内経路から value_gen.next() 掃討) ## Summary Eliminates remaining `value_gen.next()` calls from function-context code paths, unifying all ValueId allocation through `MirBuilder::next_value_id()` SSOT allocator. ## Changes ### 1. Fixed `new_typed_value()` (src/mir/builder.rs:1068) **Before**: `let id = self.value_gen.next();` (bypasses function context) **After**: `let id = self.next_value_id();` (respects function context) This is a public API used in function context, so must use SSOT allocator to avoid collisions with reserved PHI dsts and function params. ### 2. Fixed test code (src/mir/builder.rs) **test_shadowing_binding_restore** (lines 1161, 1171): - Simulates function scope with `push_lexical_scope()` - Changed to `builder.next_value_id()` for function scope simulation **test_valueid_binding_parallel_allocation** (lines 1196-1216): - Tests ValueId/BindingId independence - Changed to `builder.next_value_id()` with note that Module context fallback preserves test intent ### 3. Verified Module context fallbacks (OK, no change needed) These already check `current_function.is_some()` and use `value_gen.next()` only as Module context fallback: - `src/mir/builder/utils.rs:43` - next_value_id() SSOT implementation - `src/mir/builder/utils.rs:436` - pin_to_slot() - `src/mir/builder/utils.rs:467` - materialize_local() - `src/mir/utils/phi_helpers.rs:69` - insert_phi_unified() ## Verification ```bash rg -n "value_gen\.next\(" src/mir --type rust | grep -v "Module context" | grep -v "//" # Result: Only comments/docs remain ``` ## Acceptance ✅ cargo test --release --lib - 997 passed ✅ phase135_trim_mir_verify.sh - PASS ✅ phase132_exit_phi_parity.sh - 3/3 PASS ✅ All function-context `value_gen.next()` eliminated ## Effect - **Collision prevention**: No more ValueId collisions between function-level allocations and reserved PHI dsts - **SSOT compliance**: All ValueId allocation flows through single allocator - **Contract enforcement**: Phase 135 P1 contract_checks will catch violations immediately 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-15 19:37:30 +09:00
## Fix
### 1) Context 分割(状態の SSOT を一本化)
- Type/Core/Scope/Binding/Variable/Metadata/Compilation の 7 Context へ分割し、二重管理sync helpersを撤去。
- 入口:
- `src/mir/builder/context.rs`
- `src/mir/builder/*_context.rs`
- 読む入口: `src/mir/builder/README.md`
### 2) ValueId allocator の SSOT 徹底(関数内経路の掃討)
- 例: `src/mir/builder.rs:new_typed_value()``self.next_value_id()` を唯一入口に統一。
feat(mir): Phase 136 P0 - ValueId allocator SSOT 徹底(関数内経路から value_gen.next() 掃討) ## Summary Eliminates remaining `value_gen.next()` calls from function-context code paths, unifying all ValueId allocation through `MirBuilder::next_value_id()` SSOT allocator. ## Changes ### 1. Fixed `new_typed_value()` (src/mir/builder.rs:1068) **Before**: `let id = self.value_gen.next();` (bypasses function context) **After**: `let id = self.next_value_id();` (respects function context) This is a public API used in function context, so must use SSOT allocator to avoid collisions with reserved PHI dsts and function params. ### 2. Fixed test code (src/mir/builder.rs) **test_shadowing_binding_restore** (lines 1161, 1171): - Simulates function scope with `push_lexical_scope()` - Changed to `builder.next_value_id()` for function scope simulation **test_valueid_binding_parallel_allocation** (lines 1196-1216): - Tests ValueId/BindingId independence - Changed to `builder.next_value_id()` with note that Module context fallback preserves test intent ### 3. Verified Module context fallbacks (OK, no change needed) These already check `current_function.is_some()` and use `value_gen.next()` only as Module context fallback: - `src/mir/builder/utils.rs:43` - next_value_id() SSOT implementation - `src/mir/builder/utils.rs:436` - pin_to_slot() - `src/mir/builder/utils.rs:467` - materialize_local() - `src/mir/utils/phi_helpers.rs:69` - insert_phi_unified() ## Verification ```bash rg -n "value_gen\.next\(" src/mir --type rust | grep -v "Module context" | grep -v "//" # Result: Only comments/docs remain ``` ## Acceptance ✅ cargo test --release --lib - 997 passed ✅ phase135_trim_mir_verify.sh - PASS ✅ phase132_exit_phi_parity.sh - 3/3 PASS ✅ All function-context `value_gen.next()` eliminated ## Effect - **Collision prevention**: No more ValueId collisions between function-level allocations and reserved PHI dsts - **SSOT compliance**: All ValueId allocation flows through single allocator - **Contract enforcement**: Phase 135 P1 contract_checks will catch violations immediately 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-15 19:37:30 +09:00
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` で関数内経路から消えるmodule context の意図的フォールバックを除く)
-`cargo test --release --lib` が退行しない
feat(mir): Phase 136 P0 - ValueId allocator SSOT 徹底(関数内経路から value_gen.next() 掃討) ## Summary Eliminates remaining `value_gen.next()` calls from function-context code paths, unifying all ValueId allocation through `MirBuilder::next_value_id()` SSOT allocator. ## Changes ### 1. Fixed `new_typed_value()` (src/mir/builder.rs:1068) **Before**: `let id = self.value_gen.next();` (bypasses function context) **After**: `let id = self.next_value_id();` (respects function context) This is a public API used in function context, so must use SSOT allocator to avoid collisions with reserved PHI dsts and function params. ### 2. Fixed test code (src/mir/builder.rs) **test_shadowing_binding_restore** (lines 1161, 1171): - Simulates function scope with `push_lexical_scope()` - Changed to `builder.next_value_id()` for function scope simulation **test_valueid_binding_parallel_allocation** (lines 1196-1216): - Tests ValueId/BindingId independence - Changed to `builder.next_value_id()` with note that Module context fallback preserves test intent ### 3. Verified Module context fallbacks (OK, no change needed) These already check `current_function.is_some()` and use `value_gen.next()` only as Module context fallback: - `src/mir/builder/utils.rs:43` - next_value_id() SSOT implementation - `src/mir/builder/utils.rs:436` - pin_to_slot() - `src/mir/builder/utils.rs:467` - materialize_local() - `src/mir/utils/phi_helpers.rs:69` - insert_phi_unified() ## Verification ```bash rg -n "value_gen\.next\(" src/mir --type rust | grep -v "Module context" | grep -v "//" # Result: Only comments/docs remain ``` ## Acceptance ✅ cargo test --release --lib - 997 passed ✅ phase135_trim_mir_verify.sh - PASS ✅ phase132_exit_phi_parity.sh - 3/3 PASS ✅ All function-context `value_gen.next()` eliminated ## Effect - **Collision prevention**: No more ValueId collisions between function-level allocations and reserved PHI dsts - **SSOT compliance**: All ValueId allocation flows through single allocator - **Contract enforcement**: Phase 135 P1 contract_checks will catch violations immediately 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-15 19:37:30 +09:00
-`phase135_trim_mir_verify.sh` - PASS
-`phase132_exit_phi_parity.sh` - 3/3 PASS
## Remaining Tasks残課題
なし。状態は Context に一本化され、関数内経路から `value_gen.next()` を排除完了。Module context のフォールバックは意図的に残す。