Skip to content

Commit 4862d06

Browse files
committed
Fix tests
1 parent f87e1b4 commit 4862d06

File tree

4 files changed

+130
-71
lines changed

4 files changed

+130
-71
lines changed

crates/misc/component-async-tests/tests/scenario/transmit.rs

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ pub trait TransmitTest {
552552
) -> impl Future<Output = Result<Self::Result>> + Send + 'a;
553553

554554
fn into_params(
555+
store: impl AsContextMut<Data = Ctx>,
555556
control: StreamReader<Control>,
556557
caller_stream: StreamReader<String>,
557558
caller_future1: FutureReader<String>,
@@ -603,6 +604,7 @@ impl TransmitTest for StaticTransmitTest {
603604
}
604605

605606
fn into_params(
607+
_store: impl AsContextMut<Data = Ctx>,
606608
control: StreamReader<Control>,
607609
caller_stream: StreamReader<String>,
608610
caller_future1: FutureReader<String>,
@@ -663,21 +665,31 @@ impl TransmitTest for DynamicTransmitTest {
663665
}
664666

665667
fn into_params(
668+
mut store: impl AsContextMut<Data = Ctx>,
666669
control: StreamReader<Control>,
667670
caller_stream: StreamReader<String>,
668671
caller_future1: FutureReader<String>,
669672
caller_future2: FutureReader<String>,
670673
) -> Self::Params {
671674
vec![
672-
control.into_val(),
673-
caller_stream.into_val(),
674-
caller_future1.into_val(),
675-
caller_future2.into_val(),
675+
control.try_into_stream_any(&mut store).unwrap().into(),
676+
caller_stream
677+
.try_into_stream_any(&mut store)
678+
.unwrap()
679+
.into(),
680+
caller_future1
681+
.try_into_future_any(&mut store)
682+
.unwrap()
683+
.into(),
684+
caller_future2
685+
.try_into_future_any(&mut store)
686+
.unwrap()
687+
.into(),
676688
]
677689
}
678690

679691
fn from_result(
680-
mut store: impl AsContextMut<Data = Ctx>,
692+
_store: impl AsContextMut<Data = Ctx>,
681693
result: Self::Result,
682694
) -> Result<(
683695
StreamReader<String>,
@@ -687,9 +699,19 @@ impl TransmitTest for DynamicTransmitTest {
687699
let Val::Tuple(fields) = result else {
688700
unreachable!()
689701
};
690-
let stream = StreamReader::from_val(store.as_context_mut(), &fields[0])?;
691-
let future1 = FutureReader::from_val(store.as_context_mut(), &fields[1])?;
692-
let future2 = FutureReader::from_val(store.as_context_mut(), &fields[2])?;
702+
let mut fields = fields.into_iter();
703+
let Val::Stream(stream) = fields.next().unwrap() else {
704+
unreachable!()
705+
};
706+
let Val::Future(future1) = fields.next().unwrap() else {
707+
unreachable!()
708+
};
709+
let Val::Future(future2) = fields.next().unwrap() else {
710+
unreachable!()
711+
};
712+
let stream = StreamReader::try_from_stream_any(stream).unwrap();
713+
let future1 = FutureReader::try_from_future_any(future1).unwrap();
714+
let future2 = FutureReader::try_from_future_any(future2).unwrap();
693715
Ok((stream, future1, future2))
694716
}
695717
}
@@ -770,19 +792,20 @@ async fn test_transmit_with<Test: TransmitTest + 'static>(component: &str) -> Re
770792
.boxed(),
771793
);
772794

773-
futures.push(
774-
Test::call(
775-
accessor,
776-
&test,
777-
Test::into_params(
778-
control_rx,
779-
caller_stream_rx,
780-
caller_future1_rx,
781-
caller_future2_rx,
782-
),
795+
let params = accessor.with(|s| {
796+
Test::into_params(
797+
s,
798+
control_rx,
799+
caller_stream_rx,
800+
caller_future1_rx,
801+
caller_future2_rx,
783802
)
784-
.map(|v| v.map(Event::Result))
785-
.boxed(),
803+
});
804+
805+
futures.push(
806+
Test::call(accessor, &test, params)
807+
.map(|v| v.map(Event::Result))
808+
.boxed(),
786809
);
787810

788811
while let Some(event) = futures.try_next().await? {
Lines changed: 75 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
use crate::component::Val;
2-
use crate::component::func::{ComponentType, LiftContext, LowerContext};
1+
use crate::component::func::{LiftContext, LowerContext};
2+
use crate::component::matching::InstanceType;
3+
use crate::component::{ComponentType, Lift, Lower, Val};
34
use crate::runtime::vm::VMStore;
4-
use anyhow::{Result, anyhow};
5+
use anyhow::{Result, anyhow, bail};
56
use core::convert::Infallible;
67
use core::future::Future;
7-
use core::marker::PhantomData;
8+
use core::mem::MaybeUninit;
89
use core::pin::pin;
910
use core::task::{Context, Poll, Waker};
10-
use wasmtime_environ::component::{InterfaceType, RuntimeComponentInstanceIndex};
11+
use wasmtime_environ::component::{CanonicalAbiInfo, InterfaceType, RuntimeComponentInstanceIndex};
1112

1213
#[derive(Default)]
1314
pub struct ConcurrentState;
@@ -32,22 +33,6 @@ pub(crate) fn poll_and_block<R: Send + Sync + 'static>(
3233
}
3334
}
3435

35-
pub(crate) fn lower_future_to_index<U>(
36-
_rep: u32,
37-
_cx: &mut LowerContext<'_, U>,
38-
_ty: InterfaceType,
39-
) -> Result<u32> {
40-
should_have_failed_validation("use of `future`")
41-
}
42-
43-
pub(crate) fn lower_stream_to_index<U>(
44-
_rep: u32,
45-
_cx: &mut LowerContext<'_, U>,
46-
_ty: InterfaceType,
47-
) -> Result<u32> {
48-
should_have_failed_validation("use of `stream`")
49-
}
50-
5136
pub(crate) fn lower_error_context_to_index<U>(
5237
_rep: u32,
5338
_cx: &mut LowerContext<'_, U>,
@@ -80,56 +65,102 @@ impl ErrorContext {
8065
}
8166
}
8267

83-
pub struct StreamReader<P> {
84-
uninhabited: Infallible,
85-
_phantom: PhantomData<P>,
86-
}
68+
#[derive(PartialEq, Clone, Debug)]
69+
pub struct FutureAny(Infallible);
8770

88-
impl<P> StreamReader<P> {
89-
pub(crate) fn into_val(self) -> Val {
90-
match self.uninhabited {}
71+
unsafe impl ComponentType for FutureAny {
72+
type Lower = <u32 as ComponentType>::Lower;
73+
const ABI: CanonicalAbiInfo = CanonicalAbiInfo::SCALAR4;
74+
75+
fn typecheck(_ty: &InterfaceType, _types: &InstanceType<'_>) -> Result<()> {
76+
bail!("support for component-model-async disabled at compile time")
9177
}
78+
}
9279

93-
pub(crate) fn linear_lift_from_flat(
80+
unsafe impl Lift for FutureAny {
81+
fn linear_lift_from_flat(
9482
_cx: &mut LiftContext<'_>,
9583
_ty: InterfaceType,
96-
_src: &<u32 as ComponentType>::Lower,
84+
_src: &Self::Lower,
9785
) -> Result<Self> {
98-
should_have_failed_validation("use of `stream`")
86+
bail!("support for component-model-async disabled at compile time")
9987
}
10088

101-
pub(crate) fn linear_lift_from_memory(
89+
fn linear_lift_from_memory(
10290
_cx: &mut LiftContext<'_>,
10391
_ty: InterfaceType,
10492
_bytes: &[u8],
10593
) -> Result<Self> {
106-
should_have_failed_validation("use of `stream`")
94+
bail!("support for component-model-async disabled at compile time")
10795
}
10896
}
10997

110-
pub struct FutureReader<P> {
111-
uninhabited: Infallible,
112-
_phantom: PhantomData<P>,
98+
unsafe impl Lower for FutureAny {
99+
fn linear_lower_to_flat<T>(
100+
&self,
101+
_cx: &mut LowerContext<'_, T>,
102+
_ty: InterfaceType,
103+
_dst: &mut MaybeUninit<Self::Lower>,
104+
) -> Result<()> {
105+
match self.0 {}
106+
}
107+
108+
fn linear_lower_to_memory<T>(
109+
&self,
110+
_cx: &mut LowerContext<'_, T>,
111+
_ty: InterfaceType,
112+
_offset: usize,
113+
) -> Result<()> {
114+
match self.0 {}
115+
}
113116
}
114117

115-
impl<P> FutureReader<P> {
116-
pub(crate) fn into_val(self) -> Val {
117-
match self.uninhabited {}
118+
#[derive(PartialEq, Clone, Debug)]
119+
pub struct StreamAny(Infallible);
120+
121+
unsafe impl ComponentType for StreamAny {
122+
type Lower = <u32 as ComponentType>::Lower;
123+
const ABI: CanonicalAbiInfo = CanonicalAbiInfo::SCALAR4;
124+
125+
fn typecheck(_ty: &InterfaceType, _types: &InstanceType<'_>) -> Result<()> {
126+
bail!("support for component-model-async disabled at compile time")
118127
}
128+
}
119129

120-
pub(crate) fn linear_lift_from_flat(
130+
unsafe impl Lift for StreamAny {
131+
fn linear_lift_from_flat(
121132
_cx: &mut LiftContext<'_>,
122133
_ty: InterfaceType,
123-
_src: &<u32 as ComponentType>::Lower,
134+
_src: &Self::Lower,
124135
) -> Result<Self> {
125-
should_have_failed_validation("use of `future`")
136+
bail!("support for component-model-async disabled at compile time")
126137
}
127138

128-
pub(crate) fn linear_lift_from_memory(
139+
fn linear_lift_from_memory(
129140
_cx: &mut LiftContext<'_>,
130141
_ty: InterfaceType,
131142
_bytes: &[u8],
132143
) -> Result<Self> {
133-
should_have_failed_validation("use of `future`")
144+
bail!("support for component-model-async disabled at compile time")
145+
}
146+
}
147+
148+
unsafe impl Lower for StreamAny {
149+
fn linear_lower_to_flat<T>(
150+
&self,
151+
_cx: &mut LowerContext<'_, T>,
152+
_ty: InterfaceType,
153+
_dst: &mut MaybeUninit<Self::Lower>,
154+
) -> Result<()> {
155+
match self.0 {}
156+
}
157+
158+
fn linear_lower_to_memory<T>(
159+
&self,
160+
_cx: &mut LowerContext<'_, T>,
161+
_ty: InterfaceType,
162+
_offset: usize,
163+
) -> Result<()> {
164+
match self.0 {}
134165
}
135166
}

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! This module defines the `Type` type, representing the dynamic form of a component interface type.
22
3+
#[cfg(feature = "component-model-async")]
34
use crate::component::ComponentType;
45
use crate::component::matching::InstanceType;
56
use crate::{Engine, ExternType, FuncType};
67
use alloc::sync::Arc;
7-
use anyhow::{Result, bail};
88
use core::fmt;
99
use core::ops::Deref;
1010
use wasmtime_environ::PrimaryMap;
@@ -531,10 +531,11 @@ impl PartialEq for Flags {
531531

532532
impl Eq for Flags {}
533533

534+
#[cfg(feature = "component-model-async")]
534535
pub(crate) fn typecheck_payload<T>(
535536
payload: Option<&InterfaceType>,
536537
types: &InstanceType<'_>,
537-
) -> Result<()>
538+
) -> anyhow::Result<()>
538539
where
539540
T: ComponentType,
540541
{
@@ -544,7 +545,7 @@ where
544545
if T::IS_RUST_UNIT_TYPE {
545546
Ok(())
546547
} else {
547-
bail!("future payload types differ")
548+
anyhow::bail!("future payload types differ")
548549
}
549550
}
550551
}
@@ -567,6 +568,7 @@ impl FutureType {
567568
))
568569
}
569570

571+
#[cfg(feature = "component-model-async")]
570572
pub(crate) fn equivalent_payload_guest(
571573
&self,
572574
ty: &InstanceType<'_>,
@@ -586,7 +588,8 @@ impl FutureType {
586588
}
587589
}
588590

589-
pub(crate) fn equivalent_payload_host<T>(&self) -> Result<()>
591+
#[cfg(feature = "component-model-async")]
592+
pub(crate) fn equivalent_payload_host<T>(&self) -> anyhow::Result<()>
590593
where
591594
T: ComponentType,
592595
{
@@ -622,6 +625,7 @@ impl StreamType {
622625
))
623626
}
624627

628+
#[cfg(feature = "component-model-async")]
625629
pub(crate) fn equivalent_payload_guest(
626630
&self,
627631
ty: &InstanceType<'_>,
@@ -641,7 +645,8 @@ impl StreamType {
641645
}
642646
}
643647

644-
pub(crate) fn equivalent_payload_host<T>(&self) -> Result<()>
648+
#[cfg(feature = "component-model-async")]
649+
pub(crate) fn equivalent_payload_host<T>(&self) -> anyhow::Result<()>
645650
where
646651
T: ComponentType,
647652
{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::ValRaw;
2-
use crate::component::concurrent::{self, ErrorContext};
2+
use crate::component::ResourceAny;
3+
use crate::component::concurrent::{self, ErrorContext, FutureAny, StreamAny};
34
use crate::component::func::{Lift, LiftContext, Lower, LowerContext, desc};
4-
use crate::component::{FutureAny, ResourceAny, StreamAny};
55
use crate::prelude::*;
66
use core::mem::MaybeUninit;
77
use core::slice::{Iter, IterMut};

0 commit comments

Comments
 (0)