Modules

Modules are valid when all the components they contain are valid. Furthermore, most definitions are themselves classified with a suitable type.

Types

The sequence of types defined in a module is validated incrementally, yielding a sequence of defined types representing them individually.

\(\href{../syntax/types.html#syntax-rectype}{\mathit{type}}\)

\[\begin{array}{@{}c@{}}\displaystyle \frac{ x = {|C{.}\href{../valid/conventions.html#context}{\mathsf{types}}|} \qquad {{\mathit{dt}}^\ast} = {{{{\href{../valid/conventions.html#aux-roll-deftype}{\mathrm{roll}}}}_{x}^\ast}}{({\href{../syntax/types.html#syntax-rectype}{\mathit{rectype}}})} \qquad C \oplus \{ \begin{array}[t]{@{}l@{}} \href{../valid/conventions.html#context}{\mathsf{types}}~{{\mathit{dt}}^\ast} \}\end{array} \href{../valid/types.html#valid-rectype}{\vdash} {\href{../syntax/types.html#syntax-rectype}{\mathit{rectype}}} : {\href{../valid/types.html#valid-subtype}{\mathsf{ok}}}{(x)} }{ C \href{../valid/modules.html#valid-type}{\vdash} \href{../syntax/modules.html#syntax-type}{\mathsf{type}}~{\href{../syntax/types.html#syntax-rectype}{\mathit{rectype}}} : {{\mathit{dt}}^\ast} } \qquad \end{array}\]

\(\href{../syntax/types.html#syntax-rectype}{\mathit{type}}^\ast\)

  • If the sequence is empty, then:

    • The context \(C\) must be empty.

    • Then the type sequence is valid.

  • Otherwise:

    • Let the recursive type \(\href{../syntax/types.html#syntax-rectype}{\mathit{rectype}}\) be the last element in the sequence.

    • The sequence without \(\href{../syntax/types.html#syntax-rectype}{\mathit{rectype}}\) must be valid for some context \(C'\).

    • Let the type index \(x\) be the length of \(C'.\href{../valid/conventions.html#context}{\mathsf{types}}\), i.e., the first type index free in \(C'\).

    • Let the sequence of defined types \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}^\ast\) be the result \(\href{../valid/conventions.html#aux-roll-deftype}{\mathrm{roll}}_{x}^\ast(\href{../syntax/types.html#syntax-rectype}{\mathit{rectype}})\) of rolling up into its sequence of defined types.

    • The recursive type \(\href{../syntax/types.html#syntax-rectype}{\mathit{rectype}}\) must be valid under the context \(C\) for type index \(x\).

    • The current context \(C\) be the same as \(C'\), but with \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}^\ast\) appended to \(\href{../valid/conventions.html#context}{\mathsf{types}}\).

    • Then the type sequence is valid.

\[\begin{array}{@{}c@{}}\displaystyle \frac{ }{ C \href{../valid/modules.html#valid-types}{\vdash} \epsilon : \epsilon } \qquad \frac{ C \href{../valid/modules.html#valid-type}{\vdash} {\href{../syntax/types.html#syntax-rectype}{\mathit{type}}}_1 : {{\mathit{dt}}_1^\ast} \qquad C \oplus \{ \begin{array}[t]{@{}l@{}} \href{../valid/conventions.html#context}{\mathsf{types}}~{{\mathit{dt}}_1^\ast} \}\end{array} \href{../valid/modules.html#valid-types}{\vdash} {{\href{../syntax/types.html#syntax-rectype}{\mathit{type}}}^\ast} : {{\mathit{dt}}^\ast} }{ C \href{../valid/modules.html#valid-types}{\vdash} {\href{../syntax/types.html#syntax-rectype}{\mathit{type}}}_1~{{\href{../syntax/types.html#syntax-rectype}{\mathit{type}}}^\ast} : {{\mathit{dt}}_1^\ast}~{{\mathit{dt}}^\ast} } \qquad \end{array}\]

Functions

Functions \({\href{../syntax/modules.html#syntax-func}{\mathit{func}}}\) are classified by defined types that expand to function types of the form \(\href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~({t_1^\ast} \href{../syntax/types.html#syntax-functype}{\rightarrow} {t_2^\ast})\).

\(\{ \href{../syntax/modules.html#syntax-func}{\mathsf{type}}~x, \href{../syntax/modules.html#syntax-func}{\mathsf{locals}}~t^\ast, \href{../syntax/modules.html#syntax-func}{\mathsf{body}}~\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}} \}\)

  • The defined type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must be a function type.

  • Let \(\href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~[t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\) be the expansion of the defined type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\).

  • For each local declared by a value type \(t\) in \(t^\ast\):

    • The local for type \(t\) must be valid with local type \(\href{../valid/conventions.html#syntax-localtype}{\mathit{localtype}}_i\).

  • Let \(\href{../valid/conventions.html#syntax-localtype}{\mathit{localtype}}^\ast\) be the concatenation of all \(\href{../valid/conventions.html#syntax-localtype}{\mathit{localtype}}_i\).

  • Let \(C'\) be the same context as \(C\), but with:

    • \(\href{../valid/conventions.html#context}{\mathsf{locals}}\) set to the sequence of value types \((\href{../valid/conventions.html#syntax-init}{\mathsf{set}}~t_1)^\ast~\href{../valid/conventions.html#syntax-localtype}{\mathit{localtype}}^\ast\), concatenating parameters and locals,

    • \(\href{../valid/conventions.html#context}{\mathsf{labels}}\) set to the singular sequence containing only result type \([t_2^\ast]\).

    • \(\href{../valid/conventions.html#context}{\mathsf{return}}\) set to the result type \([t_2^\ast]\).

  • Under the context \(C'\), the expression \(\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}}\) must be valid with type \([t_2^\ast]\).

  • Then the function definition is valid with type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\).

\[\begin{array}{@{}c@{}}\displaystyle \frac{ C{.}\href{../valid/conventions.html#context}{\mathsf{types}}{}[x] \href{../valid/conventions.html#aux-expand-deftype}{\approx} \href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~({t_1^\ast} \href{../syntax/types.html#syntax-functype}{\rightarrow} {t_2^\ast}) \qquad (C \href{../valid/modules.html#valid-local}{\vdash} {\href{../syntax/modules.html#syntax-local}{\mathit{local}}} : {{\mathit{lt}}})^\ast \qquad C \oplus \{ \begin{array}[t]{@{}l@{}} \href{../valid/conventions.html#context}{\mathsf{locals}}~{(\href{../valid/conventions.html#syntax-init}{\mathsf{set}}~t_1)^\ast}~{{{\mathit{lt}}}^\ast},\; \href{../valid/conventions.html#context}{\mathsf{labels}}~({t_2^\ast}),\; \href{../valid/conventions.html#context}{\mathsf{return}}~({t_2^\ast}) \}\end{array} \href{../valid/instructions.html#valid-expr}{\vdash} {\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}}} : {t_2^\ast} }{ C \href{../valid/modules.html#valid-func}{\vdash} \href{../syntax/modules.html#syntax-func}{\mathsf{func}}~x~{{\href{../syntax/modules.html#syntax-local}{\mathit{local}}}^\ast}~{\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}}} : C{.}\href{../valid/conventions.html#context}{\mathsf{types}}{}[x] } \qquad \end{array}\]

Locals

Locals \({\href{../syntax/modules.html#syntax-local}{\mathit{local}}}\) are classified with local types.

\(\{ \href{../syntax/modules.html#syntax-local}{\mathsf{type}}~\href{../syntax/types.html#syntax-valtype}{\mathit{valtype}} \}\)

  • The value type \(\href{../syntax/types.html#syntax-valtype}{\mathit{valtype}}\) must be valid.

  • If \(\href{../syntax/types.html#syntax-valtype}{\mathit{valtype}}\) is defaultable, then:

    • The local is valid with local type \(\href{../valid/conventions.html#syntax-init}{\mathsf{set}}~\href{../syntax/types.html#syntax-valtype}{\mathit{valtype}}\).

  • Else:

    • The local is valid with local type \(\href{../valid/conventions.html#syntax-init}{\mathsf{unset}}~\href{../syntax/types.html#syntax-valtype}{\mathit{valtype}}\).

\[\begin{array}{@{}c@{}}\displaystyle \frac{ {{\href{../exec/runtime.html#default-val}{\mathrm{default}}}}_{t} \neq \epsilon }{ C \href{../valid/modules.html#valid-local}{\vdash} \href{../syntax/modules.html#syntax-local}{\mathsf{local}}~t : \href{../valid/conventions.html#syntax-init}{\mathsf{set}}~t } \qquad \frac{ {{\href{../exec/runtime.html#default-val}{\mathrm{default}}}}_{t} = \epsilon }{ C \href{../valid/modules.html#valid-local}{\vdash} \href{../syntax/modules.html#syntax-local}{\mathsf{local}}~t : \href{../valid/conventions.html#syntax-init}{\mathsf{unset}}~t } \qquad \end{array}\]

Note

For cases where both rules are applicable, the former yields the more permissable type.

Tables

Tables \({\href{../syntax/modules.html#syntax-table}{\mathit{table}}}\) are classified by table types.

\(\{ \href{../syntax/modules.html#syntax-table}{\mathsf{type}}~\href{../syntax/types.html#syntax-tabletype}{\mathit{tabletype}}, \href{../syntax/modules.html#syntax-table}{\mathsf{init}}~\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}} \}\)

  • The table type \(\href{../syntax/types.html#syntax-tabletype}{\mathit{tabletype}}\) must be valid.

  • Let \(t\) be the element reference type of \(\href{../syntax/types.html#syntax-tabletype}{\mathit{tabletype}}\).

  • The expression \(\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}}\) must be valid with result type \([t]\).

  • The expression \(\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}}\) must be constant.

  • Then the table definition is valid with type \(\href{../syntax/types.html#syntax-tabletype}{\mathit{tabletype}}\).

\[\begin{array}{@{}c@{}}\displaystyle \frac{ C \href{../valid/types.html#valid-tabletype}{\vdash} {\mathit{tt}} : \href{../valid/types.html#valid-tabletype}{\mathsf{ok}} \qquad {\href{../syntax/types.html#syntax-tabletype}{\mathit{tabletype}}} = {\mathit{lim}}~{\mathit{rt}} \qquad C \href{../valid/instructions.html#valid-const}{\vdash} {\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}}} : {\mathit{rt}}~\href{../valid/instructions.html#valid-const}{\mathsf{const}} }{ C \href{../valid/modules.html#valid-table}{\vdash} \href{../syntax/modules.html#syntax-table}{\mathsf{table}}~{\href{../syntax/types.html#syntax-tabletype}{\mathit{tabletype}}}~{\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}}} : {\href{../syntax/types.html#syntax-tabletype}{\mathit{tabletype}}} } \qquad \end{array}\]

Memories

Memories \({\href{../syntax/modules.html#syntax-mem}{\mathit{mem}}}\) are classified by memory types.

\(\{ \href{../syntax/modules.html#syntax-mem}{\mathsf{type}}~\href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} \}\)

  • The memory type \(\href{../syntax/types.html#syntax-memtype}{\mathit{memtype}}\) must be valid.

  • Then the memory definition is valid with type \(\href{../syntax/types.html#syntax-memtype}{\mathit{memtype}}\).

\[\begin{array}{@{}c@{}}\displaystyle \frac{ C \href{../valid/types.html#valid-memtype}{\vdash} {\href{../syntax/types.html#syntax-memtype}{\mathit{memtype}}} : \href{../valid/types.html#valid-memtype}{\mathsf{ok}} }{ C \href{../valid/modules.html#valid-mem}{\vdash} \href{../syntax/modules.html#syntax-mem}{\mathsf{memory}}~{\href{../syntax/types.html#syntax-memtype}{\mathit{memtype}}} : {\href{../syntax/types.html#syntax-memtype}{\mathit{memtype}}} } \qquad \end{array}\]

Globals

Globals \({\href{../syntax/modules.html#syntax-global}{\mathit{global}}}\) are classified by global types.

Sequences of globals are handled incrementally, such that each definition has access to previous definitions.

\(\{ \href{../syntax/modules.html#syntax-global}{\mathsf{type}}~\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~t, \href{../syntax/modules.html#syntax-global}{\mathsf{init}}~\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}} \}\)

  • The global type \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~t\) must be valid.

  • The expression \(\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}}\) must be valid with result type \([t]\).

  • The expression \(\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}}\) must be constant.

  • Then the global definition is valid with type \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~t\).

\[\begin{array}{@{}c@{}}\displaystyle \frac{ C \href{../valid/types.html#valid-globaltype}{\vdash} {\mathit{gt}} : \href{../valid/types.html#valid-globaltype}{\mathsf{ok}} \qquad {\href{../syntax/types.html#syntax-globaltype}{\mathit{globaltype}}} = {\href{../syntax/types.html#syntax-mut}{\mathsf{mut}}^?}~t \qquad C \href{../valid/instructions.html#valid-const}{\vdash} {\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}}} : t~\href{../valid/instructions.html#valid-const}{\mathsf{const}} }{ C \href{../valid/modules.html#valid-global}{\vdash} \href{../syntax/modules.html#syntax-global}{\mathsf{global}}~{\href{../syntax/types.html#syntax-globaltype}{\mathit{globaltype}}}~{\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}}} : {\href{../syntax/types.html#syntax-globaltype}{\mathit{globaltype}}} } \qquad \end{array}\]

\(\href{../syntax/modules.html#syntax-global}{\mathit{global}}^\ast\)

  • If the sequence is empty, then it is valid with the empty sequence of global types.

  • Else:

    • The first global definition must be valid with some type global type \(\mathit{gt}_1\).

    • Let \(C'\) be the same context as \(C\), but with the global type \(\mathit{gt}_1\) apppended to the \(\href{../valid/conventions.html#context}{\mathsf{globals}}\) list.

    • Under context \(C'\), the remainder of the sequence must be valid with some sequence \(\mathit{gt}^\ast\) of global types.

    • Then the sequence is valid with the sequence of global types consisting of \(\mathit{gt}_1\) prepended to \(\mathit{gt}^\ast\).

\[\begin{array}{@{}c@{}}\displaystyle \frac{ }{ C \href{../valid/modules.html#valid-globalseq}{\vdash} \epsilon : \epsilon } \qquad \frac{ C \href{../valid/modules.html#valid-global}{\vdash} {\href{../syntax/modules.html#syntax-global}{\mathit{global}}}_1 : {\mathit{gt}}_1 \qquad C \oplus \{ \begin{array}[t]{@{}l@{}} \href{../valid/conventions.html#context}{\mathsf{globals}}~{\mathit{gt}}_1 \}\end{array} \href{../valid/modules.html#valid-globalseq}{\vdash} {{\href{../syntax/modules.html#syntax-global}{\mathit{global}}}^\ast} : {{\mathit{gt}}^\ast} }{ C \href{../valid/modules.html#valid-globalseq}{\vdash} {\href{../syntax/modules.html#syntax-global}{\mathit{global}}}_1~{{\href{../syntax/modules.html#syntax-global}{\mathit{global}}}^\ast} : {\mathit{gt}}_1~{{\mathit{gt}}^\ast} } \qquad \end{array}\]

Tags

Tags \(\href{../syntax/modules.html#syntax-tag}{\mathit{tag}}\) are classified by their tag type, each containing an index to a function type with empty result.

\(\{ \href{../syntax/modules.html#syntax-tag}{\mathsf{type}}~x \}\)

  • The type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must be defined in the context.

  • Let \([t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast]\) be the function type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\).

  • Then the tag definition is valid with tag type \([t_1^\ast]\mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}}[t_2^\ast]\).

\[\begin{array}{@{}c@{}}\displaystyle \frac{ C{.}\href{../valid/conventions.html#context}{\mathsf{types}}{}[x] \href{../valid/conventions.html#aux-expand-deftype}{\approx} \href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~{\href{../syntax/types.html#syntax-functype}{\mathit{functype}}} }{ C \href{../valid/modules.html#valid-tag}{\vdash} \href{../syntax/modules.html#syntax-tag}{\mathsf{tag}}~x : C{.}\href{../valid/conventions.html#context}{\mathsf{types}}{}[x] } \qquad \end{array}\]

Element Segments

Element segments \({\href{../syntax/modules.html#syntax-elem}{\mathit{elem}}}\) are classified by the reference type of their elements.

\(\{ \href{../syntax/modules.html#syntax-elem}{\mathsf{type}}~t, \href{../syntax/modules.html#syntax-elem}{\mathsf{init}}~e^\ast, \href{../syntax/modules.html#syntax-elem}{\mathsf{mode}}~\href{../syntax/modules.html#syntax-elemmode}{\mathit{elemmode}} \}\)

  • The reference type \(t\) must be valid.

  • For each \(e_i\) in \(e^\ast\):

  • The element mode \(\href{../syntax/modules.html#syntax-elemmode}{\mathit{elemmode}}\) must be valid with some reference type \(t'\).

  • The reference type \(t\) must match the reference type \(t'\).

  • Then the element segment is valid with reference type \(t\).

\[\begin{array}{@{}c@{}}\displaystyle \frac{ C \href{../valid/types.html#valid-reftype}{\vdash} {\href{../syntax/types.html#syntax-elemtype}{\mathit{elemtype}}} : \href{../valid/types.html#valid-reftype}{\mathsf{ok}} \qquad (C \href{../valid/instructions.html#valid-const}{\vdash} {\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}}} : {\href{../syntax/types.html#syntax-elemtype}{\mathit{elemtype}}}~\href{../valid/instructions.html#valid-const}{\mathsf{const}})^\ast \qquad C \href{../valid/modules.html#valid-elemmode}{\vdash} {\href{../syntax/modules.html#syntax-elemmode}{\mathit{elemmode}}} : {\href{../syntax/types.html#syntax-elemtype}{\mathit{elemtype}}} }{ C \href{../valid/modules.html#valid-elem}{\vdash} \href{../syntax/modules.html#syntax-elem}{\mathsf{elem}}~{\href{../syntax/types.html#syntax-elemtype}{\mathit{elemtype}}}~{{\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}}}^\ast}~{\href{../syntax/modules.html#syntax-elemmode}{\mathit{elemmode}}} : {\href{../syntax/types.html#syntax-elemtype}{\mathit{elemtype}}} } \qquad \end{array}\]

\(\href{../syntax/modules.html#syntax-elemmode}{\mathsf{passive}}\)

\[\begin{array}{@{}c@{}}\displaystyle \frac{ }{ C \href{../valid/modules.html#valid-elemmode}{\vdash} \href{../syntax/modules.html#syntax-elemmode}{\mathsf{passive}} : {\mathit{rt}} } \qquad \end{array}\]

\(\href{../syntax/modules.html#syntax-elemmode}{\mathsf{active}}~\{ \href{../syntax/modules.html#syntax-elem}{\mathsf{table}}~x, \href{../syntax/modules.html#syntax-elem}{\mathsf{offset}}~\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}} \}\)

  • The table \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\) must be defined in the context.

  • Let \(\href{../syntax/types.html#syntax-limits}{\mathit{limits}}~t\) be the table type \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\).

  • The expression \(\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}}\) must be valid with result type \([\href{../syntax/types.html#syntax-numtype}{\mathsf{i\scriptstyle32}}]\).

  • The expression \(\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}}\) must be constant.

  • Then the element mode is valid with reference type \(t\).

\[\begin{array}{@{}c@{}}\displaystyle \frac{ C{.}\href{../valid/conventions.html#context}{\mathsf{tables}}{}[x] = {\mathit{lim}}~{\mathit{rt}'} \qquad C \href{../valid/matching.html#match-reftype}{\vdash} {\mathit{rt}} \href{../valid/matching.html#match-reftype}{\leq} {\mathit{rt}'} \qquad C \href{../valid/instructions.html#valid-const}{\vdash} {\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}}} : \href{../syntax/types.html#syntax-numtype}{\mathsf{i\scriptstyle32}}~\href{../valid/instructions.html#valid-const}{\mathsf{const}} }{ C \href{../valid/modules.html#valid-elemmode}{\vdash} \href{../syntax/modules.html#syntax-elemmode}{\mathsf{active}}~x~{\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}}} : {\mathit{rt}} } \qquad \end{array}\]

\(\href{../syntax/modules.html#syntax-elemmode}{\mathsf{declare}}\)

\[\begin{array}{@{}c@{}}\displaystyle \frac{ }{ C \href{../valid/modules.html#valid-elemmode}{\vdash} \href{../syntax/modules.html#syntax-elemmode}{\mathsf{declare}} : {\mathit{rt}} } \qquad \end{array}\]

Data Segments

Data segments \({\href{../syntax/modules.html#syntax-data}{\mathit{data}}}\) are not classified by any type but merely checked for well-formedness.

\(\{ \href{../syntax/modules.html#syntax-data}{\mathsf{init}}~b^\ast, \href{../syntax/modules.html#syntax-data}{\mathsf{mode}}~\href{../syntax/modules.html#syntax-datamode}{\mathit{datamode}} \}\)

  • The data mode \(\href{../syntax/modules.html#syntax-datamode}{\mathit{datamode}}\) must be valid.

  • Then the data segment is valid.

\[\begin{array}{@{}c@{}}\displaystyle \frac{ C \href{../valid/modules.html#valid-datamode}{\vdash} {\href{../syntax/modules.html#syntax-datamode}{\mathit{datamode}}} : \href{../valid/modules.html#valid-data}{\mathsf{ok}} }{ C \href{../valid/modules.html#valid-data}{\vdash} \href{../syntax/modules.html#syntax-data}{\mathsf{data}}~{b^\ast}~{\href{../syntax/modules.html#syntax-datamode}{\mathit{datamode}}} : \href{../valid/modules.html#valid-data}{\mathsf{ok}} } \qquad \end{array}\]

\(\href{../syntax/modules.html#syntax-datamode}{\mathsf{passive}}\)

  • The data mode is valid.

\[\begin{array}{@{}c@{}}\displaystyle \frac{ }{ C \href{../valid/modules.html#valid-datamode}{\vdash} \href{../syntax/modules.html#syntax-datamode}{\mathsf{passive}} : \href{../valid/modules.html#valid-data}{\mathsf{ok}} } \qquad \end{array}\]

\(\href{../syntax/modules.html#syntax-datamode}{\mathsf{active}}~\{ \href{../syntax/modules.html#syntax-data}{\mathsf{memory}}~x, \href{../syntax/modules.html#syntax-data}{\mathsf{offset}}~\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}} \}\)

  • The memory \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[x]\) must be defined in the context.

  • The expression \(\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}}\) must be valid with result type \([\href{../syntax/types.html#syntax-numtype}{\mathsf{i\scriptstyle32}}]\).

  • The expression \(\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}}\) must be constant.

  • Then the data mode is valid.

\[\begin{array}{@{}c@{}}\displaystyle \frac{ C{.}\href{../valid/conventions.html#context}{\mathsf{mems}}{}[x] = {\mathit{mt}} \qquad C \href{../valid/instructions.html#valid-const}{\vdash} {\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}}} : \href{../syntax/types.html#syntax-numtype}{\mathsf{i\scriptstyle32}}~\href{../valid/instructions.html#valid-const}{\mathsf{const}} }{ C \href{../valid/modules.html#valid-datamode}{\vdash} \href{../syntax/modules.html#syntax-datamode}{\mathsf{active}}~x~{\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}}} : \href{../valid/modules.html#valid-data}{\mathsf{ok}} } \qquad \end{array}\]

Start Function

Start function declarations \({\href{../syntax/modules.html#syntax-start}{\mathit{start}}}\) are not classified by any type.

\(\{ \href{../syntax/modules.html#syntax-start}{\mathsf{func}}~x \}\)

  • The function \(C.\href{../valid/conventions.html#context}{\mathsf{funcs}}[x]\) must be defined in the context.

  • The expansion of \(C.\href{../valid/conventions.html#context}{\mathsf{funcs}}[x]\) must be a function type \(\href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~[] \href{../syntax/types.html#syntax-functype}{\rightarrow} []\).

  • Then the start function is valid.

\[\begin{array}{@{}c@{}}\displaystyle \frac{ C{.}\href{../valid/conventions.html#context}{\mathsf{funcs}}{}[x] \href{../valid/conventions.html#aux-expand-deftype}{\approx} \href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~(\epsilon \href{../syntax/types.html#syntax-functype}{\rightarrow} \epsilon) }{ C \href{../valid/modules.html#valid-start}{\vdash} \href{../syntax/modules.html#syntax-start}{\mathsf{start}}~x : \href{../valid/modules.html#valid-start}{\mathsf{ok}} } \qquad \end{array}\]

Exports

Exports \({\href{../syntax/modules.html#syntax-export}{\mathit{export}}}\) are classified by their external type.

\(\{ \href{../syntax/modules.html#syntax-export}{\mathsf{name}}~\href{../syntax/values.html#syntax-name}{\mathit{name}}, \href{../syntax/modules.html#syntax-export}{\mathsf{desc}}~\href{../syntax/modules.html#syntax-exportdesc}{\mathit{exportdesc}} \}\)

  • The export description \(\href{../syntax/modules.html#syntax-exportdesc}{\mathit{exportdesc}}\) must be valid with external type \(\href{../syntax/types.html#syntax-externtype}{\mathit{externtype}}\).

  • Then the export is valid with external type \(\href{../syntax/types.html#syntax-externtype}{\mathit{externtype}}\).

\[\begin{array}{@{}c@{}}\displaystyle \frac{ C \href{../valid/modules.html#valid-externidx}{\vdash} {\href{../syntax/modules.html#syntax-externidx}{\mathit{externidx}}} : {\mathit{xt}} }{ C \href{../valid/modules.html#valid-export}{\vdash} \href{../syntax/modules.html#syntax-export}{\mathsf{export}}~{\href{../syntax/values.html#syntax-name}{\mathit{name}}}~{\href{../syntax/modules.html#syntax-externidx}{\mathit{externidx}}} : {\href{../syntax/values.html#syntax-name}{\mathit{name}}}~{\mathit{xt}} } \qquad \end{array}\]

\(\href{../syntax/modules.html#syntax-exportdesc}{\mathsf{func}}~x\)

  • The function \(C.\href{../valid/conventions.html#context}{\mathsf{funcs}}[x]\) must be defined in the context.

  • Let \(\mathit{dt}\) be the defined type \(C.\href{../valid/conventions.html#context}{\mathsf{funcs}}[x]\).

  • Then the export description is valid with external type \(\href{../syntax/types.html#syntax-externtype}{\mathsf{func}}~\mathit{dt}\).

\[\begin{array}{@{}c@{}}\displaystyle \frac{ C{.}\href{../valid/conventions.html#context}{\mathsf{funcs}}{}[x] = {\mathit{dt}} }{ C \href{../valid/modules.html#valid-externidx}{\vdash} \href{../syntax/modules.html#syntax-externidx}{\mathsf{func}}~x : \href{../syntax/types.html#syntax-externtype}{\mathsf{func}}~{\mathit{dt}} } \qquad \end{array}\]

\(\href{../syntax/modules.html#syntax-exportdesc}{\mathsf{table}}~x\)

  • The table \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\) must be defined in the context.

  • Then the export description is valid with external type \(\href{../syntax/types.html#syntax-externtype}{\mathsf{table}}~C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\).

\[\begin{array}{@{}c@{}}\displaystyle \frac{ C{.}\href{../valid/conventions.html#context}{\mathsf{tables}}{}[x] = {\mathit{tt}} }{ C \href{../valid/modules.html#valid-externidx}{\vdash} \href{../syntax/modules.html#syntax-externidx}{\mathsf{table}}~x : \href{../syntax/types.html#syntax-externtype}{\mathsf{table}}~{\mathit{tt}} } \qquad \end{array}\]

\(\href{../syntax/modules.html#syntax-exportdesc}{\mathsf{mem}}~x\)

  • The memory \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[x]\) must be defined in the context.

  • Then the export description is valid with external type \(\href{../syntax/types.html#syntax-externtype}{\mathsf{mem}}~C.\href{../valid/conventions.html#context}{\mathsf{mems}}[x]\).

\[\begin{array}{@{}c@{}}\displaystyle \frac{ C{.}\href{../valid/conventions.html#context}{\mathsf{mems}}{}[x] = {\mathit{mt}} }{ C \href{../valid/modules.html#valid-externidx}{\vdash} \href{../syntax/modules.html#syntax-externidx}{\mathsf{memory}}~x : \href{../syntax/types.html#syntax-externtype}{\mathsf{mem}}~{\mathit{mt}} } \qquad \end{array}\]

\(\href{../syntax/modules.html#syntax-exportdesc}{\mathsf{global}}~x\)

  • The global \(C.\href{../valid/conventions.html#context}{\mathsf{globals}}[x]\) must be defined in the context.

  • Then the export description is valid with external type \(\href{../syntax/types.html#syntax-externtype}{\mathsf{global}}~C.\href{../valid/conventions.html#context}{\mathsf{globals}}[x]\).

\[\begin{array}{@{}c@{}}\displaystyle \frac{ C{.}\href{../valid/conventions.html#context}{\mathsf{globals}}{}[x] = {\mathit{gt}} }{ C \href{../valid/modules.html#valid-externidx}{\vdash} \href{../syntax/modules.html#syntax-externidx}{\mathsf{global}}~x : \href{../syntax/types.html#syntax-externtype}{\mathsf{global}}~{\mathit{gt}} } \qquad \end{array}\]

\(\href{../syntax/modules.html#syntax-exportdesc}{\mathsf{tag}}~x\)

  • The tag \(C.\href{../valid/conventions.html#context}{\mathsf{tags}}[x]\) must be defined in the context.

  • Then the export description is valid with external type \(\href{../syntax/types.html#syntax-tagtype}{\mathsf{tag}}~C.\href{../valid/conventions.html#context}{\mathsf{tags}}[x]\).

\[\begin{array}{@{}c@{}}\displaystyle \frac{ C{.}\href{../valid/conventions.html#context}{\mathsf{tags}}{}[x] = {\mathit{at}} }{ C \href{../valid/modules.html#valid-externidx}{\vdash} \href{../syntax/modules.html#syntax-externidx}{\mathsf{tag}}~x : \href{../syntax/types.html#syntax-tagtype}{\mathsf{tag}}~{\mathit{at}} } \qquad \end{array}\]

Imports

Imports \({\href{../syntax/modules.html#syntax-import}{\mathit{import}}}\) are classified by external types.

\(\{ \href{../syntax/modules.html#syntax-import}{\mathsf{module}}~\href{../syntax/values.html#syntax-name}{\mathit{name}}_1, \href{../syntax/modules.html#syntax-import}{\mathsf{name}}~\href{../syntax/values.html#syntax-name}{\mathit{name}}_2, \href{../syntax/modules.html#syntax-import}{\mathsf{desc}}~\href{../syntax/modules.html#syntax-importdesc}{\mathit{importdesc}} \}\)

  • The import description \(\href{../syntax/modules.html#syntax-importdesc}{\mathit{importdesc}}\) must be valid with type \(\href{../syntax/types.html#syntax-externtype}{\mathit{externtype}}\).

  • Then the import is valid with type \(\href{../syntax/types.html#syntax-externtype}{\mathit{externtype}}\).

\[\begin{array}{@{}c@{}}\displaystyle \frac{ C \href{../valid/types.html#valid-externtype}{\vdash} {\mathit{xt}} : \href{../valid/types.html#valid-externtype}{\mathsf{ok}} }{ C \href{../valid/modules.html#valid-import}{\vdash} \href{../syntax/modules.html#syntax-import}{\mathsf{import}}~{\href{../syntax/values.html#syntax-name}{\mathit{name}}}_1~{\href{../syntax/values.html#syntax-name}{\mathit{name}}}_2~{\mathit{xt}} : {\mathit{xt}} } \qquad \end{array}\]

Modules

Modules are classified by their mapping from the external types of their imports to those of their exports.

A module is entirely closed, that is, its components can only refer to definitions that appear in the module itself. Consequently, no initial context is required. Instead, the context \(C\) for validation of the module’s content is constructed from the definitions in the module.

The external types classifying a module may contain free type indices that refer to types defined within the module.

  • Let \(\href{../syntax/modules.html#syntax-module}{\mathit{module}}\) be the module to validate.

  • The types \(\href{../syntax/modules.html#syntax-module}{\mathit{module}}.\href{../syntax/modules.html#syntax-module}{\mathsf{types}}\) must be valid yielding a context \(C_0\).

  • Let \(C\) be a context where:

    • \(C.\href{../valid/conventions.html#context}{\mathsf{types}}\) is \(C_0.\href{../valid/conventions.html#context}{\mathsf{types}}\),

    • \(C.\href{../valid/conventions.html#context}{\mathsf{funcs}}\) is \(\href{../syntax/types.html#syntax-externtype}{\mathrm{funcs}}(\mathit{it}^\ast)\) concatenated with \(\mathit{dt}^\ast\), with the import’s external types \(\mathit{it}^\ast\) and the internal defined types \(\mathit{dt}^\ast\) as determined below,

    • \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}\) is \(\href{../syntax/types.html#syntax-externtype}{\mathrm{tables}}(\mathit{it}^\ast)\) concatenated with \(\mathit{tt}^\ast\), with the import’s external types \(\mathit{it}^\ast\) and the internal table types \(\mathit{tt}^\ast\) as determined below,

    • \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}\) is \(\href{../syntax/types.html#syntax-externtype}{\mathrm{mems}}(\mathit{it}^\ast)\) concatenated with \(\mathit{mt}^\ast\), with the import’s external types \(\mathit{it}^\ast\) and the internal memory types \(\mathit{mt}^\ast\) as determined below,

    • \(C.\href{../valid/conventions.html#context}{\mathsf{globals}}\) is \(\href{../syntax/types.html#syntax-externtype}{\mathrm{globals}}(\mathit{it}^\ast)\) concatenated with \(\mathit{gt}^\ast\), with the import’s external types \(\mathit{it}^\ast\) and the internal global types \(\mathit{gt}^\ast\) as determined below,

    • \(C.\href{../valid/conventions.html#context}{\mathsf{tags}}\) is \(\href{../syntax/types.html#syntax-externtype}{\mathrm{tags}}(\mathit{it}^\ast)\) concatenated with \(\mathit{ht}^\ast\), with the import’s external types \(\mathit{it}^\ast\) and the internal tag types \(\mathit{ht}^\ast\) as determined below,

    • \(C.\href{../valid/conventions.html#context}{\mathsf{elems}}\) is \({\mathit{rt}}^\ast\) as determined below,

    • \(C.\href{../valid/conventions.html#context}{\mathsf{datas}}\) is \({\mathit{ok}}^\ast\) as determined below,

    • \(C.\href{../valid/conventions.html#context}{\mathsf{locals}}\) is empty,

    • \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}\) is empty,

    • \(C.\href{../valid/conventions.html#context}{\mathsf{return}}\) is empty.

    • \(C.\href{../valid/conventions.html#context}{\mathsf{refs}}\) is the set \(\href{../syntax/modules.html#syntax-funcidx}{\mathrm{funcidx}}(\href{../syntax/modules.html#syntax-module}{\mathit{module}} \href{../syntax/conventions.html#notation-replace}{\mathrel{\mbox{with}}} \href{../syntax/modules.html#syntax-module}{\mathsf{funcs}} = \epsilon \href{../syntax/conventions.html#notation-replace}{\mathrel{\mbox{with}}} \href{../syntax/modules.html#syntax-module}{\mathsf{start}} = \epsilon)\), i.e., the set of function indices occurring in the module, except in its functions or start function.

  • Let \(C'\) be the context where:

    • \(C'.\href{../valid/conventions.html#context}{\mathsf{globals}}\) is the sequence \(\href{../syntax/types.html#syntax-externtype}{\mathrm{globals}}(\mathit{it}^\ast)\),

    • \(C'.\href{../valid/conventions.html#context}{\mathsf{types}}\) is the same as \(C.\href{../valid/conventions.html#context}{\mathsf{types}}\),

    • \(C'.\href{../valid/conventions.html#context}{\mathsf{funcs}}\) is the same as \(C.\href{../valid/conventions.html#context}{\mathsf{funcs}}\),

    • \(C'.\href{../valid/conventions.html#context}{\mathsf{tables}}\) is the same as \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}\),

    • \(C'.\href{../valid/conventions.html#context}{\mathsf{mems}}\) is the same as \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}\),

    • \(C'.\href{../valid/conventions.html#context}{\mathsf{refs}}\) is the same as \(C.\href{../valid/conventions.html#context}{\mathsf{refs}}\),

    • all other fields are empty.

  • Under the context \(C'\):

    • The sequence \(\href{../syntax/modules.html#syntax-module}{\mathit{module}}.\href{../syntax/modules.html#syntax-module}{\mathsf{globals}}\) of globals must be valid with a sequence \(\mathit{gt}^\ast\) of global types.

    • For each \(\href{../syntax/modules.html#syntax-table}{\mathit{table}}_i\) in \(\href{../syntax/modules.html#syntax-module}{\mathit{module}}.\href{../syntax/modules.html#syntax-module}{\mathsf{tables}}\), the definition \(\href{../syntax/modules.html#syntax-table}{\mathit{table}}_i\) must be valid with a table type \(\mathit{tt}_i\).

    • For each \(\href{../syntax/modules.html#syntax-mem}{\mathit{mem}}_i\) in \(\href{../syntax/modules.html#syntax-module}{\mathit{module}}.\href{../syntax/modules.html#syntax-module}{\mathsf{mems}}\), the definition \(\href{../syntax/modules.html#syntax-mem}{\mathit{mem}}_i\) must be valid with a memory type \(\mathit{mt}_i\).

  • Under the context \(C\):

    • For each \(\href{../syntax/modules.html#syntax-func}{\mathit{func}}_i\) in \(\href{../syntax/modules.html#syntax-module}{\mathit{module}}.\href{../syntax/modules.html#syntax-module}{\mathsf{funcs}}\), the definition \(\href{../syntax/modules.html#syntax-func}{\mathit{func}}_i\) must be valid with a defined type \(\mathit{dt}_i\).

    • For each \(\href{../syntax/modules.html#syntax-tag}{\mathit{tag}}_i\) in \(\href{../syntax/modules.html#syntax-module}{\mathit{module}}.\href{../syntax/modules.html#syntax-module}{\mathsf{tags}}\), the definition \(\href{../syntax/modules.html#syntax-tag}{\mathit{tag}}_i\) must be valid with a tag type \(\mathit{ht}_i\).

    • For each \(\href{../syntax/modules.html#syntax-elem}{\mathit{elem}}_i\) in \(\href{../syntax/modules.html#syntax-module}{\mathit{module}}.\href{../syntax/modules.html#syntax-module}{\mathsf{elems}}\), the segment \(\href{../syntax/modules.html#syntax-elem}{\mathit{elem}}_i\) must be valid with reference type \(\mathit{rt}_i\).

    • For each \(\href{../syntax/modules.html#syntax-data}{\mathit{data}}_i\) in \(\href{../syntax/modules.html#syntax-module}{\mathit{module}}.\href{../syntax/modules.html#syntax-module}{\mathsf{datas}}\), the segment \(\href{../syntax/modules.html#syntax-data}{\mathit{data}}_i\) must be valid with data type \(\mathit{ok}_i\).

    • If \(\href{../syntax/modules.html#syntax-module}{\mathit{module}}.\href{../syntax/modules.html#syntax-module}{\mathsf{start}}\) is non-empty, then \(\href{../syntax/modules.html#syntax-module}{\mathit{module}}.\href{../syntax/modules.html#syntax-module}{\mathsf{start}}\) must be valid.

    • For each \(\href{../syntax/modules.html#syntax-import}{\mathit{import}}_i\) in \(\href{../syntax/modules.html#syntax-module}{\mathit{module}}.\href{../syntax/modules.html#syntax-module}{\mathsf{imports}}\), the segment \(\href{../syntax/modules.html#syntax-import}{\mathit{import}}_i\) must be valid with an external type \(\mathit{it}_i\).

    • For each \(\href{../syntax/modules.html#syntax-export}{\mathit{export}}_i\) in \(\href{../syntax/modules.html#syntax-module}{\mathit{module}}.\href{../syntax/modules.html#syntax-module}{\mathsf{exports}}\), the segment \(\href{../syntax/modules.html#syntax-export}{\mathit{export}}_i\) must be valid with external type \(\mathit{et}_i\).

  • Let \(\mathit{dt}^\ast\) be the concatenation of the internal function types \(\mathit{dt}_i\), in index order.

  • Let \(\mathit{tt}^\ast\) be the concatenation of the internal table types \(\mathit{tt}_i\), in index order.

  • Let \(\mathit{mt}^\ast\) be the concatenation of the internal memory types \(\mathit{mt}_i\), in index order.

  • Let \(\mathit{gt}^\ast\) be the concatenation of the internal global types \(\mathit{gt}_i\), in index order.

  • Let \(\mathit{ht}^\ast\) be the concatenation of the internal tag types \(\mathit{ht}_i\), in index order.

  • Let \(\mathit{rt}^\ast\) be the concatenation of the reference types \(\mathit{rt}_i\), in index order.

  • Let \(\mathit{ok}^\ast\) be the concatenation of the data types \(\mathit{ok}_i\), in index order.

  • Let \(\mathit{it}^\ast\) be the concatenation of external types \(\mathit{it}_i\) of the imports, in index order.

  • Let \(\mathit{et}^\ast\) be the concatenation of external types \(\mathit{et}_i\) of the exports, in index order.

  • The length of \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}\) must not be larger than \(1\).

  • All export names \(\href{../syntax/modules.html#syntax-export}{\mathit{export}}_i.\href{../syntax/modules.html#syntax-export}{\mathsf{name}}\) must be different.

  • Then the module is valid with external types \(\mathit{it}^\ast \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} \mathit{et}^\ast\).

\[\begin{split}\begin{array}{@{}c@{}}\displaystyle \frac{ \begin{array}{@{}c@{}} \{ \begin{array}[t]{@{}l@{}} \}\end{array} \href{../valid/modules.html#valid-types}{\vdash} {{\href{../syntax/types.html#syntax-rectype}{\mathit{type}}}^\ast} : {{\mathit{dt}'}^\ast} \qquad (\{ \begin{array}[t]{@{}l@{}} \href{../valid/conventions.html#context}{\mathsf{types}}~{{\mathit{dt}'}^\ast} \}\end{array} \href{../valid/modules.html#valid-import}{\vdash} {\href{../syntax/modules.html#syntax-import}{\mathit{import}}} : {\mathit{xt}}_{\mathsf{i}})^\ast \\ {C'} \href{../valid/modules.html#valid-globalseq}{\vdash} {{\href{../syntax/modules.html#syntax-global}{\mathit{global}}}^\ast} : {{\mathit{gt}}^\ast} \qquad ({C'} \href{../valid/modules.html#valid-table}{\vdash} {\href{../syntax/modules.html#syntax-table}{\mathit{table}}} : {\mathit{tt}})^\ast \qquad ({C'} \href{../valid/modules.html#valid-mem}{\vdash} {\href{../syntax/modules.html#syntax-mem}{\mathit{mem}}} : {\mathit{mt}})^\ast \qquad ({C'} \href{../valid/modules.html#valid-tag}{\vdash} {\href{../syntax/modules.html#syntax-tag}{\mathit{tag}}} : {\mathit{at}})^\ast \qquad (C \href{../valid/modules.html#valid-func}{\vdash} {\href{../syntax/modules.html#syntax-func}{\mathit{func}}} : {\mathit{dt}})^\ast \\ (C \href{../valid/modules.html#valid-elem}{\vdash} {\href{../syntax/modules.html#syntax-elem}{\mathit{elem}}} : {\mathit{rt}})^\ast \qquad (C \href{../valid/modules.html#valid-data}{\vdash} {\href{../syntax/modules.html#syntax-data}{\mathit{data}}} : {\mathit{ok}})^\ast \qquad (C \href{../valid/modules.html#valid-start}{\vdash} {\href{../syntax/modules.html#syntax-start}{\mathit{start}}} : \href{../valid/modules.html#valid-start}{\mathsf{ok}})^? \qquad (C \href{../valid/modules.html#valid-export}{\vdash} {\href{../syntax/modules.html#syntax-export}{\mathit{export}}} : {\mathit{nm}}~{\mathit{xt}}_{\mathsf{e}})^\ast \qquad {{\mathit{nm}}^\ast}~{\mathrm{disjoint}} \\ C = {C'} \oplus \{ \begin{array}[t]{@{}l@{}} \href{../valid/conventions.html#context}{\mathsf{globals}}~{{\mathit{gt}}^\ast},\; \href{../valid/conventions.html#context}{\mathsf{tables}}~{{\mathit{tt}}_{\mathsf{i}}^\ast}~{{\mathit{tt}}^\ast},\; \href{../valid/conventions.html#context}{\mathsf{mems}}~{{\mathit{mt}}_{\mathsf{i}}^\ast}~{{\mathit{mt}}^\ast},\; \href{../valid/conventions.html#context}{\mathsf{tags}}~{{\mathit{at}}_{\mathsf{i}}^\ast}~{{\mathit{at}}^\ast},\; \href{../valid/conventions.html#context}{\mathsf{elems}}~{{\mathit{rt}}^\ast},\; \href{../valid/conventions.html#context}{\mathsf{datas}}~{{\mathit{ok}}^\ast} \}\end{array} \\ {C'} = \{ \begin{array}[t]{@{}l@{}} \href{../valid/conventions.html#context}{\mathsf{types}}~{{\mathit{dt}'}^\ast},\; \href{../valid/conventions.html#context}{\mathsf{funcs}}~{{\mathit{dt}}_{\mathsf{i}}^\ast}~{{\mathit{dt}}^\ast},\; \href{../valid/conventions.html#context}{\mathsf{globals}}~{{\mathit{gt}}_{\mathsf{i}}^\ast},\; \href{../valid/conventions.html#context}{\mathsf{refs}}~{x^\ast} \}\end{array} \qquad {x^\ast} = {\href{../syntax/modules.html#syntax-funcidx}{\mathrm{funcidx}}}({{\href{../syntax/modules.html#syntax-global}{\mathit{global}}}^\ast}~{{\href{../syntax/modules.html#syntax-table}{\mathit{table}}}^\ast}~{{\href{../syntax/modules.html#syntax-mem}{\mathit{mem}}}^\ast}~{{\href{../syntax/modules.html#syntax-elem}{\mathit{elem}}}^\ast}~{{\href{../syntax/modules.html#syntax-data}{\mathit{data}}}^\ast}) \\ {{\mathit{dt}}_{\mathsf{i}}^\ast} = {\href{../syntax/types.html#syntax-externtype}{\mathrm{funcs}}}({{\mathit{xt}}_{\mathsf{i}}^\ast}) \qquad {{\mathit{gt}}_{\mathsf{i}}^\ast} = {\href{../syntax/types.html#syntax-externtype}{\mathrm{globals}}}({{\mathit{xt}}_{\mathsf{i}}^\ast}) \qquad {{\mathit{tt}}_{\mathsf{i}}^\ast} = {\href{../syntax/types.html#syntax-externtype}{\mathrm{tables}}}({{\mathit{xt}}_{\mathsf{i}}^\ast}) \qquad {{\mathit{mt}}_{\mathsf{i}}^\ast} = {\href{../syntax/types.html#syntax-externtype}{\mathrm{mems}}}({{\mathit{xt}}_{\mathsf{i}}^\ast}) \qquad {{\mathit{at}}_{\mathsf{i}}^\ast} = {\href{../syntax/types.html#syntax-externtype}{\mathrm{tags}}}({{\mathit{xt}}_{\mathsf{i}}^\ast}) \end{array} }{ {\href{../valid/modules.html#valid-module}{\vdash}}\, \href{../syntax/modules.html#syntax-module}{\mathsf{module}}~{{\href{../syntax/types.html#syntax-rectype}{\mathit{type}}}^\ast}~{{\href{../syntax/modules.html#syntax-import}{\mathit{import}}}^\ast}~{{\href{../syntax/modules.html#syntax-func}{\mathit{func}}}^\ast}~{{\href{../syntax/modules.html#syntax-global}{\mathit{global}}}^\ast}~{{\href{../syntax/modules.html#syntax-table}{\mathit{table}}}^\ast}~{{\href{../syntax/modules.html#syntax-mem}{\mathit{mem}}}^\ast}~{{\href{../syntax/modules.html#syntax-tag}{\mathit{tag}}}^\ast}~{{\href{../syntax/modules.html#syntax-elem}{\mathit{elem}}}^\ast}~{{\href{../syntax/modules.html#syntax-data}{\mathit{data}}}^\ast}~{{\href{../syntax/modules.html#syntax-start}{\mathit{start}}}^?}~{{\href{../syntax/modules.html#syntax-export}{\mathit{export}}}^\ast} : {{\href{../valid/conventions.html#aux-clostype}{\mathsf{clos}}}}_{C}({{\mathit{xt}}_{\mathsf{i}}^\ast} \mathrel{\href{../valid/modules.html#syntax-moduletype}{\rightarrow}} {{\mathit{xt}}_{\mathsf{e}}^\ast}) } \qquad \end{array}\end{split}\]

Todo

Check refs; check export names

Note

All functions in a module are mutually recursive. Consequently, the definition of the 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 but evaluated sequentially, such that each constant expressions only has access to imported or previously defined globals.