Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion document/core/syntax/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ while the latter performs a downcast and :ref:`traps <trap>` if the operand's ty

.. _syntax-struct.new:
.. _syntax-struct.new_default:
.. _syntax-struct.new_desc:
.. _syntax-struct.new_default_desc:
.. _syntax-struct.get:
.. _syntax-struct.get_s:
.. _syntax-struct.get_u:
Expand Down Expand Up @@ -301,7 +303,8 @@ Instructions in this group are concerned with creating and accessing :ref:`refer

$${syntax: {instr/struct instr/array instr/i31 instr/extern}}

The instructions ${:STRUCT.NEW} and ${:STRUCT.NEW_DEFAULT} allocate a new :ref:`structure <syntax-structtype>`, initializing them either with operands or with default values.
The instructions ${:STRUCT.NEW}, ${:STRUCT.NEW_DEFAULT} allocate a new :ref:`structure <syntax-structtype>`, initializing them either with operands or with default values.
The instructions ${:STRUCT.NEW_DESC} and ${:STRUCT.NEW_DEFAULT_DESC} do the same, but additionally take the :ref:`descriptor <syntax-desctype>` operand necessary to allocate types with descriptors.
The remaining instructions on structs access individual fields,
allowing for different sign extension modes in the case of :ref:`packed <syntax-packtype>` storage types.

Expand Down
4 changes: 4 additions & 0 deletions document/core/util/macros.def
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,10 @@
.. |rolldt| mathdef:: \xref{valid/conventions}{aux-roll-deftype}{\F{roll}}
.. |unrolldt| mathdef:: \xref{valid/conventions}{aux-unroll-deftype}{\F{unroll}}
.. |expanddt| mathdef:: \xref{valid/conventions}{aux-expand-deftype}{\F{expand}}
.. |expanddttodesctype| mathdef:: \xref{valid/conventions}{aux-expand-deftype-to-desctype}{\F{expand}}
.. |approxexpanddt| mathdef:: \mathrel{\xref{valid/conventions}{aux-expand-deftype}{\approx}}
.. |approxexpandyy| mathdef:: \mathrel{\xref{valid/conventions}{aux-expand-typeuse}{\approx}}
.. |approxexpanddttodesctype| mathdef:: \mathrel{\xref{valid/conventions}{aux-expand-deftype-to-desctype}{\approx}}
.. |unrollht| mathdef:: \xref{appendix/properties}{aux-unroll-heaptype}{\F{unroll}}

.. |unpack| mathdef:: \xref{syntax/types}{aux-unpack}{\F{unpack}}
Expand Down Expand Up @@ -551,6 +553,8 @@

.. |STRUCTNEW| mathdef:: \xref{syntax/instructions}{syntax-instr-struct}{\K{struct{.}new}}
.. |STRUCTNEWDEFAULT| mathdef:: \xref{syntax/instructions}{syntax-instr-struct}{\K{struct{.}new\_default}}
.. |STRUCTNEWDESC| mathdef:: \xref{syntax/instructions}{syntax-instr-struct}{\K{struct{.}new\_desc}}
.. |STRUCTNEWDEFAULTDESC| mathdef:: \xref{syntax/instructions}{syntax-instr-struct}{\K{struct{.}new\_default\_desc}}
.. |STRUCTGET| mathdef:: \xref{syntax/instructions}{syntax-instr-struct}{\K{struct{.}get}}
.. |STRUCTGETS| mathdef:: \xref{syntax/instructions}{syntax-instr-struct}{\K{struct{.}get\_s}}
.. |STRUCTGETU| mathdef:: \xref{syntax/instructions}{syntax-instr-struct}{\K{struct{.}get\_u}}
Expand Down
5 changes: 5 additions & 0 deletions document/core/valid/conventions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ Conventions
.. _aux-roll-deftype:
.. _aux-unroll-deftype:
.. _aux-expand-deftype:
.. _aux-expand-deftype-to-desctype:
.. _aux-expand-typeuse:

Rolling and Unrolling
Expand Down Expand Up @@ -169,6 +170,10 @@ $${rule: Expand {Expand_use/*}}
$${relation-ignore: Expand Expand_use}
$${definition-ignore: expanddt}

We use the same notation to denote the expansion of a :ref:`defined type <syntax-deftype>` or :ref:`type use <syntax-typeuse>` to a :ref:`desctype <syntax-desctype>` as well.

$${rule: ExpandDesc}


.. index:: ! instruction type, value type, result type, instruction, local, local index
pair: abstract syntax; instruction type
Expand Down
21 changes: 21 additions & 0 deletions document/core/valid/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,26 @@ $${rule-prose: Instr_ok/struct.new_default}
$${rule: Instr_ok/struct.new_default}


.. _valid-struct.new_desc:

:math:`\STRUCTNEWDESC~x`
........................

$${rule-prose: Instr_ok/struct.new_desc}

$${rule: Instr_ok/struct.new_desc}


.. _valid-struct.new_default_desc:

:math:`\STRUCTNEWDEFAULTDESC~x`
...............................

$${rule-prose: Instr_ok/struct.new_default_desc}

$${rule: Instr_ok/struct.new_default_desc}


.. _valid-struct.get:
.. _valid-struct.get_u:
.. _valid-struct.get_s:
Expand Down Expand Up @@ -1421,6 +1441,7 @@ $${rule:
{Instr_const/const Instr_const/vconst Instr_const/binop}
{Instr_const/ref.null Instr_const/ref.i31 Instr_const/ref.func}
{Instr_const/struct.new Instr_const/struct.new_default}
{Instr_const/struct.new_desc Instr_const/struct.new_default_desc}
{Instr_const/array.new Instr_const/array.new_default Instr_const/array.new_fixed}
{Instr_const/any.convert_extern Instr_const/extern.convert_any}
{Instr_const/global.get}
Expand Down
2 changes: 1 addition & 1 deletion specification/wasm-latest/1.2-syntax.types.spectec
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def $rollrt(typeidx, rectype) : rectype hint(show $roll_(%, %)) hint(macro "r
def $unrollrt(rectype) : rectype hint(show $unroll(%)) hint(macro "unrollrt")
def $rolldt(typeidx, rectype) : deftype* hint(show $roll_(%)*#((%))) hint(macro "rolldt")
def $unrolldt(deftype) : subtype hint(show $unroll(%)) hint(macro "unrolldt")
def $expanddt_to_desctype(deftype) : desctype hint(show $expand_desc(%))
def $expanddt_to_desctype(deftype) : desctype hint(show $expand_desc(%)) hint(macro "expanddttodesctype")
def $expanddt(deftype) : comptype hint(show $expand(%)) hint(macro "expanddt")

def $rollrt(x, rectype) = REC ($subst_subtype(subtype, ((_IDX $(x + i)))^(i<n), (REC i)^(i<n)))^n
Expand Down
2 changes: 2 additions & 0 deletions specification/wasm-latest/1.3-syntax.instructions.spectec
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ syntax instr/i31 hint(desc "scalar reference instruction") = ...
syntax instr/struct hint(desc "structure reference instruction") = ...
| STRUCT.NEW typeidx
| STRUCT.NEW_DEFAULT typeidx
| STRUCT.NEW_DESC typeidx
| STRUCT.NEW_DEFAULT_DESC typeidx
| STRUCT.GET sx? typeidx u32 hint(show STRUCT.GET#_#% % %)
| STRUCT.SET typeidx u32
| ...
Expand Down
5 changes: 5 additions & 0 deletions specification/wasm-latest/2.1-validation.types.spectec
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ rule Expand: deftype ~~ comptype -- if $expanddt(deftype) = comptype
rule Expand_use/deftype: deftype ~~_C comptype -- Expand: deftype ~~ comptype
rule Expand_use/typeidx: _IDX typeidx ~~_C comptype -- Expand: C.TYPES[typeidx] ~~ comptype

relation ExpandDesc: deftype ~~ desctype hint(macro "%expanddt_to_desctype") hint(tabular)
hint(prose "The :ref:`expansion <aux-expand-deftype-to-desctype>` of %1 is %2") ;; TODO(3, ?): avoid hardcoding reST

rule ExpandDesc: deftype ~~ desctype -- if $expanddt_to_desctype(deftype) = desctype


;; Type definitions

Expand Down
19 changes: 17 additions & 2 deletions specification/wasm-latest/2.3-validation.instructions.spectec
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,20 @@ rule Instr_ok/i31.get:

rule Instr_ok/struct.new:
C |- STRUCT.NEW x : $unpack(zt)* -> (REF (_IDX x))
-- Expand: C.TYPES[x] ~~ STRUCT (mut? zt)*
-- ExpandDesc: C.TYPES[x] ~~ describestype? eps STRUCT (mut? zt)*

rule Instr_ok/struct.new_default:
C |- STRUCT.NEW_DEFAULT x : eps -> (REF (_IDX x))
-- Expand: C.TYPES[x] ~~ STRUCT (mut? zt)*
-- ExpandDesc: C.TYPES[x] ~~ describestype? eps STRUCT (mut? zt)*
-- (Defaultable: |- $unpack(zt) DEFAULTABLE)*

rule Instr_ok/struct.new_desc:
C |- STRUCT.NEW_DESC x : $unpack(zt)* (REF NULL (EXACT (_IDX y))) -> (REF (EXACT (_IDX x)))
-- ExpandDesc: C.TYPES[x] ~~ describestype? (DESCRIPTOR (_IDX y)) (STRUCT (mut? zt)*)

rule Instr_ok/struct.new_default_desc:
C |- STRUCT.NEW_DEFAULT_DESC x : (REF NULL (EXACT (_IDX y))) -> (REF (EXACT (_IDX x)))
-- ExpandDesc: C.TYPES[x] ~~ describestype? (DESCRIPTOR (_IDX y)) (STRUCT (mut? zt)*)
-- (Defaultable: |- $unpack(zt) DEFAULTABLE)*

def $is_packtype(storagetype) : bool hint(show %1 = $unpack(%1)) hint(prose "%1 is a packed type")
Expand Down Expand Up @@ -673,6 +682,12 @@ rule Instr_const/struct.new:
rule Instr_const/struct.new_default:
C |- (STRUCT.NEW_DEFAULT x) CONST

rule Instr_const/struct.new_desc:
C |- (STRUCT.NEW_DESC x) CONST

rule Instr_const/struct.new_default_desc:
C |- (STRUCT.NEW_DEFAULT_DESC x) CONST

rule Instr_const/array.new:
C |- (ARRAY.NEW x) CONST

Expand Down
2 changes: 1 addition & 1 deletion spectec/src/backend-prose/gen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ let flatten_rec def =

let is_validation_helper_relation def =
match def.it with
| Ast.RelD (id, _, _, _) -> id.it = "Expand" || id.it = "Expand_use"
| Ast.RelD (id, _, _, _) -> id.it = "Expand" || id.it = "Expand_use" || id.it = "ExpandDesc"
| _ -> false
(* NOTE: Assume validation relation is `|-` *)
let is_validation_relation def =
Expand Down
Loading