Wasm Support

Thanks for the replies Yuta!

That sounds great, then I agree using an absolute pointer in place of relative is the way to go. However, does WASM support loading and linking multiple wasm files on the client side? How does symbol resolution work in that case? If there's the equivalent of an import table or GOT, it might still be interesting to have something like RelativeIndirectablePointer, but with an absolute address, to still be able to avoid up-front load time costs for cold metadata structures.

I wouldn't expect an extra added argument and return to have that much overhead, and it seems like it'd be a reasonably tractable peephole optimization for WASM code generators to elide the argument materialization if it were passed an undef value. I would be concerned that, even if you patch up the compiler to thunk instead of assuming the ABIs match up, we still assume that nonthrowing functions are ABI-compatible with throwing functions fairly pervasively through the runtime, and that existing Swift code in the wild may also be relying on that assumption.

If it helps, it's also worth noting that the value in the memory pointed to by the swifterror argument is generally not significant in the calling convention, only the value at the time the function returns. You could probably avoid materializing an argument altogether and just treat it as undefined on function entry and only materialize an extra return. Another possibility might be, if WASM has a native encoding for alternative returns to represent exception handling, to utilize that to represent error returns and throws instead.

In that case, I would simply disable the tests for now.

1 Like