-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Stabilize std::arch::wasm32::unreachable #61119
Copy link
Copy link
Closed
Labels
O-wasmTarget: WASM (WebAssembly), http://webassembly.org/Target: WASM (WebAssembly), http://webassembly.org/T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Metadata
Metadata
Assignees
Labels
O-wasmTarget: WASM (WebAssembly), http://webassembly.org/Target: WASM (WebAssembly), http://webassembly.org/T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
This is a tracking issue to stabilize
std::arch::wasm32::unreachableThe tentative signature is:
Semantics
This intrinsic represents instruction that is present in the MVP of WebAssembly:
unreachable.From the surface it is a simple instruction: it doesn't take any arguments nor return anything. Upon the execution it generates a trap, which terminates the execution of wasm immediately returning control to the embedder with an error. There are no way to catch a trap at the moment.
Note that technically a WebAssembly instance can be used after a trap. However, Rust doesn't guarantee that such a module is usable after a trap. For example, there is no guarantee that the stack will be reset to initial values or that any destructors be executed.
Stabilization in Rust
In a way, this intrinsic is similar to the currently stabilized
std::process::abortfunction. In fact,std::process::abortis lowered to theunreachableinstruction for wasm32-unknown-unknown - this is totally makes sense since wasm32-unknown-unknown doesn't make any assumptions of the host environment. However, there is a problem withstd::process::abort, it is only available in std. Consider how you would implement a panic handler in WebAssembly forno_stdmode when a trap is required:This works, however, it requires
#![feature(core_intrinsics)]. Here are other ways and why they are not appropriate:loop { }which might be a problem.call_indirectsuffer from the similar issues.Stabilization of
unreachablewill allow implementing the panic handler inno_stdenvironments on stable.cc @alexcrichton @sunfishcode