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

add support for lnot on ints and uints #574

Merged
merged 2 commits into from
Dec 13, 2023
Merged

Conversation

enjhnsn2
Copy link
Collaborator

@enjhnsn2 enjhnsn2 commented Dec 7, 2023

fixes #571

Copy link
Member

@nilehmann nilehmann left a comment

Choose a reason for hiding this comment

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

@enjhnsn2 looks good, but some errors need to be fixed.

We also need to add the signatures here. We have a different set of signatures depending on whether overflow checking is enabled. Overflow is not relevant for ! but we still need to duplicate the signature.

Also, can you add a test here?

pub(crate) fn mk_lnot() -> impl IntoIterator<Item = (mir::UnOp, Sig<1>)> {
let int_lnots = INT_TYS.map(|int_ty| {
define_btys! { let Int = BaseTy::Int(int_ty); };
(mir::UnOp::Not, s!(fn(a: Int) -> Int[E::tt()]))
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be

Suggested change
(mir::UnOp::Not, s!(fn(a: Int) -> Int[E::tt()]))
(mir::UnOp::Not, s!(fn(a: Int) -> Int{ v: E::tt() }))

Int[E::tt()] would mean the integer is indexed by a bool which is not well-formed.


let uint_lnots = UINT_TYS.map(|uint_ty| {
define_btys! { let Uint = BaseTy::Uint(uint_ty); };
(mir::UnOp::Not, s!(fn(a: Uint) -> Uint[E::tt()]))
Copy link
Member

Choose a reason for hiding this comment

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

Same here

@enjhnsn2
Copy link
Collaborator Author

enjhnsn2 commented Dec 8, 2023

sgtm, I'll add the duplicate signature and test. I'll take a look at the other int -> int functions to try and find a well-formed replacement for E::tt()

@enjhnsn2
Copy link
Collaborator Author

enjhnsn2 commented Dec 8, 2023

wait, the shift functions use E::tt() and those are int -> int functions. Why is it right there and wrong here? (note, I don't really understand what E::tt() does lol)

(Shl, s!(fn(a: Int, b: Int) -> Int{ v: E::tt() })),

@enjhnsn2
Copy link
Collaborator Author

enjhnsn2 commented Dec 8, 2023

it was my impression (from context) that E::tt() told Flux to treat the operorator as an uninterpreted function, as in the other bitwise operations:

// BIT
(BitAnd, s!(fn(a: Int, b: Int) -> Int{v: E::tt()})),
(BitOr,  s!(fn(a: Int, b: Int) -> Int{v: E::tt()})),

@nilehmann
Copy link
Member

E::tt() means the true formula so you can read Int{v: E::tt()} as Int{v: true}

The problem is not E::tt() but using brackets instead of braces. Using brackets as in Int[E::tt()] would mean Int[true] which is not well-formed because (rust) integers have to be refined by (logical) integers. Instead, Int{v: E::tt()} is an existential type, i.e., the index is existentially quantified and the formula E::tt() is a constraint on the index (a trivial restriction in this case).

Copy link
Member

@nilehmann nilehmann left a comment

Choose a reason for hiding this comment

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

Looks good to me. I'm going to mer it.

@nilehmann nilehmann merged commit 669e99f into flux-rs:main Dec 13, 2023
3 checks passed
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.

bitwise not crashes verification
2 participants