Zulip Chat Archive
Stream: general
Topic: Unused variables
Damiano Testa (Sep 29 2024 at 23:53):
Prompted by a question of Bhavik (see #17178), I am trying to systematically find variable
s that are unused.
Damiano Testa (Sep 29 2024 at 23:53):
It turns out that there are really a lot! I suspect that quite a few are a consequence of splitting files and copying over variable
commands where they are no longer needed.
Damiano Testa (Sep 29 2024 at 23:53):
#17261 is a first batch of removals.
Damiano Testa (Sep 29 2024 at 23:53):
The linter that found them is still not really ready for review, since it currently is incapable of dealing with def
s, but has still flagged thousands of candidates for removal.
Damiano Testa (Sep 29 2024 at 23:53):
Is this something that is desirable?
Michael Rothgang (Oct 04 2024 at 16:58):
Can the same idea be adapted to find unused open
s? That's something I wanted to think about for quite a while, but never got important enough...
Damiano Testa (Oct 04 2024 at 20:19):
Yes, a similar strategy can also be used for unused open
: the inclusion mechanism is different, but the kind of tracking is very similar.
Damiano Testa (Oct 09 2024 at 06:34):
I have been making progress towards a linter that catches variable
s that can be removed. It is not yet complete, but it has already found a lot of simplifications (many of which are already merged).
Damiano Testa (Oct 09 2024 at 06:35):
However, the current version find over 4k exceptions in mathlib (unfortunately, some of these are false positives and the corresponding variables are used, but I have not managed to find a good way of excluding them from the linter).
Damiano Testa (Oct 09 2024 at 06:36):
Would it be desirable to produce a version of the linter that is conservative, may not flag every unused variable, but certainly flags unused ones, and do a mass substitution?
Damiano Testa (Oct 09 2024 at 06:36):
This would still likely imply thousands of changes to hundreds, if not thousands of files.
Damiano Testa (Oct 09 2024 at 06:37):
#17566 is the latest batch of removals, in case you are interested.
Ruben Van de Velde (Oct 09 2024 at 06:51):
If you feel up for it, I'd lean towards reviewable chunks, but it sounds like that could keep you busy for quite a while. Alternatively you could land the linter off by default and we could spread the work around a bit.
Damiano Testa (Oct 09 2024 at 11:54):
I'll PR a few more chunks for a while, at least until the linter is more reliable. I'll probably switch to distributing the effort, once the linter is more "independent", though.
Damiano Testa (Oct 09 2024 at 11:54):
Damiano Testa (Oct 09 2024 at 12:15):
Damiano Testa (Oct 14 2024 at 01:10):
I cleaned up a little the linter and opened #17715.
Damiano Testa (Oct 14 2024 at 01:10):
This is by no means a final version, but it is there in case someone feels like checking out the branch, removing some unused variables and leave mathlib in a better shape!
Last updated: May 02 2025 at 03:31 UTC