@@ -2964,6 +2964,10 @@ ConstraintSystem::matchFunctionIsolations(FunctionType *func1,
29642964 case FunctionTypeIsolation::Kind::NonIsolated:
29652965 return true;
29662966
2967+ // A thunk is going to pass `nil` to the isolated parameter.
2968+ case FunctionTypeIsolation::Kind::NonIsolatedCaller:
2969+ return matchIfConversion();
2970+
29672971 // Erasing global-actor isolation to non-isolation can admit data
29682972 // races; such violations are diagnosed by the actor isolation checker.
29692973 // We deliberately do not allow actor isolation violations to influence
@@ -2984,6 +2988,35 @@ ConstraintSystem::matchFunctionIsolations(FunctionType *func1,
29842988 }
29852989 llvm_unreachable("bad kind");
29862990
2991+ // Converting to a caller isolated async function type.
2992+ case FunctionTypeIsolation::Kind::NonIsolatedCaller:
2993+ switch (isolation1.getKind()) {
2994+ // Exact match.
2995+ case FunctionTypeIsolation::Kind::NonIsolatedCaller:
2996+ return true;
2997+
2998+ // Global actor: Thunk will hop to the global actor
2999+ // and would ignore passed in isolation.
3000+ // Erased: Just like global actor but would hop to
3001+ // the isolation stored in the @isolated(any) function.
3002+ case FunctionTypeIsolation::Kind::GlobalActor:
3003+ case FunctionTypeIsolation::Kind::Erased:
3004+ return matchIfConversion();
3005+
3006+ // In this case the isolation is dependent on a
3007+ // specific actor passed in as the isolation parameter
3008+ // and the thunk won't have it.
3009+ case FunctionTypeIsolation::Kind::Parameter:
3010+ return false;
3011+
3012+ // For asynchronous: Thunk would hop the appropriate actor.
3013+ // For synchronous: Thunk would call the function without
3014+ // a hop.
3015+ case FunctionTypeIsolation::Kind::NonIsolated:
3016+ return matchIfConversion();
3017+ }
3018+ llvm_unreachable("bad kind");
3019+
29873020 // Converting to a global-actor-isolated type.
29883021 case FunctionTypeIsolation::Kind::GlobalActor:
29893022 switch (isolation1.getKind()) {
@@ -3004,6 +3037,11 @@ ConstraintSystem::matchFunctionIsolations(FunctionType *func1,
30043037 case FunctionTypeIsolation::Kind::NonIsolated:
30053038 return matchIfConversion();
30063039
3040+ // A thunk is going to pass in an instance of a global actor
3041+ // to the isolated parameter.
3042+ case FunctionTypeIsolation::Kind::NonIsolatedCaller:
3043+ return matchIfConversion();
3044+
30073045 // Parameter isolation cannot be altered in the same way.
30083046 case FunctionTypeIsolation::Kind::Parameter:
30093047 return false;
@@ -3030,6 +3068,10 @@ ConstraintSystem::matchFunctionIsolations(FunctionType *func1,
30303068 case FunctionTypeIsolation::Kind::GlobalActor:
30313069 return matchIfConversion();
30323070
3071+ // A thunk is going to forward the isolation.
3072+ case FunctionTypeIsolation::Kind::NonIsolatedCaller:
3073+ return matchIfConversion();
3074+
30333075 // Don't allow dynamically-isolated function types to convert to
30343076 // any specific isolation for the same policy reasons that we don't
30353077 // want to allow global-actors to change.
@@ -3050,6 +3092,11 @@ ConstraintSystem::matchFunctionIsolations(FunctionType *func1,
30503092 case FunctionTypeIsolation::Kind::GlobalActor:
30513093 return matchIfConversion(/*erasure*/ true);
30523094
3095+ // It's not possible to form a thunk for this case because
3096+ // we don't know what to pass to the isolated parameter.
3097+ case FunctionTypeIsolation::Kind::NonIsolatedCaller:
3098+ return false;
3099+
30533100 // Parameter isolation is value-dependent and can't be erased in the
30543101 // abstract, though. We need to be able to recover the isolation from
30553102 // a value.
0 commit comments