Skip to content

Commit 9438cf6

Browse files
authored
[Distributed] Func metadata operations and implement executeDistributedTarget entry (swiftlang#40605)
* [Distributed] Implement func metadata and executeDistributedTarget dont expose new entrypoints able to get all the way to calling _execute * [Distributed] reimplement distributed get type info impls * [Distributed] comment out distributed_actor_remoteCall for now * [Distributed] disable test on linux for now
1 parent f69c988 commit 9438cf6

17 files changed

+746
-132
lines changed

include/swift/AST/KnownIdentifiers.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ IDENTIFIER(using)
266266
IDENTIFIER(assignID)
267267
IDENTIFIER(resignID)
268268
IDENTIFIER(resolve)
269+
IDENTIFIER(remoteCall)
270+
IDENTIFIER(makeInvocation)
269271
IDENTIFIER(system)
270272
IDENTIFIER(ID)
271273
IDENTIFIER(id)

include/swift/Demangling/Demangle.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ class Node {
258258
// Reverses the order of children.
259259
void reverseChildren(size_t StartingAt = 0);
260260

261+
// Find a node by its kind, traversing the node depth-first,
262+
// and bailing out early if not found at the 'maxDepth'.
263+
NodePointer findByKind(Node::Kind kind, int maxDepth);
264+
261265
/// Prints the whole node tree in readable form to stderr.
262266
///
263267
/// Useful to be called from the debugger.

include/swift/Demangling/TypeDecoder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,7 @@ return {}; // Not Implemented!
12621262
// TODO: Handle OpaqueReturnType, when we're in the middle of reconstructing
12631263
// the defining decl
12641264
default:
1265+
12651266
return MAKE_NODE_TYPE_ERROR0(Node, "unexpected kind");
12661267
}
12671268
}

lib/Demangling/Demangler.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,20 @@ void Node::reverseChildren(size_t StartingAt) {
417417
}
418418
}
419419

420+
Node* Node::findByKind(Node::Kind kind, int maxDepth) {
421+
if (getKind() == kind)
422+
return this;
423+
424+
if (maxDepth <= 0)
425+
return nullptr;
426+
427+
for (auto node : *this)
428+
if (auto matchingChild = node->findByKind(kind, maxDepth - 1))
429+
return matchingChild;
430+
431+
return nullptr;
432+
}
433+
420434
//////////////////////////////////
421435
// NodeFactory member functions //
422436
//////////////////////////////////

lib/IRGen/Callee.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ namespace irgen {
176176
AsyncLetGetThrowing,
177177
AsyncLetFinish,
178178
TaskGroupWaitNext,
179+
DistributedExecuteTarget,
179180
};
180181

181182
class Kind {
@@ -221,6 +222,7 @@ namespace irgen {
221222
case SpecialKind::AsyncLetWait:
222223
case SpecialKind::AsyncLetWaitThrowing:
223224
case SpecialKind::TaskGroupWaitNext:
225+
case SpecialKind::DistributedExecuteTarget:
224226
return false;
225227
}
226228

@@ -243,6 +245,7 @@ namespace irgen {
243245
case SpecialKind::AsyncLetGetThrowing:
244246
case SpecialKind::AsyncLetFinish:
245247
case SpecialKind::TaskGroupWaitNext:
248+
case SpecialKind::DistributedExecuteTarget:
246249
return true;
247250
}
248251
llvm_unreachable("covered switch");

lib/IRGen/GenDistributed.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ void DistributedAccessor::computeArguments(llvm::Value *argumentBuffer,
210210
Address(currentOffset, IGM.getPointerAlignment()),
211211
IGM.getStoragePointerType(paramTy));
212212

213-
// 3. Adjust typed pointer to the alignement of the type.
213+
// 3. Adjust typed pointer to the alignment of the type.
214214
auto alignedOffset = typeInfo.roundUpToTypeAlignment(IGF, eltPtr, paramTy);
215215

216216
if (paramTy.isObject()) {

lib/IRGen/IRGenModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ class IRGenerator {
401401
/// Emit type metadata records for types without explicit protocol conformance.
402402
void emitTypeMetadataRecords();
403403

404-
/// Emit type metadata recrods for functions that can be looked up by name at
404+
/// Emit type metadata records for functions that can be looked up by name at
405405
/// runtime.
406406
void emitAccessibleFunctions();
407407

lib/IRGen/IRGenSIL.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2573,6 +2573,9 @@ FunctionPointer::Kind irgen::classifyFunctionPointerKind(SILFunction *fn) {
25732573

25742574
if (name.equals("swift_taskGroup_wait_next_throwing"))
25752575
return SpecialKind::TaskGroupWaitNext;
2576+
2577+
if (name.equals("swift_distributed_execute_target"))
2578+
return SpecialKind::DistributedExecuteTarget;
25762579
}
25772580

25782581
return fn->getLoweredFunctionType();

stdlib/public/Concurrency/Actor.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,17 +1721,21 @@ static void ::swift_distributed_execute_target_resume(
17211721

17221722
SWIFT_CC(swiftasync)
17231723
void ::swift_distributed_execute_target(
1724-
SWIFT_ASYNC_CONTEXT AsyncContext *callerContext, DefaultActor *actor,
1725-
const char *targetNameStart, size_t targetNameLength, void *argumentBuffer,
1724+
SWIFT_ASYNC_CONTEXT AsyncContext *callerContext,
1725+
DefaultActor *actor,
1726+
const char *targetNameStart, size_t targetNameLength,
1727+
void *argumentBuffer,
17261728
void *resultBuffer) {
17271729
auto *accessor = findDistributedAccessor(targetNameStart, targetNameLength);
1728-
1729-
if (!accessor)
1730-
return;
1730+
if (!accessor) {
1731+
assert(false && "no distributed accessor accessor");
1732+
return; // FIXME(distributed): return -1 here so the lib can fail the call
1733+
}
17311734

17321735
auto *asyncFnPtr = reinterpret_cast<
17331736
const AsyncFunctionPointer<DistributedAccessorSignature> *>(
17341737
accessor->Function.get());
1738+
assert(asyncFnPtr && "no function pointer for distributed_execute_target");
17351739

17361740
DistributedAccessorSignature::FunctionType *accessorEntry =
17371741
asyncFnPtr->Function.get();

stdlib/public/Distributed/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ add_swift_target_library(swift_Distributed ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
1818
AssertDistributed.swift
1919
DistributedActor.swift
2020
DistributedActorSystem.swift
21+
DistributedMetadata.swift
2122
HeterogeneousBuffer.swift
2223

2324
SWIFT_MODULE_DEPENDS_LINUX Glibc

stdlib/public/Distributed/DistributedActor.swift

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -144,29 +144,6 @@ extension DistributedActor {
144144
}
145145
}
146146

147-
/******************************************************************************/
148-
/******************************** Misc ****************************************/
149-
/******************************************************************************/
150-
151-
/// Error protocol to which errors thrown by any `DistributedActorSystem` should conform.
152-
@available(SwiftStdlib 5.6, *)
153-
public protocol DistributedActorSystemError: Error {
154-
}
155-
156-
@available(SwiftStdlib 5.6, *)
157-
public struct DistributedActorCodingError: DistributedActorSystemError {
158-
public let message: String
159-
160-
public init(message: String) {
161-
self.message = message
162-
}
163-
164-
public static func missingActorSystemUserInfo<Act>(_ actorType: Act.Type) -> Self
165-
where Act: DistributedActor {
166-
.init(message: "Missing DistributedActorSystem userInfo while decoding")
167-
}
168-
}
169-
170147
/******************************************************************************/
171148
/************************* Runtime Functions **********************************/
172149
/******************************************************************************/

0 commit comments

Comments
 (0)