/rust/registry/src/index.crates.io-6f17d22bba15001f/wasmi-0.20.0/src/store.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use super::{ |
2 | | engine::DedupFuncType, |
3 | | Engine, |
4 | | Func, |
5 | | FuncEntity, |
6 | | FuncIdx, |
7 | | FuncType, |
8 | | Global, |
9 | | GlobalEntity, |
10 | | GlobalIdx, |
11 | | Instance, |
12 | | InstanceEntity, |
13 | | InstanceIdx, |
14 | | Memory, |
15 | | MemoryEntity, |
16 | | MemoryIdx, |
17 | | Table, |
18 | | TableEntity, |
19 | | TableIdx, |
20 | | }; |
21 | | use core::sync::atomic::{AtomicU32, Ordering}; |
22 | | use wasmi_arena::{Arena, GuardedEntity, Index}; |
23 | | |
24 | | /// A unique store index. |
25 | | /// |
26 | | /// # Note |
27 | | /// |
28 | | /// Used to protect against invalid entity indices. |
29 | 635k | #[derive(Debug, Copy, Clone, PartialEq, Eq)] |
30 | | pub struct StoreIdx(u32); |
31 | | |
32 | | impl Index for StoreIdx { |
33 | 3.96M | fn into_usize(self) -> usize { |
34 | 3.96M | self.0 as usize |
35 | 3.96M | } |
36 | | |
37 | 0 | fn from_usize(value: usize) -> Self { |
38 | 0 | let value = value.try_into().unwrap_or_else(|error| { |
39 | 0 | panic!("index {value} is out of bounds as store index: {error}") |
40 | 0 | }); |
41 | 0 | Self(value) |
42 | 0 | } |
43 | | } |
44 | | |
45 | | impl StoreIdx { |
46 | | /// Returns a new unique [`StoreIdx`]. |
47 | 4.33k | fn new() -> Self { |
48 | 4.33k | /// A static store index counter. |
49 | 4.33k | static CURRENT_STORE_IDX: AtomicU32 = AtomicU32::new(0); |
50 | 4.33k | let next_idx = CURRENT_STORE_IDX.fetch_add(1, Ordering::AcqRel); |
51 | 4.33k | Self(next_idx) |
52 | 4.33k | } |
53 | | } |
54 | | |
55 | | /// A stored entity. |
56 | | pub type Stored<Idx> = GuardedEntity<StoreIdx, Idx>; |
57 | | |
58 | | /// The store that owns all data associated to Wasm modules. |
59 | 0 | #[derive(Debug)] |
60 | | pub struct Store<T> { |
61 | | /// The unique store index. |
62 | | /// |
63 | | /// Used to protect against invalid entity indices. |
64 | | store_idx: StoreIdx, |
65 | | /// Stored linear memories. |
66 | | memories: Arena<MemoryIdx, MemoryEntity>, |
67 | | /// Stored tables. |
68 | | tables: Arena<TableIdx, TableEntity>, |
69 | | /// Stored global variables. |
70 | | globals: Arena<GlobalIdx, GlobalEntity>, |
71 | | /// Stored Wasm or host functions. |
72 | | funcs: Arena<FuncIdx, FuncEntity<T>>, |
73 | | /// Stored module instances. |
74 | | instances: Arena<InstanceIdx, InstanceEntity>, |
75 | | /// The [`Engine`] in use by the [`Store`]. |
76 | | /// |
77 | | /// Amongst others the [`Engine`] stores the Wasm function definitions. |
78 | | engine: Engine, |
79 | | /// User provided state. |
80 | | user_state: T, |
81 | | } |
82 | | |
83 | | impl<T> Store<T> { |
84 | | /// Creates a new store. |
85 | 4.33k | pub fn new(engine: &Engine, user_state: T) -> Self { |
86 | 4.33k | Self { |
87 | 4.33k | store_idx: StoreIdx::new(), |
88 | 4.33k | memories: Arena::new(), |
89 | 4.33k | tables: Arena::new(), |
90 | 4.33k | globals: Arena::new(), |
91 | 4.33k | funcs: Arena::new(), |
92 | 4.33k | instances: Arena::new(), |
93 | 4.33k | engine: engine.clone(), |
94 | 4.33k | user_state, |
95 | 4.33k | } |
96 | 4.33k | } <wasmi::store::Store<()>>::new Line | Count | Source | 85 | 4.33k | pub fn new(engine: &Engine, user_state: T) -> Self { | 86 | 4.33k | Self { | 87 | 4.33k | store_idx: StoreIdx::new(), | 88 | 4.33k | memories: Arena::new(), | 89 | 4.33k | tables: Arena::new(), | 90 | 4.33k | globals: Arena::new(), | 91 | 4.33k | funcs: Arena::new(), | 92 | 4.33k | instances: Arena::new(), | 93 | 4.33k | engine: engine.clone(), | 94 | 4.33k | user_state, | 95 | 4.33k | } | 96 | 4.33k | } |
Unexecuted instantiation: <wasmi::store::Store<_>>::new |
97 | | |
98 | | /// Returns the [`Engine`] that this store is associated with. |
99 | 86.5k | pub fn engine(&self) -> &Engine { |
100 | 86.5k | &self.engine |
101 | 86.5k | } <wasmi::store::Store<()>>::engine Line | Count | Source | 99 | 86.5k | pub fn engine(&self) -> &Engine { | 100 | 86.5k | &self.engine | 101 | 86.5k | } |
Unexecuted instantiation: <wasmi::store::Store<_>>::engine |
102 | | |
103 | | /// Returns a shared reference to the user provided state. |
104 | 0 | pub fn state(&self) -> &T { |
105 | 0 | &self.user_state |
106 | 0 | } |
107 | | |
108 | | /// Returns a shared reference to the user provided state. |
109 | 0 | pub fn state_mut(&mut self) -> &mut T { |
110 | 0 | &mut self.user_state |
111 | 0 | } |
112 | | |
113 | | /// Consumes `self` and returns its user provided state. |
114 | 0 | pub fn into_state(self) -> T { |
115 | 0 | self.user_state |
116 | 0 | } |
117 | | |
118 | | /// Allocates a new function type to the store. |
119 | 0 | pub(super) fn alloc_func_type(&mut self, func_type: FuncType) -> DedupFuncType { |
120 | 0 | self.engine.alloc_func_type(func_type) |
121 | 0 | } |
122 | | |
123 | | /// Allocates a new global variable to the store. |
124 | 11.7k | pub(super) fn alloc_global(&mut self, global: GlobalEntity) -> Global { |
125 | 11.7k | Global::from_inner(Stored::new(self.store_idx, self.globals.alloc(global))) |
126 | 11.7k | } <wasmi::store::Store<()>>::alloc_global Line | Count | Source | 124 | 11.7k | pub(super) fn alloc_global(&mut self, global: GlobalEntity) -> Global { | 125 | 11.7k | Global::from_inner(Stored::new(self.store_idx, self.globals.alloc(global))) | 126 | 11.7k | } |
Unexecuted instantiation: <wasmi::store::Store<_>>::alloc_global |
127 | | |
128 | | /// Allocates a new table to the store. |
129 | 2.22k | pub(super) fn alloc_table(&mut self, table: TableEntity) -> Table { |
130 | 2.22k | Table::from_inner(Stored::new(self.store_idx, self.tables.alloc(table))) |
131 | 2.22k | } <wasmi::store::Store<()>>::alloc_table Line | Count | Source | 129 | 2.22k | pub(super) fn alloc_table(&mut self, table: TableEntity) -> Table { | 130 | 2.22k | Table::from_inner(Stored::new(self.store_idx, self.tables.alloc(table))) | 131 | 2.22k | } |
Unexecuted instantiation: <wasmi::store::Store<_>>::alloc_table |
132 | | |
133 | | /// Allocates a new linear memory to the store. |
134 | 1.89k | pub(super) fn alloc_memory(&mut self, memory: MemoryEntity) -> Memory { |
135 | 1.89k | Memory::from_inner(Stored::new(self.store_idx, self.memories.alloc(memory))) |
136 | 1.89k | } <wasmi::store::Store<()>>::alloc_memory Line | Count | Source | 134 | 1.89k | pub(super) fn alloc_memory(&mut self, memory: MemoryEntity) -> Memory { | 135 | 1.89k | Memory::from_inner(Stored::new(self.store_idx, self.memories.alloc(memory))) | 136 | 1.89k | } |
Unexecuted instantiation: <wasmi::store::Store<_>>::alloc_memory |
137 | | |
138 | | /// Allocates a new Wasm or host function to the store. |
139 | 63.1k | pub(super) fn alloc_func(&mut self, func: FuncEntity<T>) -> Func { |
140 | 63.1k | Func::from_inner(Stored::new(self.store_idx, self.funcs.alloc(func))) |
141 | 63.1k | } <wasmi::store::Store<()>>::alloc_func Line | Count | Source | 139 | 63.1k | pub(super) fn alloc_func(&mut self, func: FuncEntity<T>) -> Func { | 140 | 63.1k | Func::from_inner(Stored::new(self.store_idx, self.funcs.alloc(func))) | 141 | 63.1k | } |
Unexecuted instantiation: <wasmi::store::Store<_>>::alloc_func |
142 | | |
143 | | /// Allocates a new [`Instance`] to the store. |
144 | | /// |
145 | | /// # Note |
146 | | /// |
147 | | /// The resulting uninitialized [`Instance`] can be used to initialize [`Instance`] entities |
148 | | /// that require an [`Instance`] handle upon construction such as [`Func`]. |
149 | | /// Using the [`Instance`] before fully initializing it using [`Store::initialize_instance`] |
150 | | /// will cause an execution panic. |
151 | 4.33k | pub(super) fn alloc_instance(&mut self) -> Instance { |
152 | 4.33k | Instance::from_inner(Stored::new( |
153 | 4.33k | self.store_idx, |
154 | 4.33k | self.instances.alloc(InstanceEntity::uninitialized()), |
155 | 4.33k | )) |
156 | 4.33k | } <wasmi::store::Store<()>>::alloc_instance Line | Count | Source | 151 | 4.33k | pub(super) fn alloc_instance(&mut self) -> Instance { | 152 | 4.33k | Instance::from_inner(Stored::new( | 153 | 4.33k | self.store_idx, | 154 | 4.33k | self.instances.alloc(InstanceEntity::uninitialized()), | 155 | 4.33k | )) | 156 | 4.33k | } |
Unexecuted instantiation: <wasmi::store::Store<_>>::alloc_instance |
157 | | |
158 | | /// Fully initializes the [`Instance`]. |
159 | | /// |
160 | | /// # Note |
161 | | /// |
162 | | /// After this operation the [`Instance`] can be used. |
163 | | /// |
164 | | /// # Panics |
165 | | /// |
166 | | /// - If the [`Instance`] does not belong to the [`Store`]. |
167 | | /// - If the [`Instance`] is unknown to the [`Store`]. |
168 | | /// - If the [`Instance`] already has been fully initialized. |
169 | 4.31k | pub(super) fn initialize_instance(&mut self, instance: Instance, initialized: InstanceEntity) { |
170 | 4.31k | let entity_index = self.unwrap_index(instance.into_inner()); |
171 | 4.31k | let entity = self.instances.get_mut(entity_index).unwrap_or_else(|| { |
172 | 0 | panic!( |
173 | 0 | "the store has no reference to the given instance: {:?}", |
174 | 0 | instance, |
175 | 0 | ) Unexecuted instantiation: <wasmi::store::Store<()>>::initialize_instance::{closure#0}Unexecuted instantiation: <wasmi::store::Store<_>>::initialize_instance::{closure#0} |
176 | 4.31k | }); |
177 | 4.31k | assert!( |
178 | 4.31k | !entity.is_initialized(), |
179 | 0 | "encountered an already initialized instance: {:?}", |
180 | | entity |
181 | | ); |
182 | 4.31k | assert!( |
183 | 4.31k | initialized.is_initialized(), |
184 | 0 | "encountered an uninitialized new instance entity: {:?}", |
185 | | initialized, |
186 | | ); |
187 | 4.31k | *entity = initialized; |
188 | 4.31k | } <wasmi::store::Store<()>>::initialize_instance Line | Count | Source | 169 | 4.31k | pub(super) fn initialize_instance(&mut self, instance: Instance, initialized: InstanceEntity) { | 170 | 4.31k | let entity_index = self.unwrap_index(instance.into_inner()); | 171 | 4.31k | let entity = self.instances.get_mut(entity_index).unwrap_or_else(|| { | 172 | | panic!( | 173 | | "the store has no reference to the given instance: {:?}", | 174 | | instance, | 175 | | ) | 176 | 4.31k | }); | 177 | 4.31k | assert!( | 178 | 4.31k | !entity.is_initialized(), | 179 | 0 | "encountered an already initialized instance: {:?}", | 180 | | entity | 181 | | ); | 182 | 4.31k | assert!( | 183 | 4.31k | initialized.is_initialized(), | 184 | 0 | "encountered an uninitialized new instance entity: {:?}", | 185 | | initialized, | 186 | | ); | 187 | 4.31k | *entity = initialized; | 188 | 4.31k | } |
Unexecuted instantiation: <wasmi::store::Store<_>>::initialize_instance |
189 | | |
190 | | /// Unpacks and checks the stored entity index. |
191 | | /// |
192 | | /// # Panics |
193 | | /// |
194 | | /// If the stored entity does not originate from this store. |
195 | 1.98M | fn unwrap_index<Idx>(&self, stored: Stored<Idx>) -> Idx |
196 | 1.98M | where |
197 | 1.98M | Idx: Index, |
198 | 1.98M | { |
199 | 1.98M | stored.entity_index(self.store_idx).unwrap_or_else(|| { |
200 | 0 | panic!( |
201 | 0 | "encountered foreign entity in store: {}", |
202 | 0 | self.store_idx.into_usize() |
203 | 0 | ) Unexecuted instantiation: <wasmi::store::Store<()>>::unwrap_index::<wasmi::table::TableIdx>::{closure#0}Unexecuted instantiation: <wasmi::store::Store<()>>::unwrap_index::<wasmi::global::GlobalIdx>::{closure#0}Unexecuted instantiation: <wasmi::store::Store<()>>::unwrap_index::<wasmi::func::FuncIdx>::{closure#0}Unexecuted instantiation: <wasmi::store::Store<()>>::unwrap_index::<wasmi::memory::MemoryIdx>::{closure#0}Unexecuted instantiation: <wasmi::store::Store<()>>::unwrap_index::<wasmi::instance::InstanceIdx>::{closure#0}Unexecuted instantiation: <wasmi::store::Store<_>>::unwrap_index::<_>::{closure#0} |
204 | 1.98M | }) |
205 | 1.98M | } <wasmi::store::Store<()>>::unwrap_index::<wasmi::instance::InstanceIdx> Line | Count | Source | 195 | 561k | fn unwrap_index<Idx>(&self, stored: Stored<Idx>) -> Idx | 196 | 561k | where | 197 | 561k | Idx: Index, | 198 | 561k | { | 199 | 561k | stored.entity_index(self.store_idx).unwrap_or_else(|| { | 200 | | panic!( | 201 | | "encountered foreign entity in store: {}", | 202 | | self.store_idx.into_usize() | 203 | | ) | 204 | 561k | }) | 205 | 561k | } |
<wasmi::store::Store<()>>::unwrap_index::<wasmi::memory::MemoryIdx> Line | Count | Source | 195 | 410k | fn unwrap_index<Idx>(&self, stored: Stored<Idx>) -> Idx | 196 | 410k | where | 197 | 410k | Idx: Index, | 198 | 410k | { | 199 | 410k | stored.entity_index(self.store_idx).unwrap_or_else(|| { | 200 | | panic!( | 201 | | "encountered foreign entity in store: {}", | 202 | | self.store_idx.into_usize() | 203 | | ) | 204 | 410k | }) | 205 | 410k | } |
<wasmi::store::Store<()>>::unwrap_index::<wasmi::global::GlobalIdx> Line | Count | Source | 195 | 340k | fn unwrap_index<Idx>(&self, stored: Stored<Idx>) -> Idx | 196 | 340k | where | 197 | 340k | Idx: Index, | 198 | 340k | { | 199 | 340k | stored.entity_index(self.store_idx).unwrap_or_else(|| { | 200 | | panic!( | 201 | | "encountered foreign entity in store: {}", | 202 | | self.store_idx.into_usize() | 203 | | ) | 204 | 340k | }) | 205 | 340k | } |
<wasmi::store::Store<()>>::unwrap_index::<wasmi::func::FuncIdx> Line | Count | Source | 195 | 641k | fn unwrap_index<Idx>(&self, stored: Stored<Idx>) -> Idx | 196 | 641k | where | 197 | 641k | Idx: Index, | 198 | 641k | { | 199 | 641k | stored.entity_index(self.store_idx).unwrap_or_else(|| { | 200 | | panic!( | 201 | | "encountered foreign entity in store: {}", | 202 | | self.store_idx.into_usize() | 203 | | ) | 204 | 641k | }) | 205 | 641k | } |
<wasmi::store::Store<()>>::unwrap_index::<wasmi::table::TableIdx> Line | Count | Source | 195 | 25.9k | fn unwrap_index<Idx>(&self, stored: Stored<Idx>) -> Idx | 196 | 25.9k | where | 197 | 25.9k | Idx: Index, | 198 | 25.9k | { | 199 | 25.9k | stored.entity_index(self.store_idx).unwrap_or_else(|| { | 200 | | panic!( | 201 | | "encountered foreign entity in store: {}", | 202 | | self.store_idx.into_usize() | 203 | | ) | 204 | 25.9k | }) | 205 | 25.9k | } |
Unexecuted instantiation: <wasmi::store::Store<_>>::unwrap_index::<_> |
206 | | |
207 | | /// Returns a shared reference to the associated entity of the signature. |
208 | | /// |
209 | | /// # Panics |
210 | | /// |
211 | | /// - If the deduplicated function type does not originate from this store. |
212 | | /// - If the deduplicated function type cannot be resolved to its entity. |
213 | 86.5k | pub(super) fn resolve_func_type(&self, func_type: DedupFuncType) -> FuncType { |
214 | 86.5k | self.engine.resolve_func_type(func_type, Clone::clone) |
215 | 86.5k | } <wasmi::store::Store<()>>::resolve_func_type Line | Count | Source | 213 | 86.5k | pub(super) fn resolve_func_type(&self, func_type: DedupFuncType) -> FuncType { | 214 | 86.5k | self.engine.resolve_func_type(func_type, Clone::clone) | 215 | 86.5k | } |
Unexecuted instantiation: <wasmi::store::Store<_>>::resolve_func_type |
216 | | |
217 | | /// Returns a shared reference to the associated entity of the global variable. |
218 | | /// |
219 | | /// # Panics |
220 | | /// |
221 | | /// - If the global variable does not originate from this store. |
222 | | /// - If the global variable cannot be resolved to its entity. |
223 | 180k | pub(super) fn resolve_global(&self, global: Global) -> &GlobalEntity { |
224 | 180k | let entity_index = self.unwrap_index(global.into_inner()); |
225 | 180k | self.globals.get(entity_index).unwrap_or_else(|| { |
226 | 0 | panic!( |
227 | 0 | "failed to resolve stored global variable: {:?}", |
228 | 0 | entity_index, |
229 | 0 | ) Unexecuted instantiation: <wasmi::store::Store<()>>::resolve_global::{closure#0}Unexecuted instantiation: <wasmi::store::Store<_>>::resolve_global::{closure#0} |
230 | 180k | }) |
231 | 180k | } <wasmi::store::Store<()>>::resolve_global Line | Count | Source | 223 | 180k | pub(super) fn resolve_global(&self, global: Global) -> &GlobalEntity { | 224 | 180k | let entity_index = self.unwrap_index(global.into_inner()); | 225 | 180k | self.globals.get(entity_index).unwrap_or_else(|| { | 226 | | panic!( | 227 | | "failed to resolve stored global variable: {:?}", | 228 | | entity_index, | 229 | | ) | 230 | 180k | }) | 231 | 180k | } |
Unexecuted instantiation: <wasmi::store::Store<_>>::resolve_global |
232 | | |
233 | | /// Returns an exclusive reference to the associated entity of the global variable. |
234 | | /// |
235 | | /// # Panics |
236 | | /// |
237 | | /// - If the global variable does not originate from this store. |
238 | | /// - If the global variable cannot be resolved to its entity. |
239 | 159k | pub(super) fn resolve_global_mut(&mut self, global: Global) -> &mut GlobalEntity { |
240 | 159k | let entity_index = self.unwrap_index(global.into_inner()); |
241 | 159k | self.globals.get_mut(entity_index).unwrap_or_else(|| { |
242 | 0 | panic!( |
243 | 0 | "failed to resolve stored global variable: {:?}", |
244 | 0 | entity_index, |
245 | 0 | ) Unexecuted instantiation: <wasmi::store::Store<()>>::resolve_global_mut::{closure#0}Unexecuted instantiation: <wasmi::store::Store<_>>::resolve_global_mut::{closure#0} |
246 | 159k | }) |
247 | 159k | } <wasmi::store::Store<()>>::resolve_global_mut Line | Count | Source | 239 | 159k | pub(super) fn resolve_global_mut(&mut self, global: Global) -> &mut GlobalEntity { | 240 | 159k | let entity_index = self.unwrap_index(global.into_inner()); | 241 | 159k | self.globals.get_mut(entity_index).unwrap_or_else(|| { | 242 | | panic!( | 243 | | "failed to resolve stored global variable: {:?}", | 244 | | entity_index, | 245 | | ) | 246 | 159k | }) | 247 | 159k | } |
Unexecuted instantiation: <wasmi::store::Store<_>>::resolve_global_mut |
248 | | |
249 | | /// Returns a shared reference to the associated entity of the table. |
250 | | /// |
251 | | /// # Panics |
252 | | /// |
253 | | /// - If the table does not originate from this store. |
254 | | /// - If the table cannot be resolved to its entity. |
255 | 13.4k | pub(super) fn resolve_table(&self, table: Table) -> &TableEntity { |
256 | 13.4k | let entity_index = self.unwrap_index(table.into_inner()); |
257 | 13.4k | self.tables |
258 | 13.4k | .get(entity_index) |
259 | 13.4k | .unwrap_or_else(|| panic!("failed to resolve stored table: {entity_index:?}"))Unexecuted instantiation: <wasmi::store::Store<()>>::resolve_table::{closure#0}Unexecuted instantiation: <wasmi::store::Store<_>>::resolve_table::{closure#0} |
260 | 13.4k | } <wasmi::store::Store<()>>::resolve_table Line | Count | Source | 255 | 13.4k | pub(super) fn resolve_table(&self, table: Table) -> &TableEntity { | 256 | 13.4k | let entity_index = self.unwrap_index(table.into_inner()); | 257 | 13.4k | self.tables | 258 | 13.4k | .get(entity_index) | 259 | 13.4k | .unwrap_or_else(|| panic!("failed to resolve stored table: {entity_index:?}")) | 260 | 13.4k | } |
Unexecuted instantiation: <wasmi::store::Store<_>>::resolve_table |
261 | | |
262 | | /// Returns an exclusive reference to the associated entity of the table. |
263 | | /// |
264 | | /// # Panics |
265 | | /// |
266 | | /// - If the table does not originate from this store. |
267 | | /// - If the table cannot be resolved to its entity. |
268 | 12.5k | pub(super) fn resolve_table_mut(&mut self, table: Table) -> &mut TableEntity { |
269 | 12.5k | let entity_index = self.unwrap_index(table.into_inner()); |
270 | 12.5k | self.tables |
271 | 12.5k | .get_mut(entity_index) |
272 | 12.5k | .unwrap_or_else(|| panic!("failed to resolve stored table: {entity_index:?}"))Unexecuted instantiation: <wasmi::store::Store<()>>::resolve_table_mut::{closure#0}Unexecuted instantiation: <wasmi::store::Store<_>>::resolve_table_mut::{closure#0} |
273 | 12.5k | } <wasmi::store::Store<()>>::resolve_table_mut Line | Count | Source | 268 | 12.5k | pub(super) fn resolve_table_mut(&mut self, table: Table) -> &mut TableEntity { | 269 | 12.5k | let entity_index = self.unwrap_index(table.into_inner()); | 270 | 12.5k | self.tables | 271 | 12.5k | .get_mut(entity_index) | 272 | 12.5k | .unwrap_or_else(|| panic!("failed to resolve stored table: {entity_index:?}")) | 273 | 12.5k | } |
Unexecuted instantiation: <wasmi::store::Store<_>>::resolve_table_mut |
274 | | |
275 | | /// Returns a shared reference to the associated entity of the linear memory. |
276 | | /// |
277 | | /// # Panics |
278 | | /// |
279 | | /// - If the linear memory does not originate from this store. |
280 | | /// - If the linear memory cannot be resolved to its entity. |
281 | 385k | pub(super) fn resolve_memory(&self, memory: Memory) -> &MemoryEntity { |
282 | 385k | let entity_index = self.unwrap_index(memory.into_inner()); |
283 | 385k | self.memories |
284 | 385k | .get(entity_index) |
285 | 385k | .unwrap_or_else(|| panic!("failed to resolve stored linear memory: {entity_index:?}"))Unexecuted instantiation: <wasmi::store::Store<()>>::resolve_memory::{closure#0}Unexecuted instantiation: <wasmi::store::Store<_>>::resolve_memory::{closure#0} |
286 | 385k | } <wasmi::store::Store<()>>::resolve_memory Line | Count | Source | 281 | 385k | pub(super) fn resolve_memory(&self, memory: Memory) -> &MemoryEntity { | 282 | 385k | let entity_index = self.unwrap_index(memory.into_inner()); | 283 | 385k | self.memories | 284 | 385k | .get(entity_index) | 285 | 385k | .unwrap_or_else(|| panic!("failed to resolve stored linear memory: {entity_index:?}")) | 286 | 385k | } |
Unexecuted instantiation: <wasmi::store::Store<_>>::resolve_memory |
287 | | |
288 | | /// Returns an exclusive reference to the associated entity of the linear memory. |
289 | | /// |
290 | | /// # Panics |
291 | | /// |
292 | | /// - If the linear memory does not originate from this store. |
293 | | /// - If the linear memory cannot be resolved to its entity. |
294 | 25.2k | pub(super) fn resolve_memory_mut(&mut self, memory: Memory) -> &mut MemoryEntity { |
295 | 25.2k | let entity_index = self.unwrap_index(memory.into_inner()); |
296 | 25.2k | self.memories |
297 | 25.2k | .get_mut(entity_index) |
298 | 25.2k | .unwrap_or_else(|| panic!("failed to resolve stored linear memory: {entity_index:?}"))Unexecuted instantiation: <wasmi::store::Store<()>>::resolve_memory_mut::{closure#0}Unexecuted instantiation: <wasmi::store::Store<_>>::resolve_memory_mut::{closure#0} |
299 | 25.2k | } <wasmi::store::Store<()>>::resolve_memory_mut Line | Count | Source | 294 | 25.2k | pub(super) fn resolve_memory_mut(&mut self, memory: Memory) -> &mut MemoryEntity { | 295 | 25.2k | let entity_index = self.unwrap_index(memory.into_inner()); | 296 | 25.2k | self.memories | 297 | 25.2k | .get_mut(entity_index) | 298 | 25.2k | .unwrap_or_else(|| panic!("failed to resolve stored linear memory: {entity_index:?}")) | 299 | 25.2k | } |
Unexecuted instantiation: <wasmi::store::Store<_>>::resolve_memory_mut |
300 | | |
301 | | /// Returns an exclusive reference to the associated entity of the linear memory and an |
302 | | /// exclusive reference to the user provided state. |
303 | | /// |
304 | | /// # Panics |
305 | | /// |
306 | | /// - If the linear memory does not originate from this store. |
307 | | /// - If the linear memory cannot be resolved to its entity. |
308 | 0 | pub(super) fn resolve_memory_and_state_mut( |
309 | 0 | &mut self, |
310 | 0 | memory: Memory, |
311 | 0 | ) -> (&mut MemoryEntity, &mut T) { |
312 | 0 | let entity_index = self.unwrap_index(memory.into_inner()); |
313 | 0 | let memory_entity = self |
314 | 0 | .memories |
315 | 0 | .get_mut(entity_index) |
316 | 0 | .unwrap_or_else(|| panic!("failed to resolve stored linear memory: {entity_index:?}")); |
317 | 0 | (memory_entity, &mut self.user_state) |
318 | 0 | } |
319 | | |
320 | | /// Returns a shared reference to the associated entity of the Wasm or host function. |
321 | | /// |
322 | | /// # Panics |
323 | | /// |
324 | | /// - If the Wasm or host function does not originate from this store. |
325 | | /// - If the Wasm or host function cannot be resolved to its entity. |
326 | 641k | pub(super) fn resolve_func(&self, func: Func) -> &FuncEntity<T> { |
327 | 641k | let entity_index = self.unwrap_index(func.into_inner()); |
328 | 641k | self.funcs.get(entity_index).unwrap_or_else(|| { |
329 | 0 | panic!( |
330 | 0 | "failed to resolve stored Wasm or host function: {:?}", |
331 | 0 | entity_index |
332 | 0 | ) Unexecuted instantiation: <wasmi::store::Store<()>>::resolve_func::{closure#0}Unexecuted instantiation: <wasmi::store::Store<_>>::resolve_func::{closure#0} |
333 | 641k | }) |
334 | 641k | } <wasmi::store::Store<()>>::resolve_func Line | Count | Source | 326 | 641k | pub(super) fn resolve_func(&self, func: Func) -> &FuncEntity<T> { | 327 | 641k | let entity_index = self.unwrap_index(func.into_inner()); | 328 | 641k | self.funcs.get(entity_index).unwrap_or_else(|| { | 329 | | panic!( | 330 | | "failed to resolve stored Wasm or host function: {:?}", | 331 | | entity_index | 332 | | ) | 333 | 641k | }) | 334 | 641k | } |
Unexecuted instantiation: <wasmi::store::Store<_>>::resolve_func |
335 | | |
336 | | /// Returns a shared reference to the associated entity of the [`Instance`]. |
337 | | /// |
338 | | /// # Panics |
339 | | /// |
340 | | /// - If the Wasm or host function does not originate from this store. |
341 | | /// - If the Wasm or host function cannot be resolved to its entity. |
342 | 557k | pub(super) fn resolve_instance(&self, instance: Instance) -> &InstanceEntity { |
343 | 557k | let entity_index = self.unwrap_index(instance.into_inner()); |
344 | 557k | self.instances.get(entity_index).unwrap_or_else(|| { |
345 | 0 | panic!( |
346 | 0 | "failed to resolve stored module instance: {:?}", |
347 | 0 | entity_index |
348 | 0 | ) Unexecuted instantiation: <wasmi::store::Store<()>>::resolve_instance::{closure#0}Unexecuted instantiation: <wasmi::store::Store<_>>::resolve_instance::{closure#0} |
349 | 557k | }) |
350 | 557k | } <wasmi::store::Store<()>>::resolve_instance Line | Count | Source | 342 | 557k | pub(super) fn resolve_instance(&self, instance: Instance) -> &InstanceEntity { | 343 | 557k | let entity_index = self.unwrap_index(instance.into_inner()); | 344 | 557k | self.instances.get(entity_index).unwrap_or_else(|| { | 345 | | panic!( | 346 | | "failed to resolve stored module instance: {:?}", | 347 | | entity_index | 348 | | ) | 349 | 557k | }) | 350 | 557k | } |
Unexecuted instantiation: <wasmi::store::Store<_>>::resolve_instance |
351 | | } |
352 | | |
353 | | /// A trait used to get shared access to a [`Store`] in `wasmi`. |
354 | | pub trait AsContext { |
355 | | /// The user state associated with the [`Store`], aka the `T` in `Store<T>`. |
356 | | type UserState; |
357 | | |
358 | | /// Returns the store context that this type provides access to. |
359 | | fn as_context(&self) -> StoreContext<Self::UserState>; |
360 | | } |
361 | | |
362 | | /// A trait used to get exclusive access to a [`Store`] in `wasmi`. |
363 | | pub trait AsContextMut: AsContext { |
364 | | /// Returns the store context that this type provides access to. |
365 | | fn as_context_mut(&mut self) -> StoreContextMut<Self::UserState>; |
366 | | } |
367 | | |
368 | | /// A temporary handle to a `&Store<T>`. |
369 | | /// |
370 | | /// This type is suitable for [`AsContext`] trait bounds on methods if desired. |
371 | | /// For more information, see [`Store`]. |
372 | 0 | #[derive(Debug, Copy, Clone)] |
373 | | #[repr(transparent)] |
374 | | pub struct StoreContext<'a, T> { |
375 | | pub(super) store: &'a Store<T>, |
376 | | } |
377 | | |
378 | | impl<'a, T: AsContext> From<&'a T> for StoreContext<'a, T::UserState> { |
379 | | #[inline] |
380 | 33.5k | fn from(ctx: &'a T) -> Self { |
381 | 33.5k | ctx.as_context() |
382 | 33.5k | } <wasmi::store::StoreContext<()> as core::convert::From<&wasmi::store::Store<()>>>::from Line | Count | Source | 380 | 33.5k | fn from(ctx: &'a T) -> Self { | 381 | 33.5k | ctx.as_context() | 382 | 33.5k | } |
Unexecuted instantiation: <wasmi::store::StoreContext<<_ as wasmi::store::AsContext>::UserState> as core::convert::From<&_>>::from |
383 | | } |
384 | | |
385 | | impl<'a, T: AsContext> From<&'a mut T> for StoreContext<'a, T::UserState> { |
386 | | #[inline] |
387 | 0 | fn from(ctx: &'a mut T) -> Self { |
388 | 0 | T::as_context(ctx) |
389 | 0 | } |
390 | | } |
391 | | |
392 | | impl<'a, T: AsContextMut> From<&'a mut T> for StoreContextMut<'a, T::UserState> { |
393 | | #[inline] |
394 | 11.9k | fn from(ctx: &'a mut T) -> Self { |
395 | 11.9k | ctx.as_context_mut() |
396 | 11.9k | } <wasmi::store::StoreContextMut<<wasmi::store::StoreContextMut<()> as wasmi::store::AsContext>::UserState> as core::convert::From<&mut wasmi::store::StoreContextMut<()>>>::from Line | Count | Source | 394 | 11.9k | fn from(ctx: &'a mut T) -> Self { | 395 | 11.9k | ctx.as_context_mut() | 396 | 11.9k | } |
Unexecuted instantiation: <wasmi::store::StoreContextMut<<_ as wasmi::store::AsContext>::UserState> as core::convert::From<&mut _>>::from |
397 | | } |
398 | | |
399 | | /// A temporary handle to a `&mut Store<T>`. |
400 | | /// |
401 | | /// This type is suitable for [`AsContextMut`] or [`AsContext`] trait bounds on methods if desired. |
402 | | /// For more information, see [`Store`]. |
403 | 0 | #[derive(Debug)] |
404 | | #[repr(transparent)] |
405 | | pub struct StoreContextMut<'a, T> { |
406 | | pub(super) store: &'a mut Store<T>, |
407 | | } |
408 | | |
409 | | impl<T> AsContext for &'_ T |
410 | | where |
411 | | T: AsContext, |
412 | | { |
413 | | type UserState = T::UserState; |
414 | | |
415 | | #[inline] |
416 | 753k | fn as_context(&self) -> StoreContext<'_, T::UserState> { |
417 | 753k | T::as_context(*self) |
418 | 753k | } <&&&mut wasmi::store::Store<()> as wasmi::store::AsContext>::as_context Line | Count | Source | 416 | 86.2k | fn as_context(&self) -> StoreContext<'_, T::UserState> { | 417 | 86.2k | T::as_context(*self) | 418 | 86.2k | } |
Unexecuted instantiation: <&wasmi::store::StoreContext<()> as wasmi::store::AsContext>::as_context <&&mut wasmi::store::Store<()> as wasmi::store::AsContext>::as_context Line | Count | Source | 416 | 172k | fn as_context(&self) -> StoreContext<'_, T::UserState> { | 417 | 172k | T::as_context(*self) | 418 | 172k | } |
<&&mut &mut wasmi::store::Store<()> as wasmi::store::AsContext>::as_context Line | Count | Source | 416 | 12.3k | fn as_context(&self) -> StoreContext<'_, T::UserState> { | 417 | 12.3k | T::as_context(*self) | 418 | 12.3k | } |
<&&wasmi::store::StoreContextMut<()> as wasmi::store::AsContext>::as_context Line | Count | Source | 416 | 320 | fn as_context(&self) -> StoreContext<'_, T::UserState> { | 417 | 320 | T::as_context(*self) | 418 | 320 | } |
<&wasmi::store::StoreContextMut<()> as wasmi::store::AsContext>::as_context Line | Count | Source | 416 | 810 | fn as_context(&self) -> StoreContext<'_, T::UserState> { | 417 | 810 | T::as_context(*self) | 418 | 810 | } |
<&wasmi::store::Store<()> as wasmi::store::AsContext>::as_context Line | Count | Source | 416 | 481k | fn as_context(&self) -> StoreContext<'_, T::UserState> { | 417 | 481k | T::as_context(*self) | 418 | 481k | } |
Unexecuted instantiation: <&_ as wasmi::store::AsContext>::as_context |
419 | | } |
420 | | |
421 | | impl<T> AsContext for &'_ mut T |
422 | | where |
423 | | T: AsContext, |
424 | | { |
425 | | type UserState = T::UserState; |
426 | | |
427 | | #[inline] |
428 | 284k | fn as_context(&self) -> StoreContext<'_, T::UserState> { |
429 | 284k | T::as_context(*self) |
430 | 284k | } <&mut wasmi::store::Store<()> as wasmi::store::AsContext>::as_context Line | Count | Source | 428 | 271k | fn as_context(&self) -> StoreContext<'_, T::UserState> { | 429 | 271k | T::as_context(*self) | 430 | 271k | } |
<&mut &mut wasmi::store::Store<()> as wasmi::store::AsContext>::as_context Line | Count | Source | 428 | 12.6k | fn as_context(&self) -> StoreContext<'_, T::UserState> { | 429 | 12.6k | T::as_context(*self) | 430 | 12.6k | } |
Unexecuted instantiation: <&mut _ as wasmi::store::AsContext>::as_context |
431 | | } |
432 | | |
433 | | impl<T> AsContextMut for &'_ mut T |
434 | | where |
435 | | T: AsContextMut, |
436 | | { |
437 | | #[inline] |
438 | 221k | fn as_context_mut(&mut self) -> StoreContextMut<'_, T::UserState> { |
439 | 221k | T::as_context_mut(*self) |
440 | 221k | } Unexecuted instantiation: <&mut wasmi::store::StoreContextMut<()> as wasmi::store::AsContextMut>::as_context_mut <&mut wasmi::store::Store<()> as wasmi::store::AsContextMut>::as_context_mut Line | Count | Source | 438 | 221k | fn as_context_mut(&mut self) -> StoreContextMut<'_, T::UserState> { | 439 | 221k | T::as_context_mut(*self) | 440 | 221k | } |
Unexecuted instantiation: <&mut _ as wasmi::store::AsContextMut>::as_context_mut |
441 | | } |
442 | | |
443 | | impl<T> AsContext for StoreContext<'_, T> { |
444 | | type UserState = T; |
445 | | |
446 | | #[inline] |
447 | 620k | fn as_context(&self) -> StoreContext<'_, Self::UserState> { |
448 | 620k | StoreContext { store: self.store } |
449 | 620k | } <wasmi::store::StoreContext<()> as wasmi::store::AsContext>::as_context Line | Count | Source | 447 | 620k | fn as_context(&self) -> StoreContext<'_, Self::UserState> { | 448 | 620k | StoreContext { store: self.store } | 449 | 620k | } |
Unexecuted instantiation: <wasmi::store::StoreContext<_> as wasmi::store::AsContext>::as_context |
450 | | } |
451 | | |
452 | | impl<T> AsContext for StoreContextMut<'_, T> { |
453 | | type UserState = T; |
454 | | |
455 | | #[inline] |
456 | 1.51M | fn as_context(&self) -> StoreContext<'_, Self::UserState> { |
457 | 1.51M | StoreContext { store: self.store } |
458 | 1.51M | } <wasmi::store::StoreContextMut<()> as wasmi::store::AsContext>::as_context Line | Count | Source | 456 | 1.51M | fn as_context(&self) -> StoreContext<'_, Self::UserState> { | 457 | 1.51M | StoreContext { store: self.store } | 458 | 1.51M | } |
Unexecuted instantiation: <wasmi::store::StoreContextMut<_> as wasmi::store::AsContext>::as_context |
459 | | } |
460 | | |
461 | | impl<T> AsContextMut for StoreContextMut<'_, T> { |
462 | | #[inline] |
463 | 5.97M | fn as_context_mut(&mut self) -> StoreContextMut<'_, Self::UserState> { |
464 | 5.97M | StoreContextMut { |
465 | 5.97M | store: &mut *self.store, |
466 | 5.97M | } |
467 | 5.97M | } <wasmi::store::StoreContextMut<()> as wasmi::store::AsContextMut>::as_context_mut Line | Count | Source | 463 | 5.97M | fn as_context_mut(&mut self) -> StoreContextMut<'_, Self::UserState> { | 464 | 5.97M | StoreContextMut { | 465 | 5.97M | store: &mut *self.store, | 466 | 5.97M | } | 467 | 5.97M | } |
Unexecuted instantiation: <wasmi::store::StoreContextMut<_> as wasmi::store::AsContextMut>::as_context_mut |
468 | | } |
469 | | |
470 | | impl<T> AsContext for Store<T> { |
471 | | type UserState = T; |
472 | | |
473 | | #[inline] |
474 | 786k | fn as_context(&self) -> StoreContext<'_, Self::UserState> { |
475 | 786k | StoreContext { store: self } |
476 | 786k | } <wasmi::store::Store<()> as wasmi::store::AsContext>::as_context Line | Count | Source | 474 | 786k | fn as_context(&self) -> StoreContext<'_, Self::UserState> { | 475 | 786k | StoreContext { store: self } | 476 | 786k | } |
Unexecuted instantiation: <wasmi::store::Store<_> as wasmi::store::AsContext>::as_context |
477 | | } |
478 | | |
479 | | impl<T> AsContextMut for Store<T> { |
480 | | #[inline] |
481 | 221k | fn as_context_mut(&mut self) -> StoreContextMut<'_, Self::UserState> { |
482 | 221k | StoreContextMut { store: self } |
483 | 221k | } <wasmi::store::Store<()> as wasmi::store::AsContextMut>::as_context_mut Line | Count | Source | 481 | 221k | fn as_context_mut(&mut self) -> StoreContextMut<'_, Self::UserState> { | 482 | 221k | StoreContextMut { store: self } | 483 | 221k | } |
Unexecuted instantiation: <wasmi::store::Store<_> as wasmi::store::AsContextMut>::as_context_mut |
484 | | } |