val repeat_until_body:
    p: (bool -> vprop) ->
    r: R.ref bool ->
    $body: (unit -> STT bool (p true) (fun b -> p b)) ->
    Prims.unit
  -> STT unit (repeat_until_inv p r true) (fun _ -> exists_ (repeat_until_inv p r))
let repeat_until_body
  (p:bool -> vprop)
  (r:R.ref bool)
  ($body: (unit -> STT bool (p true) (fun b -> p b)))
  ()
  : STT unit
        (repeat_until_inv p r true)
        (fun _ -> exists_ (repeat_until_inv p r))
  = rewrite (repeat_until_inv p r true)
            (R.pts_to r full_perm true `star` p true);
    let b = body () in
    R.write r b;
    rewrite (R.pts_to r full_perm b `star` p b)
            (repeat_until_inv p r b);
    intro_exists b (repeat_until_inv p r)
val repeat_until_body:
    p: (bool -> vprop) ->
    r: R.ref bool ->
    $body: (unit -> STT bool (p true) (fun b -> p b)) ->
    Prims.unit
  -> STT unit (repeat_until_inv p r true) (fun _ -> exists_ (repeat_until_inv p r))
let repeat_until_body
      (p: (bool -> vprop))
      (r: R.ref bool)
      ($body: (unit -> STT bool (p true) (fun b -> p b)))
      ()
    : STT unit (repeat_until_inv p r true) (fun _ -> exists_ (repeat_until_inv p r)) =
rewrite (repeat_until_inv p r true) ((R.pts_to r full_perm true) `star` (p true));
let b = body () in
R.write r b;
rewrite ((R.pts_to r full_perm b) `star` (p b)) (repeat_until_inv p r b);
intro_exists b (repeat_until_inv p r)
Steel.ST.Loops.Util.fst.checked
Steel.ST.Util.fsti.checked Steel.ST.Reference.fsti.checked Steel.ST.Loops.fsti.checked Steel.ST.Effect.fsti.checked Steel.FractionalPermission.fst.checked prims.fst.checked FStar.Pervasives.fsti.checked
Steel.ST.Loops.Util.fst
Prims.bool Steel.Effect.Common.vprop Steel.ST.Reference.ref Prims.unit Steel.ST.Util.intro_exists FStar.Ghost.hide FStar.Set.set Steel.Memory.iname FStar.Set.empty Steel.ST.Loops.Util.repeat_until_inv Steel.ST.Util.rewrite Steel.Effect.Common.star Steel.ST.Reference.pts_to Steel.FractionalPermission.full_perm Steel.ST.Reference.write Steel.ST.Util.exists_
(*
   Copyright 2021 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.Loops.Util

open Steel.FractionalPermission
open Steel.ST.Effect
open Steel.ST.Util

module R = Steel.ST.Reference

let repeat_until_inv (p:bool -> vprop) (r:R.ref bool)
  : bool -> vprop
  = fun b -> R.pts_to r full_perm b `star` p b

inline_for_extraction
let repeat_until_cond (p:bool -> vprop) (r:R.ref bool) ()
  : STT bool (exists_ (repeat_until_inv p r)) (repeat_until_inv p r)
  = let _b = elim_exists () in
    rewrite (repeat_until_inv p r _b)
            (R.pts_to r full_perm _b `star` p _b);
    let b = R.read r in
    rewrite (R.pts_to r full_perm _b `star` p _b)
            (repeat_until_inv p r b);
    return b

inline_for_extraction
let repeat_until_body
  (p:bool -> vprop)
  (r:R.ref bool)
  ($body: (unit -> STT bool (p true) (fun b -> p b)))
  ()
  : STT unit
        (repeat_until_inv p r true)
val repeat_until_body:
    p: (bool -> vprop) ->
    r: R.ref bool ->
    $body: (unit -> STT bool (p true) (fun b -> p b)) ->
    Prims.unit
  -> STT unit (repeat_until_inv p r true) (fun _ -> exists_ (repeat_until_inv p r))

    p: (_: Prims.bool -> Steel.Effect.Common.vprop) ->
    r: Steel.ST.Reference.ref Prims.bool ->
    $body: (_: Prims.unit -> Steel.ST.Effect.STT Prims.bool) ->
    _: Prims.unit
  -> Steel.ST.Effect.STT Prims.unit