Skip to content

Commit 793b46f

Browse files
committed
ASTMangler: sink fix to be more safe
My previous fix in `6f6a46f` was the correct fix in theory, but in practice it could accidentally change the mangling of something I haven't considered, which would break ABI with Swift 6.0 I've narrowed that fix here to only affect dependent conformances specifically for Copyable/Escapable. The existing code in `appendDependentProtocolConformance` would always reach a trap because we're mangling a conformance path that ends with Copyable/Escapable. We can assume no such symbol has been successfully been mangled before, thanks to the pre-existing skip in `conformanceRequirementIndex`, so there's no risk of ABI change. rdar://135310019
1 parent db7a030 commit 793b46f

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/AST/ASTMangler.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4192,18 +4192,26 @@ void ASTMangler::appendAnyProtocolConformance(
41924192
conformance.getRequirement()->isMarkerProtocol())
41934193
return;
41944194

4195-
// While all invertible protocols are marker protocols, do not mangle them for
4196-
// compatability reasons. See equivalent hack in `conformanceRequirementIndex`
4197-
// where only invertible protocols are unconditionally skipped.
4198-
if (conformance.getRequirement()->getInvertibleProtocolKind())
4199-
return;
4195+
// While all invertible protocols are marker protocols, do not mangle them
4196+
// as a dependent conformance. See `conformanceRequirementIndex` which skips
4197+
// these, too. In theory, invertible conformances should never be mangled,
4198+
// but we *might* have let that slip by for the other cases below, so the
4199+
// early-exits are highly conservative.
4200+
const bool forInvertible =
4201+
conformance.getRequirement()->getInvertibleProtocolKind().has_value();
42004202

42014203
if (conformingType->isTypeParameter()) {
42024204
assert(genericSig && "Need a generic signature to resolve conformance");
4205+
if (forInvertible)
4206+
return;
4207+
42034208
auto path = genericSig->getConformancePath(conformingType,
42044209
conformance.getAbstract());
42054210
appendDependentProtocolConformance(path, genericSig);
42064211
} else if (auto opaqueType = conformingType->getAs<OpaqueTypeArchetypeType>()) {
4212+
if (forInvertible)
4213+
return;
4214+
42074215
GenericSignature opaqueSignature =
42084216
opaqueType->getDecl()->getOpaqueInterfaceGenericSignature();
42094217
ConformancePath conformancePath =

0 commit comments

Comments
 (0)