Skip to content

Commit fb37355

Browse files
committed
Strip Sendable from existential types in @preconcurrency mangling.
Fixes rdar://91966505.
1 parent c55a396 commit fb37355

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

lib/AST/Type.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,67 @@ Type TypeBase::stripConcurrency(bool recurse, bool dropGlobalActor) {
960960
return newFnType;
961961
}
962962

963+
if (auto existentialType = getAs<ExistentialType>()) {
964+
auto newConstraintType = existentialType->getConstraintType()
965+
->stripConcurrency(recurse, dropGlobalActor);
966+
if (newConstraintType.getPointer() ==
967+
existentialType->getConstraintType().getPointer())
968+
return Type(this);
969+
970+
return ExistentialType::get(newConstraintType);
971+
}
972+
973+
if (auto protocolType = getAs<ProtocolType>()) {
974+
if (protocolType->getDecl()->isSpecificProtocol(
975+
KnownProtocolKind::Sendable))
976+
return ProtocolCompositionType::get(getASTContext(), { }, false);
977+
978+
return Type(this);
979+
}
980+
981+
if (auto protocolCompositionType = getAs<ProtocolCompositionType>()) {
982+
SmallVector<Type, 4> newMembers;
983+
auto members = protocolCompositionType->getMembers();
984+
for (unsigned i : indices(members)) {
985+
auto memberType = members[i];
986+
auto newMemberType =
987+
memberType->stripConcurrency(recurse, dropGlobalActor);
988+
if (!newMembers.empty()) {
989+
newMembers.push_back(newMemberType);
990+
continue;
991+
}
992+
993+
if (memberType.getPointer() != newMemberType.getPointer()) {
994+
newMembers.append(members.begin(), members.begin() + i);
995+
newMembers.push_back(newMemberType);
996+
continue;
997+
}
998+
}
999+
1000+
if (!newMembers.empty()) {
1001+
return ProtocolCompositionType::get(
1002+
getASTContext(), newMembers,
1003+
protocolCompositionType->hasExplicitAnyObject());
1004+
}
1005+
1006+
return Type(this);
1007+
}
1008+
1009+
if (auto existentialMetatype = getAs<ExistentialMetatypeType>()) {
1010+
auto instanceType = existentialMetatype->getExistentialInstanceType();
1011+
auto newInstanceType =
1012+
instanceType->stripConcurrency(recurse, dropGlobalActor);
1013+
if (instanceType.getPointer() != newInstanceType.getPointer()) {
1014+
Optional<MetatypeRepresentation> repr;
1015+
if (existentialMetatype->hasRepresentation())
1016+
repr = existentialMetatype->getRepresentation();
1017+
return ExistentialMetatypeType::get(
1018+
newInstanceType, repr, getASTContext());
1019+
}
1020+
1021+
return Type(this);
1022+
}
1023+
9631024
return Type(this);
9641025
}
9651026

test/SILGen/mangling_predates_concurrency.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,13 @@
77
public func excitingFunction<T: Sendable>(value: T, body: (@Sendable () -> Void)?) -> (@MainActor () -> Void) {
88
{ }
99
}
10+
11+
public protocol P { }
12+
13+
// CHECK: sil [ossa] @$s29mangling_predates_concurrency13lotsOfChangesyyXlSgyp_AA1P_pypXpAaD_XlXptF
14+
@preconcurrency public func lotsOfChanges(
15+
_: Sendable, _: P & Sendable, _: Sendable.Type,
16+
_: (AnyObject & Sendable & P).Type
17+
) -> (AnyObject & Sendable)? {
18+
nil
19+
}

0 commit comments

Comments
 (0)