Phase 25.1b: VM undefined-value diagnostics and builder SSA helpers
This commit is contained in:
@ -37,6 +37,31 @@ pub fn ensure(builder: &mut MirBuilder, v: ValueId, kind: LocalKind) -> ValueId
|
||||
if let Some(&loc) = builder.local_ssa_map.get(&key) {
|
||||
return loc;
|
||||
}
|
||||
|
||||
// CRITICAL FIX: If `v` is from a pinned slot, check if there's a PHI value for that slot
|
||||
// in the current block's variable_map. If so, use the PHI value directly instead of
|
||||
// emitting a Copy from the old value (which might not be defined in this block).
|
||||
let names_for_v: Vec<String> = builder.variable_map.iter()
|
||||
.filter(|(k, &vid)| vid == v && k.starts_with("__pin$"))
|
||||
.map(|(k, _)| k.clone())
|
||||
.collect();
|
||||
|
||||
if let Some(first_pin_name) = names_for_v.first() {
|
||||
// This value is from a pinned slot. Check if the slot has been updated
|
||||
// (e.g., by a PHI) in the current block.
|
||||
if let Some(¤t_val) = builder.variable_map.get(first_pin_name) {
|
||||
if current_val != v {
|
||||
// The slot has been updated (likely by a PHI). Use the updated value.
|
||||
if std::env::var("NYASH_LOCAL_SSA_TRACE").ok().as_deref() == Some("1") {
|
||||
eprintln!("[local-ssa] phi-redirect bb={:?} kind={:?} slot={} %{} -> %{}",
|
||||
bb, kind, first_pin_name, v.0, current_val.0);
|
||||
}
|
||||
builder.local_ssa_map.insert(key, current_val);
|
||||
return current_val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let loc = builder.next_value_id();
|
||||
// Best-effort: errors are propagated by caller; we ignore here to keep helper infallible
|
||||
let _ = builder.emit_instruction(crate::mir::MirInstruction::Copy { dst: loc, src: v });
|
||||
|
||||
Reference in New Issue
Block a user