Skip to content

Commit a4a04a4

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 a4a04a4

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Compiler/src/ssair/show.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,18 @@ 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+
ft = maybe_argextype(stmt.args[2], code, sptypes)
112+
if stmt.args[2] isa GlobalRef && (singleton_type(ft) === singleton_type(sig[1]) !== nothing)
113+
show_unquoted(io, stmt.args[2], indent)
114+
else
115+
print(io, "(")
116+
show_unquoted(io, stmt.args[2], indent)
117+
print(io, "::", sig[1], ")")
118+
end
119+
print(io, "(")
113120
print_arg(i) = sprint(; context=io) do io
114121
show_unquoted(io, stmt.args[i], indent)
115122
if (i - 1) <= length(sig)

0 commit comments

Comments
 (0)