Skip to content

Commit e4e2e03

Browse files
committed
IRGen: Workaround for inadvertent mangling of opened archetypes
1 parent 212c9ba commit e4e2e03

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/IRGen/GenHeap.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,6 +1528,19 @@ class FixedBoxTypeInfoBase : public BoxTypeInfo {
15281528
boxedInterfaceType = boxedType.mapTypeOutOfContext();
15291529
}
15301530

1531+
{
1532+
// FIXME: This seems wrong. We used to just mangle opened archetypes as
1533+
// their interface type. Let's make that explicit now.
1534+
auto astType = boxedInterfaceType.getASTType();
1535+
astType = astType.transformRec([](Type t) -> Optional<Type> {
1536+
if (auto *openedExistential = t->getAs<OpenedArchetypeType>())
1537+
return openedExistential->getInterfaceType();
1538+
return None;
1539+
})->getCanonicalType();
1540+
boxedInterfaceType = SILType::getPrimitiveType(
1541+
astType, boxedInterfaceType.getCategory());
1542+
}
1543+
15311544
auto boxDescriptor = IGF.IGM.getAddrOfBoxDescriptor(
15321545
boxedInterfaceType,
15331546
env ? env->getGenericSignature().getCanonicalSignature()
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-swift-frontend -emit-ir %s -disable-availability-checking
2+
3+
public protocol P {}
4+
5+
struct S<T>: P {
6+
var x: Any
7+
init() { fatalError() }
8+
}
9+
10+
public func mangleArchetype(_ p: any P) -> any P {
11+
p.open
12+
}
13+
14+
extension P {
15+
var open: some P {
16+
S<Self>()
17+
}
18+
}

0 commit comments

Comments
 (0)