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

Type instability when eachindex() is passed three arguments #13870

Closed
nalimilan opened this issue Nov 4, 2015 · 0 comments
Closed

Type instability when eachindex() is passed three arguments #13870

nalimilan opened this issue Nov 4, 2015 · 0 comments

Comments

@nalimilan
Copy link
Member

The second function below suffers from lots of type instabilities, while the first one is fine. Is that expected?

julia> function f(y, mu)
           ll = 0.0
           for i in eachindex(y, mu)
               ll += 1.0
           end
           ll
       end
f (generic function with 1 method)

julia> function f(y, mu, wts)
           ll = 0.0
           for i in eachindex(y, mu, wts)
               ll += 1.0
           end
           ll
       end
f (generic function with 2 methods)

julia> @code_warntype f(1:3, 1:3, 1:3)
Variables:
  y::UnitRange{Int64}
  mu::UnitRange{Int64}
  wts::UnitRange{Int64}
  ll::Float64
  #s1::Any
  i::Any
  ##B#6980::Tuple{UnitRange{Int64},UnitRange{Int64}}
  ####B#6977#6981::Tuple{UnitRange{Int64},UnitRange{Int64}}
  ####B#6978#6982::Tuple{UnitRange{Int64},UnitRange{Int64}}
  ######xs#6976#6979#6983::Tuple{}

Body:
  begin  # none, line 2:
      ll = 0.0 # none, line 3: # abstractarray.jl, line 413: # abstractarray.jl, line 414: # abstractarray.jl, line 116: # abstractarray.jl, line 110: # abstractarray.jl, line 113: # abstractarray.jl, line 115: # abstractarray.jl, line 110: # abstractarray.jl, line 113: # abstractarray.jl, line 110: # abstractarray.jl, line 113: # abstractarray.jl, line 117: # abstractarray.jl, line 117: # abstractarray.jl, line 417: # range.jl, line 339: # int.jl, line 475: # number.jl, line 51: # essentials.jl, line 61: # int.jl, line 474: # tuple.jl, line 61: # tuple.jl, line 8: # tuple.jl, line 8:
      GenSym(3) = (Base.length)(mu::UnitRange{Int64})::Any
      GenSym(2) = (Base.length)(wts::UnitRange{Int64})::Any # operators.jl, line 103:
      GenSym(4) = (Base.max)((Base.max)((Base.box)(Int64,(Base.checked_sadd)((Base.box)(Int64,(Base.checked_ssub)((top(getfield))(y::UnitRange{Int64},:stop)::Int64,(top(getfield))(y::UnitRange{Int64},:start)::Int64)),1)),GenSym(3))::Any,GenSym(2))::Any # operators.jl, line 82:
      GenSym(0) = (Base.colon)(1,GenSym(4))::Any
      #s1 = (top(start))(GenSym(0))::Any
      unless (top(!))((top(done))(GenSym(0),#s1)::Any)::Any goto 1
      2: 
      GenSym(1) = (top(next))(GenSym(0),#s1)::Any
      i = (top(getfield))(GenSym(1),1)::Any
      #s1 = (top(getfield))(GenSym(1),2)::Any # none, line 4: # float.jl, line 204:
      ll = (Base.box)(Base.Float64,(Base.add_float)(ll::Float64,1.0))
      3: 
      unless (top(!))((top(!))((top(done))(GenSym(0),#s1)::Any)::Any)::Any goto 2
      1: 
      0:  # none, line 6:
      return ll::Float64
  end::Float64
@timholy timholy closed this as completed in 23c3139 Nov 5, 2015
timholy added a commit that referenced this issue Nov 5, 2015
Fix type-instability of eachindex(A, B, C...) (fixes #13870)
timholy added a commit that referenced this issue Nov 7, 2015
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

1 participant