Module indices

Module indices 

Source
Expand description

§Type-safe Indices and Index Spaces

Wasm specifies different classes of definitions (types, functions, globals, …). Each definition can be uniquely addressed by a single index represented as a 32-bit integer. For every definition class, there exists a separate index space, along with a special index type per class: typeidx for types, funcidx for functions, etc.

Using u32 and Vec types to represent such indices and index spaces across all classes of definitions comes with risks.

This module defines one newtype index type per definition class (e.g. TypeIdx, FuncIdx, GlobalIdx) and an index space IdxVec.

Additionally, the ExtendedIdxVec type is defined as to provide more methods on an IdxVec that consists of imported and locally-defined objects, i.e. functions, globals, tables and memories.

§What this module is not

However, this module cannot ensure that an index type is always used for the IdxVec it originally came from. Imagine a scenario, in which multiple Wasm modules are used. Even though it would not make any sense to use indices across multiple index spaces of the same definition class, detecting such mis-use is out of the scope of this module.

Instead, the caller must guarantee that indices are only used together with the correct index space. These guarantees are documented in the form of safety requirements.

See: WebAssembly Specification - 2.5.1 - Indices

Structs§

DataIdx
ElemIdx
ExtendedIdxVec
Index space for definitions that consist of imports and locals.
FuncIdx
GlobalIdx
IdxVec
An immutable vector that can only be indexed by type-safe 32-bit indices.
IdxVecOverflowError
An error for when an IdxVec is initialized with too many elements.
LocalIdx
MemIdx
TableIdx
TypeIdx
A type index that is used to index into the types index space of some Wasm module or module instance.

Traits§

Idx
A trait for all index types.

Functions§

read_label_idx
Reads a label index from Wasm code without validating it.
read_label_idx_unchecked
Reads a label index from Wasm code without validating it.