Skip to content

Commit

Permalink
fix cases where we need to codegen functions whose IR was deleted
Browse files Browse the repository at this point in the history
ref #16921
  • Loading branch information
JeffBezanson committed Jun 15, 2016
1 parent 7f44ee7 commit fcddefa
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
22 changes: 22 additions & 0 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,28 @@ extern "C" void jl_generate_fptr(jl_lambda_info_t *li)
JL_UNLOCK(&codegen_lock); // Might GC
}

extern "C" jl_lambda_info_t *jl_compile_for_dispatch(jl_lambda_info_t *li)
{
if (li->inInference || li->inCompile) {
// if inference is running on this function, get a copy
// of the function to be compiled without inference and run.
assert(li->def != NULL);
li = jl_get_unspecialized(li);
}
if (li->fptr == NULL) {
if (li->functionObjectsDecls.functionObject == NULL) {
if (li->code == jl_nothing)
jl_type_infer(li, 0);
if (li->functionObjectsDecls.functionObject == NULL && li->code == jl_nothing) {
li = jl_get_unspecialized(li);
}
jl_compile_linfo(li);
}
jl_generate_fptr(li);
}
return li;
}

// this generates llvm code for the lambda info
// (and adds it to the shadow module), but doesn't yet compile
// or generate object code for it
Expand Down
7 changes: 6 additions & 1 deletion src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ jl_lambda_info_t *jl_get_unspecialized(jl_lambda_info_t *method)
return method->unspecialized_ducttape;
if (method->sparam_syms != jl_emptysvec) {
if (def->needs_sparam_vals_ducttape == 2) {
jl_array_t *code = (jl_array_t*)method->code;
jl_array_t *code = (jl_array_t*)def->lambda_template->code;
JL_GC_PUSH1(&code);
if (!jl_typeis(code, jl_array_any_type))
code = jl_uncompress_ast(def->lambda_template, code);
Expand Down Expand Up @@ -1094,6 +1094,11 @@ jl_lambda_info_t *jl_get_specialization1(jl_tupletype_t *types)
if (sf->functionObjectsDecls.functionObject == NULL) {
if (sf->fptr != NULL)
goto not_found;
if (sf->code == jl_nothing) {
jl_type_infer(sf, 0);
if (sf->code == jl_nothing)
goto not_found;
}
jl_compile_linfo(sf);
}
JL_GC_POP();
Expand Down
2 changes: 1 addition & 1 deletion src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ STATIC_INLINE void jl_gc_wb(void *parent, void *ptr)
STATIC_INLINE void jl_gc_wb_back(void *ptr) // ptr isa jl_value_t*
{
// if ptr is old
if (__unlikely(jl_astaggedvalue(ptr)->bits.gc & 2)) {
if (__unlikely(jl_astaggedvalue(ptr)->bits.gc == 3)) {
jl_gc_queue_root((jl_value_t*)ptr);
}
}
Expand Down
17 changes: 4 additions & 13 deletions src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,18 @@ STATIC_INLINE jl_value_t *newstruct(jl_datatype_t *type)
return jv;
}

void jl_type_infer(jl_lambda_info_t *li, int force);
void jl_generate_fptr(jl_lambda_info_t *li);
void jl_compile_linfo(jl_lambda_info_t *li);
jl_lambda_info_t *jl_compile_for_dispatch(jl_lambda_info_t *li);

// invoke (compiling if necessary) the jlcall function pointer for a method
jl_lambda_info_t *jl_get_unspecialized(jl_lambda_info_t *method);
STATIC_INLINE jl_value_t *jl_call_method_internal(jl_lambda_info_t *meth, jl_value_t **args, uint32_t nargs)
{
jl_lambda_info_t *mfptr = meth;
if (__unlikely(meth->fptr == NULL)) {
if (meth->inInference || meth->inCompile) {
// if inference is running on this function, get a copy
// of the function to be compiled without inference and run.
assert(meth->def != NULL);
mfptr = jl_get_unspecialized(meth);
}
if (mfptr->fptr == NULL) {
jl_compile_linfo(mfptr);
jl_generate_fptr(mfptr);
}
}
if (__unlikely(mfptr->fptr == NULL))
mfptr = jl_compile_for_dispatch(mfptr);
if (mfptr->jlcall_api == 0)
return mfptr->fptr(args[0], &args[1], nargs-1);
else
Expand Down Expand Up @@ -204,7 +196,6 @@ jl_value_t *jl_interpret_toplevel_expr(jl_value_t *e);
jl_value_t *jl_static_eval(jl_value_t *ex, void *ctx_, jl_module_t *mod,
jl_lambda_info_t *li, int sparams, int allow_alloc);
int jl_is_toplevel_only_expr(jl_value_t *e);
void jl_type_infer(jl_lambda_info_t *li, int force);
jl_value_t *jl_call_scm_on_ast(char *funcname, jl_value_t *expr);

jl_lambda_info_t *jl_method_lookup_by_type(jl_methtable_t *mt, jl_tupletype_t *types,
Expand Down

0 comments on commit fcddefa

Please sign in to comment.