@@ -231,7 +231,7 @@ tupletype_tail(t::ANY, n) = Tuple{t.parameters[n:end]...}
231
231
232
232
# ### type-functions for builtins / intrinsics ####
233
233
234
- cmp_tfunc = (x,y)-> Bool
234
+ cmp_tfunc = (sv, x,y)-> Bool
235
235
236
236
isType (t:: ANY ) = isa (t,DataType) && is ((t:: DataType ). name,Type. name)
237
237
@@ -247,8 +247,8 @@ function add_tfunc(f::Function, minarg::Int, maxarg::Int, tfunc::ANY)
247
247
push! (t_ffunc_key, f)
248
248
push! (t_ffunc_val, (minarg, maxarg, tfunc))
249
249
end
250
- add_tfunc (throw, 1 , 1 , x -> Bottom)
251
- add_tfunc (box, 2 , 2 , (t,v)-> (isType (t) ? t. parameters[1 ] : Any))
250
+ add_tfunc (throw, 1 , 1 , (sv,x) -> Bottom)
251
+ add_tfunc (box, 2 , 2 , (sv, t,v)-> (isType (t) ? t. parameters[1 ] : Any))
252
252
add_tfunc (eq_int, 2 , 2 , cmp_tfunc)
253
253
add_tfunc (ne_int, 2 , 2 , cmp_tfunc)
254
254
add_tfunc (slt_int, 2 , 2 , cmp_tfunc)
@@ -262,7 +262,7 @@ add_tfunc(le_float, 2, 2, cmp_tfunc)
262
262
add_tfunc (fpiseq, 2 , 2 , cmp_tfunc)
263
263
add_tfunc (fpislt, 2 , 2 , cmp_tfunc)
264
264
add_tfunc (Core. Intrinsics. ccall, 3 , IInf,
265
- function (fptr, rt, at, a... )
265
+ function (sv, fptr, rt, at, a... )
266
266
if ! isType (rt)
267
267
return Any
268
268
end
@@ -277,12 +277,12 @@ add_tfunc(Core.Intrinsics.ccall, 3, IInf,
277
277
return t
278
278
end )
279
279
add_tfunc (Core. Intrinsics. llvmcall, 3 , IInf,
280
- (fptr, rt, at, a... )-> (isType (rt) ? rt. parameters[1 ] : Any))
280
+ (sv, fptr, rt, at, a... )-> (isType (rt) ? rt. parameters[1 ] : Any))
281
281
add_tfunc (Core. Intrinsics. cglobal, 1 , 2 ,
282
- (fptr, t... )-> (isempty (t) ? Ptr{Void} :
282
+ (sv, fptr, t... )-> (isempty (t) ? Ptr{Void} :
283
283
isType (t[1 ]) ? Ptr{t[1 ]. parameters[1 ]} : Ptr))
284
284
add_tfunc (Core. Intrinsics. select_value, 3 , 3 ,
285
- function (cnd, x, y)
285
+ function (sv, cnd, x, y)
286
286
if isa (cnd, Const)
287
287
if cnd. val === true
288
288
return x
@@ -296,7 +296,7 @@ add_tfunc(Core.Intrinsics.select_value, 3, 3,
296
296
tmerge (x, y)
297
297
end )
298
298
add_tfunc (is, 2 , 2 ,
299
- function (x:: ANY , y:: ANY )
299
+ function (sv, x:: ANY , y:: ANY )
300
300
if isa (x,Const) && isa (y,Const)
301
301
return Const (x. val=== y. val)
302
302
elseif isType (x) && isType (y) && isleaftype (x) && isleaftype (y)
@@ -310,23 +310,23 @@ add_tfunc(is, 2, 2,
310
310
return Bool
311
311
end
312
312
end )
313
- add_tfunc (isdefined, 1 , IInf, (args... )-> Bool)
314
- add_tfunc (Core. sizeof, 1 , 1 , x -> Int)
315
- add_tfunc (nfields, 1 , 1 , x -> (isa (x,Const) ? Const (nfields (x. val)) :
316
- isType (x) && isleaftype (x. parameters[1 ]) ? Const (nfields (x. parameters[1 ])) :
317
- Int))
318
- add_tfunc (Core. _expr, 1 , IInf, (args... )-> Expr)
319
- add_tfunc (applicable, 1 , IInf, (f, args... )-> Bool)
320
- add_tfunc (Core. Intrinsics. arraylen, 1 , 1 , x -> Int)
321
- add_tfunc (arraysize, 2 , 2 , (a,d)-> Int)
313
+ add_tfunc (isdefined, 1 , IInf, (sv, args... )-> Bool)
314
+ add_tfunc (Core. sizeof, 1 , 1 , (sv,x) -> Int)
315
+ add_tfunc (nfields, 1 , 1 , (sv,x) -> (isa (x,Const) ? Const (nfields (x. val)) :
316
+ isType (x) && isleaftype (x. parameters[1 ]) ? Const (nfields (x. parameters[1 ])) :
317
+ Int))
318
+ add_tfunc (Core. _expr, 1 , IInf, (sv, args... )-> Expr)
319
+ add_tfunc (applicable, 1 , IInf, (sv, f, args... )-> Bool)
320
+ add_tfunc (Core. Intrinsics. arraylen, 1 , 1 , (sv,x) -> Int)
321
+ add_tfunc (arraysize, 2 , 2 , (sv, a,d)-> Int)
322
322
add_tfunc (pointerref, 3 , 3 ,
323
- function (a,i,align)
323
+ function (sv, a,i,align)
324
324
a = widenconst (a)
325
325
isa (a,DataType) && a<: Ptr && isa (a. parameters[1 ],Union{Type,TypeVar}) ? a. parameters[1 ] : Any
326
326
end )
327
- add_tfunc (pointerset, 4 , 4 , (a,v,i,align)-> a)
327
+ add_tfunc (pointerset, 4 , 4 , (sv, a,v,i,align)-> a)
328
328
329
- function typeof_tfunc (t:: ANY )
329
+ function typeof_tfunc (sv, t:: ANY )
330
330
if isa (t,Const)
331
331
return Type{typeof (t. val)}
332
332
elseif isType (t)
@@ -345,7 +345,7 @@ function typeof_tfunc(t::ANY)
345
345
Type{TypeVar (:_ ,t)}
346
346
end
347
347
elseif isa (t,Union)
348
- Union{map (typeof_tfunc, t. types)... }
348
+ Union{map (t -> typeof_tfunc (sv,t) , t. types)... }
349
349
elseif isa (t,TypeVar) && ! (Any <: t.ub )
350
350
Type{t}
351
351
else
@@ -354,7 +354,7 @@ function typeof_tfunc(t::ANY)
354
354
end
355
355
add_tfunc (typeof, 1 , 1 , typeof_tfunc)
356
356
add_tfunc (typeassert, 2 , 2 ,
357
- function (v, t)
357
+ function (sv, v, t)
358
358
if isType (t)
359
359
if isa (v,Const)
360
360
if isleaftype (t) && ! isa (v. val, t. parameters[1 ])
@@ -367,7 +367,7 @@ add_tfunc(typeassert, 2, 2,
367
367
return v
368
368
end )
369
369
add_tfunc (isa, 2 , 2 ,
370
- function (v, t)
370
+ function (sv, v, t)
371
371
if isType (t) && isleaftype (t)
372
372
if v ⊑ t. parameters[1 ]
373
373
return Const (true )
@@ -378,7 +378,7 @@ add_tfunc(isa, 2, 2,
378
378
return Bool
379
379
end )
380
380
add_tfunc (issubtype, 2 , 2 ,
381
- function (a, b)
381
+ function (sv, a, b)
382
382
if isType (a) && isType (b) && isleaftype (a) && isleaftype (b)
383
383
return Const (issubtype (a. parameters[1 ], b. parameters[1 ]))
384
384
end
@@ -433,7 +433,7 @@ function limit_type_depth(t::ANY, d::Int, cov::Bool, vars)
433
433
end
434
434
435
435
# returns (type, isexact)
436
- function getfield_tfunc (s0:: ANY , name)
436
+ function getfield_tfunc (sv :: InferenceState , s0:: ANY , name)
437
437
if isa (s0, TypeVar)
438
438
s0 = s0. ub
439
439
end
@@ -453,7 +453,7 @@ function getfield_tfunc(s0::ANY, name)
453
453
s = typeof (s. val)
454
454
end
455
455
if isa (s,Union)
456
- return reduce (tmerge, Bottom, map (t-> getfield_tfunc (t, name)[1 ], s. types)), false
456
+ return reduce (tmerge, Bottom, map (t-> getfield_tfunc (sv, t, name)[1 ], s. types)), false
457
457
end
458
458
if isa (s,DataType)
459
459
if s. abstract
@@ -530,15 +530,15 @@ function getfield_tfunc(s0::ANY, name)
530
530
end
531
531
end
532
532
end
533
- add_tfunc (getfield, 2 , 2 , (s,name)-> getfield_tfunc (s,name)[1 ])
534
- add_tfunc (setfield!, 3 , 3 , (o, f, v)-> v)
535
- function fieldtype_tfunc (s:: ANY , name)
533
+ add_tfunc (getfield, 2 , 2 , (sv, s,name)-> getfield_tfunc (sv, s,name)[1 ])
534
+ add_tfunc (setfield!, 3 , 3 , (sv, o, f, v)-> v)
535
+ function fieldtype_tfunc (sv, s:: ANY , name)
536
536
if isType (s)
537
537
s = s. parameters[1 ]
538
538
else
539
539
return Type
540
540
end
541
- t, exact = getfield_tfunc (s, name)
541
+ t, exact = getfield_tfunc (sv, s, name)
542
542
if is (t,Bottom)
543
543
return t
544
544
end
559
559
has_typevars (t:: ANY , all= false ) = ccall (:jl_has_typevars_ , Cint, (Any,Cint), t, all)!= 0
560
560
561
561
# TODO : handle e.g. apply_type(T, R::Union{Type{Int32},Type{Float64}})
562
- function apply_type_tfunc (args... )
562
+ function apply_type_tfunc (sv, args... )
563
563
if ! isType (args[1 ])
564
564
return Any
565
565
end
@@ -728,7 +728,7 @@ function builtin_tfunction(f::ANY, argtypes::Array{Any,1}, sv::InferenceState)
728
728
# wrong # of args
729
729
return Bottom
730
730
end
731
- return tf[3 ](argtypes... )
731
+ return tf[3 ](sv, argtypes... )
732
732
end
733
733
734
734
limit_tuple_depth (params:: InferenceParams , t:: ANY ) = limit_tuple_depth_ (params,t,0 )
@@ -1060,12 +1060,12 @@ function abstract_call(f::ANY, fargs, argtypes::Vector{Any}, vtypes::VarTable, s
1060
1060
# allow tuple indexing functions to take advantage of constant
1061
1061
# index arguments.
1062
1062
if istopfunction (tm, f, :getindex )
1063
- return getfield_tfunc (argtypes[2 ], argtypes[3 ])[1 ]
1063
+ return getfield_tfunc (sv, argtypes[2 ], argtypes[3 ])[1 ]
1064
1064
elseif istopfunction (tm, f, :next )
1065
- t1 = getfield_tfunc (argtypes[2 ], argtypes[3 ])[1 ]
1065
+ t1 = getfield_tfunc (sv, argtypes[2 ], argtypes[3 ])[1 ]
1066
1066
return t1=== Bottom ? Bottom : Tuple{t1, Int}
1067
1067
elseif istopfunction (tm, f, :indexed_next )
1068
- t1 = getfield_tfunc (argtypes[2 ], argtypes[3 ])[1 ]
1068
+ t1 = getfield_tfunc (sv, argtypes[2 ], argtypes[3 ])[1 ]
1069
1069
return t1=== Bottom ? Bottom : Tuple{t1, Int}
1070
1070
end
1071
1071
end
0 commit comments