GNU bug report logs -
#61266
[PATCH 1/1] lint: Add unused-modules linter.
Previous Next
Reported by: Reily Siegel <mail <at> reilysiegel.com>
Date: Sat, 4 Feb 2023 06:46:02 UTC
Severity: normal
Tags: patch
Merged with 61265
Done: Ludovic Courtès <ludo <at> gnu.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
Hi Reily,
Reily Siegel <mail <at> reilysiegel.com> skribis:
> * guix/lint.scm (file-module): New function.
> (module-dependencies): New function.
> (sexp-symbols): New function.
> (file-symbols): New function.
> (report-unused-module): New function.
> (check-unused-modules): New function.
> (%local-checkers): Add check-unused-modules.
Nice! This is a hot topic, discussed at the Guix Days last week!
https://lists.gnu.org/archive/html/guix-devel/2023-02/msg00028.html
[...]
> +(define (check-unused-modules package)
> + "Check if the file in which PACKAGE is defined contains unused module imports."
> + (let* ((file (package-file package))
> + (symbols (file-symbols file))
> + (dependencies (module-dependencies (file-module file))))
> + (fold
> + (match-lambda*
> + (((module . publics) res)
> + (if (null? (lset-intersection eq? publics symbols))
> + (cons (report-unused-module package module)
> + res)
> + res)))
> + '()
> + dependencies)))
As you may know, this is an approximation: it doesn’t take into account
shadowed bindings, module import renamers and selections, and so on; it
might think a module is used just because a symbol with the same name as
one it exports appears somewhere in the code. In practice, it probably
works quite well for package modules though, right?
I have just submitted a patch adding a ‘-Wunused-module’ warning to
Guile’s compiler, which avoids these issues:
https://lists.gnu.org/archive/html/guile-devel/2023-02/msg00026.html
I wonder if we should stick to that and avoid having a lint warning
altogether. WDYT?
Thanks,
Ludo’.
This bug report was last modified 2 years and 153 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.