Skip to content

Commit 192cfd4

Browse files
committed
Fold component-model feature into rr
1 parent ae0905d commit 192cfd4

File tree

11 files changed

+234
-314
lines changed

11 files changed

+234
-314
lines changed

crates/wasmtime/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,4 +428,4 @@ debug = [
428428
compile-time-builtins = ['dep:wasm-compose', 'dep:tempfile']
429429

430430
# Enable support for the common base infrastructure of record/replay
431-
rr = ["dep:embedded-io"]
431+
rr = ["component-model", "dep:embedded-io"]

crates/wasmtime/build.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ fn main() {
3333
custom_cfg("has_custom_sync", has_custom_sync);
3434
custom_cfg("has_host_compiler_backend", has_host_compiler_backend);
3535

36-
// Component model support for record/replay
37-
let rr_component = cfg!(feature = "rr") && cfg!(feature = "component-model");
38-
custom_cfg("rr_component", rr_component);
39-
4036
// If this OS isn't supported and no debug-builtins or if Cranelift doesn't support
4137
// the host or there's no need to build these helpers.
4238
#[cfg(feature = "runtime")]

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::component::types::ComponentFunc;
88
use crate::component::{ComponentNamedList, ComponentType, Instance, Lift, Lower, Val};
99
use crate::prelude::*;
1010
use crate::rr;
11-
#[cfg(rr_component)]
11+
#[cfg(feature = "rr")]
1212
use crate::rr::component_hooks::ReplayLoweringPhase;
1313
use crate::runtime::vm::component::{
1414
ComponentInstance, VMComponentContext, VMLowering, VMLoweringCallee,
@@ -941,7 +941,7 @@ where
941941
store.0.store_opaque_mut(),
942942
)?;
943943
// Replay host function path: Just lower the results from the trace
944-
#[cfg(rr_component)]
944+
#[cfg(feature = "rr")]
945945
{
946946
let mut cx = LowerContext::new(store, options, instance);
947947
// Skip lifting/lowering logic, and just replaying the lowering state
@@ -966,11 +966,9 @@ where
966966
}
967967
}
968968
}
969-
#[cfg(not(rr_component))]
969+
#[cfg(not(feature = "rr"))]
970970
{
971-
unreachable!(
972-
"cannot reach host function replay when rr and component-model is disabled"
973-
);
971+
unreachable!("cannot reach host function replay when rr is disabled");
974972
}
975973
}
976974

@@ -1018,7 +1016,7 @@ unsafe fn dynamic_params_load(
10181016
}
10191017

