Skip to content

Commit 41f51fe

Browse files
committed
feat: rename get_elem_tactic_trivial to get_elem_tactic_extensible
1 parent b97d35d commit 41f51fe

File tree

5 files changed

+28
-12
lines changed

5 files changed

+28
-12
lines changed

src/Init/Data/Range/Basic.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,8 @@ theorem Membership.mem.step {i : Nat} {r : Std.Range} (h : i ∈ r) : (i - r.sta
8484
theorem Membership.get_elem_helper {i n : Nat} {r : Std.Range} (h₁ : i ∈ r) (h₂ : r.stop = n) :
8585
i < n := h₂ ▸ h₁.2.1
8686

87+
macro_rules
88+
| `(tactic| get_elem_tactic_extensible) => `(tactic| apply Membership.get_elem_helper; assumption; rfl)
89+
8790
macro_rules
8891
| `(tactic| get_elem_tactic_trivial) => `(tactic| apply Membership.get_elem_helper; assumption; rfl)

src/Init/GetElem.lean

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ proof in the context using `have`, because `get_elem_tactic` tries
4747
4848
The proof side-condition `valid xs i` is automatically dispatched by the
4949
`get_elem_tactic` tactic; this tactic can be extended by adding more clauses to
50-
`get_elem_tactic_trivial` using `macro_rules`.
50+
`get_elem_tactic_extensible` using `macro_rules`.
5151
5252
`xs[i]?` and `xs[i]!` do not impose a proof obligation; the former returns
5353
an `Option elem`, with `none` signalling that the value isn't present, and
@@ -280,6 +280,9 @@ instance [GetElem? cont Nat elem dom] [h : LawfulGetElem cont Nat elem dom] :
280280

281281
@[simp, grind =] theorem getElem!_fin [GetElem? Cont Nat Elem Dom] (a : Cont) (i : Fin n) [Inhabited Elem] : a[i]! = a[i.1]! := rfl
282282

283+
macro_rules
284+
| `(tactic| get_elem_tactic_extensible) => `(tactic| (with_reducible apply Fin.val_lt_of_le); get_elem_tactic_extensible; done)
285+
283286
macro_rules
284287
| `(tactic| get_elem_tactic_trivial) => `(tactic| (with_reducible apply Fin.val_lt_of_le); get_elem_tactic_trivial; done)
285288

src/Init/Tactics.lean

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,30 +1917,37 @@ syntax "‹" withoutPosition(term) "›" : term
19171917
macro_rules | `(‹$type›) => `((by assumption : $type))
19181918

19191919
/--
1920-
`get_elem_tactic_trivial` is an extensible tactic automatically called
1920+
`get_elem_tactic_extensible` is an extensible tactic automatically called
19211921
by the notation `arr[i]` to prove any side conditions that arise when
19221922
constructing the term (e.g. the index is in bounds of the array).
1923-
The default behavior is to just try `trivial` (which handles the case
1924-
where `i < arr.size` is in the context) and `simp +arith` and `omega`
1923+
The default behavior is to try `simp +arith` and `omega`
19251924
(for doing linear arithmetic in the index).
1925+
1926+
(Note that the core tactic `get_elem_tactic` has already tried
1927+
`done` and `assumption` before the extensible tactic is called.)
19261928
-/
1929+
syntax "get_elem_tactic_extensible" : tactic
1930+
1931+
/-- `get_elem_tactic_trivial` has been deprecated in favour of `get_elem_tactic_extensible`. -/
19271932
syntax "get_elem_tactic_trivial" : tactic
19281933

1934+
macro_rules | `(tactic| get_elem_tactic_extensible) => `(tactic| omega)
1935+
macro_rules | `(tactic| get_elem_tactic_extensible) => `(tactic| simp +arith; done)
1936+
19291937
macro_rules | `(tactic| get_elem_tactic_trivial) => `(tactic| omega)
19301938
macro_rules | `(tactic| get_elem_tactic_trivial) => `(tactic| simp +arith; done)
1931-
macro_rules | `(tactic| get_elem_tactic_trivial) => `(tactic| trivial)
19321939

19331940
/--
19341941
`get_elem_tactic` is the tactic automatically called by the notation `arr[i]`
19351942
to prove any side conditions that arise when constructing the term
19361943
(e.g. the index is in bounds of the array). It just delegates to
1937-
`get_elem_tactic_trivial` and gives a diagnostic error message otherwise;
1938-
users are encouraged to extend `get_elem_tactic_trivial` instead of this tactic.
1944+
`get_elem_tactic_extensible` and gives a diagnostic error message otherwise;
1945+
users are encouraged to extend `get_elem_tactic_extensible` instead of this tactic.
19391946
-/
19401947
macro "get_elem_tactic" : tactic =>
19411948
`(tactic| first
19421949
/-
1943-
Recall that `macro_rules` (namely, for `get_elem_tactic_trivial`) are tried in reverse order.
1950+
Recall that `macro_rules` (namely, for `get_elem_tactic_extensible`) are tried in reverse order.
19441951
We first, however, try `done`, since the necessary proof may already have been
19451952
found during unification, in which case there is no goal to solve (see #6999).
19461953
If a goal is present, we want `assumption` to be tried first.
@@ -1953,15 +1960,15 @@ macro "get_elem_tactic" : tactic =>
19531960
If `omega` is used to "fill" this proof, we will have a more complex proof term that
19541961
cannot be inferred by unification.
19551962
We hardcoded `assumption` here to ensure users cannot accidentally break this IF
1956-
they add new `macro_rules` for `get_elem_tactic_trivial`.
1963+
they add new `macro_rules` for `get_elem_tactic_extensible`.
19571964
19581965
TODO: Implement priorities for `macro_rules`.
1959-
TODO: Ensure we have **high-priority** macro_rules for `get_elem_tactic_trivial` which are
1966+
TODO: Ensure we have **high-priority** macro_rules for `get_elem_tactic_extensible` which are
19601967
just `done` and `assumption`.
19611968
-/
19621969
| done
19631970
| assumption
1964-
| get_elem_tactic_trivial
1971+
| get_elem_tactic_extensible
19651972
| fail "failed to prove index is valid, possible solutions:
19661973
- Use `have`-expressions to prove the index is valid
19671974
- Use `a[i]!` notation instead, runtime check is performed, and 'Panic' error message is produced if index is not valid

src/Lean/Elab/Tactic.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,6 @@ import Lean.Elab.Tactic.TreeTacAttr
5151
import Lean.Elab.Tactic.ExposeNames
5252
import Lean.Elab.Tactic.SimpArith
5353
import Lean.Elab.Tactic.Lets
54+
55+
elab "get_elem_tactic_trivial" : tactic => do
56+
throwError "`get_elem_tactic_trivial` has been renamed to `get_elem_tactic_extensible`"

tests/lean/run/grind_heapsort.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set_option grind.warning false
44
/-
55
Use `grind` as one of the tactics for array-element access and termination proofs.
66
-/
7-
macro_rules | `(tactic| get_elem_tactic_trivial) => `(tactic| grind)
7+
macro_rules | `(tactic| get_elem_tactic_extensible) => `(tactic| grind)
88
/-
99
Note: We disable model-based theory combination (-mbtc) here because `grind` can
1010
exhaust heartbeats when exploring certain "bad" termination checker scenarios.

0 commit comments

Comments
 (0)