Skip to content

Commit

Permalink
effects: improve tri-state printing
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Jul 26, 2022
1 parent 1645d1d commit a1937ab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion base/compiler/ssair/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,11 @@ function show_ir(io::IO, code::Union{IRCode, CodeInfo}, config::IRShowConfig=def
end

tristate_letter(t::TriState) = t === ALWAYS_TRUE ? '+' : t === ALWAYS_FALSE ? '!' : '?'
tristate_color(t::TriState) = t === ALWAYS_TRUE ? :green : t === ALWAYS_FALSE ? :red : :orange
tristate_color(t::TriState) = t === ALWAYS_TRUE ? :green : t === ALWAYS_FALSE ? :red : :yellow
tristate_repr(t::TriState) =
t === ALWAYS_TRUE ? "ALWAYS_TRUE" :
t === ALWAYS_FALSE ? "ALWAYS_FALSE" :
t === TRISTATE_UNKNOWN ? "TRISTATE_UNKNOWN" : nothing

function Base.show(io::IO, e::Core.Compiler.Effects)
print(io, "(")
Expand All @@ -806,4 +810,13 @@ function Base.show(io::IO, e::Core.Compiler.Effects)
e.nonoverlayed || printstyled(io, ''; color=:red)
end

function Base.show(io::IO, t::TriState)
s = tristate_repr(t)
if s !== nothing
printstyled(io, s; color = tristate_color(t))
else # unknown state, redirect to the fallback printing
Base.@invoke show(io::IO, t::Any)
end
end

@specialize
2 changes: 1 addition & 1 deletion base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2490,7 +2490,7 @@ module IRShow
import ..Base
import .Compiler: IRCode, ReturnNode, GotoIfNot, CFG, scan_ssa_use!, Argument,
isexpr, compute_basic_blocks, block_for_inst,
TriState, Effects, ALWAYS_TRUE, ALWAYS_FALSE
TriState, Effects, ALWAYS_TRUE, ALWAYS_FALSE, TRISTATE_UNKNOWN
Base.getindex(r::Compiler.StmtRange, ind::Integer) = Compiler.getindex(r, ind)
Base.size(r::Compiler.StmtRange) = Compiler.size(r)
Base.first(r::Compiler.StmtRange) = Compiler.first(r)
Expand Down

0 comments on commit a1937ab

Please sign in to comment.