Skip to content

Commit 90ab23e

Browse files
committed
SILGen: Fix invariant violation with existential conformances
When erasing a pseudogeneric value in SILGen, we actually treat the value as if it had the type `any AnyObject`, while in Sema, it's an archetype. This requires SILGen to look up conformances again instead of using the ones in the ErasureExpr.
1 parent e7131cf commit 90ab23e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/SILGen/SILGenConvert.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -853,9 +853,6 @@ ManagedValue SILGenFunction::emitExistentialErasure(
853853
[&, concreteFormalType, F](SGFContext C) -> ManagedValue {
854854
auto concreteValue = F(SGFContext());
855855
assert(concreteFormalType->isBridgeableObjectType());
856-
auto *M = SGM.M.getSwiftModule();
857-
auto conformances = M->collectExistentialConformances(
858-
concreteFormalType, anyObjectTy);
859856
return B.createInitExistentialRef(
860857
loc, SILType::getPrimitiveObjectType(anyObjectTy), concreteFormalType,
861858
concreteValue, conformances);
@@ -864,6 +861,12 @@ ManagedValue SILGenFunction::emitExistentialErasure(
864861
if (this->F.getLoweredFunctionType()->isPseudogeneric()) {
865862
if (anyObjectTy && concreteFormalType->is<ArchetypeType>()) {
866863
concreteFormalType = anyObjectTy;
864+
865+
// The original conformances are no good because they have the wrong
866+
// (pseudogeneric) subject type.
867+
auto *M = SGM.M.getSwiftModule();
868+
conformances = M->collectExistentialConformances(
869+
concreteFormalType, anyObjectTy);
867870
F = eraseToAnyObject;
868871
}
869872
}

0 commit comments

Comments
 (0)