let run ~(package : Package_plan.t) ~(prepared : Build_session.prepared) ~(attempt : Build_attempt.t) ~removed_module_names = let root = package.root in let is_local = package.is_local in let config = package.compile_config in let build_state = prepared.build_state in let compile_assets = prepared.compile_assets in let artifact_dir = package.artifact_dir in let dirty_parse_paths = package.modules |> List.concat_map (fun (module_ : Source.module_) -> module_.implementation :: Option.to_list module_.interface) |> List.filter (fun path -> let forced = Hashtbl.mem attempt.preliminary_parses (Filename.concat root path) in match attempt.freshness_mode with | Build_attempt.Reuse_freshness -> forced | Build_attempt.Initialize_freshness -> Hashtbl.mem removed_module_names (Source.module_name path) || forced || Build_freshness.source_is_not_older_than_ast compile_assets ~root ~source_mtimes:package.source_mtimes path) in let dirty_parse_path_set = Hashtbl.create (List.length dirty_parse_paths) in List.iter (fun path -> Hashtbl.replace dirty_parse_path_set path ()) dirty_parse_paths; List.iter (fun path -> Filename.concat root path |> Platform.normalize_path_for_comparison |> Build_session.mark_parse_pending attempt.session) dirty_parse_paths; let dirty_modules = Hashtbl.create (List.length package.modules) in List.iter (fun module_ -> let paths = module_.Source.implementation :: Option.to_list module_.Source.interface in if List.exists (Hashtbl.mem dirty_parse_path_set) paths then ( Hashtbl.replace dirty_modules module_.Source.name (); let key = Source.compiler_basename config module_.Source.name in (Build_state.find_exn build_state key).compile_dirty <- true)) package.modules; let parse_paths_to_run = dirty_parse_paths |> List.filter (fun path -> not (Hashtbl.mem attempt.preliminary_parses (Filename.concat root path))) in let parsed = List.map2 (fun path result -> (path, Build_attempt.preliminary_parse result)) parse_paths_to_run (List.map (fun path -> (artifact_dir, config, path)) parse_paths_to_run |> Compiler_process.run_parses ?poll:attempt.process_poll) @ (dirty_parse_paths |> List.filter_map (fun path -> Hashtbl.find_opt attempt.preliminary_parses (Filename.concat root path) |> Option.map (fun result -> (path, result)))) in List.iter (fun (path, result) -> let absolute_path = Filename.concat root path in let pending_path = Platform.normalize_path_for_comparison absolute_path in let publish_successful_parse ~publish stderr = let stderr = if is_local then stderr else Compiler_process.retain_critical_external_warnings stderr in if stderr <> "" then ( attempt.had_warnings <- true; Compiler_log.append root stderr; attempt.parse_messages <- Build_attempt.Parse_warning stderr :: attempt.parse_messages); let ast = Build_artifacts.ast_path ~artifact_dir path in if is_local && stderr <> "" then Build_attempt.register_cleanup attempt (fun () -> Build_artifacts.invalidate_ast ast; Compile_assets.refresh_ast compile_assets ~source:absolute_path ~path:ast); (* A parse in this build that printed nothing published its AST on its worker. *) if publish then Compiler_process.publish_parse ~artifact_dir path; Compile_assets.refresh_ast compile_assets ~source:absolute_path ~path:ast; if is_local && stderr <> "" then Build_session.mark_parse_pending attempt.session pending_path else Build_session.clear_parse_pending attempt.session pending_path in match result with | Build_attempt.Parse_failed {stdout; stderr} -> Build_session.mark_parse_pending attempt.session pending_path; let output = stderr ^ stdout in Compiler_log.append root output; attempt.parse_messages <- Build_attempt.Parse_error output :: attempt.parse_messages | Build_attempt.Parsed_successfully {stderr} -> publish_successful_parse ~publish:(stderr <> "") stderr | Build_attempt.Use_existing_ast -> publish_successful_parse ~publish:false "") parsed; dirty_modules