Skip to content

Commit acaa672

Browse files
committed
Verify time.rs
1 parent 177d0fd commit acaa672

File tree

6 files changed

+62
-5
lines changed

6 files changed

+62
-5
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: "ebafb8d0ca32d8c0fcd2a0cfef6b1b4bd4dc4a6f"
12+
FLUX_VERSION: "eb448b89b2caf3bb9d3e1ee41d1087d4651934c6"
1313

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

library/core/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,9 @@ check-cfg = [
4747

4848
[package.metadata.flux]
4949
enabled = true
50-
include = [ "src/ascii{*.rs,/**/*.rs}" ]
50+
include = [ "src/ascii*.rs",
51+
"src/pat.rs",
52+
"src/bstr/*.rs",
53+
"src/hash/*.rs",
54+
"src/time.rs",
55+
]

library/core/src/ascii/ascii_char.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,8 @@ impl AsciiChar {
528528
}
529529

530530
/// Gets this ASCII character as a byte.
531+
#[cfg_attr(flux, flux::spec(fn (Self) -> u8{v: v <= 127}))]
531532
#[unstable(feature = "ascii_char", issue = "110998")]
532-
#[cfg_attr(flux, flux::spec(fn(Self) -> u8{v: v <= 127}))]
533533
#[inline]
534534
pub const fn to_u8(self) -> u8 {
535535
self as u8

library/core/src/flux_info.rs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,54 @@
44
/// See the following link for more information on how extensible properties for primitive operations work:
55
/// <https://flux-rs.github.io/flux/guide/specifications.html#extensible-properties-for-primitive-ops>
66
#[flux::defs {
7+
fn char_to_int(x:char) -> int {
8+
cast(x)
9+
}
10+
711
property ShiftRightByFour[>>](x, y) {
812
16 * [>>](x, 4) == x
913
}
1014
11-
property MaskBy15[&](x, y) {
12-
[&](x, y) <= y
15+
property MaskLess[&](x, y) {
16+
[&](x, y) <= x && [&](x, y) <= y
17+
}
18+
19+
property ShiftLeft[<<](n, k) {
20+
0 < k => n <= [<<](n, k)
21+
}
22+
}]
23+
#[flux::specs {
24+
mod hash {
25+
mod sip {
26+
struct Hasher {
27+
k0: u64,
28+
k1: u64,
29+
length: usize, // how many bytes we've processed
30+
state: State, // hash State
31+
tail: u64, // unprocessed bytes le
32+
ntail: usize{v: v <= 8}, // how many bytes in tail are valid
33+
_marker: PhantomData<S>,
34+
}
35+
}
36+
37+
impl BuildHasherDefault {
38+
#[trusted] // https://github.com/flux-rs/flux/issues/1185
39+
fn new() -> Self;
40+
}
41+
}
42+
43+
impl Hasher for hash::sip::Hasher {
44+
fn write(self: &mut Self, msg: &[u8]) ensures self: Self; // mut-ref-unfolding
45+
}
46+
47+
impl Clone for hash::BuildHasherDefault {
48+
#[trusted] // https://github.com/flux-rs/flux/issues/1185
49+
fn clone(self: &Self) -> Self;
50+
}
51+
52+
impl Debug for time::Duration {
53+
#[trusted] // modular arithmetic invariant inside nested fmt_decimal
54+
fn fmt(self: &Self, f: &mut fmt::Formatter) -> fmt::Result;
1355
}
1456
}]
1557
const _: () = {};

library/core/src/num/niche_types.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ macro_rules! define_valid_range_type {
1414
$(#[$m:meta])*
1515
$vis:vis struct $name:ident($int:ident as $uint:ident in $low:literal..=$high:literal);
1616
)+) => {$(
17+
#[cfg_attr(flux, flux::opaque)]
18+
#[cfg_attr(flux, flux::refined_by(val: int))]
19+
#[cfg_attr(flux, flux::invariant($low <= cast(val) && cast(val) <= $high))]
1720
#[derive(Clone, Copy, Eq)]
1821
#[repr(transparent)]
1922
#[rustc_layout_scalar_valid_range_start($low)]
@@ -33,6 +36,7 @@ macro_rules! define_valid_range_type {
3336

3437
impl $name {
3538
#[inline]
39+
#[cfg_attr(flux, flux::spec(fn (val: $int) -> Option<Self[{val: cast(val)}]>))]
3640
pub const fn new(val: $int) -> Option<Self> {
3741
if (val as $uint) >= ($low as $uint) && (val as $uint) <= ($high as $uint) {
3842
// SAFETY: just checked the inclusive range
@@ -49,12 +53,14 @@ macro_rules! define_valid_range_type {
4953
/// Immediate language UB if `val == 0`, as it violates the validity
5054
/// invariant of this type.
5155
#[inline]
56+
#[cfg_attr(flux, flux::spec(fn (val: $int{ $low <= cast(val) && cast(val) <= $high }) -> Self[{val:cast(val)}]))] // NOTE: `val == 0` comments are stale(?)
5257
pub const unsafe fn new_unchecked(val: $int) -> Self {
5358
// SAFETY: Caller promised that `val` is non-zero.
5459
unsafe { $name(val) }
5560
}
5661

5762
#[inline]
63+
#[cfg_attr(flux, flux::spec(fn (self: Self) -> $int[cast(self.val)] ensures $low <= cast(self.val) && cast(self.val) <= $high))]
5864
pub const fn as_inner(self) -> $int {
5965
// SAFETY: This is a transparent wrapper, so unwrapping it is sound
6066
// (Not using `.0` due to MCP#807.)

library/core/src/pat.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ macro_rules! pattern_type {
1616
/// A trait implemented for integer types and `char`.
1717
/// Useful in the future for generic pattern types, but
1818
/// used right now to simplify ast lowering of pattern type ranges.
19+
#[cfg_attr(flux, flux::assoc(fn sub_ok(self: Self) -> bool { true }))]
1920
#[unstable(feature = "pattern_type_range_trait", issue = "123646")]
2021
#[rustc_const_unstable(feature = "pattern_type_range_trait", issue = "123646")]
2122
#[const_trait]
@@ -33,6 +34,7 @@ pub trait RangePattern {
3334
const MAX: Self;
3435

3536
/// A compile-time helper to subtract 1 for exclusive ranges.
37+
#[cfg_attr(flux, flux::spec(fn (self: Self{<Self as RangePattern>::sub_ok(self)}) -> Self))]
3638
#[lang = "RangeSub"]
3739
#[track_caller]
3840
fn sub_one(self) -> Self;
@@ -61,12 +63,14 @@ impl_range_pat! {
6163
u8, u16, u32, u64, u128, usize,
6264
}
6365

66+
#[cfg_attr(flux, flux::assoc(fn sub_ok(self: char) -> bool { 0 < char_to_int(self)}))]
6467
#[rustc_const_unstable(feature = "pattern_type_range_trait", issue = "123646")]
6568
impl const RangePattern for char {
6669
const MIN: Self = char::MIN;
6770

6871
const MAX: Self = char::MAX;
6972

73+
#[cfg_attr(flux, flux::spec(fn (self: char{<char as RangePattern>::sub_ok(self)}) -> char))]
7074
fn sub_one(self) -> Self {
7175
match char::from_u32(self as u32 - 1) {
7276
None => panic!("exclusive range to start of valid chars"),

0 commit comments

Comments
 (0)