Skip to content

Commit

Permalink
Merge pull request #10 from JuliaDebug/teh/precompile
Browse files Browse the repository at this point in the history
Add some precompile statements for faster startup
  • Loading branch information
timholy authored Feb 10, 2019
2 parents 4d11b77 + 1dde970 commit dbe023d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/JuliaInterpreter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ julia> JuliaInterpreter.prepare_args(mymethod, [mymethod, 1, 2], [:verbose=>true
(getfield( Symbol("#kw##mymethod"))(), Any[#kw##mymethod(), (verbose = true,), mymethod, 1, 2])
```
"""
function prepare_args(f, allargs, kwargs)
function prepare_args(@nospecialize(f), allargs, kwargs)
if !isempty(kwargs)
of = f
f = Core.kwfunc(f)
Expand Down Expand Up @@ -267,7 +267,7 @@ julia> argtypes
Tuple{typeof(mymethod),Array{Float64,1}}
```
"""
function prepare_call(f, allargs; enter_generated = false)
function prepare_call(@nospecialize(f), allargs; enter_generated = false)
args = allargs[2:end]
argtypes = Tuple{map(_Typeof,args)...}
method = try
Expand Down Expand Up @@ -871,4 +871,7 @@ macro interpret(arg)
end
end

include("precompile.jl")
_precompile_()

end # module
4 changes: 2 additions & 2 deletions src/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ end
# and hence our re-use of the `callargs` field of JuliaStackFrame would introduce
# bugs. Since these nodes use a very limited repertoire of calls, we can special-case
# this quite easily.
function lookup_or_eval(stack, frame, node, pc)
function lookup_or_eval(stack, frame, @nospecialize(node), pc)
if isa(node, SSAValue)
return lookup_var(frame, node)
elseif isa(node, SlotNumber)
Expand Down Expand Up @@ -106,7 +106,7 @@ end
instantiate_type_in_env(arg, spsig, spvals) =
ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), arg, spsig, spvals)

function resolvefc(expr)
function resolvefc(@nospecialize expr)
(isa(expr, Symbol) || isa(expr, String) || isa(expr, QuoteNode)) && return expr
if isexpr(expr, :call)
a = expr.args[1]
Expand Down
47 changes: 47 additions & 0 deletions src/precompile.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
function _precompile_()
ccall(:jl_generating_output, Cint, ()) == 1 || return nothing
precompile(Tuple{typeof(maybe_evaluate_builtin), JuliaStackFrame, Expr})
precompile(Tuple{typeof(getargs), Vector{Any}, JuliaStackFrame})
precompile(Tuple{typeof(get_call_framecode), Vector{Any}, JuliaFrameCode, Int})
for f in (evaluate_call!,
evaluate_foreigncall!,
evaluate_methoddef!,
evaluate_structtype!,
evaluate_abstracttype!,
evaluate_primitivetype!)
precompile(Tuple{typeof(f), Compiled, JuliaStackFrame, Expr, JuliaProgramCounter})
precompile(Tuple{typeof(f), Vector{JuliaStackFrame}, JuliaStackFrame, Expr, JuliaProgramCounter})
end
precompile(Tuple{typeof(lookup_global_refs!), Expr})
precompile(Tuple{typeof(lookup_or_eval), Compiled, JuliaStackFrame, Any, JuliaProgramCounter})
precompile(Tuple{typeof(lookup_or_eval), Vector{JuliaStackFrame}, JuliaStackFrame, Any, JuliaProgramCounter})
precompile(Tuple{typeof(eval_rhs), Compiled, JuliaStackFrame, Expr, JuliaProgramCounter})
precompile(Tuple{typeof(eval_rhs), Vector{JuliaStackFrame}, JuliaStackFrame, Expr, JuliaProgramCounter})
precompile(Tuple{typeof(_step_expr!), Compiled, JuliaStackFrame, Any, JuliaProgramCounter, Bool})
precompile(Tuple{typeof(_step_expr!), Vector{JuliaStackFrame}, JuliaStackFrame, Any, JuliaProgramCounter, Bool})
for f in (finish!, finish_and_return!)
precompile(Tuple{typeof(f), Compiled, JuliaStackFrame, JuliaProgramCounter, Bool})
precompile(Tuple{typeof(f), Vector{JuliaStackFrame}, JuliaStackFrame, JuliaProgramCounter, Bool})
end
precompile(Tuple{typeof(prepare_toplevel), Module, Expr})
precompile(Tuple{typeof(prepare_thunk), Module, Expr})
precompile(Tuple{typeof(prepare_locals), JuliaFrameCode, Vector{Any}})
precompile(Tuple{typeof(prepare_args), Any, Vector{Any}, Vector{Any}})
precompile(Tuple{typeof(prepare_call), Any, Vector{Any}})
precompile(Tuple{typeof(build_frame), JuliaFrameCode, Vector{Any}, Core.SimpleVector})
precompile(Tuple{typeof(extract_args), Module, Expr})
precompile(Tuple{typeof(enter_call), Int, Int})
precompile(Tuple{typeof(enter_call_expr), Expr})
precompile(Tuple{typeof(copy_codeinfo), Core.CodeInfo})
precompile(Tuple{typeof(optimize!), Core.CodeInfo, Module})
precompile(Tuple{typeof(interpret!), Vector{JuliaStackFrame}, Module, Expr})
precompile(Tuple{typeof(set_structtype_const), Module, Symbol})
precompile(Tuple{typeof(namedtuple), Vector{Any}})
precompile(Tuple{typeof(resolvefc), Any})
precompile(Tuple{typeof(checkfor_head), typeof(cant_be_lowered), Expr})
precompile(Tuple{typeof(check_isdefined), JuliaStackFrame, Expr})
precompile(Tuple{typeof(check_isdefined), JuliaStackFrame, Symbol})
precompile(Tuple{typeof(find_used), Core.CodeInfo})
precompile(Tuple{typeof(do_assignment!), JuliaStackFrame, Int, Int})
precompile(Tuple{typeof(pc_expr), JuliaStackFrame, Nothing})
end

0 comments on commit dbe023d

Please sign in to comment.