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

SIGSEGV and StackOverflow from dispatching on ::Type{T}, ::Array{Union{T,Missing},N}) #36185

Closed
oxinabox opened this issue Jun 7, 2020 · 7 comments · Fixed by #48029
Closed
Labels
types and dispatch Types, subtyping and method dispatch

Comments

@oxinabox
Copy link
Contributor

oxinabox commented Jun 7, 2020

EDIT: MWE from below

 julia> typeintersect((Tuple{Type{T},Array{Union{T,Missing},N}} where {T,N}),
                     (Tuple{Type{T},Array{Union{T,Nothing},N}} where {T,N}))
ERROR: StackOverflowError

Original text:

If I do

for U in (:(Union{T, Missing}), :(Union{T, Nothing}),)
    @eval function bar(::Type{T}, xs::Array{$U,N}) where {T,N}
        T
    end
end

Then julia SIGSEGV's (Address boundary error)

When I do:

@eval function bazz(::Type{T}, xs::Array{Union{T,Missing},N}) where {T,N}
   T
end

I get a StackOverflowError

When I do:

function bazz(::Type{T}, xs::Array{Union{T,Missing},N}) where {T,N}
   T
end

I am back to crashing out with SIGSEGV's (Address boundary error)

But if i do:

function bazz(::Type{<:T},xs::Array{Union{T,Missing},N}) where {T,N}
   T
end

then it is fine.
But that is a different expression

as is

function bazz(::Type{T},xs::Array{<:Union{T,Missing},N}) where {T,N}
   T
end

This is on Version 1.6.0-DEV.184 (2020-06-06)

@MasonProtter
Copy link
Contributor

On 1.5.0-beta1, I don't get any SIGSEVs, but I do get StackOverflowErrors. The eval appears to be unrelated to the error so far as I can tell. I get the same error with or without eval.

julia> for U in (:(Union{T, Missing}), :(Union{T, Nothing}),)
           @eval function bar(::Type{T}, xs::Array{$U,N}) where {T,N}
               T
           end
       end
ERROR: StackOverflowError:
Stacktrace:
 [1] top-level scope at none:1
 [2] eval(::Module, ::Any) at ./boot.jl:331
 [3] top-level scope at REPL[4]:2

julia> @eval function bazz(::Type{T}, xs::Array{Union{T,Missing},N}) where {T,N}
          T
       end
bazz (generic function with 1 method)

julia> @eval function bar(::Type{T}, xs::Array{Union{T,Nothing},N}) where {T,N}
          T
       end
ERROR: StackOverflowError:
Stacktrace:
 [1] top-level scope at none:1
 [2] eval(::Module, ::Any) at ./boot.jl:331
 [3] top-level scope at REPL[6]:1

julia> function bar(::Type{T}, xs::Array{Union{T,Nothing},N}) where {T,N}
          T
       end
ERROR: StackOverflowError:
Stacktrace:
 [1] top-level scope at REPL[7]:1

julia> versioninfo()
Julia Version 1.5.0-beta1.0
Commit 6443f6c95a* (2020-05-28 17:42 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: AMD Ryzen 5 2600 Six-Core Processor
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, znver1)
Environment:
  JULIA_NUM_THREADS = 6

@JeffBezanson
Copy link
Member

Seems to be a stack overflow in type intersection:

julia> typeintersect((Tuple{Type{T},Array{Union{T,Missing},N}} where {T,N}),
                     (Tuple{Type{T},Array{Union{T,Nothing},N}} where {T,N}))
ERROR: StackOverflowError:

The SEGV is probably just the usual issue with stack overflow (on mac os?).

@oxinabox
Copy link
Contributor Author

oxinabox commented Jun 9, 2020

Correct I am on MacOS

@KlausC
Copy link
Contributor

KlausC commented Jun 9, 2020

Interestingly, the stack overflow (on v1.4.1 on Linux) does not prevent the correct methods to be defined:

julia> for U in (:(Union{T, Missing}), :(Union{T, Nothing}),)
           @eval function bar(::Type{T}, xs::Array{$U,N}) where {T,N}
               T
           end
       end
ERROR: StackOverflowError:
Stacktrace:
 [1] top-level scope at REPL[1]:1
 [2] eval(::Module, ::Any) at ./boot.jl:331
 [3] top-level scope at REPL[1]:2

julia> methods(bar)
# 2 methods for generic function "bar":
[1] bar(::Type{T}, xs::Array{Union{Missing, T},N}) where {T, N} in Main at REPL[1]:3
[2] bar(::Type{T}, xs::Array{Union{Nothing, T},N}) where {T, N} in Main at REPL[1]:3
julia> bar(Float64, [nothing, 1.5])
Float64
julia> typeof([nothing, 1.5])
Array{Union{Nothing, Float64},1}

@OkonSamuel
Copy link
Contributor

OkonSamuel commented Aug 1, 2020

I can also reproduce this issue on my PC. But i just thought i should note that

for U in (:(Union{T, Missing}), :(Union{T, Nothing}),)
           @eval function bar(xs::Array{$U,N}, ::Type{T}) where {T,N}
               T
           end
       end

works.

julia> bar(Union{Int, Missing}[1,2,3], Int)
Int64
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)

@ViralBShah
Copy link
Member

ViralBShah commented Sep 6, 2022

I tried a few of the things that should have segfaulted, but don't seem to. I wonder if the segfaults got fixed in the linked PRs and if this issue can be closed.

@vtjnash
Copy link
Member

vtjnash commented Sep 6, 2022

The MWE still fails in typeintersection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants