Skip to content

Commit eb20811

Browse files
authored
fix up rename_framemethods! (#83)
I will add comments on changed lines to describe what this commit does.
1 parent 7738b80 commit eb20811

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/signatures.jl

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ function signature(@nospecialize(recurse), frame::Frame, @nospecialize(stmt), pc
4343
while !isexpr(stmt, :method, 3) # wait for the 3-arg version
4444
if isanonymous_typedef(stmt)
4545
lastpc = pc = step_through_methoddef(recurse, frame, stmt) # define an anonymous function
46-
elseif isexpr(stmt, :call) && (q = (stmt::Expr).args[1]; isa(q, QuoteNode) && q.value === Core.Typeof) &&
47-
(sym = (stmt::Expr).args[2]; isa(sym, Symbol) && !isdefined(mod, sym))
46+
elseif is_Typeof_for_anonymous_methoddef(stmt, frame.framecode.src.code, mod)
4847
return nothing, pc
4948
else
5049
lastpc = pc
@@ -61,6 +60,19 @@ end
6160
signature(@nospecialize(recurse), frame::Frame, pc) = signature(recurse, frame, pc_expr(frame, pc), pc)
6261
signature(frame::Frame, pc) = signature(finish_and_return!, frame, pc)
6362

63+
function is_Typeof_for_anonymous_methoddef(@nospecialize(stmt), code::Vector{Any}, mod::Module)
64+
isexpr(stmt, :call) || return false
65+
f = stmt.args[1]
66+
isa(f, QuoteNode) || return false
67+
f.value === Core.Typeof || return false
68+
arg1 = stmt.args[2]
69+
if isa(arg1, SSAValue)
70+
arg1 = code[arg1.id]
71+
end
72+
arg1 isa Symbol || return false
73+
return !isdefined(mod, arg1)
74+
end
75+
6476
function minid(@nospecialize(node), stmts, id)
6577
if isa(node, SSAValue)
6678
id = min(id, node.id)
@@ -262,7 +274,7 @@ function set_to_running_name!(@nospecialize(recurse), replacements, frame, metho
262274
replacements[callee] = cname
263275
mi = methodinfos[cname] = methodinfos[callee]
264276
src = frame.framecode.src
265-
replacename!(src.code[mi.start:mi.stop], callee=>cname) # the method itself
277+
replacename!(@view(src.code[mi.start:mi.stop]), callee=>cname) # the method itself
266278
for r in mi.refs # the references
267279
replacename!((src.code[r])::Expr, callee=>cname)
268280
end
@@ -365,7 +377,7 @@ end
365377

366378
replacename!(src::CodeInfo, pr) = replacename!(src.code, pr)
367379

368-
function replacename!(args::Vector{Any}, pr)
380+
function replacename!(args::AbstractVector, pr)
369381
oldname, newname = pr
370382
for i = 1:length(args)
371383
a = args[i]
@@ -377,6 +389,9 @@ function replacename!(args::Vector{Any}, pr)
377389
args[i] = QuoteNode(newname)
378390
elseif isa(a, Vector{Any})
379391
replacename!(a, pr)
392+
elseif isa(a, Core.ReturnNode) && isdefined(a, :val) && a.val isa Expr
393+
# there is something like `ReturnNode(Expr(:method, Symbol(...)))`
394+
replacename!(a.val::Expr, pr)
380395
elseif a === oldname
381396
args[i] = newname
382397
end

src/utils.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ function ismethod_with_name(src, stmt, target::AbstractString; reentrant::Bool=f
9999
return match(Regex("(^|#)$target(\$|#)"), string(name)) !== nothing
100100
end
101101

102-
103-
104102
# anonymous function types are defined in a :thunk expr with a characteristic CodeInfo
105103
function isanonymous_typedef(stmt)
106104
if isa(stmt, Expr)

0 commit comments

Comments
 (0)