Skip to content

Make Set and Map finite, add ISet and IMap.#2486

Draft
jaylorch wants to merge 167 commits into
verus-lang:mainfrom
jaylorch:sets-typed-finite
Draft

Make Set and Map finite, add ISet and IMap.#2486
jaylorch wants to merge 167 commits into
verus-lang:mainfrom
jaylorch:sets-typed-finite

Conversation

@jaylorch
Copy link
Copy Markdown
Collaborator

Set<A> and Map<A> now represent finite sets and maps, respectively. ISet<A> and IMap<A> are the new names for the old-style possibly-infinite sets and maps.

This new design is motivated because (1) it allows recursive types, such as having an enum T with a Set<T> field; and (2) finite sets are quite common in user code, and it's easy to go down a wild goose chase trying to get an ambient broadcast property to instantiate that turns out to be a missing .finite().

The simplest porting path for existing code is to use the infinite versions, which work like the previous single Set and Map. Replace Set with ISet, Map with IMap, set! with iset!, and map! with imap!.

To exploit the finite sets, use the Set and Map types. Where you might have specified a set domain with a predicate (boolean closure) before, now you might start with a finite constructor and transform it with map or filter.

let evens_lt_100 = Set::new(|x| 0 <= x < 100 && x%2==0); // old predicate constructor; now produces an `Option<Set<int>>` that you demonstrate is `Some` by proving it's finite.
let evens_lt_100 = Set::int_range(0, 100).filter(|x| x % 2 == 0); // new constructor starts with finite int range

let trees = Set::int_range(5).map(|x| tree_constructor(x)); // Construct a set of trees, one per int [0,5)

Or, even better, use the recently added set_build! macro to produce a finite set. To produce a finite map, construct the finite domain as a Set and use it as the first parameter to the new Map::new.

This PR addresses issue #1512.

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

@jaylorch jaylorch marked this pull request as draft May 25, 2026 02:46
@jaylorch jaylorch marked this pull request as ready for review May 25, 2026 05:14
@jaylorch jaylorch requested a review from tjhance May 25, 2026 05:14
@jaylorch
Copy link
Copy Markdown
Collaborator Author

Oh, I just realized I haven't made it possible to have a recursive type A using Map<A, B>. Converting to draft....

@jaylorch jaylorch marked this pull request as draft May 25, 2026 13:39
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