diff --git a/theories/typing/sum.v b/theories/typing/sum.v index 5ef44d371e164eb3ffe28dcb59eda9b05c5408ca..f2a92fd62d149d3179b2b8be38d5310e68006bae 100644 --- a/theories/typing/sum.v +++ b/theories/typing/sum.v @@ -30,15 +30,13 @@ Section sum. Global Instance emp_sync : Sync ∅. Proof. iIntros (????) "[]". Qed. - Definition list_max (l : list nat) := foldr max 0%nat l. - Definition is_pad i tyl (vl : list val) : iProp Σ := - ⌜((nth i tyl ∅).(ty_size) + length vl)%nat = (list_max $ map ty_size tyl)âŒ%I. + ⌜((nth i tyl ∅).(ty_size) + length vl)%nat = (max_list_with ty_size tyl)âŒ%I. Lemma split_sum_mt l tid q tyl : (l ↦∗{q}: λ vl, ∃ (i : nat) vl' vl'', ⌜vl = #i :: vl' ++ vl''⌠∗ - ⌜length vl = S (list_max $ map ty_size tyl)⌠∗ + ⌜length vl = S (max_list_with ty_size tyl)⌠∗ ty_own (nth i tyl ∅) tid vl')%I ⊣⊢ ∃ (i : nat), (l ↦{q} #i ∗ shift_loc l (S $ (nth i tyl ∅).(ty_size)) ↦∗{q}: is_pad i tyl) ∗ @@ -62,10 +60,10 @@ Section sum. Qed. Program Definition sum (tyl : list type) := - {| ty_size := S (list_max $ map ty_size tyl); + {| ty_size := S (max_list_with ty_size tyl); ty_own tid vl := (∃ (i : nat) vl' vl'', ⌜vl = #i :: vl' ++ vl''⌠∗ - ⌜length vl = S (list_max $ map ty_size tyl)⌠∗ + ⌜length vl = S (max_list_with ty_size tyl)⌠∗ (nth i tyl ∅).(ty_own) tid vl')%I; ty_shr κ tid l := (∃ (i : nat), @@ -96,7 +94,7 @@ Section sum. Global Instance sum_type_ne n : Proper (Forall2 (type_dist2 n) ==> type_dist2 n) sum. Proof. intros x y EQ. - assert (EQmax : list_max (map ty_size x) = list_max (map ty_size y)). + assert (EQmax : max_list_with ty_size x = max_list_with ty_size y). { induction EQ as [|???? EQ _ IH]=>//=. rewrite IH. f_equiv. apply EQ. } (* TODO: If we had the right lemma relating nth, (Forall2 R) and R, we should @@ -114,7 +112,7 @@ Section sum. Global Instance sum_ne : NonExpansive sum. Proof. intros n x y EQ. - assert (EQmax : list_max (map ty_size x) = list_max (map ty_size y)). + assert (EQmax : max_list_with ty_size x = max_list_with ty_size y). { induction EQ as [|???? EQ _ IH]=>//=. rewrite IH. f_equiv. apply EQ. } (* TODO: If we had the right lemma relating nth, (Forall2 R) and R, we should @@ -133,7 +131,7 @@ Section sum. Proper (Forall2 (subtype E L) ==> subtype E L) sum. Proof. iIntros (tyl1 tyl2 Htyl) "#? %". - iAssert (⌜list_max (map ty_size tyl1) = list_max (map ty_size tyl2)âŒ%I) with "[#]" as %Hleq. + iAssert (⌜max_list_with ty_size tyl1 = max_list_with ty_size tyl2âŒ%I) with "[#]" as %Hleq. { iInduction Htyl as [|???? Hsub] "IH"; first done. iDestruct (Hsub with "[] []") as "(% & _ & _)"; [done..|]. iDestruct "IH" as %IH. iPureIntro. simpl. inversion_clear IH. by f_equal. } @@ -206,7 +204,7 @@ Section sum. apply shr_locsE_subseteq. omega. } iDestruct (na_own_acc with "Htl") as "[$ Htlclose]". { apply difference_mono_l. - trans (shr_locsE (shift_loc l 1) (list_max (map ty_size tyl))). + trans (shr_locsE (shift_loc l 1) (max_list_with ty_size tyl)). - apply shr_locsE_subseteq. omega. - set_solver+. } destruct (Qp_lower_bound q'1 q'2) as (q' & q'01 & q'02 & -> & ->). diff --git a/theories/typing/type_sum.v b/theories/typing/type_sum.v index 539b0f3775433c4d6b94edfa7c1a2fd69593c9ea..14ea186cc53c61a16041277cc7bccc2b9efdb93d 100644 --- a/theories/typing/type_sum.v +++ b/theories/typing/type_sum.v @@ -12,7 +12,7 @@ Section case. Forall2 (λ ty e, typed_body E L C ((p +â‚— #0 â— own_ptr n (uninit 1)) :: (p +â‚— #1 â— own_ptr n ty) :: (p +â‚— #(S (ty.(ty_size))) â— - own_ptr n (uninit (list_max (map ty_size tyl) - ty_size ty))) :: T) e ∨ + own_ptr n (uninit (max_list_with ty_size tyl - ty_size ty))) :: T) e ∨ typed_body E L C ((p â— own_ptr n (sum tyl)) :: T) e) tyl el → typed_body E L C ((p â— own_ptr n (sum tyl)) :: T) (case: !p of el). Proof. @@ -49,7 +49,7 @@ Section case. Forall2 (λ ty e, typed_body E L C ((p +â‚— #0 â— own_ptr n (uninit 1)) :: (p +â‚— #1 â— own_ptr n ty) :: (p +â‚— #(S (ty.(ty_size))) â— - own_ptr n (uninit (list_max (map ty_size tyl) - ty_size ty))) :: T') e ∨ + own_ptr n (uninit (max_list_with ty_size tyl - ty_size ty))) :: T') e ∨ typed_body E L C ((p â— own_ptr n (sum tyl)) :: T') e) tyl el → typed_body E L C T (case: !p of el). Proof. unfold tctx_extract_hasty=>->. apply type_case_own'. Qed.