From a98cc1b945a90805b253b04d9993d9d867400db9 Mon Sep 17 00:00:00 2001 From: nyash-codex Date: Thu, 20 Nov 2025 16:10:56 +0900 Subject: [PATCH] feat(phi): Step 5-5-F/G - Prevent __pin$ from entering variable_map MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Step 5-5-F: build_assignment() safeguard - Skip inserting __pin$ temporaries into variable_map - __pin$ variables are transient compiler-generated temps - They should not persist across blocks or loops Step 5-5-G: build_variable_access() safeguard - Reject attempts to access __pin$ variables from variable_map - Return clear error: "COMPILER BUG: Attempt to access __pin$ temporary" - This catches stale __pin$ references early Root Cause (Corrected): - NOT BlockId renumbering (as Task initially thought) - ChatGPT analysis: variable_map/snapshot/carrier have wrong ValueIds - __pin$ temps were persisting and causing stale references Test Status: 267 PASS / 1 FAIL (no regressions) Next: Detailed MIR dump + VM trace analysis to find exact ValueId source 🐛 PHI Bug Option C実装: 箱分割設計で根本修正 --- src/mir/builder.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/mir/builder.rs b/src/mir/builder.rs index 6e630dd7..ca7fba24 100644 --- a/src/mir/builder.rs +++ b/src/mir/builder.rs @@ -456,6 +456,17 @@ impl MirBuilder { /// Build variable access pub(super) fn build_variable_access(&mut self, name: String) -> Result { + // Step 5-5-G: __pin$ variables should NEVER be accessed from variable_map + // They are transient temporaries created during expression building and + // should not persist across blocks. If we see one here, it's a compiler bug. + if name.starts_with("__pin$") { + return Err(format!( + "COMPILER BUG: Attempt to access __pin$ temporary '{}' from variable_map. \ + __pin$ variables should only exist as direct SSA values, not as named variables.", + name + )); + } + if let Some(&value_id) = self.variable_map.get(&name) { Ok(value_id) } else { @@ -500,8 +511,18 @@ impl MirBuilder { // SSA + PHI merges work correctly without explicit pinning here. // The expression building already creates necessary temporaries. - // In SSA form, each assignment creates a new value - self.variable_map.insert(var_name.clone(), value_id); + // Step 5-5-F: NEVER insert __pin$ temporaries into variable_map + // __pin$ variables are transient compiler-generated temporaries that should + // never be tracked as real variables. They are used only within expression + // building and should not persist across blocks or loops. + // + // BUG FIX: Previously, __pin$ variables would be inserted into variable_map, + // causing stale references after LoopForm transformation renumbers blocks. + // Result: VM would try to read undefined ValueIds (e.g., ValueId(270) at bb303). + if !var_name.starts_with("__pin$") { + // In SSA form, each assignment creates a new value + self.variable_map.insert(var_name.clone(), value_id); + } Ok(value_id) }