Skip to content

Commit 1f47442

Browse files
committed
remove restrictions on dist-actor init parameters
we will no longer require exactly one ActorSystem-conforming parameter.
1 parent d26760e commit 1f47442

File tree

4 files changed

+12
-76
lines changed

4 files changed

+12
-76
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4777,14 +4777,6 @@ ERROR(distributed_actor_func_static,none,
47774777
ERROR(distributed_actor_func_not_in_distributed_actor,none,
47784778
"'distributed' method can only be declared within 'distributed actor'",
47794779
())
4780-
ERROR(distributed_actor_designated_ctor_must_have_one_distributedactorsystem_param,none,
4781-
"designated distributed actor initializer %0 must accept exactly one "
4782-
"DistributedActorSystem parameter, found %1",
4783-
(DeclName, int))
4784-
ERROR(distributed_actor_designated_ctor_missing_transport_param,none,
4785-
"designated distributed actor initializer %0 is missing required "
4786-
"DistributedActorSystem parameter",
4787-
(DeclName))
47884780
ERROR(distributed_actor_user_defined_special_property,none,
47894781
"property %0 cannot be defined explicitly, as it conflicts with "
47904782
"distributed actor synthesized stored property",

lib/Sema/TypeCheckDistributed.cpp

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -595,47 +595,6 @@ void swift::checkDistributedActorProperties(const NominalTypeDecl *decl) {
595595
}
596596
}
597597

598-
void swift::checkDistributedActorConstructor(const ClassDecl *decl, ConstructorDecl *ctor) {
599-
// bail out unless distributed actor, only those have special rules to check here
600-
if (!decl->isDistributedActor())
601-
return;
602-
603-
// Only designated initializers need extra checks
604-
if (!ctor->isDesignatedInit())
605-
return;
606-
607-
// === Designated initializers must accept exactly one actor transport that
608-
// matches the actor transport type of the actor.
609-
SmallVector<ParamDecl*, 2> transportParams;
610-
int transportParamsCount = 0;
611-
Type actorSystemTy = ctor->mapTypeIntoContext(
612-
getDistributedActorSystemType(const_cast<ClassDecl *>(decl)));
613-
for (auto param : *ctor->getParameters()) {
614-
auto paramTy = ctor->mapTypeIntoContext(param->getInterfaceType());
615-
if (paramTy->isEqual(actorSystemTy)) {
616-
transportParamsCount += 1;
617-
transportParams.push_back(param);
618-
}
619-
}
620-
621-
// missing transport parameter
622-
if (transportParamsCount == 0) {
623-
ctor->diagnose(diag::distributed_actor_designated_ctor_missing_transport_param,
624-
ctor->getName());
625-
// TODO(distributed): offer fixit to insert 'system: DistributedActorSystem'
626-
return;
627-
}
628-
629-
// ok! We found exactly one transport parameter
630-
if (transportParamsCount == 1)
631-
return;
632-
633-
// TODO(distributed): rdar://81824959 report the error on the offending (2nd) matching parameter
634-
// Or maybe we can issue a note about the other offending params?
635-
ctor->diagnose(diag::distributed_actor_designated_ctor_must_have_one_distributedactorsystem_param,
636-
ctor->getName(), transportParamsCount);
637-
}
638-
639598
// ==== ------------------------------------------------------------------------
640599

641600
void TypeChecker::checkDistributedActor(SourceFile *SF, NominalTypeDecl *nominal) {
@@ -653,14 +612,6 @@ void TypeChecker::checkDistributedActor(SourceFile *SF, NominalTypeDecl *nominal
653612
(void)nominal->getDefaultInitializer();
654613

655614
for (auto member : nominal->getMembers()) {
656-
// --- Check all constructors
657-
if (auto ctor = dyn_cast<ConstructorDecl>(member)) {
658-
if (auto classDecl = dyn_cast<ClassDecl>(nominal)) {
659-
checkDistributedActorConstructor(classDecl, ctor);
660-
continue;
661-
}
662-
}
663-
664615
// --- Ensure all thunks
665616
if (auto func = dyn_cast<AbstractFunctionDecl>(member)) {
666617
if (!func->isDistributed())

lib/Sema/TypeCheckDistributed.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ bool ensureDistributedModuleLoaded(Decl *decl);
4040
/// Check for illegal property declarations (e.g. re-declaring transport or id)
4141
void checkDistributedActorProperties(const NominalTypeDecl *decl);
4242

43-
/// The local and resolve distributed actor constructors have special rules to check.
44-
void checkDistributedActorConstructor(const ClassDecl *decl, ConstructorDecl *ctor);
45-
4643
/// Type-check additional ad-hoc protocol requirements.
4744
/// Ad-hoc requirements are protocol requirements currently not expressible
4845
/// in the Swift type-system.

test/Distributed/distributed_actor_initialization.swift

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,33 @@ distributed actor OK1 {
1919
// ok, since all fields are initialized, the constructor can be synthesized
2020
}
2121

22-
// TODO(distributed): test all the FIXITs in this file
22+
distributed actor OK2 {
23+
var x: Int
2324

24-
distributed actor Bad1 {
25-
init() {
26-
// expected-error@-1 {{designated distributed actor initializer 'init()' is missing required DistributedActorSystem parameter}}
25+
init(x: Int, system: FakeActorSystem) { // ok
26+
self.x = x
2727
}
2828
}
2929

30-
distributed actor Bad12 {
31-
init(x: String) {
32-
// expected-error@-1 {{designated distributed actor initializer 'init(x:)' is missing required DistributedActorSystem parameter}}
33-
}
30+
// NOTE: keep in mind this is only through typechecking, so no explicit
31+
// actorSystem is being assigned here.
32+
distributed actor OK3 {
33+
init() {}
3434
}
3535

36-
distributed actor OK2 {
37-
var x: Int
38-
39-
init(x: Int, system: FakeActorSystem) { // ok
40-
self.x = x
36+
distributed actor OK4 {
37+
init(x: String) {
4138
}
4239
}
4340

44-
distributed actor Bad2 {
41+
distributed actor OK5 {
4542
var x: Int = 1
4643

4744
init(system: FakeActorSystem, too many: FakeActorSystem) {
48-
// expected-error@-1{{designated distributed actor initializer 'init(system:too:)' must accept exactly one DistributedActorSystem parameter, found 2}}
4945
}
5046
}
5147

52-
distributed actor OK3 {
48+
distributed actor OK6 {
5349
var x: Int
5450

5551
init(y: Int, system: FakeActorSystem) {

0 commit comments

Comments
 (0)