| /- | |
| Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | |
| Released under Apache 2.0 license as described in the file LICENSE. | |
| Authors: Leonardo de Moura | |
| -/ | |
| module | |
| prelude | |
| public import Lean.Elab.Tactic.Grind.Basic | |
| import Lean.Elab.ConfigEval | |
| import Lean.Linter.Deprecated | |
| public section | |
| namespace Lean.Elab.Tactic | |
| open ConfigEval | |
| /-- | |
| Elaborator for grind configurations, with the `(config := ...)` elaborator exposed. | |
| This allows overriding which structure is used as the expected type when elaborating | |
| the term, which affects which default values are used in `{...}` structure instance notation. | |
| -/ | |
| private declare_term_config_elab elabGrindConfigCore Grind.Config | |
| (evalConfig : Term → TermElabM Grind.Config) where | |
| option config := fun _ item => evalConfig ⟨item.value⟩ | |
| /-- | |
| Reports that `splits` is deprecated if `config` changes it with respect to `init`, and interprets | |
| `splits := 0` as `branches := 0`. | |
| -/ | |
| private def elabDeprecatedSplits (stx : Syntax) (init config : Grind.Config) : CoreM Grind.Config := do | |
| if config.splits == init.splits then | |
| return config | |
| Linter.logLintIf Linter.linter.deprecated stx | |
| "`splits` has been deprecated, use `branches` instead" | |
| if config.splits == 0 then | |
| return { config with branches := 0 } | |
| return config | |
| local macro "make_elab_grind_config" fn:ident struct:ident : command => do | |
| let cfg := mkIdent `cfg | |
| let init := mkIdent `init | |
| let logExceptions := mkIdent `logExceptions | |
| `(private local ensure_eval_expr_instance $struct | |
| def $fn ($cfg : Syntax) | |
| ($init : $struct := {}) | |
| ($logExceptions : Bool := true) : | |
| TacticM Grind.Config := do | |
| let $init : Grind.Config := { $init with } | |
| let config ← elabGrindConfigCore $cfg $init | |
| (evalConfig := fun c => do | |
| let cfg : $struct ← evalExprWithElab c | |
| return { cfg with }) | |
| (logExceptions := $logExceptions && (← read).recover) | |
| elabDeprecatedSplits $cfg $init config) | |
| make_elab_grind_config elabGrindConfig Grind.Config | |
| make_elab_grind_config elabGrindConfigInteractive Grind.ConfigInteractive | |
| make_elab_grind_config elabCutsatConfig Grind.CutsatConfig | |
| make_elab_grind_config elabLinarithConfig Grind.LinarithConfig | |
| make_elab_grind_config elabOrderConfig Grind.OrderConfig | |
| make_elab_grind_config elabGrobnerConfig Grind.GrobnerConfig | |
| namespace Grind | |
| def elabConfigItems (init : Grind.Config) (items : Array Syntax) : | |
| TermElabM Grind.Config := do | |
| let config ← elabGrindConfigCore (mkNullNode items) init | |
| (evalConfig := fun c => evalExprWithElab c) | |
| (logExceptions := false) | |
| elabDeprecatedSplits (mkNullNode items) init config | |
| def withConfigItems (items : Array Syntax) | |
| (k : GrindTacticM α) : GrindTacticM α := do | |
| if items.isEmpty then | |
| k | |
| else | |
| let config := (← read).ctx.config | |
| let config ← elabConfigItems config items | |
| let activeSolvers ← Meta.Grind.Solvers.activeIds config | |
| withReader (fun c => { c with ctx.config := config, ctx.activeSolvers := activeSolvers }) do k | |
| end Lean.Elab.Tactic.Grind |