[Chapel Merge] Add support for slicing of associative arrays by a

Branch: refs/heads/master
Revision: 0b20baa
Author: bradcray
Log Message:

Merge pull request #17610 from bradcray/slice-assoc

Add support for slicing of associative arrays by associative domains

[reviewed by @mppf]

This adds support for slicing an associative array using an associative domain. It was just about as easy as I had hoped it would be given the design of the array slicing framework. In fact, the only thing that really prevented the example in #6004 from working was bounds-checking (though to support other operations, a few more missing pieces needed to be added). Most of this PR's effort related to improving the HashedDist domain map to be suitable for slicing within our tests rather than anything related to array slices themselves.

The work here to get the basics working was:

In modules/internal/ChapelArray.chpl:

  • updated the checkSlice() bounds checking code for slices in modules/internal/ChapelArray.chpl to handle associative cases (previously, rectangular cases had been assumed)
  • refactored the helpers used by isAssociativeDom() to determine whether a class is associative so that they can be used in other places where only the class is available.

In modules/internal/ArrayViewSlice.chpl:

  • updated the read/write routines on array slice views to stop assuming they are a rectangular domain/array
    • in support of this, added a new I/O routine (at the bottom of modules/internal/DefaultAssociative.chpl) for printing an associative array restricted to the indices within a given domain, similar to what we do for rectangular slices. Unlike the rectangular case, I didn't try to unify this with the default associative domain/array I/O code because it uses a zippered iteration which I expect will be far more efficient. This code clone is admittedly somewhat regrettable (I also put a halt() in for a reading case that I was too lazy to implement).
  • added the dsiLocalSubdomains() routine to slices, which hadn't been used by previous slice forms

In modules/internal/DefaultAssociative.chpl and modules/dists/HashedDist.chpl:

  • added dsiAccess() overloads that take 1*idxType arguments, detuple them, and pass them on to the standard routines for convenience because the slicing code always passes tuples on to the underlying array. The alternative seemed to be to specialize the dsiAccess() routines in ArrayViewSlice.chpl to distinguish between associative and non-associative cases, but that seemed much more negatively impactful on the code.

In modules/dists/HashedDist.chpl:

  • added missing *localSubdomain* routines to UserMapAssocDom, and then simplified the UserMapAssocArr's version of dsiLocalSubdomains() to call the domain's version
  • fixed the UserMapAssocArr.dsiSerialWrite() routine so that we'd get a global view of the distributed array rather than per-locale arrays (e.g., where we used to print ["one"->1, "two"->2] ["three"->3] ["four"->4] we now print ["one"->1, "two"->2, "three"->3, "four"->4])
    • This also required changes to the default I/O routines in modules/internal/DefaultAssociative.chpl to support the ability to squash the square brackets and carry a first value between calls.

In modules/internal/ChapelDistribution.chpl:

  • added proc rank routines to the abstract associative domain and array classes because the slicing machinery relies on querying the ranks of these classes, and it was easier to add them here than to each subclass

In terms of testing:

  • test/users/ferguson/assoc-slice.future: retired this future, which now works
  • test/arrays/slices/sliceAssoc.chpl: A slightly expanded version of the test in #6004.
  • test/arrays/slices/sliceAssocOOB.chpl, test/arrays/slices/sliceAssocOOB2.chpl: tests of the bounds checking code
  • test/arrays/userAPI/assocArray.chpl, test/arrays/userAPI/assocDistributedHashed.chpl: expanded these existing tests to ensure that all of the existing associative array operation tests apply to slices of associative arrays as well.
    • test/arrays/userAPI/assocDistributedHashed.good: updated the multilocale output to reflect the new global view of the array output
  • test/distributions/ferguson/dist-assoc-bulkadd.bad: Updated this output to reflect that a missing rank routine is no longer what's preventing bulkAdd from working (but rather, the lack of a bulkadd routine is)
  • util/test/sort-words-within-literals: updated this script to use the .tmp filename passed in rather than guessing what it is (which doesn't work once compopts/execopts are added)

Resolves #6004.

Modified Files:
A test/arrays/slices/sliceAssoc.chpl

A test/arrays/slices/sliceAssoc.good
A test/arrays/slices/sliceAssocOOB.chpl
A test/arrays/slices/sliceAssocOOB.good
A test/arrays/slices/sliceAssocOOB2.chpl
A test/arrays/slices/sliceAssocOOB2.good
A test/arrays/userAPI/assocArray.execopts
A test/arrays/userAPI/assocDistributedHashed.execopts
R test/users/ferguson/assoc-slice.future
M modules/dists/HashedDist.chpl
M modules/internal/ArrayViewSlice.chpl
M modules/internal/ChapelArray.chpl
M modules/internal/ChapelDistribution.chpl
M modules/internal/DefaultAssociative.chpl
M test/arrays/userAPI/assocArray.chpl
M test/arrays/userAPI/assocDistributedHashed.chpl
M test/arrays/userAPI/assocDistributedHashed.good
M test/distributions/ferguson/dist-assoc-bulkadd.bad
M util/test/sort-words-within-literals

Compare: https://github.com/chapel-lang/chapel/compare/da4ad6838ca6...0b20baa34b8f