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

StackOverflow for typinf with long tuple #38364

Closed
fonsp opened this issue Nov 9, 2020 · 4 comments
Closed

StackOverflow for typinf with long tuple #38364

fonsp opened this issue Nov 9, 2020 · 4 comments
Labels
bug Indicates an unexpected problem or unintended behavior compiler:inference Type inference

Comments

@fonsp
Copy link
Member

fonsp commented Nov 9, 2020

(Feel free to change the title - I don't know what's going on 🙃)

MWE:

function maptruncated(xs)
    [
        Symbol() for x in xs[1:20]
    ]
end

xs = tuple(("💕" for _ in 1:2000)...)

maptruncated(xs)

output, full version here:

fons@woof:~/disorganised-mess$ julia bugthing.jl
Internal error: encountered unexpected error in runtime:
StackOverflowError()
jl_compute_field_offsets at /buildworker/worker/package_linux64/build/src/datatype.c:491
inst_datatype_inner at /buildworker/worker/package_linux64/build/src/jltypes.c:1367
jl_apply_tuple_type_v_ at /buildworker/worker/package_linux64/build/src/jltypes.c:1385 [inlined]
jl_apply_tuple_type_v at /buildworker/worker/package_linux64/build/src/jltypes.c:1395
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2214 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2398
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1690 [inlined]
do_apply at /buildworker/worker/package_linux64/build/src/builtins.c:655
argtypes_to_type at ./compiler/typeutils.jl:46 [inlined]
abstract_call_known at ./compiler/abstractinterpretation.jl:887
abstract_call at ./compiler/abstractinterpretation.jl:910
abstract_apply at ./compiler/abstractinterpretation.jl:619
abstract_call_known at ./compiler/abstractinterpretation.jl:688
abstract_call at ./compiler/abstractinterpretation.jl:910
abstract_call at ./compiler/abstractinterpretation.jl:895
abstract_eval at ./compiler/abstractinterpretation.jl:989
typeinf_local at ./compiler/abstractinterpretation.jl:1254
typeinf_nocycle at ./compiler/abstractinterpretation.jl:1310
typeinf at ./compiler/typeinfer.jl:12
typeinf_edge at ./compiler/typeinfer.jl:484
abstract_call_method at ./compiler/abstractinterpretation.jl:419
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:111
abstract_call_known at ./compiler/abstractinterpretation.jl:888
abstract_call at ./compiler/abstractinterpretation.jl:910
abstract_apply at ./compiler/abstractinterpretation.jl:619
abstract_call_known at ./compiler/abstractinterpretation.jl:688
abstract_call at ./compiler/abstractinterpretation.jl:910
abstract_call at ./compiler/abstractinterpretation.jl:895
abstract_eval at ./compiler/abstractinterpretation.jl:989
typeinf_local at ./compiler/abstractinterpretation.jl:1254
typeinf_nocycle at ./compiler/abstractinterpretation.jl:1310
typeinf at ./compiler/typeinfer.jl:12
typeinf_edge at ./compiler/typeinfer.jl:484



(this pattern repeats, let's skip to the end:)



abstract_call at ./compiler/abstractinterpretation.jl:910
abstract_call at ./compiler/abstractinterpretation.jl:895
abstract_eval at ./compiler/abstractinterpretation.jl:989
typeinf_local at ./compiler/abstractinterpretation.jl:1254
typeinf_nocycle at ./compiler/abstractinterpretation.jl:1310
typeinf at ./compiler/typeinfer.jl:12
typeinf_ext at ./compiler/typeinfer.jl:570
typeinf_ext at ./compiler/typeinfer.jl:601
jfptr_typeinf_ext_22701.clone_1 at /home/fons/julia-1.5.0-rc1/lib/julia/sys.so (unknown line)
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2214 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2398
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1690 [inlined]
jl_type_infer at /buildworker/worker/package_linux64/build/src/gf.c:296
jl_generate_fptr at /buildworker/worker/package_linux64/build/src/jitlayers.cpp:290
jl_compile_method_internal at /buildworker/worker/package_linux64/build/src/gf.c:1964
jl_compile_method_internal at /buildworker/worker/package_linux64/build/src/gf.c:1919 [inlined]
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2224 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2398
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1690 [inlined]
do_call at /buildworker/worker/package_linux64/build/src/interpreter.c:117
eval_value at /buildworker/worker/package_linux64/build/src/interpreter.c:206
eval_stmt_value at /buildworker/worker/package_linux64/build/src/interpreter.c:157 [inlined]
eval_body at /buildworker/worker/package_linux64/build/src/interpreter.c:566
jl_interpret_toplevel_thunk at /buildworker/worker/package_linux64/build/src/interpreter.c:660
top-level scope at /home/fons/disorganised-mess/bugthing.jl:10
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:840
jl_parse_eval_all at /buildworker/worker/package_linux64/build/src/ast.c:913
jl_load_rewrite at /buildworker/worker/package_linux64/build/src/toplevel.c:914
include at ./Base.jl:380
include at ./Base.jl:368
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2214 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2398
exec_options at ./client.jl:296
_start at ./client.jl:506
jfptr__start_34305.clone_1 at /home/fons/julia-1.5.0-rc1/lib/julia/sys.so (unknown line)
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2214 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2398
unknown function (ip: 0x401931)
unknown function (ip: 0x401533)
__libc_start_main at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x4015d4)
fons@woof:~/disorganised-mess$

I noticed that the list comprehension needs to be contained inside a function for the error to occur.

Tested in Julia master (at time of writing) and 1.5.2, on Ubuntu Linux (intel xeon) and Windows (intel i5).

@martinholters
Copy link
Member

Reduced:

xs = tuple(("a" for _ in 1:2000)...);
foo(xs) = xs[1:20]
@code_typed foo(xs)

I believe the calls to front in getindex are the problem:

julia/base/range.jl

Lines 300 to 304 in 53a781d

if r.start == 1
r.stop == length(t) && return t
r.stop == length(t)-1 && return front(t)
r.stop == length(t)-2 && return front(front(t))
elseif r.stop == length(t)

Even if they are not hit at run-time, they still need to be inferred, and @code_typed Base.front(xs) also stack overflows.

@JeffBezanson
Copy link
Member

There are various issues in the system when dealing with large tuples: if type inference doesn't get you, then subtyping or codegen probably will. Of course we want to fix all of this eventually, but for now you really just have to avoid big tuples.

@JeffBezanson JeffBezanson changed the title StackOverflow for typinf StackOverflow for typinf with long tuple Nov 11, 2020
@fonsp
Copy link
Member Author

fonsp commented Nov 11, 2020

Thanks! (In my case they came up when calling Tables.schema on a DataFrame with many columns.)

@nsajko
Copy link
Contributor

nsajko commented Oct 1, 2024

Fixed by #55575.

@nsajko nsajko closed this as completed Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior compiler:inference Type inference
Projects
None yet
Development

No branches or pull requests

5 participants