Skip to content

Commit 508bf8a

Browse files
committed
[move-only] Teach SILGenApply how to emit subscripts with borrowed base values.
I also added a bunch of tests that showed the behavior of subscripts/other accessors with the following combinations of semantics: 1. get only. 2. get/set. 3. get/modify. 4. read/set. 5. read/modify. rdar://109746476
1 parent f3f238a commit 508bf8a

File tree

5 files changed

+3016
-5
lines changed

5 files changed

+3016
-5
lines changed

lib/SILGen/ArgumentSource.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ class ArgumentSource {
280280

281281
ArgumentSource copyForDiagnostics() const;
282282

283-
void dump() const;
283+
LLVM_DUMP_METHOD void dump() const;
284284
void dump(raw_ostream &os, unsigned indent = 0) const;
285285

286286
private:

lib/SILGen/SILGenApply.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3042,6 +3042,14 @@ Expr *ArgumentSource::findStorageReferenceExprForMoveOnly(
30423042

30433043
auto argExpr = asKnownExpr();
30443044

3045+
// If we have a subscript, strip it off and make sure that our base is
3046+
// something that we can process. If we do and we succeed below, we return the
3047+
// subscript instead.
3048+
SubscriptExpr *subscriptExpr = nullptr;
3049+
if ((subscriptExpr = dyn_cast<SubscriptExpr>(argExpr))) {
3050+
argExpr = subscriptExpr->getBase();
3051+
}
3052+
30453053
// If there's a load around the outer part of this arg expr, look past it.
30463054
bool sawLoad = false;
30473055
if (auto *li = dyn_cast<LoadExpr>(argExpr)) {
@@ -3097,6 +3105,12 @@ Expr *ArgumentSource::findStorageReferenceExprForMoveOnly(
30973105
// has a move only base.
30983106
(void)std::move(*this).asKnownExpr();
30993107

3108+
// If we saw a subscript expr and the base of the subscript expr passed our
3109+
// tests above, we can emit the call to the subscript directly as a borrowed
3110+
// lvalue. Return the subscript expr here so that we emit it appropriately.
3111+
if (subscriptExpr)
3112+
return subscriptExpr;
3113+
31003114
return result.getTransitiveRoot();
31013115
}
31023116

0 commit comments

Comments
 (0)