Skip to content

Commit f40a3c7

Browse files
committed
Fix package precompilation (PrecompileTools)
With the "classic" inference timing disabled, PrecompileTools and SnoopCompile are non-functional on 1.12 & master. #57074 added timing data to the CodeInstances themselves, which should help restore SnoopCompile. However, without the tree structure provided by the old inference timing system, we still need a way to tag MethodInstances that get inferred inside `PrecompileTools.@compile_workload` blocks. This adds a simple mechanism modeled after `@trace_compile` that switching to tagging MethodInstances in `jl_push_newly_inferred`. JuliaLang/PrecompileTools.jl#47 contains the corresponding changes to PrecompileTools.jl.
1 parent bc98abc commit f40a3c7

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/julia_internal.h

+3
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,9 @@ JL_DLLEXPORT void jl_force_trace_compile_timing_disable(void);
12811281
JL_DLLEXPORT void jl_force_trace_dispatch_enable(void);
12821282
JL_DLLEXPORT void jl_force_trace_dispatch_disable(void);
12831283

1284+
JL_DLLEXPORT void jl_tag_newly_inferred_enable(void);
1285+
JL_DLLEXPORT void jl_tag_newly_inferred_disable(void);
1286+
12841287
uint32_t jl_module_next_counter(jl_module_t *m) JL_NOTSAFEPOINT;
12851288
jl_tupletype_t *arg_type_tuple(jl_value_t *arg1, jl_value_t **args, size_t nargs);
12861289

src/staticdata_utils.c

+23
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,23 @@ static jl_array_t *newly_inferred JL_GLOBALLY_ROOTED /*FIXME*/;
8686
// Mutex for newly_inferred
8787
jl_mutex_t newly_inferred_mutex;
8888
extern jl_mutex_t world_counter_lock;
89+
static _Atomic(uint8_t) jl_tag_newly_inferred_enabled = 0;
90+
91+
/**
92+
* @brief Enable tagging of all newly inferred CodeInstances.
93+
*/
94+
JL_DLLEXPORT void jl_tag_newly_inferred_enable(void)
95+
{
96+
jl_atomic_fetch_add(&jl_tag_newly_inferred_enabled, 1); // FIXME overflow?
97+
}
98+
/**
99+
* @brief Disable tagging of all newly inferred CodeInstances.
100+
*/
101+
JL_DLLEXPORT void jl_tag_newly_inferred_disable(void)
102+
{
103+
jl_atomic_fetch_add(&jl_tag_newly_inferred_enabled, -1); // FIXME underflow?
104+
}
105+
89106

90107
// Register array of newly-inferred MethodInstances
91108
// This gets called as the first step of Base.include_package_for_output
@@ -101,6 +118,12 @@ JL_DLLEXPORT void jl_push_newly_inferred(jl_value_t* ci)
101118
{
102119
if (!newly_inferred)
103120
return;
121+
uint8_t tag_newly_inferred = jl_atomic_load_relaxed(&jl_tag_newly_inferred_enabled);
122+
if (tag_newly_inferred) {
123+
jl_method_instance_t *mi = jl_get_ci_mi((jl_code_instance_t*)ci);
124+
uint8_t miflags = jl_atomic_load_relaxed(&mi->flags);
125+
jl_atomic_store_relaxed(&mi->flags, miflags | JL_MI_FLAGS_MASK_PRECOMPILED);
126+
}
104127
JL_LOCK(&newly_inferred_mutex);
105128
size_t end = jl_array_nrows(newly_inferred);
106129
jl_array_grow_end(newly_inferred, 1);

0 commit comments

Comments
 (0)