Skip to content

Commit 8415804

Browse files
committed
IRShow: Print type of arg0 for invoke when necessary
When invoking any "functor-like", such as a closure: ```julia bar(x) = @noinline ((y)->x+y)(x) ``` our IR printing was not showing the arg0 invoked, even when it is required to determine which MethodInstance this is invoking. Before: ``` julia> @code_typed optimize=true bar(1) CodeInfo( 1 ─ %1 = %new(var"#bar##2#bar##3"{Int64}, x)::var"#bar##2#bar##3"{Int64} │ %2 = invoke %1(x::Int64)::Int64 └── return %2 ) => Int64 ``` After: ``` julia> @code_typed optimize=true bar(1) CodeInfo( 1 ─ %1 = %new(var"#bar##2#bar##3"{Int64}, x)::var"#bar##2#bar##3"{Int64} │ %2 = invoke (%1::var"#bar##2#bar##3"{Int64})(x::Int64)::Int64 └── return %2 ) => Int64 ```
1 parent 2f57a31 commit 8415804

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Compiler/src/ssair/show.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,17 @@ function print_stmt(io::IO, idx::Int, @nospecialize(stmt), code::Union{IRCode,Co
105105
printstyled(io, "dynamic invoke "; color = :yellow)
106106
abi = (ci::Core.MethodInstance).specTypes
107107
end
108-
show_unquoted(io, stmt.args[2], indent)
109-
print(io, "(")
110108
# XXX: this is wrong if `sig` is not a concretetype method
111109
# more correct would be to use `fieldtype(sig, i)`, but that would obscure / discard Varargs information in show
112110
sig = abi == Tuple ? Core.svec() : Base.unwrap_unionall(abi).parameters::Core.SimpleVector
111+
if singleton_type(sig[1]) === stmt.args
112+
show_unquoted(io, stmt.args[2], indent)
113+
else
114+
print(io, "(")
115+
show_unquoted(io, stmt.args[2], indent)
116+
print(io, "::", sig[1], ")")
117+
end
118+
print(io, "(")
113119
print_arg(i) = sprint(; context=io) do io
114120
show_unquoted(io, stmt.args[i], indent)
115121
if (i - 1) <= length(sig)

0 commit comments

Comments
 (0)