Skip to content

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

nilehmann
Copy link

@nilehmann nilehmann commented Aug 1, 2025

This PR adds flux specifications for checking the following modules in core

  • pat
  • bstr
  • hash
  • time

In particular, it verifies that Nanoseconds is correctly used with values within the range.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

@nilehmann nilehmann requested a review from a team as a code owner August 1, 2025 00:51
Copy link
Member

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

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

Given I'm not intimately familiar with Flux some of the annotations introduced in this PR are not entirely clear to me, see detailed comments. Please include some comments. Thank you!

@@ -49,12 +53,14 @@ macro_rules! define_valid_range_type {
/// Immediate language UB if `val == 0`, as it violates the validity
/// invariant of this type.
#[inline]
#[cfg_attr(flux, flux::spec(fn (val: $int{ $low <= cast(val) && cast(val) <= $high }) -> Self[{val:cast(val)}]))] // NOTE: `val == 0` comments are stale(?)
Copy link
Member

Choose a reason for hiding this comment

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

I'd agree that 0 is not relevant here (anymore?) - would you mind creating an upstream PR that proposes to fix this?

Choose a reason for hiding this comment

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

Sure thing, @nilehmann will you be able to do this?

Copy link
Author

Choose a reason for hiding this comment

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

will do

Copy link
Author

Choose a reason for hiding this comment

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

@@ -508,6 +509,7 @@ 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.)
#[cfg_attr(flux, flux::spec(fn(d: u8{d < 10}) -> Self))]
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be d <= 64?

Copy link
Author

Choose a reason for hiding this comment

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

The safety comment doesn't match the UB assertion inside the function, so I wasn't sure which one to choose. If the intention is to keep the more relaxed version, then maybe we should change the UB assertion upstream.

Choose a reason for hiding this comment

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

Yes I picked 10 because that’s what the assertion inside the function checked..

Copy link
Member

Choose a reason for hiding this comment

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

I think we should get something changed upstream. It doesn't seem right to have an assert_unsafe_precondition with d < 10 here as there isn't really anything unsafe up until 63 (could be a debug_assert instead). If they, however, deem it unsafe between 10 and 63 because of some other piece of code then the comment should be changed.

Copy link
Author

Choose a reason for hiding this comment

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

I think they just yoloed it rust-lang#129374

Copy link
Member

Choose a reason for hiding this comment

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

Thank you for digging deeper! So I'd say pick whichever you prefer at this point, but please include a comment noting the disparity (and possibly linking to that PR).

Choose a reason for hiding this comment

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

@nilehmann FWIW the code checks if we change it to d <= 64 (as in the unchecked_add is fine...)

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.

5 participants