Invalidation from extending `Base.reduce_first`

FillArrays has recently introduced a specialization

Base.reduce_first(::typeof(+), x::Ones) = Fill(Base.reduce_first(+, getindex_value(x)), axes(x))

On v1.10.0-beta2, this seems to introduce invalidations (although not on v1.9.2)

 inserting reduce_first(::typeof(+), x::Ones) @ FillArrays ~/Dropbox/JuliaPackages/FillArrays.jl/src/fillalgebra.jl:357 invalidated:
   backedges: 1: superseding reduce_first(op, x) @ Base reduce.jl:403 with MethodInstance for Base.reduce_first(::typeof(+), ::Any) (6 children)

I’m unsure how to resolve this. Looking into the backedges, I find

julia> show(root; minchildren=0)
MethodInstance for Base.reduce_first(::typeof(+), ::Any) (6 children)
 MethodInstance for Base.reduce_first(::typeof(Base.add_sum), ::Any) (5 children)
  MethodInstance for (::Base.BottomRF{typeof(Base.add_sum)})(::Base._InitialValue, ::Any) (4 children)
   MethodInstance for (::Base.MappingRF{Base.var"#349#350", Base.BottomRF{typeof(Base.add_sum)}})(::Any, ::Any) (0 children)
   MethodInstance for Base.afoldl(::Base.BottomRF{typeof(Base.add_sum)}, ::Base._InitialValue, ::Vararg{Any}) (0 children)
   MethodInstance for Base._foldl_impl(::Base.BottomRF{typeof(Base.add_sum)}, ::Base._InitialValue, ::Tuple) (1 children)
    MethodInstance for Base._foldl_impl(::Base.BottomRF{typeof(Base.add_sum)}, ::Base._InitialValue, ::Tuple) (0 children)

From this, it appears that somewhere there’s a poorly inferred call involving afoldl and one involving Base._foldl_impl. Any suggestions on what to do next to resolve this?

It’s probably missing a forced-specialization, e.g., foo(f, args...) rather than foo(f::F, args...) where F. (function and type args are often despecialized)

1 Like