From b6da4f70d78fa90e30e9d990624125ba8e0a42f1 Mon Sep 17 00:00:00 2001 From: Hao Xia Date: Mon, 19 Aug 2024 15:18:25 -0700 Subject: [PATCH 01/13] Add bytecode_deps to CompiledPackage --- aptos-move/framework/src/built_package.rs | 17 ++- .../src/compilation/compiled_package.rs | 141 ++++++++++-------- 2 files changed, 95 insertions(+), 63 deletions(-) diff --git a/aptos-move/framework/src/built_package.rs b/aptos-move/framework/src/built_package.rs index f6f2f85b9bc68..2b77730dfec53 100644 --- a/aptos-move/framework/src/built_package.rs +++ b/aptos-move/framework/src/built_package.rs @@ -209,10 +209,10 @@ pub fn build_model( let language_version = language_version.unwrap_or_default(); compiler_version.check_language_support(language_version)?; build_config.move_model_for_package(package_path, ModelConfig { - target_filter, - all_files_as_targets: false, - compiler_version, - language_version, + target_filter, + all_files_as_targets: false, + compiler_version, + language_version, }) } @@ -484,6 +484,15 @@ impl BuiltPackage { }, CompiledUnit::Script(_) => None, }) + .chain( + self.package + .bytecode_deps + .iter() + .map(|(name, address)| PackageDep { + account: address.into_inner(), + package_name: name.as_str().to_string(), + }), + ) .collect::>() .into_iter() .collect(); 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 22f30d92c00e3..bb034c3e3e77f 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 @@ -81,6 +81,8 @@ pub struct CompiledPackage { pub root_compiled_units: Vec, /// The output compiled bytecode for dependencies pub deps_compiled_units: Vec<(PackageName, CompiledUnitWithSource)>, + /// Bytecode dependencies of this compiled package + pub bytecode_deps: Vec<(PackageName, NumericalAddress)>, // Optional artifacts from compilation // @@ -198,6 +200,7 @@ impl OnDiskCompiledPackage { compiled_package_info: self.package.compiled_package_info.clone(), root_compiled_units, deps_compiled_units, + bytecode_deps: Vec::new(), // TODO compiled_docs, compiled_abis, }) @@ -628,72 +631,76 @@ impl CompiledPackage { let effective_language_version = config.language_version.unwrap_or_default(); effective_compiler_version.check_language_support(effective_language_version)?; - let (file_map, all_compiled_units, optional_global_env) = match config - .compiler_version - .unwrap_or_default() - { - CompilerVersion::V1 => { - let mut paths = src_deps; - paths.push(sources_package_paths.clone()); - let compiler = - Compiler::from_package_paths(paths, bytecode_deps, flags, &known_attributes); - compiler_driver_v1(compiler)? - }, - version @ CompilerVersion::V2_0 | version @ CompilerVersion::V2_1 => { - let to_str_vec = |ps: &[Symbol]| { - ps.iter() - .map(move |s| s.as_str().to_owned()) - .collect::>() - }; - let mut global_address_map = BTreeMap::new(); - for pack in std::iter::once(&sources_package_paths) - .chain(src_deps.iter()) - .chain(bytecode_deps.iter()) - { - for (name, val) in &pack.named_address_map { - if let Some(old) = global_address_map.insert(name.as_str().to_owned(), *val) - { - if old != *val { - let pack_name = pack - .name - .map(|s| s.as_str().to_owned()) - .unwrap_or_else(|| "".to_owned()); - bail!( + let (file_map, all_compiled_units, optional_global_env) = + match config.compiler_version.unwrap_or_default() { + CompilerVersion::V1 => { + let mut paths = src_deps; + paths.push(sources_package_paths.clone()); + let compiler = Compiler::from_package_paths( + paths, + bytecode_deps.clone(), + flags, + &known_attributes, + ); + compiler_driver_v1(compiler)? + }, + CompilerVersion::V2_0 => { + let to_str_vec = |ps: &[Symbol]| { + ps.iter() + .map(move |s| s.as_str().to_owned()) + .collect::>() + }; + let mut global_address_map = BTreeMap::new(); + for pack in std::iter::once(&sources_package_paths) + .chain(src_deps.iter()) + .chain(bytecode_deps.iter()) + { + for (name, val) in &pack.named_address_map { + if let Some(old) = + global_address_map.insert(name.as_str().to_owned(), *val) + { + if old != *val { + let pack_name = pack + .name + .map(|s| s.as_str().to_owned()) + .unwrap_or_else(|| "".to_owned()); + bail!( "found remapped address alias `{}` (`{} != {}`) in package `{}`\ , please use unique address aliases across dependencies", name, old, val, pack_name ) + } } } } - } - let mut options = move_compiler_v2::Options { - sources: sources_package_paths - .paths - .iter() - .map(|path| path.as_str().to_owned()) - .collect(), - sources_deps: src_deps.iter().flat_map(|x| to_str_vec(&x.paths)).collect(), - dependencies: bytecode_deps - .iter() - .flat_map(|x| to_str_vec(&x.paths)) - .collect(), - named_address_mapping: global_address_map - .into_iter() - .map(|(k, v)| format!("{}={}", k, v)) - .collect(), - skip_attribute_checks, - known_attributes: known_attributes.clone(), - language_version: Some(effective_language_version), - compiler_version: Some(version), - compile_test_code: flags.keep_testing_functions(), - experiments: config.experiments.clone(), - ..Default::default() - }; - options = options.set_experiment(Experiment::ATTACH_COMPILED_MODULE, true); - compiler_driver_v2(options)? - }, - }; + let mut options = move_compiler_v2::Options { + sources: sources_package_paths + .paths + .iter() + .map(|path| path.as_str().to_owned()) + .collect(), + sources_deps: src_deps.iter().flat_map(|x| to_str_vec(&x.paths)).collect(), + dependencies: bytecode_deps + .iter() + .flat_map(|x| to_str_vec(&x.paths)) + .collect(), + named_address_mapping: global_address_map + .into_iter() + .map(|(k, v)| format!("{}={}", k, v)) + .collect(), + skip_attribute_checks, + known_attributes: known_attributes.clone(), + language_version: Some(effective_language_version), + compile_test_code: flags.keep_testing_functions(), + ..Default::default() + }; + for experiment in &config.experiments { + options = options.set_experiment(experiment, true) + } + options = options.set_experiment(Experiment::ATTACH_COMPILED_MODULE, true); + compiler_driver_v2(options)? + }, + }; let mut root_compiled_units = vec![]; let mut deps_compiled_units = vec![]; let obtain_package_name = @@ -799,6 +806,21 @@ impl CompiledPackage { }, root_compiled_units, deps_compiled_units, + bytecode_deps: bytecode_deps + .iter() + .map(|package| { + let name = package.name.unwrap(); + // Package address of the bytecode dep is required for publication. It must be + // provided as a named address in the dep package's Move.toml or through CLI arg + // `--named-addresses`, with the same name as the dep package. + let address = package.named_address_map.get(&name).ok_or(anyhow::anyhow!( + "address unknown for bytecode dependency {}", + name + )); + + address.map(|&a| (name, a)) + }) + .try_collect()?, compiled_docs, compiled_abis, }; @@ -878,6 +900,7 @@ impl CompiledPackage { root_path: under_path.join(root_package.as_str()), package: OnDiskPackage { compiled_package_info: self.compiled_package_info.clone(), + // TODO - bytecode deps dependencies: self .deps_compiled_units .iter() From bbe17fedeaf82854addf8d9b07c163a722e9d3ff Mon Sep 17 00:00:00 2001 From: Hao Xia Date: Mon, 19 Aug 2024 15:21:23 -0700 Subject: [PATCH 02/13] fmt --- aptos-move/framework/src/built_package.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/aptos-move/framework/src/built_package.rs b/aptos-move/framework/src/built_package.rs index 2b77730dfec53..55c1c6e62357d 100644 --- a/aptos-move/framework/src/built_package.rs +++ b/aptos-move/framework/src/built_package.rs @@ -208,12 +208,15 @@ pub fn build_model( let compiler_version = compiler_version.unwrap_or_default(); let language_version = language_version.unwrap_or_default(); compiler_version.check_language_support(language_version)?; - build_config.move_model_for_package(package_path, ModelConfig { + build_config.move_model_for_package( + package_path, + ModelConfig { target_filter, all_files_as_targets: false, compiler_version, language_version, - }) + }, + ) } impl BuiltPackage { From 1e9024282c70e97732e2ebe704f09c2ea5c329ca Mon Sep 17 00:00:00 2001 From: Hao Xia Date: Mon, 19 Aug 2024 15:33:39 -0700 Subject: [PATCH 03/13] error message --- .../move-package/src/compilation/compiled_package.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 bb034c3e3e77f..17079470aa0bc 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 @@ -810,11 +810,11 @@ impl CompiledPackage { .iter() .map(|package| { let name = package.name.unwrap(); - // Package address of the bytecode dep is required for publication. It must be - // provided as a named address in the dep package's Move.toml or through CLI arg - // `--named-addresses`, with the same name as the dep package. + // Package address of the bytecode dep is required for publication. let address = package.named_address_map.get(&name).ok_or(anyhow::anyhow!( - "address unknown for bytecode dependency {}", + "address unknown for bytecode dependency {}. It must be provided as a named \ + address in the dependency's Move.toml or through CLI arg --named-addresses, \ + with name {0}", name )); From 77bd0750132ea80e0277b1011364f6637f118190 Mon Sep 17 00:00:00 2001 From: Zekun Wang Date: Wed, 9 Oct 2024 05:09:27 -0400 Subject: [PATCH 04/13] fixed issue --- .../src/compilation/compiled_package.rs | 74 ++++++++++++++----- 1 file changed, 54 insertions(+), 20 deletions(-) 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 17079470aa0bc..5007cedc2a4c6 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 @@ -11,7 +11,7 @@ use crate::{ }, Architecture, BuildConfig, CompilerConfig, CompilerVersion, }; -use anyhow::{bail, ensure, Result}; +use anyhow::{bail, ensure, Context, Result}; use colored::Colorize; use itertools::{Either, Itertools}; use move_abigen::{Abigen, AbigenOptions}; @@ -102,6 +102,7 @@ pub struct OnDiskPackage { pub compiled_package_info: CompiledPackageInfo, /// Dependency names for this package. pub dependencies: Vec, + pub bytecode_deps: Vec, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -155,6 +156,21 @@ impl OnDiskCompiledPackage { deps_compiled_units.push((dep_name, self.decode_unit(dep_name, &bytecode_path)?)) } } + let mut bytecode_deps = vec![]; + for dep_name in self.package.bytecode_deps.iter().copied() { + let addr = self + .package + .compiled_package_info + .address_alias_instantiation + .get(&dep_name) + .ok_or_else(|| { + anyhow::anyhow!( + "Dependency {} not found in address alias instantiation", + dep_name + ) + })?; + bytecode_deps.push((dep_name, NumericalAddress::from_account_address(*addr))); + } let docs_path = self .root_path @@ -200,7 +216,7 @@ impl OnDiskCompiledPackage { compiled_package_info: self.package.compiled_package_info.clone(), root_compiled_units, deps_compiled_units, - bytecode_deps: Vec::new(), // TODO + bytecode_deps, compiled_docs, compiled_abis, }) @@ -644,7 +660,7 @@ impl CompiledPackage { ); compiler_driver_v1(compiler)? }, - CompilerVersion::V2_0 => { + CompilerVersion::V2_0 | CompilerVersion::V2_1 => { let to_str_vec = |ps: &[Symbol]| { ps.iter() .map(move |s| s.as_str().to_owned()) @@ -798,29 +814,41 @@ impl CompiledPackage { }; let compiled_package = CompiledPackage { - compiled_package_info: CompiledPackageInfo { - package_name: resolved_package.source_package.package.name, - address_alias_instantiation: resolved_package.resolution_table, - source_digest: Some(resolved_package.source_digest), - build_flags: resolution_graph.build_options.clone(), - }, root_compiled_units, deps_compiled_units, bytecode_deps: bytecode_deps .iter() - .map(|package| { + .flat_map(|package| { let name = package.name.unwrap(); - // Package address of the bytecode dep is required for publication. - let address = package.named_address_map.get(&name).ok_or(anyhow::anyhow!( - "address unknown for bytecode dependency {}. It must be provided as a named \ - address in the dependency's Move.toml or through CLI arg --named-addresses, \ - with name {0}", - name - )); - - address.map(|&a| (name, a)) + let pkg_path = package.paths.first().unwrap(); + // Read the bytecode file + let mut bytecode = Vec::new(); + std::fs::File::open(&pkg_path.to_string()) + .context(format!("Failed to open bytecode file for {}", pkg_path)) + .and_then(|mut file| { + // read contents of the file into bytecode + std::io::Read::read_to_end(&mut file, &mut bytecode).context(format!("Failed to read bytecode file {}", pkg_path)) + }) + .and_then(|_| { + CompiledModule::deserialize(&bytecode).context(format!( + "Failed to deserialize bytecode file for {}", + name + )) + }) + .map(|module| { + ( + name, + NumericalAddress::from_account_address(*module.self_addr()), + ) + }) }) .try_collect()?, + compiled_package_info: CompiledPackageInfo { + package_name: resolved_package.source_package.package.name, + address_alias_instantiation: resolved_package.resolution_table, + source_digest: Some(resolved_package.source_digest), + build_flags: resolution_graph.build_options.clone(), + }, compiled_docs, compiled_abis, }; @@ -900,7 +928,6 @@ impl CompiledPackage { root_path: under_path.join(root_package.as_str()), package: OnDiskPackage { compiled_package_info: self.compiled_package_info.clone(), - // TODO - bytecode deps dependencies: self .deps_compiled_units .iter() @@ -908,6 +935,13 @@ impl CompiledPackage { .collect::>() .into_iter() .collect(), + bytecode_deps: self + .bytecode_deps + .iter() + .map(|(package_name, _)| *package_name) + .collect::>() + .into_iter() + .collect(), }, }; From 2eef9d3e8c1091d8f270083b48759d6ba591c317 Mon Sep 17 00:00:00 2001 From: Zekun Wang Date: Wed, 9 Oct 2024 05:12:27 -0400 Subject: [PATCH 05/13] fixed issue --- .../src/compilation/compiled_package.rs | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) 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 5007cedc2a4c6..ed30fc56ef9d4 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 @@ -820,27 +820,29 @@ impl CompiledPackage { .iter() .flat_map(|package| { let name = package.name.unwrap(); - let pkg_path = package.paths.first().unwrap(); - // Read the bytecode file - let mut bytecode = Vec::new(); - std::fs::File::open(&pkg_path.to_string()) - .context(format!("Failed to open bytecode file for {}", pkg_path)) - .and_then(|mut file| { - // read contents of the file into bytecode - std::io::Read::read_to_end(&mut file, &mut bytecode).context(format!("Failed to read bytecode file {}", pkg_path)) - }) - .and_then(|_| { - CompiledModule::deserialize(&bytecode).context(format!( - "Failed to deserialize bytecode file for {}", - name - )) - }) - .map(|module| { - ( - name, - NumericalAddress::from_account_address(*module.self_addr()), - ) - }) + package.paths.iter().map(move |pkg_path| { + // Read the bytecode file + let mut bytecode = Vec::new(); + std::fs::File::open(&pkg_path.to_string()) + .context(format!("Failed to open bytecode file for {}", pkg_path)) + .and_then(|mut file| { + // read contents of the file into bytecode + std::io::Read::read_to_end(&mut file, &mut bytecode) + .context(format!("Failed to read bytecode file {}", pkg_path)) + }) + .and_then(|_| { + CompiledModule::deserialize(&bytecode).context(format!( + "Failed to deserialize bytecode file for {}", + name + )) + }) + .map(|module| { + ( + name, + NumericalAddress::from_account_address(*module.self_addr()), + ) + }) + }) }) .try_collect()?, compiled_package_info: CompiledPackageInfo { From 1aa7b3a73ccf51c44e4fed53559d73f1ad718456 Mon Sep 17 00:00:00 2001 From: Zekun Wang Date: Thu, 10 Oct 2024 03:32:28 -0400 Subject: [PATCH 06/13] refactor --- .../src/compilation/compiled_package.rs | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) 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 ed30fc56ef9d4..b3d2f27b0641b 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 @@ -821,27 +821,7 @@ impl CompiledPackage { .flat_map(|package| { let name = package.name.unwrap(); package.paths.iter().map(move |pkg_path| { - // Read the bytecode file - let mut bytecode = Vec::new(); - std::fs::File::open(&pkg_path.to_string()) - .context(format!("Failed to open bytecode file for {}", pkg_path)) - .and_then(|mut file| { - // read contents of the file into bytecode - std::io::Read::read_to_end(&mut file, &mut bytecode) - .context(format!("Failed to read bytecode file {}", pkg_path)) - }) - .and_then(|_| { - CompiledModule::deserialize(&bytecode).context(format!( - "Failed to deserialize bytecode file for {}", - name - )) - }) - .map(|module| { - ( - name, - NumericalAddress::from_account_address(*module.self_addr()), - ) - }) + get_module_addr(name, pkg_path.as_str()).map(|addr| (name, addr)) }) }) .try_collect()?, @@ -1194,3 +1174,23 @@ pub fn build_and_report_no_exit_v2_driver( Some(env), )) } + +/// Returns the address of the module +fn get_module_addr(pkg_name: Symbol, pkg_path: &str) -> Result { + // Read the bytecode file + let mut bytecode = Vec::new(); + std::fs::File::open(&pkg_path.to_string()) + .context(format!("Failed to open bytecode file for {}", pkg_path)) + .and_then(|mut file| { + // read contents of the file into bytecode + std::io::Read::read_to_end(&mut file, &mut bytecode) + .context(format!("Failed to read bytecode file {}", pkg_path)) + }) + .and_then(|_| { + CompiledModule::deserialize(&bytecode).context(format!( + "Failed to deserialize bytecode file for {}", + pkg_name + )) + }) + .map(|module| NumericalAddress::from_account_address(*module.self_addr())) +} From dff6918fa0c826fb40a1389fcc63bbce2a3f78c3 Mon Sep 17 00:00:00 2001 From: Zekun Wang Date: Thu, 10 Oct 2024 04:02:22 -0400 Subject: [PATCH 07/13] bug fix --- .../src/compilation/compiled_package.rs | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) 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 b3d2f27b0641b..151c39fac7dea 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 @@ -158,18 +158,15 @@ impl OnDiskCompiledPackage { } let mut bytecode_deps = vec![]; for dep_name in self.package.bytecode_deps.iter().copied() { - let addr = self - .package - .compiled_package_info - .address_alias_instantiation - .get(&dep_name) - .ok_or_else(|| { - anyhow::anyhow!( - "Dependency {} not found in address alias instantiation", - dep_name - ) - })?; - bytecode_deps.push((dep_name, NumericalAddress::from_account_address(*addr))); + let bytecode_paths = self.get_compiled_units_paths(dep_name)?; + let mut addrs = BTreeSet::new(); + for bytecode_path in bytecode_paths { + let addr = get_module_addr(dep_name, bytecode_path.as_str())?; + addrs.insert(addr); + } + for addr in addrs { + bytecode_deps.push((dep_name, addr)); + } } let docs_path = self From 044d6904b098e31e1da33352afaaf72eacab872e Mon Sep 17 00:00:00 2001 From: Zekun Wang Date: Thu, 10 Oct 2024 04:47:52 -0400 Subject: [PATCH 08/13] resolve merge conflicts --- .../move-package/src/compilation/compiled_package.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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 151c39fac7dea..a065b3b058378 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 @@ -657,7 +657,7 @@ impl CompiledPackage { ); compiler_driver_v1(compiler)? }, - CompilerVersion::V2_0 | CompilerVersion::V2_1 => { + version @ CompilerVersion::V2_0 | version @ CompilerVersion::V2_1 => { let to_str_vec = |ps: &[Symbol]| { ps.iter() .map(move |s| s.as_str().to_owned()) @@ -704,12 +704,11 @@ impl CompiledPackage { skip_attribute_checks, known_attributes: known_attributes.clone(), language_version: Some(effective_language_version), + compiler_version: Some(version), compile_test_code: flags.keep_testing_functions(), + experiments: config.experiments.clone(), ..Default::default() }; - for experiment in &config.experiments { - options = options.set_experiment(experiment, true) - } options = options.set_experiment(Experiment::ATTACH_COMPILED_MODULE, true); compiler_driver_v2(options)? }, @@ -1176,7 +1175,7 @@ pub fn build_and_report_no_exit_v2_driver( fn get_module_addr(pkg_name: Symbol, pkg_path: &str) -> Result { // Read the bytecode file let mut bytecode = Vec::new(); - std::fs::File::open(&pkg_path.to_string()) + std::fs::File::open(pkg_path) .context(format!("Failed to open bytecode file for {}", pkg_path)) .and_then(|mut file| { // read contents of the file into bytecode From 2fb122b280fb1cb935ad97f2697bb04c2147bdbb Mon Sep 17 00:00:00 2001 From: Zekun Wang Date: Thu, 10 Oct 2024 04:55:01 -0400 Subject: [PATCH 09/13] lint --- aptos-move/framework/src/built_package.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/aptos-move/framework/src/built_package.rs b/aptos-move/framework/src/built_package.rs index 55c1c6e62357d..3f120349a6f04 100644 --- a/aptos-move/framework/src/built_package.rs +++ b/aptos-move/framework/src/built_package.rs @@ -208,15 +208,12 @@ pub fn build_model( let compiler_version = compiler_version.unwrap_or_default(); let language_version = language_version.unwrap_or_default(); compiler_version.check_language_support(language_version)?; - build_config.move_model_for_package( - package_path, - ModelConfig { - target_filter, - all_files_as_targets: false, - compiler_version, - language_version, - }, - ) + build_config.move_model_for_package(package_path, ModelConfig { + target_filter, + all_files_as_targets: false, + compiler_version, + language_version, + }) } impl BuiltPackage { From b3be8c5a0e738443045bd558dc6c408e4fe2003a Mon Sep 17 00:00:00 2001 From: Zekun Wang Date: Tue, 29 Oct 2024 00:13:45 -0400 Subject: [PATCH 10/13] resolve comments --- .../src/compilation/compiled_package.rs | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) 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 a065b3b058378..a961abbae1400 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 @@ -82,7 +82,7 @@ pub struct CompiledPackage { /// The output compiled bytecode for dependencies pub deps_compiled_units: Vec<(PackageName, CompiledUnitWithSource)>, /// Bytecode dependencies of this compiled package - pub bytecode_deps: Vec<(PackageName, NumericalAddress)>, + pub bytecode_deps: BTreeMap, // Optional artifacts from compilation // @@ -156,18 +156,6 @@ impl OnDiskCompiledPackage { deps_compiled_units.push((dep_name, self.decode_unit(dep_name, &bytecode_path)?)) } } - let mut bytecode_deps = vec![]; - for dep_name in self.package.bytecode_deps.iter().copied() { - let bytecode_paths = self.get_compiled_units_paths(dep_name)?; - let mut addrs = BTreeSet::new(); - for bytecode_path in bytecode_paths { - let addr = get_module_addr(dep_name, bytecode_path.as_str())?; - addrs.insert(addr); - } - for addr in addrs { - bytecode_deps.push((dep_name, addr)); - } - } let docs_path = self .root_path @@ -213,7 +201,8 @@ impl OnDiskCompiledPackage { compiled_package_info: self.package.compiled_package_info.clone(), root_compiled_units, deps_compiled_units, - bytecode_deps, + // TODO: support bytecode deps + bytecode_deps: BTreeMap::new(), compiled_docs, compiled_abis, }) @@ -817,7 +806,7 @@ impl CompiledPackage { .flat_map(|package| { let name = package.name.unwrap(); package.paths.iter().map(move |pkg_path| { - get_module_addr(name, pkg_path.as_str()).map(|addr| (name, addr)) + get_addr_from_module_in_package(name, pkg_path.as_str()).map(|addr| (name, addr)) }) }) .try_collect()?, @@ -1172,7 +1161,7 @@ pub fn build_and_report_no_exit_v2_driver( } /// Returns the address of the module -fn get_module_addr(pkg_name: Symbol, pkg_path: &str) -> Result { +fn get_addr_from_module_in_package(pkg_name: Symbol, pkg_path: &str) -> Result { // Read the bytecode file let mut bytecode = Vec::new(); std::fs::File::open(pkg_path) From 1058dc2bfbaec7ac8d30dfadad7a87b17a3bd80e Mon Sep 17 00:00:00 2001 From: Zekun Wang Date: Tue, 29 Oct 2024 17:08:59 -0400 Subject: [PATCH 11/13] linter --- .../tools/move-package/src/compilation/compiled_package.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 a961abbae1400..f5a1389ffbb25 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 @@ -806,7 +806,8 @@ impl CompiledPackage { .flat_map(|package| { let name = package.name.unwrap(); package.paths.iter().map(move |pkg_path| { - get_addr_from_module_in_package(name, pkg_path.as_str()).map(|addr| (name, addr)) + get_addr_from_module_in_package(name, pkg_path.as_str()) + .map(|addr| (name, addr)) }) }) .try_collect()?, @@ -904,8 +905,8 @@ impl CompiledPackage { .collect(), bytecode_deps: self .bytecode_deps - .iter() - .map(|(package_name, _)| *package_name) + .keys() + .copied() .collect::>() .into_iter() .collect(), From 14b78ec5497032946135f7a8eb1ca08143b6ec44 Mon Sep 17 00:00:00 2001 From: Zekun Wang Date: Tue, 29 Oct 2024 20:06:06 -0400 Subject: [PATCH 12/13] config --- aptos-move/aptos-vm/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/aptos-move/aptos-vm/Cargo.toml b/aptos-move/aptos-vm/Cargo.toml index cc5fd9eb3f1bb..23eef8b310a60 100644 --- a/aptos-move/aptos-vm/Cargo.toml +++ b/aptos-move/aptos-vm/Cargo.toml @@ -63,6 +63,7 @@ aptos-aggregator = { workspace = true, features = ["testing"] } aptos-block-executor = { workspace = true, features = ["testing"] } aptos-language-e2e-tests = { workspace = true } aptos-types = { workspace = true, features = ["fuzzing"] } +move-vm-types = { workspace = true, features = ["testing"] } claims = { workspace = true } proptest = { workspace = true } rand_core = { workspace = true } From 5ab698896fa851aa7936ca80824ec98cabe4d1e6 Mon Sep 17 00:00:00 2001 From: Zekun Wang Date: Tue, 29 Oct 2024 20:50:34 -0400 Subject: [PATCH 13/13] sort --- aptos-move/aptos-vm/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aptos-move/aptos-vm/Cargo.toml b/aptos-move/aptos-vm/Cargo.toml index 23eef8b310a60..7d92c62b8006a 100644 --- a/aptos-move/aptos-vm/Cargo.toml +++ b/aptos-move/aptos-vm/Cargo.toml @@ -63,8 +63,8 @@ aptos-aggregator = { workspace = true, features = ["testing"] } aptos-block-executor = { workspace = true, features = ["testing"] } aptos-language-e2e-tests = { workspace = true } aptos-types = { workspace = true, features = ["fuzzing"] } -move-vm-types = { workspace = true, features = ["testing"] } claims = { workspace = true } +move-vm-types = { workspace = true, features = ["testing"] } proptest = { workspace = true } rand_core = { workspace = true }