Julia: Inference crash in handling of `Core._apply_iterate`

Created on 5 Nov 2019  路  4Comments  路  Source: JuliaLang/julia

When trying to fix JuliaInterpreter.jl on Julia master I ran into the following:

Using the load_bounds_error branch where the only real change is https://github.com/JuliaDebug/JuliaInterpreter.jl/commit/1c9b0dc808a92a90cb46b5e756a44bb0b110364e#diff-5a8415c3db7ae789ed68bb4ef565118cR78-R79
Julia crashes on trying to load JuliaInterpreter with:

julia> using JuliaInterpreter, Test
[ Info: Precompiling JuliaInterpreter [aa1ae85d-cabe-5617-a682-6adf51b2e16a]
Internal error: encountered unexpected error in runtime:
BoundsError(a=Array{Any, (2,)}[
  Core.Compiler.Const(val=typeof(Core._apply_iterate)(), actual=false),
  Core.Compiler.Const(val="foo", actual=false)], i=(3,))
jl_bounds_error_ints at /home/kc/julia/src/rtutils.c:183
getindex at ./array.jl:758 [inlined]
abstract_call at ./compiler/abstractinterpretation.jl:646
abstract_call at ./compiler/abstractinterpretation.jl:643
abstract_eval_call at ./compiler/abstractinterpretation.jl:884
abstract_eval at ./compiler/abstractinterpretation.jl:954

Clearly the "foo" argument in the branch is bogus (I splatted something there before so the bounds error had a Vararg for the second argument but tried to minimize the diff).

The error is thrown from

https://github.com/JuliaLang/julia/blob/2c187bddb8c67a6565109a3249348fa0058e7f27/base/compiler/abstractinterpretation.jl#L646

which was quite recently added (https://github.com/JuliaLang/julia/pull/33356).

bug inference

All 4 comments

Looks like we need some argument count checks there.

Also:

julia> f() = Core._apply()
f (generic function with 1 method)

julia> f()
Internal error: encountered unexpected error in runtime:
BoundsError(a=Array{Any, (1,)}[Core.Compiler.Const(val=typeof(Core._apply)(), actual=false)], i=(2,))

More realistic example: https://github.com/JuliaDebug/JuliaInterpreter.jl/commit/cb6ab09621dde8e8eddb5165cf33571a2644a3c7#diff-5a8415c3db7ae789ed68bb4ef565118cR81

Error is:

julia> using JuliaInterpreter
[ Info: Precompiling JuliaInterpreter [aa1ae85d-cabe-5617-a682-6adf51b2e16a]
Internal error: encountered unexpected error in runtime:
BoundsError(a=Array{Any, (2,)}[
  Core.Compiler.Const(val=typeof(Core._apply_iterate)(), actual=false),
  Vararg{Any, N} where N], i=(3,))
jl_bounds_error_ints at /home/kc/julia/src/rtutils.c:183
getindex at ./array.jl:758 [inlined]
abstract_call at ./compiler/abstractinterpretation.jl:646

I don't understand why https://github.com/JuliaDebug/JuliaInterpreter.jl/commit/cb6ab09621dde8e8eddb5165cf33571a2644a3c7#diff-5a8415c3db7ae789ed68bb4ef565118cR68-R70 doesn't trigger the same problem though.

Ah, I get it now.

Was this page helpful?
0 / 5 - 0 ratings