Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Break dependency between loading and Core.Compiler #56186

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions base/compiler/cicache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ end

function setindex!(cache::InternalCodeCache, ci::CodeInstance, mi::MethodInstance)
@assert ci.owner === cache.owner
m = mi.def
if isa(m, Method) && m.module != Core
ccall(:jl_push_newly_inferred, Cvoid, (Any,), ci)
end
ccall(:jl_mi_cache_insert, Cvoid, (Any, Any), mi, ci)
return cache
end
Expand Down
10 changes: 0 additions & 10 deletions base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

# Tracking of newly-inferred CodeInstances during precompilation
const track_newly_inferred = RefValue{Bool}(false)
const newly_inferred = CodeInstance[]

"""
The module `Core.Compiler.Timings` provides a simple implementation of nested timers that
can be used to measure the exclusive time spent inferring each method instance that is
Expand Down Expand Up @@ -264,12 +260,6 @@ function cache_result!(interp::AbstractInterpreter, result::InferenceResult)

if cache_results
code_cache(interp)[mi] = result.ci
if track_newly_inferred[]
m = mi.def
if isa(m, Method) && m.module != Core
ccall(:jl_push_newly_inferred, Cvoid, (Any,), result.ci)
end
end
end
return cache_results
end
Expand Down
13 changes: 10 additions & 3 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2863,6 +2863,9 @@ function load_path_setup_code(load_path::Bool=true)
return code
end

# Const global for GC root
const newly_inferred = CodeInstance[]

# this is called in the external process that generates precompiled package files
function include_package_for_output(pkg::PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String},
concrete_deps::typeof(_concrete_dependencies), source::Union{Nothing,String})
Expand All @@ -2882,19 +2885,23 @@ function include_package_for_output(pkg::PkgId, input::String, depot_path::Vecto
task_local_storage()[:SOURCE_PATH] = source
end

ccall(:jl_set_newly_inferred, Cvoid, (Any,), Core.Compiler.newly_inferred)
Core.Compiler.track_newly_inferred.x = true
ccall(:jl_set_newly_inferred, Cvoid, (Any,), newly_inferred)
try
Base.include(Base.__toplevel__, input)
catch ex
precompilableerror(ex) || rethrow()
@debug "Aborting `create_expr_cache'" exception=(ErrorException("Declaration of __precompile__(false) not allowed"), catch_backtrace())
exit(125) # we define status = 125 means PrecompileableError
finally
Core.Compiler.track_newly_inferred.x = false
ccall(:jl_set_newly_inferred, Cvoid, (Any,), nothing)
end
# check that the package defined the expected module so we can give a nice error message if not
Base.check_package_module_loaded(pkg)

# Re-populate the runtime's newly-inferred array, which will be included
# in the output. We removed it above to avoid including any code we may
# have compiled for error handling and validation.
ccall(:jl_set_newly_inferred, Cvoid, (Any,), newly_inferred)
end

function check_package_module_loaded(pkg::PkgId)
Expand Down
6 changes: 5 additions & 1 deletion src/staticdata_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,16 @@ extern jl_mutex_t world_counter_lock;
// This gets called as the first step of Base.include_package_for_output
JL_DLLEXPORT void jl_set_newly_inferred(jl_value_t* _newly_inferred)
{
assert(_newly_inferred == NULL || jl_is_array(_newly_inferred));
assert(_newly_inferred == NULL || _newly_inferred == jl_nothing || jl_is_array(_newly_inferred));
if (_newly_inferred == jl_nothing)
_newly_inferred = NULL;
newly_inferred = (jl_array_t*) _newly_inferred;
}

JL_DLLEXPORT void jl_push_newly_inferred(jl_value_t* ci)
{
if (!newly_inferred)
return;
JL_LOCK(&newly_inferred_mutex);
size_t end = jl_array_nrows(newly_inferred);
jl_array_grow_end(newly_inferred, 1);
Expand Down