Skip to content

Commit

Permalink
Bump walrus from 0.21.0 to 0.21.1
Browse files Browse the repository at this point in the history
walrus 0.21.1 introduced breaking changes to add support for memory64.
New types are embraced while not adding memory64 support.

Signed-off-by: Scott Andrews <scott@andrews.me>
  • Loading branch information
scothis committed Aug 9, 2024
1 parent 3da2d18 commit 63b384d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ anyhow = "1"
clap = { version = "4", features = ["derive"] }
serde = { version = "1", features = ["derive"] }
toml = "0.8"
walrus = "0.21.0"
walrus = "0.21.1"
wasm-compose = "0.212.0"
wasm-metadata = "0.212.0"
wasm-opt = { version = "0.116.1", optional = true }
Expand Down
10 changes: 5 additions & 5 deletions src/data.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use anyhow::{bail, Result};
use std::collections::HashMap;
use walrus::{
ActiveData, ActiveDataLocation, ConstExpr, DataKind, ElementItems, ElementKind,
FunctionBuilder, FunctionId, FunctionKind, Module, RefType, ValType,
ir::Value, ConstExpr, DataKind, ElementItems, ElementKind, FunctionBuilder, FunctionId,
FunctionKind, Module, RefType, ValType,
};

use crate::walrus_ops::bump_stack_global;
Expand Down Expand Up @@ -121,10 +121,10 @@ impl Data {
}
bump_stack_global(module, (self.stack_start - self.stack_ptr) as i32)?;
module.data.add(
DataKind::Active(ActiveData {
DataKind::Active {
memory,
location: ActiveDataLocation::Absolute(self.stack_ptr as u32),
}),
offset: ConstExpr::Value(Value::I32(self.stack_ptr as i32)),
},
self.bytes.as_slice()[self.stack_ptr..self.stack_start].to_vec(),
);

Expand Down
10 changes: 4 additions & 6 deletions src/virt_env.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use anyhow::{bail, Context, Result};
use serde::Deserialize;
use walrus::{
ir::Value, ActiveData, ActiveDataLocation, ConstExpr, DataKind, ExportItem, GlobalKind, Module,
};
use walrus::{ir::Value, ConstExpr, DataKind, ExportItem, GlobalKind, Module};

use crate::walrus_ops::{bump_stack_global, get_active_data_segment};

Expand Down Expand Up @@ -146,10 +144,10 @@ pub(crate) fn create_env_virt<'a>(module: &'a mut Module, env: &VirtEnv) -> Resu

// Add a new data segment for this new range created at the top of the stack
module.data.add(
DataKind::Active(ActiveData {
DataKind::Active {
memory,
location: ActiveDataLocation::Absolute(field_data_addr),
}),
offset: ConstExpr::Value(Value::I32(field_data_addr as i32)),
},
field_data_bytes,
);
Some(field_data_addr)
Expand Down
22 changes: 10 additions & 12 deletions src/walrus_ops.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
use anyhow::{bail, Context, Result};
use walrus::{
ir::Value, ActiveData, ActiveDataLocation, ConstExpr, Data, DataKind, GlobalKind, MemoryId,
Module,
};
use walrus::{ir::Value, ConstExpr, Data, DataKind, GlobalKind, MemoryId, Module};

pub(crate) fn get_active_data_start(data: &Data, mem: MemoryId) -> Result<u32> {
let DataKind::Active(active_data) = &data.kind else {
let DataKind::Active { memory, offset } = &data.kind else {
bail!("Adapter data section is not active");
};
if active_data.memory != mem {
if *memory != mem {
bail!("Adapter data memory is not the expected memory id");
}
let ActiveDataLocation::Absolute(loc) = &active_data.location else {
let ConstExpr::Value(Value::I32(loc)) = offset else {
bail!("Adapter data memory is not absolutely offset");
};
Ok(*loc)
Ok(*loc as u32)
}

pub(crate) fn get_active_data_segment(
Expand All @@ -36,15 +33,16 @@ pub(crate) fn get_active_data_segment(
}
}
let data = found_data.context("Unable to find data section for ptr")?;
let DataKind::Active(ActiveData {
location: ActiveDataLocation::Absolute(loc),
let DataKind::Active {
offset: ConstExpr::Value(Value::I32(loc)),
..
}) = &data.kind
} = &data.kind
else {
unreachable!()
};
let loc = *loc as u32;
let data_id = data.id();
let offset = (addr - *loc) as usize;
let offset = (addr - loc) as usize;
Ok((module.data.get_mut(data_id), offset))
}

Expand Down

0 comments on commit 63b384d

Please sign in to comment.