-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Julia 1.0/1.1 can't handle deep nested structs #31663
Comments
I did a few more tests, and it looks like Julia is able to construct the value, but it can't print it. Base.show(io::IO, n::AbstractNode) = print(io, "a node") it succeeds:
But my original issue arised from a type that had customized |
Possibly related to #31572? |
Yes. I'm having other side effects beyond printing, related to structs with many type parameters. I'm trying to isolate the problem, but it looks like related to #31572. |
- avoid exponential search in `is_derived_type` when parameters are used as field types - avoid inferring `show_default` - improve a fast path in subtyping
- avoid exponential search in `is_derived_type` when parameters are used as field types - avoid inferring `show_default` - improve a fast path in subtyping
This example exposes the problem regarding other side effects beyond printing: abstract type AbstractNode end
struct Node{N1<:AbstractNode, N2<:AbstractNode} <: AbstractNode
a::N1
b::N2
end
struct Leaf <: AbstractNode
end
function gen_nodes(qty::Integer) :: AbstractNode
@assert qty > 0
result = Leaf()
for i in 1:qty
result = Node(result, Leaf())
end
return result
end
count_leafs(l::Leaf) = 1
count_leafs(n::Node) = count_leafs(n.a) + count_leafs(n.b)
# this function call triggers the problem and does not return
count_leafs(gen_nodes(50)) |
This is great! 8a6271b fixes both the printing and also this new example I came up with. |
Just for the record, With |
FWIW, this usually isn’t an issue for data-structures since trees are usually parameterized on their element type, not the tree size and shape |
@vtjnash, yes, you're right. this only happens on highly parametrized structs. But keep in mind this is a minimal working example of the issue, which is not useful by itself. |
I'm migrating code from v0.6 to v1.0/v1.1 , and I found this issue that breaks Julia.
Running on Julia v1.0 or v1.1, it runs ok for 10 nested elements, but it never finishes if I try to nest about 50 elements. In the example below, I had to use
CTRL+C
to cancel.The same code runs without issues on Julia v0.6, even if I increase to 1000 nested elements.
I would say that this is a major issue for any code that deals with trees or similar data structures.
The text was updated successfully, but these errors were encountered: