[Chapel Merge] Enable support for sync of records

Branch: refs/heads/main
Revision: f569622
Author: mppf
Link: Enable support for sync of records by mppf · Pull Request #18379 · chapel-lang/chapel · GitHub
Log Message:

Merge pull request #18379 from mppf/sync-use-in

Enable support for sync of records

This PR adds support for user-defined records contained within
sync/single as well as owned/shared classes.

Resolves #18458

Issue #18477 discusses some design questions about what readXX should do.
This PR implements (3b): "readFE() always moves the value out and
readXX on an empty sync variable always returns a default-initialized
value for non-POD types and whatever bits were last left in it for POD
types".

In common use, sync and single variables store a value when they are full
and have no meaningful value when they are empty. However, it is possible
to read from an empty sync/single variable with readXX. The documentation
indicates that empty sync/single variables contain a default-initialized
value.

It is desireable to be able to support common sync/single operations with
records that cannot be default initialized (and similarly, for
non-nilable owned C or shared C). In order to do so, this PR adjusts
the sync/single implementation to store uninitialized memory for the
empty state. For POD value types, this uninitialized memory is simply the
last value stored. Then, readXX is adjusted to:

  • for POD types, return the last stored value
  • for non-POD types:
    • fail to compile if the value type does not support default
      initialization, copying from const, and assigning from const
    • if the sync variable is empty, return a new default-initialized
      value of type valType
    • if the sync variable is full, return a copy of the existing value.

In a similar way, this PR makes types that cannot be const-copy
initialized produce a compilation error for certain sync/single
operations. As a specific example, readFF requires copy initialization
but it would be surprising if it modified the value stored in the sync
variable. So, for types like owned that modify the RHS when
copy-initializing, this operation results in a compilation error.

To make these patterns easier to implement, this PR adds init versions
for sync and single records and supporting classes that take in the
type valType and in value: valType.

Reviewed by @lydia-duncan - thanks!

  • [x] full local futures testing

    Modified Files:
    A test/deprecated/sync-casting.chpl
    A test/deprecated/sync-casting.good
    A test/deprecated/sync-casting.noexec
    A test/parallel/sync/bradc/testSyncSingleTypes-arr.good
    A test/parallel/sync/bradc/testSyncSingleTypes-arr2.good
    A test/parallel/sync/bradc/testSyncSingleTypes-ok.good
    A test/parallel/sync/bradc/testSyncSingleTypes-sync.good
    A test/parallel/sync/bradc/testSyncSingleTypes.chpl
    A test/parallel/sync/bradc/testSyncSingleTypes.compopts
    A test/parallel/sync/bradc/testSyncSingleTypes.predif
    A test/types/sync/ferguson/non-nilable-single.chpl
    A test/types/sync/ferguson/non-nilable-single.good
    A test/types/sync/ferguson/readxx-empty.chpl
    A test/types/sync/ferguson/readxx-empty.good
    A test/types/sync/ferguson/sync-owned-nilable-readFF.chpl
    A test/types/sync/ferguson/sync-owned-nilable-readFF.good
    A test/types/sync/ferguson/sync-owned-nilable-writeFF.chpl
    A test/types/sync/ferguson/sync-owned-nilable-writeFF.good
    A test/types/sync/ferguson/sync-record-default-init.chpl
    A test/types/sync/ferguson/sync-record-default-init.good
    A test/types/sync/ferguson/sync-record-no-default-init.chpl
    A test/types/sync/ferguson/sync-record-no-default-init.good
    R test/parallel/sync/bradc/testBadSyncSingle-R.good
    R test/parallel/sync/bradc/testBadSyncSingle-arr.good
    R test/parallel/sync/bradc/testBadSyncSingle-arr2.good
    R test/parallel/sync/bradc/testBadSyncSingle-complex128.good
    R test/parallel/sync/bradc/testBadSyncSingle-complex64.good
    R test/parallel/sync/bradc/testBadSyncSingle-range.good
    R test/parallel/sync/bradc/testBadSyncSingle-sync.good
    R test/parallel/sync/bradc/testBadSyncSingle.chpl
    R test/parallel/sync/bradc/testBadSyncSingle.compopts
    R test/parallel/sync/bradc/testBadSyncSingle.prediff
    R test/parallel/sync/waynew/record3.prediff
    R test/types/sync/ferguson/non-nilable-single-error.chpl
    R test/types/sync/ferguson/non-nilable-single-error.good
    R test/types/sync/ferguson/non-nilable-sync-error.chpl
    R test/types/sync/ferguson/non-nilable-sync-error.good
    R test/types/sync/ferguson/sync-borrowed-nonnil.prediff
    R test/types/sync/ferguson/sync-unmanaged-nonnil.prediff
    M doc/rst/language/spec/task-parallelism-and-synchronization.rst
    M modules/internal/ChapelSyncvar.chpl
    M test/parallel/sync/waynew/record3.good
    M test/types/single/sungeun/single-copy-init.good
    M test/types/sync/ferguson/sync-borrowed-nonnil.good
    M test/types/sync/ferguson/sync-bytes.good
    M test/types/sync/ferguson/sync-complex.chpl
    M test/types/sync/ferguson/sync-complex.good
    M test/types/sync/ferguson/sync-copy-init-cannot-coerce2.good
    M test/types/sync/ferguson/sync-copy-init-other-sync.good
    M test/types/sync/ferguson/sync-owned-nilable.good
    M test/types/sync/ferguson/sync-owned-nonnil.good
    M test/types/sync/ferguson/sync-shared-nonnil.good
    M test/types/sync/ferguson/sync-unmanaged-nonnil.good

    Compare: Comparing 538076d276f0...f569622d1d98 · chapel-lang/chapel · GitHub