Skip to content

Latest commit

 

History

History
674 lines (464 loc) · 20.5 KB

File metadata and controls

674 lines (464 loc) · 20.5 KB

Modules

:ref:`Modules <syntax-module>` are valid when all the components they contain are valid. Furthermore, most definitions are themselves classified with a suitable type.

.. index:: function, local, function index, local index, type index, function type, value type, expression, import
   pair: abstract syntax; function
   single: abstract syntax; function

Functions

Functions \func are classified by :ref:`function types <syntax-functype>` of the form [t_1^\ast] \to [t_2^\ast].

\{ \FTYPE~x, \FLOCALS~t^\ast, \FBODY~\expr \}

\frac{
  C.\CTYPES[x] = [t_1^\ast] \to [t_2^\ast]
  \qquad
  C,\CLOCALS\,t_1^\ast~t^\ast,\CLABELS~[t_2^\ast],\CRETURN~[t_2^\ast] \vdashexpr \expr : [t_2^\ast]
}{
  C \vdashfunc \{ \FTYPE~x, \FLOCALS~t^\ast, \FBODY~\expr \} : [t_1^\ast] \to [t_2^\ast]
}
.. index:: table, table type
   pair: validation; table
   single: abstract syntax; table

Tables

Tables \table are classified by :ref:`table types <syntax-tabletype>`.

\{ \TTYPE~\tabletype \}

\frac{
  \vdashtabletype \tabletype \ok
}{
  C \vdashtable \{ \TTYPE~\tabletype \} : \tabletype
}
.. index:: memory, memory type
   pair: validation; memory
   single: abstract syntax; memory

Memories

Memories \mem are classified by :ref:`memory types <syntax-memtype>`.

\{ \MTYPE~\memtype \}

\frac{
  \vdashmemtype \memtype \ok
}{
  C \vdashmem \{ \MTYPE~\memtype \} : \memtype
}
.. index:: global, global type, expression
   pair: validation; global
   single: abstract syntax; global

Globals

Globals \global are classified by :ref:`global types <syntax-globaltype>` of the form \mut~t.

\{ \GTYPE~\mut~t, \GINIT~\expr \}

\frac{
  \vdashglobaltype \mut~t \ok
  \qquad
  C \vdashexpr \expr : [t]
  \qquad
  C \vdashexprconst \expr \const
}{
  C \vdashglobal \{ \GTYPE~\mut~t, \GINIT~\expr \} : \mut~t
}
.. index:: element, table, table index, expression, function index
   pair: validation; element
   single: abstract syntax; element
   single: table; element
   single: element; segment

Element Segments

Element segments \elem are classified by the :ref:`reference type <syntax-reftype>` of their elements.

\{ \ETYPE~t, \EINIT~e^\ast, \EMODE~\elemmode \}

\frac{
  (C \vdashexpr e \ok)^\ast
  \qquad
  (C \vdashexprconst e \const)^\ast
  \qquad
  C \vdashelemmode \elemmode : t
}{
  C \vdashelem \{ \ETYPE~t, \EINIT~e^\ast, \EMODE~\elemmode \} : t
}

\EPASSIVE

\frac{
}{
  C \vdashelemmode \EPASSIVE : \reftype
}

\EACTIVE~\{ \ETABLE~x, \EOFFSET~\expr \}

\frac{
  \begin{array}{@{}c@{}}
  C.\CTABLES[x] = \limits~t
  \\
  C \vdashexpr \expr : [\I32]
  \qquad
  C \vdashexprconst \expr \const
  \end{array}
}{
  C \vdashelemmode \EACTIVE~\{ \ETABLE~x, \EOFFSET~\expr \} : t
}

\EDECLARATIVE

\frac{
}{
  C \vdashelemmode \EDECLARATIVE : \reftype
}
.. index:: data, memory, memory index, expression, byte
   pair: validation; data
   single: abstract syntax; data
   single: memory; data
   single: data; segment

Data Segments

Data segments \data are not classified by any type but merely checked for well-formedness.

