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

julia crashes during method disptch #36869

Closed
OkonSamuel opened this issue Jul 31, 2020 · 3 comments · Fixed by #36996
Closed

julia crashes during method disptch #36869

OkonSamuel opened this issue Jul 31, 2020 · 3 comments · Fixed by #36996
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior types and dispatch Types, subtyping and method dispatch

Comments

@OkonSamuel
Copy link
Contributor

OkonSamuel commented Jul 31, 2020

recently julia dispatch used a less specific method rather than the expected more specific method. While playing around i discovered that following code crashes julia.

julia> using SentinelArrays
b 
julia> b =SentinelArray([1,2,3,4])
4-element SentinelArray{Int64,1,Int64,Missing,Array{Int64,1}}:
 1
 2
 3
 4

julia> f(::Type{T}, y, x::AbstractVector{T}) where T = (T, y)
f (generic function with 1 method)

julia> function g(x, y)
       if x == Int64
        z = true
       else
        z= false
        end
        return f(x, z, y)
        end
g (generic function with 1 method)

julia> f(Union{Missing, Int64}, true, b)
(Union{Missing, Int64}, true)

julia> Union{Missing, Int64} == Int64
false

julia> f(Union{Missing, Int64}, true, b)
(Union{Missing, Int64}, true)

julia> f(Union{Missing, Int64}, false, b)
(Union{Missing, Int64}, false)

julia> g(Union{Missing, Int64}, b)
Unreachable reached at 0x7ff87d4a2085signal (4): Illegal instruction
in expression starting at REPL[9]:1
g at ./REPL[4]:7
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2159 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2323
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1700 [inlined]
do_call at /buildworker/worker/package_linux64/build/src/interpreter.c:369
eval_value at /buildworker/worker/package_linux64/build/src/interpreter.c:458
eval_stmt_value at /buildworker/worker/package_linux64/build/src/interpreter.c:409 [inlined]
eval_body at /buildworker/worker/package_linux64/build/src/interpreter.c:817
jl_interpret_toplevel_thunk at /buildworker/worker/package_linux64/build/src/interpreter.c:911
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:819
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:769
jl_toplevel_eval_in at /buildworker/worker/package_linux64/build/src/toplevel.c:848
eval at ./boot.jl:331
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2145 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2323
eval_user_input at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:86
macro expansion at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:118 [inlined]
#26 at ./task.jl:358
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2145 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2323
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1700 [inlined]
start_task at /buildworker/worker/package_linux64/build/src/task.c:687
unknown function (ip: (nil))
Allocations: 30348217 (Pool: 30340443; Big: 7774); GC: 28
Illegal instruction (core dumped)

is this behavior expected??

julia> versioninfo()
Julia Version 1.4.2
Commit 44fa15b150* (2020-05-23 18:35 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i3-5005U CPU @ 2.00GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, broadwell)
@OkonSamuel OkonSamuel changed the title julia craches during method disptch julia crashes during method disptch Jul 31, 2020
@Keno Keno added the bug Indicates an unexpected problem or unintended behavior label Aug 3, 2020
@Keno Keno self-assigned this Aug 3, 2020
@Keno
Copy link
Member

Keno commented Aug 4, 2020

Inference issue:

julia> code_typed(g, Tuple{Union, typeof(b)})
1-element Vector{Any}:
 CodeInfo(
1 ─ %1 = (x == Main.Int64)::Bool
└──      goto #3 if not %1
2 ─      goto #4
3 ─      nothing::Nothing
4 ┄ %5 = φ (#2 => true, #3 => false)::Bool
│        Main.f(x, %5, y)::Union{}
└──      unreachable
) => Union{}

julia> code_typed(g, Tuple{Type{Union{Missing, Int}}, typeof(b)})
1-element Vector{Any}:
 CodeInfo(
1 ─ %1  = Main.Int64::Core.Const(Int64, false)
│   %2  = $(Expr(:foreigncall, :(:jl_types_equal), Int32, svec(Any, Any), 0, :(:ccall), Core.Argument(2), :(%1)))::Int32
│   %3  = Core.sext_int(Core.Int64, %2)::Int64
│   %4  = (%3 === 0)::Bool
│   %5  = Base.not_int(%4)::Bool
└──       goto #3 if not %5
2 ─       goto #4
3 ─       nothing::Nothing
4 ┄ %9  = φ (#2 => true, #3 => false)::Bool
│   %10 = Core.tuple(Union{Missing, Int64}, %9)::Tuple{Union,Bool}
└──       return %10
) => Tuple{Union,Bool}

julia> Type{Union{Missing, Int}} <: Union
true

@Keno
Copy link
Member

Keno commented Aug 4, 2020

Actually a type intersection issue. Reduced:

julia> struct F{T, V} <: AbstractArray{Union{T, V}, 1}
       end
julia> A = Tuple{Type{T}, AbstractVector{T}} where T
Tuple{Type{T},AbstractVector{T}} where T

julia> B = Tuple{Union, F{Int64, Missing}}
Tuple{Union,F{Int64,Missing}}

julia> typeintersect(A, B) <: A
false

julia> typeintersect(A, B) <: B
false

@Keno Keno added the types and dispatch Types, subtyping and method dispatch label Aug 4, 2020
@Keno Keno assigned JeffBezanson and unassigned Keno Aug 4, 2020
@vtjnash
Copy link
Member

vtjnash commented Aug 4, 2020

Those should be >: (though they still give false). The error being in the first parameter to F, which has managed to become not-equal to the first parameter from B.

julia> typeintersect(A, B)
Tuple{Union, F{Union{Missing, Int64}, Missing}}

KristofferC pushed a commit that referenced this issue Aug 13, 2020
@KristofferC KristofferC mentioned this issue Aug 13, 2020
25 tasks
KristofferC pushed a commit that referenced this issue Aug 18, 2020
KristofferC pushed a commit that referenced this issue Aug 19, 2020
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

Successfully merging a pull request may close this issue.

4 participants