Skip to content

Commit 796c1ed

Browse files
committed
Added tests for rr; reduce func size with packed option; commonize host func entry event
1 parent c89684e commit 796c1ed

File tree

15 files changed

+460
-74
lines changed

15 files changed

+460
-74
lines changed

crates/c-api/include/wasmtime/extern.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ typedef struct wasmtime_func {
3232
/// Private field for Wasmtime, undefined if `store_id` is zero.
3333
void *__private1;
3434
/// Private field for Wasmtime
35-
uint32_t *__private2;
36-
/// Private field for Wasmtime
37-
uint32_t *__private3;
35+
uint32_t __private2;
3836
/// Private field for Wasmtime
39-
uint32_t *__private4;
37+
uint32_t __private3;
4038
} wasmtime_func_t;
4139

4240
/// \brief Representation of a table in Wasmtime.

crates/c-api/include/wasmtime/val.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ typedef union wasmtime_val_raw {
418418
// Assert that the shape of this type is as expected since it needs to match
419419
// Rust.
420420
static inline void __wasmtime_val_assertions() {
421-
static_assert(sizeof(wasmtime_valunion_t) == 32, "should be 16-bytes large");
421+
static_assert(sizeof(wasmtime_valunion_t) == 24, "should be 24-bytes large");
422422
static_assert(__alignof(wasmtime_valunion_t) == 8,
423423
"should be 8-byte aligned");
424424
static_assert(sizeof(wasmtime_val_raw_t) == 16, "should be 16 bytes large");

crates/c-api/src/val.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub union wasmtime_val_union {
152152
}
153153

154154
const _: () = {
155-
assert!(std::mem::size_of::<wasmtime_val_union>() == 32);
155+
assert!(std::mem::size_of::<wasmtime_val_union>() == 24);
156156
assert!(std::mem::align_of::<wasmtime_val_union>() == std::mem::align_of::<u64>());
157157
};
158158

crates/wasmtime/src/runtime/component/func/options.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,8 @@ impl<'a, T: 'static> LowerContext<'a, T> {
651651
//
652652
// Realloc or any lowering methods cannot call back to the host. Hence, you cannot
653653
// have host calls entries during this method
654-
RREvent::ComponentHostFuncEntry(_) => {
655-
bail!("Cannot call into host during lowering")
654+
RREvent::HostFuncEntry(_) => {
655+
bail!("Cannot call back into host during lowering")
656656
}
657657
// Unwrapping should never occur on valid executions since *Entry should be before *Return in trace
658658
RREvent::ComponentReallocReturn(e) => {

crates/wasmtime/src/runtime/func.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ use core::future::Future;
1818
use core::mem::{self, MaybeUninit};
1919
use core::ptr::NonNull;
2020
use serde::{Deserialize, Serialize};
21-
use wasmtime_environ::{FuncIndex, VMSharedTypeIndex};
21+
use wasmtime_environ::{
22+
FuncIndex, VMSharedTypeIndex, packed_option::PackedOption, packed_option::ReservedValue,
23+
};
2224

2325
/// A reference to the abstract `nofunc` heap value.
2426
///
@@ -112,6 +114,19 @@ pub struct WasmFuncOrigin {
112114
pub index: FuncIndex,
113115
}
114116

117+
impl ReservedValue for WasmFuncOrigin {
118+
fn reserved_value() -> Self {
119+
WasmFuncOrigin {
120+
instance: InstanceId::reserved_value(),
121+
index: FuncIndex::reserved_value(),
122+
}
123+
}
124+
125+
fn is_reserved_value(&self) -> bool {
126+
self.instance.is_reserved_value() && self.index.is_reserved_value()
127+
}
128+
}
129+
115130
/// A WebAssembly function which can be called.
116131
///
117132
/// This type typically represents an exported function from a WebAssembly
@@ -294,14 +309,14 @@ pub struct Func {
294309
/// This field is populated when a [`Func`] is generated from a known instance
295310
/// (i.e. exported Wasm functions), and is usually `None` for internal
296311
/// Wasm functions and host functions.
297-
origin: Option<WasmFuncOrigin>,
312+
origin: PackedOption<WasmFuncOrigin>,
298313
}
299314

300315
// Double-check that the C representation in `extern.h` matches our in-Rust
301316
// representation here in terms of size/alignment/etc.
302317
const _: () = {
303318
#[repr(C)]
304-
struct C(u64, *mut u8, (u32, u32, u32));
319+
struct C(u64, *mut u8, (u32, u32));
305320
assert!(core::mem::size_of::<C>() == core::mem::size_of::<Func>());
306321
assert!(core::mem::align_of::<C>() == core::mem::align_of::<Func>());
307322
assert!(core::mem::offset_of!(Func, store) == 0);
@@ -566,7 +581,7 @@ impl Func {
566581
Func {
567582
store,
568583
unsafe_func_ref: func_ref.into(),
569-
origin: None,
584+
origin: PackedOption::default(),
570585
}
571586
}
572587

@@ -1035,7 +1050,7 @@ impl Func {
10351050
},
10361051
unsafe { params_and_returns.as_ref() },
10371052
&self.ty(&store),
1038-
self.origin.clone(),
1053+
self.origin.expand(),
10391054
&mut store,
10401055
)
10411056
}
@@ -1536,12 +1551,12 @@ impl Func {
15361551

15371552
/// Set the origin of this function.
15381553
pub(crate) fn set_origin(&mut self, origin: WasmFuncOrigin) {
1539-
self.origin = Some(origin);
1554+
self.origin = PackedOption::from(origin);
15401555
}
15411556

15421557
// Get the origin of this function
15431558
pub(crate) fn origin(&self) -> Option<WasmFuncOrigin> {
1544-
self.origin
1559+
self.origin.expand()
15451560
}
15461561
}
15471562

crates/wasmtime/src/runtime/rr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ impl FlatBytes for MaybeUninit<ValRaw> {
3030
#[inline]
3131
fn bytes_ref(&self, size: u8) -> &[u8] {
3232
// Uninitialized data is assumed and serialized, so hence
33-
// may contain some undefined values
33+
// may contain some undefined values. But these are irrelevant
34+
// when serializing to `RRFuncArgVals`
3435
let val = unsafe { self.assume_init_ref() };
3536
val.bytes_ref(size)
3637
}

0 commit comments

Comments
 (0)