Skip to content

Commit 4116d7a

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.
1 parent 45ec725 commit 4116d7a

18 files changed

+46
-44
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
@@ -702,9 +702,9 @@ def warn_concurrency : Flag<["-"], "warn-concurrency">,
702702
def strict_concurrency : Joined<["-"], "strict-concurrency=">,
703703
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
704704
HelpText<"Specify the how strict concurrency checking will be. The value may "
705-
"be 'off' (most 'Sendable' checking is disabled), "
706-
"'limited' ('Sendable' checking is enabled in code that uses the "
707-
"concurrency model, or 'on' ('Sendable' and other checking is "
705+
"be 'explicit' (most 'Sendable' checking is disabled), "
706+
"'targeted' ('Sendable' checking is enabled in code that uses the "
707+
"concurrency model, or 'complete' ('Sendable' and other checking is "
708708
"enabled for all code in the module)">;
709709

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

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9202,7 +9202,7 @@ ActorIsolation swift::getActorIsolationOfContext(DeclContext *dc) {
92029202
if (auto *tld = dyn_cast<TopLevelCodeDecl>(dc)) {
92039203
if (dc->isAsyncContext() ||
92049204
dc->getASTContext().LangOpts.StrictConcurrencyLevel
9205-
>= StrictConcurrency::On) {
9205+
>= StrictConcurrency::Complete) {
92069206
if (Type mainActor = dc->getASTContext().getMainActorType())
92079207
return ActorIsolation::forGlobalActor(
92089208
mainActor,

lib/Frontend/CompilerInvocation.cpp

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

695695
// Swift 6+ uses the strictest concurrency level.
696696
if (Opts.isSwiftVersionAtLeast(6)) {
697-
Opts.StrictConcurrencyLevel = StrictConcurrency::On;
697+
Opts.StrictConcurrencyLevel = StrictConcurrency::Complete;
698698
} else if (const Arg *A = Args.getLastArg(OPT_strict_concurrency)) {
699699
auto value = llvm::StringSwitch<Optional<StrictConcurrency>>(A->getValue())
700-
.Case("off", StrictConcurrency::Off)
701-
.Case("limited", StrictConcurrency::Limited)
702-
.Case("on", StrictConcurrency::On)
700+
.Case("explicit", StrictConcurrency::Explicit)
701+
.Case("targeted", StrictConcurrency::Targeted)
702+
.Case("complete", StrictConcurrency::Complete)
703703
.Default(None);
704704

705705
if (value)
@@ -709,10 +709,10 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
709709
A->getAsString(Args), A->getValue());
710710

711711
} else if (Args.hasArg(OPT_warn_concurrency)) {
712-
Opts.StrictConcurrencyLevel = StrictConcurrency::On;
712+
Opts.StrictConcurrencyLevel = StrictConcurrency::Complete;
713713
} else {
714714
// Default to "limited" checking in Swift 5.x.
715-
Opts.StrictConcurrencyLevel = StrictConcurrency::Limited;
715+
Opts.StrictConcurrencyLevel = StrictConcurrency::Targeted;
716716
}
717717

718718
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;
@@ -651,23 +651,23 @@ DiagnosticBehavior SendableCheckContext::defaultDiagnosticBehavior() const {
651651
DiagnosticBehavior
652652
SendableCheckContext::implicitSendableDiagnosticBehavior() const {
653653
switch (fromDC->getASTContext().LangOpts.StrictConcurrencyLevel) {
654-
case StrictConcurrency::Limited:
654+
case StrictConcurrency::Targeted:
655655
// Limited checking only diagnoses implicit Sendable within contexts that
656656
// have adopted concurrency.
657657
if (shouldDiagnoseExistingDataRaces(fromDC))
658658
return DiagnosticBehavior::Warning;
659659

660660
LLVM_FALLTHROUGH;
661661

662-
case StrictConcurrency::Off:
662+
case StrictConcurrency::Explicit:
663663
// Explicit Sendable conformances always diagnose, even when strict
664664
// strict checking is disabled.
665665
if (isExplicitSendableConformance())
666666
return DiagnosticBehavior::Warning;
667667

668668
return DiagnosticBehavior::Ignore;
669669

670-
case StrictConcurrency::On:
670+
case StrictConcurrency::Complete:
671671
return defaultDiagnosticBehavior();
672672
}
673673
}
@@ -2140,12 +2140,12 @@ namespace {
21402140
/// \returns true if we diagnosed the entity, \c false otherwise.
21412141
bool diagnoseReferenceToUnsafeGlobal(ValueDecl *value, SourceLoc loc) {
21422142
switch (value->getASTContext().LangOpts.StrictConcurrencyLevel) {
2143-
case StrictConcurrency::Off:
2144-
case StrictConcurrency::Limited:
2143+
case StrictConcurrency::Explicit:
2144+
case StrictConcurrency::Targeted:
21452145
// Never diagnose.
21462146
return false;
21472147

2148-
case StrictConcurrency::On:
2148+
case StrictConcurrency::Complete:
21492149
break;
21502150
}
21512151

@@ -3713,7 +3713,7 @@ ActorIsolation ActorIsolationRequest::evaluate(
37133713
if (auto var = dyn_cast<VarDecl>(value)) {
37143714
if (var->isTopLevelGlobal() &&
37153715
(var->getASTContext().LangOpts.StrictConcurrencyLevel >=
3716-
StrictConcurrency::On ||
3716+
StrictConcurrency::Complete ||
37173717
var->getDeclContext()->isAsyncContext())) {
37183718
if (Type mainActor = var->getASTContext().getMainActorType())
37193719
return inferredIsolation(
@@ -3922,11 +3922,11 @@ bool swift::contextRequiresStrictConcurrencyChecking(
39223922
const DeclContext *dc,
39233923
llvm::function_ref<Type(const AbstractClosureExpr *)> getType) {
39243924
switch (dc->getASTContext().LangOpts.StrictConcurrencyLevel) {
3925-
case StrictConcurrency::On:
3925+
case StrictConcurrency::Complete:
39263926
return true;
39273927

3928-
case StrictConcurrency::Limited:
3929-
case StrictConcurrency::Off:
3928+
case StrictConcurrency::Targeted:
3929+
case StrictConcurrency::Explicit:
39303930
// Check below to see if the context has adopted concurrency features.
39313931
break;
39323932
}

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

test/Concurrency/sendable_preconcurrency.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 -swift-version 6 %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-typecheck-verify-swift -strict-concurrency=limited -disable-availability-checking -I %t
4+
// RUN: %target-typecheck-verify-swift -strict-concurrency=targeted -disable-availability-checking -I %t
55

66
// REQUIRES: concurrency
77
// REQUIRES: asserts

test/Concurrency/sendable_without_preconcurrency.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 -swift-version 6 %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-typecheck-verify-swift -strict-concurrency=limited -disable-availability-checking -I %t
4+
// RUN: %target-typecheck-verify-swift -strict-concurrency=targeted -disable-availability-checking -I %t
55

66
// REQUIRES: concurrency
77
// REQUIRES: asserts

test/Concurrency/sendable_without_preconcurrency_2.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 -swift-version 6 %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-typecheck-verify-swift -strict-concurrency=limited -disable-availability-checking -I %t
4+
// RUN: %target-typecheck-verify-swift -strict-concurrency=targeted -disable-availability-checking -I %t
55

66
// REQUIRES: concurrency
77
// REQUIRES: asserts

test/Concurrency/sr15049.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 -disable-availability-checking -strict-concurrency=limited
1+
// RUN: %target-typecheck-verify-swift -disable-availability-checking -strict-concurrency=targeted
22
// REQUIRES: concurrency
33

44
func testAsyncSequenceTypedPatternSendable<Seq: AsyncSequence>(_ seq: Seq) async throws where Seq.Element == Int, Seq: Sendable {

test/Concurrency/strict_concurrency_off.swift renamed to test/Concurrency/strict_concurrency_explicit.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=off
1+
// RUN: %target-typecheck-verify-swift -strict-concurrency=explicit
22
// REQUIRES: concurrency
33

44
class C1 { }

test/Distributed/distributed_protocol_isolation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -disable-availability-checking %S/Inputs/FakeDistributedActorSystems.swift
3-
// RUN: %target-swift-frontend -typecheck -verify -strict-concurrency=limited -disable-availability-checking -I %t 2>&1 %s
3+
// RUN: %target-swift-frontend -typecheck -verify -strict-concurrency=targeted -disable-availability-checking -I %t 2>&1 %s
44
// REQUIRES: concurrency
55
// REQUIRES: distributed
66

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4281,7 +4281,8 @@ int main(int argc, char *argv[]) {
42814281
InitInvok.getLangOptions().EnableExperimentalConcurrency = true;
42824282
}
42834283
if (options::WarnConcurrency) {
4284-
InitInvok.getLangOptions().StrictConcurrencyLevel = StrictConcurrency::On;
4284+
InitInvok.getLangOptions().StrictConcurrencyLevel =
4285+
StrictConcurrency::Complete;
42854286
}
42864287
if (options::DisableImplicitConcurrencyImport) {
42874288
InitInvok.getLangOptions().DisableImplicitConcurrencyModuleImport = true;

validation-test/Sema/SwiftUI/rdar76252310.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 -target %target-cpu-apple-macosx10.15 -swift-version 5 -strict-concurrency=limited
1+
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx10.15 -swift-version 5 -strict-concurrency=targeted
22

33
// REQUIRES: objc_interop
44
// REQUIRES: OS=macosx

0 commit comments

Comments
 (0)