Skip to content

Commit

Permalink
Merge with upstream (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhil authored Sep 25, 2024
2 parents dca1732 + 00a589e commit 98efaab
Show file tree
Hide file tree
Showing 2,828 changed files with 22,953 additions and 21,161 deletions.
354 changes: 173 additions & 181 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ rayon = "1.3"
serde = { version = "1.0.166", default-features = false, features = ['alloc'] }
serde_derive = "1.0.166"
serde_json = { version = "1" }
wasmtime = { version = "24.0.0", default-features = false, features = ['cranelift', 'component-model', 'runtime', 'gc'] }
wasmtime = { version = "25.0.0", default-features = false, features = ['cranelift', 'component-model', 'runtime', 'gc'] }
url = "2.0.0"
pretty_assertions = "1.3.0"
semver = { version = "1.0.0", default-features = false }
Expand Down
3 changes: 3 additions & 0 deletions crates/fuzz-stats/src/bin/failed-instantiations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ impl State {
let mut config = wasm_smith::Config::arbitrary(&mut u)?;
config.allow_start_export = false;

config.exceptions_enabled = false; // Not implemented by Wasmtime
config.threads_enabled = false; // not enabled by default in Wasmtime

// NB: just added "table64" support to this and wasmtime doesn't
// implement that yet
config.memory64_enabled = false;
Expand Down
74 changes: 37 additions & 37 deletions crates/wasm-compose/tests/compositions/complex/composed.wat
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@
(type (;1;) (func (param i32 i32) (result i32)))
(type (;2;) (func (param i32 i32 i32 i32) (result i32)))
(import "a" "m" (func (;0;) (type 0)))
(memory (;0;) 0)
(export "memory" (memory 0))
(export "m" (func $m))
(export "canonical_abi_realloc" (func $canonical_abi_realloc))
(func $m (;1;) (type 1) (param i32 i32) (result i32)
unreachable
)
(func $canonical_abi_realloc (;2;) (type 2) (param i32 i32 i32 i32) (result i32)
unreachable
)
(memory (;0;) 0)
(export "memory" (memory 0))
(export "m" (func $m))
(export "canonical_abi_realloc" (func $canonical_abi_realloc))
)
(core module $m1 (;1;)
(type (;0;) (func (param i32 i32)))
Expand All @@ -99,6 +99,15 @@
(type (;3;) (func (param i32 i32 i32 i32 i32 i32 i32 i64 i64 f32 f64 i32 i32 i32)))
(type (;4;) (func (param i32 i32 i64 i32 i32 i32 i32 i32 i64 i64 f32 f64 i32 i32 i32)))
(type (;5;) (func (param i32)))
(table (;0;) 7 7 funcref)
(export "0" (func 0))
(export "1" (func 1))
(export "2" (func 2))
(export "3" (func 3))
(export "4" (func 4))
(export "5" (func 5))
(export "6" (func 6))
(export "$imports" (table 0))
(func (;0;) (type 0) (param i32 i32)
local.get 0
local.get 1
Expand Down Expand Up @@ -189,15 +198,6 @@
i32.const 6
call_indirect (type 5)
)
(table (;0;) 7 7 funcref)
(export "0" (func 0))
(export "1" (func 1))
(export "2" (func 2))
(export "3" (func 3))
(export "4" (func 4))
(export "5" (func 5))
(export "6" (func 6))
(export "$imports" (table 0))
)
(core module $m2 (;2;)
(type (;0;) (func (param i32 i32)))
Expand Down Expand Up @@ -366,6 +366,30 @@
(type (;9;) (func (param i32 i32 i64 i32 i32 i32 i32 i32 i64 i64 f32 f64 i32 i32 i32)))
(type (;10;) (func (result i32)))
(type (;11;) (func (param i32 i32 i32 i32) (result i32)))
(memory (;0;) 0)
(export "memory" (memory 0))
(export "a" (func $a))
(export "b" (func $b))
(export "c" (func $c))
(export "d" (func $d))
(export "e" (func $e))
(export "f" (func $f))
(export "g" (func $g))
(export "h" (func $h))
(export "i" (func $i))
(export "j" (func $j))
(export "k" (func $k))
(export "l" (func $l))
(export "m" (func $m))
(export "n" (func $n))
(export "o" (func $o))
(export "p" (func $p))
(export "q" (func $q))
(export "r" (func $r))
(export "s" (func $s))
(export "t" (func $t))
(export "u" (func $u))
(export "canonical_abi_realloc" (func $canonical_abi_realloc))
(func $a (;0;) (type 0)
unreachable
)
Expand Down Expand Up @@ -432,30 +456,6 @@
(func $canonical_abi_realloc (;21;) (type 11) (param i32 i32 i32 i32) (result i32)
unreachable
)
(memory (;0;) 0)
(export "memory" (memory 0))
(export "a" (func $a))
(export "b" (func $b))
(export "c" (func $c))
(export "d" (func $d))
(export "e" (func $e))
(export "f" (func $f))
(export "g" (func $g))
(export "h" (func $h))
(export "i" (func $i))
(export "j" (func $j))
(export "k" (func $k))
(export "l" (func $l))
(export "m" (func $m))
(export "n" (func $n))
(export "o" (func $o))
(export "p" (func $p))
(export "q" (func $q))
(export "r" (func $r))
(export "s" (func $s))
(export "t" (func $t))
(export "u" (func $u))
(export "canonical_abi_realloc" (func $canonical_abi_realloc))
)
(core instance (;0;) (instantiate 0))
(alias core export 0 "memory" (core memory (;0;)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
(import "example:service/[email protected]" "[method]logger.log" (func (;0;) (type 0)))
(import "example:service/[email protected]" "get-logger" (func (;1;) (type 1)))
(import "[export]example:service/[email protected]" "[resource-new]logger" (func (;2;) (type 2)))
(memory $memory (;0;) 1)
(export "memory" (memory $memory))
(export "cabi_realloc" (func $cabi_realloc))
(export "example:service/[email protected]#[method]logger.log" (func $logger-log))
(export "example:service/[email protected]#get-logger" (func $get-logger))
(func $cabi_realloc (;3;) (type 3) (param i32 i32 i32 i32) (result i32)
unreachable
)
Expand All @@ -55,16 +60,13 @@
(func $get-logger (;5;) (type 1) (result i32)
unreachable
)
(memory $memory (;0;) 1)
(export "memory" (memory $memory))
(export "cabi_realloc" (func $cabi_realloc))
(export "example:service/[email protected]#[method]logger.log" (func $logger-log))
(export "example:service/[email protected]#get-logger" (func $get-logger))
)
(core module $module-indirect (;1;)
(type (;0;) (func (param i32 i32 i32)))
(type (;1;) (func (result i32)))
(type (;2;) (func (param i32)))
(export "logger.log" (func $logger-log))
(export "[dtor]logger" (func $dtor-logger))
(func $logger-log (;0;) (type 0) (param i32 i32 i32)
unreachable
)
Expand All @@ -74,8 +76,6 @@
(func $dtor-logger (;2;) (type 2) (param i32)
unreachable
)
(export "logger.log" (func $logger-log))
(export "[dtor]logger" (func $dtor-logger))
)
(core instance $module-indirect-instance (;0;) (instantiate $module-indirect))
(alias export $import-logging-instance "logger" (type $import-logger-type (;1;)))
Expand Down
32 changes: 16 additions & 16 deletions crates/wasm-compose/tests/compositions/defs/composed.wat
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,22 @@
(type (;1;) (func (param i32 i32 i32 i32) (result i32)))
(import "wasi:cli-base/environment" "get-environment" (func (;0;) (type 0)))
(import "wasi:cli-base/environment" "get-arguments" (func (;1;) (type 0)))
(func (;2;) (type 1) (param i32 i32 i32 i32) (result i32)
unreachable
)
(memory (;0;) 0)
(export "memory" (memory 0))
(export "cabi_realloc" (func 2))
(func (;2;) (type 1) (param i32 i32 i32 i32) (result i32)
unreachable
)
(@producers
(processed-by "wit-component" "0.11.0")
)
)
(core module (;1;)
(type (;0;) (func (param i32)))
(table (;0;) 2 2 funcref)
(export "0" (func $indirect-wasi:cli-base/environment-get-environment))
(export "1" (func $indirect-wasi:cli-base/environment-get-arguments))
(export "$imports" (table 0))
(func $indirect-wasi:cli-base/environment-get-environment (;0;) (type 0) (param i32)
local.get 0
i32.const 0
Expand All @@ -47,10 +51,6 @@
i32.const 1
call_indirect (type 0)
)
(table (;0;) 2 2 funcref)
(export "0" (func $indirect-wasi:cli-base/environment-get-environment))
(export "1" (func $indirect-wasi:cli-base/environment-get-arguments))
(export "$imports" (table 0))
(@producers
(processed-by "wit-component" "0.11.0")
)
Expand Down Expand Up @@ -107,6 +107,15 @@
(type (;6;) (func (param i32) (result i32)))
(type (;7;) (func (param i32 i32)))
(type (;8;) (func (param i32 i32 i32) (result i32)))
(table (;0;) 1 1 funcref)
(memory (;0;) 17)
(global $__stack_pointer (;0;) (mut i32) i32.const 1048576)
(export "memory" (memory 0))
(export "wasi:cli-base/environment#get-environment" (func $wasi:cli-base/environment#get-environment))
(export "cabi_post_wasi:cli-base/environment#get-environment" (func $cabi_post_wasi:cli-base/environment#get-environment))
(export "wasi:cli-base/environment#get-arguments" (func $wasi:cli-base/environment#get-arguments))
(export "cabi_post_wasi:cli-base/environment#get-arguments" (func $cabi_post_wasi:cli-base/environment#get-arguments))
(export "cabi_realloc" (func $cabi_realloc))
(func $__wasm_call_ctors (;0;) (type 0))
(func $wasi:cli-base/environment#get-environment (;1;) (type 1) (result i32)
i32.const 0
Expand All @@ -119,15 +128,6 @@
(func $cabi_realloc (;5;) (type 5) (param i32 i32 i32 i32) (result i32)
i32.const 0
)
(table (;0;) 1 1 funcref)
(memory (;0;) 17)
(global $__stack_pointer (;0;) (mut i32) i32.const 1048576)
(export "memory" (memory 0))
(export "wasi:cli-base/environment#get-environment" (func $wasi:cli-base/environment#get-environment))
(export "cabi_post_wasi:cli-base/environment#get-environment" (func $cabi_post_wasi:cli-base/environment#get-environment))
(export "wasi:cli-base/environment#get-arguments" (func $wasi:cli-base/environment#get-arguments))
(export "cabi_post_wasi:cli-base/environment#get-arguments" (func $cabi_post_wasi:cli-base/environment#get-arguments))
(export "cabi_realloc" (func $cabi_realloc))
)
(core instance (;0;) (instantiate 0))
(alias core export 0 "memory" (core memory (;0;)))
Expand Down
1 change: 1 addition & 0 deletions crates/wasm-encoder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ wasmparser = { optional = true, workspace = true }
anyhow = { workspace = true }
tempfile = "3.2.0"
wasmparser = { path = "../wasmparser" }
wasmprinter = { path = "../wasmprinter" }
26 changes: 12 additions & 14 deletions crates/wasm-encoder/src/component/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,20 +206,6 @@ impl ComponentBuilder {
})
}

/// Creates an alias to a previous core instance's exported item.
///
/// The `instance` provided is the instance to access and the `name` is the
/// item to access.
///
/// Returns the index of the new item defined.
pub fn alias_core_export(&mut self, instance: u32, name: &str, kind: ExportKind) -> u32 {
self.alias(Alias::CoreInstanceExport {
instance,
kind,
name,
})
}

fn inc_kind(&mut self, kind: ComponentExportKind) -> u32 {
match kind {
ComponentExportKind::Func => inc(&mut self.funcs),
Expand Down Expand Up @@ -386,6 +372,18 @@ impl ComponentBuilder {
inc(&mut self.core_funcs)
}

/// Declares a new `thread.spawn` intrinsic.
pub fn thread_spawn(&mut self, ty: u32) -> u32 {
self.canonical_functions().thread_spawn(ty);
inc(&mut self.core_funcs)
}

/// Declares a new `thread.hw_concurrency` intrinsic.
pub fn thread_hw_concurrency(&mut self) -> u32 {
self.canonical_functions().thread_hw_concurrency();
inc(&mut self.core_funcs)
}

/// Adds a new custom section to this component.
pub fn custom_section(&mut self, section: &CustomSection<'_>) {
self.flush();
Expand Down
17 changes: 17 additions & 0 deletions crates/wasm-encoder/src/component/canonicals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,23 @@ impl CanonicalFunctionSection {
self.num_added += 1;
self
}

/// Defines a function which will spawns a new thread by invoking a shared
/// function of type `ty_index`.
pub fn thread_spawn(&mut self, ty_index: u32) -> &mut Self {
self.bytes.push(0x05);
ty_index.encode(&mut self.bytes);
self.num_added += 1;
self
}

/// Defines a function which will return the number of threads that can be
/// expected to execute concurrently.
pub fn thread_hw_concurrency(&mut self) -> &mut Self {
self.bytes.push(0x06);
self.num_added += 1;
self
}
}

impl Encode for CanonicalFunctionSection {
Expand Down
7 changes: 7 additions & 0 deletions crates/wasm-encoder/src/core.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod branch_hints;
mod code;
mod custom;
mod data;
Expand All @@ -16,6 +17,7 @@ mod tables;
mod tags;
mod types;

pub use branch_hints::*;
pub use code::*;
pub use custom::*;
pub use data::*;
Expand Down Expand Up @@ -154,6 +156,11 @@ impl Module {
&self.bytes
}

/// Give the current size of the module in bytes.
pub fn len(&self) -> usize {
self.bytes.len()
}

/// Finish writing this Wasm module and extract ownership of the encoded
/// bytes.
pub fn finish(self) -> Vec<u8> {
Expand Down
Loading

0 comments on commit 98efaab

Please sign in to comment.