New Issue: avoid copying arrays with compatible domains

23550, "vasslitvinov", "avoid copying arrays with compatible domains", "2023-09-29T03:54:57Z"

When the field or variable is declared as an array over a domain like {1..n} and initialized from another array declared separately over the domain {1..n} or from a loop expression, we want such initialization to transfer ownership reliably. In other words, we want to make sure that unnecessary copying does not occur.

Currently we have an optimization that does that when the lhs and rhs are declared over the same domain. We want to handle the case {1..n} as well. From the implementation perspective the check could be "are the index sets identical and both the lhs and rhs domains are immutable?" And/or it could be a swap-like operation that swaps the data storage of the two arrays, however not their domain pointers.

record R { var f: [1..n] real; }
var r = new R( for i in 1..n do f(i) ); // no copying is needed

// or:
var sourceArray: [1..n] real = ....;
var r = new R(sourceArray); // ideally, no copying if 'sourceArray' is unused after this

// or:
var sourceArray: [1..n] real = ....;
var anotherArray: [1..n] real = sourceArray; // ideally, no copying if 'sourceArray' is unused after this

Motivation: fft data structures discussed in Allocating a nested array of arrays