Skip to content

Commit

Permalink
IRShow: print invalid SSAValue in red (#46472)
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk authored Aug 25, 2022
1 parent c3d5009 commit 36aab14
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
17 changes: 12 additions & 5 deletions base/compiler/ssair/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -810,15 +810,19 @@ function show_ir(io::IO, ir::IRCode, config::IRShowConfig=default_config(ir);
pop_new_node! = new_nodes_iter(ir))
used = stmts_used(io, ir)
cfg = ir.cfg
show_ir_stmts(io, ir, 1:length(ir.stmts), config, used, cfg, 1; pop_new_node!)
let io = IOContext(io, :maxssaid=>length(ir.stmts))
show_ir_stmts(io, ir, 1:length(ir.stmts), config, used, cfg, 1; pop_new_node!)
end
finish_show_ir(io, cfg, config)
end

function show_ir(io::IO, ci::CodeInfo, config::IRShowConfig=default_config(ci);
pop_new_node! = Returns(nothing))
used = stmts_used(io, ci)
cfg = compute_basic_blocks(ci.code)
show_ir_stmts(io, ci, 1:length(ci.code), config, used, cfg, 1; pop_new_node!)
let io = IOContext(io, :maxssaid=>length(ci.code))
show_ir_stmts(io, ci, 1:length(ci.code), config, used, cfg, 1; pop_new_node!)
end
finish_show_ir(io, cfg, config)
end

Expand All @@ -837,7 +841,9 @@ function show_ir(io::IO, compact::IncrementalCompact, config::IRShowConfig=defau
end
end
pop_new_node! = new_nodes_iter(compact)
bb_idx = show_ir_stmts(io, compact, 1:compact.result_idx-1, config, used_compacted, cfg, 1; pop_new_node!)
bb_idx = let io = IOContext(io, :maxssaid=>length(compact.result))
show_ir_stmts(io, compact, 1:compact.result_idx-1, config, used_compacted, cfg, 1; pop_new_node!)
end

# Print uncompacted nodes from the original IR
stmts = compact.ir.stmts
Expand All @@ -847,8 +853,9 @@ function show_ir(io::IO, compact::IncrementalCompact, config::IRShowConfig=defau
# config.line_info_preprinter(io, "", compact.idx)
printstyled(io, ""^(width-indent-1), '\n', color=:red)
end

show_ir_stmts(io, compact.ir, compact.idx:length(stmts), config, used_uncompacted, cfg, bb_idx; pop_new_node!)
let io = IOContext(io, :maxssaid=>length(compact.ir.stmts))
show_ir_stmts(io, compact.ir, compact.idx:length(stmts), config, used_uncompacted, cfg, bb_idx; pop_new_node!)
end

finish_show_ir(io, cfg, config)
end
Expand Down
9 changes: 8 additions & 1 deletion base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1686,7 +1686,14 @@ end

## AST printing ##

show_unquoted(io::IO, val::SSAValue, ::Int, ::Int) = print(io, "%", val.id)
function show_unquoted(io::IO, val::SSAValue, ::Int, ::Int)
if get(io, :maxssaid, typemax(Int))::Int < val.id
# invalid SSAValue, print this in red for better recognition
printstyled(io, "%", val.id; color=:red)
else
print(io, "%", val.id)
end
end
show_unquoted(io::IO, sym::Symbol, ::Int, ::Int) = show_sym(io, sym, allow_macroname=false)
show_unquoted(io::IO, ex::LineNumberNode, ::Int, ::Int) = show_linenumber(io, ex.line, ex.file)
show_unquoted(io::IO, ex::GotoNode, ::Int, ::Int) = print(io, "goto %", ex.label)
Expand Down

2 comments on commit 36aab14

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your package evaluation job has completed - possible new issues were detected. A full report can be found here.

Please sign in to comment.