Skip to content

Commit 7f1d6d9

Browse files
committed
Support "Functor-like" code_typed invocation
This allows you to call, e.g., `code_typed((Foo, Int, Int))` to query the code for `(::Foo)(::Int, ::Int)`
1 parent 0d4d6d9 commit 7f1d6d9

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

base/reflection.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,13 @@ julia> code_typed(+, (Float64, Float64))
211211
1 ─ %1 = Base.add_float(x, y)::Float64
212212
└── return %1
213213
) => Float64
214+
215+
julia> code_typed((typeof(-), Float64, Float64))
216+
1-element Vector{Any}:
217+
CodeInfo(
218+
1 ─ %1 = Base.sub_float(x, y)::Float64
219+
└── return %1
220+
) => Float64
214221
```
215222
"""
216223
function code_typed(@nospecialize(f), @nospecialize(types=default_tt(f)); kwargs...)
@@ -221,6 +228,12 @@ function code_typed(@nospecialize(f), @nospecialize(types=default_tt(f)); kwargs
221228
return code_typed_by_type(tt; kwargs...)
222229
end
223230

231+
# support 'functor'-like queries, such as `(::Foo)(::Int, ::Int)` via `code_typed((Foo, Int, Int))`
232+
function code_typed(@nospecialize(types::Union{Tuple,Type{<:Tuple}}); kwargs...)
233+
tt = to_tuple_type(types)
234+
return code_typed_by_type(tt; kwargs...)
235+
end
236+
224237
# returns argument tuple type which is supposed to be used for `code_typed` and its family;
225238
# if there is a single method this functions returns the method argument signature,
226239
# otherwise returns `Tuple` that doesn't match with any signature

0 commit comments

Comments
 (0)