Skip to content

Commit 60602f2

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 ca3b132 commit 60602f2

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
@@ -833,9 +833,6 @@ ManagedValue SILGenFunction::emitExistentialErasure(
833833
[&, concreteFormalType, F](SGFContext C) -> ManagedValue {
834834
auto concreteValue = F(SGFContext());
835835
assert(concreteFormalType->isBridgeableObjectType());
836-
auto *M = SGM.M.getSwiftModule();
837-
auto conformances = M->collectExistentialConformances(
838-
concreteFormalType, anyObjectTy);
839836
return B.createInitExistentialRef(
840837
loc, SILType::getPrimitiveObjectType(anyObjectTy), concreteFormalType,
841838
concreteValue, conformances);
@@ -844,6 +841,12 @@ ManagedValue SILGenFunction::emitExistentialErasure(
844841
if (this->F.getLoweredFunctionType()->isPseudogeneric()) {
845842
if (anyObjectTy && concreteFormalType->is<ArchetypeType>()) {
846843
concreteFormalType = anyObjectTy;
844+
845+
// The original conformances are no good because they have the wrong
846+
// (pseudogeneric) subject type.
847+
auto *M = SGM.M.getSwiftModule();
848+
conformances = M->collectExistentialConformances(
849+
concreteFormalType, anyObjectTy);
847850
F = eraseToAnyObject;
848851
}
849852
}

0 commit comments

Comments
 (0)