@@ -1197,7 +1197,25 @@ Proof.
11971197 now eapply lookup_insert.
11981198Qed .
11991199
1200- Lemma update_version_region_insert
1200+ Lemma update_version_region_insert (glmem llmem : LMem) (a : Addr) (la : list Addr) (v v' : Version) (lw : LWord) :
1201+ a ∉ la ->
1202+ (<[(a, v):= lw]> (update_version_region glmem la v' llmem)) =
1203+ (update_version_region (<[(a, v):= lw]> glmem) la v' (<[(a, v):= lw]> llmem)).
1204+ Proof .
1205+ revert a v v' lw glmem llmem.
1206+ induction la; intros a' v v' lw glmem llmem Ha'; first set_solver.
1207+ cbn.
1208+ rewrite -/(update_version_region glmem la v' llmem).
1209+ rewrite -/(update_version_region (<[(a', v):=lw]> glmem) la v' (<[(a', v):=lw]> llmem)).
1210+ rewrite /update_version_addr.
1211+ rewrite lookup_insert_ne; last (intro; simplify_eq; set_solver).
1212+ destruct ( glmem !! (a, v') ) eqn:Ha_glmem; rewrite Ha_glmem.
1213+ - rewrite insert_commute; last (intro; simplify_eq; set_solver).
1214+ rewrite IHla; set_solver.
1215+ - rewrite IHla; set_solver.
1216+ Qed .
1217+
1218+ Lemma update_version_region_insert_subseteq
12011219 (glmem lmem lmem' : LMem) (la : list Addr) (a' : Addr) (v v' : Version) (lw : LWord):
12021220 NoDup la ->
12031221 a' ∉ la ->
@@ -1775,7 +1793,7 @@ Proof.
17751793 + split; cbn in *; try done.
17761794 eapply insert_subseteq_r_inv; eauto.
17771795 - destruct Hvalid as (Hupd & Hgl_llmem & HmaxMap' & HnextMap).
1778- split; first (eapply update_version_region_insert ; eauto).
1796+ split; first (eapply update_version_region_insert_subseteq ; eauto).
17791797 split; auto.
17801798 eapply insert_subseteq_r_inv; eauto.
17811799Qed .
@@ -2197,6 +2215,76 @@ Proof.
21972215 eapply lmeasure_measure_aux; eauto.
21982216Qed .
21992217
2218+ Definition lmeasure `{MP : MachineParameters} (m : LMem) (b e: Addr) v : option Z :=
2219+ hash_instr ← hash_lmemory_range m (b^+1)%a e v;
2220+ Some (hash_concat (hash b) hash_instr).
2221+
2222+ Lemma lmeasure_weaken_aux (lmem lmt: LMem) (la : list Addr) (v : Version) :
2223+ lmem ⊆ lmt →
2224+ Forall (fun a => is_Some (lmem !! (a, v))) la →
2225+ lmemory_get_instrs lmem la v = lmemory_get_instrs lmt la v.
2226+ Proof .
2227+ intros Hincl Hall.
2228+ induction la ; first done.
2229+ rewrite Forall_cons in Hall. destruct Hall as [ [w Ha] Hall].
2230+ apply IHla in Hall.
2231+ assert (lmt !! (a, v) = Some w) as Ha' by (eapply lookup_weaken in Ha ; eauto).
2232+ cbn.
2233+ rewrite -/(lmemory_get_instrs lmem la v) -/(lmemory_get_instrs lmt la v).
2234+ by rewrite Ha Ha' Hall.
2235+ Qed .
2236+
2237+ Lemma lmeasure_weaken `{MP : MachineParameters} {lmem lmt} {b e v} :
2238+ lmem ⊆ lmt →
2239+ Forall (fun a => is_Some (lmem !! (a, v))) (finz.seq_between b e) →
2240+ hash_lmemory_range lmem b e v = hash_lmemory_range lmt b e v.
2241+ Proof .
2242+ intros Hincl Hall.
2243+ rewrite /hash_lmemory_range.
2244+ erewrite lmeasure_weaken_aux; eauto.
2245+ Qed .
2246+
2247+ Definition ensures_is_zL (lmem : LMem) (b e : Addr) (v : Version) : Prop :=
2248+ map_Forall (fun la lw => (laddr_get_addr la) ∈ (finz.seq_between b e) ∧ (laddr_get_version la) = v
2249+ -> is_zL lw) lmem.
2250+
2251+ Lemma ensures_is_z_corresponds {phr phm lr lm vmap} {p} {b e a} {v} :
2252+ state_phys_log_corresponds phr phm lr lm vmap →
2253+ is_cur_word (LCap p b e a v) vmap ->
2254+ ensures_is_z phm b e →
2255+ ensures_is_zL lm b e v.
2256+ Proof .
2257+ intros Hcorr Hr Hensure_z.
2258+ rewrite /ensures_is_zL.
2259+ rewrite /ensures_is_z in Hensure_z.
2260+ apply bool_decide_unpack in Hensure_z.
2261+ destruct Hcorr as [ Hreg (? & ? & ?) ].
2262+ rewrite /is_cur_word in Hr.
2263+ rewrite /mem_vmap_root in H0.
2264+ rewrite /mem_current_version in H.
2265+ rewrite map_Forall_lookup in H.
2266+ rewrite map_Forall_lookup.
2267+ intros [a' v'] lw Hla [Hla_in ?]; cbn in *; simplify_eq.
2268+ specialize (Hr a' Hla_in).
2269+ rewrite map_Forall_lookup in H0; eauto.
2270+ eapply H0 in Hr.
2271+ destruct Hr as (?&?&?&?); cbn in *.
2272+ rewrite map_Forall_lookup in Hensure_z; eauto.
2273+ rewrite H2 in Hla; simplify_eq.
2274+ apply Hensure_z in H3; eauto.
2275+ destruct lw ; eauto.
2276+ Qed .
2277+
2278+ Lemma ensures_is_z_mono {lm lm'} {b e} {v} :
2279+ lm ⊆ lm' → ensures_is_zL lm' b e v -> ensures_is_zL lm b e v.
2280+ Proof .
2281+ intros Hsub Hensure_is_zL.
2282+ rewrite /ensures_is_zL in Hensure_is_zL |- *.
2283+ rewrite map_Forall_lookup.
2284+ intros [a v'] lw Hla [Hin ?] ; cbn in *; simplify_eq.
2285+ eapply lookup_weaken in Hla; eauto.
2286+ Qed .
2287+
22002288End Logical_mapsto.
22012289
22022290Section lmachine_param.
@@ -2287,10 +2375,8 @@ Qed.
22872375
22882376(** Miscellaneous about logical regions *)
22892377(* TODO move definition to regions.v ? *)
2290-
22912378Lemma elem_of_logical_region (a : Addr) (la : list Addr) (v : Version) :
2292- a ∈ la <->
2293- (a, v) ∈ logical_region la v.
2379+ a ∈ la <-> (a, v) ∈ logical_region la v.
22942380Proof .
22952381 split; rewrite /logical_region; intros Ha.
22962382 - by apply elem_of_list_fmap; exists a.
@@ -2860,3 +2946,43 @@ Proof.
28602946 cbn. intros Hreg Hcurregs.
28612947 apply (map_Forall_lookup_1 _ _ _ _ Hcurregs Hreg).
28622948Qed .
2949+
2950+ (* TODO generalise *)
2951+ Lemma map_Forall_all_P (w : LWord) (la : list Addr) (lws : list LWord) (v : Version)
2952+ (P : LWord -> Prop ) :
2953+ NoDup la ->
2954+ length lws = length la ->
2955+ w ∈ lws ->
2956+ map_Forall
2957+ (λ (a : LAddr) (lw : LWord), laddr_get_addr a ∈ la ∧ (laddr_get_version a) = v → P lw)
2958+ (logical_region_map la lws v)
2959+ -> P w.
2960+ Proof .
2961+ generalize dependent lws.
2962+ generalize dependent w.
2963+ induction la as [|a la]; intros w lws Hnodup Hlen Hw Hall_z.
2964+ - destruct lws ; set_solver.
2965+ - destruct lws as [|w1 lws] ; first set_solver.
2966+ cbn in Hlen ; simplify_eq.
2967+ apply NoDup_cons in Hnodup as [Ha_notin_l Hnodup].
2968+ cbn in Hall_z.
2969+ apply map_Forall_insert in Hall_z as [Hladdr Hall_z].
2970+ 2: { rewrite -not_elem_of_list_to_map.
2971+ intro Hcontra.
2972+ rewrite elem_of_list_fmap in Hcontra.
2973+ destruct Hcontra as ([x vx] & Hx & Hcontra)
2974+ ; cbn in Hx ; simplify_eq.
2975+ apply elem_of_zip_l in Hcontra.
2976+ rewrite elem_of_list_fmap in Hcontra.
2977+ destruct Hcontra as (y & Hy & Hcontra)
2978+ ; cbn in Hy ; simplify_eq.
2979+ set_solver.
2980+ }
2981+ apply elem_of_cons in Hw as [-> | Hw].
2982+ * apply Hladdr; set_solver.
2983+ * eapply IHla; eauto.
2984+ eapply map_Forall_impl; eauto.
2985+ intros [y vy] wy IH Hy; cbn in *.
2986+ apply IH.
2987+ set_solver.
2988+ Qed .
0 commit comments