Skip to content

Commit

Permalink
Merge pull request #254 from JuliaDebug/teh/more_optimizations
Browse files Browse the repository at this point in the history
More optimizations and a fix for `is_vararg_type`
  • Loading branch information
timholy authored Mar 31, 2019
2 parents cef5350 + 8b2d436 commit 0f99957
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
17 changes: 12 additions & 5 deletions src/generate_builtins.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ function nargs(f, table, id)
maxarg = typemax(Int)
end
# The tfunc tables are wrong for fptoui and fptosi (fixed in https://github.com/JuliaLang/julia/pull/30787)
if f == "Base.fptoui" || f == "Base.fptosi"
if f == Base.fptoui || f == Base.fptosi
minarg = 2
end
# Specialize arrayref and arrayset for small numbers of arguments
if f == Core.arrayref
maxarg = 5
elseif f == Core.arrayset
maxarg = 6
end
return minarg, maxarg
end

Expand Down Expand Up @@ -139,8 +145,9 @@ function maybe_evaluate_builtin(frame, call_expr, expand::Bool)
if !expand
return Some{Any}($fstr(argswrapped...))
end
argsflat = Base.append_any((argswrapped[1],), argswrapped[2:end]...)
new_expr = Expr(:call)
new_expr = Expr(:call, argswrapped[1])
popfirst!(argswrapped)
argsflat = Base.append_any(argswrapped...)
for x in argsflat
push!(new_expr.args, (isa(x, Symbol) || isa(x, Expr) || isa(x, QuoteNode)) ? QuoteNode(x) : x)
end
Expand Down Expand Up @@ -212,11 +219,11 @@ function maybe_evaluate_builtin(frame, call_expr, expand::Bool)
""")
end
# Now handle calls with bounded numbers of args
fcall = generate_fcall_nargs("f", minmin, maxmax)
print(io,
"""
if isa(f, Core.IntrinsicFunction)
$fcall
cargs = getargs(args, frame)
return Some{Any}(ccall(:jl_f_intrinsic_call, Any, (Any, Ptr{Any}, UInt32), f, cargs, length(cargs)))
""")
print(io,
"""
Expand Down
2 changes: 1 addition & 1 deletion src/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function resolvefc(frame, @nospecialize(expr))
error("unexpected ccall to ", expr)
end

function collect_args(frame, call_expr; isfc=false)
function collect_args(frame::Frame, call_expr::Expr; isfc::Bool=false)
args = frame.framedata.callargs
resize!(args, length(call_expr.args))
mod = moduleof(frame)
Expand Down
2 changes: 1 addition & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ is_leaf(frame::Frame) = frame.callee === nothing

function is_vararg_type(x)
if isa(x, Type)
x <: Vararg && return true
(x <: Vararg && !(x <: Union{})) && return true
if isa(x, UnionAll)
x = Base.unwrap_unionall(x)
end
Expand Down
1 change: 1 addition & 0 deletions test/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ end
# issue #6
@test @interpret(Array.body.body.name) === Array.body.body.name
@test @interpret(Vararg.body.body.name) === Vararg.body.body.name
@test !JuliaInterpreter.is_vararg_type(Union{})
frame = JuliaInterpreter.prepare_thunk(Main, :(Vararg.body.body.name))
@test JuliaInterpreter.finish_and_return!(frame, true) === Vararg.body.body.name
frame = JuliaInterpreter.prepare_thunk(Base, :(Union{AbstractChar,Tuple{Vararg{<:AbstractChar}},AbstractVector{<:AbstractChar},Set{<:AbstractChar}}))
Expand Down

0 comments on commit 0f99957

Please sign in to comment.