Skip to content

Commit 22ec081

Browse files
committed
[AST/Sema] Add a diagnostic group ExplicitSendable to replace -require-explicit-sendable
Always run explicit `Sendable` checks on public types and suppress warning printing by default instead of using a special compiler argument. Resolves: rdar://162394810
1 parent 5eb4ab2 commit 22ec081

File tree

6 files changed

+40
-8
lines changed

6 files changed

+40
-8
lines changed

include/swift/AST/DiagnosticGroups.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ GROUP(TemporaryPointers,none,"temporary-pointers")
8787
GROUP(TrailingClosureMatching,none,"trailing-closure-matching")
8888
GROUP(UnknownWarningGroup,none,"unknown-warning-group")
8989
GROUP(WeakMutability,none,"weak-mutability")
90+
GROUP(ExplicitSendable,DefaultIgnoreWarnings,"explicit-sendable-annotations")
9091

9192
GROUP_LINK(PerformanceHints,ExistentialType)
9293
GROUP_LINK(PerformanceHints,ReturnTypeImplicitCopy)

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2857,9 +2857,9 @@ WARNING(remove_public_import,none,
28572857
WARNING(remove_package_import,none,
28582858
"package import of %0 was not used in package declarations",
28592859
(Identifier))
2860-
WARNING(public_decl_needs_sendable,none,
2861-
"public %kind0 does not specify whether it is 'Sendable' or not",
2862-
(const ValueDecl *))
2860+
GROUPED_WARNING(public_decl_needs_sendable,ExplicitSendable,none,
2861+
"public %kind0 does not specify whether it is 'Sendable' or not",
2862+
(const ValueDecl *))
28632863
NOTE(explicit_disable_sendable,none,
28642864
"make %kind0 explicitly non-Sendable to suppress this warning",
28652865
(const ValueDecl *))

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "swift/AST/ASTWalker.h"
2626
#include "swift/AST/Concurrency.h"
2727
#include "swift/AST/ConformanceLookup.h"
28+
#include "swift/AST/DiagnosticGroups.h"
2829
#include "swift/AST/DistributedDecl.h"
2930
#include "swift/AST/ExistentialLayout.h"
3031
#include "swift/AST/GenericEnvironment.h"
@@ -1376,7 +1377,7 @@ static bool checkSendableInstanceStorage(
13761377
void swift::diagnoseMissingExplicitSendable(NominalTypeDecl *nominal) {
13771378
// Only diagnose when explicitly requested.
13781379
ASTContext &ctx = nominal->getASTContext();
1379-
if (!ctx.LangOpts.RequireExplicitSendable)
1380+
if (ctx.Diags.isIgnoredDiagnosticGroupTree(DiagGroupID::ExplicitSendable))
13801381
return;
13811382

13821383
if (nominal->getLoc().isInvalid())

test/Concurrency/objc_require_explicit_sendable.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-sil -o /dev/null -I %S/Inputs/custom-modules %s -verify -parse-as-library -require-explicit-sendable
2-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-sil -o /dev/null -I %S/Inputs/custom-modules %s -verify -parse-as-library -require-explicit-sendable -strict-concurrency=targeted
3-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-sil -o /dev/null -I %S/Inputs/custom-modules %s -verify -parse-as-library -require-explicit-sendable -strict-concurrency=complete
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-sil -o /dev/null -I %S/Inputs/custom-modules %s -verify -parse-as-library -Wwarning ExplicitSendable
2+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-sil -o /dev/null -I %S/Inputs/custom-modules %s -verify -parse-as-library -Wwarning ExplicitSendable -strict-concurrency=targeted
3+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-sil -o /dev/null -I %S/Inputs/custom-modules %s -verify -parse-as-library -Wwarning ExplicitSendable -strict-concurrency=complete
44

55
// REQUIRES: objc_interop
66
// REQUIRES: concurrency

test/Concurrency/require-explicit-sendable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -require-explicit-sendable -strict-concurrency=complete %s -emit-sil -o /dev/null -verify
1+
// RUN: %target-swift-frontend -Wwarning ExplicitSendable -strict-concurrency=complete %s -emit-sil -o /dev/null -verify
22

33

44
public protocol P { }
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Explicit Sendable annotations on public type declarations
2+
3+
If a public type doesn't have an explicit Sendable or non-Sendable annotation it is sometimes hard to discern whether that is intentional or not, especially if a type could be Sendable.
4+
5+
## Overview
6+
7+
The Swift compiler would emit a warning if a public type has none of the following:
8+
9+
- A conformance to `Sendable` protocol;
10+
- An unavailable conformance to `Sendable` protocol;
11+
- `~Sendable` conformance to suppress the inference.
12+
13+
Let's consider a simple public type without any Senable annotations:
14+
15+
```
16+
public struct S {
17+
let x: Int
18+
}
19+
```
20+
21+
When compiling with `-Wwarning ExplicitSendable` the following warning is going to be produced by the Swift compiler:
22+
23+
```
24+
1 | public struct S {
25+
| |- warning: public struct 'S' does not specify whether it is 'Sendable' or not [#ExplicitSendable]
26+
| |- note: consider making struct 'S' conform to the 'Sendable' protocol
27+
| `- note: make struct 'S' explicitly non-Sendable to suppress this warning
28+
2 | let x: Int
29+
3 | }
30+
```

0 commit comments

Comments
 (0)