-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
inference: track reaching defs for slots #55601
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
base: master
Are you sure you want to change the base?
Conversation
0879cc3
to
5ffbc97
Compare
5ffbc97
to
abf839b
Compare
This change effectively computes the SSA / ϕ-nodes for program slots as part of type-inference, using the "path-convergence criterion" for SSA. This allows us to conveniently reason about slot identity (in typical SSA fashion) without having to quadratically expand all of our SSA type state over the CFG.
Another change will probably be needed to make sure that `MustAlias` itself is invalidated by `.defssa`, but this is enough to make sure that any Conditional derived from MustAlias works correctly.
4829608
to
e60a5ee
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks much better than my PR in general.
Still I would like to add the test case from it, i.e.
# JuliaLang/julia#55548: invalidate stale slot wrapper types in `ssavaluetypes`
_issue55548_proj1(a, b) = a
function issue55548(a)
a = Base.inferencebarrier(a)::Union{Int64,Float64}
if _issue55548_proj1(isa(a, Int64), (a = Base.inferencebarrier(1.0)::Union{Int64,Float64}; true))
return a
end
return 2
end
@test Float64 <: Base.infer_return_type(issue55548, (Int,))
@nanosoldier |
Thanks for the test case and review @aviatesk fwiw, there's also a precision regression that I encountered w/ this PR: function foo()
value = @noinline rand((true, false, 1))
is_bool = value isa Bool
if inferencebarrier(@noinline rand(Bool))
value = 1.0
is_bool = false
end
# at this merge point, only the "false half" of the Conditional should be invalidated
return is_bool ? value : false
end
@assert only(Base.return_types(foo, ())) === Bool # fails w/ PR but I think this can be mostly fixed by widening the |
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. |
bump? are we able to land this and backport to v1.11/v1.10? |
df333d8
to
e614050
Compare
As discussed with @topolarity, I will take over this PR and finish it so we can have a fix for the underlying issue. It seems like most of the core functionality works well at the moment, so I believe it's mostly a matter of finishing up the design and related refactors, and address performance regressions. |
@nanosoldier |
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. |
@nanosoldier |
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. |
@nanosoldier |
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. |
This PR implements the "Path-Convergence Criterion" for SSA / ϕ-nodes as part of type-inference.
The
VarState.ssadef
field corresponds to the "reaching definition" of the slot in SSA form, which allows us to conveniently reason about the identity of aslot
across multiple program points. If the reaching def is equal at two program points, then the slot contents are guaranteed to be egal (i.e.x₀ === x₁
)Tasks:
StateRefinement
change to separate PRVarTable
plumbing to separate PRConditional
invalidation logicFixes #55548 (alternative to #55551), by having
Conditional
remember the reaching definition that it narrows.