\{ \DINIT~b^\ast, \DMODE~\datamode \}

  • The data mode \datamode must be valid.
  • Then the data segment is valid.
\frac{
  C \vdashdatamode \datamode \ok
}{
  C \vdashdata \{ \DINIT~b^\ast, \DMODE~\datamode \} \ok
}

\DPASSIVE

  • The data mode is valid.
\frac{
}{
  C \vdashdatamode \DPASSIVE \ok
}

\DACTIVE~\{ \DMEM~x, \DOFFSET~\expr \}

\frac{
  C.\CMEMS[x] = \limits
  \qquad
  C \vdashexpr \expr : [\I32]
  \qquad
  C \vdashexprconst \expr \const
}{
  C \vdashdatamode \DACTIVE~\{ \DMEM~x, \DOFFSET~\expr \} \ok
}
.. index:: start function, function index
   pair: validation; start function
   single: abstract syntax; start function

Start Function

Start function declarations \start are not classified by any type.

\{ \SFUNC~x \}

  • The function C.\CFUNCS[x] must be defined in the context.
  • The type of C.\CFUNCS[x] must be [] \to [].
  • Then the start function is valid.
\frac{
  C.\CFUNCS[x] = [] \to []
}{
  C \vdashstart \{ \SFUNC~x \} \ok
}
.. index:: export, name, index, function index, table index, memory index, global index
   pair: validation; export
   single: abstract syntax; export

Exports

Exports \export and export descriptions \exportdesc are classified by their :ref:`external type <syntax-externtype>`.

\{ \ENAME~\name, \EDESC~\exportdesc \}

\frac{
  C \vdashexportdesc \exportdesc : \externtype
}{
  C \vdashexport \{ \ENAME~\name, \EDESC~\exportdesc \} : \externtype
}

\EDFUNC~x

\frac{
  C.\CFUNCS[x] = \functype
}{
  C \vdashexportdesc \EDFUNC~x : \ETFUNC~\functype
}

\EDTABLE~x

\frac{
  C.\CTABLES[x] = \tabletype
}{
  C \vdashexportdesc \EDTABLE~x : \ETTABLE~\tabletype
}

\EDMEM~x

\frac{
  C.\CMEMS[x] = \memtype
}{
  C \vdashexportdesc \EDMEM~x : \ETMEM~\memtype
}

\EDGLOBAL~x

\frac{
  C.\CGLOBALS[x] = \globaltype
}{
  C \vdashexportdesc \EDGLOBAL~x : \ETGLOBAL~\globaltype
}
.. index:: import, name, function type, table type, memory type, global type
   pair: validation; import
   single: abstract syntax; import

Imports

Imports \import and import descriptions \importdesc are classified by :ref:`external types <syntax-externtype>`.

\{ \IMODULE~\name_1, \INAME~\name_2, \IDESC~\importdesc \}

  • The import description \importdesc must be valid with type \externtype.
  • Then the import is valid with type \externtype.
\frac{
  C \vdashimportdesc \importdesc : \externtype
}{
  C \vdashimport \{ \IMODULE~\name_1, \INAME~\name_2, \IDESC~\importdesc \} : \externtype
}

\IDFUNC~x

  • The function C.\CTYPES[x] must be defined in the context.
  • Let [t_1^\ast] \to [t_2^\ast] be the :ref:`function type <syntax-functype>` C.\CTYPES[x].
  • Then the import description is valid with type \ETFUNC~[t_1^\ast] \to [t_2^\ast].
\frac{
  C.\CTYPES[x] = [t_1^\ast] \to [t_2^\ast]
}{
  C \vdashimportdesc \IDFUNC~x : \ETFUNC~[t_1^\ast] \to [t_2^\ast]
}

\IDTABLE~\tabletype

\frac{
  \vdashtable \tabletype \ok
}{
  C \vdashimportdesc \IDTABLE~\tabletype : \ETTABLE~\tabletype
}

\IDMEM~\memtype

\frac{
  \vdashmemtype \memtype \ok
}{
  C \vdashimportdesc \IDMEM~\memtype : \ETMEM~\memtype
}

\IDGLOBAL~\globaltype

\frac{
  \vdashglobaltype \globaltype \ok
}{
  C \vdashimportdesc \IDGLOBAL~\globaltype : \ETGLOBAL~\globaltype
}
.. index:: module, type definition, function type, function, table, memory, global, element, data, start function, import, export, context
   pair: validation; module
   single: abstract syntax; module

Modules

Modules are classified by their mapping from the :ref:`external types <syntax-externtype>` of their :ref:`imports <syntax-import>` to those of their :ref:`exports <syntax-export>`.

A module is entirely closed, that is, its components can only refer to definitions that appear in the module itself. Consequently, no initial :ref:`context <context>` is required. Instead, the context C for validation of the module's content is constructed from the definitions in the module.

\frac{
  \begin{array}{@{}c@{}}
  (\vdashfunctype \type \ok)^\ast
  \quad
  (C \vdashfunc \func : \X{ft})^\ast
  \quad
  (C \vdashtable \table : \X{tt})^\ast
  \quad
  (C \vdashmem \mem : \X{mt})^\ast
  \quad
  (C' \vdashglobal \global : \X{gt})^\ast
  \\
  (C \vdashelem \elem : \X{rt})^\ast
  \quad
  (C \vdashdata \data \ok)^n
  \quad
  (C \vdashstart \start \ok)^?
  \quad
  (C \vdashimport \import : \X{it})^\ast
  \quad
  (C \vdashexport \export : \X{et})^\ast
  \\
  \X{ift}^\ast = \etfuncs(\X{it}^\ast)
  \qquad
  \X{itt}^\ast = \ettables(\X{it}^\ast)
  \qquad
  \X{imt}^\ast = \etmems(\X{it}^\ast)
  \qquad
  \X{igt}^\ast = \etglobals(\X{it}^\ast)
  \\
  x^\ast = \freefuncidx(\module \with \MFUNCS = \epsilon \with \MSTART = \epsilon)
  \\
  C = \{ \CTYPES~\type^\ast, \CFUNCS~\X{ift}^\ast\,\X{ft}^\ast, \CTABLES~\X{itt}^\ast\,\X{tt}^\ast, \CMEMS~\X{imt}^\ast\,\X{mt}^\ast, \CGLOBALS~\X{igt}^\ast\,\X{gt}^\ast, \CELEMS~\X{rt}^\ast, \CDATAS~{\ok}^n, \CREFS~x^\ast \}
  \\
  C' = \{ \CGLOBALS~\X{igt}^\ast, \CFUNCS~(C.\CFUNCS), \CREFS~(C.\CREFS) \}
  \qquad
  |C.\CMEMS| \leq 1
  \qquad
  (\export.\ENAME)^\ast ~\F{disjoint}
  \\
  \module = \{
    \begin{array}[t]{@{}l@{}}
      \MTYPES~\type^\ast,
      \MFUNCS~\func^\ast,
      \MTABLES~\table^\ast,
      \MMEMS~\mem^\ast,
      \MGLOBALS~\global^\ast, \\
      \MELEMS~\elem^\ast,
      \MDATAS~\data^n,
      \MSTART~\start^?,
      \MIMPORTS~\import^\ast,
      \MEXPORTS~\export^\ast \}
    \end{array}
  \end{array}
}{
  \vdashmodule \module : \X{it}^\ast \to \X{et}^\ast
}

Note

Most definitions in a module -- particularly functions -- are mutually recursive. Consequently, the definition of the :ref:`context <context>` C in this rule is recursive: it depends on the outcome of validation of the function, table, memory, and global definitions contained in the module, which itself depends on C. However, this recursion is just a specification device. All types needed to construct C can easily be determined from a simple pre-pass over the module that does not perform any actual validation.

Globals, however, are not recursive. The effect of defining the limited context C' for validating the module's globals is that their initialization expressions can only access functions and imported globals and nothing else.

Note

The restriction on the number of memories may be lifted in future versions of WebAssembly.