Skip to content

[Distributed] Func metadata operations and implement executeDistributedTarget entry #40605

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 7 commits into from
Jan 9, 2022
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
2 changes: 2 additions & 0 deletions include/swift/AST/KnownIdentifiers.def
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ IDENTIFIER(using)
IDENTIFIER(assignID)
IDENTIFIER(resignID)
IDENTIFIER(resolve)
IDENTIFIER(remoteCall)
IDENTIFIER(makeInvocation)
IDENTIFIER(system)
IDENTIFIER(ID)
IDENTIFIER(id)
Expand Down
4 changes: 4 additions & 0 deletions include/swift/Demangling/Demangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ class Node {
// Reverses the order of children.
void reverseChildren(size_t StartingAt = 0);

// Find a node by its kind, traversing the node depth-first,
// and bailing out early if not found at the 'maxDepth'.
NodePointer findByKind(Node::Kind kind, int maxDepth);

/// Prints the whole node tree in readable form to stderr.
///
/// Useful to be called from the debugger.
Expand Down
1 change: 1 addition & 0 deletions include/swift/Demangling/TypeDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@ return {}; // Not Implemented!
// TODO: Handle OpaqueReturnType, when we're in the middle of reconstructing
// the defining decl
default:

return MAKE_NODE_TYPE_ERROR0(Node, "unexpected kind");
}
}
Expand Down
14 changes: 14 additions & 0 deletions lib/Demangling/Demangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,20 @@ void Node::reverseChildren(size_t StartingAt) {
}
}

Node* Node::findByKind(Node::Kind kind, int maxDepth) {
if (getKind() == kind)
return this;

if (maxDepth <= 0)
return nullptr;

for (auto node : *this)
if (auto matchingChild = node->findByKind(kind, maxDepth - 1))
return matchingChild;

return nullptr;
}

//////////////////////////////////
// NodeFactory member functions //
//////////////////////////////////
Expand Down
3 changes: 3 additions & 0 deletions lib/IRGen/Callee.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ namespace irgen {
AsyncLetGetThrowing,
AsyncLetFinish,
TaskGroupWaitNext,
DistributedExecuteTarget,
};

class Kind {
Expand Down Expand Up @@ -221,6 +222,7 @@ namespace irgen {
case SpecialKind::AsyncLetWait:
case SpecialKind::AsyncLetWaitThrowing:
case SpecialKind::TaskGroupWaitNext:
case SpecialKind::DistributedExecuteTarget:
return false;
}

Expand All @@ -243,6 +245,7 @@ namespace irgen {
case SpecialKind::AsyncLetGetThrowing:
case SpecialKind::AsyncLetFinish:
case SpecialKind::TaskGroupWaitNext:
case SpecialKind::DistributedExecuteTarget:
return true;
}
llvm_unreachable("covered switch");
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenDistributed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void DistributedAccessor::computeArguments(llvm::Value *argumentBuffer,
Address(currentOffset, IGM.getPointerAlignment()),
IGM.getStoragePointerType(paramTy));

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

if (paramTy.isObject()) {
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/IRGenModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ class IRGenerator {
/// Emit type metadata records for types without explicit protocol conformance.
void emitTypeMetadataRecords();

/// Emit type metadata recrods for functions that can be looked up by name at
/// Emit type metadata records for functions that can be looked up by name at
/// runtime.
void emitAccessibleFunctions();

Expand Down
3 changes: 3 additions & 0 deletions lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2572,6 +2572,9 @@ FunctionPointer::Kind irgen::classifyFunctionPointerKind(SILFunction *fn) {

if (name.equals("swift_taskGroup_wait_next_throwing"))
return SpecialKind::TaskGroupWaitNext;

if (name.equals("swift_distributed_execute_target"))
return SpecialKind::DistributedExecuteTarget;
}

return fn->getLoweredFunctionType();
Expand Down
14 changes: 9 additions & 5 deletions stdlib/public/Concurrency/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1721,17 +1721,21 @@ static void ::swift_distributed_execute_target_resume(

SWIFT_CC(swiftasync)
void ::swift_distributed_execute_target(
SWIFT_ASYNC_CONTEXT AsyncContext *callerContext, DefaultActor *actor,
const char *targetNameStart, size_t targetNameLength, void *argumentBuffer,
SWIFT_ASYNC_CONTEXT AsyncContext *callerContext,
DefaultActor *actor,
const char *targetNameStart, size_t targetNameLength,
void *argumentBuffer,
void *resultBuffer) {
auto *accessor = findDistributedAccessor(targetNameStart, targetNameLength);

if (!accessor)
return;
if (!accessor) {
assert(false && "no distributed accessor accessor");
return; // FIXME(distributed): return -1 here so the lib can fail the call
}

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

DistributedAccessorSignature::FunctionType *accessorEntry =
asyncFnPtr->Function.get();
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/Distributed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ add_swift_target_library(swift_Distributed ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
AssertDistributed.swift
DistributedActor.swift
DistributedActorSystem.swift
DistributedMetadata.swift
HeterogeneousBuffer.swift

SWIFT_MODULE_DEPENDS_LINUX Glibc
Expand Down
23 changes: 0 additions & 23 deletions stdlib/public/Distributed/DistributedActor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,29 +144,6 @@ extension DistributedActor {
}
}

/******************************************************************************/
/******************************** Misc ****************************************/
/******************************************************************************/

/// Error protocol to which errors thrown by any `DistributedActorSystem` should conform.
@available(SwiftStdlib 5.6, *)
public protocol DistributedActorSystemError: Error {
}

@available(SwiftStdlib 5.6, *)
public struct DistributedActorCodingError: DistributedActorSystemError {
public let message: String

public init(message: String) {
self.message = message
}

public static func missingActorSystemUserInfo<Act>(_ actorType: Act.Type) -> Self
where Act: DistributedActor {
.init(message: "Missing DistributedActorSystem userInfo while decoding")
}
}

/******************************************************************************/
/************************* Runtime Functions **********************************/
/******************************************************************************/
Expand Down
Loading