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

subtyping bug for constrained varargs #27632

Closed
vtjnash opened this issue Jun 18, 2018 · 1 comment
Closed

subtyping bug for constrained varargs #27632

vtjnash opened this issue Jun 18, 2018 · 1 comment
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior types and dispatch Types, subtyping and method dispatch

Comments

@vtjnash
Copy link
Member

vtjnash commented Jun 18, 2018

This is bad:

julia> T = SubArray{Int64,0,Array{Int64,3},Tuple{Int64,Int64,Int64},false};
julia> methods(Base._getindex, (IndexCartesian, T, Int, Vararg{Int}), )
# 1 method for generic function "_getindex":
[1] _getindex(::IndexCartesian, A::AbstractArray{T,N}, I::Vararg{Int64,N}) where {T, N} in Base at abstractarray.jl:943

This method can never be selected for this signature, and methods is claiming it will always be selected.

This is correct:

julia> methods(Base._getindex, (IndexCartesian, T, Int,), )
# 1 method for generic function "_getindex":
[1] _getindex(::IndexCartesian, A::AbstractArray, I::Vararg{Int64,M}) where M in Base at abstractarray.jl:937

We expect to need to reduce I at runtime until it matches the length of A dims (0).

This is what happens when get this wrong (reduced from a subarray test optimization):

julia> B = ones(Int64, (1, 1, 1));

julia> A = view(B, 1, 1, 1);

julia> function _test_mixed(A)
                  for J in CartesianIndices(size(A)[2:end])
                  A[1, J]
                  end
                  nothing
              end
_test_mixed (generic function with 1 method)

julia> _test_mixed(A)
Unreachable reached at 0x113b799a3

signal (4): Illegal instruction: 4
in expression starting at no file:0
getindex at ./abstractarray.jl:904 [inlined]
_test_mixed at ./REPL[4]:3
jl_fptr_args at /Users/jameson/julia-master/src/gf.c:1823
jl_fptr_trampoline at /Users/jameson/julia-master/src/gf.c:1813
jl_apply_generic at /Users/jameson/julia-master/src/gf.c:2142
do_call at /Users/jameson/julia-master/src/interpreter.c:324
eval_value at /Users/jameson/julia-master/src/interpreter.c:409
eval_stmt_value at /Users/jameson/julia-master/src/interpreter.c:363
eval_body at /Users/jameson/julia-master/src/interpreter.c:671
jl_interpret_toplevel_thunk_callback at /Users/jameson/julia-master/src/interpreter.c:788
unknown function (ip: 0xfffffffffffffffe)
unknown function (ip: 0x11fe3712f)
unknown function (ip: 0xffffffffffffffff)
jl_interpret_toplevel_thunk at /Users/jameson/julia-master/src/interpreter.c:797
jl_toplevel_eval_flex at /Users/jameson/julia-master/src/toplevel.c:814
jl_toplevel_eval at /Users/jameson/julia-master/src/toplevel.c:823
jl_toplevel_eval_in at /Users/jameson/julia-master/src/builtins.c:631
eval at ./boot.jl:319
jl_fptr_args at /Users/jameson/julia-master/src/gf.c:1823
jl_apply_generic at /Users/jameson/julia-master/src/gf.c:2142
eval_user_input at /Users/jameson/julia-master/usr/share/julia/stdlib/v0.7/REPL/src/REPL.jl:85
macro expansion at /Users/jameson/julia-master/usr/share/julia/stdlib/v0.7/REPL/src/REPL.jl:116 [inlined]
#28 at ./task.jl:257
jl_fptr_args at /Users/jameson/julia-master/src/gf.c:1823
jl_fptr_trampoline at /Users/jameson/julia-master/src/gf.c:1813
jl_apply_generic at /Users/jameson/julia-master/src/gf.c:2142
jl_apply at /Users/jameson/julia-master/src/./julia.h:1537
start_task at /Users/jameson/julia-master/src/task.c:268
Allocations: 9571377 (Pool: 9569985; Big: 1392); GC: 20
Illegal instruction: 4
@vtjnash vtjnash changed the title method lookup method lookup bad for constrained varargs Jun 18, 2018
@vtjnash vtjnash added the bug Indicates an unexpected problem or unintended behavior label Jun 18, 2018
@vtjnash vtjnash changed the title method lookup bad for constrained varargs subtyping bug for constrained varargs Jun 18, 2018
@vtjnash
Copy link
Member Author

vtjnash commented Jun 18, 2018

More precise repro of the subtyping bug that leads to this:

julia> Tuple{Array{Int,0}, Int, Vararg{Int}} <: Tuple{AbstractArray{T,N}, Vararg{Int,N}} where {T, N}
true

However, this must return false, since the LHS is populated but can never be a subtype of the RHS.

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 types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

No branches or pull requests

2 participants