Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 55480a9

Browse files
committed
Small fixes on formal spec overview/examples
- Removes a link next to `[1]`. The link is also in the footnote so it's not strictly necessary, and adding a link right next to `[1]` makes `[]` disappear, so it appears as just `1`, which isn't probably what the author intended. - Both of `throw/catch x` and `throw/catch $x` are being used. Unified them into `throw/catch $x`. - Fixes a location of `$label2` in a test. - Removes `_m` from `catch` and `caught` administrative instructions in Exceptions-formal-examples.md. They were only removed in the overview.
1 parent 3dc715a commit 55480a9

File tree

2 files changed

+50
-50
lines changed

2 files changed

+50
-50
lines changed

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

+49-49
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Note that the block contexts and throw contexts given for the reductions are the
2020

2121
The only example with an almost full reduction trace, and all new instructions. Such explicit reduction steps are only shown in Example 4 and Example 5, to highlight the reduction step of the administrative `delegate`.
2222

23-
In the following reduction, we don't show the first 4 steps, which just reduce the several `try`s and the `throw x` to their respective administrative instructions. The type of the tag `$x` here is `[]→[]`.
23+
In the following reduction, we don't show the first 4 steps, which just reduce the several `try`s and the `throw $x` to their respective administrative instructions. The type of the tag `$x` here is `[]→[]`.
2424

