Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…#13742) the `get_alias_target` function in `alias.lean` is used by the `to_additive` command to add the “Alias of …” docstring when creating an additive version of an existing alias (this was #13330). But `get_alias_target` did not work for `alias f ↔ a b`. This fixes it by extending the `alias_attr` map to not just store whether a defintion is an alias, but also what it is an alias of. Much more principled than trying to reconstruct the alias target from the RHS of the alias definition. Note that `alias` currently says “Alias of `foo_iff`” even though it’s really an alias of `foo_iff.mp`. This is an existing bug, not fixed in this PR – the effect is just that this “bug” will uniformly apply to additive lemmas as well. Hopefully will get rid of plenty of nolint.txt entries, and create better docs. Also improve the test file for the linter significantly.
- Loading branch information
Showing
3 changed files
with
47 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,62 @@ | ||
import algebra.group.to_additive | ||
import tactic.alias | ||
|
||
/-- Test assertion helpers -/ | ||
meta def assert_ok (n : name) := do | ||
decl ← tactic.get_decl n, | ||
some msg ← linter.to_additive_doc.test decl | pure (), | ||
fail! "Linting {n} complained unexpectedly:\n{msg}" | ||
|
||
meta def assert_complain (n : name) := do | ||
decl ← tactic.get_decl n, | ||
none ← linter.to_additive_doc.test decl | pure (), | ||
fail! "Linting {n} succeeded unexpectedly" | ||
|
||
/-- Docstring -/ | ||
@[to_additive add_foo] | ||
def foo (α : Type*) [has_one α] : α := 1 | ||
|
||
run_cmd assert_complain ``foo | ||
run_cmd assert_ok ``add_foo | ||
|
||
@[to_additive add_bar "docstring"] | ||
def bar (α : Type*) [has_one α] : α := 1 | ||
|
||
run_cmd assert_complain ``bar | ||
run_cmd assert_ok ``add_bar | ||
|
||
/-- Docstring -/ | ||
@[to_additive add_baz "docstring"] | ||
def baz (α : Type*) [has_one α] : α := 1 | ||
|
||
run_cmd assert_ok ``baz | ||
run_cmd assert_ok ``add_baz | ||
|
||
@[to_additive add_quux] | ||
def quux (α : Type*) [has_one α] : α := 1 | ||
|
||
def no_to_additive (α : Type*) [has_one α] : α := 1 | ||
run_cmd assert_ok ``quux | ||
run_cmd assert_ok ``add_quux | ||
|
||
def without_to_additive (α : Type*) [has_one α] : α := 1 | ||
|
||
run_cmd assert_ok ``without_to_additive | ||
|
||
-- Aliases always have docstrings, so we do not want to complain if their | ||
-- additive version do not | ||
alias quux <- quux_alias | ||
attribute [to_additive add_quux_alias] quux_alias | ||
|
||
run_cmd assert_ok ``quux_alias | ||
run_cmd assert_ok ``add_quux_alias | ||
|
||
-- Same for iff aliases | ||
def a_one_iff_b_one (α : Type*) [has_one α] (a b : α) (h : a = b) : (a = 1) ↔ (b = 1) := by {subst h} | ||
alias a_one_iff_b_one ↔ b_one_of_a_one a_one_of_b_one | ||
attribute [to_additive] a_one_iff_b_one | ||
attribute [to_additive] b_one_of_a_one | ||
attribute [to_additive] a_one_of_b_one | ||
|
||
open tactic | ||
run_cmd do | ||
decl ← get_decl ``foo, | ||
res ← linter.to_additive_doc.test decl, | ||
-- linter complains | ||
guard $ res.is_some | ||
|
||
run_cmd do | ||
decl ← get_decl ``bar, | ||
res ← linter.to_additive_doc.test decl, | ||
-- linter complains | ||
guard $ res.is_some | ||
|
||
run_cmd do | ||
decl ← get_decl ``baz, | ||
res ← linter.to_additive_doc.test decl, | ||
-- linter is happy | ||
guard $ res.is_none | ||
|
||
run_cmd do | ||
decl ← get_decl ``quux, | ||
res ← linter.to_additive_doc.test decl, | ||
-- linter is happy | ||
guard $ res.is_none | ||
|
||
run_cmd do | ||
decl ← get_decl ``no_to_additive, | ||
res ← linter.to_additive_doc.test decl, | ||
-- linter is happy | ||
guard $ res.is_none | ||
|
||
run_cmd do | ||
decl ← get_decl ``quux_alias, | ||
res ← linter.to_additive_doc.test decl, | ||
-- linter is happy | ||
guard $ res.is_none | ||
run_cmd assert_ok ``a_one_iff_b_one | ||
run_cmd assert_ok ``a_one_of_b_one | ||
run_cmd assert_ok ``b_one_of_a_one |