Skip to content

Commit

Permalink
Attempt to resolve issue #16275
Browse files Browse the repository at this point in the history
So far, only improves the array parts.
  • Loading branch information
mppf committed Aug 21, 2020
1 parent e088b46 commit 4f80b49
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 4 deletions.
9 changes: 9 additions & 0 deletions compiler/resolution/functionResolution.cpp
Expand Up @@ -420,6 +420,10 @@ Type* getCopyTypeDuringResolution(Type* t) {

FnSymbol* fn = getInitCopyDuringResolution(at);
INT_ASSERT(fn);

if (fn->retType == t)
INT_FATAL("Expected different return type for this initCopy");

return fn->retType;
}

Expand Down Expand Up @@ -6767,6 +6771,11 @@ void resolveInitVar(CallExpr* call) {
resolveMove(call);
}

if (isAliasingArray(srcExpr->getValType()) || initCopyIter)
if (FnSymbol* initCopyFn = initCopy->resolvedFunction())
if (initCopyFn->retType == srcExpr->getValType())
INT_FATAL("Expected different return type for this initCopy");

} else if (isRecord(targetType->getValType())) {
AggregateType* at = toAggregateType(targetType->getValType());

Expand Down
25 changes: 21 additions & 4 deletions modules/internal/ChapelArray.chpl
Expand Up @@ -4381,9 +4381,27 @@ module ChapelArray {

pragma "init copy fn"
proc chpl__initCopy(const ref rhs: []) {
pragma "no copy"
var lhs = chpl__coerceCopy(rhs.type, rhs);
return lhs;

// Reindex and rank change domains should use a non-view domain
// when creating the new array. This is not a problem for slices
// because they already use a non-view domain.
if rhs._value.isRankChangeArrayView() {
type t = chpl__buildArrayRuntimeType(_getDomain(rhs.domain.upDom),
rhs.eltType);
pragma "no copy"
var lhs = chpl__coerceCopy(t, rhs);
return lhs;
} else if rhs._value.isReindexArrayView() {
type t = chpl__buildArrayRuntimeType(_getDomain(rhs.domain.updom),
rhs.eltType);
pragma "no copy"
var lhs = chpl__coerceCopy(t, rhs);
return lhs;
} else {
pragma "no copy"
var lhs = chpl__coerceCopy(rhs.type, rhs);
return lhs;
}
}

pragma "auto copy fn" proc chpl__autoCopy(x: []) {
Expand Down Expand Up @@ -4524,7 +4542,6 @@ module ChapelArray {
return lhs;
}


pragma "find user line"
pragma "coerce fn"
proc chpl__coerceCopy(type dstType:_array, rhs:_array) {
Expand Down
63 changes: 63 additions & 0 deletions test/arrays/ferguson/views-and-copying.chpl
@@ -0,0 +1,63 @@
proc returnIt(arg) { return arg; }

proc main() {
var A: [1..2] real;
var AA: [1..2, 1..2] real;

{
writeln();
writeln("slice");
const ref rB = A[1..1];
writeln("to const ref is view: ", rB.isSliceArrayView());

var B = A[1..1];
writeln("to var is view: ", B.isSliceArrayView());

const ref rReturned = returnIt(A[1..1]);
writeln("returned is view: ", rReturned.isSliceArrayView());

const ref rD = A[1..1].domain;
writeln(".domain to const ref is view: ", rD.isSliceDomainView());

var D = A[1..1].domain;
writeln(".domain to var is view: ", D.isSliceDomainView());
}

{
writeln();
writeln("reindex");
const ref rB = A.reindex(3..4);
writeln("to const ref is view: ", rB.isReindexArrayView());

var B = A.reindex(3..4);
writeln("to var is view: ", B.isReindexArrayView());

const ref rReturned = returnIt(A.reindex(3..4));
writeln("returned is view: ", rReturned.isReindexArrayView());

const ref rD = A.reindex(3..4).domain;
writeln(".domain to const ref is view: ", rD.isReindexDomainView());

var D = A.reindex(3..4).domain;
writeln(".domain to var is view: ", D.isReindexDomainView());
}

{
writeln();
writeln("rank change");
const ref rB = AA[1, ..];
writeln("to const ref is view: ", rB.isRankChangeArrayView());

var B = AA[1, ..];
writeln("to var is view: ", B.isRankChangeArrayView());

const ref rReturned = returnIt(AA[1, ..]);
writeln("returned is view: ", rReturned.isRankChangeArrayView());

const ref rD = AA[1, ..].domain;
writeln(".domain to const ref is view: ", rD.isRankChangeDomainView());

var D = AA[1, ..].domain;
writeln(".domain to var is view: ", D.isRankChangeDomainView());
}
}
21 changes: 21 additions & 0 deletions test/arrays/ferguson/views-and-copying.good
@@ -0,0 +1,21 @@

slice
to const ref is view: true
to var is view: false
returned is view: false
.domain to const ref is view: false
.domain to var is view: false

reindex
to const ref is view: true
to var is view: false
returned is view: false
.domain to const ref is view: true
.domain to var is view: true

rank change
to const ref is view: true
to var is view: false
returned is view: false
.domain to const ref is view: true
.domain to var is view: true

0 comments on commit 4f80b49

Please sign in to comment.