Repository navigation
Work Contract Language 2: arithmetic and aggregates (WVP RFC 0008) - #61
SrishtiCode wants to merge 4 commits into
Conversation
Contract::read_as reads a contract as Language 1 or 2; Contract::read stays Language 1. Adds add/sub/scale/abs, count/distinct/sum over closed kinds, full evaluation and ARITHMETIC_RANGE. Reproduces all 697 proposed v2 vectors. Bumps the workspace to 0.3.0 for the new Refusal variant.
Claude Code Review — WCL2 arithmetic and aggregates
View job run · branch: |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Claude finished @SrishtiCode's task in 8m 6s —— View job Claude Code Review — WCL2 arithmetic and aggregates
Claude review: no actionable issues found. PR summaryAdds Work Contract Language 2 (RFC 0008, under review) as a library path via Key changes reviewed
Areas reviewed
Areas skipped
Findings
Residual risks
|
Ponytail · complexity review
net: -5 lines possible. |
|
Claude finished @SrishtiCode's task in 4m 19s —— View job Claude Code Review — WCL2 arithmetic and aggregates (synchronize)
Claude review: no actionable issues found. PR summaryAdds Work Contract Language 2 (RFC 0008, under review) as a library path via Key changes reviewed
Areas reviewed
Areas skipped
Findings
Residual risks
|
Ponytail · complexity review
net: -3 lines possible. |
|
Ponytail: applied the add/sub split. Kept read.rs as is: inlining the eight-element slice makes rustfmt spread it over ten lines, so the change comes out longer, not shorter. |
|
Claude finished @SrishtiCode's task in 5m 24s —— View job Claude Code Review — WCL2 arithmetic and aggregates (synchronize)
Claude review: no actionable issues found. PR summaryAdds Work Contract Language 2 (WVP RFC 0008, under review) as a library-only path via Key changes reviewed
Areas reviewed
Areas skipped
Findings
Residual risks
|
Ponytail · complexity review
net: -3 lines possible. |
zy4
left a comment
There was a problem hiding this comment.
Reviewed: technically sound. I'll approve once RFC 0008 is accepted.
Checked
- Reproduced the conformance locally: work-contract-1 641 cases, work-contract-2 697 cases, plus the one known case not representable in verified-json-v1 (
72-scale-not-whole). - The review decisions on RFC 0008 are all here: a range check on every arithmetic node with a value and on each aggregate value; an exact running total in
i128insidesum, checked only at the end; no short-circuit, soARITHMETIC_RANGEnever depends on evaluation order;timenot numeric, onlytime − time→int;sumonly over non-optional numeric fields;count/distinctover a non-optional field; the aggregate's variable bound in its body only,thantyped in the enclosing scope. - An aggregate has a value only over a closed kind with every body settled, otherwise
UNKNOWN. Contract::readstays Language 1, so WVP v0.2 packages are unchanged.- No overflow is possible in
i128(sums ≤ 10,000 × 2⁶³, products ≤ 2⁶³ × 2⁶³).
Before merging
- Wait for RFC 0008's acceptance (review period until at least 2026-11-24). Then write the decision into the RFC and move the vectors to
test-vectors/work-contract/v2, then merge this. - Yes to
#[non_exhaustive]onRefusalin this PR. The API breaks anyway at 0.3.0, and the next language feature won't need another major bump. - Merge #62 first and rebase, so the chrono ignore isn't in this PR twice.
Not blocking: values are cloned per evaluation now, text included. That's fine under the work bound; borrowing again (Cow) can come later.
For the RFC, not this PR: aggregates are predicates, not terms, so Σ(net + tax) = gross can't be written directly (your F007 finding). I'll decide on #47 whether that goes into 0008 before acceptance, which would restart the period, or into a follow-up.

Implements Work Contract Language 2 as WVP RFC 0008 proposes it (dekrops/wvp#47): exact integer arithmetic on terms, plus
count,countwithdistinct, andsumover the records of a closed kind. This is step 1 of productizing the F007 invoice-to-payment model, which needs arithmetic.What changes
verified-contract:LanguageandContract::read_as(json, Language).Contract::readstill reads Language 1 only, so the verifier and WVP v0.2 packages are unchanged: a package whose contract nameswork-contract-2is still refused, as RFC 0008's compatibility section requires. Versions are never interchanged. Read as Language 2, awork-contract-1contract isCONTRACT_ILL_FORMED(v2 case 27), and Language 2's forms are not forms of Language 1 (CONTRACT_MALFORMED).add,sub,scaleandabs, typed as the RFC says:time − timegivesintseconds;scalefactor out of range isCONTRACT_ILL_FORMED(case 281).{ aggregate, of, in, where, cmp, than }, withfieldforsumanddistinctforcount.Refusal::ArithmeticRange(ARITHMETIC_RANGE).i128. A sum's running total is exact, and only the total is checked.Tests
tests/conformance.rsnow also runswork-contract/v2whenVERIFIED_CONFORMANCE_DIRholds it (RFC 0008's proposed vectors, fromwvpbranchrfc/wcl2-amounts-aggregates), and skips it otherwise.mainand the v2 vectors from that branch:work-contract-1: 641 cases reproduced;work-contract-2: 697 cases reproduced. That's every case except72-scale-not-whole, which uses a fractional JSON number and can't be represented inverified-json-v1, the same as in v1.and.cargo fmt --check,cargo clippy --workspace --all-targets -- -D warnings,cargo test --workspaceandcargo docpass.To run the corpora locally:
Breaking change and version bump
Adding
Refusal::ArithmeticRangeto the public, exhaustiveRefusalenum is a breaking API change forcargo-semver-checks. Followingdocs/development/releasing.md, this PR bumps the workspace from 0.2.0 to 0.3.0 ([workspace.package]and each[workspace.dependencies]entry, thencargo update --workspace).What a consumer changes: an exhaustive
matchonverified_contract::Refusalneeds an arm forArithmeticRange. Nothing in this workspace has one.While the API is breaking anyway,
Refusalcould be made#[non_exhaustive], so the next language feature doesn't need another bump. I left that out; it's your call.Not in this PR
wvp/conformance. That waits until the vectors are published on RFC 0008's acceptance.🤖 Generated with Claude Code