Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Export some functions related to TypeTag for the NativeContext #1054

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions language/move-vm/runtime/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ impl Loader {
pub(crate) fn load_type(
&self,
type_tag: &TypeTag,
data_store: &impl DataStore,
data_store: &(impl DataStore + ?Sized),
) -> VMResult<Type> {
Ok(match type_tag {
TypeTag::Bool => Type::Bool,
Expand Down Expand Up @@ -977,7 +977,7 @@ impl Loader {
pub(crate) fn load_module(
&self,
id: &ModuleId,
data_store: &impl DataStore,
data_store: &(impl DataStore + ?Sized),
) -> VMResult<Arc<Module>> {
self.load_module_internal(id, &BTreeMap::new(), &BTreeSet::new(), data_store)
}
Expand All @@ -989,7 +989,7 @@ impl Loader {
id: &ModuleId,
bundle_verified: &BTreeMap<ModuleId, CompiledModule>,
bundle_unverified: &BTreeSet<ModuleId>,
data_store: &impl DataStore,
data_store: &(impl DataStore + ?Sized),
) -> VMResult<Arc<Module>> {
// if the module is already in the code cache, load the cached version
if let Some(cached) = self.module_cache.read().module_at(id) {
Expand Down Expand Up @@ -1021,7 +1021,7 @@ impl Loader {
fn load_and_verify_module(
&self,
id: &ModuleId,
data_store: &impl DataStore,
data_store: &(impl DataStore + ?Sized),
allow_loading_failure: bool,
) -> VMResult<CompiledModule> {
// bytes fetching, allow loading to fail if the flag is set
Expand Down Expand Up @@ -1072,7 +1072,7 @@ impl Loader {
&self,
id: &ModuleId,
bundle_verified: &BTreeMap<ModuleId, CompiledModule>,
data_store: &impl DataStore,
data_store: &(impl DataStore + ?Sized),
visited: &mut BTreeSet<ModuleId>,
friends_discovered: &mut BTreeSet<ModuleId>,
allow_module_loading_failure: bool,
Expand Down Expand Up @@ -1114,7 +1114,7 @@ impl Loader {
&self,
module: &CompiledModule,
bundle_verified: &BTreeMap<ModuleId, CompiledModule>,
data_store: &impl DataStore,
data_store: &(impl DataStore + ?Sized),
visited: &mut BTreeSet<ModuleId>,
friends_discovered: &mut BTreeSet<ModuleId>,
allow_dependency_loading_failure: bool,
Expand Down Expand Up @@ -1183,7 +1183,7 @@ impl Loader {
id: &ModuleId,
bundle_verified: &BTreeMap<ModuleId, CompiledModule>,
bundle_unverified: &BTreeSet<ModuleId>,
data_store: &impl DataStore,
data_store: &(impl DataStore + ?Sized),
allow_module_loading_failure: bool,
dependencies_depth: usize,
) -> VMResult<Arc<Module>> {
Expand Down Expand Up @@ -1220,7 +1220,7 @@ impl Loader {
friends_discovered: BTreeSet<ModuleId>,
bundle_verified: &BTreeMap<ModuleId, CompiledModule>,
bundle_unverified: &BTreeSet<ModuleId>,
data_store: &impl DataStore,
data_store: &(impl DataStore + ?Sized),
allow_friend_loading_failure: bool,
dependencies_depth: usize,
) -> VMResult<()> {
Expand Down Expand Up @@ -2829,7 +2829,7 @@ impl Loader {
pub(crate) fn get_type_layout(
&self,
type_tag: &TypeTag,
move_storage: &impl DataStore,
move_storage: &(impl DataStore + ?Sized),
) -> VMResult<MoveTypeLayout> {
let ty = self.load_type(type_tag, move_storage)?;
self.type_to_type_layout(&ty)
Expand All @@ -2839,7 +2839,7 @@ impl Loader {
pub(crate) fn get_fully_annotated_type_layout(
&self,
type_tag: &TypeTag,
move_storage: &impl DataStore,
move_storage: &(impl DataStore + ?Sized),
) -> VMResult<MoveTypeLayout> {
let ty = self.load_type(type_tag, move_storage)?;
self.type_to_fully_annotated_layout(&ty)
Expand Down
18 changes: 17 additions & 1 deletion language/move-vm/runtime/src/native_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use crate::{
interpreter::Interpreter, loader::Resolver, native_extensions::NativeContextExtensions,
};
use move_binary_format::errors::{ExecutionState, PartialVMError, PartialVMResult};
use move_binary_format::errors::{ExecutionState, PartialVMError, PartialVMResult, VMResult};
use move_core_types::{
account_address::AccountAddress,
gas_algebra::InternalGas,
Expand Down Expand Up @@ -140,6 +140,22 @@ impl<'a, 'b> NativeContext<'a, 'b> {
self.data_store.events()
}

pub fn load_type(&self, type_tag: &TypeTag) -> VMResult<Type> {
self.resolver.loader().load_type(type_tag, self.data_store)
}

pub fn get_type_layout(&self, type_tag: &TypeTag) -> VMResult<MoveTypeLayout> {
self.resolver
.loader()
.get_type_layout(type_tag, self.data_store)
}

pub fn get_fully_annotated_type_layout(&self, type_tag: &TypeTag) -> VMResult<MoveTypeLayout> {
self.resolver
.loader()
.get_fully_annotated_type_layout(type_tag, self.data_store)
}

pub fn type_to_type_tag(&self, ty: &Type) -> PartialVMResult<TypeTag> {
self.resolver.loader().type_to_type_tag(ty)
}
Expand Down
7 changes: 6 additions & 1 deletion language/move-vm/runtime/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,12 @@ impl<'r, 'l, S: MoveResolver> Session<'r, 'l, S> {
}

/// Gets the underlying native extensions.
pub fn get_native_extensions(&mut self) -> &mut NativeContextExtensions<'r> {
pub fn get_native_extensions(&self) -> &NativeContextExtensions<'r> {
&self.native_extensions
}

/// Gets the underlying native extensions as mut.
pub fn get_native_extensions_mut(&mut self) -> &mut NativeContextExtensions<'r> {
&mut self.native_extensions
}
}
Expand Down