Skip to content

Commit df0080c

Browse files
authored
IRShow: use IOContext for PhiNodes/:invoke printing (#43226)
In order to allow `Argument`s to be printed nicely. > before ```julia julia> code_typed((Float64,)) do x sin(x) end 1-element Vector{Any}: CodeInfo( 1 ─ %1 = invoke Main.sin(_2::Float64)::Float64 └── return %1 ) => Float64 julia> code_typed((Bool,Any,Any)) do c, x, y z = c ? x : y z end 1-element Vector{Any}: CodeInfo( 1 ─ goto #3 if not c 2 ─ goto #4 3 ─ nothing::Nothing 4 ┄ %4 = φ (#2 => _3, #3 => _4)::Any └── return %4 ) => Any ``` > after ```julia julia> code_typed((Float64,)) do x sin(x) end 1-element Vector{Any}: CodeInfo( 1 ─ %1 = invoke Main.sin(x::Float64)::Float64 └── return %1 ) => Float64 julia> code_typed((Bool,Any,Any)) do c, x, y z = c ? x : y z end 1-element Vector{Any}: CodeInfo( 1 ─ goto #3 if not c 2 ─ goto #4 3 ─ nothing::Nothing 4 ┄ %4 = φ (#2 => x, #3 => y)::Any └── return %4 ) => Any ```
1 parent 4170090 commit df0080c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

base/compiler/ssair/show.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function print_stmt(io::IO, idx::Int, @nospecialize(stmt), used::BitSet, maxleng
4747
# XXX: this is wrong if `sig` is not a concretetype method
4848
# more correct would be to use `fieldtype(sig, i)`, but that would obscure / discard Varargs information in show
4949
sig = linfo.specTypes == Tuple ? Core.svec() : Base.unwrap_unionall(linfo.specTypes).parameters::Core.SimpleVector
50-
print_arg(i) = sprint() do io
50+
print_arg(i) = sprint(; context=io) do io
5151
show_unquoted(io, stmt.args[i], indent)
5252
if (i - 1) <= length(sig)
5353
print(io, "::", sig[i - 1])
@@ -82,7 +82,7 @@ function show_unquoted_phinode(io::IO, stmt::PhiNode, indent::Int, prefix::Strin
8282
args = String[let
8383
e = stmt.edges[i]
8484
v = !isassigned(stmt.values, i) ? "#undef" :
85-
sprint() do io′
85+
sprint(; context=io) do io′
8686
show_unquoted(io′, stmt.values[i], indent)
8787
end
8888
"$prefix$e => $v"

0 commit comments

Comments
 (0)