[Chapel Merge] Extend the count (`#`) operator on ranges to accep

Branch: refs/heads/main
Revision: 2863bb9
Author: bradcray
Link: Extend the count (`#`) operator on ranges to accept any integral value by bradcray · Pull Request #20098 · chapel-lang/chapel · GitHub
Log Message:

Merge pull request #20098 from bradcray/count-any-integral

Extend the count (#) operator on ranges to accept any integral value

Modified Files:
A test/domains/operators/countTypeMismatch.chpl

A test/domains/operators/countTypeMismatch.good
A test/types/range/count/countIntegralTypes.chpl
A test/types/range/count/countIntegralTypes.good
A test/types/range/hilde/countType1.chpl
A test/types/range/hilde/countType1.good
A test/types/range/hilde/countType2.chpl
A test/types/range/hilde/countType2.good
R test/types/range/hilde/countError.future
R test/types/range/hilde/countTypeError1.chpl
R test/types/range/hilde/countTypeError1.compopts
R test/types/range/hilde/countTypeError1.good
R test/types/range/hilde/countTypeError1.prediff
R test/types/range/hilde/countTypeError2.chpl
R test/types/range/hilde/countTypeError2.compopts
R test/types/range/hilde/countTypeError2.good
R test/types/range/hilde/countTypeError2.prediff
M modules/internal/ChapelRange.chpl
M test/types/range/hilde/countError.good

Compare: https://github.com/chapel-lang/chapel/compare/6bffb2c25252...2863bb90460b

Oops, my finger slipped and I double-clicked the merge accidentally
earlier than I'd intended. The following message should've gone into the
merge message.


[reviewed by @lydia-duncan]

Prior to this PR, for a range of idxType int(8) (say), the count
operator (#) only accepted integer values of type int(8) or
uint(8). This PR extends count on ranges to accept any integral
value so long as the value of the integer doesn't surpass the range's
size, essentially changing this check from "This value's static type
can store a too-large value, so let's not support it" into "There's no
reason to believe that this integer is particularly large or small based
on its type, so let's not make assumptions about it." This is
useful when working with small-int ranges and applying an int(64)
count, which is not uncommon since that's the default int type.

While here, I did some minor refactoring to the bounds checking code
of the # operator on ranges to make the logic slightly clearer.
No changes were required to domains and arrays because their
count operator is implemented in terms of the range type's, so they
inherit the behavior for free.

This changed a few tests from "tests of errors" into working tests,
resolved a future, and required one other test update. I also added a
new test of mixing integer types when applying # to domains and
arrays, as they didn't seem to have existing tests.

Resolves #20085.

1 Like