@@ -270,7 +270,10 @@ elab_rules : command
270270 for mutType in mutTypes do
271271 mutTypeProd <- `($mutType × $mutTypeProd)
272272 retType <- `($retType × $mutTypeProd)
273+ /- We need Velvet methods to be elaborated in a modified `do`-notation.
274+ For that we localy open the `DoNames` namespace which contains the extensioned `do`-notation. -/
273275 let defCmd <- `(command|
276+ open Lean.Elab.Term.DoNames in
274277 set_option linter.unusedVariables false in
275278 def $name $bindersIdents* : VelvetM $retType:term := do $mods* $doSeq*
276279 $suf:suffix)
@@ -340,6 +343,37 @@ elab_rules : command
340343 $pre
341344 ($name $ids*)
342345 (fun $ret => $post) := by $proofSeq $suf:suffix)
346+ let opts <- getOptions
347+
348+ /- We need to check the termination and choice semantics options before
349+ stating the proof. -/
350+ if opts.getString (defVal := "unspecified" ) `loom.semantics.choice = "unspecified" then
351+ throwError "First, you need to specify the choice semantics using `set_option loom.semantics.choice <demonic/angelic>`"
352+
353+ if opts.getString (defVal := "unspecified" ) `loom.semantics.termination = "unspecified" then
354+ throwError "First, you need to specify the termination semantics using `set_option loom.semantics.termination <partial/total>`"
355+
356+ /- Now, depending on the solver option, we will locally define the `loom_solver` tactic. -/
357+ let solver := opts.getString (defVal := "grind" ) `loom.solver
358+ let thmCmd <- match solver with
359+ | "grind" =>
360+ /- In case of `grind` solver, we need to fetch the number of splits from the options first. -/
361+ let splits := Lean.Syntax.mkNatLit <| (opts.getNat (defVal := 20 ) `loom.solver.grind.splits)
362+ `(command|
363+ macro_rules | `(tactic| loom_solver) => do `(tactic| try grind (splits := $splits)) in
364+ $thmCmd)
365+ | "custom" => pure thmCmd
366+ | _ =>
367+ /- This is the case of `cvc5` or `z3` solver. We also need to fetch the timeout from the options. -/
368+ let timeout := Syntax.mkNatLit <| (opts.getNat (defVal := 1 ) `loom.solver.smt.timeout)
369+ let solver := Syntax.mkStrLit <| (opts.getString (defVal := "cvc5" ) `loom.solver.smt.solver)
370+ `(command|
371+ set_option auto.smt.trust true in
372+ set_option auto.smt true in
373+ set_option auto.smt.solver.name $solver in
374+ set_option auto.smt.timeout $timeout in
375+ macro_rules | `(tactic| loom_solver) => do `(tactic| loom_auto) in
376+ $thmCmd)
343377 trace[Loom] "{ thmCmd} "
344378 Command.elabCommand thmCmd
345379 velvetObligations.modify (·.erase name.getId)
0 commit comments