lean4-htt/tests/pkg/sym_ext/SymExt.lean
Leonardo de Moura 2b55144c3f
feat: add extensible state mechanism for SymM (#13080)
This PR adds `SymExtension`, a typed extensible state mechanism for
`SymM`,
following the same pattern as `Grind.SolverExtension`. Extensions are
registered at initialization time via `registerSymExtension` and provide
typed `getState`/`modifyState` accessors. Extension state persists
across
`simp` invocations within a `sym =>` block and is re-initialized on each
`SymM.run`.

This enables modules (e.g., the upcoming arithmetic normalizer) to
register persistent state without modifying `Sym.State` directly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 03:58:45 +00:00

28 lines
520 B
Text

/-
Tests for `SymExtension` mechanism.
-/
module
public meta import SymExt.Decl
meta import Lean.Meta.Sym
open Lean Elab Tactic Meta Sym
run_meta SymM.run do
let c0 ← getMyCounter
assert! c0 == 0
incrementMyCounter
let c1 ← getMyCounter
assert! c1 == 1
incrementMyCounter
let c2 ← getMyCounter
assert! c2 == 2
run_meta do
SymM.run do
incrementMyCounter
let c ← getMyCounter
assert! c == 1
-- Should reset the counter
SymM.run do
let c ← getMyCounter
assert! c == 0