Skip to content

Commit 831043c

Browse files
committed
IRGen: Fix crash trying to emit capture descriptor involving element archetype
We could encode local archetypes in reflection info by performing the local archetype transform, to get an extended generic signature together with substitutions for the added generic parameters. However, for now, let's just not crash. This generalizes an earlier hack for opened existential archetypes. Instead of replacing them with nonsensical type parameters though, let's just not emit the whole descriptor. - Fixes swiftlang#83539. - Fixes rdar://157554723.
1 parent ec39484 commit 831043c

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

lib/IRGen/GenHeap.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,24 +1576,6 @@ class FixedBoxTypeInfoBase : public BoxTypeInfo {
15761576
boxedInterfaceType = boxedType.mapTypeOutOfContext();
15771577
}
15781578

1579-
{
1580-
// FIXME: This seems wrong. We used to just mangle opened archetypes as
1581-
// their interface type. Let's make that explicit now.
1582-
auto astType = boxedInterfaceType.getASTType();
1583-
astType =
1584-
astType
1585-
.transformRec([](Type t) -> std::optional<Type> {
1586-
if (auto *openedExistential = t->getAs<ExistentialArchetypeType>()) {
1587-
auto &ctx = openedExistential->getASTContext();
1588-
return ctx.TheSelfType;
1589-
}
1590-
return std::nullopt;
1591-
})
1592-
->getCanonicalType();
1593-
boxedInterfaceType = SILType::getPrimitiveType(
1594-
astType, boxedInterfaceType.getCategory());
1595-
}
1596-
15971579
auto boxDescriptor = IGF.IGM.getAddrOfBoxDescriptor(
15981580
boxedInterfaceType,
15991581
env ? env->getGenericSignature().getCanonicalSignature()

lib/IRGen/GenReflection.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,6 +1693,9 @@ llvm::Constant *IRGenModule::getAddrOfFieldName(StringRef Name) {
16931693
llvm::Constant *
16941694
IRGenModule::getAddrOfBoxDescriptor(SILType BoxedType,
16951695
CanGenericSignature genericSig) {
1696+
if (BoxedType.hasLocalArchetype())
1697+
return llvm::Constant::getNullValue(CaptureDescriptorPtrTy);
1698+
16961699
if (IRGen.Opts.ReflectionMetadata != ReflectionMetadataMode::Runtime)
16971700
return llvm::Constant::getNullValue(CaptureDescriptorPtrTy);
16981701

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-swift-frontend -emit-ir %s -target %target-swift-5.9-abi-triple
2+
3+
public protocol P {}
4+
5+
public struct G<T>: P {
6+
let s1: String
7+
let s2: String
8+
}
9+
10+
public func f<each T>(t: repeat G<each T>) {
11+
var ts: [any P] = []
12+
for x in repeat each t {
13+
ts.append(x)
14+
}
15+
}

0 commit comments

Comments
 (0)