@@ -117,7 +117,9 @@ Definition precise_rel {A:Set}{AR:ImmediateReachability A} (R:hrel A) :=
117
117
is essentially a no-op. The guarantee, however, still needs to be
118
118
projected and intersected component-wise in any structure. *)
119
119
Class rel_fold (A:Set ) :=
120
- { rgfold : forall (R G:hrel A), Set }.
120
+ { rgfold : forall (R G:hrel A), Set ;
121
+ fold : forall {R G}, A -> rgfold R G
122
+ }.
121
123
(** In meta-proofs, of things like satisfying a guarantee, we use this
122
124
identity fold instead of the appropriate developer instance so
123
125
G and P don't have to have polymorphic arities and relation arguments
@@ -126,7 +128,9 @@ Class rel_fold (A:Set) :=
126
128
*)
127
129
Section HideMetaFold.
128
130
Local Instance meta_fold {A:Set } : rel_fold A :=
129
- { rgfold := fun R G => A }.
131
+ { rgfold := fun R G => A ;
132
+ fold := fun _ _ x => x
133
+ }.
130
134
End HideMetaFold.
131
135
Notation "{{{ e }}}" := (let mfold : forall A, rel_fold A := @meta_fold in e) (at level 50).
132
136
@@ -153,6 +157,16 @@ Axiom deref : forall {A:Set}{B:Set}`{rel_fold A}{P:hpred A}{R G:hrel A}, hreflex
153
157
(*Axiom deref : forall {A:Set}{P:hpred A}{R G:hrel A}, ref A P R G -> A. *)
154
158
Notation "! e" := (deref _ _ e) (at level 30). (* with reflexivity, add an _ in there *)
155
159
160
+ (* This axiom asserts that all folds that produce the same result type operate equally on
161
+ the underlying values. This is fragile if a developer specifies multiple instances for
162
+ folding the same type. This is a weaker version of a more general axiom that
163
+ the relationship between the results of folds of different result types depends on the
164
+ relationship between results of the fold members of the instances when applied to the
165
+ same value. This version is really only useful for equating identity folds with
166
+ the identity meta_fold instance results. *)
167
+ Axiom deref_conversion : forall (A B:Set)(f f':rel_fold A) P R G rf1 rf2 fe1 fe2,
168
+ @deref A B f P R G rf1 fe1 = @deref A B f' P R G rf2 fe2.
169
+
156
170
Axiom ptr_eq_deref : forall A P P' R R' G G' h (p:ref{A|P}[R,G]) (r:ref{A|P'}[G',R']), p≡r -> h[p]=h[r].
157
171
Hint Resolve ptr_eq_deref.
158
172
Axiom ptr_eq_update : forall A P P' R R' G G' (p:ref{A|P}[R,G]) (r:ref{A|P'}[G',R']),
@@ -215,16 +229,24 @@ Global Instance ref_contains {A:Set}{P:hpred A}{R G:hrel A} : Containment (ref{A
215
229
216
230
(** ** Relation Folding *)
217
231
Definition const_rel_fold (A:Set) (R G:hrel A) : Set := A.
218
- Global Instance nat_fold : rel_fold nat := {rgfold := const_rel_fold nat}.
219
- Global Instance bool_fold : rel_fold bool := {rgfold := const_rel_fold bool}.
220
- Global Instance unit_fold : rel_fold unit := {rgfold := const_rel_fold unit}.
232
+ Definition const_id_fold {A:Set}(R G:hrel A)(x:A) := x.
233
+ Global Instance nat_fold : rel_fold nat := {rgfold := const_rel_fold nat; fold := const_id_fold}.
234
+ Global Instance bool_fold : rel_fold bool := {rgfold := const_rel_fold bool; fold := const_id_fold}.
235
+ Global Instance unit_fold : rel_fold unit := {rgfold := const_rel_fold unit; fold := const_id_fold}.
221
236
Global Instance pair_fold `{A:Set,B:Set,FA:rel_fold A,FB:rel_fold B}: rel_fold (A*B) :=
222
237
{ rgfold := fun R G =>
223
238
prod (rgfold (fun _ _ _ _ => True) (fun a a' h h' => forall b, G (a,b) (a',b) h h'))
224
- (rgfold (fun _ _ _ _ => True) (fun b b' h h' => forall a, G (a,b) (a,b') h h')) }.
239
+ (rgfold (fun _ _ _ _ => True) (fun b b' h h' => forall a, G (a,b) (a,b') h h')) ;
240
+ fold := fun R G xy => match xy with (x,y) => (fold x, fold y) end
241
+ }.
225
242
Global Instance ref_fold `{A:Set,P:hpred A,R:hrel A,G:hrel A} : rel_fold (ref{A|P}[R,G]) :=
226
243
{ rgfold := fun R' G' => ref{A|P}[R,G ⋂ (fun a a' h h' =>
227
- forall (r:ref{A|P}[R,G]), h[r]=a -> h'[r]=a' -> G' r r h h')] }.
244
+ forall (r:ref{A|P}[R,G]), h[r]=a -> h'[r]=a' -> G' r r h h')]
245
+ }.
246
+ (* We'll admit the runtime fold for references; the semantics for proofs will need an extensional treatment
247
+ as an axiom. *)
248
+ Admitted .
249
+
228
250
(** TODO: polymorphic lists *)
229
251
230
252
(** ** Reachability, containment, and folding for pure types *)
@@ -237,7 +259,7 @@ Global Instance pure_reachable `{A:Set,PA:pure_type A} : ImmediateReachability A
237
259
Global Instance pure_contains `{A:Set,PA:pure_type A} : Containment A :=
238
260
{ contains := fun _ => True }.
239
261
Global Instance pure_fold `{A:Set,PA:pure_type A} : rel_fold A :=
240
- { rgfold := fun _ _ => A }.
262
+ { rgfold := fun _ _ => A ; fold := const_id_fold }.
241
263
Global Instance nat_pure : pure_type nat.
242
264
Global Instance bool_pure : pure_type bool.
243
265
Global Instance unit_pure : pure_type unit.
@@ -247,4 +269,24 @@ Global Instance list_pure `{A:Set,PA:pure_type A} : pure_type (list A).
247
269
Things like heap dereference being the same between converted and unconverted references, etc. *)
248
270
(** For now we need an explicit subtyping operator *)
249
271
Axiom convert_P : forall {A:Set}{P P':hpred A}{R G}`{ImmediateReachability A},(forall v h, P v h -> P' v h) -> precise_pred P' -> stable P' R -> ref{A|P}[R,G] -> ref{A|P'}[R,G].
250
- Axiom conversion_P_refeq : forall h A (P P':hpred A) (R G:hrel A)`{ImmediateReachability A} pf1 pf2 pf3 x, h[(@convert_P A P P' R G _ pf1 pf2 pf3 x)]=h[x].
272
+ Axiom conversion_P_refeq : forall h A (P P':hpred A) (R G:hrel A)`{ImmediateReachability A} pf1 pf2 pf3 x, h[(@convert_P A P P' R G _ pf1 pf2 pf3 x)]=h[x].
273
+ Axiom convert : forall {A:Set}{P P':hpred A}{R R' G G':hrel A}`{ImmediateReachability A},
274
+ ref{A|P}[R,G] ->
275
+ (forall v h, P v h -> P' v h) ->
276
+ (G' ⊆ G) -> (R ⊆ R') -> stable P' R' ->
277
+ (G' ⊆ R') -> (* <-- self-splitting, this is a pure conversion *)
278
+ ref{A|P'}[R',G'].
279
+ Axiom convert_equiv : forall {A}{P P':hpred A}{R R' G G':hrel A}`{ImmediateReachability A}
280
+ (r:ref{A|P}[R,G]) pfP pfG pfR stab splt,
281
+ forall h, h[r]=h[@convert A P P' R R' G G' _ r pfP pfG pfR stab splt].
282
+
283
+ Axiom refine_ref : forall {A:Set }{P P' R G}{fld : rel_fold A}{rfl : hreflexive G}
284
+ (r : ref{A|P}[R,G])
285
+ (x : rgfold R G),
286
+ stable P' R ->
287
+ ((@deref _ _ fld _ _ _ rfl (eq_refl) r) = x) -> (* <-- This is only available in special match statements, and flow is restricted! *)
288
+ (forall h, (fold (h[r]))=(deref rfl (eq_refl) r) -> (deref rfl eq_refl r) = x -> P (h[r]) h -> P' (h[r]) h) ->
289
+ ref{A|P'}[R,G].
290
+ Axiom refinement_equiv : forall {A P P' R G}{fld : rel_fold A}{rfl : hreflexive G}
291
+ (r:ref{A|P}[R,G]) x stab pf refpf,
292
+ forall h, h[r] = h[@refine_ref A P P' R G fld rfl r x stab pf refpf].
0 commit comments