Skip to content

[6.1][Distributed] Protocol mangling and primary associated type fixes #77895

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 7 commits into from
Dec 4, 2024

Conversation

ktoso
Copy link
Contributor

@ktoso ktoso commented Dec 2, 2024

6.1 pick for #77584

Description: Distributed accessible function record mangling was too naively just using "$" + "Name" + "C" when recording protocol calls in order to point at the stub type ($NameC for Name). This breaks roundtrip mangling when more complex types are involved, like arrays or more generics as the mangling must be made properly with the class ($Name) decl context. This change makes the mangling proper and also fixes how we deal with primary associated types in these protocols (which would also crash without this change).

Scope/Impact: Low, only distributed method accessors of previously crashing shape are addressed.
Risk: Low, only distributed accessors are affected. No impact to other modules.
Testing: CI testing; Added tests which previously blew up and are now working correctly
Reviewed by: @xedin

Original PR: #77584
Radar: rdar://139332556&139781083


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

ktoso added 6 commits December 2, 2024 23:03
…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.
@ktoso ktoso requested a review from a team as a code owner December 2, 2024 14:05
@ktoso ktoso changed the title [Distributed] @resolvable now handles primary associated types in pro… [6.1][Distributed] @resolvable now handles primary associated types in protocols Dec 2, 2024
@ktoso ktoso added distributed Feature → concurrency: distributed actor 🍒 release cherry pick Flag: Release branch cherry picks swift 6.1 labels Dec 2, 2024
@ktoso
Copy link
Contributor Author

ktoso commented Dec 2, 2024

@swift-ci please test

@ktoso ktoso changed the title [6.1][Distributed] @resolvable now handles primary associated types in protocols [6.1][Distributed] Fix edge cases of mangling of distributed methods in protocols Dec 3, 2024
@ktoso
Copy link
Contributor Author

ktoso commented Dec 3, 2024

@swift-ci please build toolchain

@ktoso ktoso changed the title [6.1][Distributed] Fix edge cases of mangling of distributed methods in protocols [6.1][Distributed] Resolve crashes in mangling methods in resolvable protocols and enable primary associatedtypes Dec 4, 2024
@ktoso ktoso changed the title [6.1][Distributed] Resolve crashes in mangling methods in resolvable protocols and enable primary associatedtypes [6.1][Distributed] Protocol mangling and primary associated type fixes Dec 4, 2024
@ktoso
Copy link
Contributor Author

ktoso commented Dec 4, 2024

Added some review followup

@ktoso
Copy link
Contributor Author

ktoso commented Dec 4, 2024

@swift-ci please test

@ktoso ktoso enabled auto-merge December 4, 2024 06:22
@ktoso ktoso merged commit e1af48e into swiftlang:release/6.1 Dec 4, 2024
5 checks passed
@ktoso ktoso deleted the pick-dist-mangling-fixes branch December 4, 2024 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
distributed Feature → concurrency: distributed actor 🍒 release cherry pick Flag: Release branch cherry picks swift 6.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants