Skip to content

Commit

Permalink
Don't special-case inference of splatting ::Any parameters (#22364)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholters authored Jun 20, 2017
1 parent 6db340c commit 401b724
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
31 changes: 10 additions & 21 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1879,30 +1879,19 @@ function abstract_apply(aft::ANY, fargs::Vector{Any}, aargtypes::Vector{Any}, vt
splitunions = 1 < countunionsplit(aargtypes) <= sv.params.MAX_APPLY_UNION_ENUM
ctypes = Any[Any[aft]]
for i = 1:nargs
if aargtypes[i] === Any
# bail out completely and infer as f(::Any...)
# instead could infer the precise types for the types up to this point and just append a Vararg{Any}
# (by just using the normal logic from below), but that makes the time of the subarray test explode
push!(ctypes[1], Vararg{Any})
break
end
end
if length(ctypes[1]) == 1
for i = 1:nargs
ctypes´ = []
for ti in (splitunions ? uniontypes(aargtypes[i]) : Any[aargtypes[i]])
cti = precise_container_type(fargs[i], ti, vtypes, sv)
for ct in ctypes
if !isempty(ct) && isvarargtype(ct[end])
tail = tuple_tail_elem(unwrapva(ct[end]), cti)
push!(ctypes´, push!(ct[1:(end - 1)], tail))
else
push!(ctypes´, append_any(ct, cti))
end
ctypes´ = []
for ti in (splitunions ? uniontypes(aargtypes[i]) : Any[aargtypes[i]])
cti = precise_container_type(fargs[i], ti, vtypes, sv)
for ct in ctypes
if !isempty(ct) && isvarargtype(ct[end])
tail = tuple_tail_elem(unwrapva(ct[end]), cti)
push!(ctypes´, push!(ct[1:(end - 1)], tail))
else
push!(ctypes´, append_any(ct, cti))
end
end
ctypes = ctypes´
end
ctypes = ctypes´
end
for ct in ctypes
if length(ct) > sv.params.MAX_TUPLETYPE_LEN
Expand Down
7 changes: 7 additions & 0 deletions test/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -949,3 +949,10 @@ copy_dims_pair(out, dim::Int, tail...) = copy_dims_out(out => dim, tail...)
copy_dims_pair(out, dim::Colon, tail...) = copy_dims_out(out => dim, tail...)
@test Base.return_types(copy_dims_pair, (Tuple{}, Vararg{Union{Int,Colon}})) == Any[Tuple{}, Tuple{}, Tuple{}]
@test all(m -> 5 < count_specializations(m) < 25, methods(copy_dims_out))

# splatting an ::Any should still allow inference to use types of parameters preceding it
f22364(::Int, ::Any...) = 0
f22364(::String, ::Any...) = 0.0
g22364(x) = f22364(x, Any[[]][1]...)
@test @inferred(g22364(1)) === 0
@test @inferred(g22364("1")) === 0.0

0 comments on commit 401b724

Please sign in to comment.