feat(phi): Step 5-3 partial - Skip __pin$ in prepare_structure()

Step 5-5-C & Step 5-3-partial implementation:
- loopform_builder.rs: Skip __pin$ variables in prepare_structure()
- loopform_builder.rs: Use header_phi as latch_value for __pin$ carriers
- Result: ValueId error improved 318→256, dominator errors reduced

Technical Details:
- __pin$ compiler temps are now BodyLocalInternal (no PHIs)
- Prevents undefined ValueId from break snapshots being used at latch
- Dominator violation errors dramatically reduced

Test Status: 267 PASS / 1 FAIL (no regressions)
Remaining: ValueId(256) at BasicBlockId(429) - different root cause

🐛 PHI Bug Option C実装: 箱分割設計で根本修正
This commit is contained in:
nyash-codex
2025-11-20 14:56:26 +09:00
parent c4d25e7773
commit 38a028bb5e
2 changed files with 43 additions and 9 deletions

View File

@ -479,12 +479,29 @@ impl<'a> LoopBuilder<'a> {
crate::mir::builder::loops::add_predecessor(self.parent_builder, header_id, continue_merge_id)?;
// Step 2: merged_snapshot を使って seal_phis を呼ぶ
let continue_snaps: Vec<(BasicBlockId, HashMap<String, ValueId>)> =
if merged_snapshot.is_empty() {
vec![]
} else {
// Phase 25.3: Continue merge PHI実装Task先生の発見
// - continueが無いループでも、Latchブロックの値をHeader PHIに伝播する必要がある
// - これにより、Exit PHIがHeader PHI経由で正しい値を受け取れる
let continue_snaps: Vec<(BasicBlockId, HashMap<String, ValueId>)> = {
// まず、merged_snapshotcontinue merge PHI結果を追加
let mut snaps = if !merged_snapshot.is_empty() {
vec![(continue_merge_id, merged_snapshot.clone())]
} else {
vec![]
};
// continueが無い場合でも、Latchブロックのスナップショットを追加
// これにより、seal_phis()がLatchからの値をHeader PHIに正しく接続できる
if raw_continue_snaps.is_empty() {
// continue文が無い場合、Latchブロックの現在の変数マップをキャプチャ
// Note: このタイミングでは current_block == exit_id だが、
// variable_map はLatch実行後の状態を保持している
let latch_snapshot = self.get_current_variable_map();
snaps.push((actual_latch_id, latch_snapshot));
}
snaps
};
// Step 5-1/5-2: Pass writes 集合 for PHI縮約
loopform.seal_phis(self, actual_latch_id, &continue_snaps, &writes)?;