From d47e8592aadc046bb04315230c618fa5f06a9f23 Mon Sep 17 00:00:00 2001 From: "Brian R. Murphy" <132495859+brmataptos@users.noreply.github.com> Date: Thu, 21 Sep 2023 11:16:26 -0700 Subject: [PATCH] Fix issue 9410 by removing special-case hack to suppress unknown attribute warnings on aptos_stdlib --- .../move-compiler/src/expansion/translate.rs | 45 +++---------------- .../parser/aptos_stdlib_attributes.exp | 24 ++++++++++ .../parser/aptos_stdlib_attributes2.exp | 6 +++ 3 files changed, 36 insertions(+), 39 deletions(-) create mode 100644 third_party/move/move-compiler/tests/move_check/parser/aptos_stdlib_attributes2.exp diff --git a/third_party/move/move-compiler/src/expansion/translate.rs b/third_party/move/move-compiler/src/expansion/translate.rs index 971a0791fe8d1d..46d0a816744e2f 100644 --- a/third_party/move/move-compiler/src/expansion/translate.rs +++ b/third_party/move/move-compiler/src/expansion/translate.rs @@ -27,7 +27,6 @@ use crate::{ 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, @@ -48,7 +47,6 @@ 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( @@ -63,7 +61,6 @@ 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(), } } @@ -395,32 +392,6 @@ 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, @@ -435,7 +406,6 @@ 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()); @@ -634,16 +604,13 @@ fn unique_attributes( 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))); - } + 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.", 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 index 563f0310aeee41..8670763d938199 100644 --- 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 @@ -1,3 +1,15 @@ +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/aptos_stdlib_attributes.move:4:7 + │ +4 │ #[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/aptos_stdlib_attributes.move:4:10 + │ +4 │ #[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/aptos_stdlib_attributes.move:4:10 │ @@ -6,6 +18,18 @@ error[E02001]: duplicate declaration, item, or annotation │ │ │ Attribute previously given here +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/aptos_stdlib_attributes.move:7:7 + │ +7 │ #[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/aptos_stdlib_attributes.move:8:7 + │ +8 │ #[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/aptos_stdlib_attributes.move:8:12 │ diff --git a/third_party/move/move-compiler/tests/move_check/parser/aptos_stdlib_attributes2.exp b/third_party/move/move-compiler/tests/move_check/parser/aptos_stdlib_attributes2.exp new file mode 100644 index 00000000000000..9f01ddc163d5c7 --- /dev/null +++ b/third_party/move/move-compiler/tests/move_check/parser/aptos_stdlib_attributes2.exp @@ -0,0 +1,6 @@ +warning[W02016]: unknown attribute + ┌─ tests/move_check/parser/aptos_stdlib_attributes2.move:4:7 + │ +4 │ #[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"}'. +