Hi Chapel Developers —
In recent discussions, we've been considering changing .size
queries to return int
by convention. Today, ranges, domains, and arrays return an integer that's related to their idxType
, which can be problematic and sometimes a bit confusing. If you'd like to comment on this topic or show your support for it, please do so on the following issue, which contains the rationale and additional details:
opened 11:36PM - 05 May 21 UTC
area: Language
area: Libraries / Modules
type: Design
This issue proposes that `.size` queries on various types and collections should… return an `int` value by default, on the argument that:
* `int` is the default integer value in Chapel (e.g., `42` is inferred to be of type `int`)
* while `uint` is arguably a more logical type (since sizes can't typically be 0)...
* ...`uint`s are more awkward to work with in Chapel due to the previous rule and the errors that `int` op `uint` cases generate
* ...it's rare in practice that one creates something of size larger than `2**63`
* ...using `int` has the slight benefit that one could utilize negative numbers as sentinel values
Furthermore, for those types and collections that may potentially have sizes larger than 2**63, this issue proposes that we:
* have bounds checks (which can be turned off) to avoid accidentally returning negative numbers in such cases
* support a `.sizeAs(type t: integral)` query so that one can query the size as a `uint`
We may optionally want to also support `.sizeAs(type t: integral)` queries for other types where users may want to get the result as a smaller integer size (and get the similar bounds-checking benefits.
The main case that this change affects is the family of ranges, domains, and arrays, each of which has typically returned an integer whose width and sign correspond to their `idxType`. (e.g., `range(int(8))` returns an `int(8)` for its `.size` query)
Making this change should help resolve some existing issues such as:
* https://github.com/chapel-lang/chapel/issues/7530
* https://github.com/chapel-lang/chapel/issues/17264
Thanks,
-Brad