Skip to content

Commit 6f90d51

Browse files
committed
make Base.return_types interface similar to code_typed (#44533)
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 7ae3491 commit 6f90d51

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
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: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,30 +43,30 @@ CC.method_table(interp::MTOverlayInterp) = CC.OverlayMethodTable(CC.get_world_co
4343

4444
strangesin(x) = sin(x)
4545
@overlay OverlayedMT strangesin(x::Float64) = iszero(x) ? nothing : cos(x)
46-
@test Base.return_types((Float64,); MTOverlayInterp()) do x
46+
@test Base.return_types((Float64,); interp=MTOverlayInterp()) do x
4747
strangesin(x)
4848
end |> only === Union{Float64,Nothing}
49-
@test Base.return_types((Any,); MTOverlayInterp()) do x
49+
@test Base.return_types((Any,); interp=MTOverlayInterp()) do x
5050
Base.@invoke strangesin(x::Float64)
5151
end |> only === Union{Float64,Nothing}
5252

5353
# fallback to the internal method table
54-
@test Base.return_types((Int,), MTOverlayInterp()) do x
54+
@test Base.return_types((Int,); interp=MTOverlayInterp()) do x
5555
cos(x)
5656
end |> only === Float64
57-
@test Base.return_types((Any,); MTOverlayInterp()) do x
57+
@test Base.return_types((Any,); interp=MTOverlayInterp()) do x
5858
Base.@invoke cos(x::Float64)
5959
end |> only === Float64
6060

6161
# not fully covered overlay method match
6262
overlay_match(::Any) = nothing
6363
@overlay OverlayedMT overlay_match(::Int) = missing
64-
@test Base.return_types((Any,), MTOverlayInterp()) do x
64+
@test Base.return_types((Any,); interp=MTOverlayInterp()) do x
6565
overlay_match(x)
6666
end |> only === Union{Nothing,Missing}
6767

6868
# partial pure/concrete evaluation
69-
@test Base.return_types((), MTOverlayInterp()) do
69+
@test Base.return_types(; interp=MTOverlayInterp()) do
7070
isbitstype(Int) ? nothing : missing
7171
end |> only === Nothing
7272
Base.@assume_effects :terminates_globally function issue41694(x)
@@ -78,13 +78,13 @@ Base.@assume_effects :terminates_globally function issue41694(x)
7878
end
7979
return res
8080
end
81-
@test Base.return_types((), MTOverlayInterp()) do
81+
@test Base.return_types(; interp=MTOverlayInterp()) do
8282
issue41694(3) == 6 ? nothing : missing
8383
end |> only === Nothing
8484

8585
# disable partial pure/concrete evaluation when tainted by any overlayed call
8686
Base.@assume_effects :total totalcall(f, args...) = f(args...)
87-
@test Base.return_types(; MTOverlayInterp()) do
87+
@test Base.return_types(; interp=MTOverlayInterp()) do
8888
if totalcall(strangesin, 1.0) == cos(1.0)
8989
return nothing
9090
else

0 commit comments

Comments
 (0)