Skip to content

Commit b3e5938

Browse files
devinDevinWatson
authored andcommitted
Name the advance_by fold model and the SplitInternal harness after what they actually do
Two verification-only renames, no semantic change to any proof: - array/iter/iter_inner.rs: kani_fold_bounded32 -> kani_fold_arity32, and check_kani_fold_bounded32_soundness -> check_kani_fold_arity32_soundness. The 32 is the chunk ARITY of as_chunks::<32>(), not a bound on the input string; Chars::advance_by still runs on a str of symbolic length up to MAX_ALLOCATION_BYTES. The doc comment now says so, and says the model is an over-approximation of the per-chunk reduction whose output range 0..=32 is still exact (soundness + range surjectivity in the same harness). - str/iter.rs: check_split_internal_next_match_back -> check_split_internal_next_back_via_matcher, with a comment naming the arm it covers (self.matcher.next_match_back() inside SplitInternal::next_back). SplitInternal has no method of that name; issue #279 notes the page's wording. Re-verified on the new bytes at the pinned tools (nightly-2026-10-23, Kani c5e65fdfc3e1, CI flags, --object-bits 12, 8 GiB per CBMC process): 26/26 SUCCESSFUL (25 str::iter::verify + array::iter), 7m13s wall, 6.68 GB peak RSS.
1 parent c2cf113 commit b3e5938

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

‎library/core/src/array/iter/iter_inner.rs‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -328,14 +328,20 @@ impl<T> PolymorphicIter<[MaybeUninit<T>]> {
328328
#[cfg(kani)]
329329
use crate::kani;
330330

331-
// Loop-free sound over-approximation of `PolymorphicIter::fold` on `bool/u8` sum (total <= 32).
331+
// Loop-free model of `PolymorphicIter::fold` for one array chunk, on a `bool`/`u8` sum.
332+
//
333+
// "32" is the ARITY of the chunk (`as_chunks::<32>()` yields chunks of exactly 32 elements),
334+
// NOT a bound on the input string: `Chars::advance_by` still takes a `str` of symbolic length
335+
// up to `MAX_ALLOCATION_BYTES`. The model is exact at that arity -- `check_kani_fold_arity32_soundness`
336+
// shows real `PolymorphicIter::fold` over a 32-element chunk always returns `res <= total` and
337+
// consumes the iterator, and the same harness shows every value the model admits is realized by
338+
// the real `fold` for some 32-Boolean valuation (range surjectivity).
339+
//
332340
// Implemented as an inherent helper rather than an attached `PolymorphicIter::fold` contract
333-
// (avoiding generic-method contract limits, cf. kani#4084), and paired with
334-
// `check_kani_fold_bounded32_soundness` proving real `PolymorphicIter::fold` satisfies
335-
// `res <= total && len == 0` for all 2^32 Boolean valuations.
341+
// (avoiding generic-method contract limits, cf. kani#4084).
336342
#[cfg(kani)]
337343
impl<T> PolymorphicIter<[MaybeUninit<T>]> {
338-
pub(super) fn kani_fold_bounded32<B, F>(&mut self, mut accum: B, f: F) -> B
344+
pub(super) fn kani_fold_arity32<B, F>(&mut self, mut accum: B, f: F) -> B
339345
where
340346
F: FnMut(B, T) -> B,
341347
{
@@ -357,7 +363,7 @@ impl<T> PolymorphicIter<[MaybeUninit<T>]> {
357363

358364
#[cfg(kani)]
359365
#[kani::proof]
360-
pub fn check_kani_fold_bounded32_soundness() {
366+
pub fn check_kani_fold_arity32_soundness() {
361367
let values: [bool; 32] = [
362368
kani::any::<bool>(),
363369
kani::any::<bool>(),
@@ -405,7 +411,7 @@ pub fn check_kani_fold_bounded32_soundness() {
405411
kani::cover(res > 0 && res < 32, "mixed values");
406412

407413
// Range surjectivity witness: every modeled output `(IndexRange::zero_to(0), target)`
408-
// admitted by `kani_fold_bounded32` is realized by real `PolymorphicIter::fold`.
414+
// admitted by `kani_fold_arity32` is realized by real `PolymorphicIter::fold`.
409415
let target: u8 = kani::any::<u8>() % 33;
410416
let witness: [bool; 32] = [
411417
0 < target,

‎library/core/src/str/iter.rs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2636,8 +2636,12 @@ pub(super) mod verify {
26362636
cover!(res.is_none());
26372637
}
26382638

2639+
// Covers `SplitInternal::next_back`'s first-search arm, the one that asks the pattern
2640+
// matcher for a match backwards (`self.matcher.next_match_back()`). `SplitInternal` has no
2641+
// method of that name (issue #279 notes the challenge page's wording); the harness name
2642+
// follows the call it exercises.
26392643
#[kani::proof]
2640-
pub fn check_split_internal_next_match_back() {
2644+
pub fn check_split_internal_next_back_via_matcher() {
26412645
let s = any_haystack();
26422646
let mut split = any_split(s);
26432647
let skip_trailing = !split.allow_trailing_empty;
@@ -2903,7 +2907,7 @@ pub(super) mod verify {
29032907
#[kani::stub(crate::str::validations::utf8_char_width, stub_utf8_char_width)]
29042908
#[kani::stub(
29052909
crate::array::iter::iter_inner::PolymorphicIter::fold,
2906-
crate::array::iter::iter_inner::PolymorphicIter::kani_fold_bounded32
2910+
crate::array::iter::iter_inner::PolymorphicIter::kani_fold_arity32
29072911
)]
29082912
pub fn check_chars_advance_by() {
29092913
let s = any_haystack();

0 commit comments

Comments
 (0)