Files
orbit/src/kernel/nat.mbt
T
nandiandClaude Opus 5.5 83e694c6c4
Rolling Release / build (push) Successful in 1m39s
Rolling Release / publish (push) Successful in 8s
Prove the semver and solver kernel instead of testing it
Move number parsing, version ordering and constraints, version sorting and
solver literals into src/kernel, with contracts checked by moon prove under
overflow-checked integers. Replace the semver behaviour tests with those
proofs, keep tests for string parsing, and run the proofs in CI.

Version numbers are now 64-bit: the old parser silently wrapped at 2^31.
Drop pick_tag, which only tests called.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 16:56:21 -08:00

34 lines
843 B
MoonBit

///|
/// Value of the decimal code points `s`, or -1 if `s` is empty, has a
/// non-digit, or is 10^18 or more.
pub fn parse_nat(
s : FixedArray[Int64],
) -> Int64 where {
proof_require: s.length() < 2147483647,
proof_ensure: r => parse_post(s, r),
proof_ensure: r => valid_or_rejected(r),
} {
let t = FixedArray::make(s.length() + 1, 0L)
for i in 0..<s.length() {
let n = t[i]
let c = s[i]
t[i + 1] = if n < 0L || n > 99999999999999999L || c < 48L || c > 57L {
-1L
} else {
n * 10L + (c - 48L)
}
} where {
proof_invariant: 0 <= i && i <= s.length(),
proof_invariant: trace(s, t, i, t[i]),
proof_invariant: valid_or_rejected(t[i]),
}
let r = t[s.length()]
proof_assert trace(s, t, s.length(), r)
proof_assert decimal(s, r)
if s.length() == 0 {
-1L
} else {
r
}
}