[Chapel Merge] Add explicit string casts for common/easy cases

Branch: refs/heads/master
Revision: ab3e65d
Author: bradcray
Log Message:

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 lo..<lo
    pattern that we do for I/O
  • similarly, for ..hi ranges, we were tacking on an align 0 even 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

A test/domains/bradc/stringCast.good
M doc/rst/technotes/dsi.rst
M modules/dists/BlockDist.chpl
M modules/dists/CyclicDist.chpl
M modules/dists/ReplicatedDist.chpl
M modules/internal/ChapelArray.chpl
M modules/internal/ChapelRange.chpl
M modules/internal/DefaultRectangular.chpl
M modules/internal/String.chpl
M test/domains/userAPI/domainAPItest.chpl
M test/domains/userAPI/test2Ddomain.good
M test/domains/userAPI/testEnumDomain.good
M test/library/packages/UnitTest/AssertEqual/AssertEqualTest.good
M test/types/range/userAPI/byteRangeTest.good
M test/types/range/userAPI/codepointRangeTest.good
M test/types/range/userAPI/rangeAPItest.chpl
M test/types/range/userAPI/simpleRangeTest.good
M test/types/range/userAPI/singleEnumAPITest.good

Compare: https://github.com/chapel-lang/chapel/compare/2cc1170f3f97...ab3e65d74428