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

Crashes on upcoming Julia 1.3 #63

Closed
KristofferC opened this issue Sep 20, 2019 · 5 comments
Closed

Crashes on upcoming Julia 1.3 #63

KristofferC opened this issue Sep 20, 2019 · 5 comments

Comments

@KristofferC
Copy link

KristofferC commented Sep 20, 2019

While testing packages for 1.3 this package was noted to crash with:

Unreachable reached at 0x7fb7560115ff

signal (4): Illegal instruction
in expression starting at /root/.julia/packages/SimJulia/alkAr/test/processes.jl:45
execute at /root/.julia/packages/SimJulia/alkAr/src/processes.jl:32
#3 at /root/.julia/packages/SimJulia/alkAr/src/base.jl:51
_jl_invoke at /workspace/srcdir/julia/src/gf.c:2136 [inlined]
jl_apply_generic at /workspace/srcdir/julia/src/gf.c:2300
step at /root/.julia/packages/SimJulia/alkAr/src/simulations.jl:39
run at /root/.julia/packages/SimJulia/alkAr/src/base.jl:91
run at /root/.julia/packages/SimJulia/alkAr/src/events.jl:29
unknown function (ip: 0x7fb755fbf1c6)
_jl_invoke at /workspace/srcdir/julia/src/gf.c:2130 [inlined]
jl_apply_generic at /workspace/srcdir/julia/src/gf.c:2300
jl_apply at /workspace/srcdir/julia/src/julia.h:1631 [inlined]
do_call at /workspace/srcdir/julia/src/interpreter.c:328
eval_value at /workspace/srcdir/julia/src/interpreter.c:417
eval_stmt_value at /workspace/srcdir/julia/src/interpreter.c:368 [inlined]
eval_body at /workspace/srcdir/julia/src/interpreter.c:760

Since the code where it crashes are using a lot of functionality from ResumableFunctions.jl which touches a lot of the internals of Julia it is hard to know if this is an actual regression in Julia or an assumption about the internals by ResumableFunctions which is now no longer true.

@BenLauwens
Copy link
Collaborator

I analysed the error but it is not ResumableFunctions that causes the problem:

julia> using SimJulia

julia> @resumable function fibonnaci(sim::Simulation)
         a = 0
         b = 1
         while true
           println(a)
           @yield timeout(sim, 1)
           a, b = b, a+b
         end
       end
fibonnaci (generic function with 1 method)

generates following code

mutable struct var"##403" <: ResumableFunctions.FiniteStateMachineIterator{Any}
    _state::UInt8
    sim::Simulation
    a::Int64
    b::Int64
    function var"##403"(sim::Simulation; )::var"##403"
        fsmi = new()
        fsmi._state = 0x00
        fsmi.sim = sim
        fsmi
    end
end
function fibonnaci(sim::Simulation; )::var"##403"
    var"##403"(sim; )
end
function (_fsmi::var"##403")(_arg::Any=nothing; )::Union{Any, Nothing, Bool}
    _fsmi._state == 0x00 && @goto(_STATE_0)
    _fsmi._state == 0x01 && @goto(_STATE_1)
    error("@resumable function has stopped!")
    @label _STATE_0
    _fsmi._state = 0xff
    _arg isa Exception && throw(_arg)
    _fsmi.a = 0
    _fsmi.b = 1
    while true
        println(_fsmi.a)
        _fsmi._state = 0x01
        return timeout(_fsmi.sim, 1)
        @label _STATE_1
        _fsmi._state = 0xff
        _arg isa Exception && throw(_arg)
        (_fsmi.a, _fsmi.b) = (_fsmi.b, _fsmi.a + _fsmi.b)
    end
end

If I replace the variable name var"##403" with MyTest, the simulation runs perfectly

julia> using ResumableFunctions

julia> using SimJulia

julia> mutable struct MyTest <: ResumableFunctions.FiniteStateMachineIterator{Any}
           _state::UInt8
           sim::Simulation
           a::Int64
           b::Int64
           function MyTest(sim::Simulation; )::var"##403"
               fsmi = new()
               fsmi._state = 0x00
               fsmi.sim = sim
               fsmi
           end
       end

julia> function fibonnaci(sim::Simulation; )::MyTest
           MyTest(sim; )
       end
fibonnaci (generic function with 1 method)

julia> function (_fsmi::MyTest)(_arg::Any=nothing; )::Union{Any, Nothing, Bool}
           _fsmi._state == 0x00 && @goto(_STATE_0)
           _fsmi._state == 0x01 && @goto(_STATE_1)
           error("@resumable function has stopped!")
           @label _STATE_0
           _fsmi._state = 0xff
           _arg isa Exception && throw(_arg)
           _fsmi.a = 0
           _fsmi.b = 1
           while true
               println(_fsmi.a)
               _fsmi._state = 0x01
               return timeout(_fsmi.sim, 1)
               @label _STATE_1
               _fsmi._state = 0xff
               _arg isa Exception && throw(_arg)
               (_fsmi.a, _fsmi.b) = (_fsmi.b, _fsmi.a + _fsmi.b)
           end
       end

julia> sim = Simulation()
Simulation time: 0.0 active_process: nothing

julia> @process fibonnaci(sim)
Process 1

julia> run(sim, 10)
0
1
1
2
3
5
8
13
21
34

I use the function gensym to generate a symbol with no naming conflicts. Apparently in Julia v1.2 I get something like ##372 and in Julia v1.3 I obtain something like var"##403". Using this name as a functor referenced in an attribute of a struct causes the crash. So I presume this is a regression...

Kind regards

Ben

@KristofferC
Copy link
Author

Thanks for the analysis. I opened JuliaLang/julia#33370.

@maleadt
Copy link

maleadt commented Sep 24, 2019

Sure, the code and scripts are available at https://github.com/maleadt/creduce_julia but I can do a writeup if you prefer. There is a bug reducing packages though, so in this case I manually inlined SimJulia and ResumableFunctions into the main.jl and let it run for about an hour.

@KristofferC
Copy link
Author

I'm guessing you meant to respond at JuliaLang/julia#33370 (comment).

Anyway, I'll play around with it a bit, thanks for the link.

@maleadt
Copy link

maleadt commented Sep 25, 2019

Oh oops, yeah, had multiple tabs open. Let me know if you run into issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants