-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Distributed] Protocol mangling and primary associated type fixes #77584
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
Conversation
ff19248
to
6812658
Compare
@ktoso I see that there is a bunch of leftover comments and code, could you please clean that up and ping me when done so I can take a look when this is ready to merge? |
Oh yeah don't review this at all yet, I'm cleaning up and will make it into some nice commits. Marked as draft now, sorry! |
5cff8a5
to
86f4820
Compare
@swift-ci please smoke test |
86f4820
to
0906d32
Compare
@swift-ci please smoke test |
@swift-ci please smoke test |
Unrelated, Cxx interop fails compiling on Windows:
|
@swift-ci please smoke test Windows |
// CHECK-NEXT: > encode return type: Swift.String | ||
// CHECK-NEXT: > done recording | ||
// CHECK-NEXT: >> remoteCall: on:main.$GreeterProtocol<main.FakeRoundtripActorSystem>, target:main.$GreeterProtocol.greet(), invocation:FakeInvocationEncoder(genericSubs: [main.$GreeterProtocol<main.FakeRoundtripActorSystem>], arguments: [], returnType: Optional(Swift.String), errorType: nil), throwing:Swift.Never, returning:Swift.String | ||
// CHECK-NEXT: > execute distributed target: main.$GreeterProtocol.greet(), identifier: $s4main16$GreeterProtocolC5greetSSyYaKFTE |
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.
note: here we keep the same mangling, good 👍
@@ -40,7 +40,9 @@ func test() async throws { | |||
let ref = try KappaProtocolImpl.resolve(id: local.id, using: system) | |||
|
|||
let reply = try await ref.echo(name: "Caplin") | |||
// CHECK: >> remoteCall: on:main.KappaProtocolImpl, target:main.$KappaProtocol.echo(name:), invocation:FakeInvocationEncoder(genericSubs: [main.KappaProtocolImpl], arguments: ["Caplin"], returnType: Optional(Swift.String), errorType: nil), throwing:Swift.Never, returning:Swift.String | |||
// CHECK: >> remoteCall: on:main.KappaProtocolImpl, target:echo(name:), invocation:FakeInvocationEncoder(genericSubs: [main.KappaProtocolImpl], arguments: ["Caplin"], returnType: Optional(Swift.String), errorType: nil), throwing:Swift.Never, returning:Swift.String | |||
// CHECK: > execute distributed target: echo(name:), identifier: $s4main13KappaProtocolPAAE4echo4nameS2S_tYaKFTE |
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.
added a mangling check as well, we didnt before
@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.
LGTM! Could you add an example with array type and optional as parameters to make sure that it works as expected too?
Thanks for review! Huh seems I missed to git add my array test :) Adding some more |
…tocols Previously we would not propagate those into the generated distributed actor, making a lot of generic distributed actor protocols impossible to express. We indeed cannot handle protocols WITHOUT primary associated types, but we certainly can handle them with! This resolves rdar://139332556
This is a crucial fix without which we can crash on some distributed protocol declarations with @resolvable. We cannot "just" use a String to represent the "fake base" of the thunks, and must instead find the $Target macro generated type and use it as the base of the thunk's mangling. Calls are made in such way that record for the protocol requirement: `$s4main28GreeterDefinedSystemProtocolP5greetSSyYaKFTEHF` points at `$$s4main29$GreeterDefinedSystemProtocolC5greetSSyYaKFTE` which makes a dispatch through the _apropriate_ witness table. And the record for the $witness named e.g. `$s4main29$GreeterDefinedSystemProtocolC5greetSSyYaKFTEHF` points to `$s4main28GreeterDefinedSystemProtocolPAA11Distributed01_F9ActorStubRzrlE5greetSSyYaKFTE` which is an extension method: `distributed thunk (extension in main):main.GreeterDefinedSystemProtocol< where A: Distributed._DistributedActorStub>.greet() async throws -> Swift.String`, this very specific design allows us to call the "right method" on the recieving end of a remote call where we do not know the recipient type.
96c1266
to
a48b4f8
Compare
@swift-ci please smoke test |
1 similar comment
@swift-ci please smoke test |
a48b4f8
to
d098618
Compare
@swift-ci please smoke test |
d098618
to
746720c
Compare
@swift-ci please smoke test |
The commits are now properly staged, please check their descriptions for details.
This solves:
2a3ac44
(#77584) which was about how sometimes with generics involved or more complex type signatures of adistributed func
we'd wrongly mangle and crash during thunk mangling.Both changes go hand in hand and allow correct handling of more situations with generics and complex types in
distributed func
s