-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
inference: implement type-based alias analysis to refine constrained …
…field (#41199) 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 biggest 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.
- Loading branch information
Showing
17 changed files
with
901 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.