From d7379f1235e733ff30db17ef34a7edc094771ef5 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Tue, 12 Dec 2023 20:53:47 +0000 Subject: [PATCH] WIP changes to adapt to compressed line table format --- TypedSyntax/src/node.jl | 27 +++++++++++++++++++++------ src/codeview.jl | 6 +++--- src/reflection.jl | 22 +++++++++++++--------- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/TypedSyntax/src/node.jl b/TypedSyntax/src/node.jl index 0756e5aa..c4e0a569 100644 --- a/TypedSyntax/src/node.jl +++ b/TypedSyntax/src/node.jl @@ -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 @@ -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 diff --git a/src/codeview.jl b/src/codeview.jl index a1ccd4dc..b4033376 100644 --- a/src/codeview.jl +++ b/src/codeview.jl @@ -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 diff --git a/src/reflection.jl b/src/reflection.jl index eee04004..32f0a790 100644 --- a/src/reflection.jl +++ b/src/reflection.jl @@ -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