Why this constructor is extremly slow? Infinity Loop in Varargs function


#1

This constructor receives a wrong type actually but I do not receive any error, it seems that the compiler is in some infinite loop… I cannot figure out why? I guess I made some mistake, cause this happens on both v0.6 and v0.7

My Julia version is

julia> versioninfo()
Julia Version 0.6.0
Commit 9036443 (2017-06-19 13:05 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i5-4200M CPU @ 2.50GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, haswell)
const Ket{N} = NTuple{N, Int}

ket(spins::Int...) = Ket(spins)

struct LHamiltonian{T, N}
    # kets::Vecotr{Ket{N}}
    # vals::Vector{T}
    data::Vector{Tuple{T, Ket{N}}}
end

LHamiltonian(args...) = LHamiltonian([each for each in args])

LH = LHamiltonian(
    [(1, ket(0, 0)), (1, ket(1, 0))],
    [(-1, ket(1, 1))],
    [(1, ket(0, 0)), (-1, ket(0, 1)), (1, ket(1, 0))],
    [(-1, ket(1, 1))]
)

This also happens on this version, I built this from master a few days ago.

julia> versioninfo()
Julia Version 0.7.0-DEV.3967
Commit 755f6a5 (2018-02-14 05:00 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i5-4200M CPU @ 2.50GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, haswell)
Environment:
  JULIA_PKGDIR = /home/roger/julia/pkgs

#2

An MWE is:

julia> foo(args...) = foo([each for each in args])
foo (generic function with 1 method)

julia> foo([1,2])

it will recursively create and collect generators.


#3

I see… Thanks!