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-unstable code when using broadcasting #24186

Closed
giordano opened this issue Oct 17, 2017 · 3 comments
Closed

Type-unstable code when using broadcasting #24186

giordano opened this issue Oct 17, 2017 · 3 comments
Labels
broadcast Applying a function over a collection compiler:inference Type inference

Comments

@giordano
Copy link
Contributor

giordano commented Oct 17, 2017

In Julia master (but not in Julia 0.6) this apparently harmless function:

using StaticArrays

const v1 = SVector(1)
const v2 = SVector(2)
const v3 = SVector(3)
const v4 = SVector(4)

function foo()
    a, b, c, d = 1:4
    arg = @. v1 * a + v2 * b + v3 * c + v4 * d
end

is type-unstable:

julia> @code_warntype foo()
Variables:
  #1::getfield(Main, Symbol("##1#2"))
  a::Int64
  b::Int64
  c::Int64
  d::Int64
  #temp#@_7::Int64
  arg<optimized out>
  #temp#@_9::Tuple{Int64,Int64}
  #temp#@_10::Tuple{Int64,Int64}
  #temp#@_11::Tuple{Int64,Int64}
  #temp#@_12::Tuple{Int64,Int64}

Body:
  begin
      SSAValue(0) = $(Expr(:new, UnitRange{Int64}, 1, :((Base.select_value)((Base.sle_int)(1, 4)::Bool, 4, (Base.sub_int)(1, 1)::Int64)::Int64)))
      #temp#@_7::Int64 = (Core.getfield)(SSAValue(0), :start)::Int64
      # meta: location tuple.jl indexed_next 60
      unless (#temp#@_7::Int64 === (Base.add_int)((Core.getfield)(SSAValue(0), :stop)::Int64, 1)::Int64)::Bool goto 7
      #temp#@_9::Tuple{Int64,Int64} = (Base.throw)($(Expr(:invoke, MethodInstance for BoundsError(::Any, ::Int64), :(Base.BoundsError), SSAValue(0), 1))::BoundsError)::Union{}
      goto 9
      7: 
      #temp#@_9::Tuple{Int64,Int64} = (Core.tuple)(#temp#@_7::Int64, (Base.add_int)(#temp#@_7::Int64, 1)::Int64)::Tuple{Int64,Int64}
      9: 
      # meta: pop location
      SSAValue(1) = #temp#@_9::Tuple{Int64,Int64}
      a::Int64 = (Core.getfield)(SSAValue(1), 1)::Int64
      #temp#@_7::Int64 = (Core.getfield)(SSAValue(1), 2)::Int64
      # meta: location tuple.jl indexed_next 60
      unless (#temp#@_7::Int64 === (Base.add_int)((Core.getfield)(SSAValue(0), :stop)::Int64, 1)::Int64)::Bool goto 18
      #temp#@_10::Tuple{Int64,Int64} = (Base.throw)($(Expr(:invoke, MethodInstance for BoundsError(::Any, ::Int64), :(Base.BoundsError), SSAValue(0), 2))::BoundsError)::Union{}
      goto 20
      18: 
      #temp#@_10::Tuple{Int64,Int64} = (Core.tuple)(#temp#@_7::Int64, (Base.add_int)(#temp#@_7::Int64, 1)::Int64)::Tuple{Int64,Int64}
      20: 
      # meta: pop location
      SSAValue(2) = #temp#@_10::Tuple{Int64,Int64}
      b::Int64 = (Core.getfield)(SSAValue(2), 1)::Int64
      #temp#@_7::Int64 = (Core.getfield)(SSAValue(2), 2)::Int64
      # meta: location tuple.jl indexed_next 60
      unless (#temp#@_7::Int64 === (Base.add_int)((Core.getfield)(SSAValue(0), :stop)::Int64, 1)::Int64)::Bool goto 29
      #temp#@_11::Tuple{Int64,Int64} = (Base.throw)($(Expr(:invoke, MethodInstance for BoundsError(::Any, ::Int64), :(Base.BoundsError), SSAValue(0), 3))::BoundsError)::Union{}
      goto 31
      29: 
      #temp#@_11::Tuple{Int64,Int64} = (Core.tuple)(#temp#@_7::Int64, (Base.add_int)(#temp#@_7::Int64, 1)::Int64)::Tuple{Int64,Int64}
      31: 
      # meta: pop location
      SSAValue(3) = #temp#@_11::Tuple{Int64,Int64}
      c::Int64 = (Core.getfield)(SSAValue(3), 1)::Int64
      #temp#@_7::Int64 = (Core.getfield)(SSAValue(3), 2)::Int64
      # meta: location tuple.jl indexed_next 60
      unless (#temp#@_7::Int64 === (Base.add_int)((Core.getfield)(SSAValue(0), :stop)::Int64, 1)::Int64)::Bool goto 40
      #temp#@_12::Tuple{Int64,Int64} = (Base.throw)($(Expr(:invoke, MethodInstance for BoundsError(::Any, ::Int64), :(Base.BoundsError), SSAValue(0), 4))::BoundsError)::Union{}
      goto 42
      40: 
      #temp#@_12::Tuple{Int64,Int64} = (Core.tuple)(#temp#@_7::Int64, (Base.add_int)(#temp#@_7::Int64, 1)::Int64)::Tuple{Int64,Int64}
      42: 
      # meta: pop location
      SSAValue(4) = #temp#@_12::Tuple{Int64,Int64}
      d::Int64 = (Core.getfield)(SSAValue(4), 1)::Int64
      #temp#@_7::Int64 = (Core.getfield)(SSAValue(4), 2)::Int64
      #= line 11 =#
      #1::getfield(Main, Symbol("##1#2")) = $(Expr(:new, :(Main.##1#2)))
      # meta: location broadcast.jl broadcast 434
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/broadcast.jl broadcast_c 33
      SSAValue(10) = (Core._apply)(Core.tuple, (Size(1,),), $(Expr(:invoke, MethodInstance for broadcast_sizes(::Int64, ::SVector{1,Int64}, ::Vararg{Any,N} where N), :(StaticArrays.broadcast_sizes), :(a), :(Main.v2), :(b), :(Main.v3), :(c), :(Main.v4), :(d)))::Tuple{StaticArrays.Size{()},StaticArrays.Size{(1,)},Vararg{Any,N} where N})::Tuple{StaticArrays.Size{(1,)},StaticArrays.Size{()},StaticArrays.Size{(1,)},Vararg{Any,N} where N}
      # meta: pop locations (2)
      SSAValue(9) = (StaticArrays._broadcast)(#1::getfield(Main, Symbol("##1#2")), SSAValue(10), Main.v1, a::Int64, Main.v2, b::Int64, Main.v3, c::Int64, Main.v4, d::Int64)::Any
      return SSAValue(9)
  end::Any

It is instead stable if broadcast is not used (remove the @.):

julia> function foo()
           a, b, c, d = 1:4
           arg = v1 * a + v2 * b + v3 * c + v4 * d
       end
foo (generic function with 1 method)

julia> @code_warntype foo()
Variables:
  a::Int64
  b::Int64
  c::Int64
  d::Int64
  #temp#@_6::Int64
  arg<optimized out>
  #temp#@_8::Tuple{Int64,Int64}
  #temp#@_9::Tuple{Int64,Int64}
  #temp#@_10::Tuple{Int64,Int64}
  #temp#@_11::Tuple{Int64,Int64}
  #temp#@_12::SVector{1,Int64}
  #temp#@_18::SVector{1,Int64}

Body:
  begin
      SSAValue(0) = $(Expr(:new, UnitRange{Int64}, 1, :((Base.select_value)((Base.sle_int)(1, 4)::Bool, 4, (Base.sub_int)(1, 1)::Int64)::Int64)))
      #temp#@_6::Int64 = (Core.getfield)(SSAValue(0), :start)::Int64
      # meta: location tuple.jl indexed_next 60
      unless (#temp#@_6::Int64 === (Base.add_int)((Core.getfield)(SSAValue(0), :stop)::Int64, 1)::Int64)::Bool goto 7
      #temp#@_8::Tuple{Int64,Int64} = (Base.throw)($(Expr(:invoke, MethodInstance for BoundsError(::Any, ::Int64), :(Base.BoundsError), SSAValue(0), 1))::BoundsError)::Union{}
      goto 9
      7: 
      #temp#@_8::Tuple{Int64,Int64} = (Core.tuple)(#temp#@_6::Int64, (Base.add_int)(#temp#@_6::Int64, 1)::Int64)::Tuple{Int64,Int64}
      9: 
      # meta: pop location
      SSAValue(1) = #temp#@_8::Tuple{Int64,Int64}
      a::Int64 = (Core.getfield)(SSAValue(1), 1)::Int64
      #temp#@_6::Int64 = (Core.getfield)(SSAValue(1), 2)::Int64
      # meta: location tuple.jl indexed_next 60
      unless (#temp#@_6::Int64 === (Base.add_int)((Core.getfield)(SSAValue(0), :stop)::Int64, 1)::Int64)::Bool goto 18
      #temp#@_9::Tuple{Int64,Int64} = (Base.throw)($(Expr(:invoke, MethodInstance for BoundsError(::Any, ::Int64), :(Base.BoundsError), SSAValue(0), 2))::BoundsError)::Union{}
      goto 20
      18: 
      #temp#@_9::Tuple{Int64,Int64} = (Core.tuple)(#temp#@_6::Int64, (Base.add_int)(#temp#@_6::Int64, 1)::Int64)::Tuple{Int64,Int64}
      20: 
      # meta: pop location
      SSAValue(2) = #temp#@_9::Tuple{Int64,Int64}
      b::Int64 = (Core.getfield)(SSAValue(2), 1)::Int64
      #temp#@_6::Int64 = (Core.getfield)(SSAValue(2), 2)::Int64
      # meta: location tuple.jl indexed_next 60
      unless (#temp#@_6::Int64 === (Base.add_int)((Core.getfield)(SSAValue(0), :stop)::Int64, 1)::Int64)::Bool goto 29
      #temp#@_10::Tuple{Int64,Int64} = (Base.throw)($(Expr(:invoke, MethodInstance for BoundsError(::Any, ::Int64), :(Base.BoundsError), SSAValue(0), 3))::BoundsError)::Union{}
      goto 31
      29: 
      #temp#@_10::Tuple{Int64,Int64} = (Core.tuple)(#temp#@_6::Int64, (Base.add_int)(#temp#@_6::Int64, 1)::Int64)::Tuple{Int64,Int64}
      31: 
      # meta: pop location
      SSAValue(3) = #temp#@_10::Tuple{Int64,Int64}
      c::Int64 = (Core.getfield)(SSAValue(3), 1)::Int64
      #temp#@_6::Int64 = (Core.getfield)(SSAValue(3), 2)::Int64
      # meta: location tuple.jl indexed_next 60
      unless (#temp#@_6::Int64 === (Base.add_int)((Core.getfield)(SSAValue(0), :stop)::Int64, 1)::Int64)::Bool goto 40
      #temp#@_11::Tuple{Int64,Int64} = (Base.throw)($(Expr(:invoke, MethodInstance for BoundsError(::Any, ::Int64), :(Base.BoundsError), SSAValue(0), 4))::BoundsError)::Union{}
      goto 42
      40: 
      #temp#@_11::Tuple{Int64,Int64} = (Core.tuple)(#temp#@_6::Int64, (Base.add_int)(#temp#@_6::Int64, 1)::Int64)::Tuple{Int64,Int64}
      42: 
      # meta: pop location
      SSAValue(4) = #temp#@_11::Tuple{Int64,Int64}
      d::Int64 = (Core.getfield)(SSAValue(4), 1)::Int64
      #temp#@_6::Int64 = (Core.getfield)(SSAValue(4), 2)::Int64
      #= line 3 =#
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/linalg.jl * 26
      # meta: location broadcast.jl broadcast 434
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/broadcast.jl broadcast_c 33
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/broadcast.jl _broadcast 52
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/broadcast.jl @generated body
      #= line 110 =#
      SSAValue(25) = (Base.mul_int)((Base.getfield)((Core.getfield)(Main.v1, :data)::Tuple{Int64}, 1, false)::Int64, a::Int64)::Int64
      goto 57
      # meta: pop location
      57: 
      # meta: pop locations (4)
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/linalg.jl * 26
      # meta: location broadcast.jl broadcast 434
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/broadcast.jl broadcast_c 33
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/broadcast.jl _broadcast 52
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/broadcast.jl @generated body
      #= line 110 =#
      SSAValue(27) = (Base.mul_int)((Base.getfield)((Core.getfield)(Main.v2, :data)::Tuple{Int64}, 1, false)::Int64, b::Int64)::Int64
      goto 68
      # meta: pop location
      68: 
      # meta: pop locations (4)
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/linalg.jl * 26
      # meta: location broadcast.jl broadcast 434
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/broadcast.jl broadcast_c 33
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/broadcast.jl _broadcast 52
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/broadcast.jl @generated body
      #= line 110 =#
      SSAValue(29) = (Base.mul_int)((Base.getfield)((Core.getfield)(Main.v3, :data)::Tuple{Int64}, 1, false)::Int64, c::Int64)::Int64
      goto 79
      # meta: pop location
      79: 
      # meta: pop locations (4)
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/linalg.jl * 26
      # meta: location broadcast.jl broadcast 434
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/broadcast.jl broadcast_c 33
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/broadcast.jl _broadcast 52
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/broadcast.jl @generated body
      #= line 110 =#
      #temp#@_12::SVector{1,Int64} = $(Expr(:new, SVector{1,Int64}, :((StaticArrays.tuple)((Base.mul_int)((Base.getfield)((Core.getfield)(Main.v4, :data)::Tuple{Int64}, 1, false)::Int64, d)::Int64)::Tuple{Int64})))
      goto 90
      # meta: pop location
      90: 
      # meta: pop locations (4)
      # meta: location operators.jl + 469
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/linalg.jl + 10
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/mapreduce.jl map 15
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/mapreduce.jl _map 20
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/mapreduce.jl @generated body
      #= line 29 =#
      SSAValue(21) = (Base.add_int)(SSAValue(25), SSAValue(27))::Int64
      goto 101
      # meta: pop location
      101: 
      # meta: pop locations (3)
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/linalg.jl + 10
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/mapreduce.jl map 15
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/mapreduce.jl _map 20
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/mapreduce.jl @generated body
      #= line 29 =#
      SSAValue(23) = (Base.add_int)(SSAValue(21), SSAValue(29))::Int64
      goto 111
      # meta: pop location
      111: 
      # meta: pop locations (3)
      # meta: location operators.jl afoldl 456
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/linalg.jl + 10
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/mapreduce.jl map 15
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/mapreduce.jl _map 20
      # meta: location /home/mose/.julia/v0.7/StaticArrays/src/mapreduce.jl @generated body
      #= line 29 =#
      #temp#@_18::SVector{1,Int64} = $(Expr(:new, SVector{1,Int64}, :((StaticArrays.tuple)((Base.add_int)(SSAValue(23), (Base.getfield)((Core.getfield)(#temp#@_12, :data)::Tuple{Int64}, 1, false)::Int64)::Int64)::Tuple{Int64})))
      goto 122
      # meta: pop location
      122: 
      # meta: pop locations (5)
      return #temp#@_18::SVector{1,Int64}
  end::SVector{1,Int64}

First reported at JuliaArrays/StaticArrays.jl#321.

@kshyatt kshyatt added types and dispatch Types, subtyping and method dispatch broadcast Applying a function over a collection labels Oct 19, 2017
@ChrisRackauckas
Copy link
Member

Duplicate of #22255

@JeffBezanson JeffBezanson added compiler:inference Type inference broadcast and removed types and dispatch Types, subtyping and method dispatch labels Apr 4, 2018
@mbauman mbauman removed the broadcast label Apr 24, 2018
@giordano
Copy link
Contributor Author

I don't think this is a duplicate of #22255, this issue is still there on Julia master.

julia> versioninfo()
Julia Version 0.7.0-beta.206
Commit b6f9244d6b (2018-07-08 19:42 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i7-4700MQ CPU @ 2.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, haswell)

julia> @code_warntype foo()
Body::Any
2 1 ──        Base.ifelse(true, 4, 0)                                                     │╻╷╷              Colon
  │    %2   = new(UnitRange{Int64}, 1, 4)::UnitRange{Int64}                               ││┃                Type
  │    %3   = Base.slt_int(4, 1)::Bool                                                    ││╻╷╷╷             iterate
  └───        goto 3 if not %3                                                            │││              
  2 ──        goto 4                                                                      │││              
  3 ──        goto 4                                                                      │││              
  4 ┄─ %7   = φ (2 => true, 3 => false)::Bool                                             ││               
  │    %8   = φ (3 => 1)::Int64                                                           ││               
  │    %9   = φ (3 => 1)::Int64                                                           ││               
  └───        goto 6 if not %7                                                            ││               
  5 ── %11  = invoke Base.BoundsError(%2::Any, 1::Int64)::BoundsError                     ││               
  │           Base.throw(%11)                                                             ││               
  └───        unreachable                                                                 ││               
  6 ──        goto 7                                                                      ││               
  7 ── %15  = Base.:===(%9, 4)::Bool                                                      ││╻╷               iterate
  └───        goto 9 if not %15                                                           │││              
  8 ──        goto 10                                                                     │││              
  9 ── %18  = Base.add_int(%9, 1)::Int64                                                  │││╻                +
  └───        goto 10                                                                     ││╻                iterate
  10%20  = φ (8 => true, 9 => false)::Bool                                             ││               
  │    %21  = φ (9 => %18)::Int64                                                         ││               
  │    %22  = φ (9 => %18)::Int64                                                         ││               
  └───        goto 12 if not %20                                                          ││               
  11%24  = invoke Base.BoundsError(%2::Any, 2::Int64)::BoundsError                     ││               
  │           Base.throw(%24)                                                             ││               
  └───        unreachable                                                                 ││               
  12 ─        goto 13                                                                     ││               
  13%28  = Base.:===(%22, 4)::Bool                                                     ││╻╷               iterate
  └───        goto 15 if not %28                                                          │││              
  14 ─        goto 16                                                                     │││              
  15%31  = Base.add_int(%22, 1)::Int64                                                 │││╻                +
  └───        goto 16                                                                     ││╻                iterate
  16%33  = φ (14 => true, 15 => false)::Bool                                           ││               
  │    %34  = φ (15 => %31)::Int64                                                        ││               
  │    %35  = φ (15 => %31)::Int64                                                        ││               
  └───        goto 18 if not %33                                                          ││               
  17%37  = invoke Base.BoundsError(%2::Any, 3::Int64)::BoundsError                     ││               
  │           Base.throw(%37)                                                             ││               
  └───        unreachable                                                                 ││               
  18 ─        goto 19                                                                     ││               
  19%41  = Base.:===(%35, 4)::Bool                                                     ││╻╷               iterate
  └───        goto 21 if not %41                                                          │││              
  20 ─        goto 22                                                                     │││              
  21%44  = Base.add_int(%35, 1)::Int64                                                 │││╻                +
  └───        goto 22                                                                     ││╻                iterate
  22%46  = φ (20 => true, 21 => false)::Bool                                           ││               
  │    %47  = φ (21 => %44)::Int64                                                        ││               
  └───        goto 24 if not %46                                                          ││               
  23%49  = invoke Base.BoundsError(%2::Any, 4::Int64)::BoundsError                     ││               
  │           Base.throw(%49)                                                             ││               
  └───        unreachable                                                                 ││               
  24 ─        goto 25                                                                     ││               
3 25%53  = π (:($(QuoteNode([1]))), SArray{Tuple{1},Int64,1,1})                        │╻                broadcasted
  │    %54  = Core.tuple(%53, %8)::Tuple{SArray{Tuple{1},Int64,1,1},Int64}                ││               
  │    %55  = :(Base.Broadcast.Core)::Module                                              ││╻╷               broadcasted
  │           Base.getfield(%55, :Typeof)                                                 │││┃││              Type
  │    %57  = new(Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Nothing,typeof(*),Tuple{SArray{Tuple{1},Int64,1,1},Int64}}, *, %54, nothing)::Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Nothing,typeof(*),Tuple{SArray{Tuple{1},Int64,1,1},Int64}}                                                                                                                       
  │    %58  = π (:($(QuoteNode([2]))), SArray{Tuple{1},Int64,1,1})                        │╻                broadcasted
  │    %59  = Core.tuple(%58, %21)::Tuple{SArray{Tuple{1},Int64,1,1},Int64}               ││               
  │    %60  = :(Base.Broadcast.Core)::Module                                              ││╻╷               broadcasted
  │           Base.getfield(%60, :Typeof)                                                 │││┃││              Type
  │    %62  = new(Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Nothing,typeof(*),Tuple{SArray{Tuple{1},Int64,1,1},Int64}}, *, %59, nothing)::Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Nothing,typeof(*),Tuple{SArray{Tuple{1},Int64,1,1},Int64}}                                                                                                                       
  │    %63  = π (:($(QuoteNode([3]))), SArray{Tuple{1},Int64,1,1})                        │╻                broadcasted
  │    %64  = Core.tuple(%63, %34)::Tuple{SArray{Tuple{1},Int64,1,1},Int64}               ││               
  │    %65  = :(Base.Broadcast.Core)::Module                                              ││╻╷               broadcasted
  │           Base.getfield(%65, :Typeof)                                                 │││┃││              Type
  │    %67  = new(Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Nothing,typeof(*),Tuple{SArray{Tuple{1},Int64,1,1},Int64}}, *, %64, nothing)::Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Nothing,typeof(*),Tuple{SArray{Tuple{1},Int64,1,1},Int64}}                                                                                                                       
  │    %68  = π (:($(QuoteNode([4]))), SArray{Tuple{1},Int64,1,1})                        │╻                broadcasted
  │    %69  = Core.tuple(%68, %47)::Tuple{SArray{Tuple{1},Int64,1,1},Int64}               ││               
  │    %70  = :(Base.Broadcast.Core)::Module                                              ││╻╷               broadcasted
  │           Base.getfield(%70, :Typeof)                                                 │││┃││              Type
  │    %72  = new(Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Nothing,typeof(*),Tuple{SArray{Tuple{1},Int64,1,1},Int64}}, *, %69, nothing)::Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Nothing,typeof(*),Tuple{SArray{Tuple{1},Int64,1,1},Int64}}                                                                                                                       
  │    %73  = Core.tuple(%57, %62, %67, %72)::NTuple{4,Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Nothing,typeof(*),Tuple{SArray{Tuple{1},Int64,1,1},Int64}}}                                                                                        
  │    %74  = :(Base.Broadcast.Core)::Module                                              ││╻╷               broadcasted
  │           Base.getfield(%74, :Typeof)                                                 │││┃││              Type
  │           Base.ifelse(false, 0, 1)                                                    ││╻╷╷╷╷╷╷╷╷╷╷╷     instantiate
  │    %77  = new(Base.OneTo{Int64}, 1)::Base.OneTo{Int64}                                │││┃│││││││││       combine_axes
  │           Base.ifelse(false, 0, 1)                                                    ││││╻╷╷╷╷╷╷╷╷╷       combine_axes
  │    %79  = new(Base.OneTo{Int64}, 1)::Base.OneTo{Int64}                                │││││┃││││││││        broadcast_axes
  │           Base.ifelse(false, 0, 1)                                                    ││││││╻╷╷╷╷╷╷╷╷╷       broadcast_axes
  │    %81  = new(Base.OneTo{Int64}, 1)::Base.OneTo{Int64}                                │││││││┃│││││││         axes
  │           Base.ifelse(false, 0, 1)                                                    │││││││╻╷╷╷╷╷╷╷╷╷       broadcast_axes
  │    %83  = new(Base.OneTo{Int64}, 1)::Base.OneTo{Int64}                                ││││││││┃│││││││         axes
  │    %84  = Base.:===(1, 1)::Bool                                                       │││││││╻╷╷╷╷            _bcs
  │    %85  = Base.and_int(true, %84)::Bool                                               ││││││││╻                _bcs1
  └───        goto 27 if not %85                                                          │││││││││┃                _bcsm
  26 ─        goto 28                                                                     ││││││││││       
  27 ─        goto 28                                                                     ││││││││││       
  28%89  = φ (26 => %85, 27 => true)::Bool                                             │││││││││        
  └───        goto 30 if not %89                                                          │││││││││        
  29 ─        goto 36                                                                     │││││││││        
  30%92  = Base.:===(1, 1)::Bool                                                       ││││││││││╻╷               ==%93  = Base.and_int(true, %92)::Bool                                               │││││││││││╻                &
  └───        goto 32 if not %93                                                          ││││││││││       
  31 ─        goto 33                                                                     ││││││││││       
  32 ─        goto 33                                                                     ││││││││││       
  33%97  = φ (31 => %93, 32 => true)::Bool                                             │││││││││        
  └───        goto 35 if not %97                                                          │││││││││        
  34 ─        goto 36                                                                     │││││││││        
  35%100 = new(Base.DimensionMismatch, "arrays could not be broadcast to a common size")::DimensionMismatch      Type
  │           Base.Broadcast.throw(%100)                                                  │││││││││        
  └───        unreachable                                                                 │││││││││        
  36%103 = φ (29 => true, 34 => true)::Bool                                            ││││││││         
  │    %104 = φ (29 => true, 34 => true)::Bool                                            ││││││││         
  │    %105 = φ (29 => true, 34 => true)::Bool                                            ││││││││         
  │    %106 = φ (29 => true, 34 => true)::Bool                                            ││││││││         
  │    %107 = φ (29 => true, 34 => true)::Bool                                            ││││││││         
  │    %108 = φ (29 => true, 34 => true)::Bool                                            ││││││││         
  │    %109 = φ (29 => %83, 34 => %81)::Base.OneTo{Int64}                                 ││││││││         
  └───        goto 37                                                                     ││││││││         
  37 ─        goto 38                                                                     │││││││          
  38 ─        goto 39                                                                     ││││││           
  39%113 = Base.and_int(true, %103)::Bool                                              ││││││╻╷╷╷╷            _bcs
  └───        goto 41 if not %113                                                         │││││││┃│               _bcs1
  40 ─        goto 42                                                                     ││││││││┃                _bcsm
  41 ─        goto 42                                                                     │││││││││        
  42%117 = φ (40 => %113, 41 => true)::Bool                                            ││││││││         
  └───        goto 44 if not %117                                                         ││││││││         
  43 ─        goto 50                                                                     ││││││││         
  44%120 = Base.and_int(true, %104)::Bool                                              │││││││││╻╷               ==
  └───        goto 46 if not %120                                                         │││││││││        
  45 ─        goto 47                                                                     │││││││││        
  46 ─        goto 47                                                                     │││││││││        
  47%124 = φ (45 => %120, 46 => %105)::Bool                                            ││││││││         
  └───        goto 49 if not %124                                                         ││││││││         
  48 ─        goto 50                                                                     ││││││││         
  49%127 = new(Base.DimensionMismatch, "arrays could not be broadcast to a common size")::DimensionMismatch     Type
  │           Base.Broadcast.throw(%127)                                                  ││││││││         
  └───        unreachable                                                                 ││││││││         
  50%130 = φ (43 => %106, 48 => true)::Bool                                            │││││││          
  │    %131 = φ (43 => %107, 48 => true)::Bool                                            │││││││          
  │    %132 = φ (43 => %108, 48 => true)::Bool                                            │││││││          
  │    %133 = φ (43 => %109, 48 => %79)::Base.OneTo{Int64}                                │││││││          
  └───        goto 51                                                                     │││││││          
  51 ─        goto 52                                                                     ││││││           
  52 ─        goto 53                                                                     │││││            
  53%137 = Base.and_int(true, %130)::Bool                                              │││││╻╷╷╷╷            _bcs
  └───        goto 55 if not %137                                                         ││││││┃│               _bcs1
  54 ─        goto 56                                                                     │││││││┃                _bcsm
  55 ─        goto 56                                                                     ││││││││         
  56%141 = φ (54 => %137, 55 => true)::Bool                                            │││││││          
  └───        goto 58 if not %141                                                         │││││││          
  57 ─        goto 64                                                                     │││││││          
  58%144 = Base.and_int(true, %131)::Bool                                              ││││││││╻╷               ==
  └───        goto 60 if not %144                                                         ││││││││         
  59 ─        goto 61                                                                     ││││││││         
  60 ─        goto 61                                                                     ││││││││         
  61%148 = φ (59 => %144, 60 => %132)::Bool                                            │││││││          
  └───        goto 63 if not %148                                                         │││││││          
  62 ─        goto 64                                                                     │││││││          
  63%151 = new(Base.DimensionMismatch, "arrays could not be broadcast to a common size")::DimensionMismatch    Type
  │           Base.Broadcast.throw(%151)                                                  │││││││          
  └───        unreachable                                                                 │││││││          
  64%154 = φ (57 => %133, 62 => %77)::Base.OneTo{Int64}                                ││││││           
  │    %155 = Core.tuple(%154)::Tuple{Base.OneTo{Int64}}                                  ││││││           
  └───        goto 65                                                                     ││││││           
  65 ─        goto 66                                                                     │││││            
  66 ─        goto 67                                                                     ││││             
  67%159 = :(Base.Broadcast.Core)::Module                                              │││╻                Type
  │           Base.getfield(%159, :Typeof)                                                ││││╻                getproperty
  │    %161 = new(Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Tuple{Base.OneTo{Int64}},typeof(+),NTuple{4,Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Nothing,typeof(*),Tuple{SArray{Tuple{1},Int64,1,1},Int64}}}}, +, %73, %155)::Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Tuple{Base.OneTo{Int64}},typeof(+),NTuple{4,Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Nothing,typeof(*),Tuple{SArray{Tuple{1},Int64,1,1},Int64}}}}                                         
  └───        goto 68                                                                     │││              
  68%163 = :(StaticArrays.Broadcast)::Module                                           ││╻                copy
  │    %164 = Base.getfield(%163, :flatten)::typeof(Base.Broadcast.flatten)               │││╻                getproperty
  │    %165 = invoke %164(%161::Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Tuple{Base.OneTo{Int64}},typeof(+),NTuple{4,Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Nothing,typeof(*),Tuple{SArray{Tuple{1},Int64,1,1},Int64}}}})::Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Tuple{Base.OneTo{Int64}},getfield(Base.Broadcast, Symbol("##2#4")){Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Tuple{Base.OneTo{Int64}},typeof(+),NTuple{4,Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Nothing,typeof(*),Tuple{SArray{Tuple{1},Int64,1,1},Int64}}}},getfield(Base.Broadcast, Symbol("##9#10")){Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Nothing,typeof(*),Tuple{SArray{Tuple{1},Int64,1,1},Int64}},getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##13#14"))}},getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##17#18"))}},getfield(Base.Broadcast, Symbol("##7#8")){getfield(Base.Broadcast, Symbol("##7#8")){getfield(Base.Broadcast, Symbol("##9#10")){Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Nothing,typeof(*),Tuple{SArray{Tuple{1},Int64,1,1},Int64}},getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##13#14"))}},getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##17#18"))}},getfield(Base.Broadcast, Symbol("##7#8")){getfield(Base.Broadcast, Symbol("##7#8")){getfield(Base.Broadcast, Symbol("##9#10")){Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Nothing,typeof(*),Tuple{SArray{Tuple{1},Int64,1,1},Int64}},getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##13#14"))}},getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##17#18"))}},getfield(Base.Broadcast, Symbol("##7#8")){getfield(Base.Broadcast, Symbol("##7#8")){getfield(Base.Broadcast, Symbol("##9#10")){Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Nothing,typeof(*),Tuple{SArray{Tuple{1},Int64,1,1},Int64}},getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##13#14"))}},getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##17#18"))}},getfield(Base.Broadcast, Symbol("##7#8")){getfield(Base.Broadcast, Symbol("##7#8")){getfield(Base.Broadcast, Symbol("##5#6"))}}}}}}}}}}}}},_1} where _1
  │    %166 = Base.getfield(%165, :args)::Any                                             │││╻                getproperty
  │    %167 = Base.getfield(%165, :f)::getfield(Base.Broadcast, Symbol("##2#4")){Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Tuple{Base.OneTo{Int64}},typeof(+),NTuple{4,Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Nothing,typeof(*),Tuple{SArray{Tuple{1},Int64,1,1},Int64}}}},getfield(Base.Broadcast, Symbol("##9#10")){Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Nothing,typeof(*),Tuple{SArray{Tuple{1},Int64,1,1},Int64}},getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##13#14"))}},getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##17#18"))}},getfield(Base.Broadcast, Symbol("##7#8")){getfield(Base.Broadcast, Symbol("##7#8")){getfield(Base.Broadcast, Symbol("##9#10")){Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Nothing,typeof(*),Tuple{SArray{Tuple{1},Int64,1,1},Int64}},getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##13#14"))}},getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##17#18"))}},getfield(Base.Broadcast, Symbol("##7#8")){getfield(Base.Broadcast, Symbol("##7#8")){getfield(Base.Broadcast, Symbol("##9#10")){Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Nothing,typeof(*),Tuple{SArray{Tuple{1},Int64,1,1},Int64}},getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##13#14"))}},getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##17#18"))}},getfield(Base.Broadcast, Symbol("##7#8")){getfield(Base.Broadcast, Symbol("##7#8")){getfield(Base.Broadcast, Symbol("##9#10")){Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Nothing,typeof(*),Tuple{SArray{Tuple{1},Int64,1,1},Int64}},getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##13#14"))}},getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##17#18"))}},getfield(Base.Broadcast, Symbol("##7#8")){getfield(Base.Broadcast, Symbol("##7#8")){getfield(Base.Broadcast, Symbol("##5#6"))}}}}}}}}}}}}}
  │    %168 = Core._apply(StaticArrays.broadcast_sizes, %166)::Tuple                      ││╻                copy
  │    %169 = StaticArrays.combine_sizes(%168)::Any                                       │││              
  │    %170 = Core.tuple(%167, %169, %168)::Tuple{getfield(Base.Broadcast, Symbol("##2#4")){Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Tuple{Base.OneTo{Int64}},typeof(+),NTuple{4,Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Nothing,typeof(*),Tuple{SArray{Tuple{1},Int64,1,1},Int64}}}},getfield(Base.Broadcast, Symbol("##9#10")){Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Nothing,typeof(*),Tuple{SArray{Tuple{1},Int64,1,1},Int64}},getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##13#14"))}},getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##17#18"))}},getfield(Base.Broadcast, Symbol("##7#8")){getfield(Base.Broadcast, Symbol("##7#8")){getfield(Base.Broadcast, Symbol("##9#10")){Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Nothing,typeof(*),Tuple{SArray{Tuple{1},Int64,1,1},Int64}},getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##13#14"))}},getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##17#18"))}},getfield(Base.Broadcast, Symbol("##7#8")){getfield(Base.Broadcast, Symbol("##7#8")){getfield(Base.Broadcast, Symbol("##9#10")){Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Nothing,typeof(*),Tuple{SArray{Tuple{1},Int64,1,1},Int64}},getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##13#14"))}},getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##17#18"))}},getfield(Base.Broadcast, Symbol("##7#8")){getfield(Base.Broadcast, Symbol("##7#8")){getfield(Base.Broadcast, Symbol("##9#10")){Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1},Nothing,typeof(*),Tuple{SArray{Tuple{1},Int64,1,1},Int64}},getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##11#12")){getfield(Base.Broadcast, Symbol("##13#14"))}},getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##15#16")){getfield(Base.Broadcast, Symbol("##17#18"))}},getfield(Base.Broadcast, Symbol("##7#8")){getfield(Base.Broadcast, Symbol("##7#8")){getfield(Base.Broadcast, Symbol("##5#6"))}}}}}}}}}}}}},Any,Tuple}
  │    %171 = Core._apply(StaticArrays._broadcast, %170, %166)::Any                       │││              
  └───        goto 69                                                                     ││               
  69return %171

@giordano
Copy link
Contributor Author

I don't know when this was fixed, but I can't reproduce this any more on Julia 1.1.1 nor on master (8ebe564).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
broadcast Applying a function over a collection compiler:inference Type inference
Projects
None yet
Development

No branches or pull requests

5 participants