12885 Commits

Author SHA1 Message Date
Nick Fitzgerald 6c5184809d Cranelift: resolve value aliases when printing CLIF functions (#8214)
This makes the CLIF much easier to follow.
2024-03-22 01:24:49 +00:00
Alex Crichton 4f1e6f3785 Use some new standard library methods from Rust 1.74, 1.75 (#8209)
* Use some `byte_add` methods from Rust 1.75

Now that we're able to, use some convenience methods from the 1.75
release of Rust.

* Use `Atomic*::from_ptr` from Rust 1.75

Helps clean up some casts and clarify local intent.
2024-03-21 23:30:37 +00:00
Alex Crichton ba1a7120e7 Update Nightly Rust used in CI (#8211)
* Update Nightly Rust used in CI

Additionally update `build-build-matrix.js` which I forgot in previous
PRs.

* Fix dead code warning
2024-03-21 22:17:24 +00:00
Trevor Elliott 450b791f96 winch: Remove unused functions after trampoline refactoring (#8213)
* Remove callee saves from Winch's MacroAssembler trait

prtest:mingw-x64

* Remove the unused callee_saved_regs function

* Removed the unused callee_saved function from Winch's aarch64 backend

* Remove additional unused functions from the Winch ABI trait
2024-03-21 21:51:17 +00:00
Chris Fallin a79cf76fe0 PCC: x64: insertlane instructions read only scalar-sized values. (#8207)
* PCC: x64: insertlane instructions read only scalar-sized values.

Also fix `clamp_range` on greater-than-64-bit values: no range fact is
possible in this case (propagate `Option` a bit deeper to represent
this).

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=67538.

* Rebase to latest main with leaf-function changes and update test expectations.
2024-03-21 19:00:34 +00:00
Trevor Elliott d69ba34ee3 winch: Switch to using cranelift for all trampolines (#8109)
* Switch winch over to using cranelift for all trampolines

* Fix unused code warnings

* Fix unused code warnings

prtest:full
2024-03-21 17:59:43 +00:00
Trevor Elliott a1b54d985a Replace a debug assert with a TODO (#8210) 2024-03-21 17:02:56 +00:00
Alex Crichton ead7f735b4 Compile out wmemcheck-related libcalls when not enabled (#8203)
Currently even when the `wmemcheck` Cargo feature is disabled the
various related libcalls are still compiled into `wasmtime-runtime`.
Additionally their signatures are translated when lowering functions,
although the signatures are never used. This commit adds `#[cfg]`
annotations to compile these all out when they're not enabled.

Applying this change, however, uncovered a subtle bug in our libcalls.
Libcalls are numbered in-order as-listed in the macro ignoring `#[cfg]`,
but they're assigned a runtime slot in a `VMBuiltinFunctionsArray`
structure which does respect `#[cfg]`. This meant, for example, that if
`gc` was enabled and `wmemcheck` was disabled, as is the default for our
tests, then there was a hole in the numbering where libcall numbers were
mismatched at runtime and compile time.

To fix this I've first added a const assertion that the runtime-number
of libcalls equals the build-time number of libcalls. I then updated the
macro a bit to plumb the `#[cfg]` differently and now libcalls are
unconditionally defined regardless of cfgs but the implementation is
`std::process::abort()` if it's compiled out.

This ended up having a large-ish impact on the `disas` test suite. Lots
of functions have fewer signatures translation because wmemcheck, even
when disabled, was translating a few signatures. This also had some
assembly changes, too, because I believe functions are considered leaves
based on whether they declare a signature or not, so declaring an unused
signature was preventing all wasm functions from being considered leaves.
2024-03-21 16:49:11 +00:00
Chris Fallin 6ae6ebc725 PCC: avoid fuzzing on memory64. (#8208)
Memory64 configurations require dynamic bounds checks, which PCC cannot
currently verify. This PR turns off PCC In fuzzing if the module
requires memory64.

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=67539.
2024-03-21 16:39:09 +00:00
Alex Crichton b363db0f9c Bump MSRV to 1.75.0 (#8205)
* Bump MSRV to 1.75.0

Coupled with today's release of 1.77.0. Today's release actually has
some nice functions and such I think we'll want to use in Wasmtime but
we'll need to wait 3 months to be able to use them.

* Fix dead code warning in onnx
2024-03-21 15:44:05 +00:00
Nick Fitzgerald 082acb4e29 Cranelift: make bitcasts between integer and reference types do a copy (#8201)
* Cranelift: make `bitcast`s between integer and reference types do a copy

This avoids putting multiple conflicting regalloc constraints on values that
would otherwise be aliases of each other (one constraint that the value must be
in a register as a function argument and another that it must be in a stack slot
for a safepoint) by splitting the value in two and each split value getting its
own constraint.

Fixes #8180

* Fix test expectations
2024-03-21 15:04:30 +00:00
Jamey Sharp c6d923ae3f Add more disassembly tests for call_indirect (#8202)
I found these tests useful in thinking about #8195, #8197, and #8200, so
I thought we should track our codegen for these specific cases over
time.
2024-03-21 00:24:04 +00:00
Trevor Elliott d3cc12b455 cranelift: Fix return value handling with the winch calling convention (#8198)
* Return the last result through registers in the winch calling convention

* Add a run test for winch calling convention functions

* Disable the Winch calling convention in cranelift's aarch64 backend

* Remove the aarch64 winc.clif test

* Skip realignment for winch results on the stack
2024-03-20 23:24:49 +00:00
Andrew Gutekanst e6cd53281c Update release notes for 18.0.3 patch release (#8199) 2024-03-20 22:59:52 +00:00
Jamey Sharp f59b324602 cranelift: Optimize select_spectre_guard, carefully (#8139)
* cranelift: Optimize select_spectre_guard, carefully

This commit makes two changes to our treatment of
`select_spectre_guard`.

First, stop annotating this instruction as having any side effects. We
only care that if its value result is used, then it's computed without
branching on the condition input. We don't otherwise care when the value
is computed, or if it's computed at all.

Second, introduce some carefully selected ISLE egraph rewrites for this
instruction. These particular rewrites are those where we can statically
determine which SSA value will be the result of the instruction. Since
there is no actual choice involved, there's no way to accidentally
introduce speculation on the condition input.

* Add filetests
2024-03-20 22:31:45 +00:00
Alex Crichton 55664f5a3f Add a CodeBuilder type to the wasmtime crate (#8181)
* Add a `ModuleBuilder` type to the `wasmtime` crate

This commit is extracted from #8055 and adds a new `ModuleBuilder` type
which is intended to be able to further configure compilation beyond
what the constructors of `Module` already provide. For example in #8055
knobs will be added to process `*.dwp` files for more debuginfo
processing.

Co-authored-by: yowl00 <scott.waye@hubse.com>

* Fix build

* Review feedback

* Rename ModuleBuilder to CodeBuilder

* Fix doc errors

---------

Co-authored-by: yowl00 <scott.waye@hubse.com>
2024-03-20 20:52:14 +00:00
Alex Crichton f4bee25010 Implement opt-in for enabling WASI to block the current thread (#8190)
* Implement opt-in for enabling WASI to block the current thread

Currently all of Wasmtime's implementation of WASI is built on Tokio,
but some operations are currently not asynchronous such as opening a
file or reading a directory. Internally these use `spawn_blocking` to
satisfy the requirements of async users of WASI to avoid blocking the
current thread. This use of `spawn_blocking`, however, ends up causing
mostly just performance overhead in the use case of the CLI, for
example, where async wasm is not used. That then leads to this commit,
implementing an opt-in mechanism to be able to block the current thread.

A `WasiCtx` now has a flag indicating whether it's ok to block the
current thread and that's carried to various filesystem operations that
use `spawn_blocking`. The call to `spawn_blocking` is now conditional
and skipped if this flag is set.

Additionally the invocation point in the CLI for wasm modules is wrapped
in a Tokio runtime to avoid entering/exiting Tokio in the "leaves" when
wasm calls the host, as happens today. This hits a better fast path in
Tokio that appears to be more efficient.

Semantically this should not result in any change for CLI programs
except in one case: file writes. By default writes on `output-stream` in
WASI are asynchronous meaning that only one write can be in flight at a
time. That being said all current users are immediately blocking waiting
for this write to finish anyway, so this commit won't end up changing
much. It's already the case that file reads are always blocking, for
example. If necessary in the future though this can be further
special-cased at the preview1 layer.

* Thread around allow_blocking_current_thread less

Pass around `&File` instead.
2024-03-20 20:50:35 +00:00
Saúl Cabrera 5e05171d01 winch: Enable memory64 in Winch (#8194)
Closes: https://github.com/bytecodealliance/wasmtime/issues/8089

This commit  unlocks support for the `memory64` proposal in Winch. After all the fixes to heap handling, all the spec and misc tests are passing, which is a good indication regarding the support for this proposal.

I'll like to merge this change after: https://github.com/bytecodealliance/wasmtime/pull/8156.
2024-03-20 20:36:35 +00:00
Saúl Cabrera 8baee53bff winch: Correctly handle the result of memory grow (#8156)
This commit correctly handles the  result of the memory grow builtin function. Previously, it was assumed that the result of memory grow must be of the the target's pointer type, which doesn't accurately represent the address space covered by the memory type.
2024-03-20 19:40:04 +00:00
Trevor Elliott 50812d3a49 Change compute_arg_locs to accept a slice instead of an IntoIterator (#8193)
Co-authored-by: Jamey Sharp <jsharp@fastly.com>
2024-03-20 18:04:49 +00:00
Alex Crichton c52f63f8cd Update setup-java GitHub Action (#8191)
Looks like this is our last one on Node 16 which GitHub is warning
about.
2024-03-20 15:30:13 +00:00
Chris Fallin 46814f22b3 PCC: support imported memories as well. (#8176)
* PCC: support imported memories as well.

Exposed by a fuzzbug
(https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=67429); rather
than exclude from fuzzing, it seemed easier to just implement. We need
to define a new memory type to describe the memory definition struct
pointed to by vmctx, and set up points-to facts appropriately.

* Review feedback: abstract out a bit of the pointer-and-memtype handling logic.
2024-03-20 15:12:05 +00:00
Alex Crichton ed759830fd Clarify that v128 is affected with NaN canonicalization (#8189)
Brought up on [Zulip] as something that's good to call out in the
documentation.

[Zulip]: https://bytecodealliance.zulipchat.com/#narrow/stream/206238-general/topic/Determinism.20of.20Wasm.20SIMD.20in.20Wasmtime/near/427666631
2024-03-20 14:46:37 +00:00
Alex Crichton b3e37fb563 Remove an unused type (#8183)
Found on the latest Rust nightly
2024-03-20 14:43:49 +00:00
Alex Crichton 9254273566 Canonicalize fpromote/fdemote operations (#8182)
* Canonicalize fpromote/fdemote operations

This commit changes the strategy implemented in #8146 to canonicalize
promotes/demotes of floats to additionally handle #8179.

Closes #8179

* Canonicalize fvpromote_low/fvdemote as well
2024-03-20 14:18:27 +00:00