Skip to content

Commit

Permalink
IRShow: use IOContext for PhiNodes/:invoke printing (JuliaLang#…
Browse files Browse the repository at this point in the history
…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
```
  • Loading branch information
aviatesk authored Nov 26, 2021
1 parent 4170090 commit df0080c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/compiler/ssair/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function print_stmt(io::IO, idx::Int, @nospecialize(stmt), used::BitSet, maxleng
# XXX: this is wrong if `sig` is not a concretetype method
# more correct would be to use `fieldtype(sig, i)`, but that would obscure / discard Varargs information in show
sig = linfo.specTypes == Tuple ? Core.svec() : Base.unwrap_unionall(linfo.specTypes).parameters::Core.SimpleVector
print_arg(i) = sprint() do io
print_arg(i) = sprint(; context=io) do io
show_unquoted(io, stmt.args[i], indent)
if (i - 1) <= length(sig)
print(io, "::", sig[i - 1])
Expand Down Expand Up @@ -82,7 +82,7 @@ function show_unquoted_phinode(io::IO, stmt::PhiNode, indent::Int, prefix::Strin
args = String[let
e = stmt.edges[i]
v = !isassigned(stmt.values, i) ? "#undef" :
sprint() do io′
sprint(; context=io) do io′
show_unquoted(io′, stmt.values[i], indent)
end
"$prefix$e => $v"
Expand Down

0 comments on commit df0080c

Please sign in to comment.