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>
88 lines
2.1 KiB
Plaintext
88 lines
2.1 KiB
Plaintext
// Specification of `sort_desc`: the result lists every index of `keys` once,
|
|
// highest version first, ties in their original order.
|
|
|
|
///|
|
|
predicate same_length(keys : FixedArray[Key], idx : FixedArray[Int32]) {
|
|
idx.length() == keys.length()
|
|
}
|
|
|
|
///|
|
|
/// The first `n` entries are all below `n`.
|
|
predicate below(idx : FixedArray[Int32], n : Int32) {
|
|
∀ p : Int32, (0 <= p && p < n) → (0 <= idx[p] && idx[p] < n)
|
|
}
|
|
|
|
///|
|
|
predicate distinct(idx : FixedArray[Int32], n : Int32) {
|
|
∀ p : Int32, ∀ q : Int32, (0 <= p && p < q && q < n) → idx[p] != idx[q]
|
|
}
|
|
|
|
///|
|
|
/// Index `i` comes before index `j` in the result.
|
|
predicate before(keys : FixedArray[Key], i : Int32, j : Int32) {
|
|
key_lt(keys[j], keys[i]) || (key_eq(keys[j], keys[i]) && i < j)
|
|
}
|
|
|
|
///|
|
|
predicate ordered(keys : FixedArray[Key], idx : FixedArray[Int32], n : Int32) {
|
|
∀ p : Int32, ∀ q : Int32, (0 <= p && p < q && q < n) →
|
|
before(keys, idx[p], idx[q])
|
|
}
|
|
|
|
///|
|
|
/// Everything in `(j, n]` comes after the entry being inserted at `j`.
|
|
predicate after_hole(
|
|
keys : FixedArray[Key],
|
|
idx : FixedArray[Int32],
|
|
j : Int32,
|
|
n : Int32,
|
|
) {
|
|
∀ q : Int32, (j < q && q <= n) → before(keys, idx[j], idx[q])
|
|
}
|
|
|
|
///|
|
|
/// The first `n + 1` entries are ordered, ignoring the one at `j`.
|
|
predicate ordered_except(
|
|
keys : FixedArray[Key],
|
|
idx : FixedArray[Int32],
|
|
j : Int32,
|
|
n : Int32,
|
|
) {
|
|
∀ p : Int32, ∀ q : Int32, (0 <= p && p < q && q <= n && p != j && q != j) →
|
|
before(keys, idx[p], idx[q])
|
|
}
|
|
|
|
///|
|
|
predicate sort_post(keys : FixedArray[Key], idx : FixedArray[Int32]) {
|
|
sorted_prefix(keys, idx, keys.length())
|
|
}
|
|
|
|
///|
|
|
/// The first `n` entries are `0..<n`, reordered.
|
|
predicate sorted_prefix(
|
|
keys : FixedArray[Key],
|
|
idx : FixedArray[Int32],
|
|
n : Int32,
|
|
) {
|
|
same_length(keys, idx) &&
|
|
below(idx, n) &&
|
|
distinct(idx, n) &&
|
|
ordered(keys, idx, n)
|
|
}
|
|
|
|
///|
|
|
/// Entry `n` is being inserted and has reached position `j`.
|
|
predicate sinking(
|
|
keys : FixedArray[Key],
|
|
idx : FixedArray[Int32],
|
|
j : Int32,
|
|
n : Int32,
|
|
) {
|
|
same_length(keys, idx) &&
|
|
below(idx, n + 1) &&
|
|
distinct(idx, n + 1) &&
|
|
idx[j] == n &&
|
|
after_hole(keys, idx, j, n) &&
|
|
ordered_except(keys, idx, j, n)
|
|
}
|