Skip to content

Latest commit

 

History

History
356 lines (245 loc) · 7.69 KB

File metadata and controls

356 lines (245 loc) · 7.69 KB

Types

Most :ref:`types <syntax-type>` are universally valid. However, restrictions apply to :ref:`limits <syntax-limits>`, which must be checked during validation. Moreover, :ref:`block types <syntax-blocktype>` are converted to plain :ref:`function types <syntax-functype>` for ease of processing.

.. index:: limits
   pair: validation; limits
   single: abstract syntax; limits

Limits

:ref:`Limits <syntax-limits>` must have meaningful bounds that are within a given range.

\{ \LMIN~n, \LMAX~m^? \}

  • The value of n must not be larger than k.
  • If the maximum m^? is not empty, then:
    • Its value must not be larger than k.
    • Its value must not be smaller than n.
  • Then the limit is valid within range k.
\frac{
  n \leq k
  \qquad
  (m \leq k)^?
  \qquad
  (n \leq m)^?
}{
  \vdashlimits \{ \LMIN~n, \LMAX~m^? \} : k
}
.. index:: block type
   pair: validation; block type
   single: abstract syntax; block type

Block Types

:ref:`Block types <syntax-blocktype>` may be expressed in one of two forms, both of which are converted to plain :ref:`function types <syntax-functype>` by the following rules.

\typeidx

\frac{
  C.\CTYPES[\typeidx] = \functype
}{
  C \vdashblocktype \typeidx : \functype
}

[\valtype^?]

\frac{
}{
  C \vdashblocktype [\valtype^?] : [] \to [\valtype^?]
}
.. index:: function type
   pair: validation; function type
   single: abstract syntax; function type

Function Types

:ref:`Function types <syntax-functype>` are always valid.

[t_1^n] \to [t_2^m]

  • The function type is valid.
\frac{
}{
  \vdashfunctype [t_1^\ast] \to [t_2^\ast] \ok
}
.. index:: table type, reference type, limits
   pair: validation; table type
   single: abstract syntax; table type

Table Types

\limits~\reftype

\frac{
  \vdashlimits \limits : 2^{32} - 1
}{
  \vdashtabletype \limits~\reftype \ok
}
.. index:: memory type, limits
   pair: validation; memory type
   single: abstract syntax; memory type

Memory Types

\limits

\frac{
  \vdashlimits \limits : 2^{16}
}{
  \vdashmemtype \limits \ok
}
.. index:: global type, value type, mutability
   pair: validation; global type
   single: abstract syntax; global type

Global Types

\mut~\valtype

  • The global type is valid.
\frac{
}{
  \vdashglobaltype \mut~\valtype \ok
}
.. index:: external type, function type, table type, memory type, global type
   pair: validation; external type
   single: abstract syntax; external type

External Types

\ETFUNC~\functype

\frac{
  \vdashfunctype \functype \ok
}{
  \vdashexterntype \ETFUNC~\functype \ok
}

\ETTABLE~\tabletype

\frac{
  \vdashtabletype \tabletype \ok
}{
  \vdashexterntype \ETTABLE~\tabletype \ok
}

\ETMEM~\memtype

\frac{
  \vdashmemtype \memtype \ok
}{
  \vdashexterntype \ETMEM~\memtype \ok
}

\ETGLOBAL~\globaltype

\frac{
  \vdashglobaltype \globaltype \ok
}{
  \vdashexterntype \ETGLOBAL~\globaltype \ok
}
.. index:: ! matching, external type

Import Subtyping

When :ref:`instantiating <exec-module>` a module, :ref:`external values <syntax-externval>` must be provided whose :ref:`types <valid-externval>` are matched against the respective :ref:`external types <syntax-externtype>` classifying each import. In some cases, this allows for a simple form of subtyping, as defined here.

.. index:: limits

Limits

:ref:`Limits <syntax-limits>` \{ \LMIN~n_1, \LMAX~m_1^? \} match limits \{ \LMIN~n_2, \LMAX~m_2^? \} if and only if:

  • n_1 is larger than or equal to n_2.
  • Either:
    • m_2^? is empty.
  • Or:
    • Both m_1^? and m_2^? are non-empty.
    • m_1 is smaller than or equal to m_2.
~\\[-1ex]
\frac{
  n_1 \geq n_2
}{
  \vdashlimitsmatch \{ \LMIN~n_1, \LMAX~m_1^? \} \matcheslimits \{ \LMIN~n_2, \LMAX~\epsilon \}
}
\quad
\frac{
  n_1 \geq n_2
  \qquad
  m_1 \leq m_2
}{
  \vdashlimitsmatch \{ \LMIN~n_1, \LMAX~m_1 \} \matcheslimits \{ \LMIN~n_2, \LMAX~m_2 \}
}
.. index:: function type

Functions

An :ref:`external type <syntax-externtype>` \ETFUNC~\functype_1 matches \ETFUNC~\functype_2 if and only if:

  • Both \functype_1 and \functype_2 are the same.
~\\[-1ex]
\frac{
}{
  \vdashexterntypematch \ETFUNC~\functype \matchesexterntype \ETFUNC~\functype
}
.. index:: table type, limits, element type

Tables

An :ref:`external type <syntax-externtype>` \ETTABLE~(\limits_1~\reftype_1) matches \ETTABLE~(\limits_2~\reftype_2) if and only if:

\frac{
  \vdashlimitsmatch \limits_1 \matcheslimits \limits_2
}{
  \vdashexterntypematch \ETTABLE~(\limits_1~\reftype) \matchesexterntype \ETTABLE~(\limits_2~\reftype)
}
.. index:: memory type, limits

Memories

An :ref:`external type <syntax-externtype>` \ETMEM~\limits_1 matches \ETMEM~\limits_2 if and only if:

\frac{
  \vdashlimitsmatch \limits_1 \matcheslimits \limits_2
}{
  \vdashexterntypematch \ETMEM~\limits_1 \matchesexterntype \ETMEM~\limits_2
}
.. index:: global type, value type, mutability

Globals

An :ref:`external type <syntax-externtype>` \ETGLOBAL~\globaltype_1 matches \ETGLOBAL~\globaltype_2 if and only if:

  • Both \globaltype_1 and \globaltype_2 are the same.
~\\[-1ex]
\frac{
}{
  \vdashexterntypematch \ETGLOBAL~\globaltype \matchesexterntype \ETGLOBAL~\globaltype
}