@@ -2185,14 +2185,24 @@ ObjCMethodInst::create(SILDebugLocation DebugLoc, SILValue Operand,
2185
2185
Member, Ty);
2186
2186
}
2187
2187
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
+
2188
2201
InitExistentialAddrInst *InitExistentialAddrInst::create (
2189
2202
SILDebugLocation Loc, SILValue Existential, CanType ConcreteType,
2190
2203
SILType ConcreteLoweredType, ArrayRef<ProtocolConformanceRef> Conformances,
2191
2204
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);
2196
2206
2197
2207
SILModule &Mod = F->getModule ();
2198
2208
SmallVector<SILValue, 8 > TypeDependentOperands;
@@ -2212,10 +2222,7 @@ InitExistentialValueInst *InitExistentialValueInst::create(
2212
2222
SILDebugLocation Loc, SILType ExistentialType, CanType ConcreteType,
2213
2223
SILValue Instance, ArrayRef<ProtocolConformanceRef> Conformances,
2214
2224
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);
2219
2226
2220
2227
SILModule &Mod = F->getModule ();
2221
2228
SmallVector<SILValue, 8 > TypeDependentOperands;
@@ -2233,10 +2240,7 @@ InitExistentialRefInst *InitExistentialRefInst::create(
2233
2240
SILDebugLocation Loc, SILType ExistentialType, CanType ConcreteType,
2234
2241
SILValue Instance, ArrayRef<ProtocolConformanceRef> Conformances,
2235
2242
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);
2240
2244
2241
2245
SILModule &Mod = F->getModule ();
2242
2246
SmallVector<SILValue, 8 > TypeDependentOperands;
0 commit comments