Skip to content

Commit 91d150e

Browse files
committed
Pass the inference state into the tfuncs.
1 parent 2d90181 commit 91d150e

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

base/inference.jl

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ tupletype_tail(t::ANY, n) = Tuple{t.parameters[n:end]...}
231231

232232
#### type-functions for builtins / intrinsics ####
233233

234-
cmp_tfunc = (x,y)->Bool
234+
cmp_tfunc = (sv,x,y)->Bool
235235

236236
isType(t::ANY) = isa(t,DataType) && is((t::DataType).name,Type.name)
237237

@@ -247,8 +247,8 @@ function add_tfunc(f::Function, minarg::Int, maxarg::Int, tfunc::ANY)
247247
push!(t_ffunc_key, f)
248248
push!(t_ffunc_val, (minarg, maxarg, tfunc))
249249
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))
252252
add_tfunc(eq_int, 2, 2, cmp_tfunc)
253253
add_tfunc(ne_int, 2, 2, cmp_tfunc)
254254
add_tfunc(slt_int, 2, 2, cmp_tfunc)
@@ -262,7 +262,7 @@ add_tfunc(le_float, 2, 2, cmp_tfunc)
262262
add_tfunc(fpiseq, 2, 2, cmp_tfunc)
263263
add_tfunc(fpislt, 2, 2, cmp_tfunc)
264264
add_tfunc(Core.Intrinsics.ccall, 3, IInf,
265-
function(fptr, rt, at, a...)
265+
function(sv, fptr, rt, at, a...)
266266
if !isType(rt)
267267
return Any
268268
end
@@ -277,12 +277,12 @@ add_tfunc(Core.Intrinsics.ccall, 3, IInf,
277277
return t
278278
end)
279279
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))
281281
add_tfunc(Core.Intrinsics.cglobal, 1, 2,
282-
(fptr, t...)->(isempty(t) ? Ptr{Void} :
282+
(sv, fptr, t...)->(isempty(t) ? Ptr{Void} :
283283
isType(t[1]) ? Ptr{t[1].parameters[1]} : Ptr))
284284
add_tfunc(Core.Intrinsics.select_value, 3, 3,
285-
function (cnd, x, y)
285+
function (sv, cnd, x, y)
286286
if isa(cnd, Const)
287287
if cnd.val === true
288288
return x
@@ -296,7 +296,7 @@ add_tfunc(Core.Intrinsics.select_value, 3, 3,
296296
tmerge(x, y)
297297
end)
298298
add_tfunc(is, 2, 2,
299-
function (x::ANY, y::ANY)
299+
function (sv, x::ANY, y::ANY)
300300
if isa(x,Const) && isa(y,Const)
301301
return Const(x.val===y.val)
302302
elseif isType(x) && isType(y) && isleaftype(x) && isleaftype(y)
@@ -310,23 +310,23 @@ add_tfunc(is, 2, 2,
310310
return Bool
311311
end
312312
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)
322322
add_tfunc(pointerref, 3, 3,
323-
function (a,i,align)
323+
function (sv,a,i,align)
324324
a = widenconst(a)
325325
isa(a,DataType) && a<:Ptr && isa(a.parameters[1],Union{Type,TypeVar}) ? a.parameters[1] : Any
326326
end)
327-
add_tfunc(pointerset, 4, 4, (a,v,i,align)->a)
327+
add_tfunc(pointerset, 4, 4, (sv,a,v,i,align)->a)
328328

329-
function typeof_tfunc(t::ANY)
329+
function typeof_tfunc(sv, t::ANY)
330330
if isa(t,Const)
331331
return Type{typeof(t.val)}
332332
elseif isType(t)
@@ -345,7 +345,7 @@ function typeof_tfunc(t::ANY)
345345
Type{TypeVar(:_,t)}
346346
end
347347
elseif isa(t,Union)
348-
Union{map(typeof_tfunc, t.types)...}
348+
Union{map(t -> typeof_tfunc(sv,t), t.types)...}
349349
elseif isa(t,TypeVar) && !(Any <: t.ub)
350350
Type{t}
351351
else
@@ -354,7 +354,7 @@ function typeof_tfunc(t::ANY)
354354
end
355355
add_tfunc(typeof, 1, 1, typeof_tfunc)
356356
add_tfunc(typeassert, 2, 2,
357-
function (v, t)
357+
function (sv, v, t)
358358
if isType(t)
359359
if isa(v,Const)
360360
if isleaftype(t) && !isa(v.val, t.parameters[1])
@@ -367,7 +367,7 @@ add_tfunc(typeassert, 2, 2,
367367
return v
368368
end)
369369
add_tfunc(isa, 2, 2,
370-
function (v, t)
370+
function (sv, v, t)
371371
if isType(t) && isleaftype(t)
372372
if v t.parameters[1]
373373
return Const(true)
@@ -378,7 +378,7 @@ add_tfunc(isa, 2, 2,
378378
return Bool
379379
end)
380380
add_tfunc(issubtype, 2, 2,
381-
function (a, b)
381+
function (sv, a, b)
382382
if isType(a) && isType(b) && isleaftype(a) && isleaftype(b)
383383
return Const(issubtype(a.parameters[1], b.parameters[1]))
384384
end
@@ -433,7 +433,7 @@ function limit_type_depth(t::ANY, d::Int, cov::Bool, vars)
433433
end
434434

435435
# returns (type, isexact)
436-
function getfield_tfunc(s0::ANY, name)
436+
function getfield_tfunc(sv::InferenceState, s0::ANY, name)
437437
if isa(s0, TypeVar)
438438
s0 = s0.ub
439439
end
@@ -453,7 +453,7 @@ function getfield_tfunc(s0::ANY, name)
453453
s = typeof(s.val)
454454
end
455455
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
457457
end
458458
if isa(s,DataType)
459459
if s.abstract
@@ -530,15 +530,15 @@ function getfield_tfunc(s0::ANY, name)
530530
end
531531
end
532532
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)
536536
if isType(s)
537537
s = s.parameters[1]
538538
else
539539
return Type
540540
end
541-
t, exact = getfield_tfunc(s, name)
541+
t, exact = getfield_tfunc(sv, s, name)
542542
if is(t,Bottom)
543543
return t
544544
end
@@ -559,7 +559,7 @@ end
559559
has_typevars(t::ANY, all=false) = ccall(:jl_has_typevars_, Cint, (Any,Cint), t, all)!=0
560560

561561
# 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...)
563563
if !isType(args[1])
564564
return Any
565565
end
@@ -728,7 +728,7 @@ function builtin_tfunction(f::ANY, argtypes::Array{Any,1}, sv::InferenceState)
728728
# wrong # of args
729729
return Bottom
730730
end
731-
return tf[3](argtypes...)
731+
return tf[3](sv, argtypes...)
732732
end
733733

734734
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
10601060
# allow tuple indexing functions to take advantage of constant
10611061
# index arguments.
10621062
if istopfunction(tm, f, :getindex)
1063-
return getfield_tfunc(argtypes[2], argtypes[3])[1]
1063+
return getfield_tfunc(sv, argtypes[2], argtypes[3])[1]
10641064
elseif istopfunction(tm, f, :next)
1065-
t1 = getfield_tfunc(argtypes[2], argtypes[3])[1]
1065+
t1 = getfield_tfunc(sv, argtypes[2], argtypes[3])[1]
10661066
return t1===Bottom ? Bottom : Tuple{t1, Int}
10671067
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]
10691069
return t1===Bottom ? Bottom : Tuple{t1, Int}
10701070
end
10711071
end

0 commit comments

Comments
 (0)