wasmtime/runtime/component/
concurrent_disabled.rs

1use crate::Uninhabited;
2use crate::component::func::{ComponentType, LiftContext, LowerContext};
3use crate::component::{Instance, Val};
4use crate::runtime::vm::VMStore;
5use anyhow::{Result, anyhow};
6use core::future::Future;
7use core::marker::PhantomData;
8use core::pin::pin;
9use core::task::{Context, Poll, Waker};
10use wasmtime_environ::component::{InterfaceType, RuntimeComponentInstanceIndex};
11
12fn should_have_failed_validation<T>(what: &str) -> Result<T> {
13    // This should be unreachable; if we trap here, it indicates a
14    // bug in Wasmtime rather than in the guest.
15    Err(anyhow!(
16        "{what} should have failed validation \
17         when `component-model-async` feature disabled"
18    ))
19}
20
21impl Instance {
22    pub(crate) fn poll_and_block<R: Send + Sync + 'static>(
23        self,
24        _store: &mut dyn VMStore,
25        future: impl Future<Output = Result<R>> + Send + 'static,
26        _caller_instance: RuntimeComponentInstanceIndex,
27    ) -> Result<R> {
28        match pin!(future).poll(&mut Context::from_waker(Waker::noop())) {
29            Poll::Ready(result) => result,
30            Poll::Pending => should_have_failed_validation("async lowered import"),
31        }
32    }
33}
34
35pub(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
43pub(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
51pub(crate) fn lower_error_context_to_index<U>(
52    _rep: u32,
53    _cx: &mut LowerContext<'_, U>,
54    _ty: InterfaceType,
55) -> Result<u32> {
56    should_have_failed_validation("use of `error-context`")
57}
58
59pub struct ErrorContext(Uninhabited);
60
61impl ErrorContext {
62    pub(crate) fn into_val(self) -> Val {
63        match self.0 {}
64    }
65
66    pub(crate) fn linear_lift_from_flat(
67        _cx: &mut LiftContext<'_>,
68        _ty: InterfaceType,
69        _src: &<u32 as ComponentType>::Lower,
70    ) -> Result<Self> {
71        should_have_failed_validation("use of `error-context`")
72    }
73
74    pub(crate) fn linear_lift_from_memory(
75        _cx: &mut LiftContext<'_>,
76        _ty: InterfaceType,
77        _bytes: &[u8],
78    ) -> Result<Self> {
79        should_have_failed_validation("use of `error-context`")
80    }
81}
82
83pub struct StreamReader<P> {
84    uninhabited: Uninhabited,
85    _phantom: PhantomData<P>,
86}
87
88impl<P> StreamReader<P> {
89    pub(crate) fn into_val(self) -> Val {
90        match self.uninhabited {}
91    }
92
93    pub(crate) fn linear_lift_from_flat(
94        _cx: &mut LiftContext<'_>,
95        _ty: InterfaceType,
96        _src: &<u32 as ComponentType>::Lower,
97    ) -> Result<Self> {
98        should_have_failed_validation("use of `stream`")
99    }
100
101    pub(crate) fn linear_lift_from_memory(
102        _cx: &mut LiftContext<'_>,
103        _ty: InterfaceType,
104        _bytes: &[u8],
105    ) -> Result<Self> {
106        should_have_failed_validation("use of `stream`")
107    }
108}
109
110pub struct FutureReader<P> {
111    uninhabited: Uninhabited,
112    _phantom: PhantomData<P>,
113}
114
115impl<P> FutureReader<P> {
116    pub(crate) fn into_val(self) -> Val {
117        match self.uninhabited {}
118    }
119
120    pub(crate) fn linear_lift_from_flat(
121        _cx: &mut LiftContext<'_>,
122        _ty: InterfaceType,
123        _src: &<u32 as ComponentType>::Lower,
124    ) -> Result<Self> {
125        should_have_failed_validation("use of `future`")
126    }
127
128    pub(crate) fn linear_lift_from_memory(
129        _cx: &mut LiftContext<'_>,
130        _ty: InterfaceType,
131        _bytes: &[u8],
132    ) -> Result<Self> {
133        should_have_failed_validation("use of `future`")
134    }
135}