-
-
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
Type inference optimize hang on master: generator stuck perform_lifting / simple_walk #51694
Comments
I infiltrated into ...
│ %276775 = φ (#2857 => %275943)::Int64 ││││││││││││
│ %276776 = φ (#2857 => %275674)::Int64 ││││││││││││
│ %276777 = φ (#2857 => %275741)::Int64 ││││││││││││
│ %276778 = φ (#2857 => %275742)::Int64 ││││││││││││
│ %276779 = φ (#2857 => %275745)::Vector{Shape} ││││││││││││
│ %276780 = φ (#2857 => %275746)::Vector{Shape} ││││││││││││
│ %276781 = φ (#2857 => %275750)::Vector{Shape} ││││││││││││
│ %276782 = φ (#2857 => %275756)::Vector{Shape} ││││││││││││
│ %276783 = φ (#2857 => %275748)::Vector{Shape} ││││││││││││
│ %276784 = φ (#2857 => %275751)::Vector{Shape} ││││││││││││
│ %276785 = φ (#2857 => %275752)::Vector{Shape} ││││││││││││
│ %276786 = φ (#2857 => %275754)::Vector{Shape} ││││││││││││
│ %276787 = φ (#2857 => %275747)::Vector{Shape} ││││││││││││
│ %276788 = φ (#2857 => %275749)::Vector{Shape} ││││││││││││
│ %276789 = φ (#2857 => %275757)::Vector{Shape} ││││││││││││
│ %276790 = φ (#2857 => %275755)::Vector{Shape} ││││││││││││
│ %276791 = φ (#2857 => %275753)::Vector{Shape} ││││││││││││
│ %276792 = φ (#2857 => %275759)::Vector{Shape} ││││││││││││
│ %276793 = φ (#2857 => %275758)::Vector{Shape} ││││││││││││
│ %276794 = φ (#2857 => %275760)::Vector{Shape} ││││││││││││
│ %276795 = φ (#2857 => %275761)::Base.Generator{Vector{Shape}, typeof(identity)} ││││││││││││
... From what I've observed, |
So is the issue in whatever is producing the massive IR in the first place? Something earlier in the set of passes? |
Indeed, but the issue might lie with |
Reduced this further a bit: abstract type Shape end
struct ShapeUnion <: Shape
args::Vector{Shape}
end
# WEIRDLY, this also reproduces if shape_disjuncts is not defined!
function shape_disjuncts end
shape_disjuncts(s::ShapeUnion) = s.args
shape_disjuncts(s::Shape) = Shape[s]
# ^ (You can try commenting out the above three lines to produce another hang as well).
function shape_union(::Type{Shape}, args)
return _union(args)
end
function _union(args)
if any(arg -> arg isa ShapeUnion, args)
# Call the entry point rather than `_union_vec_no_union` because we are uncertain
# about the size and because there might be some optimization opportunity.
return shape_union(Shape, (disj for arg in args for disj in shape_disjuncts(arg)))
end
return args
end
# Reproduction:
#=
julia> code_typed(
_union,
(Vector{Shape},),
)
=# |
It doesn't look like it's just an issue with the optimization pass. I've seen the problem pop up even with optimization totally switched off. I'm thinking it's probably because of the infinite abstract interpretation rather than optimizer producing massive IRsーthe massive IR might be a result of inlining of endless inference cycle: include("test/compiler/newinterp.jl")
@newinterp CompilerDebugger
CC.may_optimize(::CompilerDebugger) = false
code_typed(_union, (Vector{Shape},); interp=CompilerDebugger()) # issue persists |
Ah, that make sense. Flatten is alphabetically before Generator, so it results in endless inference. That seems like an easy fix now |
It seems this case has already been fixed by other improvements, so we no longer need this hack, which is now causing problems. Fixes #51694
Nice! |
It seems this case has already been fixed by other improvements, so we no longer need this hack, which is now causing problems. Fixes #51694
It seems this case has already been fixed by other improvements, so we no longer need this hack, which is now causing problems. Fixes #51694
Awesome! Thanks guys! Great to see the fix land here :) |
Okay, we have a standalone isolated MRE for the hang on master!
This reliably hangs _on master (but not on julia 1.10). So I'm breaking this out from #51603, into a separate issue, since this is something separate.
I don't think we could have gotten this without @vtjnash walking us through some very gnarly hackery to find which function was stuck in inference (including reading some pointers off of registers and some manual pointer arithmetic and memory reads).
One of my takeaways here is that it would be nice to be able to set some kind of "debug mode" flag to have julia log which function it's inferring before it starts and stops inference / optimization, so that we could have found where it was stuck much more easily. Once we found that, isolating an MRE wasn't too hard.
@aviatesk and @vtjnash: Please try to reproduce the hang from this, and see if you can work out the issue from there!
Once you find the culprit, can you also give a time estimate to fix it? I do still think that if it will take more than a couple days, we should start by reverting the culprits so that main can be unbroken until we land the fix.
Originally posted by @NHDaly in #51603 (comment)
Pausing it after long enough, gives this stack trace:
The text was updated successfully, but these errors were encountered: