Skip to content

Commit

Permalink
inliner needs to do method match tests early
Browse files Browse the repository at this point in the history
fix #18222
  • Loading branch information
vtjnash committed Aug 24, 2016
1 parent 3e65d68 commit 5d2ac0d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
51 changes: 26 additions & 25 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2524,26 +2524,10 @@ function inlineable(f::ANY, ft::ANY, e::Expr, atypes::Vector{Any}, sv::Inference
return invoke_NF()
end

(linfo, ty, inferred) = typeinf(method, metharg, methsp, false)
if linfo === nothing || !inferred
return invoke_NF()
end
if linfo !== nothing && linfo.jlcall_api == 2
# in this case function can be inlined to a constant
return inline_as_constant(linfo.constval, argexprs, enclosing)
elseif linfo !== nothing && !linfo.inlineable
return invoke_NF()
elseif linfo === nothing || linfo.code === nothing
(linfo, ty, inferred) = typeinf(method, metharg, methsp, true)
end
if linfo === nothing || !inferred || !linfo.inlineable || (ast = linfo.code) === nothing
return invoke_NF()
end

na = linfo.nargs
na = method.lambda_template.nargs
# check for vararg function
isva = false
if na > 0 && linfo.isva
if na > 0 && method.lambda_template.isva
@assert length(argexprs) >= na-1
# construct tuple-forming expression for argument tail
vararg = mk_tuplecall(argexprs[na:end], sv)
Expand All @@ -2559,17 +2543,34 @@ function inlineable(f::ANY, ft::ANY, e::Expr, atypes::Vector{Any}, sv::Inference

@assert na == length(argexprs)

spvals = Any[]
for i = 1:length(methsp)
si = methsp[i]
if isa(si, TypeVar)
return NF
end
push!(spvals, si)
isa(si, TypeVar) && return NF
end

(linfo, ty, inferred) = typeinf(method, metharg, methsp, false)
if linfo === nothing || !inferred
return invoke_NF()
end
if linfo !== nothing && linfo.jlcall_api == 2
# in this case function can be inlined to a constant
return inline_as_constant(linfo.constval, argexprs, enclosing)
elseif linfo !== nothing && !linfo.inlineable
return invoke_NF()
elseif linfo === nothing || linfo.code === nothing
(linfo, ty, inferred) = typeinf(method, metharg, methsp, true)
end
if linfo === nothing || !inferred || !linfo.inlineable || (ast = linfo.code) === nothing
return invoke_NF()
end

spvals = Any[]
for i = 1:length(methsp)
push!(spvals, methsp[i])
end
for i=1:length(spvals)
for i = 1:length(spvals)
si = spvals[i]
if isa(si,Symbol) || isa(si,SSAValue) || isa(si,Slot)
if isa(si, Symbol) || isa(si, SSAValue) || isa(si, Slot)
spvals[i] = QuoteNode(si)
end
end
Expand Down
7 changes: 7 additions & 0 deletions test/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,10 @@ let tri = Triple18015(1, 2, 3)
setabc18015!(tri, b18015(tri), c18015(tri), a18015(tri))
@test tri.a === 2 && tri.b === 3 && tri.c === 1
end

# issue #18222
f18222{T<:AbstractFloat}(::Union{T, Int}) = false
f18222(x) = true
g18222(x) = f18222(x)
@test f18222(1) == g18222(1) == true
@test f18222(1.0) == g18222(1.0) == false

0 comments on commit 5d2ac0d

Please sign in to comment.