The DWARF sections in `DebugInputContext` were always set to the DWARF sections
from the .wasm file. However, when parsing split DWARF, most of the time we
want to be using the sections from the .dwp file instead. We were already
passing `gimli::Dwarf` to most places already so having the sections in
`DebugInputContext` was no benefit. So a lot of this commit is replacing
`context` with `dwarf`.
Next, sometimes we were using the wrong `gimli::Dwarf`. In general, we want
to use the skeleton unit for parsing line info, and the split unit for
everything else. `clone_unit` was wrongly using the DWARF associated with
the skeleton unit in many places. Instead of changing all of those places,
I've kept the variable names `dwarf` and `unit`, but changed which DWARF they
refer to. This also fits better with the non-split operation. So some of
the changes in this commit are updating places that were already correct
to use the new variable meanings.
Finally, this commit adds a call to `copy_relocated_attributes`. This copies
some info from the skeleton unit that is needed when parsing the split unit.
* Cranelift: Add a new backend for emitting Pulley bytecode
This commit adds two new backends for Cranelift that emits 32- and 64-bit Pulley
bytecode. The backends are both actually the same, with a common implementation
living in `cranelift/codegen/src/isa/pulley_shared`. Each backend configures an
ISA flag that determines the pointer size, and lowering inspects this flag's
value when lowering memory accesses.
To avoid multiple ISLE compilation units, and to avoid compiling duplicate
copies of Pulley's generated `MInst`, I couldn't use `MInst` as the `MachInst`
implementation directly. Instead, there is an `InstAndKind` type that is a
newtype over the generated `MInst` but which also carries a phantom type
parameter that implements the `PulleyTargetKind` trait. There are two
implementations of this trait, a 32- and 64-bit version. This is necessary
because there are various static trait methods for the mach backend which we
must implement, and which return the pointer width, but don't have access to any
`self`. Therefore, we are forced to monomorphize some amount of code. This type
parameter is fairly infectious, and all the "big" backend
types (`PulleyBackend<P>`, `PulleyABICallSite<P>`, etc...) are parameterized
over it. Nonetheless, not everything is parameterized over a `PulleyTargetKind`,
and we manage to avoid duplicate `MInst` definitions and lowering code.
Note that many methods are still stubbed out with `todo!`s. It is expected that
we will fill in those implementations as the work on Pulley progresses.
* Trust the `pulley-interpreter` crate, as it is part of our workspace
* fix some clippy warnings
* Fix a dead-code warning from inside generated code
* Use a helper for emitting br_if+comparison instructions
* Add a helper for converting `Reg` to `pulley_interpreter::XReg`
* Add version to pulley workspace dependency
* search the pulley directory for crates in the publish script
Looks like CMake before 3.20.0 doesn't generate newlines at all without
this configuration option. CMake 3.20.0 and prior, however, generates
newlines by default which is why this didn't show up in CI or
development.
Closes#9126
* Pulley: Add memory access instructions with 64-bit offsets
I had trimmed these instructions from the original upstreaming of the Pulley
interpreter because I had mistakenly believed that they were unused. Turns out
they are needed for Cranelift's Pulley backend to allow for lowering certain
address modes to a single instruction. The alternative, lowering the address
modes to a sequence of instructions, would be a bit annoying and these
instructions seem generally useful.
* rebase on top of indexing changes for `MachineState`
* Refactor use of `CodeBuilder` on the CLI
This commit refactors `wasmtime run` and `wasmtime compile` to
unconditionally use `CodeBuilder` internally. This will in theory help
out in the future if more debug-related options are added to
`CodeBuilder` for example. This refactoring required some changes to
`CodeBuilder` to be able to support a query about whether the internal
bytes were a component or a module. The text format is now converted to
binary immediately when supplied rather than during the compilation
phase. This in turn required some API changes to make the selection of
supporting the text format a compile-time choice of method rather than a
runtime value.
* Fix compile
* Fix no-cranelift build of CLI
* ISLE: reduce allocations when lexing integers
Instead of creating a temporary `Vec<u8>`, use a slice of the original
underlying `buf`, and only allocate a temporary `String` if it contains
an `_`.
Copyright (c) 2024, Arm Limited.
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
* ISLE: don't `vec![]` macro in lexer tests
`Vec` can be compared against arrays, since both deref to slices.
Copyright (c) 2024, Arm Limited.
Signed-off-by: Karl Meakin <karlwfmeakin@gmail.com>
* ISLE: create `Files`
Centralize all file related arenas in `Files` struct.
Copyright (c) 2024, Arm Limited.
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
* ISLE: dont track line/col in `Pos`
They are already tracked in `Files`, so no need to track them in `Pos`
as well. This lets us simply the implementation of `Lexer::advance_pos`
a bit.
Copyright (c) 2024, Arm Limited.
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
* ISLE: don't pass `Files` into every pass
`Files` was being threaded through a lot of passes where it wasn't
needed. It is only needed for reporting errors in `compile.rs` and for
reporting line numbers when printing in `codegen.rs`.
Copyright (c) 2024, Arm Limited.
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
* ISLE: store `&str` in `Lexer`
Store the text being lexed as `&str`, rather than `&[u8]`, so that
substrings don't need to be rechecked for UTF-8 validity when lexing
identifiers or integers.
Copyright (c) 2024, Arm Limited.
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
* ISLE: add `peek_byte` helper for lexer
Copyright (c) 2024, Arm Limited.
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
* ISLE: tests for lexing integers
Copyright (c) 2024, Arm Limited.
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
* ISLE: dont parse integers twice
Instead of trying to parse an integer as an `i128`, and then as an
`u128` if that fails, parse it only as a `u128` and then check for
`i128::MIN`.
Copyright (c) 2024, Arm Limited.
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
---------
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
Signed-off-by: Karl Meakin <karlwfmeakin@gmail.com>
* 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.
* Add test for resource_async
* Improve codegen for enums with many cases
This commit improves the compile time of generating bindings for enums
with many cases in them (e.g. 1000+). This is done by optimizing for
enums specifically rather than handling them generically like other
variants which can reduce the amount of code going into rustc to O(1)
instead of O(N) with the number of cases. This in turn can greatly
reduce compile time.
The tradeoff made in this commit is that enums are now required to have
`#[repr(...)]` annotations along with no Rust-level discriminants
specified. This enables the use of a `transmute` to lift a discriminant
into Rust with a simple bounds check. Previously this was one large
`match` statement.
Closes#9081
* Fix some tests
* Add repr tag in fuzzing
* Fix syntax for Rust 1.78
* Update nightly used in CI
Move it up beyond the LLVM 19 upgrade to see if we have any issues with
LLVM 19.
prtest:full
* Update nightly version
* Fix some warnings on nightly
* Alternative fix for warnings
* More lint fixes
* More warning tweaks
* Clean up dist build configuration
* Move updating `$PATH` to the `main.js` script which is the one that
mounts `/rust/bin` so that knowledge isn't spread around.
* Remove some unused env vars in docker containers.
* Forward cargo/rust-specific env vars to the build from outside of
containers to the build itself.
prtest:full
* Change how musl rustflags are configured
* More rustflags changes
* Review feedback
This commit adds a CI check that if versions are bumped that `cargo vet`
still works. It's hoped that #9115 won't happen again in the future with
this by ensuring we get all the various entries right in our vet
configuration.
Right now this is only on some crates such as `wasmtime` itself and
`wasmtime-cli`, but by applying it to all crates it helps with version
selection of those using just Cranelift for example.
We were using a string, but the DWARF standard specifies that:
"The value of the DW_AT_decl_file attribute corresponds to a file number from
the line number information table...".
Additionally, a typo meant we were overwriting the file attribute with
the value that was meant to be used for a DW_AT_decl_line attribute.
* Use cmake to build wasmtime-c-api
* Properly expose features when building via cmake
* Install all headers to same directory
* Add vets
* attempt to fix ci
* Run all tests on CI
prtest:full
* Set CARGO_BUILD_TARGET; add CMakeLists to package
* Update comment on github action
* Attempt to fix android build
* Fix source dir modifications of c-api build
* Re-add BINARY_DIR option
* Fix build
* Move header installation to a cmake script
Try to avoid dealing with cmake configuration/platforms/etc.
* Tweak build of headers
* Install headers in build dir for examples
* Add cmake files to dist, fix header install dir
---------
Co-authored-by: Alex Crichton <alex@alexcrichton.com>
Use the `Index` and `IndexMut` traits for accessing registers, rather
than having to define getters and setters for every register class.
Copyright (c) 2024, Arm Limited.
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
* riscv64: Refactor FpuRR instruction emission
Previously we had opcodes for each instruction length variant, with the width field implicitly embedded in the `funct7` field of the opcode.
This works, but the instructions are defined with the width field having a few more possible values. In order to add FP16 support to these instructions we would have to duplicate the opcodes.
Instead make these opcodes width agnostic and specifiy the width during emission.
* riscv64: Refactor FpuRRR instruction emission
Previously we had opcodes for each instruction length variant, with the width field implicitly embedded in the `funct7` field of the opcode.
This works, but the instructions are defined with the width field having a few more possible values. In order to add FP16 support to these instructions we would have to duplicate the opcodes.
Instead make these opcodes width agnostic and specifiy the width during emission.
* riscv64: Refactor FpuRRRR instruction emission
Previously we had opcodes for each instruction length variant, with the width field implicitly embedded in the `funct7` field of the opcode.
This works, but the instructions are defined with the width field having a few more possible values. In order to add FP16 support to these instructions we would have to duplicate the opcodes.
Instead make these opcodes width agnostic and specifiy the width during emission.
* riscv64: Fix emit tests
* riscv64: Run `cargo fmt`
* Add FP16 and I64 support for wasi-nn WinML backend.
Some devices may not support FP32.
prtest:full
* Remove unnecessary features.
* Address comments.
* Check alignment before from_raw_parts.
* Implement PartialEq for Tensor.
* Remove duplicated shape info from set_input.
* Update alignment checker.
* Add comments about creating TensorFloat16Bit from f32 array.
* Use PartialEq attribute.
* Audit new WinML dependencies
---------
Co-authored-by: Andrew Brown <andrew.brown@intel.com>
This commit groups together the registers that have to be collected from
a signal handler to correctly report a trap: namely, the program counter
and frame pointer, as of the time that the trap occurred.
I also moved the call to set_jit_trap inside test_if_trap for every
platform that uses both methods. Only the implementation for Mach ports
still needs to call set_jit_trap because it doesn't use test_if_trap.
In addition I'm fixing an unrelated doc comment that I stumbled across
while working on this.
This commit adds the `#[track_caller]` attribute to
`PackedOption::unwrap` and `PackedOption::expect`. Using this attribute
greatly improves the panic message of any `.expect` or `.unwrap` on a
`PackedOption` by using the caller's location, not the location within
`cranelift-entity`.
Change `xconst8`, `xconst16`, `xconst32` and `xconst64` instructions to
sign-extend rather than zero-extend their immediates.
Copyright (c) 2024, Arm Limited.
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
No major changes happen in this release so it's just bumping version
numbers. The goal here is to turn the crank and ensure that nothing else
breaks as part of this release process. There's a surprising number of
versions to update in-repo which we may want to make easier in the
future but for now this just manually updates.
It is planned that this does not actually break anyone in practice.
Older runtimes should support newer versions and Wasmtime after this PR
should continue to support older binaries as well.
Put another way this should not break things and if it does this will
get reverted and fixed. We've done our best to make sure this won't
break things, so let's find out in the real world now.
* cranelift-frontend: Fix stack maps and liveness for loops
Previously, we were not properly handling back edges. This manifested in values
incorrectly being considered not-live inside loop bodies where they definitely
were live. Consider the following example:
block0:
v0 = needs stack map
block1:
call foo(v0)
call foo(v0)
jump block1
We were previously considering `v0` live only for the first `call foo(v0)` but
not the second, because we mistakenly concluded that `v0` would not be used
again after that second `call`. While it won't be used again in *this* iteration
of the loop, it will be used again in the *next* iteration of the loop.
Trevor and I initially tried implementing a clever trick suggested by Chris
where, if we know the minimum post-order index of all of a block's transitive
predecessors, we can continue to compute liveness in a single pass over the
IR. We believed we could compute the minimum predecessor post-order index via
dynamic programming. It turns out, however, that approach doesn't provide
correct answers out of the box for certain kinds of irreducible control flow,
only nearly correct answers, and would require an additional clever fix-up pass
afterwards. We deemed this cleverness on cleverness unacceptable.
Instead, Trevor and I opted to implement a worklist algorithm where we process
blocks to a fixed-point. This has the advantages of being obviously correct and
producing more-precise results. It has the disadvantage of requiring multiple
passes over the IR in the face of loops and back edges. Because this analysis is
only used when needs-stack-map values are present (i.e. when the function uses
GC values) and is otherwise skipped, this additional compile-time overhead is
tolerable.
Co-Authored-By: Trevor Elliott <telliott@fastly.com>
* Add and update some comments based on review
---------
Co-authored-by: Trevor Elliott <telliott@fastly.com>
This moves the macro to `lib.rs` so that it can be used in all the tests in the
whole crate. It also makes it a little more usable by trimming whitespace and
printing both the expected and actual values, in addition to the diff.
A follow-up commit will migrate various uses of `assert_eq!` over to it.
Co-authored-by: Trevor Elliot <telliott@fastly.com>
This commit simplifies the selection of an ABI for wasm functions now
that all Cranelift backends implement tail calls. All wasm functions use
the `Tail` calling convention except when the `winch_callable` tunable
is enabled meaning that Winch-generated functions are being called.
This then additionally simplifies the activation of the tail call
proposal. It's not unconditionally active and the same across all
compilers. The Winch compiler is updated to return an error for
unsupported instructions rather than panicking so the embedder API is
suitable for feeding unsupported modules to Winch. This means that tail
calls in Winch behaves similarly to GC in Cranelift or other unsupported
proposals like SIMD in Winch.
* Validate import names given to `trappable_imports`
* Revert "Validate import names given to `trappable_imports`"
This reverts commit 527cb18c49.
* Track which `trappable_imports` names have been used
* Fix the comment on used_trappable_imports_opts
* Move use tracking to `special_case_trappable_error`
This adds support for a newly defined tail-call ABI for s390x
as well as supporting tail calls themselves.
We now use the tail-call ABI by default for Wasmtime, and
enable tail calls by default.
This also allows getting rid of a number of special case
and test exclusions for s390x.
Fixes: https://github.com/bytecodealliance/wasmtime/issues/6530
* Use proper I/O readiness to wait for the shutdown signal instead of an arbitrary timeout.
* Move generic socket setup & teardown code out of the test case.
* Make TcpRead/WriteStream private.
* Return StreamError::Closed when the underlying socket is shut down.
Added an additional LastWrite::Closed status to ensure that the OutputStream _keeps_ closed.
This commit adds a README to the
`wasi-preview1-component-adapter-provider` crate to make it clearer
how to use it and what it's for.
While the README is mostly for those who are already familiar, a
section giving a brief overview of context around the adapters was
added.
Signed-off-by: Victor Adossi <vadossi@cosmonic.com>