summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2010-10-20 22:40:10 +0200
committerLudovic Courtès <ludo@gnu.org>2010-10-20 23:45:59 +0200
commit3a1a883b632f51bf316195a8a180e2e6c52a3363 (patch)
treee6af78c0fe73c1784311ee9f200aa4f38b657cb8
parentfb3fad534629a44545282098104a5538ab2f912c (diff)
downloadguile-3a1a883b632f51bf316195a8a180e2e6c52a3363.tar.gz
Tweak `-Wunused-variable' and `-Wunused-toplevel' for special names.
* module/language/tree-il/analyze.scm (gensym?): New procedure. (unused-variable-analysis): Ignore variables whose name passes `gensym?' or is `_'. (unused-toplevel-analysis): Ignore variables whose name passes `gensym?'. * test-suite/tests/tree-il.test ("warnings")["unused-variable"]("special variable names"): New test. ["unused-toplevel"]("special variable names"): New test.
-rw-r--r--module/language/tree-il/analyze.scm11
-rw-r--r--test-suite/tests/tree-il.test19
2 files changed, 27 insertions, 3 deletions
diff --git a/module/language/tree-il/analyze.scm b/module/language/tree-il/analyze.scm
index 8a5104016..745ce3907 100644
--- a/module/language/tree-il/analyze.scm
+++ b/module/language/tree-il/analyze.scm
@@ -602,6 +602,10 @@ accurate information is missing from a given `tree-il' element."
(vars binding-info-vars) ;; ((GENSYM NAME LOCATION) ...)
(refs binding-info-refs)) ;; (GENSYM ...)
+(define (gensym? sym)
+ ;; Return #t if SYM is (likely) a generated symbol.
+ (string-any #\space (symbol->string sym)))
+
(define unused-variable-analysis
;; Report unused variables in the given tree.
(make-tree-analysis
@@ -662,7 +666,9 @@ accurate information is missing from a given `tree-il' element."
;; the LOCS location stack.
(loc (or (caddr var)
(find pair? locs))))
- (warning 'unused-variable loc name)))))
+ (if (and (not (gensym? name))
+ (not (eq? name '_)))
+ (warning 'unused-variable loc name))))))
vars)
(vlist-drop vars (length inner-vars)))
@@ -835,7 +841,8 @@ accurate information is missing from a given `tree-il' element."
(vlist-for-each (lambda (name+loc)
(let ((name (car name+loc))
(loc (cdr name+loc)))
- (warning 'unused-toplevel loc name)))
+ (if (not (gensym? name))
+ (warning 'unused-toplevel loc name))))
unused))))
(make-reference-graph vlist-null vlist-null #f))))
diff --git a/test-suite/tests/tree-il.test b/test-suite/tests/tree-il.test
index 2294ef2db..e28506fb5 100644
--- a/test-suite/tests/tree-il.test
+++ b/test-suite/tests/tree-il.test
@@ -665,6 +665,16 @@
(null? (call-with-warnings
(lambda ()
(compile '(lambda (x y z) #t)
+ #:opts %opts-w-unused)))))
+
+ (pass-if "special variable names"
+ (null? (call-with-warnings
+ (lambda ()
+ (compile '(lambda ()
+ (let ((_ 'underscore)
+ (#{gensym name}# 'ignore-me))
+ #t))
+ #:to 'assembly
#:opts %opts-w-unused))))))
(with-test-prefix "unused-toplevel"
@@ -766,7 +776,14 @@
'foo)))
(number? (string-contains (cadr w)
(format #f "top-level variable `~A'"
- 'bar)))))))
+ 'bar))))))
+
+ (pass-if "special variable names"
+ (null? (call-with-warnings
+ (lambda ()
+ (compile '(define #{gensym name}# 'ignore-me)
+ #:to 'assembly
+ #:opts %opts-w-unused-toplevel))))))
(with-test-prefix "unbound variable"