@@ -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
@@ -158,19 +158,13 @@ add_tfunc(eval(Core.Intrinsics,:cglobal), 1, 2,
158
158
isType (t[1 ]) ? Ptr{t[1 ]. parameters[1 ]} : Ptr))
159
159
add_tfunc (eval (Core. Intrinsics,:select_value ), 3 , 3 ,
160
160
# TODO : return Bottom if cnd is definitely not a Bool
161
- (cnd, x, y)-> Union ( x,y) )
161
+ (cnd, x, y)-> Union{ x,y} )
162
162
add_tfunc (is, 2 , 2 , cmp_tfunc)
163
163
add_tfunc (issubtype, 2 , 2 , cmp_tfunc)
164
164
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)
@@ -376,17 +370,30 @@ has_typevars(t::ANY) = ccall(:jl_has_typevars, Cint, (Any,), t)!=0
376
370
# TODO : handle e.g. apply_type(T, R::Union(Type{Int32},Type{Float64}))
377
371
const apply_type_tfunc = function (A, args... )
378
372
if ! isType (args[1 ])
379
- return Type
373
+ return Any
380
374
end
381
375
headtype = args[1 ]. parameters[1 ]
382
- if isa (headtype,UnionType ) || isa (headtype,TypeVar)
376
+ if isa (headtype,Union ) || isa (headtype,TypeVar)
383
377
return args[1 ]
384
378
end
379
+ largs = length (args)
380
+ if headtype === Union
381
+ largs == 1 && return Type{Bottom}
382
+ largs == 2 && return args[2 ]
383
+ args = args[2 : end ]
384
+ if all (isType, args)
385
+ return Type{Union{map (t-> t. parameters[1 ],args)... }}
386
+ else
387
+ return Any
388
+ end
389
+ elseif Union <: headtype
390
+ return Any
391
+ end
385
392
istuple = (headtype === Tuple)
386
393
uncertain = false
387
394
lA = length (A)
388
395
tparams = svec ()
389
- for i= 2 : max (lA,length (args) )
396
+ for i= 2 : max (lA,largs )
390
397
ai = args[i]
391
398
if isType (ai)
392
399
aip1 = ai. parameters[1 ]
@@ -563,10 +570,10 @@ const isconstantref = isconstantfunc
563
570
const limit_tuple_depth = t-> limit_tuple_depth_ (t,0 )
564
571
565
572
const limit_tuple_depth_ = function (t,d:: Int )
566
- if isa (t,UnionType )
573
+ if isa (t,Union )
567
574
# also limit within Union types.
568
575
# may have to recur into other stuff in the future too.
569
- return Union ( map (x-> limit_tuple_depth_ (x,d+ 1 ), t. types)... )
576
+ return Union{ map (x-> limit_tuple_depth_ (x,d+ 1 ), t. types)... }
570
577
end
571
578
if ! (isa (t,DataType) && t. name === Tuple. name)
572
579
return t
@@ -1088,7 +1095,7 @@ end
1088
1095
typealias VarTable ObjectIdDict
1089
1096
1090
1097
type StateUpdate
1091
- var:: Union( Symbol,GenSym)
1098
+ var:: Union{ Symbol,GenSym}
1092
1099
vtype
1093
1100
state:: VarTable
1094
1101
end
@@ -1130,7 +1137,7 @@ function type_too_complex(t::ANY, d)
1130
1137
if d > MAX_TYPE_DEPTH
1131
1138
return true
1132
1139
end
1133
- if isa (t,UnionType )
1140
+ if isa (t,Union )
1134
1141
p = t. types
1135
1142
elseif isa (t,DataType)
1136
1143
p = t. parameters
@@ -1158,7 +1165,7 @@ function tmerge(typea::ANY, typeb::ANY)
1158
1165
end
1159
1166
return Tuple
1160
1167
end
1161
- u = Union ( typea, typeb)
1168
+ u = Union{ typea, typeb}
1162
1169
if length (u. types) > MAX_TYPEUNION_LEN || type_too_complex (u, 0 )
1163
1170
# don't let type unions get too big
1164
1171
# TODO : something smarter, like a common supertype
@@ -1169,7 +1176,7 @@ end
1169
1176
1170
1177
issubstate (a:: VarState ,b:: VarState ) = (a. typ <: b.typ && a. undef <= b. undef)
1171
1178
1172
- function smerge (sa:: Union( NotFound,VarState) , sb:: Union( NotFound,VarState) )
1179
+ function smerge (sa:: Union{ NotFound,VarState} , sb:: Union{ NotFound,VarState} )
1173
1180
is (sa, NF) && return sb
1174
1181
is (sb, NF) && return sa
1175
1182
issubstate (sa,sb) && return sb
@@ -1183,7 +1190,7 @@ schanged(n::ANY, o::ANY) = is(o,NF) || (!is(n,NF) && !issubstate(n, o))
1183
1190
stupdate (state:: Tuple{} , changes:: VarTable , vars) = copy (changes)
1184
1191
stupdate (state:: Tuple{} , changes:: StateUpdate , vars) = stupdate (ObjectIdDict (), changes, vars)
1185
1192
1186
- function stupdate (state:: ObjectIdDict , changes:: Union( StateUpdate,VarTable) , vars)
1193
+ function stupdate (state:: ObjectIdDict , changes:: Union{ StateUpdate,VarTable} , vars)
1187
1194
for i = 1 : length (vars)
1188
1195
v = vars[i]
1189
1196
newtype = changes[v]
@@ -1195,7 +1202,7 @@ function stupdate(state::ObjectIdDict, changes::Union(StateUpdate,VarTable), var
1195
1202
state
1196
1203
end
1197
1204
1198
- function stchanged (new:: Union( StateUpdate,VarTable) , old, vars)
1205
+ function stchanged (new:: Union{ StateUpdate,VarTable} , old, vars)
1199
1206
if is (old,())
1200
1207
return true
1201
1208
end
@@ -1680,7 +1687,7 @@ function typeinf_uncached(linfo::LambdaStaticData, atypes::ANY, sparams::SimpleV
1680
1687
end
1681
1688
for i = 1 : length (gensym_types)
1682
1689
if gensym_types[i] === NF
1683
- gensym_types[i] = Union ()
1690
+ gensym_types[i] = Union{}
1684
1691
end
1685
1692
end
1686
1693
@@ -1883,7 +1890,7 @@ end
1883
1890
1884
1891
function sym_replace (e:: ANY , from1, from2, to1, to2)
1885
1892
if isa (e,Symbol) || isa (e,GenSym)
1886
- return _sym_repl (e:: Union( Symbol,GenSym) , from1, from2, to1, to2, e)
1893
+ return _sym_repl (e:: Union{ Symbol,GenSym} , from1, from2, to1, to2, e)
1887
1894
end
1888
1895
if isa (e,SymbolNode)
1889
1896
e2 = _sym_repl (e. name, from1, from2, to1, to2, e)
@@ -1907,7 +1914,7 @@ function sym_replace(e::ANY, from1, from2, to1, to2)
1907
1914
if isa (e2, SymbolNode)
1908
1915
e2 = e2. name
1909
1916
end
1910
- e. args[1 ] = e2:: Union( Symbol,GenSym)
1917
+ e. args[1 ] = e2:: Union{ Symbol,GenSym}
1911
1918
end
1912
1919
e. args[2 ] = sym_replace (e. args[2 ], from1, from2, to1, to2)
1913
1920
elseif e. head != = :line
@@ -1918,7 +1925,7 @@ function sym_replace(e::ANY, from1, from2, to1, to2)
1918
1925
return e
1919
1926
end
1920
1927
1921
- function _sym_repl (s:: Union( Symbol,GenSym) , from1, from2, to1, to2, deflt)
1928
+ function _sym_repl (s:: Union{ Symbol,GenSym} , from1, from2, to1, to2, deflt)
1922
1929
for i= 1 : length (from1)
1923
1930
if is (from1[i],s)
1924
1931
return to1[i]
@@ -1979,7 +1986,7 @@ function resolve_globals(e::ANY, locals, args, from, to, env1, env2)
1979
1986
# remove_redundant_temp_vars can only handle Symbols
1980
1987
# on the LHS of assignments, so we make sure not to put
1981
1988
# something else there
1982
- e2 = resolve_globals (e. args[1 ]:: Union( Symbol,GenSym) , locals, args, from, to, env1, env2)
1989
+ e2 = resolve_globals (e. args[1 ]:: Union{ Symbol,GenSym} , locals, args, from, to, env1, env2)
1983
1990
if isa (e2, GlobalRef)
1984
1991
# abort when trying to inline a function which assigns to a global
1985
1992
# variable in a different module, since `Mod.X=V` isn't allowed
@@ -1989,7 +1996,7 @@ function resolve_globals(e::ANY, locals, args, from, to, env1, env2)
1989
1996
# resolve_globals(e.args[2], locals, args, from, to, env1, env2))
1990
1997
# e.typ = e2.typ
1991
1998
else
1992
- e. args[1 ] = e2:: Union( Symbol,GenSym)
1999
+ e. args[1 ] = e2:: Union{ Symbol,GenSym}
1993
2000
e. args[2 ] = resolve_globals (e. args[2 ], locals, args, from, to, env1, env2)
1994
2001
end
1995
2002
elseif ! is (e. head,:line )
@@ -2236,12 +2243,6 @@ function inlineable(f::ANY, e::Expr, atype::ANY, sv::StaticVarInfo, enclosing_as
2236
2243
isleaftype (e. typ. parameters[1 ])
2237
2244
return (e. typ. parameters[1 ],())
2238
2245
end
2239
- if is (f,Union)
2240
- union = e. typ. parameters[1 ]
2241
- if isa (union,UnionType) && all (isleaftype, (union:: UnionType ). types)
2242
- return (union,())
2243
- end
2244
- end
2245
2246
end
2246
2247
if isa (f,IntrinsicFunction)
2247
2248
return NF
0 commit comments