Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-aptos committed Nov 9, 2024
1 parent 67e46c5 commit 58c55c0
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 22 deletions.
5 changes: 0 additions & 5 deletions aptos-move/e2e-benchmark/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion aptos-move/e2e-tests/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
57 changes: 57 additions & 0 deletions aptos-move/framework/move-stdlib/doc/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -671,6 +673,15 @@ Lifetime: transient



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



<pre><code><b>const</b> <a href="features.md#0x1_features_NATIVE_MEMORY_OPERATIONS">NATIVE_MEMORY_OPERATIONS</a>: u64 = 80;
</code></pre>



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

Lifetime: transient
Expand Down Expand Up @@ -3274,6 +3285,52 @@ Deprecated feature



</details>

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

## Function `get_native_memory_operations_feature`



<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_get_native_memory_operations_feature">get_native_memory_operations_feature</a>(): u64
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_get_native_memory_operations_feature">get_native_memory_operations_feature</a>(): u64 { <a href="features.md#0x1_features_NATIVE_MEMORY_OPERATIONS">NATIVE_MEMORY_OPERATIONS</a> }
</code></pre>



</details>

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

## Function `is_native_memory_operations_enabled`



<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_is_native_memory_operations_enabled">is_native_memory_operations_enabled</a>(): bool
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_is_native_memory_operations_enabled">is_native_memory_operations_enabled</a>(): bool <b>acquires</b> <a href="features.md#0x1_features_Features">Features</a> {
<a href="features.md#0x1_features_is_enabled">is_enabled</a>(<a href="features.md#0x1_features_NATIVE_MEMORY_OPERATIONS">NATIVE_MEMORY_OPERATIONS</a>)
}
</code></pre>



</details>

<a id="0x1_features_change_feature_flags"></a>
Expand Down
22 changes: 14 additions & 8 deletions aptos-move/framework/move-stdlib/doc/vector.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ The length of the vectors are not equal.

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

Whether to utilize native vector::move_range
Vector module cannot call features module, due to cyclic dependency,
so this is a constant.


<pre><code><b>const</b> <a href="vector.md#0x1_vector_USE_MOVE_RANGE">USE_MOVE_RANGE</a>: bool = <b>true</b>;
Expand Down Expand Up @@ -488,7 +491,7 @@ Pushes all of the elements of the <code>other</code> vector into the <code>self<
<b>if</b> (<a href="vector.md#0x1_vector_USE_MOVE_RANGE">USE_MOVE_RANGE</a>) {
<b>let</b> self_length = <a href="vector.md#0x1_vector_length">length</a>(self);
<b>let</b> other_length = <a href="vector.md#0x1_vector_length">length</a>(&other);
<a href="vector.md#0x1_vector_range_move">range_move</a>(&<b>mut</b> other, 0, other_length, self, self_length);
<a href="vector.md#0x1_vector_move_range">move_range</a>(&<b>mut</b> other, 0, other_length, self, self_length);
<a href="vector.md#0x1_vector_destroy_empty">destroy_empty</a>(other);
} <b>else</b> {
<a href="vector.md#0x1_vector_reverse">reverse</a>(&<b>mut</b> other);
Expand Down Expand Up @@ -557,7 +560,7 @@ In many languages this is also called <code>split_off</code>.

<b>let</b> other = <a href="vector.md#0x1_vector_empty">empty</a>();
<b>if</b> (<a href="vector.md#0x1_vector_USE_MOVE_RANGE">USE_MOVE_RANGE</a>) {
<a href="vector.md#0x1_vector_range_move">range_move</a>(self, new_len, len - new_len, &<b>mut</b> other, 0);
<a href="vector.md#0x1_vector_move_range">move_range</a>(self, new_len, len - new_len, &<b>mut</b> other, 0);
} <b>else</b> {
<b>while</b> (len &gt; new_len) {
<a href="vector.md#0x1_vector_push_back">push_back</a>(&<b>mut</b> other, <a href="vector.md#0x1_vector_pop_back">pop_back</a>(self));
Expand Down Expand Up @@ -766,7 +769,7 @@ Aborts if out of bounds.
};
} <b>else</b> {
<b>let</b> other = <a href="vector.md#0x1_vector_singleton">singleton</a>(e);
<a href="vector.md#0x1_vector_range_move">range_move</a>(&<b>mut</b> other, 0, 1, self, i);
<a href="vector.md#0x1_vector_move_range">move_range</a>(&<b>mut</b> other, 0, 1, self, i);
<a href="vector.md#0x1_vector_destroy_empty">destroy_empty</a>(other);
}
} <b>else</b> {
Expand Down Expand Up @@ -815,7 +818,7 @@ Aborts if <code>i</code> is out of bounds.
<a href="vector.md#0x1_vector_pop_back">pop_back</a>(self)
} <b>else</b> {
<b>let</b> other = <a href="vector.md#0x1_vector_empty">empty</a>();
<a href="vector.md#0x1_vector_range_move">range_move</a>(self, i, 1, &<b>mut</b> other, 0);
<a href="vector.md#0x1_vector_move_range">move_range</a>(self, i, 1, &<b>mut</b> other, 0);
<b>let</b> result = <a href="vector.md#0x1_vector_pop_back">pop_back</a>(&<b>mut</b> other);
<a href="vector.md#0x1_vector_destroy_empty">destroy_empty</a>(other);
result
Expand Down Expand Up @@ -920,10 +923,13 @@ 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 {
<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>);
std::mem::replace(<a href="vector.md#0x1_vector_borrow_mut">borrow_mut</a>(self, i), val)
// <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)
<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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions aptos-move/framework/move-stdlib/sources/mem.move
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
24 changes: 16 additions & 8 deletions aptos-move/framework/move-stdlib/sources/vector.move
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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]
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -344,10 +349,13 @@ module std::vector {
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)
}
}

/// Apply the function to each element in the vector, consuming it.
Expand Down

0 comments on commit 58c55c0

Please sign in to comment.