Skip to content

Commit 2906363

Browse files
committed
feat: no-operation simps attribute, to avoid unnecessary errors in mathport output (#106)
This is lame: not an actual port of `@[simps]` in all its glory, just a no-operation attribute so we have fewer errors on declarations in the output of mathport. Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
1 parent 8fe6808 commit 2906363

File tree

4 files changed

+83
-10
lines changed

4 files changed

+83
-10
lines changed

Mathlib.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import Mathlib.Tactic.Rcases
5555
import Mathlib.Tactic.Ring
5656
import Mathlib.Tactic.RunTac
5757
import Mathlib.Tactic.ShowTerm
58+
import Mathlib.Tactic.Simps
5859
import Mathlib.Tactic.SolveByElim
5960
import Mathlib.Tactic.Spread
6061
import Mathlib.Tactic.SudoSetOption

Mathlib/Mathport/Syntax.lean

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Mathlib.Tactic.LibrarySearch
1212
import Mathlib.Tactic.NormNum
1313
import Mathlib.Tactic.Ring
1414
import Mathlib.Tactic.ShowTerm
15+
import Mathlib.Tactic.Simps
1516
import Mathlib.Tactic.SolveByElim
1617

1718
-- To fix upstream:
@@ -638,8 +639,9 @@ syntax (name := protectProj) "protectProj" (&" without" (ppSpace ident)+)? : att
638639

639640
syntax (name := notationClass) "notationClass" "*"? (ppSpace ident)? : attr
640641

641-
syntax (name := simps) "simps" (" (" &"config" " := " term ")")? (ppSpace ident)* : attr
642-
syntax (name := simps?) "simps?" (" (" &"config" " := " term ")")? (ppSpace ident)* : attr
642+
-- Moved to Mathlib/Tactic/Simps.lean, but not yet implemented.
643+
-- syntax (name := simps) "simps" (" (" &"config" " := " term ")")? (ppSpace ident)* : attr
644+
-- syntax (name := simps?) "simps?" (" (" &"config" " := " term ")")? (ppSpace ident)* : attr
643645

644646
syntax (name := mono) "mono" (ppSpace Tactic.mono.side)? : attr
645647

@@ -691,14 +693,15 @@ syntax (name := restateAxiom) "restate_axiom " ident (ppSpace ident)? : command
691693
syntax (name := simp) "#simp" (&" only")? (" [" Tactic.simpArg,* "]")?
692694
(" with " ident+)? " :"? ppSpace term : command
693695

694-
syntax simpsRule.rename := ident " → " ident
695-
syntax simpsRule.erase := "-" ident
696-
syntax simpsRule := (simpsRule.rename <|> simpsRule.erase) &" as_prefix"?
697-
syntax simpsProj := ident (" (" simpsRule,+ ")")?
698-
syntax (name := initializeSimpsProjections) "initialize_simps_projections"
699-
(ppSpace simpsProj)* : command
700-
syntax (name := initializeSimpsProjections?) "initialize_simps_projections?"
701-
(ppSpace simpsProj)* : command
696+
-- Moved to Mathlib/Tactic/Simps.lean, but not yet implemented.
697+
-- syntax simpsRule.rename := ident " → " ident
698+
-- syntax simpsRule.erase := "-" ident
699+
-- syntax simpsRule := (simpsRule.rename <|> simpsRule.erase) &" as_prefix"?
700+
-- syntax simpsProj := ident (" (" simpsRule,+ ")")?
701+
-- syntax (name := initializeSimpsProjections) "initialize_simps_projections"
702+
-- (ppSpace simpsProj)* : command
703+
-- syntax (name := initializeSimpsProjections?) "initialize_simps_projections?"
704+
-- (ppSpace simpsProj)* : command
702705

703706
syntax (name := «where») "#where" : command
704707

Mathlib/Tactic/Simps.lean

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/-
2+
Copyright (c) 2019 Floris van Doorn. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Floris van Doorn
5+
-/
6+
7+
import Lean
8+
9+
/-!
10+
# Stub for implementation of the `@[simps]` attribute.
11+
12+
This file is currently just a stub that creates a no-operation `@[simps]` attribute.
13+
Without this, all declarations in the mathport output for mathlib3 that use `@[simps]` fail.
14+
With the no-operation attribute, the declarations can succeed,
15+
but of course all later proofs that rely on the existence of the automatically generated lemmas
16+
will fail.
17+
18+
Later we will need to port the implementation from mathlib3.
19+
20+
-/
21+
22+
23+
open Lean Meta
24+
25+
namespace Attr
26+
27+
syntax (name := simps) "simps" (" (" &"config" " := " term ")")? (ppSpace ident)* : attr
28+
syntax (name := simps?) "simps?" (" (" &"config" " := " term ")")? (ppSpace ident)* : attr
29+
30+
end Attr
31+
32+
namespace Command
33+
34+
syntax simpsRule.rename := ident " → " ident
35+
syntax simpsRule.erase := "-" ident
36+
syntax simpsRule := (simpsRule.rename <|> simpsRule.erase) &" as_prefix"?
37+
syntax simpsProj := ident (" (" simpsRule,+ ")")?
38+
syntax (name := initializeSimpsProjections) "initialize_simps_projections"
39+
(ppSpace simpsProj)* : command
40+
syntax (name := initializeSimpsProjections?) "initialize_simps_projections?"
41+
(ppSpace simpsProj)* : command
42+
43+
end Command
44+
45+
-- Defines the user attribute `simps` for automatic generation of `@[simp]` lemmas for projections.
46+
initialize simpsAttr : ParametricAttribute (Array Name) ←
47+
registerParametricAttribute {
48+
name := `simps
49+
descr := "Automatically derive lemmas specifying the projections of this declaration.",
50+
getParam := fun decl stx =>
51+
match stx with
52+
-- TODO implement support for `config := ...`
53+
| `(attr|simps $[$ids]*) => ids.mapM (·.getId.eraseMacroScopes)
54+
| _ => throwError "unexpected simps syntax {stx}"
55+
}

test/Simps.lean

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Mathlib.Tactic.Simps
2+
3+
/-!
4+
We currently only have a no-operation implementation of `@[simps]`,
5+
so there isn't much to test here.
6+
-/
7+
8+
structure X :=
9+
(a : Nat)
10+
(h : a = 3)
11+
12+
@[simps]
13+
def x : X :=
14+
3, rfl⟩

0 commit comments

Comments
 (0)