JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.77k stars 5.49k forks source link

Julia crash: Assertion failed: jl_is_method_instance(mi), file /cygdrive/d/buildbot/worker/package_win64/build/src/codegen.cpp, line 2770 #37694

Closed oheil closed 2 years ago

oheil commented 4 years ago

This code produces the crash. I wasn't able to reduce it further. The crash happens at about step 36000:

using GeneralizedGenerated

binary_operators=[
    :(+),
    :(*),
    :(-),
    :(/),
    :(^),
]
unary_operators=[
    :(sin),
    :(cos),
    :(tan),
]

function get_unary_operator()
    return rand(unary_operators)
end
function get_binary_operator()
    return rand(binary_operators)
end

function create_expression( x::Symbol, p::Symbol, depth=0, pcount=1 )
    expr1=x
    if rand(0:depth)>0
        (expr1,pcount)=create_expression( x, p, depth-1, pcount )
    end
    expr2=:( p[$pcount] )
    if rand(0:depth) == 0
        pcount+=1
    else
        (expr2,pcount)=create_expression( x, p, depth-1, pcount )
    end
    expr=expr1
    if rand(1:2)==1
        op=get_unary_operator()
        expr=Expr( :call, op, expr)
    end
    op=get_binary_operator()
    expr=Expr( :call, op, expr, expr2)
    return expr,pcount
end

function crash()
    step=1
    exception_count=0
    nan_count=0
    θ = π/2
    p = [1,2]
    while true
        (e,pcount) = create_expression( :θ, :p, 1)
        f = mk_function( :( (θ,p) -> $e ) )
        try
            new_θ=f(θ,p)
            println(step," ",exception_count," ",nan_count," : ",e," ",p," ",θ,"->",new_θ)
            if isnan(new_θ)
                nan_count+=1
            end
        catch e
            println(step," ",e)
            exception_count+=1
        end
        step+=1
    end
end

crash()

Crashing in Julia 1.4, 1.5 and latest (no other verions tested):

julia> versioninfo()
Julia Version 1.6.0-DEV.1000
Commit c0d06d3219* (2020-09-22 03:25 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, haswell)
Environment:
  JULIA_PKGDIR = c:\Program Files\Julia-0.6.2\packages\
  JULIA_SHELL = C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

Error Dump for Julia Version 1.5.0:

Assertion failed: jl_is_method_instance(mi), file /cygdrive/d/buildbot/worker/package_win64/build/src/codegen.cpp, line 2770

