Skip to content

Commit

Permalink
[compiler-v2] Also include all dependencies of vector for compiler v2…
Browse files Browse the repository at this point in the history
… from #15528
  • Loading branch information
igor-aptos committed Dec 16, 2024
1 parent c5ac4e6 commit 4bc4bab
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions third_party/move/move-model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,25 @@ pub fn run_model_builder_with_options_and_compilation_flags<
},
};

// Extract the module/script closure
// Extract the module/script dependency closure
let mut visited_modules = BTreeSet::new();
// Extract the module dependency closure for the vector module
let mut vector_and_its_dependencies = BTreeSet::new();
let mut seen_vector = false;
for (_, mident, mdef) in &expansion_ast.modules {
let src_file_hash = mdef.loc.file_hash();
if !dep_files.contains(&src_file_hash) {
collect_related_modules_recursive(mident, &expansion_ast.modules, &mut visited_modules);
}
if !seen_vector && is_vector(*mident) {
seen_vector = true;
// Collect the vector module and its dependencies.
collect_related_modules_recursive(
mident,
&expansion_ast.modules,
&mut vector_and_its_dependencies,
);
}
}
for sdef in expansion_ast.scripts.values() {
let src_file_hash = sdef.loc.file_hash();
Expand All @@ -330,14 +342,13 @@ pub fn run_model_builder_with_options_and_compilation_flags<
let mut expansion_ast = {
let E::Program { modules, scripts } = expansion_ast;
let modules = modules.filter_map(|mident, mut mdef| {
// We need to always include the `vector` module (only for compiler v2),
// For compiler v2, we need to always include the `vector` module and any of its dependencies,
// to handle cases of implicit usage.
// E.g., index operation on a vector results in a call to `vector::borrow`.
// TODO(#15483): consider refactoring code to avoid this special case.
let is_vector = mident.value.address.into_addr_bytes().into_inner()
== AccountAddress::ONE
&& mident.value.module.0.value.as_str() == "vector";
(is_vector && compile_via_model || visited_modules.contains(&mident.value)).then(|| {
((compile_via_model && vector_and_its_dependencies.contains(&mident.value))
|| visited_modules.contains(&mident.value))
.then(|| {
mdef.is_source_module = true;
mdef
})
Expand Down Expand Up @@ -416,6 +427,12 @@ pub fn run_model_builder_with_options_and_compilation_flags<
}
}

/// Is `module_ident` the `vector` module?
fn is_vector(module_ident: ModuleIdent_) -> bool {
module_ident.address.into_addr_bytes().into_inner() == AccountAddress::ONE
&& module_ident.module.0.value.as_str() == "vector"
}

fn run_move_checker(env: &mut GlobalEnv, program: E::Program) {
let mut builder = ModelBuilder::new(env);
for (module_count, (module_id, module_def)) in program
Expand Down

0 comments on commit 4bc4bab

Please sign in to comment.