@@ -609,6 +609,9 @@ static void addSendableFixIt(const GenericTypeParamDecl *genericArgument,
609609static bool shouldDiagnoseExistingDataRaces(const DeclContext *dc) {
610610 return contextRequiresStrictConcurrencyChecking(dc, [](const AbstractClosureExpr *) {
611611 return Type();
612+ },
613+ [](const ClosureExpr *closure) {
614+ return closure->isIsolatedByPreconcurrency();
612615 });
613616}
614617
@@ -4023,7 +4026,8 @@ void swift::checkOverrideActorIsolation(ValueDecl *value) {
40234026
40244027bool swift::contextRequiresStrictConcurrencyChecking(
40254028 const DeclContext *dc,
4026- llvm::function_ref<Type(const AbstractClosureExpr *)> getType) {
4029+ llvm::function_ref<Type(const AbstractClosureExpr *)> getType,
4030+ llvm::function_ref<bool(const ClosureExpr *)> isolatedByPreconcurrency) {
40274031 switch (dc->getASTContext().LangOpts.StrictConcurrencyLevel) {
40284032 case StrictConcurrency::Complete:
40294033 return true;
@@ -4044,7 +4048,7 @@ bool swift::contextRequiresStrictConcurrencyChecking(
40444048
40454049 // Don't take any more cues if this only got its type information by
40464050 // being provided to a `@preconcurrency` operation.
4047- if (explicitClosure->isIsolatedByPreconcurrency( )) {
4051+ if (isolatedByPreconcurrency(explicitClosure )) {
40484052 dc = dc->getParent();
40494053 continue;
40504054 }
@@ -4602,11 +4606,13 @@ static bool hasKnownUnsafeSendableFunctionParams(AbstractFunctionDecl *func) {
46024606
46034607Type swift::adjustVarTypeForConcurrency(
46044608 Type type, VarDecl *var, DeclContext *dc,
4605- llvm::function_ref<Type(const AbstractClosureExpr *)> getType) {
4609+ llvm::function_ref<Type(const AbstractClosureExpr *)> getType,
4610+ llvm::function_ref<bool(const ClosureExpr *)> isolatedByPreconcurrency) {
46064611 if (!var->preconcurrency())
46074612 return type;
46084613
4609- if (contextRequiresStrictConcurrencyChecking(dc, getType))
4614+ if (contextRequiresStrictConcurrencyChecking(
4615+ dc, getType, isolatedByPreconcurrency))
46104616 return type;
46114617
46124618 bool isLValue = false;
@@ -4727,9 +4733,11 @@ AnyFunctionType *swift::adjustFunctionTypeForConcurrency(
47274733 AnyFunctionType *fnType, ValueDecl *decl, DeclContext *dc,
47284734 unsigned numApplies, bool isMainDispatchQueue,
47294735 llvm::function_ref<Type(const AbstractClosureExpr *)> getType,
4736+ llvm::function_ref<bool(const ClosureExpr *)> isolatedByPreconcurrency,
47304737 llvm::function_ref<Type(Type)> openType) {
47314738 // Apply unsafe concurrency features to the given function type.
4732- bool strictChecking = contextRequiresStrictConcurrencyChecking(dc, getType);
4739+ bool strictChecking = contextRequiresStrictConcurrencyChecking(
4740+ dc, getType, isolatedByPreconcurrency);
47334741 fnType = applyUnsafeConcurrencyToFunctionType(
47344742 fnType, decl, strictChecking, numApplies, isMainDispatchQueue);
47354743
@@ -4789,7 +4797,10 @@ bool swift::completionContextUsesConcurrencyFeatures(const DeclContext *dc) {
47894797 return contextRequiresStrictConcurrencyChecking(
47904798 dc, [](const AbstractClosureExpr *) {
47914799 return Type();
4792- });
4800+ },
4801+ [](const ClosureExpr *closure) {
4802+ return closure->isIsolatedByPreconcurrency();
4803+ });
47934804}
47944805
47954806AbstractFunctionDecl const *swift::isActorInitOrDeInitContext(
@@ -4898,6 +4909,9 @@ static ActorIsolation getActorIsolationForReference(
48984909 fromDC,
48994910 [](const AbstractClosureExpr *closure) {
49004911 return closure->getType();
4912+ },
4913+ [](const ClosureExpr *closure) {
4914+ return closure->isIsolatedByPreconcurrency();
49014915 })) {
49024916 declIsolation = ActorIsolation::forGlobalActor(
49034917 declIsolation.getGlobalActor(), /*unsafe=*/false);
0 commit comments