/src/wasm-tools/crates/wasm-encoder/src/component/canonicals.rs
Line | Count | Source |
1 | | use crate::{ |
2 | | ComponentSection, ComponentSectionId, ComponentValType, Encode, ValType, encode_section, |
3 | | }; |
4 | | use alloc::vec::Vec; |
5 | | |
6 | | /// Represents options for canonical function definitions. |
7 | | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
8 | | pub enum CanonicalOption { |
9 | | /// The string types in the function signature are UTF-8 encoded. |
10 | | UTF8, |
11 | | /// The string types in the function signature are UTF-16 encoded. |
12 | | UTF16, |
13 | | /// The string types in the function signature are compact UTF-16 encoded. |
14 | | CompactUTF16, |
15 | | /// The memory to use if the lifting or lowering of a function requires memory access. |
16 | | /// |
17 | | /// The value is an index to a core memory. |
18 | | Memory(u32), |
19 | | /// The realloc function to use if the lifting or lowering of a function requires memory |
20 | | /// allocation. |
21 | | /// |
22 | | /// The value is an index to a core function of type `(func (param i32 i32 i32 i32) (result i32))`. |
23 | | Realloc(u32), |
24 | | /// The post-return function to use if the lifting of a function requires |
25 | | /// cleanup after the function returns. |
26 | | PostReturn(u32), |
27 | | /// Indicates that specified function should be lifted or lowered using the `async` ABI. |
28 | | Async, |
29 | | /// The function to use if the async lifting of a function should receive task/stream/future progress events |
30 | | /// using a callback. |
31 | | Callback(u32), |
32 | | /// The core function type to lower a component function into. |
33 | | CoreType(u32), |
34 | | /// Use the GC variant of the canonical ABI. |
35 | | Gc, |
36 | | } |
37 | | |
38 | | impl Encode for CanonicalOption { |
39 | 9.99k | fn encode(&self, sink: &mut Vec<u8>) { |
40 | 9.99k | match self { |
41 | 697 | Self::UTF8 => sink.push(0x00), |
42 | 0 | Self::UTF16 => sink.push(0x01), |
43 | 0 | Self::CompactUTF16 => sink.push(0x02), |
44 | 1.79k | Self::Memory(idx) => { |
45 | 1.79k | sink.push(0x03); |
46 | 1.79k | idx.encode(sink); |
47 | 1.79k | } |
48 | 729 | Self::Realloc(idx) => { |
49 | 729 | sink.push(0x04); |
50 | 729 | idx.encode(sink); |
51 | 729 | } |
52 | 4.93k | Self::PostReturn(idx) => { |
53 | 4.93k | sink.push(0x05); |
54 | 4.93k | idx.encode(sink); |
55 | 4.93k | } |
56 | 1.18k | Self::Async => { |
57 | 1.18k | sink.push(0x06); |
58 | 1.18k | } |
59 | 651 | Self::Callback(idx) => { |
60 | 651 | sink.push(0x07); |
61 | 651 | idx.encode(sink); |
62 | 651 | } |
63 | 0 | Self::CoreType(idx) => { |
64 | 0 | sink.push(0x08); |
65 | 0 | idx.encode(sink); |
66 | 0 | } |
67 | 0 | Self::Gc => { |
68 | 0 | sink.push(0x09); |
69 | 0 | } |
70 | | } |
71 | 9.99k | } |
72 | | } |
73 | | |
74 | | /// An encoder for the canonical function section of WebAssembly components. |
75 | | /// |
76 | | /// # Example |
77 | | /// |
78 | | /// ``` |
79 | | /// use wasm_encoder::{Component, CanonicalFunctionSection, CanonicalOption}; |
80 | | /// |
81 | | /// let mut functions = CanonicalFunctionSection::new(); |
82 | | /// functions.lift(0, 0, [CanonicalOption::UTF8]); |
83 | | /// |
84 | | /// let mut component = Component::new(); |
85 | | /// component.section(&functions); |
86 | | /// |
87 | | /// let bytes = component.finish(); |
88 | | /// ``` |
89 | | #[derive(Clone, Debug, Default)] |
90 | | pub struct CanonicalFunctionSection { |
91 | | bytes: Vec<u8>, |
92 | | num_added: u32, |
93 | | } |
94 | | |
95 | | impl CanonicalFunctionSection { |
96 | | /// Construct a new component function section encoder. |
97 | 12.0k | pub fn new() -> Self { |
98 | 12.0k | Self::default() |
99 | 12.0k | } |
100 | | |
101 | | /// The number of functions in the section. |
102 | 0 | pub fn len(&self) -> u32 { |
103 | 0 | self.num_added |
104 | 0 | } |
105 | | |
106 | | /// Determines if the section is empty. |
107 | 0 | pub fn is_empty(&self) -> bool { |
108 | 0 | self.num_added == 0 |
109 | 0 | } |
110 | | |
111 | | /// Define a function that will lift a core WebAssembly function to the canonical ABI. |
112 | 5.64k | pub fn lift<O>(&mut self, core_func_index: u32, type_index: u32, options: O) -> &mut Self |
113 | 5.64k | where |
114 | 5.64k | O: IntoIterator<Item = CanonicalOption>, |
115 | 5.64k | O::IntoIter: ExactSizeIterator, |
116 | | { |
117 | 5.64k | self.bytes.push(0x00); |
118 | 5.64k | self.bytes.push(0x00); |
119 | 5.64k | core_func_index.encode(&mut self.bytes); |
120 | 5.64k | self.encode_options(options); |
121 | 5.64k | type_index.encode(&mut self.bytes); |
122 | 5.64k | self.num_added += 1; |
123 | 5.64k | self |
124 | 5.64k | } <wasm_encoder::component::canonicals::CanonicalFunctionSection>::lift::<alloc::vec::Vec<wasm_encoder::component::canonicals::CanonicalOption>> Line | Count | Source | 112 | 5.64k | pub fn lift<O>(&mut self, core_func_index: u32, type_index: u32, options: O) -> &mut Self | 113 | 5.64k | where | 114 | 5.64k | O: IntoIterator<Item = CanonicalOption>, | 115 | 5.64k | O::IntoIter: ExactSizeIterator, | 116 | | { | 117 | 5.64k | self.bytes.push(0x00); | 118 | 5.64k | self.bytes.push(0x00); | 119 | 5.64k | core_func_index.encode(&mut self.bytes); | 120 | 5.64k | self.encode_options(options); | 121 | 5.64k | type_index.encode(&mut self.bytes); | 122 | 5.64k | self.num_added += 1; | 123 | 5.64k | self | 124 | 5.64k | } |
Unexecuted instantiation: <wasm_encoder::component::canonicals::CanonicalFunctionSection>::lift::<alloc::vec::Vec<wasm_encoder::component::canonicals::CanonicalOption>> Unexecuted instantiation: <wasm_encoder::component::canonicals::CanonicalFunctionSection>::lift::<_> |
125 | | |
126 | | /// Define a function that will lower a canonical ABI function to a core WebAssembly function. |
127 | 3.07k | pub fn lower<O>(&mut self, func_index: u32, options: O) -> &mut Self |
128 | 3.07k | where |
129 | 3.07k | O: IntoIterator<Item = CanonicalOption>, |
130 | 3.07k | O::IntoIter: ExactSizeIterator, |
131 | | { |
132 | 3.07k | self.bytes.push(0x01); |
133 | 3.07k | self.bytes.push(0x00); |
134 | 3.07k | func_index.encode(&mut self.bytes); |
135 | 3.07k | self.encode_options(options); |
136 | 3.07k | self.num_added += 1; |
137 | 3.07k | self |
138 | 3.07k | } <wasm_encoder::component::canonicals::CanonicalFunctionSection>::lower::<alloc::vec::Vec<wasm_encoder::component::canonicals::CanonicalOption>> Line | Count | Source | 127 | 2.62k | pub fn lower<O>(&mut self, func_index: u32, options: O) -> &mut Self | 128 | 2.62k | where | 129 | 2.62k | O: IntoIterator<Item = CanonicalOption>, | 130 | 2.62k | O::IntoIter: ExactSizeIterator, | 131 | | { | 132 | 2.62k | self.bytes.push(0x01); | 133 | 2.62k | self.bytes.push(0x00); | 134 | 2.62k | func_index.encode(&mut self.bytes); | 135 | 2.62k | self.encode_options(options); | 136 | 2.62k | self.num_added += 1; | 137 | 2.62k | self | 138 | 2.62k | } |
<wasm_encoder::component::canonicals::CanonicalFunctionSection>::lower::<<wit_component::encoding::RequiredOptions>::into_iter::Iter> Line | Count | Source | 127 | 444 | pub fn lower<O>(&mut self, func_index: u32, options: O) -> &mut Self | 128 | 444 | where | 129 | 444 | O: IntoIterator<Item = CanonicalOption>, | 130 | 444 | O::IntoIter: ExactSizeIterator, | 131 | | { | 132 | 444 | self.bytes.push(0x01); | 133 | 444 | self.bytes.push(0x00); | 134 | 444 | func_index.encode(&mut self.bytes); | 135 | 444 | self.encode_options(options); | 136 | 444 | self.num_added += 1; | 137 | 444 | self | 138 | 444 | } |
Unexecuted instantiation: <wasm_encoder::component::canonicals::CanonicalFunctionSection>::lower::<alloc::vec::Vec<wasm_encoder::component::canonicals::CanonicalOption>> Unexecuted instantiation: <wasm_encoder::component::canonicals::CanonicalFunctionSection>::lower::<_> |
139 | | |
140 | | /// Defines a function which will create an owned handle to the resource |
141 | | /// specified by `ty_index`. |
142 | 546 | pub fn resource_new(&mut self, ty_index: u32) -> &mut Self { |
143 | 546 | self.bytes.push(0x02); |
144 | 546 | ty_index.encode(&mut self.bytes); |
145 | 546 | self.num_added += 1; |
146 | 546 | self |
147 | 546 | } |
148 | | |
149 | | /// Defines a function which will drop the specified type of handle. |
150 | 927 | pub fn resource_drop(&mut self, ty_index: u32) -> &mut Self { |
151 | 927 | self.bytes.push(0x03); |
152 | 927 | ty_index.encode(&mut self.bytes); |
153 | 927 | self.num_added += 1; |
154 | 927 | self |
155 | 927 | } |
156 | | |
157 | | /// Defines a function which will return the representation of the specified |
158 | | /// resource type. |
159 | 546 | pub fn resource_rep(&mut self, ty_index: u32) -> &mut Self { |
160 | 546 | self.bytes.push(0x04); |
161 | 546 | ty_index.encode(&mut self.bytes); |
162 | 546 | self.num_added += 1; |
163 | 546 | self |
164 | 546 | } |
165 | | |
166 | | /// Defines a function which will spawn a new thread by invoking a shared |
167 | | /// function of type `ty_index`. |
168 | 0 | pub fn thread_spawn_ref(&mut self, ty_index: u32) -> &mut Self { |
169 | 0 | self.bytes.push(0x40); |
170 | 0 | ty_index.encode(&mut self.bytes); |
171 | 0 | self.num_added += 1; |
172 | 0 | self |
173 | 0 | } |
174 | | |
175 | | /// Defines a function which will spawn a new thread by invoking a shared |
176 | | /// function indirectly through a `funcref` table. |
177 | 0 | pub fn thread_spawn_indirect(&mut self, ty_index: u32, table_index: u32) -> &mut Self { |
178 | 0 | self.bytes.push(0x41); |
179 | 0 | ty_index.encode(&mut self.bytes); |
180 | 0 | table_index.encode(&mut self.bytes); |
181 | 0 | self.num_added += 1; |
182 | 0 | self |
183 | 0 | } |
184 | | |
185 | | /// Defines a function which will return the number of threads that can be |
186 | | /// expected to execute concurrently. |
187 | 0 | pub fn thread_available_parallelism(&mut self) -> &mut Self { |
188 | 0 | self.bytes.push(0x42); |
189 | 0 | self.num_added += 1; |
190 | 0 | self |
191 | 0 | } |
192 | | |
193 | | /// Defines a function which tells the host to increment the backpressure |
194 | | /// counter. |
195 | 689 | pub fn backpressure_inc(&mut self) -> &mut Self { |
196 | 689 | self.bytes.push(0x24); |
197 | 689 | self.num_added += 1; |
198 | 689 | self |
199 | 689 | } |
200 | | |
201 | | /// Defines a function which tells the host to decrement the backpressure |
202 | | /// counter. |
203 | 689 | pub fn backpressure_dec(&mut self) -> &mut Self { |
204 | 689 | self.bytes.push(0x25); |
205 | 689 | self.num_added += 1; |
206 | 689 | self |
207 | 689 | } |
208 | | |
209 | | /// Defines a function which returns a result to the caller of a lifted |
210 | | /// export function. This allows the callee to continue executing after |
211 | | /// returning a result. |
212 | 809 | pub fn task_return<O>(&mut self, ty: Option<ComponentValType>, options: O) -> &mut Self |
213 | 809 | where |
214 | 809 | O: IntoIterator<Item = CanonicalOption>, |
215 | 809 | O::IntoIter: ExactSizeIterator, |
216 | | { |
217 | 809 | self.bytes.push(0x09); |
218 | 809 | crate::encode_resultlist(&mut self.bytes, ty); |
219 | 809 | self.encode_options(options); |
220 | 809 | self.num_added += 1; |
221 | 809 | self |
222 | 809 | } <wasm_encoder::component::canonicals::CanonicalFunctionSection>::task_return::<alloc::vec::Vec<wasm_encoder::component::canonicals::CanonicalOption>> Line | Count | Source | 212 | 684 | pub fn task_return<O>(&mut self, ty: Option<ComponentValType>, options: O) -> &mut Self | 213 | 684 | where | 214 | 684 | O: IntoIterator<Item = CanonicalOption>, | 215 | 684 | O::IntoIter: ExactSizeIterator, | 216 | | { | 217 | 684 | self.bytes.push(0x09); | 218 | 684 | crate::encode_resultlist(&mut self.bytes, ty); | 219 | 684 | self.encode_options(options); | 220 | 684 | self.num_added += 1; | 221 | 684 | self | 222 | 684 | } |
<wasm_encoder::component::canonicals::CanonicalFunctionSection>::task_return::<<wit_component::encoding::RequiredOptions>::into_iter::Iter> Line | Count | Source | 212 | 125 | pub fn task_return<O>(&mut self, ty: Option<ComponentValType>, options: O) -> &mut Self | 213 | 125 | where | 214 | 125 | O: IntoIterator<Item = CanonicalOption>, | 215 | 125 | O::IntoIter: ExactSizeIterator, | 216 | | { | 217 | 125 | self.bytes.push(0x09); | 218 | 125 | crate::encode_resultlist(&mut self.bytes, ty); | 219 | 125 | self.encode_options(options); | 220 | 125 | self.num_added += 1; | 221 | 125 | self | 222 | 125 | } |
Unexecuted instantiation: <wasm_encoder::component::canonicals::CanonicalFunctionSection>::task_return::<_> |
223 | | |
224 | | /// Defines a function to acknowledge cancellation of the current task. |
225 | 689 | pub fn task_cancel(&mut self) -> &mut Self { |
226 | 689 | self.bytes.push(0x05); |
227 | 689 | self.num_added += 1; |
228 | 689 | self |
229 | 689 | } |
230 | | |
231 | | /// Defines a new `context.get` intrinsic of the ith slot with the given |
232 | | /// value type. |
233 | 689 | pub fn context_get(&mut self, ty: ValType, i: u32) -> &mut Self { |
234 | 689 | self.bytes.push(0x0a); |
235 | 689 | ty.encode(&mut self.bytes); |
236 | 689 | i.encode(&mut self.bytes); |
237 | 689 | self.num_added += 1; |
238 | 689 | self |
239 | 689 | } |
240 | | |
241 | | /// Defines a new `context.set` intrinsic of the ith slot with the given |
242 | | /// value type. |
243 | 689 | pub fn context_set(&mut self, ty: ValType, i: u32) -> &mut Self { |
244 | 689 | self.bytes.push(0x0b); |
245 | 689 | ty.encode(&mut self.bytes); |
246 | 689 | i.encode(&mut self.bytes); |
247 | 689 | self.num_added += 1; |
248 | 689 | self |
249 | 689 | } |
250 | | |
251 | | /// Defines a function to drop a specified task which has completed. |
252 | 689 | pub fn subtask_drop(&mut self) -> &mut Self { |
253 | 689 | self.bytes.push(0x0d); |
254 | 689 | self.num_added += 1; |
255 | 689 | self |
256 | 689 | } |
257 | | |
258 | | /// Defines a function to cancel an in-progress task. |
259 | 689 | pub fn subtask_cancel(&mut self, async_: bool) -> &mut Self { |
260 | 689 | self.bytes.push(0x06); |
261 | 689 | self.bytes.push(if async_ { 1 } else { 0 }); |
262 | 689 | self.num_added += 1; |
263 | 689 | self |
264 | 689 | } |
265 | | |
266 | | /// Defines a function to create a new `stream` handle of the specified |
267 | | /// type. |
268 | 8 | pub fn stream_new(&mut self, ty: u32) -> &mut Self { |
269 | 8 | self.bytes.push(0x0e); |
270 | 8 | ty.encode(&mut self.bytes); |
271 | 8 | self.num_added += 1; |
272 | 8 | self |
273 | 8 | } |
274 | | |
275 | | /// Defines a function to read from a `stream` of the specified type. |
276 | 8 | pub fn stream_read<O>(&mut self, ty: u32, options: O) -> &mut Self |
277 | 8 | where |
278 | 8 | O: IntoIterator<Item = CanonicalOption>, |
279 | 8 | O::IntoIter: ExactSizeIterator, |
280 | | { |
281 | 8 | self.bytes.push(0x0f); |
282 | 8 | ty.encode(&mut self.bytes); |
283 | 8 | self.encode_options(options); |
284 | 8 | self.num_added += 1; |
285 | 8 | self |
286 | 8 | } <wasm_encoder::component::canonicals::CanonicalFunctionSection>::stream_read::<<wit_component::encoding::RequiredOptions>::into_iter::Iter> Line | Count | Source | 276 | 8 | pub fn stream_read<O>(&mut self, ty: u32, options: O) -> &mut Self | 277 | 8 | where | 278 | 8 | O: IntoIterator<Item = CanonicalOption>, | 279 | 8 | O::IntoIter: ExactSizeIterator, | 280 | | { | 281 | 8 | self.bytes.push(0x0f); | 282 | 8 | ty.encode(&mut self.bytes); | 283 | 8 | self.encode_options(options); | 284 | 8 | self.num_added += 1; | 285 | 8 | self | 286 | 8 | } |
Unexecuted instantiation: <wasm_encoder::component::canonicals::CanonicalFunctionSection>::stream_read::<_> |
287 | | |
288 | | /// Defines a function to write to a `stream` of the specified type. |
289 | 8 | pub fn stream_write<O>(&mut self, ty: u32, options: O) -> &mut Self |
290 | 8 | where |
291 | 8 | O: IntoIterator<Item = CanonicalOption>, |
292 | 8 | O::IntoIter: ExactSizeIterator, |
293 | | { |
294 | 8 | self.bytes.push(0x10); |
295 | 8 | ty.encode(&mut self.bytes); |
296 | 8 | self.encode_options(options); |
297 | 8 | self.num_added += 1; |
298 | 8 | self |
299 | 8 | } <wasm_encoder::component::canonicals::CanonicalFunctionSection>::stream_write::<<wit_component::encoding::RequiredOptions>::into_iter::Iter> Line | Count | Source | 289 | 8 | pub fn stream_write<O>(&mut self, ty: u32, options: O) -> &mut Self | 290 | 8 | where | 291 | 8 | O: IntoIterator<Item = CanonicalOption>, | 292 | 8 | O::IntoIter: ExactSizeIterator, | 293 | | { | 294 | 8 | self.bytes.push(0x10); | 295 | 8 | ty.encode(&mut self.bytes); | 296 | 8 | self.encode_options(options); | 297 | 8 | self.num_added += 1; | 298 | 8 | self | 299 | 8 | } |
Unexecuted instantiation: <wasm_encoder::component::canonicals::CanonicalFunctionSection>::stream_write::<_> |
300 | | |
301 | | /// Defines a function to cancel an in-progress read from a `stream` of the |
302 | | /// specified type. |
303 | 8 | pub fn stream_cancel_read(&mut self, ty: u32, async_: bool) -> &mut Self { |
304 | 8 | self.bytes.push(0x11); |
305 | 8 | ty.encode(&mut self.bytes); |
306 | 8 | self.bytes.push(if async_ { 1 } else { 0 }); |
307 | 8 | self.num_added += 1; |
308 | 8 | self |
309 | 8 | } |
310 | | |
311 | | /// Defines a function to cancel an in-progress write to a `stream` of the |
312 | | /// specified type. |
313 | 8 | pub fn stream_cancel_write(&mut self, ty: u32, async_: bool) -> &mut Self { |
314 | 8 | self.bytes.push(0x12); |
315 | 8 | ty.encode(&mut self.bytes); |
316 | 8 | self.bytes.push(if async_ { 1 } else { 0 }); |
317 | 8 | self.num_added += 1; |
318 | 8 | self |
319 | 8 | } |
320 | | |
321 | | /// Defines a function to drop the readable end of a `stream` of the |
322 | | /// specified type. |
323 | 8 | pub fn stream_drop_readable(&mut self, ty: u32) -> &mut Self { |
324 | 8 | self.bytes.push(0x13); |
325 | 8 | ty.encode(&mut self.bytes); |
326 | 8 | self.num_added += 1; |
327 | 8 | self |
328 | 8 | } |
329 | | |
330 | | /// Defines a function to drop the writable end of a `stream` of the |
331 | | /// specified type. |
332 | 8 | pub fn stream_drop_writable(&mut self, ty: u32) -> &mut Self { |
333 | 8 | self.bytes.push(0x14); |
334 | 8 | ty.encode(&mut self.bytes); |
335 | 8 | self.num_added += 1; |
336 | 8 | self |
337 | 8 | } |
338 | | |
339 | | /// Defines a function to create a new `future` handle of the specified |
340 | | /// type. |
341 | 663 | pub fn future_new(&mut self, ty: u32) -> &mut Self { |
342 | 663 | self.bytes.push(0x15); |
343 | 663 | ty.encode(&mut self.bytes); |
344 | 663 | self.num_added += 1; |
345 | 663 | self |
346 | 663 | } |
347 | | |
348 | | /// Defines a function to read from a `future` of the specified type. |
349 | 162 | pub fn future_read<O>(&mut self, ty: u32, options: O) -> &mut Self |
350 | 162 | where |
351 | 162 | O: IntoIterator<Item = CanonicalOption>, |
352 | 162 | O::IntoIter: ExactSizeIterator, |
353 | | { |
354 | 162 | self.bytes.push(0x16); |
355 | 162 | ty.encode(&mut self.bytes); |
356 | 162 | self.encode_options(options); |
357 | 162 | self.num_added += 1; |
358 | 162 | self |
359 | 162 | } <wasm_encoder::component::canonicals::CanonicalFunctionSection>::future_read::<<wit_component::encoding::RequiredOptions>::into_iter::Iter> Line | Count | Source | 349 | 162 | pub fn future_read<O>(&mut self, ty: u32, options: O) -> &mut Self | 350 | 162 | where | 351 | 162 | O: IntoIterator<Item = CanonicalOption>, | 352 | 162 | O::IntoIter: ExactSizeIterator, | 353 | | { | 354 | 162 | self.bytes.push(0x16); | 355 | 162 | ty.encode(&mut self.bytes); | 356 | 162 | self.encode_options(options); | 357 | 162 | self.num_added += 1; | 358 | 162 | self | 359 | 162 | } |
Unexecuted instantiation: <wasm_encoder::component::canonicals::CanonicalFunctionSection>::future_read::<_> |
360 | | |
361 | | /// Defines a function to write to a `future` of the specified type. |
362 | 162 | pub fn future_write<O>(&mut self, ty: u32, options: O) -> &mut Self |
363 | 162 | where |
364 | 162 | O: IntoIterator<Item = CanonicalOption>, |
365 | 162 | O::IntoIter: ExactSizeIterator, |
366 | | { |
367 | 162 | self.bytes.push(0x17); |
368 | 162 | ty.encode(&mut self.bytes); |
369 | 162 | self.encode_options(options); |
370 | 162 | self.num_added += 1; |
371 | 162 | self |
372 | 162 | } <wasm_encoder::component::canonicals::CanonicalFunctionSection>::future_write::<<wit_component::encoding::RequiredOptions>::into_iter::Iter> Line | Count | Source | 362 | 162 | pub fn future_write<O>(&mut self, ty: u32, options: O) -> &mut Self | 363 | 162 | where | 364 | 162 | O: IntoIterator<Item = CanonicalOption>, | 365 | 162 | O::IntoIter: ExactSizeIterator, | 366 | | { | 367 | 162 | self.bytes.push(0x17); | 368 | 162 | ty.encode(&mut self.bytes); | 369 | 162 | self.encode_options(options); | 370 | 162 | self.num_added += 1; | 371 | 162 | self | 372 | 162 | } |
Unexecuted instantiation: <wasm_encoder::component::canonicals::CanonicalFunctionSection>::future_write::<_> |
373 | | |
374 | | /// Defines a function to cancel an in-progress read from a `future` of the |
375 | | /// specified type. |
376 | 663 | pub fn future_cancel_read(&mut self, ty: u32, async_: bool) -> &mut Self { |
377 | 663 | self.bytes.push(0x18); |
378 | 663 | ty.encode(&mut self.bytes); |
379 | 663 | self.bytes.push(if async_ { 1 } else { 0 }); |
380 | 663 | self.num_added += 1; |
381 | 663 | self |
382 | 663 | } |
383 | | |
384 | | /// Defines a function to cancel an in-progress write to a `future` of the |
385 | | /// specified type. |
386 | 663 | pub fn future_cancel_write(&mut self, ty: u32, async_: bool) -> &mut Self { |
387 | 663 | self.bytes.push(0x19); |
388 | 663 | ty.encode(&mut self.bytes); |
389 | 663 | self.bytes.push(if async_ { 1 } else { 0 }); |
390 | 663 | self.num_added += 1; |
391 | 663 | self |
392 | 663 | } |
393 | | |
394 | | /// Defines a function to drop the readable end of a `future` of the |
395 | | /// specified type. |
396 | 663 | pub fn future_drop_readable(&mut self, ty: u32) -> &mut Self { |
397 | 663 | self.bytes.push(0x1a); |
398 | 663 | ty.encode(&mut self.bytes); |
399 | 663 | self.num_added += 1; |
400 | 663 | self |
401 | 663 | } |
402 | | |
403 | | /// Defines a function to drop the writable end of a `future` of the |
404 | | /// specified type. |
405 | 663 | pub fn future_drop_writable(&mut self, ty: u32) -> &mut Self { |
406 | 663 | self.bytes.push(0x1b); |
407 | 663 | ty.encode(&mut self.bytes); |
408 | 663 | self.num_added += 1; |
409 | 663 | self |
410 | 663 | } |
411 | | |
412 | | /// Defines a function to create a new `error-context` with a specified |
413 | | /// debug message. |
414 | 0 | pub fn error_context_new<O>(&mut self, options: O) -> &mut Self |
415 | 0 | where |
416 | 0 | O: IntoIterator<Item = CanonicalOption>, |
417 | 0 | O::IntoIter: ExactSizeIterator, |
418 | | { |
419 | 0 | self.bytes.push(0x1c); |
420 | 0 | self.encode_options(options); |
421 | 0 | self.num_added += 1; |
422 | 0 | self |
423 | 0 | } Unexecuted instantiation: <wasm_encoder::component::canonicals::CanonicalFunctionSection>::error_context_new::<<wit_component::encoding::RequiredOptions>::into_iter::Iter> Unexecuted instantiation: <wasm_encoder::component::canonicals::CanonicalFunctionSection>::error_context_new::<_> |
424 | | |
425 | | /// Defines a function to get the debug message for a specified |
426 | | /// `error-context`. |
427 | | /// |
428 | | /// Note that the debug message might not necessarily match what was passed |
429 | | /// to `error-context.new`. |
430 | 0 | pub fn error_context_debug_message<O>(&mut self, options: O) -> &mut Self |
431 | 0 | where |
432 | 0 | O: IntoIterator<Item = CanonicalOption>, |
433 | 0 | O::IntoIter: ExactSizeIterator, |
434 | | { |
435 | 0 | self.bytes.push(0x1d); |
436 | 0 | self.encode_options(options); |
437 | 0 | self.num_added += 1; |
438 | 0 | self |
439 | 0 | } Unexecuted instantiation: <wasm_encoder::component::canonicals::CanonicalFunctionSection>::error_context_debug_message::<<wit_component::encoding::RequiredOptions>::into_iter::Iter> Unexecuted instantiation: <wasm_encoder::component::canonicals::CanonicalFunctionSection>::error_context_debug_message::<_> |
440 | | |
441 | | /// Defines a function to drop a specified `error-context`. |
442 | 0 | pub fn error_context_drop(&mut self) -> &mut Self { |
443 | 0 | self.bytes.push(0x1e); |
444 | 0 | self.num_added += 1; |
445 | 0 | self |
446 | 0 | } |
447 | | |
448 | | /// Declare a new `waitable-set.new` intrinsic, used to create a |
449 | | /// `waitable-set` pseudo-resource. |
450 | 689 | pub fn waitable_set_new(&mut self) -> &mut Self { |
451 | 689 | self.bytes.push(0x1f); |
452 | 689 | self.num_added += 1; |
453 | 689 | self |
454 | 689 | } |
455 | | |
456 | | /// Declare a new `waitable-set.wait` intrinsic, used to block on a |
457 | | /// `waitable-set`. |
458 | 689 | pub fn waitable_set_wait(&mut self, memory: u32) -> &mut Self { |
459 | 689 | self.bytes.push(0x20); |
460 | 689 | self.bytes.push(0); |
461 | 689 | memory.encode(&mut self.bytes); |
462 | 689 | self.num_added += 1; |
463 | 689 | self |
464 | 689 | } |
465 | | |
466 | | /// Declare a new `waitable-set.wait` intrinsic, used to check, without |
467 | | /// blocking, if anything in a `waitable-set` is ready. |
468 | 689 | pub fn waitable_set_poll(&mut self, memory: u32) -> &mut Self { |
469 | 689 | self.bytes.push(0x21); |
470 | 689 | self.bytes.push(0); |
471 | 689 | memory.encode(&mut self.bytes); |
472 | 689 | self.num_added += 1; |
473 | 689 | self |
474 | 689 | } |
475 | | |
476 | | /// Declare a new `waitable-set.drop` intrinsic, used to dispose a |
477 | | /// `waitable-set` pseudo-resource. |
478 | 689 | pub fn waitable_set_drop(&mut self) -> &mut Self { |
479 | 689 | self.bytes.push(0x22); |
480 | 689 | self.num_added += 1; |
481 | 689 | self |
482 | 689 | } |
483 | | |
484 | | /// Declare a new `waitable.join` intrinsic, used to add an item to a |
485 | | /// `waitable-set`. |
486 | 689 | pub fn waitable_join(&mut self) -> &mut Self { |
487 | 689 | self.bytes.push(0x23); |
488 | 689 | self.num_added += 1; |
489 | 689 | self |
490 | 689 | } |
491 | | |
492 | | /// Declare a new `thread.index` intrinsic, used to get the index of the |
493 | | /// current thread. |
494 | 0 | pub fn thread_index(&mut self) -> &mut Self { |
495 | 0 | self.bytes.push(0x26); |
496 | 0 | self.num_added += 1; |
497 | 0 | self |
498 | 0 | } |
499 | | |
500 | | /// Declare a new `thread.new-indirect` intrinsic, used to create a new |
501 | | /// thread by invoking a function indirectly through a `funcref` table. |
502 | 0 | pub fn thread_new_indirect(&mut self, ty_index: u32, table_index: u32) -> &mut Self { |
503 | 0 | self.bytes.push(0x27); |
504 | 0 | ty_index.encode(&mut self.bytes); |
505 | 0 | table_index.encode(&mut self.bytes); |
506 | 0 | self.num_added += 1; |
507 | 0 | self |
508 | 0 | } |
509 | | |
510 | | /// Declare a new `thread.resume-later` intrinsic. |
511 | 0 | pub fn thread_resume_later(&mut self) -> &mut Self { |
512 | 0 | self.bytes.push(0x28); |
513 | 0 | self.num_added += 1; |
514 | 0 | self |
515 | 0 | } |
516 | | |
517 | | /// Declare a new `thread.suspend` intrinsic. |
518 | 0 | pub fn thread_suspend(&mut self) -> &mut Self { |
519 | 0 | self.bytes.push(0x29); |
520 | 0 | self.bytes.push(0); |
521 | 0 | self.num_added += 1; |
522 | 0 | self |
523 | 0 | } |
524 | | |
525 | | /// Declare a new `thread.yield` intrinsic. |
526 | 689 | pub fn thread_yield(&mut self) -> &mut Self { |
527 | 689 | self.bytes.push(0x0c); |
528 | 689 | self.bytes.push(0); |
529 | 689 | self.num_added += 1; |
530 | 689 | self |
531 | 689 | } |
532 | | |
533 | | /// Declare a new `thread.suspend-then-resume` intrinsic. |
534 | 0 | pub fn thread_suspend_then_resume(&mut self) -> &mut Self { |
535 | 0 | self.bytes.push(0x2a); |
536 | 0 | self.bytes.push(0); |
537 | 0 | self.num_added += 1; |
538 | 0 | self |
539 | 0 | } |
540 | | |
541 | | /// Declare a new `thread.yield-then-resume` intrinsic. |
542 | 0 | pub fn thread_yield_then_resume(&mut self) -> &mut Self { |
543 | 0 | self.bytes.push(0x2b); |
544 | 0 | self.bytes.push(0); |
545 | 0 | self.num_added += 1; |
546 | 0 | self |
547 | 0 | } |
548 | | |
549 | | /// Declare a new `thread.suspend-then-promote` intrinsic. |
550 | 0 | pub fn thread_suspend_then_promote(&mut self) -> &mut Self { |
551 | 0 | self.bytes.push(0x2c); |
552 | 0 | self.bytes.push(0); |
553 | 0 | self.num_added += 1; |
554 | 0 | self |
555 | 0 | } |
556 | | |
557 | | /// Declare a new `thread.yield-then-promote` intrinsic. |
558 | 0 | pub fn thread_yield_then_promote(&mut self) -> &mut Self { |
559 | 0 | self.bytes.push(0x2d); |
560 | 0 | self.bytes.push(0); |
561 | 0 | self.num_added += 1; |
562 | 0 | self |
563 | 0 | } |
564 | | |
565 | 9.86k | fn encode_options<O>(&mut self, options: O) -> &mut Self |
566 | 9.86k | where |
567 | 9.86k | O: IntoIterator<Item = CanonicalOption>, |
568 | 9.86k | O::IntoIter: ExactSizeIterator, |
569 | | { |
570 | 9.86k | let options = options.into_iter(); |
571 | 9.86k | options.len().encode(&mut self.bytes); |
572 | 9.99k | for option in options { |
573 | 9.99k | option.encode(&mut self.bytes); |
574 | 9.99k | } |
575 | 9.86k | self |
576 | 9.86k | } <wasm_encoder::component::canonicals::CanonicalFunctionSection>::encode_options::<alloc::vec::Vec<wasm_encoder::component::canonicals::CanonicalOption>> Line | Count | Source | 565 | 8.95k | fn encode_options<O>(&mut self, options: O) -> &mut Self | 566 | 8.95k | where | 567 | 8.95k | O: IntoIterator<Item = CanonicalOption>, | 568 | 8.95k | O::IntoIter: ExactSizeIterator, | 569 | | { | 570 | 8.95k | let options = options.into_iter(); | 571 | 8.95k | options.len().encode(&mut self.bytes); | 572 | 8.95k | for option in options { | 573 | 8.36k | option.encode(&mut self.bytes); | 574 | 8.36k | } | 575 | 8.95k | self | 576 | 8.95k | } |
<wasm_encoder::component::canonicals::CanonicalFunctionSection>::encode_options::<<wit_component::encoding::RequiredOptions>::into_iter::Iter> Line | Count | Source | 565 | 909 | fn encode_options<O>(&mut self, options: O) -> &mut Self | 566 | 909 | where | 567 | 909 | O: IntoIterator<Item = CanonicalOption>, | 568 | 909 | O::IntoIter: ExactSizeIterator, | 569 | | { | 570 | 909 | let options = options.into_iter(); | 571 | 909 | options.len().encode(&mut self.bytes); | 572 | 1.62k | for option in options { | 573 | 1.62k | option.encode(&mut self.bytes); | 574 | 1.62k | } | 575 | 909 | self | 576 | 909 | } |
Unexecuted instantiation: <wasm_encoder::component::canonicals::CanonicalFunctionSection>::encode_options::<alloc::vec::Vec<wasm_encoder::component::canonicals::CanonicalOption>> Unexecuted instantiation: <wasm_encoder::component::canonicals::CanonicalFunctionSection>::encode_options::<_> |
577 | | } |
578 | | |
579 | | impl Encode for CanonicalFunctionSection { |
580 | 12.0k | fn encode(&self, sink: &mut Vec<u8>) { |
581 | 12.0k | encode_section(sink, self.num_added, &self.bytes); |
582 | 12.0k | } |
583 | | } |
584 | | |
585 | | impl ComponentSection for CanonicalFunctionSection { |
586 | 12.0k | fn id(&self) -> u8 { |
587 | 12.0k | ComponentSectionId::CanonicalFunction.into() |
588 | 12.0k | } |
589 | | } |