Skip to content

Commit b9f2652

Browse files
committed
Fix warnings for CI
1 parent 578c8b8 commit b9f2652

File tree

8 files changed

+203
-209
lines changed

8 files changed

+203
-209
lines changed

crates/environ/src/component/types.rs

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::component::{FlatTypesStorage, MAX_FLAT_PARAMS, MAX_FLAT_RESULTS};
1+
use crate::component::{MAX_FLAT_PARAMS, MAX_FLAT_RESULTS};
22
use crate::{EntityType, ModuleInternedTypeIndex, ModuleTypes, PrimaryMap};
33
use crate::{TypeTrace, prelude::*};
44
use core::hash::{Hash, Hasher};
@@ -1386,6 +1386,83 @@ const fn max_flat(a: Option<u8>, b: Option<u8>) -> Option<u8> {
13861386
}
13871387
}
13881388

1389+
/// Representation of flat types in 32-bit and 64-bit memory
1390+
///
1391+
/// This could be represented as `Vec<FlatType>` but on 64-bit architectures
1392+
/// that's 24 bytes. Otherwise `FlatType` is 1 byte large and
1393+
/// `MAX_FLAT_TYPES` is 16, so it should ideally be more space-efficient to
1394+
/// use a flat array instead of a heap-based vector.
1395+
#[derive(Debug)]
1396+
pub struct FlatTypesStorage {
1397+
/// Representation for 32-bit memory
1398+
pub memory32: [FlatType; MAX_FLAT_TYPES],
1399+
/// Representation for 64-bit memory
1400+
pub memory64: [FlatType; MAX_FLAT_TYPES],
1401+
1402+
/// Tracks the number of flat types pushed into this storage. If this is
1403+
/// `MAX_FLAT_TYPES + 1` then this storage represents an un-reprsentable
1404+
/// type in flat types.
1405+
///
1406+
/// This value should be the same on both `memory32` and `memory64`
1407+
pub len: u8,
1408+
}
1409+
1410+
impl FlatTypesStorage {
1411+
/// Create a new, empty storage for flat types
1412+
pub const fn new() -> FlatTypesStorage {
1413+
FlatTypesStorage {
1414+
memory32: [FlatType::I32; MAX_FLAT_TYPES],
1415+
memory64: [FlatType::I32; MAX_FLAT_TYPES],
1416+
len: 0,
1417+
}
1418+
}
1419+
1420+
/// Returns a reference to flat type representation
1421+
pub fn as_flat_types(&self) -> Option<FlatTypes<'_>> {
1422+
let len = usize::from(self.len);
1423+
if len > MAX_FLAT_TYPES {
1424+
assert_eq!(len, MAX_FLAT_TYPES + 1);
1425+
None
1426+
} else {
1427+
Some(FlatTypes {
1428+
memory32: &self.memory32[..len],
1429+
memory64: &self.memory64[..len],
1430+
})
1431+
}
1432+
}
1433+
1434+
/// Pushes a new flat type into this list using `t32` for 32-bit memories
1435+
/// and `t64` for 64-bit memories.
1436+
///
1437+
/// Returns whether the type was actually pushed or whether this list of
1438+
/// flat types just exceeded the maximum meaning that it is now
1439+
/// unrepresentable with a flat list of types.
1440+
pub fn push(&mut self, t32: FlatType, t64: FlatType) -> bool {
1441+
let len = usize::from(self.len);
1442+
if len < MAX_FLAT_TYPES {
1443+
self.memory32[len] = t32;
1444+
self.memory64[len] = t64;
1445+
self.len += 1;
1446+
true
1447+
} else {
1448+
// If this was the first one to go over then flag the length as
1449+
// being incompatible with a flat representation.
1450+
if len == MAX_FLAT_TYPES {
1451+
self.len += 1;
1452+
}
1453+
false
1454+
}
1455+
}
1456+
1457+
/// Generate an iterator over the 32-bit flat encoding
1458+
pub fn iter32(&self) -> impl Iterator<Item = u8> {
1459+
self.memory32
1460+
.iter()
1461+
.take(self.len as usize)
1462+
.map(|f| f.byte_size())
1463+
}
1464+
}
1465+
13891466
/// Flat representation of a type in just core wasm types.
13901467
pub struct FlatTypes<'a> {
13911468
/// The flat representation of this type in 32-bit memories.
@@ -1417,6 +1494,17 @@ pub enum FlatType {
14171494
}
14181495

14191496
impl FlatType {
1497+
/// Constructs the "joined" representation for two flat types
1498+
pub fn join(&mut self, other: FlatType) {
1499+
if *self == other {
1500+
return;
1501+
}
1502+
*self = match (*self, other) {
1503+
(FlatType::I32, FlatType::F32) | (FlatType::F32, FlatType::I32) => FlatType::I32,
1504+
_ => FlatType::I64,
1505+
};
1506+
}
1507+
14201508
/// Return the size in bytes for this flat type
14211509
pub const fn byte_size(&self) -> u8 {
14221510
match self {

crates/environ/src/component/types_builder.rs

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -840,96 +840,6 @@ where
840840
return idx;
841841
}
842842

843-
/// Representation of flat types in 32-bit and 64-bit memory
844-
///
845-
/// This could be represented as `Vec<FlatType>` but on 64-bit architectures
846-
/// that's 24 bytes. Otherwise `FlatType` is 1 byte large and
847-
/// `MAX_FLAT_TYPES` is 16, so it should ideally be more space-efficient to
848-
/// use a flat array instead of a heap-based vector.
849-
#[derive(Debug)]
850-
pub struct FlatTypesStorage {
851-
/// Representation for 32-bit memory
852-
pub memory32: [FlatType; MAX_FLAT_TYPES],
853-
/// Representation for 64-bit memory
854-
pub memory64: [FlatType; MAX_FLAT_TYPES],
855-
856-
/// Tracks the number of flat types pushed into this storage. If this is
857-
/// `MAX_FLAT_TYPES + 1` then this storage represents an un-reprsentable
858-
/// type in flat types.
859-
///
860-
/// This value should be the same on both `memory32` and `memory64`
861-
pub len: u8,
862-
}
863-
864-
impl FlatTypesStorage {
865-
/// Create a new, empty storage for flat types
866-
pub const fn new() -> FlatTypesStorage {
867-
FlatTypesStorage {
868-
memory32: [FlatType::I32; MAX_FLAT_TYPES],
869-
memory64: [FlatType::I32; MAX_FLAT_TYPES],
870-
len: 0,
871-
}
872-
}
873-
874-
/// Returns a reference to flat type representation
875-
pub fn as_flat_types(&self) -> Option<FlatTypes<'_>> {
876-
let len = usize::from(self.len);
877-
if len > MAX_FLAT_TYPES {
878-
assert_eq!(len, MAX_FLAT_TYPES + 1);
879-
None
880-
} else {
881-
Some(FlatTypes {
882-
memory32: &self.memory32[..len],
883-
memory64: &self.memory64[..len],
884-
})
885-
}
886-
}
887-
888-
/// Pushes a new flat type into this list using `t32` for 32-bit memories
889-
/// and `t64` for 64-bit memories.
890-
///
891-
/// Returns whether the type was actually pushed or whether this list of
892-
/// flat types just exceeded the maximum meaning that it is now
893-
/// unrepresentable with a flat list of types.
894-
pub fn push(&mut self, t32: FlatType, t64: FlatType) -> bool {
895-
let len = usize::from(self.len);
896-
if len < MAX_FLAT_TYPES {
897-
self.memory32[len] = t32;
898-
self.memory64[len] = t64;
899-
self.len += 1;
900-
true
901-
} else {
902-
// If this was the first one to go over then flag the length as
903-
// being incompatible with a flat representation.
904-
if len == MAX_FLAT_TYPES {
905-
self.len += 1;
906-
}
907-
false
908-
}
909-
}
910-
911-
/// Generate an iterator over the 32-bit flat encoding
912-
pub fn iter32(&self) -> impl Iterator<Item = u8> {
913-
self.memory32
914-
.iter()
915-
.take(self.len as usize)
916-
.map(|f| f.byte_size())
917-
}
918-
}
919-
920-
impl FlatType {
921-
/// Constructs the "joined" representation for two flat types
922-
pub fn join(&mut self, other: FlatType) {
923-
if *self == other {
924-
return;
925-
}
926-
*self = match (*self, other) {
927-
(FlatType::I32, FlatType::F32) | (FlatType::F32, FlatType::I32) => FlatType::I32,
928-
_ => FlatType::I64,
929-
};
930-
}
931-
}
932-
933843
#[derive(Default)]
934844
struct TypeInformationCache {
935845
records: PrimaryMap<TypeRecordIndex, TypeInformation>,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ where
867867

868868
storage[0] = MaybeUninit::new(ValRaw::i32(status as i32));
869869
rr::component_hooks::record_host_func_return(
870-
&mut storage[..1],
870+
&storage[..1],
871871
types,
872872
&InterfaceType::U32,
873873
store.0,

crates/wasmtime/src/runtime/func.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,10 +1303,7 @@ impl Func {
13031303
let nparams = ty.params().len();
13041304
val_vec.reserve(nparams + ty.results().len());
13051305

1306-
let flat_params = ty
1307-
.params()
1308-
.into_iter()
1309-
.map(|x| x.to_wasm_type().byte_size());
1306+
let flat_params = ty.params().map(|x| x.to_wasm_type().byte_size());
13101307

13111308
if !caller.store.0.replay_enabled() {
13121309
rr::core_hooks::record_validate_host_func_entry(
@@ -1332,10 +1329,7 @@ impl Func {
13321329
values_vec[i] = ret.to_raw(&mut caller.store)?;
13331330
}
13341331

1335-
let flat_results = ty
1336-
.results()
1337-
.into_iter()
1338-
.map(|x| x.to_wasm_type().byte_size());
1332+
let flat_results = ty.results().map(|x| x.to_wasm_type().byte_size());
13391333
rr::core_hooks::record_host_func_return(values_vec, flat_results, &mut caller.store.0)?;
13401334
} else {
13411335
rr::core_hooks::replay_validate_host_func_entry(

crates/wasmtime/src/runtime/func/typed.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,7 @@ where
194194
params.store(&mut store, ty, dst)?;
195195
}
196196

197-
let storage_len =
198-
mem::size_of_val::<Storage<_, _>>(&mut storage) / mem::size_of::<ValRaw>();
197+
let storage_len = mem::size_of_val::<Storage<_, _>>(&storage) / mem::size_of::<ValRaw>();
199198
let storage_slice: *mut Storage<_, _> = &mut storage;
200199
let storage_slice = storage_slice.cast::<ValRaw>();
201200
let storage_slice = core::ptr::slice_from_raw_parts_mut(storage_slice, storage_len);

crates/wasmtime/src/runtime/rr.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ impl FlatBytes for MaybeUninit<ValRaw> {
4343

4444
/// Convenience method hooks for injecting event recording/replaying in the rest of the engine
4545
mod hooks;
46-
pub(crate) use hooks::{ConstMemorySliceCell, MemorySliceCell, component_hooks, core_hooks};
46+
pub(crate) use hooks::core_hooks;
47+
#[cfg(feature = "component-model")]
48+
pub(crate) use hooks::{
49+
component_hooks, component_hooks::ConstMemorySliceCell, component_hooks::MemorySliceCell,
50+
};
4751

4852
/// Core infrastructure for RR support
4953
#[cfg(feature = "rr")]
Lines changed: 1 addition & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,5 @@
1-
#[cfg(feature = "rr-component")]
2-
use crate::rr::{RecordBuffer, Recorder, component_events::MemorySliceWriteEvent};
3-
4-
use core::ops::{Deref, DerefMut};
5-
61
/// Component specific RR hooks that use `component-model` feature gating
2+
#[cfg(feature = "component-model")]
73
pub mod component_hooks;
84
/// Core RR hooks
95
pub mod core_hooks;
10-
11-
/// Same as [`ConstMemorySliceCell`] except allows for dynamically sized slices.
12-
///
13-
/// Prefer the above for efficiency if slice size is known statically.
14-
///
15-
/// **Note**: The correct operation of this type relies of several invariants.
16-
/// See [`ConstMemorySliceCell`] for detailed description on the role
17-
/// of these types.
18-
pub struct MemorySliceCell<'a> {
19-
pub bytes: &'a mut [u8],
20-
#[cfg(feature = "rr-component")]
21-
pub offset: usize,
22-
#[cfg(feature = "rr-component")]
23-
pub recorder: Option<&'a mut RecordBuffer>,
24-
}
25-
impl<'a> Deref for MemorySliceCell<'a> {
26-
type Target = [u8];
27-
fn deref(&self) -> &Self::Target {
28-
self.bytes
29-
}
30-
}
31-
impl DerefMut for MemorySliceCell<'_> {
32-
fn deref_mut(&mut self) -> &mut Self::Target {
33-
self.bytes
34-
}
35-
}
36-
impl Drop for MemorySliceCell<'_> {
37-
/// Drop serves as a recording hook for stores to the memory slice
38-
fn drop(&mut self) {
39-
#[cfg(feature = "rr-component")]
40-
if let Some(buf) = &mut self.recorder {
41-
buf.record_event(|| MemorySliceWriteEvent {
42-
offset: self.offset,
43-
bytes: self.bytes.to_vec(),
44-
})
45-
.unwrap();
46-
}
47-
}
48-
}
49-
50-
/// Zero-cost encapsulation type for a statically sized slice of mutable memory
51-
///
52-
/// # Purpose and Usage (Read Carefully!)
53-
///
54-
/// This type (and its dynamic counterpart [`MemorySliceCell`]) are critical to
55-
/// record/replay (RR) support in Wasmtime. In practice, all lowering operations utilize
56-
/// a [`LowerContext`], which provides a capability to modify guest Wasm module state in
57-
/// the following ways:
58-
///
59-
/// 1. Write to slices of memory with [`get`](LowerContext::get)/[`get_dyn`](LowerContext::get_dyn)
60-
/// 2. Movement of memory with [`realloc`](LowerContext::realloc)
61-
///
62-
/// The above are intended to be the narrow waists for recording changes to guest state, and
63-
/// should be the **only** interfaces used during lowerng. In particular,
64-
/// [`get`](LowerContext::get)/[`get_dyn`](LowerContext::get_dyn) return
65-
/// ([`ConstMemorySliceCell`]/[`MemorySliceCell`]), which implement [`Drop`]
66-
/// allowing us a hook to just capture the final aggregate changes made to guest memory by the host.
67-
///
68-
/// ## Critical Invariants
69-
///
70-
/// Typically recording would need to know both when the slice was borrowed AND when it was
71-
/// dropped, since memory movement with [`realloc`](LowerContext::realloc) can be interleaved between
72-
/// borrows and drops, and replays would have to be aware of this. **However**, with this abstraction,
73-
/// we can be more efficient and get away with **only** recording drops, because of the implicit interaction between
74-
/// [`realloc`](LowerContext::realloc) and [`get`](LowerContext::get)/[`get_dyn`](LowerContext::get_dyn),
75-
/// which both take a `&mut self`. Since the latter implements [`Drop`], which also takes a `&mut self`,
76-
/// the compiler will automatically enforce that drops of this type need to be triggered before a
77-
/// [`realloc`](LowerContext::realloc), preventing any interleavings in between the borrow and drop of the slice.
78-
pub struct ConstMemorySliceCell<'a, const N: usize> {
79-
pub bytes: &'a mut [u8; N],
80-
#[cfg(feature = "rr-component")]
81-
pub offset: usize,
82-
#[cfg(feature = "rr-component")]
83-
pub recorder: Option<&'a mut RecordBuffer>,
84-
}
85-
impl<'a, const N: usize> Deref for ConstMemorySliceCell<'a, N> {
86-
type Target = [u8; N];
87-
fn deref(&self) -> &Self::Target {
88-
self.bytes
89-
}
90-
}
91-
impl<'a, const N: usize> DerefMut for ConstMemorySliceCell<'a, N> {
92-
fn deref_mut(&mut self) -> &mut Self::Target {
93-
self.bytes
94-
}
95-
}
96-
impl<'a, const N: usize> Drop for ConstMemorySliceCell<'a, N> {
97-
/// Drops serves as a recording hook for stores to the memory slice
98-
fn drop(&mut self) {
99-
#[cfg(feature = "rr-component")]
100-
if let Some(buf) = &mut self.recorder {
101-
buf.record_event(|| MemorySliceWriteEvent {
102-
offset: self.offset,
103-
bytes: self.bytes.to_vec(),
104-
})
105-
.unwrap();
106-
}
107-
}
108-
}

0 commit comments

Comments
 (0)