Skip to content

Commit

Permalink
fully ignore assignments to underscore symbols
Browse files Browse the repository at this point in the history
closes #9343
fixes #20931
  • Loading branch information
JeffBezanson committed Aug 2, 2018
1 parent 81835ad commit 520f0a9
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@
(append req opt vararg) rett)))))
;; no optional positional args
(let ((names (map car sparams))
(anames (llist-vars argl)))
(anames (map (lambda (x) (if (underscore-symbol? x) UNUSED x))
(llist-vars argl))))
(if (has-dups (filter (lambda (x) (not (eq? x UNUSED))) anames))
(error "function argument names not unique"))
(if (has-dups names)
Expand All @@ -337,7 +338,7 @@
(let* ((gen (generated-version body))
(nongen (non-generated-version body))
(gname (symbol (string (gensy) "#" (current-julia-module-counter))))
(gf (make-generator-function gname names (llist-vars argl) gen))
(gf (make-generator-function gname names anames gen))
(loc (function-body-lineno body)))
(set! body (insert-after-meta
nongen
Expand Down Expand Up @@ -2387,7 +2388,7 @@
((=)
(let ((v (decl-var (cadr e)))
(rest (find-assigned-vars (caddr e) env)))
(if (or (ssavalue? v) (memq v env) (globalref? v))
(if (or (ssavalue? v) (memq v env) (globalref? v) (underscore-symbol? v))
rest
(cons v rest))))
(else
Expand All @@ -2400,7 +2401,9 @@
(cond ((memq (car e) '(lambda scope-block module toplevel))
'())
((eq? (car e) kind)
(list (decl-var (cadr e))))
(if (underscore-symbol? (cadr e))
'()
(list (decl-var (cadr e)))))
(else
(apply append! (map (lambda (x) (find-decls kind x))
e))))))
Expand All @@ -2415,7 +2418,7 @@
(find-assigned-vars e env)))

(define (unbound-vars e bound tab)
(cond ((or (eq? e 'true) (eq? e 'false) (eq? e UNUSED)) tab)
(cond ((or (eq? e 'true) (eq? e 'false) (eq? e UNUSED) (underscore-symbol? e)) tab)
((symbol? e) (if (not (memq e bound)) (put! tab e #t)) tab)
((or (not (pair? e)) (quoted? e)) tab)
((memq (car e) '(lambda scope-block module toplevel)) tab)
Expand Down Expand Up @@ -2556,7 +2559,7 @@

;; compute set of variables referenced in a lambda but not bound by it
(define (free-vars- e tab)
(cond ((or (eq? e 'true) (eq? e 'false) (eq? e UNUSED)) tab)
(cond ((or (eq? e 'true) (eq? e 'false) (eq? e UNUSED) (underscore-symbol? e)) tab)
((symbol? e) (put! tab e #t))
((and (pair? e) (eq? (car e) 'outerref)) tab)
((and (pair? e) (eq? (car e) 'break-block)) (free-vars- (caddr e) tab))
Expand Down Expand Up @@ -3577,20 +3580,22 @@ f(x) = yt(x)
(value callex)
(else (emit callex)))))
((=)
(let* ((rhs (compile (caddr e) break-labels #t #f))
(lhs (cadr e))
(lhs (if (and arg-map (symbol? lhs))
(get arg-map lhs lhs)
lhs)))
(if (and value rhs)
(let ((rr (if (or (atom? rhs) (ssavalue? rhs) (eq? (car rhs) 'null))
rhs (make-ssavalue))))
(if (not (eq? rr rhs))
(emit `(= ,rr ,rhs)))
(emit `(= ,lhs ,rr))
(if tail (emit-return rr))
rr)
(emit-assignment lhs rhs))))
(let ((lhs (cadr e)))
(if (and (symbol? lhs) (underscore-symbol? lhs))
(compile (caddr e) break-labels value tail)
(let* ((rhs (compile (caddr e) break-labels #t #f))
(lhs (if (and arg-map (symbol? lhs))
(get arg-map lhs lhs)
lhs)))
(if (and value rhs)
(let ((rr (if (or (atom? rhs) (ssavalue? rhs) (eq? (car rhs) 'null))
rhs (make-ssavalue))))
(if (not (eq? rr rhs))
(emit `(= ,rr ,rhs)))
(emit `(= ,lhs ,rr))
(if tail (emit-return rr))
rr)
(emit-assignment lhs rhs))))))
((block)
(let* ((last-fname filename)
(fnm (first-non-meta e))
Expand Down

0 comments on commit 520f0a9

Please sign in to comment.