ChainRulesCore.jl icon indicating copy to clipboard operation
ChainRulesCore.jl copied to clipboard

Get rid of `MethodError: no method matching iterate(::Nothing)`

Open gdalle opened this issue 2 years ago • 1 comments

This frequent error happens because of the default dispatches

frule(ȧrgs, f, ::Vararg{Any}) = nothing
rrule(::Any, ::Vararg{Any}) = nothing

so when no rrule is defined, nothing is returned. Unfortunately, it is hard to catch because the computations with nothing can go on for a while before erroring.

I wonder if removing these default dispatches would break something badly?

gdalle avatar Sep 29 '23 08:09 gdalle

right now removing them would break Diffractor for sure, which actually uses the isnothing to decide if it is going to recurse. And it would break Zygote that looks at the best matching method is that fallback.

I think a solid case can be made to remove them in 2.0 though. I am sure we can work out a way to detect that case that is better.

oxinabox avatar Sep 29 '23 08:09 oxinabox