Skip to content

Commit

Permalink
fix Base.return_types for direct builtin calls (#46443)
Browse files Browse the repository at this point in the history
This commit also changed this fragile test case
```
@test Base.return_types(Expr) == Any[Expr]
```
to
```
@test only(Base.return_types(Core._expr)) === Expr
```
since `Expr` is just a generic function and can be overloaded
in the future (e.g. the JuliaSyntax.jl integration PR).
  • Loading branch information
aviatesk authored Aug 23, 2022
1 parent df3da05 commit 18fa383
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
40 changes: 22 additions & 18 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1402,14 +1402,19 @@ function return_types(@nospecialize(f), @nospecialize(types=default_tt(f));
return Any[rt]
end
types = to_tuple_type(types)
rt = []
if isa(f, Core.Builtin)
argtypes = Any[types.parameters...]
rt = Core.Compiler.builtin_tfunction(interp, f, argtypes, nothing)
return Any[rt]
end
rts = []
for match in _methods(f, types, -1, world)::Vector
match = match::Core.MethodMatch
meth = func_for_method_checked(match.method, types, match.sparams)
ty = Core.Compiler.typeinf_type(interp, meth, match.spec_types, match.sparams)
push!(rt, something(ty, Any))
push!(rts, something(ty, Any))
end
return rt
return rts
end

function infer_effects(@nospecialize(f), @nospecialize(types=default_tt(f));
Expand All @@ -1421,22 +1426,21 @@ function infer_effects(@nospecialize(f), @nospecialize(types=default_tt(f));
argtypes = Any[types.parameters...]
rt = Core.Compiler.builtin_tfunction(interp, f, argtypes, nothing)
return Core.Compiler.builtin_effects(f, argtypes, rt)
else
effects = Core.Compiler.EFFECTS_TOTAL
matches = _methods(f, types, -1, world)::Vector
if isempty(matches)
# this call is known to throw MethodError
return Core.Compiler.Effects(effects; nothrow=false)
end
for match in matches
match = match::Core.MethodMatch
frame = Core.Compiler.typeinf_frame(interp,
match.method, match.spec_types, match.sparams, #=run_optimizer=#false)
frame === nothing && return Core.Compiler.Effects()
effects = Core.Compiler.merge_effects(effects, frame.ipo_effects)
end
return effects
end
effects = Core.Compiler.EFFECTS_TOTAL
matches = _methods(f, types, -1, world)::Vector
if isempty(matches)
# this call is known to throw MethodError
return Core.Compiler.Effects(effects; nothrow=false)
end
for match in matches
match = match::Core.MethodMatch
frame = Core.Compiler.typeinf_frame(interp,
match.method, match.spec_types, match.sparams, #=run_optimizer=#false)
frame === nothing && return Core.Compiler.Effects()
effects = Core.Compiler.merge_effects(effects, frame.ipo_effects)
end
return effects
end

"""
Expand Down
3 changes: 2 additions & 1 deletion test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3324,7 +3324,8 @@ f_generator_splat(t::Tuple) = tuple((identity(l) for l in t)...)
@test Core.Compiler.sizeof_tfunc(UnionAll) === Int
@test !Core.Compiler.sizeof_nothrow(UnionAll)

@test Base.return_types(Expr) == Any[Expr]
@test only(Base.return_types(Core._expr)) === Expr
@test only(Base.return_types(Core.svec, (Any,))) === Core.SimpleVector

# Use a global constant to rely less on unrelated constant propagation
const const_int32_typename = Int32.name
Expand Down
2 changes: 1 addition & 1 deletion test/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ end

@test which(===, Tuple{Int, Int}) isa Method
@test length(code_typed(===, Tuple{Int, Int})) === 1
@test only(Base.return_types(===, Tuple{Int, Int})) === Any
@test only(Base.return_types(===, Tuple{Int, Int})) === Bool

module TestingExported
using Test
Expand Down

2 comments on commit 18fa383

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your package evaluation job has completed - possible new issues were detected. A full report can be found here.

Please sign in to comment.