Skip to content

Commit 7d122dd

Browse files
ioannadrossberg
andauthored
Apply suggestions from code review
Co-authored-by: Andreas Rossberg <[email protected]>
1 parent 8cfa1b6 commit 7d122dd

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ If anyone would like that I add another reduction trace, or other examples, plea
1212

1313
### notation
1414

15-
If `x` is an exception tag index, then `a_x` denotes its exception tag address, i.e., `F.exception[x] = a_x`, where `F` is the current frame.
15+
If `x` is an exception tag index, then `a_x` denotes its exception tag address, i.e., `F.tag[x] = a_x`, where `F` is the current frame.
1616

1717
## example 0
1818

@@ -189,4 +189,3 @@ The thrown exception is (eventually) caught by the outer try's `catch x`, so the
189189
```
190190
label_0 {} (caught_0{a_x} (label_0 {} instr* end) end
191191
```
192-

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

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ instr ::= ... | throw x | rethrow l
2525
Tags
2626

2727
```
28-
tag ::= export* tag exntype | export* tag tagtype import
28+
tag ::= export* tag tagtype | export* tag tagtype import
2929
```
3030

3131
Modules
@@ -41,7 +41,9 @@ mod ::= module ... tag*
4141
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.
4242

4343
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.
44-
44+
labelkind ::= try | catch
45+
labeltype ::= {result resulttype, kind labelkind?}
46+
C ::= {..., labels labeltype}
4547
The original notation `labels [t*]` is now an abbreviation for:
4648

4749
```
@@ -86,7 +88,7 @@ C ⊢ try bt instr* delegate l : [t1*]→[t2*]
8688
Stores
8789

8890
```
89-
S ::= {..., tags exninst*}
91+
S ::= {..., tags taginst*}
9092
```
9193

9294
Tag Instances
@@ -113,11 +115,9 @@ Block contexts and label kinds
113115
So far block contexts are only used in the reduction of `br l` and `return`, and only include labels or values on the stack above the hole. If we want to be able to break jumping over try-catch and try-delegate blocks, we must allow for the new administrative control instructions to appear after labels in block contexts, mirroring the label kinds of labels in validation contexts.
114116

115117
```
116-
label_kind ::= try_label_kind | catch_label_kind
117-
try_label_kind ::= catch_m{a? instr*}* | delegate{l}
118-
catch_label_kind ::= caught_m{a val*}
119-
B^0 ::= val* [_] instr*
120-
B^{k+1} ::= val* label_n{instr*} label_kind? B^k end? end instr*
118+
B^k ::= val* B'^k instr*
119+
B'^0 ::= [_]
120+
B'^{k+1} ::= label_n{instr*} B^k end | catch_m{a? instr*}* B^{k+1} end | caught_m{a val*} B^{k+1} end | delegate{l} B^{k+1} end
121121
```
122122

123123
Note that `label_n{instr*} label_kind? [_] end? end` could be seen as a simplified control frame.
@@ -135,20 +135,20 @@ T ::= val* [_] instr* | label_n{instr*} T end | caught_m{a val^n} T end
135135

136136

137137
```
138-
F; throw x ↪ F; throw a (if F.module.exnaddrs[x]=a)
138+
F; throw x ↪ F; throw a (if F.module.tagaddrs[x]=a)
139139
140140
caught_m{a val^n} B^l[rethrow l] end
141141
↪ caught_m{a val^n} B^l[val^n (throw a)] end
142142
143143
caught_m{a val^n} val^m end ↪ val^m
144144
```
145145

146-
A missing tagaddr in a `catch_m` clause (i.e., `a? = ε`) represents a `catch_all`.
146+
An absent tagaddr in a `catch_m` clause (i.e., `a? = ε`) represents a `catch_all`.
147147

148148
```
149149
F; val^n (try bt instr* (catch x instr'*)* (catch_all instr''*)? end)
150150
↪ F; label_m{} (catch_m{a instr'*}*{instr''*}? val^n instr* end) end
151-
(if bt = [t1^n]→[t2^m] ∧ (val:t1)^n ∧ (F.module.exnaddrs[x]=a)*)
151+
(if bt = [t1^n]→[t2^m] ∧ (F.module.tagaddrs[x]=a)*)
152152
153153
catch_m{a? instr*}* val^m end ↪ val^m
154154
@@ -177,16 +177,15 @@ B^l[ delegate{l} T[val^n (throw a)] end ]
177177
### Typing rules for administrative instructions
178178

179179
```
180-
S.tags[a].type = [t2*]→[]
180+
S.tags[a].type = [t*]→[]
181181
--------------------------------
182-
S;C ⊢ throw a : [t1* t2*]→[t*]
182+
S;C ⊢ throw a : [t1* t*]→[t2*]
183183
184-
(S.tags[a].type = [t'*]→[] ∧
185-
S;C, labels {result [t*], kind catch} ⊢ instr1* : [t'*]→[t*])*
186-
(S;C, labels {result [t*], kind catch} ⊢ instr2* : []→[t*])?
187-
S;C, labels {result [t*], kind try} ⊢ instr3* : []→[t*]
184+
((S.tags[a].type = [t'*]→[])?
185+
S;C, labels {result [t*], kind catch} ⊢ instr'* : [t'*?]→[t*])*
186+
S;C, labels {result [t*], kind try} ⊢ instr* : []→[t*]
188187
-----------------------------------------------------------------------
189-
S;C, labels [t*] ⊢ catch_n{a instr1*}*{instr2*}? instr3* end : []→[t*]
188+
S;C, labels [t*] ⊢ catch_n{a? instr'*}* instr* end : []→[t*]
190189
191190
S;C, labels {result [t*], kind try} ⊢ instr* : []→[t*]
192191
C.labels[l].kind = try
@@ -197,7 +196,7 @@ S.tags[a].type = [t'*]→[]
197196
(val:t')*
198197
S;C, labels {result [t*], kind catch} ⊢ instr* : []→[t*]
199198
--------------------------------------------------------------------------------
200-
S;C, labels {result [t*], kind catch} ⊢ caught_m{a val^n} instr* end : []→[t'*]
199+
S;C, labels [t*] ⊢ caught_m{a val^n} instr* end : []→[t'*]
201200
```
202201

203202
By adding the attribute `kind` to labels, we are creating situations in the proof of type preservation, where we have a derivation of some `S;C, label [t*] ⊢ instr* : []→[t*]` but we need to have that `S;C, label {result [t*], kind <labelkind>} ⊢ instr* : []→[t*]` for some `<labelkind> ::= try | catch`. To resolve this we add the following typing rule for labels in the context, which ensures our newly introduced `try` and `catch` blocks can contain any instructions a regular block can.
@@ -208,4 +207,3 @@ labelkind = try ∨ labelkind = catch
208207
-----------------------------------------------------------
209208
S;C, label {result [t*], kind labelkind} ⊢ instr* : []→[t*]
210209
```
211-

0 commit comments

Comments
 (0)