Skip to content

Commit 0e35951

Browse files
committed
[Distributed] Stage use of generic environment to decode target parameter/result types
1 parent d54e329 commit 0e35951

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

stdlib/public/Distributed/DistributedActorSystem.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,13 @@ extension DistributedActorSystem {
168168

169169
// Get the expected parameter count of the func
170170
let nameUTF8 = Array(mangledTargetName.utf8)
171+
172+
// Gen the generic environment (if any) associated with the target.
173+
let genericEnv = nameUTF8.withUnsafeBufferPointer { nameUTF8 in
174+
_getGenericEnvironmentOfDistributedTarget(nameUTF8.baseAddress!,
175+
UInt(nameUTF8.endIndex))
176+
}
177+
171178
let paramCount = nameUTF8.withUnsafeBufferPointer { nameUTF8 in
172179
__getParameterCount(nameUTF8.baseAddress!, UInt(nameUTF8.endIndex))
173180
}
@@ -193,6 +200,7 @@ extension DistributedActorSystem {
193200
let decodedNum = nameUTF8.withUnsafeBufferPointer { nameUTF8 in
194201
__getParameterTypeInfo(
195202
nameUTF8.baseAddress!, UInt(nameUTF8.endIndex),
203+
genericEnv,
196204
paramTypesBuffer.baseAddress!._rawValue, Int(paramCount))
197205
}
198206

@@ -220,7 +228,8 @@ extension DistributedActorSystem {
220228
return UnsafeRawPointer(UnsafeMutablePointer<R>.allocate(capacity: 1))
221229
}
222230

223-
guard let returnTypeFromTypeInfo: Any.Type = _getReturnTypeInfo(mangledMethodName: mangledTargetName) else {
231+
guard let returnTypeFromTypeInfo: Any.Type = _getReturnTypeInfo(mangledMethodName: mangledTargetName,
232+
genericEnv: genericEnv) else {
224233
throw ExecuteDistributedTargetError(
225234
message: "Failed to decode distributed target return type")
226235
}

stdlib/public/Distributed/DistributedMetadata.swift

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ func __getParameterCount(
4141
@available(SwiftStdlib 5.6, *)
4242
public // SPI _Distributed
4343
func _getParameterTypeInfo(
44-
mangledMethodName name: String,
45-
into typesBuffer: Builtin.RawPointer, length typesLength: Int
44+
mangledMethodName name: String,
45+
genericEnv: UnsafeRawPointer?, // GenericEnvironmentDescriptor *
46+
into typesBuffer: Builtin.RawPointer, length typesLength: Int
4647
) -> Int32 {
4748
let nameUTF8 = Array(name.utf8)
4849
return nameUTF8.withUnsafeBufferPointer { nameUTF8 in
4950
return __getParameterTypeInfo(
5051
nameUTF8.baseAddress!, UInt(nameUTF8.endIndex),
51-
typesBuffer, typesLength)
52+
genericEnv, typesBuffer, typesLength)
5253
}
5354
}
5455

@@ -59,15 +60,20 @@ func _getParameterTypeInfo(
5960
public // SPI _Distributed
6061
func __getParameterTypeInfo(
6162
_ typeNameStart: UnsafePointer<UInt8>, _ typeNameLength: UInt,
63+
_ genericEnv: UnsafeRawPointer?, // GenericEnvironmentDescriptor *
6264
_ types: Builtin.RawPointer, _ typesLength: Int
6365
) -> Int32
6466

6567
@available(SwiftStdlib 5.6, *)
6668
public // SPI _Distributed
67-
func _getReturnTypeInfo(mangledMethodName name: String) -> Any.Type? {
69+
func _getReturnTypeInfo(
70+
mangledMethodName name: String,
71+
genericEnv: UnsafeRawPointer? // GenericEnvironmentDescriptor *
72+
) -> Any.Type? {
6873
let nameUTF8 = Array(name.utf8)
6974
return nameUTF8.withUnsafeBufferPointer { nameUTF8 in
70-
return __getReturnTypeInfo(nameUTF8.baseAddress!, UInt(nameUTF8.endIndex))
75+
return __getReturnTypeInfo(nameUTF8.baseAddress!, UInt(nameUTF8.endIndex),
76+
genericEnv)
7177
}
7278
}
7379

@@ -76,7 +82,8 @@ func _getReturnTypeInfo(mangledMethodName name: String) -> Any.Type? {
7682
public // SPI _Distributed
7783
func __getReturnTypeInfo(
7884
_ typeNameStart: UnsafePointer<UInt8>,
79-
_ typeNameLength: UInt
85+
_ typeNameLength: UInt,
86+
_ genericEnv: UnsafeRawPointer? // GenericEnvironmentDescriptor *
8087
) -> Any.Type?
8188

8289

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1984,7 +1984,8 @@ unsigned swift_func_getParameterCount(const char *typeNameStart,
19841984

19851985
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_SPI
19861986
const Metadata *_Nullable
1987-
swift_func_getReturnTypeInfo(const char *typeNameStart, size_t typeNameLength) {
1987+
swift_func_getReturnTypeInfo(const char *typeNameStart, size_t typeNameLength,
1988+
GenericEnvironmentDescriptor *genericEnv) {
19881989
StackAllocatedDemangler<1024> demangler;
19891990

19901991
auto *funcType =
@@ -2022,6 +2023,7 @@ SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_SPI
20222023
unsigned
20232024
swift_func_getParameterTypeInfo(
20242025
const char *typeNameStart, size_t typeNameLength,
2026+
GenericEnvironmentDescriptor *genericEnv,
20252027
Metadata const **types, unsigned typesLength) {
20262028
if (typesLength < 0) return -1;
20272029

test/Distributed/Runtime/distributed_func_metadata.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ typealias DefaultDistributedActorSystem = FakeActorSystem
118118
static func test_returnType() {
119119
print("~~ \(#function)")
120120
// CHECK: _getReturnTypeInfo: empty() = ()
121-
print("_getReturnTypeInfo: empty() = \(String(reflecting: _getReturnTypeInfo(mangledMethodName: empty)!))")
121+
print("_getReturnTypeInfo: empty() = \(String(reflecting: _getReturnTypeInfo(mangledMethodName: empty, genericEnv: nil)!))")
122122

123123
// CHECK: _getReturnTypeInfo: one(s:) = Swift.Int
124-
print("_getReturnTypeInfo: one(s:) = \(String(reflecting: _getReturnTypeInfo(mangledMethodName: one)!))")
124+
print("_getReturnTypeInfo: one(s:) = \(String(reflecting: _getReturnTypeInfo(mangledMethodName: one, genericEnv: nil)!))")
125125
}
126126

127127
static func test_paramTypes() {
@@ -178,6 +178,7 @@ func _withParameterTypeInfo(
178178
// 2) demangle and write all parameter types into the prepared buffer
179179
let decodedNum = __getParameterTypeInfo(
180180
nameUTF8.baseAddress!, UInt(nameUTF8.endIndex),
181+
/*genericEnvironment=*/nil,
181182
infoBuffer.baseAddress!._rawValue, Int(paramCount))
182183

183184
// if we failed demangling the types, return an empty array

0 commit comments

Comments
 (0)