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

Commit 15dd632

Browse files
authored
Formal overview minor fixes (#208)
* Addressed the minor review comments. * Minor corrections, notation readability, "control" prose in block contexts. - Switching to "S ⊢ ..." notation for premises of typing rules for administrative instructions, to match the spec document. - Readability: Changing quotes to number indices, and removing unnecessary explicit exponent variables. - Suggesting prose for the new constructs in block contexts, connoting the new structured administrative instructions with control frame opcodes.
1 parent 3fb5bf4 commit 15dd632

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

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

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,13 @@ mod ::= 'module' ... tag*
3636

3737
## Validation (Typing)
3838

39-
#### Modification to Labels
39+
### Validation Contexts: Tagtypes and modified Labels
4040

4141
To verify that the `rethrow l` instruction refers to a label surrounding the instructions of a catch block (call this a catch-label), we introduce a `kind` attribute to labels in the validation context, which is set to `catch` when the label is a catch-label and empty otherwise.
4242

4343
```
4444
labelkind ::= 'catch'
4545
labeltype ::= 'catch'? resulttype
46-
C ::= {..., 'labels' labeltype}
4746
```
4847

4948
The original notation `labels [t*]` is now an abbreviation for:
@@ -52,11 +51,11 @@ The original notation `labels [t*]` is now an abbreviation for:
5251
'labels' [t*] ::= 'labels' ε [t*]
5352
```
5453

55-
### Validation Contexts
54+
The `labels` entry of validation contexts is modified to use the above definition of labels.
55+
Moreover, validation contexts now hold a list of tag types, one for each tag known to them.
5656

57-
Validation contexts now hold a list of tag types, one for each tag known to them.
5857
```
59-
C ::= { ..., 'tags' tagtype*}
58+
C ::= { ..., 'labels' labeltype, 'tags' tagtype*}
6059
```
6160

6261
### Validation Rules for Instructions
@@ -74,12 +73,12 @@ C ⊢ rethrow l : [t1*]→[t2*]
7473
7574
7675
C ⊢ bt : [t1*]→[t2*]
77-
C, labels [t2*] ⊢ instr* : [t1*]→[t2*]
76+
C, labels [t2*] ⊢ instr1* : [t1*]→[t2*]
7877
(C.tags[x] = [t*]→[] ∧
79-
C, labels catch [t2*] ⊢ instr'* : [t*]→[t2*])*
80-
(C, labels catch [t2*] ⊢ instr''* : []→[t2*])?
78+
C, labels (catch [t2*])instr2* : [t*]→[t2*])*
79+
(C, labels (catch [t2*])instr3* : []→[t2*])?
8180
-----------------------------------------------------------------------------
82-
C ⊢ try bt instr* (catch x instr'*)* (catch_all instr''*)? end : [t1*]→[t2*]
81+
C ⊢ try bt instr1* (catch x instr2*)* (catch_all instr3*)? end : [t1*]→[t2*]
8382
8483
8584
C ⊢ bt : [t1*]→[t2*]
@@ -130,6 +129,8 @@ C^k ::= 'catch'{ tagaddr? instr* }* B^k 'end'
130129
| 'delegate'{ labelidx } B^k 'end'
131130
```
132131

132+
Note the `C` in `C^k` above stands for `control`, because the related administrative instructions are in some ways modeling [control frame opcodes](https://webassembly.github.io/spec/core/appendix/algorithm.html?highlight=control#data-structures) "on the stack".
133+
133134
#### Throw Contexts
134135

135136
Throw contexts don't skip over handlers (administrative `catch` or `delegate` instructions).
@@ -152,34 +153,35 @@ An absent tag address in a `catch` administrative instruction (i.e., `a? = ε`)
152153
```
153154
F; throw x ↪ F; throw a (if F.module.tagaddrs[x]=a)
154155
155-
caught{a val^n} B^l[rethrow l] end
156-
↪ caught{a val^n} B^l[val^n (throw a)] end
156+
caught{a val*} B^l[rethrow l] end
157+
↪ caught{a val*} B^l[val* (throw a)] end
157158
158-
caught{a val^n} val^m end ↪ val^m
159+
caught{a val0*} val* end ↪ val*
159160
160161
161-
F; val^n (try bt instr* (catch x instr'*)* (catch_all instr''*)? end)
162-
↪ F; label_m{} (catch{a instr'*}*{ε instr''*}? val^n instr* end) end
162+
F; val^n (try bt instr1* (catch x instr2*)* (catch_all instr3*)? end)
163+
↪ F; label_m{} (catch{a instr2*}*{ε instr3*}? val^n instr1* end) end
163164
(if expand_F(bt) = [t1^n]→[t2^m] ∧ (F.module.tagaddrs[x]=a)*)
164165
165-
catch{a? instr*}* val^m end ↪ val^m
166+
catch{a? instr*}* val* end ↪ val*
166167
167-
S; F; catch{a1? instr*}{a'? instr'*}* T[val^n (throw a)] end
168-
↪ S; F; caught{a val^n} (val^n)? instr* end
168+
S; F; catch{a1? instr1*}{a0? instr0*}* T[val^n (throw a)] end
169+
↪ S; F; caught{a val^n} (val^n)? instr1* end
169170
(if (a1? = ε ∨ a1? = a) ∧ S.tags(a).type = [t^n]→[])
170171
171-
catch{a1? instr*}{a'? instr'*}* T[val^n (throw a)] end
172-
↪ catch{a'? instr'*}* T[val^n (throw a)] end
172+
catch{a1? instr*}{a0? instr0*}* T[val^n (throw a)] end
173+
↪ catch{a0? instr0*}* T[val^n (throw a)] end
173174
(if a1? ≠ ε ∧ a1? ≠ a)
174175
175176
catch T[val^n (throw a)] end ↪ val^n (throw a)
177+
(if S.tags(a).type = [t^n]→[])
176178
177179
178180
F; val^n (try bt instr* delegate l)
179181
↪ F; label_m{} (delegate{l} val^n instr* end) end
180-
(if expand_F(bt) = [t^n]→[t^m])
182+
(if expand_F(bt) = [t1^n]→[t2^m])
181183
182-
delegate{l} val^n end ↪ val^n
184+
delegate{l} val* end ↪ val*
183185
184186
label_m{} B^l[ delegate{l} T[val^n (throw a)] end ] end
185187
↪ val^n (throw a)
@@ -194,25 +196,26 @@ There is a subtle difference though. The instruction `br l` searches for the `l+
194196

195197
### Typing Rules for Administrative Instructions
196198

199+
197200
```
198-
S.tags[a].type = [t*]→[]
199-
--------------------------------
201+
S ⊢ tag a : tag [t*]→[]
202+
-------------------------------
200203
S;C ⊢ throw a : [t1* t*]→[t2*]
201204
202-
((S.tags[a].type = [t'*]→[])?
203-
S;C, labels catch [t*]instr'* : [t'*?]→[t*])*
204-
S;C, labels [t*] ⊢ instr* : []→[t*]
205+
((S ⊢ tag a : tag [t1*]→[])?
206+
S;C, labels (catch [t2*])instr2* : [t1*?]→[t2*])*
207+
S;C, labels [t2*] ⊢ instr1* : []→[t2*]
205208
-----------------------------------------------------------
206-
S;C, labels [t*] ⊢ catch{a? instr'*}* instr* end : []→[t*]
209+
S;C, labels [t2*] ⊢ catch{a? instr2*}* instr1* end : []→[t2*]
207210
208211
S;C, labels [t*] ⊢ instr* : []→[t*]
209-
C.labels[l] = [t'*]
212+
C.labels[l] = [t0*]
210213
------------------------------------------------------
211214
S;C, labels [t*] ⊢ delegate{l} instr* end : []→[t*]
212215
213-
S.tags[a].type = [t'*]→[]
214-
(val:t')*
215-
S;C, labels catch [t*] ⊢ instr* : []→[t*]
216+
S ⊢ tag a : tag [t0*]→[]
217+
(val:t0)*
218+
S;C, labels (catch [t*]) ⊢ instr* : []→[t*]
216219
----------------------------------------------------------
217220
S;C, labels [t*] ⊢ caught{a val^n} instr* end : []→[t*]
218221
```

0 commit comments

Comments
 (0)