Skip to content
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
6 changes: 2 additions & 4 deletions base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -805,8 +805,6 @@ function resolve_call_cycle!(interp::AbstractInterpreter, mi::MethodInstance, pa
return false
end

generating_sysimg() = ccall(:jl_generating_output, Cint, ()) != 0 && JLOptions().incremental == 0

ipo_effects(code::CodeInstance) = decode_effects(code.ipo_purity_bits)

struct EdgeCallResult
Expand Down Expand Up @@ -840,7 +838,7 @@ function typeinf_edge(interp::AbstractInterpreter, method::Method, @nospecialize
else
cache = :global # cache edge targets by default
end
if ccall(:jl_get_module_infer, Cint, (Any,), method.module) == 0 && !generating_sysimg()
if ccall(:jl_get_module_infer, Cint, (Any,), method.module) == 0 && !generating_output(#=incremental=#false)
add_remark!(interp, caller, "Inference is disabled for the target module")
return EdgeCallResult(Any, nothing, Effects())
end
Expand Down Expand Up @@ -1011,7 +1009,7 @@ function typeinf_ext(interp::AbstractInterpreter, mi::MethodInstance)
return inf
end
end
if ccall(:jl_get_module_infer, Cint, (Any,), method.module) == 0 && !generating_sysimg()
if ccall(:jl_get_module_infer, Cint, (Any,), method.module) == 0 && !generating_output(#=incremental=#false)
return retrieve_code_info(mi, get_world_counter(interp))
end
lock_mi_inference(interp, mi)
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ is_root_module(m::Module) = false

inlining_enabled() = (JLOptions().can_inline == 1)
function coverage_enabled(m::Module)
ccall(:jl_generating_output, Cint, ()) == 0 || return false # don't alter caches
generating_output() && return false # don't alter caches
cov = JLOptions().code_coverage
if cov == 1 # user
m = moduleroot(m)
Expand Down
8 changes: 4 additions & 4 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1703,7 +1703,7 @@ If a module or file is *not* safely precompilable, it should call `__precompile_
order to throw an error if Julia attempts to precompile it.
"""
@noinline function __precompile__(isprecompilable::Bool=true)
if !isprecompilable && ccall(:jl_generating_output, Cint, ()) != 0
if !isprecompilable && generating_output()
throw(PrecompilableError())
end
nothing
Expand Down Expand Up @@ -1843,7 +1843,7 @@ root_module_key(m::Module) = @lock require_lock module_keys[m]
if haskey(loaded_modules, key)
oldm = loaded_modules[key]
if oldm !== m
if (0 != ccall(:jl_generating_output, Cint, ())) && (JLOptions().incremental != 0)
if generating_output(#=incremental=#true)
error("Replacing module `$(key.name)`")
else
@warn "Replacing module `$(key.name)`"
Expand Down Expand Up @@ -1894,7 +1894,7 @@ function set_pkgorigin_version_path(pkg::PkgId, path::Union{String,Nothing})
pkgorigin = get!(PkgOrigin, pkgorigins, pkg)
if path !== nothing
# Pkg needs access to the version of packages in the sysimage.
if Core.Compiler.generating_sysimg()
if generating_output(#=incremental=#false)
pkgorigin.version = get_pkgversion_from_path(joinpath(dirname(path), ".."))
end
end
Expand Down Expand Up @@ -1949,7 +1949,7 @@ function _require(pkg::PkgId, env=nothing)
end

if JLOptions().use_compiled_modules == 1
if (0 == ccall(:jl_generating_output, Cint, ())) || (JLOptions().incremental != 0)
if !generating_output(#=incremental=#false)
if !pkg_precompile_attempted && isinteractive() && isassigned(PKG_PRECOMPILE_HOOK)
pkg_precompile_attempted = true
unlock(require_lock)
Expand Down
19 changes: 19 additions & 0 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2346,3 +2346,22 @@ function destructure_callex(topmod::Module, @nospecialize(ex))
end
return f, args, kwargs
end

"""
Base.generating_output([incremental::Bool])::Bool

Return `true` if the current process is being used to pre-generate a
code cache via any of the `--output-*` command line arguments. The
optional argument `incremental` controls whether to only return `true`
for that specific mode of compilation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a latecomer here, but I think even some sophisticated users may not clearly understand what "incremental compilation" means. Maybe add "(i.e., true for package precompilation and false for sysimg generation)"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that sounds better. I will make a PR on it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


!!! compat "Julia 1.11"
This function requires at least Julia 1.11.
"""
function generating_output(incremental::Union{Bool,Nothing}=nothing)
ccall(:jl_generating_output, Cint, ()) == 0 && return false
if incremental !== nothing
JLOptions().incremental == incremental || return false
end
return true
end
2 changes: 1 addition & 1 deletion stdlib/Profile/src/precompile.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if ccall(:jl_generating_output, Cint, ()) == 1
if Base.generating_output()
precompile(Tuple{typeof(Profile.tree!), Profile.StackFrameTree{UInt64}, Vector{UInt64}, Dict{UInt64, Vector{Base.StackTraces.StackFrame}}, Bool, Symbol, Int, UInt})
precompile(Tuple{typeof(Profile.tree!), Profile.StackFrameTree{UInt64}, Vector{UInt64}, Dict{UInt64, Vector{Base.StackTraces.StackFrame}}, Bool, Symbol, Int, UnitRange{UInt}})
precompile(Tuple{typeof(Profile.tree!), Profile.StackFrameTree{UInt64}, Vector{UInt64}, Dict{UInt64, Vector{Base.StackTraces.StackFrame}}, Bool, Symbol, UnitRange{Int}, UInt})
Expand Down
2 changes: 1 addition & 1 deletion stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ function get_code_cache()
# that those produced by `NativeInterpreter`, will leak into the native code cache,
# potentially causing runtime slowdown.
# (see https://github.com/JuliaLang/julia/issues/48453).
if (@ccall jl_generating_output()::Cint) == 1
if Base.generating_output()
return REPLInterpreterCache()
else
return REPL_INTERPRETER_CACHE
Expand Down