Skip to content

Commit 3a998d7

Browse files
committed
[Distributed] Improve getting return type metadata for distributed invocations
rdar://141313340
1 parent c4af3b3 commit 3a998d7

File tree

3 files changed

+89
-5
lines changed

3 files changed

+89
-5
lines changed

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2945,8 +2945,13 @@ swift_func_getReturnTypeInfo(const char *typeNameStart, size_t typeNameLength,
29452945

29462946
SubstGenericParametersFromMetadata substFn(genericEnv, genericArguments);
29472947

2948-
DecodedMetadataBuilder builder(
2949-
demangler,
2948+
auto request = MetadataRequest(MetadataState::Complete,
2949+
/*non-blocking*/ true);
2950+
2951+
NodePointer nodePointer = resultType->getFirstChild();
2952+
auto typeInfoOrErr = swift_getTypeByMangledNode(
2953+
request, demangler, nodePointer,
2954+
/*arguments=*/{},
29502955
/*substGenericParam=*/
29512956
[&substFn](unsigned depth, unsigned index) {
29522957
return substFn.getMetadata(depth, index).Ptr;
@@ -2956,9 +2961,12 @@ swift_func_getReturnTypeInfo(const char *typeNameStart, size_t typeNameLength,
29562961
return substFn.getWitnessTable(type, index);
29572962
});
29582963

2959-
TypeDecoder<DecodedMetadataBuilder> decoder(builder);
2964+
if (typeInfoOrErr.isError()) {
2965+
return nullptr;
2966+
}
29602967

2961-
return decodeType(decoder, resultType->getFirstChild());
2968+
auto typeInfo = typeInfoOrErr.getType();
2969+
return typeInfo.getMetadata();
29622970
}
29632971

29642972
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_SPI

test/Distributed/Inputs/FakeDistributedActorSystems.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ public final class FakeInvocationDecoder: DistributedTargetInvocationDecoder {
459459

460460
var argumentIndex: Int = 0
461461

462-
fileprivate init(
462+
public init(
463463
args: [Any],
464464
substitutions: [Any.Type] = [],
465465
returnType: Any.Type? = nil,
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -target %target-swift-5.7-abi-triple %S/../Inputs/FakeDistributedActorSystems.swift
3+
// RUN: %target-build-swift -module-name main -target %target-swift-5.7-abi-triple -j2 -parse-as-library -plugin-path %swift-plugin-dir -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
4+
// RUN: %target-codesign %t/a.out
5+
// RUN: %target-run %t/a.out | %FileCheck %s
6+
7+
// REQUIRES: executable_test
8+
// REQUIRES: concurrency
9+
// REQUIRES: distributed
10+
11+
// rdar://76038845
12+
// UNSUPPORTED: use_os_stdlib
13+
// UNSUPPORTED: back_deployment_runtime
14+
15+
// FIXME(distributed): Distributed actors currently have some issues on windows, isRemote always returns false. rdar://82593574
16+
// UNSUPPORTED: OS=windows-msvc
17+
18+
import Distributed
19+
import FakeDistributedActorSystems
20+
21+
typealias DefaultDistributedActorSystem = FakeRoundtripActorSystem
22+
23+
struct SuperLargeSizeStruct: Codable {
24+
let i1a: Int = 0
25+
let i2a: Int = 0
26+
let i3a: Int = 0
27+
let i4a: Int = 0
28+
let i5a: Int = 0
29+
let i6a: Int = 0
30+
let i7a: Int = 0
31+
let i8a: Int = 0
32+
}
33+
34+
@available(SwiftStdlib 6.0, *)
35+
distributed actor TheWorker {
36+
typealias ActorSystem = DefaultDistributedActorSystem
37+
38+
distributed func callMeCallMe() async throws -> SuperLargeSizeStruct {
39+
return .init()
40+
}
41+
}
42+
43+
@available(SwiftStdlib 6.0, *)
44+
func test_generic(system: DefaultDistributedActorSystem) async throws {
45+
let localW = TheWorker(actorSystem: system)
46+
let remoteW = try! TheWorker.resolve(id: localW.id, using: system)
47+
48+
let target = RemoteCallTarget("$s4main9TheWorkerC010callMeCallE0AA20SuperLargeSizeStructVyYaKFTE")
49+
var invocation = FakeInvocationEncoder()
50+
try invocation.recordReturnType(SuperLargeSizeStruct.self)
51+
try invocation.recordErrorType(Error.self)
52+
try invocation.doneRecording()
53+
54+
do {
55+
try await system.remoteCall(
56+
on: localW,
57+
target: target,
58+
invocation: &invocation,
59+
throwing: Error.self,
60+
returning: SuperLargeSizeStruct.self
61+
)
62+
// CHECK: >> remoteCall: on:main.TheWorker, target:main.TheWorker.callMeCallMe(), invocation:FakeInvocationEncoder(genericSubs: [], arguments: [], returnType: Optional(main.SuperLargeSizeStruct), errorType: Optional(Swift.Error)), throwing:Swift.Error, returning:main.SuperLargeSizeStruct
63+
// CHECK: > execute distributed target: main.TheWorker.callMeCallMe(), identifier: $s4main9TheWorkerC010callMeCallE0AA20SuperLargeSizeStructVyYaKFTE
64+
// CHECK: << remoteCall return: SuperLargeSizeStruct
65+
}
66+
print("==== ----------------------------------------------------------------")
67+
}
68+
69+
@available(SwiftStdlib 6.0, *)
70+
@main struct Main {
71+
static func main() async {
72+
let system = DefaultDistributedActorSystem()
73+
print("===================================================================")
74+
try! await test_generic(system: system)
75+
}
76+
}

0 commit comments

Comments
 (0)