Skip to content

Commit 18bf8e0

Browse files
committed
[Distributed] Ban inout, varargs from dist funcs
1 parent a78d1bc commit 18bf8e0

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4522,6 +4522,15 @@ ERROR(distributed_actor_func_nonisolated, none,
45224522
ERROR(distributed_actor_func_private, none,
45234523
"%0 %1 cannot be 'private'",
45244524
(DescriptiveDeclKind, DeclName))
4525+
ERROR(distributed_actor_func_inout, none,
4526+
"%0 %1 cannot declare 'inout' argument %2",
4527+
(DescriptiveDeclKind, DeclName, DeclName))
4528+
ERROR(distributed_actor_func_closure, none,
4529+
"%0 %1 cannot declare closure arguments, as they cannot be serialized",
4530+
(DescriptiveDeclKind, DeclName))
4531+
ERROR(distributed_actor_func_variadic, none,
4532+
"%0 %1 cannot declare variadic argument %2",
4533+
(DescriptiveDeclKind, DeclName, DeclName))
45254534
ERROR(distributed_actor_remote_func_is_not_static,none,
45264535
"remote function %0 must be static.",
45274536
(DeclName))

lib/Sema/TypeCheckDistributed.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,23 @@ bool swift::checkDistributedFunction(FuncDecl *func, bool diagnose) {
128128
// TODO: suggest a fixit to add Codable to the type?
129129
return true;
130130
}
131+
132+
if (param->isInOut()) {
133+
param->diagnose(
134+
diag::distributed_actor_func_inout,
135+
func->getDescriptiveKind(), func->getName(),
136+
param->getName()
137+
); // TODO(distributed): offer fixit to remove 'inout'
138+
return true;
139+
}
140+
141+
if (param->isVariadic()) {
142+
param->diagnose(
143+
diag::distributed_actor_func_variadic,
144+
func->getDescriptiveKind(), func->getName(),
145+
param->getName()
146+
);
147+
}
131148
}
132149

133150
// --- Result type must be either void or a codable type

test/Distributed/distributed_actor_inference.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ distributed actor SomeDistributedActor_6 {
6868

6969
@available(SwiftStdlib 5.6, *)
7070
distributed actor SomeDistributedActor_7 {
71-
distributed func dont_1() async throws -> Int { 42 } // expected-error{{distributed function's 'dont_1' remote counterpart '_remote_dont_1' cannot not be implemented manually.}}
72-
distributed func dont_2() async throws -> Int { 42 } // expected-error{{distributed function's 'dont_2' remote counterpart '_remote_dont_2' cannot not be implemented manually.}}
73-
distributed func dont_3() async throws -> Int { 42 } // expected-error{{distributed function's 'dont_3' remote counterpart '_remote_dont_3' cannot not be implemented manually.}}
71+
distributed func dont_1() async throws -> Int { 42 } // expected-error{{distributed instance method's'dont_1' remote counterpart '_remote_dont_1' cannot not be implemented manually.}}
72+
distributed func dont_2() async throws -> Int { 42 } // expected-error{{distributed instance method's'dont_2' remote counterpart '_remote_dont_2' cannot not be implemented manually.}}
73+
distributed func dont_3() async throws -> Int { 42 } // expected-error{{distributed instance method's'dont_3' remote counterpart '_remote_dont_3' cannot not be implemented manually.}}
7474
}
7575

7676
@available(SwiftStdlib 5.6, *)

test/Distributed/distributed_actor_isolation.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ distributed actor DistributedActor_1 {
7575
fatalError()
7676
}
7777

78+
distributed func varargs(int: Int...) {
79+
// expected-error@-1{{distributed instance method 'varargs(int:)' cannot declare variadic argument 'int'}}
80+
}
81+
82+
distributed func closure(close: () -> String) {
83+
// expected-error@-1{{distributed instance method parameter 'close' of type '() -> String' does not conform to 'Codable'}}
84+
}
85+
86+
distributed func noInout(inNOut burger: inout String) {
87+
// expected-error@-1{{distributed instance method 'noInout(inNOut:)' cannot declare 'inout' argument 'burger'}}
88+
}
89+
7890
distributed func distReturnGeneric<T: Codable & Sendable>(item: T) async throws -> T { // ok
7991
item
8092
}

0 commit comments

Comments
 (0)