From 6fd67993265ce1ffd003294e34d46055b702f5f9 Mon Sep 17 00:00:00 2001 From: "Brian R. Murphy" <132495859+brmataptos@users.noreply.github.com> Date: Tue, 15 Aug 2023 17:02:31 -0700 Subject: [PATCH] Thoroughly fix Issue 8875: Error out in compilation when encounter an unknown attribute (#9229) Fix issue-8875 thoroughly: warning for unknown attributes, add --skip-attribute-check flag. Omit warning on aptos_std library files, to avoid warning on some existing code. A few tangential fixes: * [third party/.../test, compiler] Fix Move.toml files to point to local files instead of network to avoid tests using old stdlib. Oddly, this requires fixes to capitalization of std. Fix the resolution warning to make it clear that std needs to be uncapitalized. * [compiler] Hack to move-compiler to avoid warning about unknown attributes in aptos_std=0x1. This avoids surprising warning on currently deployed library code. * [compiler] test cases and stdlib source code updates for attributes checks PR * [aptos stdlib] Now that we have verified that the move-compiler Aptos stdlib hack works, fix stdlib to use #[test_only] on test helper functions instead of #[testonly]. Leave struct attributes since it's a deployment problem to make it disappear. --- Cargo.lock | 2 + .../src/aptos_test_harness.rs | 7 +- .../samples/add-numbers/Move.toml | 3 +- .../framework/aptos-stdlib/doc/math128.md | 34 ---- .../framework/aptos-stdlib/doc/math64.md | 34 ---- .../framework/aptos-stdlib/doc/math_fixed.md | 34 ---- .../aptos-stdlib/doc/math_fixed64.md | 34 ---- .../aptos-stdlib/doc/string_utils.md | 57 +++--- .../aptos-stdlib/sources/math128.move | 2 +- .../aptos-stdlib/sources/math64.move | 2 +- .../aptos-stdlib/sources/math_fixed.move | 2 +- .../aptos-stdlib/sources/math_fixed64.move | 2 +- .../aptos-stdlib/sources/string_utils.move | 2 +- aptos-move/framework/src/aptos.rs | 7 +- aptos-move/framework/src/built_package.rs | 16 ++ aptos-move/framework/src/extended_checks.rs | 37 +++- aptos-move/framework/src/prover.rs | 10 +- .../framework/tests/move_prover_tests.rs | 12 +- aptos-move/framework/tests/move_unit_test.rs | 3 +- aptos-move/move-examples/Cargo.toml | 1 + .../move-examples/tests/move_prover_tests.rs | 2 + .../move-examples/tests/move_unit_tests.rs | 2 + .../src/admin_script_builder.rs | 5 +- crates/aptos/src/common/types.rs | 5 + crates/aptos/src/governance/mod.rs | 1 + crates/aptos/src/move_tool/coverage.rs | 3 + crates/aptos/src/move_tool/mod.rs | 24 ++- crates/aptos/src/move_tool/show.rs | 1 + crates/aptos/src/test/mod.rs | 1 + .../src/tests/proto_converter_tests.rs | 3 + third_party/move/benchmarks/src/move_vm.rs | 1 + third_party/move/evm/move-to-yul/src/lib.rs | 14 +- .../move-to-yul/tests/dispatcher_testsuite.rs | 17 +- .../move/evm/move-to-yul/tests/testsuite.rs | 14 +- .../async/move-async-vm/tests/testsuite.rs | 8 +- third_party/move/move-compiler-v2/Cargo.toml | 1 + third_party/move/move-compiler-v2/src/lib.rs | 3 + .../move/move-compiler-v2/src/options.rs | 3 + .../src/attr_derivation/async_deriver.rs | 29 ++- .../src/attr_derivation/evm_deriver.rs | 61 ++++++ .../move-compiler/src/attr_derivation/mod.rs | 68 +++++-- .../move/move-compiler/src/bin/move-build.rs | 17 +- .../move/move-compiler/src/bin/move-check.rs | 16 +- .../src/command_line/compiler.rs | 37 ++-- .../move-compiler/src/command_line/mod.rs | 2 + .../move-compiler/src/diagnostics/codes.rs | 2 + .../move/move-compiler/src/expansion/ast.rs | 7 +- .../move-compiler/src/expansion/translate.rs | 74 +++++++- third_party/move/move-compiler/src/lib.rs | 2 +- .../move/move-compiler/src/shared/mod.rs | 177 +++++++++++++++--- .../src/unit_test/filter_test_members.rs | 4 +- .../src/unit_test/plan_builder.rs | 2 +- .../src/verification/ast_filter.rs | 4 +- .../parser/aptos_stdlib_attributes.exp | 24 +++ .../parser/aptos_stdlib_attributes.move | 10 + .../parser/aptos_stdlib_attributes2.move | 6 + .../move_check/parser/attribute_placement.exp | 84 +++++++++ .../move_check/parser/attribute_variants.exp | 60 ++++++ .../parser/duplicate_attributes.exp | 18 ++ .../tests/move_check/parser/testonly.exp | 12 ++ .../tests/move_check/parser/testonly.move | 19 ++ .../aptos_stdlib_attributes.exp | 24 +++ .../aptos_stdlib_attributes.move | 10 + .../aptos_stdlib_attributes2.move | 6 + .../attribute_no_closing_bracket.exp | 8 + .../attribute_no_closing_bracket.move | 5 + .../attribute_placement.move | 46 +++++ .../attribute_variants.move | 6 + .../duplicate_attributes.exp | 24 +++ .../duplicate_attributes.move | 7 + .../extra_attributes.move | 26 +++ .../extra_attributes2.move | 23 +++ .../skip_attribute_checks/testonly.move | 9 + .../tests/move_check/typing/assign_tuple.exp | 9 + .../tests/move_check/typing/assign_tuple.move | 15 ++ .../tests/move_check/typing/tuple.move | 15 ++ .../unit_test/extra_attributes.move | 1 - .../unit_test/extra_attributes2.move | 23 +++ .../tests/move_check_testsuite.rs | 19 +- third_party/move/move-model/src/lib.rs | 32 ++-- .../move/move-model/tests/testsuite.rs | 10 +- .../move-prover/bytecode/tests/testsuite.rs | 4 +- .../move/move-prover/lab/src/benchmark.rs | 6 +- .../move-docgen/tests/testsuite.rs | 2 + third_party/move/move-prover/src/cli.rs | 14 +- third_party/move/move-prover/src/lib.rs | 4 +- .../move-vm/integration-tests/src/compiler.rs | 12 +- .../testing-infra/test-generation/src/lib.rs | 8 +- .../src/framework.rs | 20 +- .../src/vm_test_harness.rs | 18 +- .../build_tests/dependency_chain/args.exp | 6 + .../tests/build_tests/dev_address/args.exp | 6 + .../build_tests/empty_module_no_deps/args.exp | 6 + .../include_exclude_stdlib/args.exp | 12 ++ .../build_tests/unbound_address/args.exp | 2 +- .../cross_process_tests/Package1/Move.toml | 4 +- .../cross_process_tests/Package2/Move.toml | 4 +- .../no_git_remote_package/Move.toml | 2 +- .../upload_tests/valid_package1/Move.toml | 2 +- .../upload_tests/valid_package2/Move.toml | 2 +- .../upload_tests/valid_package3/Move.toml | 2 +- .../src/compilation/compiled_package.rs | 28 ++- .../src/compilation/model_builder.rs | 10 +- .../move/tools/move-package/src/lib.rs | 13 +- .../src/resolution/resolution_graph.rs | 2 +- .../compilation/basic_no_deps/Move.exp | 2 + .../basic_no_deps_address_assigned/Move.exp | 2 + .../Move.exp | 2 + .../basic_no_deps_test_mode/Move.exp | 2 + .../Move.exp | 2 + .../diamond_problem_no_conflict/Move.exp | 2 + .../compilation/multiple_deps_rename/Move.exp | 2 + .../multiple_deps_rename_one/Move.exp | 2 + .../test_sources/compilation/one_dep/Move.exp | 2 + .../one_dep_assigned_address/Move.exp | 2 + .../compilation/one_dep_renamed/Move.exp | 2 + .../compilation/one_dep_with_scripts/Move.exp | 2 + .../compilation/test_symlinks/Move.exp | 2 + .../invalid_identifier_package_name/Move.exp | 2 + .../parsing/minimal_manifest/Move.exp | 2 + .../resolution/basic_no_deps/Move.exp | 2 + .../basic_no_deps_address_assigned/Move.exp | 2 + .../Move.exp | 2 +- .../Move.exp | 2 + .../resolution/dep_good_digest/Move.exp | 2 + .../Move.exp | 2 + .../diamond_problem_no_conflict/Move.exp | 2 + .../resolution/multiple_deps_rename/Move.exp | 2 + .../test_sources/resolution/one_dep/Move.exp | 2 + .../one_dep_assigned_address/Move.exp | 2 + .../one_dep_multiple_of_same_name/Move.exp | 2 + .../one_dep_reassigned_address/Move.exp | 2 + .../Move.exp | 2 + .../Package1/Move.toml | 4 +- .../Package2/Move.toml | 4 +- .../move/tools/move-unit-test/src/lib.rs | 16 +- 136 files changed, 1392 insertions(+), 339 deletions(-) create mode 100644 third_party/move/move-compiler/tests/move_check/parser/aptos_stdlib_attributes.exp create mode 100644 third_party/move/move-compiler/tests/move_check/parser/aptos_stdlib_attributes.move create mode 100644 third_party/move/move-compiler/tests/move_check/parser/aptos_stdlib_attributes2.move create mode 100644 third_party/move/move-compiler/tests/move_check/parser/attribute_placement.exp create mode 100644 third_party/move/move-compiler/tests/move_check/parser/attribute_variants.exp create mode 100644 third_party/move/move-compiler/tests/move_check/parser/testonly.exp create mode 100644 third_party/move/move-compiler/tests/move_check/parser/testonly.move create mode 100644 third_party/move/move-compiler/tests/move_check/skip_attribute_checks/aptos_stdlib_attributes.exp create mode 100644 third_party/move/move-compiler/tests/move_check/skip_attribute_checks/aptos_stdlib_attributes.move create mode 100644 third_party/move/move-compiler/tests/move_check/skip_attribute_checks/aptos_stdlib_attributes2.move create mode 100644 third_party/move/move-compiler/tests/move_check/skip_attribute_checks/attribute_no_closing_bracket.exp create mode 100644 third_party/move/move-compiler/tests/move_check/skip_attribute_checks/attribute_no_closing_bracket.move create mode 100644 third_party/move/move-compiler/tests/move_check/skip_attribute_checks/attribute_placement.move create mode 100644 third_party/move/move-compiler/tests/move_check/skip_attribute_checks/attribute_variants.move create mode 100644 third_party/move/move-compiler/tests/move_check/skip_attribute_checks/duplicate_attributes.exp create mode 100644 third_party/move/move-compiler/tests/move_check/skip_attribute_checks/duplicate_attributes.move create mode 100644 third_party/move/move-compiler/tests/move_check/skip_attribute_checks/extra_attributes.move create mode 100644 third_party/move/move-compiler/tests/move_check/skip_attribute_checks/extra_attributes2.move create mode 100644 third_party/move/move-compiler/tests/move_check/skip_attribute_checks/testonly.move create mode 100644 third_party/move/move-compiler/tests/move_check/typing/assign_tuple.exp create mode 100644 third_party/move/move-compiler/tests/move_check/typing/assign_tuple.move create mode 100644 third_party/move/move-compiler/tests/move_check/typing/tuple.move create mode 100644 third_party/move/move-compiler/tests/move_check/unit_test/extra_attributes2.move diff --git a/Cargo.lock b/Cargo.lock index eb8c93e69c4ef..11d4e34607a2f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2297,6 +2297,7 @@ dependencies = [ name = "aptos-move-examples" version = "0.1.0" dependencies = [ + "aptos-framework", "aptos-gas-schedule", "aptos-types", "aptos-vm", @@ -8966,6 +8967,7 @@ dependencies = [ "itertools", "move-binary-format", "move-command-line-common", + "move-compiler", "move-core-types", "move-disassembler", "move-ir-types", diff --git a/aptos-move/aptos-transactional-test-harness/src/aptos_test_harness.rs b/aptos-move/aptos-transactional-test-harness/src/aptos_test_harness.rs index 17582020a415f..8480f5bf40592 100644 --- a/aptos-move/aptos-transactional-test-harness/src/aptos_test_harness.rs +++ b/aptos-move/aptos-transactional-test-harness/src/aptos_test_harness.rs @@ -51,7 +51,7 @@ use move_transactional_test_runner::{ use move_vm_runtime::session::SerializedReturnValues; use once_cell::sync::Lazy; use std::{ - collections::{BTreeMap, HashMap}, + collections::{BTreeMap, BTreeSet, HashMap}, convert::TryFrom, fmt, path::Path, @@ -294,6 +294,7 @@ static PRECOMPILED_APTOS_FRAMEWORK: Lazy = Lazy::new(|| { deps, None, move_compiler::Flags::empty().set_sources_shadow_deps(false), + aptos_framework::extended_checks::get_all_attribute_names(), ) .unwrap(); match program_res { @@ -551,6 +552,10 @@ impl<'a> MoveTestAdapter<'a> for AptosTestAdapter<'a> { self.default_syntax } + fn known_attributes(&self) -> &BTreeSet { + aptos_framework::extended_checks::get_all_attribute_names() + } + fn init( default_syntax: SyntaxChoice, _comparison_mode: bool, diff --git a/aptos-move/aptos-vm-benchmarks/samples/add-numbers/Move.toml b/aptos-move/aptos-vm-benchmarks/samples/add-numbers/Move.toml index add784d359c40..2cf87321920de 100644 --- a/aptos-move/aptos-vm-benchmarks/samples/add-numbers/Move.toml +++ b/aptos-move/aptos-vm-benchmarks/samples/add-numbers/Move.toml @@ -2,6 +2,5 @@ name = 'add-numbers' version = '1.0.0' [dependencies.AptosFramework] -git = 'https://github.com/aptos-labs/aptos-core.git' -rev = 'main' +local = '../../../..' subdir = 'aptos-move/framework/aptos-framework' diff --git a/aptos-move/framework/aptos-stdlib/doc/math128.md b/aptos-move/framework/aptos-stdlib/doc/math128.md index be26558d63967..b3a271c2e918b 100644 --- a/aptos-move/framework/aptos-stdlib/doc/math128.md +++ b/aptos-move/framework/aptos-stdlib/doc/math128.md @@ -18,7 +18,6 @@ Standard math utilities missing in the Move Language. - [Function `log2_64`](#0x1_math128_log2_64) - [Function `sqrt`](#0x1_math128_sqrt) - [Function `ceil_div`](#0x1_math128_ceil_div) -- [Function `assert_approx_the_same`](#0x1_math128_assert_approx_the_same) - [Specification](#@Specification_1) - [Function `max`](#@Specification_1_max) - [Function `min`](#@Specification_1_min) @@ -414,39 +413,6 @@ Returns square root of x, precisely floor(sqrt(x)) - - - - -## Function `assert_approx_the_same` - -For functions that approximate a value it's useful to test a value is close -to the most correct value up to last digit - - -
#[testonly]
-fun assert_approx_the_same(x: u128, y: u128, precission: u128)
-
- - - -
-Implementation - - -
fun assert_approx_the_same(x: u128, y: u128, precission: u128) {
-    if (x < y) {
-        let tmp = x;
-        x = y;
-        y = tmp;
-    };
-    let mult = pow(10, precission);
-    assert!((x - y) * mult < x, 0);
-}
-
- - -
diff --git a/aptos-move/framework/aptos-stdlib/doc/math64.md b/aptos-move/framework/aptos-stdlib/doc/math64.md index bc6436435a49e..cce24aa3e9515 100644 --- a/aptos-move/framework/aptos-stdlib/doc/math64.md +++ b/aptos-move/framework/aptos-stdlib/doc/math64.md @@ -17,7 +17,6 @@ Standard math utilities missing in the Move Language. - [Function `log2`](#0x1_math64_log2) - [Function `sqrt`](#0x1_math64_sqrt) - [Function `ceil_div`](#0x1_math64_ceil_div) -- [Function `assert_approx_the_same`](#0x1_math64_assert_approx_the_same) - [Specification](#@Specification_1) - [Function `max`](#@Specification_1_max) - [Function `min`](#@Specification_1_min) @@ -369,39 +368,6 @@ Returns square root of x, precisely floor(sqrt(x)) - - - - -## Function `assert_approx_the_same` - -For functions that approximate a value it's useful to test a value is close -to the most correct value up to last digit - - -
#[testonly]
-fun assert_approx_the_same(x: u128, y: u128, precission: u64)
-
- - - -
-Implementation - - -
fun assert_approx_the_same(x: u128, y: u128, precission: u64) {
-    if (x < y) {
-        let tmp = x;
-        x = y;
-        y = tmp;
-    };
-    let mult = (pow(10, precission) as u128);
-    assert!((x - y) * mult < x, 0);
-}
-
- - -
diff --git a/aptos-move/framework/aptos-stdlib/doc/math_fixed.md b/aptos-move/framework/aptos-stdlib/doc/math_fixed.md index e00553a0d5203..936d1ee612090 100644 --- a/aptos-move/framework/aptos-stdlib/doc/math_fixed.md +++ b/aptos-move/framework/aptos-stdlib/doc/math_fixed.md @@ -15,7 +15,6 @@ Standard math utilities missing in the Move Language. - [Function `mul_div`](#0x1_math_fixed_mul_div) - [Function `exp_raw`](#0x1_math_fixed_exp_raw) - [Function `pow_raw`](#0x1_math_fixed_pow_raw) -- [Function `assert_approx_the_same`](#0x1_math_fixed_assert_approx_the_same)
use 0x1::error;
@@ -294,39 +293,6 @@ Specialized function for x * y / z that omits intermediate shifting
 
 
 
-
-
-
-
-## Function `assert_approx_the_same`
-
-For functions that approximate a value it's useful to test a value is close
-to the most correct value up to last digit
-
-
-
#[testonly]
-fun assert_approx_the_same(x: u128, y: u128, precission: u128)
-
- - - -
-Implementation - - -
fun assert_approx_the_same(x: u128, y: u128, precission: u128) {
-    if (x < y) {
-        let tmp = x;
-        x = y;
-        y = tmp;
-    };
-    let mult = math128::pow(10, precission);
-    assert!((x - y) * mult < x, 0);
-}
-
- - -
diff --git a/aptos-move/framework/aptos-stdlib/doc/math_fixed64.md b/aptos-move/framework/aptos-stdlib/doc/math_fixed64.md index a436af50f9bd5..7dcaa1dda440c 100644 --- a/aptos-move/framework/aptos-stdlib/doc/math_fixed64.md +++ b/aptos-move/framework/aptos-stdlib/doc/math_fixed64.md @@ -15,7 +15,6 @@ Standard math utilities missing in the Move Language. - [Function `mul_div`](#0x1_math_fixed64_mul_div) - [Function `exp_raw`](#0x1_math_fixed64_exp_raw) - [Function `pow_raw`](#0x1_math_fixed64_pow_raw) -- [Function `assert_approx_the_same`](#0x1_math_fixed64_assert_approx_the_same)
use 0x1::error;
@@ -289,39 +288,6 @@ Specialized function for x * y / z that omits intermediate shifting
 
 
 
-
-
-
-
-## Function `assert_approx_the_same`
-
-For functions that approximate a value it's useful to test a value is close
-to the most correct value up to last digit
-
-
-
#[testonly]
-fun assert_approx_the_same(x: u256, y: u256, precission: u128)
-
- - - -
-Implementation - - -
fun assert_approx_the_same(x: u256, y: u256, precission: u128) {
-    if (x < y) {
-        let tmp = x;
-        x = y;
-        y = tmp;
-    };
-    let mult = (math128::pow(10, precission) as u256);
-    assert!((x - y) * mult < x, 0);
-}
-
- - -
diff --git a/aptos-move/framework/aptos-stdlib/doc/string_utils.md b/aptos-move/framework/aptos-stdlib/doc/string_utils.md index 47d5054258215..05d780705f4b0 100644 --- a/aptos-move/framework/aptos-stdlib/doc/string_utils.md +++ b/aptos-move/framework/aptos-stdlib/doc/string_utils.md @@ -9,7 +9,8 @@ A module for formatting move values as strings. - [Struct `Cons`](#0x1_string_utils_Cons) - [Struct `NIL`](#0x1_string_utils_NIL) - [Struct `FakeCons`](#0x1_string_utils_FakeCons) -- [Constants](#@Constants_0) + - [[test_only]](#@[test_only]_0) +- [Constants](#@Constants_1) - [Function `to_string`](#0x1_string_utils_to_string) - [Function `to_string_with_canonical_addresses`](#0x1_string_utils_to_string_with_canonical_addresses) - [Function `to_string_with_integer_types`](#0x1_string_utils_to_string_with_integer_types) @@ -26,17 +27,17 @@ A module for formatting move values as strings. - [Function `list4`](#0x1_string_utils_list4) - [Function `native_format`](#0x1_string_utils_native_format) - [Function `native_format_list`](#0x1_string_utils_native_format_list) -- [Specification](#@Specification_1) - - [Function `to_string`](#@Specification_1_to_string) - - [Function `to_string_with_canonical_addresses`](#@Specification_1_to_string_with_canonical_addresses) - - [Function `to_string_with_integer_types`](#@Specification_1_to_string_with_integer_types) - - [Function `debug_string`](#@Specification_1_debug_string) - - [Function `format1`](#@Specification_1_format1) - - [Function `format2`](#@Specification_1_format2) - - [Function `format3`](#@Specification_1_format3) - - [Function `format4`](#@Specification_1_format4) - - [Function `native_format`](#@Specification_1_native_format) - - [Function `native_format_list`](#@Specification_1_native_format_list) +- [Specification](#@Specification_2) + - [Function `to_string`](#@Specification_2_to_string) + - [Function `to_string_with_canonical_addresses`](#@Specification_2_to_string_with_canonical_addresses) + - [Function `to_string_with_integer_types`](#@Specification_2_to_string_with_integer_types) + - [Function `debug_string`](#@Specification_2_debug_string) + - [Function `format1`](#@Specification_2_format1) + - [Function `format2`](#@Specification_2_format2) + - [Function `format3`](#@Specification_2_format3) + - [Function `format4`](#@Specification_2_format4) + - [Function `native_format`](#@Specification_2_native_format) + - [Function `native_format_list`](#@Specification_2_native_format_list)
use 0x1::string;
@@ -109,9 +110,13 @@ A module for formatting move values as strings.
 ## Struct `FakeCons`
 
 
+
 
-
#[testonly]
-struct FakeCons<T, N> has copy, drop, store
+### [test_only]
+
+
+
+
struct FakeCons<T, N> has copy, drop, store
 
@@ -138,7 +143,7 @@ A module for formatting move values as strings. - + ## Constants @@ -542,12 +547,12 @@ Formatting with a rust-like format string, eg. + ## Specification - + ### Function `to_string` @@ -564,7 +569,7 @@ Formatting with a rust-like format string, eg. + ### Function `to_string_with_canonical_addresses` @@ -581,7 +586,7 @@ Formatting with a rust-like format string, eg. + ### Function `to_string_with_integer_types` @@ -598,7 +603,7 @@ Formatting with a rust-like format string, eg. + ### Function `debug_string` @@ -615,7 +620,7 @@ Formatting with a rust-like format string, eg. + ### Function `format1` @@ -632,7 +637,7 @@ Formatting with a rust-like format string, eg. + ### Function `format2` @@ -649,7 +654,7 @@ Formatting with a rust-like format string, eg. + ### Function `format3` @@ -666,7 +671,7 @@ Formatting with a rust-like format string, eg. + ### Function `format4` @@ -683,7 +688,7 @@ Formatting with a rust-like format string, eg. + ### Function `native_format` @@ -701,7 +706,7 @@ Formatting with a rust-like format string, eg. + ### Function `native_format_list` diff --git a/aptos-move/framework/aptos-stdlib/sources/math128.move b/aptos-move/framework/aptos-stdlib/sources/math128.move index a37cbe094d4f1..8f4dee3fb9ad7 100644 --- a/aptos-move/framework/aptos-stdlib/sources/math128.move +++ b/aptos-move/framework/aptos-stdlib/sources/math128.move @@ -295,7 +295,7 @@ module aptos_std::math128 { assert!(result == 13043817825332782212, 0); } - #[testonly] + #[test_only] /// For functions that approximate a value it's useful to test a value is close /// to the most correct value up to last digit fun assert_approx_the_same(x: u128, y: u128, precission: u128) { diff --git a/aptos-move/framework/aptos-stdlib/sources/math64.move b/aptos-move/framework/aptos-stdlib/sources/math64.move index 6aa733ed7fca6..9cf086c36182d 100644 --- a/aptos-move/framework/aptos-stdlib/sources/math64.move +++ b/aptos-move/framework/aptos-stdlib/sources/math64.move @@ -251,7 +251,7 @@ module aptos_std::math64 { assert!(result == 3037000499, 0); } - #[testonly] + #[test_only] /// For functions that approximate a value it's useful to test a value is close /// to the most correct value up to last digit fun assert_approx_the_same(x: u128, y: u128, precission: u64) { diff --git a/aptos-move/framework/aptos-stdlib/sources/math_fixed.move b/aptos-move/framework/aptos-stdlib/sources/math_fixed.move index 8046246da6f04..b7993a5f13bf4 100644 --- a/aptos-move/framework/aptos-stdlib/sources/math_fixed.move +++ b/aptos-move/framework/aptos-stdlib/sources/math_fixed.move @@ -124,7 +124,7 @@ module aptos_std::math_fixed { assert_approx_the_same(result, 1 << 33, 6); } - #[testonly] + #[test_only] /// For functions that approximate a value it's useful to test a value is close /// to the most correct value up to last digit fun assert_approx_the_same(x: u128, y: u128, precission: u128) { diff --git a/aptos-move/framework/aptos-stdlib/sources/math_fixed64.move b/aptos-move/framework/aptos-stdlib/sources/math_fixed64.move index 34cf37ca37a66..2369b6afebc3e 100644 --- a/aptos-move/framework/aptos-stdlib/sources/math_fixed64.move +++ b/aptos-move/framework/aptos-stdlib/sources/math_fixed64.move @@ -127,7 +127,7 @@ module aptos_std::math_fixed64 { assert_approx_the_same(result, 1 << 65, 16); } - #[testonly] + #[test_only] /// For functions that approximate a value it's useful to test a value is close /// to the most correct value up to last digit fun assert_approx_the_same(x: u256, y: u256, precission: u128) { diff --git a/aptos-move/framework/aptos-stdlib/sources/string_utils.move b/aptos-move/framework/aptos-stdlib/sources/string_utils.move index c7e3645e7d14a..c7f239b70de0e 100644 --- a/aptos-move/framework/aptos-stdlib/sources/string_utils.move +++ b/aptos-move/framework/aptos-stdlib/sources/string_utils.move @@ -107,7 +107,7 @@ module aptos_std::string_utils { native_format_list(&b"a = {} b = {} c = {}", &l); } - #[testonly] + /// #[test_only] struct FakeCons has copy, drop, store { car: T, cdr: N, diff --git a/aptos-move/framework/src/aptos.rs b/aptos-move/framework/src/aptos.rs index b257e4fc5a68f..f4912082d2532 100644 --- a/aptos-move/framework/src/aptos.rs +++ b/aptos-move/framework/src/aptos.rs @@ -4,8 +4,9 @@ #![forbid(unsafe_code)] use crate::{ - docgen::DocgenOptions, path_in_crate, release_builder::RELEASE_BUNDLE_EXTENSION, - release_bundle::ReleaseBundle, BuildOptions, ReleaseOptions, + docgen::DocgenOptions, extended_checks, path_in_crate, + release_builder::RELEASE_BUNDLE_EXTENSION, release_bundle::ReleaseBundle, BuildOptions, + ReleaseOptions, }; use clap::ValueEnum; use move_command_line_common::address::NumericalAddress; @@ -118,6 +119,8 @@ impl ReleaseTarget { }), skip_fetch_latest_git_deps: true, bytecode_version: None, + skip_attribute_checks: false, + known_attributes: extended_checks::get_all_attribute_names().clone(), }, packages: packages.iter().map(|(path, _)| path.to_owned()).collect(), rust_bindings: packages diff --git a/aptos-move/framework/src/built_package.rs b/aptos-move/framework/src/built_package.rs index 2b2ee97ba7f98..f1255da0008f6 100644 --- a/aptos-move/framework/src/built_package.rs +++ b/aptos-move/framework/src/built_package.rs @@ -68,6 +68,10 @@ pub struct BuildOptions { pub skip_fetch_latest_git_deps: bool, #[clap(long)] pub bytecode_version: Option, + #[clap(long)] + pub skip_attribute_checks: bool, + #[clap(skip)] + pub known_attributes: BTreeSet, } // Because named_addresses has no parser, we can't use clap's default impl. This must be aligned @@ -88,6 +92,8 @@ impl Default for BuildOptions { // while in a test (and cause some havoc) skip_fetch_latest_git_deps: false, bytecode_version: None, + skip_attribute_checks: false, + known_attributes: extended_checks::get_all_attribute_names().clone(), } } } @@ -106,6 +112,8 @@ pub fn build_model( additional_named_addresses: BTreeMap, target_filter: Option, bytecode_version: Option, + skip_attribute_checks: bool, + known_attributes: BTreeSet, ) -> anyhow::Result { let build_config = BuildConfig { dev_mode, @@ -119,6 +127,8 @@ pub fn build_model( fetch_deps_only: false, skip_fetch_latest_git_deps: true, bytecode_version, + skip_attribute_checks, + known_attributes, }; build_config.move_model_for_package(package_path, ModelConfig { target_filter, @@ -133,6 +143,7 @@ impl BuiltPackage { /// and is not `Ok` if there was an error among those. pub fn build(package_path: PathBuf, options: BuildOptions) -> anyhow::Result { let bytecode_version = options.bytecode_version; + let skip_attribute_checks = options.skip_attribute_checks; let build_config = BuildConfig { dev_mode: options.dev, additional_named_addresses: options.named_addresses.clone(), @@ -145,7 +156,10 @@ impl BuiltPackage { fetch_deps_only: false, skip_fetch_latest_git_deps: options.skip_fetch_latest_git_deps, bytecode_version, + skip_attribute_checks, + known_attributes: options.known_attributes.clone(), }; + eprintln!("Compiling, may take a little while to download git dependencies..."); let mut package = build_config.compile_package_no_exit(&package_path, &mut stderr())?; @@ -157,6 +171,8 @@ impl BuiltPackage { options.named_addresses.clone(), None, bytecode_version, + skip_attribute_checks, + options.known_attributes.clone(), )?; let runtime_metadata = extended_checks::run_extended_checks(model); if model.diag_count(Severity::Warning) > 0 { diff --git a/aptos-move/framework/src/extended_checks.rs b/aptos-move/framework/src/extended_checks.rs index 57d563f2800ee..651d4ab464fba 100644 --- a/aptos-move/framework/src/extended_checks.rs +++ b/aptos-move/framework/src/extended_checks.rs @@ -3,6 +3,7 @@ use crate::{KnownAttribute, RuntimeModuleMetadataV1}; use move_binary_format::file_format::{Ability, AbilitySet, Visibility}; +use move_compiler::shared::known_attributes; use move_core_types::{ account_address::AccountAddress, errmap::{ErrorDescription, ErrorMapping}, @@ -18,11 +19,16 @@ use move_model::{ symbol::Symbol, ty::{PrimitiveType, ReferenceKind, Type}, }; -use std::{collections::BTreeMap, rc::Rc, str::FromStr}; +use once_cell::sync::Lazy; +use std::{ + collections::{BTreeMap, BTreeSet}, + rc::Rc, + str::FromStr, +}; use thiserror::Error; const INIT_MODULE_FUN: &str = "init_module"; -const LEGAC_ENTRY_FUN_ATTRIBUTE: &str = "legacy_entry_fun"; +const LEGACY_ENTRY_FUN_ATTRIBUTE: &str = "legacy_entry_fun"; const ERROR_PREFIX: &str = "E"; const RESOURCE_GROUP: &str = "resource_group"; const RESOURCE_GROUP_MEMBER: &str = "resource_group_member"; @@ -30,6 +36,31 @@ const RESOURCE_GROUP_NAME: &str = "group"; const RESOURCE_GROUP_SCOPE: &str = "scope"; const VIEW_FUN_ATTRIBUTE: &str = "view"; +// top-level attribute names, only. +pub fn get_all_attribute_names() -> &'static BTreeSet { + const ALL_ATTRIBUTE_NAMES: [&str; 4] = [ + LEGACY_ENTRY_FUN_ATTRIBUTE, + RESOURCE_GROUP, + RESOURCE_GROUP_MEMBER, + VIEW_FUN_ATTRIBUTE, + ]; + + fn extended_attribute_names() -> BTreeSet { + ALL_ATTRIBUTE_NAMES + .into_iter() + .map(|s| s.to_string()) + .collect::>() + } + + static KNOWN_ATTRIBUTES_SET: Lazy> = Lazy::new(|| { + use known_attributes::AttributeKind; + let mut attributes = extended_attribute_names(); + known_attributes::KnownAttribute::add_attribute_names(&mut attributes); + attributes + }); + &KNOWN_ATTRIBUTES_SET +} + /// Run the extended context checker on target modules in the environment and returns a map /// from module to extended runtime metadata. Any errors during context checking are reported to /// `env`. This is invoked after general build succeeds. @@ -118,7 +149,7 @@ impl<'a> ExtendedChecker<'a> { if !fun.is_entry() { continue; } - if self.has_attribute(fun, LEGAC_ENTRY_FUN_ATTRIBUTE) { + if self.has_attribute(fun, LEGACY_ENTRY_FUN_ATTRIBUTE) { // Skip checking for legacy entries continue; } diff --git a/aptos-move/framework/src/prover.rs b/aptos-move/framework/src/prover.rs index 8e4c6bfe43fa4..16210705dcae9 100644 --- a/aptos-move/framework/src/prover.rs +++ b/aptos-move/framework/src/prover.rs @@ -8,7 +8,11 @@ use codespan_reporting::{ }; use log::LevelFilter; use move_core_types::account_address::AccountAddress; -use std::{collections::BTreeMap, path::Path, time::Instant}; +use std::{ + collections::{BTreeMap, BTreeSet}, + path::Path, + time::Instant, +}; use tempfile::TempDir; #[derive(Debug, Clone, clap::Parser, serde::Serialize, serde::Deserialize)] @@ -114,6 +118,8 @@ impl ProverOptions { package_path: &Path, named_addresses: BTreeMap, bytecode_version: Option, + skip_attribute_checks: bool, + known_attributes: &BTreeSet, ) -> anyhow::Result<()> { let now = Instant::now(); let for_test = self.for_test; @@ -123,6 +129,8 @@ impl ProverOptions { named_addresses, self.filter.clone(), bytecode_version, + skip_attribute_checks, + known_attributes.clone(), )?; let mut options = self.convert_options(); // Need to ensure a distinct output.bpl file for concurrent execution. In non-test diff --git a/aptos-move/framework/tests/move_prover_tests.rs b/aptos-move/framework/tests/move_prover_tests.rs index 684a8650f3622..54947cb469e9a 100644 --- a/aptos-move/framework/tests/move_prover_tests.rs +++ b/aptos-move/framework/tests/move_prover_tests.rs @@ -1,7 +1,7 @@ // Copyright © Aptos Foundation // SPDX-License-Identifier: Apache-2.0 -use aptos_framework::prover::ProverOptions; +use aptos_framework::{extended_checks, prover::ProverOptions}; use std::{collections::BTreeMap, path::PathBuf}; const ENV_TEST_INCONSISTENCY: &str = "MVP_TEST_INCONSISTENCY"; @@ -51,8 +51,16 @@ pub fn run_prover_for_pkg(path_to_pkg: impl Into) { options.vc_timeout = read_env_var(ENV_TEST_VC_TIMEOUT) .parse::() .unwrap_or(options.vc_timeout); + let skip_attribute_checks = false; options - .prove(false, pkg_path.as_path(), BTreeMap::default(), None) + .prove( + false, + pkg_path.as_path(), + BTreeMap::default(), + None, + skip_attribute_checks, + extended_checks::get_all_attribute_names(), + ) .unwrap() } } diff --git a/aptos-move/framework/tests/move_unit_test.rs b/aptos-move/framework/tests/move_unit_test.rs index b48fe2781442e..de6ce0ffdf086 100644 --- a/aptos-move/framework/tests/move_unit_test.rs +++ b/aptos-move/framework/tests/move_unit_test.rs @@ -2,7 +2,7 @@ // Parts of the project are originally copyright © Meta Platforms, Inc. // SPDX-License-Identifier: Apache-2.0 -use aptos_framework::path_in_crate; +use aptos_framework::{extended_checks, path_in_crate}; use aptos_gas_schedule::{MiscGasParameters, NativeGasParameters, LATEST_GAS_FEATURE_VERSION}; use aptos_types::on_chain_config::{Features, TimedFeatures}; use aptos_vm::natives; @@ -18,6 +18,7 @@ fn run_tests_for_pkg(path_to_pkg: impl Into) { move_package::BuildConfig { test_mode: true, install_dir: Some(tempdir().unwrap().path().to_path_buf()), + known_attributes: extended_checks::get_all_attribute_names().clone(), ..Default::default() }, // TODO(Gas): double check if this is correct diff --git a/aptos-move/move-examples/Cargo.toml b/aptos-move/move-examples/Cargo.toml index a3494f792bd52..bef94422971ef 100644 --- a/aptos-move/move-examples/Cargo.toml +++ b/aptos-move/move-examples/Cargo.toml @@ -13,6 +13,7 @@ repository = { workspace = true } rust-version = { workspace = true } [dependencies] +aptos-framework = { workspace = true } aptos-gas-schedule = { workspace = true } aptos-types = { workspace = true } aptos-vm ={ workspace = true, features = ["testing"] } diff --git a/aptos-move/move-examples/tests/move_prover_tests.rs b/aptos-move/move-examples/tests/move_prover_tests.rs index c425f1a991a71..99ab8b3f8d480 100644 --- a/aptos-move/move-examples/tests/move_prover_tests.rs +++ b/aptos-move/move-examples/tests/move_prover_tests.rs @@ -1,6 +1,7 @@ // Copyright © Aptos Foundation // SPDX-License-Identifier: Apache-2.0 +use aptos_framework::extended_checks; use aptos_types::account_address::AccountAddress; use move_cli::base::prove::run_move_prover; use std::{collections::BTreeMap, path::PathBuf}; @@ -24,6 +25,7 @@ pub fn run_prover_for_pkg( additional_named_addresses: named_addr, test_mode: true, install_dir: Some(tempdir().unwrap().path().to_path_buf()), + known_attributes: extended_checks::get_all_attribute_names().clone(), ..Default::default() }; run_move_prover( diff --git a/aptos-move/move-examples/tests/move_unit_tests.rs b/aptos-move/move-examples/tests/move_unit_tests.rs index ca2adbe511fb6..ea802b0b00157 100644 --- a/aptos-move/move-examples/tests/move_unit_tests.rs +++ b/aptos-move/move-examples/tests/move_unit_tests.rs @@ -1,6 +1,7 @@ // Copyright © Aptos Foundation // SPDX-License-Identifier: Apache-2.0 +use aptos_framework::extended_checks; use aptos_gas_schedule::{MiscGasParameters, NativeGasParameters, LATEST_GAS_FEATURE_VERSION}; use aptos_types::{ account_address::{create_resource_address, AccountAddress}, @@ -33,6 +34,7 @@ pub fn run_tests_for_pkg( test_mode: true, install_dir: Some(tempdir().unwrap().path().to_path_buf()), additional_named_addresses: named_addr, + known_attributes: extended_checks::get_all_attribute_names().clone(), ..Default::default() }, UnitTestingConfig::default_with_bound(Some(100_000)), diff --git a/aptos-move/writeset-transaction-generator/src/admin_script_builder.rs b/aptos-move/writeset-transaction-generator/src/admin_script_builder.rs index fc0eb093e747f..0fee6788fb569 100644 --- a/aptos-move/writeset-transaction-generator/src/admin_script_builder.rs +++ b/aptos-move/writeset-transaction-generator/src/admin_script_builder.rs @@ -24,8 +24,11 @@ pub fn compile_script(source_file_str: String, bytecode_version: Option) -> .files() .unwrap(), aptos_framework::named_addresses().clone(), + Flags::empty() + .set_sources_shadow_deps(false) + .set_skip_attribute_checks(false), + aptos_framework::extended_checks::get_all_attribute_names(), ) - .set_flags(Flags::empty().set_sources_shadow_deps(false)) .build_and_report() .unwrap(); assert!(compiled_program.len() == 1); diff --git a/crates/aptos/src/common/types.rs b/crates/aptos/src/common/types.rs index 2297c69cb01b3..0c549b1d911cb 100644 --- a/crates/aptos/src/common/types.rs +++ b/crates/aptos/src/common/types.rs @@ -987,6 +987,10 @@ pub struct MovePackageDir { /// Specify the version of the bytecode the compiler is going to emit. #[clap(long)] pub bytecode_version: Option, + + /// Do not complain about unknown attributes in Move code. + #[clap(long)] + pub skip_attribute_checks: bool, } impl MovePackageDir { @@ -998,6 +1002,7 @@ impl MovePackageDir { named_addresses: Default::default(), skip_fetch_latest_git_deps: true, bytecode_version: None, + skip_attribute_checks: false, } } diff --git a/crates/aptos/src/governance/mod.rs b/crates/aptos/src/governance/mod.rs index 708777955a8b1..60a2817d62fa8 100644 --- a/crates/aptos/src/governance/mod.rs +++ b/crates/aptos/src/governance/mod.rs @@ -996,6 +996,7 @@ impl CliCommand<()> for GenerateUpgradeProposal { move_options.skip_fetch_latest_git_deps, move_options.named_addresses(), move_options.bytecode_version, + move_options.skip_attribute_checks, ); let package = BuiltPackage::build(package_path, options)?; let release = ReleasePackage::new(package)?; diff --git a/crates/aptos/src/move_tool/coverage.rs b/crates/aptos/src/move_tool/coverage.rs index 2212aa10bde65..d5dc439c7a9a4 100644 --- a/crates/aptos/src/move_tool/coverage.rs +++ b/crates/aptos/src/move_tool/coverage.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 use crate::common::types::{CliCommand, CliError, CliResult, CliTypedResult, MovePackageDir}; +use aptos_framework::extended_checks; use async_trait::async_trait; use clap::{Parser, Subcommand}; use move_compiler::compiled_unit::{CompiledUnit, NamedCompiledModule}; @@ -149,6 +150,8 @@ fn compile_coverage( additional_named_addresses: move_options.named_addresses(), test_mode: false, install_dir: move_options.output_dir.clone(), + known_attributes: extended_checks::get_all_attribute_names().clone(), + skip_attribute_checks: false, ..Default::default() }; let path = move_options.get_package_path()?; diff --git a/crates/aptos/src/move_tool/mod.rs b/crates/aptos/src/move_tool/mod.rs index 6c5c1f27695fb..f79cf5d81f684 100644 --- a/crates/aptos/src/move_tool/mod.rs +++ b/crates/aptos/src/move_tool/mod.rs @@ -318,6 +318,7 @@ impl CliCommand> for CompilePackage { self.move_options.skip_fetch_latest_git_deps, self.move_options.named_addresses(), self.move_options.bytecode_version, + self.move_options.skip_attribute_checks, ) }; let pack = BuiltPackage::build(self.move_options.get_package_path()?, build_options) @@ -377,6 +378,7 @@ impl CompileScript { self.move_options.skip_fetch_latest_git_deps, self.move_options.named_addresses(), self.move_options.bytecode_version, + self.move_options.skip_attribute_checks, ) }; let package_dir = self.move_options.get_package_path()?; @@ -449,12 +451,15 @@ impl CliCommand<&'static str> for TestPackage { } async fn execute(self) -> CliTypedResult<&'static str> { + let known_attributes = extended_checks::get_all_attribute_names(); let mut config = BuildConfig { dev_mode: self.move_options.dev, additional_named_addresses: self.move_options.named_addresses(), test_mode: true, install_dir: self.move_options.output_dir.clone(), skip_fetch_latest_git_deps: self.move_options.skip_fetch_latest_git_deps, + known_attributes: known_attributes.clone(), + skip_attribute_checks: self.move_options.skip_attribute_checks, ..Default::default() }; @@ -465,6 +470,8 @@ impl CliCommand<&'static str> for TestPackage { self.move_options.named_addresses(), None, self.move_options.bytecode_version, + self.move_options.skip_attribute_checks, + known_attributes.clone(), )?; let _ = extended_checks::run_extended_checks(model); if model.diag_count(Severity::Warning) > 0 { @@ -500,6 +507,7 @@ impl CliCommand<&'static str> for TestPackage { // Print coverage summary if --coverage is set if self.compute_coverage { + // TODO: config seems to be dead here. config.test_mode = false; let summary = SummaryCoverage { summarize_functions: false, @@ -570,6 +578,8 @@ impl CliCommand<&'static str> for ProvePackage { move_options.get_package_path()?.as_path(), move_options.named_addresses(), move_options.bytecode_version, + move_options.skip_attribute_checks, + extended_checks::get_all_attribute_names(), ) }) .await @@ -616,6 +626,8 @@ impl CliCommand<&'static str> for DocumentPackage { docgen_options: Some(docgen_options), skip_fetch_latest_git_deps: move_options.skip_fetch_latest_git_deps, bytecode_version: move_options.bytecode_version, + skip_attribute_checks: move_options.skip_attribute_checks, + known_attributes: extended_checks::get_all_attribute_names().clone(), }; BuiltPackage::build(move_options.get_package_path()?, build_options)?; Ok("succeeded") @@ -681,6 +693,7 @@ impl TryInto for &PublishPackage { self.move_options.skip_fetch_latest_git_deps, self.move_options.named_addresses(), self.move_options.bytecode_version, + self.move_options.skip_attribute_checks, ); let package = BuiltPackage::build(package_path, options) .map_err(|e| CliError::MoveCompilationError(format!("{:#}", e)))?; @@ -696,7 +709,7 @@ impl TryInto for &PublishPackage { if !self.override_size_check && size > MAX_PUBLISH_PACKAGE_SIZE { return Err(CliError::UnexpectedError(format!( "The package is larger than {} bytes ({} bytes)! To lower the size \ - you may want to include less artifacts via `--included-artifacts`. \ + you may want to include fewer artifacts via `--included-artifacts`. \ You can also override this check with `--override-size-check", MAX_PUBLISH_PACKAGE_SIZE, size ))); @@ -748,6 +761,7 @@ impl IncludedArtifacts { skip_fetch_latest_git_deps: bool, named_addresses: BTreeMap, bytecode_version: Option, + skip_attribute_checks: bool, ) -> BuildOptions { use IncludedArtifacts::*; match self { @@ -761,6 +775,8 @@ impl IncludedArtifacts { named_addresses, skip_fetch_latest_git_deps, bytecode_version, + skip_attribute_checks, + known_attributes: extended_checks::get_all_attribute_names().clone(), ..BuildOptions::default() }, Sparse => BuildOptions { @@ -772,6 +788,8 @@ impl IncludedArtifacts { named_addresses, skip_fetch_latest_git_deps, bytecode_version, + skip_attribute_checks, + known_attributes: extended_checks::get_all_attribute_names().clone(), ..BuildOptions::default() }, All => BuildOptions { @@ -783,6 +801,8 @@ impl IncludedArtifacts { named_addresses, skip_fetch_latest_git_deps, bytecode_version, + skip_attribute_checks, + known_attributes: extended_checks::get_all_attribute_names().clone(), ..BuildOptions::default() }, } @@ -924,6 +944,7 @@ impl CliCommand for CreateResourceAccountAndPublishPackage { move_options.skip_fetch_latest_git_deps, move_options.named_addresses(), move_options.bytecode_version, + move_options.skip_attribute_checks, ); let package = BuiltPackage::build(package_path, options)?; let compiled_units = package.extract_code(); @@ -1055,6 +1076,7 @@ impl CliCommand<&'static str> for VerifyPackage { self.move_options.skip_fetch_latest_git_deps, self.move_options.named_addresses(), self.move_options.bytecode_version, + self.move_options.skip_attribute_checks, ) }; let pack = BuiltPackage::build(self.move_options.get_package_path()?, build_options) diff --git a/crates/aptos/src/move_tool/show.rs b/crates/aptos/src/move_tool/show.rs index 3cd10df1543fb..ec40258d72c5a 100644 --- a/crates/aptos/src/move_tool/show.rs +++ b/crates/aptos/src/move_tool/show.rs @@ -64,6 +64,7 @@ impl CliCommand> for ShowAbi { self.move_options.skip_fetch_latest_git_deps, self.move_options.named_addresses(), self.move_options.bytecode_version, + self.move_options.skip_attribute_checks, ) }; diff --git a/crates/aptos/src/test/mod.rs b/crates/aptos/src/test/mod.rs index 725548375750c..f5ed5a5d6d26c 100644 --- a/crates/aptos/src/test/mod.rs +++ b/crates/aptos/src/test/mod.rs @@ -1042,6 +1042,7 @@ impl CliTestFramework { named_addresses: Self::named_addresses(account_strs), skip_fetch_latest_git_deps: true, bytecode_version: None, + skip_attribute_checks: false, } } diff --git a/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/tests/proto_converter_tests.rs b/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/tests/proto_converter_tests.rs index 4fd778cfc65b7..5c5d22a739bf5 100644 --- a/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/tests/proto_converter_tests.rs +++ b/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/tests/proto_converter_tests.rs @@ -7,6 +7,7 @@ use crate::{ }; use aptos_api_test_context::current_function_name; +use aptos_framework::extended_checks; use aptos_protos::extractor::v1::{ transaction::{TransactionType, TxnData}, transaction_payload::{Payload, Type as PayloadType}, @@ -245,6 +246,8 @@ async fn build_test_module(account: AccountAddress) -> Vec { generate_docs: false, install_dir: Some(package_dir.clone()), additional_named_addresses: [("TestAccount".to_string(), account)].into(), + known_attributes: extended_checks::get_all_attribute_names().clone(), + skip_attribute_checks: false, ..Default::default() }; let package = build_config diff --git a/third_party/move/benchmarks/src/move_vm.rs b/third_party/move/benchmarks/src/move_vm.rs index 2f03c7e63dc4d..b622fa6173260 100644 --- a/third_party/move/benchmarks/src/move_vm.rs +++ b/third_party/move/benchmarks/src/move_vm.rs @@ -40,6 +40,7 @@ fn compile_modules() -> Vec { let (_files, compiled_units) = Compiler::from_files( src_files, vec![], + Flags::empty().set_skip_attribute_checks(false), move_stdlib::move_stdlib_named_addresses(), ) .build_and_report() diff --git a/third_party/move/evm/move-to-yul/src/lib.rs b/third_party/move/evm/move-to-yul/src/lib.rs index 346043fef772b..9333400655200 100644 --- a/third_party/move/evm/move-to-yul/src/lib.rs +++ b/third_party/move/evm/move-to-yul/src/lib.rs @@ -31,7 +31,9 @@ use codespan_reporting::{ diagnostic::Severity, term::termcolor::{ColorChoice, StandardStream, WriteColor}, }; -use move_compiler::{shared::PackagePaths, Flags}; +use move_compiler::{ + attr_derivation::get_known_attributes_for_flavor, shared::PackagePaths, Flags, +}; use move_core_types::metadata::Metadata; use move_model::{ model::GlobalEnv, options::ModelBuilderOptions, parse_addresses_from_options, @@ -49,6 +51,8 @@ pub fn run_to_yul_errors_to_stderr(options: Options) -> anyhow::Result<()> { pub fn run_to_yul(error_writer: &mut W, mut options: Options) -> anyhow::Result<()> { // Run the model builder. let addrs = parse_addresses_from_options(options.named_address_mapping.clone())?; + let flags = Flags::empty().set_flavor("async"); + let known_attributes = get_known_attributes_for_flavor(&flags); let env = run_model_builder_with_options_and_compilation_flags( vec![PackagePaths { name: None, @@ -61,7 +65,8 @@ pub fn run_to_yul(error_writer: &mut W, mut options: Options) -> named_address_map: addrs, }], ModelBuilderOptions::default(), - Flags::empty().set_flavor("async"), + flags, + &known_attributes, )?; // If the model contains any errors, report them now and exit. check_errors( @@ -102,6 +107,8 @@ pub fn run_to_abi_metadata( ) -> anyhow::Result> { // Run the model builder. let addrs = parse_addresses_from_options(options.named_address_mapping.clone())?; + let flags = Flags::empty().set_flavor("async"); + let known_attributes = get_known_attributes_for_flavor(&flags); let env = run_model_builder_with_options_and_compilation_flags( vec![PackagePaths { name: None, @@ -114,7 +121,8 @@ pub fn run_to_abi_metadata( named_address_map: addrs, }], ModelBuilderOptions::default(), - Flags::empty().set_flavor("async"), + flags, + &known_attributes, )?; // If the model contains any errors, report them now and exit. check_errors( diff --git a/third_party/move/evm/move-to-yul/tests/dispatcher_testsuite.rs b/third_party/move/evm/move-to-yul/tests/dispatcher_testsuite.rs index f452d7684d3c3..ee1f9c916a765 100644 --- a/third_party/move/evm/move-to-yul/tests/dispatcher_testsuite.rs +++ b/third_party/move/evm/move-to-yul/tests/dispatcher_testsuite.rs @@ -5,8 +5,13 @@ use anyhow::Result; use evm::{backend::MemoryVicinity, ExitReason}; use evm_exec_utils::{compile, exec::Executor}; -use move_compiler::shared::{NumericalAddress, PackagePaths}; -use move_model::{options::ModelBuilderOptions, run_model_builder_with_options}; +use move_compiler::{ + attr_derivation::get_known_attributes_for_flavor, + shared::{Flags, NumericalAddress, PackagePaths}, +}; +use move_model::{ + options::ModelBuilderOptions, run_model_builder_with_options_and_compilation_flags, +}; use move_stdlib::move_stdlib_named_addresses; use move_to_yul::{generator::Generator, options::Options}; use primitive_types::{H160, U256}; @@ -60,7 +65,9 @@ fn compile_yul_to_bytecode_bytes(filename: &str) -> Result> { "Async".to_string(), NumericalAddress::parse_str("0x1").unwrap(), ); - let env = run_model_builder_with_options( + let flags = Flags::verification().set_flavor("evm"); + let known_attributes = get_known_attributes_for_flavor(&flags); + let env = run_model_builder_with_options_and_compilation_flags( vec![PackagePaths { name: None, paths: vec![contract_path(filename).to_string_lossy().to_string()], @@ -72,12 +79,14 @@ fn compile_yul_to_bytecode_bytes(filename: &str) -> Result> { named_address_map, }], ModelBuilderOptions::default(), + flags, + &known_attributes, )?; let options = Options::default(); let (_, out, _) = Generator::run(&options, &env) .pop() .expect("not contract in test case"); - let (bc, _) = compile::solc_yul(&out, false)?; + let (bc, _) = compile::solc_yul(&out, true)?; Ok(bc) } diff --git a/third_party/move/evm/move-to-yul/tests/testsuite.rs b/third_party/move/evm/move-to-yul/tests/testsuite.rs index f782f09153d22..7b5fd6191ae83 100644 --- a/third_party/move/evm/move-to-yul/tests/testsuite.rs +++ b/third_party/move/evm/move-to-yul/tests/testsuite.rs @@ -7,7 +7,10 @@ use codespan_reporting::{diagnostic::Severity, term::termcolor::Buffer}; use evm::backend::MemoryVicinity; use evm_exec_utils::{compile, exec::Executor, tracing}; use move_command_line_common::testing::EXP_EXT; -use move_compiler::shared::{NumericalAddress, PackagePaths}; +use move_compiler::{ + attr_derivation, + shared::{NumericalAddress, PackagePaths}, +}; use move_model::{ model::{FunId, GlobalEnv, QualifiedId}, options::ModelBuilderOptions, @@ -46,6 +49,10 @@ fn test_runner(path: &Path) -> datatest_stable::Result<()> { "Async".to_string(), NumericalAddress::parse_str("0x1").unwrap(), ); + let flags = move_compiler::Flags::empty() + .set_sources_shadow_deps(true) + .set_flavor("async"); + let known_attributes = attr_derivation::get_known_attributes_for_flavor(&flags); let env = run_model_builder_with_options_and_compilation_flags( vec![PackagePaths { name: None, @@ -58,9 +65,8 @@ fn test_runner(path: &Path) -> datatest_stable::Result<()> { named_address_map, }], ModelBuilderOptions::default(), - move_compiler::Flags::empty() - .set_sources_shadow_deps(true) - .set_flavor("async"), + flags, + &known_attributes, )?; for exp in std::iter::once(String::new()).chain(experiments.into_iter()) { let mut options = Options { diff --git a/third_party/move/extensions/async/move-async-vm/tests/testsuite.rs b/third_party/move/extensions/async/move-async-vm/tests/testsuite.rs index 28bec3e0cb2cc..35372690cc572 100644 --- a/third_party/move/extensions/async/move-async-vm/tests/testsuite.rs +++ b/third_party/move/extensions/async/move-async-vm/tests/testsuite.rs @@ -13,7 +13,7 @@ use move_async_vm::{ use move_binary_format::access::ModuleAccess; use move_command_line_common::testing::EXP_EXT; use move_compiler::{ - compiled_unit::CompiledUnit, diagnostics::report_diagnostics_to_buffer, + attr_derivation, compiled_unit::CompiledUnit, diagnostics::report_diagnostics_to_buffer, shared::NumericalAddress, Compiler, Flags, }; use move_core_types::{ @@ -349,8 +349,10 @@ impl Harness { .filter(|p| *p != path) .cloned() .collect(); - let compiler = Compiler::from_files(targets, deps, address_map.clone()) - .set_flags(Flags::empty().set_flavor("async")); + let flags = Flags::empty().set_flavor("async"); + let known_attributes = attr_derivation::get_known_attributes_for_flavor(&flags); + let compiler = + Compiler::from_files(targets, deps, address_map.clone(), flags, &known_attributes); let (sources, inner) = compiler.build()?; match inner { Err(diags) => bail!( diff --git a/third_party/move/move-compiler-v2/Cargo.toml b/third_party/move/move-compiler-v2/Cargo.toml index 44d8c4b5d5bdd..2e9a4276af2e5 100644 --- a/third_party/move/move-compiler-v2/Cargo.toml +++ b/third_party/move/move-compiler-v2/Cargo.toml @@ -12,6 +12,7 @@ edition = "2021" [dependencies] anyhow = "1.0.62" move-binary-format = { path = "../move-binary-format" } +move-compiler = { path = "../move-compiler" } move-core-types = { path = "../move-core/types" } move-model = { path = "../move-model" } move-stackless-bytecode = { path = "../move-prover/bytecode" } diff --git a/third_party/move/move-compiler-v2/src/lib.rs b/third_party/move/move-compiler-v2/src/lib.rs index f7aa913abdf5e..efa7ab9fbd49b 100644 --- a/third_party/move/move-compiler-v2/src/lib.rs +++ b/third_party/move/move-compiler-v2/src/lib.rs @@ -13,6 +13,7 @@ use anyhow::anyhow; use codespan_reporting::term::termcolor::{ColorChoice, StandardStream, WriteColor}; pub use experiments::*; use move_binary_format::{file_format as FF, file_format::CompiledScript, CompiledModule}; +use move_compiler::shared::known_attributes::KnownAttribute; use move_model::{model::GlobalEnv, PackageInfo}; use move_stackless_bytecode::function_target_pipeline::{ FunctionTargetPipeline, FunctionTargetsHolder, FunctionVariant, @@ -76,6 +77,8 @@ pub fn run_checker(options: Options) -> anyhow::Result { sources: options.dependencies.clone(), address_map: addrs, }], + options.skip_attribute_checks, + KnownAttribute::get_all_attribute_names(), )?; // Store options in env, for later access env.set_extension(options); diff --git a/third_party/move/move-compiler-v2/src/options.rs b/third_party/move/move-compiler-v2/src/options.rs index bcf53cb76d175..1517c7c2c0687 100644 --- a/third_party/move/move-compiler-v2/src/options.rs +++ b/third_party/move/move-compiler-v2/src/options.rs @@ -27,6 +27,9 @@ pub struct Options { /// Whether to dump intermediate bytecode for debugging. #[clap(long = "dump-bytecode")] pub dump_bytecode: bool, + /// Do not complain about unknown attributes in Move code. + #[clap(long, default_value = "false")] + pub skip_attribute_checks: bool, /// Whether we generate code for tests. This specifically guarantees stable output /// for baseline testing. #[clap(long)] diff --git a/third_party/move/move-compiler/src/attr_derivation/async_deriver.rs b/third_party/move/move-compiler/src/attr_derivation/async_deriver.rs index d4efbd9b641de..c565d56e3d90e 100644 --- a/third_party/move/move-compiler/src/attr_derivation/async_deriver.rs +++ b/third_party/move/move-compiler/src/attr_derivation/async_deriver.rs @@ -18,14 +18,41 @@ use move_core_types::account_address::AccountAddress; use move_ir_types::location::{sp, Loc}; use move_symbol_pool::Symbol; use sha3::{Digest, Sha3_256}; -use std::convert::TryInto; +use std::{collections::BTreeSet, convert::TryInto}; const ACTOR_ATTR: &str = "actor"; const STATE_ATTR: &str = "state"; const INIT_ATTR: &str = "init"; const MESSAGE_ATTR: &str = "message"; + +const CONT_ATTR: &str = "cont"; +const EVENT_ATTR: &str = "event"; // "message" is mysteriously transformed into "event" +const RPC_ATTR: &str = "rpc"; + +const GENERATED_CONT_ATTR: &str = "_generated_cont"; +const GENERATED_RPC_ATTR: &str = "_generated_rpc"; +const GENERATED_SEND_ATTR: &str = "_generated_send"; + const MAX_SEND_PARAM_COUNT: usize = 8; +pub(crate) fn add_attributes_for_async(attributes: &mut BTreeSet) { + const ALL_ATTRIBUTE_NAMES: [&str; 10] = [ + ACTOR_ATTR, + CONT_ATTR, + EVENT_ATTR, + INIT_ATTR, + MESSAGE_ATTR, + RPC_ATTR, + STATE_ATTR, + GENERATED_CONT_ATTR, + GENERATED_RPC_ATTR, + GENERATED_SEND_ATTR, + ]; + ALL_ATTRIBUTE_NAMES.into_iter().for_each(|elt| { + attributes.insert(elt.to_string()); + }); +} + pub(crate) fn derive_for_async( env: &mut CompilationEnv, address_map: &NamedAddressMap, diff --git a/third_party/move/move-compiler/src/attr_derivation/evm_deriver.rs b/third_party/move/move-compiler/src/attr_derivation/evm_deriver.rs index 28bc1ff1e6f80..89fc637095f96 100644 --- a/third_party/move/move-compiler/src/attr_derivation/evm_deriver.rs +++ b/third_party/move/move-compiler/src/attr_derivation/evm_deriver.rs @@ -11,11 +11,72 @@ use crate::{ }; use move_ir_types::location::sp; use move_symbol_pool::Symbol; +use std::collections::BTreeSet; const CONTRACT_ATTR: &str = "contract"; const CALLABLE_ATTR: &str = "callable"; const EXTERNAL_ATTR: &str = "external"; +// The following appear in test code under /evm/. +const ACTOR_ATTR: &str = "actor"; +const INIT_ATTR: &str = "init"; +const MESSAGE_ATTR: &str = "message"; +const ABI_STRUCT_ATTR: &str = "abi_struct"; +const CREATE_ATTR: &str = "create"; +const DECODE_ATTR: &str = "decode"; +const DELETE_ATTR: &str = "delete"; +const ENCODE_ATTR: &str = "encode"; +const ENCODE_PACKED_ATTR: &str = "encode_packed"; +const EVENT_ATTR: &str = "event"; +const EVM_ARITH_ATTR: &str = "evm_arith"; +const EVM_TEST_ATTR: &str = "evm_test"; +const FALLBACK_ATTR: &str = "fallback"; +const INTERFACE_ATTR: &str = "interface"; +const INTERFACE_ID_ATTR: &str = "interface_id"; +const SELECTOR_ATTR: &str = "selector"; +const STATE_ATTR: &str = "state"; +const STORAGE_ATTR: &str = "storage"; + +const EVM_CONTRACT_ATTR: &str = "evm_contract"; +const PAYABLE_ATTR: &str = "payable"; +const RECEIVE_ATTR: &str = "receive"; +const VIEW_ATTR: &str = "view"; +const PURE_ATTR: &str = "pure"; + +pub(crate) fn add_attributes_for_evm(attributes: &mut BTreeSet) { + const ALL_ATTRIBUTE_NAMES: [&str; 26] = [ + CALLABLE_ATTR, + CONTRACT_ATTR, + EXTERNAL_ATTR, + ABI_STRUCT_ATTR, + ACTOR_ATTR, + CREATE_ATTR, + DECODE_ATTR, + DELETE_ATTR, + ENCODE_ATTR, + ENCODE_PACKED_ATTR, + EVENT_ATTR, + EVM_ARITH_ATTR, + EVM_TEST_ATTR, + FALLBACK_ATTR, + INIT_ATTR, + INTERFACE_ATTR, + INTERFACE_ID_ATTR, + MESSAGE_ATTR, + SELECTOR_ATTR, + STATE_ATTR, + STORAGE_ATTR, + EVM_CONTRACT_ATTR, + PAYABLE_ATTR, + RECEIVE_ATTR, + VIEW_ATTR, + PURE_ATTR, + ]; + ALL_ATTRIBUTE_NAMES.into_iter().for_each(|elt| { + attributes.insert(elt.to_string()); + }); +} + pub(crate) fn derive_for_evm( _env: &mut CompilationEnv, _address_map: &NamedAddressMap, diff --git a/third_party/move/move-compiler/src/attr_derivation/mod.rs b/third_party/move/move-compiler/src/attr_derivation/mod.rs index 6634eccd26b72..2046fa4db2ef9 100644 --- a/third_party/move/move-compiler/src/attr_derivation/mod.rs +++ b/third_party/move/move-compiler/src/attr_derivation/mod.rs @@ -3,17 +3,24 @@ // SPDX-License-Identifier: Apache-2.0 use crate::{ - attr_derivation::{async_deriver::derive_for_async, evm_deriver::derive_for_evm}, + attr_derivation::{ + async_deriver::{add_attributes_for_async, derive_for_async}, + evm_deriver::{add_attributes_for_evm, derive_for_evm}, + }, parser::ast::{ Attribute, AttributeValue, Attribute_, Attributes, Definition, Exp, Exp_, Function, FunctionBody_, FunctionName, FunctionSignature, LeadingNameAccess_, NameAccessChain, NameAccessChain_, StructDefinition, StructFields, StructName, Type, Type_, Value_, Var, Visibility, }, - shared::{CompilationEnv, Name, NamedAddressMap}, + shared::{ + known_attributes::{AttributeKind, KnownAttribute}, + CompilationEnv, Flags, Name, NamedAddressMap, + }, }; use move_ir_types::location::{sp, Loc}; use move_symbol_pool::Symbol; +use std::collections::BTreeSet; mod async_deriver; mod evm_deriver; @@ -38,11 +45,29 @@ pub fn derive_from_attributes( } } +pub fn add_attributes_for_flavor(flags: &Flags, known_attributes: &mut BTreeSet) { + if flags.has_flavor(EVM_FLAVOR) { + add_attributes_for_evm(known_attributes); + } + if flags.has_flavor(ASYNC_FLAVOR) { + add_attributes_for_async(known_attributes); + // Tests with flavor "async" seem to also use EVM attributes. + add_attributes_for_evm(known_attributes); + } + KnownAttribute::add_attribute_names(known_attributes); +} + +pub fn get_known_attributes_for_flavor(flags: &Flags) -> BTreeSet { + let mut known_attributes = BTreeSet::new(); + add_attributes_for_flavor(flags, &mut known_attributes); + known_attributes +} + // ========================================================================================== // Helper Functions for analyzing attributes and creating the AST /// Helper function to find an attribute by name. -pub fn find_attr<'a>(attrs: &'a Attributes, name: &str) -> Option<&'a Attribute> { +pub(crate) fn find_attr<'a>(attrs: &'a Attributes, name: &str) -> Option<&'a Attribute> { attrs .value .iter() @@ -50,7 +75,7 @@ pub fn find_attr<'a>(attrs: &'a Attributes, name: &str) -> Option<&'a Attribute> } /// Helper function to find an attribute in a slice. -pub fn find_attr_slice<'a>(vec: &'a [Attributes], name: &str) -> Option<&'a Attribute> { +pub(crate) fn find_attr_slice<'a>(vec: &'a [Attributes], name: &str) -> Option<&'a Attribute> { for attrs in vec { if let Some(a) = find_attr(attrs, name) { return Some(a); @@ -62,7 +87,7 @@ pub fn find_attr_slice<'a>(vec: &'a [Attributes], name: &str) -> Option<&'a Attr /// Helper to extract the parameters of an attribute. If the attribute is of the form /// `n(a1, ..., an)`, this extracts the a_i as a vector. Otherwise the attribute is assumed /// to have no parameters. -pub fn attr_params(attr: &Attribute) -> Vec<&Attribute> { +pub(crate) fn attr_params(attr: &Attribute) -> Vec<&Attribute> { match &attr.value { Attribute_::Parameterized(_, vs) => vs.value.iter().collect(), _ => vec![], @@ -71,7 +96,7 @@ pub fn attr_params(attr: &Attribute) -> Vec<&Attribute> { /// Helper to extract a named value attribute, as in `n [= v]`. #[allow(unused)] -pub fn attr_value(attr: &Attribute) -> Option<(&Name, Option<&AttributeValue>)> { +pub(crate) fn attr_value(attr: &Attribute) -> Option<(&Name, Option<&AttributeValue>)> { match &attr.value { Attribute_::Name(n) => Some((n, None)), Attribute_::Assigned(n, v) => Some((n, Some(v))), @@ -80,7 +105,7 @@ pub fn attr_value(attr: &Attribute) -> Option<(&Name, Option<&AttributeValue>)> } /// Creates a new attribute. -pub fn new_attr(loc: Loc, name: &str, params: Vec) -> Attribute { +pub(crate) fn new_attr(loc: Loc, name: &str, params: Vec) -> Attribute { let n = sp(loc, Symbol::from(name)); if params.is_empty() { sp(loc, Attribute_::Name(n)) @@ -90,7 +115,7 @@ pub fn new_attr(loc: Loc, name: &str, params: Vec) -> Attribute { } /// Helper to create a new native function declaration. -pub fn new_native_fun( +pub(crate) fn new_native_fun( loc: Loc, name: FunctionName, attributes: Attributes, @@ -112,7 +137,7 @@ pub fn new_native_fun( } /// Helper to create a new function declaration. -pub fn new_fun( +pub(crate) fn new_fun( loc: Loc, name: FunctionName, attributes: Attributes, @@ -138,7 +163,7 @@ pub fn new_fun( } /// Helper to create a new struct declaration. -pub fn new_struct(loc: Loc, name: StructName, fields: StructFields) -> StructDefinition { +pub(crate) fn new_struct(loc: Loc, name: StructName, fields: StructFields) -> StructDefinition { StructDefinition { attributes: vec![sp( // #[event] @@ -154,12 +179,12 @@ pub fn new_struct(loc: Loc, name: StructName, fields: StructFields) -> StructDef } /// Helper to create a new named variable. -pub fn new_var(loc: Loc, name: &str) -> Var { +pub(crate) fn new_var(loc: Loc, name: &str) -> Var { Var(sp(loc, Symbol::from(name))) } /// Helper to create a new type, based on its simple name. -pub fn new_simple_type(loc: Loc, ty_str: &str, ty_args: Vec) -> Type { +pub(crate) fn new_simple_type(loc: Loc, ty_str: &str, ty_args: Vec) -> Type { sp( loc, Type_::Apply(Box::new(new_simple_name(loc, ty_str)), ty_args), @@ -167,12 +192,17 @@ pub fn new_simple_type(loc: Loc, ty_str: &str, ty_args: Vec) -> Type { } /// Helper to create a simple name. -pub fn new_simple_name(loc: Loc, name: &str) -> NameAccessChain { +pub(crate) fn new_simple_name(loc: Loc, name: &str) -> NameAccessChain { sp(loc, NameAccessChain_::One(sp(loc, Symbol::from(name)))) } /// Helper to create a full name. -pub fn new_full_name(loc: Loc, addr_alias: &str, module: &str, name: &str) -> NameAccessChain { +pub(crate) fn new_full_name( + loc: Loc, + addr_alias: &str, + module: &str, + name: &str, +) -> NameAccessChain { let leading = sp( loc, LeadingNameAccess_::Name(sp(loc, Symbol::from(addr_alias))), @@ -187,22 +217,22 @@ pub fn new_full_name(loc: Loc, addr_alias: &str, module: &str, name: &str) -> Na } /// Helper to create a call exp. -pub fn new_call_exp(loc: Loc, fun: NameAccessChain, args: Vec) -> Exp { +pub(crate) fn new_call_exp(loc: Loc, fun: NameAccessChain, args: Vec) -> Exp { sp(loc, Exp_::Call(fun, false, None, sp(loc, args))) } -pub fn new_borrow_exp(loc: Loc, arg: Exp) -> Exp { +pub(crate) fn new_borrow_exp(loc: Loc, arg: Exp) -> Exp { sp(loc, Exp_::Borrow(false, Box::new(arg))) } /// Helper to create a name exp. -pub fn new_simple_name_exp(loc: Loc, name: Name) -> Exp { +pub(crate) fn new_simple_name_exp(loc: Loc, name: Name) -> Exp { sp(loc, Exp_::Name(sp(loc, NameAccessChain_::One(name)), None)) } /// Helper to create an expression for denoting a vector value. #[allow(unused)] -pub fn new_vec_u8(loc: Loc, vec: &[u8]) -> Exp { +pub(crate) fn new_vec_u8(loc: Loc, vec: &[u8]) -> Exp { let values = vec .iter() .map(|x| { @@ -223,7 +253,7 @@ pub fn new_vec_u8(loc: Loc, vec: &[u8]) -> Exp { } /// Helper to create new u64. -pub fn new_u64(loc: Loc, val: u64) -> Exp { +pub(crate) fn new_u64(loc: Loc, val: u64) -> Exp { sp( loc, Exp_::Value(sp(loc, Value_::Num(Symbol::from(val.to_string())))), diff --git a/third_party/move/move-compiler/src/bin/move-build.rs b/third_party/move/move-compiler/src/bin/move-build.rs index 86cb802d2581d..3dcd81fa270a1 100644 --- a/third_party/move/move-compiler/src/bin/move-build.rs +++ b/third_party/move/move-compiler/src/bin/move-build.rs @@ -8,7 +8,7 @@ use clap::*; use move_command_line_common::files::verify_and_create_named_address_mapping; use move_compiler::{ command_line::{self as cli}, - shared::{self, Flags, NumericalAddress}, + shared::{self, known_attributes::KnownAttribute, Flags, NumericalAddress}, }; #[derive(Debug, Parser)] @@ -77,11 +77,16 @@ pub fn main() -> anyhow::Result<()> { let interface_files_dir = format!("{}/generated_interface_files", out_dir); let named_addr_map = verify_and_create_named_address_mapping(named_addresses)?; let bytecode_version = flags.bytecode_version(); - let (files, compiled_units) = - move_compiler::Compiler::from_files(source_files, dependencies, named_addr_map) - .set_interface_files_dir(interface_files_dir) - .set_flags(flags) - .build_and_report()?; + + let (files, compiled_units) = move_compiler::Compiler::from_files( + source_files, + dependencies, + named_addr_map, + flags, + KnownAttribute::get_all_attribute_names(), + ) + .set_interface_files_dir(interface_files_dir) + .build_and_report()?; move_compiler::output_compiled_units( bytecode_version, emit_source_map, diff --git a/third_party/move/move-compiler/src/bin/move-check.rs b/third_party/move/move-compiler/src/bin/move-check.rs index 294db69b7b38b..5a7586250f8bc 100644 --- a/third_party/move/move-compiler/src/bin/move-check.rs +++ b/third_party/move/move-compiler/src/bin/move-check.rs @@ -8,7 +8,7 @@ use clap::*; use move_command_line_common::files::verify_and_create_named_address_mapping; use move_compiler::{ command_line::{self as cli}, - shared::{self, Flags, NumericalAddress}, + shared::{self, known_attributes::KnownAttribute, Flags, NumericalAddress}, }; #[derive(Debug, Parser)] @@ -65,10 +65,16 @@ pub fn main() -> anyhow::Result<()> { named_addresses, } = Options::parse(); let named_addr_map = verify_and_create_named_address_mapping(named_addresses)?; - let _files = move_compiler::Compiler::from_files(source_files, dependencies, named_addr_map) - .set_interface_files_dir_opt(out_dir) - .set_flags(flags) - .check_and_report()?; + + let _files = move_compiler::Compiler::from_files( + source_files, + dependencies, + named_addr_map, + flags, + KnownAttribute::get_all_attribute_names(), + ) + .set_interface_files_dir_opt(out_dir) + .check_and_report()?; Ok(()) } diff --git a/third_party/move/move-compiler/src/command_line/compiler.rs b/third_party/move/move-compiler/src/command_line/compiler.rs index ae2ac2f4763cb..3dccf4c16bdf9 100644 --- a/third_party/move/move-compiler/src/command_line/compiler.rs +++ b/third_party/move/move-compiler/src/command_line/compiler.rs @@ -3,6 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 use crate::{ + attr_derivation::add_attributes_for_flavor, cfgir, command_line::{DEFAULT_OUTPUT_DIR, MOVE_COMPILED_INTERFACES_DIR}, compiled_unit, @@ -22,7 +23,7 @@ use move_command_line_common::files::{ use move_core_types::language_storage::ModuleId as CompiledModuleId; use move_symbol_pool::Symbol; use std::{ - collections::BTreeMap, + collections::{BTreeMap, BTreeSet}, fs, fs::File, io::{Read, Write}, @@ -42,6 +43,7 @@ pub struct Compiler<'a> { pre_compiled_lib: Option<&'a FullyCompiledProgram>, compiled_module_named_address_mapping: BTreeMap, flags: Flags, + known_attributes: BTreeSet, } pub struct SteppedCompiler<'a, const P: Pass> { @@ -95,6 +97,8 @@ impl<'a> Compiler<'a> { pub fn from_package_paths, NamedAddress: Into>( targets: Vec>, deps: Vec>, + flags: Flags, + known_attributes: &BTreeSet, ) -> Self { fn indexed_scopes( maps: &mut NamedAddressMaps, @@ -132,7 +136,8 @@ impl<'a> Compiler<'a> { interface_files_dir_opt: None, pre_compiled_lib: None, compiled_module_named_address_mapping: BTreeMap::new(), - flags: Flags::empty(), + flags, + known_attributes: known_attributes.clone(), } } @@ -140,6 +145,8 @@ impl<'a> Compiler<'a> { targets: Vec, deps: Vec, named_address_map: BTreeMap, + flags: Flags, + known_attributes: &BTreeSet, ) -> Self { let targets = vec![PackagePaths { name: None, @@ -151,13 +158,7 @@ impl<'a> Compiler<'a> { paths: deps, named_address_map, }]; - Self::from_package_paths(targets, deps) - } - - pub fn set_flags(mut self, flags: Flags) -> Self { - assert!(self.flags.is_empty()); - self.flags = flags; - self + Self::from_package_paths(targets, deps, flags, known_attributes) } pub fn set_interface_files_dir(mut self, dir: String) -> Self { @@ -210,13 +211,15 @@ impl<'a> Compiler<'a> { pre_compiled_lib, compiled_module_named_address_mapping, flags, + mut known_attributes, } = self; generate_interface_files_for_deps( &mut deps, interface_files_dir_opt, &compiled_module_named_address_mapping, )?; - let mut compilation_env = CompilationEnv::new(flags); + add_attributes_for_flavor(&flags, &mut known_attributes); + let mut compilation_env = CompilationEnv::new(flags, known_attributes); let (source_text, pprog_and_comments_res) = parse_program(&mut compilation_env, maps, targets, deps)?; let res: Result<_, Diagnostics> = pprog_and_comments_res.and_then(|(pprog, comments)| { @@ -428,12 +431,16 @@ pub fn construct_pre_compiled_lib, NamedAddress: Into>, interface_files_dir_opt: Option, flags: Flags, + known_attributes: &BTreeSet, ) -> anyhow::Result> { - let (files, pprog_and_comments_res) = - Compiler::from_package_paths(targets, Vec::>::new()) - .set_interface_files_dir_opt(interface_files_dir_opt) - .set_flags(flags) - .run::()?; + let (files, pprog_and_comments_res) = Compiler::from_package_paths( + targets, + Vec::>::new(), + flags, + known_attributes, + ) + .set_interface_files_dir_opt(interface_files_dir_opt) + .run::()?; let (_comments, stepped) = match pprog_and_comments_res { Err(errors) => return Ok(Err((files, errors))), diff --git a/third_party/move/move-compiler/src/command_line/mod.rs b/third_party/move/move-compiler/src/command_line/mod.rs index f305e20bc3f03..e0badc1288326 100644 --- a/third_party/move/move-compiler/src/command_line/mod.rs +++ b/third_party/move/move-compiler/src/command_line/mod.rs @@ -17,6 +17,8 @@ pub const DEFAULT_OUTPUT_DIR: &str = "build"; pub const SHADOW: &str = "shadow"; pub const SHADOW_SHORT: char = 'S'; +pub const SKIP_ATTRIBUTE_CHECKS: &str = "skip-attribute-checks"; + pub const SOURCE_MAP: &str = "source-map"; pub const SOURCE_MAP_SHORT: char = 'm'; diff --git a/third_party/move/move-compiler/src/diagnostics/codes.rs b/third_party/move/move-compiler/src/diagnostics/codes.rs index bda46559ab0d2..04fe20fe839a1 100644 --- a/third_party/move/move-compiler/src/diagnostics/codes.rs +++ b/third_party/move/move-compiler/src/diagnostics/codes.rs @@ -136,6 +136,8 @@ codes!( InvalidNonPhantomUse: { msg: "invalid non-phantom type parameter usage", severity: Warning }, InvalidAttribute: { msg: "invalid attribute", severity: NonblockingError }, + // TODO(https://github.com/aptos-labs/aptos-core/issues/9411) turn into NonblockingError when safe to do so. + UnknownAttribute: { msg: "unknown attribute", severity: Warning }, ], // errors name resolution, mostly expansion/translate and naming/translate NameResolution: [ diff --git a/third_party/move/move-compiler/src/expansion/ast.rs b/third_party/move/move-compiler/src/expansion/ast.rs index 217671b1b9a28..eee44aeafb591 100644 --- a/third_party/move/move-compiler/src/expansion/ast.rs +++ b/third_party/move/move-compiler/src/expansion/ast.rs @@ -8,8 +8,11 @@ use crate::{ QuantKind, SpecApplyPattern, StructName, UnaryOp, Var, ENTRY_MODIFIER, }, shared::{ - ast_debug::*, known_attributes::KnownAttribute, unique_map::UniqueMap, - unique_set::UniqueSet, *, + ast_debug::*, + known_attributes::{AttributeKind, KnownAttribute}, + unique_map::UniqueMap, + unique_set::UniqueSet, + *, }, }; use move_ir_types::location::*; diff --git a/third_party/move/move-compiler/src/expansion/translate.rs b/third_party/move/move-compiler/src/expansion/translate.rs index 4ea08bf3f83bf..6c5c64969c8f4 100644 --- a/third_party/move/move-compiler/src/expansion/translate.rs +++ b/third_party/move/move-compiler/src/expansion/translate.rs @@ -4,6 +4,7 @@ use super::aliases::{AliasMapBuilder, OldAliasMap}; use crate::{ + command_line::SKIP_ATTRIBUTE_CHECKS, diag, diagnostics::Diagnostic, expansion::{ @@ -14,16 +15,23 @@ use crate::{ parser::ast::{ self as P, Ability, ConstantName, Field, FunctionName, ModuleName, StructName, Var, }, - shared::{known_attributes::AttributePosition, unique_map::UniqueMap, *}, + shared::{ + known_attributes::{AttributeKind, AttributePosition, KnownAttribute}, + parse_u128, parse_u64, parse_u8, + unique_map::UniqueMap, + CompilationEnv, Identifier, Name, NamedAddressMap, NamedAddressMaps, NumericalAddress, + }, FullyCompiledProgram, }; use move_command_line_common::parser::{parse_u16, parse_u256, parse_u32}; use move_ir_types::location::*; use move_symbol_pool::Symbol; +use once_cell::sync::Lazy; use std::{ collections::{BTreeMap, BTreeSet, VecDeque}, iter::IntoIterator, }; +use str; //************************************************************************************************** // Context @@ -39,6 +47,7 @@ struct Context<'env, 'map> { in_spec_context: bool, exp_specs: BTreeMap, env: &'env mut CompilationEnv, + in_aptos_stdlib: bool, // TODO(https://github.com/aptos-labs/aptos-core/issues/9410) remove after bugfix propagates. } impl<'env, 'map> Context<'env, 'map> { fn new( @@ -53,6 +62,7 @@ impl<'env, 'map> Context<'env, 'map> { aliases: AliasMap::new(), is_source_definition: false, in_spec_context: false, + in_aptos_stdlib: false, exp_specs: BTreeMap::new(), } } @@ -384,6 +394,32 @@ fn set_sender_address( }) } +// This is a hack to recognize APTOS StdLib to avoid warnings on some old errors. +// This will be removed after library attributes are cleaned up. +// (See https://github.com/aptos-labs/aptos-core/issues/9410) +fn module_is_in_aptos_stdlib(module_address: Option>) -> bool { + const APTOS_STDLIB_NAME: &str = "aptos_std"; + static APTOS_STDLIB_NUMERICAL_ADDRESS: Lazy = + Lazy::new(|| NumericalAddress::parse_str("0x1").unwrap()); + match &module_address { + Some(spanned_address) => { + let address = spanned_address.value; + match address { + Address::Numerical(optional_name, spanned_numerical_address) => match optional_name + { + Some(spanned_symbol) => { + (&spanned_symbol.value as &str) == APTOS_STDLIB_NAME + && (spanned_numerical_address.value == *APTOS_STDLIB_NUMERICAL_ADDRESS) + }, + None => false, + }, + Address::NamedUnassigned(_) => false, + } + }, + None => false, + } +} + fn module_( context: &mut Context, package_name: Option, @@ -398,7 +434,9 @@ fn module_( name, members, } = mdef; + context.in_aptos_stdlib = module_is_in_aptos_stdlib(module_address); let attributes = flatten_attributes(context, AttributePosition::Module, attributes); + assert!(context.address.is_none()); assert!(address.is_none()); set_sender_address(context, &name, module_address); @@ -574,12 +612,40 @@ fn unique_attributes( | E::Attribute_::Assigned(n, _) | E::Attribute_::Parameterized(n, _) => *n, }; - let name_ = match known_attributes::KnownAttribute::resolve(sym) { - None => E::AttributeName_::Unknown(sym), + let name_ = match KnownAttribute::resolve(sym) { + None => { + let flags = &context.env.flags(); + if !flags.skip_attribute_checks() { + let known_attributes = &context.env.get_known_attributes(); + // TODO(See https://github.com/aptos-labs/aptos-core/issues/9410) remove after bugfix propagates. + if !is_nested && !known_attributes.contains(sym.as_str()) { + if !context.in_aptos_stdlib { + let msg = format!("Attribute name '{}' is unknown (use --{} CLI option to ignore); known attributes are '{:?}'.", + sym.as_str(), + SKIP_ATTRIBUTE_CHECKS, known_attributes); + context + .env + .add_diag(diag!(Declarations::UnknownAttribute, (nloc, msg))); + } + } else if is_nested && known_attributes.contains(sym.as_str()) { + let msg = format!( + "Known attribute '{}' is not expected in a nested attribute position.", + sym.as_str() + ); + context + .env + .add_diag(diag!(Declarations::InvalidAttribute, (nloc, msg))); + }; + } + E::AttributeName_::Unknown(sym) + }, Some(known) => { debug_assert!(known.name() == sym.as_str()); if is_nested { - let msg = "Known attribute '{}' is not expected in a nested attribute position"; + let msg = format!( + "Known attribute '{}' is not expected in a nested attribute position", + sym.as_str() + ); context .env .add_diag(diag!(Declarations::InvalidAttribute, (nloc, msg))); diff --git a/third_party/move/move-compiler/src/lib.rs b/third_party/move/move-compiler/src/lib.rs index eee5721e09681..3d58b6935c55b 100644 --- a/third_party/move/move-compiler/src/lib.rs +++ b/third_party/move/move-compiler/src/lib.rs @@ -7,7 +7,7 @@ #[macro_use(sp)] extern crate move_ir_types; -mod attr_derivation; +pub mod attr_derivation; pub mod cfgir; pub mod command_line; pub mod compiled_unit; diff --git a/third_party/move/move-compiler/src/shared/mod.rs b/third_party/move/move-compiler/src/shared/mod.rs index 7468f59c31fd9..c55fb9053cd71 100644 --- a/third_party/move/move-compiler/src/shared/mod.rs +++ b/third_party/move/move-compiler/src/shared/mod.rs @@ -12,7 +12,7 @@ use move_ir_types::location::*; use move_symbol_pool::Symbol; use petgraph::{algo::astar as petgraph_astar, graphmap::DiGraphMap}; use std::{ - collections::BTreeMap, + collections::{BTreeMap, BTreeSet}, fmt, hash::Hash, sync::atomic::{AtomicUsize, Ordering as AtomicOrdering}, @@ -51,7 +51,6 @@ pub fn parse_named_address(s: &str) -> anyhow::Result<(String, NumericalAddress) let name = before_after[0].parse()?; let addr = NumericalAddress::parse_str(before_after[1]) .map_err(|err| anyhow::format_err!("{}", err))?; - Ok((name, addr)) } @@ -175,15 +174,19 @@ pub type AttributeDeriver = dyn Fn(&mut CompilationEnv, &mut ModuleDefinition); pub struct CompilationEnv { flags: Flags, diags: Diagnostics, + /// Internal table used to pass known attributes to the parser for purposes of + /// checking for unknown attributes. + known_attributes: BTreeSet, // TODO(tzakian): Remove the global counter and use this counter instead // pub counter: u64, } impl CompilationEnv { - pub fn new(flags: Flags) -> Self { + pub fn new(flags: Flags, known_attributes: BTreeSet) -> Self { Self { flags, diags: Diagnostics::new(), + known_attributes, } } @@ -239,6 +242,10 @@ impl CompilationEnv { pub fn flags(&self) -> &Flags { &self.flags } + + pub fn get_known_attributes(&self) -> &BTreeSet { + &self.known_attributes + } } //************************************************************************************************** @@ -317,6 +324,12 @@ pub struct Flags { /// included only in tests, without creating the unit test code regular tests do. #[clap(skip)] keep_testing_functions: bool, + + /// Do not complain about unknown attributes. + #[clap( + long = cli::SKIP_ATTRIBUTE_CHECKS, + )] + pub skip_attribute_checks: bool, } impl Flags { @@ -328,6 +341,7 @@ impl Flags { flavor: "".to_string(), bytecode_version: None, keep_testing_functions: false, + skip_attribute_checks: false, } } @@ -339,6 +353,7 @@ impl Flags { flavor: "".to_string(), bytecode_version: None, keep_testing_functions: false, + skip_attribute_checks: false, } } @@ -350,6 +365,7 @@ impl Flags { flavor: "".to_string(), bytecode_version: None, keep_testing_functions: false, + skip_attribute_checks: false, } } @@ -361,6 +377,7 @@ impl Flags { flavor: "".to_string(), bytecode_version: None, keep_testing_functions: true, + skip_attribute_checks: false, } } @@ -412,6 +429,17 @@ impl Flags { pub fn bytecode_version(&self) -> Option { self.bytecode_version } + + pub fn skip_attribute_checks(&self) -> bool { + self.skip_attribute_checks + } + + pub fn set_skip_attribute_checks(self, new_value: bool) -> Self { + Self { + skip_attribute_checks: new_value, + ..self + } + } } //************************************************************************************************** @@ -435,11 +463,21 @@ pub mod known_attributes { Spec, } + pub trait AttributeKind + where + Self: Sized, + { + fn add_attribute_names(table: &mut BTreeSet); + fn name(&self) -> &str; + fn expected_positions(&self) -> &'static BTreeSet; + } + #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub enum KnownAttribute { Testing(TestingAttribute), Verification(VerificationAttribute), Native(NativeAttribute), + Deprecation(DeprecationAttribute), } #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] @@ -462,6 +500,13 @@ pub mod known_attributes { pub enum NativeAttribute { // It is a fake native function that actually compiles to a bytecode instruction BytecodeInstruction, + NativeInterface, + } + + #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] + pub enum DeprecationAttribute { + // Marks deprecated funcitons whose use causes warnings + Deprecated, } impl fmt::Display for AttributePosition { @@ -494,29 +539,55 @@ pub mod known_attributes { NativeAttribute::BYTECODE_INSTRUCTION => { Self::Native(NativeAttribute::BytecodeInstruction) }, + NativeAttribute::NATIVE_INTERFACE => Self::Native(NativeAttribute::NativeInterface), + DeprecationAttribute::DEPRECATED_NAME => { + Self::Deprecation(DeprecationAttribute::Deprecated) + }, _ => return None, }) } - pub const fn name(&self) -> &str { + pub fn get_all_attribute_names() -> &'static BTreeSet { + static KNOWN_ATTRIBUTES_SET: Lazy> = Lazy::new(|| { + let mut known_attributes = BTreeSet::new(); + KnownAttribute::add_attribute_names(&mut known_attributes); + known_attributes + }); + &KNOWN_ATTRIBUTES_SET + } + } + + impl AttributeKind for KnownAttribute { + fn add_attribute_names(table: &mut BTreeSet) { + TestingAttribute::add_attribute_names(table); + VerificationAttribute::add_attribute_names(table); + NativeAttribute::add_attribute_names(table); + DeprecationAttribute::add_attribute_names(table); + } + + fn name(&self) -> &str { match self { Self::Testing(a) => a.name(), Self::Verification(a) => a.name(), Self::Native(a) => a.name(), + Self::Deprecation(a) => a.name(), } } - pub fn expected_positions(&self) -> &'static BTreeSet { + fn expected_positions(&self) -> &'static BTreeSet { match self { Self::Testing(a) => a.expected_positions(), Self::Verification(a) => a.expected_positions(), Self::Native(a) => a.expected_positions(), + Self::Deprecation(a) => a.expected_positions(), } } } impl TestingAttribute { pub const ABORT_CODE_NAME: &'static str = "abort_code"; + const ALL_ATTRIBUTE_NAMES: [&'static str; 3] = + [Self::TEST, Self::TEST_ONLY, Self::EXPECTED_FAILURE]; pub const ARITHMETIC_ERROR_NAME: &'static str = "arithmetic_error"; pub const ERROR_LOCATION: &'static str = "location"; pub const EXPECTED_FAILURE: &'static str = "expected_failure"; @@ -527,7 +598,24 @@ pub mod known_attributes { pub const TEST_ONLY: &'static str = "test_only"; pub const VECTOR_ERROR_NAME: &'static str = "vector_error"; - pub const fn name(&self) -> &str { + pub fn expected_failure_cases() -> &'static [&'static str] { + &[ + Self::ABORT_CODE_NAME, + Self::ARITHMETIC_ERROR_NAME, + Self::VECTOR_ERROR_NAME, + Self::OUT_OF_GAS_NAME, + Self::MAJOR_STATUS_NAME, + ] + } + } + impl AttributeKind for TestingAttribute { + fn add_attribute_names(table: &mut BTreeSet) { + for str in Self::ALL_ATTRIBUTE_NAMES { + table.insert(str.to_string()); + } + } + + fn name(&self) -> &str { match self { Self::Test => Self::TEST, Self::TestOnly => Self::TEST_ONLY, @@ -535,7 +623,7 @@ pub mod known_attributes { } } - pub fn expected_positions(&self) -> &'static BTreeSet { + fn expected_positions(&self) -> &'static BTreeSet { static TEST_ONLY_POSITIONS: Lazy> = Lazy::new(|| { IntoIterator::into_iter([ AttributePosition::AddressBlock, @@ -558,28 +646,26 @@ pub mod known_attributes { TestingAttribute::ExpectedFailure => &EXPECTED_FAILURE_POSITIONS, } } - - pub fn expected_failure_cases() -> &'static [&'static str] { - &[ - Self::ABORT_CODE_NAME, - Self::ARITHMETIC_ERROR_NAME, - Self::VECTOR_ERROR_NAME, - Self::OUT_OF_GAS_NAME, - Self::MAJOR_STATUS_NAME, - ] - } } impl VerificationAttribute { + const ALL_ATTRIBUTE_NAMES: [&'static str; 1] = [Self::VERIFY_ONLY]; pub const VERIFY_ONLY: &'static str = "verify_only"; + } + impl AttributeKind for VerificationAttribute { + fn add_attribute_names(table: &mut BTreeSet) { + for str in Self::ALL_ATTRIBUTE_NAMES { + table.insert(str.to_string()); + } + } - pub const fn name(&self) -> &str { + fn name(&self) -> &str { match self { Self::VerifyOnly => Self::VERIFY_ONLY, } } - pub fn expected_positions(&self) -> &'static BTreeSet { + fn expected_positions(&self) -> &'static BTreeSet { static VERIFY_ONLY_POSITIONS: Lazy> = Lazy::new(|| { IntoIterator::into_iter([ AttributePosition::AddressBlock, @@ -599,19 +685,68 @@ pub mod known_attributes { } impl NativeAttribute { + const ALL_ATTRIBUTE_NAMES: [&'static str; 2] = + [Self::BYTECODE_INSTRUCTION, Self::NATIVE_INTERFACE]; pub const BYTECODE_INSTRUCTION: &'static str = "bytecode_instruction"; + pub const NATIVE_INTERFACE: &'static str = "native_interface"; + } + impl AttributeKind for NativeAttribute { + fn add_attribute_names(table: &mut BTreeSet) { + for str in Self::ALL_ATTRIBUTE_NAMES { + table.insert(str.to_string()); + } + } - pub const fn name(&self) -> &str { + fn name(&self) -> &str { match self { NativeAttribute::BytecodeInstruction => Self::BYTECODE_INSTRUCTION, + NativeAttribute::NativeInterface => Self::NATIVE_INTERFACE, } } - pub fn expected_positions(&self) -> &'static BTreeSet { + fn expected_positions(&self) -> &'static BTreeSet { static BYTECODE_INSTRUCTION_POSITIONS: Lazy> = Lazy::new(|| IntoIterator::into_iter([AttributePosition::Function]).collect()); + static NATIVE_INTERFACE_POSITIONS: Lazy> = + Lazy::new(|| IntoIterator::into_iter([AttributePosition::Function]).collect()); match self { NativeAttribute::BytecodeInstruction => &BYTECODE_INSTRUCTION_POSITIONS, + NativeAttribute::NativeInterface => &NATIVE_INTERFACE_POSITIONS, + } + } + } + + impl DeprecationAttribute { + const ALL_ATTRIBUTE_NAMES: [&'static str; 1] = [Self::DEPRECATED_NAME]; + pub const DEPRECATED_NAME: &'static str = "deprecated"; + } + + impl AttributeKind for DeprecationAttribute { + fn add_attribute_names(table: &mut BTreeSet) { + for str in Self::ALL_ATTRIBUTE_NAMES { + table.insert(str.to_string()); + } + } + + fn name(&self) -> &str { + match self { + Self::Deprecated => Self::DEPRECATED_NAME, + } + } + + fn expected_positions(&self) -> &'static BTreeSet { + static DEPRECATED_POSITIONS: Lazy> = Lazy::new(|| { + IntoIterator::into_iter([ + AttributePosition::AddressBlock, + AttributePosition::Module, + AttributePosition::Constant, + AttributePosition::Struct, + AttributePosition::Function, + ]) + .collect() + }); + match self { + Self::Deprecated => &DEPRECATED_POSITIONS, } } } diff --git a/third_party/move/move-compiler/src/unit_test/filter_test_members.rs b/third_party/move/move-compiler/src/unit_test/filter_test_members.rs index 7931b9fe16855..b4aff62312f71 100644 --- a/third_party/move/move-compiler/src/unit_test/filter_test_members.rs +++ b/third_party/move/move-compiler/src/unit_test/filter_test_members.rs @@ -241,7 +241,9 @@ fn test_attributes(attrs: &P::Attributes) -> Vec<(Loc, known_attributes::Testing .filter_map( |attr| match KnownAttribute::resolve(attr.value.attribute_name().value)? { KnownAttribute::Testing(test_attr) => Some((attr.loc, test_attr)), - KnownAttribute::Verification(_) | KnownAttribute::Native(_) => None, + KnownAttribute::Verification(_) + | KnownAttribute::Native(_) + | KnownAttribute::Deprecation(_) => None, }, ) .collect() diff --git a/third_party/move/move-compiler/src/unit_test/plan_builder.rs b/third_party/move/move-compiler/src/unit_test/plan_builder.rs index a36e733b3e08e..0133e1d17c500 100644 --- a/third_party/move/move-compiler/src/unit_test/plan_builder.rs +++ b/third_party/move/move-compiler/src/unit_test/plan_builder.rs @@ -10,7 +10,7 @@ use crate::{ }, parser::ast::ConstantName, shared::{ - known_attributes::{KnownAttribute, TestingAttribute}, + known_attributes::{AttributeKind, KnownAttribute, TestingAttribute}, unique_map::UniqueMap, CompilationEnv, Identifier, NumericalAddress, }, diff --git a/third_party/move/move-compiler/src/verification/ast_filter.rs b/third_party/move/move-compiler/src/verification/ast_filter.rs index ec39fafcbd9bd..32aeab8a39467 100644 --- a/third_party/move/move-compiler/src/verification/ast_filter.rs +++ b/third_party/move/move-compiler/src/verification/ast_filter.rs @@ -66,7 +66,9 @@ fn verification_attributes( .filter_map( |attr| match KnownAttribute::resolve(attr.value.attribute_name().value)? { KnownAttribute::Verification(verify_attr) => Some((attr.loc, verify_attr)), - KnownAttribute::Testing(_) | KnownAttribute::Native(_) => None, + KnownAttribute::Testing(_) + | KnownAttribute::Native(_) + | KnownAttribute::Deprecation(_) => None, }, ) .collect() diff --git a/third_party/move/move-compiler/tests/move_check/parser/aptos_stdlib_attributes.exp b/third_party/move/move-compiler/tests/move_check/parser/aptos_stdlib_attributes.exp new file mode 100644 index 0000000000000..563f0310aeee4 --- /dev/null +++ b/third_party/move/move-compiler/tests/move_check/parser/aptos_stdlib_attributes.exp @@ -0,0 +1,24 @@ +error[E02001]: duplicate declaration, item, or annotation + ┌─ tests/move_check/parser/aptos_stdlib_attributes.move:4:10 + │ +4 │ #[a, a(x = 0)] + │ - ^^^^^^^^ Duplicate attribute 'a' attached to the same item + │ │ + │ Attribute previously given here + +error[E02001]: duplicate declaration, item, or annotation + ┌─ tests/move_check/parser/aptos_stdlib_attributes.move:8:12 + │ +8 │ #[b(a, a = 0, a(x = 1))] + │ - ^^^^^ Duplicate attribute 'a' attached to the same item + │ │ + │ Attribute previously given here + +error[E02001]: duplicate declaration, item, or annotation + ┌─ tests/move_check/parser/aptos_stdlib_attributes.move:8:19 + │ +8 │ #[b(a, a = 0, a(x = 1))] + │ - ^^^^^^^^ Duplicate attribute 'a' attached to the same item + │ │ + │ Attribute previously given here + diff --git a/third_party/move/move-compiler/tests/move_check/parser/aptos_stdlib_attributes.move b/third_party/move/move-compiler/tests/move_check/parser/aptos_stdlib_attributes.move new file mode 100644 index 0000000000000..2180c108cb141 --- /dev/null +++ b/third_party/move/move-compiler/tests/move_check/parser/aptos_stdlib_attributes.move @@ -0,0 +1,10 @@ +// Test that warnings about unknown "#[testonly]" attribute is +// suppressed in apts_std module. +module aptos_std::module_with_suppressed_warnings { + #[a, a(x = 0)] + fun foo() {} + + #[testonly] + #[b(a, a = 0, a(x = 1))] + fun bar() {} +} diff --git a/third_party/move/move-compiler/tests/move_check/parser/aptos_stdlib_attributes2.move b/third_party/move/move-compiler/tests/move_check/parser/aptos_stdlib_attributes2.move new file mode 100644 index 0000000000000..781e7484cc8cb --- /dev/null +++ b/third_party/move/move-compiler/tests/move_check/parser/aptos_stdlib_attributes2.move @@ -0,0 +1,6 @@ +module aptos_std::M { + fun foo() {} + + #[testonly] + fun bar() {} +} diff --git a/third_party/move/move-compiler/tests/move_check/parser/attribute_placement.exp b/third_party/move/move-compiler/tests/move_check/parser/attribute_placement.exp new file mode 100644 index 0000000000000..aee01fa4e65f6 --- /dev/null +++ b/third_party/move/move-compiler/tests/move_check/parser/attribute_placement.exp @@ -0,0 +1,84 @@ +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/attribute_placement.move:3:3 + │ +3 │ #[attr] + │ ^^^^ Attribute name 'attr' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/attribute_placement.move:5:7 + │ +5 │ #[attr] + │ ^^^^ Attribute name 'attr' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/attribute_placement.move:8:7 + │ +8 │ #[attr] + │ ^^^^ Attribute name 'attr' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/attribute_placement.move:11:7 + │ +11 │ #[attr] + │ ^^^^ Attribute name 'attr' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/attribute_placement.move:14:7 + │ +14 │ #[attr] + │ ^^^^ Attribute name 'attr' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/attribute_placement.move:17:7 + │ +17 │ #[attr] + │ ^^^^ Attribute name 'attr' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/attribute_placement.move:22:3 + │ +22 │ #[attr] + │ ^^^^ Attribute name 'attr' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/attribute_placement.move:24:7 + │ +24 │ #[attr] + │ ^^^^ Attribute name 'attr' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/attribute_placement.move:27:7 + │ +27 │ #[attr] + │ ^^^^ Attribute name 'attr' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/attribute_placement.move:31:3 + │ +31 │ #[attr] + │ ^^^^ Attribute name 'attr' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/attribute_placement.move:33:7 + │ +33 │ #[attr] + │ ^^^^ Attribute name 'attr' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/attribute_placement.move:36:7 + │ +36 │ #[attr] + │ ^^^^ Attribute name 'attr' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/attribute_placement.move:39:7 + │ +39 │ #[attr] + │ ^^^^ Attribute name 'attr' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/attribute_placement.move:44:7 + │ +44 │ #[attr] + │ ^^^^ Attribute name 'attr' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + diff --git a/third_party/move/move-compiler/tests/move_check/parser/attribute_variants.exp b/third_party/move/move-compiler/tests/move_check/parser/attribute_variants.exp new file mode 100644 index 0000000000000..8d58dee27063a --- /dev/null +++ b/third_party/move/move-compiler/tests/move_check/parser/attribute_variants.exp @@ -0,0 +1,60 @@ +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/attribute_variants.move:2:3 + │ +2 │ #[attr0] + │ ^^^^^ Attribute name 'attr0' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/attribute_variants.move:3:3 + │ +3 │ #[attr1=0, attr2=b"hello", attr3=x"0f", attr4=0x42, attr5(attr0, attr1, attr2(attr0, attr1=0))] + │ ^^^^^ Attribute name 'attr1' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/attribute_variants.move:3:12 + │ +3 │ #[attr1=0, attr2=b"hello", attr3=x"0f", attr4=0x42, attr5(attr0, attr1, attr2(attr0, attr1=0))] + │ ^^^^^ Attribute name 'attr2' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/attribute_variants.move:3:28 + │ +3 │ #[attr1=0, attr2=b"hello", attr3=x"0f", attr4=0x42, attr5(attr0, attr1, attr2(attr0, attr1=0))] + │ ^^^^^ Attribute name 'attr3' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/attribute_variants.move:3:41 + │ +3 │ #[attr1=0, attr2=b"hello", attr3=x"0f", attr4=0x42, attr5(attr0, attr1, attr2(attr0, attr1=0))] + │ ^^^^^ Attribute name 'attr4' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/attribute_variants.move:3:53 + │ +3 │ #[attr1=0, attr2=b"hello", attr3=x"0f", attr4=0x42, attr5(attr0, attr1, attr2(attr0, attr1=0))] + │ ^^^^^ Attribute name 'attr5' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/attribute_variants.move:4:3 + │ +4 │ #[bttr0=false, bttr1=0u8, bttr2=0u64, bttr3=0u128] + │ ^^^^^ Attribute name 'bttr0' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/attribute_variants.move:4:16 + │ +4 │ #[bttr0=false, bttr1=0u8, bttr2=0u64, bttr3=0u128] + │ ^^^^^ Attribute name 'bttr1' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/attribute_variants.move:4:27 + │ +4 │ #[bttr0=false, bttr1=0u8, bttr2=0u64, bttr3=0u128] + │ ^^^^^ Attribute name 'bttr2' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/attribute_variants.move:4:39 + │ +4 │ #[bttr0=false, bttr1=0u8, bttr2=0u64, bttr3=0u128] + │ ^^^^^ Attribute name 'bttr3' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + diff --git a/third_party/move/move-compiler/tests/move_check/parser/duplicate_attributes.exp b/third_party/move/move-compiler/tests/move_check/parser/duplicate_attributes.exp index 4930a1562bd0e..ece55e6ee1b76 100644 --- a/third_party/move/move-compiler/tests/move_check/parser/duplicate_attributes.exp +++ b/third_party/move/move-compiler/tests/move_check/parser/duplicate_attributes.exp @@ -1,3 +1,15 @@ +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/duplicate_attributes.move:2:7 + │ +2 │ #[a, a(x = 0)] + │ ^ Attribute name 'a' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/duplicate_attributes.move:2:10 + │ +2 │ #[a, a(x = 0)] + │ ^ Attribute name 'a' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + error[E02001]: duplicate declaration, item, or annotation ┌─ tests/move_check/parser/duplicate_attributes.move:2:10 │ @@ -6,6 +18,12 @@ error[E02001]: duplicate declaration, item, or annotation │ │ │ Attribute previously given here +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/duplicate_attributes.move:5:7 + │ +5 │ #[b(a, a = 0, a(x = 1))] + │ ^ Attribute name 'b' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + error[E02001]: duplicate declaration, item, or annotation ┌─ tests/move_check/parser/duplicate_attributes.move:5:12 │ diff --git a/third_party/move/move-compiler/tests/move_check/parser/testonly.exp b/third_party/move/move-compiler/tests/move_check/parser/testonly.exp new file mode 100644 index 0000000000000..0dc78b0a3f312 --- /dev/null +++ b/third_party/move/move-compiler/tests/move_check/parser/testonly.exp @@ -0,0 +1,12 @@ +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/testonly.move:5:7 + │ +5 │ #[testonly] + │ ^^^^^^^^ Attribute name 'testonly' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/testonly.move:15:7 + │ +15 │ #[view] + │ ^^^^ Attribute name 'view' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + diff --git a/third_party/move/move-compiler/tests/move_check/parser/testonly.move b/third_party/move/move-compiler/tests/move_check/parser/testonly.move new file mode 100644 index 0000000000000..6631942d17dc6 --- /dev/null +++ b/third_party/move/move-compiler/tests/move_check/parser/testonly.move @@ -0,0 +1,19 @@ +module 0x1::A { + #[test] + fun a() { } + + #[testonly] + public fun a_call() { + abort 0 + } + + #[test_only] + public fun b_call() { + abort 0 + } + + #[view] + public fun c_call() { + abort 0 + } +} diff --git a/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/aptos_stdlib_attributes.exp b/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/aptos_stdlib_attributes.exp new file mode 100644 index 0000000000000..d6ae3f625caa8 --- /dev/null +++ b/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/aptos_stdlib_attributes.exp @@ -0,0 +1,24 @@ +error[E02001]: duplicate declaration, item, or annotation + ┌─ tests/move_check/skip_attribute_checks/aptos_stdlib_attributes.move:4:10 + │ +4 │ #[a, a(x = 0)] + │ - ^^^^^^^^ Duplicate attribute 'a' attached to the same item + │ │ + │ Attribute previously given here + +error[E02001]: duplicate declaration, item, or annotation + ┌─ tests/move_check/skip_attribute_checks/aptos_stdlib_attributes.move:8:12 + │ +8 │ #[b(a, a = 0, a(x = 1))] + │ - ^^^^^ Duplicate attribute 'a' attached to the same item + │ │ + │ Attribute previously given here + +error[E02001]: duplicate declaration, item, or annotation + ┌─ tests/move_check/skip_attribute_checks/aptos_stdlib_attributes.move:8:19 + │ +8 │ #[b(a, a = 0, a(x = 1))] + │ - ^^^^^^^^ Duplicate attribute 'a' attached to the same item + │ │ + │ Attribute previously given here + diff --git a/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/aptos_stdlib_attributes.move b/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/aptos_stdlib_attributes.move new file mode 100644 index 0000000000000..2180c108cb141 --- /dev/null +++ b/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/aptos_stdlib_attributes.move @@ -0,0 +1,10 @@ +// Test that warnings about unknown "#[testonly]" attribute is +// suppressed in apts_std module. +module aptos_std::module_with_suppressed_warnings { + #[a, a(x = 0)] + fun foo() {} + + #[testonly] + #[b(a, a = 0, a(x = 1))] + fun bar() {} +} diff --git a/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/aptos_stdlib_attributes2.move b/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/aptos_stdlib_attributes2.move new file mode 100644 index 0000000000000..781e7484cc8cb --- /dev/null +++ b/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/aptos_stdlib_attributes2.move @@ -0,0 +1,6 @@ +module aptos_std::M { + fun foo() {} + + #[testonly] + fun bar() {} +} diff --git a/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/attribute_no_closing_bracket.exp b/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/attribute_no_closing_bracket.exp new file mode 100644 index 0000000000000..3148a6a7ca752 --- /dev/null +++ b/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/attribute_no_closing_bracket.exp @@ -0,0 +1,8 @@ +error[E01002]: unexpected token + ┌─ tests/move_check/skip_attribute_checks/attribute_no_closing_bracket.move:4:5 + │ +3 │ #[attr = 0 + │ - To match this '[' +4 │ fun foo() {} + │ ^ Expected ']' + diff --git a/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/attribute_no_closing_bracket.move b/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/attribute_no_closing_bracket.move new file mode 100644 index 0000000000000..9a28c27c391e4 --- /dev/null +++ b/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/attribute_no_closing_bracket.move @@ -0,0 +1,5 @@ +module 0x42::M { + // Errors expecting a ']' + #[attr = 0 + fun foo() {} +} diff --git a/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/attribute_placement.move b/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/attribute_placement.move new file mode 100644 index 0000000000000..0c50c6f7a5485 --- /dev/null +++ b/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/attribute_placement.move @@ -0,0 +1,46 @@ +#[attr] +address 0x42 { +#[attr] +module M { + #[attr] + use 0x42::N; + + #[attr] + struct S {} + + #[attr] + const C: u64 = 0; + + #[attr] + public fun foo() { N::bar() } + + #[attr] + spec foo {} +} +} + +#[attr] +module 0x42::N { + #[attr] + friend 0x42::M; + + #[attr] + public fun bar() {} +} + +#[attr] +script { + #[attr] + use 0x42::M; + + #[attr] + const C: u64 = 0; + + #[attr] + fun main() { + M::foo(); + } + + #[attr] + spec main { } +} diff --git a/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/attribute_variants.move b/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/attribute_variants.move new file mode 100644 index 0000000000000..482fa4cbacacc --- /dev/null +++ b/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/attribute_variants.move @@ -0,0 +1,6 @@ +#[] +#[attr0] +#[attr1=0, attr2=b"hello", attr3=x"0f", attr4=0x42, attr5(attr0, attr1, attr2(attr0, attr1=0))] +#[bttr0=false, bttr1=0u8, bttr2=0u64, bttr3=0u128] +#[] +module 0x42::M {} diff --git a/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/duplicate_attributes.exp b/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/duplicate_attributes.exp new file mode 100644 index 0000000000000..1de53e06c5e25 --- /dev/null +++ b/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/duplicate_attributes.exp @@ -0,0 +1,24 @@ +error[E02001]: duplicate declaration, item, or annotation + ┌─ tests/move_check/skip_attribute_checks/duplicate_attributes.move:2:10 + │ +2 │ #[a, a(x = 0)] + │ - ^^^^^^^^ Duplicate attribute 'a' attached to the same item + │ │ + │ Attribute previously given here + +error[E02001]: duplicate declaration, item, or annotation + ┌─ tests/move_check/skip_attribute_checks/duplicate_attributes.move:5:12 + │ +5 │ #[b(a, a = 0, a(x = 1))] + │ - ^^^^^ Duplicate attribute 'a' attached to the same item + │ │ + │ Attribute previously given here + +error[E02001]: duplicate declaration, item, or annotation + ┌─ tests/move_check/skip_attribute_checks/duplicate_attributes.move:5:19 + │ +5 │ #[b(a, a = 0, a(x = 1))] + │ - ^^^^^^^^ Duplicate attribute 'a' attached to the same item + │ │ + │ Attribute previously given here + diff --git a/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/duplicate_attributes.move b/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/duplicate_attributes.move new file mode 100644 index 0000000000000..e2de77f0f23a4 --- /dev/null +++ b/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/duplicate_attributes.move @@ -0,0 +1,7 @@ +module 0x42::M { + #[a, a(x = 0)] + fun foo() {} + + #[b(a, a = 0, a(x = 1))] + fun bar() {} +} diff --git a/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/extra_attributes.move b/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/extra_attributes.move new file mode 100644 index 0000000000000..11ff5533c4f37 --- /dev/null +++ b/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/extra_attributes.move @@ -0,0 +1,26 @@ +// tests non-abort related execution failures +module 0x1::n {} +module 0x1::m { + #[test_only] + use 0x1::n; + + #[test] + #[expected_failure(vector_error, location=std::vector, hello=0)] + fun t0() { } + + #[test] + #[expected_failure(arithmetic_error, location=n, wowza)] + fun t1() { } + + #[test] + #[expected_failure(out_of_gas, location=Self, so_many_attrs)] + fun t2() { } + + #[test] + #[expected_failure(major_status=4004, an_attr_here_is_unused, location=Self)] + fun t3() { } + + #[test] + #[expected_failure(major_status=4016, minor_code=0, location=Self)] + fun t4() { } +} diff --git a/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/extra_attributes2.move b/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/extra_attributes2.move new file mode 100644 index 0000000000000..ba09afd866987 --- /dev/null +++ b/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/extra_attributes2.move @@ -0,0 +1,23 @@ +// tests non-abort related execution failures with errors in attributes +module 0x1::n {} +module 0x1::m { + #[test] + #[expected_failure(arithmetic_error, location=Self)] + fun t5() { } + + #[test] + #[expected_failure(abort_code=3, test, location=Self)] + fun t6() { } + + #[test] + #[expected_failure(vector_error, test_only, location=Self)] + fun t7() { } + + #[test_only] + #[expected_failure(bytecode_instruction, location=Self)] + fun t8() { } + + #[test] + #[expected_failure(verify_only)] + fun t9() { } +} diff --git a/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/testonly.move b/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/testonly.move new file mode 100644 index 0000000000000..0923625d717ba --- /dev/null +++ b/third_party/move/move-compiler/tests/move_check/skip_attribute_checks/testonly.move @@ -0,0 +1,9 @@ +module 0x1::A { + #[test] + fun a() { } + + #[testonly] + public fun a_call() { + abort 0 + } +} diff --git a/third_party/move/move-compiler/tests/move_check/typing/assign_tuple.exp b/third_party/move/move-compiler/tests/move_check/typing/assign_tuple.exp new file mode 100644 index 0000000000000..d547fa6237e24 --- /dev/null +++ b/third_party/move/move-compiler/tests/move_check/typing/assign_tuple.exp @@ -0,0 +1,9 @@ +error[E04005]: expected a single type + ┌─ tests/move_check/typing/assign_tuple.move:12:13 + │ + 7 │ fun tuple(x: u64): (u64, S) { + │ -------- Expected a single type, but found expression list type: '(u64, 0x42::tuple_invalid::S)' + · +12 │ let x = tuple(x); + │ ^ Invalid type for local + diff --git a/third_party/move/move-compiler/tests/move_check/typing/assign_tuple.move b/third_party/move/move-compiler/tests/move_check/typing/assign_tuple.move new file mode 100644 index 0000000000000..bcba65ad8363c --- /dev/null +++ b/third_party/move/move-compiler/tests/move_check/typing/assign_tuple.move @@ -0,0 +1,15 @@ +module 0x42::tuple_invalid { + + struct S { + f: u64, + } + + fun tuple(x: u64): (u64, S) { + (x, S{f: x + 1}) + } + + fun use_tuple1(x: u64): u64 { + let x = tuple(x); + 1 + } +} diff --git a/third_party/move/move-compiler/tests/move_check/typing/tuple.move b/third_party/move/move-compiler/tests/move_check/typing/tuple.move new file mode 100644 index 0000000000000..ae3958d3b8e6c --- /dev/null +++ b/third_party/move/move-compiler/tests/move_check/typing/tuple.move @@ -0,0 +1,15 @@ +module 0x42::tuple { + + struct S { + f: u64, + } + + fun tuple(x: u64): (u64, S) { + (x, S{f: x + 1}) + } + + fun use_tuple(x: u64): u64 { + let (x, S{f: y}) = tuple(x); + x + y + } +} diff --git a/third_party/move/move-compiler/tests/move_check/unit_test/extra_attributes.move b/third_party/move/move-compiler/tests/move_check/unit_test/extra_attributes.move index 33bf5eda30142..11ff5533c4f37 100644 --- a/third_party/move/move-compiler/tests/move_check/unit_test/extra_attributes.move +++ b/third_party/move/move-compiler/tests/move_check/unit_test/extra_attributes.move @@ -23,5 +23,4 @@ module 0x1::m { #[test] #[expected_failure(major_status=4016, minor_code=0, location=Self)] fun t4() { } - } diff --git a/third_party/move/move-compiler/tests/move_check/unit_test/extra_attributes2.move b/third_party/move/move-compiler/tests/move_check/unit_test/extra_attributes2.move new file mode 100644 index 0000000000000..ba09afd866987 --- /dev/null +++ b/third_party/move/move-compiler/tests/move_check/unit_test/extra_attributes2.move @@ -0,0 +1,23 @@ +// tests non-abort related execution failures with errors in attributes +module 0x1::n {} +module 0x1::m { + #[test] + #[expected_failure(arithmetic_error, location=Self)] + fun t5() { } + + #[test] + #[expected_failure(abort_code=3, test, location=Self)] + fun t6() { } + + #[test] + #[expected_failure(vector_error, test_only, location=Self)] + fun t7() { } + + #[test_only] + #[expected_failure(bytecode_instruction, location=Self)] + fun t8() { } + + #[test] + #[expected_failure(verify_only)] + fun t9() { } +} diff --git a/third_party/move/move-compiler/tests/move_check_testsuite.rs b/third_party/move/move-compiler/tests/move_check_testsuite.rs index 93d87352f9105..7d05b5f75b000 100644 --- a/third_party/move/move-compiler/tests/move_check_testsuite.rs +++ b/third_party/move/move-compiler/tests/move_check_testsuite.rs @@ -9,7 +9,7 @@ use move_command_line_common::{ use move_compiler::{ compiled_unit::AnnotatedCompiledUnit, diagnostics::*, - shared::{Flags, NumericalAddress}, + shared::{known_attributes::KnownAttribute, Flags, NumericalAddress}, unit_test, CommentMap, Compiler, SteppedCompiler, PASS_CFGIR, PASS_PARSER, }; use std::{collections::BTreeMap, fs, path::Path}; @@ -23,8 +23,12 @@ const VERIFICATION_EXT: &str = "verification"; /// Root of tests which require to set flavor flags. const FLAVOR_PATH: &str = "flavors/"; +/// Root of tests which require to set skip_attribute_checks flag. +const SKIP_ATTRIBUTE_CHECKS_PATH: &str = "skip_attribute_checks/"; + fn default_testing_addresses() -> BTreeMap { let mapping = [ + ("aptos_std", "0x1"), ("std", "0x1"), ("M", "0x1"), ("A", "0x42"), @@ -85,8 +89,8 @@ fn move_check_testsuite(path: &Path) -> datatest_stable::Result<()> { let out_path = path.with_extension(OUT_EXT); let mut flags = Flags::empty(); - match path.to_str() { - Some(p) if p.contains(FLAVOR_PATH) => { + if let Some(p) = path.to_str() { + if p.contains(FLAVOR_PATH) { // Extract the flavor from the path. Its the directory name of the file. let flavor = path .parent() @@ -96,8 +100,10 @@ fn move_check_testsuite(path: &Path) -> datatest_stable::Result<()> { .to_string_lossy() .to_string(); flags = flags.set_flavor(flavor) - }, - _ => {}, + } + if p.contains(SKIP_ATTRIBUTE_CHECKS_PATH) { + flags = flags.set_skip_attribute_checks(true); + } }; run_test(path, &exp_path, &out_path, flags)?; Ok(()) @@ -111,8 +117,9 @@ fn run_test(path: &Path, exp_path: &Path, out_path: &Path, flags: Flags) -> anyh targets, move_stdlib::move_stdlib_files(), default_testing_addresses(), + flags, + KnownAttribute::get_all_attribute_names(), ) - .set_flags(flags) .run::()?; let diags = move_check_for_errors(comments_and_compiler_res); diff --git a/third_party/move/move-model/src/lib.rs b/third_party/move/move-model/src/lib.rs index 36fc33bb2a510..6b2f0febb2a33 100644 --- a/third_party/move/move-model/src/lib.rs +++ b/third_party/move/move-model/src/lib.rs @@ -78,6 +78,8 @@ pub struct PackageInfo { pub fn run_model_builder_in_compiler_mode( source: PackageInfo, deps: Vec, + skip_attribute_checks: bool, + known_attributes: &BTreeSet, ) -> anyhow::Result { let to_package_paths = |PackageInfo { sources, @@ -94,26 +96,14 @@ pub fn run_model_builder_in_compiler_mode( compile_via_model: true, ..ModelBuilderOptions::default() }, - Flags::model_compilation(), + Flags::model_compilation().set_skip_attribute_checks(skip_attribute_checks), + known_attributes, ) } // ================================================================================================= // Entry Point V1 -/// Builds the move model with default compilation flags and default options. This calls -/// the move compiler v1 to compile to bytecode first and attach the generated bytecode to -/// the model. -pub fn run_model_builder< - Paths: Into + Clone, - NamedAddress: Into + Clone, ->( - move_sources: Vec>, - deps: Vec>, -) -> anyhow::Result { - run_model_builder_with_options(move_sources, deps, ModelBuilderOptions::default()) -} - /// Build the move model with default compilation flags and custom options. pub fn run_model_builder_with_options< Paths: Into + Clone, @@ -122,12 +112,17 @@ pub fn run_model_builder_with_options< move_sources: Vec>, deps: Vec>, options: ModelBuilderOptions, + skip_attribute_checks: bool, + known_attributes: &BTreeSet, ) -> anyhow::Result { + let mut flags = Flags::verification(); + flags = flags.set_skip_attribute_checks(skip_attribute_checks); run_model_builder_with_options_and_compilation_flags( move_sources, deps, options, - Flags::verification(), + flags, + known_attributes, ) } @@ -140,15 +135,16 @@ pub fn run_model_builder_with_options_and_compilation_flags< deps: Vec>, options: ModelBuilderOptions, flags: Flags, + known_attributes: &BTreeSet, ) -> anyhow::Result { let mut env = GlobalEnv::new(); let compile_via_model = options.compile_via_model; env.set_extension(options); // Step 1: parse the program to get comments and a separation of targets and dependencies. - let (files, comments_and_compiler_res) = Compiler::from_package_paths(move_sources, deps) - .set_flags(flags) - .run::()?; + let (files, comments_and_compiler_res) = + Compiler::from_package_paths(move_sources, deps, flags, known_attributes) + .run::()?; let (comment_map, compiler) = match comments_and_compiler_res { Err(diags) => { // Add source files so that the env knows how to translate locations of parse errors diff --git a/third_party/move/move-model/tests/testsuite.rs b/third_party/move/move-model/tests/testsuite.rs index 35baedcc3a9e1..871a7fbbb63a5 100644 --- a/third_party/move/move-model/tests/testsuite.rs +++ b/third_party/move/move-model/tests/testsuite.rs @@ -4,7 +4,7 @@ use codespan_reporting::{diagnostic::Severity, term::termcolor::Buffer}; use move_command_line_common::testing::EXP_EXT; -use move_compiler::shared::PackagePaths; +use move_compiler::shared::{known_attributes::KnownAttribute, PackagePaths}; use move_model::{options::ModelBuilderOptions, run_model_builder_with_options}; use move_prover_test_utils::baseline_test::verify_or_update_baseline; use std::path::Path; @@ -15,7 +15,13 @@ fn test_runner(path: &Path, options: ModelBuilderOptions) -> datatest_stable::Re paths: vec![path.to_str().unwrap().to_string()], named_address_map: std::collections::BTreeMap::::new(), }]; - let env = run_model_builder_with_options(targets, vec![], options)?; + let env = run_model_builder_with_options( + targets, + vec![], + options, + false, + KnownAttribute::get_all_attribute_names(), + )?; let diags = if env.diag_count(Severity::Warning) > 0 { let mut writer = Buffer::no_color(); env.report_diag(&mut writer, Severity::Warning); diff --git a/third_party/move/move-prover/bytecode/tests/testsuite.rs b/third_party/move/move-prover/bytecode/tests/testsuite.rs index 6bfb513400752..62e6c307e1b0c 100644 --- a/third_party/move/move-prover/bytecode/tests/testsuite.rs +++ b/third_party/move/move-prover/bytecode/tests/testsuite.rs @@ -5,7 +5,7 @@ use anyhow::anyhow; use codespan_reporting::{diagnostic::Severity, term::termcolor::Buffer}; use move_command_line_common::testing::EXP_EXT; -use move_compiler::shared::PackagePaths; +use move_compiler::shared::{known_attributes::KnownAttribute, PackagePaths}; use move_model::{model::GlobalEnv, options::ModelBuilderOptions, run_model_builder_with_options}; use move_prover_test_utils::{baseline_test::verify_or_update_baseline, extract_test_directives}; use move_stackless_bytecode::{ @@ -211,6 +211,8 @@ fn test_runner(path: &Path) -> datatest_stable::Result<()> { }], vec![], ModelBuilderOptions::default(), + false, + KnownAttribute::get_all_attribute_names(), )?; let out = if env.has_errors() { let mut error_writer = Buffer::no_color(); diff --git a/third_party/move/move-prover/lab/src/benchmark.rs b/third_party/move/move-prover/lab/src/benchmark.rs index 2e34e1f04722e..9060c5c4da3e7 100644 --- a/third_party/move/move-prover/lab/src/benchmark.rs +++ b/third_party/move/move-prover/lab/src/benchmark.rs @@ -14,7 +14,7 @@ use clap::{ use codespan_reporting::term::termcolor::{ColorChoice, StandardStream}; use itertools::Itertools; use log::LevelFilter; -use move_compiler::shared::PackagePaths; +use move_compiler::shared::{known_attributes::KnownAttribute, PackagePaths}; use move_model::{ model::{FunctionEnv, GlobalEnv, ModuleEnv, VerificationScope}, parse_addresses_from_options, run_model_builder_with_options, @@ -150,6 +150,8 @@ fn run_benchmark( }; let addrs = parse_addresses_from_options(options.move_named_address_values.clone())?; options.move_deps.append(&mut dep_dirs.to_vec()); + let skip_attribute_checks = true; + let known_attributes = KnownAttribute::get_all_attribute_names().clone(); let env = run_model_builder_with_options( vec![PackagePaths { name: None, @@ -162,6 +164,8 @@ fn run_benchmark( named_address_map: addrs, }], options.model_builder.clone(), + skip_attribute_checks, + &known_attributes, )?; let mut error_writer = StandardStream::stderr(ColorChoice::Auto); diff --git a/third_party/move/move-prover/move-docgen/tests/testsuite.rs b/third_party/move/move-prover/move-docgen/tests/testsuite.rs index baf86d6d0d8a4..5376df7b22766 100644 --- a/third_party/move/move-prover/move-docgen/tests/testsuite.rs +++ b/third_party/move/move-prover/move-docgen/tests/testsuite.rs @@ -20,6 +20,7 @@ const FLAGS: &[&str] = &[ "--dependency=../../move-stdlib/sources", "--named-addresses=std=0x1", "--docgen", + "--skip-attribute-checks", ]; fn test_runner(path: &Path) -> datatest_stable::Result<()> { @@ -74,6 +75,7 @@ fn test_runner(path: &Path) -> datatest_stable::Result<()> { fn test_docgen(path: &Path, mut options: Options, suffix: &str) -> anyhow::Result<()> { let mut temp_path = PathBuf::from(TempDir::new()?.path()); options.docgen.output_directory = temp_path.to_string_lossy().to_string(); + options.skip_attribute_checks = true; let base_name = format!( "{}.md", path.file_stem() diff --git a/third_party/move/move-prover/src/cli.rs b/third_party/move/move-prover/src/cli.rs index febfdbd73c87b..3139723273113 100644 --- a/third_party/move/move-prover/src/cli.rs +++ b/third_party/move/move-prover/src/cli.rs @@ -11,7 +11,7 @@ use clap::{builder::PossibleValuesParser, Arg, ArgAction, ArgAction::SetTrue, Co use codespan_reporting::diagnostic::Severity; use log::LevelFilter; use move_abigen::AbigenOptions; -use move_compiler::shared::NumericalAddress; +use move_compiler::{command_line::SKIP_ATTRIBUTE_CHECKS, shared::NumericalAddress}; use move_docgen::DocgenOptions; use move_errmapgen::ErrmapOptions; use move_model::{model::VerificationScope, options::ModelBuilderOptions}; @@ -63,6 +63,8 @@ pub struct Options { pub move_named_address_values: Vec, /// Whether to run experimental pipeline pub experimental_pipeline: bool, + /// Whether to skip checking for unknown attributes + pub skip_attribute_checks: bool, /// BEGIN OF STRUCTURED OPTIONS. DO NOT ADD VALUE FIELDS AFTER THIS /// Options for the model builder. @@ -100,6 +102,7 @@ impl Default for Options { abigen: AbigenOptions::default(), errmapgen: ErrmapOptions::default(), experimental_pipeline: false, + skip_attribute_checks: false, } } } @@ -468,6 +471,12 @@ impl Options { .action(SetTrue) .help("whether to run experimental pipeline") ) + .arg( + Arg::new(SKIP_ATTRIBUTE_CHECKS) + .long(SKIP_ATTRIBUTE_CHECKS) + .action(SetTrue) + .help("whether to not complain about unknown attributes in Move code") + ) .arg( Arg::new("weak-edges") .long("weak-edges") @@ -703,6 +712,9 @@ impl Options { if matches.get_flag("experimental-pipeline") { options.experimental_pipeline = true; } + if matches.contains_id(SKIP_ATTRIBUTE_CHECKS) { + options.skip_attribute_checks = true; + } if matches.contains_id("timeout") { options.backend.vc_timeout = *matches.try_get_one("timeout")?.unwrap(); } diff --git a/third_party/move/move-prover/src/lib.rs b/third_party/move/move-prover/src/lib.rs index 801fc449e007f..3ad78753c84c8 100644 --- a/third_party/move/move-prover/src/lib.rs +++ b/third_party/move/move-prover/src/lib.rs @@ -10,7 +10,7 @@ use codespan_reporting::term::termcolor::{ColorChoice, StandardStream, WriteColo #[allow(unused_imports)] use log::{debug, info, warn}; use move_abigen::Abigen; -use move_compiler::shared::PackagePaths; +use move_compiler::shared::{known_attributes::KnownAttribute, PackagePaths}; use move_docgen::Docgen; use move_errmapgen::ErrmapGen; use move_model::{ @@ -59,6 +59,8 @@ pub fn run_move_prover( named_address_map: addrs, }], options.model_builder.clone(), + options.skip_attribute_checks, + KnownAttribute::get_all_attribute_names(), )?; run_move_prover_with_model(&env, error_writer, options, Some(now)) } diff --git a/third_party/move/move-vm/integration-tests/src/compiler.rs b/third_party/move/move-vm/integration-tests/src/compiler.rs index 5441bfa04fdd5..53fbd2cb4d4d6 100644 --- a/third_party/move/move-vm/integration-tests/src/compiler.rs +++ b/third_party/move/move-vm/integration-tests/src/compiler.rs @@ -4,7 +4,11 @@ use anyhow::{bail, Result}; use move_binary_format::file_format::{CompiledModule, CompiledScript}; -use move_compiler::{compiled_unit::AnnotatedCompiledUnit, Compiler as MoveCompiler}; +use move_compiler::{ + compiled_unit::AnnotatedCompiledUnit, + shared::{known_attributes::KnownAttribute, Flags}, + Compiler as MoveCompiler, +}; use std::{fs::File, io::Write, path::Path}; use tempfile::tempdir; @@ -21,6 +25,8 @@ pub fn compile_units(s: &str) -> Result> { vec![file_path.to_str().unwrap().to_string()], vec![], move_stdlib::move_stdlib_named_addresses(), + Flags::empty().set_skip_attribute_checks(false), + KnownAttribute::get_all_attribute_names(), ) .build_and_report()?; @@ -42,6 +48,8 @@ pub fn compile_units_with_stdlib(s: &str) -> Result> vec![file_path.to_str().unwrap().to_string()], move_stdlib::move_stdlib_files(), move_stdlib::move_stdlib_named_addresses(), + Flags::empty().set_skip_attribute_checks(false), + KnownAttribute::get_all_attribute_names(), ) .build_and_report()?; @@ -64,6 +72,8 @@ pub fn compile_modules_in_file(path: &Path) -> Result> { vec![path.to_str().unwrap().to_string()], vec![], std::collections::BTreeMap::::new(), + Flags::empty().set_skip_attribute_checks(false), + KnownAttribute::get_all_attribute_names(), ) .build_and_report()?; diff --git a/third_party/move/testing-infra/test-generation/src/lib.rs b/third_party/move/testing-infra/test-generation/src/lib.rs index bd86243740f57..b909aba8b4c33 100644 --- a/third_party/move/testing-infra/test-generation/src/lib.rs +++ b/third_party/move/testing-infra/test-generation/src/lib.rs @@ -25,7 +25,11 @@ use move_binary_format::{ }, }; use move_bytecode_verifier::verify_module; -use move_compiler::{compiled_unit::AnnotatedCompiledUnit, Compiler}; +use move_compiler::{ + compiled_unit::AnnotatedCompiledUnit, + shared::{known_attributes::KnownAttribute, Flags}, + Compiler, +}; use move_core_types::{ account_address::AccountAddress, effects::{ChangeSet, Op}, @@ -59,6 +63,8 @@ static STORAGE_WITH_MOVE_STDLIB: Lazy = Lazy::new(|| { move_stdlib::move_stdlib_files(), vec![], move_stdlib::move_stdlib_named_addresses(), + Flags::empty().set_skip_attribute_checks(true), // Not much point in checking it here. + KnownAttribute::get_all_attribute_names(), ) .build_and_report() .unwrap(); diff --git a/third_party/move/testing-infra/transactional-test-runner/src/framework.rs b/third_party/move/testing-infra/transactional-test-runner/src/framework.rs index 0908032d8b63f..db8017b734ce0 100644 --- a/third_party/move/testing-infra/transactional-test-runner/src/framework.rs +++ b/third_party/move/testing-infra/transactional-test-runner/src/framework.rs @@ -125,6 +125,7 @@ pub trait MoveTestAdapter<'a>: Sized { fn compiled_state(&mut self) -> &mut CompiledState<'a>; fn default_syntax(&self) -> SyntaxChoice; + fn known_attributes(&self) -> &BTreeSet; fn run_config(&self) -> TestRunConfig { TestRunConfig::CompilerV1 } @@ -265,6 +266,7 @@ pub trait MoveTestAdapter<'a>: Sized { state.named_address_mapping.clone(), &state.source_files().cloned().collect::>(), data_path.to_owned(), + self.known_attributes(), )?; let (named_addr_opt, module) = match unit { AnnotatedCompiledUnit::Module(annot_module) => { @@ -363,6 +365,7 @@ pub trait MoveTestAdapter<'a>: Sized { state.named_address_mapping.clone(), &state.source_files().cloned().collect::>(), data_path.to_owned(), + self.known_attributes(), )?; match unit { AnnotatedCompiledUnit::Script(annot_script) => (annot_script.named_script.script, warning_opt), @@ -702,6 +705,7 @@ fn compile_source_unit( named_address_mapping: BTreeMap, deps: &[String], path: String, + known_attributes: &BTreeSet, ) -> Result<(AnnotatedCompiledUnit, Option)> { fn rendered_diags(files: &FilesSourceText, diags: Diagnostics) -> Option { if diags.is_empty() { @@ -717,11 +721,17 @@ fn compile_source_unit( } use move_compiler::PASS_COMPILATION; - let (mut files, comments_and_compiler_res) = - move_compiler::Compiler::from_files(vec![path], deps.to_vec(), named_address_mapping) - .set_pre_compiled_lib_opt(pre_compiled_deps) - .set_flags(move_compiler::Flags::empty().set_sources_shadow_deps(true)) - .run::()?; + let (mut files, comments_and_compiler_res) = move_compiler::Compiler::from_files( + vec![path], + deps.to_vec(), + named_address_mapping, + move_compiler::Flags::empty() + .set_sources_shadow_deps(true) + .set_skip_attribute_checks(false), // In case of bugs in transactional test code. + known_attributes, + ) + .set_pre_compiled_lib_opt(pre_compiled_deps) + .run::()?; let units_or_diags = comments_and_compiler_res .map(|(_comments, move_compiler)| move_compiler.into_compiled_units()); diff --git a/third_party/move/testing-infra/transactional-test-runner/src/vm_test_harness.rs b/third_party/move/testing-infra/transactional-test-runner/src/vm_test_harness.rs index b5ccf25c69b47..6532e8aed5d1e 100644 --- a/third_party/move/testing-infra/transactional-test-runner/src/vm_test_harness.rs +++ b/third_party/move/testing-infra/transactional-test-runner/src/vm_test_harness.rs @@ -18,7 +18,9 @@ use move_command_line_common::{ address::ParsedAddress, files::verify_and_create_named_address_mapping, }; use move_compiler::{ - compiled_unit::AnnotatedCompiledUnit, shared::PackagePaths, FullyCompiledProgram, + compiled_unit::AnnotatedCompiledUnit, + shared::{known_attributes::KnownAttribute, Flags, PackagePaths}, + FullyCompiledProgram, }; use move_core_types::{ account_address::AccountAddress, @@ -37,7 +39,10 @@ use move_vm_runtime::{ }; use move_vm_test_utils::{gas_schedule::GasStatus, InMemoryStorage}; use once_cell::sync::Lazy; -use std::{collections::BTreeMap, path::Path}; +use std::{ + collections::{BTreeMap, BTreeSet}, + path::Path, +}; const STD_ADDR: AccountAddress = AccountAddress::ONE; @@ -106,6 +111,10 @@ impl<'a> MoveTestAdapter<'a> for SimpleVMTestAdapter<'a> { self.default_syntax } + fn known_attributes(&self) -> &BTreeSet { + KnownAttribute::get_all_attribute_names() + } + fn run_config(&self) -> TestRunConfig { self.run_config } @@ -399,7 +408,8 @@ static PRECOMPILED_MOVE_STDLIB: Lazy = Lazy::new(|| { named_address_map: move_stdlib::move_stdlib_named_addresses(), }], None, - move_compiler::Flags::empty(), + Flags::empty().set_skip_attribute_checks(true), // no point in checking. + KnownAttribute::get_all_attribute_names(), ) .unwrap(); match program_res { @@ -416,6 +426,8 @@ static MOVE_STDLIB_COMPILED: Lazy> = Lazy::new(|| { move_stdlib::move_stdlib_files(), vec![], move_stdlib::move_stdlib_named_addresses(), + Flags::empty().set_skip_attribute_checks(true), // no point in checking here. + KnownAttribute::get_all_attribute_names(), ) .build() .unwrap(); diff --git a/third_party/move/tools/move-cli/tests/build_tests/dependency_chain/args.exp b/third_party/move/tools/move-cli/tests/build_tests/dependency_chain/args.exp index ea1be9b5e0cee..46931d7174c7c 100644 --- a/third_party/move/tools/move-cli/tests/build_tests/dependency_chain/args.exp +++ b/third_party/move/tools/move-cli/tests/build_tests/dependency_chain/args.exp @@ -2,3 +2,9 @@ Command `build -v`: INCLUDING DEPENDENCY Bar INCLUDING DEPENDENCY Foo BUILDING A +warning[W02016]: unknown attribute + ┌─ ./sources/A.move:1:3 + │ +1 │ #[evm_contract] // for passing evm test flavor + │ ^^^^^^^^^^^^ Attribute name 'evm_contract' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + diff --git a/third_party/move/tools/move-cli/tests/build_tests/dev_address/args.exp b/third_party/move/tools/move-cli/tests/build_tests/dev_address/args.exp index fa89fc39cc0e8..6d43848bd756e 100644 --- a/third_party/move/tools/move-cli/tests/build_tests/dev_address/args.exp +++ b/third_party/move/tools/move-cli/tests/build_tests/dev_address/args.exp @@ -1,2 +1,8 @@ Command `build -v -d`: BUILDING A +warning[W02016]: unknown attribute + ┌─ ./sources/A.move:1:3 + │ +1 │ #[evm_contract] // for passing evm test flavor + │ ^^^^^^^^^^^^ Attribute name 'evm_contract' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + diff --git a/third_party/move/tools/move-cli/tests/build_tests/empty_module_no_deps/args.exp b/third_party/move/tools/move-cli/tests/build_tests/empty_module_no_deps/args.exp index dffc3c3b344de..981f783b21258 100644 --- a/third_party/move/tools/move-cli/tests/build_tests/empty_module_no_deps/args.exp +++ b/third_party/move/tools/move-cli/tests/build_tests/empty_module_no_deps/args.exp @@ -1,2 +1,8 @@ Command `build -v`: BUILDING A +warning[W02016]: unknown attribute + ┌─ ./sources/A.move:1:3 + │ +1 │ #[evm_contract] // for passing evm test flavor + │ ^^^^^^^^^^^^ Attribute name 'evm_contract' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + diff --git a/third_party/move/tools/move-cli/tests/build_tests/include_exclude_stdlib/args.exp b/third_party/move/tools/move-cli/tests/build_tests/include_exclude_stdlib/args.exp index ce37b1cf91b5a..1d60e31b47be4 100644 --- a/third_party/move/tools/move-cli/tests/build_tests/include_exclude_stdlib/args.exp +++ b/third_party/move/tools/move-cli/tests/build_tests/include_exclude_stdlib/args.exp @@ -1,5 +1,11 @@ Command `build -v`: BUILDING build_include_exclude_stdlib +warning[W02016]: unknown attribute + ┌─ ./sources/UseSigner.move:1:3 + │ +1 │ #[evm_contract] // for passing evm test flavor + │ ^^^^^^^^^^^^ Attribute name 'evm_contract' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + error[E03002]: unbound module ┌─ ./sources/UseSigner.move:3:7 │ @@ -15,3 +21,9 @@ error[E03002]: unbound module Command `-d -v build`: INCLUDING DEPENDENCY MoveStdlib BUILDING build_include_exclude_stdlib +warning[W02016]: unknown attribute + ┌─ ./sources/UseSigner.move:1:3 + │ +1 │ #[evm_contract] // for passing evm test flavor + │ ^^^^^^^^^^^^ Attribute name 'evm_contract' is unknown (use --skip-attribute-checks CLI option to ignore); known attributes are '{"bytecode_instruction", "deprecated", "expected_failure", "native_interface", "test", "test_only", "verify_only"}'. + diff --git a/third_party/move/tools/move-cli/tests/build_tests/unbound_address/args.exp b/third_party/move/tools/move-cli/tests/build_tests/unbound_address/args.exp index 47bf3e9d49617..46fb821f74f26 100644 --- a/third_party/move/tools/move-cli/tests/build_tests/unbound_address/args.exp +++ b/third_party/move/tools/move-cli/tests/build_tests/unbound_address/args.exp @@ -4,5 +4,5 @@ Named address 'A' in package 'A' ] To fix this, add an entry for each unresolved address to the [addresses] section of ./Move.toml: e.g., [addresses] -Std = "0x1" +std = "0x1" Alternatively, you can also define [dev-addresses] and call with the --dev flag diff --git a/third_party/move/tools/move-cli/tests/cross_process_tests/Package1/Move.toml b/third_party/move/tools/move-cli/tests/cross_process_tests/Package1/Move.toml index adb1224f7217a..6915223ce1792 100644 --- a/third_party/move/tools/move-cli/tests/cross_process_tests/Package1/Move.toml +++ b/third_party/move/tools/move-cli/tests/cross_process_tests/Package1/Move.toml @@ -3,7 +3,7 @@ name = "Package1" version = "0.0.0" [addresses] -Std = "0x1" +std = "0x1" [dependencies] -MoveStdlib = { git = "https://github.com/diem/move.git", subdir = "language/move-stdlib", rev = "98ed299" } +MoveStdlib = { local = "../../../../move-stdlib" } diff --git a/third_party/move/tools/move-cli/tests/cross_process_tests/Package2/Move.toml b/third_party/move/tools/move-cli/tests/cross_process_tests/Package2/Move.toml index 779b56687d865..64468724325e7 100644 --- a/third_party/move/tools/move-cli/tests/cross_process_tests/Package2/Move.toml +++ b/third_party/move/tools/move-cli/tests/cross_process_tests/Package2/Move.toml @@ -3,7 +3,7 @@ name = "Package2" version = "0.0.0" [addresses] -Std = "0x1" +std = "0x1" [dependencies] -MoveStdlib = { git = "https://github.com/diem/move.git", subdir = "language/move-stdlib", rev = "98ed299" } +MoveStdlib = { local = "../../../../move-stdlib" } diff --git a/third_party/move/tools/move-cli/tests/upload_tests/no_git_remote_package/Move.toml b/third_party/move/tools/move-cli/tests/upload_tests/no_git_remote_package/Move.toml index 637d99d854110..1591df0a97dcf 100644 --- a/third_party/move/tools/move-cli/tests/upload_tests/no_git_remote_package/Move.toml +++ b/third_party/move/tools/move-cli/tests/upload_tests/no_git_remote_package/Move.toml @@ -3,4 +3,4 @@ name = "Package1" version = "0.0.0" [addresses] -Std = "0x1" +std = "0x1" diff --git a/third_party/move/tools/move-cli/tests/upload_tests/valid_package1/Move.toml b/third_party/move/tools/move-cli/tests/upload_tests/valid_package1/Move.toml index 637d99d854110..1591df0a97dcf 100644 --- a/third_party/move/tools/move-cli/tests/upload_tests/valid_package1/Move.toml +++ b/third_party/move/tools/move-cli/tests/upload_tests/valid_package1/Move.toml @@ -3,4 +3,4 @@ name = "Package1" version = "0.0.0" [addresses] -Std = "0x1" +std = "0x1" diff --git a/third_party/move/tools/move-cli/tests/upload_tests/valid_package2/Move.toml b/third_party/move/tools/move-cli/tests/upload_tests/valid_package2/Move.toml index 637d99d854110..1591df0a97dcf 100644 --- a/third_party/move/tools/move-cli/tests/upload_tests/valid_package2/Move.toml +++ b/third_party/move/tools/move-cli/tests/upload_tests/valid_package2/Move.toml @@ -3,4 +3,4 @@ name = "Package1" version = "0.0.0" [addresses] -Std = "0x1" +std = "0x1" diff --git a/third_party/move/tools/move-cli/tests/upload_tests/valid_package3/Move.toml b/third_party/move/tools/move-cli/tests/upload_tests/valid_package3/Move.toml index 637d99d854110..1591df0a97dcf 100644 --- a/third_party/move/tools/move-cli/tests/upload_tests/valid_package3/Move.toml +++ b/third_party/move/tools/move-cli/tests/upload_tests/valid_package3/Move.toml @@ -3,4 +3,4 @@ name = "Package1" version = "0.0.0" [addresses] -Std = "0x1" +std = "0x1" diff --git a/third_party/move/tools/move-package/src/compilation/compiled_package.rs b/third_party/move/tools/move-package/src/compilation/compiled_package.rs index f36e348732551..dae2e44e43f95 100644 --- a/third_party/move/tools/move-package/src/compilation/compiled_package.rs +++ b/third_party/move/tools/move-package/src/compilation/compiled_package.rs @@ -9,7 +9,7 @@ use crate::{ layout::{SourcePackageLayout, REFERENCE_TEMPLATE_FILENAME}, parsed_manifest::{FileName, PackageDigest, PackageName}, }, - BuildConfig, + Architecture, BuildConfig, }; use anyhow::{ensure, Result}; use colored::Colorize; @@ -26,6 +26,7 @@ use move_command_line_common::{ }, }; use move_compiler::{ + attr_derivation, compiled_unit::{ self, AnnotatedCompiledUnit, CompiledUnit, NamedCompiledModule, NamedCompiledScript, }, @@ -575,11 +576,30 @@ impl CompiledPackage { &resolved_package, transitive_dependencies, )?; - let flags = if resolution_graph.build_options.test_mode { + let mut flags = if resolution_graph.build_options.test_mode { Flags::testing() } else { Flags::empty() }; + let skip_attribute_checks = resolution_graph.build_options.skip_attribute_checks; + flags = flags.set_skip_attribute_checks(skip_attribute_checks); + let mut known_attributes = resolution_graph.build_options.known_attributes.clone(); + match &resolution_graph.build_options.architecture { + Some(x) => { + match x { + Architecture::Move => (), + Architecture::AsyncMove => { + flags = flags.set_flavor("async"); + }, + Architecture::Ethereum => { + flags = flags.set_flavor("evm"); + }, + }; + }, + None => (), + }; + attr_derivation::add_attributes_for_flavor(&flags, &mut known_attributes); + // Partition deps_package according whether src is available let (src_deps, bytecode_deps): (Vec<_>, Vec<_>) = deps_package_paths .clone() @@ -600,7 +620,7 @@ impl CompiledPackage { let mut paths = src_deps; paths.push(sources_package_paths.clone()); - let compiler = Compiler::from_package_paths(paths, bytecode_deps).set_flags(flags); + let compiler = Compiler::from_package_paths(paths, bytecode_deps, flags, &known_attributes); let (file_map, all_compiled_units) = compiler_driver(compiler)?; let mut root_compiled_units = vec![]; let mut deps_compiled_units = vec![]; @@ -631,6 +651,8 @@ impl CompiledPackage { vec![sources_package_paths], deps_package_paths.into_iter().map(|(p, _)| p).collect_vec(), ModelBuilderOptions::default(), + skip_attribute_checks, + &known_attributes, )?; if resolution_graph.build_options.generate_docs { diff --git a/third_party/move/tools/move-package/src/compilation/model_builder.rs b/third_party/move/tools/move-package/src/compilation/model_builder.rs index 0710ed955c500..6708bfc80a67a 100644 --- a/third_party/move/tools/move-package/src/compilation/model_builder.rs +++ b/third_party/move/tools/move-package/src/compilation/model_builder.rs @@ -115,6 +115,14 @@ impl ModelBuilder { ), }; - run_model_builder_with_options(all_targets, all_deps, ModelBuilderOptions::default()) + let skip_attribute_checks = self.resolution_graph.build_options.skip_attribute_checks; + let known_attributes = &self.resolution_graph.build_options.known_attributes; + run_model_builder_with_options( + all_targets, + all_deps, + ModelBuilderOptions::default(), + skip_attribute_checks, + known_attributes, + ) } } diff --git a/third_party/move/tools/move-package/src/lib.rs b/third_party/move/tools/move-package/src/lib.rs index 050cdc4828f7d..af47bd762f548 100644 --- a/third_party/move/tools/move-package/src/lib.rs +++ b/third_party/move/tools/move-package/src/lib.rs @@ -19,12 +19,15 @@ use crate::{ }; use anyhow::{bail, Result}; use clap::*; +use move_compiler::{ + command_line::SKIP_ATTRIBUTE_CHECKS, shared::known_attributes::KnownAttribute, +}; use move_core_types::account_address::AccountAddress; use move_model::model::GlobalEnv; use serde::{Deserialize, Serialize}; use source_package::layout::SourcePackageLayout; use std::{ - collections::BTreeMap, + collections::{BTreeMap, BTreeSet}, fmt, io::Write, path::{Path, PathBuf}, @@ -137,6 +140,14 @@ pub struct BuildConfig { /// Bytecode version to compile move code #[clap(long = "bytecode-version", global = true)] pub bytecode_version: Option, + + // Known attribute names. Depends on compilation context (Move variant) + #[clap(skip = KnownAttribute::get_all_attribute_names().clone())] + pub known_attributes: BTreeSet, + + /// Do not complain about an unknown attribute in Move code. + #[clap(long = SKIP_ATTRIBUTE_CHECKS, default_value = "false")] + pub skip_attribute_checks: bool, } #[derive(Debug, Clone, Eq, PartialEq, PartialOrd)] diff --git a/third_party/move/tools/move-package/src/resolution/resolution_graph.rs b/third_party/move/tools/move-package/src/resolution/resolution_graph.rs index 4415f93fb6513..9c3928f3dbcd6 100644 --- a/third_party/move/tools/move-package/src/resolution/resolution_graph.rs +++ b/third_party/move/tools/move-package/src/resolution/resolution_graph.rs @@ -179,7 +179,7 @@ impl ResolvingGraph { bail!( "Unresolved addresses found: [\n{}\n]\n\ To fix this, add an entry for each unresolved address to the [addresses] section of {}/Move.toml: \ - e.g.,\n[addresses]\nStd = \"0x1\"\n\ + e.g.,\n[addresses]\nstd = \"0x1\"\n\ Alternatively, you can also define [dev-addresses] and call with the --dev flag", unresolved_addresses.join("\n"), root_package_path.to_string_lossy() diff --git a/third_party/move/tools/move-package/tests/test_sources/compilation/basic_no_deps/Move.exp b/third_party/move/tools/move-package/tests/test_sources/compilation/basic_no_deps/Move.exp index cb5253d17487a..a562ec60f64d4 100644 --- a/third_party/move/tools/move-package/tests/test_sources/compilation/basic_no_deps/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/compilation/basic_no_deps/Move.exp @@ -18,5 +18,7 @@ CompiledPackageInfo { fetch_deps_only: false, skip_fetch_latest_git_deps: false, bytecode_version: None, + known_attributes: {}, + skip_attribute_checks: false, }, } diff --git a/third_party/move/tools/move-package/tests/test_sources/compilation/basic_no_deps_address_assigned/Move.exp b/third_party/move/tools/move-package/tests/test_sources/compilation/basic_no_deps_address_assigned/Move.exp index 6ee4f9b85807e..785be46e0eaad 100644 --- a/third_party/move/tools/move-package/tests/test_sources/compilation/basic_no_deps_address_assigned/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/compilation/basic_no_deps_address_assigned/Move.exp @@ -20,5 +20,7 @@ CompiledPackageInfo { fetch_deps_only: false, skip_fetch_latest_git_deps: false, bytecode_version: None, + known_attributes: {}, + skip_attribute_checks: false, }, } diff --git a/third_party/move/tools/move-package/tests/test_sources/compilation/basic_no_deps_address_not_assigned_with_dev_assignment/Move.exp b/third_party/move/tools/move-package/tests/test_sources/compilation/basic_no_deps_address_not_assigned_with_dev_assignment/Move.exp index 7a2e6343a15eb..44424a468b45e 100644 --- a/third_party/move/tools/move-package/tests/test_sources/compilation/basic_no_deps_address_not_assigned_with_dev_assignment/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/compilation/basic_no_deps_address_not_assigned_with_dev_assignment/Move.exp @@ -20,5 +20,7 @@ CompiledPackageInfo { fetch_deps_only: false, skip_fetch_latest_git_deps: false, bytecode_version: None, + known_attributes: {}, + skip_attribute_checks: false, }, } diff --git a/third_party/move/tools/move-package/tests/test_sources/compilation/basic_no_deps_test_mode/Move.exp b/third_party/move/tools/move-package/tests/test_sources/compilation/basic_no_deps_test_mode/Move.exp index 0f8b1e0a0d4a6..d679d645623a1 100644 --- a/third_party/move/tools/move-package/tests/test_sources/compilation/basic_no_deps_test_mode/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/compilation/basic_no_deps_test_mode/Move.exp @@ -20,5 +20,7 @@ CompiledPackageInfo { fetch_deps_only: false, skip_fetch_latest_git_deps: false, bytecode_version: None, + known_attributes: {}, + skip_attribute_checks: false, }, } diff --git a/third_party/move/tools/move-package/tests/test_sources/compilation/diamond_problem_backflow_resolution/Move.exp b/third_party/move/tools/move-package/tests/test_sources/compilation/diamond_problem_backflow_resolution/Move.exp index fe3846c31a1fa..e45c1031f3d49 100644 --- a/third_party/move/tools/move-package/tests/test_sources/compilation/diamond_problem_backflow_resolution/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/compilation/diamond_problem_backflow_resolution/Move.exp @@ -21,5 +21,7 @@ CompiledPackageInfo { fetch_deps_only: false, skip_fetch_latest_git_deps: false, bytecode_version: None, + known_attributes: {}, + skip_attribute_checks: false, }, } diff --git a/third_party/move/tools/move-package/tests/test_sources/compilation/diamond_problem_no_conflict/Move.exp b/third_party/move/tools/move-package/tests/test_sources/compilation/diamond_problem_no_conflict/Move.exp index fe3846c31a1fa..e45c1031f3d49 100644 --- a/third_party/move/tools/move-package/tests/test_sources/compilation/diamond_problem_no_conflict/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/compilation/diamond_problem_no_conflict/Move.exp @@ -21,5 +21,7 @@ CompiledPackageInfo { fetch_deps_only: false, skip_fetch_latest_git_deps: false, bytecode_version: None, + known_attributes: {}, + skip_attribute_checks: false, }, } diff --git a/third_party/move/tools/move-package/tests/test_sources/compilation/multiple_deps_rename/Move.exp b/third_party/move/tools/move-package/tests/test_sources/compilation/multiple_deps_rename/Move.exp index da8ed9338db00..e18b4560e1d2e 100644 --- a/third_party/move/tools/move-package/tests/test_sources/compilation/multiple_deps_rename/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/compilation/multiple_deps_rename/Move.exp @@ -22,5 +22,7 @@ CompiledPackageInfo { fetch_deps_only: false, skip_fetch_latest_git_deps: false, bytecode_version: None, + known_attributes: {}, + skip_attribute_checks: false, }, } diff --git a/third_party/move/tools/move-package/tests/test_sources/compilation/multiple_deps_rename_one/Move.exp b/third_party/move/tools/move-package/tests/test_sources/compilation/multiple_deps_rename_one/Move.exp index bb13331e51006..2eee90247064c 100644 --- a/third_party/move/tools/move-package/tests/test_sources/compilation/multiple_deps_rename_one/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/compilation/multiple_deps_rename_one/Move.exp @@ -22,5 +22,7 @@ CompiledPackageInfo { fetch_deps_only: false, skip_fetch_latest_git_deps: false, bytecode_version: None, + known_attributes: {}, + skip_attribute_checks: false, }, } diff --git a/third_party/move/tools/move-package/tests/test_sources/compilation/one_dep/Move.exp b/third_party/move/tools/move-package/tests/test_sources/compilation/one_dep/Move.exp index 04d6d3c40e95a..eb858ed34d65f 100644 --- a/third_party/move/tools/move-package/tests/test_sources/compilation/one_dep/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/compilation/one_dep/Move.exp @@ -20,5 +20,7 @@ CompiledPackageInfo { fetch_deps_only: false, skip_fetch_latest_git_deps: false, bytecode_version: None, + known_attributes: {}, + skip_attribute_checks: false, }, } diff --git a/third_party/move/tools/move-package/tests/test_sources/compilation/one_dep_assigned_address/Move.exp b/third_party/move/tools/move-package/tests/test_sources/compilation/one_dep_assigned_address/Move.exp index 5da411f35697c..5ff2f16628f81 100644 --- a/third_party/move/tools/move-package/tests/test_sources/compilation/one_dep_assigned_address/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/compilation/one_dep_assigned_address/Move.exp @@ -20,5 +20,7 @@ CompiledPackageInfo { fetch_deps_only: false, skip_fetch_latest_git_deps: false, bytecode_version: None, + known_attributes: {}, + skip_attribute_checks: false, }, } diff --git a/third_party/move/tools/move-package/tests/test_sources/compilation/one_dep_renamed/Move.exp b/third_party/move/tools/move-package/tests/test_sources/compilation/one_dep_renamed/Move.exp index 04d6d3c40e95a..eb858ed34d65f 100644 --- a/third_party/move/tools/move-package/tests/test_sources/compilation/one_dep_renamed/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/compilation/one_dep_renamed/Move.exp @@ -20,5 +20,7 @@ CompiledPackageInfo { fetch_deps_only: false, skip_fetch_latest_git_deps: false, bytecode_version: None, + known_attributes: {}, + skip_attribute_checks: false, }, } diff --git a/third_party/move/tools/move-package/tests/test_sources/compilation/one_dep_with_scripts/Move.exp b/third_party/move/tools/move-package/tests/test_sources/compilation/one_dep_with_scripts/Move.exp index 04d6d3c40e95a..eb858ed34d65f 100644 --- a/third_party/move/tools/move-package/tests/test_sources/compilation/one_dep_with_scripts/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/compilation/one_dep_with_scripts/Move.exp @@ -20,5 +20,7 @@ CompiledPackageInfo { fetch_deps_only: false, skip_fetch_latest_git_deps: false, bytecode_version: None, + known_attributes: {}, + skip_attribute_checks: false, }, } diff --git a/third_party/move/tools/move-package/tests/test_sources/compilation/test_symlinks/Move.exp b/third_party/move/tools/move-package/tests/test_sources/compilation/test_symlinks/Move.exp index 6ee4f9b85807e..785be46e0eaad 100644 --- a/third_party/move/tools/move-package/tests/test_sources/compilation/test_symlinks/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/compilation/test_symlinks/Move.exp @@ -20,5 +20,7 @@ CompiledPackageInfo { fetch_deps_only: false, skip_fetch_latest_git_deps: false, bytecode_version: None, + known_attributes: {}, + skip_attribute_checks: false, }, } diff --git a/third_party/move/tools/move-package/tests/test_sources/parsing/invalid_identifier_package_name/Move.exp b/third_party/move/tools/move-package/tests/test_sources/parsing/invalid_identifier_package_name/Move.exp index 21da7cb042776..891d51523e355 100644 --- a/third_party/move/tools/move-package/tests/test_sources/parsing/invalid_identifier_package_name/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/parsing/invalid_identifier_package_name/Move.exp @@ -14,6 +14,8 @@ ResolutionGraph { fetch_deps_only: false, skip_fetch_latest_git_deps: false, bytecode_version: None, + known_attributes: {}, + skip_attribute_checks: false, }, root_package: SourceManifest { package: PackageInfo { diff --git a/third_party/move/tools/move-package/tests/test_sources/parsing/minimal_manifest/Move.exp b/third_party/move/tools/move-package/tests/test_sources/parsing/minimal_manifest/Move.exp index 902cee9609a12..d66c3ca089c6d 100644 --- a/third_party/move/tools/move-package/tests/test_sources/parsing/minimal_manifest/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/parsing/minimal_manifest/Move.exp @@ -14,6 +14,8 @@ ResolutionGraph { fetch_deps_only: false, skip_fetch_latest_git_deps: false, bytecode_version: None, + known_attributes: {}, + skip_attribute_checks: false, }, root_package: SourceManifest { package: PackageInfo { diff --git a/third_party/move/tools/move-package/tests/test_sources/resolution/basic_no_deps/Move.exp b/third_party/move/tools/move-package/tests/test_sources/resolution/basic_no_deps/Move.exp index 79e181224f8ba..7868882c69450 100644 --- a/third_party/move/tools/move-package/tests/test_sources/resolution/basic_no_deps/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/resolution/basic_no_deps/Move.exp @@ -14,6 +14,8 @@ ResolutionGraph { fetch_deps_only: false, skip_fetch_latest_git_deps: false, bytecode_version: None, + known_attributes: {}, + skip_attribute_checks: false, }, root_package: SourceManifest { package: PackageInfo { diff --git a/third_party/move/tools/move-package/tests/test_sources/resolution/basic_no_deps_address_assigned/Move.exp b/third_party/move/tools/move-package/tests/test_sources/resolution/basic_no_deps_address_assigned/Move.exp index 2ab48f290b8c5..af971a5488ef9 100644 --- a/third_party/move/tools/move-package/tests/test_sources/resolution/basic_no_deps_address_assigned/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/resolution/basic_no_deps_address_assigned/Move.exp @@ -14,6 +14,8 @@ ResolutionGraph { fetch_deps_only: false, skip_fetch_latest_git_deps: false, bytecode_version: None, + known_attributes: {}, + skip_attribute_checks: false, }, root_package: SourceManifest { package: PackageInfo { diff --git a/third_party/move/tools/move-package/tests/test_sources/resolution/basic_no_deps_address_not_assigned/Move.exp b/third_party/move/tools/move-package/tests/test_sources/resolution/basic_no_deps_address_not_assigned/Move.exp index 067d57d26ce13..286d76ea24d5e 100644 --- a/third_party/move/tools/move-package/tests/test_sources/resolution/basic_no_deps_address_not_assigned/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/resolution/basic_no_deps_address_not_assigned/Move.exp @@ -3,5 +3,5 @@ Named address 'A' in package 'test' ] To fix this, add an entry for each unresolved address to the [addresses] section of tests/test_sources/resolution/basic_no_deps_address_not_assigned/Move.toml: e.g., [addresses] -Std = "0x1" +std = "0x1" Alternatively, you can also define [dev-addresses] and call with the --dev flag diff --git a/third_party/move/tools/move-package/tests/test_sources/resolution/basic_no_deps_address_not_assigned_with_dev_assignment/Move.exp b/third_party/move/tools/move-package/tests/test_sources/resolution/basic_no_deps_address_not_assigned_with_dev_assignment/Move.exp index 93c1ba97cdf97..ade5b69d90846 100644 --- a/third_party/move/tools/move-package/tests/test_sources/resolution/basic_no_deps_address_not_assigned_with_dev_assignment/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/resolution/basic_no_deps_address_not_assigned_with_dev_assignment/Move.exp @@ -14,6 +14,8 @@ ResolutionGraph { fetch_deps_only: false, skip_fetch_latest_git_deps: false, bytecode_version: None, + known_attributes: {}, + skip_attribute_checks: false, }, root_package: SourceManifest { package: PackageInfo { diff --git a/third_party/move/tools/move-package/tests/test_sources/resolution/dep_good_digest/Move.exp b/third_party/move/tools/move-package/tests/test_sources/resolution/dep_good_digest/Move.exp index 1692ad324087a..3e052a4a24928 100644 --- a/third_party/move/tools/move-package/tests/test_sources/resolution/dep_good_digest/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/resolution/dep_good_digest/Move.exp @@ -14,6 +14,8 @@ ResolutionGraph { fetch_deps_only: false, skip_fetch_latest_git_deps: false, bytecode_version: None, + known_attributes: {}, + skip_attribute_checks: false, }, root_package: SourceManifest { package: PackageInfo { diff --git a/third_party/move/tools/move-package/tests/test_sources/resolution/diamond_problem_backflow_resolution/Move.exp b/third_party/move/tools/move-package/tests/test_sources/resolution/diamond_problem_backflow_resolution/Move.exp index cf5e6e183c4b7..ea59fd6ea9361 100644 --- a/third_party/move/tools/move-package/tests/test_sources/resolution/diamond_problem_backflow_resolution/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/resolution/diamond_problem_backflow_resolution/Move.exp @@ -14,6 +14,8 @@ ResolutionGraph { fetch_deps_only: false, skip_fetch_latest_git_deps: false, bytecode_version: None, + known_attributes: {}, + skip_attribute_checks: false, }, root_package: SourceManifest { package: PackageInfo { diff --git a/third_party/move/tools/move-package/tests/test_sources/resolution/diamond_problem_no_conflict/Move.exp b/third_party/move/tools/move-package/tests/test_sources/resolution/diamond_problem_no_conflict/Move.exp index a55b459854f19..9ef82bdfb100b 100644 --- a/third_party/move/tools/move-package/tests/test_sources/resolution/diamond_problem_no_conflict/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/resolution/diamond_problem_no_conflict/Move.exp @@ -14,6 +14,8 @@ ResolutionGraph { fetch_deps_only: false, skip_fetch_latest_git_deps: false, bytecode_version: None, + known_attributes: {}, + skip_attribute_checks: false, }, root_package: SourceManifest { package: PackageInfo { diff --git a/third_party/move/tools/move-package/tests/test_sources/resolution/multiple_deps_rename/Move.exp b/third_party/move/tools/move-package/tests/test_sources/resolution/multiple_deps_rename/Move.exp index 3e792236e464f..9ec3d07405ed9 100644 --- a/third_party/move/tools/move-package/tests/test_sources/resolution/multiple_deps_rename/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/resolution/multiple_deps_rename/Move.exp @@ -14,6 +14,8 @@ ResolutionGraph { fetch_deps_only: false, skip_fetch_latest_git_deps: false, bytecode_version: None, + known_attributes: {}, + skip_attribute_checks: false, }, root_package: SourceManifest { package: PackageInfo { diff --git a/third_party/move/tools/move-package/tests/test_sources/resolution/one_dep/Move.exp b/third_party/move/tools/move-package/tests/test_sources/resolution/one_dep/Move.exp index 78e15d8a03c81..c283da45cf4c3 100644 --- a/third_party/move/tools/move-package/tests/test_sources/resolution/one_dep/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/resolution/one_dep/Move.exp @@ -14,6 +14,8 @@ ResolutionGraph { fetch_deps_only: false, skip_fetch_latest_git_deps: false, bytecode_version: None, + known_attributes: {}, + skip_attribute_checks: false, }, root_package: SourceManifest { package: PackageInfo { diff --git a/third_party/move/tools/move-package/tests/test_sources/resolution/one_dep_assigned_address/Move.exp b/third_party/move/tools/move-package/tests/test_sources/resolution/one_dep_assigned_address/Move.exp index e1d4eaab354a6..478aaa186c352 100644 --- a/third_party/move/tools/move-package/tests/test_sources/resolution/one_dep_assigned_address/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/resolution/one_dep_assigned_address/Move.exp @@ -14,6 +14,8 @@ ResolutionGraph { fetch_deps_only: false, skip_fetch_latest_git_deps: false, bytecode_version: None, + known_attributes: {}, + skip_attribute_checks: false, }, root_package: SourceManifest { package: PackageInfo { diff --git a/third_party/move/tools/move-package/tests/test_sources/resolution/one_dep_multiple_of_same_name/Move.exp b/third_party/move/tools/move-package/tests/test_sources/resolution/one_dep_multiple_of_same_name/Move.exp index 0540c070119c5..83b6075587743 100644 --- a/third_party/move/tools/move-package/tests/test_sources/resolution/one_dep_multiple_of_same_name/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/resolution/one_dep_multiple_of_same_name/Move.exp @@ -14,6 +14,8 @@ ResolutionGraph { fetch_deps_only: false, skip_fetch_latest_git_deps: false, bytecode_version: None, + known_attributes: {}, + skip_attribute_checks: false, }, root_package: SourceManifest { package: PackageInfo { diff --git a/third_party/move/tools/move-package/tests/test_sources/resolution/one_dep_reassigned_address/Move.exp b/third_party/move/tools/move-package/tests/test_sources/resolution/one_dep_reassigned_address/Move.exp index a590010df9ff4..02416ca1cb776 100644 --- a/third_party/move/tools/move-package/tests/test_sources/resolution/one_dep_reassigned_address/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/resolution/one_dep_reassigned_address/Move.exp @@ -14,6 +14,8 @@ ResolutionGraph { fetch_deps_only: false, skip_fetch_latest_git_deps: false, bytecode_version: None, + known_attributes: {}, + skip_attribute_checks: false, }, root_package: SourceManifest { package: PackageInfo { diff --git a/third_party/move/tools/move-package/tests/test_sources/resolution/one_dep_unification_across_local_renamings/Move.exp b/third_party/move/tools/move-package/tests/test_sources/resolution/one_dep_unification_across_local_renamings/Move.exp index 8dc604a4dc597..9480595537c41 100644 --- a/third_party/move/tools/move-package/tests/test_sources/resolution/one_dep_unification_across_local_renamings/Move.exp +++ b/third_party/move/tools/move-package/tests/test_sources/resolution/one_dep_unification_across_local_renamings/Move.exp @@ -14,6 +14,8 @@ ResolutionGraph { fetch_deps_only: false, skip_fetch_latest_git_deps: false, bytecode_version: None, + known_attributes: {}, + skip_attribute_checks: false, }, root_package: SourceManifest { package: PackageInfo { diff --git a/third_party/move/tools/move-package/tests/thread_safety_package_test_sources/Package1/Move.toml b/third_party/move/tools/move-package/tests/thread_safety_package_test_sources/Package1/Move.toml index adb1224f7217a..3fa9d44a66093 100644 --- a/third_party/move/tools/move-package/tests/thread_safety_package_test_sources/Package1/Move.toml +++ b/third_party/move/tools/move-package/tests/thread_safety_package_test_sources/Package1/Move.toml @@ -3,7 +3,7 @@ name = "Package1" version = "0.0.0" [addresses] -Std = "0x1" +std = "0x1" [dependencies] -MoveStdlib = { git = "https://github.com/diem/move.git", subdir = "language/move-stdlib", rev = "98ed299" } +MoveStdlib = { local = "../../../../../move-stdlib" } diff --git a/third_party/move/tools/move-package/tests/thread_safety_package_test_sources/Package2/Move.toml b/third_party/move/tools/move-package/tests/thread_safety_package_test_sources/Package2/Move.toml index 779b56687d865..4eb794dd165e6 100644 --- a/third_party/move/tools/move-package/tests/thread_safety_package_test_sources/Package2/Move.toml +++ b/third_party/move/tools/move-package/tests/thread_safety_package_test_sources/Package2/Move.toml @@ -3,7 +3,7 @@ name = "Package2" version = "0.0.0" [addresses] -Std = "0x1" +std = "0x1" [dependencies] -MoveStdlib = { git = "https://github.com/diem/move.git", subdir = "language/move-stdlib", rev = "98ed299" } +MoveStdlib = { local = "../../../../../move-stdlib" } diff --git a/third_party/move/tools/move-unit-test/src/lib.rs b/third_party/move/tools/move-unit-test/src/lib.rs index 7e44638122a7f..c0b055106f8d4 100644 --- a/third_party/move/tools/move-unit-test/src/lib.rs +++ b/third_party/move/tools/move-unit-test/src/lib.rs @@ -13,7 +13,7 @@ use move_command_line_common::files::verify_and_create_named_address_mapping; use move_compiler::{ self, diagnostics::{self, codes::Severity}, - shared::{self, NumericalAddress}, + shared::{self, known_attributes::KnownAttribute, NumericalAddress}, unit_test::{self, TestPlan}, Compiler, Flags, PASS_CFGIR, }; @@ -161,11 +161,15 @@ impl UnitTestingConfig { ) -> Option { let addresses = verify_and_create_named_address_mapping(self.named_address_values.clone()).ok()?; - let (files, comments_and_compiler_res) = - Compiler::from_files(source_files, deps, addresses) - .set_flags(Flags::testing()) - .run::() - .unwrap(); + let (files, comments_and_compiler_res) = Compiler::from_files( + source_files, + deps, + addresses, + Flags::testing().set_skip_attribute_checks(false), + KnownAttribute::get_all_attribute_names(), + ) + .run::() + .unwrap(); let (_, compiler) = diagnostics::unwrap_or_report_diagnostics(&files, comments_and_compiler_res);