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

Illegal instruction when calling DataFrames function #29430

Closed
nalimilan opened this issue Sep 29, 2018 · 9 comments · Fixed by #29406
Closed

Illegal instruction when calling DataFrames function #29430

nalimilan opened this issue Sep 29, 2018 · 9 comments · Fixed by #29406
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior types and dispatch Types, subtyping and method dispatch

Comments

@nalimilan
Copy link
Member

nalimilan commented Sep 29, 2018

When running the following code using the nl/grouping2 branch of DataFrames (commit 256bd1d), Julia 0.7, 1.0 and master crashes with "Illegal instruction".

using Pkg
Pkg.add("DataFrames#nl/grouping2")
using DataFrames
df = DataFrame(Key1 = CategoricalArray(["A", "A", "B", "B"]),
               Key2 = CategoricalArray(["A", "B", "A", "B"]),
               Value = 1:4)
combine(d -> DataFrame(x=d[1, :Key2]), groupby(df, :Key1))

Unreachable reached at 0x7f4bc01192fd

signal (4): Illegal instruction
in expression starting at no file:0
append_rows! at /home/milan/.julia/dev/DataFrames/src/groupeddataframe/grouping.jl:357
_combine! at /home/milan/.julia/dev/DataFrames/src/groupeddataframe/grouping.jl:373
unknown function (ip: 0x7f4bc0118c75)
jl_fptr_trampoline at /home/milan/Dev/julia/src/gf.c:1843
jl_apply_generic at /home/milan/Dev/julia/src/gf.c:2198
_combine at /home/milan/.julia/dev/DataFrames/src/groupeddataframe/grouping.jl:261
jl_fptr_trampoline at /home/milan/Dev/julia/src/gf.c:1843
jl_apply_generic at /home/milan/Dev/julia/src/gf.c:2198
combine at /home/milan/.julia/dev/DataFrames/src/groupeddataframe/grouping.jl:238
jl_fptr_trampoline at /home/milan/Dev/julia/src/gf.c:1843
jl_apply_generic at /home/milan/Dev/julia/src/gf.c:2198
do_call at /home/milan/Dev/julia/src/interpreter.c:324
eval_value at /home/milan/Dev/julia/src/interpreter.c:430
eval_stmt_value at /home/milan/Dev/julia/src/interpreter.c:363 [inlined]
eval_body at /home/milan/Dev/julia/src/interpreter.c:678
jl_interpret_toplevel_thunk_callback at /home/milan/Dev/julia/src/interpreter.c:808
unknown function (ip: 0xfffffffffffffffe)
unknown function (ip: 0x7f4ba66bce1f)
unknown function (ip: 0x7)
jl_interpret_toplevel_thunk at /home/milan/Dev/julia/src/interpreter.c:817
jl_toplevel_eval_flex at /home/milan/Dev/julia/src/toplevel.c:818
jl_toplevel_eval_in at /home/milan/Dev/julia/src/builtins.c:622
eval at ./boot.jl:319
jl_apply_generic at /home/milan/Dev/julia/src/gf.c:2198
eval_user_input at /home/milan/Dev/julia/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:85
macro expansion at /home/milan/Dev/julia/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:117 [inlined]
#28 at ./task.jl:259
jl_apply_generic at /home/milan/Dev/julia/src/gf.c:2198
jl_apply at /home/milan/Dev/julia/src/julia.h:1559 [inlined]
start_task at /home/milan/Dev/julia/src/task.c:271
unknown function (ip: 0xffffffffffffffff)
Allocations: 39452559 (Pool: 39445133; Big: 7426); GC: 85
Illegal instruction (core dumped)

EDIT: looking at the assembly in gdb, the problematic instruction is ud2:

   │0x7fffd4163f03 <julia_append_rows!_-548180969+1251>     mov    %r15,0x48(%rbx)                                                             │
   │0x7fffd4163f07 <julia_append_rows!_-548180969+1255>     movabs $0x7ffff74da9ed,%rax                                                        │
   │0x7fffd4163f11 <julia_append_rows!_-548180969+1265>     lea    0x38(%rbx),%rdi                                                             │
   │0x7fffd4163f15 <julia_append_rows!_-548180969+1269>     mov    $0x3,%esi                                                                   │
   │0x7fffd4163f1a <julia_append_rows!_-548180969+1274>     callq  *%rax                                                                       │
  >│0x7fffd4163f1c <julia_append_rows!_-548180969+1276>     ud2                                                                                │
   │0x7fffd4163f1e <julia_append_rows!_-548180969+1278>     mov    %rsp,%rax                                                                   │
   │0x7fffd4163f21 <julia_append_rows!_-548180969+1281>     lea    -0x10(%rax),%rsi                                                            
@JeffBezanson
Copy link
Member

Should check whether #29406 or #29380 fixes this.

@galenlynch
Copy link
Contributor

I'm running into the same problem, and same illegal instruction, with some code that I wrote on Julia 1.0 (official binaries). It might be difficult to distil it into a reproducible example, but FWIW I can run each line of the function in the REPL without a problem, however calling the function causes julia to be terminated by SIGILL.

@galenlynch
Copy link
Contributor

@code_warntype showed that I had a fair amount of type instability in the function that would reliably crash. Fixing the type stability fixed the SIGILL crashes.

@JeffBezanson
Copy link
Member

#29406 seems to fix this for me.

@JeffBezanson JeffBezanson self-assigned this Oct 1, 2018
@JeffBezanson JeffBezanson added bug Indicates an unexpected problem or unintended behavior types and dispatch Types, subtyping and method dispatch labels Oct 1, 2018
@nalimilan
Copy link
Member Author

#29406 fixes it! But as you note it also introduces new ambiguities. I'd rather fix these than keep the bug, but maybe not all package authors agree...

@nalimilan
Copy link
Member Author

BTW, do you think we could work around it?

@JeffBezanson
Copy link
Member

JeffBezanson commented Oct 1, 2018

To attempt that, I'd look at code_typed for append_rows! where the crash is. The crash is probably at the first point with a wrong ::Union{} type annotation. If we didn't infer exact argument types there, adding type annotations might help. If that's not the problem, it may be necessary to weaken type information with e.g. Ref{Any}(x)[]. If performance is important here that will be a problem though.

@nalimilan
Copy link
Member Author

Thanks. There's indeed a isa(x, Type{Union{}}} check, but also lots of weird DataFrames.eltype and DataFrames.promote_type, as if the method didn't come from Base. Unfortunately I don't know the type (that's the point of using promotion), so I cannot really add better annotations. In case you want to have a look: https://gist.github.com/nalimilan/0021fb27e64f1d682206610824f7f0bf

@nalimilan
Copy link
Member Author

FWIW I've eventually found out that moving the append! call to a separate function which also takes a Boolean indicating whether it should actually call it or not works around the bug (JuliaData/DataFrames.jl@4e7f044).

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 types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants