Skip to content

Commit f92f2fe

Browse files
authored
Merge pull request #37738 from ktoso/wip-distributed-dynamic-2
2 parents 0e5f0b0 + bb9f2e4 commit f92f2fe

25 files changed

+496
-209
lines changed

include/swift/AST/Decl.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5298,7 +5298,10 @@ class ParamDecl : public VarDecl {
52985298

52995299
/// Create a new ParamDecl identical to the first except without the interface type.
53005300
static ParamDecl *cloneWithoutType(const ASTContext &Ctx, ParamDecl *PD);
5301-
5301+
5302+
/// Create a an identical copy of this ParamDecl.
5303+
static ParamDecl *clone(const ASTContext &Ctx, ParamDecl *PD);
5304+
53025305
/// Retrieve the argument (API) name for this function parameter.
53035306
Identifier getArgumentName() const {
53045307
return ArgumentNameAndDestructured.getPointer();

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4436,11 +4436,9 @@ ERROR(distributed_actor_func_param_not_codable,none,
44364436
ERROR(distributed_actor_func_result_not_codable,none,
44374437
"distributed function result type %0 does not conform to 'Codable'",
44384438
(Type))
4439-
ERROR(distributed_actor_func_missing_remote_func,none,
4440-
"distributed function is missing its remote static func implementation (%0). "
4441-
"You may want to use a distributed actor SwiftPM plugin to generate those, "
4442-
"or implement it manually.",
4443-
(Identifier))
4439+
ERROR(distributed_actor_remote_func_implemented_manually,none,
4440+
"Distributed function's %0 remote counterpart %1 cannot not be implemented manually.",
4441+
(Identifier, Identifier))
44444442
ERROR(distributed_actor_remote_func_is_not_static,none,
44454443
"remote function %0 must be static.",
44464444
(DeclName))

include/swift/AST/KnownSDKDecls.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
# define KNOWN_SDK_FUNC_DECL(Module, Name, Id)
2020
#endif
2121

22+
KNOWN_SDK_FUNC_DECL(Distributed, MissingDistributedActorTransport, "_missingDistributedActorTransport")
23+
KNOWN_SDK_FUNC_DECL(Distributed, IsRemoteDistributedActor, "__isRemoteActor")
2224

2325
#undef KNOWN_SDK_FUNC_DECL
2426

include/swift/AST/ParameterList.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ class alignas(ParamDecl *) ParameterList final :
6767
return create(decl->getASTContext(), decl);
6868
}
6969

70+
static ParameterList *clone(const ASTContext &Ctx, ParameterList *PL) {
71+
SmallVector<ParamDecl*, 4> params;
72+
params.reserve(PL->size());
73+
for (auto p : *PL)
74+
params.push_back(ParamDecl::clone(Ctx, p));
75+
return ParameterList::create(Ctx, params);
76+
}
77+
7078
SourceLoc getLParenLoc() const { return LParenLoc; }
7179
SourceLoc getRParenLoc() const { return RParenLoc; }
7280

lib/AST/ASTVerifier.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,6 +2309,12 @@ class Verifier : public ASTWalker {
23092309
}
23102310

23112311
void verifyChecked(ValueDecl *VD) {
2312+
if (VD->getName().isSimpleName() &&
2313+
!VD->getName().isSpecial() &&
2314+
VD->getName().getBaseIdentifier().str() == "echo") {
2315+
VD->dump();
2316+
}
2317+
23122318
if (VD->getInterfaceType()->hasError()) {
23132319
Out << "checked decl cannot have error type\n";
23142320
VD->dump(Out);

lib/AST/Decl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6324,6 +6324,12 @@ ParamDecl *ParamDecl::cloneWithoutType(const ASTContext &Ctx, ParamDecl *PD) {
63246324
return Clone;
63256325
}
63266326

6327+
ParamDecl *ParamDecl::clone(const ASTContext &Ctx, ParamDecl *PD) {
6328+
auto *Clone = ParamDecl::cloneWithoutType(Ctx, PD);
6329+
Clone->setInterfaceType(PD->getInterfaceType());
6330+
return Clone;
6331+
}
6332+
63276333
/// Retrieve the type of 'self' for the given context.
63286334
Type DeclContext::getSelfTypeInContext() const {
63296335
assert(isTypeContext());

lib/SIL/IR/SILDeclRef.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ bool swift::requiresForeignEntryPoint(ValueDecl *vd) {
121121
return false;
122122
}
123123

124-
SILDeclRef::SILDeclRef(ValueDecl *vd, SILDeclRef::Kind kind, bool isForeign,
125-
bool isDistributed,
124+
SILDeclRef::SILDeclRef(ValueDecl *vd, SILDeclRef::Kind kind,
125+
bool isForeign, bool isDistributed,
126126
AutoDiffDerivativeFunctionIdentifier *derivativeId)
127127
: loc(vd), kind(kind), isForeign(isForeign), isDistributed(isDistributed),
128128
defaultArgIndex(0), pointer(derivativeId) {}
@@ -171,7 +171,7 @@ SILDeclRef::SILDeclRef(SILDeclRef::Loc baseLoc, bool asForeign, bool asDistribut
171171

172172
SILDeclRef::SILDeclRef(SILDeclRef::Loc baseLoc,
173173
GenericSignature prespecializedSig)
174-
: SILDeclRef(baseLoc, false) {
174+
: SILDeclRef(baseLoc, false, false) {
175175
pointer = prespecializedSig.getPointer();
176176
}
177177

lib/SILGen/SILGenBridging.cpp

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,7 +1960,7 @@ void SILGenFunction::emitDistributedThunk(SILDeclRef thunk) {
19601960
//
19611961
// func X_distributedThunk(...) async throws -> T {
19621962
// if __isRemoteActor(self) {
1963-
// return try await Self.__remote_X(...)
1963+
// return try await self._remote_X(...)
19641964
// } else {
19651965
// return try await self.X(...)
19661966
// }
@@ -2011,19 +2011,9 @@ void SILGenFunction::emitDistributedThunk(SILDeclRef thunk) {
20112011
// ...
20122012
// }
20132013
{
2014-
auto desc = UnqualifiedLookupDescriptor(
2015-
DeclNameRef(ctx.Id___isRemoteActor),
2016-
fd->getDeclContext(), fd->getLoc(), UnqualifiedLookupOptions());
2017-
auto lookup =
2018-
evaluateOrDefault(ctx.evaluator, UnqualifiedLookupRequest{desc}, {});
2019-
FuncDecl *isRemoteFn = nullptr;
2020-
for (const auto &result : lookup) {
2021-
// FIXME: Validate this further, because we're assuming the exact type.
2022-
if (auto func = dyn_cast<FuncDecl>(result.getValueDecl())) {
2023-
isRemoteFn = func;
2024-
break;
2025-
}
2026-
}
2014+
FuncDecl* isRemoteFn = ctx.getIsRemoteDistributedActor();
2015+
assert(isRemoteFn &&
2016+
"Could not find 'is remote' function, is the '_Distributed' module available?");
20272017

20282018
ManagedValue selfAnyObject = B.createInitExistentialRef(loc, getLoweredType(ctx.getAnyObjectType()),
20292019
CanType(selfType),
@@ -2037,39 +2027,37 @@ void SILGenFunction::emitDistributedThunk(SILDeclRef thunk) {
20372027
B.createCondBranch(loc, isRemoteResultUnwrapped, isRemoteBB, isLocalBB);
20382028
}
20392029

2040-
20412030
// if __isRemoteActor(self) {
2042-
// return try await Self._remote_X(...)
2031+
// return try await self._remote_X(...)
20432032
// }
20442033
{
20452034
B.emitBlock(isRemoteBB);
20462035

20472036
auto *selfTyDecl = FunctionDC->getParent()->getSelfNominalTypeDecl();
2048-
// FIXME: should this be an llvm_unreachable instead?
20492037
assert(selfTyDecl && "distributed function declared outside of actor");
20502038

2051-
auto selfMetatype = getLoweredType(selfTyDecl->getInterfaceType());
2052-
SILValue metatypeValue = B.createMetatype(loc, selfMetatype);
2039+
// auto selfMetatype = getLoweredType(selfTyDecl->getInterfaceType());
2040+
// SILValue metatypeValue = B.createMetatype(loc, selfMetatype);
20532041

20542042
auto remoteFnDecl = selfTyDecl->lookupDirectRemoteFunc(fd);
20552043
assert(remoteFnDecl && "Could not find _remote_<dist_func_name> function");
20562044
auto remoteFnRef = SILDeclRef(remoteFnDecl);
20572045

20582046
SILGenFunctionBuilder builder(SGM);
20592047
auto remoteFnSIL = builder.getOrCreateFunction(loc, remoteFnRef, ForDefinition);
2060-
20612048
SILValue remoteFn = B.createFunctionRefFor(loc, remoteFnSIL);
20622049

20632050
auto subs = F.getForwardingSubstitutionMap();
20642051

20652052
SmallVector<SILValue, 8> remoteParams(params);
2066-
remoteParams.emplace_back(metatypeValue);
2053+
// remoteParams.emplace_back(metatypeValue);
20672054

2055+
// B.createTryApply(loc, remoteFn, subs, params, remoteReturnBB, remoteErrorBB);
20682056
B.createTryApply(loc, remoteFn, subs, remoteParams, remoteReturnBB, remoteErrorBB);
20692057
}
20702058

20712059
// else {
2072-
// return try await self.X(...)
2060+
// return (try)? (await)? self.X(...)
20732061
// }
20742062
{
20752063
B.emitBlock(isLocalBB);

lib/Sema/CodeSynthesis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include "swift/Sema/ConstraintSystem.h"
3636
#include "llvm/ADT/SmallString.h"
3737
#include "llvm/ADT/StringExtras.h"
38-
#include "CodeSynthesisDistributedActor.cpp"
38+
#include "CodeSynthesisDistributedActor.cpp" // FIXME: remove this!!!
3939
using namespace swift;
4040

4141
const bool IsImplicit = true;

0 commit comments

Comments
 (0)