Skip to content

Commit 0f99957

Browse files
authored
Merge pull request #254 from JuliaDebug/teh/more_optimizations
More optimizations and a fix for `is_vararg_type`
2 parents cef5350 + 8b2d436 commit 0f99957

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

src/generate_builtins.jl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@ function nargs(f, table, id)
2222
maxarg = typemax(Int)
2323
end
2424
# The tfunc tables are wrong for fptoui and fptosi (fixed in https://github.com/JuliaLang/julia/pull/30787)
25-
if f == "Base.fptoui" || f == "Base.fptosi"
25+
if f == Base.fptoui || f == Base.fptosi
2626
minarg = 2
2727
end
28+
# Specialize arrayref and arrayset for small numbers of arguments
29+
if f == Core.arrayref
30+
maxarg = 5
31+
elseif f == Core.arrayset
32+
maxarg = 6
33+
end
2834
return minarg, maxarg
2935
end
3036

@@ -139,8 +145,9 @@ function maybe_evaluate_builtin(frame, call_expr, expand::Bool)
139145
if !expand
140146
return Some{Any}($fstr(argswrapped...))
141147
end
142-
argsflat = Base.append_any((argswrapped[1],), argswrapped[2:end]...)
143-
new_expr = Expr(:call)
148+
new_expr = Expr(:call, argswrapped[1])
149+
popfirst!(argswrapped)
150+
argsflat = Base.append_any(argswrapped...)
144151
for x in argsflat
145152
push!(new_expr.args, (isa(x, Symbol) || isa(x, Expr) || isa(x, QuoteNode)) ? QuoteNode(x) : x)
146153
end
@@ -212,11 +219,11 @@ function maybe_evaluate_builtin(frame, call_expr, expand::Bool)
212219
""")
213220
end
214221
# Now handle calls with bounded numbers of args
215-
fcall = generate_fcall_nargs("f", minmin, maxmax)
216222
print(io,
217223
"""
218224
if isa(f, Core.IntrinsicFunction)
219-
$fcall
225+
cargs = getargs(args, frame)
226+
return Some{Any}(ccall(:jl_f_intrinsic_call, Any, (Any, Ptr{Any}, UInt32), f, cargs, length(cargs)))
220227
""")
221228
print(io,
222229
"""

src/interpret.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function resolvefc(frame, @nospecialize(expr))
135135
error("unexpected ccall to ", expr)
136136
end
137137

138-
function collect_args(frame, call_expr; isfc=false)
138+
function collect_args(frame::Frame, call_expr::Expr; isfc::Bool=false)
139139
args = frame.framedata.callargs
140140
resize!(args, length(call_expr.args))
141141
mod = moduleof(frame)

src/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ is_leaf(frame::Frame) = frame.callee === nothing
148148

149149
function is_vararg_type(x)
150150
if isa(x, Type)
151-
x <: Vararg && return true
151+
(x <: Vararg && !(x <: Union{})) && return true
152152
if isa(x, UnionAll)
153153
x = Base.unwrap_unionall(x)
154154
end

test/interpret.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ end
9999
# issue #6
100100
@test @interpret(Array.body.body.name) === Array.body.body.name
101101
@test @interpret(Vararg.body.body.name) === Vararg.body.body.name
102+
@test !JuliaInterpreter.is_vararg_type(Union{})
102103
frame = JuliaInterpreter.prepare_thunk(Main, :(Vararg.body.body.name))
103104
@test JuliaInterpreter.finish_and_return!(frame, true) === Vararg.body.body.name
104105
frame = JuliaInterpreter.prepare_thunk(Base, :(Union{AbstractChar,Tuple{Vararg{<:AbstractChar}},AbstractVector{<:AbstractChar},Set{<:AbstractChar}}))

0 commit comments

Comments
 (0)