test(core): the control harnesses prove None only on overflow; i32/i64 checked_sub is native

The tightened harnesses assert Some whenever every i128 prefix fits in i64.
That found the default Amount::checked_sub refusing x - MIN on i32/i64 where
the difference fits; both now use the native subtraction. The bridge pins
aging_total(0,0,0,0,MAX) to Some(MAX), bounds the rounded figures to one
unit of the exact value, and covers scales 0..=28. Two smaller worksheet
harnesses (nine terms on i32, seven on i32) found no verdict in 400 s and
300 s: recorded, no harness.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-11-09 12:53:09 -07:00
1 parent 632a1a543c
commit c8cfd32723
4 files changed
+95 -28

No files matched your search

+12
View File
@@ -180,6 +180,12 @@ impl Amount for i32 {
fn checked_add(self, rhs: Self) -> Option<Self> {
i32::checked_add(self, rhs)
}
// The native subtraction: the default negates `rhs` first and so
// refused `x - MIN` even where the difference fits (found by the
// K-U8 harnesses: `None` must mean overflow, and only overflow).
fn checked_sub(self, rhs: Self) -> Option<Self> {
i32::checked_sub(self, rhs)
}
fn checked_neg(self) -> Option<Self> {
i32::checked_neg(self)
}
@@ -234,6 +240,12 @@ impl Amount for i64 {
fn checked_add(self, rhs: Self) -> Option<Self> {
i64::checked_add(self, rhs)
}
// The native subtraction: the default negates `rhs` first and so
// refused `x - MIN` even where the difference fits (found by the
// K-U8 harnesses: `None` must mean overflow, and only overflow).
fn checked_sub(self, rhs: Self) -> Option<Self> {
i64::checked_sub(self, rhs)
}
fn checked_neg(self) -> Option<Self> {
i64::checked_neg(self)
}
+28 -1
View File
@@ -22,6 +22,18 @@ fn aging_total_is_sum() {
assert_eq!(i128::from(t), spec);
kani::cover!(t != 0, "a nonzero total exists");
}
// `None` only on overflow: whenever every running prefix fits in
// `i64` (not only inside the line-range box), the total exists.
let mut run: i128 = 0;
let mut fits = true;
for &v in &b {
run += i128::from(v);
fits &= i64::try_from(run).is_ok();
}
if fits {
assert!(got.is_some(), "every prefix fits, so the total exists");
kani::cover!(run != 0, "a nonzero total from fitting prefixes");
}
if b.iter().all(|v| v.in_line_range()) {
assert!(got.is_some(), "in-range buckets always total");
kani::cover!(
@@ -51,7 +63,14 @@ fn aging_total_is_sum() {
fn control_difference_identity() {
let (balance, docs, unattached): (i64, i64, i64) = (kani::any(), kani::any(), kani::any());
let spec = i128::from(balance) - i128::from(docs) - i128::from(unattached);
if let Some(d) = kernel::control_difference(balance, docs, unattached) {
let got = kernel::control_difference(balance, docs, unattached);
// `None` only on overflow: whenever both steps fit in `i64`, it exists.
let first = i128::from(balance) - i128::from(docs);
if i64::try_from(first).is_ok() && i64::try_from(spec).is_ok() {
assert!(got.is_some(), "both steps fit, so the difference exists");
kani::cover!(spec != 0, "a nonzero difference from fitting steps");
}
if let Some(d) = got {
assert_eq!(i128::from(d), spec);
if d == 0 {
assert_eq!(
@@ -90,6 +109,14 @@ fn reconciliation_total_identity() {
assert_eq!(i128::from(t), spec);
kani::cover!(t != 0, "a nonzero total");
}
// `None` only on overflow: whenever every running prefix fits in
// `i64`, the total exists.
let p1 = i128::from(f[0]) + i128::from(f[1]);
let p2 = p1 + i128::from(f[2]);
if [p1, p2, spec].iter().all(|&p| i64::try_from(p).is_ok()) {
assert!(got.is_some(), "every prefix fits, so the total exists");
kani::cover!(spec != 0, "a nonzero total from fitting prefixes");
}
if f.iter().all(|v| v.in_line_range()) {
assert!(got.is_some());
}