Skip to content

Commit

Permalink
Merge pull request bytecodealliance#76 from dhil/wasmfx-merge
Browse files Browse the repository at this point in the history
Merge with upstream. 

Notably this patch uses the latest wasmfx-tools-1.0.55 release.
  • Loading branch information
dhil committed Jan 11, 2024
2 parents 3d6fef1 + 7ffab42 commit 98a6153
Show file tree
Hide file tree
Showing 31 changed files with 548 additions and 123 deletions.
172 changes: 101 additions & 71 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ serde_json = { workspace = true }
walkdir = { workspace = true }
test-programs-artifacts = { workspace = true }
bytesize = "1.3.0"
wit-component = { workspace = true }

[target.'cfg(windows)'.dev-dependencies]
windows-sys = { workspace = true, features = ["Win32_System_Memory"] }
Expand Down Expand Up @@ -119,6 +120,7 @@ members = [
"examples/fib-debug/wasm",
"examples/wasi/wasm",
"examples/tokio/wasm",
"examples/component/wasm",
"fuzz",
"winch",
"winch/codegen",
Expand Down Expand Up @@ -235,15 +237,15 @@ is-terminal = "0.4.0"
wit-bindgen = { version = "0.15.0", default-features = false }

# wasm-tools family:
wasmparser = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "wasmfx-tools-1.0.54.rev+1" }
wat = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "wasmfx-tools-1.0.54.rev+1" }
wast = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "wasmfx-tools-1.0.54.rev+1" }
wasmprinter = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "wasmfx-tools-1.0.54.rev+1" }
wasm-encoder = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "wasmfx-tools-1.0.54.rev+1" }
wasm-smith = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "wasmfx-tools-1.0.54.rev+1" }
wasm-mutate = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "wasmfx-tools-1.0.54.rev+1" }
wit-parser = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "wasmfx-tools-1.0.54.rev+1" }
wit-component = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "wasmfx-tools-1.0.54.rev+1" }
wasmparser = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "wasmfx-tools-1.0.55" }
wat = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "wasmfx-tools-1.0.55" }
wast = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "wasmfx-tools-1.0.55" }
wasmprinter = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "wasmfx-tools-1.0.55" }
wasm-encoder = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "wasmfx-tools-1.0.55" }
wasm-smith = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "wasmfx-tools-1.0.55" }
wasm-mutate = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "wasmfx-tools-1.0.55" }
wit-parser = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "wasmfx-tools-1.0.55" }
wit-component = { git = "https://github.com/wasmfx/wasmfx-tools", tag = "wasmfx-tools-1.0.55" }

# Non-Bytecode Alliance maintained dependencies:
# --------------------------
Expand Down
37 changes: 36 additions & 1 deletion cranelift/wasm/src/code_translator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2503,7 +2503,42 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
state.push1(r);
}

Operator::RefI31 | Operator::I31GetS | Operator::I31GetU => {
Operator::TryTable { .. } | Operator::ThrowRef => {
unimplemented!("exception operators not yet implemented")
}

Operator::RefI31
| Operator::I31GetS
| Operator::I31GetU
| Operator::RefEq
| Operator::RefTestNonNull { .. }
| Operator::RefTestNullable { .. }
| Operator::RefCastNonNull { .. }
| Operator::RefCastNullable { .. }
| Operator::BrOnCast { .. }
| Operator::BrOnCastFail { .. }
| Operator::AnyConvertExtern
| Operator::ExternConvertAny
| Operator::ArrayNew { .. }
| Operator::ArrayNewDefault { .. }
| Operator::ArrayNewFixed { .. }
| Operator::ArrayNewData { .. }
| Operator::ArrayNewElem { .. }
| Operator::ArrayGet { .. }
| Operator::ArrayGetU { .. }
| Operator::ArrayGetS { .. }
| Operator::ArraySet { .. }
| Operator::ArrayLen { .. }
| Operator::ArrayFill { .. }
| Operator::ArrayCopy { .. }
| Operator::ArrayInitData { .. }
| Operator::ArrayInitElem { .. }
| Operator::StructNew { .. }
| Operator::StructNewDefault { .. }
| Operator::StructGetS { .. }
| Operator::StructGetU { .. }
| Operator::StructSet { .. }
| Operator::StructGet { .. } => {
unimplemented!("GC operators not yet implemented")
}

Expand Down
1 change: 1 addition & 0 deletions cranelift/wasm/src/sections_translator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ pub fn parse_name_section<'data>(
| wasmparser::Name::Memory(_)
| wasmparser::Name::Element(_)
| wasmparser::Name::Data(_)
| wasmparser::Name::Tag(_)
| wasmparser::Name::Unknown { .. } => {}
}
}
Expand Down
12 changes: 7 additions & 5 deletions cranelift/wasm/src/translation_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::WasmResult;
use core::u32;
use cranelift_codegen::ir;
use cranelift_frontend::FunctionBuilder;
use wasmparser::{FuncValidator, WasmFuncType, WasmModuleResources};
use wasmparser::{FuncValidator, WasmModuleResources};
use wasmtime_types::WasmType;

