Phase 25.1b: VM undefined-value diagnostics and builder SSA helpers
This commit is contained in:
@ -76,9 +76,22 @@ impl super::MirBuilder {
|
||||
self.local_ssa_map.clear();
|
||||
// BlockSchedule materialize cache is per-block as well
|
||||
self.schedule_mat_map.clear();
|
||||
// Entry materialization for pinned slots only when not suppressed.
|
||||
// This provides block-local defs in single-predecessor flows without touching user vars.
|
||||
// Entry materialization for pinned slots: re-read from variable_map after PHIs are emitted.
|
||||
// This ensures pinned slots reflect the correct PHI values in merge blocks.
|
||||
//
|
||||
// Strategy: Instead of emitting Copy instructions (which would be before PHIs),
|
||||
// we simply update the variable_map to point to the current block's values.
|
||||
// LoopBuilder and IfBuilder already update variable_map with PHI values, so
|
||||
// pinned slots will automatically pick up the correct values.
|
||||
//
|
||||
// No action needed here - just clear caches.
|
||||
if !self.suppress_pin_entry_copy_next {
|
||||
// Cache clearing is already done above, so nothing more to do here.
|
||||
// The key insight: pinned slot variables are part of variable_map,
|
||||
// and LoopBuilder/IfBuilder already manage PHIs for ALL variables in variable_map,
|
||||
// including pinned slots.
|
||||
}
|
||||
if false && !self.suppress_pin_entry_copy_next { // Keep old code for reference
|
||||
// First pass: copy all pin slots and remember old->new mapping
|
||||
let names: Vec<String> = self.variable_map.keys().cloned().collect();
|
||||
let mut pin_renames: Vec<(super::ValueId, super::ValueId)> = Vec::new();
|
||||
@ -328,12 +341,25 @@ impl super::MirBuilder {
|
||||
/// Insert a Copy immediately after PHI nodes in the current block (position-stable).
|
||||
pub(crate) fn insert_copy_after_phis(&mut self, dst: super::ValueId, src: super::ValueId) -> Result<(), String> {
|
||||
if let (Some(ref mut function), Some(bb)) = (&mut self.current_function, self.current_block) {
|
||||
if std::env::var("NYASH_SCHEDULE_TRACE").ok().as_deref() == Some("1") {
|
||||
eprintln!("[utils/insert-copy-after-phis] bb={:?} dst=%{} src=%{} attempting...",
|
||||
bb, dst.0, src.0);
|
||||
}
|
||||
if let Some(block) = function.get_block_mut(bb) {
|
||||
if std::env::var("NYASH_SCHEDULE_TRACE").ok().as_deref() == Some("1") {
|
||||
eprintln!("[utils/insert-copy-after-phis] bb={:?} dst=%{} src=%{} phi_count={} SUCCESS",
|
||||
bb, dst.0, src.0, block.phi_instructions().count());
|
||||
}
|
||||
// Propagate effects on the block
|
||||
block.insert_instruction_after_phis(super::MirInstruction::Copy { dst, src });
|
||||
// Lightweight metadata propagation (unified)
|
||||
crate::mir::builder::metadata::propagate::propagate(self, src, dst);
|
||||
return Ok(());
|
||||
} else {
|
||||
if std::env::var("NYASH_SCHEDULE_TRACE").ok().as_deref() == Some("1") {
|
||||
eprintln!("[utils/insert-copy-after-phis] bb={:?} dst=%{} src=%{} FAILED: block not found",
|
||||
bb, dst.0, src.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err("No current function/block to insert copy".to_string())
|
||||
|
||||
Reference in New Issue
Block a user