pharo-project / pharo-vm

This is the VM used by Pharo
http://pharo.org
Other
113 stars 69 forks source link

(&) bitAnd vs integerAnd #663

Open PalumboN opened 1 year ago

PalumboN commented 1 year ago

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, https://github.com/Alamvic/druid/commit/de7af6f9e0b8ef33b788caefe70c5530019e915d#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 commented 1 year ago

Related are: https://github.com/pharo-project/pharo-vm/pull/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 commented 1 year ago

So what we do?

guillep commented 1 year ago

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