@@ -36,7 +36,7 @@ type CallStack
36
36
recurred:: Bool
37
37
cycleid:: Int
38
38
result
39
- prev:: Union( EmptyCallStack,CallStack)
39
+ prev:: Union{ EmptyCallStack,CallStack}
40
40
sv:: StaticVarInfo
41
41
42
42
CallStack (ast, mod, types:: ANY , prev) = new (ast, mod, types, false , 0 , Bottom, prev)
@@ -145,7 +145,7 @@ add_tfunc(getfield(Core.Intrinsics,:ccall), 3, IInf,
145
145
if isa (t,DataType) && is ((t:: DataType ). name,Ref. name)
146
146
t = t. parameters[1 ]
147
147
if is (t,Any)
148
- return Union () # a return type of Box{Any} is invalid
148
+ return Union{} # a return type of Box{Any} is invalid
149
149
end
150
150
return t
151
151
end
@@ -165,12 +165,6 @@ add_tfunc(isa, 2, 2, cmp_tfunc)
165
165
add_tfunc (isdefined, 1 , IInf, (args... )-> Bool)
166
166
add_tfunc (Core. sizeof, 1 , 1 , x-> Int)
167
167
add_tfunc (nfields, 1 , 1 , x-> Int)
168
- add_tfunc (Union, 0 , IInf,
169
- (args... )-> (if all (isType,args)
170
- Type{Union (map (t-> t. parameters[1 ],args)... )}
171
- else
172
- Type
173
- end ))
174
168
add_tfunc (_expr, 1 , IInf, (args... )-> Expr)
175
169
add_tfunc (method_exists, 2 , 2 , cmp_tfunc)
176
170
add_tfunc (applicable, 1 , IInf, (f, args... )-> Bool)
@@ -196,8 +190,8 @@ const typeof_tfunc = function (t)
196
190
else
197
191
Type{TypeVar (:_ ,t)}
198
192
end
199
- elseif isa (t,UnionType )
200
- Union ( map (typeof_tfunc, t. types)... )
193
+ elseif isa (t,Union )
194
+ Union{ map (typeof_tfunc, t. types)... }
201
195
elseif isa (t,TypeVar)
202
196
Type{t}
203
197
else
@@ -215,12 +209,12 @@ function limit_type_depth(t::ANY, d::Int, cov::Bool, vars)
215
209
return t
216
210
end
217
211
inexact = ! cov && d > MAX_TYPE_DEPTH
218
- if isa (t,UnionType )
212
+ if isa (t,Union )
219
213
t === Bottom && return t
220
214
if d > MAX_TYPE_DEPTH
221
215
R = Any
222
216
else
223
- R = Union ( map (x-> limit_type_depth (x, d+ 1 , cov, vars), t. types)... )
217
+ R = Union{ map (x-> limit_type_depth (x, d+ 1 , cov, vars), t. types)... }
224
218
end
225
219
elseif isa (t,DataType)
226
220
P = t. parameters
@@ -254,7 +248,7 @@ const getfield_tfunc = function (A, s0, name)
254
248
return Any, false
255
249
end
256
250
end
257
- if isa (s,UnionType )
251
+ if isa (s,Union )
258
252
return reduce (tmerge, Bottom, map (t-> getfield_tfunc (A, t, name)[1 ], s. types)), false
259
253
end
260
254
if ! isa (s,DataType)
@@ -371,20 +365,39 @@ function extract_simple_tparam(Ai)
371
365
return Bottom
372
366
end
373
367
374
- # TODO : handle e.g. apply_type(T, R::Union( Type{Int32},Type{Float64}) )
368
+ # TODO : handle e.g. apply_type(T, R::Union{ Type{Int32},Type{Float64}} )
375
369
const apply_type_tfunc = function (A, args... )
376
370
if ! isType (args[1 ])
377
371
return Type
378
372
end
379
373
headtype = args[1 ]. parameters[1 ]
380
- if isa (headtype,UnionType) || isa (headtype,TypeVar)
374
+ if isa (headtype,Union)
375
+ return Bottom
376
+ end
377
+ if isa (headtype,TypeVar)
378
+ if Union <: args [1 ]
379
+ return Type
380
+ end
381
381
return args[1 ]
382
382
end
383
+ largs = length (args)
384
+ if headtype === Union
385
+ largs == 1 && return Type{Bottom}
386
+ largs == 2 && return args[2 ]
387
+ args = args[2 : end ]
388
+ if all (isType, args)
389
+ return Type{Union{map (t-> t. parameters[1 ],args)... }}
390
+ else
391
+ return Type
392
+ end
393
+ elseif Union <: headtype
394
+ return Type
395
+ end
383
396
istuple = (headtype === Tuple)
384
397
uncertain = false
385
398
lA = length (A)
386
399
tparams = svec ()
387
- for i= 2 : max (lA,length (args) )
400
+ for i= 2 : max (lA,largs )
388
401
ai = args[i]
389
402
if isType (ai)
390
403
uncertain |= (! isleaftype (ai))
@@ -560,10 +573,10 @@ const isconstantref = isconstantfunc
560
573
const limit_tuple_depth = t-> limit_tuple_depth_ (t,0 )
561
574
562
575
const limit_tuple_depth_ = function (t,d:: Int )
563
- if isa (t,UnionType )
576
+ if isa (t,Union )
564
577
# also limit within Union types.
565
578
# may have to recur into other stuff in the future too.
566
- return Union ( map (x-> limit_tuple_depth_ (x,d+ 1 ), t. types)... )
579
+ return Union{ map (x-> limit_tuple_depth_ (x,d+ 1 ), t. types)... }
567
580
end
568
581
if ! (isa (t,DataType) && t. name === Tuple. name)
569
582
return t
@@ -1092,7 +1105,7 @@ end
1092
1105
typealias VarTable ObjectIdDict
1093
1106
1094
1107
type StateUpdate
1095
- var:: Union( Symbol,GenSym)
1108
+ var:: Union{ Symbol,GenSym}
1096
1109
vtype
1097
1110
state:: VarTable
1098
1111
end
@@ -1132,7 +1145,7 @@ function type_too_complex(t::ANY, d)
1132
1145
if d > MAX_TYPE_DEPTH
1133
1146
return true
1134
1147
end
1135
- if isa (t,UnionType )
1148
+ if isa (t,Union )
1136
1149
p = t. types
1137
1150
elseif isa (t,DataType)
1138
1151
p = t. parameters
@@ -1160,7 +1173,7 @@ function tmerge(typea::ANY, typeb::ANY)
1160
1173
end
1161
1174
return Tuple
1162
1175
end
1163
- u = Union ( typea, typeb)
1176
+ u = Union{ typea, typeb}
1164
1177
if length (u. types) > MAX_TYPEUNION_LEN || type_too_complex (u, 0 )
1165
1178
# don't let type unions get too big
1166
1179
# TODO : something smarter, like a common supertype
@@ -1171,7 +1184,7 @@ end
1171
1184
1172
1185
issubstate (a:: VarState ,b:: VarState ) = (a. typ <: b.typ && a. undef <= b. undef)
1173
1186
1174
- function smerge (sa:: Union( NotFound,VarState) , sb:: Union( NotFound,VarState) )
1187
+ function smerge (sa:: Union{ NotFound,VarState} , sb:: Union{ NotFound,VarState} )
1175
1188
is (sa, NF) && return sb
1176
1189
is (sb, NF) && return sa
1177
1190
issubstate (sa,sb) && return sb
@@ -1185,7 +1198,7 @@ schanged(n::ANY, o::ANY) = is(o,NF) || (!is(n,NF) && !issubstate(n, o))
1185
1198
stupdate (state:: Tuple{} , changes:: VarTable , vars) = copy (changes)
1186
1199
stupdate (state:: Tuple{} , changes:: StateUpdate , vars) = stupdate (ObjectIdDict (), changes, vars)
1187
1200
1188
- function stupdate (state:: ObjectIdDict , changes:: Union( StateUpdate,VarTable) , vars)
1201
+ function stupdate (state:: ObjectIdDict , changes:: Union{ StateUpdate,VarTable} , vars)
1189
1202
for i = 1 : length (vars)
1190
1203
v = vars[i]
1191
1204
newtype = changes[v]
@@ -1197,7 +1210,7 @@ function stupdate(state::ObjectIdDict, changes::Union(StateUpdate,VarTable), var
1197
1210
state
1198
1211
end
1199
1212
1200
- function stchanged (new:: Union( StateUpdate,VarTable) , old, vars)
1213
+ function stchanged (new:: Union{ StateUpdate,VarTable} , old, vars)
1201
1214
if is (old,())
1202
1215
return true
1203
1216
end
@@ -1683,7 +1696,7 @@ function typeinf_uncached(linfo::LambdaStaticData, atypes::ANY, sparams::SimpleV
1683
1696
end
1684
1697
for i = 1 : length (gensym_types)
1685
1698
if gensym_types[i] === NF
1686
- gensym_types[i] = Union ()
1699
+ gensym_types[i] = Union{}
1687
1700
end
1688
1701
end
1689
1702
@@ -1886,7 +1899,7 @@ end
1886
1899
1887
1900
function sym_replace (e:: ANY , from1, from2, to1, to2)
1888
1901
if isa (e,Symbol) || isa (e,GenSym)
1889
- return _sym_repl (e:: Union( Symbol,GenSym) , from1, from2, to1, to2, e)
1902
+ return _sym_repl (e:: Union{ Symbol,GenSym} , from1, from2, to1, to2, e)
1890
1903
end
1891
1904
if isa (e,SymbolNode)
1892
1905
e2 = _sym_repl (e. name, from1, from2, to1, to2, e)
@@ -1905,12 +1918,12 @@ function sym_replace(e::ANY, from1, from2, to1, to2)
1905
1918
# on the LHS of assignments, so we make sure not to put
1906
1919
# something else there
1907
1920
@assert length (e. args) == 2
1908
- s = e. args[1 ]:: Union( Symbol,GenSym)
1921
+ s = e. args[1 ]:: Union{ Symbol,GenSym}
1909
1922
e2 = _sym_repl (s, from1, from2, to1, to2, s)
1910
1923
if isa (e2, SymbolNode)
1911
1924
e2 = e2. name
1912
1925
end
1913
- e. args[1 ] = e2:: Union( Symbol,GenSym)
1926
+ e. args[1 ] = e2:: Union{ Symbol,GenSym}
1914
1927
e. args[2 ] = sym_replace (e. args[2 ], from1, from2, to1, to2)
1915
1928
elseif e. head != = :line
1916
1929
for i= 1 : length (e. args)
@@ -1920,7 +1933,7 @@ function sym_replace(e::ANY, from1, from2, to1, to2)
1920
1933
return e
1921
1934
end
1922
1935
1923
- function _sym_repl (s:: Union( Symbol,GenSym) , from1, from2, to1, to2, deflt)
1936
+ function _sym_repl (s:: Union{ Symbol,GenSym} , from1, from2, to1, to2, deflt)
1924
1937
for i= 1 : length (from1)
1925
1938
if is (from1[i],s)
1926
1939
return to1[i]
@@ -1981,7 +1994,7 @@ function resolve_globals(e::ANY, locals, args, from, to, env1, env2)
1981
1994
# remove_redundant_temp_vars can only handle Symbols
1982
1995
# on the LHS of assignments, so we make sure not to put
1983
1996
# something else there
1984
- e2 = resolve_globals (e. args[1 ]:: Union( Symbol,GenSym) , locals, args, from, to, env1, env2)
1997
+ e2 = resolve_globals (e. args[1 ]:: Union{ Symbol,GenSym} , locals, args, from, to, env1, env2)
1985
1998
if isa (e2, GlobalRef)
1986
1999
# abort when trying to inline a function which assigns to a global
1987
2000
# variable in a different module, since `Mod.X=V` isn't allowed
@@ -1991,7 +2004,7 @@ function resolve_globals(e::ANY, locals, args, from, to, env1, env2)
1991
2004
# resolve_globals(e.args[2], locals, args, from, to, env1, env2))
1992
2005
# e.typ = e2.typ
1993
2006
else
1994
- e. args[1 ] = e2:: Union( Symbol,GenSym)
2007
+ e. args[1 ] = e2:: Union{ Symbol,GenSym}
1995
2008
e. args[2 ] = resolve_globals (e. args[2 ], locals, args, from, to, env1, env2)
1996
2009
end
1997
2010
elseif ! is (e. head,:line )
@@ -2224,12 +2237,6 @@ function inlineable(f::ANY, e::Expr, atype::ANY, sv::StaticVarInfo, enclosing_as
2224
2237
isleaftype (e. typ. parameters[1 ])
2225
2238
return (e. typ. parameters[1 ],())
2226
2239
end
2227
- if is (f,Union)
2228
- union = e. typ. parameters[1 ]
2229
- if isa (union,UnionType) && all (isleaftype, (union:: UnionType ). types)
2230
- return (union,())
2231
- end
2232
- end
2233
2240
end
2234
2241
if isa (f,IntrinsicFunction)
2235
2242
return NF
0 commit comments