Debian Codegraph @

theories/Ltac2/Rewrite.v

raw
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 From Ltac2 Require Import Init.
12 From Ltac2 Require Std.
13
14 (** Module for rewrite strategies used by [rewrite_strat]. *)
15 Module Strategy.
16 Ltac2 Type t.
17
18 (** Failure. *)
19 Ltac2 @external fail : t :=
20 "rocq-runtime.plugins.ltac2" "rewstrat_fail".
21
22 (** Success without progress. *)
23 Ltac2 @external id : t :=
24 "rocq-runtime.plugins.ltac2" "rewstrat_id".
25
26 (** Success with progress. *)
27 Ltac2 @external refl : t :=
28 "rocq-runtime.plugins.ltac2" "rewstrat_refl".
29
30 (** Applies the argument and fails if no progress was made. *)
31 Ltac2 @external progress : t -> t :=
32 "rocq-runtime.plugins.ltac2" "rewstrat_progress".
33
34 (** Applies left, and then right if left succeeded. *)
35 Ltac2 @external seq : t -> t -> t :=
36 "rocq-runtime.plugins.ltac2" "rewstrat_seq".
37
38 (** Equivalent to [List.fold_left seq id]. *)
39 Ltac2 @external seqs : t list -> t :=
40 "rocq-runtime.plugins.ltac2" "rewstrat_seqs".
41
42 (** Applies left, and then right if left failed. *)
43 Ltac2 @external choice : t -> t -> t :=
44 "rocq-runtime.plugins.ltac2" "rewstrat_choice".
45
46 (** Equivalent to [List.fold_left choice fail]. *)
47 Ltac2 @external choices : t list -> t :=
48 "rocq-runtime.plugins.ltac2" "rewstrat_choices".
49
50 (** Equivalent to [choice s id]. *)
51 Ltac2 @external try : t -> t :=
52 "rocq-runtime.plugins.ltac2" "rewstrat_try".
53
54 (** Applies the argument until it fails. *)
55 Ltac2 @external any : t -> t :=
56 "rocq-runtime.plugins.ltac2" "rewstrat_any".
57
58 (** Equivalent to [seq s (any s)]. *)
59 Ltac2 @external repeat : t -> t :=
60 "rocq-runtime.plugins.ltac2" "rewstrat_repeat".
61
62 (** Applies the argument to all immediate subterms of the considered term,
63 left-to-right. *)
64 Ltac2 @external subterms : t -> t :=
65 "rocq-runtime.plugins.ltac2" "rewstrat_all_subterms".
66
67 (** Applies the argument to the leftmost immediate subterm of the considered
68 term on which progress can be made. *)
69 Ltac2 @external subterm : t -> t :=
70 "rocq-runtime.plugins.ltac2" "rewstrat_one_subterm".
71
72 (** Traverses the term bottom-up--left-to-right and applies the argument at
73 each step as many times as possible. *)
74 Ltac2 @external bottomup : t -> t :=
75 "rocq-runtime.plugins.ltac2" "rewstrat_bottomup".
76
77 (** Traverses the term top-down--left-to-right and applies the argument at
78 each step as many times as possible. *)
79 Ltac2 @external topdown : t -> t :=
80 "rocq-runtime.plugins.ltac2" "rewstrat_topdown".
81
82 (** Traverses the term bottom-up--left-to-right until the argument makes progress. *)
83 Ltac2 @external innermost : t -> t :=
84 "rocq-runtime.plugins.ltac2" "rewstrat_innermost".
85
86 (** Traverses the term top-down--left-to-right until the argument makes progress. *)
87 Ltac2 @external outermost : t -> t :=
88 "rocq-runtime.plugins.ltac2" "rewstrat_outermost".
89
90 (** Unifies the one side of the lemma with the current subterm and on success
91 rewrite it to the other side. If the boolean argument is true, rewrites
92 left-to-right; otherwise, rewrites right-to-left. *)
93 Ltac2 @external term : preterm -> bool -> t :=
94 "rocq-runtime.plugins.ltac2" "rewstrat_one_lemma".
95
96 (** Equivalent to [choices (List.map (fun c => term c true)) l]. *)
97 Ltac2 @external terms : preterm list -> t :=
98 "rocq-runtime.plugins.ltac2" "rewstrat_lemmas".
99
100 (* TODO this needs documentation *)
101 Ltac2 @external old_hints : ident -> t :=
102 "rocq-runtime.plugins.ltac2" "rewstrat_old_hints".
103
104 (** Applies hints from rewrite hint database. *)
105 Ltac2 @external hints : ident -> t :=
106 "rocq-runtime.plugins.ltac2" "rewstrat_hints".
107
108 (** Replaces the term under consideration with the argument if they unify. *)
109 Ltac2 @external fold : constr -> t :=
110 "rocq-runtime.plugins.ltac2" "rewstrat_fold".
111
112 (** Converts the term under consideration. *)
113 Ltac2 @external eval : Std.Red.t -> t :=
114 "rocq-runtime.plugins.ltac2" "rewstrat_eval".
115
116 (** Fixed point operation for recursive strategies. [fix (fun f => s)] evaluates
117 to [s[f / fix (fun f => s)]]. The function provided in the argument is
118 executed only _once_ when the strategy is constructed — it cannot be used
119 for dynamically manage the rewriting. *)
120 Ltac2 @external fix_ : (t -> t) -> t :=
121 "rocq-runtime.plugins.ltac2" "rewstrat_fix".
122
123 End Strategy.
124
125 (* Tactics *)
126
127 (** Runs rewrite strategy on the type of a hypothesis or the goal if the second
128 argument is [None]. *)
129 Ltac2 @external rewrite_strat : Strategy.t -> ident option -> unit := "rocq-runtime.plugins.ltac2" "tac_rewrite_strat".
130
131 (** Runs rewritings from a hint database on the type of a hypothesis or the goal
132 if the second argument is [None]. The rewritings are applied top-down on all
133 subterms. *)
134 Ltac2 rewrite_db (hintdb : ident) (i : ident option) : unit := rewrite_strat (Strategy.topdown (Strategy.hints hintdb)) i.