Skip to content

Commit

Permalink
ungate native memory operations
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-aptos committed Dec 16, 2024
1 parent 4bc4bab commit 69d6f0b
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 77 deletions.
4 changes: 2 additions & 2 deletions aptos-move/framework/move-stdlib/doc/bcs.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ On the other hand, if function has returned None for some type,
it might change in the future to return Some() instead, if size becomes "known".


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="bcs.md#0x1_bcs_constant_serialized_size">constant_serialized_size</a>&lt;MoveValue&gt;(): <a href="option.md#0x1_option_Option">option::Option</a>&lt;u64&gt;
<pre><code><b>public</b> <b>fun</b> <a href="bcs.md#0x1_bcs_constant_serialized_size">constant_serialized_size</a>&lt;MoveValue&gt;(): <a href="option.md#0x1_option_Option">option::Option</a>&lt;u64&gt;
</code></pre>


Expand All @@ -94,7 +94,7 @@ it might change in the future to return Some() instead, if size becomes "known".
<summary>Implementation</summary>


<pre><code><b>native</b> <b>public</b>(<b>friend</b>) <b>fun</b> <a href="bcs.md#0x1_bcs_constant_serialized_size">constant_serialized_size</a>&lt;MoveValue&gt;(): Option&lt;u64&gt;;
<pre><code><b>native</b> <b>public</b> <b>fun</b> <a href="bcs.md#0x1_bcs_constant_serialized_size">constant_serialized_size</a>&lt;MoveValue&gt;(): Option&lt;u64&gt;;
</code></pre>


Expand Down
4 changes: 2 additions & 2 deletions aptos-move/framework/move-stdlib/doc/vector.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ Move prevents from having two mutable references to the same value, so <code>fro
vectors are always distinct.


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="vector.md#0x1_vector_move_range">move_range</a>&lt;T&gt;(from: &<b>mut</b> <a href="vector.md#0x1_vector">vector</a>&lt;T&gt;, removal_position: u64, length: u64, <b>to</b>: &<b>mut</b> <a href="vector.md#0x1_vector">vector</a>&lt;T&gt;, insert_position: u64)
<pre><code><b>public</b> <b>fun</b> <a href="vector.md#0x1_vector_move_range">move_range</a>&lt;T&gt;(from: &<b>mut</b> <a href="vector.md#0x1_vector">vector</a>&lt;T&gt;, removal_position: u64, length: u64, <b>to</b>: &<b>mut</b> <a href="vector.md#0x1_vector">vector</a>&lt;T&gt;, insert_position: u64)
</code></pre>


Expand All @@ -381,7 +381,7 @@ vectors are always distinct.
<summary>Implementation</summary>


