Skip to content

Commit cb44aa6

Browse files
authored
Require T: 'static for Store, upgrade to wasmtime_runtime_layer v34.0.0 (#54)
1 parent d84d606 commit cb44aa6

11 files changed

Lines changed: 150 additions & 151 deletions

File tree

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fxhash = { version = "0.2", default-features = false }
1313
hashbrown = { version = "0.15", default-features = false }
1414
ref-cast = { version = "1.0", default-features = false }
1515
smallvec = { version = "1.11", default-features = false }
16-
wasm_runtime_layer = { path = ".", version = "0.5", default-features = false }
16+
wasm_runtime_layer = { path = ".", version = "0.6", default-features = false }
1717

1818
[workspace.package]
1919
edition = "2021"
@@ -22,7 +22,7 @@ repository = "https://github.com/DouglasDwyer/wasm_runtime_layer"
2222

2323
[package]
2424
name = "wasm_runtime_layer"
25-
version = "0.5.0"
25+
version = "0.6.0"
2626
edition = { workspace = true }
2727
license = { workspace = true }
2828
repository = { workspace = true }
@@ -43,15 +43,15 @@ default = [ "std" ]
4343
std = [ "anyhow/std" ]
4444

4545
[dev-dependencies]
46-
js_wasm_runtime_layer = { version = "0.5", path = "backends/js_wasm_runtime_layer" }
46+
js_wasm_runtime_layer = { version = "0.6", path = "backends/js_wasm_runtime_layer" }
4747
wasmi_runtime_layer = { version = "0.47", path = "backends/wasmi_runtime_layer" }
4848
wasm-bindgen-test = { version = "0.3" }
4949
wat = { version = "1.0" }
5050

5151
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
5252
wasmer_runtime_layer = { version = "6.0", path = "backends/wasmer_runtime_layer" }
53-
wasmtime = { version = "33.0", default-features = false, features = [ "gc-null" ] }
54-
wasmtime_runtime_layer = { version = "33.0", path = "backends/wasmtime_runtime_layer" }
53+
wasmtime = { version = "34.0", default-features = false, features = [ "gc-null" ] }
54+
wasmtime_runtime_layer = { version = "34.0", path = "backends/wasmtime_runtime_layer" }
5555

5656
[package.metadata."docs.rs"]
5757
all-features = true

backends/js_wasm_runtime_layer/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "js_wasm_runtime_layer"
3-
version = "0.5.0"
3+
version = "0.6.0"
44
edition = { workspace = true }
55
license = { workspace = true }
66
repository = { workspace = true }

backends/js_wasm_runtime_layer/src/func.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ macro_rules! func_wrapper {
102102
}
103103

