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

Code before:
}

// A runtime constant
#[derive(Debug)]
pub struct Constant {
    pub(crate) value: ConstantValue,
    pub(crate) type_: ArenaType,
    // Size of constant -- used for gas charging.
    pub size: u64,
}

// A runtime function
// #[derive(Debug)]
// https://github.com/rust-lang/rust/issues/70263
pub struct Function {
    #[allow(unused)]
    pub file_format_version: u32,
    pub is_entry: bool,
    pub visibility: Visibility,
    pub index: FunctionDefinitionIndex,
    pub(crate) code: ArenaVec<Bytecode>,
    pub(crate) parameters: ArenaVec<ArenaType>,
    pub(crate) locals: ArenaVec<ArenaType>,
    pub(crate) return_: ArenaVec<ArenaType>,
    pub(crate) type_parameters: ArenaVec<AbilitySet>,
    // NOTE: This field is manually dropped in Module::drop() to prevent Arc leaks
    pub native: Option<NativeFunction>,
    pub def_is_native: bool,
    pub name: VirtualTableKey,
    pub locals_len: usize,
    pub jump_tables: ArenaVec<VariantJumpTable>,
}

impl Drop for Function {
    fn drop(&mut self) {
        // Take ownership of the Arc and drop it
        if let Some(native_fn) = self.native.take() {
            drop(native_fn);
        }
    }
}

// A variant jump table -- note that these are only full at the moment.
pub type VariantJumpTable = ArenaVec<CodeOffset>;

//
// Internal structures that are saved at the proper index in the proper tables to access
// execution information (interpreter).
// The following structs are internal to the loader and never exposed out.
// The `Loader` will create those struct and the proper table when loading a module.
// The `Resolver` uses those structs to return information to the `Interpreter`.

Review comment (suggestion):
```suggestion
    // NOTE: This field is manually dropped in Function::drop() to prevent Arc leaks
    // Any value holding a `Function` needs to ensure it is correctly dropped.
```

Code after:

// A runtime constant
#[derive(Debug)]
pub struct Constant {
    pub(crate) value: ConstantValue,
    pub(crate) type_: ArenaType,
    // Size of constant -- used for gas charging.
    pub size: u64,
}

// A runtime function
// #[derive(Debug)]
// https://github.com/rust-lang/rust/issues/70263
pub struct Function {
    #[allow(unused)]
    pub file_format_version: u32,
    pub is_entry: bool,
    pub visibility: Visibility,
    pub index: FunctionDefinitionIndex,
    pub(crate) code: ArenaVec<Bytecode>,
    pub(crate) parameters: ArenaVec<ArenaType>,
    pub(crate) locals: ArenaVec<ArenaType>,
    pub(crate) return_: ArenaVec<ArenaType>,
    pub(crate) type_parameters: ArenaVec<AbilitySet>,
    // NOTE: This field is manually dropped in Function::drop() to prevent Arc leaks
    // Any value holding a `Function` needs to ensure it is correctly dropped.
    pub native: Option<NativeFunction>,
    pub def_is_native: bool,
    pub name: VirtualTableKey,
    pub locals_len: usize,
    pub jump_tables: ArenaVec<VariantJumpTable>,
}

impl Drop for Function {
    fn drop(&mut self) {
        // Take ownership of the Arc and drop it
        if let Some(native_fn) = self.native.take() {
            drop(native_fn);
        }
    }
}

// A variant jump table -- note that these are only full at the moment.
pub type VariantJumpTable = ArenaVec<CodeOffset>;

//
// Internal structures that are saved at the proper index in the proper tables to access
// execution information (interpreter).
// The following structs are internal to the loader and never exposed out.
// The `Loader` will create those struct and the proper table when loading a module.
// The `Resolver` uses those structs to return information to the `Interpreter`.