Strange behavior when using StaticArrays.jl and Parameters.jl that is crashing Julia

Hi guys!

I am seeing a strange behavior when using concurrently StaticArrays.jl and Parameters.jl that is leading to crash. I need help because I am not sure where I should open the issue.

Look at this code:

using Parameters
using StaticArrays

@with_kw mutable struct Test{T}
    a::T = T(0)
    b::T = T(0)

    m::MVector{5,T} = zeros(MVector{5,T})
end

function conf_test(a::Number, b::Number)
    Test{Float64}(a = a,
                  b = b)
end

function gts7(testd::Test{T}) where T<:Number
    @unpack_Test testd

    m[1] = 2.0

    @pack testd = m
end

function perform_test(a::Number, b::Number)
    testd = conf_test(a,b)
    gts7(testd)
end

If I execute the following:

julia> include("teste.jl" )
perform_test (generic function with 1 method)

julia> perform_test(1,2)

Julia crashes with the following log:

signal (4): Instrução ilegal
while loading no file, in expression starting on line 0
perform_test at /home/ronan.arraes/tmp/teste.jl:26
unknown function (ip: 0x7fbf53a6d88c)
jl_call_fptr_internal at /home/abuild/rpmbuild/BUILD/julia/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/abuild/rpmbuild/BUILD/julia/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/abuild/rpmbuild/BUILD/julia/src/gf.c:1926
do_call at /home/abuild/rpmbuild/BUILD/julia/src/interpreter.c:75
eval at /home/abuild/rpmbuild/BUILD/julia/src/interpreter.c:242
jl_interpret_toplevel_expr at /home/abuild/rpmbuild/BUILD/julia/src/interpreter.c:34
jl_toplevel_eval_flex at /home/abuild/rpmbuild/BUILD/julia/src/toplevel.c:577
jl_toplevel_eval_in at /home/abuild/rpmbuild/BUILD/julia/src/builtins.c:496
eval at ./boot.jl:235
unknown function (ip: 0x7fbfe59849ef)
jl_call_fptr_internal at /home/abuild/rpmbuild/BUILD/julia/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/abuild/rpmbuild/BUILD/julia/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/abuild/rpmbuild/BUILD/julia/src/gf.c:1926
eval_user_input at ./REPL.jl:66
unknown function (ip: 0x7fbfe5a0af6f)
jl_call_fptr_internal at /home/abuild/rpmbuild/BUILD/julia/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/abuild/rpmbuild/BUILD/julia/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/abuild/rpmbuild/BUILD/julia/src/gf.c:1926
macro expansion at ./REPL.jl:97 [inlined]
#1 at ./event.jl:73
unknown function (ip: 0x7fbf53a4a56f)
jl_call_fptr_internal at /home/abuild/rpmbuild/BUILD/julia/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/abuild/rpmbuild/BUILD/julia/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/abuild/rpmbuild/BUILD/julia/src/gf.c:1926
jl_apply at /home/abuild/rpmbuild/BUILD/julia/src/julia.h:1424 [inlined]
start_task at /home/abuild/rpmbuild/BUILD/julia/src/task.c:267
unknown function (ip: 0xffffffffffffffff)
Allocations: 3905426 (Pool: 3904067; Big: 1359); GC: 6
[1]    14121 illegal hardware instruction (core dumped)  julia

On the other hand, I can do the same thing inside the perform_test function directly on REPL without problems:

julia> include("teste.jl" )
perform_test (generic function with 1 method)

julia> testd = conf_test(1,2)
Test{Float64}
  a: Float64 1.0
  b: Float64 2.0
  m: StaticArrays.MArray{Tuple{5},Float64,1,5}


julia> gts7(testd)
([2.0, 0.0, 0.0, 0.0, 0.0],)

Is it already known?

In my real code (NRLMSISE-00 model), I managed to avoid this problem by changing the MVector to a common Vector.

By the way, I am using Julia v0.6.3 and it was reproduced both on a macOS with official package and on openSUSE Linux with a server farm build package.

P.S.: “Instrução ilegal” = Illegal Instruction (or something like that).

1 Like

I can reproduce it. (But it seems to work on julia 0.7) Strange indeed. I’ll look into it but may need a few days.

1 Like

Thanks @mauro3

Please, let me know if you want any help or if you want some action from my side (like test or open an issue somewhere).

@mauro3,

I don’t know if this helps, but if you add the following modification to function gts7, then it starts to work:

function gts7(testd::Test{T}) where T<:Number
    @unpack_Test testd

    m = copy(m)

    m[1] = 2.0

    @pack testd = m
end

I suspect this is a Julia bug as Julia should not crash. To file it, I’d first try to reduce it further which I would do by manually expanding the macros of Parameters. Go for it if you want to give it a shot.

1 Like