chapel
chapel copied to clipboard
conditional with && is not param-folded away
Summary of Problem
Description:
I wrote some code with a pattern like if i==0 && someType != nothing { something() } expecting that the compiler will not try to compile something() when someType == nothing. However that doesn't work unless I write it as if someType != nothing && i==0 { something() }.
I'm not sure if this is a bug or not. I understand that if we have a() && false that we have to evaluate a() for side effects. But I would think the compiler can avoid compiling the body of a conditional such as if a() && false { compilerError("bad"); }.
Is this issue currently blocking your progress? No, there is an easy workaround
Steps to Reproduce
Source Code:
proc foo(type t) {
var sum:t = 0;
for i in 1..10 {
if i == 1 && t != nothing {
sum += i:t;
}
}
}
foo(int(8)); // OK
foo(nothing); // fails to compile despite t != nothing above
Note that it does compile as I would expect if we write i t != nothing && i == 1 in the above.
Associated Future Test(s): TODO
This is related to the discussion in https://github.com/chapel-lang/chapel/issues/20873. Reading this issue, I was convinced by the argument that we could transform the code into just the evaluation of the LHS expression, and it looks like that's where I stood most recently at the end of the comment stream on #20873 as well.
Just stumbled across this, which also may be related: https://github.com/chapel-lang/chapel/issues/20496