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

Deprecate ref-maybe-const for array formal arguments #22958

Merged

Conversation

jabraham17
Copy link
Member

@jabraham17 jabraham17 commented Aug 14, 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 Narrow lvalue checking special case from arrays to array views #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

@jabraham17 jabraham17 force-pushed the deprecate-ref-maybe-const-arguments branch from 31d94ec to 83303c6 Compare August 17, 2023 01:06
@jabraham17 jabraham17 marked this pull request as ready for review August 17, 2023 17:57
Copy link
Member

@vasslitvinov vasslitvinov left a comment

Choose a reason for hiding this comment

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

For the OP / PR message:

  • array argument formals --> array formal arguments [my preference]

  • a ref-maybe-const formal is marked as ref:
    "is marked as" --> "is inferred to be" ?

  • Please explain your addition of dsiBulkAddNoPreserveInds().
    It would also be good to add a comment in the code explaining what it does.

For the cases where you switched the default intent to const, ex. in ChapelArray.chpl or in tests like test/types/tuple/ferguson/tuple-array-concrete.chpl, I am curious why not ref and/or why an explicit intent was needed. I suspect the compiler wants to infer it as ref? why?

In test/types/tuple/ferguson/tuple-array.chpl and siblings, how well do you think your changes there preserve the intent of those tests?

@vasslitvinov
Copy link
Member

All of the "just trailing spaces" changes are auto-fixes by my editor. I think it lightens up my PR diff, but increases the quality of some of our old code prior to the pre-merge spaces check

The space check does not apply to tests. Also, to me trailing space has no impact on the quality of code.

Excessive trailing space changes affect the PR review experience, however, and are best done in a separate PR.

@jabraham17
Copy link
Member Author

For the cases where you switched the default intent to const, ex. in ChapelArray.chpl or in tests like test/types/tuple/ferguson/tuple-array-concrete.chpl, I am curious why not ref and/or why an explicit intent was needed. I suspect the compiler wants to infer it as ref? why?

In test/types/tuple/ferguson/tuple-array.chpl and siblings, how well do you think your changes there preserve the intent of those tests?

These were both changes I made with @mppf, where the rationale was we are ok forcing users to explicitly mark varargs as const. In ChapelArray, it was added to additional places other than just varargs so the intents of overloaded functions matched

@jabraham17 jabraham17 changed the title Deprecate ref-maybe-const for array argument formals Deprecate ref-maybe-const for array formal arguments Aug 22, 2023
@jabraham17
Copy link
Member Author

@vasslitvinov I think I have implemented all of your feedback except the spaces. I will look at separating those out after I resolve the merge conflicts, but I think for this PR it may be more trouble than it is worth at this point

@jabraham17 jabraham17 force-pushed the deprecate-ref-maybe-const-arguments branch from b19bf79 to d5e260a Compare August 22, 2023 22:13
some are marked notest, they will not be implemented yet

Signed-off-by: Jade Abraham <[email protected]>
currently argThis and taskIntent are disabled, forall intent is not implemented

Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
@jabraham17 jabraham17 force-pushed the deprecate-ref-maybe-const-arguments branch from d5e260a to dd93f04 Compare August 22, 2023 23:02
@jabraham17 jabraham17 merged commit ca412d6 into chapel-lang:main Aug 22, 2023
7 checks passed
@jabraham17 jabraham17 deleted the deprecate-ref-maybe-const-arguments branch August 22, 2023 23:30
@bradcray
Copy link
Member

Woohoo!

@jabraham17 jabraham17 restored the deprecate-ref-maybe-const-arguments branch August 23, 2023 16:05
jabraham17 added a commit that referenced this pull request Aug 23, 2023
fixes failing tests by adding `ref` where needed in gpu tests.

ref-maybe-const was deprecated in #22958. Array formals can no longer be
modified with the default intent, an explicit `ref` must now be
supplied. This cascades to other functions that may require a `ref` like
`c_ptrTo`.

Tested with `CHPL_GPU=cpu`

Note that `test/gpu/native/studies/sort/radixSortGpu` will not be fully
fixed due to prior issue.

