Skip to content

Commit 1fed09e

Browse files
committed
there's really no need to hide the fields of LambdaInfo
1 parent 35e0911 commit 1fed09e

File tree

8 files changed

+80
-77
lines changed

8 files changed

+80
-77
lines changed

src/alloc.c

+6-11
Original file line numberDiff line numberDiff line change
@@ -364,26 +364,21 @@ JL_DLLEXPORT jl_lambda_info_t *jl_spec_lambda_info(jl_lambda_info_t *li, jl_svec
364364
nli->inferred = 0;
365365
if (jl_options.compile_enabled == JL_OPTIONS_COMPILE_OFF && li != NULL) {
366366
// copy fptr from the unspecialized method definition
367-
nli->fptr = li->fptr;
368-
nli->jlcall_api = li->jlcall_api;
369-
nli->functionObjects.functionObject = li->functionObjects.functionObject;
370-
nli->functionObjects.specFunctionObject = li->functionObjects.specFunctionObject;
371-
nli->functionID = li->functionID;
372-
nli->specFunctionID = li->functionID;
373-
if (nli->fptr == NULL) {
367+
nli->functionObjects = li->functionObjects;
368+
if (nli->functionObjects.fptr == NULL) {
374369
jl_printf(JL_STDERR,"code missing for ");
375370
jl_static_show(JL_STDERR, (jl_value_t*)nli);
376371
jl_printf(JL_STDERR, " sysimg may not have been built with --compile=all\n");
377372
}
378373
}
379374
else {
380-
nli->fptr = NULL;
381-
nli->jlcall_api = 0;
375+
nli->functionObjects.fptr = NULL;
376+
nli->functionObjects.jlcall_api = 0;
382377
nli->functionObjects.functionObject = NULL;
383378
nli->functionObjects.specFunctionObject = NULL;
384379
nli->functionObjects.cFunctionList = NULL;
385-
nli->functionID = 0;
386-
nli->specFunctionID = 0;
380+
nli->functionObjects.functionID = 0;
381+
nli->functionObjects.specFunctionID = 0;
387382
}
388383
return nli;
389384
}

src/builtins.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ jl_value_t *jl_mk_builtin_func(const char *name, jl_fptr_t fptr)
10861086
jl_value_t *f = jl_new_generic_function_with_supertype(sname, jl_core_module, jl_builtin_type, 0);
10871087
jl_method_info_t *li = jl_new_method_info(jl_nothing, jl_emptysvec, jl_core_module);
10881088
li->name = sname;
1089-
li->unspecialized->fptr = fptr;
1089+
li->unspecialized->functionObjects.fptr = fptr;
10901090
// TODO jb/functions: what should li->ast be?
10911091
li->unspecialized->ast = (jl_value_t*)jl_exprn(lambda_sym,0);
10921092
jl_gc_wb(li->unspecialized, li->unspecialized->ast);
@@ -1097,7 +1097,7 @@ jl_value_t *jl_mk_builtin_func(const char *name, jl_fptr_t fptr)
10971097
jl_fptr_t jl_get_builtin_fptr(jl_value_t *b)
10981098
{
10991099
assert(jl_subtype(b, (jl_value_t*)jl_builtin_type, 1));
1100-
return jl_gf_mtable(b)->cache->func->fptr;
1100+
return jl_gf_mtable(b)->cache->func->functionObjects.fptr;
11011101
}
11021102

11031103
static void add_builtin_func(const char *name, jl_fptr_t fptr)

src/codegen.cpp

+16-16
Original file line numberDiff line numberDiff line change
@@ -854,12 +854,12 @@ static Function *to_function(jl_lambda_info_t *li, jl_cyclectx_t *cyclectx)
854854
#endif
855855
f = (llvm::Function*)definitions.functionObject;
856856
specf = (llvm::Function*)definitions.specFunctionObject;
857-
li->functionID = jl_assign_functionID(f, 0);
857+
li->functionObjects.functionID = jl_assign_functionID(f, 0);
858858
if (specf)
859-
li->specFunctionID = jl_assign_functionID(specf, 1);
859+
li->functionObjects.specFunctionID = jl_assign_functionID(specf, 1);
860860
if (f->getFunctionType() != jl_func_sig)
861861
// mark the pointer as jl_fptr_sparam_t calling convention
862-
li->jlcall_api = 1;
862+
li->functionObjects.jlcall_api = 1;
863863
//n_emit++;
864864
}
865865
JL_CATCH {
@@ -1057,7 +1057,7 @@ extern "C" void jl_generate_fptr(jl_lambda_info_t *li)
10571057
JL_LOCK(codegen);
10581058
// objective: assign li->fptr
10591059
assert(li->functionObjects.functionObject);
1060-
if (li->fptr == NULL) {
1060+
if (li->functionObjects.fptr == NULL) {
10611061
JL_SIGATOMIC_BEGIN();
10621062
#ifdef USE_MCJIT
10631063
if (imaging_mode) {
@@ -1076,16 +1076,16 @@ extern "C" void jl_generate_fptr(jl_lambda_info_t *li)
10761076
}
10771077
}
10781078
jl_finalize_module(m);
1079-
li->fptr = (jl_fptr_t)jl_ExecutionEngine->getFunctionAddress(((Function*)li->functionObjects.functionObject)->getName());
1079+
li->functionObjects.fptr = (jl_fptr_t)jl_ExecutionEngine->getFunctionAddress(((Function*)li->functionObjects.functionObject)->getName());
10801080
}
10811081
else {
1082-
li->fptr = (jl_fptr_t)getAddressForOrCompileFunction((Function*)li->functionObjects.functionObject);
1082+
li->functionObjects.fptr = (jl_fptr_t)getAddressForOrCompileFunction((Function*)li->functionObjects.functionObject);
10831083
}
10841084
#else
1085-
li->fptr = (jl_fptr_t)jl_ExecutionEngine->getPointerToFunction((Function*)li->functionObjects.functionObject);
1085+
li->functionObjects.fptr = (jl_fptr_t)jl_ExecutionEngine->getPointerToFunction((Function*)li->functionObjects.functionObject);
10861086
#endif
10871087

1088-
assert(li->fptr != NULL);
1088+
assert(li->functionObjects.fptr != NULL);
10891089
#ifndef KEEP_BODIES
10901090
if (!imaging_mode)
10911091
((Function*)li->functionObjects.functionObject)->deleteBody();
@@ -1369,12 +1369,12 @@ void *jl_get_llvmf(jl_function_t *f, jl_tupletype_t *tt, bool getwrapper, bool g
13691369
return llvmf;
13701370
}
13711371

1372-
if (linfo->fptr && !jl_getUnwindInfo((uintptr_t)linfo->fptr)) {
1372+
if (linfo->functionObjects.fptr && !jl_getUnwindInfo((uintptr_t)linfo->functionObjects.fptr)) {
13731373
// Not in in the current ExecutionEngine
13741374
// found in the system image: force a recompile
13751375
linfo->functionObjects.specFunctionObject = NULL;
13761376
linfo->functionObjects.functionObject = NULL;
1377-
linfo->fptr = NULL;
1377+
linfo->functionObjects.fptr = NULL;
13781378
}
13791379
if (linfo->functionObjects.functionObject == NULL) {
13801380
jl_compile_linfo(linfo, NULL);
@@ -5148,7 +5148,7 @@ extern "C" void jl_fptr_to_llvm(void *fptr, jl_lambda_info_t *lam, int specsig)
51485148
{
51495149
if (imaging_mode) {
51505150
if (!specsig) {
5151-
lam->fptr = (jl_fptr_t)fptr; // in imaging mode, it's fine to use the fptr, but we don't want it in the shadow_module
5151+
lam->functionObjects.fptr = (jl_fptr_t)fptr; // in imaging mode, it's fine to use the fptr, but we don't want it in the shadow_module
51525152
}
51535153
}
51545154
else {
@@ -5192,16 +5192,16 @@ extern "C" void jl_fptr_to_llvm(void *fptr, jl_lambda_info_t *lam, int specsig)
51925192
add_named_global(f, (void*)fptr);
51935193
}
51945194
else {
5195-
if (lam->jlcall_api == 1) { // jl_func_sig_sparams -- don't bother emitting the FunctionObject (since can't be used right now)
5196-
assert(lam->fptr == NULL);
5197-
lam->fptr = (jl_fptr_t)fptr;
5195+
if (lam->functionObjects.jlcall_api == 1) { // jl_func_sig_sparams -- don't bother emitting the FunctionObject (since can't be used right now)
5196+
assert(lam->functionObjects.fptr == NULL);
5197+
lam->functionObjects.fptr = (jl_fptr_t)fptr;
51985198
}
51995199
else {
52005200
Function *f = jlcall_func_to_llvm(funcName, fptr, shadow_module);
52015201
if (lam->functionObjects.functionObject == NULL) {
52025202
lam->functionObjects.functionObject = (void*)f;
5203-
assert(lam->fptr == NULL);
5204-
lam->fptr = (jl_fptr_t)fptr;
5203+
assert(lam->functionObjects.fptr == NULL);
5204+
lam->functionObjects.fptr = (jl_fptr_t)fptr;
52055205
}
52065206
}
52075207
}

src/dump.c

+11-11
Original file line numberDiff line numberDiff line change
@@ -847,11 +847,11 @@ static void jl_serialize_value_(ios_t *s, jl_value_t *v)
847847
write_int8(s, li->pure);
848848
write_int8(s, li->called);
849849
// save functionObject pointers
850-
jl_serialize_fptr(s, li->fptr);
851-
write_int32(s, li->functionID);
852-
write_int32(s, li->specFunctionID);
853-
if (li->functionID)
854-
write_int8(s, li->jlcall_api);
850+
jl_serialize_fptr(s, li->functionObjects.fptr);
851+
write_int32(s, li->functionObjects.functionID);
852+
write_int32(s, li->functionObjects.specFunctionID);
853+
if (li->functionObjects.functionID)
854+
write_int8(s, li->functionObjects.jlcall_api);
855855
}
856856
else if (jl_typeis(v, jl_module_type)) {
857857
jl_serialize_module(s, (jl_module_t*)v);
@@ -1504,19 +1504,19 @@ static jl_value_t *jl_deserialize_value_(ios_t *s, jl_value_t *vtag, jl_value_t
15041504
li->inferred = read_int8(s);
15051505
li->pure = read_int8(s);
15061506
li->called = read_int8(s);
1507+
li->inInference = 0;
1508+
li->inCompile = 0;
15071509
li->functionObjects.functionObject = NULL;
15081510
li->functionObjects.cFunctionList = NULL;
15091511
li->functionObjects.specFunctionObject = NULL;
1510-
li->inInference = 0;
1511-
li->inCompile = 0;
1512-
li->functionID = 0;
1513-
li->specFunctionID = 0;
1512+
li->functionObjects.functionID = 0;
1513+
li->functionObjects.specFunctionID = 0;
15141514
int32_t cfunc_llvm, func_llvm;
1515-
li->fptr = jl_deserialize_fptr(s);
1515+
li->functionObjects.fptr = jl_deserialize_fptr(s);
15161516
func_llvm = read_int32(s);
15171517
cfunc_llvm = read_int32(s);
15181518
jl_delayed_fptrs(li, func_llvm, cfunc_llvm);
1519-
li->jlcall_api = func_llvm ? read_int8(s) : 0;
1519+
li->functionObjects.jlcall_api = func_llvm ? read_int8(s) : 0;
15201520
return (jl_value_t*)li;
15211521
}
15221522
else if (vtag == (jl_value_t*)jl_module_type) {

src/gf.c

+12-12
Original file line numberDiff line numberDiff line change
@@ -845,15 +845,15 @@ static jl_value_t *lookup_match(jl_value_t *a, jl_value_t *b, jl_svec_t **penv,
845845
static jl_value_t *jl_call_unspecialized(jl_svec_t *sparam_vals, jl_lambda_info_t *meth,
846846
jl_value_t **args, uint32_t nargs)
847847
{
848-
if (__unlikely(meth->fptr == NULL)) {
848+
if (__unlikely(meth->functionObjects.fptr == NULL)) {
849849
jl_compile_linfo(meth, NULL);
850850
jl_generate_fptr(meth);
851851
}
852852
assert(jl_svec_len(meth->def->sparam_syms) == jl_svec_len(sparam_vals));
853-
if (__likely(meth->jlcall_api == 0))
854-
return meth->fptr(args[0], &args[1], nargs-1);
853+
if (__likely(meth->functionObjects.jlcall_api == 0))
854+
return meth->functionObjects.fptr(args[0], &args[1], nargs-1);
855855
else
856-
return ((jl_fptr_sparam_t)meth->fptr)(sparam_vals, args[0], &args[1], nargs-1);
856+
return ((jl_fptr_sparam_t)meth->functionObjects.fptr)(sparam_vals, args[0], &args[1], nargs-1);
857857
}
858858

859859
JL_DLLEXPORT jl_method_info_t *jl_instantiate_staged(jl_method_info_t *generator, jl_tupletype_t *tt, jl_svec_t *env)
@@ -1494,7 +1494,7 @@ jl_lambda_info_t *jl_get_specialization1(jl_tupletype_t *types, void *cyclectx)
14941494
if (sf == NULL || sf->inInference)
14951495
goto not_found;
14961496
if (sf->functionObjects.functionObject == NULL) {
1497-
if (sf->fptr != NULL)
1497+
if (sf->functionObjects.fptr != NULL)
14981498
goto not_found;
14991499
jl_compile_linfo(sf, cyclectx);
15001500
}
@@ -1704,9 +1704,9 @@ static void _compile_all_deq(jl_array_t *found)
17041704
if (complete) {
17051705
// keep track of whether all possible signatures have been cached (and thus whether it can skip trying to compile the unspecialized function)
17061706
// this is necessary because many intrinsics try to call static_eval and thus are not compilable unspecialized
1707-
if (!linfo->functionID)
1707+
if (!linfo->functionObjects.functionID)
17081708
// indicate that this method doesn't need a functionID because it was fully covered above
1709-
linfo->functionID = -1;
1709+
linfo->functionObjects.functionID = -1;
17101710
continue;
17111711
}
17121712
}
@@ -1720,11 +1720,11 @@ static void _compile_all_deq(jl_array_t *found)
17201720
linfo->functionObjects.functionObject = NULL;
17211721
linfo->functionObjects.specFunctionObject = NULL;
17221722
linfo->functionObjects.cFunctionList = NULL;
1723-
linfo->functionID = 0;
1724-
linfo->specFunctionID = 0;
1723+
linfo->functionObjects.functionID = 0;
1724+
linfo->functionObjects.specFunctionID = 0;
17251725
}
17261726
jl_compile_linfo(linfo, NULL);
1727-
assert(linfo->functionID > 0);
1727+
assert(linfo->functionObjects.functionID > 0);
17281728
}
17291729
jl_printf(JL_STDERR, "\n");
17301730
}
@@ -1735,7 +1735,7 @@ static void _compile_all_enq_ml(jl_methlist_t *ml, jl_array_t *found)
17351735
if (ml->func != NULL) {
17361736
// found a lambda specialization (not a placeholder guard)
17371737
jl_lambda_info_t *linfo = (jl_lambda_info_t*)ml->func;
1738-
if (!linfo->functionID || !linfo->inferred)
1738+
if (!linfo->functionObjects.functionID || !linfo->inferred)
17391739
// and it still needs to be compiled
17401740
jl_cell_1d_push(found, (jl_value_t*)linfo);
17411741
}
@@ -1750,7 +1750,7 @@ static void _compile_all_enq_methods(jl_method_info_t *ml, jl_array_t *found)
17501750
if (!ml->isstaged) {
17511751
// method definitions -- compile unspecialized field
17521752
jl_lambda_info_t *linfo = ml->unspecialized;
1753-
if (!linfo->functionID || !linfo->inferred) {
1753+
if (!linfo->functionObjects.functionID || !linfo->inferred) {
17541754
// and it still needs to be compiled
17551755
jl_cell_1d_push(found, (jl_value_t*)ml);
17561756
}

src/jltypes.c

+17-4
Original file line numberDiff line numberDiff line change
@@ -3479,20 +3479,29 @@ void jl_init_types(void)
34793479
jl_lambda_info_type =
34803480
jl_new_datatype(jl_symbol("LambdaInfo"),
34813481
jl_any_type, jl_emptysvec,
3482-
jl_svec(7, jl_symbol("ast"),
3482+
jl_svec(18, jl_symbol("ast"),
34833483
jl_symbol("rettype"),
34843484
jl_symbol("sparam_vals"),
34853485
jl_symbol("specTypes"),
34863486
jl_symbol("unspecialized_ducttape"),
34873487
jl_symbol("def"),
3488-
jl_symbol("pure")),
3489-
jl_svec(7, jl_any_type,
3488+
jl_symbol("called"),
3489+
jl_symbol("pure"),
3490+
jl_symbol("inferred"),
3491+
jl_symbol("inInference"),
3492+
jl_symbol("inCompile"),
3493+
jl_symbol(""), jl_symbol(""), jl_symbol(""),
3494+
jl_symbol(""), jl_symbol(""), jl_symbol("fptr"), jl_symbol("")),
3495+
jl_svec(18, jl_any_type,
34903496
jl_any_type,
34913497
jl_simplevector_type,
34923498
jl_any_type,
34933499
jl_any_type,
34943500
jl_any_type,
3495-
jl_bool_type),
3501+
jl_int32_type,
3502+
jl_bool_type, jl_bool_type, jl_bool_type, jl_bool_type,
3503+
jl_any_type, jl_any_type, jl_any_type,
3504+
jl_int32_type, jl_int32_type, jl_any_type, jl_bool_type),
34963505
0, 1, 4);
34973506

34983507
jl_method_info_type =
@@ -3577,6 +3586,10 @@ void jl_init_types(void)
35773586
jl_svecset(jl_typename_type->types, 6, jl_long_type);
35783587
jl_svecset(jl_methtable_type->types, 5, jl_long_type);
35793588
jl_svecset(jl_lambda_info_type->types, 5, jl_method_info_type);
3589+
jl_svecset(jl_lambda_info_type->types, 11, jl_voidpointer_type);
3590+
jl_svecset(jl_lambda_info_type->types, 12, jl_voidpointer_type);
3591+
jl_svecset(jl_lambda_info_type->types, 13, jl_voidpointer_type);
3592+
jl_svecset(jl_lambda_info_type->types, 16, jl_voidpointer_type);
35803593

35813594
jl_compute_field_offsets(jl_datatype_type);
35823595
jl_compute_field_offsets(jl_typename_type);

src/julia.h

+12-17
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,13 @@ typedef jl_value_t *(*jl_fptr_sparam_t)(jl_svec_t*, jl_value_t*, jl_value_t**, u
279279
typedef struct _jl_datatype_t jl_tupletype_t;
280280

281281
typedef struct _jl_llvm_functions_t {
282-
void *functionObject; // jlcall llvm Function
283-
void *cFunctionList; // c callable llvm Functions
284-
285-
// specialized llvm Function (common core for the other two)
286-
void *specFunctionObject;
282+
void *functionObject; // jlcall llvm Function
283+
void *cFunctionList; // c callable llvm Functions
284+
void *specFunctionObject; // specialized llvm Function (common core for the other two)
285+
int32_t functionID; // index that this function will have in the codegen table
286+
int32_t specFunctionID; // index that this specFunction will have in the codegen table
287+
jl_fptr_t fptr; // jlcall entry point
288+
uint8_t jlcall_api; // the c-abi for fptr; 0 = jl_fptr_t, 1 = jl_fptr_sparam_t
287289
} jl_llvm_functions_t;
288290

289291
typedef struct _jl_method_info_t {
@@ -330,25 +332,18 @@ typedef struct _jl_lambda_info_t {
330332
// this keeps codegen happy if the method contains intrinsics that depend on an sparam
331333
struct _jl_lambda_info_t *unspecialized_ducttape;
332334
jl_method_info_t *def; // original this is specialized from
335+
uint32_t called; // bit flags: whether each of the first 8 arguments is called
333336
uint8_t pure;
334-
uint8_t called; // bit flags: whether each of the first 8 arguments is called
335-
336-
// hidden fields:
337-
uint8_t inferred : 1;
338-
uint8_t jlcall_api : 1; // the c-abi for fptr; 0 = jl_fptr_t, 1 = jl_fptr_sparam_t
339-
uint8_t inInference : 1; // flags to tell if inference is running on this function
340-
// used to avoid infinite recursion
341-
uint8_t inCompile : 1;
342-
jl_fptr_t fptr; // jlcall entry point
337+
uint8_t inferred;
338+
uint8_t inInference; // flags to tell if inference is running on this function
339+
// used to avoid infinite recursion
340+
uint8_t inCompile;
343341

344342
// On the old JIT, handles to all Functions generated for this linfo
345343
// For the new JITs, handles to declarations in the shadow module
346344
// with the same name as the generated functions for this linfo, suitable
347345
// for referencing in LLVM IR
348346
jl_llvm_functions_t functionObjects;
349-
350-
int32_t functionID; // index that this function will have in the codegen table
351-
int32_t specFunctionID; // index that this specFunction will have in the codegen table
352347
} jl_lambda_info_t;
353348

354349
typedef jl_value_t jl_function_t;

src/julia_internal.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ void jl_compile_linfo(jl_lambda_info_t *li, void *cyclectx);
6161
// invoke (compiling if necessary) the jlcall function pointer for a method
6262
STATIC_INLINE jl_value_t *jl_call_method_internal(jl_lambda_info_t *meth, jl_value_t **args, uint32_t nargs)
6363
{
64-
if (__unlikely(meth->fptr == NULL)) {
64+
if (__unlikely(meth->functionObjects.fptr == NULL)) {
6565
jl_compile_linfo(meth, NULL);
6666
jl_generate_fptr(meth);
6767
}
68-
if (meth->jlcall_api == 0)
69-
return meth->fptr(args[0], &args[1], nargs-1);
68+
if (meth->functionObjects.jlcall_api == 0)
69+
return meth->functionObjects.fptr(args[0], &args[1], nargs-1);
7070
else
71-
return ((jl_fptr_sparam_t)meth->fptr)(meth->sparam_vals, args[0], &args[1], nargs-1);
71+
return ((jl_fptr_sparam_t)meth->functionObjects.fptr)(meth->sparam_vals, args[0], &args[1], nargs-1);
7272
}
7373

7474
jl_tupletype_t *jl_argtype_with_function(jl_function_t *f, jl_tupletype_t *types);

0 commit comments

Comments
 (0)