Skip to content

Commit 8369a15

Browse files
authored
allow the Compiler.jl stdlib to be installed on older version of Julia (JuliaLang#56553)
Since JuliaLang#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. Also includes a change to include `ssair/show.jl` in the context of `Compiler` to ensure that stale precompilation caches are not used. And as a result this commit bumps the version of the Compiler.jl standard library.
1 parent 2284d6d commit 8369a15

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
name = "Compiler"
22
uuid = "807dbc54-b67e-4c79-8afb-eafe4df6f2e1"
3-
version = "0.0.1"
3+
version = "0.0.2"

src/Compiler.jl

Lines changed: 21 additions & 8 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))
@@ -167,12 +180,12 @@ include("optimize.jl")
167180
include("bootstrap.jl")
168181
include("reflection_interface.jl")
169182

170-
if isdefined(Base, :IRShow)
171-
@eval module IRShow
172-
using ..Compiler: Compiler
173-
# During bootstrap, Base will later include this into its own "IRShow module"
174-
Compiler.include(IRShow, "ssair/show.jl")
175-
end
183+
module IRShow end
184+
if !isdefined(Base, :end_base_include)
185+
# During bootstrap, skip including this file and defer it to base/show.jl to include later
186+
else
187+
# When this module is loaded as the standard library, include this file as usual
188+
include(IRShow, "ssair/show.jl")
176189
end
177190

178191
end # baremodule Compiler

src/ssair/show.jl

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

3-
# This file is not loaded into `Core.Compiler` but rather loaded into the context of
4-
# `Base.IRShow` and thus does not participate in bootstrapping.
3+
# This file does not participate in bootstrapping, but is included in the system image by
4+
# being loaded from `base/show.jl`. Compiler.jl as the standard library will simply include
5+
# this file in the context of `Compiler.IRShow`.
56

67
using Base, Core.IR
78

@@ -1135,3 +1136,12 @@ function Base.show(io::IO, tinf::Timings.Timing)
11351136
end
11361137

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

0 commit comments

Comments
 (0)