Skip to content

Commit

Permalink
Fix issue 9410 by removing special-case hack to suppress unknown attr…
Browse files Browse the repository at this point in the history
…ibute warnings on aptos_stdlib
  • Loading branch information
brmataptos committed Sep 21, 2023
1 parent 021f354 commit d47e859
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 39 deletions.
45 changes: 6 additions & 39 deletions third_party/move/move-compiler/src/expansion/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -48,7 +47,6 @@ struct Context<'env, 'map> {
in_spec_context: bool,
exp_specs: BTreeMap<SpecId, E::SpecBlock>,
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(
Expand All @@ -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(),
}
}
Expand Down Expand Up @@ -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<Spanned<Address>>) -> bool {
const APTOS_STDLIB_NAME: &str = "aptos_std";
static APTOS_STDLIB_NUMERICAL_ADDRESS: Lazy<NumericalAddress> =
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<Symbol>,
Expand All @@ -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());
Expand Down Expand Up @@ -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.",
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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"}'.

0 comments on commit d47e859

Please sign in to comment.