pub struct CompiledFunctionsTable { /* private fields */ }
Expand description
A table describing the set of functions compiled into an artifact, their locations within the text section, and etc…
Logically, this type is a map from a FuncKey
to the associated function’s
- location within the associated text section, and
- optional source location.
How this map is actually implemented is with a series of lookup and binary search tables, split out in a data-oriented, struct-of-arrays style. We organize the data in this way is service of three goals:
-
Provide fast look ups: We need to look up the metadata for a function by its key at runtime. During instantiation, for example, we need to create
VMFuncRef
s for escaping functions and this requires looking up the locations of those Wasm functions and their associated array-to-Wasm trampolines. -
Keep memory overheads low and code size small: This type is serialized into all of our ELF artifacts and deserialized into all
Module
s andComponent
s at runtime. -
Be generic over any kind of function (whether defined Wasm function, trampoline, or etc…) that we compile: Adding a new kind of trampoline, for example, should not require updating this structure to add a new table of the function locations for just trampolines of that new kind. We should be able to store and query all kinds of functions uniformly.
Implementations§
Source§impl CompiledFunctionsTable
impl CompiledFunctionsTable
Sourcepub fn func_loc(&self, key: FuncKey) -> Option<&FunctionLoc>
pub fn func_loc(&self, key: FuncKey) -> Option<&FunctionLoc>
Get the location of the function associated with the given key
inside
the text section, if any.
Sourcepub fn src_loc(&self, key: FuncKey) -> Option<FilePos>
pub fn src_loc(&self, key: FuncKey) -> Option<FilePos>
Get the initial source location of the function associated with the
given key
, if any.
Sourcepub fn func_by_text_offset(&self, text_offset: u32) -> Option<FuncKey>
pub fn func_by_text_offset(&self, text_offset: u32) -> Option<FuncKey>
Given an offset into the text section, get the key for its associated function and its offset within that function.