Skip to content

Commit cc1623b

Browse files
committed
Internalize Revise precompiles into Base
For some reason (perhaps #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 4c4e078 commit cc1623b

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
@@ -55,34 +55,38 @@ cd("complet_path\t\t$CTRL_C
5555
"""
5656

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

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

0 commit comments

Comments
 (0)