-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Sema] Add custom functions to ActorIsolationChecker to determine expr type and closure actor isolation #59943
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
[Sema] Add custom functions to ActorIsolationChecker to determine expr type and closure actor isolation #59943
Conversation
670293c
to
e17be26
Compare
e17be26
to
7ab2cfd
Compare
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.
Looks good to me! Only question I have is whether new parameter should just be defaulted to avoid changing call sites that don't need customization.
include/swift/AST/ActorIsolation.h
Outdated
ActorIsolation getActorIsolationOfContext( | ||
DeclContext *dc, | ||
llvm::function_ref<ClosureActorIsolation(AbstractClosureExpr *)> | ||
getClosureActorIsolation); |
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.
Should this be defaulted to [](AbstractClosureExpr *closure) { return closure->getActorIsolation(); }
so 99% of the call sites don't have to repeat it?
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 wanted to do the same but that would mean that we need to include Expr.h
here (because we are referencing into AbstractClosureExpr
) and Expr.h
transitively includes ActorIsolation.h
creating an include dependency cycle. 😬
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.
Couldn't it default to the forward-declaration of __AbstractClosureExpr_getActorIsolation
?
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.
Now that you mention it, I think that should be possible.
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.
🤞 Yeah, it should work with forward declaration.
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 it should be possible to move ClosureActorIsolation from Expr.h to ActorIsolation.h?...
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.
Not easily because it references VarDecl *
inside a PointerUnion
, which requires knowledge about the type of VarDecl *
to compute NumLowBitsAvailable
for it.
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.
Alright then :)
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.
Huh, TIL function_ref
has SFINAE to allow covariant returns. Shame it doesn't have a constructor that just takes a callable with the exact params/return type. If we really wanted to, we could probably work around it by forward-declaring a trampoline that returns the llvm::function_ref<ClosureActorIsolation(AbstractClosureExpr *)>
, but maybe it's not worth it.
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 that’s a good idea 👍
7bd762e
to
38a9325
Compare
e0e5814
to
ebc28d2
Compare
@swift-ci Please smoke test |
…ts own function Just a little bit of cleanup because this logic is really quite general and doesn't need to live in `getActorIsolationOfContext`.
…r type and closure actor isolation When we get rid of `LeaveClosureBodiesUnchecked` we no longer save closure types to the AST and thus also don’t save their actor isolation to the AST. Hence, we need to extract types and actor isolations of parent closures from the constraint system solution instead of the AST. This prepares `ActorIsolationChecker` to take custom functions to determine the type of an expression or the actor isolation of a closure.
ebc28d2
to
442cf9b
Compare
@swift-ci Please smoke test |
When we get rid of
LeaveClosureBodiesUnchecked
we no longer save closure types to the AST and thus also don’t save their actor isolation to the AST. Hence, we need to extract types and actor isolations of parent closures from the constraint system solution instead of the AST. This preparesActorIsolationChecker
to take custom functions to determine the type of an expression or the actor isolation of a closure.