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

Commit a8056e5

Browse files
authored
Address additional review of #222, also fixing label types everywhere. (#241)
This addresses additional review comments to PR #222, that were made after it was merged. The last review comment in the discussion suggests to adjust all validation labels to use label types instead of just result types. Should address all occurrences of validation labels. Additionally adds a boolean catch_label to control frames in the validation algorithm, and some related functionality, fixing the cases for opcodes `catch` and `catch_all`. * Apply suggestions from code review Co-authored-by: Andreas Rossberg <[email protected]> Co-authored-by: Heejin Ahn <[email protected]> * Reverting changes to typing of CAUGHTadm. Changes to this rule are now done in PR #244
1 parent b56918d commit a8056e5

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

document/core/appendix/algorithm.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ The control stack is likewise manipulated through auxiliary functions:
122122
ctrls.pop()
123123
return frame
124124
125-
func label_types(frame : ctrl_frame) : list(val_types) =
125+
func label_types(frame : ctrl_frame) : list(val_type) =
126126
return (if frame.opcode == loop then frame.start_types else frame.end_types)
127127
128128
func unreachable() =

document/core/appendix/properties.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ To that end, all previous typing judgements :math:`C \vdash \X{prop}` are genera
661661
\frac{
662662
S; C,\CLABELS\,[t^\ast] \vdashinstrseq \instr^\ast : [] \to [t^\ast]
663663
\qquad
664-
C.\CLABELS[l] = [t_0^\ast]
664+
C.\CLABELS[l] = \LCATCH^?~[t_0^\ast]
665665
}{
666666
S; C,\CLABELS\,[t^\ast] \vdashadmininstr \DELEGATEadm\{l\}~\instr^\ast~\END : [] \to [t^\ast]
667667
}
@@ -685,7 +685,6 @@ To that end, all previous typing judgements :math:`C \vdash \X{prop}` are genera
685685

686686
* Then the compound instruction is valid under context :math:`C''` with type :math:`[] \to [t^\ast]`.
687687

688-
689688
.. math::
690689
\frac{
691690
S \vdashexternval \EVTAG~\tagaddr : \ETTAG~[t_0^\ast]\to[]
@@ -722,7 +721,7 @@ To that end, all previous typing judgements :math:`C \vdash \X{prop}` are genera
722721

723722
* The instruction sequence :math:`\instr_0^\ast` must be :ref:`valid <valid-instr-seq>` with some type :math:`[t_1^n] \to [t_2^*]`.
724723

725-
* Let :math:`C'` be the same :ref:`context <context>` as :math:`C`, but with the :ref:`result type <syntax-resulttype>` :math:`[t_1^n]` prepended to the |CLABELS| vector.
724+
* Let :math:`C'` be the same :ref:`context <context>` as :math:`C`, but with the :ref:`label type <syntax-labeltype>` :math:`[t_1^n]` prepended to the |CLABELS| vector.
726725

727726
* Under context :math:`C'`,
728727
the instruction sequence :math:`\instr^\ast` must be :ref:`valid <valid-instr-seq>` with type :math:`[] \to [t_2^*]`.

document/core/valid/instructions.rst

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ Memory Instructions
12341234
}
12351235
12361236
1237-
.. index:: control instructions, structured control, label, block, branch, block type, label index, function index, type index, tag index, vector, polymorphism, context
1237+
.. index:: control instructions, structured control, label, block, branch, block type, label index, label type, function index, type index, tag index, vector, polymorphism, context
12381238
pair: validation; instruction
12391239
single: abstract syntax; instruction
12401240
.. _valid-label:
@@ -1281,7 +1281,7 @@ Control Instructions
12811281

12821282
* The :ref:`block type <syntax-blocktype>` must be :ref:`valid <valid-blocktype>` as some :ref:`function type <syntax-functype>` :math:`[t_1^\ast] \to [t_2^\ast]`.
12831283

1284-
* Let :math:`C'` be the same :ref:`context <context>` as :math:`C`, but with the :ref:`result type <syntax-resulttype>` :math:`[t_2^\ast]` prepended to the |CLABELS| vector.
1284+
* Let :math:`C'` be the same :ref:`context <context>` as :math:`C`, but with the :ref:`label type <syntax-labeltype>` :math:`[t_2^\ast]` prepended to the |CLABELS| vector.
12851285

12861286
* Under context :math:`C'`,
12871287
the instruction sequence :math:`\instr^\ast` must be :ref:`valid <valid-instr-seq>` with type :math:`[t_1^\ast] \to [t_2^\ast]`.
@@ -1308,7 +1308,7 @@ Control Instructions
13081308

13091309
* The :ref:`block type <syntax-blocktype>` must be :ref:`valid <valid-blocktype>` as some :ref:`function type <syntax-functype>` :math:`[t_1^\ast] \to [t_2^\ast]`.
13101310

