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
Merged
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
10 changes: 8 additions & 2 deletions compiler/resolution/functionResolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,14 @@ isLegalLvalueActualArg(ArgSymbol* formal, Expr* actual,
sym->isParameter())
actualConst = true;

bool actualExprTmp = sym->hasFlag(FLAG_EXPR_TEMP) &&
!sym->type->symbol->hasFlag(FLAG_ARRAY);
bool actualExprTmp = sym->hasFlag(FLAG_EXPR_TEMP);

// don't emit lvalue errors for array slices
// (we can think of these as a special kind of reference)
if (isAliasingArrayType(sym->type)) {
actualExprTmp = false;
}

TypeSymbol* formalTS = NULL;
bool formalCopyMutates = false;
if (formal) {
Expand Down
7 changes: 3 additions & 4 deletions compiler/resolution/wrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2710,10 +2710,6 @@ static void initPromotionWrapper(PromotionInfo& promotion,
retval->addFlag(FLAG_PROMOTION_WRAPPER);
retval->addFlag(FLAG_FN_RETURNS_ITERATOR);

if (fn->hasFlag(FLAG_OPERATOR)) {
retval->addFlag(FLAG_OPERATOR);
}

mppf marked this conversation as resolved.
Show resolved Hide resolved
int i = 0;
for_formals(formal, fn) {

Expand Down Expand Up @@ -3207,7 +3203,10 @@ static FnSymbol* buildEmptyWrapper(FnSymbol* fn) {
if (fn->hasFlag(FLAG_METHOD_PRIMARY)) wrapper->addFlag(FLAG_METHOD_PRIMARY);
if (fn->hasFlag(FLAG_ASSIGNOP)) wrapper->addFlag(FLAG_ASSIGNOP);
if (fn->hasFlag(FLAG_LAST_RESORT)) wrapper->addFlag(FLAG_LAST_RESORT);
if (fn->hasFlag(FLAG_OPERATOR)) wrapper->addFlag(FLAG_OPERATOR);

if ( fn->hasFlag(FLAG_REF_TO_CONST_WHEN_CONST_THIS))
wrapper->addFlag(FLAG_REF_TO_CONST_WHEN_CONST_THIS);
if ( fn->hasFlag(FLAG_VOID_NO_RETURN_VALUE))
wrapper->addFlag(FLAG_VOID_NO_RETURN_VALUE);
if ( fn->hasFlag(FLAG_FN_RETURNS_ITERATOR))
Expand Down
3 changes: 0 additions & 3 deletions test/arrays/deitz/test_return_array_in_non_var_function.bad

This file was deleted.

This file was deleted.

6 changes: 2 additions & 4 deletions test/arrays/ferguson/choose-array/choose-array3-2.good
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
1 1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2 2
8 2 2 2 2 2 2 2 2 2
9 1 1 1 1 1 1 1 1 1
choose-array3-2.chpl:24: error: non-lvalue actual is passed to 'ref' formal 'C' of updateAndPrint()
choose-array3-2.chpl:24: error: non-lvalue actual is passed to 'ref' formal 'D' of updateAndPrint()
1 change: 0 additions & 1 deletion test/arrays/ferguson/if-expr/aif4-param.1-0.good
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
1 0 0
1 0 3
1 0 0
0 0 0
1 change: 0 additions & 1 deletion test/arrays/ferguson/if-expr/aif4-param.2-0.good
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
2 0 0
2 0 3
0 0 0
2 0 0
6 changes: 2 additions & 4 deletions test/arrays/ferguson/if-expr/aif4-param.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@

config param param_useA = true;

proc update(ref x)
proc passArray(const ref x)
{
writeln(x);
x[3] = 3;
writeln(x);
}


Expand All @@ -26,7 +24,7 @@ proc makeB() {
}

proc run() {
update( if param_useA then makeA() else makeB() );
passArray( if param_useA then makeA() else makeB() );

writeln(A);
writeln(B);
Expand Down
1 change: 0 additions & 1 deletion test/arrays/ferguson/if-expr/aif4.0-1.good
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
1 0 0
1 0 3
1 0 0
0 0 0
1 change: 0 additions & 1 deletion test/arrays/ferguson/if-expr/aif4.0-2.good
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
2 0 0
2 0 3
0 0 0
2 0 0
6 changes: 2 additions & 4 deletions test/arrays/ferguson/if-expr/aif4.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

config const useA = true;

proc update(ref x)
proc passArray(const ref x)
{
writeln(x);
x[3] = 3;
writeln(x);
}


Expand All @@ -25,7 +23,7 @@ proc makeB() {
}

proc run() {
update( if useA then makeA() else makeB() );
passArray( if useA then makeA() else makeB() );

writeln(A);
writeln(B);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ var globalArray: [1..2] R;
proc returnGlobalArray() {
return globalArray;
}
proc setToOne(ref A:[] R) {
A[1] = one;
proc setToOne(const ref A:[] R) {
globalArray[1] = one;
writeln(A[1].x);
}
setToOne(returnGlobalArray());
writeln(globalArray[1].x);

// Does this program output 0 or 1?
// In other words, does the act of returning globalArray
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
globalArray is 0
setting returnGlobalArray() = ArrTwo
copy/assign from 0
copy/assign from 2
globalArray is now 0
0
1.4-assign-callexpr-array.chpl:13: error: illegal lvalue in assignment
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ var globalArray: [1..2] R;
proc returnGlobalArray() const {
return globalArray;
}
proc setToOne(ref A:[] R) {
A[1] = one;
proc setToOne(const ref A:[] R) {
globalArray[1] = one;
writeln(A[1].x);
}
setToOne(returnGlobalArray());
writeln(globalArray[1].x);

// Does this program output 0 or 1?
// In other words, does the act of returning globalArray
Expand Down
17 changes: 17 additions & 0 deletions test/arrays/return/array-lvalue-error.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
proc makeInputArray(n: int) {
var A:[1..n] int = 1..n;
return A;
}

proc mutateAndSum(ref A) {
for x in A {
x *= 2;
}
return + reduce A;
}

var A = makeInputArray(1000);
A[1..10] = 4; // this should not be an error

var sum = mutateAndSum(makeInputArray(1000)); // this should be an error
writeln(sum);
1 change: 1 addition & 0 deletions test/arrays/return/array-lvalue-error.good
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
array-lvalue-error.chpl:16: error: non-lvalue actual is passed to 'ref' formal 'A' of mutateAndSum()
4 changes: 0 additions & 4 deletions test/users/thom/arrArg-fromFunction.bad

This file was deleted.

2 changes: 0 additions & 2 deletions test/users/thom/arrArg-fromFunction.future

This file was deleted.

3 changes: 2 additions & 1 deletion test/users/thom/arrArg-fromFunction.good
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
[Design] What should be the result?
arrArg-fromFunction.chpl:17: error: non-lvalue actual is passed to 'ref' formal 'X' of writeArrRef()
arrArg-fromFunction.chpl:19: error: non-lvalue actual is passed to 'ref' formal 'X' of writeArrRef()