Skip to content

Commit a2c1548

Browse files
committed
IRGen: Fix type conversion of protocol compositions containing a generic superclass constraint
Do the same thing we do for nominal types, where if the type contains an archetype, just mangle the unbound generic form, since the name is just for documentation purposes in LLVM IR dumps and does not have to be unique. This is tested as part of an upcoming patch.
1 parent cb95ee3 commit a2c1548

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/IRGen/GenType.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,8 +1531,9 @@ llvm::StructType *IRGenModule::createNominalType(CanType type) {
15311531
assert(type.getNominalOrBoundGenericNominal());
15321532

15331533
// We share type infos for different instantiations of a generic type
1534-
// when the archetypes have the same exemplars. Mangling the archetypes
1535-
// in this case can be very misleading, so we just mangle the base name.
1534+
// when the archetypes have the same exemplars. We cannot mangle
1535+
// archetypes, and the mangling does not have to be unique, so we just
1536+
// mangle the unbound generic form of the type.
15361537
if (type->hasArchetype())
15371538
type = type.getNominalOrBoundGenericNominal()->getDeclaredType()
15381539
->getCanonicalType();

lib/IRGen/IRGenMangler.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,18 @@ mangleProtocolForLLVMTypeName(ProtocolCompositionType *type) {
9494
appendOperator("_");
9595
}
9696
if (layout.superclass) {
97-
appendType(layout.superclass);
97+
auto superclassTy = layout.superclass;
98+
99+
// We share type infos for different instantiations of a generic type
100+
// when the archetypes have the same exemplars. We cannot mangle
101+
// archetypes, and the mangling does not have to be unique, so we just
102+
// mangle the unbound generic form of the type.
103+
if (superclassTy->hasArchetype()) {
104+
superclassTy = superclassTy->getClassOrBoundGenericClass()
105+
->getDeclaredType();
106+
}
107+
108+
appendType(CanType(superclassTy));
98109
appendOperator("Xc");
99110
} else if (layout.getLayoutConstraint()) {
100111
appendOperator("Xl");

0 commit comments

Comments
 (0)