10201018
/// Replay of return values from `dynamic_params_load`. Keep in sync
1021-
#[cfg(rr_component)]
1019+
#[cfg(feature = "rr")]
10221020
unsafe fn dynamic_params_load_replay(param_tys: &TypeTuple, max_flat_params: usize) -> usize {
10231021
if let Some(param_count) = param_tys.abi.flat_count(max_flat_params) {
10241022
param_count

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use crate::StoreContextMut;
2-
#[cfg(rr_component)]
2+
#[cfg(feature = "rr")]
33
use crate::ValRaw;
44
use crate::component::concurrent::ConcurrentState;
55
use crate::component::matching::InstanceType;
66
use crate::component::resources::{HostResourceData, HostResourceIndex, HostResourceTables};
77
use crate::component::{Instance, ResourceType};
88
use crate::prelude::*;
99
use crate::rr::{DynamicMemorySlice, FixedMemorySlice};
10-
#[cfg(rr_component)]
10+
#[cfg(feature = "rr")]
1111
use crate::rr::{
1212
RREvent, RecordBuffer, ReplayError, Replayer, ResultEvent, Validate,
1313
component_events::ReallocEntryEvent, component_events::ReallocReturnEvent,
@@ -19,7 +19,7 @@ use crate::runtime::vm::component::{
1919
};
2020
use crate::store::{StoreId, StoreOpaque};
2121
use alloc::sync::Arc;
22-
#[cfg(rr_component)]
22+
#[cfg(feature = "rr")]
2323
use core::mem::MaybeUninit;
2424
use core::pin::Pin;
2525
use core::ptr::NonNull;
@@ -126,7 +126,7 @@ impl<'a, T: 'static> LowerContext<'a, T> {
126126
}
127127

128128
/// Return the `InstanceFlags` for this context
129-
#[cfg(rr_component)]
129+
#[cfg(feature = "rr")]
130130
fn instance_flags(&self) -> InstanceFlags {
131131
let vminstance = self.instance.id().get(self.store.0);
132132
let opts = self.options();
@@ -139,7 +139,7 @@ impl<'a, T: 'static> LowerContext<'a, T> {
139139
/// # Panics
140140
///
141141
/// See [`as_slice`](Self::as_slice)
142-
#[cfg(rr_component)]
142+
#[cfg(feature = "rr")]
143143
fn as_slice_mut_with_recorder(&mut self) -> (&mut [u8], Option<&mut RecordBuffer>) {
144144
self.instance
145145
.options_memory_mut_with_recorder(self.store.0, self.options)
@@ -243,15 +243,15 @@ impl<'a, T: 'static> LowerContext<'a, T> {
243243
old_align: u32,
244244
new_size: usize,
245245
) -> Result<usize> {
246-
#[cfg(rr_component)]
246+
#[cfg(feature = "rr")]
247247
self.store.0.record_event(|| ReallocEntryEvent {
248248
old_addr: old,
249249
old_size,
250250
old_align,
251251
new_size,
252252
})?;
253253
let result = self.realloc_inner(old, old_size, old_align, new_size);
254-
#[cfg(rr_component)]
254+
#[cfg(feature = "rr")]
255255
self.store.0.record_event_validation(|| {
256256
ReallocReturnEvent(ResultEvent::from_anyhow_result(&result))
257257
})?;
@@ -271,7 +271,7 @@ impl<'a, T: 'static> LowerContext<'a, T> {
271271
#[inline]
272272
pub fn get<const N: usize>(&mut self, offset: usize) -> FixedMemorySlice<'_, N> {
273273
cfg_if::cfg_if! {
274-
if #[cfg(rr_component)] {
274+
if #[cfg(feature = "rr")] {
275275
let (slice_mut, recorder) = self.as_slice_mut_with_recorder();
276276
} else {
277277
let slice_mut = self.as_slice_mut();
@@ -289,9 +289,9 @@ impl<'a, T: 'static> LowerContext<'a, T> {
289289
// of `unsafe`.
290290
FixedMemorySlice {
291291
bytes: slice_mut[offset..].first_chunk_mut().unwrap(),
292-
#[cfg(rr_component)]
292+
#[cfg(feature = "rr")]
293293
offset: offset,
294-
#[cfg(rr_component)]
294+
#[cfg(feature = "rr")]
295295
recorder: recorder,
296296
}
297297
}
@@ -305,17 +305,17 @@ impl<'a, T: 'static> LowerContext<'a, T> {
305305
#[inline]
306306
pub fn get_dyn(&mut self, offset: usize, size: usize) -> DynamicMemorySlice<'_> {
307307
cfg_if::cfg_if! {
308-
if #[cfg(rr_component)] {
308+
if #[cfg(feature = "rr")] {
309309
let (slice_mut, recorder) = self.as_slice_mut_with_recorder();
310310
} else {
311311
let slice_mut = self.as_slice_mut();
312312
}
313313
}
314314
DynamicMemorySlice {
315315
bytes: &mut slice_mut[offset..][..size],
316-
#[cfg(rr_component)]
316+
#[cfg(feature = "rr")]
317317
offset: offset,
318-
#[cfg(rr_component)]
318+
#[cfg(feature = "rr")]
319319
recorder: recorder,
320320
}
321321
}
@@ -418,7 +418,7 @@ impl<'a, T: 'static> LowerContext<'a, T> {
418418
/// * It is assumed that this is only invoked at the root lower/store calls
419419
/// * Panics if invoked while replay is not enabled
420420
///
421-
#[cfg(rr_component)]
421+
#[cfg(feature = "rr")]
422422
pub fn replay_lowering(
423423
&mut self,
424424
mut result_storage: Option<&mut [MaybeUninit<ValRaw>]>,

crates/wasmtime/src/runtime/component/instance.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use crate::component::{
88
use crate::instance::OwnedImports;
99
use crate::linker::DefinitionType;
1010
use crate::prelude::*;
11-
#[cfg(rr_component)]
12-
use crate::rr::RecordBuffer;
11+
#[cfg(feature = "rr")]
12+
use crate::rr::{RecordBuffer, component_events::InstantiationEvent};
1313
use crate::runtime::vm::component::{
1414
CallContexts, ComponentInstance, ResourceTables, TypedResource, TypedResourceIndex,
1515
};
@@ -530,7 +530,7 @@ impl Instance {
530530
}
531531
}
532532

533-
#[cfg(rr_component)]
533+
#[cfg(feature = "rr")]
534534
pub(crate) fn options_memory_mut_with_recorder<'a>(
535535
&self,
536536
store: &'a mut StoreOpaque,
@@ -1080,7 +1080,7 @@ impl<'a> Instantiator<'a> {
10801080

10811081
/// Convenience helper to return the instance ID of the `ComponentInstance` that's
10821082
/// being instantiated
1083-
#[cfg(rr_component)]
1083+
#[cfg(feature = "rr")]
10841084
fn id(&self) -> ComponentInstanceId {
10851085
self.id
10861086
}
@@ -1193,14 +1193,13 @@ impl<T: 'static> InstancePre<T> {
11931193
.allocator()
11941194
.increment_component_instance_count()?;
11951195
let mut instantiator = Instantiator::new(&self.component, store.0, &self.imports);
1196-
#[cfg(rr_component)]
1197-
{
1198-
use crate::rr::component_events::InstantiationEvent;
1199-
store.0.record_event(|| InstantiationEvent {
1200-
component: *self.component.checksum(),
1201-
instance: instantiator.id(),
1202-
})?;
1203-
}
1196+
1197+
#[cfg(feature = "rr")]
1198+
store.0.record_event(|| InstantiationEvent {
1199+
component: *self.component.checksum(),
1200+
instance: instantiator.id(),
1201+
})?;
1202+
12041203
instantiator.run(&mut store).await.map_err(|e| {
12051204
store
12061205
.engine()

crates/wasmtime/src/runtime/rr/core.rs

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@ use crate::config::ModuleVersionStrategy;
22
use crate::prelude::*;
33
use core::fmt;
44
use events::EventError;
5+
pub use events::{
6+
RRFuncArgVals, ResultEvent, Validate, common_events, component_events, core_events,
7+
marker_events,
8+
};
9+
pub use io::{IOError, RecordWriter, ReplayReader};
510
use serde::{Deserialize, Serialize};
611
use wasmtime_environ::{EntityIndex, WasmChecksum};
7-
// Use component events internally even without feature flags enabled
8-
// so that [`RREvent`] has a well-defined serialization format, but export
9-
// it for other modules only when enabled
10-
pub use events::Validate;
11-
#[cfg(rr_component)]
12-
pub use events::component_events;
13-
use events::component_events as __component_events;
14-
pub use events::{RRFuncArgVals, ResultEvent, common_events, core_events, marker_events};
15-
pub use io::{IOError, RecordWriter, ReplayReader};
1612

1713
/// Settings for execution recording.
1814
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -141,23 +137,23 @@ rr_event! {
141137
///
142138
/// This is distinguished from `ComponentWasmFuncEntry` as there may
143139
/// be multiple lowering steps before actually entering the Wasm function
144-
ComponentWasmFuncBegin(__component_events::WasmFuncBeginEvent),
140+
ComponentWasmFuncBegin(component_events::WasmFuncBeginEvent),
145141
/// Entry from the host into the Wasm component function
146-
ComponentWasmFuncEntry(__component_events::WasmFuncEntryEvent),
142+
ComponentWasmFuncEntry(component_events::WasmFuncEntryEvent),
147143
/// Instantiation of a component
148-
ComponentInstantiation(__component_events::InstantiationEvent),
144+
ComponentInstantiation(component_events::InstantiationEvent),
149145
/// Component ABI realloc call in linear wasm memory
150-
ComponentReallocEntry(__component_events::ReallocEntryEvent),
146+
ComponentReallocEntry(component_events::ReallocEntryEvent),
151147
/// Return from a type lowering operation
152-
ComponentLowerFlatReturn(__component_events::LowerFlatReturnEvent),
148+
ComponentLowerFlatReturn(component_events::LowerFlatReturnEvent),
153149
/// Return from a store during a type lowering operation
154-
ComponentLowerMemoryReturn(__component_events::LowerMemoryReturnEvent),
150+
ComponentLowerMemoryReturn(component_events::LowerMemoryReturnEvent),
155151
/// An attempt to obtain a mutable slice into Wasm linear memory
156-
ComponentMemorySliceWrite(__component_events::MemorySliceWriteEvent),
152+
ComponentMemorySliceWrite(component_events::MemorySliceWriteEvent),
157153
/// Return from a component builtin
158-
ComponentBuiltinReturn(__component_events::BuiltinReturnEvent),
154+
ComponentBuiltinReturn(component_events::BuiltinReturnEvent),
159155
/// Call to `post_return` (after the function call)
160-
ComponentPostReturn(__component_events::PostReturnEvent),
156+
ComponentPostReturn(component_events::PostReturnEvent),
161157

162158
// OPTIONAL events for replay validation (Component)
163159

@@ -166,13 +162,13 @@ rr_event! {
166162
/// Since realloc is deterministic, ReallocReturn is optional.
167163
/// Any error is subsumed by the containing LowerReturn/LowerStoreReturn
168164
/// that triggered realloc
169-
ComponentReallocReturn(__component_events::ReallocReturnEvent),
165+
ComponentReallocReturn(component_events::ReallocReturnEvent),
170166
/// Call into type lowering for flat destination
171-
ComponentLowerFlatEntry(__component_events::LowerFlatEntryEvent),
167+
ComponentLowerFlatEntry(component_events::LowerFlatEntryEvent),
172168
/// Call into type lowering for memory destination
173-
ComponentLowerMemoryEntry(__component_events::LowerMemoryEntryEvent),
169+
ComponentLowerMemoryEntry(component_events::LowerMemoryEntryEvent),
174170
/// Call into a component builtin
175-
ComponentBuiltinEntry(__component_events::BuiltinEntryEvent)
171+
ComponentBuiltinEntry(component_events::BuiltinEntryEvent)
176172
}
177173

178174
impl RREvent {
@@ -708,7 +704,7 @@ mod tests {
708704
origin: origin.clone(),
709705
args: RRFuncArgVals::from_flat_iter(&values, flat_sizes.iter().copied()),
710706
})?;
711-
recorder.record_event(|| __component_events::WasmFuncEntryEvent {
707+
recorder.record_event(|| component_events::WasmFuncEntryEvent {
712708
args: RRFuncArgVals::from_flat_iter(
713709
&return_values,
714710
return_flat_sizes.iter().copied(),
@@ -724,7 +720,7 @@ mod tests {
724720
assert!(origin == replay_origin.unwrap());
725721
verify_equal_slices(&values, &replay_values, &flat_sizes)?;
726722

727-
replayer.next_event_and(|event: __component_events::WasmFuncEntryEvent| {
723+
replayer.next_event_and(|event: component_events::WasmFuncEntryEvent| {
728724
event.args.into_raw_slice(&mut return_replay_values);
729725
Ok(())
730726
})?;
@@ -735,7 +731,7 @@ mod tests {
735731

736732
#[test]
737733
fn builtin_event_entry() -> Result<()> {
738-
use __component_events::{
734+
use component_events::{
739735
BuiltinEntryEvent, ResourceDropEntryEvent, ResourceEnterCallEntryEvent,
740736
ResourceExitCallEntryEvent, ResourceTransferBorrowEntryEvent,
741737
ResourceTransferOwnEntryEvent,
@@ -781,7 +777,7 @@ mod tests {
781777

782778
#[test]
783779
fn builtin_event_return() -> Result<()> {
784-
use __component_events::{
780+
use component_events::{
785781
BuiltinError, BuiltinReturnEvent, ResourceDropReturnEvent, ResourceExitCallReturnEvent,
786782
ResourceRep32ReturnEvent, ResourceTransferBorrowReturnEvent,
787783
ResourceTransferOwnReturnEvent,
@@ -870,7 +866,7 @@ mod tests {
870866

871867
#[test]
872868
fn lower_flat_events() -> Result<()> {
873-
use __component_events::{LowerFlatEntryEvent, LowerFlatReturnEvent};
869+
use component_events::{LowerFlatEntryEvent, LowerFlatReturnEvent};
874870
use wasmtime_environ::component::InterfaceType;
875871

876872
let entry = LowerFlatEntryEvent {
@@ -900,7 +896,7 @@ mod tests {
900896

901897
#[test]
902898
fn lower_memory_events() -> Result<()> {
903-
use __component_events::{LowerMemoryEntryEvent, LowerMemoryReturnEvent};
899+
use component_events::{LowerMemoryEntryEvent, LowerMemoryReturnEvent};
904900
use wasmtime_environ::component::InterfaceType;
905901

906902
let entry = LowerMemoryEntryEvent {
@@ -932,7 +928,7 @@ mod tests {
932928

933929
#[test]
934930
fn realloc_events() -> Result<()> {
935-
use __component_events::{ReallocEntryEvent, ReallocReturnEvent};
931+
use component_events::{ReallocEntryEvent, ReallocReturnEvent};
936932

937933
let entry = ReallocEntryEvent {
938934
old_addr: 0x1000,
@@ -967,7 +963,7 @@ mod tests {
967963

968964
#[test]
969965
fn memory_slice_write_event() -> Result<()> {
970-
use __component_events::MemorySliceWriteEvent;
966+
use component_events::MemorySliceWriteEvent;
971967

972968
let event = MemorySliceWriteEvent {
973969
offset: 512,
@@ -994,7 +990,7 @@ mod tests {
994990
fn instantiation_event() -> Result<()> {
995991
use crate::component::ComponentInstanceId;
996992
use crate::store::InstanceId;
997-
use __component_events::InstantiationEvent as ComponentInstantiationEvent;
993+
use component_events::InstantiationEvent as ComponentInstantiationEvent;
998994
use core_events::InstantiationEvent as CoreInstantiationEvent;
999995
use wasmtime_environ::WasmChecksum;
1000996

crates/wasmtime/src/runtime/rr/core/events.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::{AsContextMut, Val, prelude::*};
44
use crate::{ValRaw, ValType};
55
use core::fmt;
66
use serde::{Deserialize, Serialize};
7-
#[cfg(rr_component)]
87
use wasmtime_environ::component::FlatTypesStorage;
98

109
/// A serde compatible representation of errors produced during execution
@@ -76,7 +75,6 @@ impl RRFuncArgVals {
7675
}
7776

7877
/// Construct [`RRFuncArgVals`] from raw value buffer and a [`FlatTypesStorage`]
79-
#[cfg(rr_component)]
8078
#[inline]
8179
pub fn from_flat_storage<T>(args: &[T], flat: FlatTypesStorage) -> RRFuncArgVals
8280
where

0 commit comments

Comments
 (0)