40
40
type InferenceState
41
41
sp:: SimpleVector # static parameters
42
42
label_counter:: Int # index of the current highest label for this function
43
- fedbackvars:: Dict{SSAValue, Bool}
44
43
mod:: Module
45
44
currpc:: LineNum
46
- static_typeof:: Bool
47
45
48
46
# info on the state of inference and the linfo
49
47
linfo:: LambdaInfo
@@ -68,7 +66,6 @@ type InferenceState
68
66
backedges:: Vector{Tuple{InferenceState, Vector{LineNum}}}
69
67
# iteration fixed-point detection
70
68
fixedpoint:: Bool
71
- typegotoredo:: Bool
72
69
inworkq:: Bool
73
70
optimize:: Bool
74
71
inferred:: Bool
@@ -152,13 +149,13 @@ type InferenceState
152
149
153
150
inmodule = isdefined (linfo, :def ) ? linfo. def. module : current_module () # toplevel thunks are inferred in the current module
154
151
frame = new (
155
- sp, nl, Dict {SSAValue, Bool} (), inmodule, 0 , false ,
152
+ sp, nl, inmodule, 0 ,
156
153
linfo, la, s, Union{}, W, n,
157
154
cur_hand, handler_at, n_handlers,
158
155
ssavalue_uses, ssavalue_init,
159
156
ObjectIdDict (), # Dict{InferenceState, Vector{LineNum}}(),
160
157
Vector {Tuple{InferenceState, Vector{LineNum}}} (),
161
- false , false , false , optimize, false )
158
+ false , false , optimize, false )
162
159
push! (active, frame)
163
160
nactive[] += 1
164
161
return frame
@@ -1062,8 +1059,6 @@ function abstract_eval(e::ANY, vtypes::VarTable, sv::InferenceState)
1062
1059
return abstract_eval_constant (e)
1063
1060
end
1064
1061
e = e:: Expr
1065
- # handle:
1066
- # call null new & static_typeof
1067
1062
if is (e. head,:call )
1068
1063
t = abstract_eval_call (e, vtypes, sv)
1069
1064
elseif is (e. head,:null )
@@ -1097,42 +1092,6 @@ function abstract_eval(e::ANY, vtypes::VarTable, sv::InferenceState)
1097
1092
t = abstract_eval_constant (val)
1098
1093
end
1099
1094
end
1100
- elseif is (e. head,:static_typeof )
1101
- var = e. args[1 ]
1102
- t = widenconst (abstract_eval (var, vtypes, sv))
1103
- if isa (t,DataType) && typeseq (t,t. name. primary)
1104
- # remove unnecessary typevars
1105
- t = t. name. primary
1106
- end
1107
- if is (t,Bottom)
1108
- # if we haven't gotten fed-back type info yet, return Bottom. otherwise
1109
- # Bottom is the actual type of the variable, so return Type{Bottom}.
1110
- if get! (sv. fedbackvars, var, false )
1111
- t = Type{Bottom}
1112
- else
1113
- sv. static_typeof = true
1114
- end
1115
- elseif isleaftype (t)
1116
- t = Type{t}
1117
- elseif isleaftype (sv. linfo. specTypes)
1118
- if isa (t,TypeVar)
1119
- t = Type{t. ub}
1120
- else
1121
- t = Type{t}
1122
- end
1123
- else
1124
- # if there is any type uncertainty in the arguments, we are
1125
- # effectively predicting what static_typeof will say when
1126
- # the function is compiled with actual arguments. in that case
1127
- # abstract types yield Type{<:T} instead of Type{T}.
1128
- # this doesn't really model the situation perfectly, but
1129
- # "isleaftype(inference_stack.types)" should be good enough.
1130
- if isa (t,TypeVar) || isvarargtype (t)
1131
- t = Type{t}
1132
- else
1133
- t = Type{TypeVar (:_ ,t)}
1134
- end
1135
- end
1136
1095
elseif is (e. head,:method )
1137
1096
t = (length (e. args) == 1 ) ? Any : Void
1138
1097
elseif is (e. head,:copyast )
@@ -1638,23 +1597,19 @@ function typeinf_frame(frame)
1638
1597
W = frame. ip
1639
1598
s = frame. stmt_types
1640
1599
n = frame. nstmts
1641
- @label restart_typeinf
1642
1600
while ! isempty (W)
1643
1601
# make progress on the active ip set
1644
1602
local pc:: Int = first (W), pc´:: Int
1645
1603
while true # inner loop optimizes the common case where it can run straight from pc to pc + 1
1646
1604
# print(pc,": ",s[pc],"\n")
1647
1605
delete! (W, pc)
1648
1606
frame. currpc = pc
1649
- frame. static_typeof = false
1650
1607
frame. cur_hand = frame. handler_at[pc]
1651
1608
stmt = frame. linfo. code[pc]
1652
1609
changes = abstract_interpret (stmt, s[pc]:: Array{Any,1} , frame)
1653
1610
if changes === ()
1654
- # if there was a Expr(:static_typeof) on this line,
1655
- # need to continue to the next pc even though the return type was Bottom
1656
- # otherwise, this line threw an error and there is no need to continue
1657
- frame. static_typeof || break
1611
+ # this line threw an error and there is no need to continue
1612
+ break
1658
1613
changes = s[pc]
1659
1614
end
1660
1615
if frame. cur_hand != = ()
@@ -1704,26 +1659,6 @@ function typeinf_frame(frame)
1704
1659
s[l] = newstate
1705
1660
end
1706
1661
end
1707
- elseif is (hd, :type_goto )
1708
- for i = 2 : length (stmt. args)
1709
- var = stmt. args[i]:: SSAValue
1710
- # Store types that need to be fed back via type_goto
1711
- # in ssavalue_init. After finishing inference, if any
1712
- # of these types changed, start over with the fed-back
1713
- # types known from the beginning.
1714
- # See issue #3821 (using !typeseq instead of !subtype),
1715
- # and issue #7810.
1716
- id = var. id+ 1
1717
- vt = frame. linfo. ssavaluetypes[id]
1718
- ot = frame. ssavalue_init[id]
1719
- if ot=== NF || ! (vt⊑ ot && ot⊑ vt)
1720
- frame. ssavalue_init[id] = vt
1721
- if get (frame. fedbackvars, var, false )
1722
- frame. typegotoredo = true
1723
- end
1724
- end
1725
- frame. fedbackvars[var] = true
1726
- end
1727
1662
elseif is (hd, :return )
1728
1663
pc´ = n + 1
1729
1664
rt = abstract_eval (stmt. args[1 ], s[pc], frame)
@@ -1793,39 +1728,6 @@ function typeinf_frame(frame)
1793
1728
end
1794
1729
1795
1730
if finished || frame. fixedpoint
1796
- if frame. typegotoredo
1797
- # if any type_gotos changed, clear state and restart.
1798
- frame. typegotoredo = false
1799
- for ll = 2 : length (s)
1800
- s[ll] = ()
1801
- end
1802
- empty! (W)
1803
- push! (W, 1 )
1804
- frame. cur_hand = ()
1805
- frame. handler_at = Any[ () for i= 1 : n ]
1806
- frame. n_handlers = 0
1807
- frame. linfo. ssavaluetypes[:] = frame. ssavalue_init
1808
- @goto restart_typeinf
1809
- else
1810
- # if a static_typeof was never reached,
1811
- # use Union{} as its real type and continue
1812
- # running type inference from its uses
1813
- # (one of which is the static_typeof)
1814
- # TODO : this restart should happen just before calling finish()
1815
- for (fbvar, seen) in frame. fedbackvars
1816
- if ! seen
1817
- frame. fedbackvars[fbvar] = true
1818
- id = (fbvar:: SSAValue ). id + 1
1819
- for r in frame. ssavalue_uses[id]
1820
- if ! is (s[r], ()) # s[r] === () => unreached statement
1821
- push! (W, r)
1822
- end
1823
- end
1824
- @goto restart_typeinf
1825
- end
1826
- end
1827
- end
1828
-
1829
1731
if finished
1830
1732
finish (frame)
1831
1733
else # fixedpoint propagation
@@ -1991,7 +1893,7 @@ function eval_annotate(e::ANY, vtypes::ANY, sv::InferenceState, undefs, pass)
1991
1893
1992
1894
e = e:: Expr
1993
1895
head = e. head
1994
- if is (head,:static_typeof ) || is (head, : line ) || is (head,:const )
1896
+ if is (head,:line ) || is (head,:const )
1995
1897
return e
1996
1898
elseif is (head,:(= ))
1997
1899
e. args[2 ] = eval_annotate (e. args[2 ], vtypes, sv, undefs, pass)
@@ -2213,9 +2115,6 @@ function effect_free(e::ANY, sv, allow_volatile::Bool)
2213
2115
end
2214
2116
if isa (e,Expr)
2215
2117
e = e:: Expr
2216
- if e. head === :static_typeof
2217
- return true
2218
- end
2219
2118
if e. head === :static_parameter
2220
2119
return true
2221
2120
end
0 commit comments