Realized we don't actually talk about this in the documentation but it's
an important point, so make sure to document the interaction with
blocking host calls here.
* Enable clap's `wrap_help` feature by default
This is similar to bytecodealliance/wasm-tools#1746 which makes the help
text easier to read on various terminal widths.
* Fix `cargo deny`
* Make the Wasmtime CLI use async
This means that interrupting a running Wasm program will now work
correctly, even when the program is blocked on I/O or waiting on a timeout or
some such.
This also involved making `wasi-threads` async-compatible.
Co-Authored-By: Alex Crichton <alex@alexcrichton.com>
* rustfmt
* Make `run` command enable the `tokio` feature
* Add a test for CLI, timeouts, and sleeping forever
* Fix warning
---------
Co-authored-by: Alex Crichton <alex@alexcrichton.com>
* Do not deallocate disabled GC heaps in the instance allocator
When the reference types proposal is disabled, we don't allocate a GC heap from
the instance allocator, we instead create a `DisabledGcHeap`. Rather than
returning this to the instance allocator when we're done with it, which won't
even know what to do with it since the instance allocator didn't create the GC
heap, we simply rely on the `DisabledGcHeap`'s `Drop` implementation.
* check gc types instead of reference types
This commits adds pattern-matches to detect 128-bit comparisons encoded
in 64-bit comparisons and promote them to 128-bit to enable backends to
apply architecture-specific optimizations to these operations.
This allows, for example, getting `trace!` logs from Cranelift out of
`wasmtime-cli` tests, rather than needing to modify `cranelift-codegen`'s
default features or whatever.
* Expand the set of constructors of `bindgen!`-generated bindings
This commit expands the set of supported constructors for `bindgen!`
generated structures with the goal of bringing back
`World::new(&mut store, instance)`. This method was removed previously
in a refactoring to add `*Pre` structures but refactoring preexisting
code to use `*Pre` isn't always easy, so these extra generated bindings
provide a smoother migration path for code from before.
* Update test expectations
* Fix `cranelift-codegen` build script for Pulley backends
The cargo feature is called "pulley" for both the pulley32 and pulley64
backends, since they are the same code, but the build script was checking for
cargo features named "pulley32" and "pulley64" instead.
* Fix warnings in build
* winch: Improve result handling for Aarch64
This commit introduces missing tests for Aarch64's ABI implementation.
Compared to the x64 counterpart, the aarch64 implementation was missing
tests for multi-value.
Additionally, this commit fixes an issue with how multi-value returns
are handlded in Winch's default calling convention, which only allows
1 register result, independent of the register class.
This commit also refactors the register indexing environment so that it
can be easily shared across the existing backends.
* Keep comments on Aarch64 register assignment
Use the new `WasmFeatures::wasm2()` constructor to avoid having to
indefinitely list old proposals where this can get updated as newer
versions of the specification are released that Wasmtime fully
implements. Additionally slightly refactor how conditional enabling of
features work and instead use the `set` function to guarantee setting
the requisite feature to the desired value.
Increase the limit of supported typed parameters in functions, in order
to support the WIT interface of functions that have 16 flat type
parameters plus an extra pointer for the heap return area.
Mostly frobbing what features are active for spec tests and handling the
fact that `memory64` has been rebased on the 3.0 draft version which
includes gc/function-references/exceptions/etc.
* Update the consequences of disabling the `gc` crate feature
This commit updates what happens when the `gc` Cargo feature is disabled
at compile time when compiling Wasmtime itself. Previously this would
disable the reference-types proposal (and eventually once finished the
gc/function-references proposal). This has the downside, however, of
additionally disabling non-gc-related features that were bundled into
the `reference-types` proposal such as multi-table and the encodings of
table indices as LEBs in `call_indirect` instructions for example.
The change in this commit is to instead toggle the newly-added
`GC_TYPES` feature in `wasmparser`. This feature does not correspond to
upstream wasm proposals and instead only gates types such as `externref`
or `anyref`. The `funcref` and `exnref` types are not gated as they're
not expected to require a full GC.
This means that in Wasmtime the `reference-types` feature is now always
active by default regardless of crate features. If the `gc` crate
feature is disabled then only `externref` values are disallowed.
This additionally flags `GC_TYPES` as unsupported in Winch due to no
support for `externref` yet. This means, though, that Winch can be
considered as supporting the `reference-types` proposal (and things like
multi-table) as expected. Disabling `externref` support switched a few
tests to failing so those exceptions are now listed in `tests/wast.rs`
* Fix aarch64 tests
* Fix older invocations of `check_cfg_bool`
* Bump wasm-tools dependencies
This commit updates the wasm-tools dependencies to their 216 track of
versions. This will be followed-up with some updates to how some
features are managed.
* Update vets and depend on crates.io
* pulley: add `push` and `pop` instructions
Add `xpush{32, 64}` and `xpop{32, 64}` for pushing/popping XRegs from the stack,
and `push_frame`/`pop_frame` for saving/restoring LR and FP in function
prologue/epilogue.
Copyright (c) 2024, Arm Limited.
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
* cranelift-bitset: more impls for `ScalarBitset`
Implement `Arbitrary` for `ScalarBitset`.
Also implement `DoubleEndedIterator` and `ExactSizeIterator` for `Iter`.
The `pop_min` method was added to help implement `DoubleEndedIterator`,
and `pop` was renamed to `pop_max` for consistency.
Copyright (c) 2024, Arm Limited.
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
* pulley: add instructions for pushing/popping list of registers
Add `xpush{32,64}_many` and `xpop{32,64}_many` for pushing/popping any
combination of all 32 XRegs.
Copyright (c) 2024, Arm Limited.
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
---------
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
* Update handling of wasm features and `*.wast` testing
This commit is an attempt at making it easier to manage the set of
variables we have in play with `*.wast` testing and wasm features.
The Cranelift and Winch backends support different sets of wasm features
at this time and historically Cranelift has also had
architecture-specific support for wasm features. This is hoped to help
simplify management of all of this in the future in addition to making
`*.wast` testing more robust. Notable changes here are:
* A `Config` no longer tracks a `WasmFeatures` but instead only tracks
explicitly disabled/enabled features. The final `WasmFeatures` is then
computed given the result of compiler configuration.
* Default-enabled features now start from nothing instead of
`wasmparser`'s defaults to avoid future breakage there.
* Each compiler configuration and/or backend now has a listed set of
"this feature may panic" wasm features. These are all disabled by
default and if explicitly enabled a `Config::validate` error is
returned.
* All `*.wast` tests are now run through both Cranelift and Winch. Tests
are now asserted to either fail or pass depending on configuration and
the whole test will fail if the result doesn't match the expectation.
* Many `gc` proposal tests which are now passing are flagged as passing
now. Failing `winch` tests are now explicitly listed instead of using
a litany of patterns.
* Change panicking features for winch
* Fix builds without a compiler
* stack_switch instruction
* Update cranelift/codegen/src/isa/x64/pcc.rs
Co-authored-by: Nick Fitzgerald <fitzgen@gmail.com>
* cargo fmt
* only lower on linux
* give stack_switch the call() side effect
* add function in filetest doing switching only
* Extend documentation of new instruction
* better comments on how we handle the payloads
* Revert "only lower on linux"
This reverts commit 2af10f9441.
* Add StackSwitchModel, use to compile stack_switch
* turn stack_switch_model into partial constructor
---------
Co-authored-by: Nick Fitzgerald <fitzgen@gmail.com>
Turns out just having `git` wasn't enough. In the containers things are
running as `root` and `git` doesn't like that so try to convince git
that it should like it.
* Introduce `wasmtime::ArrayRef` and allocating Wasm GC arrays
This commit introduces the `wasmtime::ArrayRef` type and support for allocating
Wasm GC arrays from the host. This commit does *not* add support for the
`array.new` family of Wasm instructions; guests still cannot allocate Wasm GC
objects yet, but initial support should be pretty straightforward after this
commit lands.
The `ArrayRef` type has everything you expect from other value types in the
`wasmtime` crate:
* A method to get its type or check whether it matches a given type
* An implementation of `WasmTy` so that it can be used with `Func::wrap`-style
APIs
* The ability to upcast it into an `AnyRef` and to do checked downcasts in the
opposite direction
There are, additionally, methods for getting, setting, and enumerating a
`ArrayRef`'s elements.
Similar to how allocating a Wasm GC struct requires a `StructRefPre`, allocating
a Wasm GC array requires an `ArrayRefPre`, and this is motivated by the same
reasons.
* fix some doc tests and add docs for Func::wrap-style APIs
* Add a comment about why we can't user `iter::repeat(elem).take(len)`
* Fix some warnings in no-gc builds
* winch: Solidify bounds check for dynamic heaps
This commit fixes and edge case for bounds checks for dynamic heaps.
https://github.com/bytecodealliance/wasmtime/pull/8157/files erroneously
tied the bounds check operation (more concretely the overflow check) to the size derived from from the heap
type. Even though offsets and access sizes are validated ahead-of-time
and bound to the heap type, in the case of overflow checking, we must
ensure that the operation size is tied to the target's pointer size to
avoid clamping the access size and offset addition, which would result
in missing an out-of-bounds memory access.
This commit also adds a disassembly test to avoid introducing
regressions in the future.
Additionally, this commit adds more comments around why `pointer_size`
is used for certain bounds checking operations.
* Update disassembly test
Precompiled artifacts for macOS show this for `wasmtime --version`
wasmtime-cli 24.0.0 (6fc3d274c 2024-08-20)
whereas for Linux they show
wasmtime-cli 24.0.0
and this is due to `git` not being available in the build environment on
Linux.
The skeleton unit may contain attributes that don't appear in
the split unit. In particular, this includes DW_AT_ranges and
DW_AT_comp_dir.
Also, set the correct form for the default directory in the
line program. Previously, the different form meant that we emitted
the directory again when a file used it. Copying the DW_AT_comp_dir
attribute is required for use of the default directory to work
successfully.
This commit is similar to #8976 where it's fixing some typos in the
encoding of the `adc` and `sbb` instructions used in Cranelift. These
appear to have copy/paste typos where the non-register-based opcodes
weren't updated from the `add` and `sub` opcodes. This problem was
exposed from a fuzz test case after #9136 landed. The fuzz test case is
minimized and included here as a new runtest and new emit tests are
additionally added.
This commit fixes an issue where a `Value` was both load-sunk and used
as-is, meaning it was both sunk and not. That triggered a panic in the
backend since this isn't valid. The reason for this is due to how some
ISLE rules were written where a `Value` was both implicitly coerced into
an `XmmMem` and an `Xmm`. This issue is similar to #4815 for example.
The fix in this commit is to force the operands into registers which
prevents load sinking which wouldn't work here anyway.
This panic was introduced in #5841 which is quite old at this point.
This bug does not affect WebAssembly translation due to how the `v128`
type maps to `i8x16` in Cranelift by default.
Closes#9143
* pulley: use enums for `{X,F,V}Reg`
Copyright (c) 2024, Arm Limited.
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
* pulley: add `BinaryOperands`
Copyright (c) 2024, Arm Limited.
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
* pulley: use `BinaryOperands` for binary operators
Copyright (c) 2024, Arm Limited.
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
---------
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
This commit builds on the support added in #8450 to extend our simple
interpreter with support for the `extended-const` proposal to
WebAssembly. This is required when updating the spec-test-submodule
since `extended-const` was merged into the mainline specification and
some proposals are starting to rebase on that.
* Move `compute_use_states` to be able to test it
Make it a free-function so it doesn't depend on the `I` type variable of `Lower`
* Don't force `Multiple` on multi-result instructions
This commit is a result of [discussion on Zulip][Zulip] and is
attempting to fix an issue where some 128-bit instructions aren't fully
benefitting from load sinking on x64. At a high level 128-bit
addition isn't able to sink loads into instructions for halves of the
128-bit operation. At a lower level the reason for this is that
currently all operands of a multiple-result instruction are considered
multiply-used (as each result could be used) which prevents load
sinking.
Operations on 128-bit integers may be coupled with `isplit` afterwards
which is a multi-result instruction. This then means that the `Multiple`
state flows backwards to the 128-bit operation and all its operands,
including whatever is necessary to produce the individual components of
each 128-bit integer.
The fix in this commit is to introduce the concept of a "root"
instruction from the perspective of the calculation of `ValueUseState`.
In other words `ValueUseState` is no longer an accurate picture of the
function as a whole, but only the parts of the function rooted at a
"root" instruction. This is currently defined as multi-result
instructions meaning that `isplit` for example is a root instruction.
This is coupled with documentation/changes to
`get_value_as_source_or_const` to never allow looking through root
instructions (or considering them a `UniqueUse`).
This commit additionally updates some documentation in a few places and
refactors some usage of `get_value_as_source_or_const` to use other
helpers instead to reduce callers of `get_value_as_source_or_const` and
who to audit when modifying this function.
[Zulip]: https://bytecodealliance.zulipchat.com/#narrow/stream/217117-cranelift/topic/ValueUseState.3A.3AMultiple.20and.20multi-result.20instructions/near/462833578
* Review comments
* Remove unneeded `cu_low_pc` parameter
`unit.low_pc` is the same value.
* Simplify `clone_line_program`
We were parsing things that had already been parsed into `gimli::Unit`,
such as `DW_AT_comp_dir`, `DW_AT_name`, and `DW_AT_stmt_list`.
* Use `gimli::Dwarf` methods in more places
This moves Wasmtime over from the old, regalloc-based stack maps system to the
new "user" stack maps system.
Removing the old regalloc-based stack maps system is left for follow-up work.
This adds `pooling-table-elements` and `pooling-max-core-instance-size` options
to the CLI, allowing the user to override the defaults.
I found myself needing to override both of these settings when running a ASP.NET
Core application built using the Native AOT feature of the .NET runtime.
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
* Implement a few minor optimizations around 128-bit integers
This commit implements a few minor changes for `i128` in both the egraph
optimizations and lowerings for x64. The optimization pass will now
transform `iconcat` into a `uextend` or `sextend` where appropriate.
The x64 backend then pattern-matches this to produce slightly more
optimal machine code. Additionally the x64 backend now handles
memory/immediate operands a bit better when the argument to a 128-bit
operation is an `iconcat`.
* Update test expectations
* Match iadd lowering rules for isub
* Add the ability to generate async drop methods for resources.
In the component model, `resource.drop` is a canonical built-in without a proper name. So I invented a custom naming scheme for the component bindgen config. I went with:
`"[drop]{resource-name}"` where `{resource-name}` is the name as defined in WIT. e.g. `"[drop]input-stream"`.
This shouldn't conflict with anything existing in the wild as WIT identifiers are not allowed to contain square brackets.
* Make `input-stream::drop` & `output-stream::drop` async
* Prevent the guest from (inadvertently) spawning an unlimited amount of background tasks through the FileOutputStream
* Properly clean up background tasks for even more types of I/O streams.
Unlike FileOutputStream, the background tasks of these stream types are truly async. So aborting _without_ awaiting them was probably already good enough in practice. Nonetheless, waiting for the background to actually shut down just seems like good resource management "hygiene" to me.
* Let HostInput/OutputStream provide specialized blocking_* implementations.
* Rename filesystem's `spawn_blocking` -> `run_blocking`
* Implement specialized `blocking_write_and_flush` for FileOutputStream.
- `write` now always spawns the syscall on a background task, regardless of `allow_blocking_current_thread`.
- `blocking_write_and_flush` is newly overridden and continues to do the `allow_blocking_current_thread` trickery that `write` used to do.
* Implement `HostInputStream` for `FileInputStream`.
- `read` always spawns the syscall on a background task, regardless of `allow_blocking_current_thread`.
- `blocking_read` performs the `run_blocking`/`allow_blocking_current_thread` trickery.
* In Preview1 adapter: ignore BlockingMode and always perform blocking I/O, as that's what preview1 did.
* Remove special case for FileInputStream and change InputStream enum to be a type alias, just like OutputStream
* Remove `[method]output-stream.forward` from bindgen config. It does not exist.
* Refactor `blocking_splice` to take advantage of specialized `blocking_read` & `blocking_write_and_flush` implementations
* Defer to regular `read` from within `blocking_read` to reduce duplication of logic.