[Chapel Merge] Fix cross-locale access to TaskErrors

Branch: refs/heads/main
Revision: 39a9f6f5083091ac14576bf1872159e587a09579
Author: vasslitvinov
Link: Fix cross-locale access to TaskErrors by vasslitvinov · Pull Request #23992 · chapel-lang/chapel · GitHub
Log Message:
Fix cross-locale access to TaskErrors (#23992)

Resolves #23905

The key fix is in TaskErrors.init(ref group:chpl_TaskErrors)
to handle the case where the incoming TaskErrors stored in asTaskErr
is on a different locale than where the initializer is running.
Before this PR, the c_ptr stored in asTaskErr.errorsArray
was dereferenced directly in TaskErrors.these() iterator.
This resulted in invalid memory accesses because this c_ptr
was allocated on asTaskErr's locale, not on the current locale.
Now such dereferences are wrapped into on asTaskErr.

While there:

  • Add assertions into TaskErrors.these() and TaskErrors.first()
    that they are executed on the receiver's locale, to ensure that
    the dereferences of the c-pointer this.errorsArray are valid.

  • Simplify the code, for example use the if const construct
    to avoid the postfix ! operators.

Looking at how this TaskErrors initializer has to hassle with
the c_ptr, I suggest to switch TaskErrors from the c_ptr
to a singly-linked list. The initializer will simply take over
the singly-linked list of Errors that it receives in the group formal.

If one of the errors on the list is a TaskErrors, then its collected errors
will take place of it in the linked list. The only downside of this
is that it complicates the implementation of the iterator
TaskErrors.these() ref. This led me to the proposal in
Errors Module: the `TaskErrors` class · Issue #21068 · chapel-lang/chapel · GitHub.

r: @benharsh

Compare: Comparing 1a7cc90e8542bab2665ac70e3fdfdf257a40bca6...cfebf149d2ff2a4cdc4a065fff899b49e34e13d9 · chapel-lang/chapel · GitHub

Diff:
M modules/standard/Errors.chpl
A test/errhandling/errorMessages/taskerrors-remote-1.chpl
A test/errhandling/errorMessages/taskerrors-remote-1.good
A test/errhandling/errorMessages/taskerrors-remote-1.numlocales
A test/errhandling/errorMessages/taskerrors-remote-1.skipif
A test/errhandling/errorMessages/taskerrors-remote-2.chpl
A test/errhandling/errorMessages/taskerrors-remote-2.good
A test/errhandling/errorMessages/taskerrors-remote-2.numlocales
A test/errhandling/errorMessages/taskerrors-remote-2.skipif
A test/errhandling/misc/issue-23905.chpl
A test/errhandling/misc/issue-23905.comm-none.good
A test/errhandling/misc/issue-23905.execopts
A test/errhandling/misc/issue-23905.good
A test/errhandling/misc/issue-23905.numlocales
https://github.com/chapel-lang/chapel/pull/23992.diff