diff --git a/aptos-move/framework/move-stdlib/doc/mem.md b/aptos-move/framework/move-stdlib/doc/mem.md index cce483a926275..4411cb38f7d1f 100644 --- a/aptos-move/framework/move-stdlib/doc/mem.md +++ b/aptos-move/framework/move-stdlib/doc/mem.md @@ -25,7 +25,7 @@ I.e. swapping/replacing non-copyable/non-droppable types. Swap contents of two passed mutable references. -
public fun swap<T>(left: &mut T, right: &mut T)
+
public(friend) fun swap<T>(left: &mut T, right: &mut T)
 
@@ -34,7 +34,7 @@ Swap contents of two passed mutable references. Implementation -
public native fun swap<T>(left: &mut T, right: &mut T);
+
public(friend) native fun swap<T>(left: &mut T, right: &mut T);
 
@@ -49,7 +49,7 @@ 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
 
@@ -58,7 +58,7 @@ and return value it had before. Implementation -
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
 }
@@ -78,7 +78,7 @@ and return value it had before.
 ### Function `swap`
 
 
-
public fun swap<T>(left: &mut T, right: &mut T)
+
public(friend) fun swap<T>(left: &mut T, right: &mut T)
 
@@ -97,7 +97,7 @@ and return value it had before. ### Function `replace` -
public fun replace<T>(ref: &mut T, new: T): T
+
public(friend) fun replace<T>(ref: &mut T, new: T): T
 
diff --git a/aptos-move/framework/move-stdlib/sources/mem.move b/aptos-move/framework/move-stdlib/sources/mem.move index 98758c43eba38..59d604aa2c4dd 100644 --- a/aptos-move/framework/move-stdlib/sources/mem.move +++ b/aptos-move/framework/move-stdlib/sources/mem.move @@ -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(left: &mut T, right: &mut T); + public(friend) native fun swap(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(ref: &mut T, new: T): T { + public(friend) fun replace(ref: &mut T, new: T): T { swap(ref, &mut new); new } diff --git a/aptos-move/framework/move-stdlib/src/natives/mem.rs b/aptos-move/framework/move-stdlib/src/natives/mem.rs index f997fec95749c..d00ac0b06abbc 100644 --- a/aptos-move/framework/move-stdlib/src/natives/mem.rs +++ b/aptos-move/framework/move-stdlib/src/natives/mem.rs @@ -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::{ @@ -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( diff --git a/third_party/move/move-vm/types/src/values/value_tests.rs b/third_party/move/move-vm/types/src/values/value_tests.rs index 14de4ab3b5123..c5d7574e774c4 100644 --- a/third_party/move/move-vm/types/src/values/value_tests.rs +++ b/third_party/move/move-vm/types/src/values/value_tests.rs @@ -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(()) }