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

Commit 06cd5bb

Browse files
committed
Add (sub open ...) and make it mandatory
Instead of using final? in the syntax, use ext ::= open | final. Implements the design discussed in #413. Update the interpreter, the abstract syntax, the binary and text formats, and MVP.md.
1 parent 5a85356 commit 06cd5bb

File tree

23 files changed

+320
-307
lines changed

23 files changed

+320
-307
lines changed

document/core/appendix/algorithm.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ Similarly, :ref:`defined types <syntax-deftype>` :code:`def_type` can be represe
5757
type array_type = Array(fields : field_type)
5858
type func_type = Func(params : list(val_type), results : list(val_type))
5959
type comp_type = struct_type | array_type | func_type
60+
type ext_type = Open | Final
6061
61-
type sub_type = Sub(super : list(def_type), body : comp_type, final : bool)
62+
type sub_type = Sub(super : list(def_type), body : comp_type, ext : ext_type)
6263
type rec_type = Rec(types : list(sub_type))
6364
6465
type def_type = Def(rec : rec_type, proj : int32)

document/core/appendix/index-types.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Category Constructor
3535
:ref:`Composite type <syntax-comptype>` :math:`\TSTRUCT~\fieldtype^\ast` :math:`\hex{5F}` (-33 as |Bs7|)
3636
:ref:`Composite type <syntax-comptype>` :math:`\TARRAY~\fieldtype` :math:`\hex{5E}` (-34 as |Bs7|)
3737
(reserved) :math:`\hex{5D}` .. :math:`\hex{51}`
38-
:ref:`Sub type <syntax-subtype>` :math:`\TSUB~\typeidx^\ast~\comptype` :math:`\hex{50}` (-48 as |Bs7|)
38+
:ref:`Sub type <syntax-subtype>` :math:`\TSUB~\TOPEN~\typeidx^\ast~\comptype` :math:`\hex{50}` (-48 as |Bs7|)
3939
:ref:`Sub type <syntax-subtype>` :math:`\TSUB~\TFINAL~\typeidx^\ast~\comptype` :math:`\hex{4F}` (-49 as |Bs7|)
4040
:ref:`Recursive type <syntax-rectype>` :math:`\TREC~\subtype^\ast` :math:`\hex{4E}` (-50 as |Bs7|)
4141
(reserved) :math:`\hex{4D}` .. :math:`\hex{41}`

document/core/binary/types.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ Recursive Types
223223
~~~~~~~~~~~~~~~
224224

225225
:ref:`Recursive types <syntax-rectype>` are encoded by the byte :math:`\hex{31}` followed by a :ref:`vector <binary-vec>` of :ref:`sub types <syntax-subtype>`.
226-
Additional shorthands are recognized for unary recursions and sub types without super types.
226+
Additional shorthands are recognized for unary recursions and final sub types without super types.
227227

228228
.. math::
229229
\begin{array}{llclll@{\qquad\qquad}l}
@@ -234,7 +234,7 @@ Additional shorthands are recognized for unary recursions and sub types without
234234
&\Rightarrow& \TREC~\X{st} \\
235235
\production{sub type} & \Bsubtype &::=&
236236
\hex{50}~~x^\ast{:\,}\Bvec(\Btypeidx)~~\X{ct}{:}\Bcomptype
237-
&\Rightarrow& \TSUB~x^\ast~\X{ct} \\ &&|&
237+
&\Rightarrow& \TSUB~\TOPEN~x^\ast~\X{ct} \\ &&|&
238238
\hex{4E}~~x^\ast{:\,}\Bvec(\Btypeidx)~~\X{ct}{:}\Bcomptype
239239
&\Rightarrow& \TSUB~\TFINAL~x^\ast~\X{ct} \\ &&|&
240240
\X{ct}{:}\Bcomptype

document/core/syntax/types.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,25 +291,27 @@ including :ref:`function types <syntax-functype>` and :ref:`aggregate types <syn
291291
\end{array}
292292
293293
294-
.. index:: ! recursive type, ! sub type, composite type, ! final, subtyping, ! roll, ! unroll, recursive type index
294+
.. index:: ! recursive type, ! sub type, composite type, ! open, ! final, subtyping, ! roll, ! unroll, recursive type index
295295
pair: abstract syntax; recursive type
296296
pair: abstract syntax; sub type
297297
.. _syntax-rectype:
298298
.. _syntax-subtype:
299+
.. _syntax-ext:
299300

300301
Recursive Types
301302
~~~~~~~~~~~~~~~
302303

303304
*Recursive types* denote a group of mutually recursive :ref:`composite types <syntax-comptype>`, each of which can optionally declare a list of :ref:`type indices <syntax-typeidx>` of supertypes that it :ref:`matches <match-comptype>`.
304-
Each type can also be declared *final*, preventing further subtyping.
305-
.
305+
Each type can also be declared *open*, in which case they may have further subtypes, or *final*, preventing further subtyping.
306306

307307
.. math::
308308
\begin{array}{llrl}
309309
\production{recursive type} & \rectype &::=&
310310
\TREC~\subtype^\ast \\
311311
\production{sub types} & \subtype &::=&
312-
\TSUB~\TFINAL^?~\typeidx^\ast~\comptype \\
312+
\TSUB~\ext~\typeidx^\ast~\comptype \\
313+
\production{extension type} & \ext &::=&
314+
\TOPEN ~|~ \TFINAL \\
313315
\end{array}
314316
315317
In a :ref:`module <syntax-module>`, each member of a recursive type is assigned a separate :ref:`type index <syntax-typeidx>`.

document/core/text/types.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ Composite Types
242242
.. _text-rectype:
243243
.. _text-subtype:
244244
.. _text-deftype:
245+
.. _text-exttype:
245246

246247
Recursive Types
247248
~~~~~~~~~~~~~~~
@@ -255,8 +256,11 @@ Recursive Types
255256
\text{(}~\text{type}~~\Tid^?~~\X{st}{:}\Tsubtype_I~\text{)}
256257
&\Rightarrow& \X{st} \\
257258
\production{sub type} & \Tsubtype_I &::=&
258-
\text{(}~\text{sub}~~\text{final}^?~~x^\ast{:\,}\Tvec(\Ttypeidx_I)~~\X{ct}{:}\Tcomptype_I~\text{)}
259-
&\Rightarrow& \TSUB~\TFINAL^?~x^\ast~\X{ct} \\
259+
\text{(}~\text{sub}~~\X{ext}{:}\Texttype~~x^\ast{:\,}\Tvec(\Ttypeidx_I)~~\X{ct}{:}\Tcomptype_I~\text{)}
260+
&\Rightarrow& \TSUB~\X{ext}~x^\ast~\X{ct} \\
261+
\production{extension type} & \Texttype &::=&
262+
\text{open} &\Rightarrow& \TOPEN \\ &&|&
263+
\text{final} &\Rightarrow& \TFINAL \\
260264
\end{array}
261265
262266

document/core/util/macros.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@
234234
.. |TARRAY| mathdef:: \xref{syntax/types}{syntax-comptype}{\K{array}}
235235
.. |TSUB| mathdef:: \xref{syntax/types}{syntax-subtype}{\K{sub}}
236236
.. |TREC| mathdef:: \xref{syntax/types}{syntax-rectype}{\K{rec}}
237+
.. |TOPEN| mathdef:: \xref{syntax/types}{syntax-subtype}{\K{open}}
237238
.. |TFINAL| mathdef:: \xref{syntax/types}{syntax-subtype}{\K{final}}
238239

239240
.. |MVAR| mathdef:: \xref{syntax/types}{syntax-mut}{\K{var}}
@@ -270,6 +271,7 @@
270271
.. |subtype| mathdef:: \xref{syntax/types}{syntax-subtype}{\X{subtype}}
271272
.. |rectype| mathdef:: \xref{syntax/types}{syntax-rectype}{\X{rectype}}
272273
.. |deftype| mathdef:: \xref{valid/conventions}{syntax-deftype}{\X{deftype}}
274+
.. |ext| mathdef:: \xref{syntax/types}{syntax-ext}{\X{ext}}
273275

274276
.. |globaltype| mathdef:: \xref{syntax/types}{syntax-globaltype}{\X{globaltype}}
275277
.. |tabletype| mathdef:: \xref{syntax/types}{syntax-tabletype}{\X{tabletype}}
@@ -906,6 +908,7 @@
906908
.. |Tstoragetype| mathdef:: \xref{text/types}{text-storagetype}{\T{storagetype}}
907909
.. |Tpackedtype| mathdef:: \xref{text/types}{text-packedtype}{\T{packedtype}}
908910
.. |Tcomptype| mathdef:: \xref{text/types}{text-comptype}{\T{comptype}}
911+
.. |Texttype| mathdef:: \xref{text/types}{text-exttype}{\T{exttype}}
909912
.. |Tsubtype| mathdef:: \xref{text/types}{text-subtype}{\T{subtype}}
910913
.. |Tdeftype| mathdef:: \xref{text/types}{text-deftype}{\T{deftype}}
911914
.. |Trectype| mathdef:: \xref{text/types}{text-rectype}{\T{rectype}}

document/core/valid/conventions.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ they only occur during :ref:`validation <valid>` or :ref:`execution <exec>`.
5252
\production{heap type} & \heaptype &::=&
5353
\dots ~|~ \deftype ~|~ \REC~i \\
5454
\production{sub types} & \subtype &::=&
55-
\TSUB~\TFINAL^?~\heaptype^\ast~\comptype \\
55+
\TSUB~\ext~\heaptype^\ast~\comptype \\
5656
\end{array}
5757
5858
The unique :ref:`value type <syntax-valtype>` |BOT| is a *bottom type* that :ref:`matches <match-heaptype>` all value types.
@@ -180,7 +180,7 @@ In addition, the following auxiliary function denotes the *expansion* of a :ref:
180180

181181
.. math::
182182
\begin{array}{@{}llll@{}}
183-
\expanddt(\deftype) &=& \comptype & (\iff \unrolldt(\deftype) = \TSUB~\TFINAL^?~\X{ht}^?~\comptype) \\
183+
\expanddt(\deftype) &=& \comptype & (\iff \unrolldt(\deftype) = \TSUB~\ext~\X{ht}^?~\comptype) \\
184184
\end{array}
185185
186186

document/core/valid/matching.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ A :ref:`defined type <syntax-deftype>` :math:`\deftype_1` matches a type :math:`
431431

