Skip to content

Commit

Permalink
fix regression in lowering [x... y] caused by #24538 (#24552)
Browse files Browse the repository at this point in the history
recursive calls to `expand-forms` should generally be tail calls,
matching the usual top-down macro expansion order.

(cherry picked from commit 27665e8)
  • Loading branch information
JeffBezanson authored and ararslan committed Nov 21, 2017
1 parent b109dfe commit c4d4898
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2172,7 +2172,7 @@
'=>
(lambda (e)
(syntax-deprecation #f "Expr(:(=>), ...)" "Expr(:call, :(=>), ...)")
`(call => ,(expand-forms (cadr e)) ,(expand-forms (caddr e))))
(expand-forms `(call => ,@(cdr e))))

'cell1d (lambda (e) (error "{ } vector syntax is discontinued"))
'cell2d (lambda (e) (error "{ } matrix syntax is discontinued"))
Expand Down Expand Up @@ -2268,13 +2268,13 @@
(and (length= e 4)
(eq? (cadddr e) ':)))
(error "invalid \":\" outside indexing"))
`(call colon ,.(map expand-forms (cdr e))))
(expand-forms `(call colon ,@(cdr e))))

'vect
(lambda (e) (expand-forms `(call (top vect) ,@(cdr e))))

'hcat
(lambda (e) (expand-forms `(call hcat ,.(map expand-forms (cdr e)))))
(lambda (e) (expand-forms `(call hcat ,@(cdr e))))

'vcat
(lambda (e)
Expand All @@ -2297,7 +2297,7 @@
`(call vcat ,@a))))))

'typed_hcat
(lambda (e) `(call (top typed_hcat) ,(expand-forms (cadr e)) ,.(map expand-forms (cddr e))))
(lambda (e) (expand-forms `(call (top typed_hcat) ,@(cdr e))))

'typed_vcat
(lambda (e)
Expand All @@ -2318,8 +2318,8 @@
,.(apply append rows)))
`(call (top typed_vcat) ,t ,@a)))))

'|'| (lambda (e) `(call ctranspose ,(expand-forms (cadr e))))
'|.'| (lambda (e) `(call transpose ,(expand-forms (cadr e))))
'|'| (lambda (e) (expand-forms `(call ctranspose ,(cadr e))))
'|.'| (lambda (e) (expand-forms `(call transpose ,(cadr e))))

'ccall
(lambda (e)
Expand Down Expand Up @@ -2360,7 +2360,7 @@
,iter))))

'flatten
(lambda (e) `(call (top Flatten) ,(expand-forms (cadr e))))
(lambda (e) (expand-forms `(call (top Flatten) ,(cadr e))))

'comprehension
(lambda (e)
Expand Down
5 changes: 5 additions & 0 deletions test/meta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,8 @@ baremodule B
end
@test B.x == 3
@test B.M.x == 4

# caused by #24538. forms that lower to `call` should wrap with `call` before
# recursively calling expand-forms.
@test [(0,0)... 1] == [0 0 1]
@test Float32[(0,0)... 1] == Float32[0 0 1]

0 comments on commit c4d4898

Please sign in to comment.