Skip to content

Commit e0f37f6

Browse files
authored
add prove_correct? command (#25)
1 parent 9bb122f commit e0f37f6

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

CaseStudies/Velvet/Syntax.lean

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ syntax "method" ident leafny_binder* "return" "(" ident ":" term ")"
6969
(ensures_caluse)* "do" doSeq
7070
Termination.suffix : command
7171

72-
syntax "prove_correct" ident Termination.suffix "by" tacticSeq : command
72+
declare_syntax_cat prove_correct_command
73+
syntax "prove_correct" : prove_correct_command
74+
syntax "prove_correct?" : prove_correct_command
75+
76+
syntax prove_correct_command ident Termination.suffix "by" tacticSeq : command
7377

7478
syntax (priority := high) ident noWs "[" term "]" ":=" term : doElem
7579
syntax (priority := high) ident noWs "[" term "]" "+=" term : doElem
@@ -321,7 +325,7 @@ lemma triple_test (arr: arrInt) :
321325

322326
@[incremental]
323327
elab_rules : command
324-
| `(command| prove_correct $name:ident $suf:suffix by%$tkp $proof:tacticSeq) => do
328+
| `(command| $pv:prove_correct_command $name:ident $suf:suffix by%$tkp $proof:tacticSeq) => do
325329
let ctx <- velvetObligations.get
326330
let .some obligation := ctx[name.getId]? | throwError "no obligation found"
327331
let bindersIdents := obligation.binderIdents
@@ -331,15 +335,14 @@ elab_rules : command
331335
let pre ← liftCoreM <| addPreludeToPreCond obligation.pre obligation.modIds
332336
let post := obligation.post
333337
let lemmaName := mkIdent <| name.getId.appendAfter "_correct"
334-
-- let proof <- withRef tkp ``()
338+
let triple <- `($(mkIdent ``triple))
335339
let proofSeq ← withRef tkp `(tacticSeq|
336340
unfold $name
337341
($proof))
338-
339342
let thmCmd <- withRef tkp `(command|
340-
@[loomSpec]
343+
@[$(mkIdent `loomSpec):ident]
341344
lemma $lemmaName $bindersIdents* :
342-
triple
345+
$triple
343346
$pre
344347
($name $ids*)
345348
(fun $ret => $post) := by $proofSeq $suf:suffix)
@@ -360,22 +363,33 @@ elab_rules : command
360363
/- In case of `grind` solver, we need to fetch the number of splits from the options first. -/
361364
let splits := Lean.Syntax.mkNatLit <| (opts.getNat (defVal := 20) `loom.solver.grind.splits)
362365
`(command|
363-
macro_rules | `(tactic| loom_solver) => do `(tactic| try grind (splits := $splits)) in
366+
macro_rules | `(tactic| loom_solver) => do
367+
`(tactic| try grind ($(mkIdent `splits):ident := $splits)) in
364368
$thmCmd)
365369
| "custom" => pure thmCmd
366370
| _ =>
367371
/- This is the case of `cvc5` or `z3` solver. We also need to fetch the timeout from the options. -/
368372
let timeout := Syntax.mkNatLit <| (opts.getNat (defVal := 1) `loom.solver.smt.timeout)
369373
let solver := Syntax.mkStrLit <| (opts.getString (defVal := "cvc5") `loom.solver.smt.solver)
374+
let autoSMTTrust := Lean.mkIdent `auto.smt.trust
375+
let autoSMT := Lean.mkIdent `auto.smt
376+
let autoSMTSolverName := Lean.mkIdent `auto.smt.solver.name
377+
let autoSMTTimeout := Lean.mkIdent `auto.smt.timeout
370378
`(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
379+
set_option $autoSMTTrust true in
380+
set_option $autoSMT true in
381+
set_option $autoSMTSolverName $solver in
382+
set_option $autoSMTTimeout $timeout in
375383
macro_rules | `(tactic| loom_solver) => do `(tactic| loom_auto) in
376384
$thmCmd)
377385
trace[Loom] "{thmCmd}"
378-
Command.elabCommand thmCmd
386+
match pv with
387+
| `(prove_correct_command| prove_correct) =>
388+
Command.elabCommand thmCmd
389+
| `(prove_correct_command| prove_correct?) =>
390+
Command.liftTermElabM do
391+
Tactic.TryThis.addSuggestion (<-getRef) thmCmd
392+
| _ => throwError "unexpected proof command: {pv}"
379393
velvetObligations.modify (·.erase name.getId)
380394

381395
set_option linter.unusedVariables false in

0 commit comments

Comments
 (0)