1311-
* Let :math:`C'` be the same :ref:`context <context>` as :math:`C`, but with the :ref:`result type <syntax-resulttype>` :math:`[t_1^\ast]` prepended to the |CLABELS| vector.
1311+
* Let :math:`C'` be the same :ref:`context <context>` as :math:`C`, but with the :ref:`label type <syntax-labeltype>` :math:`[t_1^\ast]` prepended to the |CLABELS| vector.
13121312

13131313
* Under context :math:`C'`,
13141314
the instruction sequence :math:`\instr^\ast` must be :ref:`valid <valid-instr-seq>` with type :math:`[t_1^\ast] \to [t_2^\ast]`.
@@ -1335,7 +1335,7 @@ Control Instructions
13351335

13361336
* The :ref:`block type <syntax-blocktype>` must be :ref:`valid <valid-blocktype>` as some :ref:`function type <syntax-functype>` :math:`[t_1^\ast] \to [t_2^\ast]`.
13371337

1338-
* Let :math:`C'` be the same :ref:`context <context>` as :math:`C`, but with the :ref:`result type <syntax-resulttype>` :math:`[t_2^\ast]` prepended to the |CLABELS| vector.
1338+
* Let :math:`C'` be the same :ref:`context <context>` as :math:`C`, but with the :ref:`label type <syntax-labeltype>` :math:`[t_2^\ast]` prepended to the |CLABELS| vector.
13391339

13401340
* Under context :math:`C'`,
13411341
the instruction sequence :math:`\instr_1^\ast` must be :ref:`valid <valid-instr-seq>` with type :math:`[t_1^\ast] \to [t_2^\ast]`.
@@ -1368,23 +1368,25 @@ Control Instructions
13681368

13691369
* The :ref:`block type <syntax-blocktype>` must be :ref:`valid <valid-blocktype>` as some :ref:`function type <syntax-functype>` :math:`[t_1^\ast] \to [t_2^\ast]`.
13701370

1371-
* Let :math:`C'` be the same :ref:`context <context>` as :math:`C`, but with the :ref:`result type <syntax-resulttype>` :math:`[t_2^\ast]` prepended to the |CLABELS| vector.
1371+
* Let :math:`C'` be the same :ref:`context <context>` as :math:`C`, but with the :ref:`label type <syntax-labeltype>` :math:`[t_2^\ast]` prepended to the |CLABELS| vector.
13721372

13731373
* Under context :math:`C'`,
13741374
the instruction sequence :math:`\instr_1^\ast` must be :ref:`valid <valid-instr-seq>` with type :math:`[t_1^\ast] \to [t_2^\ast]`.
13751375

1376-
* Let :math:`C''` be the same :ref:`context <context>` as :math:`C`, but with the :ref:`label <exec-label>` :math:`\LCATCH~[t_2^\ast]` prepended to the |CLABELS| vector.
1376+
* Let :math:`C''` be the same :ref:`context <context>` as :math:`C`, but with the :ref:`label type <syntax-labeltype>` :math:`\LCATCH~[t_2^\ast]` prepended to the |CLABELS| vector.
13771377

1378-
* For every :math:`(\CATCH~x~\instr_2^\ast)`:
1378+
* For every :math:`x_i` and :math:`\instr_{2i}^\ast` in :math:`(\CATCH~x~\instr_2^\ast)^\ast`:
13791379

1380-
* The tag :math:`C.\CTAGS[x]` must be defined in the context :math:`C`.
1380+
* The tag :math:`C.\CTAGS[x_i]` must be defined in the context :math:`C`.
13811381

1382-
* Let :math:`[t^\ast] \to []` be its :ref:`tag type <syntax-tagtype>`.
1382+
* Let :math:`[t_{3i}^\ast] \to [t_{4i}^\ast]` be the :ref:`tag type <syntax-tagtype>` :math:`C.\CTAGS[x_i]`.
1383+
1384+
* The :ref:`result type <syntax-resulttype>` :math:`[t_{4i}^\ast]` must be empty.
13831385

13841386
* Under context :math:`C''`,
1385-
the instruction sequence :math:`\instr_2^\ast` must be :ref:`valid <valid-instr-seq>` with type :math:`[t^\ast] \to [t_2^\ast]`.
1387+
the instruction sequence :math:`\instr_{2i}^\ast` must be :ref:`valid <valid-instr-seq>` with type :math:`[t_{3i}^\ast] \to [t_2^\ast]`.
13861388

1387-
* If there is a :math:`(\CATCHALL~\instr_3^\ast)`, then:
1389+
* If :math:`(\CATCHALL~\instr_3^\ast)^?` is not empty, then:
13881390

13891391
* Under context :math:`C''`,
13901392
the instruction sequence :math:`\instr_3^\ast` must be :ref:`valid <valid-instr-seq>` with type :math:`[] \to [t_2^\ast]`.
@@ -1471,9 +1473,9 @@ Control Instructions
14711473

