Skip to content

Commit 99bf6dc

Browse files
committed
support for inference heuristic spoofing (ref JuliaLang/julia#24852)
1 parent 3fceea6 commit 99bf6dc

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/overdub/execution.jl

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,27 @@ end
155155
# Overdub{Intercept} #
156156
#--------------------#
157157

158+
function _overdub_generator end
159+
158160
for N in 0:MAX_ARGS
159161
arg_names = [Symbol("_CASSETTE_$i") for i in 2:(N+1)]
160162
arg_types = [:(unwrap(C, $T)) for T in arg_names]
163+
stub = Core.GeneratedFunctionStub(_overdub_generator,
164+
Any[:f, arg_names...],
165+
Any[:F, :C, :M, :world, :debug],
166+
@__LINE__,
167+
Symbol(@__FILE__),
168+
true)
161169
@eval begin
162-
@generated function (f::Overdub{Intercept,F,Settings{C,M,world,debug}})($(arg_names...)) where {F,C,M,world,debug}
170+
function _overdub_generator(f::Overdub{Intercept,F,Settings{C,M,world,debug}}, $(arg_names...)) where {F,C,M,world,debug}
163171
signature = Tuple{unwrap(C, F),$(arg_types...)}
164-
method_body = lookup_method_body(signature, $arg_names, world, debug)
172+
method, method_body = lookup_method_body(signature, $arg_names, world, debug)
165173
if isa(method_body, CodeInfo)
166174
method_body = overdub_new!(overdub_calls!(getpass(C, M)(signature, method_body)))
167175
method_body.inlineable = true
176+
if isa(method, Method)
177+
method_body.method_for_inference_heuristics = method
178+
end
168179
else
169180
arg_names = $arg_names
170181
method_body = quote
@@ -175,5 +186,8 @@ for N in 0:MAX_ARGS
175186
debug && Core.println("RETURNING Overdub(...) BODY: ", method_body)
176187
return method_body
177188
end
189+
function (f::Overdub{Intercept,F,Settings{C,M,world,debug}})($(arg_names...)) where {F,C,M,world,debug}
190+
$(Expr(:meta, :generated_only, stub))
191+
end
178192
end
179193
end

src/overdub/reflection.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ function lookup_method_body(::Type{S}, arg_names::Vector,
99
Core.println("\tSIGNATURE: ", S)
1010
Core.println("\tWORLD: ", world)
1111
end
12-
S.parameters[1].name.module === Core.Inference && return nothing
12+
S.parameters[1].name.module === Core.Inference && return (nothing, nothing)
1313
results = _lookup_method_body(S, arg_names, world)
14-
results === nothing && return nothing
14+
results === nothing && return (nothing, nothing)
1515
method, code_info = results
1616
debug && Core.println("LOOKED UP METHOD: ", method)
1717
debug && Core.println("LOOKED UP CODEINFO: ", code_info)
18-
return code_info
18+
return method, code_info
1919
end
2020

2121
function _lookup_method_body(::Type{S}, arg_names::Vector,

0 commit comments

Comments
 (0)