Skip to content

[Distributed] ID synthesis must be eager, or we run into issues in real projects #42136

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
Apr 4, 2022

Conversation

ktoso
Copy link
Contributor

@ktoso ktoso commented Apr 1, 2022

Without this, in real, multi module, multi file, projects we end up with issues as follows:

Greeter.swift:9:19: error: type 'Greeter' does not conform to protocol 'DistributedActor'
distributed actor Greeter {
                  ^
Greeter.swift:9:19: error: 'DistributedActor' requires the types 'ObjectIdentifier' and 'BonjourActorSystem.ActorID' (aka 'ActorIdentity') be equivalent
distributed actor Greeter {
                  ^
Greeter.swift:9:19: note: requirement specified as 'Self.ID' == 'Self.ActorSystem.ActorID' [with Self = Greeter]
distributed actor Greeter {
                  ^
Greeter.swift:9:19: error: protocol 'DistributedActor' is broken; cannot derive conformance for type 'Greeter'
distributed actor Greeter {
                  ^

From debugging it seems that the reason is that the resolve by lookup triggers early and determines that the ID shall be taken from the extension Identifiable { var id: ObjectIdentifier {...} } and only then other synthesis is run.

In order to avoid such mixups, we can be eager about the ID type synthesis.

This is limited to distributed actor decls, because in all other cases the default would be right and follow the usual rules, but because we synthesize the ActorSystem typealias and ID types later on, things got tricky here.

If there is a cleaner way to do this I'd happily revisit but this seems not to terrible for now at least and unbreaks projects.

Resolves rdar://91020060

@ktoso ktoso requested review from xedin, kavon and DougGregor April 1, 2022 09:26
@ktoso ktoso force-pushed the wip-identifiable-synthesis-fix branch from a329289 to c889513 Compare April 1, 2022 09:47
@ktoso
Copy link
Contributor Author

ktoso commented Apr 1, 2022

@swift-ci please smoke test

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.

Makes sense to me! Could you please add a couple more test cases with protocol that conform to a DistributedActor to make sure that fetching of the ActorSystem and other bits work correctly for that case too?

@ktoso
Copy link
Contributor Author

ktoso commented Apr 1, 2022

Good idea, I actually don't do synthesis there but I guess I should maybe? Will think about it, thanks!

@ktoso
Copy link
Contributor Author

ktoso commented Apr 4, 2022

@swift-ci please smoke test and merge

@ktoso
Copy link
Contributor Author

ktoso commented Apr 4, 2022

Poked around a bit but protocols should not be impacted at all 👍

@ktoso ktoso added the distributed Feature → concurrency: distributed actor label Apr 4, 2022
@xedin
Copy link
Contributor

xedin commented Apr 4, 2022

Sounds good!

@ktoso
Copy link
Contributor Author

ktoso commented Apr 4, 2022

@swift-ci please smoke test and merge

CI stuck again...

@swift-ci swift-ci merged commit 6af7324 into swiftlang:main Apr 4, 2022
@ktoso ktoso deleted the wip-identifiable-synthesis-fix branch April 5, 2022 02:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
distributed Feature → concurrency: distributed actor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants