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

(&) bitAnd vs integerAnd #663

Open
PalumboN opened this issue Aug 1, 2023 · 3 comments
Open

(&) bitAnd vs integerAnd #663

PalumboN opened this issue Aug 1, 2023 · 3 comments
Assignees
Labels

Comments

@PalumboN
Copy link
Collaborator

PalumboN commented Aug 1, 2023

C lang defines two ways to perform an AND operation: one for booleans and the other for integers (keep the sign).

To represent this difference, there are two methods in Slang && and bitAnd:.
Sometimes, we fail to choose the correct method, overpassing the checks in Slang and the C compiler.
For example, Alamvic/druid@de7af6f#diff-df143dcb625fab9632c19e459636eca5ed081f3f308b742420b793b23c86ef95L78.

It would be nice to infer the use of && based on the receiver (or arguments) type and compile as expected or at least alert the developers that there is some undefined behaviour (then they can clarify with some unambiguous operation).

@guillep
Copy link
Member

guillep commented Aug 2, 2023

Related are: #523 and #446 by @hernanmd. I think you should take a look at the discussions there.

Before this used to do the wrong translation using the wrong type (the developer has to guess which is which). And we forbid it at compile time to avoid this kind of issues.

@hernanmd
Copy link
Collaborator

hernanmd commented Aug 2, 2023

So what we do?

@guillep
Copy link
Member

guillep commented Aug 2, 2023

AFAIK, @ivojawer (gsoc student) will probably do another pass on those issues to enhance the situation:

  • make & translate as bitAnd if the receiver and arguments are integers
  • make & translate as and: if the receiver and arguments are booleans
  • throw a type error otherwise?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants