Skip to content

Commit

Permalink
Upgrade to walrus 0.4
Browse files Browse the repository at this point in the history
Also be sure to have an explicit GC pass!
  • Loading branch information
alexcrichton committed Feb 19, 2019
1 parent 5b0cfd7 commit 8fb705a
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 24 deletions.
2 changes: 1 addition & 1 deletion crates/cli-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ failure = "0.1.2"
log = "0.4"
rustc-demangle = "0.1.13"
tempfile = "3.0"
walrus = "0.2.1"
walrus = "0.4.0"
wasm-bindgen-shared = { path = "../shared", version = '=0.2.37' }
wasm-bindgen-threads-xform = { path = '../threads-xform', version = '=0.2.37' }
wasm-bindgen-wasm-interpreter = { path = "../wasm-interpreter", version = '=0.2.37' }
1 change: 1 addition & 0 deletions crates/cli-support/src/js/closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ impl ClosureDescriptors {
let table = input.module.tables.get_mut(table_id);
let table = match &mut table.kind {
walrus::TableKind::Function(f) => f,
walrus::TableKind::Anyref(_) => unreachable!(),
};
for idx in self.element_removal_list.iter().cloned() {
log::trace!("delete element {}", idx);
Expand Down
14 changes: 5 additions & 9 deletions crates/cli-support/src/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ impl<'a> Context<'a> {

self.export_table()?;

walrus::passes::gc::run(self.module);

// Note that it's important `throw` comes last *after* we gc. The
// `__wbindgen_malloc` function may call this but we only want to
// generate code for this if it's actually live (and __wbindgen_malloc
Expand Down Expand Up @@ -871,16 +873,10 @@ impl<'a> Context<'a> {
if !self.function_table_needed {
return Ok(());
}
let mut tables = self.module.tables.iter().filter_map(|t| match t.kind {
walrus::TableKind::Function(_) => Some(t.id()),
});
let id = match tables.next() {
let id = match self.module.tables.main_function_table()? {
Some(id) => id,
None => return Ok(()),
None => bail!("no function table found in module"),
};
if tables.next().is_some() {
bail!("couldn't find function table to export");
}
self.module.exports.add("__wbg_function_table", id);
Ok(())
}
Expand Down Expand Up @@ -976,7 +972,7 @@ impl<'a> Context<'a> {
}
}
for id in to_remove {
self.module.exports.remove_root(id);
self.module.exports.delete(id);
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/cli-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl Bindgen {
// This means that whenever we encounter an import or export we'll
// execute a shim function which informs us about its type so we can
// then generate the appropriate bindings.
let mut instance = wasm_bindgen_wasm_interpreter::Interpreter::new(&module);
let mut instance = wasm_bindgen_wasm_interpreter::Interpreter::new(&module)?;

let mut memories = module.memories.iter().map(|m| m.id());
let memory = memories.next();
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ rouille = { version = "3.0.0", default-features = false }
serde = { version = "1.0", features = ['derive'] }
serde_derive = "1.0"
serde_json = "1.0"
walrus = "0.2"
walrus = "0.4"
wasm-bindgen-cli-support = { path = "../cli-support", version = "=0.2.37" }
wasm-bindgen-shared = { path = "../shared", version = "=0.2.37" }

Expand Down
2 changes: 1 addition & 1 deletion crates/threads-xform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ Support for threading-related transformations in wasm-bindgen
edition = "2018"

[dependencies]
walrus = "0.2"
failure = "0.1"
walrus = "0.4"
3 changes: 2 additions & 1 deletion crates/wasm-interpreter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ Micro-interpreter optimized for wasm-bindgen's use case
edition = '2018'

[dependencies]
walrus = "0.2"
failure = "0.1"
log = "0.4"
walrus = "0.4"

[dev-dependencies]
tempfile = "3"
17 changes: 8 additions & 9 deletions crates/wasm-interpreter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Interpreter {
///
/// Note that the `module` passed in to this function must be the same as
/// the `module` passed to `interpret` below.
pub fn new(module: &Module) -> Interpreter {
pub fn new(module: &Module) -> Result<Interpreter, failure::Error> {
let mut ret = Interpreter::default();

// The descriptor functions shouldn't really use all that much memory
Expand Down Expand Up @@ -102,14 +102,9 @@ impl Interpreter {
ret.name_map.insert(export.name.to_string(), id);
}

for table in module.tables.iter() {
match table.kind {
walrus::TableKind::Function(_) => {}
}
ret.functions = Some(table.id());
}
ret.functions = module.tables.main_function_table()?;

return ret;
return Ok(ret);
}

/// Interprets the execution of the descriptor function `func`.
Expand Down Expand Up @@ -204,6 +199,7 @@ impl Interpreter {
let functions = self.functions.expect("function table should be present");
let functions = match &module.tables.get(functions).kind {
walrus::TableKind::Function(f) => f,
_ => unreachable!(),
};
let descriptor_id = functions
.elements
Expand Down Expand Up @@ -348,8 +344,11 @@ impl Frame<'_> {

Expr::WithSideEffects(e) => {
log::debug!("side effects");
for x in e.before.iter() {
self.eval(*x);
}
let ret = self.eval(e.value);
for x in e.side_effects.iter() {
for x in e.after.iter() {
self.eval(*x);
}
return ret;
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm-interpreter/tests/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn interpret(wat: &str, name: &str, result: Option<&[u32]>) {
println!("status: {}", status);
assert!(status.success());
let module = walrus::Module::from_file(output.path()).unwrap();
let mut i = Interpreter::new(&module);
let mut i = Interpreter::new(&module).unwrap();
assert_eq!(i.interpret_descriptor(name, &module), result);
}

Expand Down

0 comments on commit 8fb705a

Please sign in to comment.