Skip to content

Commit f2d60e1

Browse files
committed
[Distributed] add note explaining DefaultDistributedActorSystem
1 parent d42593a commit f2d60e1

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4496,11 +4496,12 @@ ERROR(actor_protocol_illegal_inheritance,none,
44964496
"non-actor type %0 cannot conform to the 'Actor' protocol",
44974497
(DeclName))
44984498
ERROR(distributed_actor_conformance_missing_system_type,none,
4499-
"distributed actor %0 does not declare ActorSystem it can be used with. "
4500-
"Declare the associated actor system with a 'typealias ActorSystem = MyActorSystem' "
4501-
"inside the actor, or module-wide by declaring a global 'typealias "
4502-
"DefaultDistributedActorSystem = MyActorSystem'.",
4499+
"distributed actor %0 does not declare ActorSystem it can be used with.",
45034500
(DeclName))
4501+
NOTE(note_distributed_actor_system_can_be_defined_using_defaultdistributedactorsystem,none,
4502+
"you can provide a module-wide default actor system by declaring:\n"
4503+
"typealias DefaultDistributedActorSystem = <#ConcreteActorSystem#>\n",
4504+
())
45044505
ERROR(distributed_actor_protocol_illegal_inheritance,none,
45054506
"non-distributed actor type %0 cannot conform to the 'DistributedActor' protocol",
45064507
(DeclName))

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "swift/AST/AccessScope.h"
3030
#include "swift/AST/ClangModuleLoader.h"
3131
#include "swift/AST/Decl.h"
32+
#include "swift/AST/DistributedDecl.h"
3233
#include "swift/AST/Effects.h"
3334
#include "swift/AST/ExistentialLayout.h"
3435
#include "swift/AST/GenericEnvironment.h"
@@ -5486,17 +5487,13 @@ void swift::diagnoseConformanceFailure(Type T,
54865487
return;
54875488

54885489
// If it is missing the ActorSystem type, suggest adding it:
5489-
// FIXME(distributed): use getDistributedActorSystemType(nominal); once merged
5490-
auto &C = nominal->getASTContext();
5491-
auto DA = C.getDistributedActorDecl();
5492-
Type selfType = nominal->getSelfInterfaceType();
5493-
auto conformance = nominal->getParentModule()->lookupConformance(selfType, DA);
5494-
auto systemTy = conformance.getTypeWitnessByName(selfType, C.Id_ActorSystem);
5495-
5490+
auto systemTy = getDistributedActorSystemType(/*actor=*/nominal);
54965491
if (!systemTy || systemTy->hasError()) {
54975492
diags.diagnose(ComplainLoc,
54985493
diag::distributed_actor_conformance_missing_system_type,
54995494
nominal->getName());
5495+
diags.diagnose(nominal->getStartLoc(),
5496+
diag::note_distributed_actor_system_can_be_defined_using_defaultdistributedactorsystem);
55005497
return;
55015498
}
55025499
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-swift-frontend -typecheck -verify -enable-experimental-distributed -disable-availability-checking -I %t 2>&1 %s
2+
3+
// UNSUPPORTED: back_deploy_concurrency
4+
// REQUIRES: concurrency
5+
// REQUIRES: distributed
6+
7+
import _Distributed
8+
9+
distributed actor DA {
10+
// expected-error@-1{{distributed actor 'DA' does not declare ActorSystem it can be used with.}}
11+
12+
// expected-note@-3{{you can provide a module-wide default actor system by declaring:}}
13+
14+
// Note to add the typealias is diagnosed on the protocol:
15+
// _Distributed.DistributedActor:3:20: note: diagnostic produced elsewhere: protocol requires nested type 'ActorSystem'; do you want to add it?
16+
}

0 commit comments

Comments
 (0)