@@ -248,8 +248,10 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
248248 return asImpl ().remapASTType (ty);
249249 }
250250
251- void remapOpenedType (CanOpenedArchetypeType archetypeTy) {
252- auto existentialTy = archetypeTy->getOpenedExistentialType ()->getCanonicalType ();
251+ void remapRootOpenedType (CanOpenedArchetypeType archetypeTy) {
252+ assert (archetypeTy->isRoot ());
253+
254+ auto existentialTy = archetypeTy->getExistentialType ()->getCanonicalType ();
253255 auto replacementTy = OpenedArchetypeType::get (
254256 getOpASTType (existentialTy),
255257 archetypeTy->getInterfaceType ());
@@ -2199,7 +2201,7 @@ template<typename ImplClass>
21992201void
22002202SILCloner<ImplClass>::visitOpenExistentialAddrInst(OpenExistentialAddrInst *Inst) {
22012203 // Create a new archetype for this opened existential type.
2202- remapOpenedType (Inst->getType ().castTo <OpenedArchetypeType>());
2204+ remapRootOpenedType (Inst->getType ().castTo <OpenedArchetypeType>());
22032205
22042206 getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
22052207 recordClonedInstruction (
@@ -2212,7 +2214,7 @@ template <typename ImplClass>
22122214void SILCloner<ImplClass>::visitOpenExistentialValueInst(
22132215 OpenExistentialValueInst *Inst) {
22142216 // Create a new archetype for this opened existential type.
2215- remapOpenedType (Inst->getType ().castTo <OpenedArchetypeType>());
2217+ remapRootOpenedType (Inst->getType ().castTo <OpenedArchetypeType>());
22162218
22172219 getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
22182220 recordClonedInstruction (
@@ -2235,7 +2237,7 @@ visitOpenExistentialMetatypeInst(OpenExistentialMetatypeInst *Inst) {
22352237 exType = exMetatype->getExistentialInstanceType ()->getCanonicalType ();
22362238 openedType = cast<MetatypeType>(openedType).getInstanceType ();
22372239 }
2238- remapOpenedType (cast<OpenedArchetypeType>(openedType));
2240+ remapRootOpenedType (cast<OpenedArchetypeType>(openedType));
22392241
22402242 if (!Inst->getOperand ()->getType ().canUseExistentialRepresentation (
22412243 ExistentialRepresentation::Class)) {
@@ -2259,7 +2261,7 @@ void
22592261SILCloner<ImplClass>::
22602262visitOpenExistentialRefInst (OpenExistentialRefInst *Inst) {
22612263 // Create a new archetype for this opened existential type.
2262- remapOpenedType (Inst->getType ().castTo <OpenedArchetypeType>());
2264+ remapRootOpenedType (Inst->getType ().castTo <OpenedArchetypeType>());
22632265
22642266 getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
22652267 recordClonedInstruction (
@@ -2276,7 +2278,7 @@ void
22762278SILCloner<ImplClass>::
22772279visitOpenExistentialBoxInst (OpenExistentialBoxInst *Inst) {
22782280 // Create a new archetype for this opened existential type.
2279- remapOpenedType (Inst->getType ().castTo <OpenedArchetypeType>());
2281+ remapRootOpenedType (Inst->getType ().castTo <OpenedArchetypeType>());
22802282
22812283 getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
22822284 recordClonedInstruction (Inst, getBuilder ().createOpenExistentialBox (
@@ -2290,7 +2292,7 @@ void
22902292SILCloner<ImplClass>::
22912293visitOpenExistentialBoxValueInst (OpenExistentialBoxValueInst *Inst) {
22922294 // Create a new archetype for this opened existential type.
2293- remapOpenedType (Inst->getType ().castTo <OpenedArchetypeType>());
2295+ remapRootOpenedType (Inst->getType ().castTo <OpenedArchetypeType>());
22942296
22952297 getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
22962298 recordClonedInstruction (
0 commit comments