@@ -4491,6 +4491,8 @@ function inlining_pass(e::Expr, sv::InferenceState, stmts, ins)
4491
4491
if f === _apply
4492
4492
na = length (e. args)
4493
4493
newargs = Vector {Any} (na- 2 )
4494
+ newstmts = Any[]
4495
+ effect_free_upto = 0
4494
4496
for i = 3 : na
4495
4497
aarg = e. args[i]
4496
4498
argt = exprtype (aarg, sv. src, sv. mod)
@@ -4507,14 +4509,25 @@ function inlining_pass(e::Expr, sv::InferenceState, stmts, ins)
4507
4509
newargs[i- 2 ] = Any[ QuoteNode (x) for x in aarg ]
4508
4510
elseif isa (t, DataType) && t. name === Tuple. name && ! isvatuple (t) &&
4509
4511
length (t. parameters) <= sv. params. MAX_TUPLE_SPLAT
4512
+ for k = (effect_free_upto+ 1 ): (i- 3 )
4513
+ as = newargs[k]
4514
+ for kk = 1 : length (as)
4515
+ ak = as[kk]
4516
+ if ! effect_free (ak, sv. src, sv. mod, true )
4517
+ tmpv = newvar! (sv, widenconst (exprtype (ak, sv. src, sv. mod)))
4518
+ push! (newstmts, Expr (:(= ), tmpv, ak))
4519
+ as[kk] = tmpv
4520
+ end
4521
+ end
4522
+ end
4523
+ effect_free_upto = i- 3
4510
4524
if effect_free (aarg, sv. src, sv. mod, true )
4511
4525
# apply(f,t::(x,y)) => f(t[1],t[2])
4512
4526
tmpv = aarg
4513
4527
else
4514
4528
# apply(f,t::(x,y)) => tmp=t; f(tmp[1],tmp[2])
4515
4529
tmpv = newvar! (sv, t)
4516
- insert! (stmts, ins, Expr (:(= ), tmpv, aarg))
4517
- ins += 1
4530
+ push! (newstmts, Expr (:(= ), tmpv, aarg))
4518
4531
end
4519
4532
tp = t. parameters
4520
4533
newargs[i- 2 ] = Any[ mk_getfield (tmpv,j,tp[j]) for j= 1 : length (tp) ]
@@ -4523,6 +4536,8 @@ function inlining_pass(e::Expr, sv::InferenceState, stmts, ins)
4523
4536
return e
4524
4537
end
4525
4538
end
4539
+ splice! (stmts, ins: ins- 1 , newstmts)
4540
+ ins += length (newstmts)
4526
4541
e. args = [Any[e. args[2 ]]; newargs... ]
4527
4542
4528
4543
# now try to inline the simplified call
0 commit comments