2525
```
2626
(tag $x)
@@ -63,31 +63,31 @@ Take the frame `F = (locals i32.const 0, module m)`. We have:
6363
```
6464
↪ ↪ ↪
6565
↪ F; (label_1{}
66-
(catch_1{ a_x (local.get 0) }
66+
(catch{ a_x (local.get 0) }
6767
(label_0{}
6868
(delegate{ 0 }
6969
(label_0{}
70-
(catch_0{ ε (local.set 0 (i32.const 27)) (rethrow 0) }
70+
(catch{ ε (local.set 0 (i32.const 27)) (rethrow 0) }
7171
(throw a_x) end) end) end) end) end) end)
7272
```
7373

7474
For the trivial throw context `T = [_]` the above is the same as
7575

7676
```
7777
↪ F; (label_1{}
78-
(catch_1{ a_x (local.get 0) }
78+
(catch{ a_x (local.get 0) }
7979
(label_0{}
8080
(delegate{ 0 }
8181
(label_0{}
82-
(catch_0{ ε (local.set 0 (i32.const 27)) (rethrow 0) }
82+
(catch{ ε (local.set 0 (i32.const 27)) (rethrow 0) }
8383
T[(throw a_x)]) end) end) end) end) end)
8484
8585
↪ F; (label_1{}
86-
(catch_1{ a_x (local.get 0) }
86+
(catch{ a_x (local.get 0) }
8787
(label_0{}
8888
(delegate{ 0 }
8989
(label_0{}
90-
(caught_0{ a_x ε }
90+
(caught{ a_x ε }
9191
(local.set 0 (i32.const 27))
9292
(rethrow 0) end) end) end) end) end) end)
9393
```
@@ -96,48 +96,48 @@ Let `F'` be the frame `{locals i32.const 27, module m}`, and let `B^0 = [_]` to
9696

9797
```
9898
↪ F'; (label_1{}
99-
(catch_1{ a_x (local.get 0) }
99+
(catch{ a_x (local.get 0) }
100100
(label_0{}
101101
(delegate{ 0 }
102102
(label_0{}
103-
(caught_0{ a_x ε }
103+
(caught{ a_x ε }
104104
B^0[ (rethrow 0) ] end) end) end) end) end) end)
105105
106106
↪ F'; (label_1{}
107-
(catch_1{ a_x (local.get 0) }
107+
(catch{ a_x (local.get 0) }
108108
(label_0{}
109109
(delegate{ 0 }
110110
(label_0{}
111-
(caught_0{ a_x ε }
111+
(caught{ a_x ε }
112112
(throw a_x) end) end) end) end) end) end)
113113
```
114114

115-
Let `T' = (label_0{} (caught_0{ a_x ε } [_] end) end)` and use the same `B^0` as above to reduce the throw with the delegate.
115+
Let `T' = (label_0{} (caught{ a_x ε } [_] end) end)` and use the same `B^0` as above to reduce the throw with the delegate.
116116

117117
```
118118
↪ F'; (label_1{}
119-
(catch_1{ a_x (local.get 0) }
119+
(catch{ a_x (local.get 0) }
120120
(label_0{}
121121
B^0[ (delegate{ 0 } T'[ (throw a_x) ] end) ] end) end) end)
122122
123123
↪ F'; (label_1{}
124-
(catch_1{ a_x (local.get 0) }
124+
(catch{ a_x (local.get 0) }
125125
(throw a_x) end) end)
126126
```
127127

128-
Use the trivial throw context `T` again, this time to match the throw to the `catch_1`.
128+
Use the trivial throw context `T` again, this time to match the throw to the `catch`.
129129

130130
```
131131
↪ F'; (label_1{}
132-
(catch_1{ a_x (local.get 0) }
132+
(catch{ a_x (local.get 0) }
133133
T[ (throw a_x) ] end) end)
134134
135135
↪ F'; (label_1{}
136-
(caught_1{ a_x ε }
136+
(caught{ a_x ε }
137137
(local.get 0) end) end)
138138
139139
↪ F'; (label_1{}
140-
(caught_1{ a_x ε }
140+
(caught{ a_x ε }
141141
(i32.const 27) end) end)
142142
143143
↪ F'; (label_1{}
@@ -153,11 +153,11 @@ Use the trivial throw context `T` again, this time to match the throw to the `ca
153153
Location of a rethrown exception. Let `x, y, z` be tag indices of tags with type `[t_x]→[]`, `[t_y]→[]`, and `[t_z]→[]` respectively. Let `val_p : t_p` for every `p` among `x, y, z`.
154154

155155
```
156-
try
156+
try $label2
157157
val_x
158-
throw x
159-
catch x
160-
try $label2
158+
throw $x
159+
catch $x
160+
try
161161
val_y
162162
throw y
163163
catch_all
@@ -177,8 +177,8 @@ Folded it looks as follows.
177177
(try
178178
(do
179179
val_x
180-
(throw x))
181-
(catch x ;; <--- (rethrow 2) targets this catch.
180+
(throw $x))
181+
(catch $x ;; <--- (rethrow 2) targets this catch.
182182
(try
183183
(do
184184
val_y
@@ -196,13 +196,13 @@ In the above example, all thrown exceptions get caught and the first one gets re
196196

197197
```
198198
(label_0{}
199-
(caught_0{ a_x val_x } ;; <---- The exception rethrown by `rethrow 2` below.
199+
(caught{ a_x val_x } ;; <---- The exception rethrown by `rethrow 2` below.
200200
val_x
201201
(label_0{}
202-
(caught_0{ a_y val_y }
202+
(caught{ a_y val_y }
203203
;; The catch_all does not leave val_y here.
204204
(label_0{}
205-
(caught_0{ a_z val_z }
205+
(caught{ a_z val_z }
206206
val_z
207207
;; (rethrow 2) puts val_x and the throw below.
208208
val_x
@@ -222,7 +222,7 @@ This reduces to `val_x (throw a_x)`, throwing to the caller.
222222
(func
223223
try $label0
224224
rethrow $label0 ;; cannot be done, because it's not within catch below
225-
catch x
225+
catch $x
226226
end)
227227
```
228228

@@ -237,7 +237,7 @@ This is a validation error (no catch block at given rethrow depth).
237237
```
238238
(try $l
239239
(do
240-
(throw x))
240+
(throw $x))
241241
(delegate $l))
242242
```
243243

@@ -252,23 +252,23 @@ try $label1
252252
try
253253
try $label0
254254
try
255-
throw x
255+
throw $x
256256
delegate $label0 ;; delegate 0
257257
delegate $label1 ;; delegate 1
258258
catch_all
259259
end
260-
catch x
260+
catch $x
261261
instr*
262262
end
263263
```
264264

265-
In folded form and reduced to the point `throw x` is called, this is:
265+
In folded form and reduced to the point `throw $x` is called, this is:
266266

267267
```
268268
(label_0{}
269-
(catch_0{ a_x instr* }
269+
(catch{ a_x instr* }
270270
(label_0{}
271-
(catch_0{ ε ε }
271+
(catch{ ε ε }
272272
(label_0{}
273273
(delegate{ 1 }
274274
(label_0{}
@@ -280,26 +280,26 @@ The `delegate{ 0 }` reduces using the trivial throw and block contexts to:
280280

281281
```
282282
(label_0{}
283-
(catch_0{ a_x instr* }
283+
(catch{ a_x instr* }
284284
(label_0{}
285-
(catch_0{ ε ε }
285+
(catch{ ε ε }
286286
(label_0{}
287287
(delegate{ 1 }
288288
(throw a_x) end) end) end) end) end) end)
289289
```
290290

291-
The `delegate{ 1 }` reduces using the trivial throw context and the block context `B^1 := (catch_0{ ε ε } (label_0{} [_] end) end)` to the following:
291+
The `delegate{ 1 }` reduces using the trivial throw context and the block context `B^1 := (catch{ ε ε } (label_0{} [_] end) end)` to the following:
292292

293293
```
294294
(label_0{}
295-
(catch_0{ a_x instr* }
295+
(catch{ a_x instr* }
296296
(throw a_x) end) end)
297297
```
298-
The thrown exception is (eventually) caught by the outer try's `catch x`, so the above reduces to the following.
298+
The thrown exception is (eventually) caught by the outer try's `catch $x`, so the above reduces to the following.
299299

300300
```
301301
(label_0 {}
302-
(caught_0{a_x}
302+
(caught{a_x}
303303
instr* end) end)
304304
```
305305

@@ -310,7 +310,7 @@ The thrown exception is (eventually) caught by the outer try's `catch x`, so the
310310
```
311311
try (result i32)
312312
try $label0
313-
throw x
313+
throw $x
314314
catch_all
315315
try
316316
throw y
@@ -328,7 +328,7 @@ In folded form this is:
328328
(do
329329
(try
330330
(do
331-
(throw x))
331+
(throw $x))
332332
(catch_all
333333
(try
334334
(do
@@ -342,9 +342,9 @@ When it's time to reduce `(throw y)`, the reduction looks as follows.
342342

343343
```
344344
(label_1{}
345-
(catch_1{ ε (i32.const 4) }
345+
(catch{ ε (i32.const 4) }
346346
(label_0{}
347-
(caught_0{ a_x ε }
347+
(caught{ a_x ε }
348348
(label_0{}
349349
(delegate{ 0 }
350350
(throw a_y) end) end) end) end) end) end)
@@ -354,17 +354,17 @@ For `B^0 := [_] := T`, the above is the same as the following.
354354

355355
```
356356
(label_1{}
357-
(catch_1{ ε (i32.const 4) }
357+
(catch{ ε (i32.const 4) }
358358
(label_0{}
359-
(caught_0{ a_x ε }
359+
(caught{ a_x ε }
360360
(label_0{}
361361
B^0 [(delegate{ 0 } T[ (throw a_y) ] end)] end) end) end) end) end)
362362
363363
↪ (label_1{}
364-
(catch_1{ ε (i32.const 4) }
364+
(catch{ ε (i32.const 4) }
365365
(label_0{}
366-
(caught_0{ a_x ε }
366+
(caught{ a_x ε }
367367
(throw a_y) end) end) end) end)
368368
```
369369

370-
So `throw a_y` gets correctly caught by `catch_1{ ε (i32.const 4) }` and this example reduces to `(i32.const 4)`.
370+
So `throw a_y` gets correctly caught by `catch{ ε (i32.const 4) }` and this example reduces to `(i32.const 4)`.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ label_m{} B^l[ delegate{l} T[val^n (throw a)] end ] end
185185
↪ val^n (throw a)
186186
```
187187

188-
Note that the last reduction step above is similar to the reduction of `br l` [1](https://webassembly.github.io/spec/core/exec/instructions.html#xref-syntax-instructions-syntax-instr-control-mathsf-br-l), if we look at the entire `delegate{l}...end` as the `br l`, but also doing a throw after it breaks.
188+
Note that the last reduction step above is similar to the reduction of `br l` [1], if we look at the entire `delegate{l}...end` as the `br l`, but also doing a throw after it breaks.
189189

190190
There is a subtle difference though. The instruction `br l` searches for the `l+1`th surrounding block and breaks out after that block. Because `delegate{l}` is always wrapped in its own `label_n{} ... end` [2], with the same lookup as for `br l` we end up breaking inside the `l+1`th surrounding block, and throwing there. So if that `l+1`th surrounding block is a try, we end up throwing in its "try code", and thus correctly getting delegated to that try's catches.
191191

0 commit comments

Comments
 (0)