Skip to content

[Distributed] decode init for DistributedActor #38998

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 3 commits into from
Aug 24, 2021

Conversation

ktoso
Copy link
Contributor

@ktoso ktoso commented Aug 23, 2021

resolves rdar://70858677 by implementing the init(from:) Decodable bit in AST for the distributed actor protocol.

We're actually able to implement this in AST but only because of the note below. It would be a pain to implement in SIL and I think we should move forward with proposing the below feature as SE anyway.


Note:

This needed to enable the self = ... assignment in specifically this single initializer so we can unblock our progress here for now; The general concept we could enable in general and @jckarter worked on this before here:

This was discussed a few years ago and deserves it's own Swift Evolution proposal to enable "in general": https://forums.swift.org/t/allow-self-x-in-class-convenience-initializers/15924

@ktoso ktoso requested review from jckarter and slavapestov and removed request for jckarter August 23, 2021 16:42
selfAccess = SelfAccessKind::Mutating;
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

so this only is enabled specifically for this single initializer in distributed actors; at least until we do an SE pitch for it.

onlyUseIsValueMetatype = false;
break;
}
if (onlyUseIsValueMetatype) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only other bit we need to enable this AFAIK

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is lifted directly from [awaiting evolution] Allow convenience initializers to reassign self. #19311

@available(SwiftStdlib 5.5, *)
static let actorTransportKey = CodingUserInfoKey(rawValue: "$dist_act_transport")!
@available(SwiftStdlib 5.5, *)
public static let actorTransportKey = CodingUserInfoKey(rawValue: "$dist_act_transport")!
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was a nasty omission! made sample apps impossible.

}

let id: AnyActorIdentity = try transport.decodeIdentity(from: decoder)
self = try Self.resolve(id, using: transport)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason why we need the initializer semantics change.

@@ -121,12 +126,14 @@ public protocol ActorIdentity: Sendable, Hashable, Codable {}

@available(SwiftStdlib 5.5, *)
public struct AnyActorIdentity: ActorIdentity, @unchecked Sendable, CustomStringConvertible {
public let underlying: Any
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is important, impls need to be able to reach this.

@ktoso
Copy link
Contributor Author

ktoso commented Aug 23, 2021

@swift-ci please smoke test

@ktoso
Copy link
Contributor Author

ktoso commented Aug 23, 2021

@swift-ci please build toolchain

@swift-ci
Copy link
Contributor

Linux Toolchain (Ubuntu 16.04)
Download Toolchain
Git Sha - e38afc5374b87f78bafe5aa3cb68a7118aa801b6

Install command
tar zxf swift-PR-38998-648-ubuntu16.04.tar.gz
More info

@ktoso
Copy link
Contributor Author

ktoso commented Aug 23, 2021

TODO: SILOptimizer/definite_init_value_types_diagnostics.swift

@ktoso ktoso force-pushed the wip-ktoso-assign-self-decode branch 2 times, most recently from 1e69600 to c9a4614 Compare August 23, 2021 23:55
@ktoso ktoso added the distributed Feature → concurrency: distributed actor label Aug 23, 2021
@ktoso
Copy link
Contributor Author

ktoso commented Aug 24, 2021

Ok excellent, this works without any changes in DI actually. So it is fully isolated to the specific distributed actor initializer, therefore - going ahead with merging.

@ktoso ktoso force-pushed the wip-ktoso-assign-self-decode branch from c6da297 to 6fe7f1f Compare August 24, 2021 04:58
@ktoso
Copy link
Contributor Author

ktoso commented Aug 24, 2021

@swift-ci please smoke test

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.

2 participants