Skip to content

Commit

Permalink
[compiler-v2] Use latest_stable() versions of compiler and language…
Browse files Browse the repository at this point in the history
… wherever possible (#15213)
  • Loading branch information
vineethk authored Nov 7, 2024
1 parent dffdec5 commit f08cd51
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 36 deletions.
7 changes: 5 additions & 2 deletions aptos-move/aptos-e2e-comparison-testing/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,11 @@ impl Execution {
if compiled_cache.failed_packages_v2.contains(&package_info) {
v2_failed = true;
} else {
let compiled_res_v2 =
compile_package(package_dir, &package_info, Some(CompilerVersion::V2_0));
let compiled_res_v2 = compile_package(
package_dir,
&package_info,
Some(CompilerVersion::latest_stable()),
);
if let Ok(compiled_res) = compiled_res_v2 {
generate_compiled_blob(
&package_info,
Expand Down
9 changes: 6 additions & 3 deletions aptos-move/aptos-e2e-comparison-testing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ fn compile_aptos_packages(
for package in APTOS_PACKAGES {
let root_package_dir = aptos_commons_path.join(get_aptos_dir(package).unwrap());
let compiler_version = if v2_flag {
Some(CompilerVersion::V2_0)
Some(CompilerVersion::latest_stable())
} else {
Some(CompilerVersion::V1)
};
Expand Down Expand Up @@ -575,8 +575,11 @@ fn dump_and_compile_from_package_metadata(
return Err(anyhow::Error::msg("compilation failed at v1"));
}
if execution_mode.is_some_and(|mode| mode.is_v2_or_compare()) {
let package_v2 =
compile_package(root_package_dir, &package_info, Some(CompilerVersion::V2_0));
let package_v2 = compile_package(
root_package_dir,
&package_info,
Some(CompilerVersion::latest_stable()),
);
if let Ok(built_package) = package_v2 {
generate_compiled_blob(
&package_info,
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/e2e-move-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub(crate) fn build_package(
) -> anyhow::Result<BuiltPackage> {
let mut options = options;
if get_move_compiler_v2_from_env() {
options.compiler_version = Some(CompilerVersion::V2_0);
options.compiler_version = Some(CompilerVersion::latest_stable());
}
BuiltPackage::build(package_path.to_owned(), options)
}
Expand Down
9 changes: 6 additions & 3 deletions aptos-move/framework/src/built_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ use move_compiler::compiled_unit::{CompiledUnit, NamedCompiledModule};
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},
metadata::{
CompilerVersion, LanguageVersion, LATEST_STABLE_COMPILER_VERSION,
LATEST_STABLE_LANGUAGE_VERSION,
},
model::GlobalEnv,
};
use move_package::{
Expand Down Expand Up @@ -88,10 +91,10 @@ pub struct BuildOptions {
#[clap(long, default_value_if("move_2", "true", "7"))]
pub bytecode_version: Option<u32>,
#[clap(long, value_parser = clap::value_parser!(CompilerVersion),
default_value_if("move_2", "true", "2.0"))]
default_value_if("move_2", "true", LATEST_STABLE_COMPILER_VERSION))]
pub compiler_version: Option<CompilerVersion>,
#[clap(long, value_parser = clap::value_parser!(LanguageVersion),
default_value_if("move_2", "true", "2.1"))]
default_value_if("move_2", "true", LATEST_STABLE_LANGUAGE_VERSION))]
pub language_version: Option<LanguageVersion>,
#[clap(long)]
pub skip_attribute_checks: bool,
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/framework/tests/move_unit_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn run_tests_for_pkg(path_to_pkg: impl Into<String>) {
}
if get_move_compiler_v2_from_env() {
// Run test against v2 when MOVE_COMPILER_V2 is set
compiler_config.compiler_version = Some(CompilerVersion::V2_0);
compiler_config.compiler_version = Some(CompilerVersion::latest_stable());
build_config.compiler_config = compiler_config;
ok = run_move_unit_tests(
&pkg_path,
Expand Down
16 changes: 9 additions & 7 deletions crates/aptos/src/common/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ use hex::FromHexError;
use move_core_types::{
account_address::AccountAddress, language_storage::TypeTag, vm_status::VMStatus,
};
use move_model::metadata::{CompilerVersion, LanguageVersion};
use move_model::metadata::{
CompilerVersion, LanguageVersion, LATEST_STABLE_COMPILER_VERSION,
LATEST_STABLE_LANGUAGE_VERSION,
};
use move_package::source_package::std_lib::StdVersion;
use serde::{Deserialize, Serialize};
#[cfg(unix)]
Expand Down Expand Up @@ -1165,24 +1168,23 @@ pub struct MovePackageDir {

/// ...or --compiler COMPILER_VERSION
/// Specify the version of the compiler.
/// Defaults to `1`, or `2` if `--move-2` is selected.
/// Defaults to `1`, unless `--move-2` is selected.
#[clap(long, value_parser = clap::value_parser!(CompilerVersion),
alias = "compiler",
default_value_if("move_2", "true", "2.0"),
default_value_if("move_2", "true", LATEST_STABLE_COMPILER_VERSION),
verbatim_doc_comment)]
pub compiler_version: Option<CompilerVersion>,

/// ...or --language LANGUAGE_VERSION
/// Specify the language version to be supported.
/// Currently, defaults to `1`, unless `--move-2` is selected.
/// Defaults to `1`, unless `--move-2` is selected.
#[clap(long, value_parser = clap::value_parser!(LanguageVersion),
alias = "language",
default_value_if("move_2", "true", "2.1"),
default_value_if("move_2", "true", LATEST_STABLE_LANGUAGE_VERSION),
verbatim_doc_comment)]
pub language_version: Option<LanguageVersion>,

/// Select bytecode, language version, and compiler to support Move 2:
/// Same as `--bytecode-version=7 --language-version=2.1 --compiler-version=2.0`
/// Select bytecode, language, and compiler versions to support the latest Move 2.
#[clap(long, verbatim_doc_comment)]
pub move_2: bool,
}
Expand Down
9 changes: 6 additions & 3 deletions crates/aptos/src/governance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ use move_core_types::{
ident_str, language_storage::ModuleId, parser::parse_type_tag,
transaction_argument::TransactionArgument,
};
use move_model::metadata::{CompilerVersion, LanguageVersion};
use move_model::metadata::{
CompilerVersion, LanguageVersion, LATEST_STABLE_COMPILER_VERSION,
LATEST_STABLE_LANGUAGE_VERSION,
};
use reqwest::Url;
use serde::{Deserialize, Serialize};
use std::{
Expand Down Expand Up @@ -913,11 +916,11 @@ pub struct CompileScriptFunction {
pub bytecode_version: Option<u32>,

#[clap(long, value_parser = clap::value_parser!(CompilerVersion),
default_value_if("move_2", "true", "2.0"))]
default_value_if("move_2", "true", LATEST_STABLE_COMPILER_VERSION))]
pub compiler_version: Option<CompilerVersion>,

