@@ -2964,6 +2964,10 @@ ConstraintSystem::matchFunctionIsolations(FunctionType *func1,
2964
2964
case FunctionTypeIsolation::Kind::NonIsolated:
2965
2965
return true;
2966
2966
2967
+ // A thunk is going to pass `nil` to the isolated parameter.
2968
+ case FunctionTypeIsolation::Kind::NonIsolatedCaller:
2969
+ return matchIfConversion();
2970
+
2967
2971
// Erasing global-actor isolation to non-isolation can admit data
2968
2972
// races; such violations are diagnosed by the actor isolation checker.
2969
2973
// We deliberately do not allow actor isolation violations to influence
@@ -2984,6 +2988,35 @@ ConstraintSystem::matchFunctionIsolations(FunctionType *func1,
2984
2988
}
2985
2989
llvm_unreachable("bad kind");
2986
2990
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
+
2987
3020
// Converting to a global-actor-isolated type.
2988
3021
case FunctionTypeIsolation::Kind::GlobalActor:
2989
3022
switch (isolation1.getKind()) {
@@ -3004,6 +3037,11 @@ ConstraintSystem::matchFunctionIsolations(FunctionType *func1,
3004
3037
case FunctionTypeIsolation::Kind::NonIsolated:
3005
3038
return matchIfConversion();
3006
3039
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
+
3007
3045
// Parameter isolation cannot be altered in the same way.
3008
3046
case FunctionTypeIsolation::Kind::Parameter:
3009
3047
return false;
@@ -3030,6 +3068,10 @@ ConstraintSystem::matchFunctionIsolations(FunctionType *func1,
3030
3068
case FunctionTypeIsolation::Kind::GlobalActor:
3031
3069
return matchIfConversion();
3032
3070
3071
+ // A thunk is going to forward the isolation.
3072
+ case FunctionTypeIsolation::Kind::NonIsolatedCaller:
3073
+ return matchIfConversion();
3074
+
3033
3075
// Don't allow dynamically-isolated function types to convert to
3034
3076
// any specific isolation for the same policy reasons that we don't
3035
3077
// want to allow global-actors to change.
@@ -3050,6 +3092,11 @@ ConstraintSystem::matchFunctionIsolations(FunctionType *func1,
3050
3092
case FunctionTypeIsolation::Kind::GlobalActor:
3051
3093
return matchIfConversion(/*erasure*/ true);
3052
3094
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
+
3053
3100
// Parameter isolation is value-dependent and can't be erased in the
3054
3101
// abstract, though. We need to be able to recover the isolation from
3055
3102
// a value.
0 commit comments