-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[Sema] Fix and cleanup distributed id/actorSystem synthesis
#85245
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
a2e17a7 to
8dea46d
Compare
id/actorSystem synthesis
09b4f75 to
996f65a
Compare
|
Thanks, @hamishknight! I will take a look on Monday. |
996f65a to
02a1d6b
Compare
02a1d6b to
6a905fc
Compare
|
Thanks a lot Hamish! Looks promising, I'll do a proper review and also verify on some projects, thank you! |
And use this in `evaluateMembersRequest`.
Avoid relying on the cycle detection logic to exclude these and enforce that we never consider them since computing their interface type relies on the type witnesses already being resolved. This also means we can no longer pick up Identifiable's default implementation `id`, which we never want for a `distributed` actor. This then lets us remove the special-cased eager inference logic.
…Request` This is checking a conformance for something defined in the Distributed module itself, so things would be very broken if it failed.
…ystemOfActor` Make sure we produce an error for a broken stdlib and produce ErrorType instead.
These can be inlined into their respective requests.
Have the witness derivation logic call into the synthesis requests.
Only fallback to name lookup for serialized modules and swift interfaces. This means we can then implement the user-declared `id`/`actorSystem` error as part of redeclaration checking.
Delay their interface type computation until they are actually type-checked. This ensures their synthesis logic doesn't produce cycles.
Now that the synthesis logic for these doesn't involve kicking semantic requests we can synthesize directly as part of name lookup. This ensures they get synthesized for secondaries and we don't try and use Identifiable's default `id`. rdar://162800185
This shouldn't be necessary anymore since we we'll no longer try to infer `ID` from Identifiable's default implmentation of `id`.
The member names that triggered this don't even match the requirements in the Distributed module anymore, and `installDistributedActorIfNecessary` was only called for structs which can't be distributed actors. Rip it out.
6a905fc to
5aa0a74
Compare
|
Noticed we could replace a couple more checks for |
d5eb1b2 to
3bc7e5b
Compare
Use `isSpecialDistributedProperty` or the synthesis requests instead. While here, also make `isSpecialDistributedProperty` agnostic to interface and serialized module cases.
3bc7e5b to
965e85f
Compare
|
@swift-ci please test |
|
@swift-ci please test source compatibility |
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.
Excellent, thank you!
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.
Thank you, I also confirmed in an adopter project this solves the issue!
| bool *wouldConflictInSwift5 = nullptr, | ||
| bool skipProtocolExtensionCheck = false); | ||
|
|
||
| enum class SpecialDistributedProperty { |
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.
minor:
| enum class SpecialDistributedProperty { | |
| enum class SpecialDistributedActorProperty { |
Just to that it's clearer that we mean specifically properties of a distributed actor; (a "distributed property" exists and is distributed var {} but that's different)
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.
I'll do a follow up with a rename, we can merge this as is.
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.
I went ahead and fixed this in #85309 since there were a couple of other things I also noticed
| nonisolated var actorSystem: DefaultDistributedActorSystem { fatalError() } | ||
| // expected-error@-1 {{property 'actorSystem' cannot be defined explicitly, as it conflicts with distributed actor synthesized stored property}} | ||
| // expected-note@-2 {{candidate exactly matches}} | ||
| } |
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.
nice catch, thank you
| import Distributed | ||
|
|
||
| func foo<T: DistributedActor>(_: T.Type) where T.ActorSystem == LocalTestingDistributedActorSystem {} | ||
| func bar() { foo(A.self) } |
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.
Hmm, this doesn't quite reproduce rdar://162800185;
This works fine on existing main already, so we're missing something here
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.
Now it does, we chatted offline :-)
| // but the id synthesis will force itself to be FIRST anyway, so it works out. | ||
| nominal->addMember(propDecl, /*hint=*/idProperty, insertAtHead); | ||
| nominal->addMember(pbDecl, /*hint=*/idProperty, insertAtHead); | ||
| return propDecl; |
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.
Thanks, this refactor to requests is neat, and we keep the ordering guarantee nicely this way too
[Sema] A couple of minor follow-ups to #85245
associatedtypeinference never considersidandactorSystemproperties for a distributed actor since doing so would either result in cycles or resolving usingIdentifiable's defaultididandactorSystemfor a distributed actor, allowing redeclaration checking to diagnose user-defined versionsidandactorSystem, ensuring the synthesis logic doesn't kick semantic requestsidandactorSystemas part ofsynthesizeSemanticMembersIfNeededto ensure they're always injected into name lookup results (this is the actual fix for rdar://162800185)Identifiablederivation code andImplicitMemberAction::ResolveDistributedActor, neither of which should be necessary nowrdar://162800185