Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump wasmparser + support emitting multiple memories MemArgs #206

Merged
merged 4 commits into from Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/main.yml
Expand Up @@ -20,21 +20,21 @@ jobs:
- uses: actions/checkout@v2
with:
repository: WebAssembly/wabt
ref: 8e42376ccd5f05dc1036f91b4262e67b0fc66c2d
ref: aa0515b3c808da880942db8658abeaa969534667
path: wabt
- name: Build wabt
run: |
set -e
cd wabt
cmake . -DBUILD_TESTS=OFF
make -j$(nproc) wast2json spectest-interp wasm-interp
echo ::add-path::`pwd`
echo `pwd` > $GITHUB_PATH

- name: Install binaryen
run: |
set -e
curl -L https://github.com/WebAssembly/binaryen/releases/download/1.39.1/binaryen-1.39.1-x86_64-linux.tar.gz | tar xzf -
echo "##[add-path]`pwd`/binaryen-1.39.1"
echo "`pwd`/binaryen-1.39.1" > $GITHUB_PATH
- run: cargo build --all
- run: cargo test --all
- run: cargo check --benches
Expand All @@ -52,12 +52,12 @@ jobs:
run: |
set -e
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"
echo "`pwd`/wabt-1.0.13" > $GITHUB_PATH
- name: Install binaryen
run: |
set -e
curl -L https://github.com/WebAssembly/binaryen/releases/download/1.39.1/binaryen-1.39.1-x86_64-linux.tar.gz | tar xzf -
echo "##[add-path]`pwd`/binaryen-1.39.1"
echo "`pwd`/binaryen-1.39.1" > $GITHUB_PATH
- name: Run fuzzer
run: cargo test -p walrus-fuzz-utils > fuzz.log || (tail -n 1000 fuzz.log && exit 1)
env:
Expand All @@ -79,12 +79,12 @@ jobs:
run: |
set -e
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"
echo "`pwd`/wabt-1.0.13" > $GITHUB_PATH
- name: Install binaryen
run: |
set -e
curl -L https://github.com/WebAssembly/binaryen/releases/download/1.39.1/binaryen-1.39.1-x86_64-linux.tar.gz | tar xzf -
echo "##[add-path]`pwd`/binaryen-1.39.1"
echo "`pwd`/binaryen-1.39.1" > $GITHUB_PATH
- name: Run fuzzer
run: |
cargo fuzz run ${{ matrix.test }} -- -max_total_time=300 -rss_limit_mb=4096 > fuzz.log 2>&1 || (tail -n 1000 fuzz.log && exit 1)
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.18.0' }
wasmparser = "0.67.0"
wasmparser = "0.77.0"

[features]
parallel = ['rayon', 'id-arena/rayon']
Expand Down
44 changes: 43 additions & 1 deletion crates/tests/build.rs
Expand Up @@ -4,6 +4,42 @@ use std::fs;
use std::path::Path;
use walkdir::WalkDir;