14721474
* The label :math:`C.\CLABELS[l]` must be defined in the context.
14731475

1474-
* Let :math:`(\LCATCH^?~[t^\ast])` be the :ref:`label type <labeltype>` :math:`C.\CLABELS[l]`.
1476+
* Let :math:`(\LCATCH^?~[t^\ast])` be the :ref:`label type <syntax-labeltype>` :math:`C.\CLABELS[l]`.
14751477

1476-
* The |LCATCH| must be present in the :ref:`label type <labeltype>` :math:`C.\CLABELS[l]`.
1478+
* The |LCATCH| must be present in the :ref:`label type <syntax-labeltype>` :math:`C.\CLABELS[l]`.
14771479

14781480
* Then the instruction is valid with type :math:`[t_1^\ast] \to [t_2^\ast]`, for any sequences of :ref:`value types <syntax-valtype>` :math:`t_1^\ast` and :math:`t_2^\ast`.
14791481

@@ -1498,19 +1500,19 @@ Control Instructions
14981500

14991501
* The label :math:`C.\CLABELS[l]` must be defined in the context.
15001502

1501-
* Let :math:`[t^\ast]` be the :ref:`result type <syntax-resulttype>` :math:`C.\CLABELS[l]`.
1503+
* Let :math:`\LCATCH^?~[t^\ast]` be the :ref:`label type <syntax-labeltype>` :math:`C.\CLABELS[l]`.
15021504

15031505
* Then the instruction is valid with type :math:`[t_1^\ast~t^\ast] \to [t_2^\ast]`, for any sequences of :ref:`value types <syntax-valtype>` :math:`t_1^\ast` and :math:`t_2^\ast`.
15041506

15051507
.. math::
15061508
\frac{
1507-
C.\CLABELS[l] = [t^\ast]
1509+
C.\CLABELS[l] = \LCATCH^?~[t^\ast]
15081510
}{
15091511
C \vdashinstr \BR~l : [t_1^\ast~t^\ast] \to [t_2^\ast]
15101512
}
15111513
15121514
.. note::
1513-
The :ref:`label index <syntax-labelidx>` space in the :ref:`context <context>` :math:`C` contains the most recent label first, so that :math:`C.\CLABELS[l]` performs a relative lookup as expected.
1515+
The :ref:`label index <syntax-labelidx>` space in the :ref:`context <context>` :math:`C` contains the most recent label type first, so that :math:`C.\CLABELS[l]` performs a relative lookup as expected.
15141516

15151517
The |BR| instruction is :ref:`stack-polymorphic <polymorphism>`.
15161518

@@ -1522,19 +1524,19 @@ Control Instructions
15221524

15231525
* The label :math:`C.\CLABELS[l]` must be defined in the context.
15241526

1525-
* Let :math:`[t^\ast]` be the :ref:`result type <syntax-resulttype>` :math:`C.\CLABELS[l]`.
1527+
* Let :math:`\LCATCH^?~[t^\ast]` be the :ref:`label type <syntax-labeltype>` :math:`C.\CLABELS[l]`.
15261528

15271529
* Then the instruction is valid with type :math:`[t^\ast~\I32] \to [t^\ast]`.
15281530

15291531
.. math::
15301532
\frac{
1531-
C.\CLABELS[l] = [t^\ast]
1533+
C.\CLABELS[l] = \LCATCH^?~[t^\ast]
15321534
}{
15331535
C \vdashinstr \BRIF~l : [t^\ast~\I32] \to [t^\ast]
15341536
}
15351537
15361538
.. note::
1537-
The :ref:`label index <syntax-labelidx>` space in the :ref:`context <context>` :math:`C` contains the most recent label first, so that :math:`C.\CLABELS[l]` performs a relative lookup as expected.
1539+
The :ref:`label index <syntax-labelidx>` space in the :ref:`context <context>` :math:`C` contains the most recent label type first, so that :math:`C.\CLABELS[l]` performs a relative lookup as expected.
15381540

15391541

15401542
.. _valid-br_table:

document/core/valid/modules.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Functions :math:`\func` are classified by :ref:`function types <syntax-functype>
2929

3030
* |CLOCALS| set to the sequence of :ref:`value types <syntax-valtype>` :math:`t_1^\ast~t^\ast`, concatenating parameters and locals,
3131

32-
* |CLABELS| set to the singular sequence containing only :ref:`result type <syntax-resulttype>` :math:`[t_2^\ast]`.
32+
* |CLABELS| set to the singular sequence containing only :ref:`label type <syntax-labeltype>` :math:`[t_2^\ast]`.
3333

3434
* |CRETURN| set to the :ref:`result type <syntax-resulttype>` :math:`[t_2^\ast]`.
3535

0 commit comments

Comments
 (0)