Require Export VST.msl.iter_sepcon.
Require Export VST.concurrency.semax_conc_pred.
Require Export VST.concurrency.semax_conc.
Require Export VST.floyd.proofauto.
Require Export VST.floyd.sublist.
(* general list lemmas *)
Notation vint z := (Vint (Int.repr z)).
Notation vptrofs z := (Vptrofs (Ptrofs.repr z)).
Hint Resolve repable_0.
Definition complete MAX l := l ++ repeat (vptrofs 0) (Z.to_nat MAX - length l).
Definition remove_at {A} i (l : list A) := firstn i l ++ skipn (S i) l.
Open Scope logic.
Definition rotate {A} (l : list A) n m := sublist (m - n) (Zlength l) l ++
sublist 0 (m - n) l.
(* Lemma Znth_indep : forall {A} i (l : list A) d d', 0 <= i < Zlength l -> Znth i l d = Znth i l d'. *)
Fixpoint upto n :=
match n with
| O => []
| S n' => 0 :: map Z.succ (upto n')
end.
Opaque Z.of_nat.
(* Lemma Znth_map' : forall {A B} i (f : A -> B) al b, Znth i (map f al) (f b) = f (Znth i al b). *)
Transparent Z.of_nat.
Hint Resolve incl_nil.
Definition nil_dec {A} (l : list A) : {l = []} + {l <> []}.
Arguments eq_dec _ _ _ _ : simpl never.
Fixpoint extend {A} (l : list A) ls :=
match l, ls with
| x :: xs, y :: ys => (x :: y) :: extend xs ys
| _, _ => ls
end.
Fixpoint extendr {A} (l : list A) ls :=
match l, ls with
| x :: xs, y :: ys => (y ++ [x]) :: extendr xs ys
| _, _ => ls
end.
(* We could also consider an alpha-renaming axiom, although this may be unnecessary. *)
Hint Resolve lock_inv_isptr cond_var_isptr : saturate_local.
Hint Resolve unreadable_bot.
Definition join_Bot := join_Bot.
(* It's often useful to split Tsh in half. *)
Definition gsh1 := fst (slice.cleave Tsh).
Definition gsh2 := snd (slice.cleave Tsh).
Hint Resolve readable_gsh1 readable_gsh2 gsh1_gsh2_join.
Hint Resolve gsh1_not_bot gsh2_not_bot.
(* Lemma data_at_Tsh_conflict : forall {cs : compspecs} sh t v v' p, sepalg.nonidentity sh -> 0 < sizeof t -> data_at Tsh t v p * data_at sh t v' p |-- FF. *)
Definition remove_Znth {A} i (al : list A) := sublist 0 i al ++ sublist (i + 1) (Zlength al) al.
Instance Inhabitant_share : Inhabitant share := Share.bot. (* TODO: remove this, it's already in sublist.v *)
Instance Inhabitant_mpred : Inhabitant mpred := @FF mpred Nveric. (* TODO: remove this, it's already in sublist.v *)
Hint Resolve valid_pointer_isptr : saturate_local.
Definition super_non_expansive' {A} P := forall n ts x, compcert_rmaps.RML.R.approx n (P ts x) =
compcert_rmaps.RML.R.approx n (P ts (functors.MixVariantFunctor.fmap (rmaps.dependent_type_functor_rec ts A)
(compcert_rmaps.RML.R.approx n) (compcert_rmaps.RML.R.approx n) x)).
(* Lemma malloc_compat : forall {cs : compspecs} sh t p, complete_legal_cosu_type t = true -> natural_aligned natural_alignment t = true -> malloc_token sh (sizeof t) p = !!field_compatible t [] p && malloc_token sh (sizeof t) p. *)
Ltac lock_props := rewrite ?sepcon_assoc; rewrite <- sepcon_emp at 1; rewrite sepcon_comm; apply sepcon_derives;
[repeat apply andp_right; auto; eapply derives_trans;
try (apply exclusive_weak_exclusive || (apply rec_inv_weak_rec_inv; try apply selflock_rec)); auto |
try timeout 20 cancel].
Ltac join_sub := repeat (eapply sepalg.join_sub_trans;
[eexists; first [eassumption | simple eapply sepalg.join_comm; eassumption]|]); eassumption.
Ltac join_inj := repeat match goal with H1 : sepalg.join ?a ?b ?c, H2 : sepalg.join ?a ?b ?d |- _ =>
pose proof (sepalg.join_eq H1 H2); clear H1 H2; subst; auto end.
Ltac fast_cancel := rewrite ?sepcon_emp, ?emp_sepcon; rewrite ?sepcon_assoc;
repeat match goal with
| |- ?P |-- ?P => apply derives_refl
| |- ?P * _ |-- ?P * _ => apply sepcon_derives; [apply derives_refl|]
| |- _ |-- ?P * _ => rewrite <- !sepcon_assoc, (sepcon_comm _ P), !sepcon_assoc end;
try cancel_frame.
(*Ltac forward_malloc t n := forward_call (sizeof t); [simpl; try computable | Intros n; rewrite malloc_compat by (auto; reflexivity); Intros; rewrite memory_block_data_at_ by auto]. *)

Lemma semax_fun_id'' id f gv Espec {cs} Delta P Q R Post c :
(var_types Delta) ! id = None ->
(glob_specs Delta) ! id = Some f ->
(glob_types Delta) ! id = Some (type_of_funspec f) ->
snd (local2ptree Q) = Some gv ->
@semax cs Espec Delta
(PROPx P
(LOCALx Q
(SEPx ((func_ptr' f (gv id)) :: R)))) c Post ->
@semax cs Espec Delta (PROPx P (LOCALx Q (SEPx R))) c Post.