Unexpected error in runtime

I see this on 1.6.3:

Internal error: encountered unexpected error in runtime:
BoundsError(a=svec(), i=0)
getindex at .\essentials.jl:589 [inlined]
unswitchtupleunion at .\compiler\typeutils.jl:219
getfield_elim_pass! at .\compiler/ssair\passes.jl:624
run_passes at .\compiler/ssair\driver.jl:133
optimize at .\compiler\optimize.jl:272 [inlined]
_typeinf at .\compiler\typeinfer.jl:244
typeinf at .\compiler\typeinfer.jl:209
typeinf_edge at .\compiler\typeinfer.jl:806
abstract_call_method at .\compiler\abstractinterpretation.jl:490
abstract_call_gf_by_type at .\compiler\abstractinterpretation.jl:143
abstract_call_known at .\compiler\abstractinterpretation.jl:1048
abstract_call at .\compiler\abstractinterpretation.jl:1071
abstract_call at .\compiler\abstractinterpretation.jl:1055
abstract_eval_statement at .\compiler\abstractinterpretation.jl:1182
typeinf_local at .\compiler\abstractinterpretation.jl:1470
typeinf_nocycle at .\compiler\abstractinterpretation.jl:1534
_typeinf at .\compiler\typeinfer.jl:214
typeinf at .\compiler\typeinfer.jl:209
typeinf_edge at .\compiler\typeinfer.jl:806
abstract_call_method at .\compiler\abstractinterpretation.jl:490
abstract_call_gf_by_type at .\compiler\abstractinterpretation.jl:143
abstract_call_known at .\compiler\abstractinterpretation.jl:1048
abstract_call at .\compiler\abstractinterpretation.jl:1071
abstract_call at .\compiler\abstractinterpretation.jl:1055
abstract_eval_statement at .\compiler\abstractinterpretation.jl:1182
typeinf_local at .\compiler\abstractinterpretation.jl:1470
typeinf_nocycle at .\compiler\abstractinterpretation.jl:1534
_typeinf at .\compiler\typeinfer.jl:214
typeinf at .\compiler\typeinfer.jl:209
typeinf_edge at .\compiler\typeinfer.jl:806
abstract_call_method at .\compiler\abstractinterpretation.jl:490
abstract_call_gf_by_type at .\compiler\abstractinterpretation.jl:143
abstract_call_known at .\compiler\abstractinterpretation.jl:1048
abstract_call at .\compiler\abstractinterpretation.jl:1071
abstract_call at .\compiler\abstractinterpretation.jl:1055
abstract_eval_statement at .\compiler\abstractinterpretation.jl:1182
typeinf_local at .\compiler\abstractinterpretation.jl:1455
typeinf_nocycle at .\compiler\abstractinterpretation.jl:1534
_typeinf at .\compiler\typeinfer.jl:214
typeinf at .\compiler\typeinfer.jl:209
typeinf_ext at .\compiler\typeinfer.jl:892
typeinf_ext_toplevel at .\compiler\typeinfer.jl:925
typeinf_ext_toplevel at .\compiler\typeinfer.jl:921
jfptr_typeinf_ext_toplevel_14355.clone_1 at C:\Users\Win10\AppData\Local\Programs\Julia-1.6.3\lib\julia\sys.dll (unknown line)
_jl_invoke at /cygdrive/c/buildbot/worker/package_win64/build/src\gf.c:2237 [inlined]
jl_apply_generic at /cygdrive/c/buildbot/worker/package_win64/build/src\gf.c:2419 [inlined]
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1703 [inlined]
jl_type_infer at /cygdrive/c/buildbot/worker/package_win64/build/src\gf.c:298
jl_generate_fptr at /cygdrive/c/buildbot/worker/package_win64/build/src\jitlayers.cpp:340
jl_compile_method_internal at /cygdrive/c/buildbot/worker/package_win64/build/src\gf.c:1970
jl_compile_method_internal at /cygdrive/c/buildbot/worker/package_win64/build/src\gf.c:1924 [inlined]
_jl_invoke at /cygdrive/c/buildbot/worker/package_win64/build/src\gf.c:2229 [inlined]
jl_apply_generic at /cygdrive/c/buildbot/worker/package_win64/build/src\gf.c:2419
#_run#48 at C:\Users\Win10\.julia\packages\BenchmarkTools\uq9zP\src\execution.jl:98
_run##kw at C:\Users\Win10\.julia\packages\BenchmarkTools\uq9zP\src\execution.jl:92
unknown function (ip: 000000005b3efb58)
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1703 [inlined]
jl_f__call_latest at /cygdrive/c/buildbot/worker/package_win64/build/src\builtins.c:714
#invokelatest#2 at .\essentials.jl:710 [inlined]
invokelatest##kw at .\essentials.jl:706 [inlined]
#run_result#45 at C:\Users\Win10\.julia\packages\BenchmarkTools\uq9zP\src\execution.jl:33 [inlined]
run_result##kw at C:\Users\Win10\.julia\packages\BenchmarkTools\uq9zP\src\execution.jl:33 [inlined]
#run#49 at C:\Users\Win10\.julia\packages\BenchmarkTools\uq9zP\src\execution.jl:116
run##kw at C:\Users\Win10\.julia\packages\BenchmarkTools\uq9zP\src\execution.jl:116 [inlined]
run##kw at C:\Users\Win10\.julia\packages\BenchmarkTools\uq9zP\src\execution.jl:116 [inlined]
#warmup#54 at C:\Users\Win10\.julia\packages\BenchmarkTools\uq9zP\src\execution.jl:168 [inlined]
warmup at C:\Users\Win10\.julia\packages\BenchmarkTools\uq9zP\src\execution.jl:168
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1703 [inlined]
do_call at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:115
eval_value at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:204
eval_stmt_value at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:155 [inlined]
eval_body at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:576
jl_interpret_toplevel_thunk at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:670
top-level scope at C:\Users\Win10\.julia\packages\BenchmarkTools\uq9zP\src\execution.jl:565
jl_toplevel_eval_flex at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:877
jl_toplevel_eval_flex at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:825
jl_toplevel_eval at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:886 [inlined]
jl_toplevel_eval_in at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:929
eval at .\boot.jl:360 [inlined]
include_string at .\loading.jl:1116
_include at .\loading.jl:1170
include at .\client.jl:444
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1703 [inlined]
do_call at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:115
eval_value at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:204
eval_stmt_value at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:155 [inlined]
eval_body at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:576
jl_interpret_toplevel_thunk at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:670
top-level scope at none:1
jl_toplevel_eval_flex at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:877
jl_toplevel_eval at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:886 [inlined]
jl_toplevel_eval_in at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:929
eval at .\boot.jl:360 [inlined]
repleval at C:\Users\Win10\.julia\packages\Atom\bfwsW\src\repl.jl:198
#242 at C:\Users\Win10\.julia\packages\Atom\bfwsW\src\repl.jl:228
unknown function (ip: 000000005b3e8dd3)
with_logstate at .\logging.jl:491
with_logger at .\logging.jl:603 [inlined]
evalrepl at C:\Users\Win10\.julia\packages\Atom\bfwsW\src\repl.jl:216
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1703 [inlined]
do_call at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:115
eval_value at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:204
eval_stmt_value at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:155 [inlined]
eval_body at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:576
jl_interpret_toplevel_thunk at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:670
top-level scope at C:\Users\Win10\.julia\packages\Atom\bfwsW\src\repl.jl:264
jl_toplevel_eval_flex at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:877
jl_toplevel_eval at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:886 [inlined]
jl_toplevel_eval_in at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:929
eval at .\boot.jl:360 [inlined]
eval_user_input at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\REPL\src\REPL.jl:139
repl_backend_loop at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\REPL\src\REPL.jl:200
start_repl_backend at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\REPL\src\REPL.jl:185
#run_repl#42 at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\REPL\src\REPL.jl:317
run_repl at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\REPL\src\REPL.jl:305
#874 at .\client.jl:387
jfptr_YY.874_32319.clone_1 at C:\Users\Win10\AppData\Local\Programs\Julia-1.6.3\lib\julia\sys.dll (unknown line)
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1703 [inlined]
jl_f__call_latest at /cygdrive/c/buildbot/worker/package_win64/build/src\builtins.c:714
#invokelatest#2 at .\essentials.jl:708 [inlined]
invokelatest at .\essentials.jl:706 [inlined]
run_main_repl at .\client.jl:372
exec_options at .\client.jl:302
_start at .\client.jl:485
jfptr__start_22917.clone_1 at C:\Users\Win10\AppData\Local\Programs\Julia-1.6.3\lib\julia\sys.dll (unknown line)
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1703 [inlined]
true_main at /cygdrive/c/buildbot/worker/package_win64/build/src\jlapi.c:560
repl_entrypoint at /cygdrive/c/buildbot/worker/package_win64/build/src\jlapi.c:702
mainCRTStartup at /cygdrive/c/buildbot/worker/package_win64/build/cli\loader_exe.c:51
BaseThreadInitThunk at C:\Windows\System32\KERNEL32.DLL (unknown line)
RtlUserThreadStart at C:\Windows\SYSTEM32\ntdll.dll (unknown line)

