Skip to content

Conversation

@bradcray
Copy link
Member

@bradcray bradcray commented Jan 5, 2026

This PR rewrites list.toArray() to avoid the use of an on-clause, and therefore the delayed initialization of the temporary array being returned, in order to resolve #28201 and #28202. It also adds a test based on the code in #28201, though extends it to do cross-locale calls to ensure that everything works in single- and multi-locale settings (across comm=none vs. !=none testing configurations).

As noted in #28201 (comment), this rewrite could have an adverse impact on performance if the list is on a distinct locale from the task calling .toArray(), but I think this is the right change all the same since (a) correctness and generality are more important than performance and (b) the case where the list and calling task are on distinct locales seems unlikely to be a frequent occurrence in practice. Moreover, for the case where the two are co-located, this should accelerate things by avoiding the creation/copy of a second array (though perhaps we would have successfully stolen it anyway?).

Ultimately, if/when we care about optimizing performance, we should probably use bulk copies from the list's sub-arrays to the result array anyway, which would be faster for both the co-located and distributed cases.

That original fix was then propagated to the other standard collection types (sets, maps, heaps) and tests were added for them as well. The one case that's not as strong as the others is the map version, which results in undefined behavior when run on multiple locales due to #28266

Resolves #28201
Resolves #28202

@bradcray bradcray marked this pull request as ready for review January 6, 2026 01:43
@bradcray
Copy link
Member Author

bradcray commented Jan 6, 2026

@jabraham17 : Would you be up for giving this a review?

Copy link
Member

@jabraham17 jabraham17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good!

…ap use

While testing my new test, I found that it was getting weird behavior when
running on multiple locales, due to having the map live on one locale and
the task running the iterator on another.  I'm not sure what's causing this,
so added a future capturing the behavior and avoided the remote iteration
in my new test for now.

---
Signed-off-by: Brad Chamberlain <[email protected]>
---
Signed-off-by: Brad Chamberlain <[email protected]>
@bradcray bradcray changed the title Fix list.toArray() for lists of records of non-default initializable types Fix toArray() for standard collections of non-default initializable records (lists, sets, maps) Jan 7, 2026
@bradcray bradcray changed the title Fix toArray() for standard collections of non-default initializable records (lists, sets, maps) Fix toArray() for standard collections of non-default initializable records (lists, sets, …) Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Potential race in list.toArray [Bug]: list.toArray only works on default initializable types

2 participants