Skip to content

Commit a2b2087

Browse files
Merge pull request #74198 from nate-chandler/rdar128900124
[MoveOnly] Call mutating methods on existentials.
2 parents 1bb335d + e2fcdb4 commit a2b2087

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/SIL/Utils/FieldSensitivePrunedLiveness.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ SubElementOffset::computeForAddress(SILValue projectionDerivedFromRoot,
164164
continue;
165165
}
166166

167+
if (auto *iea =
168+
dyn_cast<InitExistentialAddrInst>(projectionDerivedFromRoot)) {
169+
projectionDerivedFromRoot = iea->getOperand();
170+
continue;
171+
}
172+
167173
if (auto *teai =
168174
dyn_cast<TupleElementAddrInst>(projectionDerivedFromRoot)) {
169175
SILType tupleType = teai->getOperand()->getType();

test/Interpreter/rdar125864434.swift renamed to test/Interpreter/moveonly_existentials.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,24 @@
77

88
protocol Boopable: ~Copyable {
99
func boop()
10+
mutating func bonk()
1011
}
1112

1213
struct S: ~Copyable, Boopable {
1314
func boop() { print("boop") }
15+
mutating func bonk() { print("hmm") }
1416
}
1517

16-
func check(_ b: borrowing any Boopable & ~Copyable) {
18+
func borrow(_ b: borrowing any Boopable & ~Copyable) {
1719
b.boop()
1820
}
1921

22+
func mutate(_ b: inout any Boopable & ~Copyable) {
23+
b.bonk()
24+
}
25+
2026
// CHECK: boop
21-
check(S())
27+
// CHECK: hmm
28+
borrow(S())
29+
var s = S() as any Boopable & ~Copyable
30+
mutate(&s)

0 commit comments

Comments
 (0)