Skip to content

Commit 7fb5764

Browse files
authored
Merge pull request Wasm-DSL#7 from dhil/funcref-merge
Merge with function-references
2 parents 42228fb + fe51e7d commit 7fb5764

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1041
-1243
lines changed

.github/workflows/ci-interpreter.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
2name: CI for interpreter & tests
1+
name: CI for interpreter & tests
22

33
on:
44
push:
@@ -21,7 +21,7 @@ jobs:
2121
- name: Setup OCaml
2222
uses: ocaml/setup-ocaml@v2
2323
with:
24-
ocaml-compiler: 4.12.x
24+
ocaml-compiler: 4.14.x
2525
- name: Setup OCaml tools
2626
run: opam install --yes ocamlbuild.0.14.0 ocamlfind.1.9.5 js_of_ocaml.4.0.0 js_of_ocaml-ppx.4.0.0
2727
- name: Setup Node.js
@@ -31,5 +31,6 @@ jobs:
3131
- name: Build interpreter
3232
run: cd interpreter && opam exec make
3333
- name: Run tests
34+
# TODO: disable node.js run until it fully implements proposal
35+
# run: cd interpreter && opam exec make JS=node ci
3436
run: cd interpreter && opam exec make test
35-
#run: cd interpreter && opam exec make JS=node ci

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
[![CI for specs](https://github.com/WebAssembly/spec/actions/workflows/ci-spec.yml/badge.svg)](https://github.com/WebAssembly/spec/actions/workflows/ci-spec.yml)
2-
[![CI for interpreter & tests](https://github.com/WebAssembly/spec/actions/workflows/ci-interpreter.yml/badge.svg)](https://github.com/WebAssembly/spec/actions/workflows/ci-interpreter.yml)
1+
[![CI for specs](https://github.com/wasmfx/specfx/actions/workflows/ci-spec.yml/badge.svg)](https://github.com/wasmfx/specfx/actions/workflows/ci-spec.yml)
2+
[![CI for interpreter & tests](https://github.com/wasmfx/specfx/actions/workflows/ci-interpreter.yml/badge.svg)](https://github.com/wasmfx/specfx/actions/workflows/ci-interpreter.yml)
33

44
# Typed Continuations Proposal for WebAssembly
55

document/core/appendix/embedding.rst

+43-40
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Modules
167167
:math:`\F{module\_imports}(\module) : (\name, \name, \externtype)^\ast`
168168
.......................................................................
169169

170-
1. Pre-condition: :math:`\module` is :ref:`valid <valid-module>` with the :ref:`dynamic <syntax-type-dyn>` external import types :math:`\externtype^\ast` and external export types :math:`{\externtype'}^\ast`.
170+
1. Pre-condition: :math:`\module` is :ref:`valid <valid-module>` with the external import types :math:`\externtype^\ast` and external export types :math:`{\externtype'}^\ast`.
171171

172172
2. Let :math:`\import^\ast` be the :ref:`imports <syntax-import>` :math:`\module.\MIMPORTS`.
173173

@@ -179,7 +179,7 @@ Modules
179179

180180
5. Return the concatenation of all :math:`\X{result}_i`, in index order.
181181

182-
6. Post-condition: each :ref:`dynamic <syntax-type-dyn>` :math:`\externtype_i` is :ref:`valid <valid-externtype>`.
182+
6. Post-condition: each :math:`\externtype_i` is :ref:`valid <valid-externtype>` under the empty :ref:`context <context>`.
183183

184184
.. math::
185185
~ \\
@@ -195,7 +195,7 @@ Modules
195195
:math:`\F{module\_exports}(\module) : (\name, \externtype)^\ast`
196196
................................................................
197197

198-
1. Pre-condition: :math:`\module` is :ref:`valid <valid-module>` with the :ref:`dynamic <syntax-type-dyn>` external import types :math:`\externtype^\ast` and external export types :math:`{\externtype'}^\ast`.
198+
1. Pre-condition: :math:`\module` is :ref:`valid <valid-module>` with the external import types :math:`\externtype^\ast` and external export types :math:`{\externtype'}^\ast`.
199199

200200
2. Let :math:`\export^\ast` be the :ref:`exports <syntax-export>` :math:`\module.\MEXPORTS`.
201201

@@ -207,7 +207,7 @@ Modules
207207

208208
5. Return the concatenation of all :math:`\X{result}_i`, in index order.
209209

210-
6. Post-condition: each :ref:`dynamic <syntax-type-dyn>` :math:`\externtype'_i` is :ref:`valid <valid-externtype>`.
210+
6. Post-condition: each :math:`\externtype'_i` is :ref:`valid <valid-externtype>` under the empty :ref:`context <context>`.
211211

212212
.. math::
213213
~ \\
@@ -246,29 +246,6 @@ Module Instances
246246
\end{array}
247247
248248
249-
.. index:: type, type instance, function type
250-
.. _embed-type:
251-
252-
Types
253-
~~~~~
254-
255-
.. _embed-type-alloc:
256-
257-
:math:`\F{type\_alloc}(\store, \functype) : (\store, \typeaddr)`
258-
...........................................................................
259-
260-
1. Pre-condition: the :ref:`dynamic <syntax-type-dyn>` :math:`\functype` is :ref:`valid <valid-functype>`.
261-
262-
2. Let :math:`\typeaddr` be the result of :ref:`allocating a type <alloc-type>` in :math:`\store` for :ref:`function type <syntax-functype>` :math:`\functype`.
263-
264-
3. Return the new store paired with :math:`\typeaddr`.
265-
266-
.. math::
267-
\begin{array}{lclll}
268-
\F{type\_alloc}(S, \X{ft}) &=& (S', \X{a}) && (\iff \alloctype(S, \X{ft}) = S', \X{a}) \\
269-
\end{array}
270-
271-
272249
.. index:: function, host function, function address, function instance, function type, store
273250
.. _embed-func:
274251

@@ -277,12 +254,12 @@ Functions
277254

278255
.. _embed-func-alloc:
279256

280-
:math:`\F{func\_alloc}(\store, \typeaddr, \hostfunc) : (\store, \funcaddr)`
257+
:math:`\F{func\_alloc}(\store, \functype, \hostfunc) : (\store, \funcaddr)`
281258
...........................................................................
282259

283-
1. Pre-condition: the :ref:`dynamic <syntax-type-dyn>` :math:`\functype` is :ref:`valid <valid-functype>`.
260+
1. Pre-condition: the :math:`\functype` is :ref:`valid <valid-functype>` under the empty :ref:`context <context>`.
284261

285-
2. Let :math:`\funcaddr` be the result of :ref:`allocating a host function <alloc-func>` in :math:`\store` with :ref:`type address <syntax-typeaddr>` :math:`\typeaddr` and host function code :math:`\hostfunc`.
262+
2. Let :math:`\funcaddr` be the result of :ref:`allocating a host function <alloc-func>` in :math:`\store` with :ref:`function type <syntax-functype>` :math:`\functype` and host function code :math:`\hostfunc`.
286263

287264
3. Return the new store paired with :math:`\funcaddr`.
288265

@@ -302,15 +279,15 @@ Functions
302279
:math:`\F{func\_type}(\store, \funcaddr) : \functype`
303280
.....................................................
304281

305-
1. Let :math:`\typeaddr` be the :ref:`type address <syntax-typeaddr>` :math:`S.\SFUNCS[a].\FITYPE`.
282+
1. Let :math:`\functype` be the :ref:`function type <syntax-functype>` :math:`S.\SFUNCS[a].\FITYPE`.
306283

307-
2. Return :math:`S.\STYPES[\typeaddr]`.
284+
2. Return :math:`\functype`.
308285

309-
3. Post-condition: the returned :ref:`dynamic <syntax-type-dyn>` :ref:`function type <syntax-functype>` is :ref:`valid <valid-functype>`.
286+
3. Post-condition: the returned :ref:`function type <syntax-functype>` is :ref:`valid <valid-functype>`.
310287

311288
.. math::
312289
\begin{array}{lclll}
313-
\F{func\_type}(S, a) &=& S.\STYPES[S.\SFUNCS[a].\FITYPE] \\
290+
\F{func\_type}(S, a) &=& S.\SFUNCS[a].\FITYPE \\
314291
\end{array}
315292
316293
@@ -350,7 +327,7 @@ Tables
350327
:math:`\F{table\_alloc}(\store, \tabletype, \reff) : (\store, \tableaddr)`
351328
..........................................................................
352329

353-
1. Pre-condition: the :ref:`dynamic <syntax-type-dyn>` :math:`\tabletype` is :ref:`valid <valid-tabletype>`.
330+
1. Pre-condition: the :math:`\tabletype` is :ref:`valid <valid-tabletype>` under the empty :ref:`context <context>`.
354331

355332
2. Let :math:`\tableaddr` be the result of :ref:`allocating a table <alloc-table>` in :math:`\store` with :ref:`table type <syntax-tabletype>` :math:`\tabletype` and initialization value :math:`\reff`.
356333

@@ -369,7 +346,7 @@ Tables
369346

370347
1. Return :math:`S.\STABLES[a].\TITYPE`.
371348

372-
2. Post-condition: the returned :ref:`dynamic <syntax-type-dyn>` :ref:`table type <syntax-tabletype>` is :ref:`valid <valid-tabletype>`.
349+
2. Post-condition: the returned :ref:`table type <syntax-tabletype>` is :ref:`valid <valid-tabletype>` under the empty :ref:`context <context>`.
373350

374351
.. math::
375352
\begin{array}{lclll}
@@ -462,7 +439,7 @@ Memories
462439
:math:`\F{mem\_alloc}(\store, \memtype) : (\store, \memaddr)`
463440
................................................................
464441

465-
1. Pre-condition: the :ref:`dynamic <syntax-type-dyn>` :math:`\memtype` is :ref:`valid <valid-memtype>`.
442+
1. Pre-condition: the :math:`\memtype` is :ref:`valid <valid-memtype>` under the empty :ref:`context <context>`.
466443

467444
2. Let :math:`\memaddr` be the result of :ref:`allocating a memory <alloc-mem>` in :math:`\store` with :ref:`memory type <syntax-memtype>` :math:`\memtype`.
468445

@@ -481,7 +458,7 @@ Memories
481458

482459
1. Return :math:`S.\SMEMS[a].\MITYPE`.
483460

484-
2. Post-condition: the returned :ref:`dynamic <syntax-type-dyn>` :ref:`memory type <syntax-memtype>` is :ref:`valid <valid-memtype>`.
461+
2. Post-condition: the returned :ref:`memory type <syntax-memtype>` is :ref:`valid <valid-memtype>` under the empty :ref:`context <context>`.
485462

486463
.. math::
487464
\begin{array}{lclll}
@@ -575,7 +552,7 @@ Globals
575552
:math:`\F{global\_alloc}(\store, \globaltype, \val) : (\store, \globaladdr)`
576553
............................................................................
577554

578-
1. Pre-condition: the :ref:`dynamic <syntax-type-dyn>` :math:`\globaltype` is :ref:`valid <valid-globaltype>`.
555+
1. Pre-condition: the :math:`\globaltype` is :ref:`valid <valid-globaltype>` under the empty :ref:`context <context>`.
579556

580557
2. Let :math:`\globaladdr` be the result of :ref:`allocating a global <alloc-global>` in :math:`\store` with :ref:`global type <syntax-globaltype>` :math:`\globaltype` and initialization value :math:`\val`.
581558

@@ -594,7 +571,7 @@ Globals
594571

595572
1. Return :math:`S.\SGLOBALS[a].\GITYPE`.
596573

597-
2. Post-condition: the returned :ref:`dynamic <syntax-type-dyn>` :ref:`global type <syntax-globaltype>` is :ref:`valid <valid-globaltype>`.
574+
2. Post-condition: the returned :ref:`global type <syntax-globaltype>` is :ref:`valid <valid-globaltype>` under the empty :ref:`context <context>`.
598575

599576
.. math::
600577
\begin{array}{lclll}
@@ -638,3 +615,29 @@ Globals
638615
\F{global\_write}(S, a, v) &=& S' && (\iff S.\SGLOBALS[a].\GITYPE = \MVAR~t \wedge S' = S \with \SGLOBALS[a].\GIVALUE = v) \\
639616
\F{global\_write}(S, a, v) &=& \ERROR && (\otherwise) \\
640617
\end{array}
618+
619+
620+
.. index:: reference, reference type
621+
.. _embed-ref:
622+
623+
References
624+
~~~~~~~~~~
625+
626+
:math:`\F{ref\_type}(\store, \reff) : \reftype`
627+
...............................................
628+
629+
1. Pre-condition: the :ref:`reference <syntax-ref>` :math:`\reff` is :ref:`valid <valid-val>` under store :math:`S`.
630+
631+
2. Return the :ref:`reference type <syntax-reftype>` :math:`t` with which :math:`\reff` is valid.
632+
633+
3. Post-condition: the returned :ref:`reference type <syntax-reftype>` is :ref:`valid <valid-reftype>` under the empty :ref:`context <context>`.
634+
635+
.. math::
636+
\begin{array}{lclll}
637+
\F{ref\_type}(S, r) &=& t && (\iff S \vdashval r : t) \\
638+
\end{array}
639+
640+
.. note::
641+
In future versions of WebAssembly,
642+
not all references may carry precise type information at run time.
643+
In such cases, this function may return a less precise supertype.

document/core/appendix/index-instructions.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,9 @@ def Instruction(name, opcode, type=None, validation=None, execution=None, operat
280280
Instruction(r'\REFNULL~\X{ht}', r'\hex{D0}', r'[] \to [(\REF~\NULL~\X{ht})]', r'valid-ref.null', r'exec-ref.null'),
281281
Instruction(r'\REFISNULL', r'\hex{D1}', r'[(\REF~\NULL~\X{ht})] \to [\I32]', r'valid-ref.is_null', r'exec-ref.is_null'),
282282
Instruction(r'\REFFUNC~x', r'\hex{D2}', r'[] \to [\FUNCREF]', r'valid-ref.func', r'exec-ref.func'),
283-
Instruction(r'\REFASNONNULL', r'\hex{D3}', r'[(\REF~\NULL~\X{ht})] \to [(\REF~\X{ht})]', r'valid-ref.as_non_null', r'exec-ref.as_non_null'),
284-
Instruction(r'\BRONNULL~l', r'\hex{D4}', r'[t^\ast~(\REF~\NULL~\X{ht})] \to [t^\ast~(\REF~\X{ht})]', r'valid-br_on_null', r'exec-br_on_null'),
285-
Instruction(None, r'\hex{D5}'),
283+
Instruction(None, r'\hex{D3}'),
284+
Instruction(r'\REFASNONNULL', r'\hex{D4}', r'[(\REF~\NULL~\X{ht})] \to [(\REF~\X{ht})]', r'valid-ref.as_non_null', r'exec-ref.as_non_null'),
285+
Instruction(r'\BRONNULL~l', r'\hex{D5}', r'[t^\ast~(\REF~\NULL~\X{ht})] \to [t^\ast~(\REF~\X{ht})]', r'valid-br_on_null', r'exec-br_on_null'),
286286
Instruction(r'\BRONNONNULL~l', r'\hex{D6}', r'[t^\ast~(\REF~\NULL~\X{ht})] \to [t^\ast]', r'valid-br_on_non_null', r'exec-br_on_non_null'),
287287
Instruction(None, r'\hex{D7}'),
288288
Instruction(None, r'\hex{D8}'),

document/core/appendix/index-rules.rst

+1-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Construct Judgement
2929
:ref:`Instruction <valid-instr>` :math:`S;C \vdashinstr \instr : \functype`
3030
:ref:`Instruction sequence <valid-instr-seq>` :math:`S;C \vdashinstrseq \instr^\ast : \functype`
3131
:ref:`Expression <valid-expr>` :math:`C \vdashexpr \expr : \resulttype`
32-
:ref:`Function <valid-func>` :math:`C \vdashfunc \func : \typeid`
32+
:ref:`Function <valid-func>` :math:`C \vdashfunc \func : \functype`
3333
:ref:`Local <valid-local>` :math:`C \vdashlocal \local : \localtype`
3434
:ref:`Table <valid-table>` :math:`C \vdashtable \table : \tabletype`
3535
:ref:`Memory <valid-mem>` :math:`C \vdashmem \mem : \memtype`
@@ -58,7 +58,6 @@ Construct Judgement
5858
:ref:`Value <valid-val>` :math:`S \vdashval \val : \valtype`
5959
:ref:`Result <valid-result>` :math:`S \vdashresult \result : \resulttype`
6060
:ref:`External value <valid-externval>` :math:`S \vdashexternval \externval : \externtype`
61-
:ref:`Type instance <valid-typeinst>` :math:`S \vdashtypeinst \typeinst \ok`
6261
:ref:`Function instance <valid-funcinst>` :math:`S \vdashfuncinst \funcinst : \functype`
6362
:ref:`Table instance <valid-tableinst>` :math:`S \vdashtableinst \tableinst : \tabletype`
6463
:ref:`Memory instance <valid-meminst>` :math:`S \vdashmeminst \meminst : \memtype`
@@ -122,7 +121,6 @@ Store Extension
122121
=============================================== ===============================================================================
123122
Construct Judgement
124123
=============================================== ===============================================================================
125-
:ref:`Type instance <extend-typeinst>` :math:`\vdashtypeinstextends \typeinst_1 \extendsto \typeinst_2`
126124
:ref:`Function instance <extend-funcinst>` :math:`\vdashfuncinstextends \funcinst_1 \extendsto \funcinst_2`
127125
:ref:`Table instance <extend-tableinst>` :math:`\vdashtableinstextends \tableinst_1 \extendsto \tableinst_2`
128126
:ref:`Memory instance <extend-meminst>` :math:`\vdashmeminstextends \meminst_1 \extendsto \meminst_2`

document/core/appendix/index-types.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ Category Constructor
1616
(reserved) :math:`\hex{7A}` .. :math:`\hex{71}`
1717
:ref:`Heap type <syntax-heaptype>` |FUNC| :math:`\hex{70}` (-16 as |Bs7|)
1818
:ref:`Heap type <syntax-heaptype>` |EXTERN| :math:`\hex{6F}` (-17 as |Bs7|)
19-
(reserved) :math:`\hex{6E}` .. :math:`\hex{6D}`
20-
:ref:`Reference type <syntax-reftype>` |REF| |NULL| :math:`\hex{6C}` (-20 as |Bs7|)
21-
:ref:`Reference type <syntax-reftype>` |REF| :math:`\hex{6B}` (-21 as |Bs7|)
22-
(reserved) :math:`\hex{6A}` .. :math:`\hex{61}`
19+
(reserved) :math:`\hex{6E}` .. :math:`\hex{65}`
20+
:ref:`Reference type <syntax-reftype>` |REF| :math:`\hex{64}` (-28 as |Bs7|)
21+
:ref:`Reference type <syntax-reftype>` |REF| |NULL| :math:`\hex{63}` (-29 as |Bs7|)
22+
(reserved) :math:`\hex{62}` .. :math:`\hex{61}`
2323
:ref:`Function type <syntax-functype>` :math:`[\valtype^\ast] \toF[\valtype^\ast]` :math:`\hex{60}` (-32 as |Bs7|)
2424
(reserved) :math:`\hex{5F}` .. :math:`\hex{41}`
2525
:ref:`Result type <syntax-resulttype>` :math:`[\epsilon]` :math:`\hex{40}` (-64 as |Bs7|)

0 commit comments

Comments
 (0)