Skip to content

Use a table of powers of ten in the decimal_seq Kani annotations - #704

Merged
feliperodri merged 1 commit into
model-checking:sync-2026-08-21from
srivatsansamraj:decimal-seq-pow10-687
Oct 3, 2026
Merged

feliperodri merged 1 commit into
model-checking:sync-2026-08-21from
srivatsansamraj:decimal-seq-pow10-687

Conversation

@srivatsansamraj

Copy link
Copy Markdown

On this sync, check_number_of_digits_decimal_left_shift fails and check_round does not finish; partition 2 of run 35923786600 was cancelled after 6 h. Both come from u64::pow. The new pow goes through strict_pow to checked_pow, whose loop carries loop_invariant(self == 0 || (acc > 0 && base > 0)) from #637, so under -Z loop-contracts a pow with a non-constant exponent yields only some positive value. The counterexample Kani reports is shift = 9, n = 2, with 512 < 10u64.pow(3) evaluating to false.

This replaces 10u64.pow(..) in the loop invariant of DecimalSeq::round and in the harness with a POW10 table. #637's invariant, which NonZero::checked_pow needs, stays as it is.

With the pinned Kani (783e7f7d1), the four decimal_seq_verify harnesses pass: check_round in 1.5 s and check_number_of_digits_decimal_left_shift in 30 s.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

@srivatsansamraj
srivatsansamraj requested a review from a team as a code owner September 30, 2026 06:38

@feliperodri feliperodri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved — verified locally on this branch with the pinned Kani (783e7f7):

without this PR with it
check_number_of_digits_decimal_left_shift fails on 1u64 << shift < 10u64.pow(n as u32 + 1), as in CI passes (49 s)
check_round no result after 4.5+ min (CI: cancelled at 6 h) passes (2.6 s)
check_left_shift, check_right_shift — pass

POW10 is exactly 10⁰…10¹⁹ and #[cfg(kani)]-only, and round returns early unless decimal_point < 19, so POW10[kani::index] stays in bounds. Still needed after the move to nightly-2026-09-25, since #637's checked_pow invariant is unchanged there.

@feliperodri
feliperodri merged commit ea9ef00 into model-checking:sync-2026-08-21 Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants