Skip to content

Commit

Permalink
[23.0.0] A few more backports (#8922)
Browse files Browse the repository at this point in the history
* Add custom-pages-sizes to CLI flags (#8917)

* Update dependency on `wit-bindgen` (#8911)

* Update dependency on `wit-bindgen`

Updating to the latest released version.

* Add vets

* Fix build of test-programs

* Fix panic with invalid DWARF file indices (#8913)

I'm not entirely sure what causes this but Wasmtime shouldn't panic with
invalid DWARF. In general (#5537) Wasmtime's support for DWARF needs to
be rewritten, but in the meantime let's play whack-a-mole with panics
and try to paper over issues.

Closes #8884
Closes #8904

* Wasmtime: Pop GC LIFO roots even when there is no GC heap (#8899)

* Wasmtime: Pop GC LIFO roots even when there is no GC heap

We can create and root `i31ref`s without ever allocating a GC heap for the
store, so we can't guard popping LIFO roots on the presence of a GC heap or else
we risk unbounded growth of the LIFO root set.

* Fix build with the gc feature disabled

---------

Co-authored-by: Nick Fitzgerald <fitzgen@gmail.com>
  • Loading branch information
alexcrichton and fitzgen authored Jul 9, 2024
1 parent d5e2170 commit 72fe1de
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 134 deletions.
174 changes: 51 additions & 123 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ io-lifetimes = { version = "2.0.3", default-features = false }
io-extras = "0.18.1"
rustix = "0.38.31"
# wit-bindgen:
wit-bindgen = { version = "0.26.0", default-features = false }
wit-bindgen-rust-macro = { version = "0.26.0", default-features = false }
wit-bindgen = { version = "0.27.0", default-features = false }
wit-bindgen-rust-macro = { version = "0.27.0", default-features = false }

# wasm-tools family:
wasmparser = { version = "0.212.0", default-features = false }
Expand Down
5 changes: 5 additions & 0 deletions crates/cli-flags/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ wasmtime_option_group! {
pub function_references: Option<bool>,
/// Configure support for the GC proposal.
pub gc: Option<bool>,
/// Configure support for the custom-page-sizes proposal.
pub custom_page_sizes: Option<bool>,
}

enum Wasm {
Expand Down Expand Up @@ -660,6 +662,9 @@ impl CommonOptions {
if let Some(enable) = self.wasm.memory64.or(all) {
config.wasm_memory64(enable);
}
if let Some(enable) = self.wasm.custom_page_sizes.or(all) {
config.wasm_custom_page_sizes(enable);
}

macro_rules! handle_conditionally_compiled {
($(($feature:tt, $field:tt, $method:tt))*) => ($(
Expand Down
10 changes: 9 additions & 1 deletion crates/cranelift/src/debug/transform/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,15 @@ where
..
} = file_context
{
write::AttributeValue::FileIndex(Some(file_map[(i - file_index_base) as usize]))
let index = usize::try_from(i - file_index_base)
.ok()
.and_then(|i| file_map.get(i).copied());
match index {
Some(index) => write::AttributeValue::FileIndex(Some(index)),
// This was seen to be invalid in #8884 and #8904 so
// ignore this seemingly invalid DWARF from LLVM
None => continue,
}
} else {
return Err(TransformError("unexpected file index attribute").into());
}
Expand Down
1 change: 1 addition & 0 deletions crates/test-programs/src/bin/api_reactor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
wit_bindgen::generate!({
world: "test-reactor",
path: "../wasi/wit",
generate_all,
});

struct T;
Expand Down
15 changes: 14 additions & 1 deletion crates/test-programs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ pub mod nn;
pub mod preview1;
pub mod sockets;

wit_bindgen::generate!("test-command" in "../wasi/wit");
wit_bindgen::generate!({
world: "test-command",
path: "../wasi/wit",
generate_all,
});

pub mod proxy {
wit_bindgen::generate!({
Expand All @@ -14,6 +18,15 @@ pub mod proxy {
with: {
"wasi:http/types@0.2.0": crate::wasi::http::types,
"wasi:http/outgoing-handler@0.2.0": crate::wasi::http::outgoing_handler,
"wasi:random/random@0.2.0": crate::wasi::random::random,
"wasi:io/error@0.2.0": crate::wasi::io::error,
"wasi:io/poll@0.2.0": crate::wasi::io::poll,
"wasi:io/streams@0.2.0": crate::wasi::io::streams,
"wasi:cli/stdout@0.2.0": crate::wasi::cli::stdout,
"wasi:cli/stderr@0.2.0": crate::wasi::cli::stderr,
"wasi:cli/stdin@0.2.0": crate::wasi::cli::stdin,
"wasi:clocks/monotonic-clock@0.2.0": crate::wasi::clocks::monotonic_clock,
"wasi:clocks/wall-clock@0.2.0": crate::wasi::clocks::wall_clock,
},
});
}
3 changes: 3 additions & 0 deletions crates/wasi-preview1-component-adapter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub mod bindings {
// Instead, we manually define the bindings for these functions in
// terms of raw pointers.
skip: ["run", "get-environment", "poll"],
generate_all,
});

#[cfg(feature = "reactor")]
Expand All @@ -78,6 +79,7 @@ pub mod bindings {
// Instead, we manually define the bindings for these functions in
// terms of raw pointers.
skip: ["get-environment", "poll"],
generate_all,
});

#[cfg(feature = "proxy")]
Expand All @@ -99,6 +101,7 @@ pub mod bindings {
raw_strings,
runtime_path: "crate::bindings::wit_bindgen_rt_shim",
skip: ["poll"],
generate_all,
});

pub mod wit_bindgen_rt_shim {
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmtime/src/runtime/gc/disabled/rooting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl RootSet {
usize::MAX
}

pub(crate) fn exit_lifo_scope(&mut self, _gc_store: &mut GcStore, _scope: usize) {}
pub(crate) fn exit_lifo_scope(&mut self, _gc_store: Option<&mut GcStore>, _scope: usize) {}

pub(crate) fn with_lifo_scope<T>(
store: &mut StoreOpaque,
Expand Down
12 changes: 9 additions & 3 deletions crates/wasmtime/src/runtime/gc/enabled/rooting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ impl RootSet {
///
/// Calls to `{enter,exit}_lifo_scope` must happen in a strict LIFO order.
#[inline]
pub(crate) fn exit_lifo_scope(&mut self, gc_store: &mut GcStore, scope: usize) {
pub(crate) fn exit_lifo_scope(&mut self, gc_store: Option<&mut GcStore>, scope: usize) {
debug_assert!(self.lifo_roots.len() >= scope);

// If we actually have roots to unroot, call an out-of-line slow path.
Expand All @@ -428,7 +428,7 @@ impl RootSet {

#[inline(never)]
#[cold]
fn exit_lifo_scope_slow(&mut self, gc_store: &mut GcStore, scope: usize) {
fn exit_lifo_scope_slow(&mut self, mut gc_store: Option<&mut GcStore>, scope: usize) {
self.lifo_generation += 1;

// TODO: In the case where we have a tracing GC that doesn't need to
Expand All @@ -438,7 +438,13 @@ impl RootSet {

let mut lifo_roots = mem::take(&mut self.lifo_roots);
for root in lifo_roots.drain(scope..) {
gc_store.drop_gc_ref(root.gc_ref);
// Only drop the GC reference if we actually have a GC store. How
// can we have a GC reference but not a GC store? If we've only
// create `i31refs`, we never force a GC store's allocation. This is
// fine because `i31ref`s never need drop barriers.
if let Some(gc_store) = &mut gc_store {
gc_store.drop_gc_ref(root.gc_ref);
}
}
self.lifo_roots = lifo_roots;
}
Expand Down
4 changes: 1 addition & 3 deletions crates/wasmtime/src/runtime/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1584,9 +1584,7 @@ impl StoreOpaque {

#[inline]
pub(crate) fn exit_gc_lifo_scope(&mut self, scope: usize) {
if let Some(gc_store) = self.gc_store.as_mut() {
self.gc_roots.exit_lifo_scope(gc_store, scope);
}
self.gc_roots.exit_lifo_scope(self.gc_store.as_mut(), scope);
}

#[cfg(feature = "gc")]
Expand Down
37 changes: 37 additions & 0 deletions supply-chain/imports.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,13 @@ user-id = 3618
user-login = "dtolnay"
user-name = "David Tolnay"

[[publisher.prettyplease]]
version = "0.2.20"
when = "2024-05-07"
user-id = 3618
user-login = "dtolnay"
user-name = "David Tolnay"

[[publisher.proc-macro2]]
version = "1.0.81"
when = "2024-04-17"
Expand Down Expand Up @@ -3092,6 +3099,12 @@ when = "2024-05-30"
user-id = 73222
user-login = "wasmtime-publish"

[[publisher.wit-bindgen]]
version = "0.27.0"
when = "2024-06-28"
user-id = 73222
user-login = "wasmtime-publish"

[[publisher.wit-bindgen-core]]
version = "0.20.0"
when = "2024-02-29"
Expand All @@ -3116,6 +3129,12 @@ when = "2024-05-30"
user-id = 73222
user-login = "wasmtime-publish"

[[publisher.wit-bindgen-core]]
version = "0.27.0"
when = "2024-06-28"
user-id = 73222
user-login = "wasmtime-publish"

[[publisher.wit-bindgen-rt]]
version = "0.22.0"
when = "2024-03-11"
Expand All @@ -3134,6 +3153,12 @@ when = "2024-05-30"
user-id = 73222
user-login = "wasmtime-publish"

[[publisher.wit-bindgen-rt]]
version = "0.27.0"
when = "2024-06-28"
user-id = 73222
user-login = "wasmtime-publish"

[[publisher.wit-bindgen-rust]]
version = "0.20.0"
when = "2024-02-29"
Expand All @@ -3158,6 +3183,12 @@ when = "2024-05-30"
user-id = 73222
user-login = "wasmtime-publish"

[[publisher.wit-bindgen-rust]]
version = "0.27.0"
when = "2024-06-28"
user-id = 73222
user-login = "wasmtime-publish"

[[publisher.wit-bindgen-rust-macro]]
version = "0.20.0"
when = "2024-02-29"
Expand All @@ -3182,6 +3213,12 @@ when = "2024-05-30"
user-id = 73222
user-login = "wasmtime-publish"

[[publisher.wit-bindgen-rust-macro]]
version = "0.27.0"
when = "2024-06-28"
user-id = 73222
user-login = "wasmtime-publish"

[[publisher.wit-component]]
version = "0.201.0"
when = "2024-02-27"
Expand Down
21 changes: 21 additions & 0 deletions tests/all/i31ref.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use wasmtime::*;

#[test]
fn always_pop_i31ref_lifo_roots() -> Result<()> {
let mut config = Config::new();
config.wasm_function_references(true);
config.wasm_gc(true);

let engine = Engine::new(&config)?;
let mut store = Store::new(&engine, ());

let anyref = {
let mut scope = RootScope::new(&mut store);
AnyRef::from_i31(&mut scope, I31::wrapping_u32(42))
};

// The anyref has left its rooting scope and been unrooted.
assert!(anyref.is_i31(&store).is_err());

Ok(())
}
1 change: 1 addition & 0 deletions tests/all/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod funcref;
mod gc;
mod globals;
mod host_funcs;
mod i31ref;
mod iloop;
mod import_calling_export;
mod import_indexes;
Expand Down

0 comments on commit 72fe1de

Please sign in to comment.