Skip to content

Commit 482afa6

Browse files
committed
Remove typeinfer lock altogether
1 parent f794bdd commit 482afa6

File tree

7 files changed

+17
-25
lines changed

7 files changed

+17
-25
lines changed

base/compiler/typeinfer.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,7 @@ function cache_result!(interp::AbstractInterpreter, result::InferenceResult)
392392
if track_newly_inferred[]
393393
m = linfo.def
394394
if isa(m, Method) && m.module != Core
395-
ccall(:jl_typeinf_lock_begin, Cvoid, ())
396-
push!(newly_inferred, linfo)
397-
ccall(:jl_typeinf_lock_end, Cvoid, ())
395+
ccall(:jl_push_newly_inferred, Cvoid, (Any,), linfo)
398396
end
399397
end
400398
end

base/loading.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,7 @@ function include_package_for_output(pkg::PkgId, input::String, depot_path::Vecto
16461646
task_local_storage()[:SOURCE_PATH] = source
16471647
end
16481648

1649+
ccall(:jl_set_newly_inferred, Cvoid, (Any,), Core.Compiler.newly_inferred)
16491650
Core.Compiler.track_newly_inferred.x = true
16501651
try
16511652
Base.include(Base.__toplevel__, input)
@@ -1656,7 +1657,6 @@ function include_package_for_output(pkg::PkgId, input::String, depot_path::Vecto
16561657
finally
16571658
Core.Compiler.track_newly_inferred.x = false
16581659
end
1659-
ccall(:jl_set_newly_inferred, Cvoid, (Any,), Core.Compiler.newly_inferred)
16601660
end
16611661

16621662
const PRECOMPILE_TRACE_COMPILE = Ref{String}()

doc/src/devdocs/locks.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ The following is a leaf lock (level 2), and only acquires level 1 locks (safepoi
4242
> * typecache
4343
> * Module->lock
4444
> * JLDebuginfoPlugin::PluginMutex
45+
> * newly_inferred_mutex
4546
4647
The following is a level 3 lock, which can only acquire level 1 or level 2 locks internally:
4748

src/dump.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ static htable_t external_mis;
158158
// Inference tracks newly-inferred MethodInstances during precompilation
159159
// and registers them by calling jl_set_newly_inferred
160160
static jl_array_t *newly_inferred JL_GLOBALLY_ROOTED;
161+
// Mutex for newly_inferred
162+
static jl_mutex_t newly_inferred_mutex;
161163

162164
// New roots to add to Methods. These can't be added until after
163165
// recaching is complete, so we have to hold on to them separately
@@ -2785,14 +2787,23 @@ JL_DLLEXPORT void jl_init_restored_modules(jl_array_t *init_order)
27852787

27862788
// --- entry points ---
27872789

2788-
// Register all newly-inferred MethodInstances
2789-
// This gets called as the final step of Base.include_package_for_output
2790+
// Register array of newly-inferred MethodInstances
2791+
// This gets called as the first step of Base.include_package_for_output
27902792
JL_DLLEXPORT void jl_set_newly_inferred(jl_value_t* _newly_inferred)
27912793
{
27922794
assert(_newly_inferred == NULL || jl_is_array(_newly_inferred));
27932795
newly_inferred = (jl_array_t*) _newly_inferred;
27942796
}
27952797

2798+
JL_DLLEXPORT void jl_push_newly_inferred(jl_value_t* linfo)
2799+
{
2800+
JL_LOCK(&newly_inferred_mutex);
2801+
size_t end = jl_array_len(newly_inferred);
2802+
jl_array_grow_end(newly_inferred, 1);
2803+
jl_arrayset(newly_inferred, linfo, end);
2804+
JL_UNLOCK(&newly_inferred_mutex);
2805+
}
2806+
27962807
// Serialize the modules in `worklist` to file `fname`
27972808
JL_DLLEXPORT int jl_save_incremental(const char *fname, jl_array_t *worklist)
27982809
{

src/gf.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3375,13 +3375,6 @@ int jl_has_concrete_subtype(jl_value_t *typ)
33753375
return ((jl_datatype_t*)typ)->has_concrete_subtype;
33763376
}
33773377

3378-
// TODO: separate the codegen and typeinf locks
3379-
// currently using a coarser lock seems like
3380-
// the best way to avoid acquisition priority
3381-
// ordering violations
3382-
//static jl_mutex_t typeinf_lock;
3383-
#define typeinf_lock jl_codegen_lock
3384-
33853378
static jl_mutex_t inference_timing_mutex;
33863379
static uint64_t inference_start_time = 0;
33873380
static uint8_t inference_is_measuring_compile_time = 0;
@@ -3406,16 +3399,6 @@ JL_DLLEXPORT void jl_typeinf_timing_end(void)
34063399
JL_UNLOCK_NOGC(&inference_timing_mutex);
34073400
}
34083401

3409-
JL_DLLEXPORT void jl_typeinf_lock_begin(void)
3410-
{
3411-
JL_LOCK(&typeinf_lock);
3412-
}
3413-
3414-
JL_DLLEXPORT void jl_typeinf_lock_end(void)
3415-
{
3416-
JL_UNLOCK(&typeinf_lock);
3417-
}
3418-
34193402
#ifdef __cplusplus
34203403
}
34213404
#endif

src/jl_exported_funcs.inc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,6 @@
479479
XX(jl_tty_set_mode) \
480480
XX(jl_tupletype_fill) \
481481
XX(jl_typeassert) \
482-
XX(jl_typeinf_lock_begin) \
483-
XX(jl_typeinf_lock_end) \
484482
XX(jl_typeinf_timing_begin) \
485483
XX(jl_typeinf_timing_end) \
486484
XX(jl_typename_str) \

src/julia.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,6 +1764,7 @@ JL_DLLEXPORT void jl_save_system_image(const char *fname);
17641764
JL_DLLEXPORT void jl_restore_system_image(const char *fname);
17651765
JL_DLLEXPORT void jl_restore_system_image_data(const char *buf, size_t len);
17661766
JL_DLLEXPORT void jl_set_newly_inferred(jl_value_t *newly_inferred);
1767+
JL_DLLEXPORT void jl_push_newly_inferred(jl_value_t *linfo);
17671768
JL_DLLEXPORT int jl_save_incremental(const char *fname, jl_array_t *worklist);
17681769
JL_DLLEXPORT jl_value_t *jl_restore_incremental(const char *fname, jl_array_t *depmods);
17691770
JL_DLLEXPORT jl_value_t *jl_restore_incremental_from_buf(const char *buf, size_t sz, jl_array_t *depmods);

0 commit comments

Comments
 (0)