Skip to content

Commit

Permalink
inference: fix return_type_tfunc modeling of concrete functions (#51042)
Browse files Browse the repository at this point in the history
The `aft` parameter is a value already, so we should be checking it in
the value domain, not the type domain like `tt`. That check happens to
already be done (somewhat unnecessarily) earlier in the function.

Fixes #40606

---------

Co-authored-by: Shuhei Kadowaki <[email protected]>
(cherry picked from commit f24a93a)
  • Loading branch information
vtjnash authored and nalimilan committed Nov 5, 2023
1 parent df1bea5 commit 2aab43e
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2620,13 +2620,15 @@ function return_type_tfunc(interp::AbstractInterpreter, argtypes::Vector{Any}, s

if length(argtypes) == 3
aft = widenslotwrapper(argtypes[2])
if !isa(aft, Const) && !(isType(aft) && !has_free_typevars(aft)) &&
!(isconcretetype(aft) && !(aft <: Builtin))
return UNKNOWN
end
argtypes_vec = Any[aft, af_argtype.parameters...]
else
argtypes_vec = Any[af_argtype.parameters...]
isempty(argtypes_vec) && push!(argtypes_vec, Union{})
aft = argtypes_vec[1]
end
if !(isa(aft, Const) || (isType(aft) && !has_free_typevars(aft)) ||
(isconcretetype(aft) && !(aft <: Builtin) && !iskindtype(aft)))
return UNKNOWN
end

if contains_is(argtypes_vec, Union{})
Expand Down Expand Up @@ -2659,8 +2661,7 @@ function return_type_tfunc(interp::AbstractInterpreter, argtypes::Vector{Any}, s
# in two ways: both as being a subtype of this, and
# because of LimitedAccuracy causes
return CallMeta(Type{<:rt}, EFFECTS_TOTAL, info)
elseif (isa(tt, Const) || isconstType(tt)) &&
(isa(aft, Const) || isconstType(aft))
elseif isa(tt, Const) || isconstType(tt)
# input arguments were known for certain
# XXX: this doesn't imply we know anything about rt
return CallMeta(Const(rt), EFFECTS_TOTAL, info)
Expand Down

0 comments on commit 2aab43e

Please sign in to comment.