Skip to content

Commit 4d6d014

Browse files
committed
Adapt WcbvEvalNamed to primitives (new values)
1 parent 69a80fc commit 4d6d014

File tree

6 files changed

+220
-81
lines changed

6 files changed

+220
-81
lines changed

erasure/theories/EPrimitive.v

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ From MetaCoq.Common Require Import Universes Primitive Reflect
44
Environment EnvironmentTyping.
55
(* From MetaCoq.Erasure Require Import BasicAst. *)
66
From Equations Require Import Equations.
7-
From Coq Require Import ssreflect.
7+
From Coq Require Import ssreflect Utf8.
88
From Coq Require Import Uint63 SpecFloat.
99

1010
Implicit Type term : Set.
@@ -377,4 +377,100 @@ Section PrimIn.
377377

378378
End PrimIn.
379379

380-
#[global] Hint Rewrite @map_primIn_spec : map.
380+
#[global] Hint Rewrite @map_primIn_spec : map.
381+
382+
Inductive All2_Set {A B : Set} (R : A -> B -> Set) : list A -> list B -> Set :=
383+
All2_nil : All2_Set R [] []
384+
| All2_cons : forall (x : A) (y : B) (l : list A) (l' : list B),
385+
R x y -> All2_Set R l l' -> All2_Set R (x :: l) (y :: l').
386+
Arguments All2_nil {_ _ _}.
387+
Arguments All2_cons {_ _ _ _ _ _ _}.
388+
Derive Signature for All2_Set.
389+
Derive NoConfusionHom for All2_Set.
390+
#[global] Hint Constructors All2_Set : core.
391+
392+
Section All2_size.
393+
Context {A B : Set} (P : A -> B -> Set) (fn : forall x1 x2, P x1 x2 -> nat).
394+
Fixpoint all2_size {l1 l2} (f : All2_Set P l1 l2) : nat :=
395+
match f with
396+
| All2_nil => 0
397+
| All2_cons _ _ _ _ rxy rll' => fn _ _ rxy + all2_size rll'
398+
end.
399+
End All2_size.
400+
401+
Lemma All2_Set_All2 {A B : Set} (R : A -> B -> Set) l l' : All2_Set R l l' -> All2 R l l'.
402+
Proof.
403+
induction 1; constructor; auto.
404+
Qed.
405+
#[export] Hint Resolve All2_Set_All2 : core.
406+
407+
Coercion All2_Set_All2 : All2_Set >-> All2.
408+
409+
Lemma All2_All2_Set {A B : Set} (R : A -> B -> Set) l l' : All2 R l l' -> All2_Set R l l'.
410+
Proof.
411+
induction 1; constructor; auto.
412+
Qed.
413+
#[export] Hint Immediate All2_All2_Set : core.
414+
415+
Set Equations Transparent.
416+
Equations All2_over {A B : Set} {P : A → B → Set} {l : list A} {l' : list B} :
417+
All2_Set P l l' → (∀ (x : A) (y : B), P x y → Type) → Type :=
418+
| All2_nil, _ := unit
419+
| All2_cons rxy rll', Q => Q _ _ rxy × All2_over rll' Q.
420+
421+
Lemma All2_over_undep {A B : Set} {P : A → B → Set} {l : list A} {l' : list B} (a : All2_Set P l l') (Q : A -> B → Type) :
422+
All2_over a (fun x y _ => Q x y) <~> All2 Q l l'.
423+
Proof.
424+
split.
425+
- induction a; cbn; constructor; intuition eauto.
426+
- induction a; cbn; intuition eauto; now depelim X.
427+
Qed.
428+
429+
Section map_All2_dep.
430+
Context {A B : Set}.
431+
Context (P : A -> B -> Set).
432+
Context {hP : forall x y, P x y -> Type}.
433+
Context (F : forall x y (e : P x y), hP x y e).
434+
435+
Equations map_All2_dep {l : list A} {l' : list B} (ev : All2_Set P l l') : All2_over ev hP :=
436+
| All2_nil := tt
437+
| All2_cons hd tl := (F _ _ hd, map_All2_dep tl).
438+
439+
End map_All2_dep.
440+
441+
Inductive onPrims {term term' : Set} (R : term -> term' -> Set) : prim_val term -> prim_val term' -> Set :=
442+
| onPrimsInt i : onPrims R (primInt; primIntModel i) (primInt; primIntModel i)
443+
| onPrimsFloat f : onPrims R (primFloat; primFloatModel f) (primFloat; primFloatModel f)
444+
| onPrimsArray v def v' def' :
445+
R def def' ->
446+
All2_Set R v v' ->
447+
let a := {| array_default := def; array_value := v |} in
448+
let a' := {| array_default := def'; array_value := v' |} in
449+
onPrims R (primArray; primArrayModel a) (primArray; primArrayModel a').
450+
Derive Signature for onPrims.
451+
452+
Variant onPrims_dep {term term' : Set} (R : term -> term' -> Set) (P : forall x y, R x y -> Type) : forall x y, onPrims R x y -> Type :=
453+
| onPrimsIntDep i : onPrims_dep R P (prim_int i) (prim_int i) (onPrimsInt R i)
454+
| onPrimsFloatDep f : onPrims_dep R P (prim_float f) (prim_float f) (onPrimsFloat R f)
455+
| onPrimsArrayDep v def v' def'
456+
(ed : R def def')
457+
(ev : All2_Set R v v') :
458+
P _ _ ed ->
459+
All2_over ev P ->
460+
let a := {| array_default := def; array_value := v |} in
461+
let a' := {| array_default := def'; array_value := v' |} in
462+
onPrims_dep R P (prim_array a) (prim_array a') (onPrimsArray R v def v' def' ed ev).
463+
Derive Signature for onPrims_dep.
464+
465+
Section map_onPrims.
466+
Context {term term' : Set}.
467+
Context {R : term -> term' -> Set}.
468+
Context {P : forall x y, R x y -> Type}.
469+
Context (F : forall x y (e : R x y), P x y e).
470+
471+
Equations map_onPrims {p : prim_val term} {p' : prim_val term'} (ev : onPrims R p p') : onPrims_dep R P p p' ev :=
472+
| @onPrimsInt _ _ _ _ := onPrimsIntDep _ _ i;
473+
| @onPrimsFloat _ _ _ _ := onPrimsFloatDep _ _ f;
474+
| @onPrimsArray v def v' def' ed ev :=
475+
onPrimsArrayDep _ _ v def v' def' ed ev (F _ _ ed) (map_All2_dep _ F ev).
476+
End map_onPrims.

erasure/theories/EWcbvEval.v

Lines changed: 17 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -69,60 +69,12 @@ Definition default_wcbv_flags := {| with_prop_case := true ; with_guarded_fix :=
6969
Definition opt_wcbv_flags := {| with_prop_case := false ; with_guarded_fix := true ; with_constructor_as_block := false|}.
7070
Definition target_wcbv_flags := {| with_prop_case := false ; with_guarded_fix := false ; with_constructor_as_block := false |}.
7171

72-
73-
Inductive All2_Set {A B : Set} (R : A -> B -> Set) : list A -> list B -> Set :=
74-
All2_nil : All2_Set R [] []
75-
| All2_cons : forall (x : A) (y : B) (l : list A) (l' : list B),
76-
R x y -> All2_Set R l l' -> All2_Set R (x :: l) (y :: l').
77-
Arguments All2_nil {_ _ _}.
78-
Arguments All2_cons {_ _ _ _ _ _ _}.
79-
Derive Signature for All2_Set.
80-
Derive NoConfusionHom for All2_Set.
81-
#[global] Hint Constructors All2_Set : core.
82-
83-
Section All2_size.
84-
Context {A B : Set} (P : A -> B -> Set) (fn : forall x1 x2, P x1 x2 -> size).
85-
Fixpoint all2_size {l1 l2} (f : All2_Set P l1 l2) : size :=
86-
match f with
87-
| All2_nil => 0
88-
| All2_cons _ _ _ _ rxy rll' => fn _ _ rxy + all2_size rll'
89-
end.
90-
End All2_size.
91-
92-
Lemma All2_Set_All2 {A B : Set} (R : A -> B -> Set) l l' : All2_Set R l l' -> All2 R l l'.
93-
Proof.
94-
induction 1; constructor; auto.
95-
Qed.
96-
#[export] Hint Resolve All2_Set_All2 : core.
97-
98-
Coercion All2_Set_All2 : All2_Set >-> All2.
99-
100-
Lemma All2_All2_Set {A B : Set} (R : A -> B -> Set) l l' : All2 R l l' -> All2_Set R l l'.
101-
Proof.
102-
induction 1; constructor; auto.
103-
Qed.
104-
#[export] Hint Immediate All2_All2_Set : core.
105-
106-
Set Equations Transparent.
107-
Equations All2_over {A B : Set} {P : A → B → Set} {l : list A} {l' : list B} :
108-
All2_Set P l l' → (∀ (x : A) (y : B), P x y → Type) → Type :=
109-
| All2_nil, _ := unit
110-
| All2_cons rxy rll', Q => Q _ _ rxy × All2_over rll' Q.
111-
112-
Lemma All2_over_undep {A B : Set} {P : A → B → Set} {l : list A} {l' : list B} (a : All2_Set P l l') (Q : A -> B → Type) :
113-
All2_over a (fun x y _ => Q x y) <~> All2 Q l l'.
114-
Proof.
115-
split.
116-
- induction a; cbn; constructor; intuition eauto.
117-
- induction a; cbn; intuition eauto; now depelim X.
118-
Qed.
119-
12072
Section Wcbv.
12173
Context {wfl : WcbvFlags}.
12274
Context (Σ : global_declarations).
12375
(* The local context is fixed: we are only doing weak reductions *)
12476

125-
Variant eval_primitive (eval : term -> term -> Set) : prim_val term -> prim_val term -> Set :=
77+
Variant eval_primitive {term term' : Set} (eval : term -> term' -> Set) : prim_val term -> prim_val term' -> Set :=
12678
| evalPrimInt i : eval_primitive eval (prim_int i) (prim_int i)
12779
| evalPrimFloat f : eval_primitive eval (prim_float f) (prim_float f)
12880
| evalPrimArray v def v' def'
@@ -133,7 +85,7 @@ Section Wcbv.
13385
eval_primitive eval (prim_array a) (prim_array a').
13486
Derive Signature for eval_primitive.
13587

136-
Variant eval_primitive_ind (eval : term -> term -> Set) (P : forall x y, eval x y -> Type) : forall x y, eval_primitive eval x y -> Type :=
88+
Variant eval_primitive_ind {term term' : Set} (eval : term -> term' -> Set) (P : forall x y, eval x y -> Type) : forall x y, eval_primitive eval x y -> Type :=
13789
| evalPrimIntDep i : eval_primitive_ind eval P (prim_int i) (prim_int i) (evalPrimInt eval i)
13890
| evalPrimFloatDep f : eval_primitive_ind eval P (prim_float f) (prim_float f) (evalPrimFloat eval f)
13991
| evalPrimArrayDep v def v' def'
@@ -145,6 +97,19 @@ Section Wcbv.
14597
eval_primitive_ind eval P (prim_array a) (prim_array a') (evalPrimArray eval v def v' def' ev ed).
14698
Derive Signature for eval_primitive_ind.
14799

100+
Section map_eval_prim.
101+
Context {term term' : Set}.
102+
Context {eval : term -> term' -> Set}.
103+
Context {P : forall x y, eval x y -> Type}.
104+
Context (F : forall x y (e : eval x y), P x y e).
105+
106+
Equations map_eval_primitive {p : prim_val term} {p' : prim_val term'} (ev : eval_primitive eval p p') : eval_primitive_ind eval P p p' ev :=
107+
| @evalPrimInt _ _ _ _ := evalPrimIntDep _ _ i;
108+
| @evalPrimFloat _ _ _ _ := evalPrimFloatDep _ _ f;
109+
| @evalPrimArray v def v' def' ev ed :=
110+
evalPrimArrayDep _ _ v def v' def' ev ed (map_All2_dep _ F ev) (F _ _ ed).
111+
End map_eval_prim.
112+
148113
Local Unset Elimination Schemes.
149114

150115
Inductive eval : term -> term -> Set :=
@@ -672,11 +637,8 @@ Section eval_rect.
672637
| [ H : _ |- _ ] =>
673638
eapply H; (unshelve eapply aux || tea); tea; cbn; try lia
674639
end.
675-
clear -aux a. revert args args' a.
676-
fix aux' 3. destruct a. constructor. constructor. apply aux. apply aux'.
677-
destruct e; constructor; eauto.
678-
clear -aux ev. revert v v' ev.
679-
fix aux' 3. destruct ev. constructor. constructor. apply aux. apply aux'.
640+
exact (map_All2_dep _ aux a).
641+
exact (map_eval_primitive aux e).
680642
Qed.
681643

682644
Definition eval_rec := eval_rect.

erasure/theories/EWcbvEvalInd.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
From Coq Require Import Utf8 Program ssreflect ssrbool.
33
From MetaCoq.Utils Require Import utils.
44
From MetaCoq.Common Require Import config Kernames BasicAst EnvMap.
5-
From MetaCoq.Erasure Require Import EAst EAstUtils EInduction EWcbvEval EGlobalEnv ECSubst EInduction.
5+
From MetaCoq.Erasure Require Import EPrimitive EAst EAstUtils EInduction EWcbvEval EGlobalEnv ECSubst EInduction.
66

77
Set Asymmetric Patterns.
88
From Equations Require Import Equations.
@@ -280,7 +280,7 @@ Proof using Type.
280280
unshelve eapply H; try match goal with |- eval _ _ _ => tea end; tea; unfold IH; intros; unshelve eapply IH'; tea; cbn; try lia
281281
end].
282282
- eapply X15; tea; auto.
283-
clear -a IH'. induction a; constructor.
283+
clear -a IH'. induction a; constructor; eauto.
284284
eapply (IH' _ _ r). cbn. lia. apply IHa.
285285
intros. eapply (IH' _ _ H). cbn. lia.
286286
- unshelve eapply X17; tea.

0 commit comments

Comments
 (0)