mirror of
https://github.com/leanprover/lean4.git
synced 2026-03-17 18:34:06 +00:00
This PR adds a `cbv_simproc` system for the `cbv` tactic, mirroring simp's `simproc` infrastructure but tailored to cbv's three-phase pipeline (`↓` pre, `cbv_eval` eval, `↑` post). User-defined simplification procedures are indexed by discrimination tree patterns and dispatched during cbv normalization. New syntax: - `cbv_simproc [↓|↑|cbv_eval] name (pattern) := body` — define and register a cbv simproc - `cbv_simproc_decl name (pattern) := body` — define without registering - `attribute [cbv_simproc [↓|↑|cbv_eval]] name` — register an existing declaration - `builtin_cbv_simproc` variants for the internal use New files: - `src/Init/CbvSimproc.lean` — syntax and macros - `src/Lean/Meta/Tactic/Cbv/CbvSimproc.lean` — types, env extensions, registration, dispatch - `src/Lean/Elab/Tactic/CbvSimproc.lean` — pattern elaboration and command elaborators --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
35 lines
992 B
Lean4
35 lines
992 B
Lean4
import Lean
|
|
|
|
open Lean Meta Sym.Simp
|
|
|
|
-- Attribute on a def that was never declared as a cbv simproc
|
|
meta def notASimproc : Simproc := fun _ => return .rfl
|
|
|
|
/-- error: Invalid `[cbv_simproc]` attribute: `notASimproc` is not a cbv simproc -/
|
|
#guard_msgs in
|
|
attribute [cbv_simproc] notASimproc
|
|
|
|
-- Attribute on a def with wrong type
|
|
def plainNat : Nat := 42
|
|
|
|
/-- error: Cbv simproc `plainNat` has an unexpected type: Expected `Simproc`, but found `Nat` -/
|
|
#guard_msgs in
|
|
attribute [cbv_simproc] plainNat
|
|
|
|
-- Erase from something without the attribute
|
|
cbv_simproc_decl untaggedProc (Nat.gcd _ _) := fun _ => return .rfl
|
|
|
|
/-- error: `untaggedProc` does not have a [cbv_simproc] attribute -/
|
|
#guard_msgs in
|
|
attribute [-cbvSimprocAttr] untaggedProc
|
|
|
|
-- Wrong type in cbv_simproc_decl pattern registration
|
|
def wrongType : Nat := 42
|
|
|
|
/--
|
|
error: Unexpected type for cbv simproc pattern: Expected `Simproc`, but `wrongType` has type
|
|
Nat
|
|
-/
|
|
#guard_msgs in
|
|
cbv_simproc_pattern% Nat.succ _ => wrongType
|