Merge pull request #17855 from bradcray/simplify-common-casts
Add explicit string casts for common/easy cases
[reviewed by @ronawho]
When we do a cast-to-string (say, in an error message) and the type
doesn't support such a cast, Chapel calls into the general-purpose
stringify() routine which is very cool in that it converts any type to
a string, but is very expensive in that it does it by virtue of
writing the value to string memory using some pretty nontrivial I/O code.
This PR takes a few common types that are compact and easy to write to
strings (ranges, rectangular domains, byteIndices, codepointIndices)
and injects string casts for them to avoid these code paths. For domains
specifically, this adds a
.doiToString() routine to the optional interface.
The net effect of these changes reverses the increase in generated code
that stemmed from #17628 and then some, resulting in a ~4000 line savings
in generated code for the stream benchmark with checks on.
While adding tests for these string casts, I found and fixed a few errors
in converting ranges to strings:
- for single-element enum ranges, we weren't generating the same
pattern that we do for I/O
- similarly, for
..hiranges, we were tacking on an
align 0even though
we don't normally print alignment for non-strided ranges
These oversights suggest that it'd be nice to better unify default I/O and
cast-to-string code to avoid repeated code and cases where their behavior
diverges like this.
I believe this will resolve https://github.com/Cray/chapel-private/issues/2074
but am not marking it as such here until we verify in nightly testing.
Modified Files: A test/domains/bradc/stringCast.chpl