Skip to content

Commit f58b133

Browse files
committed
[Distributed] adjust conformance error messages a bit
1 parent fcd93a5 commit f58b133

14 files changed

+64
-49
lines changed

include/swift/AST/DiagnosticsSema.def

+9-6
Original file line numberDiff line numberDiff line change
@@ -4363,7 +4363,7 @@ NOTE(note_add_distributed_to_decl,none,
43634363
"add 'distributed' to %0 to make this %1 witness the protocol requirement",
43644364
(DeclName, DescriptiveDeclKind))
43654365
NOTE(note_distributed_requirement_defined_here,none,
4366-
"distributed function requirement %0 declared here",
4366+
"distributed instance method requirement %0 declared here",
43674367
(DeclName))
43684368
NOTE(note_add_globalactor_to_function,none,
43694369
"add '@%0' to make %1 %2 part of global actor %3",
@@ -4502,13 +4502,13 @@ NOTE(note_distributed_actor_isolated_method,none,
45024502
"distributed actor-isolated %0 %1 declared here",
45034503
(DescriptiveDeclKind, DeclName))
45044504
ERROR(distributed_actor_isolated_method,none,
4505-
"only 'distributed' functions can be called on a potentially remote distributed actor",
4505+
"only 'distributed' instance methods can be called on a potentially remote distributed actor",
45064506
())
45074507
ERROR(distributed_actor_func_param_not_codable,none,
4508-
"distributed function parameter '%0' of type %1 does not conform to 'Codable'",
4508+
"distributed instance method parameter '%0' of type %1 does not conform to 'Codable'",
45094509
(StringRef, Type))
45104510
ERROR(distributed_actor_func_result_not_codable,none,
4511-
"distributed function result type %0 does not conform to 'Codable'",
4511+
"distributed instance method result type %0 does not conform to 'Codable'",
45124512
(Type))
45134513
ERROR(distributed_actor_remote_func_implemented_manually,none,
45144514
"distributed function's %0 remote counterpart %1 cannot not be implemented manually.",
@@ -4519,6 +4519,9 @@ ERROR(nonisolated_distributed_actor_storage,none,
45194519
ERROR(distributed_actor_func_nonisolated, none,
45204520
"function %0 cannot be both 'nonisolated' and 'distributed'",
45214521
(DeclName))
4522+
ERROR(distributed_actor_func_private, none,
4523+
"%0 %1 cannot be 'private'",
4524+
(DescriptiveDeclKind, DeclName))
45224525
ERROR(distributed_actor_remote_func_is_not_static,none,
45234526
"remote function %0 must be static.",
45244527
(DeclName))
@@ -4628,7 +4631,7 @@ ERROR(actor_instance_property_wrapper,none,
46284631
(Identifier, Identifier))
46294632

46304633
ERROR(distributed_actor_func_defined_outside_of_distributed_actor,none,
4631-
"distributed function %0 is declared outside of an distributed actor",
4634+
"distributed instance method %0 is declared outside of an distributed actor",
46324635
(DeclName))
46334636
ERROR(distributed_actor_local_var,none,
46344637
"'distributed' can not be applied to local variables",
@@ -4648,7 +4651,7 @@ ERROR(distributed_actor_not_actor_func,none,
46484651
"'distributed' can only be applied to distributed actor async functions",
46494652
())
46504653
ERROR(distributed_actor_func_static,none,
4651-
"'distributed' functions cannot be 'static'",
4654+
"'distributed' method cannot be 'static'",
46524655
())
46534656
ERROR(distributed_actor_func_not_in_distributed_actor,none,
46544657
"'distributed' function can only be declared within 'distributed actor'",

include/swift/AST/Expr.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -4367,7 +4367,7 @@ class ApplyExpr : public Expr {
43674367
/// Is this application _implicitly_ required to be a throwing call?
43684368
/// This can happen if the function is actually a proxy function invocation,
43694369
/// which may throw, regardless of the target function throwing, e.g.
4370-
/// a distributed function call on a 'remote' actor, may throw due to network
4370+
/// a distributed instance method call on a 'remote' actor, may throw due to network
43714371
/// issues reported by the transport, regardless if the actual target function
43724372
/// can throw.
43734373
bool implicitlyThrows() const {

lib/AST/Decl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ StringRef Decl::getDescriptiveKindName(DescriptiveDeclKind K) {
324324
ENTRY(Method, "instance method");
325325
ENTRY(StaticMethod, "static method");
326326
ENTRY(ClassMethod, "class method");
327-
ENTRY(DistributedMethod, "distributed method");
327+
ENTRY(DistributedMethod, "distributed instance method");
328328
ENTRY(Getter, "getter");
329329
ENTRY(Setter, "setter");
330330
ENTRY(WillSet, "willSet observer");

lib/SILGen/SILGenDistributed.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ void SILGenFunction::emitDistributedThunk(SILDeclRef thunk) {
599599
B.emitBlock(isRemoteBB);
600600

601601
auto *selfTyDecl = FunctionDC->getParent()->getSelfNominalTypeDecl();
602-
assert(selfTyDecl && "distributed function declared outside of actor");
602+
assert(selfTyDecl && "distributed instance method declared outside of actor");
603603

604604
auto remoteFnDecl = selfTyDecl->lookupDirectRemoteFunc(fd);
605605
assert(remoteFnDecl && "Could not find _remote_<dist_func_name> function");

lib/Sema/CodeSynthesisDistributedActor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ static AbstractFunctionDecl *addImplicitDistributedActorRemoteFunction(
179179
new (C) NonisolatedAttr(/*IsImplicit=*/true));
180180

181181
// users should never have to access this function directly;
182-
// it is only invoked from our distributed function thunk if the actor is remote.
182+
// it is only invoked from our distributed instance method thunk if the actor is remote.
183183
remoteFuncDecl->setUserAccessible(false);
184184
remoteFuncDecl->setSynthesized();
185185

lib/Sema/TypeCheckDistributed.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ bool swift::checkDistributedFunction(FuncDecl *func, bool diagnose) {
107107

108108
auto module = func->getParentModule();
109109

110+
if (func->getEffectiveAccess() == AccessLevel::FilePrivate) {
111+
func->diagnose(diag::distributed_actor_func_private,
112+
func->getDescriptiveKind(), func->getName());
113+
// TODO(distributed): fixit remove the 'private' from the declaration
114+
return true;
115+
}
116+
110117
// --- Check parameters for 'Codable' conformance
111118
for (auto param : *func->getParameters()) {
112119
auto paramTy = func->mapTypeIntoContext(param->getInterfaceType());
@@ -142,7 +149,7 @@ bool swift::checkDistributedFunction(FuncDecl *func, bool diagnose) {
142149
auto actorDecl = func->getParent()->getSelfNominalTypeDecl();
143150
assert(actorDecl && actorDecl->isDistributedActor());
144151

145-
// _remote function for a distributed function must not be implemented by end-users,
152+
// _remote function for a distributed instance method must not be implemented by end-users,
146153
// it must be the specific implementation synthesized by the compiler.
147154
auto remoteFuncDecl = actorDecl->lookupDirectRemoteFunc(func);
148155
if (remoteFuncDecl && !remoteFuncDecl->isSynthesized()) {

lib/Sema/TypeCheckProtocol.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -2873,7 +2873,7 @@ bool ConformanceChecker::checkActorIsolation(
28732873
auto nominal = dyn_cast<NominalTypeDecl>(witness->getDeclContext());
28742874
auto witnessClass = dyn_cast<ClassDecl>(witness->getDeclContext());
28752875
if (auto extension = dyn_cast<ExtensionDecl>(witness->getDeclContext())) {
2876-
// We can witness a distributed function in an extension, as long as
2876+
// We can witness a distributed instance method in an extension, as long as
28772877
// that extension itself is on a DistributedActor type (including
28782878
// protocols that inherit from DistributedActor, even if the protocol
28792879
// requirement was not expressed in terms of distributed actors).
@@ -2887,7 +2887,7 @@ bool ConformanceChecker::checkActorIsolation(
28872887
// requirement with a distributed function, because those are always
28882888
// cross-actor.
28892889
//
2890-
// If the distributed function is well-formed (passed checks) then it can
2890+
// If the distributed instance method is well-formed (passed checks) then it can
28912891
// witness this requirement. I.e. since checks to the distributed function
28922892
// passed, it can be called through this protocol.
28932893
if (witnessFunc && witnessFunc->isDistributed()) {
@@ -3008,7 +3008,7 @@ bool ConformanceChecker::checkActorIsolation(
30083008
auto nominal = dyn_cast<NominalTypeDecl>(witness->getDeclContext());
30093009
auto witnessClass = dyn_cast<ClassDecl>(witness->getDeclContext());
30103010
if (auto extension = dyn_cast<ExtensionDecl>(witness->getDeclContext())) {
3011-
// We can witness a distributed function in an extension, as long as
3011+
// We can witness a distributed instance method in an extension, as long as
30123012
// that extension itself is on a DistributedActor type (including
30133013
// protocols that inherit from DistributedActor, even if the protocol
30143014
// requirement was not expressed in terms of distributed actors).
@@ -3021,7 +3021,7 @@ bool ConformanceChecker::checkActorIsolation(
30213021
// requirement with a distributed function, because those are always
30223022
// cross-actor.
30233023
//
3024-
// If the distributed function is well-formed (passed checks) then it can
3024+
// If the distributed instance method is well-formed (passed checks) then it can
30253025
// witness this requirement. I.e. since checks to the distributed function
30263026
// passed, it can be called through this protocol.
30273027
if (witnessFunc && witnessFunc->isDistributed()) {

test/Distributed/distributed_actor_cannot_be_downcast_to_actor.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ distributed actor MA {
2323

2424
@available(SwiftStdlib 5.6, *)
2525
func h(ma: MA) async {
26-
// this would have been a bug, a non distributed function might have been called here,
26+
// this would have been a bug, a non distributed instance method might have been called here,
2727
// so we must not allow for it, because if the actor was remote calling a non-distributed func
2828
// would result in a hard crash (as there is no local actor to safely call the function on).
2929
await g(a: ma) // expected-error{{global function 'g(a:)' requires that 'MA' conform to 'Actor'}}

test/Distributed/distributed_actor_func_implicitly_async_throws.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ distributed actor D {
2222

2323
@available(SwiftStdlib 5.6, *)
2424
func test_not_distributed_funcs(distributed: D) async {
25-
distributed.hello() // expected-error{{only 'distributed' functions can be called on a potentially remote distributed actor}}
26-
distributed.helloAsync() // expected-error{{only 'distributed' functions can be called on a potentially remote distributed actor}}
25+
distributed.hello() // expected-error{{only 'distributed' instance methods can be called on a potentially remote distributed actor}}
26+
distributed.helloAsync() // expected-error{{only 'distributed' instance methods can be called on a potentially remote distributed actor}}
2727
// expected-error@-1{{expression is 'async' but is not marked with 'await'}}
2828
// expected-note@-2{{call is 'async'}}
2929
// {{expression is 'async' but is not marked with 'await'}}{{7-7=await }}
30-
distributed.helloAsyncThrows() // expected-error{{only 'distributed' functions can be called on a potentially remote distributed actor}}
30+
distributed.helloAsyncThrows() // expected-error{{only 'distributed' instance methods can be called on a potentially remote distributed actor}}
3131
// expected-error@-1{{expression is 'async' but is not marked with 'await'}} // TODO: no need to diagnose this, it is impossible to call anyway
3232
// expected-note@-2{{call is 'async'}}
3333
// expected-error@-3{{call can throw, but it is not marked with 'try' and the error is not handled}} // TODO: no need to diagnose this, it is impossible to call anyway
@@ -37,12 +37,12 @@ func test_not_distributed_funcs(distributed: D) async {
3737
func test_outside(distributed: D) async throws {
3838
distributed.distHello() // expected-error{{expression is 'async' but is not marked with 'await'}}
3939
// expected-error@-1{{call can throw but is not marked with 'try'}}
40-
// expected-note@-2{{calls to instance method 'distHello()' from outside of its actor context are implicitly asynchronous}}
40+
// expected-note@-2{{calls to distributed instance method 'distHello()' from outside of its actor context are implicitly asynchronous}}
4141
// expected-note@-3{{did you mean to use 'try'?}}
4242
// expected-note@-4{{did you mean to disable error propagation?}}
4343
// expected-note@-5{{did you mean to handle error as optional value?}}
4444
try distributed.distHello() // expected-error{{expression is 'async' but is not marked with 'await'}}
45-
// expected-note@-1{{calls to instance method 'distHello()' from outside of its actor context are implicitly asynchronous}}
45+
// expected-note@-1{{calls to distributed instance method 'distHello()' from outside of its actor context are implicitly asynchronous}}
4646
await distributed.distHello() // expected-error{{call can throw but is not marked with 'try'}}
4747
// expected-note@-1{{did you mean to use 'try'?}}
4848
// expected-note@-2{{did you mean to disable error propagation?}}
@@ -65,12 +65,12 @@ func test_outside(distributed: D) async throws {
6565

6666
distributed.distHelloThrows() // expected-error{{expression is 'async' but is not marked with 'await'}}
6767
// expected-error@-1{{call can throw but is not marked with 'try'}}
68-
// expected-note@-2{{calls to instance method 'distHelloThrows()' from outside of its actor context are implicitly asynchronous}}
68+
// expected-note@-2{{calls to distributed instance method 'distHelloThrows()' from outside of its actor context are implicitly asynchronous}}
6969
// expected-note@-3{{did you mean to use 'try'?}}
7070
// expected-note@-4{{did you mean to disable error propagation?}}
7171
// expected-note@-5{{did you mean to handle error as optional value?}}
7272
try distributed.distHelloThrows() // expected-error{{expression is 'async' but is not marked with 'await'}}
73-
// expected-note@-1{{calls to instance method 'distHelloThrows()' from outside of its actor context are implicitly asynchronous}}
73+
// expected-note@-1{{calls to distributed instance method 'distHelloThrows()' from outside of its actor context are implicitly asynchronous}}
7474
await distributed.distHelloThrows() // expected-error{{call can throw but is not marked with 'try'}}
7575
// expected-note@-1{{did you mean to use 'try'?}}
7676
// expected-note@-2{{did you mean to disable error propagation?}}

test/Distributed/distributed_actor_inference.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,6 @@ distributed actor BadValuesDistributedActor_7 {
104104
distributed subscript(nope: Int) -> Int { nope * 2 } // expected-error{{'distributed' modifier cannot be applied to this declaration}}
105105
distributed static let staticLetNope: Int = 13 // expected-error{{'distributed' modifier cannot be applied to this declaration}}
106106
distributed static var staticVarNope: Int { 13 } // expected-error{{'distributed' modifier cannot be applied to this declaration}}
107-
distributed static func staticNope() async throws -> Int { 13 } // expected-error{{'distributed' functions cannot be 'static'}}
107+
distributed static func staticNope() async throws -> Int { 13 } // expected-error{{'distributed' method cannot be 'static'}}
108108
}
109109

test/Distributed/distributed_actor_isolation.swift

+14-9
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ distributed actor DistributedActor_1 {
4747
""
4848
}
4949

50-
distributed static func distributedStatic() {} // expected-error{{'distributed' functions cannot be 'static'}}
50+
distributed static func distributedStatic() {} // expected-error{{'distributed' method cannot be 'static'}}
51+
distributed class func distributedClass() {}
52+
// expected-error@-1{{class methods are only allowed within classes; use 'static' to declare a static method}}
53+
// expected-error@-2{{'distributed' method cannot be 'static'}} // TODO(distributed): should call out 'class' instead?
54+
55+
distributed private func distributedPrivate() {} //expected-error{{distributed instance method 'distributedPrivate()' cannot be 'private'}}
5156

5257
func hello() {} // expected-note{{distributed actor-isolated instance method 'hello()' declared here}}
5358
func helloAsync() async {} // expected-note{{distributed actor-isolated instance method 'helloAsync()' declared here}}
@@ -63,10 +68,10 @@ distributed actor DistributedActor_1 {
6368
distributed func distIntString(int: Int, two: String) async throws -> (String) { "\(int) + \(two)" } // ok
6469

6570
distributed func dist(notCodable: NotCodableValue) async throws {
66-
// expected-error@-1 {{distributed function parameter 'notCodable' of type 'NotCodableValue' does not conform to 'Codable'}}
71+
// expected-error@-1 {{distributed instance method parameter 'notCodable' of type 'NotCodableValue' does not conform to 'Codable'}}
6772
}
6873
distributed func distBadReturn(int: Int) async throws -> NotCodableValue {
69-
// expected-error@-1 {{distributed function result type 'NotCodableValue' does not conform to 'Codable'}}
74+
// expected-error@-1 {{distributed instance method result type 'NotCodableValue' does not conform to 'Codable'}}
7075
fatalError()
7176
}
7277

@@ -77,7 +82,7 @@ distributed actor DistributedActor_1 {
7782
fatalError()
7883
}
7984
distributed func distBadReturnGeneric<T: Sendable>(int: Int) async throws -> T {
80-
// expected-error@-1 {{distributed function result type 'T' does not conform to 'Codable'}}
85+
// expected-error@-1 {{distributed instance method result type 'T' does not conform to 'Codable'}}
8186
fatalError()
8287
}
8388

@@ -88,7 +93,7 @@ distributed actor DistributedActor_1 {
8893
value
8994
}
9095
distributed func distBadGenericParam<T: Sendable>(int: T) async throws {
91-
// expected-error@-1 {{distributed function parameter 'int' of type 'T' does not conform to 'Codable'}}
96+
// expected-error@-1 {{distributed instance method parameter 'int' of type 'T' does not conform to 'Codable'}}
9297
fatalError()
9398
}
9499

@@ -98,7 +103,7 @@ distributed actor DistributedActor_1 {
98103
static func staticMainActorFunc() -> String { "" } // ok
99104

100105
static distributed func staticDistributedFunc() -> String {
101-
// expected-error@-1{{'distributed' functions cannot be 'static'}}{10-21=}
106+
// expected-error@-1{{'distributed' method cannot be 'static'}}{10-21=}
102107
fatalError()
103108
}
104109

@@ -146,9 +151,9 @@ func test_outside(
146151
_ = DistributedActor_1.staticFunc()
147152

148153
// ==== non-distributed functions
149-
distributed.hello() // expected-error{{only 'distributed' functions can be called on a potentially remote distributed actor}}
150-
_ = await distributed.helloAsync() // expected-error{{only 'distributed' functions can be called on a potentially remote distributed actor}}
151-
_ = try await distributed.helloAsyncThrows() // expected-error{{only 'distributed' functions can be called on a potentially remote distributed actor}}
154+
distributed.hello() // expected-error{{only 'distributed' instance methods can be called on a potentially remote distributed actor}}
155+
_ = await distributed.helloAsync() // expected-error{{only 'distributed' instance methods can be called on a potentially remote distributed actor}}
156+
_ = try await distributed.helloAsyncThrows() // expected-error{{only 'distributed' instance methods can be called on a potentially remote distributed actor}}
152157
}
153158

154159
// ==== Protocols and static (non isolated functions)

0 commit comments

Comments
 (0)