Skip to content

Commit 7292937

Browse files
committed
Remove unwind
It looks people have generally agreed on removing `unwind` in the MVP spec, as it overlaps with `catch_all` in functionality. Fixes WebAssembly#153.
1 parent a5e87e4 commit 7292937

File tree

1 file changed

+16
-67
lines changed

1 file changed

+16
-67
lines changed

proposals/exception-handling/Exceptions.md

+16-67
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ succeeding instructions to process the data.
3636
A WebAssembly exception is created when you throw it with the `throw`
3737
instruction. Thrown exceptions are handled as follows:
3838

39-
1. They can be caught by one of `catch`/`catch_all`/`unwind` blocks in an
40-
enclosing try block of a function body.
39+
1. They can be caught by one of `catch`/`catch_all` blocks in an enclosing try
40+
block of a function body.
4141

4242
1. Throws not caught within a function body continue up the call stack, popping
4343
call frames, until an enclosing try block is found.
@@ -59,8 +59,8 @@ may send values back to the suspended instruction, allowing the originating code
5959
to resume.
6060

6161
Exceptions are a special case of an event in that they never resume. Similarly,
62-
a `throw` instruction is the suspending event of an exception. The catch or
63-
unwind block associated with a try block defines how to handle the throw.
62+
a `throw` instruction is the suspending event of an exception. The catch block
63+
associated with a try block defines how to handle the throw.
6464

6565
WebAssembly events (i.e. exceptions) are defined by a new `event` section of a
6666
WebAssembly module. The event section is a list of declared events associated
@@ -151,32 +151,6 @@ exception is thrown, or the exception is successfully caught by the catch block.
151151
Because `try` and `end` instructions define a control-flow block, they can be
152152
targets for branches (`br` and `br_if`) as well.
153153

154-
### Try-unwind blocks
155-
156-
Try blocks can also be used with the `unwind` instruction. A try-unwind block
157-
contains an `unwind` block with the following form:
158-
159-
```
160-
try blocktype
161-
instruction*
162-
unwind
163-
instruction*
164-
end
165-
```
166-
167-
The `unwind` block is meant to contain cleanup instructions, such as
168-
destructors, in case any instruction in the corresponding try block throws. In
169-
case an exception is caught by the `unwind` block, it becomes the catching
170-
block.
171-
172-
The `end` instruction at the end of `unwind` block is special that it
173-
automatically rethrows the current exception.
174-
175-
When the program runs `br` within `unwind` block, the rest of the `unwind` block
176-
will not run and the program control will branch to the destination, as in
177-
normal blocks. Because we don't reach `end` of `unwind` block, rethrowing does
178-
not happen.
179-
180154
### Throwing an exception
181155

182156
The `throw` instruction takes an exception index as an immediate argument. That
@@ -202,8 +176,8 @@ flushed, the embedder defines how to handle uncaught exceptions. Otherwise, the
202176
found enclosing try block is the catching try block.
203177

204178
A throw inside the body of a catch block is never caught by the corresponding
205-
try block of the catch/unwind block, since instructions in the body of the
206-
catch/unwind block are not in the body of the try block.
179+
try block of the catch block, since instructions in the body of the catch block
180+
are not in the body of the try block.
207181

208182
Once a catching try block is found for the thrown exception, the operand stack
209183
is popped back to the size the operand stack had when the try block was entered
@@ -224,23 +198,15 @@ a `catch_all` block, the exception is rethrown.
224198
If control is transferred to the body of a catch block, and the last instruction
225199
in the body is executed, control then exits the try block.
226200

227-
In case of a try-unwind block, if an exception is thrown within the try block,
228-
the program control is transfered to the body of `unwind` block. After executing
229-
instructions within the `unwind` block, the exception is automatically rethrown
230-
when the control reaches the `end` instruction. As in the case of the
231-
`catch_all` block, the exception arguments are not copied onto the operand
232-
stack.
233-
234-
If the selected catch/unwind block does not throw an exception, it must yield
235-
the value(s) expected by the corresponding catching try block.
201+
If the selected catch block does not throw an exception, it must yield the
202+
value(s) expected by the corresponding catching try block.
236203

