Skip to content

Commit c7dcd21

Browse files
committed
Fix a latent bug in propagateSoleConformingType: check reabstraction.
This code was force casting the address of the opened existential to the lowered SIL type of the known conformance. This is superficially incorrect because values are stored in existentials with maximal reabstraction. Bail on any concrete types that require reabstraction. I don't think we will hit this currently because there is an earlier check that prevents optimizing a conformance on a generic types. In theory someone could add that functionality later for internal generic types with a single instantiation. More importantly, we don't want anyone copying this logic and assuming it's generally correct.
1 parent 118a725 commit c7dcd21

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,14 @@ SILCombiner::buildConcreteOpenedExistentialInfoFromSoleConformingType(
693693
return COAI;
694694
}
695695
if (auto *OEA = dyn_cast<OpenExistentialAddrInst>(OAI.OpenedArchetypeValue)) {
696+
// Bail if ConcreteSILType is not the same SILType as the type stored in the
697+
// existential after maximal reabstraction.
698+
auto archetype = OpenedArchetypeType::getAny(SoleCEI.ExistentialType);
699+
Lowering::AbstractionPattern abstractionPattern(archetype);
700+
auto abstractTy = M.Types.getLoweredType(abstractionPattern, ConcreteType);
701+
if (abstractTy != concreteSILType)
702+
return None;
703+
696704
SoleCEI.ConcreteValue =
697705
Builder.createUncheckedAddrCast(
698706
OEA->getLoc(), OEA, concreteSILType.getAddressType());

0 commit comments

Comments
 (0)