Skip to content

Commit

Permalink
Update a number of dependencies (#152)
Browse files Browse the repository at this point in the history
* Update the `wasmpaser` dependency
* Update the precompiled `wabt`
* Update the spec-test `testsuite`

And then get everything working again!
  • Loading branch information
alexcrichton committed Jan 21, 2020
1 parent 03d38ca commit b0068fc
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 29 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/main.yml
Expand Up @@ -15,8 +15,8 @@ jobs:
- name: Install wabt
run: |
set -e
curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.12/wabt-1.0.12-linux.tar.gz | tar xzf -
echo "##[add-path]`pwd`/wabt-1.0.12"
curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.13/wabt-1.0.13-linux.tar.gz | tar xzf -
echo "##[add-path]`pwd`/wabt-1.0.13"
- name: Install binaryen
run: |
set -e
Expand All @@ -38,8 +38,8 @@ jobs:
- name: Install wabt
run: |
set -e
curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.12/wabt-1.0.12-linux.tar.gz | tar xzf -
echo "##[add-path]`pwd`/wabt-1.0.12"
curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.13/wabt-1.0.13-linux.tar.gz | tar xzf -
echo "##[add-path]`pwd`/wabt-1.0.13"
- name: Install binaryen
run: |
set -e
Expand All @@ -65,8 +65,8 @@ jobs:
- name: Install wabt
run: |
set -e
curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.12/wabt-1.0.12-linux.tar.gz | tar xzf -
echo "##[add-path]`pwd`/wabt-1.0.12"
curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.13/wabt-1.0.13-linux.tar.gz | tar xzf -
echo "##[add-path]`pwd`/wabt-1.0.13"
- name: Install binaryen
run: |
set -e
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -29,7 +29,7 @@ leb128 = "0.2.4"
log = "0.4.8"
rayon = { version = "1.1.0", optional = true }
walrus-macro = { path = './crates/macro', version = '=0.14.0' }
wasmparser = "0.45.0"
wasmparser = "0.48.0"

[features]
parallel = ['rayon', 'id-arena/rayon']
Expand Down
2 changes: 1 addition & 1 deletion crates/tests/tests/spec-tests
Submodule spec-tests updated 102 files
5 changes: 5 additions & 0 deletions crates/tests/tests/spec-tests.rs
Expand Up @@ -38,6 +38,11 @@ fn run(wast: &Path) -> Result<(), anyhow::Error> {

// TODO: should get threads working
Some("threads") => return Ok(()),
// TODO: should get simd working
Some("simd") => return Ok(()),
// TODO: should get tail-call working
Some("tail-call") => return Ok(()),

// Some("threads") => &["--enable-threads"],
Some(other) => panic!("unknown wasm proposal: {}", other),
};
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Expand Up @@ -4,7 +4,7 @@ pub use anyhow::Error;
use std::fmt;

/// Either `Ok(T)` or `Err(failure::Error)`.
pub type Result<T> = ::std::result::Result<T, anyhow::Error>;
pub use anyhow::Result;

/// A leaf wasm error type.
///
Expand Down
7 changes: 6 additions & 1 deletion src/ir/mod.rs
Expand Up @@ -320,7 +320,12 @@ pub enum Instr {
},

/// `select`
Select {},
Select {
/// Optionally listed type that the `select` instruction is expected to
/// produce, used in subtyping relations with the gc proposal.
#[walrus(skip_visit)]
ty: Option<ValType>,
},

/// `unreachable`
Unreachable {},
Expand Down
50 changes: 36 additions & 14 deletions src/module/elements.rs
Expand Up @@ -76,13 +76,12 @@ impl Module {
let segment = segment?;

match segment.kind {
wasmparser::ElementKind::Passive { .. } => {
wasmparser::ElementKind::Passive { .. } | wasmparser::ElementKind::Declared => {
bail!("passive element segments not supported yet");
}
wasmparser::ElementKind::Active {
table_index,
init_expr,
items,
} => {
let table = ids.get_table(table_index)?;
let table = match &mut self.tables.get_mut(table).kind {
Expand All @@ -94,10 +93,17 @@ impl Module {

let offset = InitExpr::eval(&init_expr, ids)
.with_context(|| format!("in segment {}", i))?;
let functions = items.get_items_reader()?.into_iter().map(|func| {
let func = func?;
ids.get_func(func)
});
let functions =
segment
.items
.get_items_reader()?
.into_iter()
.map(|e| -> Result<_> {
Ok(match e? {
wasmparser::ElementItem::Func(f) => Some(ids.get_func(f)?),
wasmparser::ElementItem::Null => None,
})
});

match offset {
InitExpr::Value(Value::I32(n)) => {
Expand All @@ -106,7 +112,7 @@ impl Module {
while i + offset + 1 > table.elements.len() {
table.elements.push(None);
}
table.elements[i + offset] = Some(id?);
table.elements[i + offset] = id?;
}
}
InitExpr::Global(global) if self.globals.get(global).ty == ValType::I32 => {
Expand Down Expand Up @@ -181,11 +187,12 @@ impl Emit for ModuleElements {
//
// Note that much of this is in accordance with the
// currently-in-progress bulk-memory proposal for WebAssembly.
let active_table_header = |cx: &mut EmitContext, index: u32| {
let active_table_header = |cx: &mut EmitContext, index: u32, exprs: bool| {
let exprs_bit = if exprs { 0x4 } else { 0x0 };
if index == 0 {
cx.encoder.byte(0x00);
cx.encoder.byte(0x00 | exprs_bit);
} else {
cx.encoder.byte(0x02);
cx.encoder.byte(0x02 | exprs_bit);
cx.encoder.u32(index);
}
};
Expand All @@ -194,7 +201,7 @@ impl Emit for ModuleElements {
// constant offsets
for (&id, table, offset, len) in chunks {
let table_index = cx.indices.get_table_index(id);
active_table_header(&mut cx, table_index);
active_table_header(&mut cx, table_index, false);
InitExpr::Value(Value::I32(offset as i32)).emit(&mut cx);
cx.encoder.usize(len);
for item in table.elements[offset..][..len].iter() {
Expand All @@ -208,12 +215,27 @@ impl Emit for ModuleElements {
for (id, table) in active.iter() {
let table_index = cx.indices.get_table_index(*id);
for (global, list) in table.relative_elements.iter() {
active_table_header(&mut cx, table_index);
let exprs = list.iter().any(|i| i.is_none());
active_table_header(&mut cx, table_index, exprs);
InitExpr::Global(*global).emit(&mut cx);
cx.encoder.usize(list.len());
for func in list {
let index = cx.indices.get_func_index(*func);
cx.encoder.u32(index);
match func {
Some(id) => {
let index = cx.indices.get_func_index(*id);
if exprs {
cx.encoder.byte(0xd2);
cx.encoder.u32(index);
cx.encoder.byte(0x0b);
} else {
cx.encoder.u32(index);
}
}
None => {
cx.encoder.byte(0xd1);
cx.encoder.byte(0x0b);
}
}
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/module/functions/local_function/emit.rs
Expand Up @@ -530,8 +530,17 @@ impl<'instr> Visitor<'instr> for Emit<'_, '_> {
}
}

Select(_) => {
self.encoder.byte(0x1b); // select
Select(e) => {
match e.ty {
Some(ty) => {
self.encoder.byte(0x1c);
self.encoder.byte(0x01);
ty.emit(self.encoder);
}
None => {
self.encoder.byte(0x1b); // select
}
}
}

Unreachable(_) => {
Expand Down
10 changes: 9 additions & 1 deletion src/module/functions/local_function/mod.rs
Expand Up @@ -608,7 +608,15 @@ fn validate_instruction<'context>(
ctx.pop_operand_expected(Some(I32))?;
let t1 = ctx.pop_operand()?;
let t2 = ctx.pop_operand_expected(t1)?;
ctx.alloc_instr(Select {}, loc);
ctx.alloc_instr(Select { ty: None }, loc);
ctx.push_operand(t2);
}
Operator::TypedSelect { ty } => {
let ty = ValType::parse(&ty)?;
ctx.pop_operand_expected(Some(ty))?;
let t1 = ctx.pop_operand()?;
let t2 = ctx.pop_operand_expected(t1)?;
ctx.alloc_instr(Select { ty: Some(ty) }, loc);
ctx.push_operand(t2);
}
Operator::Return => {
Expand Down
3 changes: 3 additions & 0 deletions src/module/mod.rs
Expand Up @@ -168,6 +168,9 @@ impl Module {
}
wasmparser::SectionCode::Start => {
let idx = section.get_start_section_content()?;
if ret.start.is_some() {
bail!("multiple start sections found");
}
ret.start = Some(indices.get_func(idx)?);
}
wasmparser::SectionCode::Function => {
Expand Down
2 changes: 1 addition & 1 deletion src/module/tables.rs
Expand Up @@ -64,7 +64,7 @@ pub struct FunctionTable {

/// Elements of this table which are relative to a global, typically
/// imported.
pub relative_elements: Vec<(GlobalId, Vec<FunctionId>)>,
pub relative_elements: Vec<(GlobalId, Vec<Option<FunctionId>>)>,
}

/// Components of a table of `anyref`
Expand Down
4 changes: 3 additions & 1 deletion src/passes/used.rs
Expand Up @@ -174,7 +174,9 @@ impl Used {
for (global, list) in list.relative_elements.iter() {
stack.push_global(*global);
for id in list {
stack.push_func(*id);
if let Some(id) = *id {
stack.push_func(id);
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/passes/validate.rs
Expand Up @@ -236,4 +236,10 @@ impl<'a> Visitor<'a> for Validate<'a> {
let width = if e.sixty_four { 8 } else { 4 };
self.require_atomic(e.memory, &e.arg, width);
}

fn visit_global_set(&mut self, e: &GlobalSet) {
if !self.module.globals.get(e.global).mutable {
self.err("cannot mutate immutable global");
}
}
}

0 comments on commit b0068fc

Please sign in to comment.