Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ltac2 preterm antiquotation
$preterm:x
- Loading branch information
1 parent
f0e8b90
commit c0be1f6
Showing
12 changed files
with
300 additions
and
49 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
doc/changelog/06-Ltac2-language/17359-tac2-preterm-antiquot.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- **Added:** | ||
Ltac2 preterm antiquotation `$preterm:` | ||
(`#17359 <https://github.com/coq/coq/pull/17359>`_, | ||
fixes `#13977 <https://github.com/coq/coq/issues/13977>`_, | ||
by Gaëtan Gilbert). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
Require Import ZArith. | ||
Open Scope Z_scope. | ||
|
||
Require Import Ltac2.Ltac2. | ||
|
||
Ltac2 rec z2nat_preterm x := | ||
let b := eval cbv in (Z.leb $x 0) in | ||
lazy_match! b with | ||
| true => preterm:(O) | ||
| false => | ||
let pred := eval cbv in (Z.pred $x) in | ||
let r := z2nat_preterm pred in | ||
preterm:(S $preterm:r) | ||
end. | ||
|
||
|
||
Ltac2 rec z2nat_constr x := | ||
let b := eval cbv in (Z.leb $x 0) in | ||
lazy_match! b with | ||
| true => constr:(O) | ||
| false => let pred := eval cbv in (Z.pred $x) in | ||
let r := z2nat_constr pred in | ||
constr:(S $r) | ||
end. | ||
|
||
Ltac2 mk_app(a: constr)(b: constr) := | ||
Constr.Unsafe.make (Constr.Unsafe.App a [| b |]). | ||
|
||
Ltac2 rec z2nat_mk_app x := | ||
let b := eval cbv in (Z.leb $x 0) in | ||
lazy_match! b with | ||
| true => Env.instantiate reference:(O) | ||
| false => let pred := eval cbv in (Z.pred $x) in | ||
mk_app (Env.instantiate reference:(S)) (z2nat_mk_app pred) | ||
end. | ||
|
||
(* Time Ltac2 Eval *) | ||
(* let c := z2nat_constr constr:(10000) in *) | ||
(* Message.print (Message.of_constr c). (* 9 secs *) *) | ||
|
||
(* Time Ltac2 Eval *) | ||
(* let c := z2nat_mk_app constr:(10000) in *) | ||
(* Message.print (Message.of_constr c). (* <1 secs *) *) | ||
|
||
Time Ltac2 Eval | ||
let c := z2nat_preterm constr:(10000) in | ||
let c := constr:($preterm:c) in | ||
Message.print (Message.of_constr c). (* 6 secs *) | ||
|
||
(* Time Ltac2 Eval *) | ||
(* let c := z2nat_constr constr:(20000) in *) | ||
(* Message.print (Message.of_constr c). (* 22 secs *) *) | ||
|
||
(* Time Ltac2 Eval *) | ||
(* let c := z2nat_mk_app constr:(20000) in *) | ||
(* Message.print (Message.of_constr c). (* 1.6 secs *) *) | ||
|
||
Time Ltac2 Eval | ||
let c := z2nat_preterm constr:(20000) in | ||
let c := Constr.pretype c in | ||
Message.print (Message.of_constr c). (* 32 secs *) |
Oops, something went wrong.