From f89f377086026e161d1583253d0e26e2bb7d2530 Mon Sep 17 00:00:00 2001 From: aldenhu Date: Wed, 20 Jul 2022 22:48:18 -0700 Subject: [PATCH 1/3] move stdlib: type_info::full_name() --- .../error_description.errmap | Bin 0 -> 8565 bytes .../aptos-stdlib/sources/type_info.move | 30 ++++++++++++++++++ aptos-move/framework/src/natives/mod.rs | 2 ++ aptos-move/framework/src/natives/type_info.rs | 22 +++++++++++++ aptos-move/framework/tests/move_unit_test.rs | 7 +++- 5 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 aptos-move/framework/aptos-stdlib/aptos-framework/releases/artifacts/current/error_description/error_description.errmap diff --git a/aptos-move/framework/aptos-stdlib/aptos-framework/releases/artifacts/current/error_description/error_description.errmap b/aptos-move/framework/aptos-stdlib/aptos-framework/releases/artifacts/current/error_description/error_description.errmap new file mode 100644 index 0000000000000000000000000000000000000000..4dd6c3b82bf32ca4fda9d434c53595c4cd850b5d GIT binary patch literal 8565 zcmcIp{d3#K5e4I~ShXd^k`qU^XKs=vai$5ACQc?ZO)~?LCkZu4FeE5hopvCIJd%h> z0Ktc3=I8$5eS04uBw3-`PMw+9LjZewd%JJn+q0PU`+sUThjAF)H7`Bp4cF=TPG`^c z?Pjyb`+dLd^xL-AIQUnM9Zf~Vg3%}yS;pcq3x>nEh;nv54Tn<}W~|7>h~+U0qc9I= z;ctQkj22)g4gB9*B;sU^jbf2SpXF>G(TpJD$I5x9m=X z_my!RWhy?)SQO_>L~${hvT+fOGRlbaFrSXn;GB)qc+P_5X0Z|ZlU$tkn8igp6!qI> z@S42u^#%>kaXY@d=Xc!B-+9mVJ@*Cg?5mYWBFocan1^vhIdsXENhb0v`tmoC#_TMZ z6-drJ7xN?+qxv1a+WXvdJ-g-i2iFPefPsD9;XNCvg}_wu^&gC$vWbX98X$exyvTC$Bq>g3VK${iouVFSFXJ%9 zvmy&7LPl?hLdk_sN9GTMBsfJW=Zh0MOc~<(wJxd$wOgmNc=*cHl(oTkTW;fp-{zj(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X8`AEz8`jVT<8ypA(pC5uPzpb5B$F-@t`h>2gq5#qem8SkY zf%lc`J0%t&rsM$b&9YEQq_WBThc2ekmI=qsMT2UPr{;@#dSD?*j8dd;m+C~K4t@e( z!-(|=R#*I~Z6XWR*MPXSjMF*b0{}$U4%?=N9xq)iHL>xL|2ICC3fVZh zB7U{4W$OAs|0K?WS;K^e3a+j5zZ3Z5a^OS0lSpaT@%x{te&se@*}Z literal 0 HcmV?d00001 diff --git a/aptos-move/framework/aptos-stdlib/sources/type_info.move b/aptos-move/framework/aptos-stdlib/sources/type_info.move index 2989c0529d80e..1483267cc1100 100644 --- a/aptos-move/framework/aptos-stdlib/sources/type_info.move +++ b/aptos-move/framework/aptos-stdlib/sources/type_info.move @@ -1,4 +1,6 @@ module aptos_std::type_info { + use std::string; + struct TypeInfo has copy, drop, store { account_address: address, module_name: vector, @@ -18,6 +20,7 @@ module aptos_std::type_info { } public native fun type_of(): TypeInfo; + public native fun full_name(): string::String; #[test] fun test() { @@ -26,4 +29,31 @@ module aptos_std::type_info { assert!(module_name(&type_info) == b"type_info", 1); assert!(struct_name(&type_info) == b"TypeInfo", 2); } + + #[test] + fun test_full_name() { + use aptos_std::table::Table; + + assert!(full_name() == string::utf8(b"bool"), 0); + assert!(full_name() == string::utf8(b"u8"), 1); + assert!(full_name() == string::utf8(b"u64"), 2); + assert!(full_name() == string::utf8(b"u128"), 3); + assert!(full_name
() == string::utf8(b"address"), 4); + assert!(full_name() == string::utf8(b"signer"), 5); + + // vector + assert!(full_name>() == string::utf8(b"vector"), 6); + assert!(full_name>>() == string::utf8(b"vector>"), 7); + assert!(full_name>>() == string::utf8(b"vector>"), 8); + + + // struct + assert!(full_name() == string::utf8(b"0x1::type_info::TypeInfo"), 9); + assert!(full_name< + Table< + TypeInfo, + Table> + > + >() == string::utf8(b"0x1::table::Table<0x1::type_info::TypeInfo, 0x1::table::Table>"), 10); + } } diff --git a/aptos-move/framework/src/natives/mod.rs b/aptos-move/framework/src/natives/mod.rs index 0b42d10a9d96d..9bba3f9a5d1e7 100644 --- a/aptos-move/framework/src/natives/mod.rs +++ b/aptos-move/framework/src/natives/mod.rs @@ -14,6 +14,7 @@ use move_deps::{ pub mod cost { pub const APTOS_CREATE_ADDRESS: u64 = 5; pub const APTOS_LIB_TYPE_OF: u64 = 10; + pub const APTOS_LIB_TYPE_NAME: u64 = 10; pub const APTOS_SIP_HASH: u64 = 10; pub const APTOS_SECP256K1_RECOVER: u64 = 71; } @@ -50,6 +51,7 @@ pub fn all_natives(framework_addr: AccountAddress) -> NativeFunctionTable { signature::native_secp256k1_recover, ), ("type_info", "type_of", type_info::type_of), + ("type_info", "full_name", type_info::full_name), ("hash", "sip_hash", hash::native_sip_hash), ]; NATIVES diff --git a/aptos-move/framework/src/natives/type_info.rs b/aptos-move/framework/src/natives/type_info.rs index 6367ac85cc56d..98b6c2efabd52 100644 --- a/aptos-move/framework/src/natives/type_info.rs +++ b/aptos-move/framework/src/natives/type_info.rs @@ -29,6 +29,7 @@ pub fn type_of( let cost = GasCost::new(super::cost::APTOS_LIB_TYPE_OF, 1).total(); let type_tag = context.type_to_type_tag(&ty_args[0])?; + if let TypeTag::Struct(struct_tag) = type_tag { Ok(NativeResult::ok( cost, @@ -42,6 +43,27 @@ pub fn type_of( } } +/// Returns a string representing the TypeTag of the parameter. +pub fn full_name( + context: &mut NativeContext, + ty_args: Vec, + arguments: VecDeque, +) -> PartialVMResult { + debug_assert!(ty_args.len() == 1); + debug_assert!(arguments.is_empty()); + + let cost = GasCost::new(super::cost::APTOS_LIB_TYPE_NAME, 1).total(); + let type_tag = context.type_to_type_tag(&ty_args[0])?; + let type_name = type_tag.to_string(); + + Ok(NativeResult::ok( + cost, + smallvec![Value::struct_(Struct::pack(vec![Value::vector_u8( + type_name.as_bytes().to_vec() + )]))], + )) +} + fn type_of_internal(struct_tag: &StructTag) -> Result, std::fmt::Error> { let mut name = struct_tag.name.to_string(); if let Some(first_ty) = struct_tag.type_params.first() { diff --git a/aptos-move/framework/tests/move_unit_test.rs b/aptos-move/framework/tests/move_unit_test.rs index 075d1cffb5da2..0af58ac547e2d 100644 --- a/aptos-move/framework/tests/move_unit_test.rs +++ b/aptos-move/framework/tests/move_unit_test.rs @@ -41,10 +41,15 @@ pub fn aptos_test_natives() -> NativeFunctionTable { } #[test] -fn move_unit_tests() { +fn move_framework_unit_tests() { run_tests_for_pkg("aptos-framework"); } +#[test] +fn move_stdlib_unit_tests() { + run_tests_for_pkg("aptos-stdlib"); +} + #[test] fn move_token_unit_tests() { run_tests_for_pkg("aptos-token"); From 6e75027a2506652b2c29715e505612b7d47c1306 Mon Sep 17 00:00:00 2001 From: aldenhu Date: Thu, 21 Jul 2022 09:57:33 -0700 Subject: [PATCH 2/3] fixup! move stdlib: type_info::type_name() --- .../aptos-stdlib/sources/type_info.move | 28 +++++++++---------- aptos-move/framework/src/natives/mod.rs | 2 +- aptos-move/framework/src/natives/type_info.rs | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/aptos-move/framework/aptos-stdlib/sources/type_info.move b/aptos-move/framework/aptos-stdlib/sources/type_info.move index 1483267cc1100..5bdc186a31dd6 100644 --- a/aptos-move/framework/aptos-stdlib/sources/type_info.move +++ b/aptos-move/framework/aptos-stdlib/sources/type_info.move @@ -20,7 +20,7 @@ module aptos_std::type_info { } public native fun type_of(): TypeInfo; - public native fun full_name(): string::String; + public native fun type_name(): string::String; #[test] fun test() { @@ -31,29 +31,29 @@ module aptos_std::type_info { } #[test] - fun test_full_name() { + fun test_type_name() { use aptos_std::table::Table; - assert!(full_name() == string::utf8(b"bool"), 0); - assert!(full_name() == string::utf8(b"u8"), 1); - assert!(full_name() == string::utf8(b"u64"), 2); - assert!(full_name() == string::utf8(b"u128"), 3); - assert!(full_name
() == string::utf8(b"address"), 4); - assert!(full_name() == string::utf8(b"signer"), 5); + assert!(type_name() == string::utf8(b"bool"), 0); + assert!(type_name() == string::utf8(b"u8"), 1); + assert!(type_name() == string::utf8(b"u64"), 2); + assert!(type_name() == string::utf8(b"u128"), 3); + assert!(type_name
() == string::utf8(b"address"), 4); + assert!(type_name() == string::utf8(b"signer"), 5); // vector - assert!(full_name>() == string::utf8(b"vector"), 6); - assert!(full_name>>() == string::utf8(b"vector>"), 7); - assert!(full_name>>() == string::utf8(b"vector>"), 8); + assert!(type_name>() == string::utf8(b"vector"), 6); + assert!(type_name>>() == string::utf8(b"vector>"), 7); + assert!(type_name>>() == string::utf8(b"vector>"), 8); // struct - assert!(full_name() == string::utf8(b"0x1::type_info::TypeInfo"), 9); - assert!(full_name< + assert!(type_name() == string::utf8(b"0x1::type_info::TypeInfo"), 9); + assert!(type_name< Table< TypeInfo, Table> > - >() == string::utf8(b"0x1::table::Table<0x1::type_info::TypeInfo, 0x1::table::Table>"), 10); + >() == string::utf8(b"0x1::table::Table<0x1::type_info::TypeInfo, 0x1::table::Table>>"), 10); } } diff --git a/aptos-move/framework/src/natives/mod.rs b/aptos-move/framework/src/natives/mod.rs index 9bba3f9a5d1e7..1c74fa539e53c 100644 --- a/aptos-move/framework/src/natives/mod.rs +++ b/aptos-move/framework/src/natives/mod.rs @@ -51,7 +51,7 @@ pub fn all_natives(framework_addr: AccountAddress) -> NativeFunctionTable { signature::native_secp256k1_recover, ), ("type_info", "type_of", type_info::type_of), - ("type_info", "full_name", type_info::full_name), + ("type_info", "type_name", type_info::type_name), ("hash", "sip_hash", hash::native_sip_hash), ]; NATIVES diff --git a/aptos-move/framework/src/natives/type_info.rs b/aptos-move/framework/src/natives/type_info.rs index 98b6c2efabd52..d475e56e9e6d4 100644 --- a/aptos-move/framework/src/natives/type_info.rs +++ b/aptos-move/framework/src/natives/type_info.rs @@ -44,7 +44,7 @@ pub fn type_of( } /// Returns a string representing the TypeTag of the parameter. -pub fn full_name( +pub fn type_name( context: &mut NativeContext, ty_args: Vec, arguments: VecDeque, From e42ddd214f5ed51d1786b16e8664e4b9d2fd0935 Mon Sep 17 00:00:00 2001 From: aldenhu Date: Thu, 21 Jul 2022 13:27:12 -0700 Subject: [PATCH 3/3] increase forge latency threashold --- testsuite/run_forge.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/run_forge.sh b/testsuite/run_forge.sh index 4c503081d3053..f186c8a0719d1 100755 --- a/testsuite/run_forge.sh +++ b/testsuite/run_forge.sh @@ -14,7 +14,7 @@ pwd | grep -qE 'aptos-core$' || (echo "Please run from aptos-core root directory # for calculating regression TPS_THRESHOLD=5000 -P99_LATENCY_MS_THRESHOLD=6000 +P99_LATENCY_MS_THRESHOLD=8000 FORGE_OUTPUT=${FORGE_OUTPUT:-forge_output.txt} FORGE_REPORT=${FORGE_REPORT:-forge_report.json}