-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
inference: implement type-based alias analysis to refine constrained field #41199
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
Conversation
@femtomc you may also want to have a look at this, since I think this PR illustrates how tightly our abstract interpretation logic is bound to the lattice implementation, currently. |
844f692
to
6d92655
Compare
ce85d62
to
d542160
Compare
d542160
to
1bb4a8c
Compare
I may first work on an overhaul of our lattice implementation before going with this. |
Will this fix #39888 ? |
It will, assuming |
1bb4a8c
to
700d921
Compare
700d921
to
7c8df8e
Compare
0026bf1
to
fce4a96
Compare
90a0a5e
to
b941345
Compare
f959acd
to
fe5a54a
Compare
#41199 implements the base logic of type-based alias analysis with new lattice element `MustAlias`, but doesn't enable it for `NativeInterpreter`. This PR enables it for our native code execution pipeline, checking its performance impact.
That's fantastic! ❤️ The failure propagate type info to duplicate field loads is indeed one of the main contributors for false positives in JET. |
fe5a54a
to
6ac900c
Compare
#41199 implements the base logic of type-based alias analysis with new lattice element `MustAlias`, but doesn't enable it for `NativeInterpreter`. This PR enables it for our native code execution pipeline, checking its performance impact.
@nanosoldier |
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. |
6ac900c
to
374b3f1
Compare
@nanosoldier |
#41199 implements the base logic of type-based alias analysis with new lattice element `MustAlias`, but doesn't enable it for `NativeInterpreter`. This PR enables it for our native code execution pipeline, checking its performance impact.
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. |
Yay! This PR introduces some complicated logic into inference, nevertheless it finally comes without any performance cost (actually it even makes it slightly faster)! This should be ready to go, so I'm planning to merge this. |
Do you want to do a joint-review tomorrow, or are you content with it as-is for merging? |
I'm almost certain that this can be merged as-is (since I confirmed e.g. this PR runs successfully if we enable |
Looks like this needs a manual (command-line) rebase. |
…field This commit tries to propagate constraints imposed on object fields, e.g.: ```julia struct SomeX{T} x::Union{Nothing,T} end mutable struct MutableSomeX{T} const x::Union{Nothing,T} end let # o1::SomeX{T}, o2::MutableSomeX{T} if !isnothing(o1.x) # now inference knows `o1.x::T` here ... if !isnothing(o2.x) # now inference knows `o2.x::T` here ... end end end ``` The idea is that we can make `isa` and `===` propagate constraint imposed on an object field if the _identity_ of that object. We can have such a lattice element that wraps return type of abstract `getfield` call together with the object _identity_, and then we can form a conditional constraint that propagates the refinement information imposed on the object field when we see `isa`/`===` applied the return value of the preceding `getfield` call. So this PR defines the new lattice element called `MustAlias` (and also `InterMustAlias`, which just works in a similar way to `InterConditional`), which may be formed upon `getfield` inference to hold the retrieved type of the field and track the _identity_ of the object (in inference, "object identity" can be represented as a `SlotNumber`). This PR also implements the new logic in `abstract_call_builtin` so that `isa` and `===` can form a conditional constraint (i.e. `Conditional`) from `MustAlias`-argument that may later refine the wrapped object to `PartialStruct` that holds the refined field type information. One important note here is, `MustAlias` expects the invariant that the field of wrapped slot object never changes. The obvious limitation with this invariant is that it can't propagate constraints imposed on mutable fields, because inference currently doesn't have a precise (per-object) knowledge of memory effect.
374b3f1
to
a1fa7e3
Compare
#41199 implements the base logic of type-based alias analysis with new lattice element `MustAlias`, but doesn't enable it for `NativeInterpreter`. This PR enables it for our native code execution pipeline, checking its performance impact.
@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. |
#41199 implements the base logic of type-based alias analysis with new lattice element `MustAlias`, but doesn't enable it for `NativeInterpreter`. This PR enables it for our native code execution pipeline, checking its performance impact.
#41199 implements the base logic of type-based alias analysis with new lattice element `MustAlias`, but doesn't enable it for `NativeInterpreter`. This PR enables it for our native code execution pipeline, checking its performance impact.
This commit tries to propagate constraints imposed on object fields, e.g.:
The idea is that we can make
isa
and===
propagate constraintimposed on an object field if the identity of that object.
We can have such a lattice element that wraps return type of abstract
getfield
call together with the object identity, and then we canform a conditional constraint that propagates the refinement information
imposed on the object field when we see
isa
/===
applied the returnvalue of the preceding
getfield
call.So this PR defines the new lattice element called
MustAlias
(and alsoInterMustAlias
, which just works in a similar way toInterConditional
),which may be formed upon
getfield
inference to hold the retrieved typeof the field and track the identity of the object (in inference,
"object identity" can be represented as a
SlotNumber
).This PR also implements the new logic in
abstract_call_builtin
so thatisa
and===
can form a conditional constraint (i.e.Conditional
)from
MustAlias
-argument that may later refine the wrapped object toPartialStruct
that holds the refined field type information.One important note here is,
MustAlias
expects the invariant that thefield of wrapped slot object never changes. The obvious limitation with
this invariant is that it can't propagate constraints imposed on mutable
fields, because inference currently doesn't have a precise (per-object)
knowledge of memory effect.