Skip to content

Commit 1dd8dca

Browse files
authored
Change the ref-maybe-const deprecation on foralls into an unstable warning (#23526)
Changes the warning for an implicit ref intent on arrays in foralls into an unstable warning, which is off by default. After offline discussion, concerns raised in #23488 and #23229, and concerns raised by Arkouda developers, we decided to soften our stance on this change for the release. ## Summary of changes - add check for unstable flag in `compiler/resolution/lowerIterators.cpp` where the warning is thrown - updated warning message to indicate the feature is unstable - changed the wording in the language evolution document to reflect these changes - moved `test/unstable/ref-maybe-const-forall-intent.chpl` to the `unstable` tests folder - updated submitted perf tests .good files and perfkeys accordingly - test/studies/shootout/submitted/binarytrees3.chpl - test/studies/shootout/submitted/knucleotide3.chpl - test/studies/shootout/submitted/knucleotide4.chpl - test/studies/shootout/submitted/revcomp3.chpl - test/studies/shootout/submitted/revcomp5.chpl - test/studies/shootout/submitted/revcomp8.chpl - test/studies/shootout/submitted/spectralnorm.chpl - test/studies/shootout/submitted/spectralnorm2.chpl - test/studies/shootout/submitted/mandelbrot.chpl - test/studies/shootout/submitted/mandelbrot3.chpl ## Testing - paratest with futures - paratest with no futures + gasnet - local testing of all modified tests - local testing with `-performance` of all modified perf tests [Reviewed by @mppf]
2 parents 9378c40 + 50dbfb4 commit 1dd8dca

22 files changed

+37
-59
lines changed

compiler/resolution/lowerIterators.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3083,9 +3083,10 @@ void maybeIssueRefMaybeConstWarning(ForallStmt* fs, Symbol* sym, std::vector<Cal
30833083
for (auto ce: allCalls) {
30843084
// if a call sets the symbol, warn
30853085
if (callSetsSymbol(sym, ce)) {
3086+
// checking for --warn-unstable done in checkForallRefMaybeConst
30863087
USR_WARN(fs,
3087-
"inferring a default intent to be 'ref' is deprecated - "
3088-
"please add an explicit 'ref' forall intent for '%s'",
3088+
"inferring a 'ref' intent on an array in a forall is unstable"
3089+
" - in the future this may require an explicit 'ref' forall intent for '%s'",
30893090
sym->name);
30903091
break;
30913092
}
@@ -3094,6 +3095,9 @@ void maybeIssueRefMaybeConstWarning(ForallStmt* fs, Symbol* sym, std::vector<Cal
30943095

30953096

30963097
static void checkForallRefMaybeConst(ForallStmt* fs, std::set<Symbol*> syms) {
3098+
// bail out here if we shouldn't be warning for this forall
3099+
if (!shouldWarnUnstableFor(fs)) return;
3100+
30973101
// collect all SymExpr used in the iterand of the forall so we dont warn for them
30983102
std::vector<SymExpr*> allIterandSymExprs;
30993103
for_alist(expr, fs->iteratedExpressions()) {

doc/rst/language/evolution.rst

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,20 @@ The default intent for arrays and records
6060
*****************************************
6161

6262
In version 1.32, arrays and records now always have a default intent of
63-
``const``. This means that if arrays and records are modified inside of a loop
64-
body, a function, or a task body they must use a ``ref`` intent. This also
65-
means that record methods which modify their implicit ``this`` argument must
66-
also use a ``ref`` intent. Previously, the compiler would treat these types as
67-
either ``const ref`` intent or ``ref`` intent, depending on if they were
68-
modified. This change was motivated by improving the consistency across types
69-
and making potential problems more apparent.
70-
71-
Consider the following code segment, which contains a ``forall`` statement
63+
``const``. This means that if arrays and records are modified inside of a
64+
function, a ``coforall``, a ``begin``, or ``cobegin``, they must use a ``ref``
65+
intent. This also means that record methods which modify their implicit
66+
``this`` argument must also use a ``ref`` intent. Previously, the compiler would treat
67+
these types as either ``const ref`` intent or ``ref`` intent, depending on if
68+
they were modified. This change was motivated by improving the consistency
69+
across types and making potential problems more apparent.
70+
71+
Since there is a lot of user code relying on modifying an outer array, the
72+
corresponding change for ``forall`` is still under discussion. As a result, it
73+
will not warn by default, but modifying an outer array from a ``forall`` might
74+
not be allowed in the future in some or all cases.
75+
76+
Consider the following code segment, which contains a ``coforall`` statement
7277
which modifies local variables. Prior to version 1.32, this code compiled and
7378
worked without warning.
7479

@@ -78,7 +83,7 @@ worked without warning.
7883
const myDomain = {1..10};
7984
var myArray: [myDomain] int;
8085
81-
forall i in 2..9 with (ref myInt) {
86+
coforall i in 2..9 with (ref myInt) {
8287
myInt += i;
8388
myArray[i] = myArray[i-1] + 1;
8489
}
@@ -99,7 +104,7 @@ which can be a source of subtle bugs. In 1.32, the loop is written as:
99104
const myDomain = {1..10};
100105
var myArray: [myDomain] int;
101106
102-
forall i in 2..9 with (ref myInt, ref myArray) {
107+
coforall i in 2..9 with (ref myInt, ref myArray) {
103108
myInt += i;
104109
myArray[i] = myArray[i-1] + 1;
105110
}

test/deprecated/ref-maybe-const-forall-intent.good

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/studies/shootout/submitted/binarytrees3.good

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
binarytrees3.chpl:13: In function 'main':
2-
binarytrees3.chpl:38: warning: inferring a default intent to be 'ref' is deprecated - please add an explicit 'ref' forall intent for 'stats'
31
stretch tree of depth 11 check: 4095
42
1024 trees of depth 4 check: 31744
53
256 trees of depth 6 check: 32512
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
real
2-
verify:3: stretch tree of depth \d+\t check: 8388607
2+
verify:1: stretch tree of depth \d+\t check: 8388607
33
verify: long lived tree of depth \d+\t check: 4194303

test/studies/shootout/submitted/knucleotide3.good

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ knucleotide3.chpl:76: In function 'calculate':
4242
knucleotide3.chpl:88: warning: 'map.items' is deprecated. Consider 'map.keys' to iterate over keys or 'map.values' to iterate over values.
4343
knucleotide3.chpl:69: called as calculate(data: [domain(1,int(64),one)] uint(8), param nclSize = 18) from function 'writeCount'
4444
knucleotide3.chpl:49: called as writeCount(data: [domain(1,int(64),one)] uint(8), param str = "GGTATTTTAATTTATAGT") from function 'main'
45-
knucleotide3.chpl:100: warning: inferring a default intent to be 'ref' is deprecated - please add an explicit 'ref' forall intent for 'toNum'
4645
A 30.279
4746
T 30.113
4847
G 19.835
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
real
2-
verify:66:GG 3.902
3-
verify:72:893 GGTATTTTAATTTATAGT
2+
verify:65:GG 3.902
3+
verify:71:893 GGTATTTTAATTTATAGT

test/studies/shootout/submitted/knucleotide4.good

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ knucleotide4.chpl:75: In function 'calculate':
4848
knucleotide4.chpl:87: warning: 'map.items' is deprecated. Consider 'map.keys' to iterate over keys or 'map.values' to iterate over values.
4949
knucleotide4.chpl:68: called as calculate(data: [domain(1,int(64),one)] uint(8), param nclSize = 18) from function 'writeCount'
5050
knucleotide4.chpl:48: called as writeCount(data: [domain(1,int(64),one)] uint(8), param str = "GGTATTTTAATTTATAGT") from function 'main'
51-
knucleotide4.chpl:99: warning: inferring a default intent to be 'ref' is deprecated - please add an explicit 'ref' forall intent for 'toNum'
5251
A 30.279
5352
T 30.113
5453
G 19.835
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
real
2-
verify:72:GG 3.902
3-
verify:78:893 GGTATTTTAATTTATAGT
2+
verify:71:GG 3.902
3+
verify:77:893 GGTATTTTAATTTATAGT
-139 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)