Open
Description
Currently "assert" function and exceptions required one external abort function and one "unreachable" on wasm side.
But what if, instead of inserting unreachable on the wasm side after the abort call, we move the completion of the program to the host side?
Current approach:
function assert(cond: bool, msg: string | null = null): void {
if (cond) {
abort(__FILE, __LINE, __COLUMN, msg);
unreachable();
}
}
Proposed approach:
function assert(cond: bool, msg: string | null = null): void {
if (cond) {
abort(__FILE, __LINE, __COLUMN, msg);
}
}
and on host side use something like this:
const imports = {
env: {
abort(file, line, column, msg) {
throw new AbortError(`Abort at ${file}[${line}, ${column}]: ${__getString(msg)}`);
}
}
}
Pros:
- Reduce binary size
- Allows us to turn on recent TrapsNeverHappen mode which will remove much more dead code.
Cons:
- Breaking changes which especially sensitive for non-web environments.
- Now the processing of program termination delegate to the host's side. This can be both an advantage (e.g., user can just ignore the assert or specific assert and continue program working) and a disadvantage (non-deterministic termination depends from host to host decision). In general, this point is quite controversial.
Thoghts?