1 use crate::component::func::{LiftContext, LowerContext};
2 use crate::component::matching::InstanceType;
3 use crate::component::{ComponentType, Lift, Lower, RuntimeInstance, Val};
4 use crate::store::StoreOpaque;
5 use crate::vm::component::CallContext;
6 use crate::{Result, bail, error::format_err};
7 use core::convert::Infallible;
8 use core::mem::MaybeUninit;
9 use wasmtime_environ::component::{CanonicalAbiInfo, InterfaceType};
10
11 pub enum ConcurrentState {}
12
13 impl ConcurrentState {
call_context(&mut self, _: u32) -> Result<&mut CallContext>14 pub fn call_context(&mut self, _: u32) -> Result<&mut CallContext> {
15 match *self {}
16 }
17
current_call_context_scope_id(&self) -> Result<u32>18 pub fn current_call_context_scope_id(&self) -> Result<u32> {
19 match *self {}
20 }
21 }
22
should_have_failed_validation<T>(what: &str) -> Result<T>23 fn should_have_failed_validation<T>(what: &str) -> Result<T> {
24 // This should be unreachable; if we trap here, it indicates a
25 // bug in Wasmtime rather than in the guest.
26 Err(format_err!(
27 "{what} should have failed validation \
28 when `component-model-async` feature disabled"
29 ))
30 }
31
lower_error_context_to_index<U>( _rep: u32, _cx: &mut LowerContext<'_, U>, _ty: InterfaceType, ) -> Result<u32>32 pub(crate) fn lower_error_context_to_index<U>(
33 _rep: u32,
34 _cx: &mut LowerContext<'_, U>,
35 _ty: InterfaceType,
36 ) -> Result<u32> {
37 should_have_failed_validation("use of `error-context`")
38 }
39
40 pub struct ErrorContext(Infallible);
41
42 impl ErrorContext {
into_val(self) -> Val43 pub(crate) fn into_val(self) -> Val {
44 match self.0 {}
45 }
46
linear_lift_from_flat( _cx: &mut LiftContext<'_>, _ty: InterfaceType, _src: &<u32 as ComponentType>::Lower, ) -> Result<Self>47 pub(crate) fn linear_lift_from_flat(
48 _cx: &mut LiftContext<'_>,
49 _ty: InterfaceType,
50 _src: &<u32 as ComponentType>::Lower,
51 ) -> Result<Self> {
52 should_have_failed_validation("use of `error-context`")
53 }
54
linear_lift_from_memory( _cx: &mut LiftContext<'_>, _ty: InterfaceType, _bytes: &[u8], ) -> Result<Self>55 pub(crate) fn linear_lift_from_memory(
56 _cx: &mut LiftContext<'_>,
57 _ty: InterfaceType,
58 _bytes: &[u8],
59 ) -> Result<Self> {
60 should_have_failed_validation("use of `error-context`")
61 }
62 }
63
64 #[derive(PartialEq, Clone, Debug)]
65 pub struct FutureAny(Infallible);
66
67 unsafe impl ComponentType for FutureAny {
68 type Lower = <u32 as ComponentType>::Lower;
69 const ABI: CanonicalAbiInfo = CanonicalAbiInfo::SCALAR4;
70
typecheck(_ty: &InterfaceType, _types: &InstanceType<'_>) -> Result<()>71 fn typecheck(_ty: &InterfaceType, _types: &InstanceType<'_>) -> Result<()> {
72 bail!("support for component-model-async disabled at compile time")
73 }
74 }
75
76 unsafe impl Lift for FutureAny {
linear_lift_from_flat( _cx: &mut LiftContext<'_>, _ty: InterfaceType, _src: &Self::Lower, ) -> Result<Self>77 fn linear_lift_from_flat(
78 _cx: &mut LiftContext<'_>,
79 _ty: InterfaceType,
80 _src: &Self::Lower,
81 ) -> Result<Self> {
82 bail!("support for component-model-async disabled at compile time")
83 }
84
linear_lift_from_memory( _cx: &mut LiftContext<'_>, _ty: InterfaceType, _bytes: &[u8], ) -> Result<Self>85 fn linear_lift_from_memory(
86 _cx: &mut LiftContext<'_>,
87 _ty: InterfaceType,
88 _bytes: &[u8],
89 ) -> Result<Self> {
90 bail!("support for component-model-async disabled at compile time")
91 }
92 }
93
94 unsafe impl Lower for FutureAny {
linear_lower_to_flat<T>( &self, _cx: &mut LowerContext<'_, T>, _ty: InterfaceType, _dst: &mut MaybeUninit<Self::Lower>, ) -> Result<()>95 fn linear_lower_to_flat<T>(
96 &self,
97 _cx: &mut LowerContext<'_, T>,
98 _ty: InterfaceType,
99 _dst: &mut MaybeUninit<Self::Lower>,
100 ) -> Result<()> {
101 match self.0 {}
102 }
103
linear_lower_to_memory<T>( &self, _cx: &mut LowerContext<'_, T>, _ty: InterfaceType, _offset: usize, ) -> Result<()>104 fn linear_lower_to_memory<T>(
105 &self,
106 _cx: &mut LowerContext<'_, T>,
107 _ty: InterfaceType,
108 _offset: usize,
109 ) -> Result<()> {
110 match self.0 {}
111 }
112 }
113
114 #[derive(PartialEq, Clone, Debug)]
115 pub struct StreamAny(Infallible);
116
117 unsafe impl ComponentType for StreamAny {
118 type Lower = <u32 as ComponentType>::Lower;
119 const ABI: CanonicalAbiInfo = CanonicalAbiInfo::SCALAR4;
120
typecheck(_ty: &InterfaceType, _types: &InstanceType<'_>) -> Result<()>121 fn typecheck(_ty: &InterfaceType, _types: &InstanceType<'_>) -> Result<()> {
122 bail!("support for component-model-async disabled at compile time")
123 }
124 }
125
126 unsafe impl Lift for StreamAny {
linear_lift_from_flat( _cx: &mut LiftContext<'_>, _ty: InterfaceType, _src: &Self::Lower, ) -> Result<Self>127 fn linear_lift_from_flat(
128 _cx: &mut LiftContext<'_>,
129 _ty: InterfaceType,
130 _src: &Self::Lower,
131 ) -> Result<Self> {
132 bail!("support for component-model-async disabled at compile time")
133 }
134
linear_lift_from_memory( _cx: &mut LiftContext<'_>, _ty: InterfaceType, _bytes: &[u8], ) -> Result<Self>135 fn linear_lift_from_memory(
136 _cx: &mut LiftContext<'_>,
137 _ty: InterfaceType,
138 _bytes: &[u8],
139 ) -> Result<Self> {
140 bail!("support for component-model-async disabled at compile time")
141 }
142 }
143
144 unsafe impl Lower for StreamAny {
linear_lower_to_flat<T>( &self, _cx: &mut LowerContext<'_, T>, _ty: InterfaceType, _dst: &mut MaybeUninit<Self::Lower>, ) -> Result<()>145 fn linear_lower_to_flat<T>(
146 &self,
147 _cx: &mut LowerContext<'_, T>,
148 _ty: InterfaceType,
149 _dst: &mut MaybeUninit<Self::Lower>,
150 ) -> Result<()> {
151 match self.0 {}
152 }
153
linear_lower_to_memory<T>( &self, _cx: &mut LowerContext<'_, T>, _ty: InterfaceType, _offset: usize, ) -> Result<()>154 fn linear_lower_to_memory<T>(
155 &self,
156 _cx: &mut LowerContext<'_, T>,
157 _ty: InterfaceType,
158 _offset: usize,
159 ) -> Result<()> {
160 match self.0 {}
161 }
162 }
163
164 impl StoreOpaque {
enter_guest_sync_call( &mut self, _guest_caller: Option<RuntimeInstance>, _callee_async: bool, _callee: RuntimeInstance, ) -> Result<()>165 pub(crate) fn enter_guest_sync_call(
166 &mut self,
167 _guest_caller: Option<RuntimeInstance>,
168 _callee_async: bool,
169 _callee: RuntimeInstance,
170 ) -> Result<()> {
171 Ok(self.enter_call_not_concurrent())
172 }
173
exit_guest_sync_call(&mut self) -> Result<()>174 pub(crate) fn exit_guest_sync_call(&mut self) -> Result<()> {
175 Ok(self.exit_call_not_concurrent())
176 }
177
host_task_create(&mut self) -> Result<()>178 pub(crate) fn host_task_create(&mut self) -> Result<()> {
179 Ok(self.enter_call_not_concurrent())
180 }
181
host_task_reenter_caller(&mut self) -> Result<()>182 pub(crate) fn host_task_reenter_caller(&mut self) -> Result<()> {
183 Ok(())
184 }
185
host_task_delete(&mut self, (): ()) -> Result<()>186 pub(crate) fn host_task_delete(&mut self, (): ()) -> Result<()> {
187 Ok(self.exit_call_not_concurrent())
188 }
189
check_blocking(&mut self) -> crate::Result<()>190 pub(crate) fn check_blocking(&mut self) -> crate::Result<()> {
191 Ok(())
192 }
193
may_enter(&mut self, _instance: RuntimeInstance) -> Result<bool>194 pub(crate) fn may_enter(&mut self, _instance: RuntimeInstance) -> Result<bool> {
195 Ok(!self.trapped())
196 }
197 }
198