Skip to content

Commit

Permalink
allow the Compiler.jl stdlib to be installed on older version of Julia
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aviatesk committed Nov 14, 2024
1 parent aa05c98 commit da54d89
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Compiler/src/Compiler.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

if !isdefined(Base, :__Compiler_as_stdlib_available__)

@eval module Compiler
function __init__()
println("""
The `Compiler` standard library is not available for this version of Julia.
Use Julia version `v"1.12.0-DEV.1581"` or later.
""")
end
end

# When generating an incremental precompile file, we first check whether we
# already have a copy of this *exact* code in the system image. If so, we
# simply generates a pkgimage that has the dependency edges we recorded in
# the system image and simply returns that copy of the compiler. If not,
# we proceed to load/precompile this as an ordinary package.
if isdefined(Base, :generating_output) && Base.generating_output(true) &&
elseif (isdefined(Base, :generating_output) && Base.generating_output(true) &&
Base.samefile(joinpath(Sys.BINDIR, Base.DATAROOTDIR, Base._compiler_require_dependencies[1][2]), @eval @__FILE__) &&
!Base.any_includes_stale(
map(Base.compiler_chi, Base._compiler_require_dependencies),
"sysimg", nothing)
"sysimg", nothing))

Base.prepare_compiler_stub_image!()
append!(Base._require_dependencies, map(Base.expand_compiler_path, Base._compiler_require_dependencies))
Expand Down
8 changes: 8 additions & 0 deletions base/Base_compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,14 @@ process_sysimg_args!()

function isready end

"""
Base.__Compiler_as_stdlib_available__
This is a token for switching the definition of `Compiler` to make it installable even on
Julia versions where Compiler.jl is not available as a standard library.
"""
const __Compiler_as_stdlib_available__ = true

include(strcat(BUILDROOT, "../usr/share/julia/Compiler/src/Compiler.jl"))

const _return_type = Compiler.return_type
Expand Down

0 comments on commit da54d89

Please sign in to comment.