Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Nat and Int instead of Usize and Isize #308

Open
sonmarcho opened this issue Aug 20, 2024 · 0 comments
Open

Use Nat and Int instead of Usize and Isize #308

sonmarcho opened this issue Aug 20, 2024 · 0 comments

Comments

@sonmarcho
Copy link
Member

sonmarcho commented Aug 20, 2024

In many situations, reasoning about the bounds of Usize and Isize is very cumbersome (and sometimes, it leads to proof obligations that we don't know how to discharge), while reasoning about those bounds often doesn't really make sense.

For instance, the type Usize is often used to count the length of an array, a vector or a string, or the number of elements in a collection. If, say, we have a function which repeatedly adds elements in a vector, it can be hard (if not really possible) to properly state the precondition which will give us that the length of the vector will not overflow Usize.max. On the other hand, reasoning about this overflow often doesn't make sense: because of hardware limitations (that we don't model), it is likely that the Rust program will have run out of memory long before the length of the vector reaches Usize.max.

For this reason, we need to implement alternative definitions for Usize and Isize to model them as unbounded integers (this requires writing alternative definitions for Vec, Vec.len, Vec.push, etc.), as well as a way of switching (when calling Aeneas) between the bounded and the unbounded models.

In order to make the two versions of the definitions coexist in Lean, a possibility is maybe to use namespaces, and open the proper namespaces at the top of the generated files.

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

No branches or pull requests

1 participant