@@ -346,7 +346,8 @@ GlobalActorAttributeRequest::evaluate(
346346 // ... but not if it's an async-context top-level global
347347 if (var->isTopLevelGlobal () &&
348348 (var->getDeclContext ()->isAsyncContext () ||
349- var->getASTContext ().LangOpts .WarnConcurrency )) {
349+ var->getASTContext ().LangOpts .StrictConcurrencyLevel >=
350+ StrictConcurrency::Complete)) {
350351 var->diagnose (diag::global_actor_top_level_var)
351352 .highlight (globalActorAttr->getRangeWithAt ());
352353 return None;
@@ -727,9 +728,6 @@ static bool hasUnavailableConformance(ProtocolConformanceRef conformance) {
727728}
728729
729730static bool shouldDiagnoseExistingDataRaces (const DeclContext *dc) {
730- if (dc->getParentModule ()->isConcurrencyChecked ())
731- return true ;
732-
733731 return contextRequiresStrictConcurrencyChecking (dc, [](const AbstractClosureExpr *) {
734732 return Type ();
735733 });
@@ -738,7 +736,7 @@ static bool shouldDiagnoseExistingDataRaces(const DeclContext *dc) {
738736// / Determine the default diagnostic behavior for this language mode.
739737static DiagnosticBehavior defaultSendableDiagnosticBehavior (
740738 const LangOptions &langOpts) {
741- // Prior to Swift 6, all Sendable-related diagnostics are warnings.
739+ // Prior to Swift 6, all Sendable-related diagnostics are warnings at most .
742740 if (!langOpts.isSwiftVersionAtLeast (6 ))
743741 return DiagnosticBehavior::Warning;
744742
@@ -770,6 +768,30 @@ DiagnosticBehavior SendableCheckContext::defaultDiagnosticBehavior() const {
770768 return defaultSendableDiagnosticBehavior (fromDC->getASTContext ().LangOpts );
771769}
772770
771+ DiagnosticBehavior
772+ SendableCheckContext::implicitSendableDiagnosticBehavior () const {
773+ switch (fromDC->getASTContext ().LangOpts .StrictConcurrencyLevel ) {
774+ case StrictConcurrency::Targeted:
775+ // Limited checking only diagnoses implicit Sendable within contexts that
776+ // have adopted concurrency.
777+ if (shouldDiagnoseExistingDataRaces (fromDC))
778+ return DiagnosticBehavior::Warning;
779+
780+ LLVM_FALLTHROUGH;
781+
782+ case StrictConcurrency::Minimal:
783+ // Explicit Sendable conformances always diagnose, even when strict
784+ // strict checking is disabled.
785+ if (isExplicitSendableConformance ())
786+ return DiagnosticBehavior::Warning;
787+
788+ return DiagnosticBehavior::Ignore;
789+
790+ case StrictConcurrency::Complete:
791+ return defaultDiagnosticBehavior ();
792+ }
793+ }
794+
773795// / Determine whether the given nominal type has an explicit Sendable
774796// / conformance (regardless of its availability).
775797static bool hasExplicitSendableConformance (NominalTypeDecl *nominal,
@@ -864,10 +886,10 @@ DiagnosticBehavior SendableCheckContext::diagnosticBehavior(
864886 : DiagnosticBehavior::Ignore;
865887 }
866888
867- auto defaultBehavior = defaultDiagnosticBehavior ();
889+ DiagnosticBehavior defaultBehavior = implicitSendableDiagnosticBehavior ();
868890
869891 // If we are checking an implicit Sendable conformance, don't suppress
870- // diagnostics for declarations in the same module. We want them so make
892+ // diagnostics for declarations in the same module. We want them to make
871893 // enclosing inferred types non-Sendable.
872894 if (defaultBehavior == DiagnosticBehavior::Ignore &&
873895 nominal->getParentSourceFile () &&
@@ -885,7 +907,7 @@ bool swift::diagnoseSendabilityErrorBasedOn(
885907 if (nominal) {
886908 behavior = fromContext.diagnosticBehavior (nominal);
887909 } else {
888- behavior = fromContext.defaultDiagnosticBehavior ();
910+ behavior = fromContext.implicitSendableDiagnosticBehavior ();
889911 }
890912
891913 bool wasSuppressed = diagnose (behavior);
@@ -2048,9 +2070,16 @@ namespace {
20482070 // /
20492071 // / \returns true if we diagnosed the entity, \c false otherwise.
20502072 bool diagnoseReferenceToUnsafeGlobal (ValueDecl *value, SourceLoc loc) {
2051- if (!getDeclContext ()->getParentModule ()->isConcurrencyChecked ())
2073+ switch (value->getASTContext ().LangOpts .StrictConcurrencyLevel ) {
2074+ case StrictConcurrency::Minimal:
2075+ case StrictConcurrency::Targeted:
2076+ // Never diagnose.
20522077 return false ;
20532078
2079+ case StrictConcurrency::Complete:
2080+ break ;
2081+ }
2082+
20542083 // Only diagnose direct references to mutable global state.
20552084 auto var = dyn_cast<VarDecl>(value);
20562085 if (!var || var->isLet ())
@@ -3954,7 +3983,8 @@ ActorIsolation ActorIsolationRequest::evaluate(
39543983
39553984 if (auto var = dyn_cast<VarDecl>(value)) {
39563985 if (var->isTopLevelGlobal () &&
3957- (var->getASTContext ().LangOpts .WarnConcurrency ||
3986+ (var->getASTContext ().LangOpts .StrictConcurrencyLevel >=
3987+ StrictConcurrency::Complete ||
39583988 var->getDeclContext ()->isAsyncContext ())) {
39593989 if (Type mainActor = var->getASTContext ().getMainActorType ())
39603990 return inferredIsolation (
@@ -4155,10 +4185,16 @@ void swift::checkOverrideActorIsolation(ValueDecl *value) {
41554185bool swift::contextRequiresStrictConcurrencyChecking (
41564186 const DeclContext *dc,
41574187 llvm::function_ref<Type(const AbstractClosureExpr *)> getType) {
4158- // If Swift >= 6, everything uses strict concurrency checking.
4159- if (dc-> getASTContext (). LangOpts . isSwiftVersionAtLeast ( 6 ))
4188+ switch (dc-> getASTContext (). LangOpts . StrictConcurrencyLevel ) {
4189+ case StrictConcurrency::Complete:
41604190 return true ;
41614191
4192+ case StrictConcurrency::Targeted:
4193+ case StrictConcurrency::Minimal:
4194+ // Check below to see if the context has adopted concurrency features.
4195+ break ;
4196+ }
4197+
41624198 while (!dc->isModuleScopeContext ()) {
41634199 if (auto closure = dyn_cast<AbstractClosureExpr>(dc)) {
41644200 // A closure with an explicit global actor or nonindependent
0 commit comments