Julia: Another illegal instruction

Created on 17 Apr 2017  ·  3Comments  ·  Source: JuliaLang/julia

Very similar to https://github.com/JuliaLang/julia/issues/21243. Distilled from RigidBodyDynamics.jl:

type SpanningTree{V, E}
end

immutable TreePath{V, E}
    source::V
    source_to_lca::Vector{E}
end

function path{V, E}(src::V, target::V, tree::SpanningTree{V, E})
    TreePath(src, E[])
end

type RigidBody{T<:Number}
end

type Joint{T<:Number}
end

num_velocities(itr) = error("bad")
num_velocities{T}(p::TreePath{RigidBody{T}, Joint{T}}) = 0

type Mechanism{T<:Number}
    bodies::Vector{RigidBody{T}}
    tree::SpanningTree{RigidBody{T}, Joint{T}}

    function (::Type{Mechanism{T}}){T<:Number}(rootBody::RigidBody{T}; bla = 0)
        tree = SpanningTree{RigidBody{T}, Joint{T}}()
        new{T}([rootBody], tree)
    end
end

Mechanism{T}(rootBody::RigidBody{T}; kwargs...) = Mechanism{T}(rootBody; kwargs...)
bodies(mechanism::Mechanism) = mechanism.bodies
path(mechanism::Mechanism, from::RigidBody, to::RigidBody) = path(from, to, mechanism.tree)

function foo()
    mechanism = Mechanism(RigidBody{Float64}())
    b = first(bodies(mechanism))
    p = path(mechanism, b, b)
    nvpath = num_velocities(p)
end

foo()

With --inline=no, this results in

signal (4): Illegal instruction: 4
while loading /Users/twan/code/julia/RigidBodyDynamics/v0.6/RigidBodyDynamics/perf/runbenchmarks.jl, in expression starting on line 43
foo at /Users/twan/code/julia/RigidBodyDynamics/v0.6/RigidBodyDynamics/perf/runbenchmarks.jl:40
unknown function (ip: 0x3151a23ff)
do_call at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/interpreter.c:75
eval at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/interpreter.c:242
jl_interpret_toplevel_expr at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/interpreter.c:34
jl_toplevel_eval_flex at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/toplevel.c:577
jl_parse_eval_all at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/ast.c:873
jl_load at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/toplevel.c:616 [inlined]
jl_load_ at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/toplevel.c:623
include_from_node1 at ./loading.jl:539
jlcall_include_from_node1_18834 at /Applications/Julia-0.6.app/Contents/Resources/julia/lib/julia/sys.dylib (unknown line)
include at ./sysimg.jl:14
jlcall_include_1043 at /Applications/Julia-0.6.app/Contents/Resources/julia/lib/julia/sys.dylib (unknown line)
process_options at ./client.jl:305
_start at ./client.jl:371
jlcall__start_19032 at /Applications/Julia-0.6.app/Contents/Resources/julia/lib/julia/sys.dylib (unknown line)
true_main at /Applications/Julia-0.6.app/Contents/Resources/julia/bin/julia (unknown line)
main at /Applications/Julia-0.6.app/Contents/Resources/julia/bin/julia (unknown line)
Allocations: 848930 (Pool: 847706; Big: 1224); GC: 0
Illegal instruction: 4

Perhaps more worrying, without --inline=no this results in

ERROR: LoadError: bad
Stacktrace:
 [1] foo() at /Users/twan/code/julia/RigidBodyDynamics/v0.6/RigidBodyDynamics/perf/runbenchmarks.jl:40
 [2] include_from_node1(::String) at ./loading.jl:539
 [3] include(::String) at ./sysimg.jl:14
 [4] process_options(::Base.JLOptions) at ./client.jl:305
 [5] _start() at ./client.jl:371
while loading /Users/twan/code/julia/RigidBodyDynamics/v0.6/RigidBodyDynamics/perf/runbenchmarks.jl, in expression starting on line 43

versioninfo():

Julia Version 0.6.0-pre.beta.132
Commit 52607b07f6 (2017-04-14 14:39 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin13.4.0)
  CPU: Intel(R) Core(TM) i7-3820QM CPU @ 2.70GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, ivybridge)
bug inference

Most helpful comment

julia> a=Core.Inference.return_type(path, Tuple{Any, RigidBody{T} where T<:Number, RigidBody{T} where T<:Number})
TreePath{_,Joint{T<:Number}} where _

julia> Core.Inference.has_free_typevars(a)
true

julia> typeintersect(a, TreePath{RigidBody{T},Joint{T}} where T)
Union{}

The inferred return type of path should probably not have an unbound typevar, i.e. it's missing a where T, right?

All 3 comments

julia> a=Core.Inference.return_type(path, Tuple{Any, RigidBody{T} where T<:Number, RigidBody{T} where T<:Number})
TreePath{_,Joint{T<:Number}} where _

julia> Core.Inference.has_free_typevars(a)
true

julia> typeintersect(a, TreePath{RigidBody{T},Joint{T}} where T)
Union{}

The inferred return type of path should probably not have an unbound typevar, i.e. it's missing a where T, right?

Reduced repro:

julia> function foo{V, E}(::V, ::Pair{V, E})
           E
       end
foo (generic function with 1 method)

julia> code_warntype(foo, Tuple{Ref, Pair{Ref{T},Ref{T}} where T<:Number})
Variables:
  #self#::#foo
  #unused#@_2::Any
  #unused#@_3::Any

Body:
  begin 
      return $(Expr(:static_parameter, 2))
  end::Type{Ref{T<:Number}}

IIUC, this should be Type{Ref{T}} where T <: Number.

Thank you both for your quick response!

Was this page helpful?
0 / 5 - 0 ratings