chapel
chapel copied to clipboard
[Feature Request]: return `myArray.domain` by `const ref` ?
Summary of Feature
Description
Allow a function to return the domain of an array - declared outside the function - by const ref
For the longest time I thought that an array held its domain, so it is only natural for an accessor-like function to return that domain by const ref
.
This is not a blocking issue, as of this writing.
Code Samples
One use case is switching localSubdomain
to returning its result by const ref
to avoid creating a new domain - which is an expensive operation - each time it is invoked.
proc _array.localSubdomain() const ref
where this._value.isDefaultRectangular()
{ return this.domain; }
Another case is a class or record that initially stored a domain in one field and an array over that domain in another field. As the application evolves, the domain field is removed. We want to replace this field with an accessor-like method to avoid updating the uses of this field. Again, we do not want for this accessor to create a new domain.
// initially:
class SymEntry {
type etype;
param dimensions: int;
var d: domain(dimensions);
var a: [d] etype;
}
// later
class SymEntry {
var a;
proc etype type { return a.eltType; }
proc dimensions param { return a.domain.rank; }
proc d const ref { return a.domain; } // <----- want to do this
}
Related
This feature is similar to returning array slices by ref, #12178. In both cases the returned value is, implementation-wise, a record created locally within the function.