Repository navigation
yrc: state that the epoch period is never 0 - #26884
Merged
Merged
Conversation
finishCollection divides by YrcEpochLen * slotsInPlay(). slotsInPlay only promises 0 <= result, but gParSlots starts at 1 and only grows, so the divisor is never 0. Say so with an assume, so a prover (Nimony's staticContracts, which now treats a divisor as an obligation) can discharge it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Dec 4, 2026
planetis-m
added a commit
to planetis-m/nimony
that referenced
this pull request
Dec 4, 2026
yrc.nim's epoch period now states that it is never 0, which the division-by-zero obligation needs under --mm:yrc. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
planetis-m
added a commit
to planetis-m/nimony
that referenced
this pull request
Dec 4, 2026
yrc.nim's epoch period now states that it is never 0, which the division-by-zero obligation needs under --mm:yrc. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Araq
pushed a commit
to nim-lang/nimony
that referenced
this pull request
Dec 5, 2026
… divisor panics at run time (#3338) Fixes planetis-m/nimony-bugs-llms#666. Integer `div`/`mod`, signed and unsigned (so `/%` and `%%` too), now owes `divisor != 0`. The contract prover judges that the way it judges an array index: - **Proven:** a non-zero constant, a `sizeof`, or a divisor that the facts on the path keep away from zero (`if b > 0:`, `s.len > 0`). No run-time check is emitted. - **Disproven:** the divisor is known to be 0 on that path. This is a compile-time error in every mode: `var z = 0; echo 1 div z` reports "division by zero: 'z' is 0". - **Undecided:** a run-time check is emitted, and `nimCheckDiv` panics with `division by zero`. Under `{.feature: "staticContracts".}` it is an error instead ("cannot prove that the divisor … is not 0"). `runtimeContracts` skips the judgement, and `-d:danger` removes the check. **IR:** `(div|mod T X X .X?)`. The trailing `.` marks a discharged obligation, like the bounds of `(arrat …)`. Only `contracts_fir.copyWithVerdicts` writes it, and only `hexer/desugar.trDivMod` reads and drops it. `doc/tags.md` is updated. **Stdlib:** - `/%` and `%%` become templates, so the obligation is judged at the call site, as for `div`. - `dec2flt` guards its `IntPow10` divisor. **Nim runtime pin:** `lib/std/system/upstream.commit` moves to nim-lang/Nim#26884 (merged). Nim's `yrc.nim`, compiled here under `staticContracts`, divides by `YrcEpochLen * slotsInPlay()`, and that change adds the `{.assume: 1 <= inPlay.}` that discharges the obligation. **Not covered:** `if b != 0:` does not discharge the obligation, because the prover has no disequality facts. Such a divisor keeps the run-time check, or is an error under `staticContracts`. Guards written `b > 0` work. **Docs:** `doc/language.md` (the rule, after "Signed overflow"), `doc/differences.md`, `doc/internals/failure_modes.md`, `doc/tags.md`. **Tests:** - New: - `rtchecks/tdivbyzero`: signed, a zero the prover cannot see. - `rtchecks/tdivbyzero_unsigned`: the same for unsigned. - `errmsgs/tdivbyzero`: a divisor known to be zero. - `contracts/tdivproven`: constant, guarded and `sizeof` divisors in a `staticContracts` module; the generated C has no check. - The first three fail on master. - Linux amd64: tests/nimony 1476/1476, tests/boot, `hastur native` 207/207. - arm64 (under qemu): rtchecks and contracts pass. - The full CI tester (`tools/tester.nim`) passes locally on Linux amd64: tests 1530/1530, validator 21/21. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
finishCollectiondivides byYrcEpochLen * slotsInPlay().slotsInPlayonly ensures0 <= result, butgParSlotsstarts at 1 and only grows, so the divisor is never 0. This adds a{.assume: 1 <= inPlay.}stating that, with no run-time cost.Needed by nim-lang/nimony#3338. There, integer
div/modby zero becomes astaticContractsobligation, and nimony compiles this file (pinned throughlib/std/system/upstream.commit) inside astaticContractsmodule. Without the assume,--mm:yrcfails with "cannot prove that the divisor 'YrcEpochLen * …' is not 0".Tested:
--mm:yrc --threads:on: a small ref-allocating program runs.tests/nimony/yrcwith this file and Incorrect instantiation of generic procedures #3338: 3/3 pass.🤖 Generated with Claude Code