Skip to content

Commit 2d54aa8

Browse files
committed
Fields actually working with a general tie b/t field reads and getf
1 parent 02784cf commit 2d54aa8

File tree

1 file changed

+19
-34
lines changed

1 file changed

+19
-34
lines changed

RGref/DSL/Fields.v

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,17 @@ Axiom field_read : forall {T B F Res:Set}{P R G}`{rel_fold T}
1919
(r:ref{T|P}[R,G]) (f:F)
2020
`{FieldType B F f Res},
2121
Res.
22-
Axiom field_write : forall {Γ}{T F Res:Set}{P R G}
22+
Check @getF. Check @fold. Check @setF.
23+
Axiom field_write : forall {Γ}{T F Res:Set}{P R G}{folder:rel_fold T}
2324
(r:ref{T|P}[R,G]) (f:F) (e : Res)
24-
`{FieldType T F f Res}
25-
`{forall h v, P v h -> G v (setF v e) h (heap_write r (setF v e) h)},
25+
`{FieldTyping T F}
26+
{ft:FieldType T F f Res}
27+
`{forall h v,
28+
P v h ->
29+
(forall Post ft' fte' (pf1:rgfold R G = Post) pf2 x y,
30+
@field_read T Post F Res P R G folder pf1 pf2 r f x y =
31+
@getF (@rgfold T folder R G) F ft' f Res fte' (@fold T folder R G v)) ->
32+
G v (@setF T F _ f Res ft v e) h (heap_write r (@setF T F _ f Res ft v e) h)},
2633
rgref Γ unit Γ.
2734

2835
Section FieldDemo.
@@ -35,6 +42,7 @@ Section FieldDemo.
3542
Lemma refl_deltaD : hreflexive deltaD. Proof. red. intros. destruct x. apply incCount. eauto with arith. Qed.
3643
Hint Resolve refl_deltaD.
3744

45+
(* I feel like this is reinventing lenses... *)
3846
Inductive Dfield : Set := Count | Flag.
3947
Instance dfields : FieldTyping D Dfield.
4048
Instance dfield_count : FieldType D Dfield Count nat := {
@@ -46,41 +54,18 @@ Section FieldDemo.
4654
setF := fun v fv => match v with (mkD n b) => (mkD n fv) end
4755
}.
4856

49-
Definition getCount (d:D) := match d with (mkD n b) => n end.
50-
Definition getFlag (d:D) := match d with (mkD n b) => b end.
51-
52-
(* Print DAccess. (* <-- that is a terrible term due to dependent induction *) *)
5357
Instance pureD : pure_type D.
5458
Program Example demo {Γ} (r : ref{D|any}[deltaD,deltaD]) : rgref Γ unit Γ :=
55-
@field_write Γ D Dfield nat _ _ _ r Count ((@field_read _ D Dfield _ _ _ _ _ _ _ r Count _ _)+1) _ _ _.
56-
(* @field_write Γ D _ _ _ _ _ DAccess r Count (nat2DField ((Count2nat (@field_read _ _ _ _ _ _ _ _ _ _ _ DAccess r (DField2Fin Count) _)) + 1)) _.
59+
@field_write Γ D Dfield nat _ _ _ _ r Count ((@field_read _ D Dfield _ _ _ _ _ _ _ r Count _ _)+1) _ _ _.
5760
Next Obligation.
58-
cut (forall f p1 p2 p3, @eq (DFieldTypes f) (@field_read D D _ _ _ _ _ DFieldTypes _ p1 p2 DAccess r f p3) (@fieldOf D _ DFieldTypes DAccess (@fold D _ deltaD deltaD v) f)).
59-
intro Hcomp. rewrite Hcomp with (f := F1).
60-
destruct v. compute [nat2DField Count2nat].
61-
compute [fieldOf]. unfold DAccess. unfold DAccess_obligation_1. unfold fold.
62-
unfold pure_fold. unfold getCount. unfold getFlag. unfold const_id_fold.
63-
compute [t_rec t_rect]. (* Now pretty sure I screwed up the def of fieldUpdate *)
64-
Check DAccess_obligation_3.
65-
compute [DAccess_obligation_3].
66-
compute -[fieldUpdate].
67-
compute [fieldOf DFieldTypes DAccess DAccess_obligation_1 fold DAccess_obligation_3]. rewrite plus_comm.
68-
(* At this point we *should* be done, but the use of dependent induction to work around
69-
Coq's pattern matching has introduced some uses of JMeq to deal with *)
70-
generalize (@JMeq_eq (t (S (S O))) (@F1 (S O)) (@F1 (S O)) (@JMeq_refl (t (S (S O))) (@F1 (S O)))).
71-
intro e. elim e.*)
72-
73-
Next Obligation. unfold demo_obligation_1. unfold demo_obligation_2.
74-
Check @getF.
75-
cut (forall P R G pf1 pf2 r f fs fi,
76-
@field_read D D Dfield nat P R G (@pure_fold D pureD) pf1 pf2 r f fs fi =
77-
@getF D Dfield _ f nat _ v).
78-
intros Hfieldstuff.
61+
unfold demo_obligation_1. unfold demo_obligation_2.
62+
(* Check @getF.
63+
cut (forall T B (v:B) F Res P R G folder pf1 pf2 r f fs fi ft ftb,
64+
@field_read T B F Res P R G folder pf1 pf2 r f fs fi =
65+
@getF B F ft f Res ftb v).
66+
intros Hfieldstuff.*)
7967
destruct v.
80-
rewrite Hfieldstuff.
68+
(* rewrite Hfieldstuff.*) erewrite H0.
8169
compute. fold plus. constructor. eauto with arith.
82-
(* this should be abstracted to a general hypothesis supplied by
83-
the write framework. *)
84-
admit.
8570
Qed.
8671
End FieldDemo.

0 commit comments

Comments
 (0)