43
43
type InferenceState
44
44
sp:: SimpleVector # static parameters
45
45
label_counter:: Int # index of the current highest label for this function
46
- fedbackvars:: Dict{SSAValue, Bool}
47
46
mod:: Module
48
47
currpc:: LineNum
49
- static_typeof:: Bool
50
48
51
49
# info on the state of inference and the linfo
52
50
linfo:: LambdaInfo
@@ -71,7 +69,6 @@ type InferenceState
71
69
backedges:: Vector{Tuple{InferenceState, Vector{LineNum}}}
72
70
# iteration fixed-point detection
73
71
fixedpoint:: Bool
74
- typegotoredo:: Bool
75
72
inworkq:: Bool
76
73
# optimization
77
74
optimize:: Bool
@@ -158,13 +155,13 @@ type InferenceState
158
155
159
156
inmodule = isdefined (linfo, :def ) ? linfo. def. module : current_module () # toplevel thunks are inferred in the current module
160
157
frame = new (
161
- sp, nl, Dict {SSAValue, Bool} (), inmodule, 0 , false ,
158
+ sp, nl, inmodule, 0 ,
162
159
linfo, la, s, Union{}, W, n,
163
160
cur_hand, handler_at, n_handlers,
164
161
ssavalue_uses, ssavalue_init,
165
162
ObjectIdDict (), # Dict{InferenceState, Vector{LineNum}}(),
166
163
Vector {Tuple{InferenceState, Vector{LineNum}}} (),
167
- false , false , false , optimize, inlining, needtree, false )
164
+ false , false , optimize, inlining, needtree, false )
168
165
push! (active, frame)
169
166
nactive[] += 1
170
167
return frame
@@ -1068,8 +1065,6 @@ function abstract_eval(e::ANY, vtypes::VarTable, sv::InferenceState)
1068
1065
return abstract_eval_constant (e)
1069
1066
end
1070
1067
e = e:: Expr
1071
- # handle:
1072
- # call null new & static_typeof
1073
1068
if is (e. head,:call )
1074
1069
t = abstract_eval_call (e, vtypes, sv)
1075
1070
elseif is (e. head,:null )
@@ -1103,42 +1098,6 @@ function abstract_eval(e::ANY, vtypes::VarTable, sv::InferenceState)
1103
1098
t = abstract_eval_constant (val)
1104
1099
end
1105
1100
end
1106
- elseif is (e. head,:static_typeof )
1107
- var = e. args[1 ]
1108
- t = widenconst (abstract_eval (var, vtypes, sv))
1109
- if isa (t,DataType) && typeseq (t,t. name. primary)
1110
- # remove unnecessary typevars
1111
- t = t. name. primary
1112
- end
1113
- if is (t,Bottom)
1114
- # if we haven't gotten fed-back type info yet, return Bottom. otherwise
1115
- # Bottom is the actual type of the variable, so return Type{Bottom}.
1116
- if get! (sv. fedbackvars, var, false )
1117
- t = Type{Bottom}
1118
- else
1119
- sv. static_typeof = true
1120
- end
1121
- elseif isleaftype (t)
1122
- t = Type{t}
1123
- elseif isleaftype (sv. linfo. specTypes)
1124
- if isa (t,TypeVar)
1125
- t = Type{t. ub}
1126
- else
1127
- t = Type{t}
1128
- end
1129
- else
1130
- # if there is any type uncertainty in the arguments, we are
1131
- # effectively predicting what static_typeof will say when
1132
- # the function is compiled with actual arguments. in that case
1133
- # abstract types yield Type{<:T} instead of Type{T}.
1134
- # this doesn't really model the situation perfectly, but
1135
- # "isleaftype(inference_stack.types)" should be good enough.
1136
- if isa (t,TypeVar) || isvarargtype (t)
1137
- t = Type{t}
1138
- else
1139
- t = Type{TypeVar (:_ ,t)}
1140
- end
1141
- end
1142
1101
elseif is (e. head,:method )
1143
1102
t = (length (e. args) == 1 ) ? Any : Void
1144
1103
elseif is (e. head,:copyast )
@@ -1666,23 +1625,19 @@ function typeinf_frame(frame)
1666
1625
W = frame. ip
1667
1626
s = frame. stmt_types
1668
1627
n = frame. nstmts
1669
- @label restart_typeinf
1670
1628
while ! isempty (W)
1671
1629
# make progress on the active ip set
1672
1630
local pc:: Int = first (W), pc´:: Int
1673
1631
while true # inner loop optimizes the common case where it can run straight from pc to pc + 1
1674
1632
# print(pc,": ",s[pc],"\n")
1675
1633
delete! (W, pc)
1676
1634
frame. currpc = pc
1677
- frame. static_typeof = false
1678
1635
frame. cur_hand = frame. handler_at[pc]
1679
1636
stmt = frame. linfo. code[pc]
1680
1637
changes = abstract_interpret (stmt, s[pc]:: Array{Any,1} , frame)
1681
1638
if changes === ()
1682
- # if there was a Expr(:static_typeof) on this line,
1683
- # need to continue to the next pc even though the return type was Bottom
1684
- # otherwise, this line threw an error and there is no need to continue
1685
- frame. static_typeof || break
1639
+ # this line threw an error and there is no need to continue
1640
+ break
1686
1641
changes = s[pc]
1687
1642
end
1688
1643
if frame. cur_hand != = ()
@@ -1732,26 +1687,6 @@ function typeinf_frame(frame)
1732
1687
s[l] = newstate
1733
1688
end
1734
1689
end
1735
- elseif is (hd, :type_goto )
1736
- for i = 2 : length (stmt. args)
1737
- var = stmt. args[i]:: SSAValue
1738
- # Store types that need to be fed back via type_goto
1739
- # in ssavalue_init. After finishing inference, if any
1740
- # of these types changed, start over with the fed-back
1741
- # types known from the beginning.
1742
- # See issue #3821 (using !typeseq instead of !subtype),
1743
- # and issue #7810.
1744
- id = var. id+ 1
1745
- vt = frame. linfo. ssavaluetypes[id]
1746
- ot = frame. ssavalue_init[id]
1747
- if ot=== NF || ! (vt⊑ ot && ot⊑ vt)
1748
- frame. ssavalue_init[id] = vt
1749
- if get (frame. fedbackvars, var, false )
1750
- frame. typegotoredo = true
1751
- end
1752
- end
1753
- frame. fedbackvars[var] = true
1754
- end
1755
1690
elseif is (hd, :return )
1756
1691
pc´ = n + 1
1757
1692
rt = abstract_eval (stmt. args[1 ], s[pc], frame)
@@ -1821,39 +1756,6 @@ function typeinf_frame(frame)
1821
1756
end
1822
1757
1823
1758
if finished || frame. fixedpoint
1824
- if frame. typegotoredo
1825
- # if any type_gotos changed, clear state and restart.
1826
- frame. typegotoredo = false
1827
- for ll = 2 : length (s)
1828
- s[ll] = ()
1829
- end
1830
- empty! (W)
1831
- push! (W, 1 )
1832
- frame. cur_hand = ()
1833
- frame. handler_at = Any[ () for i= 1 : n ]
1834
- frame. n_handlers = 0
1835
- frame. linfo. ssavaluetypes[:] = frame. ssavalue_init
1836
- @goto restart_typeinf
1837
- else
1838
- # if a static_typeof was never reached,
1839
- # use Union{} as its real type and continue
1840
- # running type inference from its uses
1841
- # (one of which is the static_typeof)
1842
- # TODO : this restart should happen just before calling finish()
1843
- for (fbvar, seen) in frame. fedbackvars
1844
- if ! seen
1845
- frame. fedbackvars[fbvar] = true
1846
- id = (fbvar:: SSAValue ). id + 1
1847
- for r in frame. ssavalue_uses[id]
1848
- if ! is (s[r], ()) # s[r] === () => unreached statement
1849
- push! (W, r)
1850
- end
1851
- end
1852
- @goto restart_typeinf
1853
- end
1854
- end
1855
- end
1856
-
1857
1759
if finished
1858
1760
finish (frame)
1859
1761
else # fixedpoint propagation
@@ -2056,7 +1958,7 @@ function eval_annotate(e::ANY, vtypes::ANY, sv::InferenceState, undefs, pass)
2056
1958
2057
1959
e = e:: Expr
2058
1960
head = e. head
2059
- if is (head,:static_typeof ) || is (head, : line ) || is (head,:const )
1961
+ if is (head,:line ) || is (head,:const )
2060
1962
return e
2061
1963
elseif is (head,:(= ))
2062
1964
e. args[2 ] = eval_annotate (e. args[2 ], vtypes, sv, undefs, pass)
@@ -2282,9 +2184,6 @@ function effect_free(e::ANY, sv, allow_volatile::Bool)
2282
2184
elseif isa (e,Expr)
2283
2185
e = e:: Expr
2284
2186
head = e. head
2285
- if head === :static_typeof
2286
- return true
2287
- end
2288
2187
if head === :static_parameter || head === :meta || head === :line ||
2289
2188
head === :inbounds || head === :boundscheck
2290
2189
return true
0 commit comments