WebAssembly/module-linking

Need some way to declare thrown exceptions?

Closed this issue · 4 comments

Although the exceptions a function can throw are not part of its type, they are part of its contracts with its callers. It would be unfortunate if we could not reason about this part of a module’s ABI when checking that a module inhabits a module type. For example, modules that inhabit the same module type should ideally be drop-in replacements for each other, but if they can throw exceptions with different tags or types then they may not actually be interchangeable after all.

It’s possible that these concerns should not be addressed at the level of this proposal, though. This might be a consideration for interface types instead.

Until the exception proposal lands there doesn't seem much to say. Once Wasm has exceptions, corresponding effect annotations are an interesting consideration, but it is not obvious that they would be useful. The Wasm type system itself doesn't check exception effects, so they would be little more than unchecked comments in a module type.

Since module types are intended to reflect the core Wasm type system only, I agree that interface types are probably a more adequate place to have such a mechanism. But even there it might not provide more than documentary value.

FWIW: given that exceptional values will often contain pointers into linear memory (e.g., the string payload of a C++ std::runtime_error) and a general goal of interface types is to allow linear memories to be encapsulated when composing modules, it would follow that it's within interface types' purview to include mechanisms for adapting exceptions that propagate through a cross-interface call.

But agreed that, because module types simply capture the types of functions in a module, that unless wasm function types (core or with interface types) get an exception effect in their type, it wouldn't make sense for module types to have one. So maybe the place to ask this question is in the exception-handling repo: should be exception specifications?

Relevant issue.

I definitely think there should be exception specifications. It's the direction most languages have been moving towards.

Ok, thanks everyone. Closing in favor of continuing discussions elsewhere.