IRGen: Workaround for inadvertent mangling of opened archetypes

This commit is contained in:
Slava Pestov
2022-11-02 11:44:01 -04:00
parent 212c9ba04d
commit e4e2e034c0
2 changed files with 31 additions and 0 deletions

View File

@@ -1528,6 +1528,19 @@ public:
boxedInterfaceType = boxedType.mapTypeOutOfContext();
}
{
// FIXME: This seems wrong. We used to just mangle opened archetypes as
// their interface type. Let's make that explicit now.
auto astType = boxedInterfaceType.getASTType();
astType = astType.transformRec([](Type t) -> Optional<Type> {
if (auto *openedExistential = t->getAs<OpenedArchetypeType>())
return openedExistential->getInterfaceType();
return None;
})->getCanonicalType();
boxedInterfaceType = SILType::getPrimitiveType(
astType, boxedInterfaceType.getCategory());
}
auto boxDescriptor = IGF.IGM.getAddrOfBoxDescriptor(
boxedInterfaceType,
env ? env->getGenericSignature().getCanonicalSignature()

View File

@@ -0,0 +1,18 @@
// RUN: %target-swift-frontend -emit-ir %s -disable-availability-checking
public protocol P {}
struct S<T>: P {
var x: Any
init() { fatalError() }
}
public func mangleArchetype(_ p: any P) -> any P {
p.open
}
extension P {
var open: some P {
S<Self>()
}
}