Skip to content

Commit

Permalink
minor followups on the linetable changes
Browse files Browse the repository at this point in the history
- remove unnecessary `Core.` accessors to `DebugInfo` within `Core.Compiler`
- improve the type of `DebugInfoStream`'s `edges` field
  • Loading branch information
aviatesk committed Apr 2, 2024
1 parent d8d3842 commit f73ffdb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
25 changes: 13 additions & 12 deletions base/compiler/ssair/ir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,40 +177,41 @@ end
# mutable version of the compressed DebugInfo
mutable struct DebugInfoStream
def::Union{MethodInstance,Symbol,Nothing}
linetable::Union{Nothing,Core.DebugInfo}
edges::Vector{Any} # Vector{Core.DebugInfo}
linetable::Union{Nothing,DebugInfo}
edges::Vector{DebugInfo}
firstline::Int32 # the starting line for this block (specified by having an index of 0)
codelocs::Vector{Int32} # for each statement:
# index into linetable (if defined), else a line number (in the file represented by def)
# then index into edges
# then index into edges[linetable]
function DebugInfoStream(codelocs::Vector{Int32})
return new(nothing, nothing, [], 0, codelocs)
return new(nothing, nothing, DebugInfo[], 0, codelocs)
end
#DebugInfoStream(def::Union{MethodInstance,Nothing}, di::DebugInfo, nstmts::Int) =
# if debuginfo_file1(di.def) === debuginfo_file1(di.def)
# new(def, di.linetable, Core.svec(di.edges...), getdebugidx(di, 0),
# ccall(:jl_uncompress_codelocs, Any, (Any, Int), di.codelocs, nstmts)::Vector{Int32})
# else
# DebugInfoStream(def::Union{MethodInstance,Nothing}, di::DebugInfo, nstmts::Int) =
# if debuginfo_file1(di.def) === debuginfo_file1(di.def)
# new(def, di.linetable, Core.svec(di.edges...), getdebugidx(di, 0),
# ccall(:jl_uncompress_codelocs, Any, (Any, Int), di.codelocs, nstmts)::Vector{Int32})
# else
function DebugInfoStream(def::Union{MethodInstance,Nothing}, di::DebugInfo, nstmts::Int)
codelocs = zeros(Int32, nstmts * 3)
for i = 1:nstmts
codelocs[3i - 2] = i
end
return new(def, di, Vector{Any}(), 0, codelocs)
return new(def, di, DebugInfo[], 0, codelocs)
end
global copy(di::DebugInfoStream) = new(di.def, di.linetable, di.edges, di.firstline, di.codelocs)
end

Core.DebugInfo(di::DebugInfoStream, nstmts::Int) =
Core.DebugInfo(something(di.def), di.linetable, Core.svec(di.edges...),
DebugInfo(something(di.def), di.linetable, Core.svec(di.edges...),
ccall(:jl_compress_codelocs, Any, (Int32, Any, Int), di.firstline, di.codelocs, nstmts)::String)

getdebugidx(debuginfo::Core.DebugInfo, pc::Int) = ccall(:jl_uncompress1_codeloc, NTuple{3,Int32}, (Any, Int), debuginfo.codelocs, pc)
getdebugidx(debuginfo::DebugInfo, pc::Int) =
ccall(:jl_uncompress1_codeloc, NTuple{3,Int32}, (Any, Int), debuginfo.codelocs, pc)

function getdebugidx(debuginfo::DebugInfoStream, pc::Int)
if 3 <= 3pc <= length(debuginfo.codelocs)
return (debuginfo.codelocs[3pc - 2], debuginfo.codelocs[3pc - 1], debuginfo.codelocs[3pc - 0])
return (debuginfo.codelocs[3pc-2], debuginfo.codelocs[3pc-1], debuginfo.codelocs[3pc-0])
elseif pc == 0
return (Int32(debuginfo.firstline), Int32(0), Int32(0))
else
Expand Down
6 changes: 3 additions & 3 deletions base/compiler/ssair/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ Base.show(io::IO, code::Union{IRCode, IncrementalCompact}) = show_ir(io, code)
lineinfo_disabled(io::IO, linestart::String, idx::Int) = ""

# utility function to extract the file name from a DebugInfo object
function debuginfo_file1(debuginfo::Union{Core.DebugInfo,DebugInfoStream})
function debuginfo_file1(debuginfo::Union{DebugInfo,DebugInfoStream})
def = debuginfo.def
if def isa MethodInstance
def = def.def
Expand All @@ -342,7 +342,7 @@ function debuginfo_file1(debuginfo::Union{Core.DebugInfo,DebugInfoStream})
end

# utility function to extract the first line number and file of a block of code
function debuginfo_firstline(debuginfo::Union{Core.DebugInfo,DebugInfoStream})
function debuginfo_firstline(debuginfo::Union{DebugInfo,DebugInfoStream})
linetable = debuginfo.linetable
while linetable != nothing
debuginfo = linetable
Expand Down Expand Up @@ -375,7 +375,7 @@ function append_scopes!(scopes::Vector{LineInfoNode}, pc::Int, debuginfo, @nospe
line < 0 && (doupdate = false; line = 0) # broken debug info
push!(scopes, LineInfoNode(def, debuginfo_file1(debuginfo), Int32(line)))
else
doupdate = append_scopes!(scopes, line, debuginfo.linetable::Core.DebugInfo, def) && doupdate
doupdate = append_scopes!(scopes, line, debuginfo.linetable::DebugInfo, def) && doupdate
end
inl_to == 0 && return doupdate
def = :var"macro expansion"
Expand Down
4 changes: 2 additions & 2 deletions base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ function CodeInstance(interp::AbstractInterpreter, result::InferenceResult;
end
# n.b. relocatability = (isa(inferred_result, String) && inferred_result[end]) || inferred_result === nothing
if !@isdefined edges
edges = Core.DebugInfo(result.linfo)
edges = DebugInfo(result.linfo)
end
return CodeInstance(result.linfo, owner,
widenconst(result_type), widenconst(result.exc_result), rettype_const, inferred_result,
Expand Down Expand Up @@ -923,7 +923,7 @@ function codeinfo_for_const(interp::AbstractInterpreter, mi::MethodInstance, @no
tree.slotnames = ccall(:jl_uncompress_argnames, Vector{Symbol}, (Any,), method.slot_syms)
tree.slotflags = fill(0x00, nargs)
tree.ssavaluetypes = 1
tree.debuginfo = Core.DebugInfo(mi)
tree.debuginfo = DebugInfo(mi)
tree.ssaflags = UInt32[0]
set_inlineable!(tree, true)
tree.parent = mi
Expand Down

0 comments on commit f73ffdb

Please sign in to comment.