I’m working on a project that uses Rust to create a WebAssembly binary which will be executed in a non-web (and even non-JS) environment. I have been using a nightly compiler but with the recent release, I started considering switching to stable. Unfortunately, I discovered some roadblocks preventing me from doing that.
My use-case is as follows:
I need to implement
#[panic_handler] which performs some debug logging (which in my case is pretty much host-environment specific) and then just terminates execution via trap (ideally, with wasm’s
unreachable instruction). For the moment the code is using
core::intrinsics::unreachable and it requires nightly
feature(core_intrinsics). Technically, it’s possible to change it to
std::hint::unreachable_unchecked and get rid of the nightly feature. But this is still not a good idea since it’s an UB if the control flow reaches this function. It works for now because the optimizer is tied by immediately preceding calls to external functions I suppose, but this still looks too fragile.
I could try to abort the execution by different means like dividing by zero or adding a special function to the host environment sole purpose of which is just to trap. However, I think that those are awkward solutions.
What I think I really need is to use
core::intrinsics::abort. As far as I understood it is lowered down to
unreachable or similar instructions in non-std environments, and seems like this is exactly what I need.
The problem is that the stabilized version is
std::process::abort which implies the existence of the standard library around which is not my case.
What do you think is the best way forward here? Does this use-case sound legit for you? If so is there any chance of stabilizing of
no_std environments separately?