1 use crate::component::func::{LiftContext, LowerContext};
2 use crate::component::matching::InstanceType;
3 use crate::component::{ComponentType, Lift, Lower, Val};
4 use crate::runtime::vm::VMStore;
5 use anyhow::{Result, anyhow, bail};
6 use core::convert::Infallible;
7 use core::mem::MaybeUninit;
8 use wasmtime_environ::component::{CanonicalAbiInfo, InterfaceType};
9 
10 #[derive(Default)]
11 pub struct ConcurrentState;
12 
13 fn should_have_failed_validation<T>(what: &str) -> Result<T> {
14     // This should be unreachable; if we trap here, it indicates a
15     // bug in Wasmtime rather than in the guest.
16     Err(anyhow!(
17         "{what} should have failed validation \
18          when `component-model-async` feature disabled"
19     ))
20 }
21 
22 pub(crate) fn check_blocking(_: &mut dyn VMStore) -> Result<()> {
23     Ok(())
24 }
25 
26 pub(crate) fn lower_error_context_to_index<U>(
27     _rep: u32,
28     _cx: &mut LowerContext<'_, U>,
29     _ty: InterfaceType,
30 ) -> Result<u32> {
31     should_have_failed_validation("use of `error-context`")
32 }
33 
34 pub struct ErrorContext(Infallible);
35 
36 impl ErrorContext {
37     pub(crate) fn into_val(self) -> Val {
38         match self.0 {}
39     }
40 
41     pub(crate) fn linear_lift_from_flat(
42         _cx: &mut LiftContext<'_>,
43         _ty: InterfaceType,
44         _src: &<u32 as ComponentType>::Lower,
45     ) -> Result<Self> {
46         should_have_failed_validation("use of `error-context`")
47     }
48 
49     pub(crate) fn linear_lift_from_memory(
50         _cx: &mut LiftContext<'_>,
51         _ty: InterfaceType,
52         _bytes: &[u8],
53     ) -> Result<Self> {
54         should_have_failed_validation("use of `error-context`")
55     }
56 }
57 
58 #[derive(PartialEq, Clone, Debug)]
59 pub struct FutureAny(Infallible);
60 
61 unsafe impl ComponentType for FutureAny {
62     type Lower = <u32 as ComponentType>::Lower;
63     const ABI: CanonicalAbiInfo = CanonicalAbiInfo::SCALAR4;
64 
65     fn typecheck(_ty: &InterfaceType, _types: &InstanceType<'_>) -> Result<()> {
66         bail!("support for component-model-async disabled at compile time")
67     }
68 }
69 
70 unsafe impl Lift for FutureAny {
71     fn linear_lift_from_flat(
72         _cx: &mut LiftContext<'_>,
73         _ty: InterfaceType,
74         _src: &Self::Lower,
75     ) -> Result<Self> {
76         bail!("support for component-model-async disabled at compile time")
77     }
78 
79     fn linear_lift_from_memory(
80         _cx: &mut LiftContext<'_>,
81         _ty: InterfaceType,
82         _bytes: &[u8],
83     ) -> Result<Self> {
84         bail!("support for component-model-async disabled at compile time")
85     }
86 }
87 
88 unsafe impl Lower for FutureAny {
89     fn linear_lower_to_flat<T>(
90         &self,
91         _cx: &mut LowerContext<'_, T>,
92         _ty: InterfaceType,
93         _dst: &mut MaybeUninit<Self::Lower>,
94     ) -> Result<()> {
95         match self.0 {}
96     }
97 
98     fn linear_lower_to_memory<T>(
99         &self,
100         _cx: &mut LowerContext<'_, T>,
101         _ty: InterfaceType,
102         _offset: usize,
103     ) -> Result<()> {
104         match self.0 {}
105     }
106 }
107 
108 #[derive(PartialEq, Clone, Debug)]
109 pub struct StreamAny(Infallible);
110 
111 unsafe impl ComponentType for StreamAny {
112     type Lower = <u32 as ComponentType>::Lower;
113     const ABI: CanonicalAbiInfo = CanonicalAbiInfo::SCALAR4;
114 
115     fn typecheck(_ty: &InterfaceType, _types: &InstanceType<'_>) -> Result<()> {
116         bail!("support for component-model-async disabled at compile time")
117     }
118 }
119 
120 unsafe impl Lift for StreamAny {
121     fn linear_lift_from_flat(
122         _cx: &mut LiftContext<'_>,
123         _ty: InterfaceType,
124         _src: &Self::Lower,
125     ) -> Result<Self> {
126         bail!("support for component-model-async disabled at compile time")
127     }
128 
129     fn linear_lift_from_memory(
130         _cx: &mut LiftContext<'_>,
131         _ty: InterfaceType,
132         _bytes: &[u8],
133     ) -> Result<Self> {
134         bail!("support for component-model-async disabled at compile time")
135     }
136 }
137 
138 unsafe impl Lower for StreamAny {
139     fn linear_lower_to_flat<T>(
140         &self,
141         _cx: &mut LowerContext<'_, T>,
142         _ty: InterfaceType,
143         _dst: &mut MaybeUninit<Self::Lower>,
144     ) -> Result<()> {
145         match self.0 {}
146     }
147 
148     fn linear_lower_to_memory<T>(
149         &self,
150         _cx: &mut LowerContext<'_, T>,
151         _ty: InterfaceType,
152         _offset: usize,
153     ) -> Result<()> {
154         match self.0 {}
155     }
156 }
157