Skip to content

Teach witness thunks to hop to the actor when needed. #59450

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
Jun 15, 2022

Conversation

DougGregor
Copy link
Member

When a synchronous, actor-isolated declaration witnesses an
asynchronous, not-similarly-isolated requirement, emit an actor hop
within the witness thunk to ensure that we properly enter the context
of the actor.

When the witness is distributed, we go through the distributed thunk
rather than hopping to the actor.

Fixes #58517 / rdar://92881539.

When a synchronous, actor-isolated declaration witnesses an
asynchronous, not-similarly-isolated requirement, emit an actor hop
within the witness thunk to ensure that we properly enter the context
of the actor.

Fixes swiftlang#58517 / rdar://92881539.
…hunk

We cannot hop to a distributed actor directly, so call through the
distributed thunk instead.
@DougGregor
Copy link
Member Author

@swift-ci please test

@ktoso ktoso self-requested a review June 15, 2022 02:21
Copy link
Contributor

@ktoso ktoso left a comment

Choose a reason for hiding this comment

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

Awesome, thanks! This looks good!

You're right to not hop to the actor, but just call the thunk because the thunk is nonisolated and will hop itself when it has to do so 👍

I want to double check some cases so trying it out locally now :)

@ktoso
Copy link
Contributor

ktoso commented Jun 15, 2022

Okey I think this is also correct... just wanted to double check:

protocol DistServerProto: DistributedActor {
  distributed func distDoSomething()
}

extension DA: DistServerProto {
  // CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s17distributed_thunk2DACAA15DistServerProtoA2aDP15distDoSomethingyyFTW : $@convention(witness_method: DistServerProto) (@guaranteed DA) -> () {
  // CHECK-NOT: hop_to_executor
  // CHECK-NOT: return
  // CHECK: function_ref @$s17distributed_thunk2DAC15distDoSomethingyyF
  // CHECK: return
  distributed func distDoSomething() { }
}

@DougGregor
Copy link
Member Author

Okey I think this is also correct... just wanted to double check:

Yeah, that looks right to me.

@DougGregor
Copy link
Member Author

Windows failure is unrelated

@DougGregor DougGregor merged commit 12d0d2b into swiftlang:main Jun 15, 2022
@DougGregor DougGregor deleted the actor-isolated-sync-witness branch June 15, 2022 04:21
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.

Actor isolation is broken by conforming to an async protocol
2 participants