@@ -174,6 +174,12 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
174
174
return asImpl ().remapASTType (ty);
175
175
}
176
176
177
+ void remapOpenedType (CanArchetypeType archetypeTy) {
178
+ auto existentialTy = archetypeTy->getOpenedExistentialType ()->getCanonicalType ();
179
+ auto replacementTy = ArchetypeType::getOpened (getOpASTType (existentialTy));
180
+ registerOpenedExistentialRemapping (archetypeTy, replacementTy);
181
+ }
182
+
177
183
ProtocolConformanceRef getOpConformance (Type ty,
178
184
ProtocolConformanceRef conformance) {
179
185
// If we have open existentials to substitute, do so now.
@@ -1644,10 +1650,7 @@ template<typename ImplClass>
1644
1650
void
1645
1651
SILCloner<ImplClass>::visitOpenExistentialAddrInst(OpenExistentialAddrInst *Inst) {
1646
1652
// Create a new archetype for this opened existential type.
1647
- auto archetypeTy = Inst->getType ().castTo <ArchetypeType>();
1648
- registerOpenedExistentialRemapping (
1649
- archetypeTy,
1650
- ArchetypeType::getOpened (archetypeTy->getOpenedExistentialType ()));
1653
+ remapOpenedType (Inst->getType ().castTo <ArchetypeType>());
1651
1654
1652
1655
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
1653
1656
doPostProcess (Inst,
@@ -1661,10 +1664,7 @@ template <typename ImplClass>
1661
1664
void SILCloner<ImplClass>::visitOpenExistentialValueInst(
1662
1665
OpenExistentialValueInst *Inst) {
1663
1666
// Create a new archetype for this opened existential type.
1664
- auto archetypeTy = Inst->getType ().castTo <ArchetypeType>();
1665
- registerOpenedExistentialRemapping (
1666
- archetypeTy,
1667
- ArchetypeType::getOpened (archetypeTy->getOpenedExistentialType ()));
1667
+ remapOpenedType (Inst->getType ().castTo <ArchetypeType>());
1668
1668
1669
1669
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
1670
1670
doPostProcess (Inst, getBuilder ().createOpenExistentialValue (
@@ -1684,10 +1684,7 @@ visitOpenExistentialMetatypeInst(OpenExistentialMetatypeInst *Inst) {
1684
1684
exType = exMetatype.getInstanceType ();
1685
1685
openedType = cast<MetatypeType>(openedType).getInstanceType ();
1686
1686
}
1687
- auto archetypeTy = cast<ArchetypeType>(openedType);
1688
- registerOpenedExistentialRemapping (
1689
- archetypeTy,
1690
- ArchetypeType::getOpened (archetypeTy->getOpenedExistentialType ()));
1687
+ remapOpenedType (cast<ArchetypeType>(openedType));
1691
1688
1692
1689
if (!Inst->getOperand ()->getType ().canUseExistentialRepresentation (
1693
1690
Inst->getModule (), ExistentialRepresentation::Class)) {
@@ -1711,10 +1708,7 @@ void
1711
1708
SILCloner<ImplClass>::
1712
1709
visitOpenExistentialRefInst (OpenExistentialRefInst *Inst) {
1713
1710
// Create a new archetype for this opened existential type.
1714
- auto archetypeTy = Inst->getType ().castTo <ArchetypeType>();
1715
- registerOpenedExistentialRemapping (
1716
- archetypeTy,
1717
- ArchetypeType::getOpened (archetypeTy->getOpenedExistentialType ()));
1711
+ remapOpenedType (Inst->getType ().castTo <ArchetypeType>());
1718
1712
1719
1713
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
1720
1714
doPostProcess (Inst,
@@ -1728,10 +1722,7 @@ void
1728
1722
SILCloner<ImplClass>::
1729
1723
visitOpenExistentialBoxInst (OpenExistentialBoxInst *Inst) {
1730
1724
// Create a new archetype for this opened existential type.
1731
- auto archetypeTy = Inst->getType ().castTo <ArchetypeType>();
1732
- registerOpenedExistentialRemapping (
1733
- archetypeTy,
1734
- ArchetypeType::getOpened (archetypeTy->getOpenedExistentialType ()));
1725
+ remapOpenedType (Inst->getType ().castTo <ArchetypeType>());
1735
1726
1736
1727
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
1737
1728
doPostProcess (Inst,
@@ -1745,10 +1736,7 @@ void
1745
1736
SILCloner<ImplClass>::
1746
1737
visitOpenExistentialBoxValueInst (OpenExistentialBoxValueInst *Inst) {
1747
1738
// Create a new archetype for this opened existential type.
1748
- auto archetypeTy = Inst->getType ().castTo <ArchetypeType>();
1749
- registerOpenedExistentialRemapping (
1750
- archetypeTy,
1751
- ArchetypeType::getOpened (archetypeTy->getOpenedExistentialType ()));
1739
+ remapOpenedType (Inst->getType ().castTo <ArchetypeType>());
1752
1740
1753
1741
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
1754
1742
doPostProcess (Inst,
0 commit comments