Skip to content

Commit b0d9b9d

Browse files
authored
Merge pull request #4354 from swiftwasm/main
2 parents 95d2bac + abc8aa6 commit b0d9b9d

File tree

145 files changed

+1994
-480
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+1994
-480
lines changed

CHANGELOG.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,36 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
55

66
## Swift 5.7
77

8+
* [SE-0336][]:
9+
10+
It is now possible to declare `distributed actor` and `distributed func`s inside of them.
11+
12+
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.
13+
14+
Swift does not provide any specific distributed actor system by itself, however, packages in the ecosystem fulfil the role of providing those implementations.
15+
16+
```swift
17+
distributed actor Greeter {
18+
var greetingsSent = 0
19+
20+
distributed func greet(name: String) -> String {
21+
greetingsSent += 1
22+
return "Hello, \(name)!"
23+
}
24+
}
25+
26+
func talkTo(greeter: Greeter) async throws {
27+
// isolation of distributed actors is stronger, it is impossible to refer to
28+
// any stored properties of distributed actors from outside of them:
29+
greeter.greetingsSent // distributed actor-isolated property 'name' can not be accessed from a non-isolated context
30+
31+
// remote calls are implicitly throwing and async,
32+
// to account for the potential networking involved:
33+
let greeting = try await greeter.greet(name: "Alice")
34+
print(greeting) // Hello, Alice!
35+
}
36+
```
37+
838
* 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.
939

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

90389069
[SR-75]: <https://bugs.swift.org/browse/SR-75>
90399070
[SR-106]: <https://bugs.swift.org/browse/SR-106>

include/swift/AST/Decl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6315,7 +6315,8 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
63156315
/// diagnosed errors during type checking.
63166316
FuncDecl *getDistributedThunk() const;
63176317

6318-
/// Returns 'true' if the function has the @c @_backDeploy attribute.
6318+
/// Returns 'true' if the function has (or inherits) the @c @_backDeploy
6319+
/// attribute.
63196320
bool isBackDeployed() const;
63206321

63216322
PolymorphicEffectKind getPolymorphicEffectKind(EffectKind kind) const;

include/swift/AST/DiagnosticsParse.def

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,11 +1887,6 @@ ERROR(attr_requires_concurrency, none,
18871887
"concurrency is enabled",
18881888
(StringRef, bool))
18891889

1890-
ERROR(attr_requires_distributed, none,
1891-
"'%0' %select{attribute|modifier}1 is only valid when experimental "
1892-
"distributed support is enabled",
1893-
(StringRef, bool))
1894-
18951890
//------------------------------------------------------------------------------
18961891
// MARK: syntax parsing diagnostics
18971892
//------------------------------------------------------------------------------

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6320,5 +6320,9 @@ ERROR(attr_incompatible_with_back_deploy,none,
63206320
"'%0' cannot be applied to a back deployed %1",
63216321
(DeclAttribute, DescriptiveDeclKind))
63226322

6323+
ERROR(back_deploy_not_on_coroutine,none,
6324+
"'%0' is not supported on coroutine %1",
6325+
(DeclAttribute, DescriptiveDeclKind))
6326+
63236327
#define UNDEFINE_DIAGNOSTIC_MACROS
63246328
#include "DefineDiagnosticMacros.h"

include/swift/AST/DistributedDecl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ getDistributedSerializationRequirements(
106106
llvm::SmallPtrSet<ProtocolDecl *, 2>
107107
extractDistributedSerializationRequirements(
108108
ASTContext &C, ArrayRef<Requirement> allRequirements);
109+
109110
}
110111

111112
#endif /* SWIFT_DECL_TYPECHECKDISTRIBUTED_H */

include/swift/AST/KnownIdentifiers.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ IDENTIFIER(keyPath)
109109
IDENTIFIER(makeIterator)
110110
IDENTIFIER(makeAsyncIterator)
111111
IDENTIFIER(nestedContainer)
112+
IDENTIFIER(isEmpty)
112113
IDENTIFIER(Iterator)
113114
IDENTIFIER(AsyncIterator)
114115
IDENTIFIER(load)
@@ -124,6 +125,7 @@ IDENTIFIER(oldValue)
124125
IDENTIFIER(Optional)
125126
IDENTIFIER_(OptionalNilComparisonType)
126127
IDENTIFIER(parameter)
128+
IDENTIFIER(popFirst)
127129
IDENTIFIER(projected)
128130
IDENTIFIER(projectedValue)
129131
IDENTIFIER(Protocol)
@@ -149,7 +151,6 @@ IDENTIFIER(Type)
149151
IDENTIFIER(type)
150152
IDENTIFIER(typeMismatch)
151153
IDENTIFIER(underlyingError)
152-
IDENTIFIER(unsafelyUnwrapped)
153154
IDENTIFIER(Value)
154155
IDENTIFIER(value)
155156
IDENTIFIER_WITH_NAME(value_, "_value")

