Skip to content

[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

Merged
merged 2 commits into from
Sep 7, 2022

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Jul 7, 2022

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.

@ahoppen ahoppen requested a review from xedin July 7, 2022 07:03
@ahoppen ahoppen force-pushed the pr/actorisolation-with-gettype branch from 670293c to e17be26 Compare July 7, 2022 07:04
@ahoppen ahoppen changed the title [CodeCompletion] Determine actor isolation of closures from Solution instead of AST [Sema] Add custom functions to ActorIsolationChecker to determine expr type and closure actor isolation Jul 7, 2022
@ahoppen ahoppen force-pushed the pr/actorisolation-with-gettype branch from e17be26 to 7ab2cfd Compare July 7, 2022 10:42
Copy link
Contributor

@xedin xedin left a 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.

ActorIsolation getActorIsolationOfContext(
DeclContext *dc,
llvm::function_ref<ClosureActorIsolation(AbstractClosureExpr *)>
getClosureActorIsolation);
Copy link
Contributor

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?

Copy link
Member Author

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. 😬

Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

@xedin xedin Jul 26, 2022

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.

Copy link
Contributor

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?...

Copy link
Member Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright then :)

Copy link
Contributor

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.

Copy link
Member Author

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 👍

@ahoppen ahoppen force-pushed the pr/actorisolation-with-gettype branch 2 times, most recently from 7bd762e to 38a9325 Compare July 28, 2022 08:47
@ahoppen ahoppen force-pushed the pr/actorisolation-with-gettype branch 2 times, most recently from e0e5814 to ebc28d2 Compare September 6, 2022 20:48
@ahoppen
Copy link
Member Author

ahoppen commented Sep 6, 2022

@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.
@ahoppen ahoppen force-pushed the pr/actorisolation-with-gettype branch from ebc28d2 to 442cf9b Compare September 7, 2022 09:14
@ahoppen
Copy link
Member Author

ahoppen commented Sep 7, 2022

@swift-ci Please smoke test

@ahoppen ahoppen merged commit f366263 into swiftlang:main Sep 7, 2022
@ahoppen ahoppen deleted the pr/actorisolation-with-gettype branch September 7, 2022 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants