Skip to content

Commit a18fff4

Browse files
committed
avoid some internal methods and invalid objects
1 parent 153e235 commit a18fff4

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

src/JuliaInterpreter.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,15 @@ function prepare_args(@nospecialize(f), allargs, kwargs)
347347
return f, allargs
348348
end
349349

350+
if VERSION < v"1.2-" || !isdefined(Core.Compiler, :specialize_method)
351+
specialize_method(method::Method, @nospecialize(atypes), sparams::SimpleVector) =
352+
Core.Compiler.code_for_method(method, atypes, sparams, typemax(UInt))
353+
else
354+
const specialize_method = Core.Compiler.specialize_method
355+
end
356+
350357
function prepare_framecode(method::Method, argtypes; enter_generated=false)
351358
sig = method.sig
352-
isa(method, TypeMapEntry) && (method = method.func)
353359
if method.module == Core.Compiler || method.module == Base.Threads || method compiled_methods
354360
return Compiled()
355361
end
@@ -367,7 +373,7 @@ function prepare_framecode(method::Method, argtypes; enter_generated=false)
367373
# If we're stepping into a staged function, we need to use
368374
# the specialization, rather than stepping through the
369375
# unspecialized method.
370-
code = Core.Compiler.get_staged(Core.Compiler.code_for_method(method, argtypes, lenv, typemax(UInt), false))
376+
code = Core.Compiler.get_staged(specialize_method(method, argtypes, lenv))
371377
code === nothing && return nothing
372378
generator = false
373379
else
@@ -645,13 +651,7 @@ function determine_method_for_expr(expr; enter_generated = false)
645651
return prepare_call(f, allargs; enter_generated=enter_generated)
646652
end
647653

648-
function get_source(meth)
649-
if isa(meth.source, Array{UInt8,1})
650-
return ccall(:jl_uncompress_ast, Any, (Any, Any), meth, meth.source)
651-
else
652-
return meth.source
653-
end
654-
end
654+
get_source(meth) = Base.uncompressed_ast(meth)
655655

656656
function get_source(g::GeneratedFunctionStub)
657657
b = g(g.argnames...)

src/localmethtable.jl

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
const max_methods = 4 # maximum number of MethodInstances tracked for a particular :call statement
22

3+
struct FrameInstance
4+
framecode::JuliaFrameCode
5+
sparam_vals::SimpleVector
6+
end
7+
38
"""
49
framecode, lenv = get_call_framecode(fargs, parentframe::JuliaFrameCode, idx::Int)
510
@@ -34,9 +39,8 @@ function get_call_framecode(fargs, parentframe::JuliaFrameCode, idx::Int)
3439
tmeprev.next = tme.next
3540
tme.next = tme1
3641
end
37-
# The framecode is stashed in the `inferred` field of the MethodInstance
38-
mi = tme.func::MethodInstance
39-
return mi.inferred::JuliaFrameCode, mi.sparam_vals
42+
mi = tme.func::FrameInstance
43+
return mi.framecode, mi.sparam_vals
4044
end
4145
end
4246
depth += 1
@@ -53,17 +57,17 @@ function get_call_framecode(fargs, parentframe::JuliaFrameCode, idx::Int)
5357
isa(ret, Compiled) && return ret, nothing
5458
framecode, args, env, argtypes = ret
5559
# Store the results of the method lookup in the local method table
60+
mi = FrameInstance(framecode, env)
61+
# it's sort of odd to call this a TypeMapEntry, then set most of the fields incorrectly
62+
# but since we're just using it as a linked list, it's probably ok
5663
tme = ccall(:jl_new_struct_uninit, Any, (Any,), TypeMapEntry)::TypeMapEntry
57-
tme.func = mi = ccall(:jl_new_struct_uninit, Any, (Any,), MethodInstance)::MethodInstance
58-
tme.sig = mi.specTypes = argtypes
64+
tme.func = mi
65+
tme.simplesig = nothing
66+
tme.sig = argtypes
5967
tme.isleafsig = true
6068
tme.issimplesig = false
6169
method = framecode.scope::Method
6270
tme.va = method.isva
63-
mi.def = method
64-
mi.rettype = Any
65-
mi.sparam_vals = env
66-
mi.inferred = framecode # a slight abuse, but not insane
6771
if isassigned(parentframe.methodtables, idx)
6872
tme.next = parentframe.methodtables[idx]
6973
# Drop the oldest tme, if necessary

0 commit comments

Comments
 (0)