Skip to content

Commit

Permalink
fix #33338, race condition in triggering method compilation (#33839)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson authored and KristofferC committed Apr 11, 2020
1 parent 61950e0 commit 457a2d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1444,8 +1444,10 @@ void jl_generate_fptr(jl_code_instance_t *output)
break;
ucache = ucache->next;
}
if (codeinst->invoke)
if (codeinst->invoke) {
JL_UNLOCK(&codegen_lock);
return;
}
if (ucache != NULL) {
codeinst->specptr = ucache->specptr;
codeinst->rettype_const = ucache->rettype_const;
Expand Down
7 changes: 6 additions & 1 deletion src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ JL_DLLEXPORT jl_code_instance_t *jl_get_method_inferred(
}

JL_DLLEXPORT jl_code_instance_t *jl_set_method_inferred(
jl_method_instance_t *mi, jl_value_t *rettype,
jl_method_instance_t *mi JL_PROPAGATES_ROOT, jl_value_t *rettype,
jl_value_t *inferred_const, jl_value_t *inferred,
int32_t const_flags, size_t min_world, size_t max_world
/*, jl_array_t *edges, int absolute_max*/)
Expand Down Expand Up @@ -1833,6 +1833,7 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
{
jl_code_instance_t *codeinst;
codeinst = mi->cache;

while (codeinst) {
if (codeinst->min_world <= world && world <= codeinst->max_world && codeinst->invoke != NULL) {
return codeinst;
Expand Down Expand Up @@ -1869,6 +1870,7 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
}
}

JL_LOCK(&codegen_lock);
codeinst = mi->cache;
while (codeinst) {
if (codeinst->min_world <= world && world <= codeinst->max_world && codeinst->functionObjectsDecls.functionObject != NULL)
Expand All @@ -1893,17 +1895,20 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
jl_generate_fptr(ucache);
if (ucache->invoke != jl_fptr_sparam &&
ucache->invoke != jl_fptr_interpret_call) {
JL_UNLOCK(&codegen_lock);
return ucache;
}
jl_code_instance_t *codeinst = jl_set_method_inferred(mi, (jl_value_t*)jl_any_type, NULL, NULL,
0, 1, ~(size_t)0);
codeinst->specptr = ucache->specptr;
codeinst->rettype_const = ucache->rettype_const;
jl_atomic_store_release(&codeinst->invoke, ucache->invoke);
JL_UNLOCK(&codegen_lock);
return codeinst;
}
}

JL_UNLOCK(&codegen_lock);
jl_generate_fptr(codeinst);
return codeinst;
}
Expand Down

0 comments on commit 457a2d5

Please sign in to comment.