Skip to content

Commit 10134cf

Browse files
committed
make Base.return_types interface similar to code_typed
Especially, it should be more consistent with the other reflection utilities defined in reflection.jl if the optional `interp::AbstractInterpreter` argument is passed as keyword one.
1 parent 6635c1b commit 10134cf

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

base/reflection.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,11 +1291,12 @@ function code_typed_opaque_closure(@nospecialize(closure::Core.OpaqueClosure);
12911291
end
12921292
end
12931293

1294-
function return_types(@nospecialize(f), @nospecialize(types=default_tt(f)), interp=Core.Compiler.NativeInterpreter())
1294+
function return_types(@nospecialize(f), @nospecialize(types=default_tt(f));
1295+
world = get_world_counter(),
1296+
interp = Core.Compiler.NativeInterpreter(world))
12951297
ccall(:jl_is_in_pure_context, Bool, ()) && error("code reflection cannot be used from generated functions")
12961298
types = to_tuple_type(types)
12971299
rt = []
1298-
world = get_world_counter()
12991300
for match in _methods(f, types, -1, world)::Vector
13001301
match = match::Core.MethodMatch
13011302
meth = func_for_method_checked(match.method, types, match.sparams)

test/compiler/AbstractInterpreter.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,30 @@ import Base.Experimental: @MethodTable, @overlay
4242
CC.method_table(interp::MTOverlayInterp) = CC.OverlayMethodTable(CC.get_world_counter(interp), OverlayedMT)
4343

4444
@overlay OverlayedMT sin(x::Float64) = 1
45-
@test Base.return_types((Int,), MTOverlayInterp()) do x
45+
@test Base.return_types((Int,); interp=MTOverlayInterp()) do x
4646
sin(x)
4747
end == Any[Int]
48-
@test Base.return_types((Any,), MTOverlayInterp()) do x
48+
@test Base.return_types((Any,); interp=MTOverlayInterp()) do x
4949
Base.@invoke sin(x::Float64)
5050
end == Any[Int]
5151

5252
# fallback to the internal method table
53-
@test Base.return_types((Int,), MTOverlayInterp()) do x
53+
@test Base.return_types((Int,); interp=MTOverlayInterp()) do x
5454
cos(x)
5555
end == Any[Float64]
56-
@test Base.return_types((Any,), MTOverlayInterp()) do x
56+
@test Base.return_types((Any,); interp=MTOverlayInterp()) do x
5757
Base.@invoke cos(x::Float64)
5858
end == Any[Float64]
5959

6060
# not fully covered overlay method match
6161
overlay_match(::Any) = nothing
6262
@overlay OverlayedMT overlay_match(::Int) = missing
63-
@test Base.return_types((Any,), MTOverlayInterp()) do x
63+
@test Base.return_types((Any,); interp=MTOverlayInterp()) do x
6464
overlay_match(x)
6565
end == Any[Union{Nothing,Missing}]
6666

6767
# partial pure/concrete evaluation
68-
@test Base.return_types((), MTOverlayInterp()) do
68+
@test Base.return_types(; interp=MTOverlayInterp()) do
6969
isbitstype(Int) ? nothing : missing
7070
end == Any[Nothing]
7171
Base.@assume_effects :terminates_globally function issue41694(x)
@@ -77,6 +77,6 @@ Base.@assume_effects :terminates_globally function issue41694(x)
7777
end
7878
return res
7979
end
80-
@test Base.return_types((), MTOverlayInterp()) do
80+
@test Base.return_types(; interp=MTOverlayInterp()) do
8181
issue41694(3) == 6 ? nothing : missing
8282
end == Any[Nothing]

0 commit comments

Comments
 (0)