Skip to content

Commit f5fc83c

Browse files
committed
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
1 parent 0506ab5 commit f5fc83c

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

base/inference.jl

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3076,6 +3076,7 @@ end
30763076
#### finalize and record the result of running type inference ####
30773077

30783078
function isinlineable(m::Method, src::CodeInfo)
3079+
# compute the cost (size) of inlining this code
30793080
inlineable = false
30803081
cost = 1000
30813082
if m.module === _topmod(m.module)
@@ -3168,7 +3169,25 @@ function optimize(me::InferenceState)
31683169
end
31693170

31703171
# determine and cache inlineability
3171-
if !me.src.inlineable && !force_noinline && isdefined(me.linfo, :def)
3172+
if !force_noinline
3173+
# don't keep ASTs for functions specialized on a Union argument
3174+
# TODO: this helps avoid a type-system bug mis-computing sparams during intersection
3175+
sig = unwrap_unionall(me.linfo.specTypes)
3176+
if isa(sig, DataType) && sig.name === Tuple.name
3177+
for P in sig.parameters
3178+
P = unwrap_unionall(P)
3179+
if isa(P, Union)
3180+
force_noinline = true
3181+
break
3182+
end
3183+
end
3184+
else
3185+
force_noinline = true
3186+
end
3187+
end
3188+
if force_noinline
3189+
me.src.inlineable = false
3190+
elseif !me.src.inlineable && isdefined(me.linfo, :def)
31723191
me.src.inlineable = isinlineable(me.linfo.def, me.src)
31733192
end
31743193
me.src.inferred = true

0 commit comments

Comments
 (0)