237204
Note that a caught exception can be rethrown using the `rethrow` instruction.
238205

239206
### Rethrowing an exception
240207

241-
The `rethrow` instruction can only appear in the body of a
242-
catch/catch_all/unwind block. It always re-throws the exception caught by an
243-
enclosing catch block.
208+
The `rethrow` instruction can only appear in the body of a catch/catch_all
209+
block. It always re-throws the exception caught by an enclosing catch block.
244210

245211
Associated with the `rethrow` instruction is a _label_. The label is used to
246212
disambiguate which exception is to be rethrown, when inside nested catch blocks.
@@ -297,21 +263,6 @@ end
297263
The `rethrow` here references `try $l2`, but the `rethrow` is not within its
298264
`catch` block.
299265

300-
Also, the `rethrow` instruction cannot rethrow an exception caught
301-
by an unwind block. For example:
302-
```
303-
try $l1
304-
unwind
305-
try $l2
306-
catch
307-
try $l3
308-
unwind
309-
rethrow label ;; only $l2 is valid
310-
end
311-
end
312-
end
313-
```
314-
315266
### Try-delegate blocks
316267

317268
Try blocks can also be used with the `delegate` instruction. A try-delegate
@@ -326,8 +277,8 @@ delegate label
326277
The `delegate` clause does not have an associated body, so try-delegate blocks
327278
don't have an `end` instruction at the end. The `delegate` instruction takes a
328279
label defined by a construct in which they are enclosed, and delegates exception
329-
handling to a catch/unwind block specified by the label. For example, consider
330-
this code:
280+
handling to a catch block specified by the label. For example, consider this
281+
code:
331282

332283
```
333284
try $l1
@@ -373,10 +324,10 @@ uncaught exceptions. However, the details of this are left to the embedder.
373324

374325
#### Traps
375326

376-
The `catch`/`catch_all`/`unwind` instruction catches exceptions generated by the
377-
`throw` instruction, but does not catch traps. The rationale for this is that in
378-
general traps are not locally recoverable and are not needed to be handled in
379-
local scopes like try-catch.
327+
The `catch`/`catch_all` instruction catches exceptions generated by the `throw`
328+
instruction, but does not catch traps. The rationale for this is that in general
329+
traps are not locally recoverable and are not needed to be handled in local
330+
scopes like try-catch.
380331

381332
The `catch` instruction catches foreign exceptions generated from calls to
382333
function imports as well, including JavaScript exceptions, with a few
@@ -406,7 +357,6 @@ The following rules are added to *instructions*:
406357

407358
```
408359
try blocktype instruction* (catch instruction*)* (catch_all instruction*)? end |
409-
try blocktype instruction* unwind instruction* end |
410360
try blocktype instruction* delegate label |
411361
throw (exception except_index) |
412362
rethrow label |
@@ -564,7 +514,6 @@ throws, and rethrows as follows:
564514
| `try` | `0x06` | sig : `blocktype` | begins a block which can handle thrown exceptions |
565515
| `catch` | `0x07` | index : `varint32` | begins the catch block of the try block |
566516
| `catch_all` | `0x19` | | begins the catch_all block of the try block |
567-
| `unwind` | `0x0a` | | begins the unwind block of the try block |
568517
| `delegate` | `0x18` | relative_depth : `varuint32` | begins the delegate block of the try block |
569518
| `throw` | `0x08` | index : `varint32` | Creates an exception defined by the exception `index`and then throws it |
570519
| `rethrow` | `0x09` | relative_depth : `varuint32` | Pops the `exnref` on top of the stack and throws it |

0 commit comments

Comments
 (0)