Skip to content

Commit ed97120

Browse files
committed
[Distributed] Runtime: Implement _executeDistributedTarget
The implementation is as follows: - Looks up distributed accessor by the given target name - Extracts information required to setup async context from async function pointer stored in accessor record - Allocates context and calls accessor
1 parent 7ac42e1 commit ed97120

File tree

2 files changed

+58
-10
lines changed

2 files changed

+58
-10
lines changed

stdlib/public/Concurrency/Actor.cpp

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,16 +2016,63 @@ findDistributedAccessor(const char *targetNameStart, size_t targetNameLength) {
20162016
return nullptr;
20172017
}
20182018

2019+
/// func _executeDistributedTarget(
2020+
/// on: AnyObject,
2021+
/// _ targetName: UnsafePointer<UInt8>,
2022+
/// _ targetNameLength: UInt,
2023+
/// argumentBuffer: Builtin.RawPointer,
2024+
/// resultBuffer: Builtin.RawPointer) async throws
2025+
using TargetExecutorSignature =
2026+
AsyncSignature<void(DefaultActor *, const char *, size_t, void *, void *),
2027+
/*throws=*/true>;
2028+
2029+
SWIFT_CC(swiftasync)
2030+
SWIFT_RUNTIME_STDLIB_SPI
2031+
TargetExecutorSignature::FunctionType swift_distributed_execute_target;
2032+
2033+
/// Accessor takes a context, an argument buffer as a raw pointer,
2034+
/// and a reference to an actor.
2035+
using DistributedAccessorSignature = AsyncSignature<void(void *, HeapObject *),
2036+
/*throws=*/true>;
2037+
2038+
SWIFT_CC(swiftasync)
2039+
static DistributedAccessorSignature::ContinuationType
2040+
swift_distributed_execute_target_resume;
2041+
2042+
SWIFT_CC(swiftasync)
2043+
static void ::swift_distributed_execute_target_resume(
2044+
SWIFT_ASYNC_CONTEXT AsyncContext *context, SWIFT_CONTEXT void *error) {
2045+
auto parentCtx = context->Parent;
2046+
auto resumeInParent =
2047+
reinterpret_cast<TargetExecutorSignature::ContinuationType *>(
2048+
parentCtx->ResumeParent);
2049+
swift_task_dealloc(context);
2050+
return resumeInParent(parentCtx, error);
2051+
}
2052+
20192053
SWIFT_CC(swiftasync)
2020-
void swift_distributed_execute_target(
2021-
OpaqueValue *resultPointer,
2022-
SWIFT_ASYNC_CONTEXT AsyncContext *callerContext,
2023-
DefaultActor *actor,
2024-
const char *targetNameStart, size_t targetNameLength,
2025-
void *argumentBuffer,
2026-
void *resultBuffer,
2027-
ThrowingTaskFutureWaitContinuationFunction *resumeFn,
2028-
AsyncContext *callContext) {
2054+
void ::swift_distributed_execute_target(
2055+
SWIFT_ASYNC_CONTEXT AsyncContext *callerContext, DefaultActor *actor,
2056+
const char *targetNameStart, size_t targetNameLength, void *argumentBuffer,
2057+
void *resultBuffer) {
20292058
auto *accessor = findDistributedAccessor(targetNameStart, targetNameLength);
2030-
(void)accessor;
2059+
2060+
if (!accessor)
2061+
return;
2062+
2063+
auto *asyncFnPtr = reinterpret_cast<
2064+
const AsyncFunctionPointer<DistributedAccessorSignature> *>(accessor);
2065+
2066+
DistributedAccessorSignature::FunctionType *accessorEntry =
2067+
asyncFnPtr->Function.get();
2068+
2069+
AsyncContext *calleeContext = reinterpret_cast<AsyncContext *>(
2070+
swift_task_alloc(asyncFnPtr->ExpectedContextSize));
2071+
2072+
calleeContext->Parent = callerContext;
2073+
calleeContext->ResumeParent = reinterpret_cast<TaskContinuationFunction *>(
2074+
swift_distributed_execute_target_resume);
2075+
2076+
// TODO: Add resultBuffer as an argument to store an indirect result into.
2077+
accessorEntry(calleeContext, argumentBuffer, actor);
20312078
}

stdlib/public/Distributed/DistributedActor.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ func _distributedActorRemoteInitialize(_ actorType: Builtin.RawPointer) -> Any
187187

188188
// ==== Remote target accesss -------------------------------------------------
189189

190+
@available(SwiftStdlib 5.6, *)
190191
@_silgen_name("swift_distributed_execute_target")
191192
func _executeDistributedTarget(
192193
on: AnyObject,

0 commit comments

Comments
 (0)