Skip to content

Commit 603d574

Browse files
authored
Merge pull request #1717 from alexcrichton/walrus-update
Update with list IR from `walrus`
2 parents 8775f9b + aace8ce commit 603d574

File tree

12 files changed

+341
-388
lines changed

12 files changed

+341
-388
lines changed

azure-pipelines.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ jobs:
1818
displayName: "Crate test suite"
1919
- script: WASM_BINDGEN_NO_DEBUG=1 cargo test --target wasm32-unknown-unknown
2020
displayName: "Crate test suite (no debug)"
21-
- script: NODE_ARGS=/dev/null WASM_BINDGEN_ANYREF=1 cargo test --target wasm32-unknown-unknown --test wasm
22-
displayName: "Anyref test suite builds"
2321
- script: cargo test --target wasm32-unknown-unknown --features serde-serialize
2422
displayName: "Crate test suite (with serde)"
2523
- script: cargo test --target wasm32-unknown-unknown --features enable-interning
@@ -30,6 +28,19 @@ jobs:
3028
displayName: "Futures test suite on native"
3129
- script: cargo test -p wasm-bindgen-futures --target wasm32-unknown-unknown
3230
displayName: "Futures test suite on wasm"
31+
- script: |
32+
set -e
33+
curl https://nodejs.org/download/nightly/v13.0.0-nightly2019081215b2d13310/node-v13.0.0-nightly2019081215b2d13310-linux-x64.tar.xz | tar xJf -
34+
echo "##vso[task.prependpath]$PWD/node-v13.0.0-nightly2019081215b2d13310-linux-x64/bin"
35+
echo "##vso[task.setvariable variable=NODE_ARGS]--experimental-wasm-anyref,--experimental-wasm-bulk_memory"
36+
echo "##vso[task.setvariable variable=WASM_BINDGEN_ANYREF]1"
37+
displayName: "Install a custom node.js and configure anyref"
38+
- script: cargo test --target wasm32-unknown-unknown --test wasm
39+
displayName: "(anyref) Crate test suite"
40+
- script: WASM_BINDGEN_NO_DEBUG=1 cargo test --target wasm32-unknown-unknown --test wasm
41+
displayName: "(anyref) Crate test suite (no debug)"
42+
- script: cargo test --target wasm32-unknown-unknown --features serde-serialize --test wasm
43+
displayName: "(anyref) Crate test suite (with serde)"
3344

3445
- job: test_wasm_bindgen_windows
3546
displayName: "Run wasm-bindgen crate tests (Windows)"

crates/anyref-xform/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ edition = '2018'
1313

1414
[dependencies]
1515
failure = "0.1"
16-
walrus = "0.10.0"
16+
walrus = "0.11.0"

crates/anyref-xform/src/lib.rs

Lines changed: 138 additions & 133 deletions
Large diffs are not rendered by default.

crates/cli-support/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ log = "0.4"
1818
rustc-demangle = "0.1.13"
1919
serde_json = "1.0"
2020
tempfile = "3.0"
21-
walrus = "0.10.0"
21+
walrus = "0.11.0"
2222
wasm-bindgen-anyref-xform = { path = '../anyref-xform', version = '=0.2.48' }
2323
wasm-bindgen-shared = { path = "../shared", version = '=0.2.48' }
2424
wasm-bindgen-threads-xform = { path = '../threads-xform', version = '=0.2.48' }
2525
wasm-bindgen-wasm-interpreter = { path = "../wasm-interpreter", version = '=0.2.48' }
26-
wasm-webidl-bindings = "0.3.0"
26+
wasm-webidl-bindings = "0.4.0"

crates/cli-support/src/anyref.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@ pub fn process(module: &mut Module) -> Result<(), Error> {
4444
}
4545

