Open DanilaFe opened 6 days ago
Here are my thoughts on this topic.
recordContainingCopyMutatesField
should return a boolean indicating whether the record copy mutates a field. Instead of querying to hasFlag(FLAG_COPY_MUTATES), we should invoke recordContainingCopyMutatesField()
. This is analogous to propagateNotPOD().
We have FLAG_TYPE_INIT_EQUAL_FROM_REF
and FLAG_TYPE_INIT_EQUAL_FROM_CONST
, which get calculated and set upon calling setRecordCopyableFlags()
. Consider merging the former flag with FLAG_COPY_MUTATES.
I don't have a reproducer yet but I have been running into an issue that might be related with a record containing a type t; var field: t
instantiated with nothing
/none
.
If I remember right, @dlongnecke-cray did some work to make sure collection types supported containing classes correctly and might have some insights into why things are the way they are, if you haven't checked with him already
Instantiating with none
may cause problems regardless of this issue. I used to have a reproducer, not finding it right now.
The
copy mutates
pragma, which indicates that a type is changed when it's copied (e.g., copying a nilableowned
resets the copied-from variable tonil
). This pragma is propagated to records that containowned
fields, etc. This propagation continues even if normally-defined type (e.g.,set
in the standard library) defines a non-mutating copy constructor viainit=
. As a result, types likeset
are consideredcopy mutates
and copying them requires a mutable variable.Thus, whereas the following program works:
The following program does not:
Printing the following error:
Note that this is specifically caused by the fact that copying into the tuple would mutate the value (as far as the compiler believes), but this is not possible.
https://github.com/chapel-lang/chapel/blob/e1b1d03f487521432676709a755e3949f46717fd/compiler/resolution/lateConstCheck.cpp#L715-L721
The issue is that
recordContainingCopyMutatesField
incorrectly appliesCOPY_MUTATES
even if a non-mutatinginit=
is defined for the type.https://github.com/chapel-lang/chapel/blob/e1b1d03f487521432676709a755e3949f46717fd/compiler/resolution/resolveFunction.cpp#L392