Skip to content

[Distributed] Enable no-longer-experimental distributed by default #41780

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 6 commits into from
Mar 11, 2022
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
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,36 @@ _**Note:** This is in reverse chronological order, so newer entries are added to

## Swift 5.7

* [SE-0336][]:

It is now possible to declare `distributed actor` and `distributed func`s inside of them.

Distributed actors provide stronger isolation guarantees than "local" actors, and enable additional checks to be made on return types and parameters of distributed methods, e.g. checking if they conform to `Codable`. Distributed methods can be called on "remote" references of distributed actors, turning those invocations into remote procedure calls, by means of pluggable and user extensible distributed actor system implementations.

Swift does not provide any specific distributed actor system by itself, however, packages in the ecosystem fulfil the role of providing those implementations.

```swift
distributed actor Greeter {
var greetingsSent = 0

distributed func greet(name: String) -> String {
greetingsSent += 1
return "Hello, \(name)!"
}
}

func talkTo(greeter: Greeter) async throws {
// isolation of distributed actors is stronger, it is impossible to refer to
// any stored properties of distributed actors from outside of them:
greeter.greetingsSent // distributed actor-isolated property 'name' can not be accessed from a non-isolated context

// remote calls are implicitly throwing and async,
// to account for the potential networking involved:
let greeting = try await greeter.greet(name: "Alice")
print(greeting) // Hello, Alice!
}
```

* The compiler now emits a warning when a non-final class conforms to a protocol that imposes a same-type requirement between `Self` and an associated type. This is because such a requirement makes the conformance unsound for subclasses.

For example, Swift 5.6 would allow the following code, which at runtime would construct an instanec of `C` and not `SubC` as expected:
Expand Down Expand Up @@ -9034,6 +9064,7 @@ Swift 1.0
[SE-0337]: <https://github.com/apple/swift-evolution/blob/main/proposals/0337-support-incremental-migration-to-concurrency-checking.md>
[SE-0335]: <https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md>
[SE-0341]: <https://github.com/apple/swift-evolution/blob/main/proposals/0341-opaque-parameters.md>
[SE-0336]: <https://github.com/apple/swift-evolution/blob/main/proposals/0336-distributed-actor-isolation.md>

[SR-75]: <https://bugs.swift.org/browse/SR-75>
[SR-106]: <https://bugs.swift.org/browse/SR-106>
Expand Down
5 changes: 0 additions & 5 deletions include/swift/AST/DiagnosticsParse.def
Original file line number Diff line number Diff line change
Expand Up @@ -1887,11 +1887,6 @@ ERROR(attr_requires_concurrency, none,
"concurrency is enabled",
(StringRef, bool))

ERROR(attr_requires_distributed, none,
"'%0' %select{attribute|modifier}1 is only valid when experimental "
"distributed support is enabled",
(StringRef, bool))

//------------------------------------------------------------------------------
// MARK: syntax parsing diagnostics
//------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ namespace swift {
bool EnableInferPublicSendable = false;

/// Enable experimental 'distributed' actors and functions.
bool EnableExperimentalDistributed = false;
bool EnableExperimentalDistributed = true;

/// Enable experimental 'move only' features.
bool EnableExperimentalMoveOnly = false;
Expand Down
1 change: 0 additions & 1 deletion include/swift/IDE/CompletionLookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,6 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {

static bool canUseAttributeOnDecl(DeclAttrKind DAK, bool IsInSil,
bool IsConcurrencyEnabled,
bool IsDistributedEnabled,
Optional<DeclKind> DK);

void getAttributeDeclCompletions(bool IsInSil, Optional<DeclKind> DK);
Expand Down
8 changes: 0 additions & 8 deletions include/swift/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -748,14 +748,6 @@ class Parser {
Context.LangOpts.ParseForSyntaxTreeOnly;
}

/// Returns true to indicate that experimental 'distributed actor' syntax
/// should be parsed if the parser is only a syntax tree or if the user has
/// passed the `-enable-experimental-distributed' flag to the frontend.
bool shouldParseExperimentalDistributed() const {
return Context.LangOpts.EnableExperimentalDistributed ||
Context.LangOpts.ParseForSyntaxTreeOnly;
}

public:
InFlightDiagnostic diagnose(SourceLoc Loc, Diagnostic Diag) {
if (Diags.isDiagnosticPointsToFirstBadToken(Diag.getID()) &&
Expand Down
32 changes: 15 additions & 17 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3028,23 +3028,21 @@ AnyFunctionType::Param swift::computeSelfParam(AbstractFunctionDecl *AFD,
// FIXME(distributed): pending swift-evolution, allow `self =` in class
// inits in general.
// See also: https://github.com/apple/swift/pull/19151 general impl
if (Ctx.LangOpts.EnableExperimentalDistributed) {
auto ext = dyn_cast<ExtensionDecl>(AFD->getDeclContext());
auto distProto =
Ctx.getProtocol(KnownProtocolKind::DistributedActor);
if (distProto && ext && ext->getExtendedNominal() &&
ext->getExtendedNominal()->getInterfaceType()
->isEqual(distProto->getInterfaceType())) {
auto name = CD->getName();
auto params = name.getArgumentNames();
if (params.size() == 1 && params[0] == Ctx.Id_from) {
// FIXME(distributed): this is a workaround to allow init(from:) to
// be implemented in AST by allowing the self to be mutable in the
// decoding initializer. This should become a general Swift
// feature, allowing this in all classes:
// https://forums.swift.org/t/allow-self-x-in-class-convenience-initializers/15924
selfAccess = SelfAccessKind::Mutating;
}
auto ext = dyn_cast<ExtensionDecl>(AFD->getDeclContext());
auto distProto =
Ctx.getProtocol(KnownProtocolKind::DistributedActor);
if (distProto && ext && ext->getExtendedNominal() &&
ext->getExtendedNominal()->getInterfaceType()
->isEqual(distProto->getInterfaceType())) {
auto name = CD->getName();
auto params = name.getArgumentNames();
if (params.size() == 1 && params[0] == Ctx.Id_from) {
// FIXME(distributed): this is a workaround to allow init(from:) to
// be implemented in AST by allowing the self to be mutable in the
// decoding initializer. This should become a general Swift
// feature, allowing this in all classes:
// https://forums.swift.org/t/allow-self-x-in-class-convenience-initializers/15924
selfAccess = SelfAccessKind::Mutating;
}
}
} else {
Expand Down
20 changes: 5 additions & 15 deletions lib/IDE/CodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,7 @@ static void addKeyword(CodeCompletionResultSink &Sink, StringRef Name,
}

static void addDeclKeywords(CodeCompletionResultSink &Sink, DeclContext *DC,
bool IsConcurrencyEnabled,
bool IsDistributedEnabled) {
bool IsConcurrencyEnabled) {
auto isTypeDeclIntroducer = [](CodeCompletionKeywordKind Kind,
Optional<DeclAttrKind> DAK) -> bool {
switch (Kind) {
Expand Down Expand Up @@ -778,11 +777,6 @@ static void addDeclKeywords(CodeCompletionResultSink &Sink, DeclContext *DC,
DeclAttribute::isConcurrencyOnly(*DAK))
return;

// Remove keywords only available when distributed is enabled.
if (DAK.hasValue() && !IsDistributedEnabled &&
DeclAttribute::isDistributedOnly(*DAK))
return;

addKeyword(Sink, Name, Kind, /*TypeAnnotation=*/"", getFlair(Kind, DAK));
};

Expand Down Expand Up @@ -943,8 +937,7 @@ void CodeCompletionCallbacksImpl::addKeywords(CodeCompletionResultSink &Sink,
}
case CompletionKind::StmtOrExpr:
addDeclKeywords(Sink, CurDeclContext,
Context.LangOpts.EnableExperimentalConcurrency,
Context.LangOpts.EnableExperimentalDistributed);
Context.LangOpts.EnableExperimentalConcurrency);
addStmtKeywords(Sink, CurDeclContext, MaybeFuncBody);
LLVM_FALLTHROUGH;
case CompletionKind::ReturnStmtExpr:
Expand Down Expand Up @@ -1013,8 +1006,7 @@ void CodeCompletionCallbacksImpl::addKeywords(CodeCompletionResultSink &Sink,
}) != ParsedKeywords.end();
if (!HasDeclIntroducer) {
addDeclKeywords(Sink, CurDeclContext,
Context.LangOpts.EnableExperimentalConcurrency,
Context.LangOpts.EnableExperimentalDistributed);
Context.LangOpts.EnableExperimentalConcurrency);
addLetVarKeywords(Sink);
}
break;
Expand Down Expand Up @@ -1758,8 +1750,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
if (CurDeclContext->isTypeContext()) {
// Override completion (CompletionKind::NominalMemberBeginning).
addDeclKeywords(Sink, CurDeclContext,
Context.LangOpts.EnableExperimentalConcurrency,
Context.LangOpts.EnableExperimentalDistributed);
Context.LangOpts.EnableExperimentalConcurrency);
addLetVarKeywords(Sink);
SmallVector<StringRef, 0> ParsedKeywords;
CompletionOverrideLookup OverrideLookup(Sink, Context, CurDeclContext,
Expand All @@ -1768,8 +1759,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
} else {
// Global completion (CompletionKind::PostfixExprBeginning).
addDeclKeywords(Sink, CurDeclContext,
Context.LangOpts.EnableExperimentalConcurrency,
Context.LangOpts.EnableExperimentalDistributed);
Context.LangOpts.EnableExperimentalConcurrency);
addStmtKeywords(Sink, CurDeclContext, MaybeFuncBody);
addSuperKeyword(Sink, CurDeclContext);
addLetVarKeywords(Sink);
Expand Down
6 changes: 1 addition & 5 deletions lib/IDE/CompletionLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2852,7 +2852,6 @@ void CompletionLookup::getGenericRequirementCompletions(

bool CompletionLookup::canUseAttributeOnDecl(DeclAttrKind DAK, bool IsInSil,
bool IsConcurrencyEnabled,
bool IsDistributedEnabled,
Optional<DeclKind> DK) {
if (DeclAttribute::isUserInaccessible(DAK))
return false;
Expand All @@ -2864,8 +2863,6 @@ bool CompletionLookup::canUseAttributeOnDecl(DeclAttrKind DAK, bool IsInSil,
return false;
if (!IsConcurrencyEnabled && DeclAttribute::isConcurrencyOnly(DAK))
return false;
if (!IsDistributedEnabled && DeclAttribute::isDistributedOnly(DAK))
return false;
if (!DK.hasValue())
return true;
return DeclAttribute::canAttributeAppearOnDeclKind(DAK, DK.getValue());
Expand All @@ -2885,11 +2882,10 @@ void CompletionLookup::getAttributeDeclCompletions(bool IsInSil,
}
}
bool IsConcurrencyEnabled = Ctx.LangOpts.EnableExperimentalConcurrency;
bool IsDistributedEnabled = Ctx.LangOpts.EnableExperimentalDistributed;
std::string Description = TargetName.str() + " Attribute";
#define DECL_ATTR(KEYWORD, NAME, ...) \
if (canUseAttributeOnDecl(DAK_##NAME, IsInSil, IsConcurrencyEnabled, \
IsDistributedEnabled, DK)) \
DK)) \
addDeclAttrKeyword(#KEYWORD, Description);
#include "swift/AST/Attr.def"
}
Expand Down
8 changes: 0 additions & 8 deletions lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1987,14 +1987,6 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
DiscardAttribute = true;
}

// If this attribute is only permitted when distributed is enabled, reject it.
if (DeclAttribute::isDistributedOnly(DK) &&
!shouldParseExperimentalDistributed()) {
diagnose(Loc, diag::attr_requires_distributed, AttrName,
DeclAttribute::isDeclModifier(DK));
DiscardAttribute = true;
}

if (Context.LangOpts.Target.isOSBinFormatCOFF()) {
if (DK == DAK_WeakLinked) {
diagnose(Loc, diag::attr_unsupported_on_target, AttrName,
Expand Down
1 change: 0 additions & 1 deletion stdlib/public/Distributed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ add_swift_target_library(swift_Distributed ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
SWIFT_COMPILE_FLAGS
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
-parse-stdlib
-Xfrontend -enable-experimental-distributed
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"

SWIFT_MODULE_DEPENDS _Concurrency
Expand Down
2 changes: 1 addition & 1 deletion test/Distributed/Runtime/distributed_actor_decode.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-distributed -Xfrontend -disable-availability-checking -parse-as-library) | %FileCheck %s
// RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking -parse-as-library) | %FileCheck %s

// REQUIRES: executable_test
// REQUIRES: concurrency
Expand Down
2 changes: 1 addition & 1 deletion test/Distributed/Runtime/distributed_actor_deinit.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-distributed -Xfrontend -disable-availability-checking -parse-as-library) | %FileCheck %s
// RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking -parse-as-library) | %FileCheck %s

// REQUIRES: executable_test
// REQUIRES: concurrency
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 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-build-swift -module-name main -Xfrontend -enable-experimental-distributed -Xfrontend -disable-availability-checking -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
// RUN: %target-build-swift -module-name main -Xfrontend -disable-availability-checking -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s --color

// REQUIRES: executable_test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 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-build-swift -module-name main -Xfrontend -enable-experimental-distributed -Xfrontend -disable-availability-checking -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
// RUN: %target-build-swift -module-name main -Xfrontend -disable-availability-checking -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s --color

// REQUIRES: executable_test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 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-build-swift -module-name main -Xfrontend -enable-experimental-distributed -Xfrontend -disable-availability-checking -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
// RUN: %target-build-swift -module-name main -Xfrontend -disable-availability-checking -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s --color

// REQUIRES: executable_test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 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-build-swift -module-name main -Xfrontend -enable-experimental-distributed -Xfrontend -disable-availability-checking -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
// RUN: %target-build-swift -module-name main -Xfrontend -disable-availability-checking -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s --color

// REQUIRES: executable_test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 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-build-swift -module-name main -Xfrontend -enable-experimental-distributed -Xfrontend -disable-availability-checking -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
// RUN: %target-build-swift -module-name main -Xfrontend -disable-availability-checking -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s --color

// REQUIRES: executable_test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 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-build-swift -module-name main -Xfrontend -enable-experimental-distributed -Xfrontend -disable-availability-checking -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
// RUN: %target-build-swift -module-name main -Xfrontend -disable-availability-checking -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s --color

// REQUIRES: executable_test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 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-build-swift -module-name main -Xfrontend -enable-experimental-distributed -Xfrontend -disable-availability-checking -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
// RUN: %target-build-swift -module-name main -Xfrontend -disable-availability-checking -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s --color

// REQUIRES: executable_test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 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-build-swift -module-name main -Xfrontend -enable-experimental-distributed -Xfrontend -disable-availability-checking -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
// RUN: %target-build-swift -module-name main -Xfrontend -disable-availability-checking -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s --color

// REQUIRES: executable_test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-distributed -Xfrontend -disable-availability-checking -parse-as-library) | %FileCheck %s
// RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking -parse-as-library) | %FileCheck %s

// REQUIRES: executable_test
// REQUIRES: concurrency
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 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-build-swift -module-name main -Xfrontend -enable-experimental-distributed -Xfrontend -disable-availability-checking -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
// RUN: %target-build-swift -module-name main -Xfrontend -disable-availability-checking -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s --color

// REQUIRES: executable_test
Expand Down
Loading