Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-aptos committed Oct 21, 2024
1 parent 6b8ad6c commit 170eca3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 29 deletions.
12 changes: 6 additions & 6 deletions aptos-move/framework/move-stdlib/doc/mem.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ I.e. swapping/replacing non-copyable/non-droppable types.
Swap contents of two passed mutable references.


<pre><code><b>public</b> <b>fun</b> <a href="mem.md#0x1_mem_swap">swap</a>&lt;T&gt;(left: &<b>mut</b> T, right: &<b>mut</b> T)
<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="mem.md#0x1_mem_swap">swap</a>&lt;T&gt;(left: &<b>mut</b> T, right: &<b>mut</b> T)
</code></pre>


Expand All @@ -34,7 +34,7 @@ Swap contents of two passed mutable references.
<summary>Implementation</summary>


<pre><code><b>public</b> <b>native</b> <b>fun</b> <a href="mem.md#0x1_mem_swap">swap</a>&lt;T&gt;(left: &<b>mut</b> T, right: &<b>mut</b> T);
<pre><code><b>public</b>(<b>friend</b>) <b>native</b> <b>fun</b> <a href="mem.md#0x1_mem_swap">swap</a>&lt;T&gt;(left: &<b>mut</b> T, right: &<b>mut</b> T);
</code></pre>


Expand All @@ -49,7 +49,7 @@ Replace value reference points to with the given new value,
and return value it had before.


<pre><code><b>public</b> <b>fun</b> <a href="mem.md#0x1_mem_replace">replace</a>&lt;T&gt;(ref: &<b>mut</b> T, new: T): T
<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="mem.md#0x1_mem_replace">replace</a>&lt;T&gt;(ref: &<b>mut</b> T, new: T): T
</code></pre>


Expand All @@ -58,7 +58,7 @@ and return value it had before.
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="mem.md#0x1_mem_replace">replace</a>&lt;T&gt;(ref: &<b>mut</b> T, new: T): T {
<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="mem.md#0x1_mem_replace">replace</a>&lt;T&gt;(ref: &<b>mut</b> T, new: T): T {
<a href="mem.md#0x1_mem_swap">swap</a>(ref, &<b>mut</b> new);
new
}
Expand All @@ -78,7 +78,7 @@ and return value it had before.
### Function `swap`


<pre><code><b>public</b> <b>fun</b> <a href="mem.md#0x1_mem_swap">swap</a>&lt;T&gt;(left: &<b>mut</b> T, right: &<b>mut</b> T)
<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="mem.md#0x1_mem_swap">swap</a>&lt;T&gt;(left: &<b>mut</b> T, right: &<b>mut</b> T)
</code></pre>


Expand All @@ -97,7 +97,7 @@ and return value it had before.
### Function `replace`


<pre><code><b>public</b> <b>fun</b> <a href="mem.md#0x1_mem_replace">replace</a>&lt;T&gt;(ref: &<b>mut</b> T, new: T): T
<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="mem.md#0x1_mem_replace">replace</a>&lt;T&gt;(ref: &<b>mut</b> T, new: T): T
</code></pre>


Expand Down
9 changes: 7 additions & 2 deletions aptos-move/framework/move-stdlib/sources/mem.move
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
/// Module with methods for safe memory manipulation.
/// I.e. swapping/replacing non-copyable/non-droppable types.
module std::mem {
// TODO - functions here are `public(friend)` here for one release,
// and to be changed to `public` one release later.
#[test_only]
friend std::mem_tests;

/// Swap contents of two passed mutable references.
public native fun swap<T>(left: &mut T, right: &mut T);
public(friend) native fun swap<T>(left: &mut T, right: &mut T);

/// Replace value reference points to with the given new value,
/// and return value it had before.
public fun replace<T>(ref: &mut T, new: T): T {
public(friend) fun replace<T>(ref: &mut T, new: T): T {
swap(ref, &mut new);
new
}
Expand Down
4 changes: 2 additions & 2 deletions aptos-move/framework/move-stdlib/src/natives/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Copyright (c) The Move Contributors
// SPDX-License-Identifier: Apache-2.0

//! Implementation of native functions for utf8 strings.
//! Implementation of native functions for memory manipulation.
use aptos_gas_schedule::gas_params::natives::move_stdlib::MEM_SWAP_BASE;
use aptos_native_interface::{
Expand Down Expand Up @@ -35,7 +35,7 @@ pub fn get_feature_not_available_error() -> SafeNativeError {
/***************************************************************************************************
* native fun native_swap
*
* gas cost: MEM_SWAP_BASE + MEM_SWAP_PER_ABS_VAL_UNIT * abstract_size_of_arguments
* gas cost: MEM_SWAP_BASE
*
**************************************************************************************************/
fn native_swap(
Expand Down
19 changes: 0 additions & 19 deletions third_party/move/move-vm/types/src/values/value_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,25 +307,6 @@ fn test_mem_swap() -> PartialVMResult<()> {
}
}

// assert_err!(get_local(&locals, 0).swap_values(get_local(&locals, 4)));
// assert_err!(get_local(&locals, 0).swap_values(get_local(&locals, 6)));
// assert_err!(get_local(&locals, 0).swap_values(get_local(&locals, 8)));
// assert_err!(get_local(&locals, 0).swap_values(get_local(&locals, 10)));
// assert_err!(get_local(&locals, 0).swap_values(get_local(&locals, 12)));
// assert_err!(get_local(&locals, 2).swap_values(get_local(&locals, 4)));
// assert_err!(get_local(&locals, 2).swap_values(get_local(&locals, 4)));
// assert_err!(get_local(&locals, 2).swap_values(get_local(&locals, 4)));
// assert_err!(get_local(&locals, 2).swap_values(get_local(&locals, 4)));

// assert_ok!(get_local(&locals, 0).swap_values(get_local(&locals, 1)));
// assert_ok!(get_local(&locals, 2).swap_values(get_local(&locals, 3)));
// assert_ok!(get_local(&locals, 4).swap_values(get_local(&locals, 5)));
// assert_ok!(get_local(&locals, 6).swap_values(get_local(&locals, 7)));
// assert_ok!(get_local(&locals, 8).swap_values(get_local(&locals, 9)));
// assert_ok!(get_local(&locals, 10).swap_values(get_local(&locals, 11)));
// assert_ok!(get_local(&locals, 12).swap_values(get_local(&locals, 13)));
// assert_ok!(get_local(&locals, 14).swap_values(get_local(&locals, 15)));

Ok(())
}

Expand Down

0 comments on commit 170eca3

Please sign in to comment.