@@ -224,6 +224,11 @@ class SILCloner : protected SILVisitor<ImplClass> {
224
224
" cloned instruction dropped debug scope" );
225
225
}
226
226
227
+ // Register a re-mapping for opened existentials.
228
+ void registerOpenedExistentialRemapping (ArchetypeType *From, CanType To) {
229
+ OpenedExistentialSubs[From] = To;
230
+ }
231
+
227
232
protected:
228
233
229
234
SILBuilder Builder;
@@ -1330,8 +1335,9 @@ SILCloner<ImplClass>::visitOpenExistentialAddrInst(OpenExistentialAddrInst *Inst
1330
1335
= Inst->getType ().getSwiftRValueType ()->castTo <ArchetypeType>();
1331
1336
assert (OpenedExistentialSubs.count (archetypeTy) == 0 &&
1332
1337
" Already substituted opened existential archetype?" );
1333
- OpenedExistentialSubs[archetypeTy]
1334
- = ArchetypeType::getOpened (archetypeTy->getOpenedExistentialType ());
1338
+ registerOpenedExistentialRemapping (
1339
+ archetypeTy,
1340
+ ArchetypeType::getOpened (archetypeTy->getOpenedExistentialType ()));
1335
1341
1336
1342
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
1337
1343
doPostProcess (Inst,
@@ -1352,8 +1358,9 @@ visitOpenExistentialMetatypeInst(OpenExistentialMetatypeInst *Inst) {
1352
1358
openedType = cast<MetatypeType>(openedType).getInstanceType ();
1353
1359
}
1354
1360
auto archetypeTy = cast<ArchetypeType>(openedType);
1355
- OpenedExistentialSubs[archetypeTy]
1356
- = ArchetypeType::getOpened (archetypeTy->getOpenedExistentialType ());
1361
+ registerOpenedExistentialRemapping (
1362
+ archetypeTy,
1363
+ ArchetypeType::getOpened (archetypeTy->getOpenedExistentialType ()));
1357
1364
1358
1365
if (!Inst->getOperand ()->getType ().canUseExistentialRepresentation (
1359
1366
Inst->getModule (), ExistentialRepresentation::Class)) {
@@ -1379,8 +1386,9 @@ visitOpenExistentialRefInst(OpenExistentialRefInst *Inst) {
1379
1386
// Create a new archetype for this opened existential type.
1380
1387
auto archetypeTy
1381
1388
= Inst->getType ().getSwiftRValueType ()->castTo <ArchetypeType>();
1382
- OpenedExistentialSubs[archetypeTy]
1383
- = ArchetypeType::getOpened (archetypeTy->getOpenedExistentialType ());
1389
+ registerOpenedExistentialRemapping (
1390
+ archetypeTy,
1391
+ ArchetypeType::getOpened (archetypeTy->getOpenedExistentialType ()));
1384
1392
1385
1393
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
1386
1394
doPostProcess (Inst,
@@ -1396,8 +1404,9 @@ visitOpenExistentialBoxInst(OpenExistentialBoxInst *Inst) {
1396
1404
// Create a new archetype for this opened existential type.
1397
1405
auto archetypeTy
1398
1406
= Inst->getType ().getSwiftRValueType ()->castTo <ArchetypeType>();
1399
- OpenedExistentialSubs[archetypeTy]
1400
- = ArchetypeType::getOpened (archetypeTy->getOpenedExistentialType ());
1407
+ registerOpenedExistentialRemapping (
1408
+ archetypeTy,
1409
+ ArchetypeType::getOpened (archetypeTy->getOpenedExistentialType ()));
1401
1410
1402
1411
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
1403
1412
doPostProcess (Inst,
0 commit comments