@@ -4,17 +4,17 @@ import Core: _apply, svec, apply_type, Builtin, IntrinsicFunction
4
4
5
5
# ### parameters limiting potentially-infinite types ####
6
6
const MAX_TYPEUNION_LEN = 3
7
- const MAX_TYPE_DEPTH = 7
8
7
9
8
const UNION_SPLIT_MISMATCH_ERROR = false
10
9
11
10
immutable InferenceParams
11
+ MAX_TYPE_DEPTH
12
12
MAX_TUPLETYPE_LEN
13
13
MAX_TUPLE_SPLAT
14
14
MAX_UNION_SPLITTING
15
15
MAX_TUPLE_DEPTH
16
16
end
17
- const DEFAULT_PARAMS = InferenceParams (15 ,16 , 4 , 4 )
17
+ const DEFAULT_PARAMS = InferenceParams (7 , 15 , 16 , 4 , 4 )
18
18
19
19
# alloc_elim_pass! relies on `Slot_AssignedOnce | Slot_UsedUndef` being
20
20
# SSA. This should be true now but can break if we start to track conditional
@@ -395,26 +395,26 @@ function type_depth(t::ANY)
395
395
return 0
396
396
end
397
397
398
- function limit_type_depth (t:: ANY , d:: Int , cov:: Bool , vars)
398
+ function limit_type_depth (t:: ANY , d:: Int , cov:: Bool , vars, sv :: InferenceState )
399
399
if isa (t,TypeVar) || isa (t,TypeConstructor)
400
400
return t
401
401
end
402
- inexact = ! cov && d > MAX_TYPE_DEPTH
402
+ inexact = ! cov && d > sv . params . MAX_TYPE_DEPTH
403
403
if isa (t,Union)
404
404
t === Bottom && return t
405
- if d > MAX_TYPE_DEPTH
405
+ if d > sv . params . MAX_TYPE_DEPTH
406
406
R = Any
407
407
else
408
- R = Union{map (x-> limit_type_depth (x, d+ 1 , cov, vars), t. types)... }
408
+ R = Union{map (x-> limit_type_depth (x, d+ 1 , cov, vars, sv ), t. types)... }
409
409
end
410
410
elseif isa (t,DataType)
411
411
P = t. parameters
412
412
isempty (P) && return t
413
- if d > MAX_TYPE_DEPTH
413
+ if d > sv . params . MAX_TYPE_DEPTH
414
414
R = t. name. primary
415
415
else
416
416
stillcov = cov && (t. name === Tuple. name)
417
- Q = map (x-> limit_type_depth (x, d+ 1 , stillcov, vars), P)
417
+ Q = map (x-> limit_type_depth (x, d+ 1 , stillcov, vars, sv ), P)
418
418
if ! cov && _any (p-> contains_is (vars,p), Q)
419
419
R = t. name. primary
420
420
inexact = true
@@ -494,7 +494,8 @@ function getfield_tfunc(sv::InferenceState, s0::ANY, name)
494
494
# since the UnionAll type bound is otherwise incorrect
495
495
# in the current type system
496
496
typ = limit_type_depth (R, 0 , true ,
497
- filter! (x-> isa (x,TypeVar), Any[s. parameters... ]))
497
+ filter! (x-> isa (x,TypeVar), Any[s. parameters... ]),
498
+ sv)
498
499
return typ, isleaftype (s) && isa (R, Type) && typeof (R) === typeof (typ) && typeseq (R, typ)
499
500
end
500
501
end
@@ -525,7 +526,8 @@ function getfield_tfunc(sv::InferenceState, s0::ANY, name)
525
526
return R, alleq
526
527
else
527
528
typ = limit_type_depth (R, 0 , true ,
528
- filter! (x-> isa (x,TypeVar), Any[s. parameters... ]))
529
+ filter! (x-> isa (x,TypeVar), Any[s. parameters... ]),
530
+ sv)
529
531
return typ, alleq && isleaftype (s) && typeof (R) === typeof (typ) && typeseq (R, typ)
530
532
end
531
533
end
559
561
has_typevars (t:: ANY , all= false ) = ccall (:jl_has_typevars_ , Cint, (Any,Cint), t, all)!= 0
560
562
561
563
# TODO : handle e.g. apply_type(T, R::Union{Type{Int32},Type{Float64}})
562
- function apply_type_tfunc (sv, args... )
564
+ function apply_type_tfunc (sv:: InferenceState , args... )
563
565
if ! isType (args[1 ])
564
566
return Any
565
567
end
@@ -619,7 +621,7 @@ function apply_type_tfunc(sv, args...)
619
621
uncertain = true
620
622
end
621
623
! uncertain && return Type{appl}
622
- if type_too_complex (appl,0 )
624
+ if type_too_complex (appl, 0 , sv )
623
625
return Type{TypeVar (:_ ,headtype)}
624
626
end
625
627
! (isa (appl,TypeVar) || isvarargtype (appl)) ? Type{TypeVar (:_ ,appl)} : Type{appl}
@@ -821,8 +823,8 @@ function abstract_call_gf_by_type(f::ANY, argtype::ANY, sv::InferenceState)
821
823
end
822
824
if td > type_depth (infstate. linfo. specTypes)
823
825
# impose limit if we recur and the argument types grow beyond MAX_TYPE_DEPTH
824
- if td > MAX_TYPE_DEPTH
825
- sig = limit_type_depth (sig, 0 , true , [])
826
+ if td > sv . params . MAX_TYPE_DEPTH
827
+ sig = limit_type_depth (sig, 0 , true , [], sv )
826
828
break
827
829
else
828
830
p1, p2 = sig. parameters, infstate. linfo. specTypes. parameters
@@ -838,7 +840,7 @@ function abstract_call_gf_by_type(f::ANY, argtype::ANY, sv::InferenceState)
838
840
newsig[i] = p1[i]. name. primary
839
841
limitdepth = true
840
842
else
841
- newsig[i] = limit_type_depth (p1[i], 1 , true , [])
843
+ newsig[i] = limit_type_depth (p1[i], 1 , true , [], sv )
842
844
end
843
845
end
844
846
if limitdepth
@@ -853,8 +855,8 @@ function abstract_call_gf_by_type(f::ANY, argtype::ANY, sv::InferenceState)
853
855
854
856
# # limit argument type size growth
855
857
# tdepth = type_depth(sig)
856
- # if tdepth > MAX_TYPE_DEPTH
857
- # sig = limit_type_depth(sig, 0, true, [])
858
+ # if tdepth > sv.params. MAX_TYPE_DEPTH
859
+ # sig = limit_type_depth(sig, 0, true, [], sv )
858
860
# end
859
861
860
862
# limit length based on size of definition signature.
@@ -1260,21 +1262,21 @@ function abstract_interpret(e::ANY, vtypes::VarTable, sv::InferenceState)
1260
1262
return vtypes
1261
1263
end
1262
1264
1263
- function type_too_complex (t:: ANY , d)
1264
- if d > MAX_TYPE_DEPTH
1265
+ function type_too_complex (t:: ANY , d, sv :: InferenceState )
1266
+ if d > sv . params . MAX_TYPE_DEPTH
1265
1267
return true
1266
1268
end
1267
1269
if isa (t,Union)
1268
1270
p = t. types
1269
1271
elseif isa (t,DataType)
1270
1272
p = t. parameters
1271
1273
elseif isa (t,TypeVar)
1272
- return type_too_complex (t. lb,d+ 1 ) || type_too_complex (t. ub,d+ 1 )
1274
+ return type_too_complex (t. lb, d+ 1 , sv ) || type_too_complex (t. ub, d+ 1 , sv )
1273
1275
else
1274
1276
return false
1275
1277
end
1276
1278
for x in (p:: SimpleVector )
1277
- if type_too_complex (x, d+ 1 )
1279
+ if type_too_complex (x, d+ 1 , sv )
1278
1280
return true
1279
1281
end
1280
1282
end
@@ -1332,7 +1334,7 @@ function tmerge(typea::ANY, typeb::ANY)
1332
1334
end
1333
1335
end
1334
1336
u = Union{typea, typeb}
1335
- if length (u. types) > MAX_TYPEUNION_LEN || type_too_complex (u, 0 )
1337
+ if length (u. types) > MAX_TYPEUNION_LEN || type_too_complex (u, 0 , global_sv) # FIXME : use of global_sv
1336
1338
# don't let type unions get too big
1337
1339
# TODO : something smarter, like a common supertype
1338
1340
return Any
0 commit comments