Avoid duplicate proactive recompilation

This commit is contained in:
udo
2026-07-18 22:23:44 +00:00
parent 33a7b00c78
commit 14f4920ae8
3 changed files with 53 additions and 13 deletions
+9 -8
View File
@@ -1039,20 +1039,21 @@ void compile_shared_unit(Request* context, SharedUnit* su)
compiler_mark_source_generation(context);
}
SharedUnit* compiler_get_shared_unit_internal(Request* context, String file_name, bool force_recompile)
SharedUnit* compiler_get_shared_unit_internal(Request* context, String file_name, bool force_recompile, bool retry_current_failure = false)
{
file_name = compiler_normalize_unit_path(context, file_name);
bool bypass_cached_result = force_recompile || retry_current_failure;
auto cached = compiler_reusable_cached_unit(context, file_name, force_recompile);
auto cached = compiler_reusable_cached_unit(context, file_name, bypass_cached_result);
if(cached)
return(cached);
compiler_release_cached_unit_if_needed(context, file_name, force_recompile);
compiler_release_cached_unit_if_needed(context, file_name, bypass_cached_result);
SharedUnit* su = new SharedUnit();
setup_unit_paths(context, su, file_name);
bool can_serve_stale = !force_recompile && compiler_unit_can_serve_stale_artifact(context, file_name);
bool can_serve_stale = !bypass_cached_result && compiler_unit_can_serve_stale_artifact(context, file_name);
int fdlock = compiler_open_lock_file(su->wasm_name + ".lock", "shared-unit:" + file_name, can_serve_stale);
if(fdlock == -2 && file_exists(su->wasm_name))
{
@@ -1076,7 +1077,7 @@ SharedUnit* compiler_get_shared_unit_internal(Request* context, String file_name
return(su);
}
cached = compiler_reusable_cached_unit(context, file_name, force_recompile);
cached = compiler_reusable_cached_unit(context, file_name, bypass_cached_result);
if(cached)
{
compiler_close_lock_file(fdlock);
@@ -1084,7 +1085,7 @@ SharedUnit* compiler_get_shared_unit_internal(Request* context, String file_name
return(cached);
}
compiler_release_cached_unit_if_needed(context, file_name, force_recompile);
compiler_release_cached_unit_if_needed(context, file_name, bypass_cached_result);
auto state = inspect_shared_unit_filesystem(context, su);
auto compile_check = shared_unit_compile_check(state);
@@ -1093,9 +1094,9 @@ SharedUnit* compiler_get_shared_unit_internal(Request* context, String file_name
bool do_recompile = force_recompile || compile_check.needs_compile;
if(do_recompile)
{
if(!force_recompile && retry_deferred)
if(!force_recompile && !retry_current_failure && retry_deferred)
compiler_restore_persisted_failure(su, state);
else if(!force_recompile && !jit_enabled)
else if(!force_recompile && !retry_current_failure && !jit_enabled)
{
compiler_restore_persisted_failure(su, state, "jit_compile_disabled");
if(trim(su->compiler_messages) == "")
+7 -4
View File
@@ -1245,14 +1245,14 @@ void proactive_compile_queue_push(StringList& queue, String file_name)
queue.push_back(file_name);
}
bool proactive_compile_unit(Request& context, String file_name, bool& source_missing, bool force_compile = false)
bool proactive_compile_unit(Request& context, String file_name, bool& source_missing, bool retry_current_failure = false)
{
bool failed = false;
String wasm_path = compiler_unit_wasm_path(&context, file_name);
if(force_compile || compiler_unit_needs_recompile(&context, file_name, &source_missing))
if(retry_current_failure || compiler_unit_needs_recompile(&context, file_name, &source_missing))
{
printf("(i) proactive compile %s\n", file_name.c_str());
auto su = force_compile ? compiler_get_shared_unit_internal(&context, file_name, true) : get_shared_unit(&context, file_name);
auto su = retry_current_failure ? compiler_get_shared_unit_internal(&context, file_name, false, true) : get_shared_unit(&context, file_name);
failed = !su || su->compiler_messages != "";
if(su)
wasm_path = su->wasm_name;
@@ -1383,7 +1383,10 @@ void run_proactive_compiler(u64 worker, u64 jobs)
if(retry_it != retry_after.end() && time_precise() < retry_it->second)
continue;
bool normal_compile = compiler_unit_needs_recompile(&background_context, file_name, &source_missing);
bool failed = proactive_compile_unit(background_context, file_name, source_missing, !normal_compile && !source_missing);
bool retry_due = retry_it != retry_after.end();
bool retry_current_failure = retry_due && !normal_compile && !source_missing &&
compiler_unit_needs_recompile(&background_context, file_name, 0, false, true, true);
bool failed = proactive_compile_unit(background_context, file_name, source_missing, retry_current_failure);
if(source_missing)
retry_after.erase(file_name);
else if(failed)