Skip to content

Commit 39fc79c

Browse files
committed
Fix copy elision on nested tuple expr
Signed-off-by: Anna Rift <[email protected]>
1 parent 3876f9e commit 39fc79c

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

frontend/lib/resolution/copy-elision.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -391,20 +391,11 @@ void FindElidedCopies::handleDeclaration(const VarLikeDecl* ast,
391391
isFormal, rv);
392392
} else {
393393
ID rhsVarId = refersToId(eltExpr, rv);
394+
QualifiedType rhsType = rv.byId(rhsVarId).type();
394395
if (!rhsVarId.isEmpty() && isEligibleVarInAnyFrame(rhsVarId)) {
395-
// check that the types are the same, per tuple position
396-
if (rv.hasId(lhsVarId) && rv.hasId(rhsVarId)) {
397-
if (lhsType.type() && lhsType.type()->isTupleType()) {
398-
const TupleType* ttype = lhsType.type()->toTupleType();
399-
CHPL_ASSERT(ttype->numElements() ==
400-
tupleExprInit->numActuals());
401-
QualifiedType lhsEltType = ttype->elementType(i);
402-
403-
QualifiedType rhsType = rv.byId(rhsVarId).type();
404-
if (copyElisionAllowedForTypes(lhsEltType, rhsType, ast, rv)) {
405-
addCopyInit(frame, rhsVarId, eltExpr->id());
406-
}
407-
}
396+
// TODO: do we need to verify LHS and RHS type compatibility per element?
397+
if (copyElisionAllowedForTypes(rhsType, rhsType, ast, rv)) {
398+
addCopyInit(frame, rhsVarId, eltExpr->id());
408399
}
409400
}
410401
}

frontend/test/resolution/testCopyElision.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,17 +1381,19 @@ static void test48() {
13811381
static void test49() {
13821382
// Init
13831383
testCopyElision("test49a",
1384-
R""""(
1384+
R""""(
13851385
record R { }
13861386
proc test() {
13871387
var r = new R();
1388+
var s = new R();
13881389
1389-
var tup = (1, r, "hi");
1390+
var tup = ((1,), r, ((s, "hi"), 2, 3.14));
13901391
1391-
var (a, b, _) = tup;
1392+
var ((a,), b, ((c, d), _, e)) = tup;
13921393
}
13931394
)"""",
1394-
{"M.test@5", "M.test@9", "M.test@10"});
1395+
{"M.test@10", "M.test@11", "M.test@19", "M.test@21",
1396+
"M.test@22", "M.test@23", "M.test@26"});
13951397

13961398
// Assign
13971399
testCopyElision("test49b",

0 commit comments

Comments
 (0)