Skip to content

Commit 77d92f6

Browse files
authored
Move suivm to latest (#13814)
## Description Move suivm to latest. Suivm is getting in the way of a bunch of work happening in the execution layer. This is also showing the issues related to branches that are live for long. It is at times inevitable but we need to be careful about what people review and how to go back to latest. Hopefully the work to make latest the working branch will make this less of a problem. We'll see ## Test Plan Existing tests --- If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process. ### Type of Change (Check all that apply) - [ ] protocol change - [ ] user-visible impact - [ ] breaking change for a client SDKs - [ ] breaking change for FNs (FN binary must upgrade) - [ ] breaking change for validators or node operators (must upgrade binaries) - [ ] breaking change for on-chain data layout - [ ] necessitate either a data wipe or data migration ### Release notes
1 parent 24cb7c8 commit 77d92f6

File tree

3 files changed

+104
-6
lines changed

3 files changed

+104
-6
lines changed

move-vm/runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub mod logging;
1717
pub mod move_vm;
1818
pub mod native_extensions;
1919
pub mod native_functions;
20-
mod runtime;
20+
pub mod runtime;
2121
pub mod session;
2222
#[macro_use]
2323
mod tracing;

move-vm/runtime/src/move_vm.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,8 @@ impl MoveVM {
101101
pub fn get_module_metadata(&self, module: ModuleId, key: &[u8]) -> Option<Metadata> {
102102
self.runtime.loader().get_metadata(module, key)
103103
}
104+
105+
pub fn get_runtime(&self) -> &VMRuntime {
106+
&self.runtime
107+
}
104108
}

move-vm/runtime/src/runtime.rs

Lines changed: 99 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ use crate::{
1313
use move_binary_format::{
1414
access::ModuleAccess,
1515
errors::{verification_error, Location, PartialVMError, PartialVMResult, VMResult},
16-
file_format::LocalIndex,
16+
file_format::{AbilitySet, LocalIndex},
1717
CompiledModule, IndexKind,
1818
};
1919
use move_bytecode_verifier::script_signature;
2020
use move_core_types::{
2121
account_address::AccountAddress,
2222
identifier::{IdentStr, Identifier},
23-
language_storage::ModuleId,
23+
language_storage::{ModuleId, TypeTag},
2424
resolver::MoveResolver,
2525
value::MoveTypeLayout,
2626
vm_status::StatusCode,
@@ -31,14 +31,14 @@ use move_vm_profiler::GasProfiler;
3131
use move_vm_types::{
3232
data_store::DataStore,
3333
gas::GasMeter,
34-
loaded_data::runtime_types::Type,
34+
loaded_data::runtime_types::{CachedStructIndex, StructType, Type},
3535
values::{Locals, Reference, VMValueCast, Value},
3636
};
3737
use std::{borrow::Borrow, collections::BTreeSet, sync::Arc};
3838
use tracing::warn;
3939

4040
/// An instantiation of the MoveVM.
41-
pub(crate) struct VMRuntime {
41+
pub struct VMRuntime {
4242
loader: Loader,
4343
}
4444

@@ -68,7 +68,7 @@ impl VMRuntime {
6868
}
6969
}
7070

71-
pub(crate) fn publish_module_bundle(
71+
pub fn publish_module_bundle(
7272
&self,
7373
modules: Vec<Vec<u8>>,
7474
sender: AccountAddress,
@@ -482,4 +482,98 @@ impl VMRuntime {
482482
pub(crate) fn loader(&self) -> &Loader {
483483
&self.loader
484484
}
485+
486+
pub fn get_type_abilities(&self, ty: &Type) -> VMResult<AbilitySet> {
487+
self.loader
488+
.abilities(ty)
489+
.map_err(|e| e.finish(Location::Undefined))
490+
}
491+
492+
pub fn get_type_tag(&self, ty: &Type) -> VMResult<TypeTag> {
493+
self.loader
494+
.type_to_type_tag(ty)
495+
.map_err(|e| e.finish(Location::Undefined))
496+
}
497+
498+
pub fn get_struct_type(&self, index: CachedStructIndex) -> Option<Arc<StructType>> {
499+
self.loader.get_struct_type(index)
500+
}
501+
502+
pub fn type_to_type_layout(&self, ty: &Type) -> VMResult<MoveTypeLayout> {
503+
self.loader
504+
.type_to_type_layout(ty)
505+
.map_err(|e| e.finish(Location::Undefined))
506+
}
507+
508+
pub fn load_struct(
509+
&self,
510+
module_id: &ModuleId,
511+
struct_name: &IdentStr,
512+
data_store: &impl DataStore,
513+
) -> VMResult<(CachedStructIndex, Arc<StructType>)> {
514+
self.loader
515+
.load_struct_by_name(struct_name, module_id, data_store)
516+
}
517+
518+
pub fn execute_function_bypass_visibility(
519+
&self,
520+
module: &ModuleId,
521+
function_name: &IdentStr,
522+
ty_args: Vec<Type>,
523+
args: Vec<impl Borrow<[u8]>>,
524+
data_store: &mut impl DataStore,
525+
gas_meter: &mut impl GasMeter,
526+
extensions: &mut NativeContextExtensions,
527+
) -> VMResult<SerializedReturnValues> {
528+
#[cfg(debug_assertions)]
529+
{
530+
if gas_meter.get_profiler_mut().is_none() {
531+
gas_meter.set_profiler(GasProfiler::init_default_cfg(
532+
function_name.to_string(),
533+
gas_meter.remaining_gas().into(),
534+
));
535+
}
536+
}
537+
538+
let bypass_declared_entry_check = true;
539+
self.execute_function(
540+
module,
541+
function_name,
542+
ty_args,
543+
args,
544+
data_store,
545+
gas_meter,
546+
extensions,
547+
bypass_declared_entry_check,
548+
)
549+
}
550+
551+
pub fn type_to_fully_annotated_layout(&self, ty: &Type) -> VMResult<MoveTypeLayout> {
552+
self.loader
553+
.type_to_fully_annotated_layout(ty)
554+
.map_err(|e| e.finish(Location::Undefined))
555+
}
556+
557+
pub fn load_function(
558+
&self,
559+
module_id: &ModuleId,
560+
function_name: &IdentStr,
561+
type_arguments: &[Type],
562+
data_store: &mut impl DataStore,
563+
) -> VMResult<LoadedFunctionInstantiation> {
564+
let (_, _, _, instantiation) =
565+
self.loader
566+
.load_function(module_id, function_name, type_arguments, data_store)?;
567+
Ok(instantiation)
568+
}
569+
570+
pub fn load_module(
571+
&self,
572+
module_id: &ModuleId,
573+
data_store: &impl DataStore,
574+
) -> VMResult<Arc<CompiledModule>> {
575+
self.loader
576+
.load_module(module_id, data_store)
577+
.map(|(compiled, _)| compiled)
578+
}
485579
}

0 commit comments

Comments
 (0)