Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 80
Add Flux specifications to path/bstr/hash/time#438
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
f5fa3beaa7871ab4b51ed918a46b1750a085cf4d900375ccdFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -479,6 +479,7 @@ impl AsciiChar { | ||
| /// `b` must be in `0..=127`, or else this is UB. | ||
| #[unstable(feature = "ascii_char", issue = "110998")] | ||
| #[inline] | ||
| #[cfg_attr(flux, flux::spec(fn(b: u8{b <= 127}) -> Self))] | ||
| #[requires(b <= 127)] | ||
| #[ensures(|result| *result as u8 == b)] | ||
| pub const unsafe fn from_u8_unchecked(b: u8) -> Self { | ||
| @@ -516,6 +517,10 @@ impl AsciiChar { | ||
| /// when writing code using this method, since the implementation doesn't | ||
| /// need something really specific, not to make those other arguments do | ||
| /// something useful. It might be tightened before stabilization.) | ||
| // Only `d < 64` is required for safety as described above, but we use `d < 10` as | ||
| // in the `assert_unsafe_precondition` inside. See https://github.com/rust-lang/rust/pull/129374 | ||
| // for some context about the discrepancy. | ||
| #[cfg_attr(flux, flux::spec(fn(d: u8{d < 10}) -> Self))] | ||
| #[unstable(feature = "ascii_char", issue = "110998")] | ||
| #[inline] | ||
| #[track_caller] | ||
| @@ -536,8 +541,8 @@ impl AsciiChar { | ||
| } | ||
| /// Gets this ASCII character as a byte. | ||
| #[cfg_attr(flux, flux::spec(fn (Self) -> u8{v: v <= 127}))] | ||
tautschnig marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| #[unstable(feature = "ascii_char", issue = "110998")] | ||
| #[cfg_attr(flux, flux::spec(fn(Self) -> u8{v: v <= 127}))] | ||
| #[inline] | ||
| pub const fn to_u8(self) -> u8 { | ||
| self as u8 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -13,9 +13,22 @@ macro_rules! pattern_type { | ||
| }; | ||
| } | ||
| // The Flux spec for the `trait RangePattern` below uses | ||
| // [associated refinements](https://flux-rs.github.io/flux/tutorial/08-traits.html) | ||
carolynzech marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| // The `sub_one` method may only be safe for certain values, | ||
| // e.g. when the value is not the "minimum of the type" as in the | ||
| // case of the `char` implementation below. To specify this precondition generically | ||
| // 1. at the trait level, we introduce the predicate `sub_ok` | ||
| // which characterizes the "valid" values at which `sub_one` | ||
| // can be safely called, and by default, specify this predicate | ||
| // is "true"; | ||
| // 2. at the impl level, we can provide a type-specific implementation | ||
| // of `sub_ok` that permits the verification of the impl for that type. | ||
| /// A trait implemented for integer types and `char`. | ||
| /// Useful in the future for generic pattern types, but | ||
| /// used right now to simplify ast lowering of pattern type ranges. | ||
| #[cfg_attr(flux, flux::assoc(fn sub_ok(self: Self) -> bool { true }))] | ||
tautschnig marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| #[unstable(feature = "pattern_type_range_trait", issue = "123646")] | ||
| #[rustc_const_unstable(feature = "pattern_type_range_trait", issue = "123646")] | ||
| #[const_trait] | ||
| @@ -33,6 +46,7 @@ pub trait RangePattern { | ||
| const MAX: Self; | ||
| /// A compile-time helper to subtract 1 for exclusive ranges. | ||
| #[cfg_attr(flux, flux::spec(fn (self: Self{<Self as RangePattern>::sub_ok(self)}) -> Self))] | ||
| #[lang = "RangeSub"] | ||
| #[track_caller] | ||
| fn sub_one(self) -> Self; | ||
| @@ -61,12 +75,16 @@ impl_range_pat! { | ||
| u8, u16, u32, u64, u128, usize, | ||
| } | ||
| // The "associated refinement" `sub_ok` is defined as `non-zero` for `char`, to let Flux | ||
| // verify that the `self as u32 -1` in the impl does not underflow. | ||
| #[cfg_attr(flux, flux::assoc(fn sub_ok(self: char) -> bool { 0 < char_to_int(self)}))] | ||
| #[rustc_const_unstable(feature = "pattern_type_range_trait", issue = "123646")] | ||
| impl const RangePattern for char { | ||
| const MIN: Self = char::MIN; | ||
| const MAX: Self = char::MAX; | ||
| #[cfg_attr(flux, flux::spec(fn (self: char{<char as RangePattern>::sub_ok(self)}) -> char))] | ||
| fn sub_one(self) -> Self { | ||
| match char::from_u32(self as u32 - 1) { | ||
| None => panic!("exclusive range to start of valid chars"), | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.