Julia: Internal error in optimizer

Created on 6 Apr 2018  Â·  3Comments  Â·  Source: JuliaLang/julia

Here's a stripped down version of some code:

struct Less{O}
    is_less::O
end

struct By{T,O}
    by::T
    is_less::O
end

struct Reverse{O}
    is_less::O
end

function get_order(by = identity, func = isless, rev = false)
    ord = By(by, Less(func))
    rev ? Reverse(ord) : ord
end

get_order_kwargs(; by = identity, func = isless, rev = false) = get_order(by, func, rev)

Running the last function throws:

julia> get_order_kwargs()
Internal error: encountered unexpected error in runtime:
BoundsError(a=Core.Compiler.BitArray{1}(chunks=Array{UInt64, (1,)}[0x0000000000000000], len=1, dims=(139630074742768,)), i=(2,))
rec_backtrace at /buildworker/worker/package_linux64/build/src/stackwalk.c:94
record_backtrace at /buildworker/worker/package_linux64/build/src/task.c:246
jl_throw at /buildworker/worker/package_linux64/build/src/task.c:577
throw_boundserror at ./abstractarray.jl:467
checkbounds at ./abstractarray.jl:432 [inlined]
setindex! at ./bitarray.jl:644 [inlined]
split_struct_alloc! at ./compiler/optimize.jl:3178
optimize_value! at ./compiler/optimize.jl:4085
alloc_elim_pass! at ./compiler/optimize.jl:4109
optimize at ./compiler/optimize.jl:318
typeinf at ./compiler/typeinfer.jl:436
typeinf_edge at ./compiler/typeinfer.jl:137
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2167
abstract_call_method at ./compiler/abstractinterpretation.jl:281
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2167
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:78
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2167
abstract_call at ./compiler/abstractinterpretation.jl:669
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2167
abstract_eval_call at ./compiler/abstractinterpretation.jl:698
abstract_eval at ./compiler/abstractinterpretation.jl:770
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2167
abstract_interpret at ./compiler/abstractinterpretation.jl:887
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2167
typeinf_work at ./compiler/typeinfer.jl:276
typeinf at ./compiler/typeinfer.jl:407
typeinf_frame at ./compiler/typeinfer.jl:96 [inlined]
typeinf_code at ./compiler/typeinfer.jl:190
jfptr_typeinf_code_113.clone_1 at /m/home/home8/83/user/data/Downloads/julia-de26816a74/lib/julia/sys.so (unknown line)
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2167
typeinf_ext at ./compiler/typeinfer.jl:232
jfptr_typeinf_ext_12.clone_1 at /m/home/home8/83/user/data/Downloads/julia-de26816a74/lib/julia/sys.so (unknown line)
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2167
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1527 [inlined]
jl_apply_with_saved_exception_state at /buildworker/worker/package_linux64/build/src/rtutils.c:257
jl_type_infer at /buildworker/worker/package_linux64/build/src/gf.c:274
jl_compile_method_internal at /buildworker/worker/package_linux64/build/src/gf.c:1793 [inlined]
jl_fptr_trampoline at /buildworker/worker/package_linux64/build/src/gf.c:1837
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2167
do_call at /buildworker/worker/package_linux64/build/src/interpreter.c:324
eval_value at /buildworker/worker/package_linux64/build/src/interpreter.c:396
eval_body at /buildworker/worker/package_linux64/build/src/interpreter.c:546
jl_interpret_toplevel_thunk_callback at /buildworker/worker/package_linux64/build/src/interpreter.c:759
unknown function (ip: 0xfffffffffffffffe)
unknown function (ip: 0x7efe292bc54f)
unknown function (ip: 0xffffffffffffffff)
jl_interpret_toplevel_thunk at /buildworker/worker/package_linux64/build/src/interpreter.c:768
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:849
jl_toplevel_eval_in at /buildworker/worker/package_linux64/build/src/builtins.c:624
eval at ./boot.jl:309 [inlined]
eval at /buildworker/worker/package_linux64/build/usr/share/julia/site/v0.7/REPL/src/REPL.jl:5
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2167
eval_user_input at /buildworker/worker/package_linux64/build/usr/share/julia/site/v0.7/REPL/src/REPL.jl:85
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2167
macro expansion at /buildworker/worker/package_linux64/build/usr/share/julia/site/v0.7/REPL/src/REPL.jl:116 [inlined]
#28 at ./event.jl:92
jl_fptr_trampoline at /buildworker/worker/package_linux64/build/src/gf.c:1838
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2167
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1527 [inlined]
start_task at /buildworker/worker/package_linux64/build/src/task.c:268
unknown function (ip: 0xffffffffffffffff)
By{typeof(identity),Less{typeof(isless)}}(identity, Less{typeof(isless)}(isless))

Does not throw when I run get_order(). When I define get_order without the branch things are fine as well:

function get_order(by = identity, func = isless, rev = false)
    ord = By(by, Less(func))
    Reverse(ord)
end

julia> get_order_kwargs()
Reverse{By{typeof(identity),Less{typeof(isless)}}}(By{typeof(identity),Less{typeof(isless)}}(identity, Less{typeof(isless)}(isless)))

Version:

julia> versioninfo()
Julia Version 0.7.0-DEV.4775
Commit de26816a74 (2018-04-06 06:54 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E3-1230 v5 @ 3.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, skylake)
Environment:
needs tests optimizer

Most helpful comment

Works with the new optimizer ;).... I'll show myself out 🚪.

All 3 comments

Works with the new optimizer ;).... I'll show myself out 🚪.

So maybe this can now be closed since we have #27087 :)

Perhaps worth adding the example here as a test?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wilburtownsend picture wilburtownsend  Â·  3Comments

ararslan picture ararslan  Â·  3Comments

StefanKarpinski picture StefanKarpinski  Â·  3Comments

sbromberger picture sbromberger  Â·  3Comments

StefanKarpinski picture StefanKarpinski  Â·  3Comments