From fa4e527816e47f9699cdb269db99f7dc25ed604b Mon Sep 17 00:00:00 2001 From: Vineeth Kashyap Date: Tue, 22 Oct 2024 16:01:40 -0700 Subject: [PATCH] Externalize the linter architecture --- Cargo.lock | 18 +- Cargo.toml | 2 + aptos-move/framework/src/built_package.rs | 200 ++++++++++-------- crates/aptos/Cargo.toml | 1 + crates/aptos/src/move_tool/lint.rs | 7 +- third_party/move/move-compiler-v2/Cargo.toml | 2 - .../src/env_pipeline/model_ast_lints.rs | 112 ++++------ .../move-compiler-v2/src/external_checks.rs | 105 +++++++++ third_party/move/move-compiler-v2/src/lib.rs | 1 + .../move/move-compiler-v2/src/lint_common.rs | 49 ++--- .../move/move-compiler-v2/src/options.rs | 17 +- .../src/pipeline/lint_processor.rs | 89 ++++---- .../model_ast_lints/bad_lint_attribute_02.exp | 7 - .../model_ast_lints/bad_lint_attribute_03.exp | 7 - .../model_ast_lints/bad_lint_attribute_04.exp | 7 - .../model_ast_lints/multi_attributes_02.exp | 2 - .../move/move-compiler-v2/tests/testsuite.rs | 15 -- third_party/move/move-prover/src/lib.rs | 1 + third_party/move/scripts/move_pr.sh | 1 + .../move/tools/move-cli/src/base/test.rs | 1 + third_party/move/tools/move-linter/Cargo.toml | 33 +++ third_party/move/tools/move-linter/src/lib.rs | 28 +++ .../tools/move-linter/src/model_ast_lints.rs | 31 +++ .../model_ast_lints/blocks_in_conditions.rs | 10 +- .../src}/model_ast_lints/needless_bool.rs | 12 +- .../model_ast_lints/needless_deref_ref.rs | 10 +- .../model_ast_lints/needless_ref_deref.rs | 10 +- .../needless_ref_in_field_access.rs | 10 +- .../simpler_numeric_expression.rs | 10 +- ...unnecessary_boolean_identity_comparison.rs | 10 +- ...nnecessary_numerical_extreme_comparison.rs | 10 +- .../src}/model_ast_lints/while_true.rs | 10 +- .../src/stackless_bytecode_lints.rs | 19 ++ .../avoid_copy_on_identity_comparison.rs | 18 +- .../needless_mutable_reference.rs | 10 +- .../model_ast_lints/bad_lint_attribute_01.exp | 6 +- .../bad_lint_attribute_01.move | 0 .../model_ast_lints/bad_lint_attribute_02.exp | 7 + .../bad_lint_attribute_02.move | 0 .../model_ast_lints/bad_lint_attribute_03.exp | 7 + .../bad_lint_attribute_03.move | 0 .../model_ast_lints/bad_lint_attribute_04.exp | 7 + .../bad_lint_attribute_04.move | 0 .../model_ast_lints/bad_lint_attribute_05.exp | 6 +- .../bad_lint_attribute_05.move | 0 .../model_ast_lints/bad_lint_attribute_06.exp | 6 +- .../bad_lint_attribute_06.move | 0 .../model_ast_lints/bad_lint_attribute_07.exp | 6 +- .../bad_lint_attribute_07.move | 0 .../model_ast_lints/bad_lint_attribute_08.exp | 6 +- .../bad_lint_attribute_08.move | 0 .../model_ast_lints/bad_lint_attribute_09.exp | 6 +- .../bad_lint_attribute_09.move | 0 .../model_ast_lints/bad_lint_attribute_10.exp | 6 +- .../bad_lint_attribute_10.move | 0 .../blocks_in_conditions_warn.exp | 21 +- .../blocks_in_conditions_warn.move | 0 .../model_ast_lints/multi_attributes_01.exp | 7 +- .../model_ast_lints/multi_attributes_01.move | 0 .../model_ast_lints/multi_attributes_02.exp | 2 + .../model_ast_lints/multi_attributes_02.move | 0 .../model_ast_lints/needless_bool_warn.exp | 13 +- .../model_ast_lints/needless_bool_warn.move | 0 .../needless_deref_ref_warn.exp | 39 ++-- .../needless_deref_ref_warn.move | 0 .../needless_ref_deref_warn.exp | 7 +- .../needless_ref_deref_warn.move | 0 .../needless_ref_in_field_access_warn.exp | 57 +++-- .../needless_ref_in_field_access_warn.move | 0 .../simpler_numeric_expression_warn.exp | 41 ++-- .../simpler_numeric_expression_warn.move | 0 ...nnecessary_boolean_identity_comparison.exp | 33 ++- ...necessary_boolean_identity_comparison.move | 0 ...ary_numerical_extreme_comparisons_warn.exp | 45 ++-- ...ry_numerical_extreme_comparisons_warn.move | 0 .../model_ast_lints/while_true_warn.exp | 7 +- .../model_ast_lints/while_true_warn.move | 0 ...id_copy_on_identity_comparison_warn_01.exp | 11 +- ...d_copy_on_identity_comparison_warn_01.move | 0 .../needless_mutable_reference_warn.exp | 53 ++--- .../needless_mutable_reference_warn.move | 0 .../move/tools/move-linter/tests/testsuite.rs | 62 ++++++ .../src/compilation/build_plan.rs | 12 +- .../src/compilation/compiled_package.rs | 5 +- .../move/tools/move-package/src/lib.rs | 7 +- .../tools/move-package/tests/test_runner.rs | 2 +- 86 files changed, 801 insertions(+), 561 deletions(-) create mode 100644 third_party/move/move-compiler-v2/src/external_checks.rs delete mode 100644 third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_02.exp delete mode 100644 third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_03.exp delete mode 100644 third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_04.exp delete mode 100644 third_party/move/move-compiler-v2/tests/lints/model_ast_lints/multi_attributes_02.exp create mode 100644 third_party/move/tools/move-linter/Cargo.toml create mode 100644 third_party/move/tools/move-linter/src/lib.rs create mode 100644 third_party/move/tools/move-linter/src/model_ast_lints.rs rename third_party/move/{move-compiler-v2/src/env_pipeline => tools/move-linter/src}/model_ast_lints/blocks_in_conditions.rs (93%) rename third_party/move/{move-compiler-v2/src/env_pipeline => tools/move-linter/src}/model_ast_lints/needless_bool.rs (91%) rename third_party/move/{move-compiler-v2/src/env_pipeline => tools/move-linter/src}/model_ast_lints/needless_deref_ref.rs (91%) rename third_party/move/{move-compiler-v2/src/env_pipeline => tools/move-linter/src}/model_ast_lints/needless_ref_deref.rs (81%) rename third_party/move/{move-compiler-v2/src/env_pipeline => tools/move-linter/src}/model_ast_lints/needless_ref_in_field_access.rs (88%) rename third_party/move/{move-compiler-v2/src/env_pipeline => tools/move-linter/src}/model_ast_lints/simpler_numeric_expression.rs (90%) rename third_party/move/{move-compiler-v2/src/env_pipeline => tools/move-linter/src}/model_ast_lints/unnecessary_boolean_identity_comparison.rs (83%) rename third_party/move/{move-compiler-v2/src/env_pipeline => tools/move-linter/src}/model_ast_lints/unnecessary_numerical_extreme_comparison.rs (93%) rename third_party/move/{move-compiler-v2/src/env_pipeline => tools/move-linter/src}/model_ast_lints/while_true.rs (88%) create mode 100644 third_party/move/tools/move-linter/src/stackless_bytecode_lints.rs rename third_party/move/{move-compiler-v2/src/pipeline/lint_processor => tools/move-linter/src/stackless_bytecode_lints}/avoid_copy_on_identity_comparison.rs (85%) rename third_party/move/{move-compiler-v2/src/pipeline/lint_processor => tools/move-linter/src/stackless_bytecode_lints}/needless_mutable_reference.rs (97%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/bad_lint_attribute_01.exp (50%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/bad_lint_attribute_01.move (100%) create mode 100644 third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_02.exp rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/bad_lint_attribute_02.move (100%) create mode 100644 third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_03.exp rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/bad_lint_attribute_03.move (100%) create mode 100644 third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_04.exp rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/bad_lint_attribute_04.move (100%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/bad_lint_attribute_05.exp (58%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/bad_lint_attribute_05.move (100%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/bad_lint_attribute_06.exp (50%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/bad_lint_attribute_06.move (100%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/bad_lint_attribute_07.exp (69%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/bad_lint_attribute_07.move (100%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/bad_lint_attribute_08.exp (70%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/bad_lint_attribute_08.move (100%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/bad_lint_attribute_09.exp (66%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/bad_lint_attribute_09.move (100%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/bad_lint_attribute_10.exp (58%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/bad_lint_attribute_10.move (100%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/blocks_in_conditions_warn.exp (80%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/blocks_in_conditions_warn.move (100%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/multi_attributes_01.exp (76%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/multi_attributes_01.move (100%) create mode 100644 third_party/move/tools/move-linter/tests/model_ast_lints/multi_attributes_02.exp rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/multi_attributes_02.move (100%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/needless_bool_warn.exp (83%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/needless_bool_warn.move (100%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/needless_deref_ref_warn.exp (78%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/needless_deref_ref_warn.move (100%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/needless_ref_deref_warn.exp (74%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/needless_ref_deref_warn.move (100%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/needless_ref_in_field_access_warn.exp (79%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/needless_ref_in_field_access_warn.move (100%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/simpler_numeric_expression_warn.exp (77%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/simpler_numeric_expression_warn.move (100%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/unnecessary_boolean_identity_comparison.exp (77%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/unnecessary_boolean_identity_comparison.move (100%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.exp (76%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move (100%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/while_true_warn.exp (79%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/model_ast_lints/while_true_warn.move (100%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/stackless_bytecode_lints/avoid_copy_on_identity_comparison_warn_01.exp (75%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/stackless_bytecode_lints/avoid_copy_on_identity_comparison_warn_01.move (100%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/stackless_bytecode_lints/needless_mutable_reference_warn.exp (76%) rename third_party/move/{move-compiler-v2/tests/lints => tools/move-linter/tests}/stackless_bytecode_lints/needless_mutable_reference_warn.move (100%) create mode 100644 third_party/move/tools/move-linter/tests/testsuite.rs diff --git a/Cargo.lock b/Cargo.lock index fa0e56a9e3823..a1258db539c60 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -339,6 +339,7 @@ dependencies = [ "move-coverage", "move-disassembler", "move-ir-types", + "move-linter", "move-model", "move-package", "move-prover-boogie-backend", @@ -11149,8 +11150,6 @@ dependencies = [ "num 0.4.1", "once_cell", "petgraph 0.6.5", - "strum 0.24.1", - "strum_macros 0.24.3", "walkdir", ] @@ -11375,6 +11374,21 @@ dependencies = [ "serde", ] +[[package]] +name = "move-linter" +version = "0.1.0" +dependencies = [ + "codespan-reporting", + "datatest-stable", + "move-binary-format", + "move-compiler", + "move-compiler-v2", + "move-model", + "move-prover-test-utils", + "move-stackless-bytecode", + "num 0.4.1", +] + [[package]] name = "move-model" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 1ae37eabb8c0e..64384fd8c1c8f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -248,6 +248,7 @@ members = [ "third_party/move/tools/move-decompiler", "third_party/move/tools/move-disassembler", "third_party/move/tools/move-explain", + "third_party/move/tools/move-linter", "third_party/move/tools/move-package", "third_party/move/tools/move-resource-viewer", "third_party/move/tools/move-unit-test", @@ -853,6 +854,7 @@ move-docgen = { path = "third_party/move/move-prover/move-docgen" } move-disassembler = { path = "third_party/move/tools/move-disassembler" } move-ir-types = { path = "third_party/move/move-ir/types" } move-ir-compiler = { path = "third_party/move/move-ir-compiler" } +move-linter = { path = "third_party/move/tools/move-linter" } move-bytecode-source-map = { path = "third_party/move/move-ir-compiler/move-bytecode-source-map" } move-model = { path = "third_party/move/move-model" } move-package = { path = "third_party/move/tools/move-package" } diff --git a/aptos-move/framework/src/built_package.rs b/aptos-move/framework/src/built_package.rs index 3f120349a6f04..77c5bf7cd813d 100644 --- a/aptos-move/framework/src/built_package.rs +++ b/aptos-move/framework/src/built_package.rs @@ -19,7 +19,7 @@ use itertools::Itertools; use move_binary_format::{file_format_common::VERSION_7, CompiledModule}; use move_command_line_common::files::MOVE_COMPILED_EXTENSION; use move_compiler::compiled_unit::{CompiledUnit, NamedCompiledModule}; -use move_compiler_v2::{options::Options, Experiment}; +use move_compiler_v2::{external_checks::ExternalChecks, options::Options, Experiment}; use move_core_types::{language_storage::ModuleId, metadata::Metadata}; use move_model::{ metadata::{CompilerVersion, LanguageVersion}, @@ -38,6 +38,7 @@ use std::{ collections::{BTreeMap, BTreeSet}, io::{stderr, Write}, path::{Path, PathBuf}, + sync::Arc, }; pub const METADATA_FILE_NAME: &str = "package-metadata.bcs"; @@ -222,108 +223,123 @@ impl BuiltPackage { /// This function currently reports all Move compilation errors and warnings to stdout, /// and is not `Ok` if there was an error among those. pub fn build(package_path: PathBuf, options: BuildOptions) -> anyhow::Result { - let bytecode_version = Some(options.inferred_bytecode_version()); - let compiler_version = options.compiler_version; - let language_version = options.language_version; - Self::check_versions(&compiler_version, &language_version)?; - let skip_attribute_checks = options.skip_attribute_checks; - let build_config = BuildConfig { - dev_mode: options.dev, - additional_named_addresses: options.named_addresses.clone(), - architecture: None, - generate_abis: options.with_abis, - generate_docs: false, - generate_move_model: true, - full_model_generation: options.check_test_code, - install_dir: options.install_dir.clone(), - test_mode: false, - override_std: options.override_std.clone(), - force_recompilation: false, - fetch_deps_only: false, - skip_fetch_latest_git_deps: options.skip_fetch_latest_git_deps, - compiler_config: CompilerConfig { - bytecode_version, - compiler_version, - language_version, - skip_attribute_checks, - known_attributes: options.known_attributes.clone(), - experiments: options.experiments.clone(), - }, - }; + BuiltPackage::build_with_external_checks(package_path, options, vec![]) + } + + /// Same as `build` but allows to provide external checks to be made on Move code. + /// The `external_checks` are only run when compiler v2 is used. + pub fn build_with_external_checks( + package_path: PathBuf, + options: BuildOptions, + external_checks: Vec>, + ) -> anyhow::Result { + { + let bytecode_version = Some(options.inferred_bytecode_version()); + let compiler_version = options.compiler_version; + let language_version = options.language_version; + Self::check_versions(&compiler_version, &language_version)?; + let skip_attribute_checks = options.skip_attribute_checks; + let build_config = BuildConfig { + dev_mode: options.dev, + additional_named_addresses: options.named_addresses.clone(), + architecture: None, + generate_abis: options.with_abis, + generate_docs: false, + generate_move_model: true, + full_model_generation: options.check_test_code, + install_dir: options.install_dir.clone(), + test_mode: false, + override_std: options.override_std.clone(), + force_recompilation: false, + fetch_deps_only: false, + skip_fetch_latest_git_deps: options.skip_fetch_latest_git_deps, + compiler_config: CompilerConfig { + bytecode_version, + compiler_version, + language_version, + skip_attribute_checks, + known_attributes: options.known_attributes.clone(), + experiments: options.experiments.clone(), + }, + }; - eprintln!("Compiling, may take a little while to download git dependencies..."); - let (mut package, model_opt) = - build_config.compile_package_no_exit(&package_path, &mut stderr())?; + eprintln!("Compiling, may take a little while to download git dependencies..."); + let (mut package, model_opt) = build_config.compile_package_no_exit( + &package_path, + external_checks, + &mut stderr(), + )?; - // Run extended checks as well derive runtime metadata - let model = &model_opt.expect("move model"); + // Run extended checks as well derive runtime metadata + let model = &model_opt.expect("move model"); - if let Some(model_options) = model.get_extension::() { - if model_options.experiment_on(Experiment::STOP_BEFORE_EXTENDED_CHECKS) { - std::process::exit(0) + if let Some(model_options) = model.get_extension::() { + if model_options.experiment_on(Experiment::STOP_BEFORE_EXTENDED_CHECKS) { + std::process::exit(0) + } } - } - let runtime_metadata = extended_checks::run_extended_checks(model); - if model.diag_count(Severity::Warning) > 0 { - let mut error_writer = StandardStream::stderr(ColorChoice::Auto); - model.report_diag(&mut error_writer, Severity::Warning); - if model.has_errors() { - bail!("extended checks failed") + let runtime_metadata = extended_checks::run_extended_checks(model); + if model.diag_count(Severity::Warning) > 0 { + let mut error_writer = StandardStream::stderr(ColorChoice::Auto); + model.report_diag(&mut error_writer, Severity::Warning); + if model.has_errors() { + bail!("extended checks failed") + } } - } - if let Some(model_options) = model.get_extension::() { - if model_options.experiment_on(Experiment::STOP_AFTER_EXTENDED_CHECKS) { - std::process::exit(0) + if let Some(model_options) = model.get_extension::() { + if model_options.experiment_on(Experiment::STOP_AFTER_EXTENDED_CHECKS) { + std::process::exit(0) + } } - } - let compiled_pkg_path = package - .compiled_package_info - .build_flags - .install_dir - .as_ref() - .unwrap_or(&package_path) - .join(CompiledPackageLayout::Root.path()) - .join(package.compiled_package_info.package_name.as_str()); - inject_runtime_metadata( - compiled_pkg_path, - &mut package, - runtime_metadata, - bytecode_version, - )?; + let compiled_pkg_path = package + .compiled_package_info + .build_flags + .install_dir + .as_ref() + .unwrap_or(&package_path) + .join(CompiledPackageLayout::Root.path()) + .join(package.compiled_package_info.package_name.as_str()); + inject_runtime_metadata( + compiled_pkg_path, + &mut package, + runtime_metadata, + bytecode_version, + )?; - // If enabled generate docs. - if options.with_docs { - let docgen = if let Some(opts) = options.docgen_options.clone() { - opts - } else { - DocgenOptions::default() - }; - let dep_paths = package - .deps_compiled_units - .iter() - .map(|(_, u)| { - u.source_path - .parent() - .unwrap() - .parent() - .unwrap() - .join(get_docgen_output_dir()) - .display() - .to_string() - }) - .unique() - .collect::>(); - docgen.run(package_path.display().to_string(), dep_paths, model)? - } + // If enabled generate docs. + if options.with_docs { + let docgen = if let Some(opts) = options.docgen_options.clone() { + opts + } else { + DocgenOptions::default() + }; + let dep_paths = package + .deps_compiled_units + .iter() + .map(|(_, u)| { + u.source_path + .parent() + .unwrap() + .parent() + .unwrap() + .join(get_docgen_output_dir()) + .display() + .to_string() + }) + .unique() + .collect::>(); + docgen.run(package_path.display().to_string(), dep_paths, model)? + } - Ok(Self { - options, - package_path, - package, - }) + Ok(Self { + options, + package_path, + package, + }) + } } // Check versions and warn user if using unstable ones. diff --git a/crates/aptos/Cargo.toml b/crates/aptos/Cargo.toml index 4f31c89554ae3..f41dc21cdcb0f 100644 --- a/crates/aptos/Cargo.toml +++ b/crates/aptos/Cargo.toml @@ -77,6 +77,7 @@ move-core-types = { workspace = true } move-coverage = { workspace = true } move-disassembler = { workspace = true } move-ir-types = { workspace = true } +move-linter = { workspace = true } move-model = { workspace = true } move-package = { workspace = true } move-prover-boogie-backend = { workspace = true } diff --git a/crates/aptos/src/move_tool/lint.rs b/crates/aptos/src/move_tool/lint.rs index f122b616da4bd..915379c3792cb 100644 --- a/crates/aptos/src/move_tool/lint.rs +++ b/crates/aptos/src/move_tool/lint.rs @@ -9,6 +9,7 @@ use aptos_framework::{BuildOptions, BuiltPackage}; use async_trait::async_trait; use clap::Parser; use move_compiler_v2::Experiment; +use move_linter::MoveLintChecks; use move_model::metadata::{CompilerVersion, LanguageVersion}; use move_package::source_package::std_lib::StdVersion; use std::{collections::BTreeMap, path::PathBuf}; @@ -112,7 +113,7 @@ impl CliCommand<&'static str> for LintPackage { async fn execute(self) -> CliTypedResult<&'static str> { let move_options = MovePackageDir { - compiler_version: Some(CompilerVersion::V2_0), + compiler_version: Some(CompilerVersion::latest_stable()), ..self.to_move_options() }; let more_experiments = vec![ @@ -131,7 +132,9 @@ impl CliCommand<&'static str> for LintPackage { true, )? }; - BuiltPackage::build(package_path, build_options)?; + BuiltPackage::build_with_external_checks(package_path, build_options, vec![ + MoveLintChecks::make(), + ])?; Ok("succeeded") } } diff --git a/third_party/move/move-compiler-v2/Cargo.toml b/third_party/move/move-compiler-v2/Cargo.toml index bc620c6fc9ea6..90255ab170a9c 100644 --- a/third_party/move/move-compiler-v2/Cargo.toml +++ b/third_party/move/move-compiler-v2/Cargo.toml @@ -37,8 +37,6 @@ num = { workspace = true } once_cell = { workspace = true } #paste = "1.0.5" petgraph = { workspace = true } -strum = { workspace = true } -strum_macros = { workspace = true } [dev-dependencies] anyhow = { workspace = true } diff --git a/third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints.rs b/third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints.rs index 6fde521d401cf..729507428f5ea 100644 --- a/third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints.rs +++ b/third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints.rs @@ -1,75 +1,54 @@ // Copyright (c) Aptos Foundation // SPDX-License-Identifier: Apache-2.0 -//! This module (and its submodules) contain various model-AST-based lint checks. +//! This module exercises externally provided model-AST-based lint checks. -mod blocks_in_conditions; -mod needless_bool; -mod needless_deref_ref; -mod needless_ref_deref; -mod needless_ref_in_field_access; -mod simpler_numeric_expression; -mod unnecessary_boolean_identity_comparison; -mod unnecessary_numerical_extreme_comparison; -mod while_true; - -use crate::lint_common::{lint_skips_from_attributes, LintChecker}; -use move_compiler::shared::known_attributes::LintAttribute; +use crate::{ + external_checks::{known_checker_names, ExpChecker}, + lint_common::lint_skips_from_attributes, + Options, +}; use move_model::{ ast::ExpData, - model::{FunctionEnv, GlobalEnv, Loc}, + model::{FunctionEnv, GlobalEnv}, }; use std::collections::BTreeSet; -/// Perform various lint checks on the model AST. +/// Perform various external lint checks on the model AST. pub fn checker(env: &mut GlobalEnv) { + let options = env + .get_extension::() + .expect("Options is available"); + if options.external_checks.is_empty() { + return; + } + let known_checker_names = known_checker_names(&options.external_checks); for module in env.get_modules() { if module.is_primary_target() { - let module_lint_skips = lint_skips_from_attributes(env, module.get_attributes()); + let module_lint_skips = + lint_skips_from_attributes(env, module.get_attributes(), &known_checker_names); for function in module.get_functions() { if function.is_native() { continue; } - check_function(&function, &module_lint_skips); + check_function(&function, &module_lint_skips, &known_checker_names); } } } } -/// Implement this trait for lint checks that can be performed by looking at an -/// expression as we traverse the model AST. -/// Implement at least one of the `visit` methods to be a useful lint. -trait ExpressionLinter { - /// The corresponding lint checker enumerated value. - fn get_lint_checker(&self) -> LintChecker; - - /// Examine `expr` before any of its children have been visited. - /// Potentially emit lint warnings using `self.warning()`. - fn visit_expr_pre(&mut self, _env: &GlobalEnv, _expr: &ExpData) {} - - /// Examine `expr` after all its children have been visited. - /// Potentially emit lint warnings using `self.warning()`. - fn visit_expr_post(&mut self, _env: &GlobalEnv, _expr: &ExpData) {} - - /// Emit a lint warning with the `msg` highlighting the `loc`. - fn warning(&self, env: &GlobalEnv, loc: &Loc, msg: &str) { - env.lint_diag_with_notes(loc, msg, vec![ - format!( - "To suppress this warning, annotate the function/module with the attribute `#[{}({})]`.", - LintAttribute::SKIP, - self.get_lint_checker() - ), - ]); - } -} - /// Perform the lint checks on the code in `function`. -fn check_function(function: &FunctionEnv, module_lint_skips: &[LintChecker]) { +fn check_function( + function: &FunctionEnv, + module_lint_skips: &BTreeSet, + known_checker_names: &BTreeSet, +) { let env = function.module_env.env; - let function_lint_skips = lint_skips_from_attributes(env, function.get_attributes()); + let function_lint_skips = + lint_skips_from_attributes(env, function.get_attributes(), known_checker_names); let mut lint_skips = BTreeSet::from_iter(function_lint_skips); - lint_skips.extend(module_lint_skips); - let mut expression_linters = get_applicable_lints(lint_skips); + lint_skips.extend(module_lint_skips.clone()); + let mut expression_linters = get_applicable_lints(function, lint_skips); if let Some(def) = function.get_def() { let mut visitor = |post: bool, e: &ExpData| { if !post { @@ -88,24 +67,23 @@ fn check_function(function: &FunctionEnv, module_lint_skips: &[LintChecker]) { } /// Returns a pipeline of "expression linters" to run, skipping the ones in `lint_skips`. -fn get_applicable_lints(lint_skips: BTreeSet) -> Vec> { - get_default_expression_linter_pipeline() - .into_iter() - .filter(|lint| !lint_skips.contains(&lint.get_lint_checker())) +fn get_applicable_lints( + function_env: &FunctionEnv, + lint_skips: BTreeSet, +) -> Vec> { + let options = function_env + .module_env + .env + .get_extension::() + .expect("Options is available"); + options + .external_checks + .iter() + .flat_map(|checks| { + checks + .get_exp_checkers() + .into_iter() + .filter(|lint| !lint_skips.contains(&lint.get_name())) + }) .collect() } - -/// Returns a default pipeline of "expression linters" to run. -fn get_default_expression_linter_pipeline() -> Vec> { - vec![ - Box::::default(), - Box::::default(), - Box::::default(), - Box::::default(), - Box::::default(), - Box::::default(), - Box::::default(), - Box::::default(), - Box::::default(), - ] -} diff --git a/third_party/move/move-compiler-v2/src/external_checks.rs b/third_party/move/move-compiler-v2/src/external_checks.rs new file mode 100644 index 0000000000000..ab53caf1beb6a --- /dev/null +++ b/third_party/move/move-compiler-v2/src/external_checks.rs @@ -0,0 +1,105 @@ +// Copyright (c) Aptos Foundation +// SPDX-License-Identifier: Apache-2.0 + +//! This module contains the interface for externally specified checks +//! that can be run by the Move compiler. + +use move_compiler::shared::known_attributes::LintAttribute; +use move_model::{ + ast::ExpData, + model::{GlobalEnv, Loc}, +}; +use move_stackless_bytecode::function_target::FunctionTarget; +use std::{collections::BTreeSet, fmt, sync::Arc}; + +/// Implement this trait to provide a collection of external checks. +pub trait ExternalChecks { + /// Get all the expression checkers. + fn get_exp_checkers(&self) -> Vec>; + + /// Get all the stackless bytecode checkers. + fn get_stackless_bytecode_checkers(&self) -> Vec>; +} + +impl fmt::Debug for dyn ExternalChecks { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let exp_checkers = self + .get_exp_checkers() + .into_iter() + .map(|c| c.get_name()) + .collect::>() + .join(", "); + let stackless_bytecode_checkers = self + .get_stackless_bytecode_checkers() + .into_iter() + .map(|c| c.get_name()) + .collect::>() + .join(", "); + write!( + f, + "dyn ExternalChecks {{ exp_checkers: [{}], stackless_bytecode_checkers: [{}] }}", + exp_checkers, stackless_bytecode_checkers + ) + } +} + +/// Implement this trait for checks that can be performed by looking at an +/// expression as we traverse the model AST. +/// Implement at least one of the `visit` methods to be a useful checker. +pub trait ExpChecker { + /// Name of the expression checker. + fn get_name(&self) -> String; + + /// Examine `expr` before any of its children have been visited. + /// Potentially emit reports using `self.report()`. + fn visit_expr_pre(&mut self, _env: &GlobalEnv, _expr: &ExpData) {} + + /// Examine `expr` after all its children have been visited. + /// Potentially emit reports using `self.report()`. + fn visit_expr_post(&mut self, _env: &GlobalEnv, _expr: &ExpData) {} + + /// Report the `msg` highlighting the `loc`. + fn report(&self, env: &GlobalEnv, loc: &Loc, msg: &str) { + env.lint_diag_with_notes(loc, msg, vec![ + format!( + "To suppress this warning, annotate the function/module with the attribute `#[{}({})]`.", + LintAttribute::SKIP, + self.get_name() + ), + ]); + } +} + +/// Implement this trait for checks that are performed on the stackless bytecode. +pub trait StacklessBytecodeChecker { + /// Name of the stackless bytecode checker. + fn get_name(&self) -> String; + + /// Examine the `target` and potentially emit reports via `self.report()`. + fn check(&self, target: &FunctionTarget); + + /// Report the `msg` highlighting the `loc`. + fn report(&self, env: &GlobalEnv, loc: &Loc, msg: &str) { + env.lint_diag_with_notes(loc, msg, vec![ + format!( + "To suppress this warning, annotate the function/module with the attribute `#[{}({})]`.", + LintAttribute::SKIP, + self.get_name() + ), + ]); + } +} + +/// Get the set of known checker names from the given external checkers. +pub fn known_checker_names(external_checkers: &Vec>) -> BTreeSet { + let mut names = BTreeSet::new(); + for checkers in external_checkers { + for checker in checkers.get_exp_checkers() { + names.insert(checker.get_name()); + } + for checker in checkers.get_stackless_bytecode_checkers() { + names.insert(checker.get_name()); + } + } + names +} diff --git a/third_party/move/move-compiler-v2/src/lib.rs b/third_party/move/move-compiler-v2/src/lib.rs index cdae728718bb8..84eda127b9f03 100644 --- a/third_party/move/move-compiler-v2/src/lib.rs +++ b/third_party/move/move-compiler-v2/src/lib.rs @@ -5,6 +5,7 @@ mod bytecode_generator; pub mod env_pipeline; mod experiments; +pub mod external_checks; mod file_format_generator; pub mod lint_common; pub mod logging; diff --git a/third_party/move/move-compiler-v2/src/lint_common.rs b/third_party/move/move-compiler-v2/src/lint_common.rs index 63858546906a9..21b61c2060dda 100644 --- a/third_party/move/move-compiler-v2/src/lint_common.rs +++ b/third_party/move/move-compiler-v2/src/lint_common.rs @@ -6,45 +6,31 @@ use move_compiler::shared::known_attributes::LintAttribute; use move_model::{ast::Attribute, model::GlobalEnv}; -use std::str::FromStr; -use strum_macros::{Display, EnumString}; - -/// Enumeration of all the lint checks that can be performed. -/// -/// With the use of `strum_macros::EnumString` and `strum_macros::Display`, -/// each of the variants can be serialized to and deserialized from a string. -/// The serialization follows "snake_case". -#[derive(Copy, Clone, Ord, Eq, PartialEq, PartialOrd, EnumString, Display)] -#[strum(serialize_all = "snake_case")] -pub enum LintChecker { - AvoidCopyOnIdentityComparison, - BlocksInConditions, - NeedlessBool, - NeedlessDerefRef, - NeedlessMutableReference, - NeedlessRefDeref, - NeedlessRefInFieldAccess, - SimplerNumericExpression, - UnnecessaryBooleanIdentityComparison, - UnnecessaryNumericalExtremeComparison, - WhileTrue, -} +use std::collections::BTreeSet; /// Extract all the lint checks to skip from the given attributes. /// Also performs error-checking on any `LintAttribute::SKIP` attributes. -pub fn lint_skips_from_attributes(env: &GlobalEnv, attrs: &[Attribute]) -> Vec { +pub fn lint_skips_from_attributes( + env: &GlobalEnv, + attrs: &[Attribute], + known_checker_names: &BTreeSet, +) -> BTreeSet { let lint_skip = env.symbol_pool().make(LintAttribute::SKIP); let skip_attr = attrs.iter().find(|attr| attr.name() == lint_skip); if let Some(skip_attr) = skip_attr { - parse_lint_skip_attribute(env, skip_attr) + parse_lint_skip_attribute(env, skip_attr, known_checker_names) } else { - vec![] + BTreeSet::new() } } /// Extract all the lint checks to skip from `attr`. /// Also performs error-checking on the LintAttribute::SKIP `attr`. -fn parse_lint_skip_attribute(env: &GlobalEnv, attr: &Attribute) -> Vec { +fn parse_lint_skip_attribute( + env: &GlobalEnv, + attr: &Attribute, + known_checker_names: &BTreeSet, +) -> BTreeSet { match attr { Attribute::Assign(id, ..) => { env.error( @@ -54,7 +40,7 @@ fn parse_lint_skip_attribute(env: &GlobalEnv, attr: &Attribute) -> Vec { if attrs.is_empty() { @@ -79,14 +65,15 @@ fn parse_lint_skip_attribute(env: &GlobalEnv, attr: &Attribute) -> Vec>, } impl Default for Options { @@ -237,6 +245,13 @@ impl Options { ..self } } + + pub fn set_external_checks(self, value: Vec>) -> Self { + Self { + external_checks: value, + ..self + } + } } /// Finds the experiment in the list of definitions. A definition diff --git a/third_party/move/move-compiler-v2/src/pipeline/lint_processor.rs b/third_party/move/move-compiler-v2/src/pipeline/lint_processor.rs index 4d8ba5dd82125..798b5ec9df828 100644 --- a/third_party/move/move-compiler-v2/src/pipeline/lint_processor.rs +++ b/third_party/move/move-compiler-v2/src/pipeline/lint_processor.rs @@ -1,49 +1,23 @@ // Copyright (c) Aptos Foundation // SPDX-License-Identifier: Apache-2.0 -//! This module (and its submodules) contain various stackless-bytecode-based lint checks. +//! This module exercises externally provided stackless-bytecode-based lint checks. //! Live variable analysis is a prerequisite for this lint processor. //! The lint checks also assume that all the correctness checks have already been performed. -mod avoid_copy_on_identity_comparison; -mod needless_mutable_reference; - use crate::{ - lint_common::{lint_skips_from_attributes, LintChecker}, - pipeline::lint_processor::{ - avoid_copy_on_identity_comparison::AvoidCopyOnIdentityComparison, - needless_mutable_reference::NeedlessMutableReference, - }, + external_checks::{known_checker_names, StacklessBytecodeChecker}, + lint_common::lint_skips_from_attributes, + Options, }; -use move_compiler::shared::known_attributes::LintAttribute; -use move_model::model::{FunctionEnv, GlobalEnv, Loc}; +use move_model::model::FunctionEnv; use move_stackless_bytecode::{ function_target::{FunctionData, FunctionTarget}, function_target_pipeline::{FunctionTargetProcessor, FunctionTargetsHolder}, }; use std::collections::BTreeSet; -/// Perform various lint checks on the stackless bytecode. -pub trait StacklessBytecodeLinter { - /// The corresponding lint checker enumerated value. - fn get_lint_checker(&self) -> LintChecker; - - /// Examine the `target` and potentially emit lint warnings via `self.warning()`. - fn check(&self, target: &FunctionTarget); - - /// Emit a lint warning with the `msg` highlighting the `loc`. - fn warning(&self, env: &GlobalEnv, loc: &Loc, msg: &str) { - env.lint_diag_with_notes(loc, msg, vec![ - format!( - "To suppress this warning, annotate the function/module with the attribute `#[{}({})]`.", - LintAttribute::SKIP, - self.get_lint_checker() - ), - ]); - } -} - -/// The top-level processor for the lint pipeline. +/// The top-level processor for the stackless bytecode lint pipeline. pub struct LintProcessor {} impl FunctionTargetProcessor for LintProcessor { @@ -74,32 +48,47 @@ impl FunctionTargetProcessor for LintProcessor { } impl LintProcessor { - /// Returns the default pipeline of stackless bytecode linters to run. - fn get_default_linter_pipeline() -> Vec> { - vec![ - Box::new(AvoidCopyOnIdentityComparison {}), - Box::new(NeedlessMutableReference {}), - ] - } - /// Returns a filtered pipeline of stackless bytecode linters to run. /// The filtering is based on attributes attached to the function and module. pub fn get_applicable_linter_pipeline( target: &FunctionTarget, - ) -> Vec> { - let lint_skips = Self::get_lint_skips(target); - Self::get_default_linter_pipeline() - .into_iter() - .filter(|lint| !lint_skips.contains(&lint.get_lint_checker())) + ) -> Vec> { + let options = target + .global_env() + .get_extension::() + .expect("Options is available"); + if options.external_checks.is_empty() { + return vec![]; + } + let known_checker_names = known_checker_names(&options.external_checks); + let lint_skips = Self::get_lint_skips(target, &known_checker_names); + options + .external_checks + .iter() + .flat_map(|checks| { + checks + .get_stackless_bytecode_checkers() + .into_iter() + .filter(|lint| !lint_skips.contains(&lint.get_name())) + }) .collect() } /// Get the set of lint checks to skip based on attributes attached to the function and module. - fn get_lint_skips(target: &FunctionTarget) -> BTreeSet { - let module_lint_skips = - lint_skips_from_attributes(target.global_env(), target.module_env().get_attributes()); - let function_lint_skips = - lint_skips_from_attributes(target.global_env(), target.func_env.get_attributes()); + fn get_lint_skips( + target: &FunctionTarget, + known_checker_names: &BTreeSet, + ) -> BTreeSet { + let module_lint_skips = lint_skips_from_attributes( + target.global_env(), + target.module_env().get_attributes(), + known_checker_names, + ); + let function_lint_skips = lint_skips_from_attributes( + target.global_env(), + target.func_env.get_attributes(), + known_checker_names, + ); BTreeSet::from_iter(module_lint_skips.into_iter().chain(function_lint_skips)) } } diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_02.exp b/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_02.exp deleted file mode 100644 index 260676727fcfe..0000000000000 --- a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_02.exp +++ /dev/null @@ -1,7 +0,0 @@ - -Diagnostics: -error: no lint checks are specified to be skipped - ┌─ tests/lints/model_ast_lints/bad_lint_attribute_02.move:2:7 - │ -2 │ #[lint::skip] - │ ^^^^^^^^^^ diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_03.exp b/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_03.exp deleted file mode 100644 index 9707fc83fd20e..0000000000000 --- a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_03.exp +++ /dev/null @@ -1,7 +0,0 @@ - -Diagnostics: -error: no lint checks are specified to be skipped - ┌─ tests/lints/model_ast_lints/bad_lint_attribute_03.move:2:7 - │ -2 │ #[lint::skip()] - │ ^^^^^^^^^^^^ diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_04.exp b/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_04.exp deleted file mode 100644 index 3aeb3fe633882..0000000000000 --- a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_04.exp +++ /dev/null @@ -1,7 +0,0 @@ - -Diagnostics: -error: unknown lint check: `unknown_lint` - ┌─ tests/lints/model_ast_lints/bad_lint_attribute_04.move:2:18 - │ -2 │ #[lint::skip(unknown_lint)] - │ ^^^^^^^^^^^^ diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/multi_attributes_02.exp b/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/multi_attributes_02.exp deleted file mode 100644 index 90b32906711cc..0000000000000 --- a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/multi_attributes_02.exp +++ /dev/null @@ -1,2 +0,0 @@ - -============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/testsuite.rs b/third_party/move/move-compiler-v2/tests/testsuite.rs index 65f9c0597fb1b..fc9b5300aaa21 100644 --- a/third_party/move/move-compiler-v2/tests/testsuite.rs +++ b/third_party/move/move-compiler-v2/tests/testsuite.rs @@ -670,21 +670,6 @@ const TEST_CONFIGS: Lazy> = Lazy::new(|| { dump_bytecode: DumpLevel::None, dump_bytecode_filter: None, }, - TestConfig { - name: "lint-checks", - runner: |p| run_test(p, get_config_by_name("lint-checks")), - include: vec![ - "/lints/model_ast_lints/", - "/lints/stackless_bytecode_lints/", - ], - exclude: vec![], - exp_suffix: None, - options: opts.clone().set_experiment(Experiment::LINT_CHECKS, true), - stop_after: StopAfter::FileFormat, - dump_ast: DumpLevel::None, - dump_bytecode: DumpLevel::None, - dump_bytecode_filter: None, - }, TestConfig { name: "control-flow-simplification-on", runner: |p| run_test(p, get_config_by_name("control-flow-simplification-on")), diff --git a/third_party/move/move-prover/src/lib.rs b/third_party/move/move-prover/src/lib.rs index ed2049cbe3968..46810fe825d9d 100644 --- a/third_party/move/move-prover/src/lib.rs +++ b/third_party/move/move-prover/src/lib.rs @@ -91,6 +91,7 @@ pub fn run_move_prover_v2( whole_program: false, compile_test_code: false, compile_verify_code: true, + external_checks: vec![], }; let mut env = move_compiler_v2::run_move_compiler_for_analysis(error_writer, compiler_options)?; diff --git a/third_party/move/scripts/move_pr.sh b/third_party/move/scripts/move_pr.sh index 48f8af6239bf6..ef6588b4e6d9b 100755 --- a/third_party/move/scripts/move_pr.sh +++ b/third_party/move/scripts/move_pr.sh @@ -98,6 +98,7 @@ MOVE_CRATES="\ -p move-compiler-v2\ -p move-compiler-v2-transactional-tests\ -p move-ir-compiler-transactional-tests\ + -p move-linter\ -p move-prover-boogie-backend\ -p move-prover\ -p move-transactional-test-runner\ diff --git a/third_party/move/tools/move-cli/src/base/test.rs b/third_party/move/tools/move-cli/src/base/test.rs index 71a6a181a5e9c..955e32a8ed8f0 100644 --- a/third_party/move/tools/move-cli/src/base/test.rs +++ b/third_party/move/tools/move-cli/src/base/test.rs @@ -244,6 +244,7 @@ pub fn run_move_unit_tests_with_factory().unwrap(); let (_, compiler) = diff --git a/third_party/move/tools/move-linter/Cargo.toml b/third_party/move/tools/move-linter/Cargo.toml new file mode 100644 index 0000000000000..e4db9861a9971 --- /dev/null +++ b/third_party/move/tools/move-linter/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "move-linter" +version = "0.1.0" +authors = ["Aptos Labs"] +description = "The Move Linter" +repository = "https://github.com/aptos-labs/aptos-core" +homepage = "https://aptosfoundation.org/" +license = "Apache-2.0" +publish = false +edition = "2021" + +[dependencies] +codespan-reporting = { workspace = true } +move-binary-format = { workspace = true } +move-compiler = { workspace = true } +move-compiler-v2 = { workspace = true } +move-model = { workspace = true } +move-stackless-bytecode = { workspace = true } +num = { workspace = true } + +[dev-dependencies] +datatest-stable = { workspace = true } +move-prover-test-utils = { workspace = true } + +[features] +default = [] + +[[test]] +name = "testsuite" +harness = false + +[lib] +doctest = false diff --git a/third_party/move/tools/move-linter/src/lib.rs b/third_party/move/tools/move-linter/src/lib.rs new file mode 100644 index 0000000000000..b0fd2ae43b439 --- /dev/null +++ b/third_party/move/tools/move-linter/src/lib.rs @@ -0,0 +1,28 @@ +// Copyright (c) Aptos Foundation +// SPDX-License-Identifier: Apache-2.0 + +mod model_ast_lints; +mod stackless_bytecode_lints; + +use move_compiler_v2::external_checks::{ExpChecker, ExternalChecks, StacklessBytecodeChecker}; +use std::sync::Arc; + +/// Holds collection of lint checks for Move. +pub struct MoveLintChecks {} + +impl ExternalChecks for MoveLintChecks { + fn get_exp_checkers(&self) -> Vec> { + model_ast_lints::get_default_linter_pipeline() + } + + fn get_stackless_bytecode_checkers(&self) -> Vec> { + stackless_bytecode_lints::get_default_linter_pipeline() + } +} + +impl MoveLintChecks { + /// Make an instance of lint checks for Move, provided as `ExternalChecks`. + pub fn make() -> Arc { + Arc::new(MoveLintChecks {}) + } +} diff --git a/third_party/move/tools/move-linter/src/model_ast_lints.rs b/third_party/move/tools/move-linter/src/model_ast_lints.rs new file mode 100644 index 0000000000000..737498217b207 --- /dev/null +++ b/third_party/move/tools/move-linter/src/model_ast_lints.rs @@ -0,0 +1,31 @@ +// Copyright (c) Aptos Foundation +// SPDX-License-Identifier: Apache-2.0 + +//! This module (and its submodules) contain various model-AST-based lint checks. + +mod blocks_in_conditions; +mod needless_bool; +mod needless_deref_ref; +mod needless_ref_deref; +mod needless_ref_in_field_access; +mod simpler_numeric_expression; +mod unnecessary_boolean_identity_comparison; +mod unnecessary_numerical_extreme_comparison; +mod while_true; + +use move_compiler_v2::external_checks::ExpChecker; + +/// Returns a default pipeline of "expression linters" to run. +pub fn get_default_linter_pipeline() -> Vec> { + vec![ + Box::::default(), + Box::::default(), + Box::::default(), + Box::::default(), + Box::::default(), + Box::::default(), + Box::::default(), + Box::::default(), + Box::::default(), + ] +} diff --git a/third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints/blocks_in_conditions.rs b/third_party/move/tools/move-linter/src/model_ast_lints/blocks_in_conditions.rs similarity index 93% rename from third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints/blocks_in_conditions.rs rename to third_party/move/tools/move-linter/src/model_ast_lints/blocks_in_conditions.rs index 64047fd35368b..c81a21dced931 100644 --- a/third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints/blocks_in_conditions.rs +++ b/third_party/move/tools/move-linter/src/model_ast_lints/blocks_in_conditions.rs @@ -9,7 +9,7 @@ //! //! We also only report on the outermost condition with blocks. -use crate::{env_pipeline::model_ast_lints::ExpressionLinter, lint_common::LintChecker}; +use move_compiler_v2::external_checks::ExpChecker; use move_model::{ ast::ExpData, model::{GlobalEnv, NodeId}, @@ -37,9 +37,9 @@ enum CondExprState { }, } -impl ExpressionLinter for BlocksInConditions { - fn get_lint_checker(&self) -> LintChecker { - LintChecker::BlocksInConditions +impl ExpChecker for BlocksInConditions { + fn get_name(&self) -> String { + "blocks_in_conditions".to_string() } fn visit_expr_pre(&mut self, _env: &GlobalEnv, expr: &ExpData) { @@ -88,7 +88,7 @@ impl ExpressionLinter for BlocksInConditions { // We are done with traversing the condition of interest. self.state = None; if has_any_block && !has_spec_block { - self.warning( + self.report( env, &env.get_node_loc(id), "Having blocks in conditions make code harder to read. Consider rewriting this code." diff --git a/third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints/needless_bool.rs b/third_party/move/tools/move-linter/src/model_ast_lints/needless_bool.rs similarity index 91% rename from third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints/needless_bool.rs rename to third_party/move/tools/move-linter/src/model_ast_lints/needless_bool.rs index 5f4b118bd6a56..3858cb0119499 100644 --- a/third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints/needless_bool.rs +++ b/third_party/move/tools/move-linter/src/model_ast_lints/needless_bool.rs @@ -10,7 +10,7 @@ //! In addition, it also handles similar cases where both branches explicitly return //! boolean values. -use crate::{env_pipeline::model_ast_lints::ExpressionLinter, lint_common::LintChecker}; +use move_compiler_v2::external_checks::ExpChecker; use move_model::{ ast::{ExpData, Value}, model::GlobalEnv, @@ -19,9 +19,9 @@ use move_model::{ #[derive(Default)] pub struct NeedlessBool; -impl ExpressionLinter for NeedlessBool { - fn get_lint_checker(&self) -> LintChecker { - LintChecker::NeedlessBool +impl ExpChecker for NeedlessBool { + fn get_name(&self) -> String { + "needless_bool".to_string() } fn visit_expr_pre(&mut self, env: &GlobalEnv, expr: &ExpData) { @@ -30,7 +30,7 @@ impl ExpressionLinter for NeedlessBool { match Self::fixed_bool_values(then, else_) { None => {}, Some(ThenElseFixedValues { then, else_, .. }) if then == else_ => { - self.warning( + self.report( env, &env.get_node_loc(*id), "This if-else has the same bool expression in both branches, consider rewriting the code to remove this redundancy", @@ -43,7 +43,7 @@ impl ExpressionLinter for NeedlessBool { }) => { let negation = if then { "" } else { "the negation of " }; let returned = if both_returned { " returning" } else { "" }; - self.warning( + self.report( env, &env.get_node_loc(*id), &format!( diff --git a/third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints/needless_deref_ref.rs b/third_party/move/tools/move-linter/src/model_ast_lints/needless_deref_ref.rs similarity index 91% rename from third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints/needless_deref_ref.rs rename to third_party/move/tools/move-linter/src/model_ast_lints/needless_deref_ref.rs index b246b5a2211da..86520dfe8cb1c 100644 --- a/third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints/needless_deref_ref.rs +++ b/third_party/move/tools/move-linter/src/model_ast_lints/needless_deref_ref.rs @@ -7,7 +7,7 @@ //! `*&mut x` can be simplified to `x`. //! `*&mut y.f = 5;` can be simplified to `y.f = 5;`. -use crate::{env_pipeline::model_ast_lints::ExpressionLinter, lint_common::LintChecker}; +use move_compiler_v2::external_checks::ExpChecker; use move_model::{ ast::{ExpData, Operation}, model::{GlobalEnv, NodeId}, @@ -17,14 +17,14 @@ use move_model::{ #[derive(Default)] pub struct NeedlessDerefRef; -impl ExpressionLinter for NeedlessDerefRef { - fn get_lint_checker(&self) -> LintChecker { - LintChecker::NeedlessDerefRef +impl ExpChecker for NeedlessDerefRef { + fn get_name(&self) -> String { + "needless_deref_ref".to_string() } fn visit_expr_pre(&mut self, env: &GlobalEnv, expr: &ExpData) { if let Some((id, kind)) = Self::needless_deref_ref_pair(expr) { - self.warning( + self.report( env, &env.get_node_loc(id), &format!( diff --git a/third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints/needless_ref_deref.rs b/third_party/move/tools/move-linter/src/model_ast_lints/needless_ref_deref.rs similarity index 81% rename from third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints/needless_ref_deref.rs rename to third_party/move/tools/move-linter/src/model_ast_lints/needless_ref_deref.rs index f0a6a4d68b7ff..404917d43d2e0 100644 --- a/third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints/needless_ref_deref.rs +++ b/third_party/move/tools/move-linter/src/model_ast_lints/needless_ref_deref.rs @@ -5,7 +5,7 @@ //! taken for a dereference (`&*`). Such pairs of operators are needless and can be //! removed to make the code easier to read. -use crate::{env_pipeline::model_ast_lints::ExpressionLinter, lint_common::LintChecker}; +use move_compiler_v2::external_checks::ExpChecker; use move_model::{ ast::{ExpData, Operation}, model::GlobalEnv, @@ -15,9 +15,9 @@ use move_model::{ #[derive(Default)] pub struct NeedlessRefDeref; -impl ExpressionLinter for NeedlessRefDeref { - fn get_lint_checker(&self) -> LintChecker { - LintChecker::NeedlessRefDeref +impl ExpChecker for NeedlessRefDeref { + fn get_name(&self) -> String { + "needless_ref_deref".to_string() } fn visit_expr_pre(&mut self, env: &GlobalEnv, expr: &ExpData) { @@ -34,7 +34,7 @@ impl ExpressionLinter for NeedlessRefDeref { let Call(_, Deref, _) = args[0].as_ref() else { return; }; - self.warning( + self.report( env, &env.get_node_loc(*id), "Needless pair of `&` and `*` operators: consider removing them", diff --git a/third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints/needless_ref_in_field_access.rs b/third_party/move/tools/move-linter/src/model_ast_lints/needless_ref_in_field_access.rs similarity index 88% rename from third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints/needless_ref_in_field_access.rs rename to third_party/move/tools/move-linter/src/model_ast_lints/needless_ref_in_field_access.rs index 4e85856e852ba..f7a360285cc88 100644 --- a/third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints/needless_ref_in_field_access.rs +++ b/third_party/move/tools/move-linter/src/model_ast_lints/needless_ref_in_field_access.rs @@ -7,7 +7,7 @@ //! `(&mut s).f = 42;` can be simplified to `s.f = 42;`. //! making code easier to read in these cases. -use crate::{env_pipeline::model_ast_lints::ExpressionLinter, lint_common::LintChecker}; +use move_compiler_v2::external_checks::ExpChecker; use move_model::{ ast::{ExpData, Operation}, model::GlobalEnv, @@ -16,9 +16,9 @@ use move_model::{ #[derive(Default)] pub struct NeedlessRefInFieldAccess; -impl ExpressionLinter for NeedlessRefInFieldAccess { - fn get_lint_checker(&self) -> LintChecker { - LintChecker::NeedlessRefInFieldAccess +impl ExpChecker for NeedlessRefInFieldAccess { + fn get_name(&self) -> String { + "needless_ref_in_field_access".to_string() } fn visit_expr_pre(&mut self, env: &GlobalEnv, expr: &ExpData) { @@ -51,7 +51,7 @@ impl ExpressionLinter for NeedlessRefInFieldAccess { .display(env.symbol_pool()) .to_string(); let ref_kind = kind.to_string(); - self.warning( + self.report( env, &env.get_node_loc(*id), &format!( diff --git a/third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints/simpler_numeric_expression.rs b/third_party/move/tools/move-linter/src/model_ast_lints/simpler_numeric_expression.rs similarity index 90% rename from third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints/simpler_numeric_expression.rs rename to third_party/move/tools/move-linter/src/model_ast_lints/simpler_numeric_expression.rs index 24bd713ce2fed..7ccac2e0ba125 100644 --- a/third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints/simpler_numeric_expression.rs +++ b/third_party/move/tools/move-linter/src/model_ast_lints/simpler_numeric_expression.rs @@ -10,7 +10,7 @@ //! * `x | 0`, `x ^ 0`, `x >> 0`, `x << 0`, `x + 0`, `x - 0`, `x / 1`, `x * 1`, //! `0 | x`, `0 ^ x`, `0 + x`, `1 * x` => `x` -use crate::{env_pipeline::model_ast_lints::ExpressionLinter, lint_common::LintChecker}; +use move_compiler_v2::external_checks::ExpChecker; use move_model::{ ast::{ExpData, Operation, Value}, model::GlobalEnv, @@ -20,9 +20,9 @@ use num::BigInt; #[derive(Default)] pub struct SimplerNumericExpression; -impl ExpressionLinter for SimplerNumericExpression { - fn get_lint_checker(&self) -> LintChecker { - LintChecker::SimplerNumericExpression +impl ExpChecker for SimplerNumericExpression { + fn get_name(&self) -> String { + "simpler_numeric_expression".to_string() } fn visit_expr_pre(&mut self, env: &GlobalEnv, expr: &ExpData) { @@ -66,7 +66,7 @@ impl ExpressionLinter for SimplerNumericExpression { }, _ => None, } { - self.warning(env, &env.get_node_loc(*id), msg); + self.report(env, &env.get_node_loc(*id), msg); } } } diff --git a/third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints/unnecessary_boolean_identity_comparison.rs b/third_party/move/tools/move-linter/src/model_ast_lints/unnecessary_boolean_identity_comparison.rs similarity index 83% rename from third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints/unnecessary_boolean_identity_comparison.rs rename to third_party/move/tools/move-linter/src/model_ast_lints/unnecessary_boolean_identity_comparison.rs index 3a527c32cc257..daa930dcdee17 100644 --- a/third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints/unnecessary_boolean_identity_comparison.rs +++ b/third_party/move/tools/move-linter/src/model_ast_lints/unnecessary_boolean_identity_comparison.rs @@ -9,7 +9,7 @@ //! `x == true` ==> `x` //! `false != foo(x)` ==> `!foo(x)` -use crate::{env_pipeline::model_ast_lints::ExpressionLinter, lint_common::LintChecker}; +use move_compiler_v2::external_checks::ExpChecker; use move_model::{ ast::{ExpData, Operation, Value}, model::GlobalEnv, @@ -18,9 +18,9 @@ use move_model::{ #[derive(Default)] pub struct UnnecessaryBooleanIdentityComparison; -impl ExpressionLinter for UnnecessaryBooleanIdentityComparison { - fn get_lint_checker(&self) -> LintChecker { - LintChecker::UnnecessaryBooleanIdentityComparison +impl ExpChecker for UnnecessaryBooleanIdentityComparison { + fn get_name(&self) -> String { + "unnecessary_boolean_identity_comparison".to_string() } fn visit_expr_pre(&mut self, env: &GlobalEnv, expr: &ExpData) { @@ -45,7 +45,7 @@ impl ExpressionLinter for UnnecessaryBooleanIdentityComparison { }, if *b { "true" } else { "false" } ); - self.warning(env, &env.get_node_loc(e.node_id()), &msg); + self.report(env, &env.get_node_loc(e.node_id()), &msg); }, _ => {}, } diff --git a/third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints/unnecessary_numerical_extreme_comparison.rs b/third_party/move/tools/move-linter/src/model_ast_lints/unnecessary_numerical_extreme_comparison.rs similarity index 93% rename from third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints/unnecessary_numerical_extreme_comparison.rs rename to third_party/move/tools/move-linter/src/model_ast_lints/unnecessary_numerical_extreme_comparison.rs index c2a451ba60b2b..ade5931ed9ad8 100644 --- a/third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints/unnecessary_numerical_extreme_comparison.rs +++ b/third_party/move/tools/move-linter/src/model_ast_lints/unnecessary_numerical_extreme_comparison.rs @@ -12,7 +12,7 @@ //! `x > 0` ==> can be clarified to `x != 0` //! and similarly for comparing `x` with u64::MAX. -use crate::{env_pipeline::model_ast_lints::ExpressionLinter, lint_common::LintChecker}; +use move_compiler_v2::external_checks::ExpChecker; use move_model::{ ast::{ExpData, Operation, Value}, model::GlobalEnv, @@ -24,9 +24,9 @@ use std::fmt; #[derive(Default)] pub struct UnnecessaryNumericalExtremeComparison; -impl ExpressionLinter for UnnecessaryNumericalExtremeComparison { - fn get_lint_checker(&self) -> LintChecker { - LintChecker::UnnecessaryNumericalExtremeComparison +impl ExpChecker for UnnecessaryNumericalExtremeComparison { + fn get_name(&self) -> String { + "unnecessary_numerical_extreme_comparison".to_string() } fn visit_expr_pre(&mut self, env: &GlobalEnv, expr: &ExpData) { @@ -43,7 +43,7 @@ impl ExpressionLinter for UnnecessaryNumericalExtremeComparison { // get the type of the left-hand side. let ty = env.get_node_type(lhs.node_id()); if let Some(result) = Self::check_comparisons_with_extremes(lhs, cmp, rhs, &ty) { - self.warning(env, &env.get_node_loc(*id), &result.to_string()); + self.report(env, &env.get_node_loc(*id), &result.to_string()); } } } diff --git a/third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints/while_true.rs b/third_party/move/tools/move-linter/src/model_ast_lints/while_true.rs similarity index 88% rename from third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints/while_true.rs rename to third_party/move/tools/move-linter/src/model_ast_lints/while_true.rs index 52cca5231b438..e92c31525d7e6 100644 --- a/third_party/move/move-compiler-v2/src/env_pipeline/model_ast_lints/while_true.rs +++ b/third_party/move/tools/move-linter/src/model_ast_lints/while_true.rs @@ -4,8 +4,8 @@ //! This module implements an expression linter that checks code of the form: //! `while (true) { ... }` and suggests to use `loop { ... }` instead. -use crate::{env_pipeline::model_ast_lints::ExpressionLinter, lint_common::LintChecker}; use move_compiler::parser::syntax::FOR_LOOP_UPDATE_ITER_FLAG; +use move_compiler_v2::external_checks::ExpChecker; use move_model::{ ast::{Exp, ExpData, Value}, model::GlobalEnv, @@ -14,9 +14,9 @@ use move_model::{ #[derive(Default)] pub struct WhileTrue; -impl ExpressionLinter for WhileTrue { - fn get_lint_checker(&self) -> LintChecker { - LintChecker::WhileTrue +impl ExpChecker for WhileTrue { + fn get_name(&self) -> String { + "while_true".to_string() } fn visit_expr_pre(&mut self, env: &GlobalEnv, expr: &ExpData) { @@ -37,7 +37,7 @@ impl ExpressionLinter for WhileTrue { return; } // If we are here, it is `while (true) {...}`. - self.warning( + self.report( env, &env.get_node_loc(*id), "Use the more explicit `loop` instead.", diff --git a/third_party/move/tools/move-linter/src/stackless_bytecode_lints.rs b/third_party/move/tools/move-linter/src/stackless_bytecode_lints.rs new file mode 100644 index 0000000000000..a206cb8f51c7a --- /dev/null +++ b/third_party/move/tools/move-linter/src/stackless_bytecode_lints.rs @@ -0,0 +1,19 @@ +// Copyright (c) Aptos Foundation +// SPDX-License-Identifier: Apache-2.0 + +//! This module (and its submodules) contain various stackless-bytecode-based lint checks. +//! Live variable analysis is a prerequisite for this lint processor. +//! The lint checks also assume that all the correctness checks have already been performed. + +mod avoid_copy_on_identity_comparison; +mod needless_mutable_reference; + +use move_compiler_v2::external_checks::StacklessBytecodeChecker; + +/// Get default pipeline of "stackless bytecode linters" to run. +pub fn get_default_linter_pipeline() -> Vec> { + vec![ + Box::new(avoid_copy_on_identity_comparison::AvoidCopyOnIdentityComparison {}), + Box::new(needless_mutable_reference::NeedlessMutableReference {}), + ] +} diff --git a/third_party/move/move-compiler-v2/src/pipeline/lint_processor/avoid_copy_on_identity_comparison.rs b/third_party/move/tools/move-linter/src/stackless_bytecode_lints/avoid_copy_on_identity_comparison.rs similarity index 85% rename from third_party/move/move-compiler-v2/src/pipeline/lint_processor/avoid_copy_on_identity_comparison.rs rename to third_party/move/tools/move-linter/src/stackless_bytecode_lints/avoid_copy_on_identity_comparison.rs index 46123581cc4ec..2945bbb2c35cb 100644 --- a/third_party/move/move-compiler-v2/src/pipeline/lint_processor/avoid_copy_on_identity_comparison.rs +++ b/third_party/move/tools/move-linter/src/stackless_bytecode_lints/avoid_copy_on_identity_comparison.rs @@ -9,13 +9,11 @@ //! The comparison itself can still be expensive, but using references for the comparison //! can avoid unnecessary copies. -use crate::{ - lint_common::LintChecker, - pipeline::{ - lint_processor::StacklessBytecodeLinter, livevar_analysis_processor::LiveVarAnnotation, - }, -}; use move_binary_format::file_format::CodeOffset; +use move_compiler_v2::{ + external_checks::StacklessBytecodeChecker, + pipeline::livevar_analysis_processor::LiveVarAnnotation, +}; use move_stackless_bytecode::{ function_target::FunctionTarget, stackless_bytecode::{Bytecode, Operation}, @@ -23,9 +21,9 @@ use move_stackless_bytecode::{ pub struct AvoidCopyOnIdentityComparison {} -impl StacklessBytecodeLinter for AvoidCopyOnIdentityComparison { - fn get_lint_checker(&self) -> LintChecker { - LintChecker::AvoidCopyOnIdentityComparison +impl StacklessBytecodeChecker for AvoidCopyOnIdentityComparison { + fn get_name(&self) -> String { + "avoid_copy_on_identity_comparison".to_string() } fn check(&self, target: &FunctionTarget) { @@ -45,7 +43,7 @@ impl StacklessBytecodeLinter for AvoidCopyOnIdentityComparison { // If either `lhs` or `rhs` is live after the comparison, then at least one of them must be copied // for this comparison. if live_info.after.contains_key(&lhs) || live_info.after.contains_key(&rhs) { - self.warning( + self.report( target.global_env(), &target.get_bytecode_loc(*id), "Compare using references of these values instead (i.e., place `&` on both the operands), to avoid unnecessary copies.", diff --git a/third_party/move/move-compiler-v2/src/pipeline/lint_processor/needless_mutable_reference.rs b/third_party/move/tools/move-linter/src/stackless_bytecode_lints/needless_mutable_reference.rs similarity index 97% rename from third_party/move/move-compiler-v2/src/pipeline/lint_processor/needless_mutable_reference.rs rename to third_party/move/tools/move-linter/src/stackless_bytecode_lints/needless_mutable_reference.rs index c3758742d36a9..9ca43f6f4a1d0 100644 --- a/third_party/move/move-compiler-v2/src/pipeline/lint_processor/needless_mutable_reference.rs +++ b/third_party/move/tools/move-linter/src/stackless_bytecode_lints/needless_mutable_reference.rs @@ -10,7 +10,7 @@ //! - function parameters, //! - obtained via `&mut` or `borrow_global_mut`. -use crate::{lint_common::LintChecker, pipeline::lint_processor::StacklessBytecodeLinter}; +use move_compiler_v2::external_checks::StacklessBytecodeChecker; use move_model::{ ast::TempIndex, model::{GlobalEnv, Loc, Parameter}, @@ -220,9 +220,9 @@ impl MutableReferenceUsageTracker { /// Linter for detecting needless mutable references. pub struct NeedlessMutableReference {} -impl StacklessBytecodeLinter for NeedlessMutableReference { - fn get_lint_checker(&self) -> LintChecker { - LintChecker::NeedlessMutableReference +impl StacklessBytecodeChecker for NeedlessMutableReference { + fn get_name(&self) -> String { + "needless_mutable_reference".to_string() } fn check(&self, target: &FunctionTarget) { @@ -231,7 +231,7 @@ impl StacklessBytecodeLinter for NeedlessMutableReference { if loc.is_inlined() { continue; } - self.warning( + self.report( target.global_env(), &loc, "Needless mutable reference or borrow: consider using immutable reference or borrow instead", diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_01.exp b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_01.exp similarity index 50% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_01.exp rename to third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_01.exp index 3504e204f9a5c..a1ecc703ae7e2 100644 --- a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_01.exp +++ b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_01.exp @@ -1,7 +1,7 @@ - -Diagnostics: +Aborting with compilation errors: +exiting with checking errors error: expected `#[lint::skip(...)]`, not an assigned value - ┌─ tests/lints/model_ast_lints/bad_lint_attribute_01.move:2:7 + ┌─ tests/model_ast_lints/bad_lint_attribute_01.move:2:7 │ 2 │ #[lint::skip = true] │ ^^^^^^^^^^^^^^^^^ diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_01.move b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_01.move similarity index 100% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_01.move rename to third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_01.move diff --git a/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_02.exp b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_02.exp new file mode 100644 index 0000000000000..1027ec8ae900b --- /dev/null +++ b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_02.exp @@ -0,0 +1,7 @@ +Aborting with compilation errors: +exiting with checking errors +error: no lint checks are specified to be skipped + ┌─ tests/model_ast_lints/bad_lint_attribute_02.move:2:7 + │ +2 │ #[lint::skip] + │ ^^^^^^^^^^ diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_02.move b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_02.move similarity index 100% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_02.move rename to third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_02.move diff --git a/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_03.exp b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_03.exp new file mode 100644 index 0000000000000..a04f18ceb0729 --- /dev/null +++ b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_03.exp @@ -0,0 +1,7 @@ +Aborting with compilation errors: +exiting with checking errors +error: no lint checks are specified to be skipped + ┌─ tests/model_ast_lints/bad_lint_attribute_03.move:2:7 + │ +2 │ #[lint::skip()] + │ ^^^^^^^^^^^^ diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_03.move b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_03.move similarity index 100% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_03.move rename to third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_03.move diff --git a/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_04.exp b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_04.exp new file mode 100644 index 0000000000000..06c00f0613da0 --- /dev/null +++ b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_04.exp @@ -0,0 +1,7 @@ +Aborting with compilation errors: +exiting with checking errors +error: unknown lint check: `unknown_lint` + ┌─ tests/model_ast_lints/bad_lint_attribute_04.move:2:18 + │ +2 │ #[lint::skip(unknown_lint)] + │ ^^^^^^^^^^^^ diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_04.move b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_04.move similarity index 100% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_04.move rename to third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_04.move diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_05.exp b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_05.exp similarity index 58% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_05.exp rename to third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_05.exp index db4f37db49d3c..67dbb5c92b9c1 100644 --- a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_05.exp +++ b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_05.exp @@ -1,7 +1,7 @@ - -Diagnostics: +Aborting with compilation errors: +exiting with checking errors error: did not expect an assigned value, expected only the names of the lint checks to be skipped - ┌─ tests/lints/model_ast_lints/bad_lint_attribute_05.move:2:18 + ┌─ tests/model_ast_lints/bad_lint_attribute_05.move:2:18 │ 2 │ #[lint::skip(while_true=1)] │ ^^^^^^^^^^^^ diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_05.move b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_05.move similarity index 100% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_05.move rename to third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_05.move diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_06.exp b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_06.exp similarity index 50% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_06.exp rename to third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_06.exp index 286e183db6013..60270edcd388b 100644 --- a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_06.exp +++ b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_06.exp @@ -1,7 +1,7 @@ - -Diagnostics: +Aborting with compilation errors: +exiting with checking errors error: unexpected nested attributes - ┌─ tests/lints/model_ast_lints/bad_lint_attribute_06.move:2:18 + ┌─ tests/model_ast_lints/bad_lint_attribute_06.move:2:18 │ 2 │ #[lint::skip(while_true(yes=1))] │ ^^^^^^^^^^^^^^^^^ diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_06.move b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_06.move similarity index 100% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_06.move rename to third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_06.move diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_07.exp b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_07.exp similarity index 69% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_07.exp rename to third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_07.exp index eb59298af0683..a90fd72c1ea9b 100644 --- a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_07.exp +++ b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_07.exp @@ -1,7 +1,7 @@ - -Diagnostics: +Aborting with compilation errors: +exiting with checking errors error: duplicate declaration, item, or annotation - ┌─ tests/lints/model_ast_lints/bad_lint_attribute_07.move:2:30 + ┌─ tests/model_ast_lints/bad_lint_attribute_07.move:2:30 │ 2 │ #[lint::skip(while_true, while_true)] │ ---------- ^^^^^^^^^^ Duplicate attribute 'while_true' attached to the same item diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_07.move b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_07.move similarity index 100% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_07.move rename to third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_07.move diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_08.exp b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_08.exp similarity index 70% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_08.exp rename to third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_08.exp index a28f882372822..b131d6040fc16 100644 --- a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_08.exp +++ b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_08.exp @@ -1,7 +1,7 @@ - -Diagnostics: +Aborting with compilation errors: +exiting with checking errors error: duplicate declaration, item, or annotation - ┌─ tests/lints/model_ast_lints/bad_lint_attribute_08.move:3:7 + ┌─ tests/model_ast_lints/bad_lint_attribute_08.move:3:7 │ 2 │ #[lint::skip(while_true)] │ ---------- Attribute previously given here diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_08.move b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_08.move similarity index 100% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_08.move rename to third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_08.move diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_09.exp b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_09.exp similarity index 66% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_09.exp rename to third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_09.exp index 5d46cfaac7671..facadd3f5d062 100644 --- a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_09.exp +++ b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_09.exp @@ -1,7 +1,7 @@ - -Diagnostics: +Aborting with compilation errors: +exiting with checking errors error: invalid attribute - ┌─ tests/lints/model_ast_lints/bad_lint_attribute_09.move:2:7 + ┌─ tests/model_ast_lints/bad_lint_attribute_09.move:2:7 │ 2 │ #[lint::skip(while_true)] │ ^^^^^^^^^^ diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_09.move b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_09.move similarity index 100% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_09.move rename to third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_09.move diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_10.exp b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_10.exp similarity index 58% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_10.exp rename to third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_10.exp index 6e91cdf4f0124..d4556c18c31c9 100644 --- a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_10.exp +++ b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_10.exp @@ -1,7 +1,7 @@ - -Diagnostics: +Aborting with compilation errors: +exiting with checking errors error: unexpected token - ┌─ tests/lints/model_ast_lints/bad_lint_attribute_10.move:3:9 + ┌─ tests/model_ast_lints/bad_lint_attribute_10.move:3:9 │ 3 │ #[lint::skip(while_true)] │ ^ diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_10.move b/third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_10.move similarity index 100% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/bad_lint_attribute_10.move rename to third_party/move/tools/move-linter/tests/model_ast_lints/bad_lint_attribute_10.move diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/blocks_in_conditions_warn.exp b/third_party/move/tools/move-linter/tests/model_ast_lints/blocks_in_conditions_warn.exp similarity index 80% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/blocks_in_conditions_warn.exp rename to third_party/move/tools/move-linter/tests/model_ast_lints/blocks_in_conditions_warn.exp index 328ffc6e3793b..cab5d1e0210bc 100644 --- a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/blocks_in_conditions_warn.exp +++ b/third_party/move/tools/move-linter/tests/model_ast_lints/blocks_in_conditions_warn.exp @@ -1,7 +1,7 @@ Diagnostics: warning: [lint] Having blocks in conditions make code harder to read. Consider rewriting this code. - ┌─ tests/lints/model_ast_lints/blocks_in_conditions_warn.move:20:13 + ┌─ tests/model_ast_lints/blocks_in_conditions_warn.move:20:13 │ 20 │ if ({let x = foo(); !x}) { │ ^^^^^^^^^^^^^^^^^^^ @@ -9,7 +9,7 @@ warning: [lint] Having blocks in conditions make code harder to read. Consider r = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(blocks_in_conditions)]`. warning: [lint] Having blocks in conditions make code harder to read. Consider rewriting this code. - ┌─ tests/lints/model_ast_lints/blocks_in_conditions_warn.move:26:13 + ┌─ tests/model_ast_lints/blocks_in_conditions_warn.move:26:13 │ 26 │ if ({x = x && foo(); x}) { │ ^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ warning: [lint] Having blocks in conditions make code harder to read. Consider r = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(blocks_in_conditions)]`. warning: [lint] Having blocks in conditions make code harder to read. Consider rewriting this code. - ┌─ tests/lints/model_ast_lints/blocks_in_conditions_warn.move:32:16 + ┌─ tests/model_ast_lints/blocks_in_conditions_warn.move:32:16 │ 32 │ match ({let x = blah(); x}) { │ ^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ warning: [lint] Having blocks in conditions make code harder to read. Consider r = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(blocks_in_conditions)]`. warning: [lint] Having blocks in conditions make code harder to read. Consider rewriting this code. - ┌─ tests/lints/model_ast_lints/blocks_in_conditions_warn.move:39:13 + ┌─ tests/model_ast_lints/blocks_in_conditions_warn.move:39:13 │ 39 │ if ({let x = foo(); x}) { │ ^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ warning: [lint] Having blocks in conditions make code harder to read. Consider r = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(blocks_in_conditions)]`. warning: [lint] Having blocks in conditions make code harder to read. Consider rewriting this code. - ┌─ tests/lints/model_ast_lints/blocks_in_conditions_warn.move:40:17 + ┌─ tests/model_ast_lints/blocks_in_conditions_warn.move:40:17 │ 40 │ if ({let x = foo(); x}) { │ ^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ warning: [lint] Having blocks in conditions make code harder to read. Consider r = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(blocks_in_conditions)]`. warning: [lint] Having blocks in conditions make code harder to read. Consider rewriting this code. - ┌─ tests/lints/model_ast_lints/blocks_in_conditions_warn.move:44:17 + ┌─ tests/model_ast_lints/blocks_in_conditions_warn.move:44:17 │ 44 │ if ({let x = foo(); x}) { │ ^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ warning: [lint] Having blocks in conditions make code harder to read. Consider r = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(blocks_in_conditions)]`. warning: [lint] Having blocks in conditions make code harder to read. Consider rewriting this code. - ┌─ tests/lints/model_ast_lints/blocks_in_conditions_warn.move:52:13 + ┌─ tests/model_ast_lints/blocks_in_conditions_warn.move:52:13 │ 52 │ if ({if ({let x = foo(); x}) {bar();}; let x = foo(); x}) { │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -57,7 +57,7 @@ warning: [lint] Having blocks in conditions make code harder to read. Consider r = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(blocks_in_conditions)]`. warning: [lint] Having blocks in conditions make code harder to read. Consider rewriting this code. - ┌─ tests/lints/model_ast_lints/blocks_in_conditions_warn.move:58:16 + ┌─ tests/model_ast_lints/blocks_in_conditions_warn.move:58:16 │ 58 │ while ({x = x + 1; x < 10}) { │ ^^^^^^^^^^^^^^^^^^^ @@ -65,12 +65,9 @@ warning: [lint] Having blocks in conditions make code harder to read. Consider r = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(blocks_in_conditions)]`. warning: [lint] Having blocks in conditions make code harder to read. Consider rewriting this code. - ┌─ tests/lints/model_ast_lints/blocks_in_conditions_warn.move:64:13 + ┌─ tests/model_ast_lints/blocks_in_conditions_warn.move:64:13 │ 64 │ if ({x = x + 1; x < 10} && {x = x + 1; x < 11}) { │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ │ = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(blocks_in_conditions)]`. - - -============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/blocks_in_conditions_warn.move b/third_party/move/tools/move-linter/tests/model_ast_lints/blocks_in_conditions_warn.move similarity index 100% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/blocks_in_conditions_warn.move rename to third_party/move/tools/move-linter/tests/model_ast_lints/blocks_in_conditions_warn.move diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/multi_attributes_01.exp b/third_party/move/tools/move-linter/tests/model_ast_lints/multi_attributes_01.exp similarity index 76% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/multi_attributes_01.exp rename to third_party/move/tools/move-linter/tests/model_ast_lints/multi_attributes_01.exp index be3dbb945935b..3dce6416b501d 100644 --- a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/multi_attributes_01.exp +++ b/third_party/move/tools/move-linter/tests/model_ast_lints/multi_attributes_01.exp @@ -1,7 +1,7 @@ Diagnostics: warning: [lint] Having blocks in conditions make code harder to read. Consider rewriting this code. - ┌─ tests/lints/model_ast_lints/multi_attributes_01.move:13:13 + ┌─ tests/model_ast_lints/multi_attributes_01.move:13:13 │ 13 │ if ({let y = x + 1; y < 5}) { │ ^^^^^^^^^^^^^^^^^^^^^^ @@ -9,7 +9,7 @@ warning: [lint] Having blocks in conditions make code harder to read. Consider r = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(blocks_in_conditions)]`. warning: [lint] Use the more explicit `loop` instead. - ┌─ tests/lints/model_ast_lints/multi_attributes_01.move:16:9 + ┌─ tests/model_ast_lints/multi_attributes_01.move:16:9 │ 16 │ ╭ while (true) { 17 │ │ // do nothing @@ -17,6 +17,3 @@ warning: [lint] Use the more explicit `loop` instead. │ ╰─────────^ │ = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(while_true)]`. - - -============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/multi_attributes_01.move b/third_party/move/tools/move-linter/tests/model_ast_lints/multi_attributes_01.move similarity index 100% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/multi_attributes_01.move rename to third_party/move/tools/move-linter/tests/model_ast_lints/multi_attributes_01.move diff --git a/third_party/move/tools/move-linter/tests/model_ast_lints/multi_attributes_02.exp b/third_party/move/tools/move-linter/tests/model_ast_lints/multi_attributes_02.exp new file mode 100644 index 0000000000000..144ada2dd20d1 --- /dev/null +++ b/third_party/move/tools/move-linter/tests/model_ast_lints/multi_attributes_02.exp @@ -0,0 +1,2 @@ + +No errors or warnings! diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/multi_attributes_02.move b/third_party/move/tools/move-linter/tests/model_ast_lints/multi_attributes_02.move similarity index 100% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/multi_attributes_02.move rename to third_party/move/tools/move-linter/tests/model_ast_lints/multi_attributes_02.move diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/needless_bool_warn.exp b/third_party/move/tools/move-linter/tests/model_ast_lints/needless_bool_warn.exp similarity index 83% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/needless_bool_warn.exp rename to third_party/move/tools/move-linter/tests/model_ast_lints/needless_bool_warn.exp index 09202a85c1d1e..0602129401434 100644 --- a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/needless_bool_warn.exp +++ b/third_party/move/tools/move-linter/tests/model_ast_lints/needless_bool_warn.exp @@ -1,7 +1,7 @@ Diagnostics: warning: [lint] This if-else can be replaced with just the condition - ┌─ tests/lints/model_ast_lints/needless_bool_warn.move:7:9 + ┌─ tests/model_ast_lints/needless_bool_warn.move:7:9 │ 7 │ if (foo()) true else false │ ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -9,7 +9,7 @@ warning: [lint] This if-else can be replaced with just the condition = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_bool)]`. warning: [lint] This if-else can be replaced with just the negation of the condition - ┌─ tests/lints/model_ast_lints/needless_bool_warn.move:11:9 + ┌─ tests/model_ast_lints/needless_bool_warn.move:11:9 │ 11 │ ╭ if (foo()) { false } 12 │ │ else { @@ -21,7 +21,7 @@ warning: [lint] This if-else can be replaced with just the negation of the condi = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_bool)]`. warning: [lint] This if-else can be replaced with just returning the condition - ┌─ tests/lints/model_ast_lints/needless_bool_warn.move:19:9 + ┌─ tests/model_ast_lints/needless_bool_warn.move:19:9 │ 19 │ ╭ if (foo()) { 20 │ │ return true @@ -33,7 +33,7 @@ warning: [lint] This if-else can be replaced with just returning the condition = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_bool)]`. warning: [lint] This if-else can be replaced with just returning the negation of the condition - ┌─ tests/lints/model_ast_lints/needless_bool_warn.move:28:13 + ┌─ tests/model_ast_lints/needless_bool_warn.move:28:13 │ 28 │ ╭ if (foo()) { 29 │ │ return false @@ -45,12 +45,9 @@ warning: [lint] This if-else can be replaced with just returning the negation of = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_bool)]`. warning: [lint] This if-else has the same bool expression in both branches, consider rewriting the code to remove this redundancy - ┌─ tests/lints/model_ast_lints/needless_bool_warn.move:38:9 + ┌─ tests/model_ast_lints/needless_bool_warn.move:38:9 │ 38 │ if (x) { return false } else { return false } │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ │ = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_bool)]`. - - -============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/needless_bool_warn.move b/third_party/move/tools/move-linter/tests/model_ast_lints/needless_bool_warn.move similarity index 100% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/needless_bool_warn.move rename to third_party/move/tools/move-linter/tests/model_ast_lints/needless_bool_warn.move diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/needless_deref_ref_warn.exp b/third_party/move/tools/move-linter/tests/model_ast_lints/needless_deref_ref_warn.exp similarity index 78% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/needless_deref_ref_warn.exp rename to third_party/move/tools/move-linter/tests/model_ast_lints/needless_deref_ref_warn.exp index 218d94dfe989c..3b0453a641aac 100644 --- a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/needless_deref_ref_warn.exp +++ b/third_party/move/tools/move-linter/tests/model_ast_lints/needless_deref_ref_warn.exp @@ -1,7 +1,7 @@ Diagnostics: warning: [lint] Needless pair of `*` and `&mut` operators: consider removing them - ┌─ tests/lints/model_ast_lints/needless_deref_ref_warn.move:18:9 + ┌─ tests/model_ast_lints/needless_deref_ref_warn.move:18:9 │ 18 │ *&mut r.x = 5; │ ^^^^^^^^^^^^^ @@ -9,7 +9,7 @@ warning: [lint] Needless pair of `*` and `&mut` operators: consider removing the = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_deref_ref)]`. warning: [lint] Needless pair of `*` and `&` operators: consider removing them - ┌─ tests/lints/model_ast_lints/needless_deref_ref_warn.move:27:9 + ┌─ tests/model_ast_lints/needless_deref_ref_warn.move:27:9 │ 27 │ *&borrow_global(addr).y │ ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ warning: [lint] Needless pair of `*` and `&` operators: consider removing them = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_deref_ref)]`. warning: [lint] Needless pair of `*` and `&mut` operators: consider removing them - ┌─ tests/lints/model_ast_lints/needless_deref_ref_warn.move:35:9 + ┌─ tests/model_ast_lints/needless_deref_ref_warn.move:35:9 │ 35 │ *&mut borrow_global_mut(addr).y │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ warning: [lint] Needless pair of `*` and `&mut` operators: consider removing the = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_deref_ref)]`. warning: [lint] Needless pair of `*` and `&mut` operators: consider removing them - ┌─ tests/lints/model_ast_lints/needless_deref_ref_warn.move:60:9 + ┌─ tests/model_ast_lints/needless_deref_ref_warn.move:60:9 │ 60 │ *&mut make_S().x = 5; │ ^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ warning: [lint] Needless pair of `*` and `&mut` operators: consider removing the = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_deref_ref)]`. warning: [lint] Needless pair of `*` and `&mut` operators: consider removing them - ┌─ tests/lints/model_ast_lints/needless_deref_ref_warn.move:68:9 + ┌─ tests/model_ast_lints/needless_deref_ref_warn.move:68:9 │ 68 │ *&mut make_S().y.a = 5; │ ^^^^^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ warning: [lint] Needless pair of `*` and `&mut` operators: consider removing the = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_deref_ref)]`. warning: [lint] Needless pair of `*` and `&mut` operators: consider removing them - ┌─ tests/lints/model_ast_lints/needless_deref_ref_warn.move:82:9 + ┌─ tests/model_ast_lints/needless_deref_ref_warn.move:82:9 │ 82 │ *&mut mod_S(&mut s).x = 6; │ ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ warning: [lint] Needless pair of `*` and `&mut` operators: consider removing the = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_deref_ref)]`. warning: [lint] Needless pair of `*` and `&` operators: consider removing them - ┌─ tests/lints/model_ast_lints/needless_deref_ref_warn.move:99:9 + ┌─ tests/model_ast_lints/needless_deref_ref_warn.move:99:9 │ 99 │ *&s │ ^^^ @@ -57,7 +57,7 @@ warning: [lint] Needless pair of `*` and `&` operators: consider removing them = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_deref_ref)]`. warning: [lint] Needless pair of `*` and `&mut` operators: consider removing them - ┌─ tests/lints/model_ast_lints/needless_deref_ref_warn.move:109:9 + ┌─ tests/model_ast_lints/needless_deref_ref_warn.move:109:9 │ 109 │ *&mut s │ ^^^^^^^ @@ -65,7 +65,7 @@ warning: [lint] Needless pair of `*` and `&mut` operators: consider removing the = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_deref_ref)]`. warning: [lint] Needless pair of `*` and `&mut` operators: consider removing them - ┌─ tests/lints/model_ast_lints/needless_deref_ref_warn.move:114:9 + ┌─ tests/model_ast_lints/needless_deref_ref_warn.move:114:9 │ 114 │ *&mut s.x │ ^^^^^^^^^ @@ -73,7 +73,7 @@ warning: [lint] Needless pair of `*` and `&mut` operators: consider removing the = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_deref_ref)]`. warning: [lint] Needless pair of `*` and `&` operators: consider removing them - ┌─ tests/lints/model_ast_lints/needless_deref_ref_warn.move:119:9 + ┌─ tests/model_ast_lints/needless_deref_ref_warn.move:119:9 │ 119 │ *& s.y.a │ ^^^^^^^^ @@ -81,7 +81,7 @@ warning: [lint] Needless pair of `*` and `&` operators: consider removing them = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_deref_ref)]`. warning: [lint] Needless pair of `*` and `&` operators: consider removing them - ┌─ tests/lints/model_ast_lints/needless_deref_ref_warn.move:129:9 + ┌─ tests/model_ast_lints/needless_deref_ref_warn.move:129:9 │ 129 │ *& e.x │ ^^^^^^ @@ -89,7 +89,7 @@ warning: [lint] Needless pair of `*` and `&` operators: consider removing them = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_deref_ref)]`. warning: [lint] Needless pair of `*` and `&mut` operators: consider removing them - ┌─ tests/lints/model_ast_lints/needless_deref_ref_warn.move:139:9 + ┌─ tests/model_ast_lints/needless_deref_ref_warn.move:139:9 │ 139 │ *&mut e.x │ ^^^^^^^^^ @@ -97,7 +97,7 @@ warning: [lint] Needless pair of `*` and `&mut` operators: consider removing the = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_deref_ref)]`. warning: [lint] Needless pair of `*` and `&mut` operators: consider removing them - ┌─ tests/lints/model_ast_lints/needless_deref_ref_warn.move:144:9 + ┌─ tests/model_ast_lints/needless_deref_ref_warn.move:144:9 │ 144 │ *&mut e.x = 6; │ ^^^^^^^^^^^^^ @@ -105,7 +105,7 @@ warning: [lint] Needless pair of `*` and `&mut` operators: consider removing the = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_deref_ref)]`. warning: [lint] Needless pair of `*` and `&mut` operators: consider removing them - ┌─ tests/lints/model_ast_lints/needless_deref_ref_warn.move:148:9 + ┌─ tests/model_ast_lints/needless_deref_ref_warn.move:148:9 │ 148 │ *&mut x = 42; │ ^^^^^^^^^^^^ @@ -113,7 +113,7 @@ warning: [lint] Needless pair of `*` and `&mut` operators: consider removing the = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_deref_ref)]`. warning: [lint] Needless pair of `*` and `&mut` operators: consider removing them - ┌─ tests/lints/model_ast_lints/needless_deref_ref_warn.move:153:9 + ┌─ tests/model_ast_lints/needless_deref_ref_warn.move:153:9 │ 153 │ *&mut x = 5; │ ^^^^^^^^^^^ @@ -121,22 +121,17 @@ warning: [lint] Needless pair of `*` and `&mut` operators: consider removing the = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_deref_ref)]`. warning: [lint] Needless pair of `*` and `&` operators: consider removing them - ┌─ tests/lints/model_ast_lints/needless_deref_ref_warn.move:170:26 + ┌─ tests/model_ast_lints/needless_deref_ref_warn.move:170:26 │ 170 │ let _foo1: Foo = *&bar.foo; │ ^^^^^^^^^ │ = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_deref_ref)]`. - -Diagnostics: warning: [lint] Needless mutable reference or borrow: consider using immutable reference or borrow instead - ┌─ tests/lints/model_ast_lints/needless_deref_ref_warn.move:35:15 + ┌─ tests/model_ast_lints/needless_deref_ref_warn.move:35:15 │ 35 │ *&mut borrow_global_mut(addr).y │ ^^^^^^^^^^^^^^^^^^^^^^^^^^ │ = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_mutable_reference)]`. - - -============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/needless_deref_ref_warn.move b/third_party/move/tools/move-linter/tests/model_ast_lints/needless_deref_ref_warn.move similarity index 100% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/needless_deref_ref_warn.move rename to third_party/move/tools/move-linter/tests/model_ast_lints/needless_deref_ref_warn.move diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/needless_ref_deref_warn.exp b/third_party/move/tools/move-linter/tests/model_ast_lints/needless_ref_deref_warn.exp similarity index 74% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/needless_ref_deref_warn.exp rename to third_party/move/tools/move-linter/tests/model_ast_lints/needless_ref_deref_warn.exp index 0f7168de61a3c..6563ad1ac54f6 100644 --- a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/needless_ref_deref_warn.exp +++ b/third_party/move/tools/move-linter/tests/model_ast_lints/needless_ref_deref_warn.exp @@ -1,7 +1,7 @@ Diagnostics: warning: [lint] Needless pair of `&` and `*` operators: consider removing them - ┌─ tests/lints/model_ast_lints/needless_ref_deref_warn.move:9:46 + ┌─ tests/model_ast_lints/needless_ref_deref_warn.move:9:46 │ 9 │ let pre = string::sub_string(&*k, 0, 5); │ ^^^ @@ -9,12 +9,9 @@ warning: [lint] Needless pair of `&` and `*` operators: consider removing them = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_ref_deref)]`. warning: [lint] Needless pair of `&` and `*` operators: consider removing them - ┌─ tests/lints/model_ast_lints/needless_ref_deref_warn.move:35:9 + ┌─ tests/model_ast_lints/needless_ref_deref_warn.move:35:9 │ 35 │ &*x │ ^^^ │ = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_ref_deref)]`. - - -============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/needless_ref_deref_warn.move b/third_party/move/tools/move-linter/tests/model_ast_lints/needless_ref_deref_warn.move similarity index 100% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/needless_ref_deref_warn.move rename to third_party/move/tools/move-linter/tests/model_ast_lints/needless_ref_deref_warn.move diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/needless_ref_in_field_access_warn.exp b/third_party/move/tools/move-linter/tests/model_ast_lints/needless_ref_in_field_access_warn.exp similarity index 79% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/needless_ref_in_field_access_warn.exp rename to third_party/move/tools/move-linter/tests/model_ast_lints/needless_ref_in_field_access_warn.exp index a0d938626a2eb..041b124ecd9c6 100644 --- a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/needless_ref_in_field_access_warn.exp +++ b/third_party/move/tools/move-linter/tests/model_ast_lints/needless_ref_in_field_access_warn.exp @@ -1,7 +1,7 @@ Diagnostics: warning: [lint] Needless `&` taken for field access: consider removing `&` and directly accessing the field `x` - ┌─ tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move:19:9 + ┌─ tests/model_ast_lints/needless_ref_in_field_access_warn.move:19:9 │ 19 │ (&s).x │ ^^^^ @@ -9,7 +9,7 @@ warning: [lint] Needless `&` taken for field access: consider removing `&` and d = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_ref_in_field_access)]`. warning: [lint] Needless `&` taken for field access: consider removing `&` and directly accessing the field `y` - ┌─ tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move:27:11 + ┌─ tests/model_ast_lints/needless_ref_in_field_access_warn.move:27:11 │ 27 │ (&(&s).y).a + (&((&s).y)).a │ ^^^^ @@ -17,7 +17,7 @@ warning: [lint] Needless `&` taken for field access: consider removing `&` and d = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_ref_in_field_access)]`. warning: [lint] Needless `&` taken for field access: consider removing `&` and directly accessing the field `a` - ┌─ tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move:27:9 + ┌─ tests/model_ast_lints/needless_ref_in_field_access_warn.move:27:9 │ 27 │ (&(&s).y).a + (&((&s).y)).a │ ^^^^^^^^^ @@ -25,7 +25,7 @@ warning: [lint] Needless `&` taken for field access: consider removing `&` and d = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_ref_in_field_access)]`. warning: [lint] Needless `&` taken for field access: consider removing `&` and directly accessing the field `y` - ┌─ tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move:27:26 + ┌─ tests/model_ast_lints/needless_ref_in_field_access_warn.move:27:26 │ 27 │ (&(&s).y).a + (&((&s).y)).a │ ^^^^ @@ -33,7 +33,7 @@ warning: [lint] Needless `&` taken for field access: consider removing `&` and d = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_ref_in_field_access)]`. warning: [lint] Needless `&` taken for field access: consider removing `&` and directly accessing the field `a` - ┌─ tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move:27:23 + ┌─ tests/model_ast_lints/needless_ref_in_field_access_warn.move:27:23 │ 27 │ (&(&s).y).a + (&((&s).y)).a │ ^^^^^^^^^^^ @@ -41,7 +41,7 @@ warning: [lint] Needless `&` taken for field access: consider removing `&` and d = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_ref_in_field_access)]`. warning: [lint] Needless `&` taken for field access: consider removing `&` and directly accessing the field `y` - ┌─ tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move:35:9 + ┌─ tests/model_ast_lints/needless_ref_in_field_access_warn.move:35:9 │ 35 │ (&s).y.a + (&s.y).a + (&(&s).y).a + (&(s.y)).a │ ^^^^ @@ -49,7 +49,7 @@ warning: [lint] Needless `&` taken for field access: consider removing `&` and d = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_ref_in_field_access)]`. warning: [lint] Needless `&` taken for field access: consider removing `&` and directly accessing the field `a` - ┌─ tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move:35:20 + ┌─ tests/model_ast_lints/needless_ref_in_field_access_warn.move:35:20 │ 35 │ (&s).y.a + (&s.y).a + (&(&s).y).a + (&(s.y)).a │ ^^^^^^ @@ -57,7 +57,7 @@ warning: [lint] Needless `&` taken for field access: consider removing `&` and d = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_ref_in_field_access)]`. warning: [lint] Needless `&` taken for field access: consider removing `&` and directly accessing the field `y` - ┌─ tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move:35:33 + ┌─ tests/model_ast_lints/needless_ref_in_field_access_warn.move:35:33 │ 35 │ (&s).y.a + (&s.y).a + (&(&s).y).a + (&(s.y)).a │ ^^^^ @@ -65,7 +65,7 @@ warning: [lint] Needless `&` taken for field access: consider removing `&` and d = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_ref_in_field_access)]`. warning: [lint] Needless `&` taken for field access: consider removing `&` and directly accessing the field `a` - ┌─ tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move:35:31 + ┌─ tests/model_ast_lints/needless_ref_in_field_access_warn.move:35:31 │ 35 │ (&s).y.a + (&s.y).a + (&(&s).y).a + (&(s.y)).a │ ^^^^^^^^^ @@ -73,7 +73,7 @@ warning: [lint] Needless `&` taken for field access: consider removing `&` and d = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_ref_in_field_access)]`. warning: [lint] Needless `&` taken for field access: consider removing `&` and directly accessing the field `a` - ┌─ tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move:35:45 + ┌─ tests/model_ast_lints/needless_ref_in_field_access_warn.move:35:45 │ 35 │ (&s).y.a + (&s.y).a + (&(&s).y).a + (&(s.y)).a │ ^^^^^^^^ @@ -81,7 +81,7 @@ warning: [lint] Needless `&` taken for field access: consider removing `&` and d = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_ref_in_field_access)]`. warning: [lint] Needless `&` taken for field access: consider removing `&` and directly accessing the field `y` - ┌─ tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move:43:9 + ┌─ tests/model_ast_lints/needless_ref_in_field_access_warn.move:43:9 │ 43 │ (&make_S()).y.a │ ^^^^^^^^^^^ @@ -89,7 +89,7 @@ warning: [lint] Needless `&` taken for field access: consider removing `&` and d = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_ref_in_field_access)]`. warning: [lint] Needless `&mut` taken for field access: consider removing `&mut` and directly accessing the field `y` - ┌─ tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move:51:9 + ┌─ tests/model_ast_lints/needless_ref_in_field_access_warn.move:51:9 │ 51 │ (&mut make_S()).y.a + (&mut (&mut s).y).a │ ^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ warning: [lint] Needless `&mut` taken for field access: consider removing `&mut` = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_ref_in_field_access)]`. warning: [lint] Needless `&mut` taken for field access: consider removing `&mut` and directly accessing the field `y` - ┌─ tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move:51:37 + ┌─ tests/model_ast_lints/needless_ref_in_field_access_warn.move:51:37 │ 51 │ (&mut make_S()).y.a + (&mut (&mut s).y).a │ ^^^^^^^^ @@ -105,7 +105,7 @@ warning: [lint] Needless `&mut` taken for field access: consider removing `&mut` = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_ref_in_field_access)]`. warning: [lint] Needless `&mut` taken for field access: consider removing `&mut` and directly accessing the field `a` - ┌─ tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move:51:31 + ┌─ tests/model_ast_lints/needless_ref_in_field_access_warn.move:51:31 │ 51 │ (&mut make_S()).y.a + (&mut (&mut s).y).a │ ^^^^^^^^^^^^^^^^^ @@ -113,7 +113,7 @@ warning: [lint] Needless `&mut` taken for field access: consider removing `&mut` = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_ref_in_field_access)]`. warning: [lint] Needless `&mut` taken for field access: consider removing `&mut` and directly accessing the field `x` - ┌─ tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move:59:9 + ┌─ tests/model_ast_lints/needless_ref_in_field_access_warn.move:59:9 │ 59 │ (&mut s).x = 5; │ ^^^^^^^^ @@ -121,7 +121,7 @@ warning: [lint] Needless `&mut` taken for field access: consider removing `&mut` = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_ref_in_field_access)]`. warning: [lint] Needless `&mut` taken for field access: consider removing `&mut` and directly accessing the field `y` - ┌─ tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move:67:15 + ┌─ tests/model_ast_lints/needless_ref_in_field_access_warn.move:67:15 │ 67 │ (&mut (&mut s).y).a = 5; │ ^^^^^^^^ @@ -129,7 +129,7 @@ warning: [lint] Needless `&mut` taken for field access: consider removing `&mut` = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_ref_in_field_access)]`. warning: [lint] Needless `&mut` taken for field access: consider removing `&mut` and directly accessing the field `a` - ┌─ tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move:67:9 + ┌─ tests/model_ast_lints/needless_ref_in_field_access_warn.move:67:9 │ 67 │ (&mut (&mut s).y).a = 5; │ ^^^^^^^^^^^^^^^^^ @@ -137,7 +137,7 @@ warning: [lint] Needless `&mut` taken for field access: consider removing `&mut` = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_ref_in_field_access)]`. warning: [lint] Needless `&mut` taken for field access: consider removing `&mut` and directly accessing the field `a` - ┌─ tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move:68:9 + ┌─ tests/model_ast_lints/needless_ref_in_field_access_warn.move:68:9 │ 68 │ (&mut (s.y)).a = 6; │ ^^^^^^^^^^^^ @@ -145,7 +145,7 @@ warning: [lint] Needless `&mut` taken for field access: consider removing `&mut` = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_ref_in_field_access)]`. warning: [lint] Needless `&mut` taken for field access: consider removing `&mut` and directly accessing the field `a` - ┌─ tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move:77:9 + ┌─ tests/model_ast_lints/needless_ref_in_field_access_warn.move:77:9 │ 77 │ (&mut make_S().y).a = 5; │ ^^^^^^^^^^^^^^^^^ @@ -153,7 +153,7 @@ warning: [lint] Needless `&mut` taken for field access: consider removing `&mut` = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_ref_in_field_access)]`. warning: [lint] Needless `&` taken for field access: consider removing `&` and directly accessing the field `0` - ┌─ tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move:90:9 + ┌─ tests/model_ast_lints/needless_ref_in_field_access_warn.move:90:9 │ 90 │ (&e).0 + (&mut e).0 │ ^^^^ @@ -161,7 +161,7 @@ warning: [lint] Needless `&` taken for field access: consider removing `&` and d = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_ref_in_field_access)]`. warning: [lint] Needless `&mut` taken for field access: consider removing `&mut` and directly accessing the field `0` - ┌─ tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move:90:18 + ┌─ tests/model_ast_lints/needless_ref_in_field_access_warn.move:90:18 │ 90 │ (&e).0 + (&mut e).0 │ ^^^^^^^^ @@ -169,17 +169,15 @@ warning: [lint] Needless `&mut` taken for field access: consider removing `&mut` = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_ref_in_field_access)]`. warning: [lint] Needless `&mut` taken for field access: consider removing `&mut` and directly accessing the field `0` - ┌─ tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move:98:9 + ┌─ tests/model_ast_lints/needless_ref_in_field_access_warn.move:98:9 │ 98 │ (&mut e).0 = 50; │ ^^^^^^^^ │ = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_ref_in_field_access)]`. - -Diagnostics: warning: [lint] Needless mutable reference or borrow: consider using immutable reference or borrow instead - ┌─ tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move:51:9 + ┌─ tests/model_ast_lints/needless_ref_in_field_access_warn.move:51:9 │ 51 │ (&mut make_S()).y.a + (&mut (&mut s).y).a │ ^^^^^^^^^^^^^^^ @@ -187,7 +185,7 @@ warning: [lint] Needless mutable reference or borrow: consider using immutable r = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_mutable_reference)]`. warning: [lint] Needless mutable reference or borrow: consider using immutable reference or borrow instead - ┌─ tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move:51:37 + ┌─ tests/model_ast_lints/needless_ref_in_field_access_warn.move:51:37 │ 51 │ (&mut make_S()).y.a + (&mut (&mut s).y).a │ ^^^^^^^^ @@ -195,7 +193,7 @@ warning: [lint] Needless mutable reference or borrow: consider using immutable r = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_mutable_reference)]`. warning: [lint] Needless mutable reference or borrow: consider using immutable reference or borrow instead - ┌─ tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move:90:18 + ┌─ tests/model_ast_lints/needless_ref_in_field_access_warn.move:90:18 │ 90 │ (&e).0 + (&mut e).0 │ ^^^^^^^^ @@ -203,12 +201,9 @@ warning: [lint] Needless mutable reference or borrow: consider using immutable r = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_mutable_reference)]`. warning: [lint] Needless mutable reference or borrow: consider using immutable reference or borrow instead - ┌─ tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move:125:18 + ┌─ tests/model_ast_lints/needless_ref_in_field_access_warn.move:125:18 │ 125 │ (&s).x + (&mut s).x │ ^^^^^^^^ │ = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_mutable_reference)]`. - - -============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move b/third_party/move/tools/move-linter/tests/model_ast_lints/needless_ref_in_field_access_warn.move similarity index 100% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/needless_ref_in_field_access_warn.move rename to third_party/move/tools/move-linter/tests/model_ast_lints/needless_ref_in_field_access_warn.move diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/simpler_numeric_expression_warn.exp b/third_party/move/tools/move-linter/tests/model_ast_lints/simpler_numeric_expression_warn.exp similarity index 77% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/simpler_numeric_expression_warn.exp rename to third_party/move/tools/move-linter/tests/model_ast_lints/simpler_numeric_expression_warn.exp index ce1a02091de4a..c198c6c019996 100644 --- a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/simpler_numeric_expression_warn.exp +++ b/third_party/move/tools/move-linter/tests/model_ast_lints/simpler_numeric_expression_warn.exp @@ -1,7 +1,7 @@ Diagnostics: warning: [lint] This expression can be simplified to just `0` - ┌─ tests/lints/model_ast_lints/simpler_numeric_expression_warn.move:3:9 + ┌─ tests/model_ast_lints/simpler_numeric_expression_warn.move:3:9 │ 3 │ (x & 0) + 1 │ ^^^^^^^ @@ -9,7 +9,7 @@ warning: [lint] This expression can be simplified to just `0` = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(simpler_numeric_expression)]`. warning: [lint] This expression can be simplified to just `0` - ┌─ tests/lints/model_ast_lints/simpler_numeric_expression_warn.move:7:9 + ┌─ tests/model_ast_lints/simpler_numeric_expression_warn.move:7:9 │ 7 │ (0 & x) * 0 │ ^^^^^^^ @@ -17,7 +17,7 @@ warning: [lint] This expression can be simplified to just `0` = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(simpler_numeric_expression)]`. warning: [lint] This expression can be simplified to just `0` - ┌─ tests/lints/model_ast_lints/simpler_numeric_expression_warn.move:7:9 + ┌─ tests/model_ast_lints/simpler_numeric_expression_warn.move:7:9 │ 7 │ (0 & x) * 0 │ ^^^^^^^^^^^ @@ -25,7 +25,7 @@ warning: [lint] This expression can be simplified to just `0` = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(simpler_numeric_expression)]`. warning: [lint] This expression can be simplified to just `0` - ┌─ tests/lints/model_ast_lints/simpler_numeric_expression_warn.move:11:10 + ┌─ tests/model_ast_lints/simpler_numeric_expression_warn.move:11:10 │ 11 │ ((0 * x) % 1) | 0 │ ^^^^^^^ @@ -33,7 +33,7 @@ warning: [lint] This expression can be simplified to just `0` = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(simpler_numeric_expression)]`. warning: [lint] This expression can be simplified to just `0` - ┌─ tests/lints/model_ast_lints/simpler_numeric_expression_warn.move:11:9 + ┌─ tests/model_ast_lints/simpler_numeric_expression_warn.move:11:9 │ 11 │ ((0 * x) % 1) | 0 │ ^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ warning: [lint] This expression can be simplified to just `0` = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(simpler_numeric_expression)]`. warning: [lint] This binary operation can be simplified to just the left-hand side - ┌─ tests/lints/model_ast_lints/simpler_numeric_expression_warn.move:11:9 + ┌─ tests/model_ast_lints/simpler_numeric_expression_warn.move:11:9 │ 11 │ ((0 * x) % 1) | 0 │ ^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ warning: [lint] This binary operation can be simplified to just the left-hand si = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(simpler_numeric_expression)]`. warning: [lint] This binary operation can be simplified to just the left-hand side - ┌─ tests/lints/model_ast_lints/simpler_numeric_expression_warn.move:15:9 + ┌─ tests/model_ast_lints/simpler_numeric_expression_warn.move:15:9 │ 15 │ (x ^ 0) - 0 + (x >> 0) + (x << 0) + 0 │ ^^^^^^^ @@ -57,7 +57,7 @@ warning: [lint] This binary operation can be simplified to just the left-hand si = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(simpler_numeric_expression)]`. warning: [lint] This binary operation can be simplified to just the left-hand side - ┌─ tests/lints/model_ast_lints/simpler_numeric_expression_warn.move:15:9 + ┌─ tests/model_ast_lints/simpler_numeric_expression_warn.move:15:9 │ 15 │ (x ^ 0) - 0 + (x >> 0) + (x << 0) + 0 │ ^^^^^^^^^^^ @@ -65,7 +65,7 @@ warning: [lint] This binary operation can be simplified to just the left-hand si = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(simpler_numeric_expression)]`. warning: [lint] This binary operation can be simplified to just the left-hand side - ┌─ tests/lints/model_ast_lints/simpler_numeric_expression_warn.move:15:23 + ┌─ tests/model_ast_lints/simpler_numeric_expression_warn.move:15:23 │ 15 │ (x ^ 0) - 0 + (x >> 0) + (x << 0) + 0 │ ^^^^^^^^ @@ -73,7 +73,7 @@ warning: [lint] This binary operation can be simplified to just the left-hand si = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(simpler_numeric_expression)]`. warning: [lint] This binary operation can be simplified to just the left-hand side - ┌─ tests/lints/model_ast_lints/simpler_numeric_expression_warn.move:15:34 + ┌─ tests/model_ast_lints/simpler_numeric_expression_warn.move:15:34 │ 15 │ (x ^ 0) - 0 + (x >> 0) + (x << 0) + 0 │ ^^^^^^^^ @@ -81,7 +81,7 @@ warning: [lint] This binary operation can be simplified to just the left-hand si = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(simpler_numeric_expression)]`. warning: [lint] This binary operation can be simplified to just the left-hand side - ┌─ tests/lints/model_ast_lints/simpler_numeric_expression_warn.move:15:9 + ┌─ tests/model_ast_lints/simpler_numeric_expression_warn.move:15:9 │ 15 │ (x ^ 0) - 0 + (x >> 0) + (x << 0) + 0 │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -89,7 +89,7 @@ warning: [lint] This binary operation can be simplified to just the left-hand si = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(simpler_numeric_expression)]`. warning: [lint] This binary operation can be simplified to just the left-hand side - ┌─ tests/lints/model_ast_lints/simpler_numeric_expression_warn.move:19:9 + ┌─ tests/model_ast_lints/simpler_numeric_expression_warn.move:19:9 │ 19 │ (x / 1) * 1 │ ^^^^^^^ @@ -97,7 +97,7 @@ warning: [lint] This binary operation can be simplified to just the left-hand si = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(simpler_numeric_expression)]`. warning: [lint] This binary operation can be simplified to just the left-hand side - ┌─ tests/lints/model_ast_lints/simpler_numeric_expression_warn.move:19:9 + ┌─ tests/model_ast_lints/simpler_numeric_expression_warn.move:19:9 │ 19 │ (x / 1) * 1 │ ^^^^^^^^^^^ @@ -105,7 +105,7 @@ warning: [lint] This binary operation can be simplified to just the left-hand si = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(simpler_numeric_expression)]`. warning: [lint] This binary operation can be simplified to just the right-hand side - ┌─ tests/lints/model_ast_lints/simpler_numeric_expression_warn.move:23:13 + ┌─ tests/model_ast_lints/simpler_numeric_expression_warn.move:23:13 │ 23 │ 0 + (0 | x) + (0 ^ x) │ ^^^^^^^ @@ -113,7 +113,7 @@ warning: [lint] This binary operation can be simplified to just the right-hand s = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(simpler_numeric_expression)]`. warning: [lint] This binary operation can be simplified to just the right-hand side - ┌─ tests/lints/model_ast_lints/simpler_numeric_expression_warn.move:23:9 + ┌─ tests/model_ast_lints/simpler_numeric_expression_warn.move:23:9 │ 23 │ 0 + (0 | x) + (0 ^ x) │ ^^^^^^^^^^^ @@ -121,7 +121,7 @@ warning: [lint] This binary operation can be simplified to just the right-hand s = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(simpler_numeric_expression)]`. warning: [lint] This binary operation can be simplified to just the right-hand side - ┌─ tests/lints/model_ast_lints/simpler_numeric_expression_warn.move:23:23 + ┌─ tests/model_ast_lints/simpler_numeric_expression_warn.move:23:23 │ 23 │ 0 + (0 | x) + (0 ^ x) │ ^^^^^^^ @@ -129,7 +129,7 @@ warning: [lint] This binary operation can be simplified to just the right-hand s = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(simpler_numeric_expression)]`. warning: [lint] This binary operation can be simplified to just the right-hand side - ┌─ tests/lints/model_ast_lints/simpler_numeric_expression_warn.move:27:9 + ┌─ tests/model_ast_lints/simpler_numeric_expression_warn.move:27:9 │ 27 │ 1 * x │ ^^^^^ @@ -137,7 +137,7 @@ warning: [lint] This binary operation can be simplified to just the right-hand s = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(simpler_numeric_expression)]`. warning: [lint] This binary operation can be simplified to just the left-hand side - ┌─ tests/lints/model_ast_lints/simpler_numeric_expression_warn.move:31:14 + ┌─ tests/model_ast_lints/simpler_numeric_expression_warn.move:31:14 │ 31 │ 0 >> x + 0 << x │ ^^^^^ @@ -145,12 +145,9 @@ warning: [lint] This binary operation can be simplified to just the left-hand si = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(simpler_numeric_expression)]`. warning: [lint] This expression can be simplified to just `0` - ┌─ tests/lints/model_ast_lints/simpler_numeric_expression_warn.move:31:9 + ┌─ tests/model_ast_lints/simpler_numeric_expression_warn.move:31:9 │ 31 │ 0 >> x + 0 << x │ ^^^^^^^^^^ │ = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(simpler_numeric_expression)]`. - - -============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/simpler_numeric_expression_warn.move b/third_party/move/tools/move-linter/tests/model_ast_lints/simpler_numeric_expression_warn.move similarity index 100% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/simpler_numeric_expression_warn.move rename to third_party/move/tools/move-linter/tests/model_ast_lints/simpler_numeric_expression_warn.move diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/unnecessary_boolean_identity_comparison.exp b/third_party/move/tools/move-linter/tests/model_ast_lints/unnecessary_boolean_identity_comparison.exp similarity index 77% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/unnecessary_boolean_identity_comparison.exp rename to third_party/move/tools/move-linter/tests/model_ast_lints/unnecessary_boolean_identity_comparison.exp index d1e27c9ceec82..ca50156fb99a1 100644 --- a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/unnecessary_boolean_identity_comparison.exp +++ b/third_party/move/tools/move-linter/tests/model_ast_lints/unnecessary_boolean_identity_comparison.exp @@ -1,7 +1,7 @@ Diagnostics: warning: [lint] Directly use the boolean expression, instead of comparing it with `true`. - ┌─ tests/lints/model_ast_lints/unnecessary_boolean_identity_comparison.move:13:13 + ┌─ tests/model_ast_lints/unnecessary_boolean_identity_comparison.move:13:13 │ 13 │ if (foo(x) == true) { bar() }; │ ^^^^^^ @@ -9,7 +9,7 @@ warning: [lint] Directly use the boolean expression, instead of comparing it wit = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_boolean_identity_comparison)]`. warning: [lint] Directly use the negation of the boolean expression, instead of comparing it with `false`. - ┌─ tests/lints/model_ast_lints/unnecessary_boolean_identity_comparison.move:14:13 + ┌─ tests/model_ast_lints/unnecessary_boolean_identity_comparison.move:14:13 │ 14 │ if (foo(x) == false) { bar() }; │ ^^^^^^ @@ -17,7 +17,7 @@ warning: [lint] Directly use the negation of the boolean expression, instead of = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_boolean_identity_comparison)]`. warning: [lint] Directly use the negation of the boolean expression, instead of comparing it with `true`. - ┌─ tests/lints/model_ast_lints/unnecessary_boolean_identity_comparison.move:15:13 + ┌─ tests/model_ast_lints/unnecessary_boolean_identity_comparison.move:15:13 │ 15 │ if (foo(x) != true) { bar() }; │ ^^^^^^ @@ -25,7 +25,7 @@ warning: [lint] Directly use the negation of the boolean expression, instead of = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_boolean_identity_comparison)]`. warning: [lint] Directly use the boolean expression, instead of comparing it with `false`. - ┌─ tests/lints/model_ast_lints/unnecessary_boolean_identity_comparison.move:16:13 + ┌─ tests/model_ast_lints/unnecessary_boolean_identity_comparison.move:16:13 │ 16 │ if (foo(x) != false) { bar() }; │ ^^^^^^ @@ -33,7 +33,7 @@ warning: [lint] Directly use the boolean expression, instead of comparing it wit = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_boolean_identity_comparison)]`. warning: [lint] Directly use the boolean expression, instead of comparing it with `true`. - ┌─ tests/lints/model_ast_lints/unnecessary_boolean_identity_comparison.move:17:21 + ┌─ tests/model_ast_lints/unnecessary_boolean_identity_comparison.move:17:21 │ 17 │ if (true == foo(x)) { bar() }; │ ^^^^^^ @@ -41,7 +41,7 @@ warning: [lint] Directly use the boolean expression, instead of comparing it wit = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_boolean_identity_comparison)]`. warning: [lint] Directly use the negation of the boolean expression, instead of comparing it with `false`. - ┌─ tests/lints/model_ast_lints/unnecessary_boolean_identity_comparison.move:18:22 + ┌─ tests/model_ast_lints/unnecessary_boolean_identity_comparison.move:18:22 │ 18 │ if (false == foo(x)) { bar() }; │ ^^^^^^ @@ -49,7 +49,7 @@ warning: [lint] Directly use the negation of the boolean expression, instead of = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_boolean_identity_comparison)]`. warning: [lint] Directly use the negation of the boolean expression, instead of comparing it with `true`. - ┌─ tests/lints/model_ast_lints/unnecessary_boolean_identity_comparison.move:19:21 + ┌─ tests/model_ast_lints/unnecessary_boolean_identity_comparison.move:19:21 │ 19 │ if (true != foo(x)) { bar() }; │ ^^^^^^ @@ -57,7 +57,7 @@ warning: [lint] Directly use the negation of the boolean expression, instead of = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_boolean_identity_comparison)]`. warning: [lint] Directly use the boolean expression, instead of comparing it with `false`. - ┌─ tests/lints/model_ast_lints/unnecessary_boolean_identity_comparison.move:20:22 + ┌─ tests/model_ast_lints/unnecessary_boolean_identity_comparison.move:20:22 │ 20 │ if (false != foo(x)) { bar() }; │ ^^^^^^ @@ -65,7 +65,7 @@ warning: [lint] Directly use the boolean expression, instead of comparing it wit = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_boolean_identity_comparison)]`. warning: [lint] Comparison can be clarified to use `!=` instead - ┌─ tests/lints/model_ast_lints/unnecessary_boolean_identity_comparison.move:21:13 + ┌─ tests/model_ast_lints/unnecessary_boolean_identity_comparison.move:21:13 │ 21 │ if ((x + 1 > 0) == false) { bar() }; │ ^^^^^^^^^^^ @@ -73,7 +73,7 @@ warning: [lint] Comparison can be clarified to use `!=` instead = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_numerical_extreme_comparison)]`. warning: [lint] Directly use the negation of the boolean expression, instead of comparing it with `false`. - ┌─ tests/lints/model_ast_lints/unnecessary_boolean_identity_comparison.move:21:13 + ┌─ tests/model_ast_lints/unnecessary_boolean_identity_comparison.move:21:13 │ 21 │ if ((x + 1 > 0) == false) { bar() }; │ ^^^^^^^^^^^ @@ -81,7 +81,7 @@ warning: [lint] Directly use the negation of the boolean expression, instead of = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_boolean_identity_comparison)]`. warning: [lint] Directly use the boolean expression, instead of comparing it with `true`. - ┌─ tests/lints/model_ast_lints/unnecessary_boolean_identity_comparison.move:22:18 + ┌─ tests/model_ast_lints/unnecessary_boolean_identity_comparison.move:22:18 │ 22 │ let _y = foo(x) == true; │ ^^^^^^ @@ -89,7 +89,7 @@ warning: [lint] Directly use the boolean expression, instead of comparing it wit = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_boolean_identity_comparison)]`. warning: [lint] Directly use the boolean expression, instead of comparing it with `true`. - ┌─ tests/lints/model_ast_lints/unnecessary_boolean_identity_comparison.move:23:25 + ┌─ tests/model_ast_lints/unnecessary_boolean_identity_comparison.move:23:25 │ 23 │ assert!(true == !foo(x), 42); │ ^^^^^^^ @@ -97,7 +97,7 @@ warning: [lint] Directly use the boolean expression, instead of comparing it wit = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_boolean_identity_comparison)]`. warning: [lint] Directly use the boolean expression, instead of comparing it with `true`. - ┌─ tests/lints/model_ast_lints/unnecessary_boolean_identity_comparison.move:24:14 + ┌─ tests/model_ast_lints/unnecessary_boolean_identity_comparison.move:24:14 │ 24 │ take(foo(x) == true); │ ^^^^^^ @@ -105,7 +105,7 @@ warning: [lint] Directly use the boolean expression, instead of comparing it wit = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_boolean_identity_comparison)]`. warning: [lint] Directly use the boolean expression, instead of comparing it with `true`. - ┌─ tests/lints/model_ast_lints/unnecessary_boolean_identity_comparison.move:25:18 + ┌─ tests/model_ast_lints/unnecessary_boolean_identity_comparison.move:25:18 │ 25 │ let _z = foo(x) == TRUE; │ ^^^^^^ @@ -113,12 +113,9 @@ warning: [lint] Directly use the boolean expression, instead of comparing it wit = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_boolean_identity_comparison)]`. warning: [lint] Directly use the boolean expression, instead of comparing it with `true`. - ┌─ tests/lints/model_ast_lints/unnecessary_boolean_identity_comparison.move:29:13 + ┌─ tests/model_ast_lints/unnecessary_boolean_identity_comparison.move:29:13 │ 29 │ if ((*x && *y) == true) { bar() }; │ ^^^^^^^^^^ │ = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_boolean_identity_comparison)]`. - - -============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/unnecessary_boolean_identity_comparison.move b/third_party/move/tools/move-linter/tests/model_ast_lints/unnecessary_boolean_identity_comparison.move similarity index 100% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/unnecessary_boolean_identity_comparison.move rename to third_party/move/tools/move-linter/tests/model_ast_lints/unnecessary_boolean_identity_comparison.move diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.exp b/third_party/move/tools/move-linter/tests/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.exp similarity index 76% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.exp rename to third_party/move/tools/move-linter/tests/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.exp index ffc25993fd137..6c25788cfb485 100644 --- a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.exp +++ b/third_party/move/tools/move-linter/tests/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.exp @@ -1,7 +1,7 @@ Diagnostics: warning: [lint] Comparison is always false, consider rewriting the code to remove the redundant comparison - ┌─ tests/lints/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:9:13 + ┌─ tests/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:9:13 │ 9 │ if (x + 1 > 255) { bar() }; │ ^^^^^^^^^^^ @@ -9,7 +9,7 @@ warning: [lint] Comparison is always false, consider rewriting the code to remov = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_numerical_extreme_comparison)]`. warning: [lint] Comparison is always false, consider rewriting the code to remove the redundant comparison - ┌─ tests/lints/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:13:13 + ┌─ tests/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:13:13 │ 13 │ if ((*x + *y > 255) == true) { bar() }; │ ^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ warning: [lint] Comparison is always false, consider rewriting the code to remov = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_numerical_extreme_comparison)]`. warning: [lint] Directly use the boolean expression, instead of comparing it with `true`. - ┌─ tests/lints/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:13:13 + ┌─ tests/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:13:13 │ 13 │ if ((*x + *y > 255) == true) { bar() }; │ ^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ warning: [lint] Directly use the boolean expression, instead of comparing it wit = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_boolean_identity_comparison)]`. warning: [lint] Comparison is always false, consider rewriting the code to remove the redundant comparison - ┌─ tests/lints/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:17:13 + ┌─ tests/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:17:13 │ 17 │ if (x < 0 || 0 > x) { bar() }; │ ^^^^^ @@ -33,7 +33,7 @@ warning: [lint] Comparison is always false, consider rewriting the code to remov = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_numerical_extreme_comparison)]`. warning: [lint] Comparison is always false, consider rewriting the code to remove the redundant comparison - ┌─ tests/lints/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:17:22 + ┌─ tests/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:17:22 │ 17 │ if (x < 0 || 0 > x) { bar() }; │ ^^^^^ @@ -41,7 +41,7 @@ warning: [lint] Comparison is always false, consider rewriting the code to remov = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_numerical_extreme_comparison)]`. warning: [lint] Comparison can be simplified to use `==` instead - ┌─ tests/lints/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:18:13 + ┌─ tests/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:18:13 │ 18 │ if (foo(x) <= 0) { bar() }; │ ^^^^^^^^^^^ @@ -49,7 +49,7 @@ warning: [lint] Comparison can be simplified to use `==` instead = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_numerical_extreme_comparison)]`. warning: [lint] Comparison can be simplified to use `==` instead - ┌─ tests/lints/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:19:13 + ┌─ tests/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:19:13 │ 19 │ if (0 >= foo(x)) { bar() }; │ ^^^^^^^^^^^ @@ -57,7 +57,7 @@ warning: [lint] Comparison can be simplified to use `==` instead = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_numerical_extreme_comparison)]`. warning: [lint] Comparison can be clarified to use `!=` instead - ┌─ tests/lints/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:20:13 + ┌─ tests/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:20:13 │ 20 │ if (foo(x) > 0) { bar() }; │ ^^^^^^^^^^ @@ -65,7 +65,7 @@ warning: [lint] Comparison can be clarified to use `!=` instead = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_numerical_extreme_comparison)]`. warning: [lint] Comparison can be clarified to use `!=` instead - ┌─ tests/lints/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:21:13 + ┌─ tests/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:21:13 │ 21 │ if (0 < foo(x)) { bar() }; │ ^^^^^^^^^^ @@ -73,7 +73,7 @@ warning: [lint] Comparison can be clarified to use `!=` instead = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_numerical_extreme_comparison)]`. warning: [lint] Comparison is always true, consider rewriting the code to remove the redundant comparison - ┌─ tests/lints/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:22:13 + ┌─ tests/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:22:13 │ 22 │ if (foo(x) >= 0) { bar() }; │ ^^^^^^^^^^^ @@ -81,7 +81,7 @@ warning: [lint] Comparison is always true, consider rewriting the code to remove = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_numerical_extreme_comparison)]`. warning: [lint] Comparison is always true, consider rewriting the code to remove the redundant comparison - ┌─ tests/lints/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:23:13 + ┌─ tests/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:23:13 │ 23 │ if (0 <= foo(x)) { bar() }; │ ^^^^^^^^^^^ @@ -89,7 +89,7 @@ warning: [lint] Comparison is always true, consider rewriting the code to remove = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_numerical_extreme_comparison)]`. warning: [lint] Comparison is always false, consider rewriting the code to remove the redundant comparison - ┌─ tests/lints/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:36:13 + ┌─ tests/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:36:13 │ 36 │ if (a > U8_MAX || f > (U8_MAX as u256)) { bar() }; │ ^^^^^^^^^^ @@ -97,7 +97,7 @@ warning: [lint] Comparison is always false, consider rewriting the code to remov = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_numerical_extreme_comparison)]`. warning: [lint] Comparison can be simplified to use `==` instead - ┌─ tests/lints/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:37:13 + ┌─ tests/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:37:13 │ 37 │ if (b >= U16_MAX) { bar() }; │ ^^^^^^^^^^^^ @@ -105,7 +105,7 @@ warning: [lint] Comparison can be simplified to use `==` instead = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_numerical_extreme_comparison)]`. warning: [lint] Comparison is always false, consider rewriting the code to remove the redundant comparison - ┌─ tests/lints/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:38:13 + ┌─ tests/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:38:13 │ 38 │ if (U32_MAX < c) { bar() }; │ ^^^^^^^^^^^ @@ -113,7 +113,7 @@ warning: [lint] Comparison is always false, consider rewriting the code to remov = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_numerical_extreme_comparison)]`. warning: [lint] Comparison can be simplified to use `==` instead - ┌─ tests/lints/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:39:13 + ┌─ tests/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:39:13 │ 39 │ if (U64_MAX <= d) { bar() }; │ ^^^^^^^^^^^^ @@ -121,7 +121,7 @@ warning: [lint] Comparison can be simplified to use `==` instead = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_numerical_extreme_comparison)]`. warning: [lint] Comparison can be clarified to use `!=` instead - ┌─ tests/lints/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:40:13 + ┌─ tests/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:40:13 │ 40 │ if (e < U128_MAX) { bar() }; │ ^^^^^^^^^^^^ @@ -129,7 +129,7 @@ warning: [lint] Comparison can be clarified to use `!=` instead = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_numerical_extreme_comparison)]`. warning: [lint] Comparison is always true, consider rewriting the code to remove the redundant comparison - ┌─ tests/lints/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:41:13 + ┌─ tests/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:41:13 │ 41 │ if (f <= U256_MAX) { bar() }; │ ^^^^^^^^^^^^^ @@ -137,7 +137,7 @@ warning: [lint] Comparison is always true, consider rewriting the code to remove = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_numerical_extreme_comparison)]`. warning: [lint] Comparison is always true, consider rewriting the code to remove the redundant comparison - ┌─ tests/lints/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:42:13 + ┌─ tests/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:42:13 │ 42 │ if (U256_MAX >= f) { bar() }; │ ^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ warning: [lint] Comparison is always true, consider rewriting the code to remove = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_numerical_extreme_comparison)]`. warning: [lint] Comparison can be clarified to use `!=` instead - ┌─ tests/lints/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:43:13 + ┌─ tests/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:43:13 │ 43 │ if (U128_MAX > e) { bar() }; │ ^^^^^^^^^^^^ @@ -153,7 +153,7 @@ warning: [lint] Comparison can be clarified to use `!=` instead = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_numerical_extreme_comparison)]`. warning: [lint] Comparison is always true, consider rewriting the code to remove the redundant comparison - ┌─ tests/lints/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:45:20 + ┌─ tests/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:45:20 │ 45 │ assert a <= U8_MAX; │ ^^^^^^^^^^^ @@ -161,12 +161,9 @@ warning: [lint] Comparison is always true, consider rewriting the code to remove = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_numerical_extreme_comparison)]`. warning: [lint] Comparison is always false, consider rewriting the code to remove the redundant comparison - ┌─ tests/lints/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:54:19 + ┌─ tests/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move:54:19 │ 54 │ apply(|x| x > U8_MAX, x) │ ^^^^^^^^^^ │ = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(unnecessary_numerical_extreme_comparison)]`. - - -============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move b/third_party/move/tools/move-linter/tests/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move similarity index 100% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move rename to third_party/move/tools/move-linter/tests/model_ast_lints/unnecessary_numerical_extreme_comparisons_warn.move diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/while_true_warn.exp b/third_party/move/tools/move-linter/tests/model_ast_lints/while_true_warn.exp similarity index 79% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/while_true_warn.exp rename to third_party/move/tools/move-linter/tests/model_ast_lints/while_true_warn.exp index cd5f5119e1956..8d913df6f58cf 100644 --- a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/while_true_warn.exp +++ b/third_party/move/tools/move-linter/tests/model_ast_lints/while_true_warn.exp @@ -1,7 +1,7 @@ Diagnostics: warning: [lint] Use the more explicit `loop` instead. - ┌─ tests/lints/model_ast_lints/while_true_warn.move:3:9 + ┌─ tests/model_ast_lints/while_true_warn.move:3:9 │ 3 │ ╭ while (true) { 4 │ │ if (x > 10) { break; } else { test_warn_1(x + 1); } @@ -11,7 +11,7 @@ warning: [lint] Use the more explicit `loop` instead. = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(while_true)]`. warning: [lint] Use the more explicit `loop` instead. - ┌─ tests/lints/model_ast_lints/while_true_warn.move:11:9 + ┌─ tests/model_ast_lints/while_true_warn.move:11:9 │ 11 │ ╭ while (true) { 12 │ │ if (__update_iter_flag) { i = i + 1; } else { __update_iter_flag = true; } @@ -19,6 +19,3 @@ warning: [lint] Use the more explicit `loop` instead. │ ╰─────────^ │ = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(while_true)]`. - - -============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/lints/model_ast_lints/while_true_warn.move b/third_party/move/tools/move-linter/tests/model_ast_lints/while_true_warn.move similarity index 100% rename from third_party/move/move-compiler-v2/tests/lints/model_ast_lints/while_true_warn.move rename to third_party/move/tools/move-linter/tests/model_ast_lints/while_true_warn.move diff --git a/third_party/move/move-compiler-v2/tests/lints/stackless_bytecode_lints/avoid_copy_on_identity_comparison_warn_01.exp b/third_party/move/tools/move-linter/tests/stackless_bytecode_lints/avoid_copy_on_identity_comparison_warn_01.exp similarity index 75% rename from third_party/move/move-compiler-v2/tests/lints/stackless_bytecode_lints/avoid_copy_on_identity_comparison_warn_01.exp rename to third_party/move/tools/move-linter/tests/stackless_bytecode_lints/avoid_copy_on_identity_comparison_warn_01.exp index a7b86b250891f..b3a2a0f030dd6 100644 --- a/third_party/move/move-compiler-v2/tests/lints/stackless_bytecode_lints/avoid_copy_on_identity_comparison_warn_01.exp +++ b/third_party/move/tools/move-linter/tests/stackless_bytecode_lints/avoid_copy_on_identity_comparison_warn_01.exp @@ -1,7 +1,7 @@ Diagnostics: warning: [lint] Compare using references of these values instead (i.e., place `&` on both the operands), to avoid unnecessary copies. - ┌─ tests/lints/stackless_bytecode_lints/avoid_copy_on_identity_comparison_warn_01.move:20:17 + ┌─ tests/stackless_bytecode_lints/avoid_copy_on_identity_comparison_warn_01.move:20:17 │ 20 │ let p = a == b; │ ^^^^^^ @@ -9,7 +9,7 @@ warning: [lint] Compare using references of these values instead (i.e., place `& = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(avoid_copy_on_identity_comparison)]`. warning: [lint] Compare using references of these values instead (i.e., place `&` on both the operands), to avoid unnecessary copies. - ┌─ tests/lints/stackless_bytecode_lints/avoid_copy_on_identity_comparison_warn_01.move:32:13 + ┌─ tests/stackless_bytecode_lints/avoid_copy_on_identity_comparison_warn_01.move:32:13 │ 32 │ if (a == b) a else b │ ^^^^^^ @@ -17,7 +17,7 @@ warning: [lint] Compare using references of these values instead (i.e., place `& = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(avoid_copy_on_identity_comparison)]`. warning: [lint] Compare using references of these values instead (i.e., place `&` on both the operands), to avoid unnecessary copies. - ┌─ tests/lints/stackless_bytecode_lints/avoid_copy_on_identity_comparison_warn_01.move:38:13 + ┌─ tests/stackless_bytecode_lints/avoid_copy_on_identity_comparison_warn_01.move:38:13 │ 38 │ if (a == b) { │ ^^^^^^ @@ -25,12 +25,9 @@ warning: [lint] Compare using references of these values instead (i.e., place `& = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(avoid_copy_on_identity_comparison)]`. warning: [lint] Compare using references of these values instead (i.e., place `&` on both the operands), to avoid unnecessary copies. - ┌─ tests/lints/stackless_bytecode_lints/avoid_copy_on_identity_comparison_warn_01.move:46:17 + ┌─ tests/stackless_bytecode_lints/avoid_copy_on_identity_comparison_warn_01.move:46:17 │ 46 │ assert!(a == b); │ ^^^^^^ │ = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(avoid_copy_on_identity_comparison)]`. - - -============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/lints/stackless_bytecode_lints/avoid_copy_on_identity_comparison_warn_01.move b/third_party/move/tools/move-linter/tests/stackless_bytecode_lints/avoid_copy_on_identity_comparison_warn_01.move similarity index 100% rename from third_party/move/move-compiler-v2/tests/lints/stackless_bytecode_lints/avoid_copy_on_identity_comparison_warn_01.move rename to third_party/move/tools/move-linter/tests/stackless_bytecode_lints/avoid_copy_on_identity_comparison_warn_01.move diff --git a/third_party/move/move-compiler-v2/tests/lints/stackless_bytecode_lints/needless_mutable_reference_warn.exp b/third_party/move/tools/move-linter/tests/stackless_bytecode_lints/needless_mutable_reference_warn.exp similarity index 76% rename from third_party/move/move-compiler-v2/tests/lints/stackless_bytecode_lints/needless_mutable_reference_warn.exp rename to third_party/move/tools/move-linter/tests/stackless_bytecode_lints/needless_mutable_reference_warn.exp index 6c2805c244b0c..d748cc4d53589 100644 --- a/third_party/move/move-compiler-v2/tests/lints/stackless_bytecode_lints/needless_mutable_reference_warn.exp +++ b/third_party/move/tools/move-linter/tests/stackless_bytecode_lints/needless_mutable_reference_warn.exp @@ -1,7 +1,7 @@ Diagnostics: warning: [lint] Needless pair of `*` and `&mut` operators: consider removing them - ┌─ tests/lints/stackless_bytecode_lints/needless_mutable_reference_warn.move:200:9 + ┌─ tests/stackless_bytecode_lints/needless_mutable_reference_warn.move:200:9 │ 200 │ *&mut s.x │ ^^^^^^^^^ @@ -9,7 +9,7 @@ warning: [lint] Needless pair of `*` and `&mut` operators: consider removing the = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_deref_ref)]`. warning: [lint] Needless pair of `*` and `&mut` operators: consider removing them - ┌─ tests/lints/stackless_bytecode_lints/needless_mutable_reference_warn.move:204:9 + ┌─ tests/stackless_bytecode_lints/needless_mutable_reference_warn.move:204:9 │ 204 │ *&mut s │ ^^^^^^^ @@ -17,25 +17,15 @@ warning: [lint] Needless pair of `*` and `&mut` operators: consider removing the = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_deref_ref)]`. warning: [lint] Needless pair of `*` and `&mut` operators: consider removing them - ┌─ tests/lints/stackless_bytecode_lints/needless_mutable_reference_warn.move:212:9 + ┌─ tests/stackless_bytecode_lints/needless_mutable_reference_warn.move:212:9 │ 212 │ *&mut u │ ^^^^^^^ │ = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_deref_ref)]`. - -Diagnostics: -warning: Unused assignment to `x`. Consider removing or prefixing with an underscore: `_x` - ┌─ tests/lints/stackless_bytecode_lints/needless_mutable_reference_warn.move:175:9 - │ -175 │ x = y; // Produces a cycle in the `derived_edges`. - │ ^^^^^ - - -Diagnostics: warning: [lint] Needless mutable reference or borrow: consider using immutable reference or borrow instead - ┌─ tests/lints/stackless_bytecode_lints/needless_mutable_reference_warn.move:14:17 + ┌─ tests/stackless_bytecode_lints/needless_mutable_reference_warn.move:14:17 │ 14 │ let y = &mut x; │ ^^^^^^ @@ -43,7 +33,7 @@ warning: [lint] Needless mutable reference or borrow: consider using immutable r = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_mutable_reference)]`. warning: [lint] Needless mutable reference or borrow: consider using immutable reference or borrow instead - ┌─ tests/lints/stackless_bytecode_lints/needless_mutable_reference_warn.move:24:17 + ┌─ tests/stackless_bytecode_lints/needless_mutable_reference_warn.move:24:17 │ 24 │ let y = &mut x; │ ^^^^^^ @@ -51,7 +41,7 @@ warning: [lint] Needless mutable reference or borrow: consider using immutable r = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_mutable_reference)]`. warning: [lint] Needless mutable reference or borrow: consider using immutable reference or borrow instead - ┌─ tests/lints/stackless_bytecode_lints/needless_mutable_reference_warn.move:41:20 + ┌─ tests/stackless_bytecode_lints/needless_mutable_reference_warn.move:41:20 │ 41 │ fun test3_warn(s: &mut S): u64 { │ ^ @@ -59,7 +49,7 @@ warning: [lint] Needless mutable reference or borrow: consider using immutable r = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_mutable_reference)]`. warning: [lint] Needless mutable reference or borrow: consider using immutable reference or borrow instead - ┌─ tests/lints/stackless_bytecode_lints/needless_mutable_reference_warn.move:109:17 + ┌─ tests/stackless_bytecode_lints/needless_mutable_reference_warn.move:109:17 │ 109 │ let r = borrow_global_mut(addr); │ ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -67,7 +57,7 @@ warning: [lint] Needless mutable reference or borrow: consider using immutable r = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_mutable_reference)]`. warning: [lint] Needless mutable reference or borrow: consider using immutable reference or borrow instead - ┌─ tests/lints/stackless_bytecode_lints/needless_mutable_reference_warn.move:114:17 + ┌─ tests/stackless_bytecode_lints/needless_mutable_reference_warn.move:114:17 │ 114 │ let r = borrow_global_mut(addr); │ ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -75,7 +65,7 @@ warning: [lint] Needless mutable reference or borrow: consider using immutable r = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_mutable_reference)]`. warning: [lint] Needless mutable reference or borrow: consider using immutable reference or borrow instead - ┌─ tests/lints/stackless_bytecode_lints/needless_mutable_reference_warn.move:119:21 + ┌─ tests/stackless_bytecode_lints/needless_mutable_reference_warn.move:119:21 │ 119 │ fun test_warn_3(s: &mut S, p: bool, addr: address): u64 acquires S { │ ^ @@ -83,7 +73,7 @@ warning: [lint] Needless mutable reference or borrow: consider using immutable r = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_mutable_reference)]`. warning: [lint] Needless mutable reference or borrow: consider using immutable reference or borrow instead - ┌─ tests/lints/stackless_bytecode_lints/needless_mutable_reference_warn.move:120:19 + ┌─ tests/stackless_bytecode_lints/needless_mutable_reference_warn.move:120:19 │ 120 │ let ref = borrow_global_mut(addr); │ ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -91,7 +81,7 @@ warning: [lint] Needless mutable reference or borrow: consider using immutable r = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_mutable_reference)]`. warning: [lint] Needless mutable reference or borrow: consider using immutable reference or borrow instead - ┌─ tests/lints/stackless_bytecode_lints/needless_mutable_reference_warn.move:153:22 + ┌─ tests/stackless_bytecode_lints/needless_mutable_reference_warn.move:153:22 │ 153 │ a = &mut e1.0; │ ^^ @@ -99,7 +89,7 @@ warning: [lint] Needless mutable reference or borrow: consider using immutable r = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_mutable_reference)]`. warning: [lint] Needless mutable reference or borrow: consider using immutable reference or borrow instead - ┌─ tests/lints/stackless_bytecode_lints/needless_mutable_reference_warn.move:155:22 + ┌─ tests/stackless_bytecode_lints/needless_mutable_reference_warn.move:155:22 │ 155 │ a = &mut e2.0; │ ^^ @@ -107,7 +97,7 @@ warning: [lint] Needless mutable reference or borrow: consider using immutable r = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_mutable_reference)]`. warning: [lint] Needless mutable reference or borrow: consider using immutable reference or borrow instead - ┌─ tests/lints/stackless_bytecode_lints/needless_mutable_reference_warn.move:160:21 + ┌─ tests/stackless_bytecode_lints/needless_mutable_reference_warn.move:160:21 │ 160 │ fun test_warn_2(a: &mut E, b: &mut E) { │ ^ @@ -115,7 +105,7 @@ warning: [lint] Needless mutable reference or borrow: consider using immutable r = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_mutable_reference)]`. warning: [lint] Needless mutable reference or borrow: consider using immutable reference or borrow instead - ┌─ tests/lints/stackless_bytecode_lints/needless_mutable_reference_warn.move:160:32 + ┌─ tests/stackless_bytecode_lints/needless_mutable_reference_warn.move:160:32 │ 160 │ fun test_warn_2(a: &mut E, b: &mut E) { │ ^ @@ -123,15 +113,21 @@ warning: [lint] Needless mutable reference or borrow: consider using immutable r = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_mutable_reference)]`. warning: [lint] Needless mutable reference or borrow: consider using immutable reference or borrow instead - ┌─ tests/lints/stackless_bytecode_lints/needless_mutable_reference_warn.move:173:28 + ┌─ tests/stackless_bytecode_lints/needless_mutable_reference_warn.move:173:28 │ 173 │ public fun test_warn_3(x: &mut u64) { │ ^ │ = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_mutable_reference)]`. +warning: Unused assignment to `x`. Consider removing or prefixing with an underscore: `_x` + ┌─ tests/stackless_bytecode_lints/needless_mutable_reference_warn.move:175:9 + │ +175 │ x = y; // Produces a cycle in the `derived_edges`. + │ ^^^^^ + warning: [lint] Needless mutable reference or borrow: consider using immutable reference or borrow instead - ┌─ tests/lints/stackless_bytecode_lints/needless_mutable_reference_warn.move:242:17 + ┌─ tests/stackless_bytecode_lints/needless_mutable_reference_warn.move:242:17 │ 242 │ let u = &mut s; │ ^^^^^^ @@ -139,12 +135,9 @@ warning: [lint] Needless mutable reference or borrow: consider using immutable r = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_mutable_reference)]`. warning: [lint] Needless mutable reference or borrow: consider using immutable reference or borrow instead - ┌─ tests/lints/stackless_bytecode_lints/needless_mutable_reference_warn.move:252:17 + ┌─ tests/stackless_bytecode_lints/needless_mutable_reference_warn.move:252:17 │ 252 │ let u = &mut s; │ ^^^^^^ │ = To suppress this warning, annotate the function/module with the attribute `#[lint::skip(needless_mutable_reference)]`. - - -============ bytecode verification succeeded ======== diff --git a/third_party/move/move-compiler-v2/tests/lints/stackless_bytecode_lints/needless_mutable_reference_warn.move b/third_party/move/tools/move-linter/tests/stackless_bytecode_lints/needless_mutable_reference_warn.move similarity index 100% rename from third_party/move/move-compiler-v2/tests/lints/stackless_bytecode_lints/needless_mutable_reference_warn.move rename to third_party/move/tools/move-linter/tests/stackless_bytecode_lints/needless_mutable_reference_warn.move diff --git a/third_party/move/tools/move-linter/tests/testsuite.rs b/third_party/move/tools/move-linter/tests/testsuite.rs new file mode 100644 index 0000000000000..454957cdd161b --- /dev/null +++ b/third_party/move/tools/move-linter/tests/testsuite.rs @@ -0,0 +1,62 @@ +// Copyright (c) Aptos Foundation +// SPDX-License-Identifier: Apache-2.0 + +use codespan_reporting::{diagnostic::Severity, term::termcolor::Buffer}; +use move_compiler_v2::{run_move_compiler, Experiment}; +use move_linter::MoveLintChecks; +use move_model::metadata::{CompilerVersion, LanguageVersion}; +use move_prover_test_utils::baseline_test; +use std::path::{Path, PathBuf}; + +/// Extension for expected output files. +pub const EXP_EXT: &str = "exp"; + +datatest_stable::harness!(test_runner, "tests", r".*\.move$"); + +fn test_runner(path: &Path) -> datatest_stable::Result<()> { + let compiler_options = move_compiler_v2::Options { + sources: vec![path.display().to_string()], + dependencies: vec![path_from_crate_root("../../move-stdlib/sources")], + named_address_mapping: vec![ + "std=0x1".to_string(), + "aptos_std=0x1".to_string(), + "aptos_framework=0x1".to_string(), + ], + language_version: Some(LanguageVersion::latest_stable()), + compiler_version: Some(CompilerVersion::latest_stable()), + experiments: vec![Experiment::LINT_CHECKS.to_string()], + external_checks: vec![MoveLintChecks::make()], + ..Default::default() + }; + let mut output = String::new(); + let mut error_writer = Buffer::no_color(); + match run_move_compiler(&mut error_writer, compiler_options) { + Err(e) => { + output.push_str(&format!( + "Aborting with compilation errors:\n{:#}\n{}\n", + e, + String::from_utf8_lossy(&error_writer.into_inner()) + )); + }, + Ok((env, _)) => { + env.report_diag(&mut error_writer, Severity::Warning); + let diag = String::from_utf8_lossy(&error_writer.into_inner()).to_string(); + if !diag.is_empty() { + output.push_str(&format!("\nDiagnostics:\n{}", diag)); + } else { + output.push_str("\nNo errors or warnings!"); + } + }, + } + // Generate/check baseline. + let baseline_path = path.with_extension(EXP_EXT); + baseline_test::verify_or_update_baseline(baseline_path.as_path(), &output)?; + Ok(()) +} + +/// Returns a path relative to the crate root. +fn path_from_crate_root(path: &str) -> String { + let mut buf = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + buf.push(path); + buf.to_string_lossy().to_string() +} diff --git a/third_party/move/tools/move-package/src/compilation/build_plan.rs b/third_party/move/tools/move-package/src/compilation/build_plan.rs index efc72d9a1435a..a0441be7aa2f8 100644 --- a/third_party/move/tools/move-package/src/compilation/build_plan.rs +++ b/third_party/move/tools/move-package/src/compilation/build_plan.rs @@ -18,9 +18,10 @@ use move_compiler::{ diagnostics::{report_diagnostics_to_color_buffer, report_warnings, FilesSourceText}, Compiler, }; +use move_compiler_v2::external_checks::ExternalChecks; use move_model::model; use petgraph::algo::toposort; -use std::{collections::BTreeSet, io::Write, path::Path}; +use std::{collections::BTreeSet, io::Write, path::Path, sync::Arc}; #[cfg(feature = "evm-backend")] use { colored::Colorize, @@ -126,6 +127,7 @@ impl BuildPlan { self.compile_with_driver( writer, config, + vec![], |compiler| { let (files, units) = compiler.build_and_report()?; Ok((files, units, None)) @@ -135,15 +137,19 @@ impl BuildPlan { .map(|(package, _)| package) } - /// Compilation process does not exit even if warnings/failures are encountered + /// Compilation process does not exit even if warnings/failures are encountered. + /// External checks on Move code can be provided via `external_checks`, these checks + /// are only run when using the compiler v2. pub fn compile_no_exit( &self, config: &CompilerConfig, + external_checks: Vec>, writer: &mut W, ) -> Result<(CompiledPackage, Option)> { self.compile_with_driver( writer, config, + external_checks, |compiler| { let (files, units_res) = compiler.build()?; match units_res { @@ -169,6 +175,7 @@ impl BuildPlan { &self, writer: &mut W, config: &CompilerConfig, + external_checks: Vec>, compiler_driver_v1: impl FnMut(Compiler) -> CompilerDriverResult, compiler_driver_v2: impl FnMut(move_compiler_v2::Options) -> CompilerDriverResult, ) -> Result<(CompiledPackage, Option)> { @@ -213,6 +220,7 @@ impl BuildPlan { root_package.clone(), transitive_dependencies, config, + external_checks, &self.resolution_graph, compiler_driver_v1, compiler_driver_v2, 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 f5a1389ffbb25..31fb59bd73bef 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 @@ -27,7 +27,7 @@ use move_compiler::{ shared::{Flags, NamedAddressMap, NumericalAddress, PackagePaths}, Compiler, }; -use move_compiler_v2::Experiment; +use move_compiler_v2::{external_checks::ExternalChecks, Experiment}; use move_docgen::{Docgen, DocgenOptions}; use move_model::{ model::GlobalEnv, options::ModelBuilderOptions, @@ -39,6 +39,7 @@ use std::{ collections::{BTreeMap, BTreeSet}, io::Write, path::{Path, PathBuf}, + sync::Arc, }; use termcolor::{ColorChoice, StandardStream}; @@ -544,6 +545,7 @@ impl CompiledPackage { /* whether source is available */ bool, )>, config: &CompilerConfig, + external_checks: Vec>, resolution_graph: &ResolvedGraph, mut compiler_driver_v1: impl FnMut(Compiler) -> CompilerDriverResult, mut compiler_driver_v2: impl FnMut(move_compiler_v2::Options) -> CompilerDriverResult, @@ -696,6 +698,7 @@ impl CompiledPackage { compiler_version: Some(version), compile_test_code: flags.keep_testing_functions(), experiments: config.experiments.clone(), + external_checks, ..Default::default() }; options = options.set_experiment(Experiment::ATTACH_COMPILED_MODULE, true); diff --git a/third_party/move/tools/move-package/src/lib.rs b/third_party/move/tools/move-package/src/lib.rs index 74e92af81eecf..75f7d112f1eae 100644 --- a/third_party/move/tools/move-package/src/lib.rs +++ b/third_party/move/tools/move-package/src/lib.rs @@ -22,6 +22,7 @@ use clap::*; use move_compiler::{ command_line::SKIP_ATTRIBUTE_CHECKS, shared::known_attributes::KnownAttribute, }; +use move_compiler_v2::external_checks::ExternalChecks; use move_core_types::account_address::AccountAddress; use move_model::{ metadata::{CompilerVersion, LanguageVersion}, @@ -34,6 +35,7 @@ use std::{ fmt, io::Write, path::{Path, PathBuf}, + sync::Arc, }; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] @@ -199,15 +201,18 @@ impl BuildConfig { /// Compile the package at `path` or the containing Move package. Do not exit process on warning /// or failure. + /// External checks on Move code can be provided, these are only run if compiler v2 is used. pub fn compile_package_no_exit( self, path: &Path, + external_checks: Vec>, writer: &mut W, ) -> Result<(CompiledPackage, Option)> { let config = self.compiler_config.clone(); // Need clone because of mut self let resolved_graph = self.resolution_graph_for_package(path, writer)?; let mutx = PackageLock::lock(); - let ret = BuildPlan::create(resolved_graph)?.compile_no_exit(&config, writer); + let ret = + BuildPlan::create(resolved_graph)?.compile_no_exit(&config, external_checks, writer); mutx.unlock(); ret } diff --git a/third_party/move/tools/move-package/tests/test_runner.rs b/third_party/move/tools/move-package/tests/test_runner.rs index 43f831e63838d..937a5313cb19d 100644 --- a/third_party/move/tools/move-package/tests/test_runner.rs +++ b/third_party/move/tools/move-package/tests/test_runner.rs @@ -82,7 +82,7 @@ fn run_test_impl( .into()) }, (true, _) => match BuildPlan::create(resolved_package) - .and_then(|bp| bp.compile_no_exit(&compiler_config.clone(), &mut Vec::new())) + .and_then(|bp| bp.compile_no_exit(&compiler_config.clone(), vec![], &mut vec![])) { Ok((mut pkg, _)) => { pkg.compiled_package_info.source_digest =