Hello Guilers! Following a discussion started at the Guix Days and continued online¹, it seems we could benefit from a compiler warning for unused modules, and this is what this patch does.
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. Currently we cannot do any better because warnings operate at the tree-il, after macro expansion, and there’s nothing indicating whether a piece of code results from macro expansion. There’s also the rare case of modules imported for their side effects, not for their bindings, and that should be kept even if seemingly “unused”. One example might be the use of (rnrs bytevectors) in (rnrs io ports). But again, that’s super unusual. Anyway, it’s pretty useful already and has allowed me to trim imports in Guile modules. Thoughts? Ludo’. ¹ https://lists.gnu.org/archive/html/guix-devel/2023-02/msg00028.html Ludovic Courtès (3): Add -Wunused-module. Add 'record-case' to '.dir-locals.el'. Remove unnecessary module imports. .dir-locals.el | 1 + NEWS | 17 +++ 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/language/tree-il/analyze.scm | 138 +++++++++++++++++++++++- module/language/tree-il/fix-letrec.scm | 4 - module/sxml/apply-templates.scm | 2 - module/sxml/simple.scm | 1 - module/system/base/message.scm | 11 +- 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 - test-suite/tests/tree-il.test | 141 ++++++++++++++++++++++++- 43 files changed, 305 insertions(+), 77 deletions(-) base-commit: 9d339ea1a95c3b2d04a88aa6b116f997349fc4f4 -- 2.39.1