logoalt Hacker News

WhereIsTheTruthyesterday at 6:36 PM6 repliesview on HN

> GC and Exception handling

This was not necessary.. what a mistake, specially EH..


Replies

aagyesterday at 6:38 PM

Not including GC would have been a mistake. Having to carry a complete garbage collector with every program, especially on platforms like browsers were excellent ones already exist, would have been a waste.

show 3 replies
flohofwoeyesterday at 6:58 PM

I think it's a "you don't pay for it if you don't use it" thing, so I guess it's fine. It won't affect me compiling my C or Zig code to WASM for instance since those languages have neither garbage collection nor exceptions.

sehuggyesterday at 6:45 PM

It's kinda nice to have 1st class exception support. C++ exceptions barely work in Emscripten right now. Part of the problem is that you can't branch to arbitrary labels in WASM.

bangaladoreyesterday at 6:38 PM

WASM isn't a language, so them adding stuff like this serves to increase performance and standardize rather than forcing compilers to emulate common functionality.

hiccuphippoyesterday at 6:45 PM

This allows more languages to compile to it. You don't need to use these features if you don't want to.

dzaimayesterday at 7:11 PM

Besides making it much nicer for GC'd languages to target WASM, an important aspect is that it also allows cross-language GC.

Whereas with a manual GC, if you had a JS object holding a reference to an object on your custom heap, and your heap holds a reference to that JS object (with indirections sprinkled in to taste) but nothing else references it, that'd result in a permanent memory leak, as both heaps would have to consider everything held by the other as GC roots; so you'd still be forced to manually avoid cycles despite only ever using GC'd languages. Wasm GC entirely avoids this problem.