4646
cfg.run(module)?;
47+
48+
// Make sure to export the `anyref` table for the JS bindings since it
49+
// will need to be initialized. If it doesn't exist though then the
50+
// module must not use it, so we skip it.
51+
let table = module.tables.iter().find(|t| match t.kind {
52+
walrus::TableKind::Anyref(_) => true,
53+
_ => false,
54+
});
55+
let table = match table {
56+
Some(t) => t.id(),
57+
None => return Ok(()),
58+
};
59+
module.exports.add("__wbg_anyref_table", table);
60+
61+
// Clean up now-unused intrinsics and shims and such
4762
walrus::passes::gc::run(module);
4863

4964
// The GC pass above may end up removing some imported intrinsics. For

crates/cli-support/src/descriptors.rs

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ use crate::descriptor::{Closure, Descriptor};
1414
use failure::Error;
1515
use std::borrow::Cow;
1616
use std::collections::{HashMap, HashSet};
17-
use std::mem;
1817
use walrus::ImportId;
19-
use walrus::{CustomSection, FunctionId, LocalFunction, Module, TypedCustomSectionId};
18+
use walrus::{CustomSection, FunctionId, Module, TypedCustomSectionId};
2019
use wasm_bindgen_wasm_interpreter::Interpreter;
2120

2221
#[derive(Default, Debug)]
@@ -112,19 +111,16 @@ impl WasmBindgenDescriptorsSection {
112111
let mut element_removal_list = HashSet::new();
113112
let mut func_to_descriptor = HashMap::new();
114113
for (id, local) in module.funcs.iter_local() {
115-
let entry = local.entry_block();
116114
let mut find = FindDescribeClosure {
117-
func: local,
118115
wbindgen_describe_closure,
119-
cur: entry.into(),
120-
call: None,
116+
found: false,
121117
};
122-
find.visit_block_id(&entry);
123-
if let Some(call) = find.call {
118+
dfs_in_order(&mut find, local, local.entry_block());
119+
if find.found {
124120
let descriptor = interpreter
125121
.interpret_closure_descriptor(id, module, &mut element_removal_list)
126122
.unwrap();
127-
func_to_descriptor.insert(id, (call, Descriptor::decode(descriptor)));
123+
func_to_descriptor.insert(id, Descriptor::decode(descriptor));
128124
}
129125
}
130126

@@ -150,7 +146,7 @@ impl WasmBindgenDescriptorsSection {
150146
// freshly manufactured import. Save off the type of this import in
151147
// ourselves, and then we're good to go.
152148
let ty = module.funcs.get(wbindgen_describe_closure).ty();
153-
for (func, (call_instr, descriptor)) in func_to_descriptor {
149+
for (func, descriptor) in func_to_descriptor {
154150
let import_name = format!("__wbindgen_closure_wrapper{}", func.index());
155151
let (id, import_id) =
156152
module.add_import_func("__wbindgen_placeholder__", &import_name, ty);
@@ -160,37 +156,42 @@ impl WasmBindgenDescriptorsSection {
160156
walrus::FunctionKind::Local(l) => l,
161157
_ => unreachable!(),
162158
};
163-
let call = local.get_mut(call_instr).unwrap_call_mut();
164-
assert_eq!(call.func, wbindgen_describe_closure);
165-
call.func = id;
159+
let entry = local.entry_block();
160+
dfs_pre_order_mut(
161+
&mut UpdateDescribeClosure {
162+
wbindgen_describe_closure,
163+
replacement: id,
164+
},
165+
local,
166+
entry,
167+
);
166168
self.closure_imports
167169
.insert(import_id, descriptor.unwrap_closure());
168170
}
169171
return Ok(());
170172

171-
struct FindDescribeClosure<'a> {
172-
func: &'a LocalFunction,
173+
struct FindDescribeClosure {
173174
wbindgen_describe_closure: FunctionId,
174-
cur: ExprId,
175-
call: Option<ExprId>,
175+
found: bool,
176176
}
177177

178-
impl<'a> Visitor<'a> for FindDescribeClosure<'a> {
179-
fn local_function(&self) -> &'a LocalFunction {
180-
self.func
178+
impl<'a> Visitor<'a> for FindDescribeClosure {
179+
fn visit_call(&mut self, call: &Call) {
180+
if call.func == self.wbindgen_describe_closure {
181+
self.found = true;
182+
}
181183
}
184+
}
182185

183-
fn visit_expr_id(&mut self, id: &ExprId) {
184-
let prev = mem::replace(&mut self.cur, *id);
185-
id.visit(self);
186-
self.cur = prev;
187-
}
186+
struct UpdateDescribeClosure {
187+
wbindgen_describe_closure: FunctionId,
188+
replacement: FunctionId,
189+
}
188190

189-
fn visit_call(&mut self, call: &Call) {
190-
call.visit(self);
191+
impl<'a> VisitorMut for UpdateDescribeClosure {
192+
fn visit_call_mut(&mut self, call: &mut Call) {
191193
if call.func == self.wbindgen_describe_closure {
192-
assert!(self.call.is_none());
193-
self.call = Some(self.cur);
194+
call.func = self.replacement;
194195
}
195196
}
196197
}

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

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -624,30 +624,16 @@ impl<'a> Context<'a> {
624624
return Ok(());
625625
}
626626

627-
// Make sure to export the `anyref` table for the JS bindings since it
628-
// will need to be initialized. If it doesn't exist though then the
629-
// module must not use it, so we skip it.
630-
let table = self.module.tables.iter().find(|t| match t.kind {
631-
walrus::TableKind::Anyref(_) => true,
632-
_ => false,
633-
});
634-
let table = match table {
635-
Some(t) => t.id(),
636-
None => return Ok(()),
637-
};
638-
self.module.exports.add("__wbg_anyref_table", table);
639-
640627
let ty = self.module.types.add(&[], &[]);
641628
let (import, import_id) =
642629
self.module
643630
.add_import_func(PLACEHOLDER_MODULE, "__wbindgen_init_anyref_table", ty);
644631

645632
self.module.start = Some(match self.module.start {
646633
Some(prev_start) => {
647-
let mut builder = walrus::FunctionBuilder::new();
648-
let call_init = builder.call(import, Box::new([]));
649-
let call_prev = builder.call(prev_start, Box::new([]));
650-
builder.finish(ty, Vec::new(), vec![call_init, call_prev], self.module)
634+
let mut builder = walrus::FunctionBuilder::new(&mut self.module.types, &[], &[]);
635+
builder.func_body().call(import).call(prev_start);
636+
builder.finish(Vec::new(), &mut self.module.funcs)
651637
}
652638
None => import,
653639
});
@@ -827,11 +813,9 @@ impl<'a> Context<'a> {
827813
// because the start function currently only shows up when it's injected
828814
// through thread/anyref transforms. These injected start functions need
829815
// to happen before user code, so we always schedule them first.
830-
let mut builder = walrus::FunctionBuilder::new();
831-
let call1 = builder.call(prev_start, Box::new([]));
832-
let call2 = builder.call(id, Box::new([]));
833-
let ty = self.module.funcs.get(id).ty();
834-
let new_start = builder.finish(ty, Vec::new(), vec![call1, call2], self.module);
816+
let mut builder = walrus::FunctionBuilder::new(&mut self.module.types, &[], &[]);
817+
builder.func_body().call(prev_start).call(id);
818+
let new_start = builder.finish(Vec::new(), &mut self.module.funcs);
835819
self.module.start = Some(new_start);
836820
Ok(())
837821
}

crates/cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
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 = { version = "0.10.0", features = ['parallel'] }
27+
walrus = { version = "0.11.0", features = ['parallel'] }
2828
wasm-bindgen-cli-support = { path = "../cli-support", version = "=0.2.48" }
2929
wasm-bindgen-shared = { path = "../shared", version = "=0.2.48" }
3030

crates/threads-xform/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ edition = "2018"
1313

1414
[dependencies]
1515
failure = "0.1"
16-
walrus = "0.10.0"
16+
walrus = "0.11.0"

0 commit comments

Comments
 (0)