Skip to content

WIP improve frule inference - #202

Open
aviatesk wants to merge 4 commits into
mainfrom
kf/genericinferencewip
Open

WIP improve frule inference#202
aviatesk wants to merge 4 commits into
mainfrom
kf/genericinferencewip

Conversation

@aviatesk

Copy link
Copy Markdown
Member

@aviatesk
aviateskforce-pushed the kf/genericinferencewip branch from c39a1ce to 607ba18CompareJuly 31, 2023 21:06
Comment threadsrc/stage2/interpreter.jl Outdated
aviatesk added a commit to JuliaLang/julia that referenced this pull request Jul 31, 2023
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

codecovBot commented Jul 31, 2023

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.23077% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.96%. Comparing base (9b2a506) to head (2438a47).
⚠️ Report is 202 commits behind head on main.

Files with missing linesPatch %Lines
src/stage2/interpreter.jl69.23%4 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

aviatesk added a commit to JuliaLang/julia that referenced this pull request Aug 1, 2023
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!`.
aviatesk added a commit to JuliaLang/julia that referenced this pull request Aug 1, 2023
…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!`.
@aviatesk
aviatesk requested a review from CopilotJuly 3, 2026 01:42

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 ADInterpreter with a generic cache and widen current_level to Union{Int,Missing}.
  • Add conditional overloads for CC.InferenceState and CC.update_bestguess! (guarded on CC.update_bestguess! existing) to override bestguess behavior when current_level === missing.
  • Remove an older abstract_call_gf_by_type compatibility overload.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 61 to 63
native_interpreter::NativeInterpreter
current_level::Int
current_level::Union{Int, Missing}
remarks::OffsetVector{RemarksCache}
Comment on lines 73 to 75
#=native_interpreter::NativeInterpreter=#NativeInterpreter(),
#=current_level::Int=#0,
#=remarks::OffsetVector{RemarksCache}=#OffsetVector([RemarksCache()], 0:0))
Comment on lines +58 to +60
# Cache results for forward inference over a converged inference (current_level == missing)
generic::OptCache

Comment on lines +101 to +120
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
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@aviatesk@Keno