Skip to content

Commit 0567d22

Browse files
committed
Fill out list on older Julia versions
1 parent 6546d85 commit 0567d22

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

src/utils.jl

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,23 +207,36 @@ else
207207
function linetable_scopes(m::Method)
208208
src = Base.uncompressed_ast(m)
209209
lt, cl = src.linetable, src.codelocs
210-
return [iszero(cl[pc]) ? Core.LineInfoNode[] : [lt[cl[pc]]] for pc = eachindex(cl)]
210+
lts = [Vector{Core.LineInfoNode}() for _ = eachindex(src.code)]
211+
for pc = eachindex(src.code)
212+
iszero(cl[pc]) && continue
213+
scope = lts[pc]
214+
push!(scope, lt[cl[pc]])
215+
while (k = last(scope).inlined_at) != Int32(0)
216+
push!(scope, lt[k])
217+
end
218+
if length(scope) > 1
219+
reverse!(scope)
220+
end
221+
end
222+
return lts
211223
end
212224
end
213225
@doc """
214226
scopes = linetable_scopes(m::Method)
215227
216-
Return an array of "scopes" for each statement in the lowered code for `m`.
217-
If `src = Base.uncompressed_ast(m)`, then `scopes[pc]` is an vector of `LineInfoNode`
218-
objects that represent the scopes active at the statement at position `pc` in `src.code`.
228+
Return an array of "scopes" for each statement in the lowered code for `m`. If
229+
`src = Base.uncompressed_ast(m)`, then `scopes[pc]` is an vector of
230+
`LineInfoNode` objects that represent the scopes active at the statement at
231+
position `pc` in `src.code`.
219232
220-
On Julia 1.12 and later, `scopes[pc]` may have length larger than 1, where the first entry
221-
is for the source location in `m`, and any later entries reflect code from inlining.
222-
It will be a vector of `Base.Compiler.IRShow.LineInfoNode` objects.
233+
`scopes[pc]` may have length larger than 1, where the first entry is for the
234+
source location in `m`, and any later entries reflect code from inlining.
223235
224-
Prior to Julia 1.12, `scopes[pc]` will have length 1, and will be a vector of `Core.LineInfoNode`
225-
objects (which have more fields than `Base.Compiler.IRShow.LineInfoNode`). It will represent
226-
the final stage of inlining for the statement at position `pc` in `src.code`.
236+
The precise type of these entries varies with Julia version,
237+
`Base.Compiler.IRShow.LineInfoNode` objects on Julia 1.12 and up, and
238+
`Core.LineInfoNode` objects on earlier versions. These objects differ in some of
239+
their fields. `:method`, `:file`, and `:line` are common to both types.
227240
""" linetable_scopes
228241

229242
getmethod(m::Method) = m

0 commit comments

Comments
 (0)