A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
wasmtime-wizer: add type_hints to global_get (#12314)
Gentle5913761e9dc9
diff --git a/crates/wizer/src/component/snapshot.rs b/crates/wizer/src/component/snapshot.rsindex a78e86dc7a..b874217d0a 100644--- a/crates/wizer/src/component/snapshot.rs+++ b/crates/wizer/src/component/snapshot.rs@@ -1,3 +1,5 @@+use wasmparser::ValType;+use crate::component::info::Accessor;use crate::component::{ComponentContext, ComponentInstanceState, WIZER_INSTANCE};use crate::snapshot::Snapshot;@@ -80,7 +82,7 @@ impl<S> InstanceState for ViaComponent<'_, '_, S>whereS: ComponentInstanceState,{- async fn global_get(&mut self, name: &str) -> SnapshotVal {+ async fn global_get(&mut self, name: &str, _: ValType) -> SnapshotVal {let Accessor::Global {accessor_export_name,ty,diff --git a/crates/wizer/src/lib.rs b/crates/wizer/src/lib.rsindex 0f289c0be3..9bc27df3c3 100644--- a/crates/wizer/src/lib.rs+++ b/crates/wizer/src/lib.rs@@ -24,6 +24,7 @@ pub use crate::info::ModuleContext;pub use crate::snapshot::SnapshotVal;use ::wasmtime::{Result, bail, error::Context as _};use std::collections::{HashMap, HashSet};+pub use wasmparser::ValType;const DEFAULT_KEEP_INIT_FUNC: bool = false;@@ -377,7 +378,11 @@ pub trait InstanceState {////// This function panics if `name` isn't an exported global or if the type/// of the global doesn't fit in `SnapshotVal`.- fn global_get(&mut self, name: &str) -> impl Future<Output = SnapshotVal> + Send;+ fn global_get(+ &mut self,+ name: &str,+ type_hint: ValType,+ ) -> impl Future<Output = SnapshotVal> + Send;/// Loads the contents of the memory specified by `name`, returning the/// entier contents as a `Vec<u8>`.diff --git a/crates/wizer/src/snapshot.rs b/crates/wizer/src/snapshot.rsindex cbd246770d..ecebec9c4f 100644--- a/crates/wizer/src/snapshot.rs+++ b/crates/wizer/src/snapshot.rs@@ -75,9 +75,11 @@ async fn snapshot_globals(log::debug!("Snapshotting global values");let mut ret = Vec::new();- for (i, name) in module.defined_global_exports.as_ref().unwrap().iter() {- let val = ctx.global_get(&name).await;- ret.push((*i, val));+ for (i, ty, name) in module.defined_globals() {+ if let Some(name) = name {+ let val = ctx.global_get(name, ty.content_type).await;+ ret.push((i, val));+ }}ret}diff --git a/crates/wizer/src/wasmtime.rs b/crates/wizer/src/wasmtime.rsindex fe8ae2be3d..7ce9fd6e1b 100644--- a/crates/wizer/src/wasmtime.rs+++ b/crates/wizer/src/wasmtime.rs@@ -1,5 +1,7 @@use crate::{InstanceState, SnapshotVal, Wizer};+use wasmparser::ValType;use wasmtime::error::Context;+use wasmtime::{Extern, Instance, Module, Result, Store, Val};impl Wizer {@@ -93,7 +95,7 @@ pub struct WasmtimeWizer<'a, T: 'static> {}impl<T: Send> InstanceState for WasmtimeWizer<'_, T> {- async fn global_get(&mut self, name: &str) -> SnapshotVal {+ async fn global_get(&mut self, name: &str, _: ValType) -> SnapshotVal {let global = self.instance.get_global(&mut *self.store, name).unwrap();match global.get(&mut *self.store) {Val::I32(x) => SnapshotVal::I32(x),