Skip to content

Commit 180db15

Browse files
committed
Handle svec, arrayset, and arrayref in normal tfuncs
1 parent 8ab1ece commit 180db15

File tree

1 file changed

+22
-29
lines changed

1 file changed

+22
-29
lines changed

base/compiler/tfuncs.jl

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ function nfields_tfunc(@nospecialize(x))
390390
end
391391
add_tfunc(nfields, 1, 1, nfields_tfunc, 1)
392392
add_tfunc(Core._expr, 1, INT_INF, (@nospecialize args...)->Expr, 100)
393+
add_tfunc(svec, 0, INT_INF, (@nospecialize args...)->SimpleVector, 20)
393394
function typevar_tfunc(@nospecialize(n), @nospecialize(lb_arg), @nospecialize(ub_arg))
394395
lb = Union{}
395396
ub = Any
@@ -1300,6 +1301,26 @@ function tuple_tfunc(atypes::Vector{Any})
13001301
return anyinfo ? PartialStruct(typ, atypes) : typ
13011302
end
13021303

1304+
function arrayref_tfunc(@nospecialize(boundscheck), @nospecialize(a), @nospecialize i...)
1305+
a = widenconst(a)
1306+
if a <: Array
1307+
if isa(a, DataType) && (isa(a.parameters[1], Type) || isa(a.parameters[1], TypeVar))
1308+
# TODO: the TypeVar case should not be needed here
1309+
a = a.parameters[1]
1310+
return isa(a, TypeVar) ? a.ub : a
1311+
elseif isa(a, UnionAll) && !has_free_typevars(a)
1312+
unw = unwrap_unionall(a)
1313+
if isa(unw, DataType)
1314+
return rewrap_unionall(unw.parameters[1], a)
1315+
end
1316+
end
1317+
end
1318+
return Any
1319+
end
1320+
add_tfunc(arrayref, 3, INT_INF, arrayref_tfunc, 20)
1321+
add_tfunc(const_arrayref, 3, INT_INF, arrayref_tfunc, 20)
1322+
add_tfunc(arrayset, 4, INT_INF, (@nospecialize(boundscheck), @nospecialize(a), @nospecialize(v), @nospecialize i...)->a, 20)
1323+
13031324
function array_type_undefable(@nospecialize(a))
13041325
if isa(a, Union)
13051326
return array_type_undefable(a.a) || array_type_undefable(a.b)
@@ -1390,36 +1411,8 @@ end
13901411

13911412
function builtin_tfunction(interp::AbstractInterpreter, @nospecialize(f), argtypes::Array{Any,1},
13921413
sv::Union{InferenceState,Nothing})
1393-
isva = !isempty(argtypes) && isvarargtype(argtypes[end])
13941414
if f === tuple
13951415
return tuple_tfunc(argtypes)
1396-
elseif f === svec
1397-
return SimpleVector
1398-
elseif f === arrayset
1399-
if length(argtypes) < 4
1400-
isva && return Any
1401-
return Bottom
1402-
end
1403-
return argtypes[2]
1404-
elseif f === arrayref || f === const_arrayref
1405-
if length(argtypes) < 3
1406-
isva && return Any
1407-
return Bottom
1408-
end
1409-
a = widenconst(argtypes[2])
1410-
if a <: Array
1411-
if isa(a, DataType) && (isa(a.parameters[1], Type) || isa(a.parameters[1], TypeVar))
1412-
# TODO: the TypeVar case should not be needed here
1413-
a = a.parameters[1]
1414-
return isa(a, TypeVar) ? a.ub : a
1415-
elseif isa(a, UnionAll) && !has_free_typevars(a)
1416-
unw = unwrap_unionall(a)
1417-
if isa(unw, DataType)
1418-
return rewrap_unionall(unw.parameters[1], a)
1419-
end
1420-
end
1421-
end
1422-
return Any
14231416
elseif f === invoke
14241417
if length(argtypes) > 1 && sv !== nothing && (isa(argtypes[1], Const) || isa(argtypes[1], Type))
14251418
if isa(argtypes[1], Const)
@@ -1464,7 +1457,7 @@ function builtin_tfunction(interp::AbstractInterpreter, @nospecialize(f), argtyp
14641457
tf = T_FFUNC_VAL[fidx]
14651458
end
14661459
tf = tf::Tuple{Int, Int, Any}
1467-
if isva
1460+
if !isempty(argtypes) && isvarargtype(argtypes[end])
14681461
if length(argtypes) - 1 > tf[2]
14691462
# definitely too many arguments
14701463
return Bottom

0 commit comments

Comments
 (0)