fn is_known_failing(name: &str) -> bool {
match name {
// TODO issues to investigate: wasm parsed when it shouldn't
"tests_spec_tests_proposals_bulk_memory_operations_binary_wast"
| "tests_spec_tests_proposals_reference_types_binary_wast" => true,

// SIMD isn't fully implemented yet.
"tests_spec_tests_proposals_simd_simd_boolean_wast"
| "tests_spec_tests_proposals_simd_simd_conversions_wast"
| "tests_spec_tests_proposals_simd_simd_f32x4_rounding_wast"
| "tests_spec_tests_proposals_simd_simd_f64x2_rounding_wast"
| "tests_spec_tests_proposals_simd_simd_i16x8_extadd_pairwise_i8x16_wast"
| "tests_spec_tests_proposals_simd_simd_i16x8_extmul_i8x16_wast"
| "tests_spec_tests_proposals_simd_simd_i16x8_q15mulr_sat_s_wast"
| "tests_spec_tests_proposals_simd_simd_i32x4_extadd_pairwise_i16x8_wast"
| "tests_spec_tests_proposals_simd_simd_i32x4_extmul_i16x8_wast"
| "tests_spec_tests_proposals_simd_simd_i32x4_trunc_sat_f64x2_wast"
| "tests_spec_tests_proposals_simd_simd_i64x2_arith2_wast"
| "tests_spec_tests_proposals_simd_simd_i64x2_cmp_wast"
| "tests_spec_tests_proposals_simd_simd_i64x2_extmul_i32x4_wast"
| "tests_spec_tests_proposals_simd_simd_i8x16_arith2_wast"
| "tests_spec_tests_proposals_simd_simd_int_to_int_extend_wast"
| "tests_spec_tests_proposals_simd_simd_load16_lane_wast"
| "tests_spec_tests_proposals_simd_simd_load32_lane_wast"
| "tests_spec_tests_proposals_simd_simd_load64_lane_wast"
| "tests_spec_tests_proposals_simd_simd_load8_lane_wast"
| "tests_spec_tests_proposals_simd_simd_load_zero_wast"
| "tests_spec_tests_proposals_simd_simd_store16_lane_wast"
| "tests_spec_tests_proposals_simd_simd_store32_lane_wast"
| "tests_spec_tests_proposals_simd_simd_store64_lane_wast"
| "tests_spec_tests_proposals_simd_simd_store8_lane_wast" => true,

_ => false,
}
}

