chapel icon indicating copy to clipboard operation
chapel copied to clipboard

comparisons between uint and 0 aren't folded by the compiler

Open bradcray opened this issue 8 years ago • 6 comments

Feature request

Summary of Problem

Given a comparison between a uint and 0 that is known to always be true by definition such as 'a > 0' or 'a >= 0', I believe the compiler should param fold this conditional as it does with other obvious facts. It doesn't currently at present because the overload that handles this case returns 'true' along one branch (when the other arg is a param 0) and calls the execution time comparison in the other branch; so the routine can't be a param routine and can't be folded.

A potential fix is to break the routine into two using a where clause to disambiguate and making the obvious case a param function and the other case not. But this runs into bugs in our handling of where clauses which is another issue (#5236).

Steps to Reproduce

Source Code:

config var x: uint;

if (x < 0) then
  compilerError("This should never happen");

Compile command: chpl foo.chpl

Execution command: ./a.out

Configuration Information

  • Output of chpl --version: 1.14.0.a771ec7
  • Output of $CHPL_HOME/util/printchplenv --anonymize: N/A
  • Back-end compiler and version, e.g. gcc --version or clang --version: N/A
  • (For Cray systems only) Output of module list: N/A

bradcray avatar Jan 25 '17 17:01 bradcray

PR #5277 makes an attempt to fix this issue using the new where clause fixes introduced in PR #5275 but is currently failing with three tests.

bradcray avatar Jan 30 '17 19:01 bradcray

PR #11570 has some related changes. See https://github.com/chapel-lang/chapel/pull/11570#discussion_r230961816

mppf avatar Nov 07 '18 18:11 mppf

Here is a link to the test we'd like to get to pass for this issue to close: https://github.com/chapel-lang/chapel/pull/5277/files#diff-c60cb09d88210e77db2f5c34662d065d

mppf avatar Nov 07 '18 18:11 mppf

#25529 implements this specifically for <.

I am leaving this issue open as a request for similar changes to other operators: <= >= > == !=.

vasslitvinov avatar Jul 12 '24 17:07 vasslitvinov

I hate to look a gift horse in the mouth (particularly one that I requested), but I wonder whether it's worse to support thse foldings only for < without adding the symmetric support to >, <, >=, and >=... (just from a non-orthogonality perspective)

bradcray avatar Jul 25 '24 00:07 bradcray

@bradcray I do not have an answer to the "is it worse" question. My thinking is (a) if we like what I did in #25529 then we can do the same for the other operators, and (b) feel free to back out #25529 pending (a), if desired.

vasslitvinov avatar Jul 25 '24 00:07 vasslitvinov