val weaken_repr:
    a: _ ->
    framed: _ ->
    pre: pre_t ->
    post: post_t a ->
    req: req_t pre ->
    req': req_t pre ->
    ens: ens_t pre a post ->
    ens': ens_t pre a post ->
    f: Steel.Effect.repr a framed pre post req ens ->
    squash (forall (h0: hmem pre). req' (mk_rmem _ h0) ==> req (mk_rmem _ h0)) ->
    squash (forall (h0: hmem pre) x (h1: hmem (post x)).
            ens (mk_rmem _ h0) x (mk_rmem _ h1) ==> ens' (mk_rmem _ h0) x (mk_rmem _ h1))
  -> Tot (Steel.Effect.repr a framed pre post req' ens')
let weaken_repr a framed
                (pre:pre_t)
                (post:post_t a)
                (req req':req_t pre)
                (ens ens':ens_t pre a post)
                (f:Steel.Effect.repr a framed pre post req ens)
                (_:squash (forall (h0:hmem pre).
                            req' (mk_rmem _ h0) ==>
                            req (mk_rmem _ h0)))
                (_:squash (forall (h0:hmem pre) x (h1:hmem (post x)).
                            ens (mk_rmem _ h0)
                                x
                                (mk_rmem _ h1) ==>
                            ens' (mk_rmem _ h0) x (mk_rmem _ h1)))
  : Tot (Steel.Effect.repr a framed pre post req' ens')
  = let focus_rmem_refl (r:vprop) (h:rmem r)
      : Lemma (ensures focus_rmem #r h r == h)
              [SMTPat (focus_rmem #r h r)]
      = focus_rmem_refl r h
    in
    let equiv_trans (x y z:vprop) : Lemma
      (requires equiv x y /\ equiv y z)
      (ensures equiv x z)
      [SMTPat (equiv x z);
       SMTPat (equiv x y)]
     = equiv_trans x y z
    in
    let cbs (p:vprop)
      : Lemma (p `can_be_split` (p `star` emp))
              [SMTPat (p `can_be_split` (p `star` emp))]
      = star_commutative p emp;
        cm_identity p;
        equiv_sym (p `star` emp) p;
        equiv_can_be_split p (p `star` emp)
    in
    let epost ()
      : Lemma (equiv_forall post (fun x -> star (post x) emp))
      = introduce forall x. post x `equiv` (post x `star` emp)
        with (
          equiv_star_emp_r (post x);
          equiv_sym (post x `star` emp) (post x)
        );
        equiv_forall_elim post (fun x -> star (post x) emp)
    in
    epost ();
    Steel.Effect.subcomp_opaque a #framed #framed
                         #pre #post
                         #req #ens
                         #pre #post
                         #req' #ens'
                         #emp
                         #True
                         #()
                         #()
                         #()
                         f
val weaken_repr:
    a: _ ->
    framed: _ ->
    pre: pre_t ->
    post: post_t a ->
    req: req_t pre ->
    req': req_t pre ->
    ens: ens_t pre a post ->
    ens': ens_t pre a post ->
    f: Steel.Effect.repr a framed pre post req ens ->
    squash (forall (h0: hmem pre). req' (mk_rmem _ h0) ==> req (mk_rmem _ h0)) ->
    squash (forall (h0: hmem pre) x (h1: hmem (post x)).
            ens (mk_rmem _ h0) x (mk_rmem _ h1) ==> ens' (mk_rmem _ h0) x (mk_rmem _ h1))
  -> Tot (Steel.Effect.repr a framed pre post req' ens')
let weaken_repr
      a
      framed
      (pre: pre_t)
      (post: post_t a)
      (req: req_t pre)
      (req': req_t pre)
      (ens: ens_t pre a post)
      (ens': ens_t pre a post)
      (f: Steel.Effect.repr a framed pre post req ens)
      (_: squash (forall (h0: hmem pre). req' (mk_rmem _ h0) ==> req (mk_rmem _ h0)))
      (_:
          squash (forall (h0: hmem pre) x (h1: hmem (post x)).
                ens (mk_rmem _ h0) x (mk_rmem _ h1) ==> ens' (mk_rmem _ h0) x (mk_rmem _ h1)))
    : Tot (Steel.Effect.repr a framed pre post req' ens') =
let focus_rmem_refl (r: vprop) (h: rmem r)
    : Lemma (ensures focus_rmem #r h r == h) [SMTPat (focus_rmem #r h r)] =
  focus_rmem_refl r h
in
let equiv_trans (x y z: vprop)
    : Lemma (requires equiv x y /\ equiv y z)
      (ensures equiv x z)
      [SMTPat (equiv x z); SMTPat (equiv x y)] =
  equiv_trans x y z
in
let cbs (p: vprop)
    : Lemma (p `can_be_split` (p `star` emp)) [SMTPat (p `can_be_split` (p `star` emp))] =
  star_commutative p emp;
  cm_identity p;
  equiv_sym (p `star` emp) p;
  equiv_can_be_split p (p `star` emp)
in
let epost () : Lemma (equiv_forall post (fun x -> star (post x) emp)) =
  introduce forall x . (post x) `equiv` ((post x) `star` emp)
  with (equiv_star_emp_r (post x);
    equiv_sym ((post x) `star` emp) (post x));
  equiv_forall_elim post (fun x -> star (post x) emp)
in
epost ();
Steel.Effect.subcomp_opaque a #framed #framed #pre #post #req #ens #pre #post #req' #ens' #emp #True
  #() #() #() f
Steel.ST.Effect.fst.checked
Steel.Memory.fsti.checked Steel.Effect.Common.fsti.checked Steel.Effect.fst.checked prims.fst.checked FStar.Tactics.fst.checked FStar.Pervasives.fsti.checked FStar.Monotonic.Pure.fst.checked FStar.Ghost.fsti.checked FStar.Classical.Sugar.fsti.checked
Steel.ST.Effect.fst
Prims.bool Steel.Effect.Common.pre_t Steel.Effect.Common.post_t Steel.Effect.Common.req_t Steel.Effect.Common.ens_t Steel.Effect.repr Prims.squash Prims.l_Forall Steel.Effect.Common.hmem Prims.l_imp Steel.Effect.Common.mk_rmem Steel.Effect.subcomp_opaque Steel.Effect.Common.emp Prims.l_True Prims.unit Steel.Effect.Common.equiv_forall Steel.Effect.Common.star Steel.Effect.Common.vprop Prims.Nil FStar.Pervasives.pattern Steel.Effect.Common.equiv_forall_elim FStar.Classical.Sugar.forall_intro Steel.Effect.Common.equiv Steel.Effect.Common.equiv_sym Steel.ST.Effect.equiv_star_emp_r Steel.Effect.Common.can_be_split Prims.Cons FStar.Pervasives.smt_pat Steel.Effect.Common.equiv_can_be_split Steel.Effect.Common.cm_identity Steel.Effect.Common.star_commutative Prims.l_and Prims.prop Steel.Effect.Common.equiv_trans Steel.Effect.Common.rmem' Steel.Effect.Common.valid_rmem Prims.eq2 Steel.Effect.Common.focus_rmem Steel.Effect.Common.rmem Steel.Effect.Common.focus_rmem_refl
(*
   Copyright 2020 Microsoft Research

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*)

module Steel.ST.Effect
friend Steel.Effect
open Steel.Memory
open FStar.Ghost
module Mem = Steel.Memory
module T = FStar.Tactics
include Steel.Effect.Common
open Steel.Effect
#set-options "--warn_error -330"  //turn off the experimental feature warning
#set-options "--ide_id_info_off"

let repr a framed pre post req ens : Type u#2 =
  Steel.Effect.repr a framed pre post (fun _ -> req) (fun _ v _ -> ens v)

let equiv_star_emp_r (p:vprop)
  : Lemma ((p `star` emp) `equiv` p)
  = cm_identity p;
    assert ((emp `star` p) `equiv` p);
    star_commutative p emp;
    equiv_trans (p `star` emp) (emp `star` p) p

let weaken_repr a framed
                (pre:pre_t)
                (post:post_t a)
                (req req':req_t pre)
                (ens ens':ens_t pre a post)
                (f:Steel.Effect.repr a framed pre post req ens)
                (_:squash (forall (h0:hmem pre).
                            req' (mk_rmem _ h0) ==>
                            req (mk_rmem _ h0)))
                (_:squash (forall (h0:hmem pre) x (h1:hmem (post x)).
                            ens (mk_rmem _ h0)
                                x
                                (mk_rmem _ h1) ==>
                            ens' (mk_rmem _ h0) x (mk_rmem _ h1)))
val weaken_repr:
    a: _ ->
    framed: _ ->
    pre: pre_t ->
    post: post_t a ->
    req: req_t pre ->
    req': req_t pre ->
    ens: ens_t pre a post ->
    ens': ens_t pre a post ->
    f: Steel.Effect.repr a framed pre post req ens ->
    squash (forall (h0: hmem pre). req' (mk_rmem _ h0) ==> req (mk_rmem _ h0)) ->
    squash (forall (h0: hmem pre) x (h1: hmem (post x)).
            ens (mk_rmem _ h0) x (mk_rmem _ h1) ==> ens' (mk_rmem _ h0) x (mk_rmem _ h1))
  -> Tot (Steel.Effect.repr a framed pre post req' ens')

    a: Type ->
    framed: Prims.bool ->
    pre: Steel.Effect.Common.pre_t ->
    post: Steel.Effect.Common.post_t a ->
    req: Steel.Effect.Common.req_t pre ->
    req': Steel.Effect.Common.req_t pre ->
    ens: Steel.Effect.Common.ens_t pre a post ->
    ens': Steel.Effect.Common.ens_t pre a post ->
    f: Steel.Effect.repr a framed pre post req ens ->
    _:
      Prims.squash (forall (h0: Steel.Effect.Common.hmem pre).
            req' (Steel.Effect.Common.mk_rmem pre h0) ==> req (Steel.Effect.Common.mk_rmem pre h0)) ->
    _:
      Prims.squash (forall (h0: Steel.Effect.Common.hmem pre)
            (x: a)
            (h1: Steel.Effect.Common.hmem (post x)).
            ens (Steel.Effect.Common.mk_rmem pre h0) x (Steel.Effect.Common.mk_rmem (post x) h1) ==>
            ens' (Steel.Effect.Common.mk_rmem pre h0) x (Steel.Effect.Common.mk_rmem (post x) h1))
  -> Steel.Effect.repr a framed pre post req' ens'