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

digamma is type-unstable in Julia master #42

Closed
giordano opened this issue Aug 11, 2017 · 3 comments
Closed

digamma is type-unstable in Julia master #42

giordano opened this issue Aug 11, 2017 · 3 comments

Comments

@giordano
Copy link
Member

In Julia 0.7:

julia> Base.Test.@inferred digamma(3.0)
ERROR: return type Float64 does not match inferred return type Any
Stacktrace:
 [1] error(::String) at ./error.jl:28

julia> Base.Test.@inferred digamma(complex(3.0))
0.9227843350984687 + 0.0im

julia> @code_warntype digamma(3.0)
Variables:
  #self#::SpecialFunctions.#digamma
  z@_2::Float64
  x@_3::Float64
  n::Int64
  t::Float64
  ψ::Any
  x@_7::Any
  y::Any
  r::Any
  s::Any
  a6::Any
  a5::Any
  a4::Any
  a3::Any
  a2::Any
  a1::Any
  a0::Any
  tt::Float64
  #temp#@_19::Int64
  ν::Int64
  z@_21::Float64
  #temp#@_22::Any
  fy@_23::Float64
  #temp#@_24::Float64
  fy@_25::Float64
  #temp#@_26::Bool
  #temp#@_27::Int64
  #temp#@_28::Float64

