From 8a51f84d6dd9d0114fe83a42b5665851e2abb8f4 Mon Sep 17 00:00:00 2001 From: Teng Zhang Date: Tue, 26 Nov 2024 10:25:44 -0800 Subject: [PATCH 1/4] add move-1 flag --- crates/aptos/CHANGELOG.md | 3 ++- crates/aptos/src/common/types.rs | 22 ++++++++++++++++------ crates/aptos/src/move_tool/mod.rs | 1 - 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/crates/aptos/CHANGELOG.md b/crates/aptos/CHANGELOG.md index 3bff5c8b2bc12..0a6c48449559d 100644 --- a/crates/aptos/CHANGELOG.md +++ b/crates/aptos/CHANGELOG.md @@ -5,8 +5,9 @@ All notable changes to the Aptos CLI will be captured in this file. This project # Unreleased - Add flag `--benchmark` to `aptos move prove`, which allows to benchmark verification times of individual functions in a package. - Add flag `--only ` to `aptos move prove`, which allows to scope verification to a function. - - Fix `aptos init` to show the explorer link for accounts when account is already created on chain instead of prompting to fund the account. +- Set Compiler v2 as the default compiler and Move 2 as the default language version except for `aptos governance`. +- Add new `--move-1` flag to use Compiler v1 and Move 1. ## [5.1.0] - 2024/12/13 - More optimizations are now default for compiler v2. diff --git a/crates/aptos/src/common/types.rs b/crates/aptos/src/common/types.rs index 1eb9d8826ffa9..9667831e814f5 100644 --- a/crates/aptos/src/common/types.rs +++ b/crates/aptos/src/common/types.rs @@ -48,7 +48,7 @@ use aptos_types::{ }; use aptos_vm_types::output::VMOutput; use async_trait::async_trait; -use clap::{Parser, ValueEnum}; +use clap::{ArgGroup, Parser, ValueEnum}; use hex::FromHexError; use indoc::indoc; use move_core_types::{ @@ -1110,6 +1110,7 @@ impl FromStr for OptimizationLevel { /// Options for compiling a move package dir #[derive(Debug, Clone, Parser)] +#[clap(group = ArgGroup::new("move-version").args(&["move_1", "move_2"]).required(false))] pub struct MovePackageDir { /// Path to a move package (the folder with a Move.toml file). Defaults to current directory. #[clap(long, value_parser)] @@ -1179,25 +1180,33 @@ pub struct MovePackageDir { /// ...or --compiler COMPILER_VERSION /// Specify the version of the compiler. - /// Defaults to `1`, unless `--move-2` is selected. + /// Defaults to the latest stable compiler version (at least 2) #[clap(long, value_parser = clap::value_parser!(CompilerVersion), alias = "compiler", + default_value = LATEST_STABLE_COMPILER_VERSION, default_value_if("move_2", "true", LATEST_STABLE_COMPILER_VERSION), + default_value_if("move_1", "true", "1"), verbatim_doc_comment)] pub compiler_version: Option, /// ...or --language LANGUAGE_VERSION /// Specify the language version to be supported. - /// Defaults to `1`, unless `--move-2` is selected. + /// Defaults to the latest stable language version (at least 2) #[clap(long, value_parser = clap::value_parser!(LanguageVersion), alias = "language", + default_value = LATEST_STABLE_LANGUAGE_VERSION, default_value_if("move_2", "true", LATEST_STABLE_LANGUAGE_VERSION), + default_value_if("move_1", "true", "1"), verbatim_doc_comment)] pub language_version: Option, /// Select bytecode, language, and compiler versions to support the latest Move 2. #[clap(long, verbatim_doc_comment)] pub move_2: bool, + + /// Select bytecode, language, and compiler versions for Move 1. + #[clap(long, verbatim_doc_comment)] + pub move_1: bool, } impl Default for MovePackageDir { @@ -1216,11 +1225,12 @@ impl MovePackageDir { override_std: None, skip_fetch_latest_git_deps: true, bytecode_version: None, - compiler_version: None, - language_version: None, + compiler_version: Some(CompilerVersion::latest_stable()), + language_version: Some(LanguageVersion::latest_stable()), skip_attribute_checks: false, check_test_code: false, - move_2: false, + move_2: true, + move_1: false, optimize: None, experiments: vec![], } diff --git a/crates/aptos/src/move_tool/mod.rs b/crates/aptos/src/move_tool/mod.rs index 18511fe23680a..d42dcbbf47db9 100644 --- a/crates/aptos/src/move_tool/mod.rs +++ b/crates/aptos/src/move_tool/mod.rs @@ -908,7 +908,6 @@ impl IncludedArtifacts { experiments.append(&mut move_options.experiments.clone()); experiments.append(&mut more_experiments); - // TODO(#14441): Remove `None |` here when we update default CompilerVersion if matches!( move_options.compiler_version, Option::None | Some(CompilerVersion::V1) From 03bd97ed5563e6a409b65d3f08b1e671faf34187 Mon Sep 17 00:00:00 2001 From: Teng Zhang Date: Mon, 6 Jan 2025 12:04:25 -0800 Subject: [PATCH 2/4] governance --- crates/aptos/src/governance/mod.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/crates/aptos/src/governance/mod.rs b/crates/aptos/src/governance/mod.rs index 48ed43d422d8b..237216713f641 100644 --- a/crates/aptos/src/governance/mod.rs +++ b/crates/aptos/src/governance/mod.rs @@ -915,17 +915,29 @@ pub struct CompileScriptFunction { #[clap(long, default_value_if("move_2", "true", "7"))] pub bytecode_version: Option, + /// Specify the version of the compiler. + /// Defaults to the latest stable compiler version (at least 2) #[clap(long, value_parser = clap::value_parser!(CompilerVersion), - default_value_if("move_2", "true", LATEST_STABLE_COMPILER_VERSION))] + default_value = LATEST_STABLE_COMPILER_VERSION, + default_value_if("move_2", "true", LATEST_STABLE_COMPILER_VERSION), + default_value_if("move_1", "true", "1"),)] pub compiler_version: Option, + /// Specify the language version to be supported. + /// Defaults to the latest stable language version (at least 2) #[clap(long, value_parser = clap::value_parser!(LanguageVersion), - default_value_if("move_2", "true", LATEST_STABLE_LANGUAGE_VERSION))] + default_value = LATEST_STABLE_LANGUAGE_VERSION, + default_value_if("move_2", "true", LATEST_STABLE_LANGUAGE_VERSION), + default_value_if("move_1", "true", "1"),)] pub language_version: Option, /// Select bytecode, language, compiler for Move 2 - #[clap(long)] + #[clap(long, default_value_t = true)] pub move_2: bool, + + /// Select bytecode, language, and compiler versions for Move 1. + #[clap(long, default_value_t = false)] + pub move_1: bool, } impl CompileScriptFunction { From 174879231e755f15ddadd14e612bb440694c2053 Mon Sep 17 00:00:00 2001 From: Teng Zhang Date: Tue, 7 Jan 2025 00:30:06 -0800 Subject: [PATCH 3/4] set default as v2 --- crates/aptos/CHANGELOG.md | 2 +- crates/aptos/src/governance/mod.rs | 6 +++-- crates/aptos/src/move_tool/coverage.rs | 9 ++++++-- crates/aptos/src/move_tool/mod.rs | 32 +++++++++++++++++++------- 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/crates/aptos/CHANGELOG.md b/crates/aptos/CHANGELOG.md index 0a6c48449559d..ab9da71f870a0 100644 --- a/crates/aptos/CHANGELOG.md +++ b/crates/aptos/CHANGELOG.md @@ -6,7 +6,7 @@ All notable changes to the Aptos CLI will be captured in this file. This project - Add flag `--benchmark` to `aptos move prove`, which allows to benchmark verification times of individual functions in a package. - Add flag `--only ` to `aptos move prove`, which allows to scope verification to a function. - Fix `aptos init` to show the explorer link for accounts when account is already created on chain instead of prompting to fund the account. -- Set Compiler v2 as the default compiler and Move 2 as the default language version except for `aptos governance`. +- Set Compiler v2 as the default compiler and Move 2 as the default language version. - Add new `--move-1` flag to use Compiler v1 and Move 1. ## [5.1.0] - 2024/12/13 diff --git a/crates/aptos/src/governance/mod.rs b/crates/aptos/src/governance/mod.rs index 237216713f641..d43ff9bd443d7 100644 --- a/crates/aptos/src/governance/mod.rs +++ b/crates/aptos/src/governance/mod.rs @@ -983,8 +983,10 @@ impl CompileScriptFunction { &self.framework_package_args, prompt_options, self.bytecode_version, - self.language_version, - self.compiler_version, + self.language_version + .or_else(|| Some(LanguageVersion::latest_stable())), + self.compiler_version + .or_else(|| Some(CompilerVersion::latest_stable())), ) } } diff --git a/crates/aptos/src/move_tool/coverage.rs b/crates/aptos/src/move_tool/coverage.rs index 366b6bb9472f9..4a04b62bd9d15 100644 --- a/crates/aptos/src/move_tool/coverage.rs +++ b/crates/aptos/src/move_tool/coverage.rs @@ -16,6 +16,7 @@ use move_coverage::{ summary::summarize_inst_cov, }; use move_disassembler::disassembler::Disassembler; +use move_model::metadata::{CompilerVersion, LanguageVersion}; use move_package::{compilation::compiled_package::CompiledPackage, BuildConfig, CompilerConfig}; /// Display a coverage summary for all modules in a package @@ -175,8 +176,12 @@ fn compile_coverage( move_options.bytecode_version, move_options.language_version, ), - compiler_version: move_options.compiler_version, - language_version: move_options.language_version, + compiler_version: move_options + .compiler_version + .or_else(|| Some(CompilerVersion::latest_stable())), + language_version: move_options + .language_version + .or_else(|| Some(LanguageVersion::latest_stable())), experiments: experiments_from_opt_level(&move_options.optimize), }, ..Default::default() diff --git a/crates/aptos/src/move_tool/mod.rs b/crates/aptos/src/move_tool/mod.rs index d42dcbbf47db9..48eba29d53606 100644 --- a/crates/aptos/src/move_tool/mod.rs +++ b/crates/aptos/src/move_tool/mod.rs @@ -564,8 +564,14 @@ impl CliCommand<&'static str> for TestPackage { self.move_options.bytecode_version, self.move_options.language_version, ), - compiler_version: self.move_options.compiler_version, - language_version: self.move_options.language_version, + compiler_version: self + .move_options + .compiler_version + .or_else(|| Some(CompilerVersion::latest_stable())), + language_version: self + .move_options + .language_version + .or_else(|| Some(LanguageVersion::latest_stable())), experiments: experiments_from_opt_level(&self.move_options.optimize), }, ..Default::default() @@ -717,8 +723,12 @@ impl CliCommand<&'static str> for DocumentPackage { move_options.bytecode_version, move_options.language_version, ), - compiler_version: move_options.compiler_version, - language_version: move_options.language_version, + compiler_version: move_options + .compiler_version + .or_else(|| Some(CompilerVersion::latest_stable())), + language_version: move_options + .language_version + .or_else(|| Some(LanguageVersion::latest_stable())), skip_attribute_checks: move_options.skip_attribute_checks, check_test_code: move_options.check_test_code, known_attributes: extended_checks::get_all_attribute_names().clone(), @@ -899,8 +909,12 @@ impl IncludedArtifacts { let override_std = move_options.override_std.clone(); let bytecode_version = fix_bytecode_version(move_options.bytecode_version, move_options.language_version); - let compiler_version = move_options.compiler_version; - let language_version = move_options.language_version; + let compiler_version = move_options + .compiler_version + .or_else(|| Some(CompilerVersion::latest_stable())); + let language_version = move_options + .language_version + .or_else(|| Some(LanguageVersion::latest_stable())); let skip_attribute_checks = move_options.skip_attribute_checks; let check_test_code = move_options.check_test_code; let optimize = move_options.optimize.clone(); @@ -909,8 +923,10 @@ impl IncludedArtifacts { experiments.append(&mut more_experiments); if matches!( - move_options.compiler_version, - Option::None | Some(CompilerVersion::V1) + move_options + .compiler_version + .or_else(|| Some(CompilerVersion::latest_stable())), + Some(CompilerVersion::V1) ) { if !matches!(optimize, Option::None | Some(OptimizationLevel::Default)) { return Err(CliError::CommandArgumentError( From 38a1522b9a15fdf8beeeea956a8366008e9bb776 Mon Sep 17 00:00:00 2001 From: Teng Zhang Date: Tue, 7 Jan 2025 20:04:06 -0800 Subject: [PATCH 4/4] Update crates/aptos/src/move_tool/mod.rs Co-authored-by: Vineeth Kashyap --- crates/aptos/src/move_tool/mod.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/crates/aptos/src/move_tool/mod.rs b/crates/aptos/src/move_tool/mod.rs index 48eba29d53606..743a170eb7030 100644 --- a/crates/aptos/src/move_tool/mod.rs +++ b/crates/aptos/src/move_tool/mod.rs @@ -922,12 +922,7 @@ impl IncludedArtifacts { experiments.append(&mut move_options.experiments.clone()); experiments.append(&mut more_experiments); - if matches!( - move_options - .compiler_version - .or_else(|| Some(CompilerVersion::latest_stable())), - Some(CompilerVersion::V1) - ) { + if matches!(compiler_version, Some(CompilerVersion::V1)) { if !matches!(optimize, Option::None | Some(OptimizationLevel::Default)) { return Err(CliError::CommandArgumentError( "`--optimization-level`/`--optimize` flag is not compatible with Move Compiler V1"