From 2aab43eea7bdb31f8a98a1f86ab2b34af788dbd3 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Sun, 27 Aug 2023 01:08:19 -0400 Subject: [PATCH] inference: fix return_type_tfunc modeling of concrete functions (#51042) 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 <40514306+aviatesk@users.noreply.github.com> (cherry picked from commit f24a93a3f6607f569c739cbcd3a84d21bdc6c908) --- base/compiler/tfuncs.jl | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/base/compiler/tfuncs.jl b/base/compiler/tfuncs.jl index bc5c4240ac2224..eae04021342d01 100644 --- a/base/compiler/tfuncs.jl +++ b/base/compiler/tfuncs.jl @@ -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{}) @@ -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)