| 1 |
(** * Reification Cache *) |
| 2 |
(** This file defines the cache that holds reified versions of |
| 3 |
operations, as well as the tactics that reify and apply things |
| 4 |
from the cache. *) |
| 5 |
From Coq Require Import Relation_Definitions. |
| 6 |
Require Import Crypto.Util.Tactics.Head. |
| 7 |
Require Import Crypto.Util.Tactics.SubstEvars. |
| 8 |
Require Import Crypto.Language.API. |
| 9 |
Require Import Rewriter.Language.Wf. |
| 10 |
|
| 11 |
Import |
| 12 |
Language.API.Compilers |
| 13 |
Language.Wf.Compilers. |
| 14 |
|
| 15 |
Import Compilers.API. |
| 16 |
|
| 17 |
Fixpoint pointwise_equal {t} : relation (type.interp base.interp t) |
| 18 |
:= match t with |
| 19 |
| type.base t => Logic.eq |
| 20 |
| type.arrow s d |
| 21 |
=> fun (f g : type.interp base.interp s -> type.interp base.interp d) |
| 22 |
=> forall x, pointwise_equal (f x) (g x) |
| 23 |
end. |
| 24 |
|
| 25 |
Definition is_reification_of' {t} (e : Expr t) (v : type.interp base.interp t) : Prop |
| 26 |
:= pointwise_equal (Interp e) v /\ Wf e. |
| 27 |
|
| 28 |
Notation is_reification_of rop op |
| 29 |
:= (match @is_reification_of' (reify_type_of op) rop op with |
| 30 |
| T |
| 31 |
=> ltac:( |
| 32 |
let T := (eval cbv [pointwise_equal is_reification_of' T] in T) in |
| 33 |
let T := (eval cbn [type.interp base.interp base.base_interp] in T) in |
| 34 |
exact T) |
| 35 |
end) |
| 36 |
(only parsing). |
| 37 |
|
| 38 |
Ltac cache_reify _ := |
| 39 |
split; |
| 40 |
[ intros; |
| 41 |
etransitivity; |
| 42 |
[ |
| 43 |
| repeat match goal with |- _ = ?f' ?x => is_var x; apply (f_equal (fun f => f _)) end; |
| 44 |
Reify_rhs (); |
| 45 |
reflexivity ]; |
| 46 |
subst_evars; |
| 47 |
reflexivity |
| 48 |
| prove_Wf () ]. |
| 49 |
|
| 50 |
Ltac apply_cached_reification op lem := |
| 51 |
lazymatch goal with |
| 52 |
| [ |- _ = ?RHS ] |
| 53 |
=> let f := head RHS in |
| 54 |
constr_eq f op; |
| 55 |
simple apply lem |
| 56 |
end. |
| 57 |
|
| 58 |
Create HintDb reify_gen_cache discriminated. |
| 59 |
Create HintDb wf_gen_cache discriminated. |
| 60 |
|
| 61 |
Module Export Hints. |
| 62 |
#[global] |
| 63 |
Hint Resolve conj : reify_gen_cache wf_gen_cache. |
| 64 |
#[global] |
| 65 |
Hint Unfold Wf.Compilers.Wf : wf_gen_cache. |
| 66 |
End Hints. |