Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inference StackOverflow on BenchmarkTools when defining specialized getindex for Tuples and UnitRanges #20923

Closed
pabloferz opened this issue Mar 7, 2017 · 1 comment
Labels
compiler:inference Type inference domain:error handling Handling of exceptions by Julia or the user

Comments

@pabloferz
Copy link
Contributor

I noticed this when working on #20720. If you try to speed-up getindex(::Tuple, ::UnitRange) defining Base.getindex(t::Tuple, r::UnitRange{<:Real}) = ntuple(n -> t[r[n]], length(r)) you get the following when using BenchmarkTools

julia> using BenchmarkTools

julia> t = (1:51...);

julia> @benchmark map(+, $t)
BenchmarkTools.Trial: 
  memory estimate:  992 bytes
  allocs estimate:  2
  --------------
  minimum time:     2.278 μs (0.00% GC)
  median time:      2.278 μs (0.00% GC)
  mean time:        2.278 μs (0.00% GC)
  maximum time:     2.278 μs (0.00% GC)
  --------------
  samples:          10000
  evals/sample:     10
  time tolerance:   5.00%
  memory tolerance: 1.00%

julia> t = (1:52...);

julia> @benchmark map(+, $t)
WARNING: An error occurred during inference. Type inference is now partially disabled.
TypeError(func=:Tuple, context="parameter", expected=Type{T} where T, got=<?#0x7f6777f96650::<circular reference @-1>>)
rec_backtrace at /home/data/Public/GitHub/julia/src/stackwalk.c:84
record_backtrace at /home/data/Public/GitHub/julia/src/task.c:239
jl_throw at /home/data/Public/GitHub/julia/src/task.c:565
jl_type_error_rt at /home/data/Public/GitHub/julia/src/rtutils.c:118
jl_f_apply_type at /home/data/Public/GitHub/julia/src/builtins.c:727
jl_call_method_internal at /home/data/Public/GitHub/julia/src/julia_internal.h:262 [inlined]
jl_apply_generic at /home/data/Public/GitHub/julia/src/gf.c:2221
jl_apply at /home/data/Public/GitHub/julia/src/julia.h:1410 [inlined]
jl_f__apply at /home/data/Public/GitHub/julia/src/builtins.c:426
abstract_call at ./inference.jl:1811
unknown function (ip: 0x7f69763b0c9e)
jl_call_method_internal at /home/data/Public/GitHub/julia/src/julia_internal.h:262 [inlined]
jl_apply_generic at /home/data/Public/GitHub/julia/src/gf.c:2221
abstract_eval_call at ./inference.jl:1872
abstract_eval at ./inference.jl:1895
abstract_interpret at ./inference.jl:2022
unknown function (ip: 0x7f69763ac8c6)
jl_call_method_internal at /home/data/Public/GitHub/julia/src/julia_internal.h:262 [inlined]
jl_apply_generic at /home/data/Public/GitHub/julia/src/gf.c:2221
typeinf_frame at ./inference.jl:2678
typeinf_loop at ./inference.jl:2594
typeinf_frame at ./inference.jl:2447
typeinf_code at ./inference.jl:2517
unknown function (ip: 0x7f69763c6a8d)
jl_call_method_internal at /home/data/Public/GitHub/julia/src/julia_internal.h:262 [inlined]
jl_apply_generic at /home/data/Public/GitHub/julia/src/gf.c:2221
typeinf_ext at ./inference.jl:2556
unknown function (ip: 0x7f69763a7352)
jl_call_method_internal at /home/data/Public/GitHub/julia/src/julia_internal.h:262 [inlined]
jl_apply_generic at /home/data/Public/GitHub/julia/src/gf.c:2221
jl_apply at /home/data/Public/GitHub/julia/src/julia.h:1410 [inlined]
jl_type_infer at /home/data/Public/GitHub/julia/src/gf.c:267
jl_compile_for_dispatch at /home/data/Public/GitHub/julia/src/gf.c:1614
jl_call_method_internal at /home/data/Public/GitHub/julia/src/julia_internal.h:238 [inlined]
jl_apply_generic at /home/data/Public/GitHub/julia/src/gf.c:2221
jl_apply at /home/data/Public/GitHub/julia/src/julia.h:1410 [inlined]
jl_f__apply at /home/data/Public/GitHub/julia/src/builtins.c:426
#_run#4 at /home/pabloferz/.julia/v0.6/BenchmarkTools/src/execution.jl:323
_run at /home/pabloferz/.julia/v0.6/BenchmarkTools/src/execution.jl:311
unknown function (ip: 0x7f6766f9eed6)
jl_call_method_internal at /home/data/Public/GitHub/julia/src/julia_internal.h:262 [inlined]
jl_apply_generic at /home/data/Public/GitHub/julia/src/gf.c:2221
do_call at /home/data/Public/GitHub/julia/src/interpreter.c:75
eval at /home/data/Public/GitHub/julia/src/interpreter.c:230
jl_interpret_toplevel_expr at /home/data/Public/GitHub/julia/src/interpreter.c:34
jl_toplevel_eval_flex at /home/data/Public/GitHub/julia/src/toplevel.c:577
jl_toplevel_eval_in at /home/data/Public/GitHub/julia/src/builtins.c:484
#run_result#16 at /home/pabloferz/.julia/v0.6/BenchmarkTools/src/execution.jl:33
unknown function (ip: 0x7f6766f9a4c2)
jl_call_method_internal at /home/data/Public/GitHub/julia/src/julia_internal.h:262 [inlined]
jl_invoke at /home/data/Public/GitHub/julia/src/gf.c:41
#run#17 at /home/pabloferz/.julia/v0.6/BenchmarkTools/src/execution.jl:36
run at /home/pabloferz/.julia/v0.6/BenchmarkTools/src/execution.jl:36
unknown function (ip: 0x7f6766f9ee02)
jl_call_method_internal at /home/data/Public/GitHub/julia/src/julia_internal.h:262 [inlined]
jl_apply_generic at /home/data/Public/GitHub/julia/src/gf.c:2221
do_call at /home/data/Public/GitHub/julia/src/interpreter.c:75
eval at /home/data/Public/GitHub/julia/src/interpreter.c:230
eval_body at /home/data/Public/GitHub/julia/src/interpreter.c:534
jl_interpret_toplevel_thunk at /home/data/Public/GitHub/julia/src/interpreter.c:679
jl_toplevel_eval_flex at /home/data/Public/GitHub/julia/src/toplevel.c:592
jl_toplevel_eval_in at /home/data/Public/GitHub/julia/src/builtins.c:484
eval at ./boot.jl:235
unknown function (ip: 0x7f69764ea16f)
jl_call_method_internal at /home/data/Public/GitHub/julia/src/julia_internal.h:262 [inlined]
jl_apply_generic at /home/data/Public/GitHub/julia/src/gf.c:2221
eval_user_input at ./REPL.jl:66
unknown function (ip: 0x7f6766f6fa26)
jl_call_method_internal at /home/data/Public/GitHub/julia/src/julia_internal.h:262 [inlined]
jl_apply_generic at /home/data/Public/GitHub/julia/src/gf.c:2221
macro expansion at ./REPL.jl:97 [inlined]
#1 at ./event.jl:73
unknown function (ip: 0x7f6766f67e0f)
jl_call_method_internal at /home/data/Public/GitHub/julia/src/julia_internal.h:262 [inlined]
jl_apply_generic at /home/data/Public/GitHub/julia/src/gf.c:2221
jl_apply at /home/data/Public/GitHub/julia/src/julia.h:1410 [inlined]
start_task at /home/data/Public/GitHub/julia/src/task.c:261
unknown function (ip: 0xffffffffffffffff)
ERROR: TypeError: 
Stacktrace:
 [1] abstract_call(::Any, ::Array{Any,1}, ::Array{Any,1}, ::Array{Any,1}, ::Core.Inference.InferenceState) at ./inference.jl:1811
 [2] abstract_eval_call(::Expr, ::Array{Any,1}, ::Core.Inference.InferenceState) at ./inference.jl:1872
 [3] abstract_eval(::Any, ::Array{Any,1}, ::Core.Inference.InferenceState) at ./inference.jl:1895
 [4] abstract_interpret(::Any, ::Array{Any,1}, ::Core.Inference.InferenceState) at ./inference.jl:2014
 [5] typeinf_frame(::Core.Inference.InferenceState) at ./inference.jl:2678
 [6] typeinf_loop(::Core.Inference.InferenceState) at ./inference.jl:2577
 [7] typeinf_frame(::Core.MethodInstance, ::Void, ::Bool, ::Bool, ::Core.Inference.InferenceParams) at ./inference.jl:2447
 [8] typeinf_code(::Core.MethodInstance, ::Bool, ::Bool, ::Core.Inference.InferenceParams) at ./inference.jl:2517
 [9] typeinf_ext(::Core.MethodInstance, ::UInt64) at ./inference.jl:2556
 [10] push!(::BenchmarkTools.Trial, ::Any, ::Any, ::Any, ::Any) at /home/pabloferz/.julia/v0.6/BenchmarkTools/src/trials.jl:26
 [11] #_run#4(::Bool, ::String, ::Array{Any,1}, ::Function, ::BenchmarkTools.Benchmark{Symbol("##benchmark#690")}, ::BenchmarkTools.Parameters) at /home/pabloferz/.julia/v0.6/BenchmarkTools/src/execution.jl:323
 [12] _run(::BenchmarkTools.Benchmark{Symbol("##benchmark#690")}, ::BenchmarkTools.Parameters) at /home/pabloferz/.julia/v0.6/BenchmarkTools/src/execution.jl:311
 [13] #run_result#16(::Array{Any,1}, ::Function, ::BenchmarkTools.Benchmark{Symbol("##benchmark#690")}, ::BenchmarkTools.Parameters) at /home/pabloferz/.julia/v0.6/BenchmarkTools/src/execution.jl:33
 [14] #run#17(::Array{Any,1}, ::Function, ::BenchmarkTools.Benchmark{Symbol("##benchmark#690")}, ::BenchmarkTools.Parameters) at /home/pabloferz/.julia/v0.6/BenchmarkTools/src/execution.jl:36
 [15] run(::BenchmarkTools.Benchmark{Symbol("##benchmark#690")}) at /home/pabloferz/.julia/v0.6/BenchmarkTools/src/execution.jl:36SYSTEM: show(lasterr) caused an error
StackOverflowError()

Stacktrace:
 [1] abstract_call(::Any, ::Array{Any,1}, ::Array{Any,1}, ::Array{Any,1}, ::Core.Inference.InferenceState) at ./inference.jl:1811
 [2] abstract_eval_call(::Expr, ::Array{Any,1}, ::Core.Inference.InferenceState) at ./inference.jl:1872
 [3] abstract_eval(::Any, ::Array{Any,1}, ::Core.Inference.InferenceState) at ./inference.jl:1895
 [4] abstract_interpret(::Any, ::Array{Any,1}, ::Core.Inference.InferenceState) at ./inference.jl:2014
 [5] typeinf_frame(::Core.Inference.InferenceState) at ./inference.jl:2678
 [6] typeinf_loop(::Core.Inference.InferenceState) at ./inference.jl:2577
 [7] typeinf_frame(::Core.MethodInstance, ::Void, ::Bool, ::Bool, ::Core.Inference.InferenceParams) at ./inference.jl:2447
 [8] typeinf_code(::Core.MethodInstance, ::Bool, ::Bool, ::Core.Inference.InferenceParams) at ./inference.jl:2517
 [9] typeinf_ext(::Core.MethodInstance, ::UInt64) at ./inference.jl:2556
 [10] push!(::BenchmarkTools.Trial, ::Any, ::Any, ::Any, ::Any) at /home/pabloferz/.julia/v0.6/BenchmarkTools/src/trials.jl:26
 [11] #_run#4(::Bool, ::String, ::Array{Any,1}, ::Function, ::BenchmarkTools.Benchmark{Symbol("##benchmark#690")}, ::BenchmarkTools.Parameters) at /home/pabloferz/.julia/v0.6/BenchmarkTools/src/execution.jl:323
 [12] _run(::BenchmarkTools.Benchmark{Symbol("##benchmark#690")}, ::BenchmarkTools.Parameters) at /home/pabloferz/.julia/v0.6/BenchmarkTools/src/execution.jl:311
 [13] #run_result#16(::Array{Any,1}, ::Function, ::BenchmarkTools.Benchmark{Symbol("##benchmark#690")}, ::BenchmarkTools.Parameters) at /home/pabloferz/.julia/v0.6/BenchmarkTools/src/execution.jl:33
 [14] #run#17(::Array{Any,1}, ::Function, ::BenchmarkTools.Benchmark{Symbol("##benchmark#690")}, ::BenchmarkTools.Parameters) at /home/pabloferz/.julia/v0.6/BenchmarkTools/src/execution.jl:36
 [15] run(::BenchmarkTools.Benchmark{Symbol("##benchmark#690")}) at /home/pabloferz/.julia/v0.6/BenchmarkTools/src/execution.jl:36
 [16] eval(::Module, ::Any) at ./boot.jl:235
 [17] eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./REPL.jl:66
 [18] macro expansion at ./REPL.jl:97 [inlined]
 [19] (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:73

P.S.: Sorry for the title, I'll improve it once I have a better diagnose of the underlying issue.

@ararslan ararslan added domain:error handling Handling of exceptions by Julia or the user compiler:inference Type inference labels Mar 7, 2017
@pabloferz
Copy link
Contributor Author

Closing this as this seems to be fixed on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:inference Type inference domain:error handling Handling of exceptions by Julia or the user
Projects
None yet
Development

No branches or pull requests

2 participants