@@ -438,11 +438,6 @@ function rrule(
438438 return z, mapfoldl_pullback_tuple
439439end
440440
441- function rrule (:: RuleConfig{>:HasReverseMode} , :: typeof (mapfoldl_impl), f, op, init, x:: Tuple{} )
442- foldl_pullback_empty (dy) = (NoTangent (), NoTangent (), NoTangent (), dy, NoTangent ())
443- return init, foldl_pullback_empty
444- end
445-
446441# ####
447442# #### `foldl(f, ::Tuple)`
448443# ####
@@ -491,6 +486,10 @@ function rrule(
491486 init,
492487 x:: Tuple ;
493488 ) where {G}
489+ # Trivial case handled here to avoid ambiguities (and necc. because of Base.tail below)
490+ foldl_pullback_empty (dy) = (NoTangent (), NoTangent (), NoTangent (), dy, NoTangent ())
491+ isempty (x) && return init, foldl_pullback_empty
492+
494493 # Treat `init` by simply appending it to the `x`:
495494 y, back = rrule (config, Base. mapfoldl_impl, identity, op, Base. _InitialValue (), (init, x... ))
496495 project_x = ProjectTo (x)
@@ -502,12 +501,6 @@ function rrule(
502501 return y, foldl_pullback_tuple_init
503502end
504503
505- # Base.tail doesn't work on (), trivial case:
506- function rrule (:: RuleConfig{>:HasReverseMode} , :: typeof (mapfoldl_impl), :: typeof (identity), op, init, x:: Tuple{} )
507- foldl_pullback_empty (dy) = (NoTangent (), NoTangent (), NoTangent (), dy, NoTangent ())
508- return init, foldl_pullback_empty
509- end
510-
511504# ####
512505# #### `foldl(f, ::Array)`
513506# ####
0 commit comments