Remove macros from verifier; fixes #1248
This removes `report!`, `fatal!`, and `nonfatal!` from the verifier code and replaces them with methods on `VerifierErrors`. In order to maintain similar ease-of-use, `VerifierError` is expanded with several `From` implementations that convert a tuple to a verifier error.
This commit is contained in:
@@ -65,13 +65,13 @@ impl<'a> CssaVerifier<'a> {
|
||||
|
||||
for (idx, &val) in values.iter().enumerate() {
|
||||
if !self.func.dfg.value_is_valid(val) {
|
||||
return fatal!(errors, val, "Invalid value in {}", vreg);
|
||||
return errors.fatal((val, format!("Invalid value in {}", vreg)));
|
||||
}
|
||||
if !self.func.dfg.value_is_attached(val) {
|
||||
return fatal!(errors, val, "Detached value in {}", vreg);
|
||||
return errors.fatal((val, format!("Detached value in {}", vreg)));
|
||||
}
|
||||
if self.liveness.get(val).is_none() {
|
||||
return fatal!(errors, val, "Value in {} has no live range", vreg);
|
||||
return errors.fatal((val, format!("Value in {} has no live range", vreg)));
|
||||
};
|
||||
|
||||
// Check topological ordering with the previous values in the virtual register.
|
||||
@@ -82,29 +82,31 @@ impl<'a> CssaVerifier<'a> {
|
||||
let prev_ebb = self.func.layout.pp_ebb(prev_def);
|
||||
|
||||
if prev_def == def {
|
||||
return fatal!(
|
||||
errors,
|
||||
return errors.fatal((
|
||||
val,
|
||||
format!(
|
||||
"Values {} and {} in {} = {} defined at the same program point",
|
||||
prev_val,
|
||||
val,
|
||||
vreg,
|
||||
DisplayList(values)
|
||||
);
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
// Enforce topological ordering of defs in the virtual register.
|
||||
if self.preorder.dominates(def_ebb, prev_ebb)
|
||||
&& self.domtree.dominates(def, prev_def, &self.func.layout)
|
||||
{
|
||||
return fatal!(
|
||||
errors,
|
||||
return errors.fatal((
|
||||
val,
|
||||
format!(
|
||||
"Value in {} = {} def dominates previous {}",
|
||||
vreg,
|
||||
DisplayList(values),
|
||||
prev_val
|
||||
);
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,14 +121,15 @@ impl<'a> CssaVerifier<'a> {
|
||||
&& self.domtree.dominates(prev_def, def, &self.func.layout)
|
||||
{
|
||||
if self.liveness[prev_val].overlaps_def(def, def_ebb, &self.func.layout) {
|
||||
return fatal!(
|
||||
errors,
|
||||
return errors.fatal((
|
||||
val,
|
||||
format!(
|
||||
"Value def in {} = {} interferes with {}",
|
||||
vreg,
|
||||
DisplayList(values),
|
||||
prev_val
|
||||
);
|
||||
),
|
||||
));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
@@ -152,13 +155,13 @@ impl<'a> CssaVerifier<'a> {
|
||||
|
||||
for (&ebb_param, &pred_arg) in ebb_params.iter().zip(pred_args) {
|
||||
if !self.virtregs.same_class(ebb_param, pred_arg) {
|
||||
return fatal!(
|
||||
errors,
|
||||
return errors.fatal((
|
||||
pred,
|
||||
format!(
|
||||
"{} and {} must be in the same virtual register",
|
||||
ebb_param,
|
||||
pred_arg
|
||||
);
|
||||
ebb_param, pred_arg
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,13 +67,10 @@ impl<'a> FlagsVerifier<'a> {
|
||||
}
|
||||
}
|
||||
Some(old) if old != value => {
|
||||
return fatal!(
|
||||
errors,
|
||||
return errors.fatal((
|
||||
ebb,
|
||||
"conflicting live-in CPU flags: {} and {}",
|
||||
old,
|
||||
value
|
||||
);
|
||||
format!("conflicting live-in CPU flags: {} and {}", old, value),
|
||||
));
|
||||
}
|
||||
x => assert_eq!(x, Some(value)),
|
||||
}
|
||||
@@ -104,7 +101,9 @@ impl<'a> FlagsVerifier<'a> {
|
||||
// We've reached the def of `live_flags`, so it is no longer live above.
|
||||
live_val = None;
|
||||
} else if self.func.dfg.value_type(res).is_flags() {
|
||||
return fatal!(errors, inst, "{} clobbers live CPU flags in {}", res, live);
|
||||
errors
|
||||
.report((inst, format!("{} clobbers live CPU flags in {}", res, live)));
|
||||
return Err(());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +115,11 @@ impl<'a> FlagsVerifier<'a> {
|
||||
.map_or(false, |c| c.clobbers_flags)
|
||||
&& live_val.is_some()
|
||||
{
|
||||
return fatal!(errors, inst, "encoding clobbers live CPU flags in {}", live);
|
||||
errors.report((
|
||||
inst,
|
||||
format!("encoding clobbers live CPU flags in {}", live),
|
||||
));
|
||||
return Err(());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,7 +167,10 @@ fn merge(
|
||||
) -> VerifierStepResult<()> {
|
||||
if let Some(va) = *a {
|
||||
if b != va {
|
||||
return fatal!(errors, inst, "conflicting live CPU flags: {} and {}", va, b);
|
||||
return errors.fatal((
|
||||
inst,
|
||||
format!("conflicting live CPU flags: {} and {}", va, b),
|
||||
));
|
||||
}
|
||||
} else {
|
||||
*a = Some(b);
|
||||
|
||||
@@ -54,7 +54,9 @@ impl<'a> LivenessVerifier<'a> {
|
||||
for &val in self.func.dfg.ebb_params(ebb) {
|
||||
let lr = match self.liveness.get(val) {
|
||||
Some(lr) => lr,
|
||||
None => return fatal!(errors, ebb, "EBB arg {} has no live range", val),
|
||||
None => {
|
||||
return errors.fatal((ebb, format!("EBB arg {} has no live range", val)))
|
||||
}
|
||||
};
|
||||
self.check_lr(ebb.into(), val, lr, errors)?;
|
||||
}
|
||||
@@ -72,30 +74,32 @@ impl<'a> LivenessVerifier<'a> {
|
||||
for &val in self.func.dfg.inst_results(inst) {
|
||||
let lr = match self.liveness.get(val) {
|
||||
Some(lr) => lr,
|
||||
None => return fatal!(errors, inst, "{} has no live range", val),
|
||||
None => return errors.fatal((inst, format!("{} has no live range", val))),
|
||||
};
|
||||
self.check_lr(inst.into(), val, lr, errors)?;
|
||||
|
||||
if encoding.is_legal() {
|
||||
// A legal instruction is not allowed to define ghost values.
|
||||
if lr.affinity.is_unassigned() {
|
||||
return fatal!(
|
||||
errors,
|
||||
return errors.fatal((
|
||||
inst,
|
||||
format!(
|
||||
"{} is a ghost value defined by a real [{}] instruction",
|
||||
val,
|
||||
self.isa.encoding_info().display(encoding)
|
||||
);
|
||||
),
|
||||
));
|
||||
}
|
||||
} else if !lr.affinity.is_unassigned() {
|
||||
// A non-encoded instruction can only define ghost values.
|
||||
return fatal!(
|
||||
errors,
|
||||
return errors.fatal((
|
||||
inst,
|
||||
format!(
|
||||
"{} is a real {} value defined by a ghost instruction",
|
||||
val,
|
||||
lr.affinity.display(&self.isa.register_info())
|
||||
);
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,23 +107,24 @@ impl<'a> LivenessVerifier<'a> {
|
||||
for &val in self.func.dfg.inst_args(inst) {
|
||||
let lr = match self.liveness.get(val) {
|
||||
Some(lr) => lr,
|
||||
None => return fatal!(errors, inst, "{} has no live range", val),
|
||||
None => return errors.fatal((inst, format!("{} has no live range", val))),
|
||||
};
|
||||
|
||||
debug_assert!(self.func.layout.inst_ebb(inst).unwrap() == ebb);
|
||||
if !lr.reaches_use(inst, ebb, &self.func.layout) {
|
||||
return fatal!(errors, inst, "{} is not live at this use", val);
|
||||
return errors.fatal((inst, format!("{} is not live at this use", val)));
|
||||
}
|
||||
|
||||
// A legal instruction is not allowed to depend on ghost values.
|
||||
if encoding.is_legal() && lr.affinity.is_unassigned() {
|
||||
return fatal!(
|
||||
errors,
|
||||
return errors.fatal((
|
||||
inst,
|
||||
format!(
|
||||
"{} is a ghost value used by a real [{}] instruction",
|
||||
val,
|
||||
self.isa.encoding_info().display(encoding)
|
||||
);
|
||||
self.isa.encoding_info().display(encoding),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,17 +147,14 @@ impl<'a> LivenessVerifier<'a> {
|
||||
ExpandedProgramPoint::Inst(i) => i.into(),
|
||||
};
|
||||
if lr.def() != def {
|
||||
return fatal!(
|
||||
errors,
|
||||
return errors.fatal((
|
||||
loc,
|
||||
"Wrong live range def ({}) for {}",
|
||||
lr.def(),
|
||||
val
|
||||
);
|
||||
format!("Wrong live range def ({}) for {}", lr.def(), val),
|
||||
));
|
||||
}
|
||||
if lr.is_dead() {
|
||||
if !lr.is_local() {
|
||||
return fatal!(errors, loc, "Dead live range {} should be local", val);
|
||||
return errors.fatal((loc, format!("Dead live range {} should be local", val)));
|
||||
} else {
|
||||
return Ok(());
|
||||
}
|
||||
@@ -163,17 +165,14 @@ impl<'a> LivenessVerifier<'a> {
|
||||
};
|
||||
match lr.def_local_end().into() {
|
||||
ExpandedProgramPoint::Ebb(e) => {
|
||||
return fatal!(
|
||||
errors,
|
||||
return errors.fatal((
|
||||
loc,
|
||||
"Def local range for {} can't end at {}",
|
||||
val,
|
||||
e
|
||||
);
|
||||
format!("Def local range for {} can't end at {}", val, e),
|
||||
));
|
||||
}
|
||||
ExpandedProgramPoint::Inst(i) => {
|
||||
if self.func.layout.inst_ebb(i) != Some(def_ebb) {
|
||||
return fatal!(errors, loc, "Def local end for {} in wrong ebb", val);
|
||||
return errors.fatal((loc, format!("Def local end for {} in wrong ebb", val)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -181,25 +180,21 @@ impl<'a> LivenessVerifier<'a> {
|
||||
// Now check the live-in intervals against the CFG.
|
||||
for (mut ebb, end) in lr.liveins() {
|
||||
if !l.is_ebb_inserted(ebb) {
|
||||
return fatal!(
|
||||
errors,
|
||||
return errors.fatal((
|
||||
loc,
|
||||
"{} livein at {} which is not in the layout",
|
||||
val,
|
||||
ebb
|
||||
);
|
||||
format!("{} livein at {} which is not in the layout", val, ebb),
|
||||
));
|
||||
}
|
||||
let end_ebb = match l.inst_ebb(end) {
|
||||
Some(e) => e,
|
||||
None => {
|
||||
return fatal!(
|
||||
errors,
|
||||
return errors.fatal((
|
||||
loc,
|
||||
format!(
|
||||
"{} livein for {} ends at {} which is not in the layout",
|
||||
val,
|
||||
ebb,
|
||||
end
|
||||
);
|
||||
val, ebb, end
|
||||
),
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -208,13 +203,10 @@ impl<'a> LivenessVerifier<'a> {
|
||||
// If `val` is live-in at `ebb`, it must be live at all the predecessors.
|
||||
for BasicBlock { inst: pred, ebb } in self.cfg.pred_iter(ebb) {
|
||||
if !lr.reaches_use(pred, ebb, &self.func.layout) {
|
||||
return fatal!(
|
||||
errors,
|
||||
return errors.fatal((
|
||||
pred,
|
||||
"{} is live in to {} but not live at predecessor",
|
||||
val,
|
||||
ebb
|
||||
);
|
||||
format!("{} is live in to {} but not live at predecessor", val, ebb),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,13 +216,10 @@ impl<'a> LivenessVerifier<'a> {
|
||||
ebb = match l.next_ebb(ebb) {
|
||||
Some(e) => e,
|
||||
None => {
|
||||
return fatal!(
|
||||
errors,
|
||||
return errors.fatal((
|
||||
loc,
|
||||
"end of {} livein ({}) never reached",
|
||||
val,
|
||||
end_ebb
|
||||
);
|
||||
format!("end of {} livein ({}) never reached", val, end_ebb),
|
||||
));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -104,14 +104,15 @@ impl<'a> LocationVerifier<'a> {
|
||||
}
|
||||
|
||||
// TODO: We could give a better error message here.
|
||||
fatal!(
|
||||
errors,
|
||||
errors.fatal((
|
||||
inst,
|
||||
format!(
|
||||
"{} constraints not satisfied in: {}\n{}",
|
||||
self.encinfo.display(enc),
|
||||
self.func.dfg.display_inst(inst, self.isa),
|
||||
self.func.display(self.isa)
|
||||
)
|
||||
self.func.display(self.isa),
|
||||
),
|
||||
))
|
||||
}
|
||||
|
||||
/// Check that the result values produced by a ghost instruction are not assigned a value
|
||||
@@ -126,13 +127,14 @@ impl<'a> LocationVerifier<'a> {
|
||||
for &res in results {
|
||||
let loc = self.func.locations[res];
|
||||
if loc.is_assigned() {
|
||||
return fatal!(
|
||||
errors,
|
||||
return errors.fatal((
|
||||
inst,
|
||||
format!(
|
||||
"ghost result {} value must not have a location ({}).",
|
||||
res,
|
||||
loc.display(&self.reginfo)
|
||||
);
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,50 +216,51 @@ impl<'a> LocationVerifier<'a> {
|
||||
ir::ArgumentLoc::Unassigned => {}
|
||||
ir::ArgumentLoc::Reg(reg) => {
|
||||
if loc != ir::ValueLoc::Reg(reg) {
|
||||
return fatal!(
|
||||
errors,
|
||||
return errors.fatal((
|
||||
inst,
|
||||
format!(
|
||||
"ABI expects {} in {}, got {}",
|
||||
value,
|
||||
abi.location.display(&self.reginfo),
|
||||
loc.display(&self.reginfo)
|
||||
);
|
||||
loc.display(&self.reginfo),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
ir::ArgumentLoc::Stack(offset) => {
|
||||
if let ir::ValueLoc::Stack(ss) = loc {
|
||||
let slot = &self.func.stack_slots[ss];
|
||||
if slot.kind != want_kind {
|
||||
return fatal!(
|
||||
errors,
|
||||
return errors.fatal((
|
||||
inst,
|
||||
format!(
|
||||
"call argument {} should be in a {} slot, but {} is {}",
|
||||
value,
|
||||
want_kind,
|
||||
ss,
|
||||
slot.kind
|
||||
);
|
||||
value, want_kind, ss, slot.kind
|
||||
),
|
||||
));
|
||||
}
|
||||
if slot.offset.unwrap() != offset {
|
||||
return fatal!(
|
||||
errors,
|
||||
return errors.fatal((
|
||||
inst,
|
||||
format!(
|
||||
"ABI expects {} at stack offset {}, but {} is at {}",
|
||||
value,
|
||||
offset,
|
||||
ss,
|
||||
slot.offset.unwrap()
|
||||
);
|
||||
),
|
||||
));
|
||||
}
|
||||
} else {
|
||||
return fatal!(
|
||||
errors,
|
||||
return errors.fatal((
|
||||
inst,
|
||||
format!(
|
||||
"ABI expects {} at stack offset {}, got {}",
|
||||
value,
|
||||
offset,
|
||||
loc.display(&self.reginfo)
|
||||
);
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -281,21 +284,23 @@ impl<'a> LocationVerifier<'a> {
|
||||
|
||||
if let Some(d) = divert.diversion(arg) {
|
||||
if d.to != src {
|
||||
return fatal!(
|
||||
errors,
|
||||
return errors.fatal((
|
||||
inst,
|
||||
format!(
|
||||
"inconsistent with current diversion to {}",
|
||||
d.to.display(&self.reginfo)
|
||||
);
|
||||
),
|
||||
));
|
||||
}
|
||||
} else if self.func.locations[arg] != src {
|
||||
return fatal!(
|
||||
errors,
|
||||
return errors.fatal((
|
||||
inst,
|
||||
format!(
|
||||
"inconsistent with global location {} ({})",
|
||||
self.func.locations[arg].display(&self.reginfo),
|
||||
self.func.dfg.display_inst(inst, None)
|
||||
);
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
divert.apply(&self.func.dfg[inst]);
|
||||
@@ -338,14 +343,15 @@ impl<'a> LocationVerifier<'a> {
|
||||
val_to_remove.push(value)
|
||||
}
|
||||
} else if lr.is_livein(ebb, &self.func.layout) {
|
||||
return fatal!(
|
||||
errors,
|
||||
return errors.fatal((
|
||||
inst,
|
||||
format!(
|
||||
"SingleDest: {} is diverted to {} and live in to {}",
|
||||
value,
|
||||
d.to.display(&self.reginfo),
|
||||
ebb
|
||||
);
|
||||
ebb,
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
if is_after_branch && unique_predecessor {
|
||||
@@ -360,26 +366,28 @@ impl<'a> LocationVerifier<'a> {
|
||||
let lr = &liveness[value];
|
||||
if let Some(ebb) = ebb {
|
||||
if lr.is_livein(ebb, &self.func.layout) {
|
||||
return fatal!(
|
||||
errors,
|
||||
return errors.fatal((
|
||||
inst,
|
||||
format!(
|
||||
"Table.default: {} is diverted to {} and live in to {}",
|
||||
value,
|
||||
d.to.display(&self.reginfo),
|
||||
ebb
|
||||
);
|
||||
ebb,
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
for ebb in self.func.jump_tables[jt].iter() {
|
||||
if lr.is_livein(*ebb, &self.func.layout) {
|
||||
return fatal!(
|
||||
errors,
|
||||
return errors.fatal((
|
||||
inst,
|
||||
format!(
|
||||
"Table.case: {} is diverted to {} and live in to {}",
|
||||
value,
|
||||
d.to.display(&self.reginfo),
|
||||
ebb
|
||||
);
|
||||
ebb,
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user