Skip to content

Commit

Permalink
Sema: Use coerceToRValue() to load tuples of lvalues instead of coerc…
Browse files Browse the repository at this point in the history
…eTupleToTuple()
  • Loading branch information
slavapestov committed Mar 27, 2019
1 parent 18e8fea commit ab81406
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
12 changes: 5 additions & 7 deletions lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5259,13 +5259,7 @@ Expr *ExprRewriter::coerceExistential(Expr *expr, Type toType,
// Load tuples with lvalue elements.
if (auto tupleType = fromType->getAs<TupleType>()) {
if (tupleType->hasLValueType()) {
auto toTuple = tupleType->getRValueType()->castTo<TupleType>();
SmallVector<unsigned, 4> sources;
bool failed = computeTupleShuffle(tupleType, toTuple, sources);
assert(!failed && "Couldn't convert tuple to tuple?");
(void)failed;

coerceTupleToTuple(expr, tupleType, toTuple, locator, sources);
expr = cs.coerceToRValue(expr);
}
}

Expand Down Expand Up @@ -6492,6 +6486,10 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
auto toTuple = toType->getAs<TupleType>();
if (!toTuple)
break;

if (fromTuple->hasLValueType() && !toTuple->hasLValueType())
return coerceToType(cs.coerceToRValue(expr), toType, locator);

SmallVector<unsigned, 4> sources;
if (!computeTupleShuffle(fromTuple, toTuple, sources)) {
return coerceTupleToTuple(expr, fromTuple, toTuple,
Expand Down
10 changes: 5 additions & 5 deletions lib/Sema/TypeCheckConstraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3134,15 +3134,11 @@ Expr *TypeChecker::coerceToRValue(Expr *expr,
return FVE;
}

// Load lvalues.
if (exprTy->is<LValueType>())
return addImplicitLoadExpr(expr, getType, setType);

// Walk into parenthesized expressions to update the subexpression.
if (auto paren = dyn_cast<IdentityExpr>(expr)) {
auto sub = coerceToRValue(paren->getSubExpr(), getType, setType);
paren->setSubExpr(sub);
setType(paren, getType(sub));
setType(paren, ParenType::get(Context, getType(sub)));
return paren;
}

Expand Down Expand Up @@ -3186,6 +3182,10 @@ Expr *TypeChecker::coerceToRValue(Expr *expr,
return tuple;
}

// Load lvalues.
if (exprTy->is<LValueType>())
return addImplicitLoadExpr(expr, getType, setType);

// Nothing to do.
return expr;
}
Expand Down

0 comments on commit ab81406

Please sign in to comment.