pub struct ValidationStack {
stack: Vec<ValidationStackEntry>,
pub ctrl_stack: Vec<CtrlStackEntry>,
}
Fields§
§stack: Vec<ValidationStackEntry>
§ctrl_stack: Vec<CtrlStackEntry>
Implementations§
Source§impl ValidationStack
impl ValidationStack
Sourcepub(super) fn new_for_func(block_ty: FuncType) -> Self
pub(super) fn new_for_func(block_ty: FuncType) -> Self
Initialize a new ValidationStack to validate a block of type block_ty
pub fn len(&self) -> usize
pub fn push_valtype(&mut self, valtype: ValType)
Sourcepub(super) fn drop_val(&mut self) -> Result<()>
pub(super) fn drop_val(&mut self) -> Result<()>
Similar to ValidationStack::pop_valtype
, because it pops a value from the stack,
but more public and doesn’t actually return the popped value.
Sourcepub(super) fn make_unspecified(&mut self) -> Result<()>
pub(super) fn make_unspecified(&mut self) -> Result<()>
Mark the current control block as unreachable, removing all of the types pushed to the stack since the current control block was entered.
pop operations from the stack will yield Ok(ValidationStackEntry::Bottom)
if the stack height is the same as the height when this control
block was entered.
Returns Ok(())
if called during validation of a control block. Returns Err(Error::ValidationCtrlStackEmpty)
if no control block context is found
in the control block stack.
Sourcefn pop_valtype(&mut self) -> Result<ValidationStackEntry>
fn pop_valtype(&mut self) -> Result<ValidationStackEntry>
Pop a ValidationStackEntry
from the ValidationStack
§Returns
- Returns
Ok(_)
with the former top-mostValidationStackEntry
inside, if the stack had at least one element pushed after the current control block is entered. May also returnOk(ValidationStackEntry::Bottom)
ifmake_unspecified
is called within the current control block. - Returns
Err(_)
otherwise.
Sourcepub fn assert_pop_ref_type(
&mut self,
expected_ty: Option<RefType>,
) -> Result<()>
pub fn assert_pop_ref_type( &mut self, expected_ty: Option<RefType>, ) -> Result<()>
Attempt popping Valtype::RefType(expected_ty)
from type stack.
§Returns
- Returns
Ok(())
ifValtype::RefType(expected_ty)
unifies to the item returned bypop_valtype
operation andErr(_)
otherwise.
Sourcepub fn assert_pop_val_type(&mut self, expected_ty: ValType) -> Result<()>
pub fn assert_pop_val_type(&mut self, expected_ty: ValType) -> Result<()>
Attempt popping expected_ty from type stack.
§Returns
- Returns
Ok(())
if expected_ty unifies to the item returned bypop_valtype
operation andErr(_)
otherwise.
fn assert_val_types_on_top_with_custom_stacks( stack: &mut Vec<ValidationStackEntry>, ctrl_stack: &[CtrlStackEntry], expected_val_types: &[ValType], unify_to_expected_types: bool, ) -> Result<()>
fn assert_val_types_with_custom_stacks( stack: &mut Vec<ValidationStackEntry>, ctrl_stack: &[CtrlStackEntry], expected_val_types: &[ValType], unify_to_expected_types: bool, ) -> Result<()>
Sourcepub(super) fn assert_val_types_on_top(
&mut self,
expected_val_types: &[ValType],
unify_to_expected_types: bool,
) -> Result<()>
pub(super) fn assert_val_types_on_top( &mut self, expected_val_types: &[ValType], unify_to_expected_types: bool, ) -> Result<()>
Assert that the types retrieved from the type stack by pop_valtype
unify to expected_val_types
, and
after this operation the type stack would be the same as the first time the current control block is entered.
This method will unify the types on the stack to the expected valtypes if unify_to_expected_types
is set.
Any occurence of an error may leave the stack in an invalid state.
§Returns
Ok(_)
, the tail of the stack unifies to theexpected_val_types
Err(_)
otherwise
Sourcepub fn assert_val_types(
&mut self,
expected_val_types: &[ValType],
unify_to_expected_types: bool,
) -> Result<()>
pub fn assert_val_types( &mut self, expected_val_types: &[ValType], unify_to_expected_types: bool, ) -> Result<()>
Assert that the types retrieved from the type stack by pop_valtype
unify to expected_val_types
.
This method will unify the types on the stack to the expected valtypes if unify_to_expected_types
is set.
Any occurence of an error may leave the stack in an invalid state.
§Returns
Ok(_)
, the tail of the stack unifies to theexpected_val_types
Err(_)
otherwise
Sourcepub fn assert_val_types_of_label_jump_types_on_top(
&mut self,
label_idx: usize,
unify_to_expected_types: bool,
) -> Result<()>
pub fn assert_val_types_of_label_jump_types_on_top( &mut self, label_idx: usize, unify_to_expected_types: bool, ) -> Result<()>
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).
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.
This method will unify the types on the stack to the expected valtypes if unify_to_expected_types
is set.
§Returns
Ok(_)
, the tail of the stack unifies to the label signature of thelabel_idx
th outer control blockErr(_)
otherwise
Sourcepub fn assert_push_ctrl(
&mut self,
label_info: LabelInfo,
block_ty: FuncType,
unify_to_expected_types: bool,
) -> Result<()>
pub fn assert_push_ctrl( &mut self, label_info: LabelInfo, block_ty: FuncType, unify_to_expected_types: bool, ) -> Result<()>
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.
This method will unify the types on the stack to the expected valtypes if unify_to_expected_types
is set.
§Returns
Ok(_)
, the tail of the stack unifies to the input signature of the new control blockErr(_)
otherwise
Sourcepub fn assert_pop_ctrl(
&mut self,
unify_to_expected_types: bool,
) -> Result<(LabelInfo, FuncType)>
pub fn assert_pop_ctrl( &mut self, unify_to_expected_types: bool, ) -> Result<(LabelInfo, FuncType)>
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.
This method will unify the types on the stack to the expected valtypes if unify_to_expected_types
is set.
§Returns
Ok(_)
, the tail of the stack unifies to the output signature of the current control blockErr(_)
otherwise
Sourcepub fn validate_polymorphic_select(&mut self) -> Result<()>
pub fn validate_polymorphic_select(&mut self) -> Result<()>
Validate the SELECT
instruction within the current control block. Returns OK(()) on success, Err(_) otherwise.