Skip to content

Commit c04368d

Browse files
committed
support for inference heuristic spoofing (ref JuliaLang/julia#24852)
1 parent 4669089 commit c04368d

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/overdub/execution.jl

+16-2
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,27 @@ end
168168
# Overdub{Intercept} #
169169
#--------------------#
170170

171+
function _overdub_generator end
172+
171173
for N in 0:MAX_ARGS
172174
arg_names = [Symbol("_CASSETTE_$i") for i in 2:(N+1)]
173175
arg_types = [:(unbox(C, $T)) for T in arg_names]
176+
stub = Core.GeneratedFunctionStub(_overdub_generator,
177+
Any[:f, arg_names...],
178+
Any[:F, :C, :M, :world, :debug],
179+
@__LINE__,
180+
Symbol(@__FILE__),
181+
true)
174182
@eval begin
175-
@generated function (f::Overdub{Intercept,F,Settings{C,M,world,debug}})($(arg_names...)) where {F,C,M,world,debug}
183+
function _overdub_generator(f::Overdub{Intercept,F,Settings{C,M,world,debug}}, $(arg_names...)) where {F,C,M,world,debug}
176184
signature = Tuple{unbox(C, F),$(arg_types...)}
177-
method_body = lookup_method_body(signature, $arg_names, world, debug)
185+
method, method_body = lookup_method_body(signature, $arg_names, world, debug)
178186
if isa(method_body, CodeInfo)
179187
method_body = overdub_new!(overdub_calls!(getpass(C, M)(signature, method_body)))
180188
method_body.inlineable = true
189+
if isa(method, Method)
190+
method_body.method_for_inference_heuristics = method
191+
end
181192
else
182193
arg_names = $arg_names
183194
method_body = quote
@@ -188,5 +199,8 @@ for N in 0:MAX_ARGS
188199
debug && Core.println("RETURNING Overdub(...) BODY: ", method_body)
189200
return method_body
190201
end
202+
function (f::Overdub{Intercept,F,Settings{C,M,world,debug}})($(arg_names...)) where {F,C,M,world,debug}
203+
$(Expr(:meta, :generated_only, stub))
204+
end
191205
end
192206
end

src/overdub/reflection.jl

+3-3
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)