Skip to content

Commit

Permalink
WIP changes to adapt to compressed line table format
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Jan 2, 2024
1 parent 6c96853 commit d7379f1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
27 changes: 21 additions & 6 deletions TypedSyntax/src/node.jl
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,17 @@ function collect_symbol_nodes!(symlocs::AbstractDict, node)
return symlocs
end

function debuginfo_line(lt::Core.DebugInfo, i::Int)
codeloc = Base.IRShow.getdebugidx(lt, i)
line::Int = codeloc[1]
line < 0 && return 0 # broken or disabled debug info?
if line == 0 && codeloc[2] == 0
return 0 # no line number update
end
return Int(Base.IRShow.buildLineInfoNode(lt, :var"n/a", i)[1].line)
end


# Main logic for mapping `src.code[i]` to node(s) in the SyntaxNode tree
# Success: when we map it to a unique node
# Δline is the (Revise) offset of the line number
Expand Down Expand Up @@ -427,14 +438,18 @@ function map_ssas_to_source(src::CodeInfo, rootnode::SyntaxNode, Δline::Int)
# Append (to `mapped`) all nodes in `targets` that are consistent with the line number of the `i`th stmt
# (Essentially `copy!(mapped, filter(predicate, targets))`)
function append_targets_for_line!(mapped#=::Vector{nodes}=#, i::Int, targets#=::Vector{nodes}=#)
j = src.codelocs[i]
lt = src.linetable::Vector{Any}
start = getline(lt, j) + Δline
stop = getnextline(lt, j, Δline) - 1
linerange = start : stop
line = debuginfo_line(src.debuginfo, i)
for t in targets
source_line(t) linerange && push!(mapped, t)
source_line(t) == line && push!(mapped, t)
end
#jwn j = src.codelocs[i]
#jwn lt = src.linetable::Vector{Any}
#jwn start = getline(lt, j) + Δline
#jwn stop = getnextline(lt, j, Δline) - 1
#jwn linerange = start : stop
#jwn for t in targets
#jwn source_line(t) ∈ linerange && push!(mapped, t)
#jwn end
return mapped
end
# For a call argument `arg`, find all source statements that match
Expand Down
6 changes: 3 additions & 3 deletions src/codeview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ function cthulhu_typed(io::IO, debuginfo::Symbol,
# We empty the body when filling kwargs
istruncated = isempty(children(body))
idxend = istruncated ? JuliaSyntax.last_byte(sig) : lastindex(tsn.source)
if any(iszero, src.codelocs)
@warn "Some line information is missing, type-assignment may be incomplete"
end
#jwn if any(iszero, src.codelocs)
#jwn @warn "Some line information is missing, type-assignment may be incomplete"
#jwn end
if src.slottypes === nothing
@warn "Inference terminated in an incomplete state due to argument-type changes during recursion"
end
Expand Down
22 changes: 13 additions & 9 deletions src/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -340,16 +340,20 @@ function find_caller_of(interp::AbstractInterpreter, callee::MethodInstance, cal
end

function add_sourceline!(locs, CI, stmtidx::Int)
if isa(CI, IRCode)
stack = Base.IRShow.compute_loc_stack(CI.linetable, CI.stmts.line[stmtidx])
for (i, idx) in enumerate(stack)
line = CI.linetable[idx]
line.line == 0 && continue
push!(locs, (CI.linetable[idx], i-1))
end
else
push!(locs, (CI.linetable[CI.codelocs[stmtidx]], 0))
stack = Base.IRShow.buildLineInfoNode(CI.debuginfo, :var"n/a", i)
for (i, di) in enumerate(stack)
push!(locs, (di, i-1))
end
#jwn if isa(CI, IRCode)
#jwn stack = Base.IRShow.compute_loc_stack(CI.linetable, CI.stmts.line[stmtidx])
#jwn for (i, idx) in enumerate(stack)
#jwn line = CI.linetable[idx]
#jwn line.line == 0 && continue
#jwn push!(locs, (CI.linetable[idx], i-1))
#jwn end
#jwn else
#jwn push!(locs, (CI.linetable[CI.codelocs[stmtidx]], 0))
#jwn end
return locs
end

Expand Down

0 comments on commit d7379f1

Please sign in to comment.