-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Distributed] Only synthesize Codable for DA where the ID is Codable #72081
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1043,3 +1043,29 @@ NormalProtocolConformance *GetDistributedActorImplicitCodableRequest::evaluate( | |
return addDistributedActorCodableConformance(classDecl, | ||
C.getProtocol(protoKind)); | ||
} | ||
|
||
bool CanSynthesizeDistributedActorCodableConformanceRequest::evaluate( | ||
Evaluator &evaluator, NominalTypeDecl *actor) const { | ||
|
||
if (actor && !isa<ClassDecl>(actor)) | ||
return false; | ||
|
||
if (!actor->isDistributedActor()) | ||
return false; | ||
|
||
auto systemTy = getConcreteReplacementForProtocolActorSystemType(actor); | ||
if (!systemTy) | ||
return false; | ||
|
||
if (!systemTy->getAnyNominal()) | ||
return false; | ||
|
||
auto idTy = getDistributedActorSystemActorIDType(systemTy->getAnyNominal()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actor system doesn't have to be a concrete nominal type for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, I'll add a test like that and cover it. Same type requirement should be the case you're mentioning yeah There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Heh weirdly enough facing term verification crashes that I don't quite understand when trying to use the |
||
if (!idTy) | ||
return false; | ||
|
||
return TypeChecker::conformsToKnownProtocol( | ||
idTy, KnownProtocolKind::Decodable, actor->getParentModule()) && | ||
TypeChecker::conformsToKnownProtocol( | ||
idTy, KnownProtocolKind::Encodable, actor->getParentModule()); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// RUN: %empty-directory(%t) | ||
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -disable-availability-checking %S/Inputs/FakeDistributedActorSystems.swift | ||
// RUN: %target-swift-frontend -typecheck -verify -disable-availability-checking -I %t 2>&1 %s | ||
// REQUIRES: concurrency | ||
// REQUIRES: distributed | ||
|
||
import Distributed | ||
import FakeDistributedActorSystems | ||
|
||
distributed actor YesVeryMuchSo { | ||
typealias ActorSystem = FakeRoundtripActorSystem | ||
} | ||
func test_YesVeryMuchSo(_ actor: YesVeryMuchSo) { | ||
let _: any Codable = actor // implicit conformance, ID was Codable | ||
|
||
// unrelated protocol | ||
let _: any CustomSerializationProtocol = actor // expected-error{{value of type 'YesVeryMuchSo' does not conform to specified type 'CustomSerializationProtocol'}} | ||
} | ||
|
||
// ==== ------------------------------------------------------------------------ | ||
|
||
distributed actor SerReqNotCodable { | ||
typealias ActorSystem = FakeCustomSerializationRoundtripActorSystem | ||
} | ||
func test_NotAtAll_NoImplicit(_ actor: SerReqNotCodable) { | ||
let _: any Codable = actor // OK, the ID was Codable, even though SerializationRequirement was something else | ||
|
||
// no implicit conformance | ||
let _: any CustomSerializationProtocol = actor // expected-error{{value of type 'SerReqNotCodable' does not conform to specified type 'CustomSerializationProtocol'}} | ||
} | ||
|
||
// ==== ------------------------------------------------------------------------ | ||
|
||
distributed actor NotAtAll_NothingCodable { | ||
typealias ActorSystem = FakeIdIsNotCodableActorSystem | ||
} | ||
func test_NotAtAll_NoImplicit(_ actor: NotAtAll_NothingCodable) { | ||
let _: any Codable = actor // expected-error{{value of type 'NotAtAll_NothingCodable' does not conform to specified type 'Decodable'}} | ||
|
||
// no implicit conformance | ||
let _: any CustomSerializationProtocol = actor // expected-error{{value of type 'NotAtAll_NothingCodable' does not conform to specified type 'CustomSerializationProtocol'}} | ||
} | ||
|
||
public struct NotCodableID: Sendable, Hashable {} | ||
|
||
@available(SwiftStdlib 5.7, *) | ||
public struct FakeIdIsNotCodableActorSystem: DistributedActorSystem, CustomStringConvertible { | ||
public typealias ActorID = NotCodableID | ||
public typealias InvocationDecoder = FakeInvocationDecoder | ||
public typealias InvocationEncoder = FakeInvocationEncoder | ||
public typealias SerializationRequirement = Codable | ||
public typealias ResultHandler = FakeRoundtripResultHandler | ||
|
||
// just so that the struct does not become "trivial" | ||
let someValue: String = "" | ||
let someValue2: String = "" | ||
let someValue3: String = "" | ||
let someValue4: String = "" | ||
|
||
public init() { | ||
} | ||
|
||
public func resolve<Act>(id: ActorID, as actorType: Act.Type) throws -> Act? | ||
where Act: DistributedActor, | ||
Act.ID == ActorID { | ||
nil | ||
} | ||
|
||
public func assignID<Act>(_ actorType: Act.Type) -> ActorID | ||
where Act: DistributedActor, | ||
Act.ID == ActorID { | ||
.init() | ||
} | ||
|
||
public func actorReady<Act>(_ actor: Act) | ||
where Act: DistributedActor, | ||
Act.ID == ActorID { | ||
} | ||
|
||
public func resignID(_ id: ActorID) { | ||
} | ||
|
||
public func makeInvocationEncoder() -> InvocationEncoder { | ||
.init() | ||
} | ||
|
||
public func remoteCall<Act, Err, Res>( | ||
on actor: Act, | ||
target: RemoteCallTarget, | ||
invocation invocationEncoder: inout InvocationEncoder, | ||
throwing: Err.Type, | ||
returning: Res.Type | ||
) async throws -> Res | ||
where Act: DistributedActor, | ||
Act.ID == ActorID, | ||
Err: Error, | ||
Res: SerializationRequirement { | ||
throw ExecuteDistributedTargetError(message: "\(#function) not implemented.") | ||
} | ||
|
||
public func remoteCallVoid<Act, Err>( | ||
on actor: Act, | ||
target: RemoteCallTarget, | ||
invocation invocationEncoder: inout InvocationEncoder, | ||
throwing: Err.Type | ||
) async throws | ||
where Act: DistributedActor, | ||
Act.ID == ActorID, | ||
Err: Error { | ||
throw ExecuteDistributedTargetError(message: "\(#function) not implemented.") | ||
} | ||
|
||
public nonisolated var description: Swift.String { | ||
"\(Self.self)()" | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.