diff --git a/compiler/resolution/cullOverReferences.cpp b/compiler/resolution/cullOverReferences.cpp index 4697fed0791b..b7e20ed84442 100644 --- a/compiler/resolution/cullOverReferences.cpp +++ b/compiler/resolution/cullOverReferences.cpp @@ -483,11 +483,14 @@ static void maybeIssueRefMaybeConstWarning(ArgSymbol* arg) { bool useFunctionForWarning = (isTaskIntent | isArgThis) && arg->getFunction(); Symbol* warnSym = useFunctionForWarning ? (Symbol*)arg->getFunction() : (Symbol*)arg; - USR_WARN(warnSym, - "inferring a default intent to be 'ref' is deprecated " - "- please %s '%s'", - intentName, - argName); + USR_FATAL_CONT(warnSym, + "%s is const by default, but code attempted to modify it.", + argName); + USR_PRINT("If you intended to modify %s, %s '%s'.", + argName, + intentName, + argName); + USR_STOP(); } } diff --git a/test/arrays/errors/error-const-use-as-ref-1.chpl b/test/arrays/errors/error-const-use-as-ref-1.chpl new file mode 100644 index 000000000000..a50e919e4c43 --- /dev/null +++ b/test/arrays/errors/error-const-use-as-ref-1.chpl @@ -0,0 +1,13 @@ +// without ref gets infered to be const ref +proc bar(A) { // should fail without ref + A = 1; +} + +proc main() { + var A: [1..10] int; + A = 1..10; + writeln("A, ", A); + + bar(A); + writeln("A, ", A); +} diff --git a/test/arrays/errors/error-const-use-as-ref-1.good b/test/arrays/errors/error-const-use-as-ref-1.good new file mode 100644 index 000000000000..bb2fbfa65114 --- /dev/null +++ b/test/arrays/errors/error-const-use-as-ref-1.good @@ -0,0 +1,2 @@ +error-const-use-as-ref-1.chpl:2: error: A is const by default, but code attempted to modify it. +note: If you intended to modify A, use an explicit 'ref' intent for the argument 'A'. diff --git a/test/arrays/errors/error-const-use-as-ref-2.chpl b/test/arrays/errors/error-const-use-as-ref-2.chpl new file mode 100644 index 000000000000..c49bd1ffb611 --- /dev/null +++ b/test/arrays/errors/error-const-use-as-ref-2.chpl @@ -0,0 +1,13 @@ +// without ref on the var args +proc foobar(args...) { + args[0] = 2; +} + +proc main() { + var A: [1..10] int; + A = 1..10; + writeln("A, ", A); + + foobar(A); + writeln("A, ", A); +} diff --git a/test/arrays/errors/error-const-use-as-ref-2.good b/test/arrays/errors/error-const-use-as-ref-2.good new file mode 100644 index 000000000000..aac2584c0ca1 --- /dev/null +++ b/test/arrays/errors/error-const-use-as-ref-2.good @@ -0,0 +1,2 @@ +error-const-use-as-ref-2.chpl:2: error: args is const by default, but code attempted to modify it. +note: If you intended to modify args, use an explicit 'ref' intent for the argument 'args'. diff --git a/test/deprecated/ref-maybe-const-this-intent.good b/test/deprecated/ref-maybe-const-this-intent.good deleted file mode 100644 index b68134ce320b..000000000000 --- a/test/deprecated/ref-maybe-const-this-intent.good +++ /dev/null @@ -1,5 +0,0 @@ -ref-maybe-const-this-intent.chpl:28: warning: inferring a default intent to be 'ref' is deprecated - please add an explicit 'ref' task intent for 'this' -ref-maybe-const-this-intent.chpl:19: warning: inferring a default intent to be 'ref' is deprecated - please add an explicit 'ref' task intent for 'this' -ref-maybe-const-this-intent.chpl:4: warning: inferring a default intent to be 'ref' is deprecated - please use an explicit 'ref' this-intent for the method 'foo' -(10, 12) -(x = 2) diff --git a/test/deprecated/ref-maybe-const-this-intent.numlocales b/test/deprecated/ref-maybe-const-this-intent.numlocales deleted file mode 100644 index d00491fd7e5b..000000000000 --- a/test/deprecated/ref-maybe-const-this-intent.numlocales +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/test/deprecated/ref-maybe-const.chpl b/test/deprecated/ref-maybe-const.chpl deleted file mode 100644 index 0780a0260865..000000000000 --- a/test/deprecated/ref-maybe-const.chpl +++ /dev/null @@ -1,29 +0,0 @@ -// infered to be const ref -proc foo(A) { - return A; -} - -// without ref gets infered to be const ref -proc bar(A) { // should fail without ref - A = 1; -} - -// without ref on the var args -proc foobar(args...) { - args[0] = 2; -} - -proc main() { - var A: [1..10] int; - A = 1..10; - writeln("A, ", A); - - var B = foo(A); - writeln("B, ", B); - - bar(A); - writeln("A, ", A); - - foobar(A); - writeln("A, ", A); -} diff --git a/test/deprecated/ref-maybe-const.good b/test/deprecated/ref-maybe-const.good deleted file mode 100644 index dcd2c0b49985..000000000000 --- a/test/deprecated/ref-maybe-const.good +++ /dev/null @@ -1,6 +0,0 @@ -ref-maybe-const.chpl:7: warning: inferring a default intent to be 'ref' is deprecated - please use an explicit 'ref' intent for the argument 'A' -ref-maybe-const.chpl:12: warning: inferring a default intent to be 'ref' is deprecated - please use an explicit 'ref' intent for the argument 'args' -A, 1 2 3 4 5 6 7 8 9 10 -B, 1 2 3 4 5 6 7 8 9 10 -A, 1 1 1 1 1 1 1 1 1 1 -A, 2 2 2 2 2 2 2 2 2 2 diff --git a/test/llvm/parallel_loop_access/different_numbers.chpl b/test/llvm/parallel_loop_access/different_numbers.chpl index 719d02de20f5..da38fa7d55c1 100644 --- a/test/llvm/parallel_loop_access/different_numbers.chpl +++ b/test/llvm/parallel_loop_access/different_numbers.chpl @@ -8,7 +8,7 @@ proc start_loop3() { return 5; } proc end_loop3() { return 6; } //Check whether we generate different metadata number for loops -proc loop (A, B, n) { +proc loop (ref A, B, n) { //CHECK-LABEL: void @loop foreach i in 1..n { //CHECK-LABEL: start_loop1 diff --git a/test/llvm/parallel_loop_access/generation_inside_loop.chpl b/test/llvm/parallel_loop_access/generation_inside_loop.chpl index 3cde1e1018e6..8d50a89cbb8b 100644 --- a/test/llvm/parallel_loop_access/generation_inside_loop.chpl +++ b/test/llvm/parallel_loop_access/generation_inside_loop.chpl @@ -11,7 +11,7 @@ proc end_block() { return 5; } // - basic block at start of loop // - basic block at the end of the loop -proc loop (A, B, n) { +proc loop (ref A, B, n) { //CHECK-LABEL: void @loop foreach i in 1..n { // CHECK-LABEL: start_block diff --git a/test/llvm/parallel_loop_access/no_parallel_loop_accesses.chpl b/test/llvm/parallel_loop_access/no_parallel_loop_accesses.chpl index 28f2164a89ba..6e0231dc9a21 100644 --- a/test/llvm/parallel_loop_access/no_parallel_loop_accesses.chpl +++ b/test/llvm/parallel_loop_access/no_parallel_loop_accesses.chpl @@ -12,7 +12,7 @@ proc keep(ref arg) { return 1; } proc mark() { return 2; } // CHECK: void @loop1 -proc loop1(A, B) { +proc loop1(ref A, B) { // Check that we don't generate llvm.access.group metadata in // non-order-independent loops for i in 0..n { diff --git a/test/llvm/parallel_loop_access/parallel_loop_accesses1.chpl b/test/llvm/parallel_loop_access/parallel_loop_accesses1.chpl index 3cac0e3b9849..07cfaf41db66 100644 --- a/test/llvm/parallel_loop_access/parallel_loop_accesses1.chpl +++ b/test/llvm/parallel_loop_access/parallel_loop_accesses1.chpl @@ -2,7 +2,7 @@ config const n = 11; // check for correct access.group and llvm.loop.parallel_accesses hinting // CHECK: void @loop1 -proc loop1 (A, B) { +proc loop1 (ref A, B) { foreach i in 0..n { // CHECK: load i32, // CHECK-SAME: !llvm.access.group ![[GROUP:[0-9]+]] diff --git a/test/llvm/parallel_loop_access/parallel_loop_accesses2.chpl b/test/llvm/parallel_loop_access/parallel_loop_accesses2.chpl index cb3fd190b132..2214afca86f1 100644 --- a/test/llvm/parallel_loop_access/parallel_loop_accesses2.chpl +++ b/test/llvm/parallel_loop_access/parallel_loop_accesses2.chpl @@ -2,7 +2,7 @@ config const n = 11; // check for correct access.group and llvm.loop.parallel_accesses hinting // CHECK: void @nestedLoops -proc nestedLoops (A, B) { +proc nestedLoops (ref A, B) { for i in 0..n { foreach j in 0..n { for k in 0..n { diff --git a/test/llvm/parallel_loop_access/simple_forall.chpl b/test/llvm/parallel_loop_access/simple_forall.chpl index 6ff579ecf2a8..5fa01c0e10be 100644 --- a/test/llvm/parallel_loop_access/simple_forall.chpl +++ b/test/llvm/parallel_loop_access/simple_forall.chpl @@ -5,7 +5,7 @@ proc main() { writeln(A[1], " ", A[n]); } -proc loop(A) { +proc loop(ref A) { forall i in 1..n { A[i] = 17.5 * i; } diff --git a/test/llvm/parallel_loop_access/simple_loop.chpl b/test/llvm/parallel_loop_access/simple_loop.chpl index f627d02cf0c3..830a3c46b9b4 100644 --- a/test/llvm/parallel_loop_access/simple_loop.chpl +++ b/test/llvm/parallel_loop_access/simple_loop.chpl @@ -1,5 +1,5 @@ //Check whether we add parallel_loop_access metadata for loops at all -proc loop (A, B, n) { +proc loop (ref A, B, n) { foreach i in 1..n { // CHECK: !llvm.access.group ![[GROUP1:[0-9]+]] A[i] = 3*B[i]; diff --git a/test/llvm/parallel_loop_access/zippered_forall.chpl b/test/llvm/parallel_loop_access/zippered_forall.chpl index d0669b72ee49..286819722be0 100644 --- a/test/llvm/parallel_loop_access/zippered_forall.chpl +++ b/test/llvm/parallel_loop_access/zippered_forall.chpl @@ -5,7 +5,7 @@ proc main() { writeln(A[1], " ", A[n]); } -proc loop(A) { +proc loop(ref A) { forall (i,j) in zip(1..n, 2..) { A[i] = 17.5 * j; } diff --git a/test/llvm/vectorization/complicated_loop.chpl b/test/llvm/vectorization/complicated_loop.chpl index d407a72a9939..a0d7406b8e53 100644 --- a/test/llvm/vectorization/complicated_loop.chpl +++ b/test/llvm/vectorization/complicated_loop.chpl @@ -1,5 +1,5 @@ //This test checks whether vectorization occurs for more complicated loops -proc loop (A, B, C) { +proc loop (ref A, ref B, C) { // CHECK: <4 x i32> foreach j in 0..511 { var i = j : int(32); diff --git a/test/llvm/vectorization/double_loop.chpl b/test/llvm/vectorization/double_loop.chpl index bc1901553fe2..ad97be83ac21 100644 --- a/test/llvm/vectorization/double_loop.chpl +++ b/test/llvm/vectorization/double_loop.chpl @@ -1,5 +1,5 @@ //Check whether vectorization occurs for nested loops -proc loop (A, B) { +proc loop (ref A, B) { foreach i in 0..511 { foreach j in 0..511 { // CHECK: <4 x i32> diff --git a/test/llvm/vectorization/forall_loop.chpl b/test/llvm/vectorization/forall_loop.chpl index 75e741ab4792..8be58060cf74 100644 --- a/test/llvm/vectorization/forall_loop.chpl +++ b/test/llvm/vectorization/forall_loop.chpl @@ -1,5 +1,5 @@ //Check whether vectorization occurs for forall loop -proc loop (A, B) { +proc loop (ref A, B) { forall i in 0..511 { A[i] = B[i]*3; } diff --git a/test/llvm/vectorization/nested_loop.chpl b/test/llvm/vectorization/nested_loop.chpl index 6b1fa56bcf9c..4e523fae6a73 100644 --- a/test/llvm/vectorization/nested_loop.chpl +++ b/test/llvm/vectorization/nested_loop.chpl @@ -1,5 +1,5 @@ -proc loop (A, B, C, D, E, F, n) { +proc loop (ref A, B, ref C, D, ref E, F, n) { foreach i in 1..n { A[i] = 3*B[i]; foreach j in 1..n { diff --git a/test/llvm/vectorization/simple_loop.chpl b/test/llvm/vectorization/simple_loop.chpl index 6c09a3e29e2d..63248e174deb 100644 --- a/test/llvm/vectorization/simple_loop.chpl +++ b/test/llvm/vectorization/simple_loop.chpl @@ -1,7 +1,7 @@ //Check whether vectorization occurs at all //This loop is trivial case for loop vectorizer and if //vectorization shouldn't happen it definitely won't happen in this case -proc loop (A, B, n) { +proc loop (ref A, B, n) { foreach i in 0..n { // CHECK: <4 x i32> A[i] = 3*B[i]; diff --git a/test/llvm/vectorization/zipped_loop.chpl b/test/llvm/vectorization/zipped_loop.chpl index 8747c3f22884..1efb78510523 100644 --- a/test/llvm/vectorization/zipped_loop.chpl +++ b/test/llvm/vectorization/zipped_loop.chpl @@ -1,5 +1,5 @@ //Check if zipped 'foreach' loop is vectorizable -proc loop (A, B) { +proc loop (ref A, B) { foreach (i,j) in zip(0..511, 0..511) { // CHECK: <4 x i32> A[i,j] = B[i,j]*3; diff --git a/test/studies/isx/isx-no-return.chpl b/test/studies/isx/isx-no-return.chpl index 32ce9842004d..8b1d5b8af65a 100644 --- a/test/studies/isx/isx-no-return.chpl +++ b/test/studies/isx/isx-no-return.chpl @@ -246,7 +246,7 @@ proc bucketSort(bucketID, trial: int, time = false, verify = false) { } -proc bucketizeLocalKeys(myBucketedKeys, bucketID, myKeys, sendOffsets) { +proc bucketizeLocalKeys(ref myBucketedKeys, bucketID, myKeys, sendOffsets) { var bucketOffsets: [LocBucketSpace] atomic int; bucketOffsets.write(sendOffsets); @@ -262,7 +262,7 @@ proc bucketizeLocalKeys(myBucketedKeys, bucketID, myKeys, sendOffsets) { } -proc countLocalBucketSizes(bucketSizes, myKeys) { +proc countLocalBucketSizes(ref bucketSizes, myKeys) { forall key in myKeys { const bucketIndex = key / bucketWidth; bucketSizes[bucketIndex].add(1); @@ -287,7 +287,7 @@ proc exchangeKeys(bucketID, sendOffsets, bucketSizes, myBucketedKeys) { } -proc countLocalKeys(myLocalKeyCounts, bucketID, myBucketSize, myMinKeyVal) { +proc countLocalKeys(ref myLocalKeyCounts, bucketID, myBucketSize, myMinKeyVal) { ref myBucket = allBucketKeys[bucketID]; forall i in 0..#myBucketSize do myLocalKeyCounts[myBucket[i]].add(1); @@ -330,7 +330,7 @@ proc verifyResults(bucketID, myBucketSize, myLocalKeyCounts) { } -proc makeInput(myKeys, bucketID) { +proc makeInput(ref myKeys, bucketID) { use Random; use Random.PCGRandomLib; diff --git a/test/types/records/intents/error-const-use-as-ref-1.chpl b/test/types/records/intents/error-const-use-as-ref-1.chpl new file mode 100644 index 000000000000..45a41986b8f6 --- /dev/null +++ b/test/types/records/intents/error-const-use-as-ref-1.chpl @@ -0,0 +1,13 @@ +record R { + var x: int = 11; + var y: int = 12; + proc foo() { + x = 10; + } + proc bar() { // should not warn + writeln((x,y)); + } +} +var r = new R(); +r.foo(); +r.bar(); diff --git a/test/types/records/intents/error-const-use-as-ref-1.good b/test/types/records/intents/error-const-use-as-ref-1.good new file mode 100644 index 000000000000..7a30e84ab6f3 --- /dev/null +++ b/test/types/records/intents/error-const-use-as-ref-1.good @@ -0,0 +1,2 @@ +error-const-use-as-ref-1.chpl:4: error: foo is const by default, but code attempted to modify it. +note: If you intended to modify foo, use an explicit 'ref' this-intent for the method 'foo'. diff --git a/test/types/records/intents/error-const-use-as-ref-2.chpl b/test/types/records/intents/error-const-use-as-ref-2.chpl new file mode 100644 index 000000000000..0888d755966e --- /dev/null +++ b/test/types/records/intents/error-const-use-as-ref-2.chpl @@ -0,0 +1,18 @@ +record R2 { + var x = 0; + proc ref foo() { + coforall l in Locales do on l { + editThis(); + } + } + proc ref editThis() { + x += 1; + } + + proc ref bar() { + begin on Locales[0] do editThis(); + } +} +var r2 = new R2(); +r2.foo(); +writeln(r2); diff --git a/test/types/records/intents/error-const-use-as-ref-2.good b/test/types/records/intents/error-const-use-as-ref-2.good new file mode 100644 index 000000000000..dd4577b0a1a8 --- /dev/null +++ b/test/types/records/intents/error-const-use-as-ref-2.good @@ -0,0 +1,2 @@ +error-const-use-as-ref-2.chpl:4: error: this is const by default, but code attempted to modify it. +note: If you intended to modify this, add an explicit 'ref' task intent for 'this'. diff --git a/test/deprecated/ref-maybe-const-this-intent.chpl b/test/types/records/intents/error-const-use-as-ref-3.chpl similarity index 58% rename from test/deprecated/ref-maybe-const-this-intent.chpl rename to test/types/records/intents/error-const-use-as-ref-3.chpl index 5975db3b0d11..51540d8f3ac9 100644 --- a/test/deprecated/ref-maybe-const-this-intent.chpl +++ b/test/types/records/intents/error-const-use-as-ref-3.chpl @@ -1,18 +1,3 @@ -record R { - var x: int = 11; - var y: int = 12; - proc foo() { - x = 10; - } - proc bar() { // should not warn - writeln((x,y)); - } -} -var r = new R(); -r.foo(); -r.bar(); - - record R2 { var x = 0; proc ref foo() { @@ -29,6 +14,5 @@ record R2 { } } var r2 = new R2(); -r2.foo(); sync r2.bar(); writeln(r2); diff --git a/test/types/records/intents/error-const-use-as-ref-3.good b/test/types/records/intents/error-const-use-as-ref-3.good new file mode 100644 index 000000000000..3322bf243ab0 --- /dev/null +++ b/test/types/records/intents/error-const-use-as-ref-3.good @@ -0,0 +1,2 @@ +error-const-use-as-ref-3.chpl:13: error: this is const by default, but code attempted to modify it. +note: If you intended to modify this, add an explicit 'ref' task intent for 'this'.