<pre><code><b>native</b> <b>public</b>(<b>friend</b>) <b>fun</b> <a href="vector.md#0x1_vector_move_range">move_range</a>&lt;T&gt;(
<pre><code><b>native</b> <b>public</b> <b>fun</b> <a href="vector.md#0x1_vector_move_range">move_range</a>&lt;T&gt;(
from: &<b>mut</b> <a href="vector.md#0x1_vector">vector</a>&lt;T&gt;,
removal_position: u64,
length: u64,
Expand Down
7 changes: 1 addition & 6 deletions aptos-move/framework/move-stdlib/sources/bcs.move
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ module std::bcs {
/// Aborts with `0x1c5` error code if there is a failure when calculating serialized size.
native public fun serialized_size<MoveValue>(v: &MoveValue): u64;

// TODO - function `constant_serialized_size1 is `public(friend)` here for one release,
// and to be changed to `public` one release later.
#[test_only]
friend std::bcs_tests;

/// If the type has known constant (always the same, independent of instance) serialized size
/// in BCS (Binary Canonical Serialization) format, returns it, otherwise returns None.
/// Aborts with `0x1c5` error code if there is a failure when calculating serialized size.
Expand All @@ -28,7 +23,7 @@ module std::bcs {
/// If this function returned Some() for some type before - it is guaranteed to continue returning Some().
/// On the other hand, if function has returned None for some type,
/// it might change in the future to return Some() instead, if size becomes "known".
native public(friend) fun constant_serialized_size<MoveValue>(): Option<u64>;
native public fun constant_serialized_size<MoveValue>(): Option<u64>;

// ==============================
// Module Specification
Expand Down
10 changes: 2 additions & 8 deletions aptos-move/framework/move-stdlib/sources/mem.move
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
/// Module with methods for safe memory manipulation.
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;

/// Swap contents of two passed mutable references.
///
/// Move prevents from having two mutable references to the same value,
/// so `left` and `right` references are always distinct.
public(friend) native fun swap<T>(left: &mut T, right: &mut T);
public native fun swap<T>(left: &mut T, right: &mut T);

/// Replace the value reference points to with the given new value,
/// and return the value it had before.
public(friend) fun replace<T>(ref: &mut T, new: T): T {
public fun replace<T>(ref: &mut T, new: T): T {
swap(ref, &mut new);
new
}
Expand Down
7 changes: 1 addition & 6 deletions aptos-move/framework/move-stdlib/sources/vector.move
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ module std::vector {
/// Aborts if `i` or `j` is out of bounds.
native public fun swap<Element>(self: &mut vector<Element>, i: u64, j: u64);

// TODO - function `move_range` here is `public(friend)` for one release,
// and to be changed to `public` one release later.
#[test_only]
friend std::vector_tests;

/// Moves range of elements `[removal_position, removal_position + length)` from vector `from`,
/// to vector `to`, inserting them starting at the `insert_position`.
/// In the `from` vector, elements after the selected range are moved left to fill the hole
Expand All @@ -82,7 +77,7 @@ module std::vector {
/// elements is kept).
/// Move prevents from having two mutable references to the same value, so `from` and `to`
/// vectors are always distinct.
native public(friend) fun move_range<T>(
native public fun move_range<T>(
from: &mut vector<T>,
removal_position: u64,
length: u64,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ impl EntryPoints {
repeats,
} => get_payload(
module_id,
ident_str!("test_middle_range_move").to_owned(),
ident_str!("test_middle_move_range").to_owned(),
vec![
bcs::to_bytes(vec_len).unwrap(),
bcs::to_bytes(element_len).unwrap(),
Expand Down
97 changes: 54 additions & 43 deletions crates/transaction-generator-lib/src/publishing/raw_module_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,11 +1000,11 @@ pub static MODULES_SIMPLE: Lazy<Vec<Vec<u8>>> = Lazy::new(|| { vec![
pub static PACKAGE_FRAMEWORK_USECASES_METADATA: Lazy<Vec<u8>> = Lazy::new(|| {
vec![
17, 70, 114, 97, 109, 101, 119, 111, 114, 107, 85, 115, 101, 99, 97, 115, 101, 115,
1, 0, 0, 0, 0, 0, 0, 0, 0, 64, 67, 51, 69, 57, 51, 69, 69, 54,
70, 68, 66, 54, 67, 65, 65, 55, 52, 70, 50, 48, 50, 55, 70, 56, 68, 54,
65, 51, 55, 70, 69, 70, 68, 50, 65, 69, 69, 54, 56, 70, 56, 65, 57, 57,
70, 54, 55, 70, 65, 48, 57, 52, 65, 48, 68, 50, 67, 56, 57, 70, 54, 56,
48, 55, 215, 1, 31, 139, 8, 0, 0, 0, 0, 0, 2, 255, 165, 144, 187, 142,
1, 0, 0, 0, 0, 0, 0, 0, 0, 64, 67, 52, 70, 68, 56, 67, 50, 49,
56, 51, 69, 66, 52, 70, 55, 48, 70, 70, 65, 52, 66, 69, 56, 65, 48, 67,
57, 54, 68, 53, 50, 67, 70, 69, 52, 53, 68, 55, 48, 49, 68, 49, 52, 57,
55, 56, 57, 50, 51, 53, 55, 69, 55, 70, 55, 57, 50, 68, 70, 55, 68, 56,
66, 50, 215, 1, 31, 139, 8, 0, 0, 0, 0, 0, 2, 255, 165, 144, 187, 142,
194, 64, 12, 69, 251, 249, 10, 107, 182, 38, 236, 15, 108, 193, 238, 138, 150, 6,
170, 8, 33, 51, 49, 33, 100, 176, 163, 241, 240, 144, 16, 255, 78, 44, 30, 130,
22, 100, 23, 215, 246, 189, 167, 112, 217, 97, 104, 177, 166, 185, 99, 220, 18, 252,
Expand Down Expand Up @@ -1606,46 +1606,57 @@ pub static MODULE_FRAMEWORK_USECASES_TOKEN_V1: Lazy<Vec<u8>> = Lazy::new(|| {
#[rustfmt::skip]
pub static MODULE_FRAMEWORK_USECASES_VECTOR_EXAMPLE: Lazy<Vec<u8>> = Lazy::new(|| {
vec![
161, 28, 235, 11, 7, 0, 0, 10, 8, 1, 0, 4, 3, 4, 46, 4, 50, 8,
5, 58, 81, 7, 139, 1, 97, 8, 236, 1, 64, 16, 172, 2, 31, 12, 203, 2,
213, 2, 0, 0, 1, 3, 0, 1, 0, 1, 0, 1, 0, 2, 5, 6, 0, 1,
1, 4, 7, 8, 1, 0, 1, 1, 5, 9, 6, 1, 0, 1, 0, 6, 5, 6,
0, 1, 1, 7, 7, 11, 1, 0, 1, 1, 8, 12, 6, 1, 0, 1, 2, 3,
3, 3, 5, 3, 6, 3, 2, 3, 3, 1, 10, 10, 3, 1, 3, 1, 10, 3,
11, 10, 3, 3, 1, 3, 10, 10, 3, 1, 3, 3, 10, 3, 7, 3, 10, 10,
3, 4, 3, 3, 3, 3, 0, 2, 7, 10, 9, 0, 3, 1, 9, 0, 3, 7,
10, 9, 0, 3, 9, 0, 3, 10, 10, 3, 1, 10, 3, 1, 10, 9, 0, 2,
7, 10, 9, 0, 10, 9, 0, 3, 10, 10, 3, 1, 10, 10, 3, 14, 118, 101,
99, 116, 111, 114, 95, 101, 120, 97, 109, 112, 108, 101, 12, 103, 101, 110, 101, 114,
97, 116, 101, 95, 118, 101, 99, 18, 116, 101, 115, 116, 95, 114, 101, 109, 111, 118,
101, 95, 105, 110, 115, 101, 114, 116, 6, 118, 101, 99, 116, 111, 114, 6, 114, 101,
109, 111, 118, 101, 6, 105, 110, 115, 101, 114, 116, 16, 116, 101, 115, 116, 95, 116,
114, 105, 109, 95, 97, 112, 112, 101, 110, 100, 4, 116, 114, 105, 109, 6, 97, 112,
112, 101, 110, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 171, 205,
161, 28, 235, 11, 7, 0, 0, 10, 8, 1, 0, 4, 3, 4, 59, 4, 63, 10,
5, 73, 115, 7, 188, 1, 131, 1, 8, 191, 2, 64, 16, 255, 2, 31, 12, 158,
3, 192, 3, 0, 0, 1, 3, 0, 1, 0, 1, 0, 1, 0, 2, 5, 6, 0,
1, 1, 4, 7, 6, 1, 0, 1, 0, 5, 9, 6, 0, 1, 1, 6, 10, 11,
1, 0, 1, 1, 7, 12, 6, 1, 0, 1, 0, 8, 9, 6, 0, 1, 1, 9,
10, 14, 1, 0, 1, 1, 10, 15, 6, 1, 0, 1, 2, 3, 4, 3, 5, 3,
7, 3, 8, 3, 2, 3, 3, 1, 10, 10, 3, 1, 3, 1, 10, 3, 11, 10,
3, 3, 1, 3, 10, 10, 3, 1, 3, 3, 10, 3, 7, 3, 10, 10, 3, 5,
3, 3, 3, 3, 3, 0, 5, 7, 10, 9, 0, 3, 3, 7, 10, 9, 0, 3,
5, 10, 10, 3, 10, 10, 3, 1, 7, 10, 10, 3, 7, 10, 10, 3, 4, 3,
3, 3, 3, 2, 7, 10, 9, 0, 3, 1, 9, 0, 3, 7, 10, 9, 0, 3,
9, 0, 3, 10, 10, 3, 1, 10, 3, 1, 10, 9, 0, 2, 7, 10, 9, 0,
10, 9, 0, 3, 10, 10, 3, 1, 10, 10, 3, 14, 118, 101, 99, 116, 111, 114,
95, 101, 120, 97, 109, 112, 108, 101, 12, 103, 101, 110, 101, 114, 97, 116, 101, 95,
118, 101, 99, 22, 116, 101, 115, 116, 95, 109, 105, 100, 100, 108, 101, 95, 109, 111,
118, 101, 95, 114, 97, 110, 103, 101, 6, 118, 101, 99, 116, 111, 114, 10, 109, 111,
118, 101, 95, 114, 97, 110, 103, 101, 18, 116, 101, 115, 116, 95, 114, 101, 109, 111,
118, 101, 95, 105, 110, 115, 101, 114, 116, 6, 114, 101, 109, 111, 118, 101, 6, 105,
110, 115, 101, 114, 116, 16, 116, 101, 115, 116, 95, 116, 114, 105, 109, 95, 97, 112,
112, 101, 110, 100, 4, 116, 114, 105, 109, 6, 97, 112, 112, 101, 110, 100, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 20, 99, 111, 109,
112, 105, 108, 97, 116, 105, 111, 110, 95, 109, 101, 116, 97, 100, 97, 116, 97, 9,
0, 3, 50, 46, 48, 3, 50, 46, 49, 0, 0, 0, 0, 4, 65, 64, 2, 0,
0, 0, 0, 0, 0, 0, 0, 12, 2, 6, 0, 0, 0, 0, 0, 0, 0, 0,
12, 3, 9, 12, 4, 5, 8, 5, 23, 10, 4, 4, 62, 11, 3, 6, 1, 0,
0, 0, 0, 0, 0, 0, 22, 12, 3, 10, 3, 10, 1, 35, 3, 19, 5, 23,
13, 2, 10, 3, 68, 2, 5, 6, 64, 3, 0, 0, 0, 0, 0, 0, 0, 0,
12, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 12, 5, 9, 12, 7, 11, 0,
12, 8, 5, 33, 5, 57, 10, 7, 4, 59, 11, 5, 6, 1, 0, 0, 0, 0,
0, 0, 0, 22, 12, 5, 10, 5, 10, 8, 35, 3, 44, 5, 57, 10, 2, 12,
10, 13, 10, 6, 0, 0, 0, 0, 0, 0, 0, 0, 67, 2, 12, 11, 10, 5,
11, 11, 21, 13, 6, 11, 10, 68, 3, 5, 31, 11, 6, 2, 8, 12, 7, 5,
39, 8, 12, 4, 5, 14, 1, 1, 4, 0, 10, 34, 11, 0, 11, 1, 17, 0,
12, 4, 6, 0, 0, 0, 0, 0, 0, 0, 0, 12, 0, 9, 12, 5, 5, 10,
5, 30, 10, 5, 4, 31, 11, 0, 6, 1, 0, 0, 0, 0, 0, 0, 0, 22,
12, 0, 10, 0, 10, 3, 35, 3, 21, 5, 30, 13, 4, 10, 2, 56, 0, 12,
6, 13, 4, 10, 2, 11, 6, 56, 1, 5, 8, 2, 8, 12, 5, 5, 16, 4,
1, 4, 0, 13, 33, 11, 0, 11, 1, 17, 0, 12, 4, 6, 0, 0, 0, 0,
0, 0, 0, 0, 12, 0, 9, 12, 5, 5, 10, 5, 29, 10, 5, 4, 30, 11,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 171, 205, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1, 20, 99, 111, 109, 112, 105, 108, 97, 116, 105,
111, 110, 95, 109, 101, 116, 97, 100, 97, 116, 97, 9, 0, 3, 50, 46, 48, 3,
50, 46, 49, 0, 0, 0, 0, 4, 65, 64, 2, 0, 0, 0, 0, 0, 0, 0,
0, 12, 2, 6, 0, 0, 0, 0, 0, 0, 0, 0, 12, 3, 9, 12, 4, 5,
8, 5, 23, 10, 4, 4, 62, 11, 3, 6, 1, 0, 0, 0, 0, 0, 0, 0,
22, 12, 3, 10, 3, 10, 1, 35, 3, 19, 5, 23, 13, 2, 10, 3, 68, 2,
5, 6, 64, 3, 0, 0, 0, 0, 0, 0, 0, 0, 12, 6, 6, 0, 0, 0,
0, 0, 0, 0, 0, 12, 5, 9, 12, 7, 11, 0, 12, 8, 5, 33, 5, 57,
10, 7, 4, 59, 11, 5, 6, 1, 0, 0, 0, 0, 0, 0, 0, 22, 12, 5,
10, 5, 10, 8, 35, 3, 44, 5, 57, 10, 2, 12, 10, 13, 10, 6, 0, 0,
0, 0, 0, 0, 0, 0, 67, 2, 12, 11, 10, 5, 11, 11, 21, 13, 6, 11,
10, 68, 3, 5, 31, 11, 6, 2, 8, 12, 7, 5, 39, 8, 12, 4, 5, 14,
1, 1, 4, 0, 8, 46, 10, 0, 10, 1, 17, 0, 12, 5, 11, 0, 11, 1,
17, 0, 12, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 12, 0, 9, 12, 7,
5, 14, 5, 42, 10, 7, 4, 43, 11, 0, 6, 1, 0, 0, 0, 0, 0, 0,
0, 22, 12, 0, 10, 0, 10, 4, 35, 3, 25, 5, 42, 13, 5, 13, 6, 12,
8, 10, 2, 10, 3, 11, 8, 10, 2, 56, 0, 13, 6, 13, 5, 12, 8, 10,
2, 10, 3, 11, 8, 10, 2, 56, 0, 5, 12, 2, 8, 12, 7, 5, 20, 3,
1, 4, 0, 13, 34, 11, 0, 11, 1, 17, 0, 12, 4, 6, 0, 0, 0, 0,
0, 0, 0, 0, 12, 0, 9, 12, 5, 5, 10, 5, 30, 10, 5, 4, 31, 11,
0, 6, 1, 0, 0, 0, 0, 0, 0, 0, 22, 12, 0, 10, 0, 10, 3, 35,
3, 21, 5, 29, 13, 4, 10, 2, 56, 2, 12, 6, 13, 4, 11, 6, 56, 3,
5, 8, 2, 8, 12, 5, 5, 16, 0,
3, 21, 5, 30, 13, 4, 10, 2, 56, 1, 12, 6, 13, 4, 10, 2, 11, 6,
56, 2, 5, 8, 2, 8, 12, 5, 5, 16, 6, 1, 4, 0, 16, 33, 11, 0,
11, 1, 17, 0, 12, 4, 6, 0, 0, 0, 0, 0, 0, 0, 0, 12, 0, 9,
12, 5, 5, 10, 5, 29, 10, 5, 4, 30, 11, 0, 6, 1, 0, 0, 0, 0,
0, 0, 0, 22, 12, 0, 10, 0, 10, 3, 35, 3, 21, 5, 29, 13, 4, 10,
2, 56, 3, 12, 6, 13, 4, 11, 6, 56, 4, 5, 8, 2, 8, 12, 5, 5,
16, 0,
]
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ module 0xABCD::vector_example {
};
}

// public entry fun test_middle_range_move(vec_len: u64, element_len: u64, index: u64, move_len: u64, repeats: u64) {
// let vec1 = generate_vec(vec_len, element_len);
// let vec2 = generate_vec(vec_len, element_len);

// for (i in 0..repeats) {
// vector::move_range(&mut vec1, index, move_len, &mut vec2, index);
// vector::move_range(&mut vec2, index, move_len, &mut vec1, index);
// };
// }
public entry fun test_middle_move_range(vec_len: u64, element_len: u64, index: u64, move_len: u64, repeats: u64) {
let vec1 = generate_vec(vec_len, element_len);
let vec2 = generate_vec(vec_len, element_len);

for (i in 0..repeats) {
vector::move_range(&mut vec1, index, move_len, &mut vec2, index);
vector::move_range(&mut vec2, index, move_len, &mut vec1, index);
};
}
}

0 comments on commit 69d6f0b

Please sign in to comment.