Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions compiler/resolution/cullOverReferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
13 changes: 13 additions & 0 deletions test/arrays/errors/error-const-use-as-ref-1.chpl
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 2 additions & 0 deletions test/arrays/errors/error-const-use-as-ref-1.good
Original file line number Diff line number Diff line change
@@ -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'.
13 changes: 13 additions & 0 deletions test/arrays/errors/error-const-use-as-ref-2.chpl
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 2 additions & 0 deletions test/arrays/errors/error-const-use-as-ref-2.good
Original file line number Diff line number Diff line change
@@ -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'.
5 changes: 0 additions & 5 deletions test/deprecated/ref-maybe-const-this-intent.good

This file was deleted.

1 change: 0 additions & 1 deletion test/deprecated/ref-maybe-const-this-intent.numlocales

This file was deleted.

29 changes: 0 additions & 29 deletions test/deprecated/ref-maybe-const.chpl

This file was deleted.

6 changes: 0 additions & 6 deletions test/deprecated/ref-maybe-const.good

This file was deleted.

2 changes: 1 addition & 1 deletion test/llvm/parallel_loop_access/different_numbers.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/llvm/parallel_loop_access/generation_inside_loop.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]+]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test/llvm/parallel_loop_access/simple_forall.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion test/llvm/parallel_loop_access/simple_loop.chpl
Original file line number Diff line number Diff line change
@@ -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];
Expand Down
2 changes: 1 addition & 1 deletion test/llvm/parallel_loop_access/zippered_forall.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion test/llvm/vectorization/complicated_loop.chpl
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/llvm/vectorization/double_loop.chpl
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
2 changes: 1 addition & 1 deletion test/llvm/vectorization/forall_loop.chpl
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion test/llvm/vectorization/nested_loop.chpl
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test/llvm/vectorization/simple_loop.chpl
Original file line number Diff line number Diff line change
@@ -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];
Expand Down
2 changes: 1 addition & 1 deletion test/llvm/vectorization/zipped_loop.chpl
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
8 changes: 4 additions & 4 deletions test/studies/isx/isx-no-return.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -330,7 +330,7 @@ proc verifyResults(bucketID, myBucketSize, myLocalKeyCounts) {
}


proc makeInput(myKeys, bucketID) {
proc makeInput(ref myKeys, bucketID) {
use Random;
use Random.PCGRandomLib;

Expand Down
13 changes: 13 additions & 0 deletions test/types/records/intents/error-const-use-as-ref-1.chpl
Original file line number Diff line number Diff line change
@@ -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();
2 changes: 2 additions & 0 deletions test/types/records/intents/error-const-use-as-ref-1.good
Original file line number Diff line number Diff line change
@@ -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'.
18 changes: 18 additions & 0 deletions test/types/records/intents/error-const-use-as-ref-2.chpl
Original file line number Diff line number Diff line change
@@ -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);
2 changes: 2 additions & 0 deletions test/types/records/intents/error-const-use-as-ref-2.good
Original file line number Diff line number Diff line change
@@ -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'.
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -29,6 +14,5 @@ record R2 {
}
}
var r2 = new R2();
r2.foo();
sync r2.bar();
writeln(r2);
2 changes: 2 additions & 0 deletions test/types/records/intents/error-const-use-as-ref-3.good
Original file line number Diff line number Diff line change
@@ -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'.