Skip to content

Commit ac7febc

Browse files
committed
no call to Base.rest if vararg is all-underscore
1 parent af3cd59 commit ac7febc

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/julia-syntax.scm

+9-1
Original file line numberDiff line numberDiff line change
@@ -2112,9 +2112,17 @@
21122112
x (make-ssavalue)))
21132113
(ini (if (eq? x xx) '() (list (sink-assignment xx (expand-forms x)))))
21142114
(n (length lhss))
2115+
;; skip last assignment if it is an all-underscore vararg
2116+
(n (if (> n 0)
2117+
(let ((l (last lhss)))
2118+
(if (and (pair? l) (eq? (car l) '|...|)
2119+
(underscore-symbol? (cadr l)))
2120+
(- n 1)
2121+
n))
2122+
n))
21152123
(st (gensy)))
21162124
`(block
2117-
(local ,st)
2125+
,.(if (> n 0) `((local ,st)) '())
21182126
,@ini
21192127
,.(map (lambda (i lhs)
21202128
(expand-forms

test/syntax.jl

+8
Original file line numberDiff line numberDiff line change
@@ -2613,3 +2613,11 @@ end
26132613
end
26142614

26152615
@test eval(Expr(:if, Expr(:block, Expr(:&&, true, Expr(:call, :(===), 1, 1))), 1, 2)) == 1
2616+
2617+
@testset "all-underscore varargs on the rhs" begin
2618+
@test ncalls_in_lowered(quote _..., = a end, GlobalRef(Base, :rest)) == 0
2619+
@test ncalls_in_lowered(quote ___..., = a end, GlobalRef(Base, :rest)) == 0
2620+
@test ncalls_in_lowered(quote a, _... = b end, GlobalRef(Base, :rest)) == 0
2621+
@test ncalls_in_lowered(quote a, _... = b, c end, GlobalRef(Base, :rest)) == 0
2622+
@test ncalls_in_lowered(quote a, _... = (b...,) end, GlobalRef(Base, :rest)) == 0
2623+
end

0 commit comments

Comments
 (0)