Skip to content

Commit 92d6adc

Browse files
committed
allow the Compiler.jl stdlib to be installed on older version of Julia
Since #56409, Compiler.jl as a standard library has become available. However, for Julia versions prior to this change, even though the stdlib can be installed via Pkg.jl, the precompilation fails due to code compatibility issues. Consequently, when an external package that uses the Compiler stdlib adds Compiler.jl to its Project.toml, the package would stop working on older Julia versions. To address this, this commit adopts the same approach as JET.jl. Specifically, on older Julia versions, a dummy `Compiler` module is defined, allowing dependent packages to switch between using the Compiler.jl stdlib or the previous `Core.Compiler`. While this is a somewhat hacky solution, it should resolve the issue for now.
1 parent aa05c98 commit 92d6adc

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

Compiler/src/Compiler.jl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3+
if isdefined(Base, :end_base_include) && isdefined(Base, :Compiler)
4+
5+
# Define a dummy `Compiler` module to make it installable even on Julia versions where
6+
# Compiler.jl is not available as a standard library.
7+
@eval module Compiler
8+
function __init__()
9+
println("""
10+
The `Compiler` standard library is not available for this version of Julia.
11+
Use Julia version `v"1.12.0-DEV.1581"` or later.
12+
""")
13+
end
14+
end
15+
316
# When generating an incremental precompile file, we first check whether we
417
# already have a copy of this *exact* code in the system image. If so, we
518
# simply generates a pkgimage that has the dependency edges we recorded in
619
# the system image and simply returns that copy of the compiler. If not,
720
# we proceed to load/precompile this as an ordinary package.
8-
if isdefined(Base, :generating_output) && Base.generating_output(true) &&
21+
elseif (isdefined(Base, :generating_output) && Base.generating_output(true) &&
922
Base.samefile(joinpath(Sys.BINDIR, Base.DATAROOTDIR, Base._compiler_require_dependencies[1][2]), @eval @__FILE__) &&
1023
!Base.any_includes_stale(
1124
map(Base.compiler_chi, Base._compiler_require_dependencies),
12-
"sysimg", nothing)
25+
"sysimg", nothing))
1326

1427
Base.prepare_compiler_stub_image!()
1528
append!(Base._require_dependencies, map(Base.expand_compiler_path, Base._compiler_require_dependencies))

Compiler/src/ssair/show.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,3 +1135,12 @@ function Base.show(io::IO, tinf::Timings.Timing)
11351135
end
11361136

11371137
@specialize
1138+
1139+
const __debuginfo = Dict{Symbol, Any}(
1140+
# :full => src -> statementidx_lineinfo_printer(src), # and add variable slot information
1141+
:source => src -> statementidx_lineinfo_printer(src),
1142+
# :oneliner => src -> statementidx_lineinfo_printer(PartialLineInfoPrinter, src),
1143+
:none => src -> lineinfo_disabled,
1144+
)
1145+
const default_debuginfo = Ref{Symbol}(:none)
1146+
debuginfo(sym) = sym === :default ? default_debuginfo[] : sym

base/show.jl

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2824,15 +2824,6 @@ end
28242824
module IRShow
28252825
using ..Compiler: Compiler
28262826
Base.include(IRShow, Base.strcat(Base.BUILDROOT, "../usr/share/julia/Compiler/src/ssair/show.jl"))
2827-
2828-
const __debuginfo = Dict{Symbol, Any}(
2829-
# :full => src -> statementidx_lineinfo_printer(src), # and add variable slot information
2830-
:source => src -> statementidx_lineinfo_printer(src),
2831-
# :oneliner => src -> statementidx_lineinfo_printer(PartialLineInfoPrinter, src),
2832-
:none => src -> lineinfo_disabled,
2833-
)
2834-
const default_debuginfo = Ref{Symbol}(:none)
2835-
debuginfo(sym) = sym === :default ? default_debuginfo[] : sym
28362827
end
28372828

28382829
function show(io::IO, src::CodeInfo; debuginfo::Symbol=:source)

0 commit comments

Comments
 (0)