Skip to content

collecting a tree iterator is horribly type unstable, with lots of run time dispatch, even when the element type is provided explicitly #158

@nsajko

Description

@nsajko
using JET, AbstractTrees
struct S
    c::Int
end
function AbstractTrees.children(s::S)
    c = s.c
    Iterators.map(Returns(S(c - 1)), Base.OneTo(c))
end
it = Leaves(S(3))
@report_opt collect(S, it)  # ═════ 15 possible errors found ═════
it = PreOrderDFS(S(3))
@report_opt collect(S, it)  # ═════ 9 possible errors found ═════
it = PostOrderDFS(S(3))
@report_opt collect(S, it)  # ═════ 16 possible errors found ═════

For comparison, Base.Generator collects fine without run time dispatch:

using JET
struct S
    c::Int
end
it = Iterators.map(S, 1:5)
@report_opt collect(S, it)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions