Zulip Chat Archive
Stream: mathlib4
Topic: Persistent #allow_unused_tactic
Patrick Massot (Dec 31 2024 at 16:15):
It seems that #allow_unused_tactic
that allows to silence the unused tactic linter does not work across files. I want to define a tactic and make sure it is never flagged.
Patrick Massot (Dec 31 2024 at 16:15):
Is this possible?
Patrick Massot (Dec 31 2024 at 16:17):
Actually, the unxy-ed version is I would be very happy if this linter would consider that anything that changes the tactic state is used, even if it is the same up to defeq. The current implementation of the linter explicitly whitelists change
.
Johan Commelin (Jan 02 2025 at 09:22):
cc @Damiano Testa
Damiano Testa (Jan 03 2025 at 05:55):
First, an answer the original question.
I had thought about making a persistent #allow_unused_tactic
: I think that this would be useful at least downstream. For instance, I used by ... done
when I teach and right now I have to allow
done
in every file.
Damiano Testa (Jan 03 2025 at 05:55):
The persistent version could be implemented by adding an environment extension that stores the unused tactics that are allowed. This would mean that docs#Mathlib.Tactic.allowedRef (the IO.Ref
that currently stores the allowed tactics) could be removed in favour of a dynamic implementation, by allowing each tactic at the point of definition, rather than up front, when the linter is defined.
Damiano Testa (Jan 03 2025 at 05:55):
I still think that the current file-only exclusion is valuable, so my preference would be to add #allow_unused_tactic!
that is persistent, while keeping also the current #allow_unused_tactic
unchanged.
Damiano Testa (Jan 03 2025 at 06:25):
For the second part, the implementation does not actually use isDefEq
, but looks at whether there is a change in the list of metavariables (i.e. their name) and tactics such as change
actually do modify the metavariable.
Damiano Testa (Jan 03 2025 at 06:25):
Can you give an example of a situation where you would like the linter to not flag a tactic as unused? I would probably consider this a bug in the linter, rather than a tactic that should be allowed.
Damiano Testa (Jan 03 2025 at 06:25):
In fact, #20412 removes change
from the allowed tactics: let's see if the linter flags something that it should not in mathlib!
Damiano Testa (Jan 03 2025 at 06:30):
I just looked at the first 3 exceptions flagged by the linter with change
being in scope, and they are all situations where the infoview shows no difference.
Damiano Testa (Jan 03 2025 at 07:14):
I went through all the exceptions and they were all situations where the infoview showed no difference before and after change
.
Damiano Testa (Jan 03 2025 at 07:15):
In one situation, this allowed the removal of a porting note.
Damiano Testa (Jan 03 2025 at 07:15):
The PR above incorporates also the cleanup.
Johan Commelin (Jan 03 2025 at 09:11):
Looks great!
Patrick Massot (Jan 03 2025 at 10:35):
Thanks Damiano! I’m very happy that this question helped cleaning up a bit.
Damiano Testa (Jan 03 2025 at 12:58):
Patrick, are you still interested in the persistent form of #allow_unused_tactic
?
Patrick Massot (Jan 03 2025 at 13:00):
Sure!
Patrick Massot (Jan 03 2025 at 13:01):
I cannot really check that the latest change to the linter is enough for me because I haven’t updated Verbose Lean to Lean 4.15.0-rc1 because of the token issue with white spaces.
Patrick Massot (Jan 03 2025 at 13:01):
But I’m sure this is a useful command anyway.
Damiano Testa (Jan 03 2025 at 13:02):
You mentioned a custom tactic: maybe you could test on Mathlib's master where you add a stub of your tactic.
Damiano Testa (Jan 03 2025 at 13:03):
(However, the current version of #allow_unused_tactic
is certainly not persistent and it only works in the file where it is written.)
Damiano Testa (Jan 03 2025 at 13:12):
With respect to the persistent unused tactic issue: should I completely remove the current exceptions IO.Ref
, in favor of extending the to-be-created environment extension?
Patrick Massot (Jan 03 2025 at 13:15):
Mathlib master doesn’t help with
import Mathlib.Tactic
open Lean Parser Elab Tactic
macro "rename_bvar' " old:ident " → " new:ident loc?:(location)? : tactic =>
`(tactic|rename_bvar $old → $new $[$loc?]?)
set_option linter.unusedVariables false
example (n : ℤ) (hnk : ∃ k, n = 2 * k + 1) : True := by
rename_bvar' k → l at hnk
trivial
Patrick Massot (Jan 03 2025 at 13:16):
Using rename_bvar
instead of rename_bvar'
works because it is whitelisted.
Damiano Testa (Jan 03 2025 at 14:19):
#20438 implements the persistent version of #allow_unused_tactic
. The PR contains both versions:
#allow_unused_tactic ids
, the non-persistent command that is already in Mathlib;#allow_unused_tactic! ids
the persistent command that is new to the PR.
Damiano Testa (Jan 03 2025 at 14:19):
The persistence is achieved through an environment extension, which means that in order to use it, it needs to be in a separate file. All of Mathlib serves as a test for persistence, since I used #allow_unused_tactic! ids
for a few tactics that before were in the IO.Ref
.
Damiano Testa (Jan 03 2025 at 14:19):
Besides moving code around, the PR basically introduces the extension and uses it almost minimally. I opted for not moving the exceptions to the files where the tactics are defined.
Damiano Testa (Jan 03 2025 at 14:39):
If this is something that is used frequently, then maybe we can also think a little about how to input the tactics that should be ignored: the SyntaxNodeKind
is not really how I would identify a tactic and there is a layer of obscurity between wanting to allow refine
to be unused and realizing that it is really Lean.Parser.Tactic.refine
that should be used.
Damiano Testa (Jan 03 2025 at 14:41):
Even something as simple-minded as
elab "#show_kind " t:tactic : command => do
let stx ← `(tactic| $t)
Lean.logInfo m!"The `SyntaxNodeKind` is '{stx.raw.getKind}'"
-- The `SyntaxNodeKind` is 'Lean.Parser.Tactic.refine'
#show_kind refine _
could be useful.
Patrick Massot (Jan 03 2025 at 16:01):
Ironically, this PR doesn’t pass linting CI.
Patrick Massot (Jan 03 2025 at 16:01):
I also realized from the other thread that I probably want to simply disable (all?) linters in my course material.
Damiano Testa (Jan 03 2025 at 16:05):
I pushed what I think is a fix for the linting!
Damiano Testa (Jan 03 2025 at 16:56):
CI passed and I also added the #show_kind
command to the PR.
Damiano Testa (Feb 10 2025 at 14:03):
The persistent form of #allow_unused_tactic
just made it into mathlib master
. Using
#allow_unused_tactic!
Lean.Parser.Tactic.done
Lean.Parser.Tactic.skip
should make the linter ignore done
and skip
from where the command is issued onwards, also on files imported by the file where the command is issued.
Last updated: May 02 2025 at 03:31 UTC