Skip to content

Commit

Permalink
chore: fix symm and label bugs from #3408
Browse files Browse the repository at this point in the history
  • Loading branch information
joehendrix committed Feb 21, 2024
1 parent 6719af3 commit 8bba335
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
18 changes: 0 additions & 18 deletions src/Init/Meta.lean
Original file line number Diff line number Diff line change
Expand Up @@ -1429,24 +1429,6 @@ declare_simp_like_tactic (dsimp := true) dsimpAutoUnfold "dsimp! " fun (c : Lean

end Tactic

namespace Command

/--
Initialize a new "label" attribute.
Declarations tagged with the attribute can be retrieved using `Std.Tactic.LabelAttr.labelled`.
-/
macro (name := _root_.Lean.Parser.Command.registerLabelAttr)
doc:(docComment)? "register_label_attr " id:ident : command => do
let str := id.getId.toString
let idParser := mkIdentFrom id (`Parser.Attr ++ id.getId)
let descr := quote (removeLeadingSpaces
(doc.map (·.getDocString) |>.getD ("labelled declarations for " ++ id.getId.toString)))
`($[$doc:docComment]? initialize ext : LabelExtension ←
registerLabelAttr $(quote id.getId) $descr $(quote id.getId)
$[$doc:docComment]? syntax (name := $idParser:ident) $(quote str):str : attr)

end Command

end Parser

end Lean
2 changes: 1 addition & 1 deletion src/Init/Tactics.lean
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ syntax (name := normCastAddElim) "norm_cast_add_elim" ident : command
It replaces the target with `u ~ t`.
* `symm at h` will rewrite a hypothesis `h : t ~ u` to `h : u ~ t`.
-/
syntax (name := symm) "symm" (Parser.Tactic.location)? : tactic
syntax (name := symm) "symm" (location)? : tactic

/-- For every hypothesis `h : a ~ b` where a `@[symm]` lemma is available,
add a hypothesis `h_symm : b ~ a`. -/
Expand Down
5 changes: 3 additions & 2 deletions src/Lean/Elab/Tactic/Symm.lean
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ namespace Lean.Elab.Tactic
@[builtin_tactic Lean.Parser.Tactic.symm]
def evalSymm : Tactic := fun stx =>
match stx with
| `(tactic| symm $(loc)) => do
| `(tactic| symm $(loc?)?) => do
let atHyp h := liftMetaTactic1 fun g => g.applySymmAt h
let atTarget := liftMetaTactic1 fun g => g.applySymm
withLocation (expandOptLocation loc) atHyp atTarget fun _ => throwError "symm made no progress"
let loc := if let some loc := loc? then expandLocation loc else Location.targets #[] true
withLocation loc atHyp atTarget fun _ => throwError "symm made no progress"
| _ => throwUnsupportedSyntax

@[builtin_tactic Lean.Parser.Tactic.symmSaturate]
Expand Down
14 changes: 14 additions & 0 deletions src/Lean/LabelAttribute.lean
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ def registerLabelAttr (attrName : Name) (attrDescr : String)
labelExtensionMapRef.modify fun map => map.insert attrName ext
return ext

/--
Initialize a new "label" attribute.
Declarations tagged with the attribute can be retrieved using `Std.Tactic.LabelAttr.labelled`.
-/
macro (name := _root_.Lean.Parser.Command.registerLabelAttr)
doc:(docComment)? "register_label_attr " id:ident : command => do
let str := id.getId.toString
let idParser := mkIdentFrom id (`Parser.Attr ++ id.getId)
let descr := quote (removeLeadingSpaces
(doc.map (·.getDocString) |>.getD ("labelled declarations for " ++ id.getId.toString)))
`($[$doc:docComment]? initialize ext : Lean.LabelExtension ←
registerLabelAttr $(quote id.getId) $descr $(quote id.getId)
$[$doc:docComment]? syntax (name := $idParser:ident) $(quote str):str : attr)

/-- When `attrName` is an attribute created using `register_labelled_attr`,
return the names of all declarations labelled using that attribute. -/
def labelled (attrName : Name) : CoreM (Array Name) := do
Expand Down

0 comments on commit 8bba335

Please sign in to comment.