Skip to content

Commit 8bbf832

Browse files
authored
Merge pull request swiftwasm#655 from PassiveLogic/kr/cleanup-removal
NFC: BridgeJS: Remove dead cleanup infrastructure
2 parents b18be89 + b643c47 commit 8bbf832

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+348
-1512
lines changed

Benchmarks/Sources/Generated/BridgeJS.swift

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,7 @@ extension SimpleStruct: _BridgedSwiftStruct {
132132
}
133133

134134
init(unsafelyCopying jsObject: JSObject) {
135-
let __bjs_cleanupId = _bjs_struct_lower_SimpleStruct(jsObject.bridgeJSLowerParameter())
136-
defer {
137-
_swift_js_struct_cleanup(__bjs_cleanupId)
138-
}
135+
_bjs_struct_lower_SimpleStruct(jsObject.bridgeJSLowerParameter())
139136
self = Self.bridgeJSStackPop()
140137
}
141138

@@ -148,9 +145,9 @@ extension SimpleStruct: _BridgedSwiftStruct {
148145

149146
#if arch(wasm32)
150147
@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_SimpleStruct")
151-
fileprivate func _bjs_struct_lower_SimpleStruct(_ objectId: Int32) -> Int32
148+
fileprivate func _bjs_struct_lower_SimpleStruct(_ objectId: Int32) -> Void
152149
#else
153-
fileprivate func _bjs_struct_lower_SimpleStruct(_ objectId: Int32) -> Int32 {
150+
fileprivate func _bjs_struct_lower_SimpleStruct(_ objectId: Int32) -> Void {
154151
fatalError("Only available on WebAssembly")
155152
}
156153
#endif
@@ -179,10 +176,7 @@ extension Address: _BridgedSwiftStruct {
179176
}
180177

181178
init(unsafelyCopying jsObject: JSObject) {
182-
let __bjs_cleanupId = _bjs_struct_lower_Address(jsObject.bridgeJSLowerParameter())
183-
defer {
184-
_swift_js_struct_cleanup(__bjs_cleanupId)
185-
}
179+
_bjs_struct_lower_Address(jsObject.bridgeJSLowerParameter())
186180
self = Self.bridgeJSStackPop()
187181
}
188182

@@ -195,9 +189,9 @@ extension Address: _BridgedSwiftStruct {
195189

196190
#if arch(wasm32)
197191
@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_Address")
198-
fileprivate func _bjs_struct_lower_Address(_ objectId: Int32) -> Int32
192+
fileprivate func _bjs_struct_lower_Address(_ objectId: Int32) -> Void
199193
#else
200-
fileprivate func _bjs_struct_lower_Address(_ objectId: Int32) -> Int32 {
194+
fileprivate func _bjs_struct_lower_Address(_ objectId: Int32) -> Void {
201195
fatalError("Only available on WebAssembly")
202196
}
203197
#endif
@@ -232,10 +226,7 @@ extension Person: _BridgedSwiftStruct {
232226
}
233227

234228
init(unsafelyCopying jsObject: JSObject) {
235-
let __bjs_cleanupId = _bjs_struct_lower_Person(jsObject.bridgeJSLowerParameter())
236-
defer {
237-
_swift_js_struct_cleanup(__bjs_cleanupId)
238-
}
229+
_bjs_struct_lower_Person(jsObject.bridgeJSLowerParameter())
239230
self = Self.bridgeJSStackPop()
240231
}
241232

@@ -248,9 +239,9 @@ extension Person: _BridgedSwiftStruct {
248239

249240
#if arch(wasm32)
250241
@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_Person")
251-
fileprivate func _bjs_struct_lower_Person(_ objectId: Int32) -> Int32
242+
fileprivate func _bjs_struct_lower_Person(_ objectId: Int32) -> Void
252243
#else
253-
fileprivate func _bjs_struct_lower_Person(_ objectId: Int32) -> Int32 {
244+
fileprivate func _bjs_struct_lower_Person(_ objectId: Int32) -> Void {
254245
fatalError("Only available on WebAssembly")
255246
}
256247
#endif
@@ -285,10 +276,7 @@ extension ComplexStruct: _BridgedSwiftStruct {
285276
}
286277

287278
init(unsafelyCopying jsObject: JSObject) {
288-
let __bjs_cleanupId = _bjs_struct_lower_ComplexStruct(jsObject.bridgeJSLowerParameter())
289-
defer {
290-
_swift_js_struct_cleanup(__bjs_cleanupId)
291-
}
279+
_bjs_struct_lower_ComplexStruct(jsObject.bridgeJSLowerParameter())
292280
self = Self.bridgeJSStackPop()
293281
}
294282

@@ -301,9 +289,9 @@ extension ComplexStruct: _BridgedSwiftStruct {
301289

302290
#if arch(wasm32)
303291
@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_ComplexStruct")
304-
fileprivate func _bjs_struct_lower_ComplexStruct(_ objectId: Int32) -> Int32
292+
fileprivate func _bjs_struct_lower_ComplexStruct(_ objectId: Int32) -> Void
305293
#else
306-
fileprivate func _bjs_struct_lower_ComplexStruct(_ objectId: Int32) -> Int32 {
294+
fileprivate func _bjs_struct_lower_ComplexStruct(_ objectId: Int32) -> Void {
307295
fatalError("Only available on WebAssembly")
308296
}
309297
#endif
@@ -330,10 +318,7 @@ extension Point: _BridgedSwiftStruct {
330318
}
331319

332320
init(unsafelyCopying jsObject: JSObject) {
333-
let __bjs_cleanupId = _bjs_struct_lower_Point(jsObject.bridgeJSLowerParameter())
334-
defer {
335-
_swift_js_struct_cleanup(__bjs_cleanupId)
336-
}
321+
_bjs_struct_lower_Point(jsObject.bridgeJSLowerParameter())
337322
self = Self.bridgeJSStackPop()
338323
}
339324

@@ -346,9 +331,9 @@ extension Point: _BridgedSwiftStruct {
346331

347332
#if arch(wasm32)
348333
@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_Point")
349-
fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Int32
334+
fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Void
350335
#else
351-
fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Int32 {
336+
fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Void {
352337
fatalError("Only available on WebAssembly")
353338
}
354339
#endif

Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.swift

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ extension PlayBridgeJSOutput: _BridgedSwiftStruct {
2424
}
2525

2626
init(unsafelyCopying jsObject: JSObject) {
27-
let __bjs_cleanupId = _bjs_struct_lower_PlayBridgeJSOutput(jsObject.bridgeJSLowerParameter())
28-
defer {
29-
_swift_js_struct_cleanup(__bjs_cleanupId)
30-
}
27+
_bjs_struct_lower_PlayBridgeJSOutput(jsObject.bridgeJSLowerParameter())
3128
self = Self.bridgeJSStackPop()
3229
}
3330

@@ -40,9 +37,9 @@ extension PlayBridgeJSOutput: _BridgedSwiftStruct {
4037

4138
#if arch(wasm32)
4239
@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_PlayBridgeJSOutput")
43-
fileprivate func _bjs_struct_lower_PlayBridgeJSOutput(_ objectId: Int32) -> Int32
40+
fileprivate func _bjs_struct_lower_PlayBridgeJSOutput(_ objectId: Int32) -> Void
4441
#else
45-
fileprivate func _bjs_struct_lower_PlayBridgeJSOutput(_ objectId: Int32) -> Int32 {
42+
fileprivate func _bjs_struct_lower_PlayBridgeJSOutput(_ objectId: Int32) -> Void {
4643
fatalError("Only available on WebAssembly")
4744
}
4845
#endif
@@ -77,10 +74,7 @@ extension PlayBridgeJSDiagnostic: _BridgedSwiftStruct {
7774
}
7875

7976
init(unsafelyCopying jsObject: JSObject) {
80-
let __bjs_cleanupId = _bjs_struct_lower_PlayBridgeJSDiagnostic(jsObject.bridgeJSLowerParameter())
81-
defer {
82-
_swift_js_struct_cleanup(__bjs_cleanupId)
83-
}
77+
_bjs_struct_lower_PlayBridgeJSDiagnostic(jsObject.bridgeJSLowerParameter())
8478
self = Self.bridgeJSStackPop()
8579
}
8680

@@ -93,9 +87,9 @@ extension PlayBridgeJSDiagnostic: _BridgedSwiftStruct {
9387

9488
#if arch(wasm32)
9589
@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_PlayBridgeJSDiagnostic")
96-
fileprivate func _bjs_struct_lower_PlayBridgeJSDiagnostic(_ objectId: Int32) -> Int32
90+
fileprivate func _bjs_struct_lower_PlayBridgeJSDiagnostic(_ objectId: Int32) -> Void
9791
#else
98-
fileprivate func _bjs_struct_lower_PlayBridgeJSDiagnostic(_ objectId: Int32) -> Int32 {
92+
fileprivate func _bjs_struct_lower_PlayBridgeJSDiagnostic(_ objectId: Int32) -> Void {
9993
fatalError("Only available on WebAssembly")
10094
}
10195
#endif
@@ -122,10 +116,7 @@ extension PlayBridgeJSResult: _BridgedSwiftStruct {
122116
}
123117

124118
init(unsafelyCopying jsObject: JSObject) {
125-
let __bjs_cleanupId = _bjs_struct_lower_PlayBridgeJSResult(jsObject.bridgeJSLowerParameter())
126-
defer {
127-
_swift_js_struct_cleanup(__bjs_cleanupId)
128-
}
119+
_bjs_struct_lower_PlayBridgeJSResult(jsObject.bridgeJSLowerParameter())
129120
self = Self.bridgeJSStackPop()
130121
}
131122

@@ -138,9 +129,9 @@ extension PlayBridgeJSResult: _BridgedSwiftStruct {
138129

139130
#if arch(wasm32)
140131
@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_PlayBridgeJSResult")
141-
fileprivate func _bjs_struct_lower_PlayBridgeJSResult(_ objectId: Int32) -> Int32
132+
fileprivate func _bjs_struct_lower_PlayBridgeJSResult(_ objectId: Int32) -> Void
142133
#else
143-
fileprivate func _bjs_struct_lower_PlayBridgeJSResult(_ objectId: Int32) -> Int32 {
134+
fileprivate func _bjs_struct_lower_PlayBridgeJSResult(_ objectId: Int32) -> Void {
144135
fatalError("Only available on WebAssembly")
145136
}
146137
#endif

Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,10 +1243,7 @@ struct StructCodegen {
12431243
printer.write(
12441244
multilineString: """
12451245
\(accessControl)init(unsafelyCopying jsObject: JSObject) {
1246-
let __bjs_cleanupId = \(lowerFunctionName)(jsObject.bridgeJSLowerParameter())
1247-
defer {
1248-
_swift_js_struct_cleanup(__bjs_cleanupId)
1249-
}
1246+
\(lowerFunctionName)(jsObject.bridgeJSLowerParameter())
12501247
self = Self.bridgeJSStackPop()
12511248
}
12521249
"""
@@ -1274,7 +1271,7 @@ struct StructCodegen {
12741271
functionName: lowerFunctionName,
12751272
signature: SwiftSignatureBuilder.buildABIFunctionSignature(
12761273
abiParameters: [("objectId", .i32)],
1277-
returnType: .i32
1274+
returnType: nil
12781275
)
12791276
)
12801277
let liftExternDeclPrinter = CodeFragmentPrinter()

Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ public struct BridgeJSLink {
261261
"let \(JSGlueVariableScope.reservedF32Stack) = [];",
262262
"let \(JSGlueVariableScope.reservedF64Stack) = [];",
263263
"let \(JSGlueVariableScope.reservedPointerStack) = [];",
264-
"let \(JSGlueVariableScope.reservedTmpStructCleanups) = [];",
265264
"const \(JSGlueVariableScope.reservedEnumHelpers) = {};",
266265
"const \(JSGlueVariableScope.reservedStructHelpers) = {};",
267266
"",
@@ -403,38 +402,13 @@ public struct BridgeJSLink {
403402
printer.write("return \(JSGlueVariableScope.reservedPointerStack).pop();")
404403
}
405404
printer.write("}")
406-
printer.write("bjs[\"swift_js_struct_cleanup\"] = function(cleanupId) {")
407-
printer.indent {
408-
printer.write("if (cleanupId === 0) { return; }")
409-
printer.write("const index = (cleanupId | 0) - 1;")
410-
printer.write("const cleanup = \(JSGlueVariableScope.reservedTmpStructCleanups)[index];")
411-
printer.write("\(JSGlueVariableScope.reservedTmpStructCleanups)[index] = null;")
412-
printer.write("if (cleanup) { cleanup(); }")
413-
printer.write(
414-
"while (\(JSGlueVariableScope.reservedTmpStructCleanups).length > 0 && \(JSGlueVariableScope.reservedTmpStructCleanups)[\(JSGlueVariableScope.reservedTmpStructCleanups).length - 1] == null) {"
415-
)
416-
printer.indent {
417-
printer.write("\(JSGlueVariableScope.reservedTmpStructCleanups).pop();")
418-
}
419-
printer.write("}")
420-
}
421-
printer.write("}")
422-
423405
if !allStructs.isEmpty {
424406
for structDef in allStructs {
425407
printer.write("bjs[\"swift_js_struct_lower_\(structDef.name)\"] = function(objectId) {")
426408
printer.indent {
427409
printer.write(
428-
"const { cleanup: cleanup } = \(JSGlueVariableScope.reservedStructHelpers).\(structDef.name).lower(\(JSGlueVariableScope.reservedSwift).memory.getObject(objectId));"
410+
"\(JSGlueVariableScope.reservedStructHelpers).\(structDef.name).lower(\(JSGlueVariableScope.reservedSwift).memory.getObject(objectId));"
429411
)
430-
printer.write("if (cleanup) {")
431-
printer.indent {
432-
printer.write(
433-
"return \(JSGlueVariableScope.reservedTmpStructCleanups).push(cleanup);"
434-
)
435-
}
436-
printer.write("}")
437-
printer.write("return 0;")
438412
}
439413
printer.write("}")
440414

@@ -956,14 +930,12 @@ public struct BridgeJSLink {
956930
for structDef in allStructs {
957931
let structPrinter = CodeFragmentPrinter()
958932
let structScope = JSGlueVariableScope(intrinsicRegistry: intrinsicRegistry)
959-
let structCleanup = CodeFragmentPrinter()
960933
let fragment = IntrinsicJSFragment.structHelper(structDefinition: structDef, allStructs: allStructs)
961934
_ = try fragment.printCode(
962935
[structDef.name],
963936
IntrinsicJSFragment.PrintCodeContext(
964937
scope: structScope,
965-
printer: structPrinter,
966-
cleanupCode: structCleanup
938+
printer: structPrinter
967939
)
968940
)
969941
bodyPrinter.write(lines: structPrinter.lines)
@@ -975,14 +947,12 @@ public struct BridgeJSLink {
975947
for enumDef in allAssocEnums {
976948
let enumPrinter = CodeFragmentPrinter()
977949
let enumScope = JSGlueVariableScope(intrinsicRegistry: intrinsicRegistry)
978-
let enumCleanup = CodeFragmentPrinter()
979950
let fragment = IntrinsicJSFragment.associatedValueEnumHelperFactory(enumDefinition: enumDef)
980951
_ = try fragment.printCode(
981952
[enumDef.valuesName],
982953
IntrinsicJSFragment.PrintCodeContext(
983954
scope: enumScope,
984-
printer: enumPrinter,
985-
cleanupCode: enumCleanup
955+
printer: enumPrinter
986956
)
987957
)
988958
bodyPrinter.write(lines: enumPrinter.lines)
@@ -1227,7 +1197,6 @@ public struct BridgeJSLink {
12271197

12281198
class ExportedThunkBuilder {
12291199
var body: CodeFragmentPrinter
1230-
var cleanupCode: CodeFragmentPrinter
12311200
var parameterForwardings: [String] = []
12321201
let effects: Effects
12331202
let scope: JSGlueVariableScope
@@ -1237,11 +1206,9 @@ public struct BridgeJSLink {
12371206
self.effects = effects
12381207
self.scope = JSGlueVariableScope(intrinsicRegistry: intrinsicRegistry)
12391208
self.body = CodeFragmentPrinter()
1240-
self.cleanupCode = CodeFragmentPrinter()
12411209
self.context = IntrinsicJSFragment.PrintCodeContext(
12421210
scope: scope,
12431211
printer: body,
1244-
cleanupCode: cleanupCode,
12451212
hasDirectAccessToSwiftClass: hasDirectAccessToSwiftClass
12461213
)
12471214
}
@@ -1312,10 +1279,9 @@ public struct BridgeJSLink {
13121279
]
13131280
}
13141281

1315-
/// Renders the thunk body (body code, cleanup, exception handling, and optional return) into a printer.
1282+
/// Renders the thunk body (body code, exception handling, and optional return) into a printer.
13161283
func renderFunctionBody(into printer: CodeFragmentPrinter, returnExpr: String?) {
13171284
printer.write(contentsOf: body)
1318-
printer.write(contentsOf: cleanupCode)
13191285
printer.write(lines: checkExceptionLines())
13201286
if let returnExpr = returnExpr {
13211287
printer.write("return \(returnExpr);")
@@ -1541,8 +1507,7 @@ public struct BridgeJSLink {
15411507
let printer = CodeFragmentPrinter()
15421508
let context = IntrinsicJSFragment.PrintCodeContext(
15431509
scope: scope,
1544-
printer: printer,
1545-
cleanupCode: CodeFragmentPrinter()
1510+
printer: printer
15461511
)
15471512
let enumValuesName = enumDefinition.valuesName
15481513

@@ -2127,7 +2092,6 @@ extension BridgeJSLink {
21272092
class ImportedThunkBuilder {
21282093
let body: CodeFragmentPrinter
21292094
let scope: JSGlueVariableScope
2130-
let cleanupCode: CodeFragmentPrinter
21312095
let context: BridgeContext
21322096
var parameterNames: [String] = []
21332097
var parameterForwardings: [String] = []
@@ -2136,12 +2100,10 @@ extension BridgeJSLink {
21362100
init(context: BridgeContext = .importTS, intrinsicRegistry: JSIntrinsicRegistry) {
21372101
self.body = CodeFragmentPrinter()
21382102
self.scope = JSGlueVariableScope(intrinsicRegistry: intrinsicRegistry)
2139-
self.cleanupCode = CodeFragmentPrinter()
21402103
self.context = context
21412104
self.printContext = IntrinsicJSFragment.PrintCodeContext(
21422105
scope: scope,
2143-
printer: body,
2144-
cleanupCode: cleanupCode
2106+
printer: body
21452107
)
21462108
}
21472109

@@ -2680,7 +2642,6 @@ extension BridgeJSLink {
26802642
getterPrinter.write("get \(property.name)() {")
26812643
getterPrinter.indent {
26822644
getterPrinter.write(contentsOf: getterThunkBuilder.body)
2683-
getterPrinter.write(contentsOf: getterThunkBuilder.cleanupCode)
26842645
getterPrinter.write(lines: getterThunkBuilder.checkExceptionLines())
26852646
if let returnExpr = getterReturnExpr {
26862647
getterPrinter.write("return \(returnExpr);")
@@ -2708,7 +2669,6 @@ extension BridgeJSLink {
27082669
setterPrinter.write("set \(property.name)(value) {")
27092670
setterPrinter.indent {
27102671
setterPrinter.write(contentsOf: setterThunkBuilder.body)
2711-
setterPrinter.write(contentsOf: setterThunkBuilder.cleanupCode)
27122672
setterPrinter.write(lines: setterThunkBuilder.checkExceptionLines())
27132673
}
27142674
setterPrinter.write("},")

0 commit comments

Comments
 (0)