Skip to content

Commit f2bc548

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

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
@@ -951,6 +951,67 @@ Type TypeBase::stripConcurrency(bool recurse, bool dropGlobalActor) {
951951
return newFnType;
952952
}
953953

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

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)