Types

Most types are universally valid. However, restrictions apply to limits, which must be checked during validation. Moreover, block types are converted to plain function types for ease of processing.

Limits

Limits must have meaningful bounds that are within a given range.

{min n,max 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.

nk(mk)?(nm)?{min n,max m?}:k

Block Types

Block types may be expressed in one of two forms, both of which are converted to plain function types by the following rules.

typeidx

  • The type C.types[typeidx] must be defined in the context.

  • Then the block type is valid as function type C.types[typeidx].

C.types[typeidx]=functypeCtypeidx:functype

[valtype?]

C[valtype?]:[][valtype?]

Function Types

Function types are always valid.

[t1n][t2m]

  • The function type is valid.

[t1][t2]ok

Table Types

limits reftype

  • The limits limits must be valid within range 2321.

  • Then the table type is valid.

limits:2321limits reftypeok

Memory Types

limits

  • The limits limits must be valid within range 216.

  • Then the memory type is valid.

limits:216limits shareok

Global Types

mut valtype

  • The global type is valid.

mut valtypeok

External Types

func functype

functypeokfunc functypeok

table tabletype

tabletypeoktable tabletypeok

mem memtype

memtypeokmem memtypeok

global globaltype

globaltypeokglobal globaltypeok

Import Subtyping

When instantiating a module, external values must be provided whose types are matched against the respective external types classifying each import. In some cases, this allows for a simple form of subtyping (written “” formally), as defined here.

Limits

Limits {min n1,max m1?} match limits {min n2,max m2?} if and only if:

  • n1 is larger than or equal to n2.

  • Either:

    • m2? is empty.

  • Or:

    • Both m1? and m2? are non-empty.

    • m1 is smaller than or equal to m2.

 n1n2{min n1,max m1?}{min n2,max ϵ}n1n2m1m2{min n1,max m1}{min n2,max m2}

Functions

An external type func functype1 matches func functype2 if and only if:

  • Both functype1 and functype2 are the same.

 func functypefunc functype

Tables

An external type table (limits1 reftype1) matches table (limits2 reftype2) if and only if:

  • Limits limits1 match limits2.

  • Both reftype1 and reftype2 are the same.

limits1limits2table (limits1 reftype)table (limits2 reftype)

Memories

An external type mem limits1 matches mem limits2 if and only if:

  • Limits limits1 match limits2.

limits1limits2mem limits1mem limits2

Globals

An external type global globaltype1 matches global globaltype2 if and only if:

  • Both globaltype1 and globaltype2 are the same.

 global globaltypeglobal globaltype