432432
* Or:
433433

434-
* Let the :ref:`sub type <syntax-subtype>` :math:`\TSUB~\TFINAL^?~\heaptype^\ast~\comptype` be the result of :ref:`unrolling <aux-unroll-deftype>` :math:`\deftype_1`.
434+
* Let the :ref:`sub type <syntax-subtype>` :math:`\TSUB~\ext~\heaptype^\ast~\comptype` be the result of :ref:`unrolling <aux-unroll-deftype>` :math:`\deftype_1`.
435435

436436
* Then there must exist a :ref:`heap type <syntax-heaptype>` :math:`\heaptype_i` in :math:`\heaptype^\ast` that :ref:`matches <match-heaptype>` :math:`\deftype_2`.
437437

@@ -446,7 +446,7 @@ A :ref:`defined type <syntax-deftype>` :math:`\deftype_1` matches a type :math:`
446446
.. math::
447447
~\\[-1ex]
448448
\frac{
449-
\unrolldt(\deftype_1) = \TSUB~\TFINAL^?~\heaptype^\ast~\comptype
449+
\unrolldt(\deftype_1) = \TSUB~\ext~\heaptype^\ast~\comptype
450450
\qquad
451451
C \vdashheaptypematch \heaptype^\ast[i] \matchesheaptype \deftype_2
452452
}{

document/core/valid/types.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ Recursive Types
405405
C \vdashrectype \TREC~\subtype~{\subtype'}^\ast ~{\ok}(x)
406406
}
407407
408-
:math:`\TSUB~\TFINAL^?~y^\ast~\comptype`
408+
:math:`\TSUB~\ext~y^\ast~\comptype`
409409
........................................
410410

411411
* The :ref:`composite type <syntax-comptype>` :math:`\comptype` must be :ref:`valid <valid-comptype>`.
@@ -420,7 +420,7 @@ Recursive Types
420420

421421
* Let :math:`\subtype_i` be the :ref:`unrolling <aux-unroll-deftype>` of the :ref:`defined type <syntax-deftype>` :math:`C.\CTYPES[y_i]`.
422422

423-
* The :ref:`sub type <syntax-subtype>` :math:`\subtype_i` must not contain :math:`\TFINAL`.
423+
* The :ref:`sub type <syntax-subtype>` :math:`\subtype_i` must contain :math:`\TOPEN`.
424424

425425
* Let :math:`\comptype'_i` be the :ref:`expansion <aux-expand-deftype>` of the :ref:`defined type <syntax-deftype>` :math:`C.\CTYPES[y_i]`.
426426

@@ -435,14 +435,14 @@ Recursive Types
435435
\qquad
436436
(y < x)^\ast
437437
\qquad
438-
(\unrolldt(C.\CTYPES[y]) = \TSUB~{y'}^\ast~\comptype')^\ast
438+
(\unrolldt(C.\CTYPES[y]) = \TSUB~\TOPEN~{y'}^\ast~\comptype')^\ast
439439
\\
440440
C \vdashcomptype \comptype \ok
441441
\qquad
442442
(C \vdashcomptypematch \comptype \matchescomptype \comptype')^\ast
443443
\end{array}
444444
}{
445-
C \vdashsubtype \TSUB~\TFINAL^?~y^\ast~\comptype ~{\ok}(x)
445+
C \vdashsubtype \TSUB~\ext~y^\ast~\comptype ~{\ok}(x)
446446
}
447447
448448
.. note::

interpreter/binary/decode.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ let sub_type s =
258258
| Some i when i = -0x30 land 0x7f ->
259259
skip 1 s;
260260
let xs = vec (var_type u32) s in
261-
SubT (NoFinal, List.map (fun x -> VarHT x) xs, str_type s)
261+
SubT (Open, List.map (fun x -> VarHT x) xs, str_type s)
262262
| Some i when i = -0x31 land 0x7f ->
263263
skip 1 s;
264264
let xs = vec (var_type u32) s in

0 commit comments

Comments
 (0)