[Reviewed by @DanilaFe]
jabraham17 added a commit that referenced this pull request Aug 23, 2023
Fix issues missed with ref-maybe-const deprecation
(#22958). We now require `ref`
to be used when modifying an array

Added `ref` where needed in python interop tests

[Not reviewed - trivial test change]
jabraham17 added a commit that referenced this pull request Aug 24, 2023
Deprecates ref-maybe-const for task intents. The compiler will warn when
a ref-maybe-const task intent is inferred to be `ref` in
`cullOverReferences`.

Implements part of the decisions for
#21398 (comment)

Followup to #22958

## Summary of changes
- enable warning for task intents
- add extra logic to handle task variables for record method receivers
and nested functions.
- add explicit task variables where needed in modules and tests on
`coforall` and `[co]begin`

## New tests
- add `test/deprecated/ref-maybe-const-task-intents.chpl`

## Testing
- paratest with futures
- paratest with gasnet

[Reviewed by @vasslitvinov]

closes Cray/chapel-private#5253
jabraham17 added a commit that referenced this pull request Aug 29, 2023
Deprecates ref-maybe-const for this intents. The compiler will warn when
a method receiver is modified without explicitly marking the method as
`ref`.

Implements part of the decisions for
#21398 (comment)

This PR also exposes a bug with records
```chapel
record R1 {
  var x: int;
  proc /*ref*/ foo() do x = 17;
}
record R2 {
  var x: R1;
  proc bar() do return x;
}
var r = new R2();
r.bar().foo();
writeln(r);
```
With `ref-maybe-const`, this code compiled when it should have failed to
compile. Using an explicit `ref` intent causes user code that previously
worked (incorrectly) to break.

The deprecation warning ignores methods which use `pragma "reference to
const when const this"`.

Followup to #22958 and #23049

## Summary of changes
- enable warning for this intents
- add an explicit `ref` where needed in modules and tests on methods

## New tests
- enable `test/deprecated/ref-maybe-const-this-intents.chpl`

## Testing
- paratest with futures
- paratest with gasnet

[Reviewed by @vasslitvinov]
@jabraham17 jabraham17 deleted the deprecate-ref-maybe-const-arguments branch August 31, 2023 17:53
jabraham17 added a commit that referenced this pull request Sep 5, 2023
Deprecates ref-maybe-const for `forall` intents. The compiler will warn
when an array is used in a modifiable context inside of a forall loop.
For example passing the array to a function which takes a `ref` argument
or assigning the array to a `ref` var.

Implements the rest of the decisions for
#21398 (comment)

Followup to #22958, #23049, and #23060

## Summary of changes
- enable warning for forall intents
- add an explicit `ref` where needed in modules and tests on foralls
- for tests in `test/optimizations/autoLocalAccess` and
`test/optimizations/autoAggregation`, added a PREDIFF pending a fix for
the optimizations tested here
- using an explicit `ref` shadow variable for these causes the
optimization to fail, this is a temporary solution until the
optimization is fixed.
- enable `test/deprecated/ref-maybe-const-forall-intents.chpl`
- futurize `test/gpu/native/distArray/blockInsideOn.chpl`
- using a forall with a shadow var for a distributed array inside of an
`on gpu` block makes the loop gpu ineligible

## Testing
- [x] paratest with futures
- [x] paratest with gasnet
- [x] gpu testing
  - [x] nvidia with UM
  - [x] amd with AOD
- [x] paratest with c backend on nightly test machine

[Reviewed by @vasslitvinov]

closes #21398
closes Cray/chapel-private#5093
jabraham17 added a commit that referenced this pull request Sep 6, 2023
…23228)

Adds explicit ref forall intents where needed due to the ref-maybe-const
forall intent deprecation (#23175).

While there, also reverted accidental changes made to submitted tests
due to ref-maybe-const array formals in (#22958).

Some submitted performance tests use verify the results using a line
number, those were updated as well.

While there, added a `use Math` for some tests still using `exp` from
`AutoMath`.

Tested files locally where applicable. Also tested submitted tests with
`--performance`

[Reviewed by @e-kayrakli]
jabraham17 added a commit that referenced this pull request Sep 19, 2023
Updates documentation for `bulkAdd` and `bulkAddNoPreserveInds`, which
where modified in #22958.

[Reviewed by @dlongnecke-cray]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants