Skip to content

Commit d7cb89b

Browse files
committed
prepare roundtrip test
1 parent 785f2e1 commit d7cb89b

File tree

6 files changed

+328
-42
lines changed

6 files changed

+328
-42
lines changed

stdlib/public/Concurrency/Actor.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ void swift::runJobInEstablishedExecutorContext(Job *job) {
239239
task->runInFullyEstablishedContext();
240240

241241
assert(ActiveTask::get() == nullptr &&
242-
"active task wasn't cleared before susspending?");
242+
"active task wasn't cleared before suspending?");
243243
} else {
244244
// There's no extra bookkeeping to do for simple jobs besides swapping in
245245
// the voucher.
@@ -1726,11 +1726,7 @@ void ::swift_distributed_execute_target(
17261726
void *argumentBuffer,
17271727
void *resultBuffer) {
17281728
auto *accessor = findDistributedAccessor(targetNameStart, targetNameLength);
1729-
if (!accessor) {
1730-
assert(false && "no distributed accessor accessor");
1731-
return;
1732-
}
1733-
fprintf(stderr, "[%s:%d] (%s) found accessor\n", __FILE__, __LINE__, __FUNCTION__);
1729+
assert(accessor && "no distributed accessor accessor");
17341730

17351731
auto *asyncFnPtr = reinterpret_cast<
17361732
const AsyncFunctionPointer<DistributedAccessorSignature> *>(

stdlib/public/Distributed/DistributedActorSystem.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ public protocol DistributedActorSystem: Sendable {
124124
// func remoteCall<Act, Err, Res>(
125125
// on actor: Act,
126126
// target: RemoteCallTarget,
127-
// arguments: Invocation,
127+
// invocation: Invocation,
128128
// throwing: Err.Type,
129129
// returning: Res.Type
130-
// ) async throws -> Res.Type
130+
// ) async throws -> Res
131131
// where Act: DistributedActor,
132132
// Act.ID == ActorID,
133133
// Res: SerializationRequirement
@@ -205,8 +205,7 @@ extension DistributedActorSystem {
205205
guard decodedNum == paramCount else {
206206
throw ExecuteDistributedTargetError(
207207
message: """
208-
Failed to decode the expected number of params of distributed invocation target, error code: \(decodedNum)
209-
(decoded: \(decodedNum), expected params: \(paramCount)
208+
Failed to decode the expected [\(paramCount)] number of parameter types of distributed invocation target, error code: \(decodedNum);
210209
mangled name: \(mangledTargetName)
211210
""")
212211
}
@@ -287,15 +286,16 @@ func _executeDistributedTarget(
287286
/// A distributed 'target' can be a `distributed func` or `distributed` computed property.
288287
@available(SwiftStdlib 5.6, *)
289288
public struct RemoteCallTarget {
290-
let mangledName: String
289+
public let mangledName: String
291290

292291
// Only intended to be created by the _Distributed library.
293-
internal init(mangledName: String) {
292+
// TODO(distributed): make internal
293+
public init(_mangledName mangledName: String) {
294294
self.mangledName = mangledName
295295
}
296296

297297
// <module>.Base.hello(hi:)
298-
var fullName: String {
298+
public var fullName: String {
299299
fatalError("NOT IMPLEMENTED YET: \(#function)")
300300
}
301301
}

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,17 +1921,20 @@ swift_func_getParameterCount(const char *typeNameStart, size_t typeNameLength) {
19211921
node = node->findByKind(Node::Kind::Function, /*maxDepth=*/2);
19221922
if (!node) return -3;
19231923

1924-
node = node->findByKind(Node::Kind::Type, /*maxDepth=*/2);
1925-
if (!node) return -4;
1926-
19271924
node = node->findByKind(Node::Kind::ArgumentTuple, /*maxDepth=*/3);
1928-
// Get the "deepest" Tuple from the ArgumentTuple, that's the arguments
1929-
while (node && node->getKind() != Node::Kind::Tuple) {
1930-
node = node->getFirstChild();
1931-
}
1925+
auto typeNode = node->findByKind(Node::Kind::Type, /*maxDepth=*/1);
1926+
if (!typeNode) return 0;
19321927

1933-
if (node) {
1934-
return node->getNumChildren();
1928+
assert(typeNode->getKind() == Node::Kind::Type);
1929+
if (auto paramsNode = typeNode->getFirstChild()) {
1930+
if (paramsNode->getKind() == Node::Kind::Tuple) {
1931+
return paramsNode->getNumChildren();
1932+
} else {
1933+
// it was some specific type e.g. Structure
1934+
return 1;
1935+
}
1936+
} else {
1937+
return -11;
19351938
}
19361939

19371940
return -5;
@@ -1994,17 +1997,9 @@ swift_func_getParameterTypeInfo(
19941997
node = node->findByKind(Node::Kind::Type, /*maxDepth=*/2);
19951998
if (!node) return -4;
19961999

2000+
auto argumentTuple = node->findByKind(Node::Kind::ArgumentTuple, /*maxDepth=*/3);
19972001
node = node->findByKind(Node::Kind::ArgumentTuple, /*maxDepth=*/3);
1998-
// Get the "deepest" Tuple from the ArgumentTuple, that's the arguments
1999-
while (node && node->getKind() != Node::Kind::Tuple) {
2000-
node = node->getFirstChild();
2001-
}
2002-
2003-
// Only successfully return if the expected parameter count is the same
2004-
// as space prepared for it in the buffer.
2005-
if (!node || (node && node->getNumChildren() != typesLength)) {
2006-
return -5;
2007-
}
2002+
node = node->findByKind(Node::Kind::Type, /*maxDepth=*/1);
20082003

20092004
DecodedMetadataBuilder builder(
20102005
demangler,
@@ -2014,22 +2009,34 @@ swift_func_getParameterTypeInfo(
20142009
[](const Metadata *, unsigned) { return nullptr; });
20152010
TypeDecoder<DecodedMetadataBuilder> decoder(builder);
20162011

2012+
// --- Handle a single parameter:
2013+
if (!node) return -9;
2014+
if (node->getFirstChild() &&
2015+
node->getFirstChild()->getKind() != Node::Kind::Tuple) {
2016+
auto builtTypeOrError = decoder.decodeMangledType(argumentTuple);
2017+
if (builtTypeOrError.isError()) {
2018+
auto err = builtTypeOrError.getError();
2019+
char *errStr = err->copyErrorString();
2020+
err->freeErrorString(errStr);
2021+
return -10;
2022+
}
2023+
2024+
assert(typesLength == 1);
2025+
types[0] = builtTypeOrError.getType();
2026+
return 1;
2027+
}
2028+
2029+
// --- Handle multiple parameters:
2030+
node = node->findByKind(Node::Kind::Tuple, /*maxDepth=*/2);
20172031
auto typeIdx = 0;
20182032
// for each parameter (TupleElement), store it into the provided buffer
20192033
for (auto tupleElement : *node) {
2020-
assert(tupleElement->getKind() == Node::Kind::TupleElement);
2021-
assert(tupleElement->getNumChildren() == 1);
2022-
2023-
auto typeNode = tupleElement->getFirstChild();
2024-
assert(typeNode->getKind() == Node::Kind::Type);
2025-
20262034
auto builtTypeOrError = decoder.decodeMangledType(tupleElement);
20272035
if (builtTypeOrError.isError()) {
20282036
auto err = builtTypeOrError.getError();
20292037
char *errStr = err->copyErrorString();
20302038
err->freeErrorString(errStr);
2031-
typeIdx += 1;
2032-
continue;
2039+
return -20;
20332040
}
20342041

20352042
types[typeIdx] = builtTypeOrError.getType();

test/Distributed/Runtime/distributed_actor_remoteCall.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// XXX: %target-swift-frontend -primary-file %s -emit-sil -parse-as-library -enable-experimental-distributed -disable-availability-checking | %FileCheck %s --enable-var-scope --dump-input=always
2-
// TODO: %target-run-simple-swift( -Xfrontend -module-name=main -Xfrontend -disable-availability-checking -Xfrontend -enable-experimental-distributed -parse-as-library) | %FileCheck %s --dump-input=always
2+
// RUN: %target-run-simple-swift( -Xfrontend -module-name=main -Xfrontend -disable-availability-checking -Xfrontend -enable-experimental-distributed -parse-as-library) | %FileCheck %s --dump-input=always
33

44
// REQUIRES: executable_test
55
// REQUIRES: concurrency

0 commit comments

Comments
 (0)