Normalize passes keep spans and clean warnings
This commit is contained in:
@ -9,15 +9,15 @@ pub fn check_weakref_and_barrier(function: &MirFunction) -> Result<(), Vec<Verif
|
||||
let mut def_map: std::collections::HashMap<ValueId, (BasicBlockId, usize, &MirInstruction)> =
|
||||
std::collections::HashMap::new();
|
||||
for (bid, block) in &function.blocks {
|
||||
for (idx, inst) in block.all_instructions().enumerate() {
|
||||
if let Some(dst) = inst.dst_value() {
|
||||
def_map.insert(dst, (*bid, idx, inst));
|
||||
for (idx, sp) in block.all_spanned_instructions_enumerated() {
|
||||
if let Some(dst) = sp.inst.dst_value() {
|
||||
def_map.insert(dst, (*bid, idx, sp.inst));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (bid, block) in &function.blocks {
|
||||
for (idx, inst) in block.all_instructions().enumerate() {
|
||||
match inst {
|
||||
for (idx, sp) in block.all_spanned_instructions_enumerated() {
|
||||
match sp.inst {
|
||||
MirInstruction::WeakRef {
|
||||
op: crate::mir::WeakRefOp::Load,
|
||||
value,
|
||||
@ -103,11 +103,10 @@ pub fn check_barrier_context(function: &MirFunction) -> Result<(), Vec<Verificat
|
||||
|
||||
let mut errors = Vec::new();
|
||||
for (bid, block) in &function.blocks {
|
||||
let mut insts: Vec<(usize, &MirInstruction)> =
|
||||
block.instructions.iter().enumerate().collect();
|
||||
if let Some(term) = &block.terminator {
|
||||
insts.push((usize::MAX, term));
|
||||
}
|
||||
let insts: Vec<(usize, &MirInstruction)> = block
|
||||
.all_spanned_instructions_enumerated()
|
||||
.map(|(i, sp)| (i, sp.inst))
|
||||
.collect();
|
||||
for (idx, inst) in &insts {
|
||||
let is_barrier = matches!(
|
||||
inst,
|
||||
|
||||
@ -42,8 +42,8 @@ pub fn check_merge_uses(function: &MirFunction) -> Result<(), Vec<VerificationEr
|
||||
let mut phi_dsts_in_block: HashMap<BasicBlockId, HashSet<ValueId>> = HashMap::new();
|
||||
for (bid, block) in &function.blocks {
|
||||
let set = phi_dsts_in_block.entry(*bid).or_default();
|
||||
for inst in block.all_instructions() {
|
||||
if let crate::mir::MirInstruction::Phi { dst, .. } = inst {
|
||||
for sp in block.all_spanned_instructions() {
|
||||
if let crate::mir::MirInstruction::Phi { dst, .. } = sp.inst {
|
||||
set.insert(*dst);
|
||||
}
|
||||
}
|
||||
@ -57,11 +57,11 @@ pub fn check_merge_uses(function: &MirFunction) -> Result<(), Vec<VerificationEr
|
||||
}
|
||||
let phi_dsts = phi_dsts_in_block.get(bid);
|
||||
let doms_of_block = dominators.get(bid).unwrap();
|
||||
for inst in block.all_instructions() {
|
||||
if let crate::mir::MirInstruction::Phi { .. } = inst {
|
||||
for sp in block.all_spanned_instructions() {
|
||||
if let crate::mir::MirInstruction::Phi { .. } = sp.inst {
|
||||
continue;
|
||||
}
|
||||
for used in inst.used_values() {
|
||||
for used in sp.inst.used_values() {
|
||||
if let Some(&db) = def_block.get(&used) {
|
||||
if !doms_of_block.contains(&db) {
|
||||
let is_phi_dst = phi_dsts.map(|s| s.contains(&used)).unwrap_or(false);
|
||||
|
||||
@ -11,11 +11,11 @@ pub fn check_dominance(function: &MirFunction) -> Result<(), Vec<VerificationErr
|
||||
let def_block = utils::compute_def_blocks(function);
|
||||
let dominators = utils::compute_dominators(function);
|
||||
for (use_block_id, block) in &function.blocks {
|
||||
for instruction in block.all_instructions() {
|
||||
if let crate::mir::MirInstruction::Phi { .. } = instruction {
|
||||
for sp in block.all_spanned_instructions() {
|
||||
if let crate::mir::MirInstruction::Phi { .. } = sp.inst {
|
||||
continue;
|
||||
}
|
||||
for used_value in instruction.used_values() {
|
||||
for used_value in sp.inst.used_values() {
|
||||
if let Some(&def_bb) = def_block.get(&used_value) {
|
||||
if def_bb != *use_block_id {
|
||||
let doms = dominators.get(use_block_id).unwrap();
|
||||
|
||||
@ -9,8 +9,8 @@ pub fn check_no_legacy_ops(function: &MirFunction) -> Result<(), Vec<Verificatio
|
||||
}
|
||||
let mut errors = Vec::new();
|
||||
for (bid, block) in &function.blocks {
|
||||
for (idx, inst) in block.all_instructions().enumerate() {
|
||||
let legacy_name = match inst {
|
||||
for (idx, sp) in block.all_spanned_instructions_enumerated() {
|
||||
let legacy_name = match sp.inst {
|
||||
MirInstruction::TypeCheck { .. } => Some("TypeCheck"), // -> TypeOp(Check)
|
||||
MirInstruction::Cast { .. } => Some("Cast"), // -> TypeOp(Cast)
|
||||
MirInstruction::WeakNew { .. } => Some("WeakNew"), // -> WeakRef(New)
|
||||
|
||||
@ -14,8 +14,8 @@ pub fn check_ssa_form(function: &MirFunction) -> Result<(), Vec<VerificationErro
|
||||
}
|
||||
|
||||
for (block_id, block) in &function.blocks {
|
||||
for (inst_idx, instruction) in block.all_instructions().enumerate() {
|
||||
if let Some(dst) = instruction.dst_value() {
|
||||
for (inst_idx, sp) in block.all_spanned_instructions_enumerated() {
|
||||
if let Some(dst) = sp.inst.dst_value() {
|
||||
if let Some((first_block, _)) = definitions.insert(dst, (*block_id, inst_idx)) {
|
||||
errors.push(VerificationError::MultipleDefinition {
|
||||
value: dst,
|
||||
@ -28,12 +28,12 @@ pub fn check_ssa_form(function: &MirFunction) -> Result<(), Vec<VerificationErro
|
||||
}
|
||||
|
||||
for (block_id, block) in &function.blocks {
|
||||
for (inst_idx, instruction) in block.all_instructions().enumerate() {
|
||||
for used_value in instruction.used_values() {
|
||||
for (inst_idx, sp) in block.all_spanned_instructions_enumerated() {
|
||||
for used_value in sp.inst.used_values() {
|
||||
if !definitions.contains_key(&used_value) {
|
||||
eprintln!(
|
||||
"[ssa-undef-debug] fn={} bb={:?} inst_idx={} used={:?} inst={:?}",
|
||||
function.signature.name, block_id, inst_idx, used_value, instruction
|
||||
function.signature.name, block_id, inst_idx, used_value, sp.inst
|
||||
);
|
||||
errors.push(VerificationError::UndefinedValue {
|
||||
value: used_value,
|
||||
|
||||
@ -17,8 +17,8 @@ pub fn compute_def_blocks(function: &MirFunction) -> HashMap<ValueId, BasicBlock
|
||||
def_block.insert(*pid, function.entry_block);
|
||||
}
|
||||
for (bid, block) in &function.blocks {
|
||||
for inst in block.all_instructions() {
|
||||
if let Some(dst) = inst.dst_value() {
|
||||
for sp in block.all_spanned_instructions() {
|
||||
if let Some(dst) = sp.inst.dst_value() {
|
||||
def_block.insert(dst, *bid);
|
||||
}
|
||||
}
|
||||
@ -79,8 +79,8 @@ pub fn compute_reachable_blocks(function: &MirFunction) -> HashSet<BasicBlockId>
|
||||
worklist.push(*successor);
|
||||
}
|
||||
}
|
||||
for instruction in &block.instructions {
|
||||
if let crate::mir::MirInstruction::Catch { handler_bb, .. } = instruction {
|
||||
for sp in block.iter_spanned() {
|
||||
if let crate::mir::MirInstruction::Catch { handler_bb, .. } = sp.inst {
|
||||
if !reachable.contains(handler_bb) {
|
||||
worklist.push(*handler_bb);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user