1 // Wasmtime's runtime has lots of fiddly bits where we're doing operations like 2 // casting between wasm i32/i64 and host `usize` values. There's also in general 3 // just lots of pieces of low-level manipulation of memory and internals of VM 4 // runtime state. To help keep all the integer casts correct be a bit more 5 // strict than the default settings to help weed out bugs ahead of time. 6 // 7 // This inevitably leads to wordier code than might otherwise be used because, 8 // for example, `u64 as usize` is warned against and will be an error on CI. 9 // This happens pretty frequently and needs to be replaced with `val.try_into()` 10 // or `usize::try_from(val)` where the error is handled. In some cases the 11 // correct thing to do is to `.unwrap()` the error to indicate a fatal mistake, 12 // but in some cases the correct thing is to propagate the error. 13 // 14 // Some niche cases that explicitly want truncation are recommended to have a 15 // function along the lines of 16 // 17 // #[allow(clippy::cast_possible_truncation)] 18 // fn truncate_i32_to_i8(a: i32) -> i8 { a as i8 } 19 // 20 // as this explicitly indicates the intent of truncation is desired. Other 21 // locations should use fallible conversions. 22 // 23 // If performance is absolutely critical then it's recommended to use `#[allow]` 24 // with a comment indicating why performance is critical as well as a short 25 // explanation of why truncation shouldn't be happening at runtime. This 26 // situation should be pretty rare though. 27 #![warn(clippy::cast_possible_truncation)] 28 29 #[macro_use] 30 pub(crate) mod func; 31 32 pub(crate) mod code; 33 pub(crate) mod code_memory; 34 #[cfg(feature = "debug-builtins")] 35 pub(crate) mod debug; 36 #[cfg(feature = "gc")] 37 pub(crate) mod exception; 38 pub(crate) mod externals; 39 #[cfg(feature = "async")] 40 pub(crate) mod fiber; 41 pub(crate) mod gc; 42 pub(crate) mod instance; 43 pub(crate) mod instantiate; 44 pub(crate) mod limits; 45 pub(crate) mod linker; 46 pub(crate) mod memory; 47 pub(crate) mod module; 48 pub(crate) mod resources; 49 pub(crate) mod store; 50 pub(crate) mod trampoline; 51 pub(crate) mod trap; 52 pub(crate) mod type_registry; 53 pub(crate) mod types; 54 pub(crate) mod uninhabited; 55 pub(crate) mod v128; 56 pub(crate) mod values; 57 pub(crate) mod vm; 58 59 #[cfg(feature = "component-model")] 60 pub mod component; 61 62 cfg_if::cfg_if! { 63 if #[cfg(miri)] { 64 // no extensions on miri 65 } else if #[cfg(not(feature = "std"))] { 66 // no extensions on no-std 67 } else if #[cfg(unix)] { 68 pub mod unix; 69 } else if #[cfg(windows)] { 70 pub mod windows; 71 } else { 72 // ... unknown os! 73 } 74 } 75 76 pub use code_memory::CodeMemory; 77 #[cfg(feature = "gc")] 78 pub use exception::*; 79 pub use externals::*; 80 pub use func::*; 81 pub use gc::*; 82 pub use instance::{Instance, InstancePre}; 83 pub use instantiate::CompiledModule; 84 pub use limits::*; 85 pub use linker::*; 86 pub use memory::*; 87 pub use module::{Module, ModuleExport}; 88 pub use resources::*; 89 #[cfg(all(feature = "async", feature = "call-hook"))] 90 pub use store::CallHookHandler; 91 pub use store::{ 92 AsContext, AsContextMut, CallHook, Store, StoreContext, StoreContextMut, UpdateDeadline, 93 }; 94 pub use trap::*; 95 pub use types::*; 96 pub use v128::V128; 97 pub use values::*; 98 99 pub(crate) use uninhabited::*; 100 101 #[cfg(feature = "pooling-allocator")] 102 pub use vm::{PoolConcurrencyLimitError, PoolingAllocatorMetrics}; 103 104 #[cfg(feature = "profiling")] 105 mod profiling; 106 #[cfg(feature = "profiling")] 107 pub use profiling::GuestProfiler; 108 109 #[cfg(feature = "async")] 110 pub(crate) mod stack; 111 #[cfg(feature = "async")] 112 pub use stack::*; 113 114 #[cfg(feature = "coredump")] 115 mod coredump; 116 #[cfg(feature = "coredump")] 117 pub use coredump::*; 118 119 #[cfg(feature = "wave")] 120 mod wave; 121 122 fn _assertions_runtime() { 123 use crate::_assert_send_and_sync; 124 125 #[cfg(feature = "async")] 126 fn _assert_send<T: Send>(_t: T) {} 127 128 _assert_send_and_sync::<Caller<'_, ()>>(); 129 _assert_send_and_sync::<ExternRef>(); 130 _assert_send_and_sync::<(Func, TypedFunc<(), ()>, Global, Table, Memory)>(); 131 _assert_send_and_sync::<Instance>(); 132 _assert_send_and_sync::<InstancePre<()>>(); 133 _assert_send_and_sync::<InstancePre<*mut u8>>(); 134 _assert_send_and_sync::<Linker<()>>(); 135 _assert_send_and_sync::<Linker<*mut u8>>(); 136 _assert_send_and_sync::<Module>(); 137 _assert_send_and_sync::<Store<()>>(); 138 _assert_send_and_sync::<StoreContext<'_, ()>>(); 139 _assert_send_and_sync::<StoreContextMut<'_, ()>>(); 140 141 #[cfg(feature = "async")] 142 fn _call_async(s: &mut Store<()>, f: Func) { 143 _assert_send(f.call_async(&mut *s, &[], &mut [])) 144 } 145 #[cfg(feature = "async")] 146 fn _typed_call_async(s: &mut Store<()>, f: TypedFunc<(), ()>) { 147 _assert_send(f.call_async(&mut *s, ())) 148 } 149 #[cfg(feature = "async")] 150 fn _instantiate_async(s: &mut Store<()>, m: &Module) { 151 _assert_send(Instance::new_async(s, m, &[])) 152 } 153 } 154