Skip to content

Commit 2b48e8e

Browse files
committed
effects: improve tri-state printing
1 parent 815e470 commit 2b48e8e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

base/compiler/ssair/show.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,11 @@ function show_ir(io::IO, code::Union{IRCode, CodeInfo}, config::IRShowConfig=def
791791
end
792792

793793
tristate_letter(t::TriState) = t === ALWAYS_TRUE ? '+' : t === ALWAYS_FALSE ? '!' : '?'
794-
tristate_color(t::TriState) = t === ALWAYS_TRUE ? :green : t === ALWAYS_FALSE ? :red : :orange
794+
tristate_color(t::TriState) = t === ALWAYS_TRUE ? :green : t === ALWAYS_FALSE ? :red : :yellow
795+
tristate_repr(t::TriState) =
796+
t === ALWAYS_TRUE ? "ALWAYS_TRUE" :
797+
t === ALWAYS_FALSE ? "ALWAYS_FALSE" :
798+
t === TRISTATE_UNKNOWN ? "TRISTATE_UNKNOWN" : nothing
795799

796800
function Base.show(io::IO, e::Core.Compiler.Effects)
797801
print(io, "(")
@@ -808,4 +812,13 @@ function Base.show(io::IO, e::Core.Compiler.Effects)
808812
e.nonoverlayed || printstyled(io, ''; color=:red)
809813
end
810814

815+
function Base.show(io::IO, t::TriState)
816+
s = tristate_repr(t)
817+
if s !== nothing
818+
printstyled(io, s; color = tristate_color(t))
819+
else # unknown state, redirect to the fallback printing
820+
Base.@invoke show(io::IO, t::Any)
821+
end
822+
end
823+
811824
@specialize

base/show.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2558,7 +2558,7 @@ module IRShow
25582558
import ..Base
25592559
import .Compiler: IRCode, ReturnNode, GotoIfNot, CFG, scan_ssa_use!, Argument,
25602560
isexpr, compute_basic_blocks, block_for_inst,
2561-
TriState, Effects, ALWAYS_TRUE, ALWAYS_FALSE
2561+
TriState, Effects, ALWAYS_TRUE, ALWAYS_FALSE, TRISTATE_UNKNOWN
25622562
Base.getindex(r::Compiler.StmtRange, ind::Integer) = Compiler.getindex(r, ind)
25632563
Base.size(r::Compiler.StmtRange) = Compiler.size(r)
25642564
Base.first(r::Compiler.StmtRange) = Compiler.first(r)

0 commit comments

Comments
 (0)