Skip to content

Commit bc07b99

Browse files
committed
feat: allow set_option to set grind config options
1 parent 82f1c7e commit bc07b99

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/Lean/Elab/Tactic/Grind/BuiltinTactic.lean

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import Lean.Elab.Tactic.Basic
2525
import Lean.Elab.Tactic.RenameInaccessibles
2626
import Lean.Elab.Tactic.Grind.Filter
2727
import Lean.Elab.Tactic.Grind.ShowState
28+
import Lean.Elab.Tactic.Grind.Config
2829
import Lean.Elab.SetOption
2930
namespace Lean.Elab.Tactic.Grind
3031

@@ -425,9 +426,30 @@ where
425426
liftGrindM <| resetAnchors
426427
replaceMainGoal [{ goal with mvarId }]
427428

429+
def isGrindConfigField? (stx : Syntax) : CoreM (Option Name) := do
430+
unless stx.isIdent do return none
431+
let id := stx.getId
432+
let env ← getEnv
433+
let info := getStructureInfo env ``Grind.Config
434+
unless info.fieldNames.contains id do return none
435+
return some id
436+
428437
@[builtin_grind_tactic setOption] def elabSetOption : GrindTactic := fun stx => do
429-
let options ← Elab.elabSetOption stx[1] stx[3]
430-
withOptions (fun _ => options) do evalGrindTactic stx[5]
438+
if let some fieldName ← isGrindConfigField? stx[1] then
439+
let val := stx[3]
440+
let val ← match val.isNatLit? with
441+
| some num => pure <| DataValue.ofNat num
442+
| none => match val with
443+
| Syntax.atom _ "true" => pure <| DataValue.ofBool true
444+
| Syntax.atom _ "false" => pure <| DataValue.ofBool false
445+
| _ => throwErrorAt val "`grind` configuration option must be a Boolean or a numeral"
446+
let config := (← read).ctx.config
447+
let config ← setConfigField config fieldName val
448+
withReader (fun c => { c with ctx.config := config }) do
449+
evalGrindTactic stx[5]
450+
else
451+
let options ← Elab.elabSetOption stx[1] stx[3]
452+
withOptions (fun _ => options) do evalGrindTactic stx[5]
431453

432454
@[builtin_grind_tactic mbtc] def elabMBTC : GrindTactic := fun _ => do
433455
liftGoalM do
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
set_option warn.sorry false
2+
opaque f : Nat → Nat
3+
opaque g : Nat → Nat
4+
theorem fax : f (x + 1) = g (f x) := sorry
5+
6+
example : f (x + 100) = a := by
7+
grind =>
8+
set_option gen 15 in
9+
-- The following instantiations should not fail since we set
10+
-- `gen` to 15
11+
use [fax]; use [fax]; use [fax]; use [fax]; use [fax]
12+
use [fax]; use [fax]; use [fax]; use [fax]; use [fax]
13+
use [fax]; use [fax]; use [fax]; use [fax]; use [fax]
14+
fail_if_success use [fax] -- should fail
15+
sorry

0 commit comments

Comments
 (0)