From afa6bd29c1aedeb05b44c71321a7d1b1954672d3 Mon Sep 17 00:00:00 2001 From: Igor Date: Thu, 5 Dec 2024 16:10:27 -0800 Subject: [PATCH] test why backward incompatible error --- .../e2e-benchmark/data/calibration_values.tsv | 2 +- .../framework/move-stdlib/doc/vector.md | 74 +++++++++---------- .../framework/move-stdlib/sources/vector.move | 32 ++++---- .../move-binary-format/src/compatibility.rs | 6 ++ 4 files changed, 60 insertions(+), 54 deletions(-) diff --git a/aptos-move/e2e-benchmark/data/calibration_values.tsv b/aptos-move/e2e-benchmark/data/calibration_values.tsv index 949378c6b2043..f8f8281e3b772 100644 --- a/aptos-move/e2e-benchmark/data/calibration_values.tsv +++ b/aptos-move/e2e-benchmark/data/calibration_values.tsv @@ -25,7 +25,7 @@ IncGlobalMilestoneAggV2 { milestone_every: 1 } 60 0.914 1.051 33.5 IncGlobalMilestoneAggV2 { milestone_every: 2 } 60 0.914 1.105 19.0 EmitEvents { count: 1000 } 60 0.937 1.158 8818.7 VectorTrimAppend { vec_len: 3000, element_len: 1, index: 0, repeats: 0 } 6 0.925 1.001 6058.1 -VectorTrimAppend { vec_len: 3000, element_len: 1, index: 100, repeats: 1000 } 6 0.925 1.001 29450.7 +VectorTrimAppend { vec_len: 3000, element_len: 1, index: 100, repeats: 1000 } 6 0.925 1.001 34000.0 VectorTrimAppend { vec_len: 3000, element_len: 1, index: 2990, repeats: 1000 } 6 0.925 1.001 17626.5 VectorRemoveInsert { vec_len: 3000, element_len: 1, index: 100, repeats: 1000 } 6 0.925 1.001 30870.3 VectorRemoveInsert { vec_len: 3000, element_len: 1, index: 2998, repeats: 1000 } 6 0.925 1.001 20343.2 diff --git a/aptos-move/framework/move-stdlib/doc/vector.md b/aptos-move/framework/move-stdlib/doc/vector.md index 9e837c9c1cfae..97e3c3ba48109 100644 --- a/aptos-move/framework/move-stdlib/doc/vector.md +++ b/aptos-move/framework/move-stdlib/doc/vector.md @@ -40,7 +40,6 @@ the return on investment didn't seem worth it for these simple functions. - [Function `remove`](#0x1_vector_remove) - [Function `remove_value`](#0x1_vector_remove_value) - [Function `swap_remove`](#0x1_vector_swap_remove) -- [Function `replace`](#0x1_vector_replace) - [Function `for_each`](#0x1_vector_for_each) - [Function `for_each_reverse`](#0x1_vector_for_each_reverse) - [Function `for_each_ref`](#0x1_vector_for_each_ref) @@ -68,6 +67,7 @@ the return on investment didn't seem worth it for these simple functions. - [Function `range`](#0x1_vector_range) - [Function `range_with_step`](#0x1_vector_range_with_step) - [Function `slice`](#0x1_vector_slice) +- [Function `replace`](#0x1_vector_replace) - [Specification](#@Specification_1) - [Helper Functions](#@Helper_Functions_2) - [Function `singleton`](#@Specification_1_singleton) @@ -907,42 +907,6 @@ Aborts if i is out of bounds. - - - - -## Function `replace` - -Replace the ith element of the vector self with the given value, and return -to the caller the value that was there before. -Aborts if i is out of bounds. - - -
public fun replace<Element>(self: &mut vector<Element>, i: u64, val: Element): Element
-
- - - -
-Implementation - - -
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);
-    // TODO: Enable after tests are fixed.
-    // if (USE_MOVE_RANGE) {
-    //     mem::replace(borrow_mut(self, i), val)
-    // } else {
-    push_back(self, val);
-    swap(self, i, last_idx);
-    pop_back(self)
-    // }
-}
-
- - -
@@ -1836,6 +1800,42 @@ when used in the context of destroying a vector. + + + + +## Function `replace` + +Replace the ith element of the vector self with the given value, and return +to the caller the value that was there before. +Aborts if i is out of bounds. + + +
public fun replace<Element>(self: &mut vector<Element>, i: u64, val: Element): Element
+
+ + + +
+Implementation + + +
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);
+    // TODO: Enable after tests are fixed.
+    // 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/vector.move b/aptos-move/framework/move-stdlib/sources/vector.move index b7add1eb2112a..a90d91bb46d2d 100644 --- a/aptos-move/framework/move-stdlib/sources/vector.move +++ b/aptos-move/framework/move-stdlib/sources/vector.move @@ -351,22 +351,6 @@ module std::vector { pragma intrinsic = true; } - /// Replace the `i`th element of the vector `self` with the given value, and return - /// to the caller the value that was there before. - /// Aborts if `i` is out of bounds. - public fun replace(self: &mut vector, i: u64, val: Element): Element { - let last_idx = length(self); - assert!(i < last_idx, EINDEX_OUT_OF_BOUNDS); - // TODO: Enable after tests are fixed. - // 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. public inline fun for_each(self: vector, f: |Element|) { reverse(&mut self); // We need to reverse the vector to consume it efficiently @@ -726,6 +710,22 @@ module std::vector { vec } + /// Replace the `i`th element of the vector `self` with the given value, and return + /// to the caller the value that was there before. + /// Aborts if `i` is out of bounds. + public fun replace(self: &mut vector, i: u64, val: Element): Element { + let last_idx = length(self); + assert!(i < last_idx, EINDEX_OUT_OF_BOUNDS); + // TODO: Enable after tests are fixed. + // if (USE_MOVE_RANGE) { + // mem::replace(borrow_mut(self, i), val) + // } else { + push_back(self, val); + swap(self, i, last_idx); + pop_back(self) + // } + } + // ================================================================= // Module Specification diff --git a/third_party/move/move-binary-format/src/compatibility.rs b/third_party/move/move-binary-format/src/compatibility.rs index be95e220456e6..618cdd02ff474 100644 --- a/third_party/move/move-binary-format/src/compatibility.rs +++ b/third_party/move/move-binary-format/src/compatibility.rs @@ -257,6 +257,12 @@ impl Compatibility { } if !errors.is_empty() { + panic!( + "Module update failure: new module not compatible with \ + existing module in `{}`: {}", + old_view.id(), + errors.join(", ") + ); Err( PartialVMError::new(StatusCode::BACKWARD_INCOMPATIBLE_MODULE_UPDATE).with_message( format!(