@@ -44,9 +44,13 @@ function code_escapes(@nospecialize(f), @nospecialize(types=Base.default_tt(f));
44
44
match = Base. _which (tt; world, raise= true )
45
45
mi = Core. Compiler. specialize_method (match):: MethodInstance
46
46
interp = EscapeAnalyzer (world, mi)
47
- Core. Compiler. typeinf_ext (interp, mi)
47
+ frame = Core. Compiler. typeinf_frame (interp, mi, #= run_optimizer =# true )
48
48
isdefined (interp, :result ) || error (" optimization didn't happen: maybe everything has been constant folded?" )
49
- return EscapeResult (interp. result. ir, interp. result. estate, interp. result. mi, debuginfo === :source , interp)
49
+ slotnames = let src = frame. src
50
+ src isa CodeInfo ? src. slotnames : nothing
51
+ end
52
+ return EscapeResult (interp. result. ir, interp. result. estate, interp. result. mi,
53
+ slotnames, debuginfo === :source , interp)
50
54
end
51
55
52
56
# in order to run a whole analysis from ground zero (e.g. for benchmarking, etc.)
@@ -285,13 +289,15 @@ struct EscapeResult
285
289
ir:: IRCode
286
290
state:: EscapeState
287
291
mi:: Union{Nothing,MethodInstance}
292
+ slotnames:: Union{Nothing,Vector{Symbol}}
288
293
source:: Bool
289
294
interp:: Union{Nothing,EscapeAnalyzer}
290
295
function EscapeResult (ir:: IRCode , state:: EscapeState ,
291
296
mi:: Union{Nothing,MethodInstance} = nothing ,
297
+ slotnames:: Union{Nothing,Vector{Symbol}} = nothing ,
292
298
source:: Bool = false ,
293
299
interp:: Union{Nothing,EscapeAnalyzer} = nothing )
294
- return new (ir, state, mi, source, interp)
300
+ return new (ir, state, mi, slotnames, source, interp)
295
301
end
296
302
end
297
303
Base. show (io:: IO , result:: EscapeResult ) = print_with_info (io, result)
@@ -301,7 +307,8 @@ Base.show(io::IO, result::EscapeResult) = print_with_info(io, result)
301
307
Base. show (io:: IO , cached:: EscapeCacheInfo ) = show (io, EscapeResult (cached. ir, cached. state))
302
308
303
309
# adapted from https://github.com/JuliaDebug/LoweredCodeUtils.jl/blob/4612349432447e868cf9285f647108f43bd0a11c/src/codeedges.jl#L881-L897
304
- function print_with_info (io:: IO , (; ir, state, mi, source):: EscapeResult )
310
+ function print_with_info (io:: IO , result:: EscapeResult )
311
+ (; ir, state, mi, slotnames, source) = result
305
312
# print escape information on SSA values
306
313
function preprint (io:: IO )
307
314
ft = ir. argtypes[1 ]
@@ -314,7 +321,8 @@ function print_with_info(io::IO, (; ir, state, mi, source)::EscapeResult)
314
321
arg = state[Argument (i)]
315
322
i == 1 && continue
316
323
c, color = get_name_color (arg, true )
317
- printstyled (io, c, ' ' , ' _' , i, " ::" , ir. argtypes[i]; color)
324
+ slot = isnothing (slotnames) ? " _$i " : slotnames[i]
325
+ printstyled (io, c, ' ' , slot, " ::" , ir. argtypes[i]; color)
318
326
i ≠ state. nargs && print (io, " , " )
319
327
end
320
328
print (io, ' )' )
0 commit comments