Skip to content

Implement BoundedArbitrary for BTreeMap and BTreeSet#4626

Open
hz2 wants to merge 2 commits into
model-checking:mainfrom
hz2:bounded-arbitrary-btree
Open

Implement BoundedArbitrary for BTreeMap and BTreeSet#4626
hz2 wants to merge 2 commits into
model-checking:mainfrom
hz2:bounded-arbitrary-btree

Conversation

@hz2

@hz2 hz2 commented Jul 9, 2026

Copy link
Copy Markdown

Summary

  • Add BoundedArbitrary implementations for BTreeMap<K, V> and BTreeSet<V>
  • Follow the same pattern as the existing HashMap and HashSet impls in library/kani/src/bounded_arbitrary.rs
  • Add test harnesses in tests/expected/bounded-arbitrary/btree/

Motivation

BTreeMap and BTreeSet operations cause state-space explosion during verification due to tree rebalancing internals (see #1251, #3965). Users currently have no idiomatic way to generate bounded symbolic BTree collections.

The existing BoundedArbitrary impls cover Vec, Box<[T]>, String, HashMap, and HashSet -- but BTreeMap and BTreeSet are absent despite being commonly used in Rust codebases.

This addition lets users write:

let map: BTreeMap<u8, bool> = kani::bounded_any::<_, 4>();

Testing

Added tests/expected/bounded-arbitrary/btree/btree.rs with cover property checks for sizes 0, 1, and 2 on both BTreeMap and BTreeSet, matching the structure of tests/expected/bounded-arbitrary/hash/hash.rs.

Related issues: #1251, #3965

@github-actions github-actions Bot added Z-EndToEndBenchCI Tag a PR to run benchmark CI Z-CompilerBenchCI Tag a PR to run benchmark CI labels Jul 9, 2026
@hz2
hz2 force-pushed the bounded-arbitrary-btree branch 2 times, most recently from 41da7be to 8e142d8 Compare July 10, 2026 14:06
@hz2
hz2 marked this pull request as ready for review July 10, 2026 14:06
@hz2
hz2 requested a review from a team as a code owner July 10, 2026 14:06
@feliperodri
feliperodri requested a review from Copilot July 11, 2026 14:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread library/kani/src/bounded_arbitrary.rs
Comment thread library/kani/src/bounded_arbitrary.rs
Comment thread tests/expected/bounded-arbitrary/btree/btree.rs
Comment thread tests/expected/bounded-arbitrary/btree/btree.rs
@feliperodri

Copy link
Copy Markdown
Contributor

@hz2 don't forget to update the branch and address all CI issues before merging. Thanks for the contribution! 🦀

hz2 and others added 2 commits July 17, 2026 13:46
Add BoundedArbitrary implementations for BTreeMap<K, V> and BTreeSet<V>,
following the same pattern as the existing HashMap and HashSet impls.

BTreeMap and BTreeSet operations cause state-space explosion during
verification due to tree rebalancing internals. Providing a bounded
constructor via BoundedArbitrary gives users an idiomatic way to generate
symbolic BTree collections with controlled size.

Usage:
    let map: BTreeMap<u8, bool> = kani::bounded_any::<_, 4>();
Note that duplicate arbitrary keys/values collapse cardinality, and
assert the upper-bound invariant explicitly in the test harnesses.
@hz2
hz2 force-pushed the bounded-arbitrary-btree branch from 8e142d8 to afa39be Compare July 17, 2026 20:48
@hz2
hz2 requested a review from feliperodri July 17, 2026 23:27
@feliperodri
feliperodri enabled auto-merge July 18, 2026 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Z-CompilerBenchCI Tag a PR to run benchmark CI Z-EndToEndBenchCI Tag a PR to run benchmark CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants