Skip to content

Commit

Permalink
test why backward incompatible error
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-aptos committed Dec 6, 2024
1 parent 729b683 commit afa6bd2
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 54 deletions.
2 changes: 1 addition & 1 deletion aptos-move/e2e-benchmark/data/calibration_values.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
74 changes: 37 additions & 37 deletions aptos-move/framework/move-stdlib/doc/vector.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -907,42 +907,6 @@ Aborts if <code>i</code> is out of bounds.



</details>

<a id="0x1_vector_replace"></a>

## Function `replace`

Replace the <code>i</code>th element of the vector <code>self</code> with the given value, and return
to the caller the value that was there before.
Aborts if <code>i</code> is out of bounds.


<pre><code><b>public</b> <b>fun</b> <a href="vector.md#0x1_vector_replace">replace</a>&lt;Element&gt;(self: &<b>mut</b> <a href="vector.md#0x1_vector">vector</a>&lt;Element&gt;, i: u64, val: Element): Element
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="vector.md#0x1_vector_replace">replace</a>&lt;Element&gt;(self: &<b>mut</b> <a href="vector.md#0x1_vector">vector</a>&lt;Element&gt;, i: u64, val: Element): Element {
<b>let</b> last_idx = <a href="vector.md#0x1_vector_length">length</a>(self);
<b>assert</b>!(i &lt; last_idx, <a href="vector.md#0x1_vector_EINDEX_OUT_OF_BOUNDS">EINDEX_OUT_OF_BOUNDS</a>);
// TODO: Enable after tests are fixed.
// <b>if</b> (<a href="vector.md#0x1_vector_USE_MOVE_RANGE">USE_MOVE_RANGE</a>) {
// <a href="mem.md#0x1_mem_replace">mem::replace</a>(<a href="vector.md#0x1_vector_borrow_mut">borrow_mut</a>(self, i), val)
// } <b>else</b> {
<a href="vector.md#0x1_vector_push_back">push_back</a>(self, val);
<a href="vector.md#0x1_vector_swap">swap</a>(self, i, last_idx);
<a href="vector.md#0x1_vector_pop_back">pop_back</a>(self)
// }
}
</code></pre>



</details>

<a id="0x1_vector_for_each"></a>
Expand Down Expand Up @@ -1836,6 +1800,42 @@ when used in the context of destroying a vector.



</details>

<a id="0x1_vector_replace"></a>

## Function `replace`

Replace the <code>i</code>th element of the vector <code>self</code> with the given value, and return
to the caller the value that was there before.
Aborts if <code>i</code> is out of bounds.


<pre><code><b>public</b> <b>fun</b> <a href="vector.md#0x1_vector_replace">replace</a>&lt;Element&gt;(self: &<b>mut</b> <a href="vector.md#0x1_vector">vector</a>&lt;Element&gt;, i: u64, val: Element): Element
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="vector.md#0x1_vector_replace">replace</a>&lt;Element&gt;(self: &<b>mut</b> <a href="vector.md#0x1_vector">vector</a>&lt;Element&gt;, i: u64, val: Element): Element {
<b>let</b> last_idx = <a href="vector.md#0x1_vector_length">length</a>(self);
<b>assert</b>!(i &lt; last_idx, <a href="vector.md#0x1_vector_EINDEX_OUT_OF_BOUNDS">EINDEX_OUT_OF_BOUNDS</a>);
// TODO: Enable after tests are fixed.
// <b>if</b> (<a href="vector.md#0x1_vector_USE_MOVE_RANGE">USE_MOVE_RANGE</a>) {
// <a href="mem.md#0x1_mem_replace">mem::replace</a>(<a href="vector.md#0x1_vector_borrow_mut">borrow_mut</a>(self, i), val)
// } <b>else</b> {
<a href="vector.md#0x1_vector_push_back">push_back</a>(self, val);
<a href="vector.md#0x1_vector_swap">swap</a>(self, i, last_idx);
<a href="vector.md#0x1_vector_pop_back">pop_back</a>(self)
// }
}
</code></pre>



</details>

<a id="@Specification_1"></a>
Expand Down
32 changes: 16 additions & 16 deletions aptos-move/framework/move-stdlib/sources/vector.move
Original file line number Diff line number Diff line change
Expand Up @@ -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<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)
// }
}

/// Apply the function to each element in the vector, consuming it.
public inline fun for_each<Element>(self: vector<Element>, f: |Element|) {
reverse(&mut self); // We need to reverse the vector to consume it efficiently
Expand Down Expand Up @@ -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<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)
// }
}

// =================================================================
// Module Specification

Expand Down
6 changes: 6 additions & 0 deletions third_party/move/move-binary-format/src/compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down

0 comments on commit afa6bd2

Please sign in to comment.