From 0daa290129716a6bf5af616c14befb5d0a8032c1 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 29 Jul 2019 13:04:45 -0700 Subject: [PATCH] Update to walrus 0.9.0 This commit updates the `walrus` dependency with recent upstream API changes in `walrus` itself, namely updates to passive segements and how memory data segments are handled --- crates/anyref-xform/Cargo.toml | 2 +- crates/anyref-xform/src/lib.rs | 2 +- crates/cli-support/Cargo.toml | 4 ++-- crates/cli-support/src/descriptors.rs | 9 ++------- crates/cli/Cargo.toml | 2 +- crates/threads-xform/Cargo.toml | 2 +- crates/threads-xform/src/lib.rs | 25 +++++++++++++++++++------ crates/wasm-interpreter/Cargo.toml | 2 +- 8 files changed, 28 insertions(+), 20 deletions(-) diff --git a/crates/anyref-xform/Cargo.toml b/crates/anyref-xform/Cargo.toml index 76a4ab4c..e42abd1e 100644 --- a/crates/anyref-xform/Cargo.toml +++ b/crates/anyref-xform/Cargo.toml @@ -13,4 +13,4 @@ edition = '2018' [dependencies] failure = "0.1" -walrus = "0.8.0" +walrus = "0.9.0" diff --git a/crates/anyref-xform/src/lib.rs b/crates/anyref-xform/src/lib.rs index 1862eb99..4b7a5dc1 100644 --- a/crates/anyref-xform/src/lib.rs +++ b/crates/anyref-xform/src/lib.rs @@ -676,7 +676,7 @@ impl Transform<'_> { // initialized correctly. fn inject_initialization(&mut self, module: &mut Module) { let ty = module.types.add(&[], &[]); - let import = module.add_import_func( + let (import, _) = module.add_import_func( "__wbindgen_placeholder__", "__wbindgen_init_anyref_table", ty, diff --git a/crates/cli-support/Cargo.toml b/crates/cli-support/Cargo.toml index 6b5f86e3..df8d3da2 100644 --- a/crates/cli-support/Cargo.toml +++ b/crates/cli-support/Cargo.toml @@ -18,9 +18,9 @@ log = "0.4" rustc-demangle = "0.1.13" serde_json = "1.0" tempfile = "3.0" -walrus = "0.8.0" +walrus = "0.9.0" wasm-bindgen-anyref-xform = { path = '../anyref-xform', version = '=0.2.48' } wasm-bindgen-shared = { path = "../shared", version = '=0.2.48' } wasm-bindgen-threads-xform = { path = '../threads-xform', version = '=0.2.48' } wasm-bindgen-wasm-interpreter = { path = "../wasm-interpreter", version = '=0.2.48' } -wasm-webidl-bindings = "0.1.2" +wasm-webidl-bindings = "0.2.0" diff --git a/crates/cli-support/src/descriptors.rs b/crates/cli-support/src/descriptors.rs index 3c0c9b6f..bfd8d63b 100644 --- a/crates/cli-support/src/descriptors.rs +++ b/crates/cli-support/src/descriptors.rs @@ -152,13 +152,8 @@ impl WasmBindgenDescriptorsSection { let ty = module.funcs.get(wbindgen_describe_closure).ty(); for (func, (call_instr, descriptor)) in func_to_descriptor { let import_name = format!("__wbindgen_closure_wrapper{}", func.index()); - let id = module.add_import_func("__wbindgen_placeholder__", &import_name, ty); - let import_id = module - .imports - .iter() - .find(|i| i.name == import_name) - .unwrap() - .id(); + let (id, import_id) = + module.add_import_func("__wbindgen_placeholder__", &import_name, ty); module.funcs.get_mut(id).name = Some(import_name); let local = match &mut module.funcs.get_mut(func).kind { diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index ac1806e9..6617d8e0 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -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.8.0" +walrus = "0.9.0" wasm-bindgen-cli-support = { path = "../cli-support", version = "=0.2.48" } wasm-bindgen-shared = { path = "../shared", version = "=0.2.48" } diff --git a/crates/threads-xform/Cargo.toml b/crates/threads-xform/Cargo.toml index 8660a1a5..d2a1960e 100644 --- a/crates/threads-xform/Cargo.toml +++ b/crates/threads-xform/Cargo.toml @@ -13,4 +13,4 @@ edition = "2018" [dependencies] failure = "0.1" -walrus = "0.8.0" +walrus = "0.9.0" diff --git a/crates/threads-xform/src/lib.rs b/crates/threads-xform/src/lib.rs index f199a93d..a02fe9c4 100644 --- a/crates/threads-xform/src/lib.rs +++ b/crates/threads-xform/src/lib.rs @@ -101,7 +101,7 @@ impl Config { let prev_max = mem.maximum.unwrap(); assert!(mem.import.is_some()); mem.maximum = Some(cmp::max(self.maximum_memory / PAGE_SIZE, prev_max)); - assert!(mem.data.is_empty()); + assert!(mem.data_segments.is_empty()); let init_memory = module .exports @@ -146,11 +146,24 @@ fn switch_data_segments_to_passive( ) -> Result, Error> { let mut ret = Vec::new(); let memory = module.memories.get_mut(memory); - let data = mem::replace(&mut memory.data, Default::default()); - for (offset, value) in data.into_iter() { - let len = value.len() as u32; - let id = module.data.add(value); - ret.push(PassiveSegment { id, offset, len }); + for id in mem::replace(&mut memory.data_segments, Default::default()) { + let data = module.data.get_mut(id); + let kind = match &data.kind { + walrus::DataKind::Active(kind) => kind, + walrus::DataKind::Passive => continue, + }; + let offset = match kind.location { + walrus::ActiveDataLocation::Absolute(n) => { + walrus::InitExpr::Value(walrus::ir::Value::I32(n as i32)) + } + walrus::ActiveDataLocation::Relative(global) => walrus::InitExpr::Global(global), + }; + data.kind = walrus::DataKind::Passive; + ret.push(PassiveSegment { + id, + offset, + len: data.value.len() as u32, + }); } Ok(ret) diff --git a/crates/wasm-interpreter/Cargo.toml b/crates/wasm-interpreter/Cargo.toml index 1965e303..637949e3 100644 --- a/crates/wasm-interpreter/Cargo.toml +++ b/crates/wasm-interpreter/Cargo.toml @@ -14,7 +14,7 @@ edition = '2018' [dependencies] failure = "0.1" log = "0.4" -walrus = "0.8.0" +walrus = "0.9.0" [dev-dependencies] tempfile = "3"