Uh oh!
There was an error while loading. Please reload this page.
WIP improve frule inference - #202
Conversation
c39a1ce to
607ba18CompareUh oh!
There was an error while loading. Please reload this page.
Currently, the code that updates `bestguess` using `ReturnNode` information includes hardcodes that relate to `Conditional` and `LimitedAccuracy`. These behaviors are actually lattice-dependent and therefore should be overloadable by `AbstractInterpreter`. Additionally, particularly in Diffractor, a clever strategy is required to update return types in a way that it takes into account information from both the original method and its rule method (xref: JuliaDiff/Diffractor.jl#202). This also requires such an overload to exist. In response to these needs, this commit introduces an implementation of a hook named `update_bestguess!`.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@## main #202 +/- ##
==========================================
- Coverage 55.01% 54.96% -0.06%
==========================================
Files 28 28 Lines 2790 2800 +10 ==========================================
+ Hits 1535 1539 +4 - Misses 1255 1261 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Currently, the code that updates `bestguess` using `ReturnNode` information includes hardcodes that relate to `Conditional` and `LimitedAccuracy`. These behaviors are actually lattice-dependent and therefore should be overloadable by `AbstractInterpreter`. Additionally, particularly in Diffractor, a clever strategy is required to update return types in a way that it takes into account information from both the original method and its rule method (xref: JuliaDiff/Diffractor.jl#202). This also requires such an overload to exist. In response to these needs, this commit introduces an implementation of a hook named `update_bestguess!`.
…50744) Currently, the code that updates `bestguess` using `ReturnNode` information includes hardcodes that relate to `Conditional` and `LimitedAccuracy`. These behaviors are actually lattice-dependent and therefore should be overloadable by `AbstractInterpreter`. Additionally, particularly in Diffractor, a clever strategy is required to update return types in a way that it takes into account information from both the original method and its rule method (xref: JuliaDiff/Diffractor.jl#202). This also requires such an overload to exist. In response to these needs, this commit introduces an implementation of a hook named `update_bestguess!`.
There was a problem hiding this comment.
Pull request overview
Updates ADInterpreter to support an alternate “generic inference” mode intended to work with Julia’s bestguess-overload branch by allowing a converged-inference pathway (current_level === missing) and hooking into Core.Compiler’s bestguess initialization/update points.
Changes:
- Extend
ADInterpreterwith agenericcache and widencurrent_leveltoUnion{Int,Missing}. - Add conditional overloads for
CC.InferenceStateandCC.update_bestguess!(guarded onCC.update_bestguess!existing) to override bestguess behavior whencurrent_level === missing. - Remove an older
abstract_call_gf_by_typecompatibility overload.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| native_interpreter::NativeInterpreter | ||
| current_level::Int | ||
| current_level::Union{Int, Missing} | ||
| remarks::OffsetVector{RemarksCache} |
| #=native_interpreter::NativeInterpreter=#NativeInterpreter(), | ||
| #=current_level::Int=#0, | ||
| #=remarks::OffsetVector{RemarksCache}=#OffsetVector([RemarksCache()], 0:0)) |
| # Cache results for forward inference over a converged inference (current_level == missing) | ||
| generic::OptCache | ||
| function CC.InferenceState(result::InferenceResult, cache::Symbol, interp::ADInterpreter) | ||
| sv = @invoke CC.InferenceState(result::InferenceResult, cache::Symbol, interp::AbstractInterpreter) | ||
| sv === nothing && return sv | ||
| if interp.current_level === missing | ||
| # override initial bestguess | ||
| arginfo = ArgInfo(nothing, result.argtypes) | ||
| si = StmtInfo(false) | ||
| sv.bestguess = CC.abstract_call(interp.native_interpreter, arginfo, si, sv).rt | ||
| end | ||
| return sv | ||
| end | ||
| function CC.update_bestguess!(interp::ADInterpreter, frame::InferenceState, | ||
| currstate::CC.VarTable, @nospecialize(rt)) | ||
| if interp.current_level === missing | ||
| rt = CC.getfield_tfunc(rt, Const(1)) | ||
| end | ||
| return @invoke CC.update_bestguess!(interp::AbstractInterpreter, frame::InferenceState, | ||
| currstate::CC.VarTable, rt::Any) | ||
| end |
Supposed to work with https://github.com/JuliaLang/julia/tree/avi/bestguess-overload.