/// Get the parameter and result types for the given Wasm blocktype.
Expand All @@ -30,11 +30,13 @@ where
wasmparser::BlockType::FuncType(ty_index) => {
let ty = validator
.resources()
.func_type_at(ty_index)
.expect("should be valid");
.sub_type_at(ty_index)
.expect("should be valid")
.unwrap_func();

(
itertools::Either::Right(ty.inputs()),
itertools::Either::Right(ty.outputs()),
itertools::Either::Right(ty.params().iter().copied()),
itertools::Either::Right(ty.results().iter().copied()),
)
}
});
Expand Down
2 changes: 1 addition & 1 deletion cranelift/wasm/wasmtests/icall-simd.wat
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
(func $foo (export "foo") (param i32) (param v128) (result v128)
(call_indirect (type $ft) (local.get 1) (local.get 0))
)
(table (;0;) 23 23 anyfunc)
(table (;0;) 23 23 funcref)
)
2 changes: 1 addition & 1 deletion cranelift/wasm/wasmtests/icall.wat
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
(func $foo (export "foo") (param i32 f32) (result i32)
(call_indirect (type $ft) (local.get 1) (local.get 0))
)
(table (;0;) 23 23 anyfunc)
(table (;0;) 23 23 funcref)
)
2 changes: 1 addition & 1 deletion cranelift/wasm/wasmtests/unreachable_code.wat
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@
end
drop
)
(table (;0;) 16 anyfunc)
(table (;0;) 16 funcref)
(elem (i32.const 0))
)
1 change: 1 addition & 0 deletions crates/environ/src/module_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,7 @@ and for re-adding support for interface types you can see this issue:
| wasmparser::Name::Memory(_)
| wasmparser::Name::Element(_)
| wasmparser::Name::Data(_)
| wasmparser::Name::Tag(_)
| wasmparser::Name::Unknown { .. } => {}
}
}
Expand Down
18 changes: 11 additions & 7 deletions crates/fuzzing/src/generators/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ impl Config {
// Allow a memory to be generated, but don't let it get too large.
// Additionally require the maximum size to guarantee that the growth
// behavior is consistent across engines.
config.max_memory_pages = 10;
config.max_memory32_pages = 10;
config.max_memory64_pages = 10;
config.memory_max_size_required = true;

// If tables are generated make sure they don't get too large to avoid
Expand Down Expand Up @@ -339,19 +340,22 @@ impl<'a> Arbitrary<'a> for Config {

// Ensure the pooling allocator can support the maximal size of
// memory, picking the smaller of the two to win.
if cfg.max_memory_pages < pooling.memory_pages {
pooling.memory_pages = cfg.max_memory_pages;
} else {
cfg.max_memory_pages = pooling.memory_pages;
}
let min = cfg
.max_memory32_pages
.min(cfg.max_memory64_pages)
.min(pooling.memory_pages);
pooling.memory_pages = min;
cfg.max_memory32_pages = min;
cfg.max_memory64_pages = min;

// If traps are disallowed then memories must have at least one page
// of memory so if we still are only allowing 0 pages of memory then
// increase that to one here.
if cfg.disallow_traps {
if pooling.memory_pages == 0 {
pooling.memory_pages = 1;
cfg.max_memory_pages = 1;
cfg.max_memory32_pages = 1;
cfg.max_memory64_pages = 1;
}
// .. additionally update tables
if pooling.table_elements == 0 {
Expand Down
7 changes: 3 additions & 4 deletions crates/fuzzing/src/generators/module.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
//! Generate a Wasm module and the configuration for generating it.

use arbitrary::{Arbitrary, Unstructured};
use wasm_smith::SwarmConfig;

/// Default module-level configuration for fuzzing Wasmtime.
///
/// Internally this uses `wasm-smith`'s own `SwarmConfig` but we further refine
/// Internally this uses `wasm-smith`'s own `Config` but we further refine
/// the defaults here as well.
#[derive(Debug, Clone)]
pub struct ModuleConfig {
#[allow(missing_docs)]
pub config: SwarmConfig,
pub config: wasm_smith::Config,
}

impl<'a> Arbitrary<'a> for ModuleConfig {
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<ModuleConfig> {
let mut config = SwarmConfig::arbitrary(u)?;
let mut config = wasm_smith::Config::arbitrary(u)?;

// Allow multi-memory but make it unlikely
if u.ratio(1, 20)? {
Expand Down
10 changes: 5 additions & 5 deletions crates/fuzzing/src/generators/single_inst_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,11 @@ static INSTRUCTIONS: &[SingleInstModule] = &[
inst!(F32Ge, (f32, f32) -> i32),
inst!(F64Ge, (f64, f64) -> i32),
// Integer conversions ("to integer").
inst!(I32Extend8S, (i32) -> i32, |c| c.config.sign_extension_enabled),
inst!(I32Extend16S, (i32) -> i32, |c| c.config.sign_extension_enabled),
inst!(I64Extend8S, (i64) -> i64, |c| c.config.sign_extension_enabled),
inst!(I64Extend16S, (i64) -> i64, |c| c.config.sign_extension_enabled),
inst!(I64Extend32S, (i64) -> i64, |c| c.config.sign_extension_enabled),
inst!(I32Extend8S, (i32) -> i32, |c| c.config.sign_extension_ops_enabled),
inst!(I32Extend16S, (i32) -> i32, |c| c.config.sign_extension_ops_enabled),
inst!(I64Extend8S, (i64) -> i64, |c| c.config.sign_extension_ops_enabled),
inst!(I64Extend16S, (i64) -> i64, |c| c.config.sign_extension_ops_enabled),
inst!(I64Extend32S, (i64) -> i64, |c| c.config.sign_extension_ops_enabled),
inst!(I32WrapI64, (i64) -> i32),
inst!(I64ExtendI32S, (i32) -> i64),
inst!(I64ExtendI32U, (i32) -> i64),
Expand Down
1 change: 1 addition & 0 deletions crates/test-programs/artifacts/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ fn build_and_generate_tests() {
s if s.starts_with("cli_") => "cli",
s if s.starts_with("api_") => "api",
s if s.starts_with("nn_") => "nn",
s if s.starts_with("piped_") => "piped",
// If you're reading this because you hit this panic, either add it
// to a test suite above or add a new "suite". The purpose of the
// categorization above is to have a static assertion that tests
Expand Down
51 changes: 51 additions & 0 deletions crates/test-programs/src/bin/piped_polling.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use test_programs::wasi::cli::{stdin, stdout};

fn main() {
match std::env::var("PIPED_SIDE")
.expect("piped tests require the PIPED_SIDE env var")
.as_str()
{
"PRODUCER" => producer(),
"CONSUMER" => consumer(),
side => panic!("unknown piped test side: {side}"),
}
}

fn producer() {
let out = stdout::get_stdout();
let out_pollable = out.subscribe();

for i in 1..100 {
let message = format!("{i}");
loop {
let available = out.check_write().unwrap() as usize;
if available >= message.len() {
break;
}

out_pollable.block();
assert!(out_pollable.ready());
}

out.write(message.as_bytes()).unwrap()
}

drop(out_pollable);
}

fn consumer() {
let stdin = stdin::get_stdin();
let stdin_pollable = stdin.subscribe();

for i in 1..100 {
let expected = format!("{i}");

stdin_pollable.block();
assert!(stdin_pollable.ready());

let bytes = stdin.read(expected.len() as u64).unwrap();
assert_eq!(&bytes, expected.as_bytes());
}

drop(stdin_pollable);
}
30 changes: 30 additions & 0 deletions crates/test-programs/src/bin/piped_simple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use test_programs::wasi::cli::{stdin, stdout};

fn main() {
match std::env::var("PIPED_SIDE")
.expect("piped tests require the PIPED_SIDE env var")
.as_str()
{
"PRODUCER" => producer(),
"CONSUMER" => consumer(),
side => panic!("unknown piped test side: {side}"),
}
}

const CHUNK: &[u8] = &[b'a'; 50];

fn producer() {
let out = stdout::get_stdout();
let n = out.check_write().unwrap() as usize;
assert!(n > CHUNK.len());
out.write(CHUNK).unwrap();
}

fn consumer() {
let stdin = stdin::get_stdin();
let stdin_pollable = stdin.subscribe();
stdin_pollable.block();
assert!(stdin_pollable.ready());
let bytes = stdin.read(CHUNK.len() as u64).unwrap();
assert_eq!(&bytes, CHUNK);
}
22 changes: 19 additions & 3 deletions crates/test-programs/src/bin/preview2_stream_pollable_correct.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
use test_programs::wasi::cli::stdin;
use test_programs::wasi::io::streams;
use test_programs::wasi::cli::{stdin, stdout};

fn main() {
let stdin: streams::InputStream = stdin::get_stdin();
let stdin = stdin::get_stdin();
let stdin_pollable = stdin.subscribe();
stdin_pollable.block();
assert!(stdin_pollable.ready(), "after blocking, pollable is ready");
drop(stdin_pollable);
drop(stdin);

// Pollables can be used many times over their lifetime
let stdout = stdout::get_stdout();
let stdout_pollable = stdout.subscribe();

let chunk = [b'a'; 50];
for _ in 1..10 {
stdout_pollable.block();
assert!(stdout_pollable.ready(), "after blocking, pollable is ready");

let n = stdout.check_write().unwrap() as usize;
assert!(n >= chunk.len());
stdout.write(&chunk).unwrap();
}

drop(stdout_pollable);
drop(stdout);
}
1 change: 1 addition & 0 deletions crates/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ pub trait TypeConvert {
wasmparser::HeapType::Concrete(i) => self.lookup_heap_type(i),

wasmparser::HeapType::Any
| wasmparser::HeapType::Exn
| wasmparser::HeapType::None
| wasmparser::HeapType::NoExtern
| wasmparser::HeapType::NoFunc
Expand Down
2 changes: 2 additions & 0 deletions crates/wasmtime/src/engine/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ impl Metadata<'_> {
typed_continuations,
gc,
component_model_values,
component_model_nested_names,

// Always on; we don't currently have knobs for these.
mutable_global: _,
Expand All @@ -234,6 +235,7 @@ impl Metadata<'_> {
assert!(!memory_control);
assert!(!gc);
assert!(!component_model_values);
assert!(!component_model_nested_names);

Metadata {
target: engine.compiler().triple().to_string(),
Expand Down
2 changes: 2 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ create_target(wasi wasi/main.c)
create_rust_wasm(fib-debug wasm32-unknown-unknown)
create_rust_wasm(tokio wasm32-wasi)
create_rust_wasm(wasi wasm32-wasi)
create_rust_wasm(component wasm32-unknown-unknown)
create_rust_test(epochs)
create_rust_test(externref)
create_rust_test(fib-debug)
Expand All @@ -77,3 +78,4 @@ create_rust_test(serialize)
create_rust_test(threads)
create_rust_test(wasi)
create_rust_test(tokio wasmtime-wasi/tokio)
create_rust_test(component)
Loading

0 comments on commit 98a6153

Please sign in to comment.