[Chapel Merge] Fix param-folding bug and clarify param-folding in the spec

Branch: refs/heads/main
Revision: d034044e12b0409eea3f180a75fd32296c0f9c74
Author: jabraham17
Link: Fix param-folding bug and clarify param-folding in the spec by jabraham17 · Pull Request #28881 · chapel-lang/chapel · GitHub
Log Message:
Fix param-folding bug and clarify param-folding in the spec (#28881)

This PR does two distinct yet related topics, fixes a bug in some
comparison operators and clarifies the way Chapel does param folding
(resolving numerous old issues)

In #5235 it was suggested we should param fold comparisons like 0 > myUintVar, since we know the result of the comparison at compile time
(a 0 will never be greater than any uint value). This was partially
implemented in #25529. There was concern that the optimization was only
partially implemented. However, a user recently found an issue with that
PR, caused by incorrect logic. This resulted in branches being param
folded when they should never be param folded.

Based on further discussion on this issue when I went to fix this bug,
we came to consensus in
How much should Chapel param fold · Issue #28834 · chapel-lang/chapel · GitHub that Chapel should
not do any param folding of non-param values, except for the
short-circuiting operators.

This PR reverts the partial paran fold optimization described above and
cleans up many operator calls as a result.

To prevent future concerns and confusion, I have also added
clarification to the spec about when and where Chapel will param-fold.

Resolves How much should Chapel param fold · Issue #28834 · chapel-lang/chapel · GitHub
Resolves comparisons between uint and 0 aren't folded by the compiler · Issue #5235 · chapel-lang/chapel · GitHub
Resolves Document rationale for why short-circuiting operators don't fold RHS param values · Issue #20873 · chapel-lang/chapel · GitHub
Resolves optimization opportunity: fold `(non-param) && false` · Issue #20496 · chapel-lang/chapel · GitHub
Resolves conditional with && is not param-folded away · Issue #25531 · chapel-lang/chapel · GitHub

  • paratest

[Reviewed by @DanilaFe offline]

Compare: Comparing 45e984765d7d0c92e7661fbd4649de31ef5b9dde...d36fe419c472d33068a1a26be6968700b05b41d4 · chapel-lang/chapel · GitHub

Diff:
M doc/rst/language/spec/expressions.rst
M doc/rst/language/spec/variables.rst
M modules/internal/ChapelBase.chpl
A test/expressions/comparisons/compareUintMax.chpl
A test/expressions/comparisons/compareUintMax.execopts
A test/expressions/comparisons/compareUintMax.good
A test/expressions/comparisons/noParamFold.chpl
A test/expressions/comparisons/noParamFold.good
D test/expressions/comparisons/paramUintCompares.chpl
D test/expressions/comparisons/paramUintCompares.good
A test/expressions/paramFold/foldAND.chpl
A test/expressions/paramFold/foldAND.good
A test/expressions/paramFold/foldOR.chpl
A test/expressions/paramFold/foldOR.good
A test/parallel/forall/reduce-intents/ri-bool-baseline-bug.future
M test/visibility/except/operatorsExceptions/exceptLessThan.good
https://github.com/chapel-lang/chapel/pull/28881.diff