Skip to content

Commit 389c240

Browse files
committed
[AST] Mark Sendable as a repressible protocol
This allows to spell `~Sendable` to suppress the conformance inference on types when `TildeSendable` flag is enabled.
1 parent 1ac87e7 commit 389c240

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8943,6 +8943,13 @@ ERROR(attr_inline_always_on_accessor,none,
89438943
"'@inline(always)' on class variable accessors whose variable declaration"
89448944
" is not final are not allowed", ())
89458945

8946+
//===----------------------------------------------------------------------===//
8947+
// MARK: `~Sendable`
8948+
//===----------------------------------------------------------------------===//
8949+
ERROR(tilde_sendable_requires_feature_flag,none,
8950+
"'~Sendable' requires -enable-experimental-feature TildeSendable",
8951+
())
8952+
89468953
//===----------------------------------------------------------------------===//
89478954
// MARK: Swift Performance hints
89488955
//===----------------------------------------------------------------------===//

include/swift/AST/KnownProtocols.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ PROTOCOL(CodingKey)
107107
PROTOCOL(Encodable)
108108
PROTOCOL(Decodable)
109109

110-
PROTOCOL(Sendable)
110+
REPRESSIBLE_PROTOCOL(Sendable)
111111
PROTOCOL(SendableMetatype)
112112
PROTOCOL(UnsafeSendable)
113113

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7499,6 +7499,10 @@ ProtocolConformance *swift::deriveImplicitSendableConformance(
74997499
if (isa<ProtocolDecl>(nominal))
75007500
return nullptr;
75017501

7502+
// An explicit use `~Sendable` suppresses the conformance.
7503+
if (nominal->suppressesConformance(KnownProtocolKind::Sendable))
7504+
return nullptr;
7505+
75027506
// Actor types are always Sendable; they don't get it via this path.
75037507
auto classDecl = dyn_cast<ClassDecl>(nominal);
75047508
if (classDecl && classDecl->isActor())

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ class CheckRepressions {
123123
ctx.getProtocol(*kp));
124124
return Type();
125125
}
126+
127+
if (rpk == RepressibleProtocolKind::Sendable) {
128+
if (!ctx.LangOpts.hasFeature(Feature::TildeSendable)) {
129+
diagnoseInvalid(repr, repr.getLoc(),
130+
diag::tilde_sendable_requires_feature_flag);
131+
return Type();
132+
}
133+
}
134+
126135
if (auto *extension = dyn_cast<const ExtensionDecl *>(decl)) {
127136
diagnoseInvalid(repr, extension,
128137
diag::suppress_inferrable_protocol_extension,

0 commit comments

Comments
 (0)