Skip to content

Commit e77fbfb

Browse files
authored
Simplify precompiles (#71)
This switches to "do a little work" for precompilation, rather than explicitly spelling out the specific signatures. This should be more maintainable and potentially more exhaustive (or could be made to be so) since it precompiles across runtime dispatch boundaries.
1 parent 5f36e09 commit e77fbfb

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

src/packagedef.jl

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,32 @@ include("codeedges.jl")
2020
# precompilation
2121

2222
if ccall(:jl_generating_output, Cint, ()) == 1
23-
kwdefine = NamedTuple{(:define,),Tuple{Bool}}
24-
for ct in (Vector{Any}, Set{Any})
25-
f = methoddef!
26-
m = which(f, Tuple{Function, ct, Frame, Expr, Int})
27-
@assert precompile(Tuple{typeof(f), Function, ct, Frame, Expr, Int})
28-
mbody = bodymethod(m)
29-
# @assert precompile(Tuple{mbody.sig.parameters[1], Bool, typeof(f), Function, ct, Frame, Expr, Int})
30-
@assert precompile(Tuple{Core.kwftype(typeof(f)), kwdefine, typeof(f), Function, ct, Frame, Expr, Int})
31-
f = methoddefs!
32-
@assert precompile(Tuple{typeof(f), Any, ct, Frame})
33-
@assert precompile(Tuple{Core.kwftype(typeof(f)), kwdefine, typeof(f), Function, ct, Frame})
23+
ex = :(f(x; color::Symbol=:green) = 2x)
24+
lwr = Meta.lower(@__MODULE__, ex)
25+
frame = Frame(@__MODULE__, lwr.args[1])
26+
rename_framemethods!(frame)
27+
ex = quote
28+
s = 0
29+
k = 5
30+
for i = 1:3
31+
global s, k
32+
s += rand(1:5)
33+
k += i
34+
end
3435
end
35-
@assert precompile(Tuple{typeof(rename_framemethods!), Any, Frame, Dict{Symbol,MethodInfo},
36-
Vector{SelfCall}, Dict{Symbol,Union{Nothing, Bool, Symbol}}})
37-
@assert precompile(Tuple{typeof(rename_framemethods!), Any, Frame, Dict{Symbol,MethodInfo},
38-
Vector{NamedTuple{(:linetop, :linebody, :callee, :caller),Tuple{Int64,Int64,Symbol,Union{Bool, Symbol}}}},
39-
Dict{Symbol,Union{Bool, Symbol}}})
40-
@assert precompile(Tuple{typeof(identify_framemethod_calls), Frame})
41-
@assert precompile(Tuple{typeof(callchain), Vector{SelfCall}})
42-
@assert precompile(Tuple{typeof(callchain), Vector{NamedTuple{(:linetop, :linebody, :callee, :caller),Tuple{Int64,Int64,Symbol,Union{Bool, Symbol}}}}})
43-
44-
@assert precompile(CodeLinks, (Int, Int))
45-
@assert precompile(CodeEdges, (Int,))
46-
@assert precompile(CodeEdges, (CodeInfo,))
47-
@assert precompile(add_links!, (Pair{Union{SSAValue,SlotNumber,NamedVar},Links}, Any, CodeLinks))
48-
@assert precompile(lines_required!, (Vector{Bool}, Set{NamedVar}, CodeInfo, CodeEdges))
49-
50-
precompile(Tuple{typeof(setindex!),Dict{Union{GlobalRef, Symbol},Links},Links,Symbol})
51-
precompile(Tuple{typeof(setindex!),Dict{Union{GlobalRef, Symbol},Variable},Variable,Symbol})
36+
lwr = Meta.lower(@__MODULE__, ex)
37+
src = lwr.args[1]
38+
edges = CodeEdges(src)
39+
isrequired = lines_required(:s, src, edges)
40+
lines_required(:s, src, edges; norequire=())
41+
lines_required(:s, src, edges; norequire=exclude_named_typedefs(src, edges))
42+
for isreq in (isrequired, convert(Vector{Bool}, isrequired))
43+
lines_required!(isreq, src, edges; norequire=())
44+
lines_required!(isreq, src, edges; norequire=exclude_named_typedefs(src, edges))
45+
end
46+
frame = Frame(@__MODULE__, src)
47+
# selective_eval_fromstart!(frame, isrequired, true)
48+
precompile(selective_eval_fromstart!, (typeof(frame), typeof(isrequired), Bool)) # can't @eval during precompilation
49+
print_with_code(Base.inferencebarrier(devnull)::IO, src, edges)
50+
print_with_code(Base.inferencebarrier(devnull)::IO, src, isrequired)
5251
end

0 commit comments

Comments
 (0)