Skip to content

Commit 6032f22

Browse files
committed
Implemented latest review comments and updated.
In particular: - The labels surrounding try-catch and try-delegate now get a standard label in the first step, which is then refined to catch-labels and/or try-labels per subblock. + For that I allowed the new administrative instructions to appear nested directly inside a label_n{} in block contexts. + Also added a validation rule to the administrative label_n{}. + Due to this, all block contexts appear now without a successor exponent. - Updated to latest try-catch syntax described in issue WebAssembly#157. - Corrected some previously wrong syntax. - Removed try-unwind (...) as per issue WebAssembly#156 - Updated Exceptions-formal-examples.md similarly.
1 parent 2f41468 commit 6032f22

File tree

2 files changed

+129
-180
lines changed

2 files changed

+129
-180
lines changed

proposals/exception-handling/Exceptions-formal-examples.md

Lines changed: 62 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,22 @@ If anyone would like that I add another reduction trace, or other examples, plea
1212

1313
### notation
1414

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.
15+
If `x` is an exception index, then `a_x` denotes its exception tag, i.e., `F.exception[x] = a_x`, where `F` is the current frame.
1616

1717
## example 0
1818

19-
The only example with an almost full reduction trace, and all new instructions (`rethrow` and `catch_all` are hidden in `unwind`'s reduct). The first 3 steps, reducing the several `try`s to their respective administrative instructions, are not shown.
19+
The only example with an almost full reduction trace, and all new instructions. The first 3 steps, reducing the several `try`s to their respective administrative instructions, are not shown.
2020

2121
```
2222
(func (result i32) (local i32)
2323
try
2424
try
2525
try
2626
throw x
27-
unwind
27+
catch_all
2828
i32.const 27
2929
local.set 0
30+
rethrow 0
3031
end
3132
delegate 0
3233
catch x
@@ -37,48 +38,59 @@ The only example with an almost full reduction trace, and all new instructions (
3738
Take the frame `F = (locals i32.const 0, module m)`. We have:
3839

3940
```
40-
↪ ↪ ↪ F; catch_1{a_x local.get 0} (label_1{}
41-
(delegate{0} (label_0{}
42-
(catch_0{i32.const 27 local.set 0 rethrow 0} (label_0{} ;; the try-unwind
41+
↪ ↪ ↪ F; label_1{} (catch_1{a_x local.get 0}
42+
(label_0{} (delegate{0}
43+
(label_0{} (catch_0{i32.const 27 local.set 0 rethrow 0}
4344
throw a_x end) end) end) end) end) end
44-
4545
```
4646

47-
For the throw context `T = label_0{}[_]end` the above is the same as
47+
For the empty throw context `T = [_]` the above is the same as
4848

4949
```
50-
F; catch_1{a_x local.get 0} (label_1{}
51-
(delegate{0} (label_0{}
52-
(catch_0{i32.const 27 local.set 0 rethrow 0}
50+
F; label_1{} (catch_1{a_x local.get 0}
51+
label_0{} (delegate{0}
52+
label_0{} (catch_0{i32.const 27 local.set 0 rethrow 0}
5353
T[throw a_x] end) end) end) end) end
5454
55-
↪ F; catch_1{a_x local.get 0} (label_1{}
56-
(delegate{0} (label_0{}
57-
(caught{a_x} (label_0{} i32.const 27 local.set 0 rethrow 0
55+
↪ F; label_1{} (catch_1{a_x local.get 0}
56+
(label_0{} (delegate{0}
57+
(label_0{} (caught{a_x} i32.const 27 local.set 0 rethrow 0
5858
end) end) end) end) end) end
5959
```
6060

61-
Let `F'` be the frame `{locals i32.const 27, module m}`, and let `B^1 = label_0{} [_] end`.
61+
Let `F'` be the frame `{locals i32.const 27, module m}`, and let `B^0 = [_]`.
6262

6363
```
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
64+
↪ F; label_1{} (catch_1{a_x local.get 0}
65+
(label_0{} (delegate{0}
66+
(label_0{} (caught{a_x} B^0 [rethrow 0]
67+
end) end) end) end) end) end
6768
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
69+
↪ F; label_1{} (catch_1{a_x local.get 0}
70+
(label_0{} (delegate{0}
71+
(label_0{} (caught{a_x} B^0 [throw a_x]
72+
end) end) end) end) end) end
7173
```
7274

73-
Let `T' = label_0{} (caught{a_x} B^1 [_] end) end`.
75+
Let `T' = label_0{} (caught{a_x} B^0 [_] end) end`.
7476

7577
```
76-
↪ F'; catch_1{a_x local.get 0} (label_1{}
77-
(delegate{0} T'[throw a_x] end) end) end
78+
↪ F; label_1{} (catch_1{a_x local.get 0}
79+
(label_0{} (delegate{0}
80+
T'[throw a_x] end) end) end) end
7881
79-
↪ F'; catch_1{a_x local.get 0} (label_1{} throw a_x end) end
82+
↪ F; label_1{} (catch_1{a_x local.get 0}
83+
(label_0{} (delegate{0}
84+
T'[throw a_x] end) end) end) end
8085
81-
↪ F'; caught_1{a_x} (label_1{} local.get 0 end) end
86+
↪ F; label_1{} (catch_1{a_x local.get 0}
87+
(label_0{} (delegate{0}
88+
T'[throw a_x] end) end) end) end
89+
90+
↪ F; label_1{} (catch_1{a_x local.get 0}
91+
T'[throw a_x] end) end
92+
93+
↪ F; label_1{} (caught_1{a_x} local.get 0 end) end
8294
8395
↪ ↪ ↪ i32.const 27
8496
```
@@ -87,32 +99,38 @@ Let `T' = label_0{} (caught{a_x} B^1 [_] end) end`.
8799

88100
### example 1
89101

90-
Interaction of `rethrow` with `unwind`. Taken from [this comment](https://github.com/WebAssembly/exception-handling/issues/87#issuecomment-705586912) by @rossberg.
102+
Location of a rethrown exception.
91103

92104
```
93105
try
106+
val1
94107
throw x
95108
catch x
96109
try
97-
instr1*
98-
rethrow 0
99-
unwind
100-
instr2*
110+
val2
111+
throw y
112+
catch_all
113+
try
114+
val3
115+
throw z
116+
catch z
117+
rethrow 2
118+
end
101119
end
102120
end
103121
```
104122

105-
Assuming `instr1*` and `instr2*` don't throw another exception, this example reduces to
123+
In the above example, all thrown exceptions get caught and the first one gets rethrown from the catching block of the last one. So the above reduces to
106124

107125
```
108-
caught_0{a_x} (label_0 {}
109-
(caught_0{a_x} (label_0 {}
110-
instr2* throw a_x end) end) end) end
126+
label_0{} caught{a_x val1}
127+
val1 (label_0{} caught{a_y val2}
128+
(label_0{} caught{a_z val3}
129+
val3 val1 (throw a_x) end end)
130+
end end) end end)
111131
```
112132

113-
which in turn reduces to `throw a_x`.
114-
115-
Note that any global state changes due to `instr1*` or `instr2*` will take place.
133+
which in this case is the same as `val1 (throw a_x)`.
116134

117135
### example 2
118136

@@ -137,7 +155,7 @@ This is a validation error (no catch block at given rethrow depth).
137155

138156
### example 3
139157

140-
`delegate` targetting a catch is a validation error.
158+
`delegate` targeting a catch is a validation error.
141159

142160
```
143161
try $label0
@@ -152,93 +170,23 @@ This is a validation error because `delegate`'s `$label0` refers to the catch-la
152170

153171
### example 4
154172

155-
`delegate` correctly targetting a `try-delegate` and a `try-catch`.
173+
`delegate` correctly targeting a `try-delegate` and a `try-catch`.
156174

157175
```
158176
try $label1
159177
try $label0
160178
try
161179
throw x
162-
delegate $label0
163-
delegate $label1
180+
delegate $label0 ;; delegate 0
181+
delegate $label1 ;; delegate 1
164182
catch x
165183
instr*
166184
end
167185
```
168186

169-
The thrown exception is (eventually) caught by the outer try's `catch x`, so the above reduces to
187+
The thrown exception is (eventually) caught by the outer try's `catch x`, so the above reduces to the following.
170188

171189
```
172-
caught_0{a_x} (label_0 {} instr* end) end
173-
```
174-
175-
176-
## interaction of `delegate` and `unwind`
177-
178-
Two examples from issue #130.
179-
180-
### example 5
181-
182-
The [opening example](https://github.com/WebAssembly/exception-handling/issues/130#issue-713113953)
183-
of issue #130.
184-
185-
```
186-
i32.const 11
187-
global.set 0
188-
try $l
189-
try
190-
try
191-
throw x
192-
delegate 1
193-
unwind
194-
i32.const 27
195-
global.set 0
196-
end
197-
catch_all
198-
end
199-
global.get 0
190+
label_0 {} (caught_0{a_x} (label_0 {} instr* end) end
200191
```
201192

202-
Here, `delegate 1` targets the label `$l` (so it would be the same if we wrote `delegate $l` instead).
203-
204-
This example returns `11`, because `delegate` skips everything up to and not including `try $l`.
205-
206-
### example 6
207-
208-
This example
209-
[appears to keep](https://github.com/WebAssembly/exception-handling/issues/130#issuecomment-704249682)
210-
the issue #130 open.
211-
212-
@RossTate expressed concerns with respect to an example possibly equivalent to
213-
the one below. "Possibly", because the original example in the comment refers to
214-
an `unwinding` branch, first presented in issue #124, so I attempted to rewrite
215-
the example to match the current syntax as best I could.
216-
217-
```
218-
try $t
219-
try $l
220-
try $u
221-
try
222-
throw x
223-
delegate $t
224-
unwind
225-
instr1*
226-
end
227-
catch x
228-
instr2*
229-
end
230-
instr3*
231-
catch_all
232-
instr4*
233-
end
234-
```
235-
236-
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
237-
238-
```
239-
caught_0{a_x} (label_0{} instr4* end) end
240-
```
241-
242-
During the above reduction, `instr1*`, `instr2*`, and `instr3*` are never executed.
243-
244-

0 commit comments

Comments
 (0)