104104
impl WasmFunc<Engine> for Func {
105-
fn new<T>(
105+
fn new<T: 'static>(
106106
mut ctx: impl AsContextMut<Engine, UserState = T>,
107107
ty: FuncType,
108108
func: impl 'static

backends/js_wasm_runtime_layer/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ impl WasmEngine for Engine {
9696
type Instance = Instance;
9797
type Memory = Memory;
9898
type Module = Module;
99-
type Store<T> = Store<T>;
100-
type StoreContext<'a, T: 'a> = StoreContext<'a, T>;
101-
type StoreContextMut<'a, T: 'a> = StoreContextMut<'a, T>;
99+
type Store<T: 'static> = Store<T>;
100+
type StoreContext<'a, T: 'static> = StoreContext<'a, T>;
101+
type StoreContextMut<'a, T: 'static> = StoreContextMut<'a, T>;
102102
type Table = Table;
103103
}
104104

@@ -332,7 +332,7 @@ impl WasmExternRef<Engine> for ExternRef {
332332
unimplemented!("ExternRef is not supported in the js_wasm_runtime_layer backend")
333333
}
334334

335-
fn downcast<'a, 's: 'a, T: 'static, S: 's>(
335+
fn downcast<'a, 's: 'a, T: 'static, S: 'static>(
336336
&self,
337337
_: <Engine as WasmEngine>::StoreContext<'s, S>,
338338
) -> anyhow::Result<&'a T> {

backends/js_wasm_runtime_layer/src/store.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::{
2222
/// no-longer used modules. It is as such recommended to have the stores lifetime correspond to its
2323
/// modules, and not repeatedly create and drop modules within an existing store, but rather create
2424
/// a new store for it, to avoid unbounded memory use.
25-
pub struct Store<T> {
25+
pub struct Store<T: 'static> {
2626
/// The internal store is kept behind a pointer.
2727
///
2828
/// This is to allow referencing and reconstructing a calling context in exported functions,
@@ -58,7 +58,7 @@ pub struct Store<T> {
5858
inner: *mut StoreInner<T>,
5959
}
6060

61-
impl<T> Store<T> {
61+
impl<T: 'static> Store<T> {
6262
/// Creates a new store from the inner box
6363
fn from_inner(inner: Box<StoreInner<T>>) -> Self {
6464
Self {
@@ -85,13 +85,13 @@ impl<T> Store<T> {
8585
}
8686
}
8787

88-
impl<T> Drop for Store<T> {
88+
impl<T: 'static> Drop for Store<T> {
8989
fn drop(&mut self) {
9090
unsafe { drop(Box::from_raw(self.inner)) }
9191
}
9292
}
9393

94-
impl<T> WasmStore<T, Engine> for Store<T> {
94+
impl<T: 'static> WasmStore<T, Engine> for Store<T> {
9595
fn new(engine: &Engine, data: T) -> Self {
9696
#[cfg(feature = "tracing")]
9797
let _span = tracing::debug_span!("Store::new").entered();
@@ -135,29 +135,29 @@ impl<T> WasmStore<T, Engine> for Store<T> {
135135
}
136136
}
137137

138-
impl<T> AsContext<Engine> for Store<T> {
138+
impl<T: 'static> AsContext<Engine> for Store<T> {
139139
type UserState = T;
140140

141141
fn as_context(&self) -> <Engine as WasmEngine>::StoreContext<'_, Self::UserState> {
142142
self.get()
143143
}
144144
}
145145

146-
impl<T> AsContextMut<Engine> for Store<T> {
146+
impl<T: 'static> AsContextMut<Engine> for Store<T> {
147147
fn as_context_mut(&mut self) -> StoreContextMut<T> {
148148
self.get_mut()
149149
}
150150
}
151151

152-
impl<T: fmt::Debug> fmt::Debug for Store<T> {
152+
impl<T: 'static + fmt::Debug> fmt::Debug for Store<T> {
153153
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
154154
self.inner.fmt(f)
155155
}
156156
}
157157

158158
#[derive(Debug)]
159159
/// Holds the inner state of the store
160-
pub struct StoreInner<T> {
160+
pub struct StoreInner<T: 'static> {
161161
/// The engine used
162162
pub(crate) engine: Engine,
163163
/// Instances are not Send + Sync
@@ -181,7 +181,7 @@ pub struct StoreInner<T> {
181181
drop_resources: Vec<DropResource>,
182182
}
183183

184-
impl<T> StoreInner<T> {
184+
impl<T: 'static> StoreInner<T> {
185185
/// Inserts a new function and returns its id
186186
pub(crate) fn insert_func(&mut self, func: FuncInner) -> Func {
187187
Func {
@@ -225,19 +225,19 @@ impl<T> StoreInner<T> {
225225
}
226226

227227
/// Immutable context to the store
228-
pub struct StoreContext<'a, T: 'a> {
228+
pub struct StoreContext<'a, T: 'static> {
229229
/// The store
230230
store: &'a StoreInner<T>,
231231
}
232232

233-
impl<'a, T: 'a> StoreContext<'a, T> {
233+
impl<'a, T: 'static> StoreContext<'a, T> {
234234
/// Provides a store context from a reference
235235
pub fn from_ref(store: &'a StoreInner<T>) -> Self {
236236
Self { store }
237237
}
238238
}
239239

240-
impl<T> Deref for StoreContext<'_, T> {
240+
impl<T: 'static> Deref for StoreContext<'_, T> {
241241
type Target = StoreInner<T>;
242242

243243
fn deref(&self) -> &Self::Target {
@@ -246,12 +246,12 @@ impl<T> Deref for StoreContext<'_, T> {
246246
}
247247

248248
/// Mutable context to the store
249-
pub struct StoreContextMut<'a, T: 'a> {
249+
pub struct StoreContextMut<'a, T: 'static> {
250250
/// The store
251251
store: &'a mut StoreInner<T>,
252252
}
253253

254-
impl<'a, T: 'a> StoreContextMut<'a, T> {
254+
impl<'a, T: 'static> StoreContextMut<'a, T> {
255255
/// Returns a pointer to the inner store
256256
pub(crate) fn as_ptr(&mut self) -> *mut StoreInner<T> {
257257
self.store as *mut _
@@ -263,21 +263,21 @@ impl<'a, T: 'a> StoreContextMut<'a, T> {
263263
}
264264
}
265265

266-
impl<T> Deref for StoreContextMut<'_, T> {
266+
impl<T: 'static> Deref for StoreContextMut<'_, T> {
267267
type Target = StoreInner<T>;
268268

269269
fn deref(&self) -> &Self::Target {
270270
&*self.store
271271
}
272272
}
273273

274-
impl<T> DerefMut for StoreContextMut<'_, T> {
274+
impl<T: 'static> DerefMut for StoreContextMut<'_, T> {
275275
fn deref_mut(&mut self) -> &mut Self::Target {
276276
&mut *self.store
277277
}
278278
}
279279

280-
impl<'a, T: 'a> WasmStoreContext<'a, T, Engine> for StoreContext<'a, T> {
280+
impl<'a, T: 'static> WasmStoreContext<'a, T, Engine> for StoreContext<'a, T> {
281281
fn engine(&self) -> &Engine {
282282
&self.engine
283283
}
@@ -287,15 +287,15 @@ impl<'a, T: 'a> WasmStoreContext<'a, T, Engine> for StoreContext<'a, T> {
287287
}
288288
}
289289

290-
impl<'a, T: 'a> AsContext<Engine> for StoreContext<'a, T> {
290+
impl<'a, T: 'static> AsContext<Engine> for StoreContext<'a, T> {
291291
type UserState = T;
292292

293293
fn as_context(&self) -> StoreContext<'_, T> {
294294
StoreContext { store: self.store }
295295
}
296296
}
297297

298-
impl<'a, T: 'a> WasmStoreContext<'a, T, Engine> for StoreContextMut<'a, T> {
298+
impl<'a, T: 'static> WasmStoreContext<'a, T, Engine> for StoreContextMut<'a, T> {
299299
fn engine(&self) -> &Engine {
300300
&self.engine
301301
}
@@ -305,21 +305,21 @@ impl<'a, T: 'a> WasmStoreContext<'a, T, Engine> for StoreContextMut<'a, T> {
305305
}
306306
}
307307

308-
impl<'a, T: 'a> WasmStoreContextMut<'a, T, Engine> for StoreContextMut<'a, T> {
308+
impl<'a, T: 'static> WasmStoreContextMut<'a, T, Engine> for StoreContextMut<'a, T> {
309309
fn data_mut(&mut self) -> &mut T {
310310
&mut self.data
311311
}
312312
}
313313

314-
impl<'a, T: 'a> AsContext<Engine> for StoreContextMut<'a, T> {
314+
impl<'a, T: 'static> AsContext<Engine> for StoreContextMut<'a, T> {
315315
type UserState = T;
316316

317317
fn as_context(&self) -> <Engine as WasmEngine>::StoreContext<'_, T> {
318318
StoreContext { store: self.store }
319319
}
320320
}
321321

322-
impl<'a, T: 'a> AsContextMut<Engine> for StoreContextMut<'a, T> {
322+
impl<'a, T: 'static> AsContextMut<Engine> for StoreContextMut<'a, T> {
323323
fn as_context_mut(&mut self) -> StoreContextMut<'_, T> {
324324
StoreContextMut { store: self.store }
325325
}

0 commit comments

Comments
 (0)