@@ -2185,14 +2185,24 @@ ObjCMethodInst::create(SILDebugLocation DebugLoc, SILValue Operand,
21852185 Member, Ty);
21862186}
21872187
2188+ static void checkExistentialPreconditions (SILType ExistentialType,
2189+ CanType ConcreteType,
2190+ ArrayRef<ProtocolConformanceRef> Conformances) {
2191+ #ifndef NDEBUG
2192+ auto layout = ExistentialType.getASTType ().getExistentialLayout ();
2193+ assert (layout.getProtocols ().size () == Conformances.size ());
2194+
2195+ for (auto conformance : Conformances) {
2196+ assert (!conformance.isAbstract () || isa<ArchetypeType>(ConcreteType));
2197+ }
2198+ #endif
2199+ }
2200+
21882201InitExistentialAddrInst *InitExistentialAddrInst::create (
21892202 SILDebugLocation Loc, SILValue Existential, CanType ConcreteType,
21902203 SILType ConcreteLoweredType, ArrayRef<ProtocolConformanceRef> Conformances,
21912204 SILFunction *F) {
2192- #ifndef NDEBUG
2193- auto layout = Existential->getType ().getASTType ().getExistentialLayout ();
2194- assert (layout.getProtocols ().size () == Conformances.size ());
2195- #endif
2205+ checkExistentialPreconditions (Existential->getType (), ConcreteType, Conformances);
21962206
21972207 SILModule &Mod = F->getModule ();
21982208 SmallVector<SILValue, 8 > TypeDependentOperands;
@@ -2212,10 +2222,7 @@ InitExistentialValueInst *InitExistentialValueInst::create(
22122222 SILDebugLocation Loc, SILType ExistentialType, CanType ConcreteType,
22132223 SILValue Instance, ArrayRef<ProtocolConformanceRef> Conformances,
22142224 SILFunction *F) {
2215- #ifndef NDEBUG
2216- auto layout = ExistentialType.getASTType ().getExistentialLayout ();
2217- assert (layout.getProtocols ().size () == Conformances.size ());
2218- #endif
2225+ checkExistentialPreconditions (ExistentialType, ConcreteType, Conformances);
22192226
22202227 SILModule &Mod = F->getModule ();
22212228 SmallVector<SILValue, 8 > TypeDependentOperands;
@@ -2233,10 +2240,7 @@ InitExistentialRefInst *InitExistentialRefInst::create(
22332240 SILDebugLocation Loc, SILType ExistentialType, CanType ConcreteType,
22342241 SILValue Instance, ArrayRef<ProtocolConformanceRef> Conformances,
22352242 SILFunction *F, ValueOwnershipKind forwardingOwnershipKind) {
2236- #ifndef NDEBUG
2237- auto layout = ExistentialType.getASTType ().getExistentialLayout ();
2238- assert (layout.getProtocols ().size () == Conformances.size ());
2239- #endif
2243+ checkExistentialPreconditions (ExistentialType, ConcreteType, Conformances);
22402244
22412245 SILModule &Mod = F->getModule ();
22422246 SmallVector<SILValue, 8 > TypeDependentOperands;
0 commit comments