@@ -121,7 +121,7 @@ to methods defined in `frame` that occur within `frame`.
121
121
122
122
`methodinfos` is a Dict of `name=>info` pairs, where `info` is a [`MethodInfo`](@ref).
123
123
124
- `selfcalls` is a list of `(linetop, linebody, callee, caller)` tuples that holds the location of
124
+ `selfcalls` is a list of `SelfCall (linetop, linebody, callee, caller)` that holds the location of
125
125
calls the methods defined in `frame`. `linetop` is the line in `frame` (top meaning "top level"),
126
126
which will correspond to a 3-argument `:method` expression containing a `CodeInfo` body.
127
127
`linebody` is the line within the `CodeInfo` body from which the call is made.
@@ -223,26 +223,27 @@ function callchain(selfcalls)
223
223
return calledby
224
224
end
225
225
226
- function set_to_running_name! (@nospecialize (recurse), replacements, frame, methodinfos, calledby, callee, caller)
226
+ function set_to_running_name! (@nospecialize (recurse), replacements, frame, methodinfos, selfcall, calledby, callee, caller)
227
227
if isa (caller, Symbol) && startswith (String (caller), ' #' )
228
228
rep = get (replacements, caller, nothing )
229
229
if rep === nothing
230
230
parentcaller = get (calledby, caller, nothing )
231
231
if parentcaller != = nothing
232
- set_to_running_name! (recurse, replacements, frame, methodinfos, calledby, caller, parentcaller)
232
+ set_to_running_name! (recurse, replacements, frame, methodinfos, selfcall, calledby, caller, parentcaller)
233
233
end
234
234
else
235
235
caller = rep
236
236
end
237
237
end
238
- if isa (caller, Symbol)
239
- mi = methodinfos[caller]
240
- cname, _pc, _ = get_running_name (recurse, frame, mi. start, callee, get (replacements, caller, caller))
241
- else
242
- # For generated constructors (which have no name), we just assume they immediately follow their callee
243
- mi = methodinfos[callee]
244
- cname, _pc, _ = get_running_name (recurse, frame, mi. stop+ 1 , callee, get (replacements, caller, caller))
238
+ # Back up to the beginning of the signature
239
+ pc = selfcall. linetop
240
+ stmt = pc_expr (frame, pc)
241
+ while pc > 1 && ! ismethod1 (stmt)
242
+ pc -= 1
243
+ stmt = pc_expr (frame, pc)
245
244
end
245
+ @assert ismethod1 (stmt)
246
+ cname, _pc, _ = get_running_name (recurse, frame, pc+ 1 , callee, get (replacements, caller, caller))
246
247
replacements[callee] = cname
247
248
mi = methodinfos[cname] = methodinfos[callee]
248
249
src = frame. framecode. src
@@ -270,8 +271,10 @@ function rename_framemethods!(@nospecialize(recurse), frame::Frame, methodinfos,
270
271
replacements = Dict {Symbol,Symbol} ()
271
272
for (callee, caller) in calledby
272
273
(! startswith (String (callee), ' #' ) || haskey (replacements, callee)) && continue
274
+ idx = findfirst (sc-> sc. callee === callee && sc. caller === caller, selfcalls)
275
+ idx === nothing && continue
273
276
try
274
- set_to_running_name! (recurse, replacements, frame, methodinfos, calledby, callee, caller)
277
+ set_to_running_name! (recurse, replacements, frame, methodinfos, selfcalls[idx], calledby, callee, caller)
275
278
catch err
276
279
@warn " skipping callee $callee (called by $caller ) due to $err "
277
280
end
297
300
rename_framemethods! (frame:: Frame ) = rename_framemethods! (finish_and_return!, frame)
298
301
299
302
"""
300
- pctop, isgen = find_corrected_name (recurse, frame, pc, name, parentname)
303
+ pctop, isgen = find_name_caller_sig (recurse, frame, pc, name, parentname)
301
304
302
305
Scans forward from `pc` in `frame` until a method is found that calls `name`.
303
306
`pctop` points to the beginning of that method's signature.
@@ -306,7 +309,7 @@ Scans forward from `pc` in `frame` until a method is found that calls `name`.
306
309
Alternatively, this returns `nothing` if `pc` does not appear to point to either
307
310
a keyword or generated method.
308
311
"""
309
- function find_corrected_name (@nospecialize (recurse), frame, pc, name, parentname)
312
+ function find_name_caller_sig (@nospecialize (recurse), frame, pc, name, parentname)
310
313
stmt = pc_expr (frame, pc)
311
314
while true
312
315
pc0 = pc
@@ -316,18 +319,6 @@ function find_corrected_name(@nospecialize(recurse), frame, pc, name, parentname
316
319
stmt = pc_expr (frame, pc)
317
320
end
318
321
body = stmt. args[3 ]
319
- if stmt. args[1 ] != = name && isa (body, SSAValue)
320
- # OK, we can't skip all the stuff that might define the body
321
- # See https://github.com/timholy/Revise.jl/issues/398
322
- pc = pc0
323
- stmt = pc_expr (frame, pc)
324
- while ! ismethod3 (stmt)
325
- pc = step_expr! (recurse, frame, stmt, true )
326
- pc === nothing && return nothing
327
- stmt = pc_expr (frame, pc)
328
- end
329
- body = @lookup (frame, stmt. args[3 ])
330
- end
331
322
if stmt. args[1 ] != = name && isa (body, CodeInfo)
332
323
# This might be the GeneratedFunctionStub for a @generated method
333
324
for (i, bodystmt) in enumerate (body. code)
@@ -379,8 +370,7 @@ function replacename!(args::Vector{Any}, pr)
379
370
end
380
371
381
372
function get_running_name (@nospecialize (recurse), frame, pc, name, parentname)
382
- # Get the correct name (the one that's actively running)
383
- nameinfo = find_corrected_name (recurse, frame, pc, name, parentname)
373
+ nameinfo = find_name_caller_sig (recurse, frame, pc, name, parentname)
384
374
if nameinfo === nothing
385
375
pc = skip_until (stmt-> isexpr (stmt, :method , 3 ), frame, pc)
386
376
pc = next_or_nothing (frame, pc)
0 commit comments