@@ -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::On)) {
350351 var->diagnose (diag::global_actor_top_level_var)
351352 .highlight (globalActorAttr->getRangeWithAt ());
352353 return None;
@@ -607,9 +608,6 @@ static bool hasUnavailableConformance(ProtocolConformanceRef conformance) {
607608}
608609
609610static bool shouldDiagnoseExistingDataRaces (const DeclContext *dc) {
610- if (dc->getParentModule ()->isConcurrencyChecked ())
611- return true ;
612-
613611 return contextRequiresStrictConcurrencyChecking (dc, [](const AbstractClosureExpr *) {
614612 return Type ();
615613 });
@@ -2117,9 +2115,16 @@ namespace {
21172115 // /
21182116 // / \returns true if we diagnosed the entity, \c false otherwise.
21192117 bool diagnoseReferenceToUnsafeGlobal (ValueDecl *value, SourceLoc loc) {
2120- if (!getDeclContext ()->getParentModule ()->isConcurrencyChecked ())
2118+ switch (value->getASTContext ().LangOpts .StrictConcurrencyLevel ) {
2119+ case StrictConcurrency::Off:
2120+ case StrictConcurrency::Limited:
2121+ // Never diagnose.
21212122 return false ;
21222123
2124+ case StrictConcurrency::On:
2125+ break ;
2126+ }
2127+
21232128 // Only diagnose direct references to mutable global state.
21242129 auto var = dyn_cast<VarDecl>(value);
21252130 if (!var || var->isLet ())
@@ -3683,7 +3688,8 @@ ActorIsolation ActorIsolationRequest::evaluate(
36833688
36843689 if (auto var = dyn_cast<VarDecl>(value)) {
36853690 if (var->isTopLevelGlobal () &&
3686- (var->getASTContext ().LangOpts .WarnConcurrency ||
3691+ (var->getASTContext ().LangOpts .StrictConcurrencyLevel >=
3692+ StrictConcurrency::On ||
36873693 var->getDeclContext ()->isAsyncContext ())) {
36883694 if (Type mainActor = var->getASTContext ().getMainActorType ())
36893695 return inferredIsolation (
@@ -3891,10 +3897,16 @@ void swift::checkOverrideActorIsolation(ValueDecl *value) {
38913897bool swift::contextRequiresStrictConcurrencyChecking (
38923898 const DeclContext *dc,
38933899 llvm::function_ref<Type(const AbstractClosureExpr *)> getType) {
3894- // If Swift >= 6, everything uses strict concurrency checking.
3895- if (dc-> getASTContext (). LangOpts . isSwiftVersionAtLeast ( 6 ))
3900+ switch (dc-> getASTContext (). LangOpts . StrictConcurrencyLevel ) {
3901+ case StrictConcurrency::On:
38963902 return true ;
38973903
3904+ case StrictConcurrency::Limited:
3905+ case StrictConcurrency::Off:
3906+ // Check below to see if the context has adopted concurrency features.
3907+ break ;
3908+ }
3909+
38983910 while (!dc->isModuleScopeContext ()) {
38993911 if (auto closure = dyn_cast<AbstractClosureExpr>(dc)) {
39003912 // A closure with an explicit global actor or nonindependent
0 commit comments