Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inference error from new Tuple / Vararg types #10930

Closed
vtjnash opened this issue Apr 21, 2015 · 1 comment
Closed

inference error from new Tuple / Vararg types #10930

vtjnash opened this issue Apr 21, 2015 · 1 comment
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@vtjnash
Copy link
Member

vtjnash commented Apr 21, 2015

julia> f() = _apply(call, tuple, (f(x)::Vararg,), (f(y)::Vararg,))
f (generic function with 1 method)

julia> code_typed(f,())
ERROR: Vararg type in non-final position
 in abstract_call at ./inference.jl:871
 in abstract_apply at ./inference.jl:766
 in abstract_call at ./inference.jl:814
 in abstract_eval_call at ./inference.jl:901
 in abstract_eval at ./inference.jl:928
 in typeinf_uncached at ./inference.jl:1588
 in typeinf at ./inference.jl:1304
 in code_typed at inference.jl:3256

this is a reduced test case from a situation that comes up at the end of building the sysimg with --compile=all when trying to precompile the following definition:

function promote(x, y, zs...)
    # promotion.jl:139
    (convert(promote_typeof(x,y,zs...), x), 
     convert(promote_typeof(x,y,zs...), y), 
     convert(Tuple{Vararg{promote_typeof(x,y,zs...)}}, zs)...)
end

I suspect that issue may come from inferring that the return values of convert(Tuple{Vararg}, zs)...) is Vararg (rather than Any), although the stacktrace shows that this results from attempting to infer the result type of the following expression:

Base.cnvt_all(::Type{_<:Vararg{T<:Any}}, ::Any, ::Vararg{Any}) =

Expr(:call1, top(:_apply), :call, :tuple,
  Expr(:call1, top(:tuple),
    Expr(:call1, :convert, :T, :x)::Vararg{T<:Any}
  )::Tuple{Vararg{T<:Any}},
  Expr(:call1, top(:_apply), :call, :cnvt_all,
    Expr(:call1, top(:tuple), :T)::Tuple{Type{_<:Vararg{T<:Any}}},
    :rest
  )::Tuple{Vararg{T<:Any}}
)::Tuple{Vararg{T<:Any}}

this in turn came from:

Base.convert{T}(::Type{Tuple{_<:Vararg{T}}}, ::Tuple}) =
Expr(:call1, top(:_apply), :call, :cnvt_all, Expr(:call1, top(:tuple), :T)::Tuple{Type{_<:Vararg{T<:Any}}}, :x)::Any

with T=_<:Vararg

note, these are defined in base as:

convert{T}(::Type{Tuple{Vararg{T}}}, x::Tuple) = cnvt_all(T, x...)
cnvt_all(T, x, rest...) = tuple(convert(T,x), cnvt_all(T, rest...)...)

finally, that in turn came from part of our original expression:

Expr(:call, :convert, Expr(:call1, top(:apply_type), :Tuple, Expr(:call1, top(:apply_type), :Vararg, Expr(:call1, top(:_apply), :call, :promote_typeof, Expr(:call1, top(:tuple), :x, :y)::Tuple{Any, Any}, :zs)::Type)::Type{_<:Vararg{T<:Any}})::Type{_<:Tuple{_<:Vararg{T<:Any}}}, :zs)::Any

edit: I realized this can also be triggered directly:

julia> code_typed(promote,(Any,Any,Vararg{Any}))
ERROR: Vararg type in non-final position
 in abstract_call at ./inference.jl:871
 in abstract_apply at ./inference.jl:766
 in abstract_call at ./inference.jl:814
 in abstract_eval_call at ./inference.jl:901
 in abstract_eval at ./inference.jl:928
 in typeinf_uncached at ./inference.jl:1588
 in typeinf at ./inference.jl:1304
 in typeinf at ./inference.jl:1254
 in abstract_call_gf at ./inference.jl:693
 in abstract_call at ./inference.jl:837
 in abstract_apply at ./inference.jl:766
 in abstract_call at ./inference.jl:814
 in abstract_eval_call at ./inference.jl:901
 in abstract_eval at ./inference.jl:928
 in typeinf_uncached at ./inference.jl:1588
 in typeinf at ./inference.jl:1304
 in typeinf at ./inference.jl:1254
 in abstract_call_gf at ./inference.jl:693
 in abstract_call at ./inference.jl:837
 in abstract_eval_call at ./inference.jl:901
 in abstract_eval at ./inference.jl:928
 in abstract_eval_call at ./inference.jl:878
 in abstract_eval at ./inference.jl:928
 in typeinf_uncached at ./inference.jl:1588
 in typeinf at ./inference.jl:1304
 in code_typed at inference.jl:3256
@JeffBezanson JeffBezanson added the bug Indicates an unexpected problem or unintended behavior label Apr 24, 2015
@JeffBezanson JeffBezanson self-assigned this Apr 24, 2015
@mauro3
Copy link
Contributor

mauro3 commented May 19, 2015

I also stumbled across this. Here's another test-cases in case that helps:

find_tvar{T<:Tuple}(sig::Type{T}) = 1
function find_tvar(arg)
    if arg<:Tuple
        find_tvar(arg[random_var_name])
    end
    return 1
end
find_tvar(Vararg{Int}) # errors with above error

Note that this does not errror:

#find_tvar{T<:Tuple}(sig::Type{T}) = 1
function find_tvar(arg)
    if arg<:Tuple
        find_tvar(arg[random_var_name])
    end
    return 1
end
find_tvar(Vararg{Int})

and this neither

find_tvar{T<:Tuple}(sig::Type{T}) = 1
function find_tvar(arg)
    if arg<:Tuple
        find_tvar(arg[1])
    end
    return 1
end
find_tvar(Vararg{Int})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants