18876, "bradcray", "Should (some) parallel-safe collection types use 'ref' task intents by default?", "2021-12-16T00:43:31Z"
Currently, all traditional, user-level records use const ref
as their default task intent, to prevent inadvertent parallel modifications that may not be safe. Since our collections like list
, set
, map
are implemented using records, they get this default intent by default. Similarly associative domains (though not exactly a typical user record) are passed by const ref
by default, like other domains, even though they are parallel-safe by default.
While working on advent of code programs this week, something that tripped me up a few times was that I would create a parallel-safe collection, and then get errors when trying to access it within a forall loop. For example:
var l: list(int, parSafe=true);
forall i in 1..n do
l.append(i); // error, as 'l' is a const ref shadow variable
var s: domain(int); // parSafe by default
forall i in 1..n do
s.add(i); // error, as 's' is a const ref shadow variable
It seems as though it would be more productive to have non-parallel-safe collections use 'const' default intents like this, while having parallel-safe ones use 'ref' by default. However, I'm not confident there aren't other cases in which 'ref' by default might cause issues.
This question seems like it intersects a bit with whether parallel-safe vs. non- collections are unified into a single type (as they currently are) or are accessed via different type names in that some mechanisms that we might use to specify a default task intent for a record may be difficult to control via a param
field on the type itself.