-
Notifications
You must be signed in to change notification settings - Fork 51
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
Method overrides using a method overlay table. #122
Conversation
Even cleaner using a MethodTableView: struct OverlayMethodTable <: Core.Compiler.MethodTableView
inner::Core.Compiler.MethodTableView
end
Core.Compiler.method_table(interp::GPUInterpreter, sv::InferenceState) = OverlayMethodTable(sv.method_table)
function Core.Compiler.findall(@nospecialize(sig::Type{<:Tuple}), table::OverlayMethodTable; limit::Int=typemax(Int))
ft = first(sig.parameters)
tt = Tuple{sig.parameters[2:end]...}
if haskey(CI_CACHE.overrides, ft.instance)
for f in CI_CACHE.overrides[ft.instance]
hasmethod(f, tt) || continue
sig = Tuple{typeof(f), tt.parameters...}
end
end
Core.Compiler.findall(sig, table.inner; limit)
end But same issue with the resulting IR. |
Any chance that this mechanism can be easily extended to dispatch on function signature? Or would that end up with a lot of the same issues that Cassette has? |
Yeah, sure. The method table query has the full call signature, so we can do with that what we want. What kind of overrides did you have in mind, and how should it work? In the case of, e.g., |
Pretty much what you show with |
Usually we should want to always do method overriding, so maybe we can provide a hook like |
And of course this should dispatch on the current job to allow this to be target-specific... |
Yeah of course, this is very early development. |
7836f97
to
9a99f5c
Compare
Codecov Report
@@ Coverage Diff @@
## master #122 +/- ##
===========================================
- Coverage 82.94% 70.21% -12.73%
===========================================
Files 22 22
Lines 1589 1558 -31
===========================================
- Hits 1318 1094 -224
- Misses 271 464 +193
Continue to review full report at Codecov.
|
9a99f5c
to
4bacd4e
Compare
4bacd4e
to
e026483
Compare
e026483
to
0ff7e14
Compare
Now part of #151. |
Just prototyping. This overrides MethodInstance->CodeInstance lookups by hacking the cache lookup:
Not ideal because the cache isn't really meant for this, I think. But it works. I'd rather specialize some functionality from abstract interpretation, but that doesn't seem to work with the IR we emit:
We successfully convince inference to use
bar
, but the IR still contains references tofoo
, resulting in bad code:I had hoped that we would not need to rewrite the code when using the interpreter.