Skip to content

Commit 0a2e53f

Browse files
committed
[RequirementMachine] Skip Sendable conformance requirements from preconcurrency
declarations in requirement inference.
1 parent 041d9de commit 0a2e53f

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/AST/RequirementMachine/RequirementLowering.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,25 @@ struct InferRequirementsWalker : public TypeWalker {
482482
}
483483

484484
Action walkToTypePost(Type ty) override {
485+
// Skip `Sendable` conformance requirements that are inferred from
486+
// `@preconcurrency` declarations.
487+
auto skipRequirement = [](Requirement req, Decl *fromDecl) {
488+
if (!fromDecl->preconcurrency())
489+
return false;
490+
491+
return (req.getKind() == RequirementKind::Conformance &&
492+
req.getSecondType()->castTo<ProtocolType>()->getDecl()
493+
->isSpecificProtocol(KnownProtocolKind::Sendable));
494+
};
495+
485496
// Infer from generic typealiases.
486497
if (auto typeAlias = dyn_cast<TypeAliasType>(ty.getPointer())) {
487498
auto decl = typeAlias->getDecl();
488499
auto subMap = typeAlias->getSubstitutionMap();
489500
for (const auto &rawReq : decl->getGenericSignature().getRequirements()) {
501+
if (skipRequirement(rawReq, decl))
502+
continue;
503+
490504
desugarRequirement(rawReq.subst(subMap), SourceLoc(), reqs, errors);
491505
}
492506

@@ -567,6 +581,9 @@ struct InferRequirementsWalker : public TypeWalker {
567581
// Handle the requirements.
568582
// FIXME: Inaccurate TypeReprs.
569583
for (const auto &rawReq : genericSig.getRequirements()) {
584+
if (skipRequirement(rawReq, decl))
585+
continue;
586+
570587
auto req = rawReq.subst(subMap);
571588
desugarRequirement(req, SourceLoc(), reqs, errors);
572589
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures 2>&1 | %FileCheck %s
2+
3+
// CHECK-LABEL: ExistingType
4+
// CHECK: Canonical generic signature: <τ_0_0 where τ_0_0 : Sendable>
5+
@preconcurrency
6+
public struct ExistingType<T: Sendable> : Sendable {}
7+
8+
// CHECK-LABEL: existingClient(arg:)
9+
// CHECK: Canonical generic signature: <τ_0_0>
10+
public func existingClient<T>(arg: T.Type) -> ExistingType<T>? { nil }
11+
12+
public typealias Alias = ExistingType
13+
14+
// CHECK-LABEL: existingClient2(arg:)
15+
// CHECK: Canonical generic signature: <τ_0_0>
16+
public func existingClient2<T>(arg: T.Type) -> Alias<T>? { nil }

0 commit comments

Comments
 (0)