fn for_each_wat_file<P, F>(dir: P, mut f: F)
where
P: AsRef<Path>,
Expand Down Expand Up @@ -37,8 +73,14 @@ fn generate_tests(name: &str) {

for_each_wat_file(Path::new("tests").join(name), |path| {
let test_name = path_to_ident(path);
let ignore_test = if is_known_failing(&test_name) {
"#[ignore]"
} else {
""
};
tests.push_str(&format!(
"#[test] fn {}() {{ walrus_tests_utils::handle(run(\"{}\".as_ref())); }}\n",
"#[test] {} fn {}() {{ walrus_tests_utils::handle(run(\"{}\".as_ref())); }}\n",
ignore_test,
test_name,
path.display(),
));
Expand Down
28 changes: 7 additions & 21 deletions crates/tests/tests/round_trip/simd.wat
Expand Up @@ -263,13 +263,13 @@
local.get 1
local.get 2
v128.bitselect)
(func $v128.any_true (export "v128.any_true") (param v128) (result i32)
local.get 0
v128.any_true)

(func $i8x16.neg (export "i8x16.neg") (param v128) (result v128)
local.get 0
i8x16.neg)
(func $i8x16.any_true (export "i8x16.any_true") (param v128) (result i32)
local.get 0
i8x16.any_true)
(func $i8x16.all_true (export "i8x16.all_true") (param v128) (result i32)
local.get 0
i8x16.all_true)
Expand Down Expand Up @@ -313,9 +313,6 @@
(func $i16x8.neg (export "i16x8.neg") (param v128) (result v128)
local.get 0
i16x8.neg)
(func $i16x8.any_true (export "i16x8.any_true") (param v128) (result i32)
local.get 0
i16x8.any_true)
(func $i16x8.all_true (export "i16x8.all_true") (param v128) (result i32)
local.get 0
i16x8.all_true)
Expand Down Expand Up @@ -363,9 +360,6 @@
(func $i32x4.neg (export "i32x4.neg") (param v128) (result v128)
local.get 0
i32x4.neg)
(func $i32x4.any_true (export "i32x4.any_true") (param v128) (result i32)
local.get 0
i32x4.any_true)
(func $i32x4.all_true (export "i32x4.all_true") (param v128) (result i32)
local.get 0
i32x4.all_true)
Expand Down Expand Up @@ -929,30 +923,24 @@
(func $v128.not (type 10) (param v128) (result v128)
local.get 0
v128.not)
(func $v128.any_true (type 6) (param v128) (result i32)
local.get 0
v128.any_true)
(func $i8x16.neg (type 10) (param v128) (result v128)
local.get 0
i8x16.neg)
(func $i8x16.any_true (type 6) (param v128) (result i32)
local.get 0
i8x16.any_true)
(func $i8x16.all_true (type 6) (param v128) (result i32)
local.get 0
i8x16.all_true)
(func $i16x8.neg (type 10) (param v128) (result v128)
local.get 0
i16x8.neg)
(func $i16x8.any_true (type 6) (param v128) (result i32)
local.get 0
i16x8.any_true)
(func $i16x8.all_true (type 6) (param v128) (result i32)
local.get 0
i16x8.all_true)
(func $i32x4.neg (type 10) (param v128) (result v128)
local.get 0
i32x4.neg)
(func $i32x4.any_true (type 6) (param v128) (result i32)
local.get 0
i32x4.any_true)
(func $i32x4.all_true (type 6) (param v128) (result i32)
local.get 0
i32x4.all_true)
Expand Down Expand Up @@ -1057,8 +1045,8 @@
(export "v128.or" (func $v128.or))
(export "v128.xor" (func $v128.xor))
(export "v128.bitselect" (func $v128.bitselect))
(export "v128.any_true" (func $v128.any_true))
(export "i8x16.neg" (func $i8x16.neg))
(export "i8x16.any_true" (func $i8x16.any_true))
(export "i8x16.all_true" (func $i8x16.all_true))
(export "i8x16.shl" (func $i8x16.shl))
(export "i8x16.shr_s" (func $i8x16.shr_s))
Expand All @@ -1070,7 +1058,6 @@
(export "i8x16.sub_sat_u" (func $i8x16.sub_sat_u))
(export "i8x16.sub_sat_s" (func $i8x16.sub_sat_s))
(export "i16x8.neg" (func $i16x8.neg))
(export "i16x8.any_true" (func $i16x8.any_true))
(export "i16x8.all_true" (func $i16x8.all_true))
(export "i16x8.shl" (func $i16x8.shl))
(export "i16x8.shr_s" (func $i16x8.shr_s))
Expand All @@ -1083,7 +1070,6 @@
(export "i16x8.sub_sat_s" (func $i16x8.sub_sat_s))
(export "i16x8.mul" (func $i16x8.mul))
(export "i32x4.neg" (func $i32x4.neg))
(export "i32x4.any_true" (func $i32x4.any_true))
(export "i32x4.all_true" (func $i32x4.all_true))
(export "i32x4.shl" (func $i32x4.shl))
(export "i32x4.shr_s" (func $i32x4.shr_s))
Expand Down
2 changes: 1 addition & 1 deletion crates/tests/tests/spec-tests
Submodule spec-tests updated 45 files
+1 −1 binary-leb128.wast
+67 −3 binary.wast
+35 −0 br_table.wast
+123 −0 data.wast
+61 −0 elem.wast
+32 −0 exports.wast
+120 −18 global.wast
+51 −0 imports.wast
+6 −6 local_get.wast
+19 −19 local_tee.wast
+610 −0 proposals/memory64/address.wast
+4 −11 proposals/memory64/address64.wast
+1,001 −0 proposals/memory64/binary-leb128.wast
+993 −0 proposals/memory64/binary.wast
+0 −179 proposals/memory64/bulk64.wast
+242 −0 proposals/memory64/memory.wast
+4 −4 proposals/memory64/memory64.wast
+2 −2 proposals/memory64/memory_trap64.wast
+72 −45 proposals/simd/simd_boolean.wast
+265 −741 proposals/simd/simd_conversions.wast
+0 −1 proposals/simd/simd_i16x8_arith2.wast
+68 −0 proposals/simd/simd_i16x8_extadd_pairwise_i8x16.wast
+404 −0 proposals/simd/simd_i16x8_extmul_i8x16.wast
+110 −0 proposals/simd/simd_i16x8_q15mulr_sat_s.wast
+110 −0 proposals/simd/simd_i32x4_dot_i16x8.wast
+68 −0 proposals/simd/simd_i32x4_extadd_pairwise_i16x8.wast
+404 −0 proposals/simd/simd_i32x4_extmul_i16x8.wast
+239 −0 proposals/simd/simd_i32x4_trunc_sat_f32x4.wast
+239 −0 proposals/simd/simd_i32x4_trunc_sat_f64x2.wast
+78 −0 proposals/simd/simd_i64x2_arith2.wast
+414 −0 proposals/simd/simd_i64x2_cmp.wast
+404 −0 proposals/simd/simd_i64x2_extmul_i32x4.wast
+119 −20 proposals/simd/simd_i8x16_arith2.wast
+599 −0 proposals/simd/simd_int_to_int_extend.wast
+5 −5 proposals/simd/simd_lane.wast
+211 −0 proposals/simd/simd_load16_lane.wast
+143 −0 proposals/simd/simd_load32_lane.wast
+97 −0 proposals/simd/simd_load64_lane.wast
+299 −0 proposals/simd/simd_load8_lane.wast
+154 −0 proposals/simd/simd_load_zero.wast
+299 −0 proposals/simd/simd_store16_lane.wast
+199 −0 proposals/simd/simd_store32_lane.wast
+131 −0 proposals/simd/simd_store64_lane.wast
+427 −0 proposals/simd/simd_store8_lane.wast
+77 −4 select.wast
4 changes: 1 addition & 3 deletions src/ir/mod.rs
Expand Up @@ -943,20 +943,18 @@ pub enum UnaryOp {
F64x2ExtractLane { idx: u8 },

V128Not,
V128AnyTrue,

I8x16Abs,
I8x16Neg,
I8x16AnyTrue,
I8x16AllTrue,
I8x16Bitmask,
I16x8Abs,
I16x8Neg,
I16x8AnyTrue,
I16x8AllTrue,
I16x8Bitmask,
I32x4Abs,
I32x4Neg,
I32x4AnyTrue,
I32x4AllTrue,
I32x4Bitmask,
I64x2Neg,
Expand Down
3 changes: 3 additions & 0 deletions src/module/exports.rs
Expand Up @@ -145,6 +145,9 @@ impl Module {
Type | Module | Instance => {
unimplemented!("module linking not supported");
}
Event => {
unimplemented!("exception handling not supported");
}
};
self.exports.arena.alloc_with_id(|id| Export {
id,
Expand Down
20 changes: 14 additions & 6 deletions src/module/functions/local_function/emit.rs
Expand Up @@ -500,15 +500,15 @@ impl<'instr> Visitor<'instr> for Emit<'_, '_> {

V128Not => self.simd(0x4d),

V128AnyTrue => self.simd(0x53),

I8x16Abs => self.simd(0x60),
I8x16Neg => self.simd(0x61),
I8x16AnyTrue => self.simd(0x62),
I8x16AllTrue => self.simd(0x63),
I8x16Bitmask => self.simd(0x64),

I16x8Abs => self.simd(0x80),
I16x8Neg => self.simd(0x81),
I16x8AnyTrue => self.simd(0x82),
I16x8AllTrue => self.simd(0x83),
I16x8Bitmask => self.simd(0x84),
I16x8WidenLowI8x16S => self.simd(0x87),
Expand All @@ -518,7 +518,6 @@ impl<'instr> Visitor<'instr> for Emit<'_, '_> {

I32x4Abs => self.simd(0xa0),
I32x4Neg => self.simd(0xa1),
I32x4AnyTrue => self.simd(0xa2),
I32x4AllTrue => self.simd(0xa3),
I32x4Bitmask => self.simd(0xa4),
I32x4WidenLowI16x8S => self.simd(0xa7),
Expand Down Expand Up @@ -893,9 +892,18 @@ impl Emit<'_, '_> {
}

fn memarg(&mut self, id: MemoryId, arg: &MemArg) {
assert_eq!(self.indices.get_memory_index(id), 0);
self.encoder.u32(arg.align.trailing_zeros());
self.encoder.u32(arg.offset);
let mem_index = self.indices.get_memory_index(id);
if mem_index == 0 {
self.encoder.u32(arg.align.trailing_zeros());
self.encoder.u32(arg.offset);
} else {
assert!(arg.align.trailing_zeros() < (1 << 6), "alignment too large");
let multi_memory_flag = 1 << 6;
let flags = arg.align.trailing_zeros() | multi_memory_flag;
self.encoder.u32(flags);
self.encoder.u32(arg.offset);
self.encoder.u32(mem_index);
};
}

fn simd(&mut self, opcode: u32) {
Expand Down