Embedded Swift

In Embedded Swift for Wasm interoperating with JS, what could work is a #utf16 macro that converts string literals to [UInt16], similar to the #utf8 macro I previously suggested here: SE-0382: Expression Macros - #23 by Max_Desiatov. That way with an allocator you can get all of the array operations available, such as concatenation, addressing via integer indices, transformations with map etc.

As for JavaScriptKit, it was designed before Embedded Swift existed and with little constraints on binary size, which looked small anyway when compared to 5 MB minimum of non-embedded Swift binaries built for WASI. Its dynamic approach to bridging would need to be rethought for Embedded Swift. Maybe it could be built on top of macros that automatically produce @_extern and @_expose bindings which are static, don't requite passing and re-encoding a huge amount of strings around, and have much better performance as a consequence.

2 Likes