Skip to content

Commit

Permalink
Merge pull request #100 from vtjnash/jn/patch-1
Browse files Browse the repository at this point in the history
avoid some internal methods and invalid objects
  • Loading branch information
timholy authored Mar 5, 2019
2 parents 8a3e084 + a18fff4 commit c0e481d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
18 changes: 9 additions & 9 deletions src/JuliaInterpreter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,15 @@ function prepare_args(@nospecialize(f), allargs, kwargs)
return f, allargs
end

if VERSION < v"1.2-" || !isdefined(Core.Compiler, :specialize_method)
specialize_method(method::Method, @nospecialize(atypes), sparams::SimpleVector) =
Core.Compiler.code_for_method(method, atypes, sparams, typemax(UInt))
else
const specialize_method = Core.Compiler.specialize_method
end

function prepare_framecode(method::Method, argtypes; enter_generated=false)
sig = method.sig
isa(method, TypeMapEntry) && (method = method.func)
if method.module == Core.Compiler || method.module == Base.Threads || method compiled_methods
return Compiled()
end
Expand All @@ -367,7 +373,7 @@ function prepare_framecode(method::Method, argtypes; enter_generated=false)
# If we're stepping into a staged function, we need to use
# the specialization, rather than stepping through the
# unspecialized method.
code = Core.Compiler.get_staged(Core.Compiler.code_for_method(method, argtypes, lenv, typemax(UInt), false))
code = Core.Compiler.get_staged(specialize_method(method, argtypes, lenv))
code === nothing && return nothing
generator = false
else
Expand Down Expand Up @@ -645,13 +651,7 @@ function determine_method_for_expr(expr; enter_generated = false)
return prepare_call(f, allargs; enter_generated=enter_generated)
end

function get_source(meth)
if isa(meth.source, Array{UInt8,1})
return ccall(:jl_uncompress_ast, Any, (Any, Any), meth, meth.source)
else
return meth.source
end
end
get_source(meth) = Base.uncompressed_ast(meth)

function get_source(g::GeneratedFunctionStub)
b = g(g.argnames...)
Expand Down
22 changes: 13 additions & 9 deletions src/localmethtable.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
const max_methods = 4 # maximum number of MethodInstances tracked for a particular :call statement

struct FrameInstance
framecode::JuliaFrameCode
sparam_vals::SimpleVector
end

"""
framecode, lenv = get_call_framecode(fargs, parentframe::JuliaFrameCode, idx::Int)
Expand Down Expand Up @@ -34,9 +39,8 @@ function get_call_framecode(fargs, parentframe::JuliaFrameCode, idx::Int)
tmeprev.next = tme.next
tme.next = tme1
end
# The framecode is stashed in the `inferred` field of the MethodInstance
mi = tme.func::MethodInstance
return mi.inferred::JuliaFrameCode, mi.sparam_vals
mi = tme.func::FrameInstance
return mi.framecode, mi.sparam_vals
end
end
depth += 1
Expand All @@ -53,17 +57,17 @@ function get_call_framecode(fargs, parentframe::JuliaFrameCode, idx::Int)
isa(ret, Compiled) && return ret, nothing
framecode, args, env, argtypes = ret
# Store the results of the method lookup in the local method table
mi = FrameInstance(framecode, env)
# it's sort of odd to call this a TypeMapEntry, then set most of the fields incorrectly
# but since we're just using it as a linked list, it's probably ok
tme = ccall(:jl_new_struct_uninit, Any, (Any,), TypeMapEntry)::TypeMapEntry
tme.func = mi = ccall(:jl_new_struct_uninit, Any, (Any,), MethodInstance)::MethodInstance
tme.sig = mi.specTypes = argtypes
tme.func = mi
tme.simplesig = nothing
tme.sig = argtypes
tme.isleafsig = true
tme.issimplesig = false
method = framecode.scope::Method
tme.va = method.isva
mi.def = method
mi.rettype = Any
mi.sparam_vals = env
mi.inferred = framecode # a slight abuse, but not insane
if isassigned(parentframe.methodtables, idx)
tme.next = parentframe.methodtables[idx]
# Drop the oldest tme, if necessary
Expand Down

0 comments on commit c0e481d

Please sign in to comment.