From 401b724fbbf5a59cc47cb624b01d563517857234 Mon Sep 17 00:00:00 2001 From: Martin Holters Date: Tue, 20 Jun 2017 08:22:56 +0200 Subject: [PATCH] Don't special-case inference of splatting ::Any parameters (#22364) --- base/inference.jl | 31 ++++++++++--------------------- test/inference.jl | 7 +++++++ 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/base/inference.jl b/base/inference.jl index 549e7b6b4b895..db09e8d35ea17 100644 --- a/base/inference.jl +++ b/base/inference.jl @@ -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 diff --git a/test/inference.jl b/test/inference.jl index 360b262ee5c5e..54574454b765f 100644 --- a/test/inference.jl +++ b/test/inference.jl @@ -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