Skip to content

[Distributed] Explicitly ban __owned and other specifiers we don't support #66119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -5085,6 +5085,9 @@ ERROR(distributed_actor_func_nonisolated, none,
ERROR(distributed_actor_func_inout, none,
"cannot declare 'inout' argument %0 in %1 %2",
(DeclName, DescriptiveDeclKind, DeclName))
ERROR(distributed_actor_func_unsupported_specifier, none,
"cannot declare '%0' argument %1 in %2 %3",
(StringRef, DeclName, DescriptiveDeclKind, DeclName))
ERROR(distributed_actor_func_closure, none,
"%0 %1 cannot declare closure arguments, as they cannot be serialized",
(DescriptiveDeclKind, DeclName))
Expand Down
16 changes: 15 additions & 1 deletion lib/Sema/TypeCheckDistributed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,8 @@ bool CheckDistributedFunctionRequest::evaluate(
checkDistributedSerializationRequirementIsExactlyCodable(
C, serializationRequirements);

// --- Check parameters for 'Codable' conformance
for (auto param : *func->getParameters()) {
// --- Check parameters for 'Codable' conformance
auto paramTy = func->mapTypeIntoContext(param->getInterfaceType());

for (auto req : serializationRequirements) {
Expand All @@ -555,6 +555,7 @@ bool CheckDistributedFunctionRequest::evaluate(
}
}

// --- Check parameters for various illegal modifiers
if (param->isInOut()) {
param->diagnose(
diag::distributed_actor_func_inout,
Expand All @@ -566,6 +567,19 @@ bool CheckDistributedFunctionRequest::evaluate(
return true;
}

if (param->getSpecifier() == ParamSpecifier::LegacyShared ||
param->getSpecifier() == ParamSpecifier::LegacyOwned ||
param->getSpecifier() == ParamSpecifier::Consuming ||
param->getSpecifier() == ParamSpecifier::Borrowing) {
param->diagnose(
diag::distributed_actor_func_unsupported_specifier,
ParamDecl::getSpecifierSpelling(param->getSpecifier()),
param->getName(),
func->getDescriptiveKind(),
func->getName());
return true;
}

if (param->isVariadic()) {
param->diagnose(
diag::distributed_actor_func_variadic,
Expand Down
25 changes: 25 additions & 0 deletions test/Distributed/distributed_actor_ban_owned_shared.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -disable-availability-checking %S/Inputs/FakeDistributedActorSystems.swift
// RUN: %target-swift-frontend -typecheck -verify -disable-availability-checking -I %t 2>&1 %s
// REQUIRES: concurrency
// REQUIRES: distributed

import Distributed
import FakeDistributedActorSystems

typealias DefaultDistributedActorSystem = FakeActorSystem

class Param: Codable {}

distributed actor First {
distributed func owned(_: __owned Param) async throws {} // expected-error{{cannot declare '__owned' argument '_' in distributed instance method 'owned'}}
distributed func shared(_: __shared Param) async throws {} // expected-error{{cannot declare '__shared' argument '_' in distributed instance method 'shared'}}
distributed func consuming(_: consuming Param) async throws {}
// expected-error@-1{{Copyable types cannot be 'consuming' or 'borrowing' yet}}
// expected-error@-2{{parameter '' of type '<<error type>>' in distributed instance method does not conform to serialization requirement 'Codable'}}
}

func test(first: First) async throws {
try await first.owned(.init())
try await first.shared(.init())
}