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
#56553)

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.

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.
  • Loading branch information
aviatesk authored Nov 14, 2024
1 parent 286ece2 commit 1e063d8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Compiler/Project.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name = "Compiler"
uuid = "807dbc54-b67e-4c79-8afb-eafe4df6f2e1"
version = "0.0.1"
version = "0.0.2"
29 changes: 21 additions & 8 deletions Compiler/src/Compiler.jl
Original file line number Diff line number Diff line change
@@ -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))
Expand Down Expand Up @@ -167,12 +180,12 @@ include("optimize.jl")
include("bootstrap.jl")
include("reflection_interface.jl")

if isdefined(Base, :IRShow)
@eval module IRShow
using ..Compiler: Compiler
# During bootstrap, Base will later include this into its own "IRShow module"
Compiler.include(IRShow, "ssair/show.jl")
end
module IRShow end
if !isdefined(Base, :end_base_include)
# During bootstrap, skip including this file and defer it to base/show.jl to include later
else
# When this module is loaded as the standard library, include this file as usual
include(IRShow, "ssair/show.jl")
end

end # baremodule Compiler
Expand Down
14 changes: 12 additions & 2 deletions Compiler/src/ssair/show.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

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

using Base, Core.IR

Expand Down Expand Up @@ -1135,3 +1136,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
15 changes: 2 additions & 13 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2821,19 +2821,8 @@ function show(io::IO, vm::Core.TypeofVararg)
end
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
Compiler.include(Compiler.IRShow, "ssair/show.jl") # define `show` for the compiler types
const IRShow = Compiler.IRShow # an alias for compatibility

function show(io::IO, src::CodeInfo; debuginfo::Symbol=:source)
# Fix slot names and types in function body
Expand Down

2 comments on commit 1e063d8

@aviatesk
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register subdir=Compiler

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/119404

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a Compiler-v0.0.2 -m "<description of version>" 1e063d8e75b708e61afa6a011b0719172f505c34
git push origin Compiler-v0.0.2

Please sign in to comment.