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 3, 2018
1 parent f90a12a commit 3f8eed2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 25 deletions.
50 changes: 29 additions & 21 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@
;; GF method does not need to keep decl expressions on lambda args
;; except for rest arg
(define (method-lambda-expr argl body rett)
(let ((argl (map arg-name argl))
(let ((argl (map (lambda (x)
(let ((n (arg-name x)))
(if (underscore-symbol? n) UNUSED n)))
argl))
(body (blockify body)))
`(lambda ,argl ()
(scope-block
Expand Down Expand Up @@ -324,7 +327,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 +341,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 +2391,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 +2404,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 +2421,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 +2562,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 +3583,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
15 changes: 11 additions & 4 deletions src/method.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,19 @@ static void jl_method_set_source(jl_method_t *m, jl_code_info_t *src)
uint8_t j;
uint8_t called = 0;
int gen_only = 0;
for (j = 1; j < m->nargs && j <= 8; j++) {
for (j = 1; j < m->nargs && j <= sizeof(m->nospecialize) * 8; j++) {
jl_value_t *ai = jl_array_ptr_ref(src->slotnames, j);
if (ai == (jl_value_t*)unused_sym)
if (ai == (jl_value_t*)unused_sym) {
// TODO: enable this. currently it triggers a bug on arguments like
// ::Type{>:Missing}
//int sn = j-1;
//m->nospecialize |= (1 << sn);
continue;
if (jl_array_uint8_ref(src->slotflags, j) & 64)
called |= (1 << (j - 1));
}
if (j <= 8) {
if (jl_array_uint8_ref(src->slotflags, j) & 64)
called |= (1 << (j - 1));
}
}
m->called = called;
m->pure = src->pure;
Expand Down

0 comments on commit 3f8eed2

Please sign in to comment.