Struct wasmtime_types::ConstExpr
source · pub struct ConstExpr { /* private fields */ }
Expand description
A constant expression.
These are used to initialize globals, table elements, etc…
Implementations§
source§impl ConstExpr
impl ConstExpr
sourcepub fn new(ops: impl IntoIterator<Item = ConstOp>) -> Self
pub fn new(ops: impl IntoIterator<Item = ConstOp>) -> Self
Create a new const expression from the given opcodes.
Does not do any validation that the const expression is well-typed.
Panics if given zero opcodes.
sourcepub fn from_wasmparser(
expr: ConstExpr<'_>,
) -> WasmResult<(Self, SmallVec<[FuncIndex; 1]>)>
pub fn from_wasmparser( expr: ConstExpr<'_>, ) -> WasmResult<(Self, SmallVec<[FuncIndex; 1]>)>
Create a new const expression from a wasmparser
const expression.
Returns the new const expression as well as the escaping function
indices that appeared in ref.func
instructions, if any.
sourcepub fn provably_nonzero_i32(&self) -> bool
pub fn provably_nonzero_i32(&self) -> bool
Is this ConstExpr a provably nonzero integer value?
This must be conservative: if the expression might be zero,
it must return false
. It is always allowed to return false
for some expression kind that we don’t support. However, if it
returns true
, the expression must be actually nonzero.
We use this for certain table optimizations that rely on knowing for sure that index 0 is not referenced.