Skip to content

Commit 9354f12

Browse files
committed
feat: merge RunCmd and RunTac, add by_elab (#361)
1 parent 88962d2 commit 9354f12

File tree

9 files changed

+60
-35
lines changed

9 files changed

+60
-35
lines changed

Mathlib.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ import Mathlib.Tactic.Replace
102102
import Mathlib.Tactic.RestateAxiom
103103
import Mathlib.Tactic.Ring
104104
import Mathlib.Tactic.RunCmd
105-
import Mathlib.Tactic.RunTac
106105
import Mathlib.Tactic.Sat.FromLRAT
107106
import Mathlib.Tactic.SeqFocus
108107
import Mathlib.Tactic.Set

Mathlib/Data/List/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ theorem ext_get {l₁ l₂ : List α} (hl : length l₁ = length l₂)
687687
if h₁ : n < length l₁ then by
688688
rw [get?_eq_get, get?_eq_get, h n h₁ (by rwa [←hl])]
689689
else by
690-
have h₁ := le_of_not_gt h₁
690+
have h₁ := le_of_not_lt h₁
691691
rw [get?_len_le h₁, get?_len_le]; rwa [← hl]
692692

693693
theorem modifyNthTail_id : ∀ n (l : List α), l.modifyNthTail id n = l

Mathlib/Mathport/Syntax.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ syntax caseArg := binderIdent,+ (" :" (ppSpace (ident <|> "_"))+)?
195195
(" [" simpArg,* "]")? (" with " (colGt ident)+)? (ppSpace location)? : tactic
196196
/- E -/ syntax (name := symm) "symm" : tactic
197197
/- E -/ syntax (name := trans) "trans" (ppSpace colGt term)? : tactic
198-
/- B -/ syntax (name := acRfl') "ac_rfl" : tactic
199198
/- B -/ syntax (name := cc) "cc" : tactic
200199

201200
-- builtin unfold only accepts single ident

Mathlib/Tactic/Conv.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Copyright (c) 2021 Gabriel Ebner. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Gabriel Ebner
55
-/
6-
import Mathlib.Tactic.RunTac
6+
import Mathlib.Tactic.RunCmd
77

88
/-!
99
Additional `conv` tactics.

Mathlib/Tactic/RunCmd.lean

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,61 @@
11
/-
2-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
2+
Copyright (c) 2018 Sebastian Ullrich. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
4-
Authors: Mario Carneiro
4+
Authors: Sebastian Ullrich, Mario Carneiro
55
-/
6-
import Lean
6+
import Lean.Elab.SyntheticMVars
77
import Mathlib.Util.TermUnsafe
88

99
/-!
10-
Define a `run_cmd a; b` command which executes code in `CommandElabM Unit`.
11-
This is almost the same as `#eval show CommandElabM Unit from do a; b`,
12-
except that it doesn't print an empty diagnostic.
10+
Defines commands to compile and execute a command / term / tactic on the spot:
11+
12+
* `run_cmd doSeq` command which executes code in `CommandElabM Unit`.
13+
This is almost the same as `#eval show CommandElabM Unit from do doSeq`,
14+
except that it doesn't print an empty diagnostic.
15+
16+
* `run_tac doSeq` tactic which executes code in `TacticM Unit`.
17+
18+
* `by_elab doSeq` term which executes code in `TermElabM Expr` to produce an expression.
1319
-/
1420

15-
namespace Lean.Parser.Command
16-
open Meta Elab Command Term
21+
namespace Mathlib.RunCmd
22+
open Lean Meta Elab Command Term Tactic
1723

24+
/--
25+
The `run_cmd doSeq` command executes code in `CommandElabM Unit`.
26+
This is almost the same as `#eval show CommandElabM Unit from do doSeq`,
27+
except that it doesn't print an empty diagnostic.
28+
-/
1829
elab (name := runCmd) "run_cmd " elems:doSeq : command => do
1930
← liftTermElabM <|
2031
unsafe evalTerm (CommandElabM Unit)
2132
(mkApp (mkConst ``CommandElabM) (mkConst ``Unit))
2233
(← `(discard do $elems))
34+
35+
/-- The `run_tac doSeq` tactic executes code in `TacticM Unit`. -/
36+
elab (name := runTac) "run_tac" e:doSeq : tactic => do
37+
unsafe evalTerm (TacticM Unit) (mkApp (mkConst ``TacticM) (mkConst ``Unit))
38+
(← `(discard do $e))
39+
40+
/--
41+
* The `by_elab doSeq` expression runs the `doSeq` as a `TermElabM Expr` to
42+
synthesize the expression.
43+
* `by_elab fun expectedType? => do doSeq` receives the expected type (an `Option Expr`)
44+
as well.
45+
-/
46+
syntax (name := byElab) "by_elab" doSeq : term
47+
48+
/-- Elaborator for `by_elab`. -/
49+
@[termElab byElab] def elabRunElab : TermElab := fun
50+
| `(by_elab $cmds:doSeq), expectedType? => do
51+
if let `(Lean.Parser.Term.doSeq| $e:term) := cmds then
52+
if e matches `(Lean.Parser.Term.doSeq| fun $_* => $_) then
53+
let tac ← unsafe evalTerm
54+
(Option Expr → TermElabM Expr)
55+
(Lean.mkForall `x .default
56+
(mkApp (mkConst ``Option) (mkConst ``Expr))
57+
(mkApp (mkConst ``TermElabM) (mkConst ``Expr))) e
58+
return ← tac expectedType?
59+
(← unsafe evalTerm (TermElabM Expr) (mkApp (mkConst ``TermElabM) (mkConst ``Expr))
60+
(← `(do $cmds)))
61+
| _, _ => throwUnsupportedSyntax

Mathlib/Tactic/RunTac.lean

Lines changed: 0 additions & 14 deletions
This file was deleted.

scripts/nolints.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,6 @@
439439
["docBlame", "Mathlib.ExtendedBinder.«term∀ᵉ_,_»"],
440440
["docBlame", "Mathlib.ExtendedBinder.«term∃__,_»"],
441441
["docBlame", "Mathlib.ExtendedBinder.«term∃ᵉ_,_»"],
442-
["docBlame", "Mathlib.RunTac.tacticRun_tac_"],
443442
["docBlame", "Mathlib.Tactic.haveLetCore"],
444443
["docBlame", "Mathlib.Tactic.renameArg"],
445444
["docBlame", "Mathlib.Tactic.set"],

test/runCmd.lean

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Lean.Elab.Tactic.ElabTerm
2+
import Mathlib.Tactic.RunCmd
3+
4+
open Lean Elab Tactic
5+
6+
example : True := by
7+
run_tac
8+
evalApplyLikeTactic MVarId.apply (← `(True.intro))
9+
10+
example : True := by_elab
11+
Term.elabTerm (← `(True.intro)) none

test/runTac.lean

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)