wasm-micro-runtime: Updating Exception Handling in WAMR
Feature
Adding support for the latest exception handling specification to WAMR
Benefit
This would bring WAMR’s exception handling inline with the current standard,
Implementation
At the moment (see GitHub names below) would like to collaborate to add support for exception handing in WAMR. To reduce the cost of code maintenance going forward the expectation is to replace the current (now out dated) exception handling implementation with one which meets the current Wasm specification.
Contributors
@woodsmc
@ermler
@cjbudnik
@Papadiddypub
Scope
This effort will focus on implementing the new exception handling implementation in WAMRs interpreter mode. Due to time constraints and the availability of the contributors it is unlikely that there would be folks available to address FastJIT / JIT or AoT. If there were additional contributors who would like to assist they would be most welcome.
Alternatives
There are alternative approaches to how the specification is implemented, including keeping the current implementation and adding additional support for the new specification. We considered and rejected this approach as it would increase the amount of code which would need to be maintained, and the number of applications using exception handling on WAMR is limited at the moment.
Implementation Discussion (Open Questions)
The following outlines some of the current discussions as this effort starts to get going, it is shared here for comment, reflection and openness. Feed back and any ideas would be really appreciated:
Every Wasm function can return an exception
The new specification indicated that if an exception handler can not be found (uncaught exception) that the exception should be returned to the caller. This implies that every Wasm function can return an exception OR its originally anticipated results, even if that function returns void, it would still be possible for it to return an exception.
We understand that this is maybe a fundamental shift in how WAMR supports invoking functions, now every Wasm function returns an exception or the data its function signature indicates. Would this mean updating the WAMR runtime’s API ? - How could we do this in a way that has minimal impact for existing users, while still adhering to the specification ?
Naming Conventions: When an exception isn’t an exception
The existing WAMR code base uses “exceptions” to mean “traps”, in the long run this may cause some confusion. Is it worth while refactoring the code to rename “exceptions” to traps, so that when the exception handling implementation is added the code is easier to understand and maintain ?
The growing list of return values
Realistically a Wasm function can return any one of the following:
- The original function signature parameter(s)
- An exception
- A trap
It a discussion with Ben Titzer at CMU, he suggested unifying the return path from exception and trap? - Perhaps this would work if we addressed naming convention issue too ?
Ben also pointed out that stack switching is likely to introduce another return path, where a function call results in a set of suspend / resume calls which result in a broken stack and no return path / value.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 2
- Comments: 20 (12 by maintainers)
@bashor Awesome, it’s great to know that the Kotlin tool chain is compiling to the new EH spec, it would be great if we could use this tool chain to build some example user code (in addition to the specification tests) as we commence the implementation. I might reach out to you to ensure we can setup a Kotlin development environment correctly to do this…
Thank you.