Skip to content

Commit bf8840b

Browse files
committed
Allow the mangler to disregard inverses
1 parent d26bde7 commit bf8840b

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

include/swift/AST/ExistentialLayout.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,11 @@ struct ExistentialLayout {
125125
/// Whether this existential needs to have an extended existential shape. This
126126
/// is relevant for the mangler to mangle as a symbolic link where possible
127127
/// and for IRGen directly emitting some existentials.
128-
bool needsExtendedShape() const;
128+
///
129+
/// If 'allowInverses' is false, then regardless of if this existential layout
130+
/// has inverse requirements those will not influence the need for having a
131+
/// shape.
132+
bool needsExtendedShape(bool allowInverses = true) const;
129133

130134
private:
131135
SmallVector<ProtocolDecl *, 4> protocols;

lib/AST/ASTMangler.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,19 +1613,17 @@ void ASTMangler::appendType(Type type, GenericSignature sig,
16131613
// ExtendedExistentialTypeShapes consider existential metatypes to
16141614
// be part of the existential, so if we're symbolically referencing
16151615
// shapes, we need to handle that at this level.
1616-
if (EMT->getExistentialLayout().needsExtendedShape()) {
1616+
if (EMT->getExistentialLayout().needsExtendedShape(AllowInverses)) {
16171617
auto referent = SymbolicReferent::forExtendedExistentialTypeShape(EMT);
16181618
if (canSymbolicReference(referent)) {
16191619
appendSymbolicExtendedExistentialType(referent, EMT, sig, forDecl);
16201620
return;
16211621
}
1622-
}
16231622

1624-
if (EMT->getInstanceType()->isExistentialType() &&
1625-
EMT->hasParameterizedExistential())
16261623
appendConstrainedExistential(EMT->getInstanceType(), sig, forDecl);
1627-
else
1624+
} else {
16281625
appendType(EMT->getInstanceType(), sig, forDecl);
1626+
}
16291627

16301628
if (EMT->hasRepresentation()) {
16311629
appendOperator("Xm",
@@ -1678,8 +1676,7 @@ void ASTMangler::appendType(Type type, GenericSignature sig,
16781676
return appendType(strippedTy, sig, forDecl);
16791677
}
16801678

1681-
if (PCT->hasParameterizedExistential()
1682-
|| (PCT->hasInverse() && AllowInverses))
1679+
if (PCT->getExistentialLayout().needsExtendedShape(AllowInverses))
16831680
return appendConstrainedExistential(PCT, sig, forDecl);
16841681

16851682
// We mangle ProtocolType and ProtocolCompositionType using the
@@ -1693,7 +1690,8 @@ void ASTMangler::appendType(Type type, GenericSignature sig,
16931690

16941691
case TypeKind::Existential: {
16951692
auto *ET = cast<ExistentialType>(tybase);
1696-
if (ET->getExistentialLayout().needsExtendedShape()) {
1693+
1694+
if (ET->getExistentialLayout().needsExtendedShape(AllowInverses)) {
16971695
auto referent = SymbolicReferent::forExtendedExistentialTypeShape(ET);
16981696
if (canSymbolicReference(referent)) {
16991697
appendSymbolicExtendedExistentialType(referent, ET, sig, forDecl);
@@ -1703,6 +1701,7 @@ void ASTMangler::appendType(Type type, GenericSignature sig,
17031701
return appendConstrainedExistential(ET->getConstraintType(), sig,
17041702
forDecl);
17051703
}
1704+
17061705
return appendType(ET->getConstraintType(), sig, forDecl);
17071706
}
17081707

lib/AST/Type.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,11 @@ Type ExistentialLayout::getSuperclass() const {
435435
return Type();
436436
}
437437

438-
bool ExistentialLayout::needsExtendedShape() const {
438+
bool ExistentialLayout::needsExtendedShape(bool allowInverses) const {
439439
if (!getParameterizedProtocols().empty())
440440
return true;
441441

442-
if (hasInverses())
442+
if (allowInverses && hasInverses())
443443
return true;
444444

445445
return false;

0 commit comments

Comments
 (0)