Skip to content

[Distributed] DistributedActorSystem renaming and redesign #40387

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 9 commits into from
Dec 13, 2021
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/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3309,6 +3309,9 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
/// If the passed in function is not distributed this function returns null.
AbstractFunctionDecl* lookupDirectRemoteFunc(AbstractFunctionDecl *func);

/// Find, or potentially synthesize, the implicit 'id' property of this actor.
ValueDecl *getDistributedActorIDProperty() const;

/// Collect the set of protocols to which this type should implicitly
/// conform, such as AnyObject (for classes).
void getImplicitProtocols(SmallVectorImpl<ProtocolDecl *> &protocols);
Expand Down
6 changes: 3 additions & 3 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -4681,13 +4681,13 @@ ERROR(distributed_actor_func_static,none,
ERROR(distributed_actor_func_not_in_distributed_actor,none,
"'distributed' method can only be declared within 'distributed actor'",
())
ERROR(distributed_actor_designated_ctor_must_have_one_transport_param,none,
ERROR(distributed_actor_designated_ctor_must_have_one_distributedactorsystem_param,none,
"designated distributed actor initializer %0 must accept exactly one "
"ActorTransport parameter, found %1",
"DistributedActorSystem parameter, found %1",
(DeclName, int))
ERROR(distributed_actor_designated_ctor_missing_transport_param,none,
"designated distributed actor initializer %0 is missing required "
"ActorTransport parameter",
"DistributedActorSystem parameter",
(DeclName))
ERROR(distributed_actor_user_defined_special_property,none,
"property %0 cannot be defined explicitly, as it conflicts with "
Expand Down
4 changes: 2 additions & 2 deletions include/swift/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ class DeclRefExpr : public Expr {

/// Set whether this reference must account for a `throw` occurring for reasons
/// other than the function implementation itself throwing, e.g. an
/// `ActorTransport` implementing a `distributed func` call throwing a
/// `DistributedActorSystem` implementing a `distributed func` call throwing a
/// networking error.
void setImplicitlyThrows(bool isImplicitlyThrows) {
Bits.DeclRefExpr.IsImplicitlyThrows = isImplicitlyThrows;
Expand Down Expand Up @@ -1619,7 +1619,7 @@ class LookupExpr : public Expr {

/// Set whether this reference must account for a `throw` occurring for reasons
/// other than the function implementation itself throwing, e.g. an
/// `ActorTransport` implementing a `distributed func` call throwing a
/// `DistributedActorSystem` implementing a `distributed func` call throwing a
/// networking error.
void setImplicitlyThrows(bool isImplicitlyThrows) {
Bits.LookupExpr.IsImplicitlyThrows = isImplicitlyThrows;
Expand Down
21 changes: 11 additions & 10 deletions include/swift/AST/KnownIdentifiers.def
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ IDENTIFIER(decode)
IDENTIFIER(decodeIfPresent)
IDENTIFIER(Decoder)
IDENTIFIER(decoder)
IDENTIFIER(DefaultActorTransport)
IDENTIFIER(DefaultDistributedActorSystem)
IDENTIFIER_(Differentiation)
IDENTIFIER_WITH_NAME(PatternMatchVar, "$match")
IDENTIFIER(dynamicallyCall)
Expand Down Expand Up @@ -142,7 +142,6 @@ IDENTIFIER_WITH_NAME(SwiftObject, "_TtCs12_SwiftObject")
IDENTIFIER(SwiftNativeNSObject)
IDENTIFIER(to)
IDENTIFIER(toRaw)
IDENTIFIER(Transport)
IDENTIFIER(Type)
IDENTIFIER(type)
IDENTIFIER(typeMismatch)
Expand Down Expand Up @@ -256,18 +255,20 @@ IDENTIFIER_(regexString)
IDENTIFIER_(StringProcessing)

// Distributed actors
IDENTIFIER(transport)
IDENTIFIER(using)
IDENTIFIER(actor)
IDENTIFIER(actorTransport)
IDENTIFIER(actorType)
IDENTIFIER(actorReady)
IDENTIFIER(assignIdentity)
IDENTIFIER(resignIdentity)
IDENTIFIER(ActorSystem)
IDENTIFIER(actorSystem)
IDENTIFIER(ActorID)
IDENTIFIER(actorType)
IDENTIFIER(using)
IDENTIFIER(assignID)
IDENTIFIER(resignID)
IDENTIFIER(resolve)
IDENTIFIER(system)
IDENTIFIER(ID)
IDENTIFIER(id)
IDENTIFIER(identity)
IDENTIFIER(identifier)
IDENTIFIER(Invocation)
IDENTIFIER(_distributedActorRemoteInitialize)
IDENTIFIER(_distributedActorDestroy)
IDENTIFIER(__isRemoteActor)
Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/KnownProtocols.def
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ PROTOCOL(Differentiable)
// Distributed Actors
PROTOCOL(DistributedActor)
PROTOCOL(ActorIdentity)
PROTOCOL(ActorTransport)
PROTOCOL(DistributedActorSystem)

PROTOCOL(AsyncSequence)
PROTOCOL(AsyncIteratorProtocol)
Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/KnownSDKDecls.def
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# define KNOWN_SDK_FUNC_DECL(Module, Name, Id)
#endif

KNOWN_SDK_FUNC_DECL(Distributed, MissingDistributedActorTransport, "_missingDistributedActorTransport")
KNOWN_SDK_FUNC_DECL(Distributed, MissingDistributedActorSystem, "_missingDistributedActorSystem")
KNOWN_SDK_FUNC_DECL(Distributed, IsRemoteDistributedActor, "__isRemoteActor")

#undef KNOWN_SDK_FUNC_DECL
Expand Down
22 changes: 20 additions & 2 deletions include/swift/AST/TypeCheckRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,24 @@ class GetDistributedRemoteFuncRequest :
bool isCached() const { return true; }
};

/// Obtain the 'id' property of a 'distributed actor'.
class GetDistributedActorIDPropertyRequest :
public SimpleRequest<GetDistributedActorIDPropertyRequest,
ValueDecl *(NominalTypeDecl *),
RequestFlags::Cached> {
public:
using SimpleRequest::SimpleRequest;

private:
friend SimpleRequest;

ValueDecl *evaluate(Evaluator &evaluator, NominalTypeDecl *actor) const;

public:
// Caching
bool isCached() const { return true; }
};

/// Retrieve the static "shared" property within a global actor that provides
/// the actor instance representing the global actor.
///
Expand Down Expand Up @@ -2215,8 +2233,8 @@ enum class ImplicitMemberAction : uint8_t {
ResolveEncodable,
ResolveDecodable,
ResolveDistributedActor,
ResolveDistributedActorIdentity,
ResolveDistributedActorTransport,
ResolveDistributedActorID,
ResolveDistributedActorSystem,
};

class ResolveImplicitMemberRequest
Expand Down
2 changes: 2 additions & 0 deletions include/swift/AST/TypeCheckerTypeIDZone.def
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ SWIFT_REQUEST(TypeChecker, IsDistributedActorRequest, bool(NominalTypeDecl *),
Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, GetDistributedRemoteFuncRequest, AbstractFunctionDecl *(AbstractFunctionDecl *),
Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, GetDistributedActorIDPropertyRequest, ValueDecl *(NominalTypeDecl *),
Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, GlobalActorInstanceRequest,
VarDecl *(NominalTypeDecl *),
Cached, NoLocationInfo)
Expand Down
24 changes: 12 additions & 12 deletions include/swift/SILOptimizer/Utils/DistributedActor.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,32 @@ class SILLocation;
class SILType;
class SILValue;

/// Finds the first `ActorTransport`-compatible parameter of the given function.
/// Finds the first `DistributedActorSystem`-compatible parameter of the given function.
/// \returns nullptr if the function does not have such a parameter.
SILArgument *findFirstActorTransportArg(SILFunction &F);
SILArgument *findFirstDistributedActorSystemArg(SILFunction &F);

/// Emit a call to a witness of the actor transport protocol.
/// Emit a call to a witness of the actor actorSystem protocol.
///
/// \param methodName The name of the method on the ActorTransport protocol.
/// \param transport The transport on which to invoke the method
/// \param methodName The name of the method on the DistributedActorSystem protocol.
/// \param actorSystem The actorSystem on which to invoke the method
/// \param actorType If non-empty, the type of the distributed actor that is
/// provided as one of the arguments.
/// \param args The arguments provided to the call, not including the transport.
/// \param args The arguments provided to the call, not including the actorSystem.
/// \param tryTargets For a call that can throw, the normal and error basic
/// blocks that the call will branch to.
void emitActorTransportWitnessCall(
void emitDistributedActorSystemWitnessCall(
SILBuilder &B, SILLocation loc, DeclName methodName,
SILValue transport, SILType actorType, llvm::ArrayRef<SILValue> args,
SILValue actorSystem, SILType actorType, llvm::ArrayRef<SILValue> args,
llvm::Optional<std::pair<SILBasicBlock *, SILBasicBlock *>> tryTargets =
llvm::None);

/// Emits code that notifies the distributed actor's transport that the
/// Emits code that notifies the distributed actor's actorSystem that the
/// actor is ready for execution.
/// \param B the builder to use when emitting the code.
/// \param actor the distributed actor instance to pass to the transport as
/// being "ready" \param transport a value representing the ActorTransport
/// \param actor the distributed actor instance to pass to the actorSystem as
/// being "ready" \param actorSystem a value representing the DistributedActorSystem
void emitActorReadyCall(SILBuilder &B, SILLocation loc, SILValue actor,
SILValue transport);
SILValue actorSystem);

} // namespace swift

Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ ProtocolDecl *ASTContext::getProtocol(KnownProtocolKind kind) const {
M = getLoadedModule(Id_Concurrency);
break;
case KnownProtocolKind::DistributedActor:
case KnownProtocolKind::ActorTransport:
case KnownProtocolKind::DistributedActorSystem:
case KnownProtocolKind::ActorIdentity:
M = getLoadedModule(Id_Distributed);
break;
Expand Down
16 changes: 14 additions & 2 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4332,8 +4332,8 @@ void NominalTypeDecl::synthesizeSemanticMembersIfNeeded(DeclName member) {
if (baseName == DeclBaseName::createConstructor()) {
if ((member.isSimpleName() || argumentNames.front() == Context.Id_from)) {
action.emplace(ImplicitMemberAction::ResolveDecodable);
} else if (argumentNames.front() == Context.Id_transport) {
action.emplace(ImplicitMemberAction::ResolveDistributedActorTransport);
} else if (argumentNames.front() == Context.Id_system) {
action.emplace(ImplicitMemberAction::ResolveDistributedActorSystem);
}
} else if (!baseName.isSpecial() &&
baseName.getIdentifier() == Context.Id_encode &&
Expand Down Expand Up @@ -7400,6 +7400,18 @@ AbstractFunctionDecl::getDistributedActorRemoteFuncDecl() const {
nullptr);
}

ValueDecl*
NominalTypeDecl::getDistributedActorIDProperty() const {
if (!this->isDistributedActor())
return nullptr;

auto mutableThis = const_cast<NominalTypeDecl *>(this);
return evaluateOrDefault(
getASTContext().evaluator,
GetDistributedActorIDPropertyRequest{mutableThis},
nullptr);
}

BraceStmt *AbstractFunctionDecl::getBody(bool canSynthesize) const {
if ((getBodyKind() == BodyKind::Synthesize ||
getBodyKind() == BodyKind::Unparsed) &&
Expand Down
6 changes: 3 additions & 3 deletions lib/AST/TypeCheckRequests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1055,11 +1055,11 @@ void swift::simple_display(llvm::raw_ostream &out,
case ImplicitMemberAction::ResolveDistributedActor:
out << "resolve DistributedActor";
break;
case ImplicitMemberAction::ResolveDistributedActorIdentity:
case ImplicitMemberAction::ResolveDistributedActorID:
out << "resolve DistributedActor.id";
break;
case ImplicitMemberAction::ResolveDistributedActorTransport:
out << "resolve DistributedActor.actorTransport";
case ImplicitMemberAction::ResolveDistributedActorSystem:
out << "resolve DistributedActor.actorSystem";
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5307,7 +5307,7 @@ SpecialProtocol irgen::getSpecialProtocolID(ProtocolDecl *P) {
case KnownProtocolKind::Differentiable:
case KnownProtocolKind::FloatingPoint:
case KnownProtocolKind::Actor:
case KnownProtocolKind::ActorTransport:
case KnownProtocolKind::DistributedActorSystem:
case KnownProtocolKind::DistributedActor:
case KnownProtocolKind::ActorIdentity:
case KnownProtocolKind::SerialExecutor:
Expand Down
Loading