From 2e3dca6923fd0efa75ed7e2ed54cd97fc7098187 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Fri, 4 Apr 2025 05:42:34 -0500 Subject: [PATCH] Generalize the "method" for `linetable_scopes` It could be a module, too. --- Project.toml | 2 +- src/utils.jl | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Project.toml b/Project.toml index 9ad3299..1d77231 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "CodeTracking" uuid = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2" authors = ["Tim Holy "] -version = "1.3.8" +version = "1.3.9" [deps] InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" diff --git a/src/utils.jl b/src/utils.jl index 0d69bdb..8d3db2a 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -195,8 +195,7 @@ fileline(lin::LineInfoNode) = String(lin.file), lin.line fileline(lnn::LineNumberNode) = String(lnn.file), lnn.line if VERSION ≥ v"1.12.0-DEV.173" # https://github.com/JuliaLang/julia/pull/52415 - function linetable_scopes(m::Method) - src = Base.uncompressed_ast(m) + function linetable_scopes(src::Core.CodeInfo, m) lts = [Vector{Base.Compiler.IRShow.LineInfoNode}() for _ = eachindex(src.code)] for pc = eachindex(src.code) Base.IRShow.append_scopes!(lts[pc], pc, src.debuginfo, m) @@ -204,8 +203,7 @@ if VERSION ≥ v"1.12.0-DEV.173" # https://github.com/JuliaLang/julia/pull/524 return lts end else - function linetable_scopes(m::Method) - src = Base.uncompressed_ast(m) + function linetable_scopes(src::Core.CodeInfo, _) lt, cl = src.linetable, src.codelocs lts = [Vector{Core.LineInfoNode}() for _ = eachindex(src.code)] for pc = eachindex(src.code) @@ -222,7 +220,8 @@ else return lts end end -@doc """ + +""" scopes = linetable_scopes(m::Method) Return an array of "scopes" for each statement in the lowered code for `m`. If @@ -237,7 +236,8 @@ The precise type of these entries varies with Julia version, `Base.Compiler.IRShow.LineInfoNode` objects on Julia 1.12 and up, and `Core.LineInfoNode` objects on earlier versions. These objects differ in some of their fields. `:method`, `:file`, and `:line` are common to both types. -""" linetable_scopes +""" +linetable_scopes(m::Method) = linetable_scopes(Base.uncompressed_ast(m), m) getmethod(m::Method) = m getmethod(mi::Core.MethodInstance) = getmethod(mi.def)