Skip to content

Commit

Permalink
inference: prohibit inlining of methods (un)specialized on Unions
Browse files Browse the repository at this point in the history
TODO: this is helping to avoid a type-system bug mis-computing sparams during intersection,
but that can already cause significant problems elsewhere too
  • Loading branch information
vtjnash committed May 18, 2017
1 parent 2fe4823 commit 3b82cd6
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3076,6 +3076,7 @@ end
#### finalize and record the result of running type inference ####

function isinlineable(m::Method, src::CodeInfo)
# compute the cost (size) of inlining this code
inlineable = false
cost = 1000
if m.module === _topmod(m.module)
Expand Down Expand Up @@ -3168,7 +3169,25 @@ function optimize(me::InferenceState)
end

# determine and cache inlineability
if !me.src.inlineable && !force_noinline && isdefined(me.linfo, :def)
if !force_noinline
# don't keep ASTs for functions specialized on a Union argument
# TODO: this helps avoid a type-system bug mis-computing sparams during intersection
sig = unwrap_unionall(me.linfo.specTypes)
if isa(sig, DataType) && sig.name === Tuple.name
for P in sig.parameters
P = unwrap_unionall(P)
if isa(P, Union)
force_noinline = true
break
end
end
else
force_noinline = true
end
end
if force_noinline
me.src.inlineable = false
elseif !me.src.inlineable && isdefined(me.linfo, :def)
me.src.inlineable = isinlineable(me.linfo.def, me.src)
end
me.src.inferred = true
Expand Down

0 comments on commit 3b82cd6

Please sign in to comment.