Skip to content

Commit

Permalink
Sync with the latest version of the upstream spec (#159)
Browse files Browse the repository at this point in the history
* Sync with the latest version of the upstream spec

* Renumber a bunch of SIMD opcodes
* Implement some more reference-types validation
* Update dependencies
* Fix spec tests by always enabling multi-value/other stable proposals

* Update wabt

* Build a non-release version of wabt on CI
  • Loading branch information
alexcrichton committed May 5, 2020
1 parent dcbc5b6 commit f5157bd
Show file tree
Hide file tree
Showing 10 changed files with 302 additions and 259 deletions.
17 changes: 14 additions & 3 deletions .github/workflows/main.yml
Expand Up @@ -14,11 +14,22 @@ jobs:
submodules: true
- name: Install Rust
run: rustup update ${{ matrix.rust }} && rustup default ${{ matrix.rust }}
- name: Install wabt

# Build an up-to-date version of wabt since the releases don't always have
# all the features we want.
- uses: actions/checkout@v2
with:
repository: WebAssembly/wabt
ref: 9068d3927b404ce1e9c600473255a90504034eee
path: wabt
- name: Build wabt
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"
cd wabt
cmake . -DBUILD_TESTS=OFF
make -j$(nproc) wast2json spectest-interp wasm-interp
echo ::add-path::`pwd`
- 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.15.0' }
wasmparser = "0.51.0"
wasmparser = "0.52.0"

[features]
parallel = ['rayon', 'id-arena/rayon']
Expand Down
23 changes: 0 additions & 23 deletions crates/tests/tests/round_trip/simd.wat
Expand Up @@ -309,10 +309,6 @@
local.get 0
local.get 1
i8x16.sub_saturate_s)
(func $i8x16.mul (export "i8x16.mul") (param v128 v128) (result v128)
local.get 0
local.get 1
i8x16.mul)

