Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VM Values Rewrite #20172

Open
wants to merge 16 commits into
base: cgswords/linkage-split
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions external-crates/move/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Call Stack:
[16] CallGeneric(1)

Locals:
[0] false
[0] (&) false
[1] [true, false]
[2] -

Expand All @@ -47,7 +47,7 @@ Call Stack:

Locals:
[0] 3
[1] 3
[1] (&) 3
[2] -


Expand Down Expand Up @@ -151,7 +151,7 @@ Call Stack:

Locals:
[0] 3
[1] 3
[1] (&) 3
[2] -


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl TypeTag {
| TypeTag::U256
| TypeTag::Address
| TypeTag::Signer => (),
TypeTag::Vector(inner) => find_addresses_recur(account_addresses, &*inner),
TypeTag::Vector(inner) => find_addresses_recur(account_addresses, inner),
TypeTag::Struct(tag) => {
let StructTag {
address,
Expand Down
25 changes: 24 additions & 1 deletion external-crates/move/crates/move-proc-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, Data, DataEnum, DeriveInput, ItemFn};
use syn::{parse_macro_input, Data, DataEnum, DeriveInput, Ident, ItemFn};

/// This macro generates a function `order_to_variant_map` which returns a map
/// of the position of each variant to the name of the variant.
Expand Down Expand Up @@ -111,3 +111,26 @@ pub fn growing_stack(_attr: TokenStream, item: TokenStream) -> TokenStream {

output.into()
}

/// Procedural macro to parse an identifier and return it with the first letter capitalized.
#[proc_macro]
pub fn capitalize(input: TokenStream) -> TokenStream {
// Parse the input as an identifier
let ident = parse_macro_input!(input as Ident);

// Convert the identifier to a string
let mut ident_str = ident.to_string();

// Capitalize the first letter
ident_str[..1].make_ascii_uppercase();

// Create a new identifier with the capitalized string
let new_ident = Ident::new(&ident_str, ident.span());

// Generate and return the output TokenStream
let output = quote! {
#new_ident
};

output.into()
}
Original file line number Diff line number Diff line change
Expand Up @@ -372,23 +372,7 @@ pub fn format_vm_error(e: &VMError) -> String {
Location::Undefined => "undefined".to_owned(),
Location::Module(id) => format!("0x{}::{}", id.address().short_str_lossless(), id.name()),
};
// format!(
// "{{
// major_status: {major_status:?},
// sub_status: {sub_status:?},
// message: {message:?},
// location: {location_string},
// indices: {indices:?},
// offsets: {offsets:?},
// }}",
// major_status = e.major_status(),
// sub_status = e.sub_status(),
// message = e.message(),
// location_string = location_string,
// // TODO maybe include source map info?
// indices = e.indices(),
// offsets = e.offsets(),
// ) ;
format!(
"{{
major_status: {major_status:?},
Expand All @@ -403,6 +387,7 @@ pub fn format_vm_error(e: &VMError) -> String {
// TODO maybe include source map info?
indices = e.indices(),
offsets = e.offsets(),
// message = e.message(),
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module 0x6::M {
#[test]
fun unexpected_abort_in_native_function() {
abort_in_native()
}

fun abort_in_native() {
std::string::internal_sub_string_for_testing(&vector[0], 1, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,4 @@ module 0x6::M {
fun unexpected_abort_in_other_function() {
abort_in_other_function()
}


#[test]
fun unexpected_abort_in_native_function() {
abort_in_native()
}

fun abort_in_native() {
std::string::internal_sub_string_for_testing(&vector[0], 1, 0);
}
}
1 change: 1 addition & 0 deletions external-crates/move/crates/move-vm-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ move-compiler.workspace = true
memory-stats.workspace = true
tempfile.workspace = true
move-stdlib.workspace = true
move-proc-macros.workspace = true

[features]
default = []
Expand Down
48 changes: 45 additions & 3 deletions external-crates/move/crates/move-vm-runtime/src/cache/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,32 @@ impl<T> ArenaPointer<T> {

#[inline]
pub fn to_ref<'a>(self) -> &'a T {
to_ref(self.0)
to_ref(self.ptr_clone().0)
}

#[inline]
pub fn to_mut_ref<'a>(self) -> &'a mut T {
to_mut_ref(self.ptr_clone().0)
}

#[inline]
pub fn from_ref(t: &T) -> Self {
Self(t as *const T)
}

#[inline]
pub fn ptr_eq(&self, other: &Self) -> bool {
std::ptr::eq(self.0, other.0)
}

#[inline]
pub fn ptr_clone(&self) -> Self {
Self(self.0)
}

#[inline]
pub fn replace_ptr(&mut self, other: ArenaPointer<T>) {
self.0 = other.0;
}
}

Expand Down Expand Up @@ -98,6 +123,12 @@ pub fn to_ref<'a, T>(value: *const T) -> &'a T {
unsafe { &*value as &T }
}

#[allow(clippy::not_unsafe_ptr_arg_deref)]
#[inline]
pub fn to_mut_ref<'a, T>(value: *const T) -> &'a mut T {
unsafe { &mut *(value as *mut T) }
}

// -----------------------------------------------
// Trait Implementations
// -----------------------------------------------
Expand All @@ -120,16 +151,27 @@ impl<T: ::std::fmt::Debug> ::std::fmt::Debug for ArenaPointer<T> {
// Pointer equality
impl<T> PartialEq for ArenaPointer<T> {
fn eq(&self, other: &Self) -> bool {
std::ptr::eq(self.0, other.0)
self.ptr_eq(other)
}
}

impl<T> Eq for ArenaPointer<T> {}

impl<T> Clone for ArenaPointer<T> {
#[allow(clippy::non_canonical_clone_impl)]
fn clone(&self) -> Self {
*self
self.ptr_clone()
}
}

impl<T> Copy for ArenaPointer<T> {}

impl<T> From<Box<T>> for ArenaPointer<T> {
fn from(boxed: Box<T>) -> Self {
// Use `Box::into_raw` to extract the raw pointer from the box.
let raw_ptr: *const T = Box::into_raw(boxed);

// Create an `ArenaPointer` from the raw pointer.
ArenaPointer(raw_ptr)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use move_core_types::{
use lasso::{Spur, ThreadedRodeo};

/// A wrapper around a lasso ThreadedRoade with some niceties to make it easier to use in the VM.
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct IdentifierInterner(ThreadedRodeo);

pub type IdentifierKey = Spur;
Expand Down Expand Up @@ -81,9 +81,3 @@ impl IdentifierInterner {
}
}
}

impl Default for IdentifierInterner {
fn default() -> Self {
Self(ThreadedRodeo::default())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl CrossVersionPackageCache {
type_args: Vec<Type>,
datatype: DatatypeInfo,
) -> PartialVMResult<&DatatypeInfo> {
if self.cached_types.contains(&key) {
if self.cached_types.contains(key) {
let module_name = string_interner.resolve_string(&key.module_name, "module name")?;
let member_name = string_interner.resolve_string(&key.module_name, "member name")?;
return Err(
Expand All @@ -89,7 +89,7 @@ impl CrossVersionPackageCache {
}

pub fn contains_cached_type(&self, key: &IntraPackageKey) -> bool {
self.cached_types.contains(&key)
self.cached_types.contains(key)
}

pub fn resolve_type_by_name(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ pub struct DebugFlags {
pub const DEBUG_FLAGS: DebugFlags = DebugFlags {
function_list_sizes: true,
function_resolution: true,
eval_step: false,
eval_step: true,
};

#[cfg(debug_assertions)]
#[macro_export]
macro_rules! dbg_println {
($( $args:expr ),*$(,)?) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl InMemoryStorage {
println!("Linkage context: {:?}", stored_package.linkage_context);
println!("Type origins: {:?}", stored_package.type_origin_table);
println!("Modules:");
for (module_name, _blob) in &stored_package.modules {
for module_name in stored_package.modules.keys() {
println!("\tModule: {:?}", module_name);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub trait VMTestAdapter<Storage: MoveResolver + Sync + Send> {
let pkg = self.get_package_from_store(&package_id)?;
Ok(LinkageContext::new(
package_id,
HashMap::from_iter(pkg.linkage_table.into_iter()),
HashMap::from_iter(pkg.linkage_table),
))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ impl VMDispatchTables {
def_idx: &VTableKey,
depth_cache: &mut BTreeMap<VTableKey, DepthFormula>,
) -> PartialVMResult<DepthFormula> {
let datatype = self.resolve_type(&VTableKey::from(def_idx.clone()))?.1;
let datatype = self.resolve_type(&def_idx.clone())?.1;
// If we've already computed this datatypes depth, no more work remains to be done.
if let Some(form) = &datatype.depth {
return Ok(form.clone());
}
if let Some(form) = depth_cache.get(&def_idx) {
if let Some(form) = depth_cache.get(def_idx) {
return Ok(form.clone());
}

Expand Down Expand Up @@ -265,7 +265,7 @@ impl VMDispatchTables {
}

pub fn type_at(&self, idx: &VTableKey) -> PartialVMResult<Arc<CachedDatatype>> {
Ok(self.resolve_type(&VTableKey::from(idx.clone()))?.1)
Ok(self.resolve_type(&idx.clone())?.1)
}

// -------------------------------------------
Expand Down
Loading
Loading