Skip to content

Commit 617db6b

Browse files
yuyichaotkelman
authored andcommitted
Ignore line number node when counting expressions for inlining. Fix #13551
(cherry picked from commit 5206bca) ref #13553
1 parent e1a3749 commit 617db6b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

base/inference.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,6 +1925,7 @@ end
19251925
function occurs_more(e::ANY, pred, n)
19261926
if isa(e,Expr)
19271927
e = e::Expr
1928+
e.head === :line && return 0
19281929
c = 0
19291930
for a = e.args
19301931
c += occurs_more(a, pred, n)
@@ -2612,10 +2613,17 @@ function inline_worthy(body::Expr, cost::Integer=1000) # precondition: 0 < cost;
26122613
return false
26132614
end
26142615
symlim = 1000 + 5_000_000 ÷ cost
2615-
if length(body.args) < (symlim + 500) ÷ 1000
2616+
nargs = 0
2617+
for arg in body.args
2618+
if (!isa(arg, LineNumberNode) &&
2619+
!(isa(arg, Expr) && (arg::Expr).head === :line))
2620+
nargs += 1
2621+
end
2622+
end
2623+
if nargs < (symlim + 500) ÷ 1000
26162624
symlim *= 16
26172625
symlim ÷= 1000
2618-
if occurs_more(body, e->true, symlim) < symlim
2626+
if occurs_more(body, e->(!isa(e, LineNumberNode)), symlim) < symlim
26192627
return true
26202628
end
26212629
end
@@ -2653,7 +2661,7 @@ end
26532661
const corenumtype = Union{Int32,Int64,Float32,Float64}
26542662

26552663
function inlining_pass(e::Expr, sv, ast)
2656-
if e.head == :method
2664+
if e.head === :method
26572665
# avoid running the inlining pass on function definitions
26582666
return (e,())
26592667
end

0 commit comments

Comments
 (0)