Skip to content

Commit

Permalink
Add a VMComponentContext type and create it on instantiation (#4215)
Browse files Browse the repository at this point in the history
* Add a `VMComponentContext` type and create it on instantiation

This commit fills out the `wasmtime-runtime` crate's support for
`VMComponentContext` and creates it as part of the instantiation
process. This moves a few maps that were temporarily allocated in an
`InstanceData` into the `VMComponentContext` and additionally reads the
canonical options data from there instead.

This type still won't be used in its "full glory" until the lowering of
host functions is completely implemented, however, which will be coming
in a future commit.

* Remove `DerefMut` implementation

* Rebase conflicts
  • Loading branch information
alexcrichton authored Jun 3, 2022
1 parent 4c1339a commit 2af358d
Show file tree
Hide file tree
Showing 9 changed files with 537 additions and 48 deletions.
14 changes: 12 additions & 2 deletions crates/environ/src/component/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,21 @@ pub enum Initializer {
/// previously created module instance, and stored into the
/// `VMComponentContext` at the `index` specified. This lowering is then
/// used in the future by pointers from `CanonicalOptions`.
ExtractMemory(CoreExport<MemoryIndex>),
ExtractMemory {
/// The index of the memory being defined.
index: RuntimeMemoryIndex,
/// Where this memory is being extracted from.
export: CoreExport<MemoryIndex>,
},

/// Same as `ExtractMemory`, except it's extracting a function pointer to be
/// used as a `realloc` function.
ExtractRealloc(CoreDef),
ExtractRealloc {
/// The index of the realloc being defined.
index: RuntimeReallocIndex,
/// Where this realloc is being extracted from.
def: CoreDef,
},

/// The `module` specified is saved into the runtime state at the next
/// `RuntimeModuleIndex`, referred to later by `Export` definitions.
Expand Down
4 changes: 2 additions & 2 deletions crates/environ/src/component/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ impl<'a, 'data> Translator<'a, 'data> {
self.result
.component
.initializers
.push(Initializer::ExtractMemory(export));
.push(Initializer::ExtractMemory { index, export });
index
}

Expand All @@ -1041,7 +1041,7 @@ impl<'a, 'data> Translator<'a, 'data> {
self.result
.component
.initializers
.push(Initializer::ExtractRealloc(def));
.push(Initializer::ExtractRealloc { index, def });
index
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ pooling-allocator = []
# It is useful for applications that do not bind their own exception ports and
# need portable signal handling.
posix-signals-on-macos = []

component-model = ["wasmtime-environ/component-model"]
Loading

0 comments on commit 2af358d

Please sign in to comment.