@@ -970,7 +970,7 @@ function sp_type_rewrap(@nospecialize(T), linfo::MethodInstance, isreturn::Bool)
970
970
end
971
971
972
972
function abstract_eval_cfunction (interp:: AbstractInterpreter , e:: Expr , vtypes:: VarTable , sv:: InferenceState )
973
- f = abstract_eval (interp, e. args[2 ], vtypes, sv)
973
+ f = abstract_eval_value (interp, e. args[2 ], vtypes, sv)
974
974
# rt = sp_type_rewrap(e.args[3], sv.linfo, true)
975
975
at = Any[ sp_type_rewrap (argt, sv. linfo, false ) for argt in e. args[4 ]:: SimpleVector ]
976
976
pushfirst! (at, f)
@@ -981,7 +981,21 @@ function abstract_eval_cfunction(interp::AbstractInterpreter, e::Expr, vtypes::V
981
981
nothing
982
982
end
983
983
984
- function abstract_eval (interp:: AbstractInterpreter , @nospecialize (e), vtypes:: VarTable , sv:: InferenceState )
984
+ function abstract_eval_value_expr (interp:: AbstractInterpreter , e:: Expr , vtypes:: VarTable , sv:: InferenceState )
985
+ if e. head === :static_parameter
986
+ n = e. args[1 ]
987
+ t = Any
988
+ if 1 <= n <= length (sv. sptypes)
989
+ t = sv. sptypes[n]
990
+ end
991
+ elseif e. head === :boundscheck
992
+ return Bool
993
+ else
994
+ return Any
995
+ end
996
+ end
997
+
998
+ function abstract_eval_special_value (interp:: AbstractInterpreter , @nospecialize (e), vtypes:: VarTable , sv:: InferenceState )
985
999
if isa (e, QuoteNode)
986
1000
return AbstractEvalConstant ((e:: QuoteNode ). value)
987
1001
elseif isa (e, SSAValue)
@@ -992,31 +1006,44 @@ function abstract_eval(interp::AbstractInterpreter, @nospecialize(e), vtypes::Va
992
1006
return abstract_eval_global (e. mod, e. name)
993
1007
end
994
1008
1009
+ return AbstractEvalConstant (e)
1010
+ end
1011
+
1012
+ function abstract_eval_value (interp:: AbstractInterpreter , @nospecialize (e), vtypes:: VarTable , sv:: InferenceState )
1013
+ if isa (e, Expr)
1014
+ return abstract_eval_value_expr (interp, e, vtypes, sv)
1015
+ else
1016
+ return abstract_eval_special_value (interp, e, vtypes, sv)
1017
+ end
1018
+ end
1019
+
1020
+ function abstract_eval_statement (interp:: AbstractInterpreter , @nospecialize (e), vtypes:: VarTable , sv:: InferenceState )
995
1021
if ! isa (e, Expr)
996
- return AbstractEvalConstant (e )
1022
+ return abstract_eval_special_value (interp, e, vtypes, sv )
997
1023
end
1024
+
998
1025
e = e:: Expr
999
1026
if e. head === :call
1000
1027
ea = e. args
1001
1028
n = length (ea)
1002
1029
argtypes = Vector {Any} (undef, n)
1003
1030
@inbounds for i = 1 : n
1004
- ai = abstract_eval (interp, ea[i], vtypes, sv)
1031
+ ai = abstract_eval_value (interp, ea[i], vtypes, sv)
1005
1032
if ai === Bottom
1006
1033
return Bottom
1007
1034
end
1008
1035
argtypes[i] = ai
1009
1036
end
1010
1037
t = abstract_call (interp, ea, argtypes, vtypes, sv)
1011
1038
elseif e. head === :new
1012
- t = instanceof_tfunc (abstract_eval (interp, e. args[1 ], vtypes, sv))[1 ]
1039
+ t = instanceof_tfunc (abstract_eval_value (interp, e. args[1 ], vtypes, sv))[1 ]
1013
1040
if isconcretetype (t) && ! t. mutable
1014
1041
args = Vector {Any} (undef, length (e. args)- 1 )
1015
1042
ats = Vector {Any} (undef, length (e. args)- 1 )
1016
1043
anyconst = false
1017
1044
allconst = true
1018
1045
for i = 2 : length (e. args)
1019
- at = abstract_eval (interp, e. args[i], vtypes, sv)
1046
+ at = abstract_eval_value (interp, e. args[i], vtypes, sv)
1020
1047
if ! anyconst
1021
1048
anyconst = has_nontrivial_const_info (at)
1022
1049
end
@@ -1046,9 +1073,9 @@ function abstract_eval(interp::AbstractInterpreter, @nospecialize(e), vtypes::Va
1046
1073
end
1047
1074
end
1048
1075
elseif e. head === :splatnew
1049
- t = instanceof_tfunc (abstract_eval (interp, e. args[1 ], vtypes, sv))[1 ]
1076
+ t = instanceof_tfunc (abstract_eval_value (interp, e. args[1 ], vtypes, sv))[1 ]
1050
1077
if length (e. args) == 2 && isconcretetype (t) && ! t. mutable
1051
- at = abstract_eval (interp, e. args[2 ], vtypes, sv)
1078
+ at = abstract_eval_value (interp, e. args[2 ], vtypes, sv)
1052
1079
n = fieldcount (t)
1053
1080
if isa (at, Const) && isa (at. val, Tuple) && n == length (at. val) &&
1054
1081
_all (i-> at. val[i] isa fieldtype (t, i), 1 : n)
@@ -1059,35 +1086,27 @@ function abstract_eval(interp::AbstractInterpreter, @nospecialize(e), vtypes::Va
1059
1086
end
1060
1087
end
1061
1088
elseif e. head === :foreigncall
1062
- abstract_eval (interp, e. args[1 ], vtypes, sv)
1089
+ abstract_eval_value (interp, e. args[1 ], vtypes, sv)
1063
1090
t = sp_type_rewrap (e. args[2 ], sv. linfo, true )
1064
1091
for i = 3 : length (e. args)
1065
- if abstract_eval (interp, e. args[i], vtypes, sv) === Bottom
1092
+ if abstract_eval_value (interp, e. args[i], vtypes, sv) === Bottom
1066
1093
t = Bottom
1067
1094
end
1068
1095
end
1069
1096
elseif e. head === :cfunction
1070
1097
t = e. args[1 ]
1071
1098
isa (t, Type) || (t = Any)
1072
1099
abstract_eval_cfunction (interp, e, vtypes, sv)
1073
- elseif e. head === :static_parameter
1074
- n = e. args[1 ]
1075
- t = Any
1076
- if 1 <= n <= length (sv. sptypes)
1077
- t = sv. sptypes[n]
1078
- end
1079
1100
elseif e. head === :method
1080
1101
t = (length (e. args) == 1 ) ? Any : Nothing
1081
1102
elseif e. head === :copyast
1082
- t = abstract_eval (interp, e. args[1 ], vtypes, sv)
1103
+ t = abstract_eval_value (interp, e. args[1 ], vtypes, sv)
1083
1104
if t isa Const && t. val isa Expr
1084
1105
# `copyast` makes copies of Exprs
1085
1106
t = Expr
1086
1107
end
1087
1108
elseif e. head === :invoke
1088
1109
error (" type inference data-flow error: tried to double infer a function" )
1089
- elseif e. head === :boundscheck
1090
- return Bool
1091
1110
elseif e. head === :isdefined
1092
1111
sym = e. args[1 ]
1093
1112
t = Bool
@@ -1116,7 +1135,7 @@ function abstract_eval(interp::AbstractInterpreter, @nospecialize(e), vtypes::Va
1116
1135
end
1117
1136
end
1118
1137
else
1119
- t = Any
1138
+ return abstract_eval_value_expr (interp, e, vtypes, sv)
1120
1139
end
1121
1140
@assert ! isa (t, TypeVar)
1122
1141
if isa (t, DataType) && isdefined (t, :instance )
@@ -1175,7 +1194,7 @@ function typeinf_local(interp::AbstractInterpreter, frame::InferenceState)
1175
1194
elseif isa (stmt, GotoNode)
1176
1195
pc´ = (stmt:: GotoNode ). label
1177
1196
elseif isa (stmt, GotoIfNot)
1178
- condt = abstract_eval (interp, stmt. cond, s[pc], frame)
1197
+ condt = abstract_eval_value (interp, stmt. cond, s[pc], frame)
1179
1198
if condt === Bottom
1180
1199
break
1181
1200
end
@@ -1209,7 +1228,7 @@ function typeinf_local(interp::AbstractInterpreter, frame::InferenceState)
1209
1228
end
1210
1229
elseif isa (stmt, ReturnNode)
1211
1230
pc´ = n + 1
1212
- rt = widenconditional (abstract_eval (interp, stmt. val, s[pc], frame))
1231
+ rt = widenconditional (abstract_eval_value (interp, stmt. val, s[pc], frame))
1213
1232
if ! isa (rt, Const) && ! isa (rt, Type) && ! isa (rt, PartialStruct)
1214
1233
# only propagate information we know we can store
1215
1234
# and is valid inter-procedurally
@@ -1254,7 +1273,7 @@ function typeinf_local(interp::AbstractInterpreter, frame::InferenceState)
1254
1273
end
1255
1274
else
1256
1275
if hd === :(= )
1257
- t = abstract_eval (interp, stmt. args[2 ], changes, frame)
1276
+ t = abstract_eval_statement (interp, stmt. args[2 ], changes, frame)
1258
1277
t === Bottom && break
1259
1278
frame. src. ssavaluetypes[pc] = t
1260
1279
lhs = stmt. args[1 ]
@@ -1269,7 +1288,7 @@ function typeinf_local(interp::AbstractInterpreter, frame::InferenceState)
1269
1288
elseif hd === :inbounds || hd === :meta || hd === :loopinfo || hd == :code_coverage_effect
1270
1289
# these do not generate code
1271
1290
else
1272
- t = abstract_eval (interp, stmt, changes, frame)
1291
+ t = abstract_eval_statement (interp, stmt, changes, frame)
1273
1292
t === Bottom && break
1274
1293
if ! isempty (frame. ssavalue_uses[pc])
1275
1294
record_ssa_assign (pc, t, frame)
0 commit comments