#[clap(long, value_parser = clap::value_parser!(LanguageVersion),
default_value_if("move_2", "true", "2.0"))]
default_value_if("move_2", "true", LATEST_STABLE_LANGUAGE_VERSION))]
pub language_version: Option<LanguageVersion>,

/// Select bytecode, language, compiler for Move 2
Expand Down
6 changes: 3 additions & 3 deletions crates/aptos/src/move_tool/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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_model::metadata::{CompilerVersion, LanguageVersion, LATEST_STABLE_LANGUAGE_VERSION};
use move_package::source_package::std_lib::StdVersion;
use std::{collections::BTreeMap, path::PathBuf};

Expand All @@ -30,10 +30,10 @@ pub struct LintPackage {

/// ...or --language LANGUAGE_VERSION
/// Specify the language version to be supported.
/// Currently, defaults to `2.0`.
/// Defaults to the latest stable language version.
#[clap(long, value_parser = clap::value_parser!(LanguageVersion),
alias = "language",
default_value = "2.0",
default_value = LATEST_STABLE_LANGUAGE_VERSION,
verbatim_doc_comment)]
pub language_version: Option<LanguageVersion>,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ impl ModuleGenerator {
) -> (FF::CompiledModule, SourceMap, Option<FF::FunctionHandle>) {
let options = module_env.env.get_extension::<Options>().expect("options");
let language_version = options.language_version.unwrap_or_default();
let compiler_version = options.compiler_version.unwrap_or(CompilerVersion::V2_0);
let compiler_version = options
.compiler_version
.unwrap_or(CompilerVersion::latest_stable());
let gen_access_specifiers = language_version.is_at_least(LanguageVersion::V2_0)
&& options.experiment_on(Experiment::GEN_ACCESS_SPECIFIERS);
let compilation_metadata = CompilationMetadata::new(compiler_version, language_version);
Expand Down
2 changes: 1 addition & 1 deletion third_party/move/move-compiler-v2/tests/testsuite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const TEST_CONFIGS: Lazy<BTreeMap<&str, TestConfig>> = Lazy::new(|| {
// Turn optimization on by default. Some configs below may turn it off.
.set_experiment(Experiment::OPTIMIZE, true)
.set_experiment(Experiment::OPTIMIZE_WAITING_FOR_COMPARE_TESTS, true)
.set_language_version(LanguageVersion::V2_1);
.set_language_version(LanguageVersion::latest_stable());
opts.testing = true;
let configs = vec![
// --- Tests for checking and ast processing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ struct TestConfig {
name: &'static str,
runner: fn(&Path) -> datatest_stable::Result<()>,
experiments: &'static [(&'static str, bool)],
language_version: LanguageVersion,
/// Run the tests with language version 1 (if true),
/// or with latest language version (if false).
is_lang_v1: bool,
/// Path substrings for tests to include. If empty, all tests are included.
include: &'static [&'static str],
/// Path substrings for tests to exclude (applied after the include filter).
Expand All @@ -44,7 +46,7 @@ const TEST_CONFIGS: &[TestConfig] = &[
(Experiment::OPTIMIZE_WAITING_FOR_COMPARE_TESTS, true),
(Experiment::ACQUIRES_CHECK, false),
],
language_version: LanguageVersion::V2_1,
is_lang_v1: false,
include: &[], // all tests except those excluded below
exclude: &["/operator_eval/"],
},
Expand All @@ -55,7 +57,7 @@ const TEST_CONFIGS: &[TestConfig] = &[
(Experiment::OPTIMIZE, false),
(Experiment::ACQUIRES_CHECK, false),
],
language_version: LanguageVersion::V2_1,
is_lang_v1: false,
include: &[], // all tests except those excluded below
exclude: &["/operator_eval/"],
},
Expand All @@ -68,23 +70,23 @@ const TEST_CONFIGS: &[TestConfig] = &[
(Experiment::AST_SIMPLIFY, false),
(Experiment::ACQUIRES_CHECK, false),
],
language_version: LanguageVersion::V2_1,
is_lang_v1: false,
include: &[], // all tests except those excluded below
exclude: &["/operator_eval/"],
},
TestConfig {
name: "operator-eval-lang-1",
runner: |p| run(p, get_config_by_name("operator-eval-lang-1")),
experiments: &[(Experiment::OPTIMIZE, true)],
language_version: LanguageVersion::V1,
is_lang_v1: true,
include: &["/operator_eval/"],
exclude: &[],
},
TestConfig {
name: "operator-eval-lang-2",
runner: |p| run(p, get_config_by_name("operator-eval-lang-2")),
experiments: &[(Experiment::OPTIMIZE, true)],
language_version: LanguageVersion::V2_1,
is_lang_v1: false,
include: &["/operator_eval/"],
exclude: &[],
},
Expand Down Expand Up @@ -134,7 +136,11 @@ fn run(path: &Path, config: TestConfig) -> datatest_stable::Result<()> {
// Enable access control file format generation for those tests
v2_experiments.push((Experiment::GEN_ACCESS_SPECIFIERS.to_string(), true))
}
let language_version = config.language_version;
let language_version = if config.is_lang_v1 {
LanguageVersion::V1
} else {
LanguageVersion::latest_stable()
};
let vm_test_config = if p.contains(SKIP_V1_COMPARISON_PATH) || move_test_debug() {
TestRunConfig::CompilerV2 {
language_version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn test_runner(path: &Path) -> datatest_stable::Result<()> {
named_address_mapping: vec!["std=0x1".to_string()],
..Options::default()
};
options = options.set_language_version(LanguageVersion::V2_1);
options = options.set_language_version(LanguageVersion::latest_stable());
let mut test_output = String::new();
let mut error_writer = Buffer::no_color();
match run_move_compiler_for_analysis(&mut error_writer, options) {
Expand Down
6 changes: 4 additions & 2 deletions third_party/move/move-model/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use std::{
};

const UNSTABLE_MARKER: &str = "-unstable";
pub const LATEST_STABLE_LANGUAGE_VERSION: &str = "2.1";
pub const LATEST_STABLE_COMPILER_VERSION: &str = "2.0";

pub static COMPILATION_METADATA_KEY: &[u8] = "compilation_metadata".as_bytes();

Expand Down Expand Up @@ -152,7 +154,7 @@ impl CompilerVersion {

/// The latest stable compiler version.
pub fn latest_stable() -> Self {
CompilerVersion::V2_0
CompilerVersion::from_str(LATEST_STABLE_COMPILER_VERSION).expect("valid version")
}

/// Check whether the compiler version supports the given language version,
Expand Down Expand Up @@ -256,7 +258,7 @@ impl LanguageVersion {

/// The latest stable language version.
pub fn latest_stable() -> Self {
LanguageVersion::V2_1
LanguageVersion::from_str(LATEST_STABLE_LANGUAGE_VERSION).expect("valid version")
}

/// Whether the language version is equal to greater than `ver`
Expand Down
2 changes: 1 addition & 1 deletion third_party/move/tools/move-package/tests/test_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fn check_or_update(
update_baseline: bool,
compiler_version: CompilerVersion,
) -> datatest_stable::Result<()> {
let exp_ext = if compiler_version == CompilerVersion::V2_0 {
let exp_ext = if compiler_version != CompilerVersion::V1 {
EXP_EXT_V2
} else {
EXP_EXT
Expand Down

0 comments on commit f08cd51

Please sign in to comment.