Skip to content

[Distributed] Report error rather than crash no ad-hoc requirements are implemented #66020

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/Sema/DerivedConformanceDistributedActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ bool DerivedConformance::canDeriveDistributedActor(
bool DerivedConformance::canDeriveDistributedActorSystem(
NominalTypeDecl *nominal, DeclContext *dc) {
auto &C = nominal->getASTContext();

// Make sure ad-hoc requirements that we'll use in synthesis are present, before we try to use them.
// This leads to better error reporting because we already have errors happening (missing witnesses).
if (auto handlerType = getDistributedActorSystemResultHandlerType(nominal)) {
if (!C.getOnReturnOnDistributedTargetInvocationResultHandler(
handlerType->getAnyNominal()))
return false;
}

return C.getLoadedModule(C.Id_Distributed);
}

Expand Down
39 changes: 39 additions & 0 deletions test/Distributed/distributed_imcomplete_system_dont_crash.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -typecheck -verify -disable-availability-checking 2>&1 %s
// REQUIRES: concurrency
// REQUIRES: distributed

import Distributed

public final class CompletelyHollowActorSystem: DistributedActorSystem {
// expected-error@-1{{type 'CompletelyHollowActorSystem' does not conform to protocol 'DistributedActorSystem'}}
// expected-note@-2{{protocol 'DistributedActorSystem' requires function 'remoteCallVoid' with signature:}}
// expected-error@-3{{class 'CompletelyHollowActorSystem' is missing witness for protocol requirement 'remoteCall'}}
// expected-note@-4{{protocol 'DistributedActorSystem' requires function 'remoteCall' with signature:}}
// expected-error@-5{{class 'CompletelyHollowActorSystem' is missing witness for protocol requirement 'remoteCallVoid'}}

public typealias ActorID = String
public typealias InvocationEncoder = Encoder
// expected-note@-1{{possibly intended match 'CompletelyHollowActorSystem.InvocationEncoder' (aka 'CompletelyHollowActorSystem.Encoder') does not conform to 'DistributedTargetInvocationEncoder'}}
public typealias InvocationDecoder = Decoder
// expected-note@-1{{possibly intended match 'CompletelyHollowActorSystem.InvocationDecoder' (aka 'CompletelyHollowActorSystem.Decoder') does not conform to 'DistributedTargetInvocationDecoder'}}

public typealias SerializationRequirement = Codable

public func actorReady<Act>(_ actor: Act) where Act : DistributedActor, ActorID == Act.ID {

}

public struct Encoder: InvocationEncoder {

}

public struct Decoder: InvocationDecoder {

}

public struct ResultHandler: DistributedTargetInvocationResultHandler {
// expected-error@-1{{type 'CompletelyHollowActorSystem.ResultHandler' does not conform to protocol 'DistributedTargetInvocationResultHandler'}}
}

}