@@ -33,43 +33,9 @@ Axiom trust_cofix : forall {A}, A.
3333#[global]
3434Hint Constructors eval : core.
3535
36- Module Thunk.
37- Definition make (t : term) : term :=
38- tLambda (nNamed "thunk") (lift 1 0 t).
39-
40- Definition force (t : term) :=
41- tApp t tBox.
42-
43- Definition make_name (x : string) (n : nat) : string :=
44- (x ++ string_of_nat n)%bs.
45-
46- (* Thunk an n-ary function:
47- [t] is supposed to be of type T0 -> ... -> Tn -> C here
48- and we want to produce an expansion:
49- λ x0 .. xn (), t x0 xn () *)
50- Equations make_n_aux (n : nat) (t : term) (acc : list term) : term :=
51- make_n_aux 0 t acc => tLambda
52- (nNamed "thunk")
53- (mkApps (lift0 1 t) (rev (tRel 0 :: map (lift0 1) acc)));
54- make_n_aux (S n) t acc =>
55- tLambda
56- (nNamed (make_name "x" (S n)))
57- (make_n_aux n (lift0 1 t) (tRel 0 :: map (lift0 1) acc)).
58-
59- Definition make_n (n : nat) (t : term) := make_n_aux n t [].
60-
61- (* Eval compute in make_n 2 (tRel 0). *)
62-
63- End Thunk.
64-
6536Section trans.
6637 Context (Σ : GlobalContextMap.t).
6738
68- Definition trans_cofix (d : def term) :=
69- {| dname := d.(dname);
70- dbody := Thunk.make_n d.(rarg) d.(dbody);
71- rarg := d.(rarg) |}.
72-
7339 Fixpoint trans (t : term) : term :=
7440 match t with
7541 | tRel i => tRel i
@@ -81,33 +47,31 @@ Section trans.
8147 let brs' := List.map (on_snd trans) brs in
8248 match GlobalContextMap.lookup_inductive_kind Σ (fst ind).(inductive_mind) with
8349 | Some CoFinite =>
84- tCase ind (Thunk.force (trans c)) brs'
50+ tCase ind (tForce (trans c)) brs'
8551 | _ => tCase ind (trans c) brs'
8652 end
8753 | tProj p c =>
8854 match GlobalContextMap.lookup_inductive_kind Σ p.(proj_ind).(inductive_mind) with
89- | Some CoFinite => tProj p (Thunk.force (trans c))
55+ | Some CoFinite => tProj p (tForce (trans c))
9056 | _ => tProj p (trans c)
9157 end
9258 | tFix mfix idx =>
9359 let mfix' := List.map (map_def trans) mfix in
9460 tFix mfix' idx
9561 | tCoFix mfix idx =>
9662 let mfix' := List.map (map_def trans) mfix in
97- let mfix' := List.map trans_cofix mfix' in
98- match nth_error mfix' idx with
99- | Some d => Thunk.make_n d.(rarg) (tFix mfix' idx)
100- | None => tCoFix mfix' idx
101- end
63+ tFix mfix' idx
10264 | tBox => t
10365 | tVar _ => t
10466 | tConst _ => t
10567 | tConstruct ind i args =>
10668 match GlobalContextMap.lookup_inductive_kind Σ ind.(inductive_mind) with
107- | Some CoFinite => Thunk.make (tConstruct ind i (map trans args))
69+ | Some CoFinite => tLazy (tConstruct ind i (map trans args))
10870 | _ => tConstruct ind i (map trans args)
10971 end
11072 | tPrim p => tPrim (map_prim trans p)
73+ | tLazy t => tLazy (trans t)
74+ | tForce t => tForce (trans t)
11175 end .
11276
11377 (* cofix succ x := match x with Stream x xs => Stream (x + 1) (succ xs) ->
@@ -160,14 +124,9 @@ Section trans.
160124 unfold test_def in *;
161125 simpl closed in *; try solve [simpl subst; simpl closed; f_equal; auto; rtoProp; solve_all]; try easy.
162126 - destruct GlobalContextMap.lookup_inductive_kind as [[]|] => /= //; solve_all.
163- rewrite -Nat.add_1_r. now eapply closedn_lift.
164127 - move/andP: H => [] clt clargs.
165128 destruct GlobalContextMap.lookup_inductive_kind as [[]|] => /= //; rtoProp; solve_all; solve_all.
166129 - destruct GlobalContextMap.lookup_inductive_kind as [[]|] => /= //; rtoProp; solve_all; solve_all.
167- - solve_all. destruct nth_error eqn:hnth.
168- * apply trust_cofix.
169- * cbn. unfold trans_cofix. len. solve_all.
170- unfold test_def. cbn. apply trust_cofix.
171130 - primProp. solve_all_k 6.
172131 Qed .
173132
@@ -219,25 +178,13 @@ Section trans.
219178 - destruct (k ?= n)%nat; auto.
220179 - destruct GlobalContextMap.lookup_inductive_kind as [[]|] => /= //.
221180 1,3,4:f_equal; rewrite map_map_compose; solve_all.
222- unfold Thunk.make. f_equal. cbn.
223- rewrite !map_map_compose. f_equal; solve_all.
224- specialize (H k cl). rewrite H.
225- rewrite closed_subst. now apply closed_trans.
226- rewrite closed_subst. now apply closed_trans.
227- now rewrite commut_lift_subst_rec.
181+ do 2 f_equal; solve_all.
228182 - destruct GlobalContextMap.lookup_inductive_kind as [[]|] => /= //.
229183 all:f_equal; eauto; try (rewrite /on_snd map_map_compose; solve_all).
230- unfold Thunk.force. f_equal; eauto .
184+ f_equal. eauto .
231185 - destruct GlobalContextMap.lookup_inductive_kind as [[]|] => /= //.
232186 all:f_equal; eauto; try (rewrite /on_snd map_map_compose; solve_all).
233- unfold Thunk.force. f_equal; eauto .
234- - f_equal. solve_all.
235- rewrite !nth_error_map. destruct nth_error eqn:hnth => //=.
236- 2:{ f_equal. rewrite map_map_compose. eapply map_ext_in => x hin.
237- rewrite /trans_cofix /map_def //=. f_equal. len.
238- rewrite /Thunk.make_n. apply trust_cofix.
239- }
240- apply trust_cofix.
187+ f_equal; eauto .
241188 Qed .
242189
243190 Lemma trans_substl s t :
@@ -284,19 +231,19 @@ Section trans.
284231 discriminate.
285232 Qed .
286233
287- Lemma trans_cunfold_cofix mfix idx n f :
234+ (* Lemma trans_cunfold_cofix mfix idx n f :
288235 forallb (closedn 0) (EGlobalEnv.cofix_subst mfix) ->
289236 cunfold_cofix mfix idx = Some (n, f) ->
290237 exists d, nth_error mfix idx = Some d /\
291- cunfold_fix (map trans_cofix mfix) idx = Some (n, substl (fix_subst (map trans_cofix mfix)) (Thunk.make_n (rarg d) ( dbody d) )).
238+ cunfold_fix mfix idx = Some (n, substl (fix_subst mfix) ( dbody d)).
292239 Proof using Type.
293240 intros hcofix.
294241 unfold cunfold_cofix, cunfold_fix.
295242 rewrite nth_error_map.
296243 destruct nth_error.
297244 intros [= <- <-] => /=. f_equal. exists d. split => //.
298245 discriminate.
299- Qed .
246+ Qed. *)
300247
301248 Lemma trans_nth {n l d} :
302249 trans (nth n l d) = nth n (map trans l) (trans d).
@@ -450,7 +397,6 @@ Proof.
450397 unfold lookup_inductive in hl.
451398 destruct lookup_minductive => //.
452399 rewrite (IHt _ H2 _ H0 H1) //.
453- - apply trust_cofix.
454400Qed .
455401
456402Lemma wellformed_trans_decl_extends {wfl: EEnvFlags} {Σ : GlobalContextMap.t} t :
@@ -611,11 +557,6 @@ Proof.
611557 exists mdecl, idecl; split => //.
612558Qed .
613559
614- Lemma isLambda_make_n n t : isLambda (Thunk.make_n n t).
615- Proof .
616- induction n; cbn => //.
617- Qed .
618-
619560Lemma value_trans {efl : EEnvFlags} {fl : WcbvFlags} {hasc : cstr_as_blocks = true} {wcon : with_constructor_as_block = true} {Σ : GlobalContextMap.t} {c} :
620561 has_tApp -> wf_glob Σ ->
621562 wellformed Σ 0 c ->
@@ -628,11 +569,6 @@ Proof.
628569 all:try solve [intros; repeat constructor => //].
629570 destruct args => //.
630571 move=> /andP[] wc. now rewrite wcon in wc.
631- move=> _ /andP [] hascof /andP[] /Nat.ltb_lt /nth_error_Some hnth hm.
632- destruct nth_error => //.
633- pose proof (isLambda_make_n (rarg d) (tFix (map trans_cofix mfix) idx)).
634- destruct Thunk.make_n => //. apply trust_cofix.
635- (* do 3 constructor. *)
636572 - intros p pv IH wf. cbn. constructor. constructor 2.
637573 cbn in wf. move/andP: wf => [hasp tp].
638574 primProp. depelim tp; depelim pv; depelim IH; constructor; cbn in *; rtoProp; intuition auto; solve_all.
@@ -641,7 +577,8 @@ Proof.
641577 cbn -[GlobalContextMap.lookup_inductive_kind].
642578 destruct GlobalContextMap.lookup_inductive_kind as [[]|] eqn:hl' => //.
643579 1,3,4:eapply value_constructor; tea; [erewrite <-lookup_constructor_trans; tea|now len|solve_all].
644- now do 2 constructor.
580+ apply trust_cofix.
581+ (* now do 2 constructor. *)
645582 - intros f args vh harglen hargs ihargs.
646583 rewrite wellformed_mkApps // => /andP[] wff wfargs.
647584 rewrite trans_mkApps.
@@ -669,6 +606,7 @@ Ltac destruct_times :=
669606From MetaCoq.Erasure Require Import EWcbvEvalCstrsAsBlocksInd.
670607Lemma trans_correct {efl : EEnvFlags} {fl} {wcon : with_constructor_as_block = true}
671608 {wcb : cstr_as_blocks = true}
609+ {wpc : with_prop_case = false} (* Avoid tLazy tBox values *)
672610 {Σ : GlobalContextMap.t} t v :
673611 has_tApp ->
674612 wf_glob Σ ->
@@ -712,7 +650,8 @@ Proof.
712650 1,3,4: eauto.
713651 + now rewrite -is_propositional_cstr_trans.
714652 + rewrite nth_error_map H2 //.
715- + eapply eval_beta. eapply e0; eauto.
653+ + eapply trust_cofix.
654+ (* eapply eval_beta. eapply e0; eauto.
716655 constructor; eauto.
717656 rewrite closed_subst // simpl_subst_k //.
718657 eapply EWcbvEval.eval_to_value in H.
@@ -724,27 +663,19 @@ Proof.
724663 instantiate (1 := map (trans Σ) args).
725664 eapply All2_All2_Set.
726665 eapply values_final. solve_all.
727- unshelve eapply value_trans; tea.
666+ unshelve eapply value_trans; tea.*)
728667 + now len.
729668 + now len.
730- + exact e .
669+ + apply trust_cofix .
731670
732- - subst brs.
733- cbn -[lookup_constructor lookup_constructor_pars_args
734- GlobalContextMap.lookup_inductive_kind] in e0 |- *.
735- rewrite GlobalContextMap.lookup_inductive_kind_spec.
736- rewrite trans_substl ?map_repeat /= in e.
737- { now apply forallb_repeat. }
738- destruct lookup_inductive_kind as [[]|] eqn:hl => //.
739- 1,3,4:eapply eval_iota_sing; [eauto|eauto|
740- now rewrite -is_propositional_trans|reflexivity|
741- rewrite /= ?trans_substl //; simpl; eauto].
742- eapply eval_iota_sing; eauto.
743- eapply eval_box; eauto.
744- rewrite -is_propositional_trans //.
745- reflexivity.
671+ - now rewrite H in wpc.
746672
747673 - apply trust_cofix.
674+ (*rewrite trans_mkApps /= in e1.
675+ cbn; eapply eval_fix => //; tea.
676+ len. apply trust_cofix*)
677+
678+
748679 - apply trust_cofix.
749680 - apply trust_cofix.
750681 - apply trust_cofix.
@@ -910,13 +841,22 @@ Proof.
910841 destruct lookup_inductive_kind as [[]|] => /= //.
911842 2-3:constructor; eauto; solve_all.
912843 constructor; eauto; solve_all. cbn.
913- unfold Thunk.force.
914- eapply isEtaExp_expanded.
915- all:apply trust_cofix.
916- - apply trust_cofix.
917- - apply trust_cofix.
918- - apply trust_cofix.
919- - apply trust_cofix.
844+ now constructor.
845+ constructor; eauto; solve_all.
846+ - cbn -[GlobalContextMap.lookup_inductive_kind].
847+ rewrite GlobalContextMap.lookup_inductive_kind_spec.
848+ destruct lookup_inductive_kind as [[]|] => /= //.
849+ 2-3:constructor; eauto; solve_all.
850+ constructor; eauto; solve_all. cbn.
851+ now constructor.
852+ constructor; eauto; solve_all.
853+ - cbn. econstructor; eauto. solve_all. now eapply isLambda_trans.
854+ - cbn. econstructor; eauto; solve_all. apply trust_cofix.
855+ - cbn -[GlobalContextMap.lookup_inductive_kind].
856+ rewrite GlobalContextMap.lookup_inductive_kind_spec.
857+ destruct lookup_inductive_kind as [[]|] => /= //.
858+ 1,3,4:eapply expanded_tConstruct_app; eauto; solve_all.
859+ apply trust_cofix. (* Needs constructor_as_blocks = true invariant *)
920860Qed .
921861 (*cbn.
922862 eapply isEtaExp_substl. eapply forallb_repeat => //.
0 commit comments