Commit 52ec56c
committed
feat: preserve identity across all return shapes
Emit a per-class extension override of _BridgedSwiftHeapObject's
bridgeJSLowerReturn that routes through the identity cache, symmetric
to the existing bridgeJSStackPush override. Without it,
Optional<SwiftIdentityClass> returns bypassed the per-class table:
_BridgedAsOptional.bridgeJSLowerReturn calls
value.bridgeJSLowerReturn() on the inner heap object, and that call
previously hit the default implementation (passRetained + bare
pointer) instead of our per-method thunk.
With this override, scalar, array-element, and Optional returns all
route through the same identity handshake. The existing Optional
identity test is upgraded from observability-only to strict === .
Side effect: the per-method `case .swiftHeapObject where isSwiftIdentityMode`
branch in ExportedThunkBuilder.lowerReturnValue is now redundant —
ret.bridgeJSLowerReturn() picks up the extension override
automatically. The builder's isSwiftIdentityMode predicate is
removed; codegen is simpler.
Also drops the ENABLE_TEST_INTROSPECTION compile-flag gate on the
Task 5 identity-table-size helpers. The generated BridgeJS.swift
always declares the Wasm exports for `@JS func` declarations, so a
conditional function definition broke the Generated file on
toolchains that didn't pick up the target's swiftSettings define.
The helpers are trivial and cost nothing to always-emit in test
targets that don't ship.
165/165 tests green.1 parent 37fbaf0 commit 52ec56c
17 files changed
Lines changed: 205 additions & 426 deletions
File tree
- Benchmarks/Sources/Generated
- Plugins/BridgeJS
- Sources
- BridgeJSCore
- BridgeJSLink
- Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests
- Sources/JavaScriptKit
- Documentation.docc/Articles/BridgeJS/Exporting-Swift
- Tests
- BridgeJSIdentityTests
- Generated
- JavaScript
- BridgeJSSwiftIdentityTests
- Generated
- JavaScript
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1822 | 1822 | | |
1823 | 1823 | | |
1824 | 1824 | | |
1825 | | - | |
1826 | | - | |
1827 | | - | |
1828 | | - | |
1829 | | - | |
1830 | | - | |
1831 | | - | |
| 1825 | + | |
1832 | 1826 | | |
1833 | 1827 | | |
1834 | 1828 | | |
| |||
1961 | 1955 | | |
1962 | 1956 | | |
1963 | 1957 | | |
| 1958 | + | |
| 1959 | + | |
| 1960 | + | |
| 1961 | + | |
| 1962 | + | |
| 1963 | + | |
| 1964 | + | |
| 1965 | + | |
| 1966 | + | |
| 1967 | + | |
1964 | 1968 | | |
1965 | 1969 | | |
1966 | 1970 | | |
| |||
2001 | 2005 | | |
2002 | 2006 | | |
2003 | 2007 | | |
2004 | | - | |
2005 | | - | |
2006 | | - | |
2007 | | - | |
2008 | | - | |
2009 | | - | |
2010 | | - | |
| 2008 | + | |
2011 | 2009 | | |
2012 | 2010 | | |
2013 | 2011 | | |
| |||
2018 | 2016 | | |
2019 | 2017 | | |
2020 | 2018 | | |
2021 | | - | |
2022 | | - | |
2023 | | - | |
2024 | | - | |
2025 | | - | |
2026 | | - | |
2027 | | - | |
| 2019 | + | |
2028 | 2020 | | |
2029 | 2021 | | |
2030 | 2022 | | |
| |||
2035 | 2027 | | |
2036 | 2028 | | |
2037 | 2029 | | |
2038 | | - | |
2039 | | - | |
2040 | | - | |
2041 | | - | |
2042 | | - | |
2043 | | - | |
2044 | | - | |
| 2030 | + | |
2045 | 2031 | | |
2046 | 2032 | | |
2047 | 2033 | | |
| |||
2079 | 2065 | | |
2080 | 2066 | | |
2081 | 2067 | | |
| 2068 | + | |
| 2069 | + | |
| 2070 | + | |
| 2071 | + | |
| 2072 | + | |
| 2073 | + | |
| 2074 | + | |
| 2075 | + | |
| 2076 | + | |
| 2077 | + | |
2082 | 2078 | | |
2083 | 2079 | | |
2084 | 2080 | | |
| |||
2119 | 2115 | | |
2120 | 2116 | | |
2121 | 2117 | | |
2122 | | - | |
2123 | | - | |
2124 | | - | |
2125 | | - | |
2126 | | - | |
2127 | | - | |
2128 | | - | |
| 2118 | + | |
2129 | 2119 | | |
2130 | 2120 | | |
2131 | 2121 | | |
| |||
2174 | 2164 | | |
2175 | 2165 | | |
2176 | 2166 | | |
| 2167 | + | |
| 2168 | + | |
| 2169 | + | |
| 2170 | + | |
| 2171 | + | |
| 2172 | + | |
| 2173 | + | |
| 2174 | + | |
| 2175 | + | |
| 2176 | + | |
2177 | 2177 | | |
2178 | 2178 | | |
2179 | 2179 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
| 228 | + | |
233 | 229 | | |
234 | 230 | | |
235 | 231 | | |
| |||
241 | 237 | | |
242 | 238 | | |
243 | 239 | | |
244 | | - | |
245 | | - | |
246 | | - | |
| 240 | + | |
247 | 241 | | |
248 | 242 | | |
249 | 243 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
| 34 | + | |
| 35 | + | |
44 | 36 | | |
45 | 37 | | |
46 | 38 | | |
| |||
125 | 117 | | |
126 | 118 | | |
127 | 119 | | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | 120 | | |
134 | | - | |
| 121 | + | |
135 | 122 | | |
136 | | - | |
137 | 123 | | |
138 | 124 | | |
139 | 125 | | |
| |||
351 | 337 | | |
352 | 338 | | |
353 | 339 | | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | 340 | | |
375 | 341 | | |
376 | 342 | | |
| |||
506 | 472 | | |
507 | 473 | | |
508 | 474 | | |
509 | | - | |
510 | | - | |
| 475 | + | |
511 | 476 | | |
512 | 477 | | |
513 | 478 | | |
| |||
528 | 493 | | |
529 | 494 | | |
530 | 495 | | |
531 | | - | |
532 | | - | |
| 496 | + | |
533 | 497 | | |
534 | 498 | | |
535 | 499 | | |
| |||
559 | 523 | | |
560 | 524 | | |
561 | 525 | | |
562 | | - | |
| 526 | + | |
563 | 527 | | |
564 | 528 | | |
565 | 529 | | |
| |||
588 | 552 | | |
589 | 553 | | |
590 | 554 | | |
591 | | - | |
| 555 | + | |
592 | 556 | | |
593 | 557 | | |
594 | 558 | | |
| |||
602 | 566 | | |
603 | 567 | | |
604 | 568 | | |
605 | | - | |
| 569 | + | |
606 | 570 | | |
607 | 571 | | |
608 | 572 | | |
| |||
704 | 668 | | |
705 | 669 | | |
706 | 670 | | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
| 671 | + | |
711 | 672 | | |
712 | 673 | | |
713 | 674 | | |
| |||
753 | 714 | | |
754 | 715 | | |
755 | 716 | | |
756 | | - | |
757 | | - | |
758 | | - | |
759 | | - | |
| 717 | + | |
| 718 | + | |
760 | 719 | | |
761 | 720 | | |
762 | 721 | | |
| |||
772 | 731 | | |
773 | 732 | | |
774 | 733 | | |
775 | | - | |
776 | | - | |
777 | | - | |
778 | | - | |
779 | | - | |
| 734 | + | |
780 | 735 | | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
781 | 746 | | |
782 | 747 | | |
783 | 748 | | |
| |||
790 | 755 | | |
791 | 756 | | |
792 | 757 | | |
793 | | - | |
| 758 | + | |
794 | 759 | | |
795 | 760 | | |
796 | 761 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
346 | 346 | | |
347 | 347 | | |
348 | 348 | | |
349 | | - | |
| 349 | + | |
350 | 350 | | |
351 | | - | |
352 | | - | |
| 351 | + | |
353 | 352 | | |
354 | 353 | | |
355 | 354 | | |
| |||
Lines changed: 2 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1202 | 1202 | | |
1203 | 1203 | | |
1204 | 1204 | | |
1205 | | - | |
| 1205 | + | |
1206 | 1206 | | |
1207 | 1207 | | |
1208 | 1208 | | |
1209 | | - | |
1210 | | - | |
1211 | | - | |
| 1209 | + | |
1212 | 1210 | | |
1213 | 1211 | | |
1214 | 1212 | | |
| |||
0 commit comments