| 1 |
Require Import Crypto.Util.Decidable. |
| 2 |
Require Import Crypto.Util.SideConditions.CorePackages. |
| 3 |
Require Import Crypto.Util.Tactics.HeadUnderBinders. |
| 4 |
|
| 5 |
Definition vm_decide_package (P : Prop) := P. |
| 6 |
Definition cbv_minus_then_vm_decide_package {T} (ident : T) (P : Prop) := P. |
| 7 |
Definition vm_compute_reflexivity_package (P : Prop) := P. |
| 8 |
Inductive cast_bias := LHS | RHS. |
| 9 |
Definition vm_compute_evar_package_gen {bias : cast_bias} {T} (v : T) := |
| 10 |
@evar_package T v. |
| 11 |
Notation vm_compute_evar_package_vm_small := (@vm_compute_evar_package_gen LHS). |
| 12 |
Notation vm_compute_evar_package_vm_large := (@vm_compute_evar_package_gen RHS). |
| 13 |
Notation vm_compute_evar_package := vm_compute_evar_package_vm_small. |
| 14 |
Definition native_compute_evar_package_gen {bias : cast_bias} {T} (v : T) := |
| 15 |
@evar_package T v. |
| 16 |
Notation native_compute_evar_package_native_small := (@native_compute_evar_package_gen LHS). |
| 17 |
Notation native_compute_evar_package_native_large := (@native_compute_evar_package_gen RHS). |
| 18 |
Notation native_compute_evar_package := native_compute_evar_package_native_small. |
| 19 |
Definition vm_compute_cbv_evar_package_gen {bias : cast_bias} {T} (v : T) := |
| 20 |
@evar_package T v. |
| 21 |
Notation vm_compute_cbv_evar_package_vm_small := (@vm_compute_cbv_evar_package_gen LHS). |
| 22 |
Notation vm_compute_cbv_evar_package_vm_large := (@vm_compute_cbv_evar_package_gen RHS). |
| 23 |
Notation vm_compute_cbv_evar_package := vm_compute_cbv_evar_package_vm_small. |
| 24 |
Definition vm_cast_evar_package {s} (v : s) d := @evard_package s d v. |
| 25 |
Definition cast_evar_package {s} (v : s) d := @evard_package s d v. |
| 26 |
Definition vm_compute_cast_evar_package {s} (v : s) d := @evard_package s d v. |
| 27 |
|
| 28 |
Definition optional_evar_Prop_package {T} (P : T -> Prop) (alt_pkg : Type) |
| 29 |
:= @evar_Prop_package |
| 30 |
(option T) |
| 31 |
(fun v => match v with |
| 32 |
| Some v => P v |
| 33 |
| None => True |
| 34 |
end). |
| 35 |
|
| 36 |
Definition None_evar_Prop_package' {alt_pkg T P} : @optional_evar_Prop_package T P alt_pkg |
| 37 |
:= {| val := None ; evar_package_pf := I |}. |
| 38 |
Notation None_evar_Prop_package := (@None_evar_Prop_package' unit). |
| 39 |
|
| 40 |
Notation optional_evar_package pkg_type |
| 41 |
:= (optional_evar_Prop_package |
| 42 |
(ltac:(lazymatch eval hnf in pkg_type%type with evar_Prop_package ?P => exact P end)) |
| 43 |
pkg_type) |
| 44 |
(only parsing). |
| 45 |
|
| 46 |
Definition option_evar_rel_package {A} (v : option A) B (R : B -> A -> Prop) (alt_pkg : A -> Type) |
| 47 |
:= @evar_Prop_package |
| 48 |
(option B) |
| 49 |
(fun v' => match v', v with |
| 50 |
| Some v', Some v => R v' v |
| 51 |
| None, None => True |
| 52 |
| Some _, None | None, Some _ => False |
| 53 |
end). |
| 54 |
|
| 55 |
Notation optional_evar_rel_package pkg_type x |
| 56 |
:= (option_evar_rel_package |
| 57 |
x |
| 58 |
_ |
| 59 |
(fun a b |
| 60 |
=> ltac:(lazymatch eval hnf in (pkg_type%function b) with |
| 61 |
| evar_Prop_package ?P |
| 62 |
=> let P := (eval cbv beta in (P a)) in |
| 63 |
exact P |
| 64 |
end)) |
| 65 |
pkg_type) |
| 66 |
(only parsing). |
| 67 |
|
| 68 |
Definition unoption_evar_rel_package {A v B R alt_pkg} |
| 69 |
(f : forall v, alt_pkg v -> @evar_rel_package A v B R) |
| 70 |
: forall (pkg : match v with |
| 71 |
| Some v => alt_pkg v |
| 72 |
| None => True |
| 73 |
end), |
| 74 |
@option_evar_rel_package A v B R alt_pkg |
| 75 |
:= match v |
| 76 |
return match v with |
| 77 |
| Some v => alt_pkg v |
| 78 |
| None => True |
| 79 |
end -> @option_evar_rel_package A v B R alt_pkg |
| 80 |
with |
| 81 |
| Some v => fun pkg => {| val := Some (val (f _ pkg)); |
| 82 |
evar_package_pf := evar_package_pf (f _ pkg) |} |
| 83 |
| None => fun _ => None_evar_Prop_package |
| 84 |
end. |
| 85 |
|
| 86 |
Ltac autosolve autosolve_tac else_tac := |
| 87 |
lazymatch goal with |
| 88 |
| [ |- match ?x with Some _ => _ | None => _ end ] |
| 89 |
=> let x' := (eval hnf in x) in |
| 90 |
progress change x with x'; |
| 91 |
cbv beta iota; |
| 92 |
autosolve_tac else_tac |
| 93 |
| [ |- vm_decide_package (_ = true) ] => abstract vm_cast_no_check (eq_refl true) |
| 94 |
| [ |- vm_decide_package (_ = false) ] => abstract vm_cast_no_check (eq_refl false) |
| 95 |
| [ |- vm_decide_package ?P ] => cbv beta delta [vm_decide_package]; vm_decide |
| 96 |
| [ |- cbv_minus_then_vm_decide_package ?ident ?P ] => cbv -[ident]; vm_decide |
| 97 |
| [ |- vm_compute_reflexivity_package ?P ] => vm_compute; reflexivity |
| 98 |
| [ |- vm_compute_evar_package_vm_small ?v ] |
| 99 |
=> let v' := (eval vm_compute in v) in |
| 100 |
(exists v'); abstract vm_cast_no_check (eq_refl v') |
| 101 |
| [ |- vm_compute_evar_package_vm_large ?v ] |
| 102 |
=> let v' := (eval vm_compute in v) in |
| 103 |
(exists v'); abstract vm_cast_no_check (eq_refl v) |
| 104 |
| [ |- vm_compute_cbv_evar_package_vm_small ?v ] |
| 105 |
=> let v' := (eval vm_compute in v) in |
| 106 |
let v' := (eval cbv in v) in |
| 107 |
(exists v'); abstract vm_cast_no_check (eq_refl v') |
| 108 |
| [ |- vm_compute_cbv_evar_package_vm_large ?v ] |
| 109 |
=> let v' := (eval vm_compute in v) in |
| 110 |
let v' := (eval cbv in v) in |
| 111 |
(exists v'); abstract vm_cast_no_check (eq_refl v) |
| 112 |
| [ |- native_compute_evar_package_native_small ?v ] |
| 113 |
=> let v' := (eval native_compute in v) in |
| 114 |
(exists v'); abstract native_cast_no_check (eq_refl v') |
| 115 |
| [ |- native_compute_evar_package_native_large ?v ] |
| 116 |
=> let v' := (eval native_compute in v) in |
| 117 |
(exists v'); abstract native_cast_no_check (eq_refl v) |
| 118 |
| [ |- vm_cast_evar_package ?v ?d ] |
| 119 |
=> unshelve eexists (v <: d); |
| 120 |
[ vm_compute; reflexivity |
| 121 |
| cbv beta; |
| 122 |
let lhs := lazymatch goal with |- ?lhs = _ => lhs end in |
| 123 |
abstract exact_no_check (eq_refl lhs) ] |
| 124 |
| [ |- cast_evar_package (s:=?s) ?v ?d ] |
| 125 |
=> exact (@Build_evard_package |
| 126 |
s d v |
| 127 |
v eq_refl eq_refl) |
| 128 |
| [ |- vm_compute_cast_evar_package (s:=?s) ?v ?d ] |
| 129 |
=> let v' := (eval vm_compute in v) in |
| 130 |
exact (@Build_evard_package |
| 131 |
s d v |
| 132 |
v' eq_refl eq_refl) |
| 133 |
| [ |- @option_evar_rel_package ?A ?v ?B ?R ?alt_pkg ] |
| 134 |
=> refine (@unoption_evar_rel_package A v B R alt_pkg (fun _ x => x) _); |
| 135 |
autosolve_tac else_tac |
| 136 |
| _ => else_tac () |
| 137 |
end. |