WebAssembly / gc

Branch of the spec repo scoped to discussion of GC integration in WebAssembly
https://webassembly.github.io/gc/
Other
990 stars 71 forks source link

Qustion on allocation failure #554

Closed yamt closed 1 month ago

yamt commented 1 month ago

a naive implementation of things like struct.new would involve dynamic memory allocation. eg. malloc in C. when it fails, what should happen? a trap?

tlively commented 1 month ago

Yes, see this part of the spec: https://webassembly.github.io/gc/core/appendix/implementation.html#execution

If the runtime limits of an implementation are exceeded during execution of a computation, then it may terminate that computation and report an embedder-specific error to the invoking code.

"terminate that computation" effectively means a trap, although the error returned to the embedder may or may not be different from the error for a trap.

rossberg commented 1 month ago

"Terminate the computation" can mean other means. It's intentionally vague, since it depends on implementation and host environment how reliable they can still operate at such a point. For example, if the embedder is JavaScript and Wasm runs out of memory to allocate, then running more JavaScript will most likely not be possible either. Hence a catchable trap might not be an option.

tlively commented 1 month ago

Closing this as answered, but feel free to reopen if there are follow-on questions.