google / xls

XLS: Accelerated HW Synthesis

Home Page:http://google.github.io/xls/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Logical operators applied to non-bool/u1 : maybe generate warning?

hzeller opened this issue · comments

Consider the following:

fn foo(x: u32, y: u32) -> u32 {
 x && y
}

This code is accepted and the expression is treated as (x & y).
However, it is a bit weird that a typically boolean operator can be used on non-booleans without triggering a warning. Maybe the user meant to do something else ?

Unlike other languages, && and || don't do any shortcut evaluation in DSLX so these boolean vs bitwise ops are equivalent (and I suspect they are lowered to just bitwise_and and bitwise_or in the IR anyway). But if we provide this operator, implying 'booleanness', maybe it is still worthwhile emitting a warning when these are applied to anything not boolean just to keep the user on their toes keeping code readable.

Possibly low-hanging fruit (except then fixing possibly broken existing code), but also entirely non-critical.

Ah yeah, good find, Rust also flags an error for this -- I think it's just a bug, will squash.