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>
This commit is contained in:
1 parent
2d815bbb75
commit
83e694c6c4
16 files changed
+874
-330
No files matched your search
@@ -0,0 +1,115 @@
|
||||
///|
|
||||
/// A version reduced to integers. `pre` ranks the prerelease: callers must give
|
||||
/// equal prereleases equal ranks and order the others as they compare.
|
||||
pub(all) struct Key {
|
||||
major : Int64
|
||||
minor : Int64
|
||||
patch : Int64
|
||||
pre : Int32
|
||||
}
|
||||
|
||||
///|
|
||||
#derive(Eq, Debug)
|
||||
pub(all) enum Op {
|
||||
Any
|
||||
Ge
|
||||
Le
|
||||
Gt
|
||||
Lt
|
||||
Eq
|
||||
Ne
|
||||
Caret
|
||||
Tilde
|
||||
Prefix
|
||||
NotPrefix
|
||||
}
|
||||
|
||||
///|
|
||||
pub extend Op with Eq::{equal, not_equal}
|
||||
|
||||
///|
|
||||
pub extend Op with Debug::{to_repr}
|
||||
|
||||
///|
|
||||
/// -1, 0 or 1 as `a` is below, equal to or above `b`.
|
||||
pub fn compare(
|
||||
a : Key,
|
||||
b : Key,
|
||||
) -> Int32 where {
|
||||
proof_ensure: r => compare_post(a, b, r),
|
||||
} {
|
||||
if a.major < b.major {
|
||||
-1
|
||||
} else if a.major > b.major {
|
||||
1
|
||||
} else if a.minor < b.minor {
|
||||
-1
|
||||
} else if a.minor > b.minor {
|
||||
1
|
||||
} else if a.patch < b.patch {
|
||||
-1
|
||||
} else if a.patch > b.patch {
|
||||
1
|
||||
} else if a.pre < b.pre {
|
||||
-1
|
||||
} else if a.pre > b.pre {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
/// Whether `v` satisfies the clause `op b`, where `b` was written with `parts`
|
||||
/// components.
|
||||
pub fn matches(
|
||||
op : Op,
|
||||
v : Key,
|
||||
b : Key,
|
||||
parts : Int32,
|
||||
) -> Bool where {
|
||||
proof_require: key_inv(v),
|
||||
proof_require: key_inv(b),
|
||||
proof_require: 1 <= parts && parts <= 3,
|
||||
proof_ensure: r => r == allowed(op, v, b, parts),
|
||||
} {
|
||||
match op {
|
||||
Any => true
|
||||
Ge => compare(v, b) >= 0
|
||||
Le => compare(v, b) <= 0
|
||||
Gt => compare(v, b) > 0
|
||||
Lt => compare(v, b) < 0
|
||||
Eq => compare(v, b) == 0
|
||||
Ne => compare(v, b) != 0
|
||||
Caret =>
|
||||
compare(v, b) >= 0 &&
|
||||
v.major == b.major &&
|
||||
(b.major != 0L || v.minor == b.minor)
|
||||
Tilde =>
|
||||
compare(v, b) >= 0 &&
|
||||
v.major == b.major &&
|
||||
(parts == 1 || v.minor == b.minor)
|
||||
Prefix => same_prefix(v, b, parts)
|
||||
NotPrefix => !same_prefix(v, b, parts)
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
fn same_prefix(
|
||||
v : Key,
|
||||
b : Key,
|
||||
parts : Int32,
|
||||
) -> Bool where {
|
||||
proof_require: key_inv(v),
|
||||
proof_require: key_inv(b),
|
||||
proof_require: 1 <= parts && parts <= 3,
|
||||
proof_ensure: r => r == in_prefix(v, b, parts),
|
||||
} {
|
||||
if parts == 1 {
|
||||
v.major == b.major
|
||||
} else if parts == 2 {
|
||||
v.major == b.major && v.minor == b.minor
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user