Skip to content

[WebAssembly] Could C++ EH avoid catch_ref and throw_ref? #149086

@sunfishcode

Description

@sunfishcode

Currently, WebAssemblyLateEHPrepare.cpp rewrites pseudo "rethrow" instructions to catch_ref and throw_ref.

Would it work to instead rewrite it to catch and throw, effectively discarding the old exception object and creating a new one? From my reading of the code, it doesn't look like clang/libcxxabi/libunwind/etc. depend on the state or identity of the thrown exception object, so I'm curious if this might work.

Doing this could help Wasm engines that don't implement Wasm GC, as they could then omit throw_ref, catch_ref, catch_all_ref, and exnref, while still supporting enough to run C++ exceptions and setjmp/longjmp.

Would it be less efficient? In an engine that omits catch_ref/catch_all_ref, there wouldn't be any overhead to creating a new exception object because it wouldn't ever need to be reified. In an engine that does implement Wasm GC, optimized implementations often use bump allocation for short-lived objects, and these would be very short-lived objects. It also seems like there might be ways engines could avoid using the GC heap in common cases. But I'm curious what others think.

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend:WebAssemblyquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions