-
-
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
Recursion disables constant propagation #39915
Comments
This looks odd to me: julia> @code_typed constant_select((1, 1.0, "a", :a))
CodeInfo(
1 ─ %1 = Core.getfield(a_tuple, 3)::String
│ %2 = Core.getfield(a_tuple, 4)::Symbol
└── goto #3 if not false
2 ─ %4 = Core.tuple(%2)::Tuple{Symbol}
└── goto #4
3 ─ goto #4
4 ┄ %7 = φ (#2 => %4, #3 => ())::Union{Tuple{}, Tuple{Symbol}}
└── goto #6 if not true
5 ─ %9 = Core.tuple(%1)::Tuple{String}
│ %10 = Core._apply_iterate(Base.iterate, Core.tuple, %9, %7)::Union{Tuple{String}, Tuple{String, Symbol}}
└── goto #7
6 ─ goto #7
7 ┄ %13 = φ (#5 => %10, #6 => %7)::Tuple
└── goto #8
8 ─ %15 = Base.getfield(a_tuple, 1, true)::Int64
│ %16 = Core.tuple(%15)::Tuple{Int64}
│ %17 = Core._apply_iterate(Base.iterate, Core.tuple, %16, %13)::Tuple{Int64, Vararg{Any}}
└── goto #9
9 ─ return %17
) => Tuple{Int64, Vararg{Any}} Shouldn't we be able to just eliminate block |
Well, fixing it is easy, you just need to delete the That said, I'm thinking we could maybe improve the condition there to not be quite as strict. Let me play with it. |
Inlining can often discover information that inference doesn't have access to, particularly in cases involving recursion, because we aggressively limit inference's exploration to avoid blowing up compile times. To investigate issues like this, one needs to look at unoptimized IR. In the near future, Cthulhu will display inference remarks to tell the user why it bailed. In this case it would have said: |
At the moment, we restrict const prop whenever we see a cycle in methods being called. However, I think this condition can be relaxed slightly: In particular, if the type complexity limiting did not decide to limit the growth of the type in question, I think it should be fine to constant prop as long as there is no cycle in *method instances* (rather than just methods). Fixes #39915
At the moment, we restrict const prop whenever we see a cycle in methods being called. However, I think this condition can be relaxed slightly: In particular, if the type complexity limiting did not decide to limit the growth of the type in question, I think it should be fine to constant prop as long as there is no cycle in *method instances* (rather than just methods). Fixes #39915
At the moment, we restrict const prop whenever we see a cycle in methods being called. However, I think this condition can be relaxed slightly: In particular, if the type complexity limiting did not decide to limit the growth of the type in question, I think it should be fine to constant prop as long as there is no cycle in *method instances* (rather than just methods). Fixes JuliaLang#39915, replaces JuliaLang#39918 Co-Authored-By: Keno Fisher <[email protected]>
At the moment, we restrict const prop whenever we see a cycle in methods being called. However, I think this condition can be relaxed slightly: In particular, if the type complexity limiting did not decide to limit the growth of the type in question, I think it should be fine to constant prop as long as there is no cycle in *method instances* (rather than just methods). Fixes JuliaLang#39915, replaces JuliaLang#39918 Co-Authored-By: Keno Fisher <[email protected]>
At the moment, we restrict const prop whenever we see a cycle in methods being called. However, I think this condition can be relaxed slightly: In particular, if the type complexity limiting did not decide to limit the growth of the type in question, I think it should be fine to constant prop as long as there is no cycle in *method instances* (rather than just methods). Fixes JuliaLang#39915, replaces JuliaLang#39918 Co-Authored-By: Keno Fisher <[email protected]>
At the moment, we restrict const prop whenever we see a cycle in methods being called. However, I think this condition can be relaxed slightly: In particular, if the type complexity limiting did not decide to limit the growth of the type in question, I think it should be fine to constant prop as long as there is no cycle in *method instances* (rather than just methods). Fixes JuliaLang#39915, replaces JuliaLang#39918 Co-Authored-By: Keno Fisher <[email protected]>
At the moment, we restrict const prop whenever we see a cycle in methods being called. However, I think this condition can be relaxed slightly: In particular, if the type complexity limiting did not decide to limit the growth of the type in question, I think it should be fine to constant prop as long as there is no cycle in *method instances* (rather than just methods). Fixes #39915, replaces #39918 Co-authored-by: Keno Fisher <[email protected]>
Woohoo! |
At the moment, we restrict const prop whenever we see a cycle in methods being called. However, I think this condition can be relaxed slightly: In particular, if the type complexity limiting did not decide to limit the growth of the type in question, I think it should be fine to constant prop as long as there is no cycle in *method instances* (rather than just methods). Fixes JuliaLang#39915, replaces JuliaLang#39918 Co-authored-by: Keno Fisher <[email protected]>
At the moment, we restrict const prop whenever we see a cycle in methods being called. However, I think this condition can be relaxed slightly: In particular, if the type complexity limiting did not decide to limit the growth of the type in question, I think it should be fine to constant prop as long as there is no cycle in *method instances* (rather than just methods). Fixes JuliaLang#39915, replaces JuliaLang#39918 Co-authored-by: Keno Fisher <[email protected]>
So, this is a very annoying problem, and one that people don't seem to really know about. It's best demonstrated by example:
My naive understanding of what's going on is that when Julia recurs into
my_getindex
, the compiler detects thatwhich_ones
is still a tuple of Bools (just a smaller one), figures out that we are recurring, and bails on constant propagation.I've always gotten the impression that this is an unfixable problem, but...if it's fixable, that would be super cool.
The text was updated successfully, but these errors were encountered: