Skip to content

Commit 20457f4

Browse files
[NFC] BridgeJS: Remove remaining explicit captures from enum/struct helpers
1 parent 63b7b72 commit 20457f4

File tree

13 files changed

+71
-71
lines changed

13 files changed

+71
-71
lines changed

Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ public struct BridgeJSLink {
478478
printer.write("bjs[\"swift_js_struct_lift_\(structDef.name)\"] = function() {")
479479
printer.indent {
480480
printer.write(
481-
"const value = \(JSGlueVariableScope.reservedStructHelpers).\(structDef.name).lift(\(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));"
481+
"const value = \(JSGlueVariableScope.reservedStructHelpers).\(structDef.name).lift();"
482482
)
483483
printer.write("return \(JSGlueVariableScope.reservedSwift).memory.retain(value);")
484484
}
@@ -1162,7 +1162,7 @@ public struct BridgeJSLink {
11621162
for skeleton in skeletons.compactMap(\.exported) {
11631163
for enumDef in skeleton.enums where enumDef.enumType == .associatedValue {
11641164
printer.write(
1165-
"const \(enumDef.name)Helpers = __bjs_create\(enumDef.valuesName)Helpers()(\(JSGlueVariableScope.reservedTmpParamInts), \(JSGlueVariableScope.reservedTmpParamF32s), \(JSGlueVariableScope.reservedTmpParamF64s), \(JSGlueVariableScope.reservedTmpParamPointers), \(JSGlueVariableScope.reservedTmpRetPointers), \(JSGlueVariableScope.reservedTextEncoder), \(JSGlueVariableScope.reservedSwift), \(JSGlueVariableScope.reservedStructHelpers), \(JSGlueVariableScope.reservedEnumHelpers));"
1165+
"const \(enumDef.name)Helpers = __bjs_create\(enumDef.valuesName)Helpers()();"
11661166
)
11671167
printer.write("\(JSGlueVariableScope.reservedEnumHelpers).\(enumDef.name) = \(enumDef.name)Helpers;")
11681168
printer.nextLine()
@@ -1178,7 +1178,7 @@ public struct BridgeJSLink {
11781178
for skeleton in skeletons.compactMap(\.exported) {
11791179
for structDef in skeleton.structs {
11801180
printer.write(
1181-
"const \(structDef.name)Helpers = __bjs_create\(structDef.name)Helpers()(\(JSGlueVariableScope.reservedTmpParamInts), \(JSGlueVariableScope.reservedTmpParamF32s), \(JSGlueVariableScope.reservedTmpParamF64s), \(JSGlueVariableScope.reservedTmpParamPointers), \(JSGlueVariableScope.reservedTmpRetPointers), \(JSGlueVariableScope.reservedTextEncoder), \(JSGlueVariableScope.reservedSwift), \(JSGlueVariableScope.reservedEnumHelpers));"
1181+
"const \(structDef.name)Helpers = __bjs_create\(structDef.name)Helpers()();"
11821182
)
11831183
printer.write(
11841184
"\(JSGlueVariableScope.reservedStructHelpers).\(structDef.name) = \(structDef.name)Helpers;"

Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,7 +2075,7 @@ struct IntrinsicJSFragment: Sendable {
20752075
printer.write("const __bjs_create\(enumName)Helpers = () => {")
20762076
printer.indent()
20772077
printer.write(
2078-
"return (\(JSGlueVariableScope.reservedTmpParamInts), \(JSGlueVariableScope.reservedTmpParamF32s), \(JSGlueVariableScope.reservedTmpParamF64s), \(JSGlueVariableScope.reservedTmpParamPointers), \(JSGlueVariableScope.reservedTmpRetPointers), textEncoder, \(JSGlueVariableScope.reservedSwift), \(JSGlueVariableScope.reservedStructHelpers), \(JSGlueVariableScope.reservedEnumHelpers)) => ({"
2078+
"return () => ({"
20792079
)
20802080
printer.indent()
20812081

@@ -3109,7 +3109,7 @@ struct IntrinsicJSFragment: Sendable {
31093109
printer.write("const __bjs_create\(structName)Helpers = () => {")
31103110
printer.indent()
31113111
printer.write(
3112-
"return (\(JSGlueVariableScope.reservedTmpParamInts), \(JSGlueVariableScope.reservedTmpParamF32s), \(JSGlueVariableScope.reservedTmpParamF64s), \(JSGlueVariableScope.reservedTmpParamPointers), \(JSGlueVariableScope.reservedTmpRetPointers), textEncoder, \(JSGlueVariableScope.reservedSwift), \(JSGlueVariableScope.reservedEnumHelpers)) => ({"
3112+
"return () => ({"
31133113
)
31143114
printer.indent()
31153115

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export async function createInstantiator(options, swift) {
4848
let _exports = null;
4949
let bjs = null;
5050
const __bjs_createPointHelpers = () => {
51-
return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers) => ({
51+
return () => ({
5252
lower: (value) => {
5353
tmpParamF64s.push(value.x);
5454
tmpParamF64s.push(value.y);
@@ -147,7 +147,7 @@ export async function createInstantiator(options, swift) {
147147
return 0;
148148
}
149149
bjs["swift_js_struct_lift_Point"] = function() {
150-
const value = structHelpers.Point.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers);
150+
const value = structHelpers.Point.lift();
151151
return swift.memory.retain(value);
152152
}
153153
bjs["swift_js_return_optional_bool"] = function(isSome, value) {
@@ -389,7 +389,7 @@ export async function createInstantiator(options, swift) {
389389
}
390390

391391
}
392-
const PointHelpers = __bjs_createPointHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers);
392+
const PointHelpers = __bjs_createPointHelpers()();
393393
structHelpers.Point = PointHelpers;
394394

395395
const exports = {

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export async function createInstantiator(options, swift) {
4141
let _exports = null;
4242
let bjs = null;
4343
const __bjs_createConfigHelpers = () => {
44-
return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers) => ({
44+
return () => ({
4545
lower: (value) => {
4646
const bytes = textEncoder.encode(value.name);
4747
const id = swift.memory.retain(bytes);
@@ -63,7 +63,7 @@ export async function createInstantiator(options, swift) {
6363
});
6464
};
6565
const __bjs_createMathOperationsHelpers = () => {
66-
return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers) => ({
66+
return () => ({
6767
lower: (value) => {
6868
tmpParamF64s.push(value.baseValue);
6969
return { cleanup: undefined };
@@ -172,7 +172,7 @@ export async function createInstantiator(options, swift) {
172172
return 0;
173173
}
174174
bjs["swift_js_struct_lift_Config"] = function() {
175-
const value = structHelpers.Config.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers);
175+
const value = structHelpers.Config.lift();
176176
return swift.memory.retain(value);
177177
}
178178
bjs["swift_js_struct_lower_MathOperations"] = function(objectId) {
@@ -183,7 +183,7 @@ export async function createInstantiator(options, swift) {
183183
return 0;
184184
}
185185
bjs["swift_js_struct_lift_MathOperations"] = function() {
186-
const value = structHelpers.MathOperations.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers);
186+
const value = structHelpers.MathOperations.lift();
187187
return swift.memory.retain(value);
188188
}
189189
bjs["swift_js_return_optional_bool"] = function(isSome, value) {
@@ -431,10 +431,10 @@ export async function createInstantiator(options, swift) {
431431
}
432432
}
433433
}
434-
const ConfigHelpers = __bjs_createConfigHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers);
434+
const ConfigHelpers = __bjs_createConfigHelpers()();
435435
structHelpers.Config = ConfigHelpers;
436436

437-
const MathOperationsHelpers = __bjs_createMathOperationsHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers);
437+
const MathOperationsHelpers = __bjs_createMathOperationsHelpers()();
438438
structHelpers.MathOperations = MathOperationsHelpers;
439439

440440
const exports = {

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export async function createInstantiator(options, swift) {
116116
let _exports = null;
117117
let bjs = null;
118118
const __bjs_createPointHelpers = () => {
119-
return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers) => ({
119+
return () => ({
120120
lower: (value) => {
121121
tmpParamF64s.push(value.x);
122122
tmpParamF64s.push(value.y);
@@ -130,7 +130,7 @@ export async function createInstantiator(options, swift) {
130130
});
131131
};
132132
const __bjs_createAPIResultValuesHelpers = () => {
133-
return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({
133+
return () => ({
134134
lower: (value) => {
135135
const enumTag = value.tag;
136136
switch (enumTag) {
@@ -201,7 +201,7 @@ export async function createInstantiator(options, swift) {
201201
});
202202
};
203203
const __bjs_createComplexResultValuesHelpers = () => {
204-
return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({
204+
return () => ({
205205
lower: (value) => {
206206
const enumTag = value.tag;
207207
switch (enumTag) {
@@ -321,7 +321,7 @@ export async function createInstantiator(options, swift) {
321321
});
322322
};
323323
const __bjs_createResultValuesHelpers = () => {
324-
return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({
324+
return () => ({
325325
lower: (value) => {
326326
const enumTag = value.tag;
327327
switch (enumTag) {
@@ -385,7 +385,7 @@ export async function createInstantiator(options, swift) {
385385
});
386386
};
387387
const __bjs_createNetworkingResultValuesHelpers = () => {
388-
return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({
388+
return () => ({
389389
lower: (value) => {
390390
const enumTag = value.tag;
391391
switch (enumTag) {
@@ -431,7 +431,7 @@ export async function createInstantiator(options, swift) {
431431
});
432432
};
433433
const __bjs_createAPIOptionalResultValuesHelpers = () => {
434-
return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({
434+
return () => ({
435435
lower: (value) => {
436436
const enumTag = value.tag;
437437
switch (enumTag) {
@@ -560,7 +560,7 @@ export async function createInstantiator(options, swift) {
560560
});
561561
};
562562
const __bjs_createTypedPayloadResultValuesHelpers = () => {
563-
return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({
563+
return () => ({
564564
lower: (value) => {
565565
const enumTag = value.tag;
566566
switch (enumTag) {
@@ -635,7 +635,7 @@ export async function createInstantiator(options, swift) {
635635
});
636636
};
637637
const __bjs_createAllTypesResultValuesHelpers = () => {
638-
return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({
638+
return () => ({
639639
lower: (value) => {
640640
const enumTag = value.tag;
641641
switch (enumTag) {
@@ -722,7 +722,7 @@ export async function createInstantiator(options, swift) {
722722
});
723723
};
724724
const __bjs_createOptionalAllTypesResultValuesHelpers = () => {
725-
return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({
725+
return () => ({
726726
lower: (value) => {
727727
const enumTag = value.tag;
728728
switch (enumTag) {
@@ -965,7 +965,7 @@ export async function createInstantiator(options, swift) {
965965
return 0;
966966
}
967967
bjs["swift_js_struct_lift_Point"] = function() {
968-
const value = structHelpers.Point.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers);
968+
const value = structHelpers.Point.lift();
969969
return swift.memory.retain(value);
970970
}
971971
bjs["swift_js_return_optional_bool"] = function(isSome, value) {
@@ -1103,31 +1103,31 @@ export async function createInstantiator(options, swift) {
11031103
}
11041104

11051105
}
1106-
const PointHelpers = __bjs_createPointHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers);
1106+
const PointHelpers = __bjs_createPointHelpers()();
11071107
structHelpers.Point = PointHelpers;
11081108

1109-
const APIResultHelpers = __bjs_createAPIResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers);
1109+
const APIResultHelpers = __bjs_createAPIResultValuesHelpers()();
11101110
enumHelpers.APIResult = APIResultHelpers;
11111111

1112-
const ComplexResultHelpers = __bjs_createComplexResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers);
1112+
const ComplexResultHelpers = __bjs_createComplexResultValuesHelpers()();
11131113
enumHelpers.ComplexResult = ComplexResultHelpers;
11141114

1115-
const ResultHelpers = __bjs_createResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers);
1115+
const ResultHelpers = __bjs_createResultValuesHelpers()();
11161116
enumHelpers.Result = ResultHelpers;
11171117

1118-
const NetworkingResultHelpers = __bjs_createNetworkingResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers);
1118+
const NetworkingResultHelpers = __bjs_createNetworkingResultValuesHelpers()();
11191119
enumHelpers.NetworkingResult = NetworkingResultHelpers;
11201120

1121-
const APIOptionalResultHelpers = __bjs_createAPIOptionalResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers);
1121+
const APIOptionalResultHelpers = __bjs_createAPIOptionalResultValuesHelpers()();
11221122
enumHelpers.APIOptionalResult = APIOptionalResultHelpers;
11231123

1124-
const TypedPayloadResultHelpers = __bjs_createTypedPayloadResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers);
1124+
const TypedPayloadResultHelpers = __bjs_createTypedPayloadResultValuesHelpers()();
11251125
enumHelpers.TypedPayloadResult = TypedPayloadResultHelpers;
11261126

1127-
const AllTypesResultHelpers = __bjs_createAllTypesResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers);
1127+
const AllTypesResultHelpers = __bjs_createAllTypesResultValuesHelpers()();
11281128
enumHelpers.AllTypesResult = AllTypesResultHelpers;
11291129

1130-
const OptionalAllTypesResultHelpers = __bjs_createOptionalAllTypesResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers);
1130+
const OptionalAllTypesResultHelpers = __bjs_createOptionalAllTypesResultValuesHelpers()();
11311131
enumHelpers.OptionalAllTypesResult = OptionalAllTypesResultHelpers;
11321132

11331133
const exports = {

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export async function createInstantiator(options, swift) {
3535
let _exports = null;
3636
let bjs = null;
3737
const __bjs_createFooContainerHelpers = () => {
38-
return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers) => ({
38+
return () => ({
3939
lower: (value) => {
4040
let id;
4141
if (value.foo != null) {
@@ -184,7 +184,7 @@ export async function createInstantiator(options, swift) {
184184
return 0;
185185
}
186186
bjs["swift_js_struct_lift_FooContainer"] = function() {
187-
const value = structHelpers.FooContainer.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers);
187+
const value = structHelpers.FooContainer.lift();
188188
return swift.memory.retain(value);
189189
}
190190
bjs["swift_js_return_optional_bool"] = function(isSome, value) {
@@ -298,7 +298,7 @@ export async function createInstantiator(options, swift) {
298298
/** @param {WebAssembly.Instance} instance */
299299
createExports: (instance) => {
300300
const js = swift.memory.heap;
301-
const FooContainerHelpers = __bjs_createFooContainerHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers);
301+
const FooContainerHelpers = __bjs_createFooContainerHelpers()();
302302
structHelpers.FooContainer = FooContainerHelpers;
303303

304304
const exports = {

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export async function createInstantiator(options, swift) {
5959
let _exports = null;
6060
let bjs = null;
6161
const __bjs_createResultValuesHelpers = () => {
62-
return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({
62+
return () => ({
6363
lower: (value) => {
6464
const enumTag = value.tag;
6565
switch (enumTag) {
@@ -723,7 +723,7 @@ export async function createInstantiator(options, swift) {
723723
for (const cleanup of arrayCleanups) { cleanup(); }
724724
}
725725
}
726-
const ResultHelpers = __bjs_createResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers);
726+
const ResultHelpers = __bjs_createResultValuesHelpers()();
727727
enumHelpers.Result = ResultHelpers;
728728

729729
const exports = {

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export async function createInstantiator(options, swift) {
4646
let _exports = null;
4747
let bjs = null;
4848
const __bjs_createAPIResultValuesHelpers = () => {
49-
return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({
49+
return () => ({
5050
lower: (value) => {
5151
const enumTag = value.tag;
5252
switch (enumTag) {
@@ -312,7 +312,7 @@ export async function createInstantiator(options, swift) {
312312
return ret;
313313
}
314314
}
315-
const APIResultHelpers = __bjs_createAPIResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers);
315+
const APIResultHelpers = __bjs_createAPIResultValuesHelpers()();
316316
enumHelpers.APIResult = APIResultHelpers;
317317

318318
if (typeof globalThis.Utils === 'undefined') {

0 commit comments

Comments
 (0)