Skip to content

Commit d501019

Browse files
committed
Rename the -strict-concurrency= options to be more descriptive.
The three options are now: * `explicit`: Enforce Sendable constraints where it has been explicitly adopted and perform actor-isolation checking wherever code has adopted concurrency. (This is the default) * `targeted`: Enforce Sendable constraints and perform actor-isolation checking wherever code has adopted concurrency, including code that has explicitly adopted Sendable. * `complete`: Enforce Sendable constraints and actor-isolation checking throughout the entire module. (cherry picked from commit 4116d7a)
1 parent f18873c commit d501019

17 files changed

+45
-43
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,16 @@ namespace swift {
6060

6161
/// Describes how strict concurrency checking should be.
6262
enum class StrictConcurrency {
63-
/// Turns off strict checking, which disables (e.g.) Sendable checking in
64-
/// most cases.
65-
Off,
66-
/// Enables concurrency checking in a limited manner that is intended to
67-
/// only affect code that has already adopted the concurrency model.
68-
Limited,
69-
/// Enables strict concurrency checking throughout the entire model,
70-
/// providing an approximation of the fully-checked model.
71-
On
63+
/// Enforce Sendable constraints where it has been explicitly adopted and
64+
/// perform actor-isolation checking wherever code has adopted concurrency.
65+
Explicit,
66+
/// Enforce Sendable constraints and perform actor-isolation checking
67+
/// wherever code has adopted concurrency, including code that has
68+
/// explicitly adopted Sendable.
69+
Targeted,
70+
/// Enforce Sendable constraints and actor-isolation checking throughout
71+
/// the entire module.
72+
Complete,
7273
};
7374

7475
/// Access or distribution level of a library.
@@ -324,7 +325,7 @@ namespace swift {
324325
bool UseMalloc = false;
325326

326327
/// Specifies how strict concurrency checking will be.
327-
StrictConcurrency StrictConcurrencyLevel = StrictConcurrency::Limited;
328+
StrictConcurrency StrictConcurrencyLevel = StrictConcurrency::Targeted;
328329

329330
/// Enable experimental #assert feature.
330331
bool EnableExperimentalStaticAssert = false;

include/swift/Option/Options.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -706,9 +706,9 @@ def warn_concurrency : Flag<["-"], "warn-concurrency">,
706706
def strict_concurrency : Joined<["-"], "strict-concurrency=">,
707707
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
708708
HelpText<"Specify the how strict concurrency checking will be. The value may "
709-
"be 'off' (most 'Sendable' checking is disabled), "
710-
"'limited' ('Sendable' checking is enabled in code that uses the "
711-
"concurrency model, or 'on' ('Sendable' and other checking is "
709+
"be 'explicit' (most 'Sendable' checking is disabled), "
710+
"'targeted' ('Sendable' checking is enabled in code that uses the "
711+
"concurrency model, or 'complete' ('Sendable' and other checking is "
712712
"enabled for all code in the module)">;
713713

714714
def Rpass_EQ : Joined<["-"], "Rpass=">,

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9164,7 +9164,7 @@ ActorIsolation swift::getActorIsolationOfContext(DeclContext *dc) {
91649164
if (auto *tld = dyn_cast<TopLevelCodeDecl>(dc)) {
91659165
if (dc->isAsyncContext() ||
91669166
dc->getASTContext().LangOpts.StrictConcurrencyLevel
9167-
>= StrictConcurrency::On) {
9167+
>= StrictConcurrency::Complete) {
91689168
if (Type mainActor = dc->getASTContext().getMainActorType())
91699169
return ActorIsolation::forGlobalActor(
91709170
mainActor,

lib/Frontend/CompilerInvocation.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -686,12 +686,12 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
686686

687687
// Swift 6+ uses the strictest concurrency level.
688688
if (Opts.isSwiftVersionAtLeast(6)) {
689-
Opts.StrictConcurrencyLevel = StrictConcurrency::On;
689+
Opts.StrictConcurrencyLevel = StrictConcurrency::Complete;
690690
} else if (const Arg *A = Args.getLastArg(OPT_strict_concurrency)) {
691691
auto value = llvm::StringSwitch<Optional<StrictConcurrency>>(A->getValue())
692-
.Case("off", StrictConcurrency::Off)
693-
.Case("limited", StrictConcurrency::Limited)
694-
.Case("on", StrictConcurrency::On)
692+
.Case("explicit", StrictConcurrency::Explicit)
693+
.Case("targeted", StrictConcurrency::Targeted)
694+
.Case("complete", StrictConcurrency::Complete)
695695
.Default(None);
696696

697697
if (value)
@@ -701,10 +701,10 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
701701
A->getAsString(Args), A->getValue());
702702

703703
} else if (Args.hasArg(OPT_warn_concurrency)) {
704-
Opts.StrictConcurrencyLevel = StrictConcurrency::On;
704+
Opts.StrictConcurrencyLevel = StrictConcurrency::Complete;
705705
} else {
706706
// Default to "limited" checking in Swift 5.x.
707-
Opts.StrictConcurrencyLevel = StrictConcurrency::Limited;
707+
Opts.StrictConcurrencyLevel = StrictConcurrency::Targeted;
708708
}
709709

710710
Opts.WarnImplicitOverrides =

lib/IDE/CompletionLookup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ void CompletionLookup::analyzeActorIsolation(
768768
}
769769

770770
// If the reference is 'async', all types must be 'Sendable'.
771-
if (Ctx.LangOpts.StrictConcurrencyLevel >= StrictConcurrency::On &&
771+
if (Ctx.LangOpts.StrictConcurrencyLevel >= StrictConcurrency::Complete &&
772772
implicitlyAsync && T) {
773773
auto *M = CurrDeclContext->getParentModule();
774774
if (isa<VarDecl>(VD)) {

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ GlobalActorAttributeRequest::evaluate(
347347
if (var->isTopLevelGlobal() &&
348348
(var->getDeclContext()->isAsyncContext() ||
349349
var->getASTContext().LangOpts.StrictConcurrencyLevel >=
350-
StrictConcurrency::On)) {
350+
StrictConcurrency::Complete)) {
351351
var->diagnose(diag::global_actor_top_level_var)
352352
.highlight(globalActorAttr->getRangeWithAt());
353353
return None;
@@ -771,23 +771,23 @@ DiagnosticBehavior SendableCheckContext::defaultDiagnosticBehavior() const {
771771
DiagnosticBehavior
772772
SendableCheckContext::implicitSendableDiagnosticBehavior() const {
773773
switch (fromDC->getASTContext().LangOpts.StrictConcurrencyLevel) {
774-
case StrictConcurrency::Limited:
774+
case StrictConcurrency::Targeted:
775775
// Limited checking only diagnoses implicit Sendable within contexts that
776776
// have adopted concurrency.
777777
if (shouldDiagnoseExistingDataRaces(fromDC))
778778
return DiagnosticBehavior::Warning;
779779

780780
LLVM_FALLTHROUGH;
781781

782-
case StrictConcurrency::Off:
782+
case StrictConcurrency::Explicit:
783783
// Explicit Sendable conformances always diagnose, even when strict
784784
// strict checking is disabled.
785785
if (isExplicitSendableConformance())
786786
return DiagnosticBehavior::Warning;
787787

788788
return DiagnosticBehavior::Ignore;
789789

790-
case StrictConcurrency::On:
790+
case StrictConcurrency::Complete:
791791
return defaultDiagnosticBehavior();
792792
}
793793
}
@@ -2071,12 +2071,12 @@ namespace {
20712071
/// \returns true if we diagnosed the entity, \c false otherwise.
20722072
bool diagnoseReferenceToUnsafeGlobal(ValueDecl *value, SourceLoc loc) {
20732073
switch (value->getASTContext().LangOpts.StrictConcurrencyLevel) {
2074-
case StrictConcurrency::Off:
2075-
case StrictConcurrency::Limited:
2074+
case StrictConcurrency::Explicit:
2075+
case StrictConcurrency::Targeted:
20762076
// Never diagnose.
20772077
return false;
20782078

2079-
case StrictConcurrency::On:
2079+
case StrictConcurrency::Complete:
20802080
break;
20812081
}
20822082

@@ -3984,7 +3984,7 @@ ActorIsolation ActorIsolationRequest::evaluate(
39843984
if (auto var = dyn_cast<VarDecl>(value)) {
39853985
if (var->isTopLevelGlobal() &&
39863986
(var->getASTContext().LangOpts.StrictConcurrencyLevel >=
3987-
StrictConcurrency::On ||
3987+
StrictConcurrency::Complete ||
39883988
var->getDeclContext()->isAsyncContext())) {
39893989
if (Type mainActor = var->getASTContext().getMainActorType())
39903990
return inferredIsolation(
@@ -4186,11 +4186,11 @@ bool swift::contextRequiresStrictConcurrencyChecking(
41864186
const DeclContext *dc,
41874187
llvm::function_ref<Type(const AbstractClosureExpr *)> getType) {
41884188
switch (dc->getASTContext().LangOpts.StrictConcurrencyLevel) {
4189-
case StrictConcurrency::On:
4189+
case StrictConcurrency::Complete:
41904190
return true;
41914191

4192-
case StrictConcurrency::Limited:
4193-
case StrictConcurrency::Off:
4192+
case StrictConcurrency::Targeted:
4193+
case StrictConcurrency::Explicit:
41944194
// Check below to see if the context has adopted concurrency features.
41954195
break;
41964196
}

test/ClangImporter/objc_async.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -I %S/Inputs/custom-modules %s -verify -verify-additional-file %swift_src_root/test/Inputs/clang-importer-sdk/usr/include/ObjCConcurrency.h -strict-concurrency=limited -parse-as-library
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -I %S/Inputs/custom-modules %s -verify -verify-additional-file %swift_src_root/test/Inputs/clang-importer-sdk/usr/include/ObjCConcurrency.h -strict-concurrency=targeted -parse-as-library
22

33
// REQUIRES: objc_interop
44
// REQUIRES: concurrency

test/Concurrency/async_tasks.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -strict-concurrency=limited -disable-availability-checking
1+
// RUN: %target-typecheck-verify-swift -strict-concurrency=targeted -disable-availability-checking
22
// REQUIRES: concurrency
33

44
@available(SwiftStdlib 5.1, *)

test/Concurrency/sendable_checking.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -strict-concurrency=limited
1+
// RUN: %target-typecheck-verify-swift -strict-concurrency=targeted
22
// REQUIRES: concurrency
33
// REQUIRES: OS=macosx
44

test/Concurrency/sendable_module_checking.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/StrictModule.swiftmodule -module-name StrictModule -warn-concurrency %S/Inputs/StrictModule.swift
33
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/NonStrictModule.swiftmodule -module-name NonStrictModule %S/Inputs/NonStrictModule.swift
4-
// RUN: %target-swift-frontend -typecheck -strict-concurrency=limited -disable-availability-checking -I %t 2>&1 %s | %FileCheck %s
4+
// RUN: %target-swift-frontend -typecheck -strict-concurrency=targeted -disable-availability-checking -I %t 2>&1 %s | %FileCheck %s
55

66
// REQUIRES: concurrency
77

0 commit comments

Comments
 (0)