You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Updated validation rules to match latest semantics of WebAssembly#137
As of commit 275c449
- `rethrow` is as in the first proposal.
- Labels do get a new attribute `kind` which is set to `try` or
`catch' for labels surrounding instructions which start with
`try` or `catch` respectively, and empty otherwise. This is used
to validate `delegate` and `rethrow`/`unwind` respectively.
- `unwind` can no longer be a target of `rethrow`'s immediate
- The `Caught` stack is removed.
I also added a file with Wasm code examples from comments (referenced),
and what they reduce to according to these semantics.
The first example is the only one with a full reduction, and it uses all
new instructions, so it's hopefully easy to get an idea of how this works,
even for readers without much formal spec involvement.
This document contains WebAssembly code examples mentioned in comments on this repository, and what they reduce to, according to the "3rd proposal formal spec overview".
4
+
5
+
Its purpose is to make sure everyone is happy with the implications of the semantics in the current 3rd proposal, or to aid discussions on these semantics.
6
+
7
+
The first *example 0* contains all the new instructions, and it is the only one with an almost full reduction displayed. It is meant to easily show how the spec works, even if the reader has not spent much time with the WebAssembly formal spec.
8
+
9
+
For all other examples just the result of the reduction is given. These examples are taken from comments in this repository, which are linked. Some times/often the examples are modified to fit the current syntax.
10
+
11
+
If anyone would like that I add another reduction trace, or other examples, please let me know, I'd be happy to.
12
+
13
+
### notation
14
+
15
+
If `x` is an exception index, then `a_x` denotes its exception tag, i.e., `F_exn(x) = a_x`, where `F` is the current frame.
16
+
17
+
## example 0
18
+
19
+
The only example with an almost full reduction trace, and all new instructions (`rethrow` is hidden in `unwind`'s reduct). The first 3 steps, reducing the several `try`s to their respective administrative instructions, are not shown.
20
+
21
+
```
22
+
(func (result i32) (local i32)
23
+
try
24
+
try
25
+
try
26
+
throw x
27
+
unwind
28
+
i32.const 27
29
+
local.set 0
30
+
end
31
+
delegate 0
32
+
catch x
33
+
local.get 0
34
+
end)
35
+
```
36
+
37
+
Take the frame `F = (locals i32.const 0, module m)`. We have:
Let `F'` be the frame `{locals i32.const 27, module m}`, and let `B^1 = label_0{} [_] end`.
62
+
63
+
```
64
+
↪ F'; catch_1{a_x local.get 0} (label_1{}
65
+
(delegate{0} (label_0{}
66
+
(caught{a_x} B^1 [rethrow 0] end) end) end) end) end
67
+
68
+
↪ F'; catch_1{a_x local.get 0} (label_1{}
69
+
(delegate{0} (label_0{}
70
+
(caught{a_x} B^1 [throw a_x] end) end) end) end) end
71
+
```
72
+
73
+
Let `T' = label_0{} (caught{a_x} B^1 [_] end) end`.
74
+
75
+
```
76
+
↪ F'; catch_1{a_x local.get 0} (label_1{} throw a_x end) end
77
+
78
+
↪ F'; caught_1{a_x} (label_1{} local.get 0 end) end
79
+
80
+
↪ ↪ ↪ i32.const 27
81
+
```
82
+
83
+
## behaviour of `rethrow`
84
+
85
+
### example 1
86
+
87
+
Interaction of `rethrow` with `unwind`. Taken from [this comment](https://github.com/WebAssembly/exception-handling/issues/87#issuecomment-705586912) by @rossberg.
Note that any global state changes due to `instr1*` or `instr2*` will take place.
111
+
112
+
### example 2
113
+
114
+
`rethrow`'s immediate validation error.
115
+
116
+
@aheejin gave the following
117
+
[example in this comment](https://github.com/WebAssembly/exception-handling/pull/143#discussion_r522673735)
118
+
119
+
```
120
+
try $label0
121
+
rethrow $label0 ;; cannot be done, because it's not within catch below
122
+
catch
123
+
end
124
+
```
125
+
126
+
This is a validation error (no catch block at given rethrow depth).
127
+
128
+
## target of `delegate`'s immediate (label depth)
129
+
130
+
@aheejin gave the following
131
+
[examples in this comment](https://github.com/WebAssembly/exception-handling/pull/143#discussion_r522673735)
132
+
133
+
### example 3
134
+
135
+
`delegate` inside a catch is a validation error.
136
+
137
+
```
138
+
try $label0
139
+
catch
140
+
try
141
+
...
142
+
delegate $label0 ;; cannot be done, because $label0's catch is not below but above here
143
+
end
144
+
```
145
+
146
+
This is a validation error because `delegate`'s `$label0` refers to the catch-label `label { result ε, type catch}`, not to a try-label.
147
+
148
+
### example 4
149
+
150
+
`delegate` correctly targetting a `try-delegate` and a `try-catch`.
151
+
152
+
```
153
+
try $label1
154
+
try $label0
155
+
try
156
+
throw x
157
+
delegate $label0
158
+
delegate $label1
159
+
catch x
160
+
instr*
161
+
end
162
+
```
163
+
164
+
The thrown exception is (eventually) caught by the outer try's `catch x`, so the above reduces to
165
+
166
+
```
167
+
caught_0{a_x} (label_0 {} instr* end) end
168
+
```
169
+
170
+
171
+
## interaction of `delegate` and `unwind`
172
+
173
+
Two examples from issue #130.
174
+
175
+
### example 5
176
+
177
+
The [opening example](https://github.com/WebAssembly/exception-handling/issues/130#issue-713113953)
178
+
of issue #130.
179
+
180
+
```
181
+
i32.const 11
182
+
global.set 0
183
+
try $l
184
+
try
185
+
try
186
+
throw x
187
+
delegate 1
188
+
unwind
189
+
i32.const 27
190
+
global.set 0
191
+
end
192
+
catch_all
193
+
end
194
+
global.get 0
195
+
```
196
+
197
+
Here, `delegate 1` targets the label `$l` (so it would be the same if we wrote `delegate $l` instead).
198
+
199
+
This example returns `11`, because `delegate` skips everything up to and not including `try $l`.
200
+
201
+
### example 6
202
+
203
+
This example
204
+
[appears to keep](https://github.com/WebAssembly/exception-handling/issues/130#issuecomment-704249682)
205
+
the issue #130 open.
206
+
207
+
@RossTate expressed concerns with respect to an example possibly equivalent to
208
+
the one below. "Possibly", because the original example in the comment refers to
209
+
an `unwinding` branch, first presented in issue #124, so I attempted to rewrite
210
+
the example to match the current syntax as best I could.
211
+
212
+
```
213
+
try $t
214
+
try $l
215
+
try $u
216
+
try
217
+
throw x
218
+
delegate $t
219
+
unwind
220
+
instr1*
221
+
end
222
+
catch x
223
+
instr2*
224
+
end
225
+
instr3*
226
+
catch_all
227
+
instr4*
228
+
end
229
+
```
230
+
231
+
The thrown exception tag `a_x` is delegated to the outer `try $l - catch_all`, ignoring the `try $u - unwind` and `try - catch x` in between. So this example reduces to
232
+
233
+
```
234
+
caught_0{a_x} (label_0{} instr4* end) end
235
+
```
236
+
237
+
During the above reduction, `instr1*`, `instr2*`, and `instr3*` are never executed.
Copy file name to clipboardExpand all lines: proposals/exception-handling/Exceptions-formal-overview.md
+35-36Lines changed: 35 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,46 +39,52 @@ mod ::= module ... exn*
39
39
40
40
## Validation (Typing)
41
41
42
-
To verify that the `rethrow l` instruction refers to a surrounding catch block, we introduce a stack `caught` to validation contexts, which gets an exception index or the keyword `all` prepended whenever we enter instructions inside a `catch exnidx` or `catch_all` block, respectively. This addition is reflected in the execution rules, by the administrative instruction `caught` which models the stack of caught exceptions on the wasm stack.
43
42
43
+
To verify that a `try...delegate l` instruction refers to a label surrounding the instructions of a try block (call this a try-label), introduce a `kind` attribute to labels in the validation context, which is set to `try` when the label is a try-label.
44
44
45
-
### Instructions
45
+
Similarly, to verify that the `rethrow l` instruction refers to a label surrounding the instructions of a catch block (call this a catch-label), we allow the `kind` attribute of labels in the validation context to be set to `catch` when the label is a catch-label. This addition is reflected in the execution rules, by the administrative instruction `caught` which introduces a label around the catching try-block.
46
+
47
+
The original notation `label [t*]` is now a shortcut for `label {result [t*], kind ε}`.
0 commit comments