where the type variable _A Julia couldn't infer (or chose to ignore?) is the inner result type (which is again a PrivateState here).
Confusingly, inferring Transducers.wrapping by (1) using @descend or by (2) running @code_warntype on next which in turn calls wrapping as below says it actually is inferrable:
using Transducers: next
@code_warntype next(rf, state, 1)
showingerror() do
@inferred next(rf, state, 1)
end
return type Transducers.PrivateState{Transducers.Reduction{Transducers.Scan{typeof(+),Initials.InitialOf{typeof(+)}},Transducers.Reduction{Transducers.Scan{typeof(+),Initials.InitialOf{typeof(+)}},Transducers.BottomRF{Transducers.NOTYPE,typeof(*)},Transducers.NOTYPE},Transducers.NOTYPE},Int64,Transducers.PrivateState{Transducers.Reduction{Transducers.Scan{typeof(+),Initials.InitialOf{typeof(+)}},Transducers.BottomRF{Transducers.NOTYPE,typeof(*)},Transducers.NOTYPE},Int64,Int64}} does not match inferred return type Union{Transducers.PrivateState{Transducers.Reduction{Transducers.Scan{typeof(+),Initials.InitialOf{typeof(+)}},Transducers.Reduction{Transducers.Scan{typeof(+),Initials.InitialOf{typeof(+)}},Transducers.BottomRF{Transducers.NOTYPE,typeof(*)},Transducers.NOTYPE},Transducers.NOTYPE},Int64,_A} where _A, Transducers.Reduced}
Maybe there is some threshold in the inference which stops trying to run on nested calls when the argument is too complex or something?
This post is generated from this script: https://gist.github.com/85a0751820f2be4a6aaa707959e7cd96
Examples
Currently, nested
Scan
cannot be inferred (in most of the cases):Specifying initial value (
init=1
) does not help:Side note: In some REPL sessions, following actually could be inferred. But now I can't reproduce this...
Looking into the Julia IR
Using
@descend foldl(*, Scan(+) |> Scan(+), 1:1)
, it looks like the inference of the first example failed inThe first type instability occurs at
which is inferred to return
where the type variable
_A
Julia couldn't infer (or chose to ignore?) is the inner result type (which is again aPrivateState
here).Confusingly, inferring
Transducers.wrapping
by (1) using@descend
or by (2) running@code_warntype
onnext
which in turn callswrapping
as below says it actually is inferrable:More confusingly,
@inferred
reports the result as in%62
above (similar report: https://discourse.julialang.org/t/24998)Maybe there is some threshold in the inference which stops trying to run on nested calls when the argument is too complex or something?
Version information
Julia
Transducers
This page was generated using Literate.jl.