Skip to content

Commit d685c1c

Browse files
authored
Merge pull request #66119 from ktoso/wip-distributed-ban-__owned
2 parents 4720673 + 6e14025 commit d685c1c

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5099,6 +5099,9 @@ ERROR(distributed_actor_func_nonisolated, none,
50995099
ERROR(distributed_actor_func_inout, none,
51005100
"cannot declare 'inout' argument %0 in %1 %2",
51015101
(DeclName, DescriptiveDeclKind, DeclName))
5102+
ERROR(distributed_actor_func_unsupported_specifier, none,
5103+
"cannot declare '%0' argument %1 in %2 %3",
5104+
(StringRef, DeclName, DescriptiveDeclKind, DeclName))
51025105
ERROR(distributed_actor_func_closure, none,
51035106
"%0 %1 cannot declare closure arguments, as they cannot be serialized",
51045107
(DescriptiveDeclKind, DeclName))

lib/Sema/TypeCheckDistributed.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,8 @@ bool CheckDistributedFunctionRequest::evaluate(
535535
checkDistributedSerializationRequirementIsExactlyCodable(
536536
C, serializationRequirements);
537537

538-
// --- Check parameters for 'Codable' conformance
539538
for (auto param : *func->getParameters()) {
539+
// --- Check parameters for 'Codable' conformance
540540
auto paramTy = func->mapTypeIntoContext(param->getInterfaceType());
541541

542542
for (auto req : serializationRequirements) {
@@ -555,6 +555,7 @@ bool CheckDistributedFunctionRequest::evaluate(
555555
}
556556
}
557557

558+
// --- Check parameters for various illegal modifiers
558559
if (param->isInOut()) {
559560
param->diagnose(
560561
diag::distributed_actor_func_inout,
@@ -566,6 +567,19 @@ bool CheckDistributedFunctionRequest::evaluate(
566567
return true;
567568
}
568569

570+
if (param->getSpecifier() == ParamSpecifier::LegacyShared ||
571+
param->getSpecifier() == ParamSpecifier::LegacyOwned ||
572+
param->getSpecifier() == ParamSpecifier::Consuming ||
573+
param->getSpecifier() == ParamSpecifier::Borrowing) {
574+
param->diagnose(
575+
diag::distributed_actor_func_unsupported_specifier,
576+
ParamDecl::getSpecifierSpelling(param->getSpecifier()),
577+
param->getName(),
578+
func->getDescriptiveKind(),
579+
func->getName());
580+
return true;
581+
}
582+
569583
if (param->isVariadic()) {
570584
param->diagnose(
571585
diag::distributed_actor_func_variadic,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -disable-availability-checking %S/Inputs/FakeDistributedActorSystems.swift
3+
// RUN: %target-swift-frontend -typecheck -verify -disable-availability-checking -I %t 2>&1 %s
4+
// REQUIRES: concurrency
5+
// REQUIRES: distributed
6+
7+
import Distributed
8+
import FakeDistributedActorSystems
9+
10+
typealias DefaultDistributedActorSystem = FakeActorSystem
11+
12+
class Param: Codable {}
13+
14+
distributed actor First {
15+
distributed func owned(_: __owned Param) async throws {} // expected-error{{cannot declare '__owned' argument '_' in distributed instance method 'owned'}}
16+
distributed func shared(_: __shared Param) async throws {} // expected-error{{cannot declare '__shared' argument '_' in distributed instance method 'shared'}}
17+
distributed func consuming(_: consuming Param) async throws {}
18+
// expected-error@-1{{Copyable types cannot be 'consuming' or 'borrowing' yet}}
19+
// expected-error@-2{{parameter '' of type '<<error type>>' in distributed instance method does not conform to serialization requirement 'Codable'}}
20+
}
21+
22+
func test(first: First) async throws {
23+
try await first.owned(.init())
24+
try await first.shared(.init())
25+
}

0 commit comments

Comments
 (0)