Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module.deserialize - accept AsEngineRef #3433

Merged
merged 4 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/api/src/sys/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,11 @@ impl Module {
/// # }
/// ```
pub unsafe fn deserialize(
store: &impl AsStoreRef,
engine: &impl AsEngineRef,
bytes: impl IntoBytes,
) -> Result<Self, DeserializeError> {
let bytes = bytes.into_bytes();
let artifact = store.as_store_ref().engine().deserialize(&bytes)?;
let artifact = engine.as_engine_ref().engine().deserialize(&bytes)?;
Ok(Self::from_artifact(artifact))
}

Expand All @@ -334,11 +334,11 @@ impl Module {
/// # }
/// ```
pub unsafe fn deserialize_from_file(
store: &impl AsStoreRef,
engine: &impl AsEngineRef,
path: impl AsRef<Path>,
) -> Result<Self, DeserializeError> {
let artifact = store
.as_store_ref()
let artifact = engine
.as_engine_ref()
.engine()
.deserialize_from_file(path.as_ref())?;
Ok(Self::from_artifact(artifact))
Expand Down
4 changes: 2 additions & 2 deletions lib/cache/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use crate::hash::Hash;
use std::error::Error;
use wasmer::{Module, Store};
use wasmer::{Module, AsEngineRef};

/// A generic cache for storing and loading compiled wasm modules.
pub trait Cache {
Expand All @@ -17,7 +17,7 @@ pub trait Cache {
///
/// # Safety
/// This function is unsafe as the cache store could be tampered with.
unsafe fn load(&self, store: &Store, key: Hash) -> Result<Module, Self::DeserializeError>;
unsafe fn load(&self, engine: &impl AsEngineRef, key: Hash) -> Result<Module, Self::DeserializeError>;

/// Store a [`Module`] into the cache with the given [`Hash`].
fn store(&mut self, key: Hash, module: &Module) -> Result<(), Self::SerializeError>;
Expand Down
6 changes: 3 additions & 3 deletions lib/cache/src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::hash::Hash;
use std::fs::{create_dir_all, File};
use std::io::{self, Write};
use std::path::PathBuf;
use wasmer::{DeserializeError, Module, SerializeError, Store};
use wasmer::{DeserializeError, Module, SerializeError, AsEngineRef};

/// Representation of a directory that contains compiled wasm artifacts.
///
Expand Down Expand Up @@ -91,14 +91,14 @@ impl Cache for FileSystemCache {
type DeserializeError = DeserializeError;
type SerializeError = SerializeError;

unsafe fn load(&self, store: &Store, key: Hash) -> Result<Module, Self::DeserializeError> {
unsafe fn load(&self, engine: &impl AsEngineRef, key: Hash) -> Result<Module, Self::DeserializeError> {
let filename = if let Some(ref ext) = self.ext {
format!("{}.{}", key.to_string(), ext)
} else {
key.to_string()
};
let path = self.path.join(filename);
Module::deserialize_from_file(store, path)
Module::deserialize_from_file(engine, path)
}

fn store(&mut self, key: Hash, module: &Module) -> Result<(), Self::SerializeError> {
Expand Down