-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Concurrency] Add a .isolation
member on dynamically isolated function values.
#72324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Concurrency] Add a .isolation
member on dynamically isolated function values.
#72324
Conversation
…lation of a dynamically isolated function value in the AST.
…ically isolated function values.
@swift-ci please smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to convert it back into UnresolvedDeclRefExpr if encountered during pre-check?
// member that extracts the isolation value. | ||
if (auto *fn = dyn_cast<FunctionType>(instanceTy)) { | ||
if (fn->getIsolation().isErased() && | ||
memberName.getBaseIdentifier().str() == "isolation") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think memberName.isSimpleName(Context.Id_isolation)
could be used here
@@ -9746,6 +9747,16 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName, | |||
if (auto *selfTy = instanceTy->getAs<DynamicSelfType>()) | |||
instanceTy = selfTy->getSelfType(); | |||
|
|||
// Dynamically isolated function types have a magic '.isolation' | |||
// member that extracts the isolation value. | |||
if (auto *fn = dyn_cast<FunctionType>(instanceTy)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe better use instanceTy->getAs<FunctionType>()
because member could be wrapped in parens
|
||
func extractFunctionIsolationExpr( | ||
_ fn1: @isolated(any) @escaping () async -> Void, | ||
_ fn2: @isolated(any) @escaping (Int, String) -> Bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add a few test-cases that deal with optional unwrap (both styles) as well?
…tion-expr [Concurrency] Add a `.isolation` member on dynamically isolated function values.
This change implements the
.isolation
member on function values with dynamically isolated function type. The approach is very straightforward:isolation
on function types with erased isolation and records a specialExtractFunctionIsolation
overload choice.ExtractFunctionIsolation
overload choice is selected, CSApply injectsExtractFunctionIsolationExpr
around the function expression.function_extract_isolation
instruction.The
.isolation
member is equivalent to theextractFunctionIsolation
function currently in the concurrency library, but supported on any type of dynamically isolated function; the current API doesn't abstract over effects, ownership, etc.Once isolated captures are implemented, we can teach the actor isolation checker to recognize when a context is isolated to an actor value that came from
ExtractFunctionIsolationExpr
and understand that calls to the base function value do not cross an isolation boundary.