I know, I should post a MWE;) Are there any techniques to automatically minimize my program?

Also interesting: the program continues to run. Shouldn’t it crash?

Here is the MWE:

function Base.iterate(::Nothing)
end

mutable struct TrieSet{K} <: AbstractSet{AbstractArray{K}}
    dict::Dict{K, TrieSet{K}}
    value::Bool
    function TrieSet{K}() where K
        new(Dict{K, TrieSet{K}}(), false)
    end
end

function walk(trie::TrieSet{K}, f, prefix=Vector{K}()) where K
    if trie.value
        f(prefix)
    end
    for (char, subtrie) in trie.dict
        walk(subtrie, f, vcat(prefix, char))
    end
end

function Base.push!(trie::TrieSet{K}, key) where K
    for char in key
        if trie.dict == nothing
            trie.dict = Dict{K, TrieSet{K}}(char => TrieSet{K}())
        elseif !haskey(trie.dict, char)
            trie.dict[char] = TrieSet{K}()
        end
        trie = trie.dict[char]
    end
    trie.value = true
end

function getsubtrie(trie::TrieSet{K}, key) where K
    prefix = Vector{K}()
    for char in key
        if trie.dict == nothing || !haskey(trie.dict, char)
            return nothing
        end
        push!(prefix, char)
        trie = trie.dict[char]
    end
    return trie, prefix
end

struct PrefixTrieSet{K} <: AbstractSet{AbstractArray{K}}
    subtrie::TrieSet{K}
    prefix::Vector{K}
    function PrefixTrieSet{K}(trie, prefix) where K
        new(getsubtrie(trie, prefix)...)
    end
end

function keys(trie::PrefixTrieSet{K}) where K
    result = Vector{Vector{K}}()
    walk(trie.subtrie, x -> push!(result, x), trie.prefix)
    return result
end

set = TrieSet{Char}()
push!(set, "a")
keys(PrefixTrieSet{Char}(set, "a"))

The error does not occur if function Base.iterate(::Nothing) is removed.

If this is reproducible, I’ll file an issue.

Issue Internal error: encountered unexpected error in runtime · Issue #42579 · JuliaLang/julia · GitHub is confirmed.

fixed in codegen: fix unswitchtupleunion for empty Tuple{} · JuliaLang/julia@1e17975 · GitHub

1 Like