Skip to content

Commit 2ffb2bc

Browse files
timholyElOceanografo
authored andcommitted
Internalize Revise precompiles into Base
For some reason (perhaps JuliaLang#32705?) most or all of these fail if they are emitted as precompile statements, so this moves them into Base itself. This drops the time for a revision down to 1.85s.
1 parent e612038 commit 2ffb2bc

File tree

2 files changed

+68
-28
lines changed

2 files changed

+68
-28
lines changed

base/Base.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,42 @@ end_base_include = time_ns()
391391
const _sysimage_modules = PkgId[]
392392
in_sysimage(pkgid::PkgId) = pkgid in _sysimage_modules
393393

394+
# Precompiles for Revise
395+
# TODO: move these to contrib/generate_precompile.jl
396+
# The problem is they don't work there
397+
let m = which(+, (Int, Int))
398+
while true # defeat interpreter heuristic to force compilation
399+
delete!(push!(Set{Method}(), m), m)
400+
copy(Core.Compiler.retrieve_code_info(Core.Compiler.specialize_method(m, [Int, Int], Core.svec())))
401+
402+
empty!(Set())
403+
push!(push!(Set{Union{GlobalRef,Symbol}}(), :two), GlobalRef(Base, :two))
404+
(setindex!(Dict{String,Base.PkgId}(), Base.PkgId(Base), "file.jl"))["file.jl"]
405+
(setindex!(Dict{Symbol,Vector{Int}}(), [1], :two))[:two]
406+
(setindex!(Dict{Base.PkgId,String}(), "file.jl", Base.PkgId(Base)))[Base.PkgId(Base)]
407+
(setindex!(Dict{Union{GlobalRef,Symbol}, Vector{Int}}(), [1], :two))[:two]
408+
(setindex!(IdDict{Type, Union{Missing, Vector{Tuple{LineNumberNode, Expr}}}}(), missing, Int))[Int]
409+
Dict{Symbol, Union{Nothing, Bool, Symbol}}(:one => false)[:one]
410+
Dict(Base => [:(1+1)])[Base]
411+
Dict(:one => [1])[:one]
412+
Dict("abc" => Set())["abc"]
413+
pushfirst!([], sum)
414+
get(Base.pkgorigins, Base.PkgId(Base), nothing)
415+
sort!([1,2,3])
416+
unique!([1,2,3])
417+
cumsum([1,2,3])
418+
append!(Int[], BitSet())
419+
isempty(BitSet())
420+
delete!(BitSet([1,2]), 3)
421+
deleteat!(Int32[1,2,3], [1,3])
422+
deleteat!(Any[1,2,3], [1,3])
423+
Core.svec(1, 2) == Core.svec(3, 4)
424+
any(t->t[1].line > 1, [(LineNumberNode(2,:none), :(1+1))])
425+
426+
break # end defeat interpreter heuristic
427+
end
428+
end
429+
394430
if is_primary_base_module
395431
function __init__()
396432
# try to ensuremake sure OpenBLAS does not set CPU affinity (#1070, #9639)

contrib/generate_precompile.jl

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -56,34 +56,38 @@ cd("complet_path\t\t$CTRL_C
5656
"""
5757

5858
precompile_script = """
59-
# Used by Revise & its dependencies
60-
delete!(push!(Set{Module}(), Base), Main)
61-
m = first(methods(+))
62-
delete!(push!(Set{Method}(), m), m)
63-
empty!(Set())
64-
push!(push!(Set{Union{GlobalRef,Symbol}}(), :two), GlobalRef(Base, :two))
65-
(setindex!(Dict{String,Base.PkgId}(), Base.PkgId(Base), "file.jl"))["file.jl"]
66-
(setindex!(Dict{Symbol,Vector{Int}}(), [1], :two))[:two]
67-
(setindex!(Dict{Base.PkgId,String}(), "file.jl", Base.PkgId(Base)))[Base.PkgId(Base)]
68-
(setindex!(Dict{Union{GlobalRef,Symbol}, Vector{Int}}(), [1], :two))[:two]
69-
(setindex!(IdDict{Type, Union{Missing, Vector{Tuple{LineNumberNode, Expr}}}}(), missing, Int))[Int]
70-
Dict{Symbol, Union{Nothing, Bool, Symbol}}(:one => false)[:one]
71-
Dict(Base => [:(1+1)])[Base]
72-
Dict(:one => [1])[:one]
73-
Dict("abc" => Set())["abc"]
74-
pushfirst!([], sum)
75-
get(Base.pkgorigins, Base.PkgId(Base), nothing)
76-
sort!([1,2,3])
77-
unique!([1,2,3])
78-
cumsum([1,2,3])
79-
append!(Int[], BitSet())
80-
isempty(BitSet())
81-
delete!(BitSet([1,2]), 3)
82-
deleteat!(Int32[1,2,3], [1,3])
83-
deleteat!(Any[1,2,3], [1,3])
84-
Core.svec(1, 2) == Core.svec(3, 4)
85-
copy(Core.Compiler.retrieve_code_info(Core.Compiler.specialize_method(which(+, (Int, Int)), [Int, Int], Core.svec())))
86-
any(t->t[1].line > 1, [(LineNumberNode(2,:none),:(1+1))])
59+
# NOTE: these were moved to the end of Base.jl. TODO: move back here.
60+
# # Used by Revise & its dependencies
61+
# while true # force inference
62+
# delete!(push!(Set{Module}(), Base), Main)
63+
# m = first(methods(+))
64+
# delete!(push!(Set{Method}(), m), m)
65+
# empty!(Set())
66+
# push!(push!(Set{Union{GlobalRef,Symbol}}(), :two), GlobalRef(Base, :two))
67+
# (setindex!(Dict{String,Base.PkgId}(), Base.PkgId(Base), "file.jl"))["file.jl"]
68+
# (setindex!(Dict{Symbol,Vector{Int}}(), [1], :two))[:two]
69+
# (setindex!(Dict{Base.PkgId,String}(), "file.jl", Base.PkgId(Base)))[Base.PkgId(Base)]
70+
# (setindex!(Dict{Union{GlobalRef,Symbol}, Vector{Int}}(), [1], :two))[:two]
71+
# (setindex!(IdDict{Type, Union{Missing, Vector{Tuple{LineNumberNode, Expr}}}}(), missing, Int))[Int]
72+
# Dict{Symbol, Union{Nothing, Bool, Symbol}}(:one => false)[:one]
73+
# Dict(Base => [:(1+1)])[Base]
74+
# Dict(:one => [1])[:one]
75+
# Dict("abc" => Set())["abc"]
76+
# pushfirst!([], sum)
77+
# get(Base.pkgorigins, Base.PkgId(Base), nothing)
78+
# sort!([1,2,3])
79+
# unique!([1,2,3])
80+
# cumsum([1,2,3])
81+
# append!(Int[], BitSet())
82+
# isempty(BitSet())
83+
# delete!(BitSet([1,2]), 3)
84+
# deleteat!(Int32[1,2,3], [1,3])
85+
# deleteat!(Any[1,2,3], [1,3])
86+
# Core.svec(1, 2) == Core.svec(3, 4)
87+
# # copy(Core.Compiler.retrieve_code_info(Core.Compiler.specialize_method(which(+, (Int, Int)), [Int, Int], Core.svec())))
88+
# any(t->t[1].line > 1, [(LineNumberNode(2,:none),:(1+1))])
89+
# break # end force inference
90+
# end
8791
"""
8892

8993
julia_exepath() = joinpath(Sys.BINDIR::String, Base.julia_exename())

0 commit comments

Comments
 (0)