use crate::component::func::{LiftContext, LowerContext}; use crate::component::matching::InstanceType; use crate::component::{ComponentType, Lift, Lower, RuntimeInstance, Val}; use crate::store::StoreOpaque; use crate::vm::component::CallContext; use crate::{Result, bail, error::format_err}; use core::convert::Infallible; use core::mem::MaybeUninit; use wasmtime_environ::component::{CanonicalAbiInfo, InterfaceType}; pub enum ConcurrentState {} impl ConcurrentState { pub fn call_context(&mut self, _: u32) -> Result<&mut CallContext> { match *self {} } pub fn current_call_context_scope_id(&self) -> Result { match *self {} } } fn should_have_failed_validation(what: &str) -> Result { // This should be unreachable; if we trap here, it indicates a // bug in Wasmtime rather than in the guest. Err(format_err!( "{what} should have failed validation \ when `component-model-async` feature disabled" )) } pub(crate) fn lower_error_context_to_index( _rep: u32, _cx: &mut LowerContext<'_, U>, _ty: InterfaceType, ) -> Result { should_have_failed_validation("use of `error-context`") } pub struct ErrorContext(Infallible); impl ErrorContext { pub(crate) fn into_val(self) -> Val { match self.0 {} } pub(crate) fn linear_lift_from_flat( _cx: &mut LiftContext<'_>, _ty: InterfaceType, _src: &::Lower, ) -> Result { should_have_failed_validation("use of `error-context`") } pub(crate) fn linear_lift_from_memory( _cx: &mut LiftContext<'_>, _ty: InterfaceType, _bytes: &[u8], ) -> Result { should_have_failed_validation("use of `error-context`") } } #[derive(PartialEq, Clone, Debug)] pub struct FutureAny(Infallible); unsafe impl ComponentType for FutureAny { type Lower = ::Lower; const ABI: CanonicalAbiInfo = CanonicalAbiInfo::SCALAR4; fn typecheck(_ty: &InterfaceType, _types: &InstanceType<'_>) -> Result<()> { bail!("support for component-model-async disabled at compile time") } } unsafe impl Lift for FutureAny { fn linear_lift_from_flat( _cx: &mut LiftContext<'_>, _ty: InterfaceType, _src: &Self::Lower, ) -> Result { bail!("support for component-model-async disabled at compile time") } fn linear_lift_from_memory( _cx: &mut LiftContext<'_>, _ty: InterfaceType, _bytes: &[u8], ) -> Result { bail!("support for component-model-async disabled at compile time") } } unsafe impl Lower for FutureAny { fn linear_lower_to_flat( &self, _cx: &mut LowerContext<'_, T>, _ty: InterfaceType, _dst: &mut MaybeUninit, ) -> Result<()> { match self.0 {} } fn linear_lower_to_memory( &self, _cx: &mut LowerContext<'_, T>, _ty: InterfaceType, _offset: usize, ) -> Result<()> { match self.0 {} } } #[derive(PartialEq, Clone, Debug)] pub struct StreamAny(Infallible); unsafe impl ComponentType for StreamAny { type Lower = ::Lower; const ABI: CanonicalAbiInfo = CanonicalAbiInfo::SCALAR4; fn typecheck(_ty: &InterfaceType, _types: &InstanceType<'_>) -> Result<()> { bail!("support for component-model-async disabled at compile time") } } unsafe impl Lift for StreamAny { fn linear_lift_from_flat( _cx: &mut LiftContext<'_>, _ty: InterfaceType, _src: &Self::Lower, ) -> Result { bail!("support for component-model-async disabled at compile time") } fn linear_lift_from_memory( _cx: &mut LiftContext<'_>, _ty: InterfaceType, _bytes: &[u8], ) -> Result { bail!("support for component-model-async disabled at compile time") } } unsafe impl Lower for StreamAny { fn linear_lower_to_flat( &self, _cx: &mut LowerContext<'_, T>, _ty: InterfaceType, _dst: &mut MaybeUninit, ) -> Result<()> { match self.0 {} } fn linear_lower_to_memory( &self, _cx: &mut LowerContext<'_, T>, _ty: InterfaceType, _offset: usize, ) -> Result<()> { match self.0 {} } } impl StoreOpaque { pub(crate) fn enter_guest_sync_call( &mut self, _guest_caller: Option, _callee_async: bool, _callee: RuntimeInstance, ) -> Result<()> { Ok(self.enter_call_not_concurrent()) } pub(crate) fn exit_guest_sync_call(&mut self) -> Result<()> { Ok(self.exit_call_not_concurrent()) } pub(crate) fn host_task_create(&mut self) -> Result<()> { Ok(self.enter_call_not_concurrent()) } pub(crate) fn host_task_reenter_caller(&mut self) -> Result<()> { Ok(()) } pub(crate) fn host_task_delete(&mut self, (): ()) -> Result<()> { Ok(self.exit_call_not_concurrent()) } pub(crate) fn check_blocking(&mut self) -> crate::Result<()> { Ok(()) } pub(crate) fn may_enter(&mut self, _instance: RuntimeInstance) -> Result { Ok(!self.trapped()) } }