Skip to content

Commit d752ebd

Browse files
alexcrichtonafonso360jameysharptimjrd
authored
[pch/backpressure_2] Merge changes from main and resolve conflicts (#6950)
* Enhance `async` configuration of `bindgen!` macro (#6942) 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. * cranelift-interpreter: Fix SIMD shifts and rotates (#6939) * cranelift-interpreter: Fix SIMD `ishl`/`{s,u}`shr * fuzzgen: Enable a few more ops * cranelift: Fix tests for {u,s}shr * fuzzgen: Change pattern matching arms for shifts Co-Authored-By: Jamey Sharp <jsharp@fastly.com> --------- Co-authored-by: Jamey Sharp <jsharp@fastly.com> * Partially revert CLI argument changes from #6737 (#6944) * 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 * riscv64: Use `PCRelLo12I` relocation on Loads (#6938) * 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 * Update Rust in CI to 1.72.0, clarify Wasmtime's MSRV (#6900) * 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 * aarch64: Use `RegScaled*` addressing modes (#6945) 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 * cranelift: Validate `iconst` ranges (#6850) * 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 * Some minor fixes and features for WASI and sockets (#6948) * 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. --------- Co-authored-by: Afonso Bordado <afonso360@users.noreply.github.com> Co-authored-by: Jamey Sharp <jsharp@fastly.com> Co-authored-by: Timothée Jourde <timjrd@netc.fr>
1 parent d35ca8e commit d752ebd

File tree

52 files changed

+1059
-485
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1059
-485
lines changed

.github/actions/install-rust/action.yml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ inputs:
55
toolchain:
66
description: 'Default toolchan to install'
77
required: false
8-
default: '1.71.0'
8+
default: 'default'
99
lockfiles:
1010
description: 'Path glob for Cargo.lock files to use as cache keys'
1111
required: false
@@ -14,13 +14,28 @@ inputs:
1414
runs:
1515
using: composite
1616
steps:
17+
- name: Install Rust
18+
shell: bash
19+
id: select
20+
run: |
21+
# Determine MSRV as N in `1.N.0` by looking at the `rust-version`
22+
# located in the root `Cargo.toml`.
23+
msrv=$(grep 'rust-version.*1' Cargo.toml | sed 's/.*\.\([0-9]*\)\..*/\1/')
24+
25+
if [ "${{ inputs.toolchain }}" = "default" ]; then
26+
echo "version=1.$((msrv+2)).0" >> "$GITHUB_OUTPUT"
27+
elif [ "${{ inputs.toolchain }}" = "msrv" ]; then
28+
echo "version=1.$msrv.0" >> "$GITHUB_OUTPUT"
29+
else
30+
echo "version=${{ inputs.toolchain }}" >> "$GITHUB_OUTPUT"
31+
fi
1732
1833
- name: Install Rust
1934
shell: bash
2035
run: |
2136
rustup set profile minimal
22-
rustup update "${{ inputs.toolchain }}" --no-self-update
23-
rustup default "${{ inputs.toolchain }}"
37+
rustup update "${{ steps.select.outputs.version }}" --no-self-update
38+
rustup default "${{ steps.select.outputs.version }}"
2439
2540
# Save disk space by avoiding incremental compilation. Also turn down
2641
# debuginfo from 2 to 0 to help save disk space.
@@ -31,11 +46,7 @@ runs:
3146
EOF
3247
3348
# Deny warnings on CI to keep our code warning-free as it lands in-tree.
34-
# Don't do this on nightly though, since there's a fair amount of
35-
# warning churn there.
36-
if [[ "${{ inputs.toolchain }}" != nightly* ]]; then
37-
echo RUSTFLAGS="-D warnings" >> "$GITHUB_ENV"
38-
fi
49+
echo RUSTFLAGS="-D warnings" >> "$GITHUB_ENV"
3950
4051
if [[ "${{ runner.os }}" = "macOS" ]]; then
4152
cat >> "$GITHUB_ENV" <<EOF

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@ jobs:
383383
with:
384384
submodules: true
385385
- uses: ./.github/actions/install-rust
386+
with:
387+
toolchain: ${{ matrix.rust }}
386388

387389
# Install targets in order to build various tests throughout the repo
388390
- run: rustup target add wasm32-wasi wasm32-unknown-unknown ${{ matrix.target }}

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ exclude = [
123123
version = "13.0.0"
124124
authors = ["The Wasmtime Project Developers"]
125125
edition = "2021"
126-
rust-version = "1.71.0"
126+
# Wasmtime's current policy is that this number can be no larger than the
127+
# current stable release of Rust minus 2.
128+
rust-version = "1.70.0"
127129

128130
[workspace.dependencies]
129131
wasmtime-wmemcheck = { path = "crates/wmemcheck", version = "=13.0.0" }

RELEASES.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,6 @@ Unreleased.
8080
These methods do not affect the size of the pre-allocated pool.
8181
[#6835](https://github.com/bytecodealliance/wasmtime/pull/6835)
8282

83-
* Options to the `wasmtime` CLI for Wasmtime itself must now come before the
84-
WebAssembly module. For example `wasmtime run foo.wasm --disable-cache` now
85-
must be specified as `wasmtime run --disable-cache foo.wasm`. Any
86-
argument/option after the WebAssembly module is now interpreted as an argument
87-
to the wasm module itself.
88-
[#6737](https://github.com/bytecodealliance/wasmtime/pull/6737)
89-
9083
* Builder methods for WASI contexts onw use `&mut self` instead of `self`.
9184
[#6770](https://github.com/bytecodealliance/wasmtime/pull/6770)
9285

ci/build-test-matrix.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,22 @@ const names = fs.readFileSync(process.argv[3]).toString();
3232
// on CI.
3333
// * `isa` - changes to `cranelift/codegen/src/$isa` will automatically run this
3434
// test suite.
35+
// * `rust` - the Rust version to install, and if unset this'll be set to
36+
// `default`
3537
const array = [
3638
{
3739
"os": "ubuntu-latest",
3840
"name": "Test Linux x86_64",
3941
"filter": "linux-x64",
4042
"isa": "x64"
4143
},
44+
{
45+
"os": "ubuntu-latest",
46+
"name": "Test MSRV on Linux x86_64",
47+
"filter": "linux-x64",
48+
"isa": "x64",
49+
"rust": "msrv",
50+
},
4251
{
4352
"os": "macos-latest",
4453
"name": "Test macOS x86_64",
@@ -90,6 +99,12 @@ const array = [
9099
}
91100
];
92101

102+
for (let config of array) {
103+
if (config.rust === undefined) {
104+
config.rust = 'default';
105+
}
106+
}
107+
93108
function myFilter(item) {
94109
if (item.isa && names.includes(`cranelift/codegen/src/isa/${item.isa}`)) {
95110
return true;

cranelift/codegen/src/isa/aarch64/inst.isle

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3122,15 +3122,37 @@
31223122
(rule 5 (amode ty (iadd (sextend x @ (value_type $I32)) y) offset)
31233123
(AMode.RegExtended (amode_add y offset) x (ExtendOp.SXTW)))
31243124

3125+
;; `RegScaled*` rules where this matches an addition of an "index register" to a
3126+
;; base register. The index register is shifted by the size of the type loaded
3127+
;; in bytes to enable this mode matching.
3128+
;;
3129+
;; Note that this can additionally bundle an extending operation but the
3130+
;; extension must happen before the shift. This will pattern-match the shift
3131+
;; first and then if that succeeds afterwards try to find an extend.
3132+
(rule 6 (amode ty (iadd x (ishl y (iconst (u64_from_imm64 n)))) offset)
3133+
(if-let $true (u64_eq (ty_bytes ty) (u64_shl 1 n)))
3134+
(amode_reg_scaled (amode_add x offset) y ty))
3135+
(rule 7 (amode ty (iadd (ishl y (iconst (u64_from_imm64 n))) x) offset)
3136+
(if-let $true (u64_eq (ty_bytes ty) (u64_shl 1 n)))
3137+
(amode_reg_scaled (amode_add x offset) y ty))
3138+
3139+
(decl amode_reg_scaled (Reg Value Type) AMode)
3140+
(rule 0 (amode_reg_scaled base index ty)
3141+
(AMode.RegScaled base index ty))
3142+
(rule 1 (amode_reg_scaled base (uextend index @ (value_type $I32)) ty)
3143+
(AMode.RegScaledExtended base index ty (ExtendOp.UXTW)))
3144+
(rule 2 (amode_reg_scaled base (sextend index @ (value_type $I32)) ty)
3145+
(AMode.RegScaledExtended base index ty (ExtendOp.SXTW)))
3146+
31253147
;; Small optimizations where constants found in `iadd` are folded into the
31263148
;; `offset` immediate.
31273149
;;
31283150
;; NB: this should probably be done by mid-end optimizations rather than here
31293151
;; in the backend, but currently Cranelift doesn't do that.
3130-
(rule 6 (amode ty (iadd x (iconst (simm32 y))) offset)
3152+
(rule 8 (amode ty (iadd x (iconst (simm32 y))) offset)
31313153
(if-let new_offset (s32_add_fallible y offset))
31323154
(amode ty x new_offset))
3133-
(rule 7 (amode ty (iadd (iconst (simm32 x)) y) offset)
3155+
(rule 9 (amode ty (iadd (iconst (simm32 x)) y) offset)
31343156
(if-let new_offset (s32_add_fallible x offset))
31353157
(amode ty y new_offset))
31363158

cranelift/codegen/src/isa/riscv64/inst/args.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,18 @@ impl AMode {
161161
}
162162
}
163163

164+
/// Retrieve a MachLabel that corresponds to this addressing mode, if it exists.
165+
pub(crate) fn get_label_with_sink(&self, sink: &mut MachBuffer<Inst>) -> Option<MachLabel> {
166+
match self {
167+
&AMode::Const(addr) => Some(sink.get_label_for_constant(addr)),
168+
&AMode::Label(label) => Some(label),
169+
&AMode::RegOffset(..)
170+
| &AMode::SPOffset(..)
171+
| &AMode::FPOffset(..)
172+
| &AMode::NominalSPOffset(..) => None,
173+
}
174+
}
175+
164176
pub(crate) fn to_string_with_alloc(&self, allocs: &mut AllocationConsumer<'_>) -> String {
165177
format!("{}", self.clone().with_allocs(allocs))
166178
}

cranelift/codegen/src/isa/riscv64/inst/emit.rs

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -620,18 +620,49 @@ impl MachInstEmit for Inst {
620620
let base = from.get_base_register();
621621
let offset = from.get_offset_with_state(state);
622622
let offset_imm12 = Imm12::maybe_from_i64(offset);
623+
let label = from.get_label_with_sink(sink);
623624

624-
// TODO: We shouldn't just fall back to `LoadAddr` immediately. For `MachLabel`s
625-
// we should try to emit the `auipc` and add a relocation on this load.
626-
let (addr, imm12) = match (base, offset_imm12) {
627-
// If the offset fits into an imm12 we can directly encode it.
628-
(Some(base), Some(imm12)) => (base, imm12),
629-
// Otherwise load the address it into a reg and load from it.
630-
_ => {
625+
let (addr, imm12) = match (base, offset_imm12, label) {
626+
// When loading from a Reg+Offset, if the offset fits into an imm12 we can directly encode it.
627+
(Some(base), Some(imm12), None) => (base, imm12),
628+
629+
// Otherwise, if the offset does not fit into a imm12, we need to materialize it into a
630+
// register and load from that.
631+
(Some(_), None, None) => {
631632
let tmp = writable_spilltmp_reg();
632633
Inst::LoadAddr { rd: tmp, mem: from }.emit(&[], sink, emit_info, state);
633634
(tmp.to_reg(), Imm12::zero())
634635
}
636+
637+
// If the AMode contains a label we can emit an internal relocation that gets
638+
// resolved with the correct address later.
639+
(None, Some(imm), Some(label)) => {
640+
debug_assert_eq!(imm.as_i16(), 0);
641+
642+
// Get the current PC.
643+
sink.use_label_at_offset(sink.cur_offset(), label, LabelUse::PCRelHi20);
644+
Inst::Auipc {
645+
rd,
646+
imm: Imm20::from_bits(0),
647+
}
648+
.emit(&[], sink, emit_info, state);
649+
650+
// Emit a relocation for the load. This patches the offset into the instruction.
651+
sink.use_label_at_offset(sink.cur_offset(), label, LabelUse::PCRelLo12I);
652+
653+
// Imm12 here is meaningless since it's going to get replaced.
654+
(rd.to_reg(), Imm12::zero())
655+
}
656+
657+
// These cases are impossible with the current AModes that we have. We either
658+
// always have a register, or always have a label. Never both, and never neither.
659+
(None, None, None)
660+
| (None, Some(_), None)
661+
| (Some(_), None, Some(_))
662+
| (Some(_), Some(_), Some(_))
663+
| (None, None, Some(_)) => {
664+
unreachable!("Invalid load address")
665+
}
635666
};
636667

637668
let srcloc = state.cur_srcloc();
@@ -650,8 +681,6 @@ impl MachInstEmit for Inst {
650681
let offset = to.get_offset_with_state(state);
651682
let offset_imm12 = Imm12::maybe_from_i64(offset);
652683

653-
// TODO: We shouldn't just fall back to `LoadAddr` immediately. For `MachLabel`s
654-
// we should try to emit the `auipc` and add a relocation on this store.
655684
let (addr, imm12) = match (base, offset_imm12) {
656685
// If the offset fits into an imm12 we can directly encode it.
657686
(Some(base), Some(imm12)) => (base, imm12),

cranelift/codegen/src/legalizer/mod.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use crate::cursor::{Cursor, FuncCursor};
1717
use crate::flowgraph::ControlFlowGraph;
1818
use crate::ir::immediates::Imm64;
19-
use crate::ir::types::{I128, I64};
19+
use crate::ir::types::{self, I128, I64};
2020
use crate::ir::{self, InstBuilder, InstructionData, MemFlags, Value};
2121
use crate::isa::TargetIsa;
2222
use crate::trace;
@@ -38,7 +38,17 @@ fn imm_const(pos: &mut FuncCursor, arg: Value, imm: Imm64, is_signed: bool) -> V
3838
let imm = pos.ins().iconst(I64, imm);
3939
pos.ins().uextend(I128, imm)
4040
}
41-
_ => pos.ins().iconst(ty.lane_type(), imm),
41+
_ => {
42+
let bits = imm.bits();
43+
let unsigned = match ty.lane_type() {
44+
types::I8 => bits as u8 as i64,
45+
types::I16 => bits as u16 as i64,
46+
types::I32 => bits as u32 as i64,
47+
types::I64 => bits,
48+
_ => unreachable!(),
49+
};
50+
pos.ins().iconst(ty.lane_type(), unsigned)
51+
}
4252
}
4353
}
4454

cranelift/codegen/src/prelude.isle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787

8888
(decl pure u16_as_u64 (u16) u64)
8989
(extern constructor u16_as_u64 u16_as_u64)
90+
(convert u16 u64 u16_as_u64)
9091

9192
(decl pure u32_as_u64 (u32) u64)
9293
(extern constructor u32_as_u64 u32_as_u64)

0 commit comments

Comments
 (0)