Skip to content

Commit

Permalink
fix #36391, ensure anything precompiled ends up in output (#36451)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson authored Jun 29, 2020
1 parent 0b331c7 commit 223f656
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,8 @@ static void jl_serialize_value_(jl_serializer_state *s, jl_value_t *v, int as_li
int flags = validate << 0;
if (codeinst->invoke == jl_fptr_const_return)
flags |= 1 << 2;
if (codeinst->precompile)
flags |= 1 << 3;
write_uint8(s->s, flags);
jl_serialize_value(s, (jl_value_t*)codeinst->def);
if (validate || codeinst->min_world == 0) {
Expand Down Expand Up @@ -1494,6 +1496,8 @@ static jl_value_t *jl_deserialize_value_code_instance(jl_serializer_state *s, jl
jl_gc_wb(codeinst, codeinst->rettype);
if (constret)
codeinst->invoke = jl_fptr_const_return;
if ((flags >> 3) & 1)
codeinst->precompile = 1;
codeinst->next = (jl_code_instance_t*)jl_deserialize_value(s, (jl_value_t**)&codeinst->next);
jl_gc_wb(codeinst, codeinst->next);
if (validate)
Expand Down
6 changes: 5 additions & 1 deletion src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ JL_DLLEXPORT jl_code_instance_t *jl_new_codeinst(
}
codeinst->specptr.fptr = NULL;
codeinst->isspecsig = 0;
codeinst->precompile = 0;
codeinst->next = NULL;
JL_GC_POP();
return codeinst;
Expand Down Expand Up @@ -2089,6 +2090,7 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
jl_atomic_store_release(&codeinst->invoke, ucache->invoke);
jl_mi_cache_insert(mi, codeinst);
}
codeinst->precompile = 1;
return codeinst;
}

Expand Down Expand Up @@ -2194,9 +2196,11 @@ static void _generate_from_hint(jl_method_instance_t *mi, size_t world)
// don't bother generating output in the current environment
if (generating_llvm) {
jl_value_t *codeinst = jl_rettype_inferred(mi, world, world);
if (codeinst != jl_nothing)
if (codeinst != jl_nothing) {
if (((jl_code_instance_t*)codeinst)->invoke == jl_fptr_const_return)
return; // probably not a good idea to generate code
((jl_code_instance_t*)codeinst)->precompile = 1;
}
// If we are saving LLVM or native code, generate the LLVM IR so that it'll
// be included in the saved LLVM module.
// TODO: compilation is now stateless
Expand Down
9 changes: 5 additions & 4 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2356,7 +2356,7 @@ void jl_init_types(void) JL_GC_DISABLED
jl_code_instance_type =
jl_new_datatype(jl_symbol("CodeInstance"), core,
jl_any_type, jl_emptysvec,
jl_perm_symsvec(10,
jl_perm_symsvec(11,
"def",
"next",
"min_world",
Expand All @@ -2366,8 +2366,8 @@ void jl_init_types(void) JL_GC_DISABLED
"inferred",
//"edges",
//"absolute_max",
"isspecsig", "invoke", "specptr"), // function object decls
jl_svec(10,
"isspecsig", "precompile", "invoke", "specptr"), // function object decls
jl_svec(11,
jl_method_instance_type,
jl_any_type,
jl_ulong_type,
Expand All @@ -2378,6 +2378,7 @@ void jl_init_types(void) JL_GC_DISABLED
//jl_any_type,
//jl_bool_type,
jl_bool_type,
jl_bool_type,
jl_any_type, jl_any_type), // fptrs
0, 1, 1);
jl_svecset(jl_code_instance_type->types, 1, jl_code_instance_type);
Expand Down Expand Up @@ -2498,8 +2499,8 @@ void jl_init_types(void) JL_GC_DISABLED
jl_svecset(jl_methtable_type->types, 11, jl_uint8_type);
jl_svecset(jl_method_type->types, 13, jl_method_instance_type);
jl_svecset(jl_method_instance_type->types, 5, jl_code_instance_type);
jl_svecset(jl_code_instance_type->types, 8, jl_voidpointer_type);
jl_svecset(jl_code_instance_type->types, 9, jl_voidpointer_type);
jl_svecset(jl_code_instance_type->types, 10, jl_voidpointer_type);

jl_compute_field_offsets(jl_datatype_type);
jl_compute_field_offsets(jl_typename_type);
Expand Down
1 change: 1 addition & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ typedef struct _jl_code_instance_t {

// compilation state cache
uint8_t isspecsig; // if specptr is a specialized function signature for specTypes->rettype
uint8_t precompile; // if set, this will be added to the output system image
jl_callptr_t invoke; // jlcall entry point
jl_generic_specptr_t specptr; // private data for `jlcall entry point`
} jl_code_instance_t;
Expand Down
2 changes: 1 addition & 1 deletion src/precompile.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ static int precompile_enq_specialization_(jl_method_instance_t *mi, void *closur
!jl_ir_flag_inlineable((jl_array_t*)codeinst->inferred)) {
do_compile = 1;
}
else if (codeinst->invoke != NULL) {
else if (codeinst->invoke != NULL || codeinst->precompile) {
do_compile = 1;
}
}
Expand Down

0 comments on commit 223f656

Please sign in to comment.