Skip to content
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

inference: refactoring to allow irinterp to perform :call inference #48913

Merged
merged 1 commit into from
Apr 4, 2023

Conversation

aviatesk
Copy link
Member

@aviatesk aviatesk commented Mar 6, 2023

This commit implements a significant refactoring of the inference routines,
which is necessary to enable :call inference in irinterp. While this
commit does not yet enable :call inference, a subsequent small commit
will do so. This is because external AbstractInterpreters first need
to adjust their code for this refactoring, and in the event of a
regression detected by the recursive :call inference, we will be able
to simply revert the small commit.

Additionally, this commit improves the robustness of irinterp by
allowing it to handle invoke calls, which currently result in a crash.

TODOs:

  • implement a simple recursion detection mechanism for IRInterpretationState
  • add proper invalidation support
  • allow constant inference from semi-concrete interpretation
  • propagate callinfo and allow double inlining

@aviatesk aviatesk added compiler:inference Type inference DO NOT MERGE Do not merge this PR! labels Mar 6, 2023
@aviatesk aviatesk changed the title very wip: inference: allow semi-concrete interpret to perform recursi… very wip: inference: allow semi-concrete interpret to perform recursive inference Mar 6, 2023
aviatesk added a commit that referenced this pull request Mar 7, 2023
- remove `update_valid_age!(edge::InferenceState, sv::InferenceState)`
  and replace all the usages with `update_valid_age!(sv, edge.valid_worlds)`:
  this will simplify the incoming `AbsIntState` interface (see #48913)
- remove `Effects(sv::InferenceState)` utility: replace all the usages
  with `sv.ipo_effects`, which is more explictly saying that we are
  looking at IPO-valid effects
- normalize more `li::MethodInstance` to `mi::MethodInstance`
- import `Core.MethodTable`
- fix up `setindex!` return values
@aviatesk aviatesk force-pushed the avi/irsv branch 2 times, most recently from 56bea36 to 1010057 Compare March 7, 2023 17:36
aviatesk added a commit that referenced this pull request Mar 8, 2023
- remove `update_valid_age!(edge::InferenceState, sv::InferenceState)`
  and replace all the usages with `update_valid_age!(sv, edge.valid_worlds)`:
  this will simplify the incoming `AbsIntState` interface (see #48913)
- remove `Effects(sv::InferenceState)` utility: replace all the usages
  with `sv.ipo_effects`, which is more explictly saying that we are
  looking at IPO-valid effects
- normalize more `li::MethodInstance` to `mi::MethodInstance`
- import `Core.MethodTable`
- fix up `setindex!` return values
@aviatesk aviatesk force-pushed the avi/irsv branch 4 times, most recently from a4d3be7 to 513c5e6 Compare March 8, 2023 10:56
@aviatesk aviatesk changed the title very wip: inference: allow semi-concrete interpret to perform recursive inference wip: inference: allow semi-concrete interpret to perform recursive inference Mar 8, 2023
@aviatesk aviatesk force-pushed the avi/irsv branch 2 times, most recently from c01f6cc to 4f0d57f Compare March 8, 2023 16:10
@aviatesk aviatesk force-pushed the avi/irsv branch 3 times, most recently from 965c082 to 53809c6 Compare March 12, 2023 09:40
@aviatesk
Copy link
Member Author

I am still working on item 1, which is to implement a proper recursion detection support for irinterp. I am currently wondering if a simple recursion detection mechanism is sufficient, as the existing recursion detection mechanism with InferenceState may be overkill for irinterp, given that we only perform irinterp on methods that are proven to be :terminates, indicating that there is no heavy recursion (unless specified by user annotation). Additionally, I am also considering whether we should implement the LimitedAccuracy-related system for irinterp. Any thoughts on this?

@Keno
Copy link
Member

Keno commented Mar 14, 2023

I'm not sure. :terminates is a pretty strong condition, so in theory it should probably be ok, but I'm not sure I'm comfortable saying that it can't happen. However, if it does happen, we probably have the same issue right now without this change, so if you want to finish this up and keep working on the termination change separately I think that would be ok as long as nothing shows up on pkgeval. I do think it would be good to eventually relax the :terminates requirement, for which strong recursion detection would be required, but that can be separate.

@aviatesk aviatesk changed the title wip: inference: allow semi-concrete interpret to perform recursive inference inference: allow semi-concrete interpret to perform recursive inference Mar 16, 2023
@aviatesk
Copy link
Member Author

aviatesk commented Mar 16, 2023

Okay, now I think this PR is ready. I also tweaked miscellaneous inference subroutines like abstract_invoke so that they are reused during irinterp. Now irinterp should be more robust.

@nanosoldier runtests(ALL, vs = ":master")

@aviatesk aviatesk removed the DO NOT MERGE Do not merge this PR! label Mar 16, 2023
@aviatesk
Copy link
Member Author

@nanosoldier runbenchmarks("inference", vs=":master")

aviatesk added a commit to JuliaDebug/Cthulhu.jl that referenced this pull request Mar 30, 2023
@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here.

Copy link
Member

@Keno Keno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for splitting this up.

aviatesk added a commit to aviatesk/JET.jl that referenced this pull request Mar 31, 2023
This commit implements a significant refactoring of the inference routines,
which is necessary to enable `:call` inference in irinterp. While this
commit does not yet enable `:call` inference, a subsequent small commit
will do so. This is because external `AbstractInterpreter`s first need
to adjust their code for this refactoring, and in the event of a
regression detected by the recursive `:call` inference, we will be able
to simply revert the small commit.

Additionally, this commit improves the robustness of irinterp by
allowing it to handle invoke calls, which currently result in a crash.

TODOs:
- [x] implement a simple recursion detection mechanism for `IRInterpretationState`
- [x] add proper invalidation support
- [x] allow constant inference from semi-concrete interpretation
- [x] propagate callinfo and allow double inlining
aviatesk added a commit that referenced this pull request Apr 3, 2023
Built on top of #48913, this commit enables `:call` inference in irinterp.
In a case when some regression is detected, we can simply revert this
commit rather than reverting the whole refactoring from #48913.
@aviatesk
Copy link
Member Author

aviatesk commented Apr 3, 2023

@nanosoldier runtests()

@staticfloat
Copy link
Member

Nanosoldier is down, but we don't expect this to change performance that much (yet); it's the follow-on PR that will have significant impact.

@staticfloat staticfloat merged commit 2ec27e9 into master Apr 4, 2023
@staticfloat staticfloat deleted the avi/irsv branch April 4, 2023 00:09
aviatesk added a commit that referenced this pull request Apr 4, 2023
Built on top of #48913, this commit enables `:call` inference in irinterp.
In a case when some regression is detected, we can simply revert this
commit rather than reverting the whole refactoring from #48913.
aviatesk added a commit to JuliaDebug/Cthulhu.jl that referenced this pull request Apr 4, 2023
aviatesk added a commit to JuliaDiff/Diffractor.jl that referenced this pull request Apr 5, 2023
@vtjnash
Copy link
Member

vtjnash commented Apr 5, 2023

Nanosoldier is not affected by the PkgEval outage

aviatesk added a commit to JuliaDiff/Diffractor.jl that referenced this pull request Apr 6, 2023
aviatesk added a commit that referenced this pull request Apr 10, 2023
Built on top of #48913, this commit enables `:call` inference in irinterp.
In a case when some regression is detected, we can simply revert this
commit rather than reverting the whole refactoring from #48913.
aviatesk added a commit that referenced this pull request Apr 10, 2023
Built on top of #48913, this commit enables `:call` inference in irinterp.
In a case when some regression is detected, we can simply revert this
commit rather than reverting the whole refactoring from #48913.
Xnartharax pushed a commit to Xnartharax/julia that referenced this pull request Apr 19, 2023
- remove `update_valid_age!(edge::InferenceState, sv::InferenceState)`
  and replace all the usages with `update_valid_age!(sv, edge.valid_worlds)`:
  this will simplify the incoming `AbsIntState` interface (see JuliaLang#48913)
- remove `Effects(sv::InferenceState)` utility: replace all the usages
  with `sv.ipo_effects`, which is more explictly saying that we are
  looking at IPO-valid effects
- normalize more `li::MethodInstance` to `mi::MethodInstance`
- import `Core.MethodTable`
- fix up `setindex!` return values
aviatesk added a commit that referenced this pull request Apr 28, 2023
Built on top of #48913, this commit enables `:call` inference in irinterp.
In a case when some regression is detected, we can simply revert this
commit rather than reverting the whole refactoring from #48913.
aviatesk added a commit that referenced this pull request Apr 28, 2023
Built on top of #48913, this commit enables `:call` inference in irinterp.
In a case when some regression is detected, we can simply revert this
commit rather than reverting the whole refactoring from #48913.
aviatesk added a commit that referenced this pull request Apr 29, 2023
Built on top of #48913, this commit enables `:call` inference in irinterp.
In a case when some regression is detected, we can simply revert this
commit rather than reverting the whole refactoring from #48913.
aviatesk added a commit that referenced this pull request May 4, 2023
Built on top of #48913, this commit enables `:call` inference in irinterp.
In a case when some regression is detected, we can simply revert this
commit rather than reverting the whole refactoring from #48913.
aviatesk added a commit that referenced this pull request May 4, 2023
* inference: enable `:call` inference in irinterp

Built on top of #48913, this commit enables `:call` inference in irinterp.
In a case when some regression is detected, we can simply revert this
commit rather than reverting the whole refactoring from #48913.

* fix irinterp lattice

Now `LimitedAccuracy` can appear in irinterp, so we should include
`InferenceLattice` for `[typeinf|ipo]_lattice` for irinterp.
oscardssmith pushed a commit that referenced this pull request Aug 5, 2024
If the LimitedAccuracy was supposed to resolve against the top-most
frame (or hypothetically a non-InferenceState frame), it would not have
a parentframe, preventing it from reaching the subsequent
poison_callstack line that is required for reliable inference (avoiding
caching bad results). This should restore the original intent of this
code (pre #48913)
KristofferC pushed a commit that referenced this pull request Aug 8, 2024
If the LimitedAccuracy was supposed to resolve against the top-most
frame (or hypothetically a non-InferenceState frame), it would not have
a parentframe, preventing it from reaching the subsequent
poison_callstack line that is required for reliable inference (avoiding
caching bad results). This should restore the original intent of this
code (pre #48913)

(cherry picked from commit d1b1a5d)
lazarusA pushed a commit to lazarusA/julia that referenced this pull request Aug 17, 2024
If the LimitedAccuracy was supposed to resolve against the top-most
frame (or hypothetically a non-InferenceState frame), it would not have
a parentframe, preventing it from reaching the subsequent
poison_callstack line that is required for reliable inference (avoiding
caching bad results). This should restore the original intent of this
code (pre JuliaLang#48913)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:inference Type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants