New Issue: Rethink "write to array element" interface?

17999, "bradcray", "Rethink "write to array element" interface?", "2021-06-28T19:53:58Z"

In two separate contexts that I've been working with recently, I've been facing challenges with how we implement writes to array elements, for cases like this: A[i] = j;

Specifically, the current interface for writing to an array essentially accesses into the array and returns a reference to the array element that should be written. This works fine for traditional/simple arrays, but for some more complicated approaches that we might like to express, it raises challenges:

  • in one, the array is composed of two distinct memories: a "main" memory that represents the array elements but that cannot be directly indexed/accessed; and a "local" memory that serves as a cache for the array memory and can be written/indexed, but then has to be copied back to the main copy to be considered complete. With our current interface, there's no hook for causing that "write back" to occur.
  • in the second, we store an array element on multiple locales and would like to update all (or at least, multiple) copies of the array element on a write. As one example, when writing to a local fluff value of a Stencil distribution, we may want to update both the fluff value and the original value. As a second example, if we had some sort of replicated-for-resilience array type, we might want to update all of the array replicands on a write.

I'm looking for inspiration as to how we might be able to adjust our array machinery to support these cases, ideally without too much fuss for the array developer.