@@ -153,6 +153,12 @@ function default_expr_type_printer(io::IO, @nospecialize(typ), used::Bool)
153
153
nothing
154
154
end
155
155
156
+ normalize_method_name (m:: Method ) = m. name
157
+ normalize_method_name (m:: MethodInstance ) = (m. def:: Method ). name
158
+ normalize_method_name (m:: Symbol ) = m
159
+ normalize_method_name (m) = Symbol (" " )
160
+ @noinline method_name (m:: LineInfoNode ) = normalize_method_name (m. method)
161
+
156
162
# converts the linetable for line numbers
157
163
# into a list in the form:
158
164
# 1 outer-most-frame
@@ -266,7 +272,7 @@ function compute_ir_line_annotations(code::Union{IRCode, CodeInfo})
266
272
# be a line number mismatch in inner most frame. Ignore those
267
273
if length (last_stack) == length (stack) && first_mismatch == length (stack)
268
274
last_entry, entry = linetable[last_stack[end ]], linetable[stack[end ]]
269
- if last_entry. method == entry. method && last_entry. file == entry. file
275
+ if method_name ( last_entry) === method_name ( entry) && last_entry. file = == entry. file
270
276
first_mismatch = nothing
271
277
end
272
278
end
@@ -299,13 +305,14 @@ function compute_ir_line_annotations(code::Union{IRCode, CodeInfo})
299
305
print (buf, " │" )
300
306
end
301
307
end
302
- print (buf, " ╷" ^ max (0 ,depth- last_depth- stole_one))
308
+ print (buf, " ╷" ^ max (0 , depth - last_depth - stole_one))
303
309
if printing_depth != 0
304
310
if length (stack) == printing_depth
305
- loc_method = String (linetable[ line] . method)
311
+ loc_method = line
306
312
else
307
- loc_method = String (linetable[ stack[printing_depth+ 1 ]] . method)
313
+ loc_method = stack[printing_depth + 1 ]
308
314
end
315
+ loc_method = method_name (linetable[loc_method])
309
316
end
310
317
loc_method = string (" " ^ printing_depth, loc_method)
311
318
end
@@ -326,14 +333,14 @@ Base.show(io::IO, code::IRCode) = show_ir(io, code)
326
333
327
334
lineinfo_disabled (io:: IO , linestart:: String , lineidx:: Int32 ) = " "
328
335
329
- function DILineInfoPrinter (linetable:: Vector )
336
+ function DILineInfoPrinter (linetable:: Vector , showtypes :: Bool = false )
330
337
context = LineInfoNode[]
331
338
context_depth = Ref (0 )
332
339
indent (s:: String ) = s^ (max (context_depth[], 1 ) - 1 )
333
340
function emit_lineinfo_update (io:: IO , linestart:: String , lineidx:: Int32 )
334
341
# internal configuration options:
335
342
linecolor = :yellow
336
- collapse = true
343
+ collapse = showtypes ? false : true
337
344
indent_all = true
338
345
# convert lineidx to a vector
339
346
if lineidx < 0
@@ -373,11 +380,11 @@ function DILineInfoPrinter(linetable::Vector)
373
380
# if so, drop all existing calls to it from the top of the context
374
381
# AND check if instead the context was previously printed that way
375
382
# but now has removed the recursive frames
376
- let method = context[nctx]. method
377
- if (nctx < nframes && DI[nframes - nctx]. method === method) ||
378
- (nctx < length (context) && context[nctx + 1 ]. method === method)
383
+ let method = method_name ( context[nctx])
384
+ if (nctx < nframes && method_name ( DI[nframes - nctx]) === method) ||
385
+ (nctx < length (context) && method_name ( context[nctx + 1 ]) === method)
379
386
update_line_only = true
380
- while nctx > 0 && context[nctx]. method === method
387
+ while nctx > 0 && method_name ( context[nctx]) === method
381
388
nctx -= 1
382
389
end
383
390
end
@@ -388,9 +395,9 @@ function DILineInfoPrinter(linetable::Vector)
388
395
# compute the new inlining depth
389
396
if collapse
390
397
npops = 1
391
- let Prev = context[nctx + 1 ]. method
398
+ let Prev = method_name ( context[nctx + 1 ])
392
399
for i = (nctx + 2 ): length (context)
393
- Next = context[i]. method
400
+ Next = method_name ( context[i])
394
401
Prev === Next || (npops += 1 )
395
402
Prev = Next
396
403
end
@@ -402,9 +409,8 @@ function DILineInfoPrinter(linetable::Vector)
402
409
if ! update_line_only && nctx < nframes
403
410
let CtxLine = context[nctx + 1 ],
404
411
FrameLine = DI[nframes - nctx]
405
- if CtxLine. file == FrameLine. file &&
406
- CtxLine. method == FrameLine. method &&
407
- CtxLine. mod == FrameLine. mod
412
+ if CtxLine. file === FrameLine. file &&
413
+ method_name (CtxLine) === method_name (FrameLine)
408
414
update_line_only = true
409
415
end
410
416
end
@@ -426,12 +432,12 @@ function DILineInfoPrinter(linetable::Vector)
426
432
if frame. line != typemax (frame. line) && frame. line != 0
427
433
print (io, linestart)
428
434
Base. with_output_color (linecolor, io) do io
429
- print (io, indent (" │" ), " @ " , frame. file, " :" , frame. line, " within `" , frame. method , " '" )
435
+ print (io, indent (" │" ), " @ " , frame. file, " :" , frame. line, " within `" , method_name ( frame) , " '" )
430
436
if collapse
431
- method = frame. method
437
+ method = method_name ( frame)
432
438
while nctx < nframes
433
439
frame = DI[nframes - nctx]
434
- frame. method === method || break
440
+ method_name ( frame) === method || break
435
441
nctx += 1
436
442
push! (context, frame)
437
443
print (io, " @ " , frame. file, " :" , frame. line)
@@ -444,23 +450,33 @@ function DILineInfoPrinter(linetable::Vector)
444
450
# now print the rest of the new frames
445
451
while nctx < nframes
446
452
frame = DI[nframes - nctx]
453
+ nctx += 1
454
+ started = false
455
+ if showtypes && ! isa (frame. method, Symbol) && nctx != 1
456
+ print (io, linestart)
457
+ Base. with_output_color (linecolor, io) do io
458
+ print (io, indent (" │" ))
459
+ print (io, " ┌ invoke " , frame. method)
460
+ println (io)
461
+ end
462
+ started = true
463
+ end
447
464
print (io, linestart)
448
465
Base. with_output_color (linecolor, io) do io
449
466
print (io, indent (" │" ))
450
- nctx += 1
451
467
push! (context, frame)
452
468
context_depth[] += 1
453
- nctx != 1 && print (io, " ┌" )
469
+ nctx != 1 && print (io, started ? " │ " : " ┌" )
454
470
print (io, " @ " , frame. file)
455
471
if frame. line != typemax (frame. line) && frame. line != 0
456
472
print (io, " :" , frame. line)
457
473
end
458
- print (io, " within `" , frame. method , " '" )
474
+ print (io, " within `" , method_name ( frame) , " '" )
459
475
if collapse
460
- method = frame. method
476
+ method = method_name ( frame)
461
477
while nctx < nframes
462
478
frame = DI[nframes - nctx]
463
- frame. method === method || break
479
+ method_name ( frame) === method || break
464
480
nctx += 1
465
481
push! (context, frame)
466
482
print (io, " @ " , frame. file, " :" , frame. line)
@@ -471,10 +487,10 @@ function DILineInfoPrinter(linetable::Vector)
471
487
end
472
488
# FOR DEBUGGING `collapse`:
473
489
# this double-checks the computation of context_depth
474
- # let Prev = context[1].method ,
490
+ # let Prev = method_name( context[1]) ,
475
491
# depth2 = 1
476
492
# for i = 2:nctx
477
- # Next = context[i].method
493
+ # Next = method_name( context[i])
478
494
# (collapse && Prev === Next) || (depth2 += 1)
479
495
# Prev = Next
480
496
# end
@@ -565,7 +581,7 @@ function show_ir(io::IO, code::IRCode, expr_type_printer=default_expr_type_print
565
581
printstyled (io, " \e [$(start_column) G$(rail) \e [1G" , color = :light_black )
566
582
print (io, bb_guard_rail)
567
583
ssa_guard = " " ^ (maxlength_idx + 4 + (i - 1 ))
568
- entry_label = " $(ssa_guard)$(entry. method ) at $(entry. file) :$(entry. line) "
584
+ entry_label = " $(ssa_guard)$(method_name ( entry) ) at $(entry. file) :$(entry. line) "
569
585
hline = string (" ─" ^ (start_column- length (entry_label)- length (bb_guard_rail)+ max_depth- i), " ┐" )
570
586
printstyled (io, string (entry_label, hline), " \n " ; color= :light_black )
571
587
bb_guard_rail = bb_guard_rail_cont
0 commit comments