Branch: refs/heads/master
Revision: e8be46a
Author: bradcray
Log Message:
Merge pull request #16776 from bradcray/enable-bool-tuple-indexing
Enable bool tuple indexing
[reviewed by @e-kayrakli]
It’s recently been pointed out that while Chapel supports indexing arrays by booleans (where the interpretation is to coerce to an integer and grab element 0 or 1), tuples traditionally have not. I believe that this is a simple oversight rather than an intentional design choice, and this PR adds the ability to index tuples by boolean expressions. A pair of tests demonstrate indexing tuples and arrays by booleans (both param and non-param values).
This feature is particularly useful now that we use 0-based indexing for tuples (and for arrays with inferred indexing), supporting the ability to write ("this", "that")(myBooleanExpr) to choose between “this” and “that”. Note that unlike conditional expressions (if myBooleanExpr then "that" else "this"), the tuple/array forms evaluate both conditions rather than just the one corresponding to the bool. This means that if you’re selecting between side effecting functions (foo(), bar())(myBooleanExpr), both functions will be called when using boolean indexing.
Modified Files:
A test/arrays/indexing/boolIndexing-true.good
A test/arrays/indexing/boolIndexing.chpl
A test/arrays/indexing/boolIndexing.execopts
A test/arrays/indexing/boolIndexing.good
A test/types/tuple/indexing/boolIndex-hetTuple.good
A test/types/tuple/indexing/boolIndex-true.good
A test/types/tuple/indexing/boolIndex.chpl
A test/types/tuple/indexing/boolIndex.compopts
A test/types/tuple/indexing/boolIndex.execopts
A test/types/tuple/indexing/boolIndex.good
M compiler/AST/expr.cpp
M compiler/include/expr.h
M compiler/resolution/preFold.cpp
M modules/internal/ChapelTuple.chpl
Compare: https://github.com/chapel-lang/chapel/compare/2955609d60f8...e8be46af2442