(func $i16x8.neg (export "i16x8.neg") (param v128) (result v128)
local.get 0
Expand Down Expand Up @@ -401,12 +397,6 @@
(func $i64x2.neg (export "i64x2.neg") (param v128) (result v128)
local.get 0
i64x2.neg)
(func $i64x2.any_true (export "i64x2.any_true") (param v128) (result i32)
local.get 0
i64x2.any_true)
(func $i64x2.all_true (export "i64x2.all_true") (param v128) (result i32)
local.get 0
i64x2.all_true)
(func $i64x2.shl (export "i64x2.shl") (param v128 i32) (result v128)
local.get 0
local.get 1
Expand Down Expand Up @@ -759,10 +749,6 @@
local.get 0
local.get 1
i8x16.sub_saturate_s)
(func $i8x16.mul (type 15) (param v128 v128) (result v128)
local.get 0
local.get 1
i8x16.mul)
(func $i16x8.shl (type 11) (param v128 i32) (result v128)
local.get 0
local.get 1
Expand Down Expand Up @@ -973,12 +959,6 @@
(func $i64x2.neg (type 10) (param v128) (result v128)
local.get 0
i64x2.neg)
(func $i64x2.any_true (type 6) (param v128) (result i32)
local.get 0
i64x2.any_true)
(func $i64x2.all_true (type 6) (param v128) (result i32)
local.get 0
i64x2.all_true)
(func $f32x4.abs (type 10) (param v128) (result v128)
local.get 0
f32x4.abs)
Expand Down Expand Up @@ -1089,7 +1069,6 @@
(export "i8x16.sub" (func $i8x16.sub))
(export "i8x16.sub_saturate_u" (func $i8x16.sub_saturate_u))
(export "i8x16.sub_saturate_s" (func $i8x16.sub_saturate_s))
(export "i8x16.mul" (func $i8x16.mul))
(export "i16x8.neg" (func $i16x8.neg))
(export "i16x8.any_true" (func $i16x8.any_true))
(export "i16x8.all_true" (func $i16x8.all_true))
Expand All @@ -1113,8 +1092,6 @@
(export "i32x4.sub" (func $i32x4.sub))
(export "i32x4.mul" (func $i32x4.mul))
(export "i64x2.neg" (func $i64x2.neg))
(export "i64x2.any_true" (func $i64x2.any_true))
(export "i64x2.all_true" (func $i64x2.all_true))
(export "i64x2.shl" (func $i64x2.shl))
(export "i64x2.shr_s" (func $i64x2.shr_s))
(export "i64x2.shr_u" (func $i64x2.shr_u))
Expand Down
2 changes: 1 addition & 1 deletion crates/tests/tests/spec-tests
Submodule spec-tests updated 49 files
+18 −2 README.md
+2 −2 binary.wast
+374 −3 block.wast
+51 −0 br.wast
+55 −0 call.wast
+39 −10 call_indirect.wast
+199 −0 conversions.wast
+2 −2 custom.wast
+20 −0 fac.wast
+275 −15 func.wast
+497 −0 global.wast
+18 −0 i32.wast
+30 −0 i64.wast
+628 −11 if.wast
+318 −2 loop.wast
+30 −0 memory.wast
+195 −0 proposals/annotations/annotations.wast
+2 −2 proposals/bulk-memory-operations/binary.wast
+44 −0 proposals/bulk-memory-operations/bulk.wast
+2 −2 proposals/bulk-memory-operations/custom.wast
+17 −1 proposals/bulk-memory-operations/memory_init.wast
+26 −2 proposals/bulk-memory-operations/table_init.wast
+36 −1 proposals/reference-types/elem.wast
+1 −0 proposals/reference-types/linking.wast
+23 −1 proposals/reference-types/ref_func.wast
+2 −2 proposals/reference-types/select.wast
+31 −0 proposals/reference-types/table-sub.wast
+2 −0 proposals/reference-types/table_grow.wast
+568 −31 proposals/sign-extension-ops/i32.wast
+66 −32 proposals/sign-extension-ops/i64.wast
+268 −77 proposals/simd/simd_align.wast
+4 −0 proposals/simd/simd_const.wast
+4 −314 proposals/simd/simd_conversions.wast
+4 −8 proposals/simd/simd_f32x4.wast
+4 −4 proposals/simd/simd_f64x2.wast
+115 −21 proposals/simd/simd_i16x8_arith2.wast
+103 −18 proposals/simd/simd_i32x4_arith2.wast
+114 −21 proposals/simd/simd_i8x16_arith2.wast
+337 −57 proposals/simd/simd_lane.wast
+2 −26 proposals/simd/simd_load.wast
+112 −57 proposals/threads/atomic.wast
+30 −0 proposals/threads/memory.wast
+54 −0 table.wast
+18 −27 type.wast
+16 −1 update-testsuite.sh
+188 −188 utf8-custom-section-id.wast
+188 −188 utf8-import-field.wast
+188 −188 utf8-import-module.wast
+176 −176 utf8-invalid-encoding.wast
35 changes: 28 additions & 7 deletions crates/tests/tests/spec-tests.rs
@@ -1,4 +1,4 @@
use anyhow::Context;
use anyhow::{bail, Context};
use std::fs;
use std::path::Path;
use std::process::Command;
Expand All @@ -10,6 +10,12 @@ struct Test {
commands: Vec<serde_json::Value>,
}

const STABLE_FEATURES: &[&str] = &[
"--enable-multi-value",
"--enable-saturating-float-to-int",
"--enable-sign-extension",
];

fn run(wast: &Path) -> Result<(), anyhow::Error> {
static INIT_LOGS: std::sync::Once = std::sync::Once::new();
INIT_LOGS.call_once(|| {
Expand All @@ -23,11 +29,13 @@ fn run(wast: &Path) -> Result<(), anyhow::Error> {
.next()
.map(|s| s.to_str().unwrap());
let extra_args: &[&str] = match proposal {
None => &[],
Some("mutable-global") => &[],
Some("sign-extension-ops") => &["--enable-sign-extension"],
Some("multi-value") => &["--enable-multi-value"],
Some("nontrapping-float-to-int-conversions") => &["--enable-saturating-float-to-int"],
// stable features
None
| Some("multi-value")
| Some("nontrapping-float-to-int-conversions")
| Some("sign-extension-ops")
| Some("mutable-global") => &[],

Some("reference-types") => &["--enable-reference-types", "--enable-bulk-memory"],
Some("bulk-memory-operations") => &["--enable-bulk-memory"],

Expand All @@ -38,6 +46,9 @@ fn run(wast: &Path) -> Result<(), anyhow::Error> {
// TODO: should get tail-call working
Some("tail-call") => return Ok(()),

// not a walrus thing, but not implemented in wabt fully yet anyway
Some("annotations") => return Ok(()),

// Some("threads") => &["--enable-threads"],
Some(other) => panic!("unknown wasm proposal: {}", other),
};
Expand All @@ -48,11 +59,14 @@ fn run(wast: &Path) -> Result<(), anyhow::Error> {
.arg(wast)
.arg("-o")
.arg(&json)
.args(STABLE_FEATURES)
.args(extra_args)
.status()
.context("executing `wast2json`")?;
assert!(status.success());

let wabt_ok = run_spectest_interp(tempdir.path(), extra_args).is_ok();

let contents = fs::read_to_string(&json).context("failed to read file")?;
let test: Test = serde_json::from_str(&contents).context("failed to parse file")?;
let mut files = Vec::new();
Expand Down Expand Up @@ -128,6 +142,12 @@ fn run(wast: &Path) -> Result<(), anyhow::Error> {
}
}

// If wabt didn't succeed before we ran walrus there's no hope of it passing
// after we run walrus.
if !wabt_ok {
return Ok(());
}

// First up run the spec-tests as-is after we round-tripped through walrus.
// This should for sure work correctly
run_spectest_interp(tempdir.path(), extra_args)?;
Expand Down Expand Up @@ -159,6 +179,7 @@ fn run_spectest_interp(cwd: &Path, extra_args: &[&str]) -> Result<(), anyhow::Er
let output = Command::new("spectest-interp")
.current_dir(cwd)
.arg("foo.json")
.args(STABLE_FEATURES)
.args(extra_args)
.output()
.context("executing `spectest-interp`")?;
Expand All @@ -181,7 +202,7 @@ fn run_spectest_interp(cwd: &Path, extra_args: &[&str]) -> Result<(), anyhow::Er
println!("status: {}", output.status);
println!("stdout:\n{}", String::from_utf8_lossy(&output.stdout));
println!("stderr:\n{}", String::from_utf8_lossy(&output.stderr));
panic!("failed");
bail!("failed");
}

include!(concat!(env!("OUT_DIR"), "/spec-tests.rs"));
20 changes: 8 additions & 12 deletions src/ir/mod.rs
Expand Up @@ -619,7 +619,7 @@ impl Value {
encoder.f64(n);
}
Value::V128(n) => {
encoder.raw(&[0xfd, 0x02]); // v128.const
encoder.raw(&[0xfd, 0x0c]); // v128.const
for i in 0..16 {
encoder.byte((n >> (i * 8)) as u8);
}
Expand Down Expand Up @@ -796,7 +796,6 @@ pub enum BinaryOp {
I8x16Sub,
I8x16SubSaturateS,
I8x16SubSaturateU,
I8x16Mul,
I16x8Shl,
I16x8ShrS,
I16x8ShrU,
Expand Down Expand Up @@ -935,18 +934,19 @@ pub enum UnaryOp {

V128Not,

I8x16Abs,
I8x16Neg,
I8x16AnyTrue,
I8x16AllTrue,
I16x8Abs,
I16x8Neg,
I16x8AnyTrue,
I16x8AllTrue,
I32x4Abs,
I32x4Neg,
I32x4AnyTrue,
I32x4AllTrue,
I64x2Neg,
I64x2AnyTrue,
I64x2AllTrue,

F32x4Abs,
F32x4Neg,
Expand All @@ -955,14 +955,10 @@ pub enum UnaryOp {
F64x2Neg,
F64x2Sqrt,

I32x4TruncSF32x4Sat,
I32x4TruncUF32x4Sat,
I64x2TruncSF64x2Sat,
I64x2TruncUF64x2Sat,
F32x4ConvertSI32x4,
F32x4ConvertUI32x4,
F64x2ConvertSI64x2,
F64x2ConvertUI64x2,
I32x4TruncSatF32x4S,
I32x4TruncSatF32x4U,
F32x4ConvertI32x4S,
F32x4ConvertI32x4U,

I32TruncSSatF32,
I32TruncUSatF32,
Expand Down

0 comments on commit f5157bd

Please sign in to comment.