Skip to content

Commit 242f5f7

Browse files
committed
Add specs for digit_unchecked + comments
1 parent 30bd65f commit 242f5f7

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

.github/workflows/flux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99

1010
env:
1111
FIXPOINT_VERSION: "556104ba5508891c357b0bdf819ce706e93d9349"
12-
FLUX_VERSION: "347252ab34de1594a7531d9bdc4477369623ead3"
12+
FLUX_VERSION: "bfecf2ae0d181993c4e07f3233f7e04c5ed5ad1a"
1313

1414
jobs:
1515
check-flux-on-core:

library/core/src/ascii/ascii_char.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ impl AsciiChar {
471471
/// `b` must be in `0..=127`, or else this is UB.
472472
#[unstable(feature = "ascii_char", issue = "110998")]
473473
#[inline]
474+
#[cfg_attr(flux, flux::spec(fn(b: u8{b <= 127}) -> Self))]
474475
#[requires(b <= 127)]
475476
#[ensures(|result| *result as u8 == b)]
476477
pub const unsafe fn from_u8_unchecked(b: u8) -> Self {
@@ -508,6 +509,7 @@ impl AsciiChar {
508509
/// when writing code using this method, since the implementation doesn't
509510
/// need something really specific, not to make those other arguments do
510511
/// something useful. It might be tightened before stabilization.)
512+
#[cfg_attr(flux, flux::spec(fn(d: u8{d < 10}) -> Self))]
511513
#[unstable(feature = "ascii_char", issue = "110998")]
512514
#[inline]
513515
#[track_caller]

library/core/src/num/uint_macros.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ macro_rules! uint_impl {
582582
without modifying the original"]
583583
#[inline(always)]
584584
#[track_caller]
585+
#[cfg_attr(flux, flux::spec(fn(self: Self, rhs: Self{self + rhs <= $MaxV}) -> Self[self + rhs]))]
585586
#[requires(!self.overflowing_add(rhs).1)]
586587
pub const unsafe fn unchecked_add(self, rhs: Self) -> Self {
587588
assert_unsafe_precondition!(

library/core/src/pat.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ macro_rules! pattern_type {
1313
};
1414
}
1515

16+
// The Flux spec for the `trait RangePattern` below uses
17+
// [associated refinements](https://flux-rs.github.io/flux/tutorial/08-traits.html)
18+
// The `sub_one` method may only be safe for certain values,
19+
// e.g. when the value is not the "minimum of the type" as in the
20+
// case of the `char` implementation below. To specify this precondition generically
21+
// 1. at the trait level, we introduce the predicate `sub_ok`
22+
// which characterizes the "valid" values at which `sub_one`
23+
// can be safely called, and by default, specify this predicate
24+
// is "true";
25+
// 2. at the impl level, we can provide a type-specific implementation
26+
// of `sub_ok` that permits the verification of the impl for that type.
27+
1628
/// A trait implemented for integer types and `char`.
1729
/// Useful in the future for generic pattern types, but
1830
/// used right now to simplify ast lowering of pattern type ranges.
@@ -63,13 +75,16 @@ impl_range_pat! {
6375
u8, u16, u32, u64, u128, usize,
6476
}
6577

78+
// The "associated refinement" `sub_ok` is defined as `non-zero` for `char`, to let Flux
79+
// verify that the `self as u32 -1` in the impl does not underflow.
6680
#[cfg_attr(flux, flux::assoc(fn sub_ok(self: char) -> bool { 0 < char_to_int(self)}))]
6781
#[rustc_const_unstable(feature = "pattern_type_range_trait", issue = "123646")]
6882
impl const RangePattern for char {
6983
const MIN: Self = char::MIN;
7084

7185
const MAX: Self = char::MAX;
7286

87+
7388
#[cfg_attr(flux, flux::spec(fn (self: char{<char as RangePattern>::sub_ok(self)}) -> char))]
7489
fn sub_one(self) -> Self {
7590
match char::from_u32(self as u32 - 1) {

0 commit comments

Comments
 (0)