Skip to content

Commit 11a8e58

Browse files
committed
Wrap typeinf's needtree in InferenceParams.
1 parent 84f7649 commit 11a8e58

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

base/inference.jl

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ type InferenceParams
1717
MAX_TUPLE_SPLAT::Int
1818
MAX_UNION_SPLITTING::Int
1919

20+
# default values will be used for regular compilation, as the compiler calls typeinf_ext
21+
# without specifying, or allowing to override, the inference parameters
2022
InferenceParams(;optimize::Bool=true, inlining::Bool=inlining_enabled(), needtree::Bool=true,
2123
typeunion_len=3::Int, type_depth=7::Int, tupletype_len=15::Int,
2224
tuple_depth=16::Int, tuple_splat=4::Int, union_splitting=4::Int) =
@@ -1620,9 +1622,9 @@ function typeinf_edge(method::Method, atypes::ANY, sparams::SimpleVector, caller
16201622
return typeinf_edge(method, atypes, sparams, true, caller,
16211623
InferenceParams(needtree=false), InferenceHooks())
16221624
end
1623-
function typeinf(method::Method, atypes::ANY, sparams::SimpleVector, needtree::Bool=false)
1624-
return typeinf_edge(method, atypes, sparams, true, nothing,
1625-
InferenceParams(needtree=needtree), InferenceHooks())
1625+
function typeinf(method::Method, atypes::ANY, sparams::SimpleVector,
1626+
params::InferenceParams=InferenceParams())
1627+
return typeinf_edge(method, atypes, sparams, true, nothing, params, InferenceHooks())
16261628
end
16271629
# compute an inferred (optionally optimized) AST without global effects (i.e. updating the cache)
16281630
# TODO: make this use a custom cache, which we then can either keep around or throw away
@@ -2593,7 +2595,7 @@ function inlineable(f::ANY, ft::ANY, e::Expr, atypes::Vector{Any}, sv::Inference
25932595
isa(si, TypeVar) && return NF
25942596
end
25952597

2596-
(linfo, ty, inferred) = typeinf(method, metharg, methsp, false)
2598+
(linfo, ty, inferred) = typeinf(method, metharg, methsp, InferenceParams(needtree=false))
25972599
if linfo === nothing || !inferred
25982600
return invoke_NF()
25992601
end
@@ -2603,7 +2605,7 @@ function inlineable(f::ANY, ft::ANY, e::Expr, atypes::Vector{Any}, sv::Inference
26032605
elseif linfo !== nothing && !linfo.inlineable
26042606
return invoke_NF()
26052607
elseif linfo === nothing || linfo.code === nothing
2606-
(linfo, ty, inferred) = typeinf(method, metharg, methsp, true)
2608+
(linfo, ty, inferred) = typeinf(method, metharg, methsp)
26072609
end
26082610
if linfo === nothing || !inferred || !linfo.inlineable || (ast = linfo.code) === nothing
26092611
return invoke_NF()
@@ -3873,11 +3875,12 @@ function reindex_labels!(linfo::LambdaInfo, sv::InferenceState)
38733875
end
38743876

38753877
function return_type(f::ANY, t::ANY, params::InferenceParams=InferenceParams())
3876-
# TODO: is this correct? when is return_type actually executed, ie. not pure_eval_call'd?
3877-
# also, should pass params to typeinf
3878+
# TODO: are all local calls to return_type processed by pure_eval_call?
3879+
# if not, this behavior isn't correct, as it uses the default params
3880+
# for a call which might have been inferred with a different set of params
38783881
rt = Union{}
38793882
for m in _methods(f, t, -1)
3880-
_, ty, inferred = typeinf(m[3], m[1], m[2], false)
3883+
_, ty, inferred = typeinf(m[3], m[1], m[2], InferenceParams(needtree=false))
38813884
!inferred && return Any
38823885
rt = tmerge(rt, ty, params)
38833886
rt === Any && break
@@ -3891,8 +3894,8 @@ end
38913894
# this ensures that typeinf_ext doesn't recurse before it can add the item to the workq
38923895

38933896
for m in _methods_by_ftype(Tuple{typeof(typeinf_loop), Vararg{Any}}, 10)
3894-
typeinf(m[3], m[1], m[2], true)
3897+
typeinf(m[3], m[1], m[2])
38953898
end
38963899
for m in _methods_by_ftype(Tuple{typeof(typeinf_edge), Vararg{Any}}, 10)
3897-
typeinf(m[3], m[1], m[2], true)
3900+
typeinf(m[3], m[1], m[2])
38983901
end

base/reflection.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ function _dump_function(f::ANY, t::ANY, native::Bool, wrapper::Bool, strip_ir_me
489489
tt, meth.sig, meth.tvars)::SimpleVector
490490
li = func_for_method_checked(meth, tt)
491491
# try to infer it
492-
(linfo, ty, inf) = Core.Inference.typeinf(li, ti, env, true)
492+
(linfo, ty, inf) = Core.Inference.typeinf(li, ti, env)
493493
# get the code for it
494494
return _dump_function(linfo, native, wrapper, strip_ir_metadata, dump_module)
495495
end
@@ -566,7 +566,7 @@ function code_typed(f::ANY, types::ANY=Tuple; optimize=true)
566566
for x in _methods(f,types,-1)
567567
linfo = func_for_method_checked(x[3], types)
568568
if optimize
569-
(li, ty, inf) = Core.Inference.typeinf(linfo, x[1], x[2], true)
569+
(li, ty, inf) = Core.Inference.typeinf(linfo, x[1], x[2])
570570
else
571571
(li, ty, inf) = Core.Inference.typeinf_uncached(linfo, x[1], x[2],
572572
Core.Inference.InferenceParams(optimize=false))

0 commit comments

Comments
 (0)