* [PATCH 1/3] Add -Wunused-module.
2023-02-11 23:32 ` [PATCH 0/3] Add '-Wunused-module' Ludovic Courtès
@ 2023-02-11 23:32 ` Ludovic Courtès
2023-02-11 23:32 ` [PATCH 2/3] Add 'record-case' to '.dir-locals.el' Ludovic Courtès
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Ludovic Courtès @ 2023-02-11 23:32 UTC (permalink / raw)
To: guile-devel; +Cc: guix-devel, Ludovic Courtès
* module/language/tree-il/analyze.scm (<module-info>): New record type.
(unused-module-analysis): New variable.
(make-unused-module-analysis): New analysis.
(make-analyzer): Add it.
* module/system/base/message.scm (%warning-types): Add 'unused-module'.
* test-suite/tests/tree-il.test (%opts-w-unused-module): New variable.
("warnings")["unused-module"]: New test prefix.
* NEWS: Update.
---
NEWS | 17 ++++
module/language/tree-il/analyze.scm | 138 ++++++++++++++++++++++++++-
module/system/base/message.scm | 11 ++-
test-suite/tests/tree-il.test | 141 +++++++++++++++++++++++++++-
4 files changed, 304 insertions(+), 3 deletions(-)
diff --git a/NEWS b/NEWS
index 4313880c7..a0009406f 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,23 @@ See the end for copying conditions.
Please send Guile bug reports to bug-guile@gnu.org.
+\f
+Changes in 3.0.10 (since 3.0.9)
+
+* New interfaces and functionality
+
+** New warning: unused-module
+
+This analysis, enabled at `-W2', issues warnings for modules that appear
+in a `use-modules' form or as a #:use-module clause of `define-module',
+and whose bindings are unused. This is useful to trim the list of
+imports of a module.
+
+In some cases, the compiler cannot conclude whether a module is
+definitely unused---this is notably the case for modules that are only
+used at macro-expansion time, such as (srfi srfi-26). In those cases,
+the compiler reports it as "possibly unused".
+
\f
Changes in 3.0.9 (since 3.0.8)
diff --git a/module/language/tree-il/analyze.scm b/module/language/tree-il/analyze.scm
index 7918b9ddd..ef68e2b9b 100644
--- a/module/language/tree-il/analyze.scm
+++ b/module/language/tree-il/analyze.scm
@@ -1,6 +1,6 @@
;;; Diagnostic warnings for Tree-IL
-;; Copyright (C) 2001,2008-2014,2016,2018-2022 Free Software Foundation, Inc.
+;; Copyright (C) 2001,2008-2014,2016,2018-2023 Free Software Foundation, Inc.
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
@@ -334,6 +334,139 @@ given `tree-il' element."
(make-reference-graph vlist-null vlist-null #f))))
+\f
+;;;
+;;; Unused module analysis.
+;;;
+
+;; Module uses and references to bindings of imported modules.
+(define-record-type <module-info>
+ (module-info location qualified-references
+ toplevel-references toplevel-definitions)
+ module-info?
+ (location module-info-location) ;location vector | #f
+ (qualified-references module-info-qualified-references) ;module name vhash
+ (toplevel-references module-info-toplevel-references) ;list of symbols
+ (toplevel-definitions module-info-toplevel-definitions)) ;symbol vhash
+
+(define unused-module-analysis
+ ;; Report unused modules in the given tree.
+ (make-tree-analysis
+ (lambda (x info env locs)
+ ;; Going down into X: extend INFO accordingly.
+ (match x
+ ((or ($ <module-ref> loc module name)
+ ($ <module-set> loc module name))
+ (let ((references (module-info-qualified-references info)))
+ (if (vhash-assoc module references)
+ info
+ (module-info (module-info-location info)
+ (vhash-cons module #t references)
+ (module-info-toplevel-references info)
+ (module-info-toplevel-definitions info)))))
+ ((or ($ <toplevel-ref> loc module name)
+ ($ <toplevel-set> loc module name))
+ (if (equal? module (module-name env))
+ (let ((references (module-info-toplevel-references info)))
+ (module-info (module-info-location info)
+ (module-info-qualified-references info)
+ (cons x references)
+ (module-info-toplevel-definitions info)))
+ (let ((references (module-info-qualified-references info)))
+ (module-info (module-info-location info)
+ (vhash-cons module #t references)
+ (module-info-toplevel-references info)
+ (module-info-toplevel-definitions info)))))
+ (($ <toplevel-define> loc module name)
+ (module-info (module-info-location info)
+ (module-info-qualified-references info)
+ (module-info-toplevel-references info)
+ (vhash-consq name x
+ (module-info-toplevel-definitions info))))
+
+ ;; Record the approximate location of the module import. We
+ ;; could parse the #:imports arguments to determine the location
+ ;; of each #:use-module but we'll leave that as an exercise for
+ ;; the reader.
+ (($ <call> loc ($ <module-ref> _ '(guile) 'define-module*))
+ (module-info loc
+ (module-info-qualified-references info)
+ (module-info-toplevel-references info)
+ (module-info-toplevel-definitions info)))
+ (($ <call> loc ($ <module-ref> _ '(guile) 'process-use-modules))
+ (module-info loc
+ (module-info-qualified-references info)
+ (module-info-toplevel-references info)
+ (module-info-toplevel-definitions info)))
+
+ (_
+ info)))
+
+ (lambda (x info env locs) ;leaving X's scope
+ info)
+
+ (lambda (info env) ;finishing
+ (define (defining-module ref env)
+ ;; Return the name of the module that defines REF, a
+ ;; <toplevel-ref> or <toplevel-set>, in ENV.
+ (let ((name (if (toplevel-ref? ref)
+ (toplevel-ref-name ref)
+ (toplevel-set-name ref))))
+ (match (vhash-assq name (module-info-toplevel-definitions info))
+ (#f
+ ;; NAME is not among the top-level definitions of this
+ ;; compilation unit, so check which module provides it.
+ (and=> (module-variable env name)
+ (lambda (variable)
+ (and=> (find (lambda (module)
+ (module-reverse-lookup module variable))
+ (module-uses env))
+ module-name))))
+ (_
+ (if (toplevel-ref? ref)
+ (toplevel-ref-mod ref)
+ (toplevel-set-mod ref))))))
+
+ (define (module-exports-macros? module)
+ ;; Return #t if MODULE exports one or more macros.
+ (let ((tag (make-prompt-tag "return")))
+ (call-with-prompt tag
+ (lambda ()
+ (module-for-each (lambda (symbol variable)
+ (when (and (variable-bound? variable)
+ (macro?
+ (variable-ref variable)))
+ (abort-to-prompt tag #t)))
+ module)
+ #f)
+ (lambda (k exports-macros?)
+ exports-macros?))))
+
+ (let ((used-modules ;list of modules actually used
+ (fold (lambda (reference modules)
+ (let ((module (defining-module reference env)))
+ (if (or (not module) (vhash-assoc module modules))
+ modules
+ (vhash-cons module #t modules))))
+ (module-info-qualified-references info)
+ (module-info-toplevel-references info))))
+
+ ;; Compare the modules imported by ENV with USED-MODULES, which
+ ;; is the list of modules actually referenced.
+ (for-each (lambda (module)
+ (unless (vhash-assoc (module-name module) used-modules)
+ ;; If MODULE exports macros, and if the expansion
+ ;; of those macros doesn't contain <module-ref>s
+ ;; inside MODULE, then we cannot conclude whether
+ ;; or not MODULE is used.
+ (warning 'unused-module
+ (module-info-location info)
+ (module-name module)
+ (not (module-exports-macros? module)))))
+ (module-uses env))))
+
+ (module-info #f vlist-null '() vlist-null)))
+
\f
;;;
;;; Shadowed top-level definition analysis.
@@ -1268,6 +1401,8 @@ resort, return #t when EXP refers to the global variable SPECIAL-NAME."
#:level 3 #:kind unused-variable #:analysis unused-variable-analysis)
(define-analysis make-unused-toplevel-analysis
#:level 2 #:kind unused-toplevel #:analysis unused-toplevel-analysis)
+(define-analysis make-unused-module-analysis
+ #:level 2 #:kind unused-module #:analysis unused-module-analysis)
(define-analysis make-shadowed-toplevel-analysis
#:level 2 #:kind shadowed-toplevel #:analysis shadowed-toplevel-analysis)
(define-analysis make-arity-analysis
@@ -1287,6 +1422,7 @@ resort, return #t when EXP refers to the global variable SPECIAL-NAME."
(analysis (cons analysis tail)))))))
(let ((analyses (compute-analyses make-unused-variable-analysis
make-unused-toplevel-analysis
+ make-unused-module-analysis
make-shadowed-toplevel-analysis
make-arity-analysis
make-format-analysis
diff --git a/module/system/base/message.scm b/module/system/base/message.scm
index 869afa783..92ec0389d 100644
--- a/module/system/base/message.scm
+++ b/module/system/base/message.scm
@@ -1,6 +1,6 @@
;;; User interface messages
-;; Copyright (C) 2009-2012,2016,2018,2020-2021 Free Software Foundation, Inc.
+;; Copyright (C) 2009-2012,2016,2018,2020-2021,2023 Free Software Foundation, Inc.
;;; This library is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU Lesser General Public License as published by
@@ -115,6 +115,15 @@
(emit port "~A: warning: possibly unused local top-level variable `~A'~%"
loc name)))
+ (unused-module
+ "report unused modules"
+ ,(lambda (port loc name definitely-unused?)
+ (if definitely-unused?
+ (emit port "~A: warning: unused module ~a~%"
+ loc name)
+ (emit port "~A: warning: possibly unused module ~a~%"
+ loc name))))
+
(shadowed-toplevel
"report shadowed top-level variables"
,(lambda (port loc name previous-loc)
diff --git a/test-suite/tests/tree-il.test b/test-suite/tests/tree-il.test
index b296be336..b64d6fcfc 100644
--- a/test-suite/tests/tree-il.test
+++ b/test-suite/tests/tree-il.test
@@ -1,7 +1,7 @@
;;;; tree-il.test --- test suite for compiling tree-il -*- scheme -*-
;;;; Andy Wingo <wingo@pobox.com> --- May 2009
;;;;
-;;;; Copyright (C) 2009-2014,2018-2021 Free Software Foundation, Inc.
+;;;; Copyright (C) 2009-2014,2018-2021,2023 Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
@@ -217,6 +217,9 @@
(define %opts-w-unused-toplevel
'(#:warnings (unused-toplevel)))
+(define %opts-w-unused-module
+ '(#:warnings (unused-module)))
+
(define %opts-w-shadowed-toplevel
'(#:warnings (shadowed-toplevel)))
@@ -414,6 +417,142 @@
#:to 'cps
#:opts %opts-w-unused-toplevel))))))
+ (with-test-prefix "unused-module"
+
+ (pass-if-equal "quiet"
+ '()
+ (call-with-warnings
+ (lambda ()
+ (compile '(begin
+ (use-modules (ice-9 popen))
+ (define (proc cmd)
+ (open-input-pipe cmd)))
+ #:env (make-fresh-user-module)
+ #:opts %opts-w-unused-module))))
+
+ (pass-if-equal "quiet, renamer"
+ '()
+ (call-with-warnings
+ (lambda ()
+ (compile '(begin
+ (use-modules ((ice-9 popen) #:prefix p-))
+ (define (proc cmd)
+ (p-open-input-pipe cmd)))
+ #:env (make-fresh-user-module)
+ #:opts %opts-w-unused-module))))
+
+ (pass-if "definitely unused"
+ (let* ((defmod '(define-module (foo)
+ #:use-module (ice-9 vlist)
+ #:use-module (ice-9 popen)
+ #:export (proc)))
+ (w (call-with-warnings
+ (lambda ()
+ (set-source-properties! defmod
+ '((filename . "foo.scm")
+ (line . 0)
+ (column . 0)))
+ (compile `(begin
+ ,defmod
+ (define (frob x)
+ (vlist-cons x vlist-null)))
+ #:env (make-fresh-user-module)
+ #:opts %opts-w-unused-module)))))
+ (and (= (length w) 1)
+ (string-prefix? "foo.scm:1:0" (car w))
+ (number? (string-contains (car w)
+ "unused module (ice-9 popen)")))))
+
+ (pass-if "definitely unused, use-modules"
+ (let* ((usemod '(use-modules (rnrs bytevectors)
+ (ice-9 q)))
+ (w (call-with-warnings
+ (lambda ()
+ (set-source-properties! usemod
+ '((filename . "bar.scm")
+ (line . 5)
+ (column . 0)))
+ (compile `(begin
+ ,usemod
+ (define (square x)
+ (* x x)))
+ #:env (make-fresh-user-module)
+ #:opts %opts-w-unused-module)))))
+ (and (= (length w) 2)
+ (string-prefix? "bar.scm:6:0" (car w))
+ (number? (string-contains (car w)
+ "unused module (rnrs bytevectors)"))
+ (number? (string-contains (cadr w)
+ "unused module (ice-9 q)")))))
+
+ (pass-if "definitely unused, local binding shadows imported one"
+ (let ((w (call-with-warnings
+ (lambda ()
+ (compile `(begin
+ (define-module (whatever x y z)
+ #:use-module (ice-9 popen)
+ #:export (frob))
+
+ (define (open-input-pipe x)
+ ;; Shadows the one from (ice-9 popen).
+ x)
+ (define (frob y)
+ (close-port (open-input-pipe y))))
+ #:env (make-fresh-user-module)
+ #:opts %opts-w-unused-module)))))
+ (and (= (length w) 1)
+ (number? (string-contains (car w)
+ "unused module (ice-9 popen)")))))
+
+ (pass-if-equal "(ice-9 match) is actually used"
+ '()
+ ;; (ice-9 match) is used and the macro expansion of the 'match'
+ ;; form refers to (@@ (ice-9 match) car) and the likes.
+ (call-with-warnings
+ (lambda ()
+ (compile '(begin
+ (use-modules (ice-9 match))
+ (define (proc lst)
+ (match lst
+ ((a b c) (+ a (* b c))))))
+ #:env (make-fresh-user-module)
+ #:opts %opts-w-unused-module))))
+
+ (pass-if "(srfi srfi-26) might be unused"
+ ;; At the tree-il level, it is impossible to know whether (srfi
+ ;; srfi-26) is actually use, because all we see is the output of
+ ;; macro expansion, and in this case it doesn't capture any
+ ;; binding from (srfi srfi-26).
+ (let* ((w (call-with-warnings
+ (lambda ()
+ (compile `(begin
+ (define-module (whatever)
+ #:use-module (srfi srfi-26)
+ #:export (square))
+ (define double
+ (cut * 2 <>)))
+ #:env (make-fresh-user-module)
+ #:opts %opts-w-unused-module)))))
+ (and (= (length w) 1)
+ (number? (string-contains (car w)
+ "possibly unused module (srfi srfi-26)")))))
+
+ (pass-if-equal "(ice-9 format) is actually used"
+ '()
+ ;; The 'format' binding of (ice-9 format) takes precedence over
+ ;; (@@ (guile) format), so (ice-9 format) must not be reported as
+ ;; unused.
+ (call-with-warnings
+ (lambda ()
+ (compile '(begin
+ (define-module (whatever-else)
+ #:use-module (ice-9 format)
+ #:export (proc))
+ (define (proc lst)
+ (format #f "~{~a ~}~%" lst)))
+ #:env (make-fresh-user-module)
+ #:opts %opts-w-unused-module)))))
+
(with-test-prefix "shadowed-toplevel"
(pass-if "quiet"
--
2.39.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/3] Add 'record-case' to '.dir-locals.el'.
2023-02-11 23:32 ` [PATCH 0/3] Add '-Wunused-module' Ludovic Courtès
2023-02-11 23:32 ` [PATCH 1/3] Add -Wunused-module Ludovic Courtès
@ 2023-02-11 23:32 ` Ludovic Courtès
2023-02-11 23:32 ` [PATCH 3/3] Remove unnecessary module imports Ludovic Courtès
2023-02-12 18:14 ` [PATCH 0/3] Add '-Wunused-module' Jan Nieuwenhuizen
3 siblings, 0 replies; 7+ messages in thread
From: Ludovic Courtès @ 2023-02-11 23:32 UTC (permalink / raw)
To: guile-devel; +Cc: guix-devel, Ludovic Courtès
* module/language/tree-il/fix-letrec.scm (fix-letrec): Remove "Local
Variables" bit.
* .dir-locals.el (scheme-mode): Add 'record-case'.
---
.dir-locals.el | 1 +
module/language/tree-il/fix-letrec.scm | 4 ----
2 files changed, 1 insertion(+), 4 deletions(-)
diff --git a/.dir-locals.el b/.dir-locals.el
index 90257e7bf..908670479 100644
--- a/.dir-locals.el
+++ b/.dir-locals.el
@@ -47,6 +47,7 @@
(eval . (put '$letrec 'scheme-indent-function 3))
(eval . (put '$kclause 'scheme-indent-function 1))
(eval . (put '$fun 'scheme-indent-function 1))
+ (eval . (put 'record-case 'scheme-indent-function 1))
(eval . (put 'syntax-parameterize 'scheme-indent-function 1))))
(emacs-lisp-mode . ((indent-tabs-mode . nil)))
(texinfo-mode . ((indent-tabs-mode . nil)
diff --git a/module/language/tree-il/fix-letrec.scm b/module/language/tree-il/fix-letrec.scm
index 2cd550ae9..12c1d500a 100644
--- a/module/language/tree-il/fix-letrec.scm
+++ b/module/language/tree-il/fix-letrec.scm
@@ -318,7 +318,3 @@
(else x)))
x)))
-
-;;; Local Variables:
-;;; eval: (put 'record-case 'scheme-indent-function 1)
-;;; End:
--
2.39.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/3] Remove unnecessary module imports.
2023-02-11 23:32 ` [PATCH 0/3] Add '-Wunused-module' Ludovic Courtès
2023-02-11 23:32 ` [PATCH 1/3] Add -Wunused-module Ludovic Courtès
2023-02-11 23:32 ` [PATCH 2/3] Add 'record-case' to '.dir-locals.el' Ludovic Courtès
@ 2023-02-11 23:32 ` Ludovic Courtès
2023-02-12 18:14 ` [PATCH 0/3] Add '-Wunused-module' Jan Nieuwenhuizen
3 siblings, 0 replies; 7+ messages in thread
From: Ludovic Courtès @ 2023-02-11 23:32 UTC (permalink / raw)
To: guile-devel; +Cc: guix-devel, Ludovic Courtès
These were found with:
make GUILE_WARNINGS='-W1 -Wunused-module'
* module/ice-9/copy-tree.scm:
* module/ice-9/eval-string.scm:
* module/ice-9/getopt-long.scm:
* module/ice-9/poll.scm:
* module/ice-9/popen.scm:
* module/ice-9/sandbox.scm:
* module/ice-9/threads.scm:
* module/sxml/apply-templates.scm:
* module/sxml/simple.scm:
* module/system/base/types.scm:
* module/system/repl/command.scm:
* module/system/repl/common.scm:
* module/system/repl/coop-server.scm:
* module/system/repl/debug.scm:
* module/system/repl/error-handling.scm:
* module/system/repl/repl.scm:
* module/system/repl/server.scm:
* module/system/vm/assembler.scm:
* module/system/vm/disassembler.scm:
* module/system/vm/dwarf.scm:
* module/system/vm/elf.scm:
* module/system/vm/frame.scm:
* module/system/vm/inspect.scm:
* module/system/vm/linker.scm:
* module/system/vm/program.scm:
* module/system/vm/trace.scm:
* module/system/vm/trap-state.scm:
* module/system/vm/traps.scm:
* module/system/xref.scm:
* module/texinfo/indexing.scm:
* module/texinfo/plain-text.scm:
* module/texinfo/reflection.scm:
* module/texinfo/string-utils.scm:
* module/web/client.scm:
* module/web/http.scm:
* module/web/request.scm:
* module/web/response.scm: Remove imports of unused modules.
---
module/ice-9/copy-tree.scm | 1 -
module/ice-9/eval-string.scm | 1 -
module/ice-9/getopt-long.scm | 1 -
module/ice-9/poll.scm | 1 -
module/ice-9/popen.scm | 1 -
module/ice-9/sandbox.scm | 1 -
module/ice-9/threads.scm | 1 -
module/sxml/apply-templates.scm | 2 --
module/sxml/simple.scm | 1 -
module/system/base/types.scm | 1 -
module/system/repl/command.scm | 3 ---
module/system/repl/common.scm | 2 --
module/system/repl/coop-server.scm | 1 -
module/system/repl/debug.scm | 6 ------
module/system/repl/error-handling.scm | 1 -
module/system/repl/repl.scm | 4 ----
module/system/repl/server.scm | 1 -
module/system/vm/assembler.scm | 2 --
module/system/vm/disassembler.scm | 2 --
module/system/vm/dwarf.scm | 2 --
module/system/vm/elf.scm | 2 --
module/system/vm/frame.scm | 2 --
module/system/vm/inspect.scm | 5 -----
module/system/vm/linker.scm | 2 --
module/system/vm/program.scm | 1 -
module/system/vm/trace.scm | 3 ---
module/system/vm/trap-state.scm | 1 -
module/system/vm/traps.scm | 2 --
module/system/xref.scm | 1 -
module/texinfo/indexing.scm | 1 -
module/texinfo/plain-text.scm | 3 ---
module/texinfo/reflection.scm | 2 --
module/texinfo/string-utils.scm | 2 --
module/web/client.scm | 3 ---
module/web/http.scm | 2 --
module/web/request.scm | 1 -
module/web/response.scm | 2 --
37 files changed, 70 deletions(-)
diff --git a/module/ice-9/copy-tree.scm b/module/ice-9/copy-tree.scm
index e1d91ad9e..004167821 100644
--- a/module/ice-9/copy-tree.scm
+++ b/module/ice-9/copy-tree.scm
@@ -23,7 +23,6 @@
(define-module (ice-9 copy-tree)
- #:use-module (ice-9 match)
#:use-module (srfi srfi-11)
#:replace (copy-tree))
diff --git a/module/ice-9/eval-string.scm b/module/ice-9/eval-string.scm
index 789980938..ea0f17777 100644
--- a/module/ice-9/eval-string.scm
+++ b/module/ice-9/eval-string.scm
@@ -21,7 +21,6 @@
(define-module (ice-9 eval-string)
#:use-module (system base compile)
#:use-module (system base language)
- #:use-module (system vm program)
#:use-module (system vm loader)
#:replace (eval-string))
diff --git a/module/ice-9/getopt-long.scm b/module/ice-9/getopt-long.scm
index 14eaf8e23..18b235390 100644
--- a/module/ice-9/getopt-long.scm
+++ b/module/ice-9/getopt-long.scm
@@ -161,7 +161,6 @@
#:use-module (srfi srfi-9)
#:use-module (ice-9 match)
#:use-module (ice-9 regex)
- #:use-module (ice-9 optargs)
#:export (getopt-long option-ref))
(define %program-name (make-fluid "guile"))
diff --git a/module/ice-9/poll.scm b/module/ice-9/poll.scm
index 57b5047ab..2688270ac 100644
--- a/module/ice-9/poll.scm
+++ b/module/ice-9/poll.scm
@@ -19,7 +19,6 @@
(define-module (ice-9 poll)
#:use-module (srfi srfi-9)
- #:use-module (srfi srfi-9 gnu)
#:use-module (rnrs bytevectors)
#:export (make-empty-poll-set
poll-set?
diff --git a/module/ice-9/popen.scm b/module/ice-9/popen.scm
index e638726a4..957cde0aa 100644
--- a/module/ice-9/popen.scm
+++ b/module/ice-9/popen.scm
@@ -19,7 +19,6 @@
;;;;
(define-module (ice-9 popen)
- #:use-module (rnrs bytevectors)
#:use-module (ice-9 binary-ports)
#:use-module (ice-9 threads)
#:use-module (srfi srfi-1)
diff --git a/module/ice-9/sandbox.scm b/module/ice-9/sandbox.scm
index fcfc57365..601485cce 100644
--- a/module/ice-9/sandbox.scm
+++ b/module/ice-9/sandbox.scm
@@ -21,7 +21,6 @@
;;; Code:
(define-module (ice-9 sandbox)
- #:use-module (ice-9 control)
#:use-module (ice-9 match)
#:use-module ((ice-9 threads) #:select (current-thread))
#:use-module (system vm vm)
diff --git a/module/ice-9/threads.scm b/module/ice-9/threads.scm
index c42bd266f..5a13cec1d 100644
--- a/module/ice-9/threads.scm
+++ b/module/ice-9/threads.scm
@@ -31,7 +31,6 @@
(define-module (ice-9 threads)
#:use-module (ice-9 match)
- #:use-module (ice-9 control)
;; These bindings are marked as #:replace because when deprecated code
;; is enabled, (ice-9 deprecated) also exports these names.
;; (Referencing one of the deprecated names prints a warning directing
diff --git a/module/sxml/apply-templates.scm b/module/sxml/apply-templates.scm
index 0ee27477c..dd2742397 100644
--- a/module/sxml/apply-templates.scm
+++ b/module/sxml/apply-templates.scm
@@ -49,9 +49,7 @@
;;; Code:
(define-module (sxml apply-templates)
- #:use-module (sxml ssax)
#:use-module ((sxml xpath) :hide (filter))
-
#:export (apply-templates))
(define (apply-templates tree templates)
diff --git a/module/sxml/simple.scm b/module/sxml/simple.scm
index 703ad9137..57fccbc9c 100644
--- a/module/sxml/simple.scm
+++ b/module/sxml/simple.scm
@@ -30,7 +30,6 @@
#:use-module (sxml ssax)
#:use-module (sxml transform)
#:use-module (ice-9 match)
- #:use-module (srfi srfi-13)
#:export (xml->sxml sxml->xml sxml->string))
;; Helpers from upstream/SSAX.scm.
diff --git a/module/system/base/types.scm b/module/system/base/types.scm
index b63febff8..7ed038d3a 100644
--- a/module/system/base/types.scm
+++ b/module/system/base/types.scm
@@ -20,7 +20,6 @@
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-9)
#:use-module (srfi srfi-9 gnu)
- #:use-module (srfi srfi-11)
#:use-module (srfi srfi-26)
#:use-module (srfi srfi-60)
#:use-module (ice-9 match)
diff --git a/module/system/repl/command.scm b/module/system/repl/command.scm
index 0024fd165..74187270a 100644
--- a/module/system/repl/command.scm
+++ b/module/system/repl/command.scm
@@ -20,7 +20,6 @@
;;; Code:
(define-module (system repl command)
- #:use-module (system base syntax)
#:use-module (system base pmatch)
#:autoload (system base compile) (compile-file)
#:use-module (system repl common)
@@ -31,14 +30,12 @@
#:use-module (system vm loader)
#:use-module (system vm program)
#:use-module (system vm trap-state)
- #:use-module (system vm vm)
#:autoload (system base language) (lookup-language language-reader
language-title language-name)
#:autoload (system vm trace) (call-with-trace)
#:use-module (ice-9 format)
#:use-module (ice-9 session)
#:use-module (ice-9 documentation)
- #:use-module (ice-9 and-let-star)
#:use-module (ice-9 rdelim)
#:use-module (ice-9 control)
#:use-module ((ice-9 pretty-print) #:select ((pretty-print . pp)))
diff --git a/module/system/repl/common.scm b/module/system/repl/common.scm
index 8c5426d37..59b5c494a 100644
--- a/module/system/repl/common.scm
+++ b/module/system/repl/common.scm
@@ -22,8 +22,6 @@
#:use-module (system base syntax)
#:use-module (system base compile)
#:use-module (system base language)
- #:use-module (system base message)
- #:use-module (system vm program)
#:use-module (system vm loader)
#:use-module (ice-9 control)
#:use-module (ice-9 copy-tree)
diff --git a/module/system/repl/coop-server.scm b/module/system/repl/coop-server.scm
index c29bbd645..aaab44f6e 100644
--- a/module/system/repl/coop-server.scm
+++ b/module/system/repl/coop-server.scm
@@ -21,7 +21,6 @@
(define-module (system repl coop-server)
#:use-module (ice-9 match)
- #:use-module (ice-9 receive)
#:use-module (ice-9 threads)
#:use-module (ice-9 q)
#:use-module (srfi srfi-9)
diff --git a/module/system/repl/debug.scm b/module/system/repl/debug.scm
index 383d37921..c83241340 100644
--- a/module/system/repl/debug.scm
+++ b/module/system/repl/debug.scm
@@ -19,17 +19,11 @@
;;; Code:
(define-module (system repl debug)
- #:use-module (system base pmatch)
#:use-module (system base syntax)
- #:use-module (system base language)
- #:use-module (system vm vm)
#:use-module (system vm frame)
#:use-module (system vm debug)
#:use-module (ice-9 format)
#:use-module (ice-9 match)
- #:use-module (ice-9 rdelim)
- #:use-module (ice-9 pretty-print)
- #:use-module ((system vm inspect) #:select ((inspect . %inspect)))
#:use-module (system vm program)
#:export (<debug>
make-debug debug?
diff --git a/module/system/repl/error-handling.scm b/module/system/repl/error-handling.scm
index 8d5a8a5f0..c12ca6f4a 100644
--- a/module/system/repl/error-handling.scm
+++ b/module/system/repl/error-handling.scm
@@ -20,7 +20,6 @@
;;; Code:
(define-module (system repl error-handling)
- #:use-module (system base pmatch)
#:use-module (system vm trap-state)
#:use-module (system repl debug)
#:use-module (ice-9 format)
diff --git a/module/system/repl/repl.scm b/module/system/repl/repl.scm
index 5b27125f1..d83d28759 100644
--- a/module/system/repl/repl.scm
+++ b/module/system/repl/repl.scm
@@ -21,11 +21,7 @@
;;; Code:
(define-module (system repl repl)
- #:use-module (system base syntax)
- #:use-module (system base pmatch)
- #:use-module (system base compile)
#:use-module (system base language)
- #:use-module (system vm vm)
#:use-module (system repl error-handling)
#:use-module (system repl common)
#:use-module (system repl command)
diff --git a/module/system/repl/server.scm b/module/system/repl/server.scm
index 7a04affe9..9a8f51c5b 100644
--- a/module/system/repl/server.scm
+++ b/module/system/repl/server.scm
@@ -27,7 +27,6 @@
#:use-module (ice-9 iconv)
#:use-module (rnrs bytevectors)
#:use-module (ice-9 binary-ports)
- #:use-module (srfi srfi-1)
#:use-module (srfi srfi-26) ; cut
#:export (make-tcp-server-socket
make-unix-domain-server-socket
diff --git a/module/system/vm/assembler.scm b/module/system/vm/assembler.scm
index 165976363..33f3018f6 100644
--- a/module/system/vm/assembler.scm
+++ b/module/system/vm/assembler.scm
@@ -51,12 +51,10 @@
#:use-module (system syntax internal)
#:use-module (language bytecode)
#:use-module (rnrs bytevectors)
- #:use-module (rnrs bytevectors gnu)
#:use-module (ice-9 binary-ports)
#:use-module (ice-9 vlist)
#:use-module (ice-9 match)
#:use-module (srfi srfi-1)
- #:use-module (srfi srfi-4)
#:use-module (srfi srfi-9)
#:use-module (srfi srfi-11)
#:export (make-assembler
diff --git a/module/system/vm/disassembler.scm b/module/system/vm/disassembler.scm
index 2c9755ab9..ac1d21639 100644
--- a/module/system/vm/disassembler.scm
+++ b/module/system/vm/disassembler.scm
@@ -29,9 +29,7 @@
#:use-module (rnrs bytevectors)
#:use-module (ice-9 format)
#:use-module (ice-9 match)
- #:use-module (ice-9 vlist)
#:use-module (srfi srfi-1)
- #:use-module (srfi srfi-4)
#:export (disassemble-program
fold-program-code
disassemble-image
diff --git a/module/system/vm/dwarf.scm b/module/system/vm/dwarf.scm
index f3e45c758..587906c9e 100644
--- a/module/system/vm/dwarf.scm
+++ b/module/system/vm/dwarf.scm
@@ -71,8 +71,6 @@
(define-module (system vm dwarf)
#:use-module (rnrs bytevectors)
- #:use-module (system foreign)
- #:use-module (system base target)
#:use-module (system vm elf)
#:use-module ((srfi srfi-1) #:select (fold))
#:use-module (srfi srfi-9)
diff --git a/module/system/vm/elf.scm b/module/system/vm/elf.scm
index 6ee62f129..8cd142bbe 100644
--- a/module/system/vm/elf.scm
+++ b/module/system/vm/elf.scm
@@ -36,8 +36,6 @@
#:use-module (system foreign)
#:use-module (system base target)
#:use-module (srfi srfi-9)
- #:use-module (ice-9 receive)
- #:use-module (ice-9 vlist)
#:export (has-elf-header?
(make-elf* . make-elf)
diff --git a/module/system/vm/frame.scm b/module/system/vm/frame.scm
index 6b14fc62a..9218bf3b2 100644
--- a/module/system/vm/frame.scm
+++ b/module/system/vm/frame.scm
@@ -19,8 +19,6 @@
;;; Code:
(define-module (system vm frame)
- #:use-module (system base pmatch)
- #:use-module (system foreign)
#:use-module (system vm program)
#:use-module (system vm debug)
#:use-module (system vm disassembler)
diff --git a/module/system/vm/inspect.scm b/module/system/vm/inspect.scm
index 1f6d99d19..4825fa234 100644
--- a/module/system/vm/inspect.scm
+++ b/module/system/vm/inspect.scm
@@ -19,12 +19,7 @@
;;; Code:
(define-module (system vm inspect)
- #:use-module (system base pmatch)
- #:use-module (system base syntax)
- #:use-module (system vm vm)
- #:use-module (system vm frame)
#:use-module (system vm disassembler)
- #:use-module (ice-9 rdelim)
#:use-module (ice-9 pretty-print)
#:use-module (ice-9 format)
#:use-module (system vm program)
diff --git a/module/system/vm/linker.scm b/module/system/vm/linker.scm
index e126cfb0d..cf213323e 100644
--- a/module/system/vm/linker.scm
+++ b/module/system/vm/linker.scm
@@ -67,9 +67,7 @@
(define-module (system vm linker)
#:use-module (rnrs bytevectors)
#:use-module (rnrs bytevectors gnu)
- #:use-module (system foreign)
#:use-module (system base target)
- #:use-module ((srfi srfi-1) #:select (append-map))
#:use-module (srfi srfi-9)
#:use-module (ice-9 binary-ports)
#:use-module (ice-9 receive)
diff --git a/module/system/vm/program.scm b/module/system/vm/program.scm
index e5dbcc089..4858d5158 100644
--- a/module/system/vm/program.scm
+++ b/module/system/vm/program.scm
@@ -21,7 +21,6 @@
(define-module (system vm program)
#:use-module (ice-9 match)
#:use-module (system vm debug)
- #:use-module (rnrs bytevectors)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-26)
#:export (source:addr source:line source:column source:file
diff --git a/module/system/vm/trace.scm b/module/system/vm/trace.scm
index 54840d8fd..c1eaffa9c 100644
--- a/module/system/vm/trace.scm
+++ b/module/system/vm/trace.scm
@@ -19,12 +19,9 @@
;;; Code:
(define-module (system vm trace)
- #:use-module (system base syntax)
#:use-module (system vm vm)
#:use-module (system vm frame)
- #:use-module (system vm program)
#:use-module (system vm traps)
- #:use-module (rnrs bytevectors)
#:use-module (ice-9 format)
#:export (trace-calls-in-procedure
trace-calls-to-procedure
diff --git a/module/system/vm/trap-state.scm b/module/system/vm/trap-state.scm
index 464740bcd..ba4cc6b31 100644
--- a/module/system/vm/trap-state.scm
+++ b/module/system/vm/trap-state.scm
@@ -26,7 +26,6 @@
#:use-module (system vm vm)
#:use-module (system vm traps)
#:use-module (system vm trace)
- #:use-module (system vm frame)
#:use-module (system vm program)
#:export (add-trap!
list-traps
diff --git a/module/system/vm/traps.scm b/module/system/vm/traps.scm
index 76be8d7d3..cd0e13cc9 100644
--- a/module/system/vm/traps.scm
+++ b/module/system/vm/traps.scm
@@ -58,10 +58,8 @@
#:use-module (ice-9 match)
#:use-module (system vm vm)
#:use-module (system vm debug)
- #:use-module (system vm frame)
#:use-module (system vm program)
#:use-module (system xref)
- #:use-module (rnrs bytevectors)
#:export (trap-at-procedure-call
trap-in-procedure
trap-instructions-in-procedure
diff --git a/module/system/xref.scm b/module/system/xref.scm
index e335f9481..104bf3edf 100644
--- a/module/system/xref.scm
+++ b/module/system/xref.scm
@@ -17,7 +17,6 @@
\f
(define-module (system xref)
- #:use-module (system base compile)
#:use-module (system vm program)
#:use-module (system vm disassembler)
#:use-module (ice-9 match)
diff --git a/module/texinfo/indexing.scm b/module/texinfo/indexing.scm
index d7d10cd69..c77013d7d 100644
--- a/module/texinfo/indexing.scm
+++ b/module/texinfo/indexing.scm
@@ -29,7 +29,6 @@
(define-module (texinfo indexing)
#:use-module (sxml simple)
- #:use-module (srfi srfi-13)
#:export (stexi-extract-index))
(define defines
diff --git a/module/texinfo/plain-text.scm b/module/texinfo/plain-text.scm
index 5ea99c86b..666df74f5 100644
--- a/module/texinfo/plain-text.scm
+++ b/module/texinfo/plain-text.scm
@@ -26,11 +26,8 @@
;;; Code:
(define-module (texinfo plain-text)
- #:use-module (texinfo)
#:use-module (texinfo string-utils)
- #:use-module (sxml transform)
#:use-module (srfi srfi-1)
- #:use-module (srfi srfi-13)
#:use-module (ice-9 match)
#:export (stexi->plain-text
*line-width*))
diff --git a/module/texinfo/reflection.scm b/module/texinfo/reflection.scm
index 50cb2ab05..4ff11995c 100644
--- a/module/texinfo/reflection.scm
+++ b/module/texinfo/reflection.scm
@@ -33,10 +33,8 @@
#:use-module (oop goops)
#:use-module (texinfo)
#:use-module (texinfo plain-text)
- #:use-module (srfi srfi-13)
#:use-module (ice-9 session)
#:use-module (ice-9 documentation)
- #:use-module (ice-9 optargs)
#:use-module ((sxml transform) #:select (pre-post-order))
#:export (module-stexi-documentation
script-stexi-documentation
diff --git a/module/texinfo/string-utils.scm b/module/texinfo/string-utils.scm
index 42074d334..0d2c994d7 100644
--- a/module/texinfo/string-utils.scm
+++ b/module/texinfo/string-utils.scm
@@ -24,8 +24,6 @@
;;; Code:
(define-module (texinfo string-utils)
- #:use-module (srfi srfi-13)
- #:use-module (srfi srfi-14)
#:export (escape-special-chars
transform-string
expand-tabs
diff --git a/module/web/client.scm b/module/web/client.scm
index a08c4203c..6c54c5021 100644
--- a/module/web/client.scm
+++ b/module/web/client.scm
@@ -36,7 +36,6 @@
#:use-module (ice-9 binary-ports)
#:use-module (ice-9 copy-tree)
#:use-module (ice-9 iconv)
- #:use-module (ice-9 rdelim)
#:use-module (web request)
#:use-module (web response)
#:use-module (web uri)
@@ -45,8 +44,6 @@
#:use-module (srfi srfi-9)
#:use-module (srfi srfi-9 gnu)
#:use-module (srfi srfi-26)
- #:use-module ((rnrs io ports)
- #:prefix rnrs-ports:)
#:use-module (ice-9 match)
#:autoload (ice-9 ftw) (scandir)
#:export (current-http-proxy
diff --git a/module/web/http.scm b/module/web/http.scm
index 29736f2eb..94f9c7ea8 100644
--- a/module/web/http.scm
+++ b/module/web/http.scm
@@ -30,7 +30,6 @@
;;; Code:
(define-module (web http)
- #:use-module ((srfi srfi-1) #:select (append-map! map!))
#:use-module (srfi srfi-9)
#:use-module (srfi srfi-19)
#:use-module (ice-9 rdelim)
@@ -39,7 +38,6 @@
#:use-module (ice-9 binary-ports)
#:use-module (ice-9 textual-ports)
#:use-module (ice-9 exceptions)
- #:use-module (rnrs bytevectors)
#:use-module (web uri)
#:export (string->header
header->string
diff --git a/module/web/request.scm b/module/web/request.scm
index eea32e9ce..ff4b94485 100644
--- a/module/web/request.scm
+++ b/module/web/request.scm
@@ -23,7 +23,6 @@
#:use-module (rnrs bytevectors)
#:use-module (ice-9 binary-ports)
#:use-module (ice-9 textual-ports)
- #:use-module (ice-9 rdelim)
#:use-module (srfi srfi-9)
#:use-module (web uri)
#:use-module (web http)
diff --git a/module/web/response.scm b/module/web/response.scm
index 06e1c6dc1..4ac4d74ca 100644
--- a/module/web/response.scm
+++ b/module/web/response.scm
@@ -20,10 +20,8 @@
;;; Code:
(define-module (web response)
- #:use-module (rnrs bytevectors)
#:use-module (ice-9 binary-ports)
#:use-module (ice-9 textual-ports)
- #:use-module (ice-9 rdelim)
#:use-module (ice-9 match)
#:use-module (srfi srfi-9)
#:use-module (web http)
--
2.39.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 0/3] Add '-Wunused-module'
2023-02-11 23:32 ` [PATCH 0/3] Add '-Wunused-module' Ludovic Courtès
` (2 preceding siblings ...)
2023-02-11 23:32 ` [PATCH 3/3] Remove unnecessary module imports Ludovic Courtès
@ 2023-02-12 18:14 ` Jan Nieuwenhuizen
2023-02-20 10:51 ` Ludovic Courtès
2023-02-24 16:00 ` Ludovic Courtès
3 siblings, 2 replies; 7+ messages in thread
From: Jan Nieuwenhuizen @ 2023-02-12 18:14 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: guile-devel
Ludovic Courtès writes:
Hello,
> The new ‘-Wunused-module’ warning is enabled at ‘-W2’ only. The main
> reason for not enabling it at ‘-W1’ is that in the case of modules used
> at macro-expansion time only, such as (srfi srfi-26), it cannot
> determine whether a module is definitely unused. In this case, the
> compiler reports the module as “possibly unused”, and it is up to the
> programmer to check that claim.
[..]
> Thoughts?
The `possibly undefined' warnings about the srfi-9 gnu, srfi-26 and
curried-definition modules are a bit unfortunate, but easy to check.
It allowed me to trim quite some imports in Dezyne modules.
Very nice!
It seems that only re-exporting a (non-macro) variable from an otherwise
un used module gives a false positive `unused module' warning; it
doesn't even say `possibly unused module'. Not a big problem, but can
anything be done about that?
Greetings,
Janneke
$ git diff --stat
dzn/ast.scm | 3 ---
dzn/ast/display.scm | 3 +--
dzn/ast/equal.scm | 5 +----
dzn/ast/goops.scm | 1 -
dzn/ast/lookup.scm | 1 -
dzn/ast/normalize.scm | 17 ++++++++---------
dzn/ast/parse.scm | 4 ----
dzn/ast/wfc.scm | 1 -
dzn/code.scm | 7 -------
dzn/code/c++.scm | 6 ------
dzn/code/dot.scm | 4 +---
dzn/code/dzn.scm | 7 -------
dzn/code/json.scm | 4 +---
dzn/code/makreel.scm | 6 +-----
dzn/commands/code.scm | 3 +--
dzn/commands/graph.scm | 3 +--
dzn/commands/lts.scm | 4 +---
dzn/commands/parse.scm | 4 ----
dzn/commands/simulate.scm | 3 +--
dzn/commands/traces.scm | 4 +---
dzn/commands/verify.scm | 5 +----
dzn/explore.scm | 4 ----
dzn/indent.scm | 8 +-------
dzn/lts.scm | 3 +--
dzn/parse/peg.scm | 5 +----
dzn/peg.scm | 3 +--
dzn/script.scm | 4 +---
dzn/simulate.scm | 2 --
dzn/templates.scm | 4 +---
dzn/verify/constraint.scm | 4 +---
dzn/verify/pipeline.scm | 2 --
dzn/vm/compliance.scm | 1 -
dzn/vm/evaluate.scm | 3 +--
dzn/vm/report.scm | 1 -
dzn/vm/run.scm | 4 +---
dzn/vm/step.scm | 2 --
dzn/vm/util.scm | 4 +---
test/dzn/dzn.scm | 6 +++---
test/dzn/language.scm | 11 ++++++-----
test/dzn/normalize.scm | 5 ++---
test/dzn/silence.scm | 3 +--
41 files changed, 41 insertions(+), 133 deletions(-)
--
Janneke Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond https://LilyPond.org
Freelance IT https://www.JoyOfSource.com | Avatar® https://AvatarAcademy.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/3] Add '-Wunused-module'
2023-02-12 18:14 ` [PATCH 0/3] Add '-Wunused-module' Jan Nieuwenhuizen
@ 2023-02-20 10:51 ` Ludovic Courtès
2023-02-24 16:00 ` Ludovic Courtès
1 sibling, 0 replies; 7+ messages in thread
From: Ludovic Courtès @ 2023-02-20 10:51 UTC (permalink / raw)
To: Jan Nieuwenhuizen; +Cc: guile-devel, dezyne-devel
Hey janneke!
Jan Nieuwenhuizen <janneke@gnu.org> skribis:
> Ludovic Courtès writes:
>
> Hello,
>
>> The new ‘-Wunused-module’ warning is enabled at ‘-W2’ only. The main
>> reason for not enabling it at ‘-W1’ is that in the case of modules used
>> at macro-expansion time only, such as (srfi srfi-26), it cannot
>> determine whether a module is definitely unused. In this case, the
>> compiler reports the module as “possibly unused”, and it is up to the
>> programmer to check that claim.
> [..]
>> Thoughts?
>
> The `possibly undefined' warnings about the srfi-9 gnu, srfi-26 and
> curried-definition modules are a bit unfortunate, but easy to check.
> It allowed me to trim quite some imports in Dezyne modules.
> Very nice!
Good!
> It seems that only re-exporting a (non-macro) variable from an otherwise
> un used module gives a false positive `unused module' warning; it
> doesn't even say `possibly unused module'. Not a big problem, but can
> anything be done about that?
Oh, I hadn’t thought about that. It should be possible to fix it, I’ll
take a look.
Thanks for testing!
Ludo’.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/3] Add '-Wunused-module'
2023-02-12 18:14 ` [PATCH 0/3] Add '-Wunused-module' Jan Nieuwenhuizen
2023-02-20 10:51 ` Ludovic Courtès
@ 2023-02-24 16:00 ` Ludovic Courtès
1 sibling, 0 replies; 7+ messages in thread
From: Ludovic Courtès @ 2023-02-24 16:00 UTC (permalink / raw)
To: Jan Nieuwenhuizen; +Cc: guile-devel
Hello!
Jan Nieuwenhuizen <janneke@gnu.org> skribis:
> It seems that only re-exporting a (non-macro) variable from an otherwise
> un used module gives a false positive `unused module' warning; it
> doesn't even say `possibly unused module'. Not a big problem, but can
> anything be done about that?
I fixed that and pushed the result to ‘main’:
e2ed33ef0 Remove unnecessary module imports.
89c3bae3c Add -Wunused-module.
821e0f9cd Add 'record-case' to '.dir-locals.el'.
Thanks again for your feedback!
Ludo’.
^ permalink raw reply [flat|nested] 7+ messages in thread