mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-31 01:11:06 +00:00
Upgrade to walrus 0.4
Also be sure to have an explicit GC pass!
This commit is contained in:
parent
5b0cfd7cea
commit
8fb705a1ef
@ -17,7 +17,7 @@ failure = "0.1.2"
|
|||||||
log = "0.4"
|
log = "0.4"
|
||||||
rustc-demangle = "0.1.13"
|
rustc-demangle = "0.1.13"
|
||||||
tempfile = "3.0"
|
tempfile = "3.0"
|
||||||
walrus = "0.2.1"
|
walrus = "0.4.0"
|
||||||
wasm-bindgen-shared = { path = "../shared", version = '=0.2.37' }
|
wasm-bindgen-shared = { path = "../shared", version = '=0.2.37' }
|
||||||
wasm-bindgen-threads-xform = { path = '../threads-xform', 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' }
|
wasm-bindgen-wasm-interpreter = { path = "../wasm-interpreter", version = '=0.2.37' }
|
||||||
|
@ -142,6 +142,7 @@ impl ClosureDescriptors {
|
|||||||
let table = input.module.tables.get_mut(table_id);
|
let table = input.module.tables.get_mut(table_id);
|
||||||
let table = match &mut table.kind {
|
let table = match &mut table.kind {
|
||||||
walrus::TableKind::Function(f) => f,
|
walrus::TableKind::Function(f) => f,
|
||||||
|
walrus::TableKind::Anyref(_) => unreachable!(),
|
||||||
};
|
};
|
||||||
for idx in self.element_removal_list.iter().cloned() {
|
for idx in self.element_removal_list.iter().cloned() {
|
||||||
log::trace!("delete element {}", idx);
|
log::trace!("delete element {}", idx);
|
||||||
|
@ -536,6 +536,8 @@ impl<'a> Context<'a> {
|
|||||||
|
|
||||||
self.export_table()?;
|
self.export_table()?;
|
||||||
|
|
||||||
|
walrus::passes::gc::run(self.module);
|
||||||
|
|
||||||
// Note that it's important `throw` comes last *after* we gc. The
|
// Note that it's important `throw` comes last *after* we gc. The
|
||||||
// `__wbindgen_malloc` function may call this but we only want to
|
// `__wbindgen_malloc` function may call this but we only want to
|
||||||
// generate code for this if it's actually live (and __wbindgen_malloc
|
// generate code for this if it's actually live (and __wbindgen_malloc
|
||||||
@ -871,16 +873,10 @@ impl<'a> Context<'a> {
|
|||||||
if !self.function_table_needed {
|
if !self.function_table_needed {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let mut tables = self.module.tables.iter().filter_map(|t| match t.kind {
|
let id = match self.module.tables.main_function_table()? {
|
||||||
walrus::TableKind::Function(_) => Some(t.id()),
|
|
||||||
});
|
|
||||||
let id = match tables.next() {
|
|
||||||
Some(id) => id,
|
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);
|
self.module.exports.add("__wbg_function_table", id);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -976,7 +972,7 @@ impl<'a> Context<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for id in to_remove {
|
for id in to_remove {
|
||||||
self.module.exports.remove_root(id);
|
self.module.exports.delete(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ impl Bindgen {
|
|||||||
// This means that whenever we encounter an import or export we'll
|
// 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
|
// execute a shim function which informs us about its type so we can
|
||||||
// then generate the appropriate bindings.
|
// 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 mut memories = module.memories.iter().map(|m| m.id());
|
||||||
let memory = memories.next();
|
let memory = memories.next();
|
||||||
|
@ -24,7 +24,7 @@ rouille = { version = "3.0.0", default-features = false }
|
|||||||
serde = { version = "1.0", features = ['derive'] }
|
serde = { version = "1.0", features = ['derive'] }
|
||||||
serde_derive = "1.0"
|
serde_derive = "1.0"
|
||||||
serde_json = "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-cli-support = { path = "../cli-support", version = "=0.2.37" }
|
||||||
wasm-bindgen-shared = { path = "../shared", version = "=0.2.37" }
|
wasm-bindgen-shared = { path = "../shared", version = "=0.2.37" }
|
||||||
|
|
||||||
|
@ -12,5 +12,5 @@ Support for threading-related transformations in wasm-bindgen
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
walrus = "0.2"
|
|
||||||
failure = "0.1"
|
failure = "0.1"
|
||||||
|
walrus = "0.4"
|
||||||
|
@ -12,8 +12,9 @@ Micro-interpreter optimized for wasm-bindgen's use case
|
|||||||
edition = '2018'
|
edition = '2018'
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
walrus = "0.2"
|
failure = "0.1"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
walrus = "0.4"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempfile = "3"
|
tempfile = "3"
|
||||||
|
@ -64,7 +64,7 @@ impl Interpreter {
|
|||||||
///
|
///
|
||||||
/// Note that the `module` passed in to this function must be the same as
|
/// Note that the `module` passed in to this function must be the same as
|
||||||
/// the `module` passed to `interpret` below.
|
/// 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();
|
let mut ret = Interpreter::default();
|
||||||
|
|
||||||
// The descriptor functions shouldn't really use all that much memory
|
// The descriptor functions shouldn't really use all that much memory
|
||||||
@ -102,14 +102,9 @@ impl Interpreter {
|
|||||||
ret.name_map.insert(export.name.to_string(), id);
|
ret.name_map.insert(export.name.to_string(), id);
|
||||||
}
|
}
|
||||||
|
|
||||||
for table in module.tables.iter() {
|
ret.functions = module.tables.main_function_table()?;
|
||||||
match table.kind {
|
|
||||||
walrus::TableKind::Function(_) => {}
|
|
||||||
}
|
|
||||||
ret.functions = Some(table.id());
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return Ok(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Interprets the execution of the descriptor function `func`.
|
/// Interprets the execution of the descriptor function `func`.
|
||||||
@ -204,6 +199,7 @@ impl Interpreter {
|
|||||||
let functions = self.functions.expect("function table should be present");
|
let functions = self.functions.expect("function table should be present");
|
||||||
let functions = match &module.tables.get(functions).kind {
|
let functions = match &module.tables.get(functions).kind {
|
||||||
walrus::TableKind::Function(f) => f,
|
walrus::TableKind::Function(f) => f,
|
||||||
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
let descriptor_id = functions
|
let descriptor_id = functions
|
||||||
.elements
|
.elements
|
||||||
@ -348,8 +344,11 @@ impl Frame<'_> {
|
|||||||
|
|
||||||
Expr::WithSideEffects(e) => {
|
Expr::WithSideEffects(e) => {
|
||||||
log::debug!("side effects");
|
log::debug!("side effects");
|
||||||
|
for x in e.before.iter() {
|
||||||
|
self.eval(*x);
|
||||||
|
}
|
||||||
let ret = self.eval(e.value);
|
let ret = self.eval(e.value);
|
||||||
for x in e.side_effects.iter() {
|
for x in e.after.iter() {
|
||||||
self.eval(*x);
|
self.eval(*x);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -16,7 +16,7 @@ fn interpret(wat: &str, name: &str, result: Option<&[u32]>) {
|
|||||||
println!("status: {}", status);
|
println!("status: {}", status);
|
||||||
assert!(status.success());
|
assert!(status.success());
|
||||||
let module = walrus::Module::from_file(output.path()).unwrap();
|
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);
|
assert_eq!(i.interpret_descriptor(name, &module), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user