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