@@ -1035,13 +1035,27 @@ void ElementUseCollector::collectClassSelfUses() {
1035
1035
}
1036
1036
}
1037
1037
1038
+ static void
1039
+ collectBorrowedSuperUses (UpcastInst *Inst,
1040
+ llvm::SmallVectorImpl<UpcastInst *> &UpcastUsers) {
1041
+ for (auto *Use : Inst->getUses ()) {
1042
+ if (auto *URCI = dyn_cast<UncheckedRefCastInst>(Use->getUser ())) {
1043
+ for (auto *InnerUse : URCI->getUses ()) {
1044
+ if (auto *InnerUpcastUser = dyn_cast<UpcastInst>(InnerUse->getUser ())) {
1045
+ UpcastUsers.push_back (InnerUpcastUser);
1046
+ }
1047
+ }
1048
+ }
1049
+ }
1050
+ }
1051
+
1038
1052
// / isSuperInitUse - If this "upcast" is part of a call to super.init, return
1039
1053
// / the Apply instruction for the call, otherwise return null.
1040
1054
static SILInstruction *isSuperInitUse (UpcastInst *Inst) {
1041
1055
1042
1056
// "Inst" is an Upcast instruction. Check to see if it is used by an apply
1043
1057
// that came from a call to super.init.
1044
- for (auto UI : Inst->getUses ()) {
1058
+ for (auto * UI : Inst->getUses ()) {
1045
1059
auto *User = UI->getUser ();
1046
1060
// If this used by another upcast instruction, recursively handle it, we may
1047
1061
// have a multiple upcast chain.
@@ -1263,6 +1277,17 @@ collectClassSelfUses(SILValue ClassPointer, SILType MemorySILType,
1263
1277
Uses.push_back (DIMemoryUse (AI, DIUseKind::SuperInit,
1264
1278
0 , TheMemory.NumElements ));
1265
1279
recordFailableInitCall (AI);
1280
+
1281
+ // Now that we know that we have a super.init site, check if our upcast
1282
+ // has any borrow users. These used to be represented by a separate
1283
+ // load, but now with sil ownership, they are represented as borrows
1284
+ // from the same upcast as the super init user upcast.
1285
+ llvm::SmallVector<UpcastInst *, 4 > ExtraUpcasts;
1286
+ collectBorrowedSuperUses (UCI, ExtraUpcasts);
1287
+ for (auto *Upcast : ExtraUpcasts) {
1288
+ Uses.push_back (
1289
+ DIMemoryUse (Upcast, DIUseKind::Load, 0 , TheMemory.NumElements ));
1290
+ }
1266
1291
continue ;
1267
1292
}
1268
1293
@@ -1334,6 +1359,17 @@ void ElementUseCollector::collectDelegatingClassInitSelfLoadUses(
1334
1359
if (auto *subAI = isSuperInitUse (UCI)) {
1335
1360
Uses.push_back (DIMemoryUse (subAI, DIUseKind::SuperInit, 0 , 1 ));
1336
1361
recordFailableInitCall (subAI);
1362
+
1363
+ // Now that we know that we have a super.init site, check if our upcast
1364
+ // has any borrow users. These used to be represented by a separate
1365
+ // load, but now with sil ownership, they are represented as borrows
1366
+ // from the same upcast as the super init user upcast.
1367
+ llvm::SmallVector<UpcastInst *, 4 > ExtraUpcasts;
1368
+ collectBorrowedSuperUses (UCI, ExtraUpcasts);
1369
+ for (auto *Upcast : ExtraUpcasts) {
1370
+ Uses.push_back (
1371
+ DIMemoryUse (Upcast, DIUseKind::Escape, 0 , TheMemory.NumElements ));
1372
+ }
1337
1373
continue ;
1338
1374
}
1339
1375
}
0 commit comments