Commit f683048
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. This was necessary for
Optional<SwiftIdentityClass> returns: the _BridgedAsOptional bridge
calls value.bridgeJSLowerReturn() on the inner heap object, which
previously hit the default implementation (passRetained + bare pointer)
and bypassed our per-class identity table.
With this override, scalar, array-element, and Optional returns all
route through the same identity handshake. Before the fix, .some(x)
returned a fresh wrapper each call; now it preserves === identity.
Side benefit: the per-method `case .swiftHeapObject where isSwiftIdentityMode`
branch in ExportedThunkBuilder.lowerReturnValue is redundant —
ret.bridgeJSLowerReturn() picks up the extension override automatically.
The builder's isSwiftIdentityMode predicate is removed; codegen is
simpler.
The upgraded E2E test now asserts === identity for Optional.some.
165/165 tests green.1 parent 37fbaf0 commit f683048
8 files changed
Lines changed: 166 additions & 204 deletions
File tree
- Benchmarks/Sources/Generated
- Plugins/BridgeJS
- Sources/BridgeJSCore
- 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 | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | 128 | | |
134 | | - | |
| 129 | + | |
135 | 130 | | |
136 | | - | |
137 | 131 | | |
138 | 132 | | |
139 | 133 | | |
| |||
351 | 345 | | |
352 | 346 | | |
353 | 347 | | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | 348 | | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
375 | 355 | | |
376 | 356 | | |
377 | 357 | | |
| |||
506 | 486 | | |
507 | 487 | | |
508 | 488 | | |
509 | | - | |
510 | | - | |
| 489 | + | |
511 | 490 | | |
512 | 491 | | |
513 | 492 | | |
| |||
528 | 507 | | |
529 | 508 | | |
530 | 509 | | |
531 | | - | |
532 | | - | |
| 510 | + | |
533 | 511 | | |
534 | 512 | | |
535 | 513 | | |
| |||
559 | 537 | | |
560 | 538 | | |
561 | 539 | | |
562 | | - | |
| 540 | + | |
563 | 541 | | |
564 | 542 | | |
565 | 543 | | |
| |||
588 | 566 | | |
589 | 567 | | |
590 | 568 | | |
591 | | - | |
| 569 | + | |
592 | 570 | | |
593 | 571 | | |
594 | 572 | | |
| |||
602 | 580 | | |
603 | 581 | | |
604 | 582 | | |
605 | | - | |
| 583 | + | |
606 | 584 | | |
607 | 585 | | |
608 | 586 | | |
| |||
772 | 750 | | |
773 | 751 | | |
774 | 752 | | |
775 | | - | |
776 | | - | |
777 | | - | |
778 | | - | |
779 | | - | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
780 | 759 | | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
781 | 770 | | |
782 | 771 | | |
783 | 772 | | |
| |||
790 | 779 | | |
791 | 780 | | |
792 | 781 | | |
793 | | - | |
| 782 | + | |
794 | 783 | | |
795 | 784 | | |
796 | 785 | | |
| |||
Lines changed: 11 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
| 8 | + | |
15 | 9 | | |
16 | 10 | | |
17 | 11 | | |
| |||
60 | 54 | | |
61 | 55 | | |
62 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
63 | 67 | | |
64 | 68 | | |
65 | 69 | | |
| |||
Lines changed: 10 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
| 72 | + | |
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
78 | 86 | | |
79 | 87 | | |
80 | 88 | | |
| |||
91 | 99 | | |
92 | 100 | | |
93 | 101 | | |
94 | | - | |
95 | | - | |
| 102 | + | |
96 | 103 | | |
97 | 104 | | |
98 | 105 | | |
| |||
0 commit comments