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

Bounded integers #642

Merged
merged 12 commits into from
May 6, 2024
Merged

Bounded integers #642

merged 12 commits into from
May 6, 2024

Conversation

W95Psp
Copy link
Collaborator

@W95Psp W95Psp commented Apr 29, 2024

This PR:

  • renames the method refine (from the trait Refine, which is implemented by types for which refine types have been defined) into check ("check" is less "refinement-oriented" vocabulary and conveys the right intuition);
  • adds an invariant method to the Refinement trait, so that one can check whether a value satisfies a refinement;
  • use that invariant method to generate a debug_assert! that ensures the refinement holds at runtime (in debug mode only);
  • add a no_debug_runtime_check option to disable that runtime check even in debug mode (useful since that check requires the refined type to impl Clone);
  • introduces a module num_traits that defines a small trait hierarchy for operations we want to support on machine integers;
  • introduces a series of refined type BoundedT, for any machine integer T, all of those types implement traits from num_traits;
  • rewrite the chacha20 example using BoundedUsize<0, 15> instead of preconditions (that reformulation of chacha20 TC in F*).

This PR builds on #643.

TODO:

  • figure out how to name & where to put hax-bounded-integers;
  • add bounded math integers (let's first merge Add support for math integers #629) this is not possible right now because we'd need adt_const_params;
  • move the example out of the crate bounded math crate, or at least behind a #[test];
  • derive more impls for traits on BoundedTs

Future work:

  • implement MachineInt for every primitive type?

@W95Psp W95Psp linked an issue Apr 29, 2024 that may be closed by this pull request
@W95Psp W95Psp force-pushed the bounded-integers branch 3 times, most recently from 4414031 to 4987cf4 Compare April 29, 2024 15:10
@W95Psp W95Psp changed the base branch from main to math-integers April 29, 2024 15:10
@W95Psp W95Psp changed the base branch from math-integers to main April 29, 2024 15:11
@W95Psp W95Psp force-pushed the bounded-integers branch from 4987cf4 to 15e6ad7 Compare April 29, 2024 15:15
@W95Psp W95Psp changed the base branch from main to math-integers April 29, 2024 15:15
@W95Psp W95Psp changed the base branch from math-integers to main April 29, 2024 15:15
@W95Psp W95Psp force-pushed the bounded-integers branch from 15e6ad7 to f0b1251 Compare April 29, 2024 15:52
@W95Psp W95Psp changed the base branch from main to refinements April 29, 2024 15:52
@W95Psp W95Psp mentioned this pull request Apr 29, 2024
@franziskuskiefer franziskuskiefer mentioned this pull request Apr 29, 2024
3 tasks
@W95Psp W95Psp mentioned this pull request Apr 30, 2024
@W95Psp W95Psp force-pushed the bounded-integers branch from f0b1251 to 08c1dc9 Compare April 30, 2024 09:42
Base automatically changed from refinements to main April 30, 2024 12:03
@W95Psp W95Psp force-pushed the bounded-integers branch 6 times, most recently from 1ce7d17 to 16b1dc3 Compare May 2, 2024 11:04
@W95Psp W95Psp marked this pull request as ready for review May 2, 2024 11:57
@W95Psp W95Psp requested a review from franziskuskiefer May 2, 2024 12:32
@W95Psp
Copy link
Collaborator Author

W95Psp commented May 2, 2024

The CI is failing because of the hax-bounded-integers not being found by the CI, I will fix that after your review @franziskuskiefer, I expect us to want hax-bounded-integers somewhere else anyway

Copy link
Member

@franziskuskiefer franziskuskiefer left a comment

Choose a reason for hiding this comment

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

We'll want to do changes here. But let's get something in and improve later when we know better what exactly we need.

hax-lib/src/lib.rs Outdated Show resolved Hide resolved
@W95Psp W95Psp force-pushed the bounded-integers branch from 7040001 to f4cf13e Compare May 6, 2024 10:07
@W95Psp W95Psp force-pushed the bounded-integers branch from 167bef9 to d67383d Compare May 6, 2024 10:50
@W95Psp W95Psp enabled auto-merge May 6, 2024 10:51
@W95Psp W95Psp added this pull request to the merge queue May 6, 2024
Merged via the queue into main with commit fa92539 May 6, 2024
11 checks passed
@W95Psp W95Psp deleted the bounded-integers branch May 6, 2024 11:21
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.

Bounded integers
2 participants