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