From 58c55c0612f3e11e5596491119a5435d2d7e88bd Mon Sep 17 00:00:00 2001 From: Igor Date: Mon, 21 Oct 2024 11:19:32 -0700 Subject: [PATCH] minor fixes --- aptos-move/e2e-benchmark/src/main.rs | 5 -- aptos-move/e2e-tests/src/executor.rs | 5 +- .../framework/move-stdlib/doc/features.md | 57 +++++++++++++++++++ .../framework/move-stdlib/doc/vector.md | 22 ++++--- .../move-stdlib/sources/configs/features.move | 8 +++ .../framework/move-stdlib/sources/mem.move | 1 + .../framework/move-stdlib/sources/vector.move | 24 +++++--- 7 files changed, 100 insertions(+), 22 deletions(-) diff --git a/aptos-move/e2e-benchmark/src/main.rs b/aptos-move/e2e-benchmark/src/main.rs index a59dfc021fec5..c80223ef0f110 100644 --- a/aptos-move/e2e-benchmark/src/main.rs +++ b/aptos-move/e2e-benchmark/src/main.rs @@ -355,7 +355,6 @@ fn main() { 0, package.publish_transaction_payload(), ); - // println!("Published package: {:?}", entry_point.package_name()); if let Some(init_entry_point) = entry_point.initialize_entry_point() { execute_txn( &mut executor, @@ -367,10 +366,6 @@ fn main() { Some(publisher.address()), ), ); - // println!( - // "Executed init entry point: {:?}", - // entry_point.initialize_entry_point() - // ); } let measurement = execute_and_time_entry_point( diff --git a/aptos-move/e2e-tests/src/executor.rs b/aptos-move/e2e-tests/src/executor.rs index 3e05f3ac6d6a6..eeb73581e6831 100644 --- a/aptos-move/e2e-tests/src/executor.rs +++ b/aptos-move/e2e-tests/src/executor.rs @@ -1056,7 +1056,10 @@ impl FakeExecutor { let elapsed = start.elapsed(); if let Err(err) = result { if !should_error { - println!("Shouldn't error, but ignoring for now... {}", err); + println!( + "Entry function under measurement failed with an error. Continuing, but measurements are probably not what is expected. Error: {}", + err + ); } } times.push(TimeAndGas { diff --git a/aptos-move/framework/move-stdlib/doc/features.md b/aptos-move/framework/move-stdlib/doc/features.md index 3919625f4ff9c..e5604063b6071 100644 --- a/aptos-move/framework/move-stdlib/doc/features.md +++ b/aptos-move/framework/move-stdlib/doc/features.md @@ -133,6 +133,8 @@ return true. - [Function `transaction_simulation_enhancement_enabled`](#0x1_features_transaction_simulation_enhancement_enabled) - [Function `get_collection_owner_feature`](#0x1_features_get_collection_owner_feature) - [Function `is_collection_owner_enabled`](#0x1_features_is_collection_owner_enabled) +- [Function `get_native_memory_operations_feature`](#0x1_features_get_native_memory_operations_feature) +- [Function `is_native_memory_operations_enabled`](#0x1_features_is_native_memory_operations_enabled) - [Function `change_feature_flags`](#0x1_features_change_feature_flags) - [Function `change_feature_flags_internal`](#0x1_features_change_feature_flags_internal) - [Function `change_feature_flags_for_next_epoch`](#0x1_features_change_feature_flags_for_next_epoch) @@ -671,6 +673,15 @@ Lifetime: transient + + + + +
const NATIVE_MEMORY_OPERATIONS: u64 = 80;
+
+ + + Lifetime: transient @@ -3274,6 +3285,52 @@ Deprecated feature + + + + +## Function `get_native_memory_operations_feature` + + + +
public fun get_native_memory_operations_feature(): u64
+
+ + + +
+Implementation + + +
public fun get_native_memory_operations_feature(): u64 { NATIVE_MEMORY_OPERATIONS }
+
+ + + +
+ + + +## Function `is_native_memory_operations_enabled` + + + +
public fun is_native_memory_operations_enabled(): bool
+
+ + + +
+Implementation + + +
public fun is_native_memory_operations_enabled(): bool acquires Features {
+    is_enabled(NATIVE_MEMORY_OPERATIONS)
+}
+
+ + +
diff --git a/aptos-move/framework/move-stdlib/doc/vector.md b/aptos-move/framework/move-stdlib/doc/vector.md index 691f9db98b1a0..616fa0abf21aa 100644 --- a/aptos-move/framework/move-stdlib/doc/vector.md +++ b/aptos-move/framework/move-stdlib/doc/vector.md @@ -150,6 +150,9 @@ The length of the vectors are not equal. +Whether to utilize native vector::move_range +Vector module cannot call features module, due to cyclic dependency, +so this is a constant.
const USE_MOVE_RANGE: bool = true;
@@ -488,7 +491,7 @@ Pushes all of the elements of the other vector into the self<
     if (USE_MOVE_RANGE) {
         let self_length = length(self);
         let other_length = length(&other);
-        range_move(&mut other, 0, other_length, self, self_length);
+        move_range(&mut other, 0, other_length, self, self_length);
         destroy_empty(other);
     } else {
         reverse(&mut other);
@@ -557,7 +560,7 @@ In many languages this is also called split_off.
 
     let other = empty();
     if (USE_MOVE_RANGE) {
-        range_move(self, new_len, len - new_len, &mut other, 0);
+        move_range(self, new_len, len - new_len, &mut other, 0);
     } else {
         while (len > new_len) {
             push_back(&mut other, pop_back(self));
@@ -766,7 +769,7 @@ Aborts if out of bounds.
             };
         } else {
             let other = singleton(e);
-            range_move(&mut other, 0, 1, self, i);
+            move_range(&mut other, 0, 1, self, i);
             destroy_empty(other);
         }
     } else {
@@ -815,7 +818,7 @@ Aborts if i is out of bounds.
             pop_back(self)
         } else {
             let other = empty();
-            range_move(self, i, 1, &mut other, 0);
+            move_range(self, i, 1, &mut other, 0);
             let result = pop_back(&mut other);
             destroy_empty(other);
             result
@@ -920,10 +923,13 @@ Aborts if i is out of bounds.
 
public fun replace<Element>(self: &mut vector<Element>, i: u64, val: Element): Element {
     let last_idx = length(self);
     assert!(i < last_idx, EINDEX_OUT_OF_BOUNDS);
-    std::mem::replace(borrow_mut(self, i), val)
-    // push_back(self, val);
-    // swap(self, i, last_idx);
-    // pop_back(self)
+    if (USE_MOVE_RANGE) {
+        mem::replace(borrow_mut(self, i), val)
+    } else {
+        push_back(self, val);
+        swap(self, i, last_idx);
+        pop_back(self)
+    }
 }
 
diff --git a/aptos-move/framework/move-stdlib/sources/configs/features.move b/aptos-move/framework/move-stdlib/sources/configs/features.move index 2bdba4056eaae..2b3a5291c600d 100644 --- a/aptos-move/framework/move-stdlib/sources/configs/features.move +++ b/aptos-move/framework/move-stdlib/sources/configs/features.move @@ -607,6 +607,14 @@ module std::features { is_enabled(COLLECTION_OWNER) } + const NATIVE_MEMORY_OPERATIONS: u64 = 80; + + public fun get_native_memory_operations_feature(): u64 { NATIVE_MEMORY_OPERATIONS } + + public fun is_native_memory_operations_enabled(): bool acquires Features { + is_enabled(NATIVE_MEMORY_OPERATIONS) + } + // ============================================================================================ // Feature Flag Implementation diff --git a/aptos-move/framework/move-stdlib/sources/mem.move b/aptos-move/framework/move-stdlib/sources/mem.move index 59d604aa2c4dd..72cf7a039b72c 100644 --- a/aptos-move/framework/move-stdlib/sources/mem.move +++ b/aptos-move/framework/move-stdlib/sources/mem.move @@ -3,6 +3,7 @@ module std::mem { // TODO - functions here are `public(friend)` here for one release, // and to be changed to `public` one release later. + friend std::vector; #[test_only] friend std::mem_tests; diff --git a/aptos-move/framework/move-stdlib/sources/vector.move b/aptos-move/framework/move-stdlib/sources/vector.move index 4c699c120f453..2a050294e17f0 100644 --- a/aptos-move/framework/move-stdlib/sources/vector.move +++ b/aptos-move/framework/move-stdlib/sources/vector.move @@ -9,6 +9,8 @@ /// Move functions here because many have loops, requiring loop invariants to prove, and /// the return on investment didn't seem worth it for these simple functions. module std::vector { + use std::mem; + /// The index into the vector is out of bounds const EINDEX_OUT_OF_BOUNDS: u64 = 0x20000; @@ -24,6 +26,9 @@ module std::vector { /// The range in `slice` is invalid. const EINVALID_SLICE_RANGE: u64 = 0x20004; + /// Whether to utilize native vector::move_range + /// Vector module cannot call features module, due to cyclic dependency, + /// so this is a constant. const USE_MOVE_RANGE: bool = true; #[bytecode_instruction] @@ -118,7 +123,7 @@ module std::vector { if (USE_MOVE_RANGE) { let self_length = length(self); let other_length = length(&other); - range_move(&mut other, 0, other_length, self, self_length); + move_range(&mut other, 0, other_length, self, self_length); destroy_empty(other); } else { reverse(&mut other); @@ -156,7 +161,7 @@ module std::vector { let other = empty(); if (USE_MOVE_RANGE) { - range_move(self, new_len, len - new_len, &mut other, 0); + move_range(self, new_len, len - new_len, &mut other, 0); } else { while (len > new_len) { push_back(&mut other, pop_back(self)); @@ -258,7 +263,7 @@ module std::vector { }; } else { let other = singleton(e); - range_move(&mut other, 0, 1, self, i); + move_range(&mut other, 0, 1, self, i); destroy_empty(other); } } else { @@ -290,7 +295,7 @@ module std::vector { pop_back(self) } else { let other = empty(); - range_move(self, i, 1, &mut other, 0); + move_range(self, i, 1, &mut other, 0); let result = pop_back(&mut other); destroy_empty(other); result @@ -344,10 +349,13 @@ module std::vector { public fun replace(self: &mut vector, i: u64, val: Element): Element { let last_idx = length(self); assert!(i < last_idx, EINDEX_OUT_OF_BOUNDS); - std::mem::replace(borrow_mut(self, i), val) - // push_back(self, val); - // swap(self, i, last_idx); - // pop_back(self) + if (USE_MOVE_RANGE) { + mem::replace(borrow_mut(self, i), val) + } else { + push_back(self, val); + swap(self, i, last_idx); + pop_back(self) + } } /// Apply the function to each element in the vector, consuming it.