@@ -1889,8 +1889,7 @@ static ActorIsolation getInnermostIsolatedContext(
1889
1889
case ActorIsolation::GlobalActor:
1890
1890
case ActorIsolation::GlobalActorUnsafe:
1891
1891
return ActorIsolation::forGlobalActor (
1892
- dc->mapTypeIntoContext (isolation.getGlobalActor ()),
1893
- isolation == ActorIsolation::GlobalActorUnsafe)
1892
+ dc->mapTypeIntoContext (isolation.getGlobalActor ()))
1894
1893
.withPreconcurrency (isolation.preconcurrency ());
1895
1894
}
1896
1895
}
@@ -3238,8 +3237,7 @@ namespace {
3238
3237
// we are within that global actor already.
3239
3238
if (!(getContextIsolation ().isGlobalActor () &&
3240
3239
getContextIsolation ().getGlobalActor ()->isEqual (globalActor))) {
3241
- unsatisfiedIsolation = ActorIsolation::forGlobalActor (
3242
- globalActor, /* unsafe=*/ false );
3240
+ unsatisfiedIsolation = ActorIsolation::forGlobalActor (globalActor);
3243
3241
}
3244
3242
3245
3243
mayExitToNonisolated = false ;
@@ -3891,7 +3889,7 @@ namespace {
3891
3889
3892
3890
// If the closure specifies a global actor, use it.
3893
3891
if (Type globalActor = resolveGlobalActorType (explicitClosure))
3894
- return ActorIsolation::forGlobalActor (globalActor, /* unsafe= */ false )
3892
+ return ActorIsolation::forGlobalActor (globalActor)
3895
3893
.withPreconcurrency (preconcurrency);
3896
3894
}
3897
3895
@@ -3927,7 +3925,7 @@ namespace {
3927
3925
case ActorIsolation::GlobalActorUnsafe: {
3928
3926
Type globalActor = closure->mapTypeIntoContext (
3929
3927
parentIsolation.getGlobalActor ()->mapTypeOutOfContext ());
3930
- return ActorIsolation::forGlobalActor (globalActor, /* unsafe= */ false )
3928
+ return ActorIsolation::forGlobalActor (globalActor)
3931
3929
.withPreconcurrency (preconcurrency);
3932
3930
}
3933
3931
@@ -4124,7 +4122,7 @@ getIsolationFromAttributes(const Decl *decl, bool shouldDiagnose = true,
4124
4122
isUnsafe = true ;
4125
4123
4126
4124
return ActorIsolation::forGlobalActor (
4127
- globalActorType->mapTypeOutOfContext (), isUnsafe )
4125
+ globalActorType->mapTypeOutOfContext ())
4128
4126
.withPreconcurrency (decl->preconcurrency () || isUnsafe);
4129
4127
}
4130
4128
@@ -4216,8 +4214,8 @@ getIsolationFromWitnessedRequirements(ValueDecl *value) {
4216
4214
return true ;
4217
4215
4218
4216
// Update the global actor type, now that we've done this substitution.
4219
- std::get<1 >(isolated) = ActorIsolation::forGlobalActor (
4220
- globalActor, isolation == ActorIsolation::GlobalActorUnsafe );
4217
+ std::get<1 >(isolated) = ActorIsolation::forGlobalActor (globalActor)
4218
+ . withPreconcurrency ( isolation. preconcurrency () );
4221
4219
return false ;
4222
4220
}
4223
4221
}
@@ -4461,8 +4459,7 @@ getActorIsolationForMainFuncDecl(FuncDecl *fnDecl) {
4461
4459
4462
4460
return isMainFunction && hasMainActor
4463
4461
? ActorIsolation::forGlobalActor (
4464
- ctx.getMainActorType ()->mapTypeOutOfContext (),
4465
- /* isUnsafe*/ false )
4462
+ ctx.getMainActorType ()->mapTypeOutOfContext ())
4466
4463
: llvm::Optional<ActorIsolation>();
4467
4464
}
4468
4465
@@ -4906,8 +4903,8 @@ ActorIsolation ActorIsolationRequest::evaluate(
4906
4903
var->getDeclContext ()->isAsyncContext ())) {
4907
4904
if (Type mainActor = var->getASTContext ().getMainActorType ())
4908
4905
return inferredIsolation (
4909
- ActorIsolation::forGlobalActor (mainActor,
4910
- /* unsafe= */ var->preconcurrency () ));
4906
+ ActorIsolation::forGlobalActor (mainActor))
4907
+ . withPreconcurrency ( var->preconcurrency ());
4911
4908
}
4912
4909
if (auto isolation = getActorIsolationFromWrappedProperty (var))
4913
4910
return inferredIsolation (isolation);
@@ -4993,7 +4990,8 @@ ActorIsolation ActorIsolationRequest::evaluate(
4993
4990
ASTContext &ctx = value->getASTContext ();
4994
4991
if (Type mainActor = ctx.getMainActorType ()) {
4995
4992
return inferredIsolation (
4996
- ActorIsolation::forGlobalActor (mainActor, /* unsafe=*/ true ));
4993
+ ActorIsolation::forGlobalActor (mainActor)
4994
+ .withPreconcurrency (true ));
4997
4995
}
4998
4996
}
4999
4997
@@ -5907,14 +5905,12 @@ AnyFunctionType *swift::adjustFunctionTypeForConcurrency(
5907
5905
return fnType;
5908
5906
5909
5907
case ActorIsolation::GlobalActorUnsafe:
5910
- // Only treat as global-actor-qualified within code that has adopted
5911
- // Swift Concurrency features.
5912
- if (!strictChecking)
5908
+ case ActorIsolation::GlobalActor:
5909
+ // For preconcurrency, only treat as global-actor-qualified
5910
+ // within code that has adopted Swift Concurrency features.
5911
+ if (!strictChecking && isolation.preconcurrency ())
5913
5912
return fnType;
5914
5913
5915
- LLVM_FALLTHROUGH;
5916
-
5917
- case ActorIsolation::GlobalActor:
5918
5914
globalActorType = openType (isolation.getGlobalActor ());
5919
5915
break ;
5920
5916
}
@@ -6058,22 +6054,19 @@ static ActorIsolation getActorIsolationForReference(
6058
6054
ValueDecl *decl, const DeclContext *fromDC) {
6059
6055
auto declIsolation = getActorIsolation (decl);
6060
6056
6061
- // If the isolation is "unsafe" global actor isolation , adjust it based on
6057
+ // If the isolation is preconcurrency global actor, adjust it based on
6062
6058
// context itself. For contexts that require strict checking, treat it as
6063
6059
// global actor isolation. Otherwise, treat it as unspecified isolation.
6064
- if (declIsolation == ActorIsolation::GlobalActorUnsafe) {
6065
- if (contextRequiresStrictConcurrencyChecking (
6060
+ if (declIsolation == ActorIsolation::GlobalActor &&
6061
+ declIsolation.preconcurrency ()) {
6062
+ if (!contextRequiresStrictConcurrencyChecking (
6066
6063
fromDC,
6067
6064
[](const AbstractClosureExpr *closure) {
6068
6065
return closure->getType ();
6069
6066
},
6070
6067
[](const ClosureExpr *closure) {
6071
6068
return closure->isIsolatedByPreconcurrency ();
6072
6069
})) {
6073
- declIsolation = ActorIsolation::forGlobalActor (
6074
- declIsolation.getGlobalActor (), /* unsafe=*/ false )
6075
- .withPreconcurrency (declIsolation.preconcurrency ());
6076
- } else {
6077
6070
declIsolation = ActorIsolation::forUnspecified ();
6078
6071
}
6079
6072
}
0 commit comments