Repository: MystenLabs/sui
File: external-crates/move/crates/move-vm-runtime/src/jit/execution/ast.rs (Rust)

Code before:
    pub fn get_native(
        &self,
        interner: &IdentifierInterner,
    ) -> PartialVMResult<&UnboxedNativeFunction> {
        if cfg!(feature = "lazy_natives") {
            // If lazy_natives is configured, this is a MISSING_DEPENDENCY error, as we skip
            // checking those at module loading time.
            self.native.as_deref().ok_or_else(|| {
                PartialVMError::new(StatusCode::MISSING_DEPENDENCY).with_message(format!(
                    "Missing Native Function `{}`",
                    self.name.member_name(interner).unwrap()
                ))
            })
        } else {
            // Otherwise this error should not happen, hence UNREACHABLE
            self.native.as_deref().ok_or_else(|| {
                PartialVMError::new(StatusCode::UNREACHABLE)
                    .with_message("Missing Native Function".to_string())
            })
        }
    }
}

impl CallType {
    fn vtable_key(&self) -> &VirtualTableKey {
        match self {
            CallType::Direct(vmpointer) => vmpointer.vtable_key(),
            CallType::Virtual(vtable_key) => vtable_key,
        }
    }
}

impl StructDef {
    pub fn datatype(&self) -> Type {
        Type::Datatype(self.def_vtable_key.clone())
    }

    pub fn field_count(&self) -> usize {
        self.fields.len()
    }
}

impl EnumDef {
    pub fn datatype(&self) -> Type {
        Type::Datatype(self.def_vtable_key.clone())
    }
}

impl VariantDef {
    pub fn datatype(&self) -> Type {
        Type::Datatype(self.enum_def.to_ref().def_vtable_key.clone())

Review comment (bug):
Should we try to get the member name here? (even if we fail, we could just not unwrap or do an `ok_or_else` for the name).

Code after:
            .to_string(interner)
            .expect("Identifier interner error: function virtual name not found")
    }

    pub fn pretty_short_string(&self, interner: &IdentifierInterner) -> String {
        // [SAFETY] If this is an error, that means we have an uninterned identifier key, which
        // should never happen in a well-formed module. This is as good a time to panic as any.
        self.name
            .to_short_string(interner)
            .expect("Identifier interner error: function short name not found")
    }

    pub fn is_native(&self) -> bool {
        self.def_is_native
    }

    pub fn get_native(
        &self,
        _interner: &IdentifierInterner,
    ) -> PartialVMResult<&UnboxedNativeFunction> {
        if cfg!(feature = "lazy_natives") {
            // If lazy_natives is configured, this is a MISSING_DEPENDENCY error, as we skip
            // checking those at module loading time.
            self.native.as_deref().ok_or_else(|| {
                PartialVMError::new(StatusCode::MISSING_DEPENDENCY)
                    .with_message("Missing Native Function".to_string())
            })
        } else {
            // Otherwise this error should not happen, hence UNREACHABLE
            self.native.as_deref().ok_or_else(|| {
                PartialVMError::new(StatusCode::UNREACHABLE)
                    .with_message("Missing Native Function".to_string())
            })
        }
    }
}

impl CallType {
    fn vtable_key(&self) -> &VirtualTableKey {
        match self {
            CallType::Direct(vmpointer) => vmpointer.vtable_key(),
            CallType::Virtual(vtable_key) => vtable_key,
        }
    }
}

impl StructDef {
    pub fn datatype(&self) -> Type {
        Type::Datatype(self.def_vtable_key.clone())
    }