You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Mark the current control block as unreachable, removing all of the types pushed to the stack since the current control block was entered.
76
+
/// pop operations from the stack will yield `Ok(ValidationStackEntry::Bottom)` if the stack height is the same as the height when this control
77
+
/// block was entered.
78
+
///
79
+
/// Returns `Ok(())` if called during validation of a control block. `Returns Err(Error::ValidationCtrlStackEmpty)` if no control block context is found
/// Asserts that the values on top of the stack match those of a value iterator
219
-
/// This method will unify the types on the stack to the expected valtypes.
220
-
/// The last element of `expected_val_types` is unified to the top-most
221
-
/// [`ValidationStackEntry`], the second last `expected_val_types` element to the second top-most
222
-
/// [`ValidationStackEntry`] etc.
223
-
///
224
-
/// Any unification failure or arity mismatch will cause an error.
225
-
///
227
+
228
+
/// Assert that the types retrieved from the type stack by `pop_valtype` unify to `expected_val_types`, and
229
+
/// after this operation the type stack would be the same as the first time the current control block is entered.
230
+
/// This method will unify the types on the stack to the expected valtypes if `unify_to_expected_types` is set.
226
231
/// Any occurence of an error may leave the stack in an invalid state.
227
232
///
228
233
/// # Returns
229
234
///
230
-
/// - `Ok(_)`, the tail of the stack matches the `expected_val_types`
235
+
/// - `Ok(_)`, the tail of the stack unifies to the `expected_val_types`
231
236
/// - `Err(_)` otherwise
232
237
///
233
238
pub(super)fnassert_val_types_on_top(
@@ -243,16 +248,15 @@ impl ValidationStack {
243
248
)
244
249
}
245
250
246
-
// TODO better documentation
247
-
/// Asserts that the valtypes on the stack match the expected valtypes and no other type is on the stack.
248
-
/// This method will unify the types on the stack to the expected valtypes.
249
-
/// This starts by comparing the top-most valtype with the last element from `expected_val_types` and then continues downwards on the stack.
250
-
/// If a label is reached and not all `expected_val_types` have been checked, the assertion fails.
251
+
/// Assert that the types retrieved from the type stack by `pop_valtype` unify to `expected_val_types`.
252
+
/// This method will unify the types on the stack to the expected valtypes if `unify_to_expected_types` is set.
253
+
/// Any occurence of an error may leave the stack in an invalid state.
251
254
///
252
255
/// # Returns
253
256
///
254
-
/// - `Ok(())` if all expected valtypes were found
257
+
/// - `Ok(_)`, the tail of the stack unifies to the `expected_val_types`
255
258
/// - `Err(_)` otherwise
259
+
///
256
260
pubfnassert_val_types(
257
261
&mutself,
258
262
expected_val_types:&[ValType],
@@ -266,6 +270,15 @@ impl ValidationStack {
266
270
)
267
271
}
268
272
273
+
/// Call `assert_val_types_on_top` for the label signature of the `label_idx`th outer control block (0 corresponds to the current control block).
274
+
/// Label signature of all controi blocks are the output signature of the control blocks except for the Loop block. For Loop blocks, it is the input signature.
275
+
/// This method will unify the types on the stack to the expected valtypes if `unify_to_expected_types` is set.
276
+
///
277
+
/// # Returns
278
+
///
279
+
/// - `Ok(_)`, the tail of the stack unifies to the label signature of the `label_idx`th outer control block
280
+
/// - `Err(_)` otherwise
281
+
///
269
282
pubfnassert_val_types_of_label_jump_types_on_top(
270
283
&mutself,
271
284
label_idx:usize,
@@ -284,6 +297,14 @@ impl ValidationStack {
284
297
)
285
298
}
286
299
300
+
/// Signal to this struct that a new control block is entered, and calls `assert_val_types_on_top` with the input signature of the new control block.
301
+
/// This method will unify the types on the stack to the expected valtypes if `unify_to_expected_types` is set.
302
+
///
303
+
/// # Returns
304
+
///
305
+
/// - `Ok(_)`, the tail of the stack unifies to the input signature of the new control block
306
+
/// - `Err(_)` otherwise
307
+
///
287
308
pubfnassert_push_ctrl(
288
309
&mutself,
289
310
label_info:LabelInfo,
@@ -301,8 +322,14 @@ impl ValidationStack {
301
322
Ok(())
302
323
}
303
324
304
-
// TODO: rename/refactor this function to make it more clear that it ALSO
305
-
// checks the stack for valid return types.
325
+
/// Signal to this struct that the current control block is exited, and calls `assert_val_types_on_top` with the output signature of the new control block.
326
+
/// This method will unify the types on the stack to the expected valtypes if `unify_to_expected_types` is set.
327
+
///
328
+
/// # Returns
329
+
///
330
+
/// - `Ok(_)`, the tail of the stack unifies to the output signature of the current control block
331
+
/// - `Err(_)` otherwise
332
+
///
306
333
pubfnassert_pop_ctrl(
307
334
&mutself,
308
335
unify_to_expected_types:bool,
@@ -329,6 +356,7 @@ impl ValidationStack {
329
356
))
330
357
}
331
358
359
+
/// Validate the `SELECT` instruction within the current control block. Returns OK(()) on success, Err(_) otherwise.
0 commit comments