Skip to content

Commit e66de7b

Browse files
authored
Merge pull request #1277 from alexcrichton/upgrade-walrus
Upgrade to walrus 0.4
2 parents 5b0cfd7 + 8fb705a commit e66de7b

File tree

9 files changed

+21
-24
lines changed

9 files changed

+21
-24
lines changed

crates/cli-support/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ failure = "0.1.2"
1717
log = "0.4"
1818
rustc-demangle = "0.1.13"
1919
tempfile = "3.0"
20-
walrus = "0.2.1"
20+
walrus = "0.4.0"
2121
wasm-bindgen-shared = { path = "../shared", version = '=0.2.37' }
2222
wasm-bindgen-threads-xform = { path = '../threads-xform', version = '=0.2.37' }
2323
wasm-bindgen-wasm-interpreter = { path = "../wasm-interpreter", version = '=0.2.37' }

crates/cli-support/src/js/closures.rs

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ impl ClosureDescriptors {
142142
let table = input.module.tables.get_mut(table_id);
143143
let table = match &mut table.kind {
144144
walrus::TableKind::Function(f) => f,
145+
walrus::TableKind::Anyref(_) => unreachable!(),
145146
};
146147
for idx in self.element_removal_list.iter().cloned() {
147148
log::trace!("delete element {}", idx);

crates/cli-support/src/js/mod.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,8 @@ impl<'a> Context<'a> {
536536

537537
self.export_table()?;
538538

539+
walrus::passes::gc::run(self.module);
540+
539541
// Note that it's important `throw` comes last *after* we gc. The
540542
// `__wbindgen_malloc` function may call this but we only want to
541543
// generate code for this if it's actually live (and __wbindgen_malloc
@@ -871,16 +873,10 @@ impl<'a> Context<'a> {
871873
if !self.function_table_needed {
872874
return Ok(());
873875
}
874-
let mut tables = self.module.tables.iter().filter_map(|t| match t.kind {
875-
walrus::TableKind::Function(_) => Some(t.id()),
876-
});
877-
let id = match tables.next() {
876+
let id = match self.module.tables.main_function_table()? {
878877
Some(id) => id,
879-
None => return Ok(()),
878+
None => bail!("no function table found in module"),
880879
};
881-
if tables.next().is_some() {
882-
bail!("couldn't find function table to export");
883-
}
884880
self.module.exports.add("__wbg_function_table", id);
885881
Ok(())
886882
}
@@ -976,7 +972,7 @@ impl<'a> Context<'a> {
976972
}
977973
}
978974
for id in to_remove {
979-
self.module.exports.remove_root(id);
975+
self.module.exports.delete(id);
980976
}
981977
}
982978

crates/cli-support/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ impl Bindgen {
202202
// This means that whenever we encounter an import or export we'll
203203
// execute a shim function which informs us about its type so we can
204204
// then generate the appropriate bindings.
205-
let mut instance = wasm_bindgen_wasm_interpreter::Interpreter::new(&module);
205+
let mut instance = wasm_bindgen_wasm_interpreter::Interpreter::new(&module)?;
206206

207207
let mut memories = module.memories.iter().map(|m| m.id());
208208
let memory = memories.next();

crates/cli/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ rouille = { version = "3.0.0", default-features = false }
2424
serde = { version = "1.0", features = ['derive'] }
2525
serde_derive = "1.0"
2626
serde_json = "1.0"
27-
walrus = "0.2"
27+
walrus = "0.4"
2828
wasm-bindgen-cli-support = { path = "../cli-support", version = "=0.2.37" }
2929
wasm-bindgen-shared = { path = "../shared", version = "=0.2.37" }
3030

crates/threads-xform/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ Support for threading-related transformations in wasm-bindgen
1212
edition = "2018"
1313

1414
[dependencies]
15-
walrus = "0.2"
1615
failure = "0.1"
16+
walrus = "0.4"

crates/wasm-interpreter/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ Micro-interpreter optimized for wasm-bindgen's use case
1212
edition = '2018'
1313

1414
[dependencies]
15-
walrus = "0.2"
15+
failure = "0.1"
1616
log = "0.4"
17+
walrus = "0.4"
1718

1819
[dev-dependencies]
1920
tempfile = "3"

crates/wasm-interpreter/src/lib.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl Interpreter {
6464
///
6565
/// Note that the `module` passed in to this function must be the same as
6666
/// the `module` passed to `interpret` below.
67-
pub fn new(module: &Module) -> Interpreter {
67+
pub fn new(module: &Module) -> Result<Interpreter, failure::Error> {
6868
let mut ret = Interpreter::default();
6969

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

105-
for table in module.tables.iter() {
106-
match table.kind {
107-
walrus::TableKind::Function(_) => {}
108-
}
109-
ret.functions = Some(table.id());
110-
}
105+
ret.functions = module.tables.main_function_table()?;
111106

112-
return ret;
107+
return Ok(ret);
113108
}
114109

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

349345
Expr::WithSideEffects(e) => {
350346
log::debug!("side effects");
347+
for x in e.before.iter() {
348+
self.eval(*x);
349+
}
351350
let ret = self.eval(e.value);
352-
for x in e.side_effects.iter() {
351+
for x in e.after.iter() {
353352
self.eval(*x);
354353
}
355354
return ret;

crates/wasm-interpreter/tests/smoke.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn interpret(wat: &str, name: &str, result: Option<&[u32]>) {
1616
println!("status: {}", status);
1717
assert!(status.success());
1818
let module = walrus::Module::from_file(output.path()).unwrap();
19-
let mut i = Interpreter::new(&module);
19+
let mut i = Interpreter::new(&module).unwrap();
2020
assert_eq!(i.interpret_descriptor(name, &module), result);
2121
}
2222

0 commit comments

Comments
 (0)