@@ -305,13 +305,25 @@ pub fn run_model_builder_with_options_and_compilation_flags<
305305 } ,
306306 } ;
307307
308- // Extract the module/script closure
308+ // Extract the module/script dependency closure
309309 let mut visited_modules = BTreeSet :: new ( ) ;
310+ // Extract the module dependency closure for the vector module
311+ let mut vector_and_its_dependencies = BTreeSet :: new ( ) ;
312+ let mut seen_vector = false ;
310313 for ( _, mident, mdef) in & expansion_ast. modules {
311314 let src_file_hash = mdef. loc . file_hash ( ) ;
312315 if !dep_files. contains ( & src_file_hash) {
313316 collect_related_modules_recursive ( mident, & expansion_ast. modules , & mut visited_modules) ;
314317 }
318+ if !seen_vector && is_vector ( * mident) {
319+ seen_vector = true ;
320+ // Collect the vector module and its dependencies.
321+ collect_related_modules_recursive (
322+ mident,
323+ & expansion_ast. modules ,
324+ & mut vector_and_its_dependencies,
325+ ) ;
326+ }
315327 }
316328 for sdef in expansion_ast. scripts . values ( ) {
317329 let src_file_hash = sdef. loc . file_hash ( ) ;
@@ -330,14 +342,13 @@ pub fn run_model_builder_with_options_and_compilation_flags<
330342 let mut expansion_ast = {
331343 let E :: Program { modules, scripts } = expansion_ast;
332344 let modules = modules. filter_map ( |mident, mut mdef| {
333- // We need to always include the `vector` module (only for compiler v2) ,
345+ // For compiler v2, we need to always include the `vector` module and any of its dependencies ,
334346 // to handle cases of implicit usage.
335347 // E.g., index operation on a vector results in a call to `vector::borrow`.
336348 // TODO(#15483): consider refactoring code to avoid this special case.
337- let is_vector = mident. value . address . into_addr_bytes ( ) . into_inner ( )
338- == AccountAddress :: ONE
339- && mident. value . module . 0 . value . as_str ( ) == "vector" ;
340- ( is_vector && compile_via_model || visited_modules. contains ( & mident. value ) ) . then ( || {
349+ ( ( compile_via_model && vector_and_its_dependencies. contains ( & mident. value ) )
350+ || visited_modules. contains ( & mident. value ) )
351+ . then ( || {
341352 mdef. is_source_module = true ;
342353 mdef
343354 } )
@@ -416,6 +427,12 @@ pub fn run_model_builder_with_options_and_compilation_flags<
416427 }
417428}
418429
430+ /// Is `module_ident` the `vector` module?
431+ fn is_vector ( module_ident : ModuleIdent_ ) -> bool {
432+ module_ident. address . into_addr_bytes ( ) . into_inner ( ) == AccountAddress :: ONE
433+ && module_ident. module . 0 . value . as_str ( ) == "vector"
434+ }
435+
419436fn run_move_checker ( env : & mut GlobalEnv , program : E :: Program ) {
420437 let mut builder = ModelBuilder :: new ( env) ;
421438 for ( module_count, ( module_id, module_def) ) in program
0 commit comments