signal (22): SIGABRT
in expression starting at REPL[8]:1
crt_sig_handler at /cygdrive/d/buildbot/worker/package_win64/build/src\signals-win.c:92
raise at C:\WINDOWS\System32\msvcrt.dll (unknown line)
abort at C:\WINDOWS\System32\msvcrt.dll (unknown line)
assert at C:\WINDOWS\System32\msvcrt.dll (unknown line)
emit_invoke at /cygdrive/d/buildbot/worker/package_win64/build/src\codegen.cpp:2770
emit_expr at /cygdrive/d/buildbot/worker/package_win64/build/src\codegen.cpp:3628
emit_ssaval_assign at /cygdrive/d/buildbot/worker/package_win64/build/src\codegen.cpp:3339
emit_stmtpos at /cygdrive/d/buildbot/worker/package_win64/build/src\codegen.cpp:3533 [inlined]
emit_function at /cygdrive/d/buildbot/worker/package_win64/build/src\codegen.cpp:6085
jl_emit_code at /cygdrive/d/buildbot/worker/package_win64/build/src\codegen.cpp:6431
jl_emit_codeinst at /cygdrive/d/buildbot/worker/package_win64/build/src\codegen.cpp:6465
jl_compile_workqueue at /cygdrive/d/buildbot/worker/package_win64/build/src\codegen.cpp:6568
_jl_compile_codeinst at /cygdrive/d/buildbot/worker/package_win64/build/src\jitlayers.cpp:100
jl_generate_fptr at /cygdrive/d/buildbot/worker/package_win64/build/src\jitlayers.cpp:302
jl_compile_method_internal at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:1964
jl_compile_method_internal at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:1931 [inlined]
_jl_invoke at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:2224 [inlined]
jl_apply_generic at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:2398
#s23#24 at C:\Users\oheil\.julia\packages\GeneralizedGenerated\wp5nX\src\ngg\runtime_fns.jl:68 [inlined]
#s23#24 at .\none:0
GeneratedFunctionStub at .\boot.jl:527
jl_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\julia.h:1690 [inlined]
jl_call_staged at /cygdrive/d/buildbot/worker/package_win64/build/src\method.c:376
jl_code_for_staged at /cygdrive/d/buildbot/worker/package_win64/build/src\method.c:423
get_staged at .\compiler\utilities.jl:94
retrieve_code_info at .\compiler\utilities.jl:105 [inlined]
InferenceState at .\compiler\inferencestate.jl:118
typeinf_ext at .\compiler\typeinfer.jl:568
typeinf_ext at .\compiler\typeinfer.jl:601
jfptr_typeinf_ext_20352.clone_1 at C:\Users\oheil\AppData\Local\Programs\Julia 1.5.0\lib\julia\sys.dll (unknown line)
_jl_invoke at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:2214 [inlined]
jl_apply_generic at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:2398 [inlined]
jl_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\julia.h:1690 [inlined]
jl_type_infer at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:296
jl_generate_fptr at /cygdrive/d/buildbot/worker/package_win64/build/src\jitlayers.cpp:290
jl_compile_method_internal at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:1964
jl_compile_method_internal at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:1931 [inlined]
_jl_invoke at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:2224 [inlined]
jl_apply_generic at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:2398
crash at .\REPL[7]:11
unknown function (ip: 000000002D545823)
jl_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\julia.h:1690 [inlined]
do_call at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:117
eval_value at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:206
eval_stmt_value at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:157 [inlined]
eval_body at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:548
jl_interpret_toplevel_thunk at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:660
jl_toplevel_eval_flex at /cygdrive/d/buildbot/worker/package_win64/build/src\toplevel.c:840
jl_toplevel_eval_flex at /cygdrive/d/buildbot/worker/package_win64/build/src\toplevel.c:790
jl_toplevel_eval at /cygdrive/d/buildbot/worker/package_win64/build/src\toplevel.c:849 [inlined]
jl_toplevel_eval_in at /cygdrive/d/buildbot/worker/package_win64/build/src\toplevel.c:883
eval at .\boot.jl:331
eval_user_input at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\REPL\src\REPL.jl:134
repl_backend_loop at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\REPL\src\REPL.jl:195
start_repl_backend at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\REPL\src\REPL.jl:180
#run_repl#37 at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\REPL\src\REPL.jl:292
run_repl at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\REPL\src\REPL.jl:288
#806 at .\client.jl:399
jfptr_YY.806_58616.clone_1 at C:\Users\oheil\AppData\Local\Programs\Julia 1.5.0\lib\julia\sys.dll (unknown line)
jl_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\julia.h:1690 [inlined]
do_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\builtins.c:655
jl_f__apply at /cygdrive/d/buildbot/worker/package_win64/build/src\builtins.c:669 [inlined]
jl_f__apply_latest at /cygdrive/d/buildbot/worker/package_win64/build/src\builtins.c:705
#invokelatest#1 at .\essentials.jl:710 [inlined]
invokelatest at .\essentials.jl:709 [inlined]
run_main_repl at .\client.jl:383
exec_options at .\client.jl:313
_start at .\client.jl:506
jfptr__start_54312.clone_1 at C:\Users\oheil\AppData\Local\Programs\Julia 1.5.0\lib\julia\sys.dll (unknown line)
unknown function (ip: 00000000004017E1)
unknown function (ip: 0000000000401BD6)
unknown function (ip: 00000000004013DE)
unknown function (ip: 000000000040151A)
BaseThreadInitThunk at C:\WINDOWS\System32\KERNEL32.DLL (unknown line)
RtlUserThreadStart at C:\WINDOWS\SYSTEM32\ntdll.dll (unknown line)
Allocations: 270591907 (Pool: 270585039; Big: 6868); GC: 300

[Verarbeitung des Prozesses mit Code 3 beendet]

Error Dump for Julia Version 1.6.0-DEV.1000:

Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x668b1488 -- jl_rettype_inferred at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:339
in expression starting at REPL[8]:1
jl_rettype_inferred at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:339
emit_invoke at /cygdrive/d/buildbot/worker/package_win64/build/src\codegen.cpp:3411
emit_expr at /cygdrive/d/buildbot/worker/package_win64/build/src\codegen.cpp:4328
emit_ssaval_assign at /cygdrive/d/buildbot/worker/package_win64/build/src\codegen.cpp:3988
emit_stmtpos at /cygdrive/d/buildbot/worker/package_win64/build/src\codegen.cpp:4230 [inlined]
emit_function at /cygdrive/d/buildbot/worker/package_win64/build/src\codegen.cpp:6788
jl_emit_code at /cygdrive/d/buildbot/worker/package_win64/build/src\codegen.cpp:7150
jl_emit_codeinst at /cygdrive/d/buildbot/worker/package_win64/build/src\codegen.cpp:7184
jl_compile_workqueue at /cygdrive/d/buildbot/worker/package_win64/build/src\codegen.cpp:7285
_jl_compile_codeinst at /cygdrive/d/buildbot/worker/package_win64/build/src\jitlayers.cpp:105
jl_generate_fptr at /cygdrive/d/buildbot/worker/package_win64/build/src\jitlayers.cpp:313
jl_compile_method_internal at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:1895
jl_compile_method_internal at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:1849 [inlined]
_jl_invoke at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:2155 [inlined]
jl_apply_generic at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:2345
#s9#24 at C:\Users\oheil\.julia\packages\GeneralizedGenerated\wp5nX\src\ngg\runtime_fns.jl:68 [inlined]
#s9#24 at .\none:0
GeneratedFunctionStub at .\boot.jl:571
jl_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\julia.h:1682 [inlined]
jl_call_staged at /cygdrive/d/buildbot/worker/package_win64/build/src\method.c:396
jl_code_for_staged at /cygdrive/d/buildbot/worker/package_win64/build/src\method.c:443
get_staged at .\compiler\utilities.jl:94
retrieve_code_info at .\compiler\utilities.jl:105 [inlined]
InferenceState at .\compiler\inferencestate.jl:129
typeinf_ext at .\compiler\typeinfer.jl:629
typeinf_ext_toplevel at .\compiler\typeinfer.jl:664
typeinf_ext_toplevel at .\compiler\typeinfer.jl:660
jfptr_typeinf_ext_toplevel_14960.clone_1 at C:\Users\oheil\AppData\Local\Programs\Julia-1.6.0-DEV\lib\julia\sys.dll (unknown line)
_jl_invoke at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:2163 [inlined]
jl_apply_generic at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:2345 [inlined]
jl_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\julia.h:1682 [inlined]
jl_type_infer at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:300
jl_generate_fptr at /cygdrive/d/buildbot/worker/package_win64/build/src\jitlayers.cpp:301
jl_compile_method_internal at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:1895
jl_compile_method_internal at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:1849 [inlined]
_jl_invoke at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:2155 [inlined]
jl_apply_generic at /cygdrive/d/buildbot/worker/package_win64/build/src\gf.c:2345
crash at .\REPL[7]:11
unknown function (ip: 000000003A9623F3)
jl_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\julia.h:1682 [inlined]
do_call at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:115
eval_value at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:204
eval_stmt_value at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:155 [inlined]
eval_body at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:575
jl_interpret_toplevel_thunk at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:669
jl_toplevel_eval_flex at /cygdrive/d/buildbot/worker/package_win64/build/src\toplevel.c:837
jl_toplevel_eval_flex at /cygdrive/d/buildbot/worker/package_win64/build/src\toplevel.c:785
jl_toplevel_eval at /cygdrive/d/buildbot/worker/package_win64/build/src\toplevel.c:846 [inlined]
jl_toplevel_eval_in at /cygdrive/d/buildbot/worker/package_win64/build/src\toplevel.c:880
eval at .\boot.jl:360
eval_user_input at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\REPL\src\REPL.jl:139
repl_backend_loop at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\REPL\src\REPL.jl:200
start_repl_backend at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\REPL\src\REPL.jl:185
#run_repl#42 at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\REPL\src\REPL.jl:316
run_repl at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\REPL\src\REPL.jl:304
#849 at .\client.jl:387
jfptr_YY.849_36093.clone_1 at C:\Users\oheil\AppData\Local\Programs\Julia-1.6.0-DEV\lib\julia\sys.dll (unknown line)
jl_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\julia.h:1682 [inlined]
do_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\builtins.c:672
jl_f__apply at /cygdrive/d/buildbot/worker/package_win64/build/src\builtins.c:686 [inlined]
jl_f__apply_latest at /cygdrive/d/buildbot/worker/package_win64/build/src\builtins.c:722
#invokelatest#2 at .\essentials.jl:709 [inlined]
invokelatest at .\essentials.jl:708 [inlined]
run_main_repl at .\client.jl:372
exec_options at .\client.jl:302
_start at .\client.jl:485
jfptr__start_25966.clone_1 at C:\Users\oheil\AppData\Local\Programs\Julia-1.6.0-DEV\lib\julia\sys.dll (unknown line)
jl_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\julia.h:1682 [inlined]
true_main at /cygdrive/d/buildbot/worker/package_win64/build/ui\repl.c:106
wmain at /cygdrive/d/buildbot/worker/package_win64/build/ui\repl.c:227
__tmainCRTStartup at /usr/src/debug/mingw64-x86_64-runtime-7.0.0-1/crt\crtexe.c:334
mainCRTStartup at /usr/src/debug/mingw64-x86_64-runtime-7.0.0-1/crt\crtexe.c:223
BaseThreadInitThunk at C:\WINDOWS\System32\KERNEL32.DLL (unknown line)
RtlUserThreadStart at C:\WINDOWS\SYSTEM32\ntdll.dll (unknown line)
Allocations: 338449709 (Pool: 338441904; Big: 7805); GC: 402

[Verarbeitung des Prozesses mit Code 1 beendet]
NLaws commented 3 years ago

Possibly related to https://github.com/JuliaLang/julia/issues/35580?

We are seeing the same issue but can't make a MWE unfortunately since it is occurring in the REopt Lite API(https://github.com/nrel/reopt_lite_api) (which calls Julia via Python via Celery workers in a Django app)

ViralBShah commented 2 years ago

Please reopen if still crashing.

oheil commented 2 years ago

Not crashing in 1.8.2. Great work!