include/swift/AST/KnownStdlibTypes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ KNOWN_STDLIB_TYPE_DECL(String, NominalTypeDecl, 0)
4949
KNOWN_STDLIB_TYPE_DECL(StaticString, NominalTypeDecl, 0)
5050
KNOWN_STDLIB_TYPE_DECL(Substring, NominalTypeDecl, 0)
5151
KNOWN_STDLIB_TYPE_DECL(Array, NominalTypeDecl, 1)
52+
KNOWN_STDLIB_TYPE_DECL(ArraySlice, NominalTypeDecl, 1)
5253
KNOWN_STDLIB_TYPE_DECL(_ContiguousArrayStorage, ClassDecl, 1)
5354
KNOWN_STDLIB_TYPE_DECL(Set, NominalTypeDecl, 1)
5455
KNOWN_STDLIB_TYPE_DECL(Sequence, NominalTypeDecl, 1)

include/swift/AST/SwiftNameTranslation.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ namespace objc_translation {
5454
bool checkParent = true);
5555

5656
} // end namespace objc_translation
57+
58+
namespace cxx_translation {
59+
60+
/// Returns true if the given value decl D is visible to C++ of its
61+
/// own accord (i.e. without considering its context)
62+
bool isVisibleToCxx(const ValueDecl *VD, AccessLevel minRequiredAccess,
63+
bool checkParent = true);
64+
65+
} // end namespace cxx_translation
66+
5767
} // end namespace swift
5868

5969
#endif

include/swift/AST/TypeCheckRequests.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,30 @@ class IsDistributedActorRequest :
10391039
bool isCached() const { return true; }
10401040
};
10411041

1042+
/// Retrieve the implicit conformance for the given distributed actor type to
1043+
/// the Codable protocol protocol.
1044+
///
1045+
/// Similar to 'GetImplicitSendableRequest'.
1046+
class GetDistributedActorImplicitCodableRequest :
1047+
public SimpleRequest<GetDistributedActorImplicitCodableRequest,
1048+
NormalProtocolConformance *(NominalTypeDecl *, KnownProtocolKind),
1049+
RequestFlags::Cached> {
1050+
public:
1051+
using SimpleRequest::SimpleRequest;
1052+
1053+
private:
1054+
friend SimpleRequest;
1055+
1056+
NormalProtocolConformance *evaluate(
1057+
Evaluator &evaluator,
1058+
NominalTypeDecl *nominal,
1059+
KnownProtocolKind protoKind) const;
1060+
1061+
public:
1062+
// Caching
1063+
bool isCached() const { return true; }
1064+
};
1065+
10421066
/// Obtain the 'remoteCall' function of a 'DistributedActorSystem'.
10431067
class GetDistributedActorSystemRemoteCallFunctionRequest :
10441068
public SimpleRequest<GetDistributedActorSystemRemoteCallFunctionRequest,

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ SWIFT_REQUEST(TypeChecker, IsDefaultActorRequest,
107107
Cached, NoLocationInfo)
108108
SWIFT_REQUEST(TypeChecker, IsDistributedActorRequest, bool(NominalTypeDecl *),
109109
Cached, NoLocationInfo)
110+
SWIFT_REQUEST(TypeChecker, GetDistributedActorImplicitCodableRequest,
111+
NormalProtocolConformance *(NominalTypeDecl *, KnownProtocolKind),
112+
Cached, NoLocationInfo)
110113
SWIFT_REQUEST(TypeChecker, GetDistributedActorSystemRemoteCallFunctionRequest,
111114
AbstractFunctionDecl *(NominalTypeDecl *, bool),
112115
Cached, NoLocationInfo)

0 commit comments

Comments
 (0)