Skip to content

Commit fc47e95

Browse files
authored
fix #39600: broadcast fusion broken for comparison (#39602)
1 parent e7921da commit fc47e95

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

test/syntax.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2696,3 +2696,14 @@ end == 4
26962696
x25652 = x+3
26972697
x25652
26982698
end == 4
2699+
2700+
@testset "issue #39600" begin
2701+
A = 1:.5:2
2702+
@test (!).(1 .< A .< 2) == [true, false, true]
2703+
@test .!(1 .< A .< 2) == [true, false, true]
2704+
@test (.!)(1 .< A .< 2) == [true, false, true]
2705+
2706+
@test ncalls_in_lowered(:((!).(1 .< A .< 2)), GlobalRef(Base, :materialize)) == 1
2707+
@test ncalls_in_lowered(:(.!(1 .< A .< 2)), GlobalRef(Base, :materialize)) == 1
2708+
@test ncalls_in_lowered(:((.!)(1 .< A .< 2)), GlobalRef(Base, :materialize)) == 1
2709+
end

0 commit comments

Comments
 (0)