From f5fc83ce1382b0e5d3f5475a8aa1b3f1fe250e61 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Wed, 17 May 2017 15:25:54 -0400 Subject: [PATCH] inference: prohibit inlining of methods (un)specialized on Unions TODO: this is helping to avoid a type-system bug mis-computing sparams during intersection, but that can already cause significant problems elsewhere too --- base/inference.jl | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/base/inference.jl b/base/inference.jl index a98e0c8842c91..3bd9f8db9f85f 100644 --- a/base/inference.jl +++ b/base/inference.jl @@ -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) @@ -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