val return_ (a:Type)
            (x:a)
            (#[@@@ framing_implicit] p:a -> vprop)
  : repr a true (return_pre (p x)) p True (fun v -> v == x)
let return_ (a:Type)
            (x:a)
            (#[@@@ framing_implicit] p:a -> vprop)
  : Tot (repr a true (return_pre (p x)) p True (fun v -> v == x))
  = let k : Steel.Effect.repr a true
            (p x)
            p
            (fun _ -> True)
            (return_ens a x p)
          = Steel.Effect.return_ a x #p
    in
    weaken_repr _ _ _ _ _ _ _ _ k () ()
val return_ (a:Type)
            (x:a)
            (#[@@@ framing_implicit] p:a -> vprop)
  : repr a true (return_pre (p x)) p True (fun v -> v == x)
let return_ (a: Type) (x: a) (#[@@@ framing_implicit]p: (a -> vprop))
    : Tot (repr a true (return_pre (p x)) p True (fun v -> v == x)) =
let k:Steel.Effect.repr a true (p x) p (fun _ -> True) (return_ens a x p) =
  Steel.Effect.return_ a x #p
in
weaken_repr _ _ _ _ _ _ _ _ k () ()
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
Steel.Effect.Common.vprop Steel.ST.Effect.weaken_repr Steel.Effect.Common.rmem' Steel.Effect.Common.valid_rmem Prims.l_True Steel.Effect.Common.rmem Steel.Effect.Common.return_pre Prims.l_and Prims.eq2 FStar.Tactics.Effect.rewrite_with_tactic Steel.Effect.Common.frame_vc_norm Steel.Effect.Common.frame_equalities' Steel.Effect.Common.focus_rmem Steel.Effect.repr Steel.Effect.return_ Steel.ST.Effect.repr
(*
   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)))
  : 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


let return_ (a:Type)
            (x:a)
            (#[@@@ framing_implicit] p:a -> vprop)
val return_ (a:Type)
            (x:a)
            (#[@@@ framing_implicit] p:a -> vprop)
  : repr a true (return_pre (p x)) p True (fun v -> v == x)
a: Type -> x: a
  -> Steel.ST.Effect.repr a
      true
      (Steel.Effect.Common.return_pre (p x))
      p
      Prims.l_True
      (fun v -> v == x)