Skip to content

Commit 08eead6

Browse files
authored
Merge pull request #61874 from slavapestov/mangle-opened-archetypes-workaround
IRGen: Workaround for mangling of opened archetypes
2 parents a415b1f + e4e2e03 commit 08eead6

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
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()

lib/IRGen/GenReflection.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,6 @@ IRGenModule::getLoweredTypeRef(SILType loweredType,
368368
auto substTy =
369369
substOpaqueTypesWithUnderlyingTypes(loweredType, genericSig);
370370
auto type = substTy.getASTType();
371-
if (substTy.hasArchetype())
372-
type = type->mapTypeOutOfContext()->getCanonicalType();
373-
374371
return getTypeRefImpl(*this, type, genericSig, role);
375372
}
376373

@@ -1324,7 +1321,7 @@ class CaptureDescriptorBuilder : public ReflectionMetadataBuilder {
13241321

13251322
// Now add typerefs of all of the captures.
13261323
for (auto CaptureType : CaptureTypes) {
1327-
addLoweredTypeRef(CaptureType, sig);
1324+
addLoweredTypeRef(CaptureType.mapTypeOutOfContext(), sig);
13281325
}
13291326

13301327
// Add the pairs that make up the generic param -> metadata source map
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)