Fix a bug in returning reshape() expressions #27403
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
One of the follow-ups I had lined up for the new aliasing reshape() capability was to determine why one of the four cases in returnReshape.chpl wasn't working even though the others were. Specifically, this call:
was getting a lifetime checking error about returning a scoped variable, when other similar calls like:
were not.
Digging into this a bit more, I'm still not entirely certain why the two cases were resulting in different behavior, though I did find that the foo() routine should have been getting a similar error, in that capturing its result into a variable and modifying it:
was resulting in a modification to 'A' as well, even though returning an array and storing it in a variable should result in a deep copy.
Once I realized this, it didn't take long to determine that this is another place in the compiler where the current logic determines the existence of an array view by virtue of the expression's type. Updating it to also look for the new
FLAG_IS_ARRAY_VIEW
flag fixed the aliasing issue while also resolving the original error about returning a scoped variable.To lock this fix in, I updated the test to make it check that none of the modifications to the returned arrays resulted in a modification to the original.
While here, I also looked for other calls to
isAliasingArrayType()
that didn't have a similar check for the new flag and added the check, hoping to head off additional bugs down the road.