Skip to content

Commit c49fdbe

Browse files
committed
[sil-cloner] Add a helper method for registering opened existentials remapping. NFC.
This is just a minor re-factoring of the existing code. It does not change the functionality.
1 parent cd59716 commit c49fdbe

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

include/swift/SIL/SILCloner.h

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ class SILCloner : protected SILVisitor<ImplClass> {
224224
"cloned instruction dropped debug scope");
225225
}
226226

227+
// Register a re-mapping for opened existentials.
228+
void registerOpenedExistentialRemapping(ArchetypeType *From, CanType To) {
229+
OpenedExistentialSubs[From] = To;
230+
}
231+
227232
protected:
228233

229234
SILBuilder Builder;
@@ -1330,8 +1335,9 @@ SILCloner<ImplClass>::visitOpenExistentialAddrInst(OpenExistentialAddrInst *Inst
13301335
= Inst->getType().getSwiftRValueType()->castTo<ArchetypeType>();
13311336
assert(OpenedExistentialSubs.count(archetypeTy) == 0 &&
13321337
"Already substituted opened existential archetype?");
1333-
OpenedExistentialSubs[archetypeTy]
1334-
= ArchetypeType::getOpened(archetypeTy->getOpenedExistentialType());
1338+
registerOpenedExistentialRemapping(
1339+
archetypeTy,
1340+
ArchetypeType::getOpened(archetypeTy->getOpenedExistentialType()));
13351341

13361342
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
13371343
doPostProcess(Inst,
@@ -1352,8 +1358,9 @@ visitOpenExistentialMetatypeInst(OpenExistentialMetatypeInst *Inst) {
13521358
openedType = cast<MetatypeType>(openedType).getInstanceType();
13531359
}
13541360
auto archetypeTy = cast<ArchetypeType>(openedType);
1355-
OpenedExistentialSubs[archetypeTy]
1356-
= ArchetypeType::getOpened(archetypeTy->getOpenedExistentialType());
1361+
registerOpenedExistentialRemapping(
1362+
archetypeTy,
1363+
ArchetypeType::getOpened(archetypeTy->getOpenedExistentialType()));
13571364

13581365
if (!Inst->getOperand()->getType().canUseExistentialRepresentation(
13591366
Inst->getModule(), ExistentialRepresentation::Class)) {
@@ -1379,8 +1386,9 @@ visitOpenExistentialRefInst(OpenExistentialRefInst *Inst) {
13791386
// Create a new archetype for this opened existential type.
13801387
auto archetypeTy
13811388
= Inst->getType().getSwiftRValueType()->castTo<ArchetypeType>();
1382-
OpenedExistentialSubs[archetypeTy]
1383-
= ArchetypeType::getOpened(archetypeTy->getOpenedExistentialType());
1389+
registerOpenedExistentialRemapping(
1390+
archetypeTy,
1391+
ArchetypeType::getOpened(archetypeTy->getOpenedExistentialType()));
13841392

13851393
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
13861394
doPostProcess(Inst,
@@ -1396,8 +1404,9 @@ visitOpenExistentialBoxInst(OpenExistentialBoxInst *Inst) {
13961404
// Create a new archetype for this opened existential type.
13971405
auto archetypeTy
13981406
= Inst->getType().getSwiftRValueType()->castTo<ArchetypeType>();
1399-
OpenedExistentialSubs[archetypeTy]
1400-
= ArchetypeType::getOpened(archetypeTy->getOpenedExistentialType());
1407+
registerOpenedExistentialRemapping(
1408+
archetypeTy,
1409+
ArchetypeType::getOpened(archetypeTy->getOpenedExistentialType()));
14011410

14021411
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
14031412
doPostProcess(Inst,

0 commit comments

Comments
 (0)