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

Binary bitwise operators ^, &, | should be invalid on Bools. #8596

Open
mcourteaux opened this issue Mar 17, 2025 · 2 comments · May be fixed by #8597
Open

Binary bitwise operators ^, &, | should be invalid on Bools. #8596

mcourteaux opened this issue Mar 17, 2025 · 2 comments · May be fixed by #8597
Assignees
Labels
dev_meeting Topic to be discussed at the next dev meeting enhancement New user-visible features or improvements to existing features. python Issues related to Halide/Python interop

Comments

@mcourteaux
Copy link
Contributor

Instead, !=, &&, and || should be used.
I tried adding user_asserts for type.bits() > 1, however that breaks the Python bindings as they rely on & and | instead of and and or (as it seems you cannot overload and and or in Python).

I ran into this issue because I had used a ^ on a bool arguments (uint1) which caused the WebGPU backend to complain that ^ is only valid on int datatypes, which is correct. This made me realize I should have used !=. So, trying to prevent bugs like this in the future, I added asserts (like mentioned before) in IROperator.cpp on all those bitwise operators to make sure you're not using them on booleans. However, that breaks the Python bindings as described.

@mcourteaux mcourteaux added enhancement New user-visible features or improvements to existing features. python Issues related to Halide/Python interop labels Mar 17, 2025
@mcourteaux
Copy link
Contributor Author

I'm thinking simply redirecting them to the correct operators if they are evaluated on bool Exprs is the easiest thing to do that's also backwards compatible.

@mcourteaux
Copy link
Contributor Author

I'll PR this.

@mcourteaux mcourteaux self-assigned this Mar 17, 2025
@abadams abadams added the dev_meeting Topic to be discussed at the next dev meeting label Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev_meeting Topic to be discussed at the next dev meeting enhancement New user-visible features or improvements to existing features. python Issues related to Halide/Python interop
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants