From 1746d9791d43d725d9fae6c995ee73cf7969654d Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 25 Feb 2026 17:36:05 +0900 Subject: [PATCH] BridgeJS: Remove inline array lifting/lowering codegen --- Benchmarks/Sources/Generated/BridgeJS.swift | 64 ++-------- .../Sources/BridgeJSCore/ExportSwift.swift | 66 +--------- .../BridgeJSCodegenTests/ArrayTypes.swift | 96 ++------------- .../ImportedTypeInExportedInterface.swift | 20 +-- .../Generated/BridgeJS.swift | 116 +++--------------- 5 files changed, 41 insertions(+), 321 deletions(-) diff --git a/Benchmarks/Sources/Generated/BridgeJS.swift b/Benchmarks/Sources/Generated/BridgeJS.swift index 77fefad8..bf033ae2 100644 --- a/Benchmarks/Sources/Generated/BridgeJS.swift +++ b/Benchmarks/Sources/Generated/BridgeJS.swift @@ -1578,16 +1578,7 @@ public func _bjs_ArrayRoundtrip_roundtripNestedPointArray(_ _self: UnsafeMutable @_cdecl("bjs_ArrayRoundtrip_takeOptionalIntArray") public func _bjs_ArrayRoundtrip_takeOptionalIntArray(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - ArrayRoundtrip.bridgeJSLiftParameter(_self).takeOptionalIntArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Optional] = [] - __result.reserveCapacity(__count) - for _ in 0..<__count { - __result.append(Optional.bridgeJSStackPop()) - } - __result.reverse() - return __result - }()) + ArrayRoundtrip.bridgeJSLiftParameter(_self).takeOptionalIntArray(_: [Optional].bridgeJSStackPop()) #else fatalError("Only available on WebAssembly") #endif @@ -1598,10 +1589,7 @@ public func _bjs_ArrayRoundtrip_takeOptionalIntArray(_ _self: UnsafeMutableRawPo public func _bjs_ArrayRoundtrip_makeOptionalIntArray(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).makeOptionalIntArray() - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSStackPush() - } - _swift_js_push_i32(Int32(ret.count)) + ret.bridgeJSStackPush() #else fatalError("Only available on WebAssembly") #endif @@ -1611,20 +1599,8 @@ public func _bjs_ArrayRoundtrip_makeOptionalIntArray(_ _self: UnsafeMutableRawPo @_cdecl("bjs_ArrayRoundtrip_roundtripOptionalIntArray") public func _bjs_ArrayRoundtrip_roundtripOptionalIntArray(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).roundtripOptionalIntArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Optional] = [] - __result.reserveCapacity(__count) - for _ in 0..<__count { - __result.append(Optional.bridgeJSStackPop()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSStackPush() - } - _swift_js_push_i32(Int32(ret.count)) + let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).roundtripOptionalIntArray(_: [Optional].bridgeJSStackPop()) + ret.bridgeJSStackPush() #else fatalError("Only available on WebAssembly") #endif @@ -1634,16 +1610,7 @@ public func _bjs_ArrayRoundtrip_roundtripOptionalIntArray(_ _self: UnsafeMutable @_cdecl("bjs_ArrayRoundtrip_takeOptionalPointArray") public func _bjs_ArrayRoundtrip_takeOptionalPointArray(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - ArrayRoundtrip.bridgeJSLiftParameter(_self).takeOptionalPointArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Optional] = [] - __result.reserveCapacity(__count) - for _ in 0..<__count { - __result.append(Optional.bridgeJSStackPop()) - } - __result.reverse() - return __result - }()) + ArrayRoundtrip.bridgeJSLiftParameter(_self).takeOptionalPointArray(_: [Optional].bridgeJSStackPop()) #else fatalError("Only available on WebAssembly") #endif @@ -1654,10 +1621,7 @@ public func _bjs_ArrayRoundtrip_takeOptionalPointArray(_ _self: UnsafeMutableRaw public func _bjs_ArrayRoundtrip_makeOptionalPointArray(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).makeOptionalPointArray() - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSStackPush() - } - _swift_js_push_i32(Int32(ret.count)) + ret.bridgeJSStackPush() #else fatalError("Only available on WebAssembly") #endif @@ -1667,20 +1631,8 @@ public func _bjs_ArrayRoundtrip_makeOptionalPointArray(_ _self: UnsafeMutableRaw @_cdecl("bjs_ArrayRoundtrip_roundtripOptionalPointArray") public func _bjs_ArrayRoundtrip_roundtripOptionalPointArray(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).roundtripOptionalPointArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Optional] = [] - __result.reserveCapacity(__count) - for _ in 0..<__count { - __result.append(Optional.bridgeJSStackPop()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSStackPush() - } - _swift_js_push_i32(Int32(ret.count)) + let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).roundtripOptionalPointArray(_: [Optional].bridgeJSStackPop()) + ret.bridgeJSStackPush() #else fatalError("Only available on WebAssembly") #endif diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift index 12d472cb..4280b266 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift @@ -713,14 +713,12 @@ struct StackCodegen { switch type { case .string, .int, .uint, .bool, .float, .double, .jsObject(nil), .jsValue, .swiftStruct, .swiftHeapObject, .unsafePointer, - .swiftProtocol, .caseEnum, .associatedValueEnum, .rawValueEnum: + .swiftProtocol, .caseEnum, .associatedValueEnum, .rawValueEnum, .array: return "\(raw: type.swiftType).bridgeJSStackPop()" case .jsObject(let className?): return "\(raw: className)(unsafelyWrapping: JSObject.bridgeJSStackPop())" case .nullable(let wrappedType, let kind): return liftNullableExpression(wrappedType: wrappedType, kind: kind) - case .array(let elementType): - return liftArrayExpression(elementType: elementType) case .dictionary(let valueType): return liftDictionaryExpression(valueType: valueType) case .closure: @@ -730,36 +728,6 @@ struct StackCodegen { } } - func liftArrayExpression(elementType: BridgeType) -> ExprSyntax { - switch elementType { - case .jsObject(let className?) where className != "JSObject": - return "[JSObject].bridgeJSStackPop().map { \(raw: className)(unsafelyWrapping: $0) }" - case .nullable, .closure: - return liftArrayExpressionInline(elementType: elementType) - case .void, .namespaceEnum: - fatalError("Invalid array element type: \(elementType)") - default: - return "[\(raw: elementType.swiftType)].bridgeJSStackPop()" - } - } - - private func liftArrayExpressionInline(elementType: BridgeType) -> ExprSyntax { - let elementLift = liftExpression(for: elementType) - let swiftTypeName = elementType.swiftType - return """ - { - let __count = Int(_swift_js_pop_i32()) - var __result: [\(raw: swiftTypeName)] = [] - __result.reserveCapacity(__count) - for _ in 0..<__count { - __result.append(\(elementLift)) - } - __result.reverse() - return __result - }() - """ - } - func liftDictionaryExpression(valueType: BridgeType) -> ExprSyntax { switch valueType { case .jsObject(let className?) where className != "JSObject": @@ -845,16 +813,8 @@ struct StackCodegen { varPrefix: String ) -> [CodeBlockItemSyntax] { switch elementType { - case .jsObject(let className?) where className != "JSObject": - return ["\(raw: accessor).map { $0.jsObject }.bridgeJSStackPush()"] case .swiftProtocol: return ["\(raw: accessor).map { $0 as! \(raw: elementType.swiftType) }.bridgeJSStackPush()"] - case .nullable, .closure: - return lowerArrayStatementsInline( - elementType: elementType, - accessor: accessor, - varPrefix: varPrefix - ) case .void, .namespaceEnum: fatalError("Invalid array element type: \(elementType)") default: @@ -862,30 +822,6 @@ struct StackCodegen { } } - private func lowerArrayStatementsInline( - elementType: BridgeType, - accessor: String, - varPrefix: String - ) -> [CodeBlockItemSyntax] { - var statements: [String] = [] - let elementVarName = "__bjs_elem_\(varPrefix)" - statements.append("for \(elementVarName) in \(accessor) {") - - let elementStatements = lowerStatements( - for: elementType, - accessor: elementVarName, - varPrefix: "\(varPrefix)_elem" - ) - for stmt in elementStatements { - statements.append(stmt.description) - } - - statements.append("}") - statements.append("_swift_js_push_i32(Int32(\(accessor).count))") - let parsed: CodeBlockItemListSyntax = "\(raw: statements.joined(separator: "\n"))" - return Array(parsed) - } - private func lowerDictionaryStatements( valueType: BridgeType, accessor: String, diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.swift index 6ced2439..0d95a5b7 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.swift @@ -228,20 +228,8 @@ public func _bjs_processOpaquePointerArray() -> Void { @_cdecl("bjs_processOptionalIntArray") public func _bjs_processOptionalIntArray() -> Void { #if arch(wasm32) - let ret = processOptionalIntArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Optional] = [] - __result.reserveCapacity(__count) - for _ in 0..<__count { - __result.append(Optional.bridgeJSStackPop()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSStackPush() - } - _swift_js_push_i32(Int32(ret.count)) + let ret = processOptionalIntArray(_: [Optional].bridgeJSStackPop()) + ret.bridgeJSStackPush() #else fatalError("Only available on WebAssembly") #endif @@ -251,20 +239,8 @@ public func _bjs_processOptionalIntArray() -> Void { @_cdecl("bjs_processOptionalStringArray") public func _bjs_processOptionalStringArray() -> Void { #if arch(wasm32) - let ret = processOptionalStringArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Optional] = [] - __result.reserveCapacity(__count) - for _ in 0..<__count { - __result.append(Optional.bridgeJSStackPop()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSStackPush() - } - _swift_js_push_i32(Int32(ret.count)) + let ret = processOptionalStringArray(_: [Optional].bridgeJSStackPop()) + ret.bridgeJSStackPush() #else fatalError("Only available on WebAssembly") #endif @@ -285,20 +261,8 @@ public func _bjs_processOptionalArray() -> Void { @_cdecl("bjs_processOptionalPointArray") public func _bjs_processOptionalPointArray() -> Void { #if arch(wasm32) - let ret = processOptionalPointArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Optional] = [] - __result.reserveCapacity(__count) - for _ in 0..<__count { - __result.append(Optional.bridgeJSStackPop()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSStackPush() - } - _swift_js_push_i32(Int32(ret.count)) + let ret = processOptionalPointArray(_: [Optional].bridgeJSStackPop()) + ret.bridgeJSStackPush() #else fatalError("Only available on WebAssembly") #endif @@ -308,20 +272,8 @@ public func _bjs_processOptionalPointArray() -> Void { @_cdecl("bjs_processOptionalDirectionArray") public func _bjs_processOptionalDirectionArray() -> Void { #if arch(wasm32) - let ret = processOptionalDirectionArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Optional] = [] - __result.reserveCapacity(__count) - for _ in 0..<__count { - __result.append(Optional.bridgeJSStackPop()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSStackPush() - } - _swift_js_push_i32(Int32(ret.count)) + let ret = processOptionalDirectionArray(_: [Optional].bridgeJSStackPop()) + ret.bridgeJSStackPush() #else fatalError("Only available on WebAssembly") #endif @@ -331,20 +283,8 @@ public func _bjs_processOptionalDirectionArray() -> Void { @_cdecl("bjs_processOptionalStatusArray") public func _bjs_processOptionalStatusArray() -> Void { #if arch(wasm32) - let ret = processOptionalStatusArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Optional] = [] - __result.reserveCapacity(__count) - for _ in 0..<__count { - __result.append(Optional.bridgeJSStackPop()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSStackPush() - } - _swift_js_push_i32(Int32(ret.count)) + let ret = processOptionalStatusArray(_: [Optional].bridgeJSStackPop()) + ret.bridgeJSStackPush() #else fatalError("Only available on WebAssembly") #endif @@ -420,20 +360,8 @@ public func _bjs_processJSObjectArray() -> Void { @_cdecl("bjs_processOptionalJSObjectArray") public func _bjs_processOptionalJSObjectArray() -> Void { #if arch(wasm32) - let ret = processOptionalJSObjectArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Optional] = [] - __result.reserveCapacity(__count) - for _ in 0..<__count { - __result.append(Optional.bridgeJSStackPop()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSStackPush() - } - _swift_js_push_i32(Int32(ret.count)) + let ret = processOptionalJSObjectArray(_: [Optional].bridgeJSStackPop()) + ret.bridgeJSStackPush() #else fatalError("Only available on WebAssembly") #endif diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.swift index 809dfb43..f3c3f2fc 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.swift @@ -75,8 +75,8 @@ public func _bjs_makeFoo() -> Int32 { @_cdecl("bjs_processFooArray") public func _bjs_processFooArray() -> Void { #if arch(wasm32) - let ret = processFooArray(_: [JSObject].bridgeJSStackPop().map { Foo(unsafelyWrapping: $0) }) - ret.map { $0.jsObject }.bridgeJSStackPush() + let ret = processFooArray(_: [Foo].bridgeJSStackPop()) + ret.bridgeJSStackPush() #else fatalError("Only available on WebAssembly") #endif @@ -86,20 +86,8 @@ public func _bjs_processFooArray() -> Void { @_cdecl("bjs_processOptionalFooArray") public func _bjs_processOptionalFooArray() -> Void { #if arch(wasm32) - let ret = processOptionalFooArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Optional] = [] - __result.reserveCapacity(__count) - for _ in 0..<__count { - __result.append(Optional.bridgeJSStackPop().map { Foo(unsafelyWrapping: $0) }) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSStackPush() - } - _swift_js_push_i32(Int32(ret.count)) + let ret = processOptionalFooArray(_: [Optional].bridgeJSStackPop()) + ret.bridgeJSStackPush() #else fatalError("Only available on WebAssembly") #endif diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift index 048400d4..6a7ce73c 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift @@ -5692,20 +5692,8 @@ public func _bjs_roundTripGreeterArray() -> Void { @_cdecl("bjs_roundTripOptionalIntArray") public func _bjs_roundTripOptionalIntArray() -> Void { #if arch(wasm32) - let ret = roundTripOptionalIntArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Optional] = [] - __result.reserveCapacity(__count) - for _ in 0..<__count { - __result.append(Optional.bridgeJSStackPop()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSStackPush() - } - _swift_js_push_i32(Int32(ret.count)) + let ret = roundTripOptionalIntArray(_: [Optional].bridgeJSStackPop()) + ret.bridgeJSStackPush() #else fatalError("Only available on WebAssembly") #endif @@ -5715,20 +5703,8 @@ public func _bjs_roundTripOptionalIntArray() -> Void { @_cdecl("bjs_roundTripOptionalStringArray") public func _bjs_roundTripOptionalStringArray() -> Void { #if arch(wasm32) - let ret = roundTripOptionalStringArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Optional] = [] - __result.reserveCapacity(__count) - for _ in 0..<__count { - __result.append(Optional.bridgeJSStackPop()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSStackPush() - } - _swift_js_push_i32(Int32(ret.count)) + let ret = roundTripOptionalStringArray(_: [Optional].bridgeJSStackPop()) + ret.bridgeJSStackPush() #else fatalError("Only available on WebAssembly") #endif @@ -5738,20 +5714,8 @@ public func _bjs_roundTripOptionalStringArray() -> Void { @_cdecl("bjs_roundTripOptionalDataPointArray") public func _bjs_roundTripOptionalDataPointArray() -> Void { #if arch(wasm32) - let ret = roundTripOptionalDataPointArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Optional] = [] - __result.reserveCapacity(__count) - for _ in 0..<__count { - __result.append(Optional.bridgeJSStackPop()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSStackPush() - } - _swift_js_push_i32(Int32(ret.count)) + let ret = roundTripOptionalDataPointArray(_: [Optional].bridgeJSStackPop()) + ret.bridgeJSStackPush() #else fatalError("Only available on WebAssembly") #endif @@ -5761,20 +5725,8 @@ public func _bjs_roundTripOptionalDataPointArray() -> Void { @_cdecl("bjs_roundTripOptionalDirectionArray") public func _bjs_roundTripOptionalDirectionArray() -> Void { #if arch(wasm32) - let ret = roundTripOptionalDirectionArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Optional] = [] - __result.reserveCapacity(__count) - for _ in 0..<__count { - __result.append(Optional.bridgeJSStackPop()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSStackPush() - } - _swift_js_push_i32(Int32(ret.count)) + let ret = roundTripOptionalDirectionArray(_: [Optional].bridgeJSStackPop()) + ret.bridgeJSStackPush() #else fatalError("Only available on WebAssembly") #endif @@ -5784,20 +5736,8 @@ public func _bjs_roundTripOptionalDirectionArray() -> Void { @_cdecl("bjs_roundTripOptionalStatusArray") public func _bjs_roundTripOptionalStatusArray() -> Void { #if arch(wasm32) - let ret = roundTripOptionalStatusArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Optional] = [] - __result.reserveCapacity(__count) - for _ in 0..<__count { - __result.append(Optional.bridgeJSStackPop()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSStackPush() - } - _swift_js_push_i32(Int32(ret.count)) + let ret = roundTripOptionalStatusArray(_: [Optional].bridgeJSStackPop()) + ret.bridgeJSStackPush() #else fatalError("Only available on WebAssembly") #endif @@ -6005,20 +5945,8 @@ public func _bjs_roundTripJSObjectArray() -> Void { @_cdecl("bjs_roundTripOptionalJSObjectArray") public func _bjs_roundTripOptionalJSObjectArray() -> Void { #if arch(wasm32) - let ret = roundTripOptionalJSObjectArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Optional] = [] - __result.reserveCapacity(__count) - for _ in 0..<__count { - __result.append(Optional.bridgeJSStackPop()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSStackPush() - } - _swift_js_push_i32(Int32(ret.count)) + let ret = roundTripOptionalJSObjectArray(_: [Optional].bridgeJSStackPop()) + ret.bridgeJSStackPush() #else fatalError("Only available on WebAssembly") #endif @@ -6028,8 +5956,8 @@ public func _bjs_roundTripOptionalJSObjectArray() -> Void { @_cdecl("bjs_roundTripFooArray") public func _bjs_roundTripFooArray() -> Void { #if arch(wasm32) - let ret = roundTripFooArray(_: [JSObject].bridgeJSStackPop().map { Foo(unsafelyWrapping: $0) }) - ret.map { $0.jsObject }.bridgeJSStackPush() + let ret = roundTripFooArray(_: [Foo].bridgeJSStackPop()) + ret.bridgeJSStackPush() #else fatalError("Only available on WebAssembly") #endif @@ -6039,20 +5967,8 @@ public func _bjs_roundTripFooArray() -> Void { @_cdecl("bjs_roundTripOptionalFooArray") public func _bjs_roundTripOptionalFooArray() -> Void { #if arch(wasm32) - let ret = roundTripOptionalFooArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Optional] = [] - __result.reserveCapacity(__count) - for _ in 0..<__count { - __result.append(Optional.bridgeJSStackPop().map { Foo(unsafelyWrapping: $0) }) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSStackPush() - } - _swift_js_push_i32(Int32(ret.count)) + let ret = roundTripOptionalFooArray(_: [Optional].bridgeJSStackPop()) + ret.bridgeJSStackPush() #else fatalError("Only available on WebAssembly") #endif