From da0116a860ed8440f6623e5daf206e68f380c087 Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki Date: Thu, 14 Nov 2024 17:27:35 +0900 Subject: [PATCH] allow the Compiler.jl stdlib to be installed on older version of Julia Since JuliaLang/julia#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. --- Compiler/src/Compiler.jl | 17 +++++++++++++++-- Compiler/src/ssair/show.jl | 9 +++++++++ base/show.jl | 9 --------- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Compiler/src/Compiler.jl b/Compiler/src/Compiler.jl index d454a4853a228..2320525c97907 100644 --- a/Compiler/src/Compiler.jl +++ b/Compiler/src/Compiler.jl @@ -1,15 +1,28 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license +if isdefined(Base, :end_base_include) && !isdefined(Base, :Compiler) + +# Define a dummy `Compiler` module to make it installable even on Julia versions where +# Compiler.jl is not available as a standard library. +@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)) diff --git a/Compiler/src/ssair/show.jl b/Compiler/src/ssair/show.jl index 6e4f2004e1a84..22394c84eb2f7 100644 --- a/Compiler/src/ssair/show.jl +++ b/Compiler/src/ssair/show.jl @@ -1135,3 +1135,12 @@ function Base.show(io::IO, tinf::Timings.Timing) end @specialize + +const __debuginfo = Dict{Symbol, Any}( + # :full => src -> statementidx_lineinfo_printer(src), # and add variable slot information + :source => src -> statementidx_lineinfo_printer(src), + # :oneliner => src -> statementidx_lineinfo_printer(PartialLineInfoPrinter, src), + :none => src -> lineinfo_disabled, + ) +const default_debuginfo = Ref{Symbol}(:none) +debuginfo(sym) = sym === :default ? default_debuginfo[] : sym diff --git a/base/show.jl b/base/show.jl index e332cf521addb..6fa3f0cf8c454 100644 --- a/base/show.jl +++ b/base/show.jl @@ -2824,15 +2824,6 @@ end module IRShow using ..Compiler: Compiler Base.include(IRShow, Base.strcat(Base.BUILDROOT, "../usr/share/julia/Compiler/src/ssair/show.jl")) - - const __debuginfo = Dict{Symbol, Any}( - # :full => src -> statementidx_lineinfo_printer(src), # and add variable slot information - :source => src -> statementidx_lineinfo_printer(src), - # :oneliner => src -> statementidx_lineinfo_printer(PartialLineInfoPrinter, src), - :none => src -> lineinfo_disabled, - ) - const default_debuginfo = Ref{Symbol}(:none) - debuginfo(sym) = sym === :default ? default_debuginfo[] : sym end function show(io::IO, src::CodeInfo; debuginfo::Symbol=:source)