MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / try_def_var

Method try_def_var

cranelift/frontend/src/frontend.rs:489–503  ·  view source on GitHub ↗

Registers a new definition of a user variable. This function will return an error if the value supplied does not match the type the variable was declared to have.

(&mut self, var: Variable, val: Value)

Source from the content-addressed store, hash-verified

487 /// an error if the value supplied does not match the type the variable was
488 /// declared to have.
489 pub fn try_def_var(&mut self, var: Variable, val: Value) -> Result<(), DefVariableError> {
490 log::trace!("try_def_var: {var:?} = {val:?}");
491
492 let var_ty = *self
493 .func_ctx
494 .variables
495 .get(var)
496 .ok_or(DefVariableError::DefinedBeforeDeclared(var))?;
497 if var_ty != self.func.dfg.value_type(val) {
498 return Err(DefVariableError::TypeMismatch(var, val));
499 }
500
501 self.func_ctx.ssa.def_var(var, val, self.position.unwrap());
502 Ok(())
503 }
504
505 /// Register a new definition of a user variable. The type of the value must be
506 /// the same as the type registered for the variable.

Callers 1

def_varMethod · 0.80

Calls 5

OkFunction · 0.85
getMethod · 0.45
value_typeMethod · 0.45
def_varMethod · 0.45
unwrapMethod · 0.45

Tested by

no test coverage detected