Skip to content

Commit

Permalink
support for inference heuristic spoofing (ref JuliaLang/julia#24852)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrevels committed Dec 26, 2017
1 parent 4669089 commit c04368d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
18 changes: 16 additions & 2 deletions src/overdub/execution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,27 @@ end
# Overdub{Intercept} #
#--------------------#

function _overdub_generator end

for N in 0:MAX_ARGS
arg_names = [Symbol("_CASSETTE_$i") for i in 2:(N+1)]
arg_types = [:(unbox(C, $T)) for T in arg_names]
stub = Core.GeneratedFunctionStub(_overdub_generator,
Any[:f, arg_names...],
Any[:F, :C, :M, :world, :debug],
@__LINE__,
Symbol(@__FILE__),
true)
@eval begin
@generated function (f::Overdub{Intercept,F,Settings{C,M,world,debug}})($(arg_names...)) where {F,C,M,world,debug}
function _overdub_generator(f::Overdub{Intercept,F,Settings{C,M,world,debug}}, $(arg_names...)) where {F,C,M,world,debug}
signature = Tuple{unbox(C, F),$(arg_types...)}
method_body = lookup_method_body(signature, $arg_names, world, debug)
method, method_body = lookup_method_body(signature, $arg_names, world, debug)
if isa(method_body, CodeInfo)
method_body = overdub_new!(overdub_calls!(getpass(C, M)(signature, method_body)))
method_body.inlineable = true
if isa(method, Method)
method_body.method_for_inference_heuristics = method
end
else
arg_names = $arg_names
method_body = quote
Expand All @@ -188,5 +199,8 @@ for N in 0:MAX_ARGS
debug && Core.println("RETURNING Overdub(...) BODY: ", method_body)
return method_body
end
function (f::Overdub{Intercept,F,Settings{C,M,world,debug}})($(arg_names...)) where {F,C,M,world,debug}
$(Expr(:meta, :generated_only, stub))
end
end
end
6 changes: 3 additions & 3 deletions src/overdub/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ function lookup_method_body(::Type{S}, arg_names::Vector,
Core.println("\tSIGNATURE: ", S)
Core.println("\tWORLD: ", world)
end
S.parameters[1].name.module === Core.Inference && return nothing
S.parameters[1].name.module === Core.Inference && return (nothing, nothing)
results = _lookup_method_body(S, arg_names, world)
results === nothing && return nothing
results === nothing && return (nothing, nothing)
method, code_info = results
debug && Core.println("LOOKED UP METHOD: ", method)
debug && Core.println("LOOKED UP CODEINFO: ", code_info)
return code_info
return method, code_info
end

function _lookup_method_body(::Type{S}, arg_names::Vector,
Expand Down

0 comments on commit c04368d

Please sign in to comment.