Body:
  begin
      z@_21::Float64 = z@_2::Float64
      NewvarNode(:(n::Int64))
      NewvarNode(:(t::Float64))
      NewvarNode(:(ψ::Any))
      x@_3::Float64 = z@_21::Float64
      #= line 26 =#
      $(Expr(:inbounds, false))
      # meta: location float.jl <= 497
      fy@_23::Float64 = (Base.sitofp)(Float64, 0)::Float64
      # meta: pop location
      $(Expr(:inbounds, :pop))
      unless (Base.or_int)((Base.lt_float)(x@_3::Float64, fy@_23::Float64)::Bool, (Base.and_int)((Base.and_int)((Base.eq_float)(x@_3::Float64, fy@_23::Float64)::Bool, (Base.lt_float)(fy@_23::Float64, 9.223372036854776e18)::Bool)::Bool, (Base.sle_int)((Base.fptosi)(Int64, fy@_23::Float64)::Int64, 0)::Bool)::Bool)::Bool goto 35
      #= line 27 =#
      $(Expr(:inbounds, false))
      # meta: location special/trig.jl cot 324
      # meta: location math.jl tan 442
      SSAValue(8) = $(Expr(:foreigncall, ("tan", "libopenlibm"), Float64, svec(Float64), :(:ccall), 1, :((Base.mul_float)(3.141592653589793, z@_21)::Float64)))
      # meta: location math.jl nan_dom_err 323
      unless (Base.and_int)((Base.ne_float)(SSAValue(8), SSAValue(8))::Bool, (Base.not_int)((Base.ne_float)((Base.mul_float)(3.141592653589793, z@_21::Float64)::Float64, (Base.mul_float)(3.141592653589793, z@_21::Float64)::Float64)::Bool)::Bool)::Bool goto 22
      #temp#@_24::Float64 = (Base.Math.throw)($(Expr(:invoke, MethodInstance for DomainError(::Any, ::Any), :(Base.Math.DomainError), :((Base.mul_float)(3.141592653589793, z@_21)::Float64), "NaN result for non-NaN input."))::DomainError)::Union{}
      goto 24
      22: 
      #temp#@_24::Float64 = SSAValue(8)
      24: 
      # meta: pop location
      # meta: pop location
      # meta: pop location
      $(Expr(:inbounds, :pop))
      ψ::Any = (Base.mul_float)((Base.neg_float)(3.141592653589793)::Float64, (Base.div_float)((Base.sitofp)(Float64, 1)::Float64, #temp#@_24::Float64)::Float64)::Float64
      #= line 28 =#
      z@_21::Float64 = (Base.sub_float)((Base.sitofp)(Float64, 1)::Float64, z@_21::Float64)::Float64
      #= line 29 =#
      x@_3::Float64 = z@_21::Float64
      goto 38
      35: 
      #= line 31 =#
      ψ::Any = (Base.sitofp)(Float64, 0)::Float64
      38: 
      #= line 33 =#
      $(Expr(:inbounds, false))
      # meta: location float.jl < 493
      fy@_25::Float64 = (Base.sitofp)(Float64, 7)::Float64
      # meta: pop location
      $(Expr(:inbounds, :pop))
      unless (Base.or_int)((Base.lt_float)(x@_3::Float64, fy@_25::Float64)::Bool, (Base.and_int)((Base.and_int)((Base.eq_float)(x@_3::Float64, fy@_25::Float64)::Bool, (Base.lt_float)(fy@_25::Float64, 9.223372036854776e18)::Bool)::Bool, (Base.slt_int)((Base.fptosi)(Int64, fy@_25::Float64)::Int64, 7)::Bool)::Bool)::Bool goto 90
      #= line 35 =#
      $(Expr(:inbounds, false))
      # meta: location float.jl floor 334
      # meta: location float.jl trunc 671
      unless (Base.le_float)(-9.223372036854776e18, (Base.floor_llvm)(x@_3::Float64)::Float64)::Bool goto 53
      #temp#@_26::Bool = (Base.lt_float)((Base.floor_llvm)(x@_3::Float64)::Float64, 9.223372036854776e18)::Bool
      goto 55
      53: 
      #temp#@_26::Bool = false
      55: 
      unless #temp#@_26::Bool goto 60
      #= line 672 =#
      #temp#@_27::Int64 = (Base.fptosi)(Int64, (Base.floor_llvm)(x@_3::Float64)::Float64)::Int64
      goto 63
      60: 
      #= line 674 =#
      #temp#@_27::Int64 = (Base.throw)($(Expr(:invoke, MethodInstance for InexactError(::Symbol, ::Any, ::Any), :(Base.InexactError), :(:trunc), Int64, :((Base.floor_llvm)(x@_3)::Float64)))::InexactError)::Union{}
      63: 
      # meta: pop location
      # meta: pop location
      $(Expr(:inbounds, :pop))
      n::Int64 = (Base.sub_int)(7, #temp#@_27::Int64)::Int64
      #= line 36 =#
      $(Expr(:inbounds, false))
      # meta: location range.jl colon 5
      # meta: pop location
      $(Expr(:inbounds, :pop))
      SSAValue(11) = (Base.select_value)((Base.sle_int)(1, (Base.sub_int)(n::Int64, 1)::Int64)::Bool, (Base.sub_int)(n::Int64, 1)::Int64, (Base.sub_int)(1, 1)::Int64)::Int64
      #temp#@_19::Int64 = 1
      75: 
      unless (Base.not_int)((#temp#@_19::Int64 === (Base.add_int)(SSAValue(11), 1)::Int64)::Bool)::Bool goto 85
      SSAValue(12) = #temp#@_19::Int64
      SSAValue(13) = (Base.add_int)(#temp#@_19::Int64, 1)::Int64
      ν::Int64 = SSAValue(12)
      #temp#@_19::Int64 = SSAValue(13)
      #= line 37 =#
      ψ::Any = (Base.sub_float)(ψ::Float64, (Base.div_float)((Base.sitofp)(Float64, 1)::Float64, (Base.add_float)(z@_21::Float64, (Base.sitofp)(Float64, ν::Int64)::Float64)::Float64)::Float64)::Float64
      83: 
      goto 75
      85: 
      #= line 39 =#
      ψ::Any = (Base.sub_float)(ψ::Float64, (Base.div_float)((Base.sitofp)(Float64, 1)::Float64, z@_21::Float64)::Float64)::Float64
      #= line 40 =#
      z@_21::Float64 = (Base.add_float)(z@_21::Float64, (Base.sitofp)(Float64, n::Int64)::Float64)::Float64
      90: 
      #= line 42 =#
      t::Float64 = (Base.div_float)((Base.sitofp)(Float64, 1)::Float64, z@_21::Float64)::Float64
      #= line 43 =#
      $(Expr(:inbounds, false))
      # meta: location math.jl log 442
      SSAValue(10) = $(Expr(:foreigncall, ("log", "libopenlibm"), Float64, svec(Float64), :(:ccall), 1, :(z@_21)))
      # meta: location math.jl nan_dom_err 323
      unless (Base.and_int)((Base.ne_float)(SSAValue(10), SSAValue(10))::Bool, (Base.not_int)((Base.ne_float)(z@_21::Float64, z@_21::Float64)::Bool)::Bool)::Bool goto 101
      #temp#@_28::Float64 = (Base.Math.throw)($(Expr(:invoke, MethodInstance for DomainError(::Any, ::Any), :(Base.Math.DomainError), :(z@_21), "NaN result for non-NaN input."))::DomainError)::Union{}
      goto 103
      101: 
      #temp#@_28::Float64 = SSAValue(10)
      103: 
      # meta: pop location
      # meta: pop location
      $(Expr(:inbounds, :pop))
      ψ::Any = (Base.add_float)(ψ::Float64, (Base.sub_float)(#temp#@_28::Float64, (Base.mul_float)(0.5, t::Float64)::Float64)::Float64)::Float64
      #= line 44 =#
      t::Float64 = (Base.mul_float)(t::Float64, t::Float64)::Float64
      #= line 46 =#
      SSAValue(2) = ψ::Float64
      SSAValue(3) = t::Float64
      tt::Float64 = t::Float64
      # meta: location math.jl
      #= line 139 =#
      goto 117
      117: 
      Base.Math.t = tt::Float64
      #temp#@_22::Any = (Base.Math.muladd)(Base.Math.t, (Base.Math.muladd)(Base.Math.t, (Base.Math.muladd)(Base.Math.t, (Base.Math.muladd)(Base.Math.t, (Base.Math.muladd)(Base.Math.t, (Base.Math.muladd)(Base.Math.t, (Base.Math.muladd)(Base.Math.t, -0.4432598039215686, 0.08333333333333333)::Any, -0.021092796092796094)::Any, 0.007575757575757576)::Any, -0.004166666666666667)::Any, 0.003968253968253968)::Any, -0.008333333333333333)::Any, 0.08333333333333333)::Any
      120: 
      # meta: pop location
      SSAValue(5) = (SSAValue(3) * #temp#@_22::Any)::Any
      SSAValue(6) = (SSAValue(2) - SSAValue(5))::Any
      ψ::Any = SSAValue(6)
      return SSAValue(6)
  end::Any

The same function is type-stable in Julia 0.6, so it has probably to do with some change in Julia base code.

@giordano
Copy link
Member Author

By git-bisecting Julia, I found that the type-instability pops up after JuliaLang/julia#22985 😕

@stevengj
Copy link
Member

I filed a Julia issue, since it seems to occur for any @evalpoly invocation.

@giordano
Copy link
Member Author

giordano commented Sep 8, 2017

Fixed by JuliaLang/julia#23247

@giordano giordano closed this as completed Sep 8, 2017
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

2 participants