Skip to content

Commit 295995a

Browse files
simeonschaubKristofferC
authored andcommitted
fix #39600: broadcast fusion broken for comparison (#39602)
(cherry picked from commit fc47e95)
1 parent d37a8d4 commit 295995a

File tree

2 files changed

+39
-27
lines changed

2 files changed

+39
-27
lines changed

src/julia-syntax.scm

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,33 +1769,34 @@
17691769
(args (map dot-to-fuse (cdr kws+args)))
17701770
(make `(call (top ,(if (null? kws) 'broadcasted 'broadcasted_kwsyntax)) ,@kws ,f ,@args)))
17711771
(if top (cons 'fuse make) make)))
1772-
(if (and (length= e 3) (eq? (car e) '|.|))
1773-
(let ((f (cadr e)) (x (caddr e)))
1774-
(cond ((or (atom? x) (eq? (car x) 'quote) (eq? (car x) 'inert) (eq? (car x) '$))
1775-
`(call (top getproperty) ,f ,x))
1776-
((eq? (car x) 'tuple)
1777-
(if (and (eq? (identifier-name f) '^) (length= x 3) (integer? (caddr x)))
1778-
(make-fuse '(top literal_pow)
1779-
(list f (cadr x) (expand-forms `(call (call (core apply_type) (top Val) ,(caddr x))))))
1780-
(make-fuse f (cdr x))))
1781-
(else
1782-
(error (string "invalid syntax \"" (deparse e) "\"")))))
1783-
(if (and (pair? e) (eq? (car e) 'call))
1784-
(begin
1785-
(define (make-fuse- f x)
1786-
(if (and (eq? (identifier-name f) '^) (length= x 2) (integer? (cadr x)))
1787-
(make-fuse '(top literal_pow)
1788-
(list f (car x) (expand-forms `(call (call (core apply_type) (top Val) ,(cadr x))))))
1789-
(make-fuse f x)))
1790-
(let ((f (cadr e)))
1791-
(cond ((dotop-named? f)
1792-
(make-fuse- (undotop f) (cddr e)))
1793-
;; (.+)(a, b) is parsed as (call (|.| +) a b), but we still want it to fuse
1794-
((and (length= f 2) (eq? (car f) '|.|))
1795-
(make-fuse- (cadr f) (cddr e)))
1796-
(else
1797-
e))))
1798-
e)))
1772+
(cond ((and (length= e 3) (eq? (car e) '|.|))
1773+
(let ((f (cadr e)) (x (caddr e)))
1774+
(cond ((or (atom? x) (eq? (car x) 'quote) (eq? (car x) 'inert) (eq? (car x) '$))
1775+
`(call (top getproperty) ,f ,x))
1776+
((eq? (car x) 'tuple)
1777+
(if (and (eq? (identifier-name f) '^) (length= x 3) (integer? (caddr x)))
1778+
(make-fuse '(top literal_pow)
1779+
(list f (cadr x) (expand-forms `(call (call (core apply_type) (top Val) ,(caddr x))))))
1780+
(make-fuse f (cdr x))))
1781+
(else
1782+
(error (string "invalid syntax \"" (deparse e) "\""))))))
1783+
((and (pair? e) (eq? (car e) 'call))
1784+
(define (make-fuse- f x)
1785+
(if (and (eq? (identifier-name f) '^) (length= x 2) (integer? (cadr x)))
1786+
(make-fuse '(top literal_pow)
1787+
(list f (car x) (expand-forms `(call (call (core apply_type) (top Val) ,(cadr x))))))
1788+
(make-fuse f x)))
1789+
(let ((f (cadr e)))
1790+
(cond ((dotop-named? f)
1791+
(make-fuse- (undotop f) (cddr e)))
1792+
;; (.+)(a, b) is parsed as (call (|.| +) a b), but we still want it to fuse
1793+
((and (length= f 2) (eq? (car f) '|.|))
1794+
(make-fuse- (cadr f) (cddr e)))
1795+
(else
1796+
e))))
1797+
((and (pair? e) (eq? (car e) 'comparison))
1798+
(dot-to-fuse (expand-compare-chain (cdr e)) top))
1799+
(else e)))
17991800
(let ((e (dot-to-fuse rhs #t)) ; an expression '(fuse func args) if expr is a dot call
18001801
(lhs-view (ref-to-view lhs))) ; x[...] expressions on lhs turn in to view(x, ...) to update x in-place
18011802
(if (fuse? e)

test/syntax.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2663,3 +2663,14 @@ end == 4
26632663
x25652 = x+3
26642664
x25652
26652665
end == 4
2666+
2667+
@testset "issue #39600" begin
2668+
A = 1:.5:2
2669+
@test (!).(1 .< A .< 2) == [true, false, true]
2670+
@test .!(1 .< A .< 2) == [true, false, true]
2671+
@test (.!)(1 .< A .< 2) == [true, false, true]
2672+
2673+
@test ncalls_in_lowered(:((!).(1 .< A .< 2)), GlobalRef(Base, :materialize)) == 1
2674+
@test ncalls_in_lowered(:(.!(1 .< A .< 2)), GlobalRef(Base, :materialize)) == 1
2675+
@test ncalls_in_lowered(:((.!)(1 .< A .< 2)), GlobalRef(Base, :materialize)) == 1
2676+
end

0 commit comments

Comments
 (0)