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

Recompute Memory::ty, make it return by value #2293

Merged
merged 3 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Looking for changes that affect our C API? See the [C API Changelog](lib/c-api/C
- [#2135](https://github.com/wasmerio/wasmer/pull/2135) [Documentation](./PACKAGING.md) for linux distribution maintainers

### Changed
- [#2293](https://github.com/wasmerio/wasmer/pull/2293) The `Memory::ty` trait method now returns `MemoryType` by value. `wasmer_vm::LinearMemory` now recomputes `MemoryType`'s `minimum` field when accessing its type. This behavior is what's expected by the latest spectests. `wasmer::Memory::ty` has also been updated to follow suit, it now returns `MemoryType` by value.
- [#2251](https://github.com/wasmerio/wasmer/pull/2251) Wasmer CLI will now execute WASI modules with multiple WASI namespaces in them by default. Use `--allow-multiple-wasi-versions` to suppress the warning and use `--deny-multiple-wasi-versions` to make it an error.
- [#2201](https://github.com/wasmerio/wasmer/pull/2201) Implement `loupe::MemoryUsage` for `wasmer::Instance`.
- [#2200](https://github.com/wasmerio/wasmer/pull/2200) Implement `loupe::MemoryUsage` for `wasmer::Module`.
Expand Down
2 changes: 1 addition & 1 deletion lib/api/src/externals/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Memory {
///
/// assert_eq!(m.ty(), &mt);
/// ```
pub fn ty(&self) -> &MemoryType {
pub fn ty(&self) -> MemoryType {
self.vm_memory.from.ty()
}

Expand Down
2 changes: 1 addition & 1 deletion lib/api/src/externals/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Extern {
pub fn ty(&self) -> ExternType {
match self {
Self::Function(ft) => ExternType::Function(ft.ty().clone()),
Self::Memory(ft) => ExternType::Memory(*ft.ty()),
Self::Memory(ft) => ExternType::Memory(ft.ty()),
Self::Table(tt) => ExternType::Table(*tt.ty()),
Self::Global(gt) => ExternType::Global(*gt.ty()),
}
Expand Down
6 changes: 3 additions & 3 deletions lib/api/tests/externals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ fn memory_new() -> Result<()> {
};
let memory = Memory::new(&store, memory_type)?;
assert_eq!(memory.size(), Pages(0));
assert_eq!(*memory.ty(), memory_type);
assert_eq!(memory.ty(), memory_type);
Ok(())
}

Expand Down Expand Up @@ -209,7 +209,7 @@ fn function_new() -> Result<()> {
fn function_new_env() -> Result<()> {
let store = Store::default();
#[derive(Clone, WasmerEnv)]
struct MyEnv {};
struct MyEnv {}

let my_env = MyEnv {};
let function = Function::new_native_with_env(&store, my_env.clone(), |_env: &MyEnv| {});
Expand Down Expand Up @@ -281,7 +281,7 @@ fn function_new_dynamic() -> Result<()> {
fn function_new_dynamic_env() -> Result<()> {
let store = Store::default();
#[derive(Clone, WasmerEnv)]
struct MyEnv {};
struct MyEnv {}
let my_env = MyEnv {};

// Using &FunctionType signature
Expand Down
2 changes: 1 addition & 1 deletion lib/engine/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn get_extern_from_export(_module: &ModuleInfo, export: &Export) -> ExternType {
match export {
Export::Function(ref f) => ExternType::Function(f.vm_function.signature.clone()),
Export::Table(ref t) => ExternType::Table(*t.ty()),
Export::Memory(ref m) => ExternType::Memory(*m.ty()),
Export::Memory(ref m) => ExternType::Memory(m.ty()),
Export::Global(ref g) => {
let global = g.from.ty();
ExternType::Global(*global)
Expand Down
2 changes: 1 addition & 1 deletion lib/vm/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ unsafe impl Sync for VMMemory {}

impl VMMemory {
/// Get the type for this exported memory
pub fn ty(&self) -> &MemoryType {
pub fn ty(&self) -> MemoryType {
self.from.ty()
}

Expand Down
10 changes: 7 additions & 3 deletions lib/vm/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl MemoryStyle {
/// Trait for implementing Wasm Memory used by Wasmer.
pub trait Memory: fmt::Debug + Send + Sync + MemoryUsage {
/// Returns the memory type for this memory.
fn ty(&self) -> &MemoryType;
fn ty(&self) -> MemoryType;

/// Returns the memory style for this memory.
fn style(&self) -> &MemoryStyle;
Expand Down Expand Up @@ -310,8 +310,12 @@ impl LinearMemory {

impl Memory for LinearMemory {
/// Returns the type for this memory.
fn ty(&self) -> &MemoryType {
&self.memory
fn ty(&self) -> MemoryType {
let minimum = self.size();
let mut out = self.memory.clone();
out.minimum = minimum;

out
}

/// Returns the memory style for this memory.
Expand Down