mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge pull request #85319 from xedin/rdar-162394810
[AST/Sema] Add a diagnostic group `ExplicitSendable` to replace `-require-explicit-sendable`
This commit is contained in:
@@ -87,6 +87,7 @@ GROUP(TemporaryPointers,none,"temporary-pointers")
|
|||||||
GROUP(TrailingClosureMatching,none,"trailing-closure-matching")
|
GROUP(TrailingClosureMatching,none,"trailing-closure-matching")
|
||||||
GROUP(UnknownWarningGroup,none,"unknown-warning-group")
|
GROUP(UnknownWarningGroup,none,"unknown-warning-group")
|
||||||
GROUP(WeakMutability,none,"weak-mutability")
|
GROUP(WeakMutability,none,"weak-mutability")
|
||||||
|
GROUP(ExplicitSendable,DefaultIgnoreWarnings,"explicit-sendable-annotations")
|
||||||
|
|
||||||
GROUP_LINK(PerformanceHints,ExistentialType)
|
GROUP_LINK(PerformanceHints,ExistentialType)
|
||||||
GROUP_LINK(PerformanceHints,ReturnTypeImplicitCopy)
|
GROUP_LINK(PerformanceHints,ReturnTypeImplicitCopy)
|
||||||
|
|||||||
@@ -2857,7 +2857,7 @@ WARNING(remove_public_import,none,
|
|||||||
WARNING(remove_package_import,none,
|
WARNING(remove_package_import,none,
|
||||||
"package import of %0 was not used in package declarations",
|
"package import of %0 was not used in package declarations",
|
||||||
(Identifier))
|
(Identifier))
|
||||||
WARNING(public_decl_needs_sendable,none,
|
GROUPED_WARNING(public_decl_needs_sendable,ExplicitSendable,none,
|
||||||
"public %kind0 does not specify whether it is 'Sendable' or not",
|
"public %kind0 does not specify whether it is 'Sendable' or not",
|
||||||
(const ValueDecl *))
|
(const ValueDecl *))
|
||||||
NOTE(explicit_disable_sendable,none,
|
NOTE(explicit_disable_sendable,none,
|
||||||
|
|||||||
@@ -245,9 +245,6 @@ namespace swift {
|
|||||||
// Availability macros definitions to be expanded at parsing.
|
// Availability macros definitions to be expanded at parsing.
|
||||||
SmallVector<std::string, 4> AvailabilityMacros;
|
SmallVector<std::string, 4> AvailabilityMacros;
|
||||||
|
|
||||||
/// Require public declarations to declare that they are Sendable (or not).
|
|
||||||
bool RequireExplicitSendable = false;
|
|
||||||
|
|
||||||
/// Detect and automatically import modules' cross-import overlays.
|
/// Detect and automatically import modules' cross-import overlays.
|
||||||
bool EnableCrossImportOverlays = false;
|
bool EnableCrossImportOverlays = false;
|
||||||
|
|
||||||
|
|||||||
@@ -1272,7 +1272,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
|||||||
if (Args.getLastArg(OPT_debug_cycles))
|
if (Args.getLastArg(OPT_debug_cycles))
|
||||||
Opts.DebugDumpCycles = true;
|
Opts.DebugDumpCycles = true;
|
||||||
|
|
||||||
Opts.RequireExplicitSendable |= Args.hasArg(OPT_require_explicit_sendable);
|
|
||||||
for (const Arg *A : Args.filtered(OPT_define_availability)) {
|
for (const Arg *A : Args.filtered(OPT_define_availability)) {
|
||||||
Opts.AvailabilityMacros.push_back(A->getValue());
|
Opts.AvailabilityMacros.push_back(A->getValue());
|
||||||
}
|
}
|
||||||
@@ -2724,6 +2723,14 @@ static bool ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
|
|||||||
}
|
}
|
||||||
}());
|
}());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// `-require-explicit-sendable` is an alias to `-Wwarning ExplicitSendable`.
|
||||||
|
if (Args.hasArg(OPT_require_explicit_sendable) &&
|
||||||
|
!Args.hasArg(OPT_suppress_warnings)) {
|
||||||
|
Opts.WarningsAsErrorsRules.push_back(WarningAsErrorRule(
|
||||||
|
WarningAsErrorRule::Action::Disable, "ExplicitSendable"));
|
||||||
|
}
|
||||||
|
|
||||||
if (Args.hasArg(OPT_debug_diagnostic_names)) {
|
if (Args.hasArg(OPT_debug_diagnostic_names)) {
|
||||||
Opts.PrintDiagnosticNames = PrintDiagnosticNamesMode::Identifier;
|
Opts.PrintDiagnosticNames = PrintDiagnosticNamesMode::Identifier;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "swift/AST/ASTWalker.h"
|
#include "swift/AST/ASTWalker.h"
|
||||||
#include "swift/AST/Concurrency.h"
|
#include "swift/AST/Concurrency.h"
|
||||||
#include "swift/AST/ConformanceLookup.h"
|
#include "swift/AST/ConformanceLookup.h"
|
||||||
|
#include "swift/AST/DiagnosticGroups.h"
|
||||||
#include "swift/AST/DistributedDecl.h"
|
#include "swift/AST/DistributedDecl.h"
|
||||||
#include "swift/AST/ExistentialLayout.h"
|
#include "swift/AST/ExistentialLayout.h"
|
||||||
#include "swift/AST/GenericEnvironment.h"
|
#include "swift/AST/GenericEnvironment.h"
|
||||||
@@ -1376,7 +1377,7 @@ static bool checkSendableInstanceStorage(
|
|||||||
void swift::diagnoseMissingExplicitSendable(NominalTypeDecl *nominal) {
|
void swift::diagnoseMissingExplicitSendable(NominalTypeDecl *nominal) {
|
||||||
// Only diagnose when explicitly requested.
|
// Only diagnose when explicitly requested.
|
||||||
ASTContext &ctx = nominal->getASTContext();
|
ASTContext &ctx = nominal->getASTContext();
|
||||||
if (!ctx.LangOpts.RequireExplicitSendable)
|
if (ctx.Diags.isIgnoredDiagnosticGroupTree(DiagGroupID::ExplicitSendable))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (nominal->getLoc().isInvalid())
|
if (nominal->getLoc().isInvalid())
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
// 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
|
||||||
|
// 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
|
||||||
|
// 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
|
||||||
// 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
|
// 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
|
||||||
// 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
|
// 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
|
||||||
// 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
|
// 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,6 +1,6 @@
|
|||||||
|
// RUN: %target-swift-frontend -Wwarning ExplicitSendable -strict-concurrency=complete %s -emit-sil -o /dev/null -verify
|
||||||
// RUN: %target-swift-frontend -require-explicit-sendable -strict-concurrency=complete %s -emit-sil -o /dev/null -verify
|
// RUN: %target-swift-frontend -require-explicit-sendable -strict-concurrency=complete %s -emit-sil -o /dev/null -verify
|
||||||
|
|
||||||
|
|
||||||
public protocol P { }
|
public protocol P { }
|
||||||
|
|
||||||
// expected-note@+2{{consider making struct 'S1' conform to the 'Sendable' protocol}}{{18-18=: Sendable}}
|
// expected-note@+2{{consider making struct 'S1' conform to the 'Sendable' protocol}}{{18-18=: Sendable}}
|
||||||
|
|||||||
30
userdocs/diagnostics/explicit-sendable-annotations.md
Normal file
30
userdocs/diagnostics/explicit-sendable-annotations.md
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
# Explicit Sendable annotations on public type declarations
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
The Swift compiler would emit a warning if a public type has none of the following:
|
||||||
|
|
||||||
|
- A conformance to `Sendable` protocol;
|
||||||
|
- An unavailable conformance to `Sendable` protocol;
|
||||||
|
- `~Sendable` conformance to suppress the inference.
|
||||||
|
|
||||||
|
Let's consider a simple public type without any Senable annotations:
|
||||||
|
|
||||||
|
```
|
||||||
|
public struct S {
|
||||||
|
let x: Int
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
When compiling with `-Wwarning ExplicitSendable` the following warning is going to be produced by the Swift compiler:
|
||||||
|
|
||||||
|
```
|
||||||
|
1 | public struct S {
|
||||||
|
| |- warning: public struct 'S' does not specify whether it is 'Sendable' or not [#ExplicitSendable]
|
||||||
|
| |- note: consider making struct 'S' conform to the 'Sendable' protocol
|
||||||
|
| `- note: make struct 'S' explicitly non-Sendable to suppress this warning
|
||||||
|
2 | let x: Int
|
||||||
|
3 | }
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user