* add new wasi-test printing unicode on stdout
there's not yet a way to show this test is actually doing what we
intend, I'm using CI to see how this runs on all platforms
Reported in #6824
prtest:full
* cap-std-sync: use std::io::Std{in,out,err}'s {read,write}_vectored directly
instead of using AsFilelike to view these as a File.
This means we also have to use std's mutexes to access these descriptors,
which also seems like a good idea.
We believe will fix unicode output on windows issues:
https://github.com/bytecodealliance/wasmtime/issues/6824
This was removed in #6195 but re-added in #6877, I believe by accident,
so this re-deletes it. I've also edited `.gitmodules` a bit while I was
here to remove it and additionally keep other entries up-to-date with
matching paths.
The MachineEnv structure contains the allocatable and preferred
register sets. This is currently fixed per TargetIsa - however,
conceptually these register sets can differ between ABIs on the
same ISA.
To allow for this, replace the TargetIsa machine_env routine with
an ABIMachineSpec get_machine_env routine. To ensure the structure
is still only allocated once, cache it via static OnceLock variables.
No functional change intended.
This patch refactors all of the ISA/ABI specific prolog/epilog
generation code around the following two ideas:
1. Separate *planning* of the function's frame layout from the
actual *implementation* within prolog / epilog code.
2. No longer overload different purposes (middle-end register
tracking, platform-specific details like authorization modes,
and pop-stack-on-return) into a single return instruction.
As to 1., the new approach is based around a FrameLayout data
structure, which collects all information needed to emit prolog
and epilog code, specifically the list of clobbered registers,
and the sizes of all areas of the function's stack frame.
This data structure is now computed *once*, before any code is
emitted, and stored in the Callee data structure. ABIs need to
implement this via a new compute_frame_layout callback, which
gets all data from common code needed to make all decisions
around stack layout in one place.
The FrameLayout is then used going forward to answer all questions
about frame sizes, and it is passed to all ABI routines involved
in prolog / epilog code generation. [ This removes a lot of
duplicated calculation, e.g. the list of clobbered registers is
now only computed once and re-used everywhere. ]
This in turn allows to reduce the number of distinct callbacks
ABIs need to implement, and simplifies common code logic around
how and when to call them. In particular, we now only have the
following four routines, which are always called in this order:
gen_prologue_frame_setup
gen_clobber_save
gen_clobber_restore
gen_epilogue_frame_restore
The main differences to before are:
- frame_setup/restore are now called unconditionally (the target
ABI can look in the FrameLayout to detect the case where no
frame setup is required and skip whatever it thinks appropriate
in that case)
- there is no separate gen_prologue_start; if the target needs
to do anything here, it can now just do it instead in
gen_prologue_frame_setup
- common code no longer attempts to emit a return instruction;
instead the target can do whatever is necessary/optimal in
gen_epilogue_frame_restore
[ In principle we could also just have a single gen_prologue
and gen_epilogue callback - I didn't implement this because
then all the stack checking / probing logic would have to be
moved to target code as well. ]
As to 2., currently targets are required to implement a single
"Ret" return instruction. This is initially used during
register allocation to hold a list of return preg/vreg pairs.
During epilog emission, this is replaced by another copy of
the same "Ret" instruction that now carries various platform
specific data (e.g. authorization modes on aarch64), and is
also overloaded to handle the case where the ABI requires
that a number of bytes are popped during return.
This is a bit unfortunate in that it blows up the size of
the instruction data, and also forces targets (that do not
have a "ret N" instruction like Intel) into duplicated and
possible sub-optimal implementations of stack adjustment
during low-level emission of the return instruction.
The new approach separates these concerns. Initially, common
code emits a new "Rets" instruction that is completely parallel
to the existing "Args", and is used only during register
allocation holding the preg/vreg pairs. That instruction
-like now- is replaced during epilog emission - but unlike
now the replacement is now completely up to the target, which
can do whatever it needs in gen_epilogue_frame_restore.
This would typically emit some platform-specific low-level
"Ret" instruction instead of the regalloc "Rets". It also
allows non-Intel targets to just create a normal (or even
optimized) stack adjustment sequence before its low-level "Ret".
[ In particular, on riscv64 pop-stack-before-return currently
emits two distinct stack adjustment instructions immediately
after one another. These could now be easily merged, but that's
not yet done in this patch. ]
No functional change intended on any target.
* Stream backpressure v2
Co-authored-by: Pat Hickey <phickey@fastly.com>
Co-authored-by: Trevor Elliott <telliott@fastly.com>
Co-authored-by: Dan Gohman <dev@sunfishcode.online>
Stop testing pseudocode
Restructure when notifications are sent, and make sure to flush the writer
Fix the wasi-http module versions of flush and blocking_flush
Use blocking_write_and_flush for blocking writes in the adapters
Fix a warning in wasi-http
Remove an unused DropPollable
add comment explaining try_write for tcpstream
refactor: separate struct for representing TcpReadStream
by factoring into HostTcpSocket a little bit
tcp read stream: handle stream closing
tcp tests: use blocking_read where its expecting to wait for input
move common test body into wasi-sockets-tests/src/lib.rs
ensure parent socket outlives pollable
input and output streams can be children now
tcp's streams are the sockets children
tcp.wit: document child relationships
tcp tests: fix to drop socket after its child streams
review feedback: propogate worker task panic
style
error source fix
tcp: use preview2::spawn, and propogate worker panics
join handle await always propogates panic
background task handles ewouldblock as well
document choice of constant
* sync wit notes into wasi-http
* improve wit docs for output-stream
* doc: document `HostOutputStream` (#6980)
* doc: document `HostOutputStream`
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Co-authored-by: Pat Hickey <pat@moreproductive.org>
* fix(wasi): fail when `MemoryOutputStream` buffer is full
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
---------
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Co-authored-by: Pat Hickey <pat@moreproductive.org>
* rustfmt
prtest:full
* windows and doc fixes
* cli test wasi-http: use blocking-write-and-flush
* Disable some tests, and adjust timeouts when running under qemu
* Try to reproduce the riscv64 failures
* Update riscv to LLVM 17 with beta rust
* Revert "Try to reproduce the riscv64 failures"
This reverts commit 8ac678171f.
* Pin the beta version for riscv64
* Fix a warning on nightly
---------
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Co-authored-by: Roman Volosatovs <rvolosatovs@users.noreply.github.com>
Co-authored-by: Trevor Elliott <telliott@fastly.com>
Co-authored-by: Alex Crichton <alex@alexcrichton.com>
Running cargo license on the c-api crate reports that this crate is
unlicensed.
We use cargo-license to automate our license tracking for this library
in our C++ application and it'd be nice to just have a license in here.
I used the standard license that wasmtime uses, but happy to use
another.
Signed-off-by: Tyler Rockwood <rockwood@redpanda.com>
* x64: Add support for sarx, shlx, and shrx
These instructions are in the BMI2 instruction set and unconditionally
used by LLVM for shifts which don't have an immediate. They're
equivalent to the sar, shl, and shr instructions except they use
3-operand form to lessen register allocation pressure.
Currently the integration here doesn't add new lowering but instead
takes an AVX-like approach by updating the `x64_sar` and related helpers
to use `sarx` instead if it fits. This means that the
shift-a-value-stored-in-memory functionality of `sarx` and friends isn't
exposed, so that's left for a future PR.
* x64: Add support for BMI2 `rorx` instruction
This is similar to `rol` and `ror` but requires an immediate argument
and additionally has no constraints on registers.
* x64: Add support for BMI2 `bzhi` instruction
This commit adds support for the `bzhi` instruction which is part of
BMI2. This instruction is used to zero out the upper bits of a register
indexed by a register operand. Emission of this instruction is
pattern-matched on CLIF which looks like this pattern. Equivalent code
fed to LLVM will additionally generate the `bzhi` instruction.
Relative to the alternative lowerings x64 provides this gives a little
bit more register freedom and additionally cuts down on a few
instructions. Note that the raw functionality of `bzhi` can't be exposed
though because the semantics of when the index is out-of-bounds doesn't
match easily to a CLIF instruction, so usage of `bzhi` is always
preceded by an `and` instruction. This matches LLVM as well, but LLVM
probably has fancy logic where if it can prove the range of values of
the index it probably elides the `and`.
* Pattern match more `x - 1` patterns
Looks like LLVM generates this as `x + (-1)` which is equivalent to `x - 1`
so create a custom partial constructor to pattern match the
possibilities of a decremented value.
* Add tests for BMI{1,2} coming from wasm
These are intended to serve as integration tests to ensure that even
coming from wasm these instructions are all emitted.
This change is a small refactoring to some of the MacroAssembler functions to
use `Reg` instead of `RegImm` where appropriate (e.g. when the operand is a
destination).
@elliottt pointed this out while working on https://github.com/bytecodealliance/wasmtime/pull/6982
This change also changes the signature of `float_abs` and `float_neg`, which can
be simplified to take a single register.
* riscv64: Add compressed extension instructions
The C extension has been split a little bit since its introduction
let's support the finer grained instructions.
This also disables compressed instruction support by default.
* ci: Enable zcb extension on RISC-V QEMU
* riscv64: Enable RVC mode in capstone
Conditionally enable compressed instruction disassembly.
* riscv64: Prepare to emit compressed instructions
This commit reorganizes our emit function to first
try a special case for compressed instruction, before
falling back to uncompressed instructions.
Currently the compressed case does nothing.
* riscv64: Move emit register allocation to separate function
We can only emit compressed instructions if they have a
specific physical register. For example `c.mv` does not support
using the `x0` register.
Thus, move the allocation function that converts from
virtual registers to physical registers into a separate step
before trying to emit the instruction.
This allows us to know the real register when emitting
compressed instructions.
* riscv64: Emit BrTable as uncompressed
`br_table` computes physical offsets from a certain instruction.
Thus we need to force these instructions to be uncompressed
in order to not jump into the wrong target.
* riscv64: Mark DWARF CIE code alignment as 2 bytes
* riscv64: Make minimum function alignment 2 bytes
* riscv64: Emit `c.add`
* riscv64: Add `c.mv`
* riscv64: Add c runtests
* Revert "ci: Enable zcb extension on RISC-V QEMU"
This reverts commit 212dec48d4ef0ab2d92ad55e3a649b914ca0fb39.
It looks like the version of QEMU that CI uses does not yet
support Zcb.
* Redesign Wasmtime's CLI
This commit follows through on discussion from #6741 to redesign the
flags that the `wasmtime` binary accepts on the CLI. Almost all flags
have been renamed/moved and will require callers to update. The main
motivation here is to cut down on the forest of options in `wasmtime -h`
which are difficult to mentally group together and understand.
The main change implemented here is to move options behind "option
groups" which are intended to be abbreviated with a single letter:
* `-O foo` - an optimization or performance-tuning related option
* `-C foo` - a codegen option affecting the compilation process.
* `-D foo` - a debug-related option
* `-W foo` - a wasm-related option, for example changing wasm semantics
* `-S foo` - a WASI-related option, configuring various proposals for example
Each option group can be explored by passing `help`, for example `-O
help`. This will print all options within the group along with their
help message. Additionally `-O help-long` can be passed to print the
full comment for each option if desired.
Option groups can be specified multiple times on the command line, for
example `-Wrelaxed-simd -Wthreads`. They can also be combined together
with commas as `-Wrelaxed-simd,threads`. Configuration works as a "last
option wins" so `-Ccache,cache=n` would end up with a compilation
cache disabled.
Boolean options can be specified as `-C foo` to enable `foo`, or they
can be specified with `-Cfoo=$val` with any of `y`, `n`, `yes`, `no`,
`true`, or `false`. All other options require a `=foo` value to be
passed and the parsing depends on the type.
This commit additionally applies a few small refactorings to the CLI as
well. For example the help text no longer prints information about wasm
features after printing the option help. This is still available via
`-Whelp` as all wasm features have moved from `--wasm-features` to `-W`.
Additionally flags are no longer conditionally compiled in, but instead
all flags are always supported. A runtime error is returned if support
for a flag is not compiled in. Additionally the "experimental" name of
WASI proposals has been dropped in favor of just the name of the
proposal, for example `--wasi nn` instead of `--wasi-modules
experimental-wasi-nn`. This is intended to mirror how wasm proposals
don't have "experimental" in the name and an opt-in is required
regardless.
A full listing of flags and how they have changed is:
| old cli flag | new cli flag |
|-----------------------------------------------|-------------------------------------------------|
| `-O, --optimize` | removed |
| `--opt-level <LEVEL>` | `-O opt-level=N` |
| `--dynamic-memory-guard-size <SIZE>` | `-O dynamic-memory-guard-size=...` |
| `--static-memory-forced` | `-O static-memory-forced` |
| `--static-memory-guard-size <SIZE>` | `-O static-memory-guard-size=N` |
| `--static-memory-maximum-size <MAXIMUM>` | `-O static-memory-maximum-size=N` |
| `--dynamic-memory-reserved-for-growth <SIZE>` | `-O dynamic-memory-reserved-for-growth=...` |
| `--pooling-allocator` | `-O pooling-allocator` |
| `--disable-memory-init-cow` | `-O memory-init-cow=no` |
| `--compiler <COMPILER>` | `-C compiler=..` |
| `--enable-cranelift-debug-verifier` | `-C cranelift-debug-verifier` |
| `--cranelift-enable <SETTING>` | `-C cranelift-NAME` |
| `--cranelift-set <NAME=VALUE>` | `-C cranelift-NAME=VALUE` |
| `--config <CONFIG_PATH>` | `-C cache-config=..` |
| `--disable-cache` | `-C cache=no` |
| `--disable-parallel-compilation` | `-C parallel-compilation=no` |
| `-g` | `-D debug-info` |
| `--disable-address-map` | `-D address-map=no` |
| `--disable-logging` | `-D logging=no` |
| `--log-to-files` | `-D log-to-files` |
| `--coredump-on-trap <PATH>` | `-D coredump=..` |
| `--wasm-features all` | `-W all-proposals` |
| `--wasm-features -all` | `-W all-proposals=n` |
| `--wasm-features bulk-memory` | `-W bulk-memory` |
| `--wasm-features multi-memory` | `-W multi-memory` |
| `--wasm-features multi-value` | `-W multi-value` |
| `--wasm-features reference-types` | `-W reference-types` |
| `--wasm-features simd` | `-W simd` |
| `--wasm-features tail-call` | `-W tail-call` |
| `--wasm-features threads` | `-W threads` |
| `--wasm-features memory64` | `-W memory64` |
| `--wasm-features copmonent-model` | `-W component-model` |
| `--wasm-features function-references` | `-W function-references` |
| `--relaxed-simd-deterministic` | `-W relaxed-simd-deterministic` |
| `--enable-cranelift-nan-canonicalization` | `-W nan-canonicalization` |
| `--fuel <N>` | `-W fuel=N` |
| `--epoch-interruption` | `-W epoch-interruption` |
| `--allow-unknown-exports` | `-W unknown-exports-allow` |
| `--trap-unknown-imports` | `-W unknown-imports-trap` |
| `--default-values-unknown-imports` | `-W unknown-imports-default` |
| `--max-instances <MAX_INSTANCES>` | `-W max-instances=N` |
| `--max-memories <MAX_MEMORIES>` | `-W max-memories=N` |
| `--max-memory-size <BYTES>` | `-W max-memory-size=N` |
| `--max-table-elements <MAX_TABLE_ELEMENTS>` | `-W max-table-elements=N` |
| `--max-tables <MAX_TABLES>` | `-W max-tables=N` |
| `--max-wasm-stack <MAX_WASM_STACK>` | `-W max-wasm-stack=N` |
| `--trap-on-grow-failure` | `-W trap-on-grow-failure` |
| `--wasm-timeout <TIME>` | `-W timeout=N` |
| `--wmemcheck` | `-W wmemcheck` |
| `--wasi-modules default` | removed |
| `--wasi-modules -default` | removed |
| `--wasi-modules wasi-common` | `-S common` |
| `--wasi-modules -wasi-common` | `-S common=n` |
| `--wasi-modules experimental-wasi-nn` | `-S nn` |
| `--wasi-modules experimental-wasi-threads` | `-S threads` |
| `--wasi-modules experimental-wasi-http` | `-S http` |
| `--listenfd` | `-S listenfd` |
| `--tcplisten <SOCKET ADDRESS>` | `-S tcplisten=...` |
| `--wasi-nn-graph <FORMAT::HOST>` | `-S nn-graph=FORMAT::HOST` |
| `--preview2` | `-S preview2` |
| `--dir <DIRECTORY>` | `--dir ...` |
| `--mapdir <GUEST_DIR::HOST_DIR>` | `--dir a::b` |
* Be more descriptive with help text
* Document `=val` is optional for `-Ccranelift-xxx`
* Fix compile after rebase
* Fix rebase of `--inherit-network`
* Fix wasi-http test
* Fix compile without pooling allocator support
* Update some flags in docs
* Fix bench-api build
* Update flags for gdb/lldb tests
* Fixup optimization flags
prtest:full
* [wasmtime-wasi] fix logic error in `monotonic-clock/subscribe`
When calculating the number of nanoseconds to wait, we should subtract the
current time from the deadline, not vice-versa. This was causing guests to
sleep indefinitely due to integer underflow.
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
* add `sleep` test to `wasi-tests`
Note that this is annotated `should_panic` when testing preview1 scenarios,
since those won't have preview2 imports.
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
---------
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
* Remove tutorial/wasm-writing documentation
This commit removes the tutorial and "Writing WebAssembly" documentation
sections from Wasmtime's documentation. These sections are quite dated
at this point (they still recommend `cargo wasi`!) and haven't been
updated much since their inception, especially in the arena of
components. Today it seems best to leave this sort of documentation to
[other resources] which are more tailored towards documentation of
writing wasm.
[other resources]: https://component-model.bytecodealliance.org/
* Remove markdown example from docs
Like the previous commit this is quite dated and recommends
effectively-deprecated tooling and doesn't take into account components.
* Update our intro docs a bit
* Link security blog post from docs
* Fold docs of wasm proposals into tier docs
This was already a bit duplicated so consolidate into one location.
Additionally add some proposals that weren't previously documented and
move some around based on their implementation status.
* Document unsupported features
In an effort to head off questions about platform support I figure it
might be a good idea to start documenting what's not supported at this
time. This is intended to mirror the current state, not future, of
Wasmtime. In other words this should answer the question of "Does
Wasmtime support X?" as opposed to "Does Wasmtime want to support X?"
since we want to eventually support all of these features in the limit.
* Fold WASI docs into tier docs
Similar to the previous commit but for WASI proposals.
* x64: Remove recursion in `to_amode` helper
This commit removes the recursion present in the x64 backend's
`to_amode` and `to_amode_add` helpers. The recursion is currently
unbounded and controlled by user input meaning it's not too hard to
craft user input which triggers stack overflow in the host. By removing
recursion there's no need to worry about this since the stack depth will
never be hit.
The main concern with removing recursion is that code quality may not be
quite as good any more. The purpose of the recursion here is to "hunt
for constants" and update the immediate `Offset32`, and now without
recursion only at most one constant is found and folded instead of an
arbitrary number of constants as before. This should continue to produce
the same code as before so long as optimizations are enabled, but
without optimizations this will produce worse code than before.
Note with a hypothetical mid-end optimization that does this constant
folding for us the rules here could be further simplified to purely
consider the shape of the input `Value` to amode computation without
considering constants at all.
* aarch64: Remove recursion from amode lowering rules
Same as the prior commit for x64, but for aarch64 instead. Unlikely to
be reachable from wasm due to this only being a part of addressing modes
which are more strictly controlled in wasm (e.g. wasm addresses are
always a zero-extended value added to a base, so it's not possible to
have a long chain of constants at the top level in clif)
* riscv64: Use `MachLabel` for Jal
* riscv64: Use `Inst::gen_jump` for jumps
This is mostly a personal preference. It emits the exact same code.
* riscv64: Use VecMachLabel on BrTable
* riscv64: Remove `BranchTarget::Offset` arm
Replaces it with `Fallthrough` which works the same way with
a fixed offset of 0.
* riscv64: Rename `BranchTarget`
It is now only used for `CondBr`
* riscv64: Panic on fallthrough taken target in condbr
* Improve lowering of store_imm on x64
Adds a new x64 rule for directly lowering stores of immediates with a MOV instruction.
* Ensure that the MovImmM operand fits in an i32 and add tests.
* Update winch to handle MovImmM change
* winch: Support f32.abs and f64.abs on x64
Co-authored-by: Nick Fitzgerald <fitzgen@gmail.com>
* Add an implementation of f32.neg and f64.neg
* Enable spec tests for winch with f{32,64}.{neg,abs}
* Enable differential fuzzing for f{32,64}.{neg,abs} for winch
* Comments from code review
---------
Co-authored-by: Nick Fitzgerald <fitzgen@gmail.com>
* cranelift: Implement `vall_true` for floats in the interpreter
* cranelift: Implement `vany_true` for floats in the interpreter
* cranelift: Implement `vhigh_bits` for floats in the interpreter
* cranelift: Forbid vector return types for `vhigh_bits`
This instruction doesen't really make sense with a vector return type.
The description also states that it returns a scalar integer so I suspect
it wasn't intended to allow vector integers.
* fuzzgen: Enable `v{all,any}_true` and `vhigh_bits`
This allows for running the generated make files directly if your
confirgure step wants to use a vendored cargo program.
Signed-off-by: Tyler Rockwood <rockwood@redpanda.com>
* riscv64: Add G extension predicate
Also adds descriptions to some existing flags
* riscv64: Restrict creating a backend without base features
* riscv64: Clarify INSTRUCTION_SIZE constant
* riscv64: Update wording on ISA flag error
Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
* riscv64: Run rustfmt
---------
Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
There is no need to get exclusive access to State:
* All mutation of State and Descriptors is handled internally with cells.
`descriptors_mut` does not need exclusive access to State, and eliminating
that constraint means we can trivially shorten all uses of `with_mut` to `with`.
* recursive access to State is required for implementing the cabi_realloc
functions. These functions do not need exclusive access to State, but if
another call has already taken an exclusive borrow, realloc will trap.
I recently found a bug that would occur if `path_open` is the first call into
the adapter, the State will be borrowed exclusively and `descriptors_mut` will
initialize the descriptors by calling out to get the preopens. Because preopens
are a list, the runtime needs to call cabi_realloc to return them, and that
call will fail where cabi_import_realloc tries to borrow the exclusively-
borrowed State.
This commit optimizes the lifting and lowering routines for `list<u8>`
and other similar primitive integer types. The current lifting/lowering
is intended to be general-purpose and correct but doesn't optimize well
with LLVM for a number of reasons. I first attempted to reshape the
general-purpose code to be easier for LLVM to optimize but in the end
was unable to convince LLVM that various pointers here don't alias which
meant that the general-purpose lowering/lifting never optimized well.
Instead, however, I've added new trait methods which are implemented the
same way as the general purpose methods beforehand. The
integer/primitive implementations overwrite these implementations with
more specialized versions given knowledge of primitives.
On a local benchmark this makes lifting/lowering disappear from a
profile since memcpy is generally much faster than per-item processing.
* riscv64: Use label based jump in Icmp
* riscv64: Use labels in LoadExtData
* riscv64: Use labels in BrTable
* riscv64: Delete BranchTarget::offset
* riscv64: Enable default extensions
This only affects tests and the adapter itself, but not in any breaking
way. The tests for wasi-http are reorganized to be commands which is
also required to not have any exports currently since wit-bindgen for
Rust guests doesn't support generating bindings in one crate and
exporting in another.
* feat(wasmtime-cli): add async support flag
Within the wasmtime CLI, the current default behavior
is to only inject the synchronous functions to linkers.
This will add a flag called `--async` that will inject
the asynchronous one instead.
* chore: refactor wasi http crate
* feat(wasmtime-wasi): make in_tokio function public
* feat(wasi-http): define default feature called sync
* Revert "feat(wasmtime-cli): add async support flag"
This reverts commit b743ff2003a2e391972330aa8e8437c6356e580a.
* chore: improve flaky tests for wasi http
* feat(wasi-http): expose sync api for components
* chore: add tests for sync api of wasi http components
* feat(wasmtime-cli): restore support for wasi http module
* chore: revert change to outbound http request invalid test
* chore: have extra tracing to help debugging
* feat(wasi-http): allow modules with sync functions in linker
* fix(wasi-http): missing response body in sync api
* feat: include blocking for io streams
* chore: add tests for wasi http module in cli
* chore: disable preview2 flag in wasi http test
* chore: use preview2 flag in wasi http test
* fix(wasi-http): missing stream output in sync api
* chore: fix tests for wasi http
* chore: add tracing for poll oneoff call
* chore: send exit signal on wasi http test
* chore: swap println to tracing debug
* chore: set http server timeout to 50 secs by default
* chore: add test posting large file
* chore: revert formatting in cargo toml
* chore: fix wasi-http feature and skip failing tests
prtest:full
---------
Co-authored-by: Eduardo Rodrigues <eduardomourar@users.noreply.github.com>
* Add a test
* Disable test
* Add support for specifying stack locations in debug info
Always emit SysV-style CFI unwind info if we need debug info,
and reference it in the debug info using DW_OP_call_frame_cfa.
* Add toolchain comment to the test
* Add a comment and assert
While this is not at all WASM-specific, it is somewhat rare that
LLDB is used for native debugging on Windows, so the cause of
the slowdown on the order of 50x may not be immediately obvious.
After https://github.com/bytecodealliance/wasmtime/pull/6850 was merged,
the s390x back-end now always uses iilf instead of lhi to load negative
constants, which is a small code size regression.
Fix the isle predicate to get back lhi whenever possible.
* winch: Add support for `br_table`
This change adds support for the `br_table` instruction, including
several modifications to the existing control flow implementation:
* Improved handling of jumps to loops: Previously, the compiler erroneously
treated the result of loop blocks as the definitive result of the jump. This
change fixes this bug.
* Streamlined result handling and stack pointer balancing: In the past, these
operations were executed in two distinct steps, complicating the process of
ensuring the correct invariants when emitting unconditional jumps. To simplify
this, `CodeGenContext::unconditional_jump` is introduced . This function
guarantees all necessary invariants are met, encapsulating the entire operation
within a single function for easier understanding and maintenance.
* Handling of unreachable state at the end of a function: when reaching the end
of a function in an unreachable state, clear the stack and ensure that the
machine stack pointer is correctly placed according to the expectations of the
outermost block.
In addition to the above refactoring, the main implementation of the
`br_table` instruction involves emitting labels for each target. Within each
label, an unconditional jump is emitted to the frame's label, ensuring correct
stack pointer balancing when the jump is emitted.
While it is possible to optimize this process by avoiding intermediate labels
when balancing isn't required, I've opted to maintain the current
implementation until such optimization becomes necessary.
* chore: Rust fmt
* fuzzing: Add `BrTable` to list of support instructions
* docs: Improve documentation for `unconditional_jump`
* Fix up a debug info transform bug
"Block"s in DWARF are arbitrary-sized constants.
They are used for e. g. __int128 constants in C/C++, which is how this was hit.
* Add the ".vs" folder to ".gitignore"
This is generated by VS when using its "open folder feature".
* Monotonize instructon offsets after code emission
Turns out that this is easier then fixing them in-place when
removing the branch because a bunch of ambient state needs to
be passed through to the MachBuffer for that to become possible.
Testing: tested to fix the issue on both one of the reported
samples as well as my own.
* Move the last optimize_branches earlier
It is more obviously correct this way that the code which
is using buffer.cur_offset() is not reading stale values.
* Fix the zero-offset problem with NO_INST_OFFSET
Also delete EmitResult::inst_offsets, it was not used.
* Add a test
* Check both sides of the range for NO_INST_OFFSET
If either is unknown, err on the safe side.
* Use `command::add_to_linker` in tests to reduce the number of times
all the `add_to_linker` are listed.
* Add all `wasi:sockets` interfaces currently implemented to both the
sync and async `command` functions (this enables all the interfaces in
the CLI for example).
* Use `tokio::net::TcpStream::try_io` whenever I/O is performed on a
socket, ensuring that readable/writable flags are set/cleared
appropriately (otherwise once readable a socket is infinitely readable).
* Add a `with_ambient_tokio_runtime` helper function to use when
creating a `tokio::net::TcpStream` since otherwise it panics due to a
lack of active runtime in a synchronous context.
* Add `WouldBlock` handling to return a 0-length read.
* Add an `--inherit-network` CLI flag to enable basic usage of sockets
in the CLI.
This will conflict a small amount with #6877 but should be easy to
resolve, and otherwise this targets different usability points/issues
than that PR.
* cranelift: Validate `iconst` ranges
Add the following checks:
`iconst.i8` immediate must be within 0 .. 2^8-1
`iconst.i16` immediate must be within 0 .. 2^16-1
`iconst.i32` immediate must be within 0 .. 2^32-1
Resolves#3059
* cranelift: Parse `iconst` according to its type
Modifies the parser for textual CLIF so that V in `iconst.T V` is
parsed according to T.
Before this commit, something like `iconst.i32 0xffff_ffff_ffff` was
valid because all `iconst` were parsed the same as an
`iconst.i64`. Now the above example will throw an error.
Also, a negative immediate as in `iconst.iN -X` is now converted to
`2^N - X`.
This commit also fixes some broken tests.
* cranelift: Update tests to match new CLIF parser
This commit adds a few cases to `amode` construction on AArch64 for
using the `RegScaled*` variants of `AMode`. This won't affect wasm due
to this only matching the sign-extension happening before the shift, but
it should otherwise help non-wasm Cranelift use cases.
Closes#6742
* Update Rust in CI to 1.72.0
* Update CI, tooling, and docs for MSRV
This commit codifies an MSRV policy for Wasmtime at "stable minus two"
meaning that the latest three releases of Rust will be supported. This
is enforced on CI with a full test suite job running on Linux x86_64
with the minimum supported Rust version. The full test suite will use
the latest stable version. A downside of this approach is that new
changes may break MSRV support on non-Linux or non-x86_64 platforms and
we won't know about it, but that's deemed a minor enough risk at this
time.
A minor fix is applied to Wasmtime's `Cargo.toml` to support Rust 1.70.0
instead of requiring Rust 1.71.0
* Fix installation of rust
* Scrape MSRV from Cargo.toml
* Cranelift is the same as Wasmtime's MSRV now, more words too
* Fix a typo
* riscv64: Use `PCRelLo12I` relocation on Loads
* riscv64: Strenghten pattern matching when emitting Load's
* riscv64: Clarify some of the load address logic
* riscv64: Even stronger matching
* Partially revert CLI argument changes from #6737
This commit is a partial revert of #6737. That change was reverted
in #6830 for the 12.0.0 release of Wasmtime and otherwise it's currently
slated to get released with the 13.0.0 release of Wasmtime. Discussion
at today's Wasmtime meeting concluded that it's best to couple this
change with #6925 as a single release rather than spread out across
multiple releases. This commit is thus the revert of #6737, although
it's a partial revert in that I've kept many of the new tests added to
showcase the differences before/after when the change lands.
This means that Wasmtime 13.0.0 will exhibit the same CLI behavior as
12.0.0 and all prior releases. The 14.0.0 release will have both a new
CLI and new argument passing semantics. I'll revert this revert (aka
re-land #6737) once the 13.0.0 release branch is created and `main`
becomes 14.0.0.
* Update release notes
This commit takes a leaf out of `wiggle`'s book to enable bindings
generation for async host functions where only some host functions are
async instead of all of them. This enhances the `async` key with a few
more options:
async: {
except_imports: ["foo"],
only_imports: ["bar"],
}
This is beyond what `wiggle` supports where either an allow-list or
deny-list can be specified (although only one can be specified). This
can be useful if either the list of sync imports or the list of async
imports is small.