Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Narrow lvalue checking special case from arrays to array views #22816

Merged
merged 6 commits into from
Jul 31, 2023

Conversation

mppf
Copy link
Member

@mppf mppf commented Jul 26, 2023

Resolves #22330
Resolves #20166

This PR implements Option 2 from #22330 by changing an exception in isLegalLvalueActualArg for arrays into an exception for array views (including slices). That makes arrays more consistent with other types while allowing code assigning to a slice, e.g., A[2..n-1] = 1.0, to continue to work. The rationale for having an exception for array views is 1) they are a pretty special type already and 2) they arguably behave more as a reference than a value (and in the future, might be considered a special kind of reference).

For example, here is a program that previously compiled, but after this PR fails to compile with an lvalue error:

proc processArr(ref X) { }
proc createArr() {
  return [1,2];
}

processArr(createArr()); // error: non-lvalue actual is passed to 'ref' formal 'X' of processArr()

To address this error, a user will need to add a new variable:

var A = createArr();
processArr(A); // OK!

To do so, this PR updates isLegalLvalueActualArg as described above and also updates the code propagating flags to promotion wrapper functions to consider FLAG_REF_TO_CONST_WHEN_CONST_THIS, to address an issue that was revealed in testing. While there, this PR moves the code propagating FLAG_OPERATOR, from initPromotionWrapper to buildEmptyWrapper (where the other flags are handled).

Reviewed by @lydia-duncan - thanks!

  • full comm=none testing

@mppf mppf changed the title Restrict lvalue checking from arrays to array slices Narrow lvalue checking special case from arrays to array slices Jul 26, 2023
mppf added 5 commits July 26, 2023 16:14
To avoid compilation error in

  runtime/configMatters/comm/unordered/unorderedCopyStress

---
Signed-off-by: Michael Ferguson <[email protected]>
---
Signed-off-by: Michael Ferguson <[email protected]>
To avoid the lvalue error but still have the tests check
the if-expr array memory management.

---
Signed-off-by: Michael Ferguson <[email protected]>
@mppf mppf marked this pull request as ready for review July 27, 2023 21:06
Copy link
Member

@lydia-duncan lydia-duncan left a comment

Choose a reason for hiding this comment

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

Minor update request to the PR message but otherwise this is great, thanks!

compiler/resolution/wrappers.cpp Show resolved Hide resolved
@mppf mppf changed the title Narrow lvalue checking special case from arrays to array slices Narrow lvalue checking special case from arrays to array views Jul 27, 2023
@mppf mppf merged commit 93d48cd into chapel-lang:main Jul 31, 2023
7 checks passed
@mppf mppf deleted the returned-array-rvalue branch July 31, 2023 13:58
mppf added a commit that referenced this pull request Aug 1, 2023
Adjusts a test to adapt to the new error from PR #22816.

Test change only - not reviewed.
jabraham17 added a commit that referenced this pull request Aug 22, 2023
Deprecates ref-maybe-const for array formal arguments. Compiler will
warn when a ref-maybe-const formal is inferred to be `ref` in
`cullOverReferences`. This will not warn for compiler generated
functions or outer variables (when outlining nested functions). It is
written in a way that exceptions can be removed to implement other
ref-maybe-const deprecations.

Implements part of the decisions for
#21398 (comment)

## Summary of changes
- add explicit intents (either `ref` or `const`) where needed in modules
and tests
- some functions, the body was modified to remove the need for an
explicit intent (eg `ref a = ...` to `const ref a = ...`)
- tweaks `compiler/passes/expandExternArrayCalls.cpp` to interpret
intents and use `c_ptrConst`.
- added temporaries for lvalue errors due to #22816 
- tweaks `compiler/passes/normalize.cpp` to fix lvalue error with
`convertToExternalArray`.
- rewrite `bulkAdd` for sparse domains to prefer codepaths that do not
require `sort`
- calling sort along any codepath requires the `inds` to be marked as
`ref`
- instead of taking a `preserveInds` boolean argument, now there is a
separate `bulkAddNoPreserveInds`
- change uses of `c_ptrTo` to `c_ptrToConst` where applicable

## New tests
- add `test/deprecated/ref-maybe-const.chpl`
- also added deprecation tests for this intents, task intents, and
forall intents, these are marked notest for now
- futurize `test/functions/ferguson/ref-pair/ifexpr/ifexpr2-1.chpl`
- add `test/users/ibertolacc/void_extern_proc_array_ref.chpl`

## Testing
- paratest (llvm) with futures
- paratest (llvm) with gasnet
- paratest (c)
- paratest with --verify

[Reviewed by @vasslitvinov]

closes Cray/chapel-private#5218
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants