JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.86k stars 5.49k forks source link

Julia hangs in ntuple with out of bounds access #35351

Open raminammour opened 4 years ago

raminammour commented 4 years ago

Hello,

I made a typo today that led to the following, it hangs for a long time before it gives an OOB error. It doesn't for smaller values in Val. Here is a MRE, with the output if killed if that is helpful:

julia> function ff()
       nv=[(i,l) for i in 1:2 for l in 0:i]
       nt = ntuple(i->nv[i],Val(3^6))
       end
ff (generic function with 1 method)

julia> ff()
^C^C^C^C^CWARNING: Force throwing a SIGINT
ERROR: ^C^C^C^C^C^CWARNING: Force throwing a SIGINT
^C^C^C^C^C^C^C^CWARNING: Force throwing a SIGINT
^C^C^C^C^C^C^C^C^C^C^C^CWARNING: Force throwing a SIGINT
fatal: error thrown and no exception handler available.
InterruptException()
_ZN4llvm13StringMapImpl9RemoveKeyENS_9StringRefE at /Applications/Julia-1.3.app/Contents/Resources/julia/lib/julia/libLLVM.dylib (unknown line)
_ZN4llvm11Instruction15eraseFromParentEv at /Applications/Julia-1.3.app/Contents/Resources/julia/lib/julia/libLLVM.dylib (unknown line)
_ZN4llvm4SROA22deleteDeadInstructionsERNS_15SmallPtrSetImplIPNS_10AllocaInstEEE at /Applications/Julia-1.3.app/Contents/Resources/julia/lib/julia/libLLVM.dylib (unknown line)
_ZN4llvm4SROA7runImplERNS_8FunctionERNS_13DominatorTreeERNS_15AssumptionCacheE at /Applications/Julia-1.3.app/Contents/Resources/julia/lib/julia/libLLVM.dylib (unknown line)
_ZN4llvm4sroa14SROALegacyPass13runOnFunctionERNS_8FunctionE at /Applications/Julia-1.3.app/Contents/Resources/julia/lib/julia/libLLVM.dylib (unknown line)
_ZN4llvm13FPPassManager13runOnFunctionERNS_8FunctionE at /Applications/Julia-1.3.app/Contents/Resources/julia/lib/julia/libLLVM.dylib (unknown line)
_ZN4llvm13FPPassManager11runOnModuleERNS_6ModuleE at /Applications/Julia-1.3.app/Contents/Resources/julia/lib/julia/libLLVM.dylib (unknown line)
_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE at /Applications/Julia-1.3.app/Contents/Resources/julia/lib/julia/libLLVM.dylib (unknown line)
operator() at /Users/julia/buildbot/worker/package_macos64/build/src/jitlayers.cpp:370
addModule at /Users/julia/buildbot/worker/package_macos64/build/usr/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h:57
addModule at /Users/julia/buildbot/worker/package_macos64/build/src/jitlayers.cpp:508
jl_add_to_ee at /Users/julia/buildbot/worker/package_macos64/build/src/jitlayers.cpp:761 [inlined]
jl_finalize_function at /Users/julia/buildbot/worker/package_macos64/build/src/jitlayers.cpp:769
getAddressForFunction at /Users/julia/buildbot/worker/package_macos64/build/src/codegen.cpp:1351
jl_generate_fptr at /Users/julia/buildbot/worker/package_macos64/build/src/codegen.cpp:1447
jl_compile_method_internal at /Users/julia/buildbot/worker/package_macos64/build/src/gf.c:1904
_jl_invoke at /Users/julia/buildbot/worker/package_macos64/build/src/gf.c:2140 [inlined]
jl_apply_generic at /Users/julia/buildbot/worker/package_macos64/build/src/gf.c:2305
jl_apply at /Users/julia/buildbot/worker/package_macos64/build/src/./julia.h:1631 [inlined]
jl_f__apply at /Users/julia/buildbot/worker/package_macos64/build/src/builtins.c:627
jl_f__apply_latest at /Users/julia/buildbot/worker/package_macos64/build/src/builtins.c:665
#invokelatest#1 at ./essentials.jl:709 [inlined]
invokelatest at ./essentials.jl:708 [inlined]
_start at ./client.jl:462
jfptr__start_2084.clone_1 at /Applications/Julia-1.3.app/Contents/Resources/julia/lib/julia/sys.dylib (unknown line)
true_main at /Applications/Julia-1.3.app/Contents/Resources/julia/bin/julia (unknown line)
main at /Applications/Julia-1.3.app/Contents/Resources/julia/bin/julia (unknown line)

[Process completed]

If you wait and time it from the terminal:

time ./julia er.jl
ERROR: LoadError: BoundsError: attempt to access 5-element Array{Tuple{Int64,Int64},1} at index [6]
Stacktrace:
 [1] getindex at ./array.jl:744 [inlined]
 [2] #5 at /Applications/Julia-1.3.app/Contents/Resources/julia/bin/er.jl:3 [inlined]
 [3] macro expansion at ./ntuple.jl:50 [inlined]
 [4] ntuple(::var"#5#8"{Array{Tuple{Int64,Int64},1}}, ::Val{729}) at ./ntuple.jl:46
 [5] ff() at /Applications/Julia-1.3.app/Contents/Resources/julia/bin/er.jl:3
 [6] top-level scope at /Applications/Julia-1.3.app/Contents/Resources/julia/bin/er.jl:1
 [7] include at ./boot.jl:328 [inlined]
 [8] include_relative(::Module, ::String) at ./loading.jl:1105
 [9] include(::Module, ::String) at ./Base.jl:31
 [10] exec_options(::Base.JLOptions) at ./client.jl:287
 [11] _start() at ./client.jl:460
in expression starting at /Applications/Julia-1.3.app/Contents/Resources/julia/bin/er.jl:1

real    3m21.629s
user    2m53.796s
sys 0m28.505s

Feel free to close if this is not a bug.

Cheers!

KristofferC commented 4 years ago

Could you try with 1.4? It is pretty fast for me there.

Also, is there a reason you are using Val(3^6) instead of just 3^6?

raminammour commented 4 years ago

In the code I was writing Val mattered. Without Val it doesn't hang. In fact my guess is it is in the compilation, since once the error is thrown the compiled function throws fast after. Downloading 1.4 now, as good a time as any, I guess :)

raminammour commented 4 years ago

I confirm, not an issue on 1.4, fails fast...