Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider removing tags from proposal #32

Closed
eholk opened this issue Nov 3, 2017 · 7 comments
Closed

Consider removing tags from proposal #32

eholk opened this issue Nov 3, 2017 · 7 comments

Comments

@eholk
Copy link
Contributor

eholk commented Nov 3, 2017

Recent discussions have revealed that the tag system we are currently proposing is not very useful for implementing exceptions in C++ via LLVM. While tools are certainly welcome to ignore tags entirely and use only catch_all, as #31 proposes, it seems that we should consider removing the tags portion of the proposal entirely.

As far as I know, we currently have no languages that are planning to use tags. This means we could be in the unfortunate position of requiring more complexity on the part of WebAssembly implementations for a feature that is unused. It seems better not to require this in the first place.

From a design standpoint, I like tags, and I can definitely see how they could be useful to some languages. If there are languages actively planning to use these features, we should pull the implementors into the design process to make sure we come up with something that meets their needs.

If we do not have current users for tags, I suggest removing them from the proposal. Ideally we would do this in a way that leaves the door open for them if they are needed in the future.

@rossberg
Copy link
Member

rossberg commented Nov 6, 2017

The primary purpose of exception tags in Wasm is not to distinguish different exceptions within the same language (although you can use them for that, too), it is to distinguish exceptions from different languages.

Keep in mind that Wasm effectively is a multi-language environment, where calls and exceptions can potentially cross language boundaries in arbitrary ways. In such an environment a language implementation has to be able to reliably distinguish one of its own exceptions (and corresponding assumptions about associated data) from foreign ones. The only way to achieve that reliably in an uncooperative environment is through some generative naming mechanism.

In other words, C++ is a current user, and must remain so!

@eholk
Copy link
Contributor Author

eholk commented Nov 6, 2017

My understanding of the discussion on #31 and in-person discussions with @aheejin is that because C++ needs to ensure destructors run in the presence of all exceptions, and because LLVM does not distinguish cleanup code (i.e. the code that needs to run even in the presence of a non-C++ excpetion) from catch code, the current plan is to only generate catch_all clauses and then use some other mechanism (such as Itanium-style LSDA) to decide what type of exception it was.

@rossberg
Copy link
Member

rossberg commented Nov 6, 2017

Even then you will still need to distinguish based on the tag (i.e., some separate matching mechanism would be needed).

@eholk
Copy link
Contributor Author

eholk commented Nov 6, 2017

I think the plan is to do something like having a global variable like is_cpp_exception that the C++ code will always set before throwing an exception. When using just catch_all, you don't get access to the tag anyway.

@rossberg
Copy link
Member

rossberg commented Nov 6, 2017

How would that work? Your exception could fly through some other language's frame that catches it and throws one of its own. Where would you have a chance to clear your flag?

@aheejin
Copy link
Member

aheejin commented Nov 6, 2017

@rossberg That's a good point... Then we are going to need instructions like match as Eric proposed in #30. I think it would be good to have an instruction like not_match as well, because from the C++'s point of view (and most of future target language's point of view) the important thing is to tell if this is "our" exception or not.

If there are another use cases, I don't particularly insist on removing the current catch tag instructions, but what I tried to convey in #31 is at least C++ cannot use it, because it has no way of separating cleanup code or catch (...) part of the code from a CFG.

@eholk
Copy link
Contributor Author

eholk commented Nov 9, 2017

This thread has given us a strong argument in favor of keeping tags. I think it also strongly suggests that we need a way to dynamically inspect an exception. Since we've now considered removing tags and decided to keep them, I'm going to mark this issue as closed.

@eholk eholk closed this as completed Nov 9, 2017
ioannad pushed a commit to ioannad/exception-handling that referenced this issue Jun 6, 2020
I recently looked into adding support for bulk memory operations into
some Rust tooling in preparation for an overall threading story, and on
reading the overview here I was slightly confused about a few encodings
and some semantics. In the end I'm hopeful that these updates can help
clarify these for future readers! No major functional change is intended
here, only tweaks to wording and clarification of what I believe the
original intent of the instructions were.

Changes made were:

* Fixed a broken `modules.html` link
* Clarified some wording about how the new encoding of data segments
  with a flags field up front is backwards compatible.
* Lifted the style of specifying encodings in `BinaryEncoding.md` to
  replace the current table for the new encoding of a data section. (I
  found this to be a bit more readable, but it should be functionally
  the same!)
* Update `memory.*` instructions (and transitively `table.*`) to all be
  succeeded by an immediate index of which memory/table to operate over.
  This should, in the future, allow initializing/dropping data segments
  with multiple memories in play.
* Updated the chart of instruction binary encodings to explicitly
  specify the following immediates of segments and tables.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants