val for_loop (start:US.t)
             (finish:US.t { US.v start <= US.v finish })
             (inv: nat_at_most finish -> vprop)
             (body:
                    (i:u32_between start finish ->
                          STT unit
                          (inv (US.v i))
                          (fun _ -> inv (US.v i + 1))))
  : STT unit
      (inv (US.v start))
      (fun _ -> inv (US.v finish))
let for_loop (start:US.t)
             (finish:US.t { US.v start <= US.v finish })
             (inv: nat_at_most finish -> vprop)
             (body:
                    (i:u32_between start finish ->
                          STT unit
                          (inv (US.v i))
                          (fun _ -> inv (US.v i + 1))))
  : STT unit
      (inv (US.v start))
      (fun _ -> inv (US.v finish))
  = coerce_steel (fun _ -> for_loop' start finish inv body); ()
val for_loop (start:US.t)
             (finish:US.t { US.v start <= US.v finish })
             (inv: nat_at_most finish -> vprop)
             (body:
                    (i:u32_between start finish ->
                          STT unit
                          (inv (US.v i))
                          (fun _ -> inv (US.v i + 1))))
  : STT unit
      (inv (US.v start))
      (fun _ -> inv (US.v finish))
let for_loop
      (start: US.t)
      (finish: US.t{US.v start <= US.v finish})
      (inv: (nat_at_most finish -> vprop))
      (body: (i: u32_between start finish -> STT unit (inv (US.v i)) (fun _ -> inv (US.v i + 1))))
    : STT unit (inv (US.v start)) (fun _ -> inv (US.v finish)) =
coerce_steel (fun _ -> for_loop' start finish inv body);
()
Steel.ST.Loops.fst.checked
Steel.ST.Util.fsti.checked Steel.ST.Coercions.fsti.checked Steel.Loops.fsti.checked Steel.Effect.Atomic.fsti.checked Steel.Effect.fsti.checked prims.fst.checked FStar.SizeT.fsti.checked FStar.Pervasives.fsti.checked FStar.Ghost.fsti.checked
Steel.ST.Loops.fst
FStar.SizeT.t Prims.b2t Prims.op_LessThanOrEqual FStar.SizeT.v Steel.ST.Loops.nat_at_most Steel.Effect.Common.vprop Steel.ST.Loops.u32_between Prims.unit Prims.op_Addition Steel.ST.Coercions.coerce_steel Prims.l_True Steel.ST.Loops.for_loop'
(*
   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
module US = FStar.SizeT
open Steel.ST.Util
open Steel.ST.Coercions
module L = Steel.Loops
module SE = Steel.Effect
module SEA = Steel.Effect.Atomic
open FStar.Ghost

(* This module provides some common iterative looping combinators *)

let for_loop' (start:US.t)
              (finish:US.t { US.v start <= US.v finish })
              (inv: nat_at_most finish -> vprop)
              ($body:
                    (i:u32_between start finish ->
                          STT unit
                          (inv (US.v i))
                          (fun _ -> inv (US.v i + 1))))
  : SE.SteelT unit
      (inv (US.v start))
      (fun _ -> inv (US.v finish))
  = let body (i:u32_between start finish)
      : SE.SteelT unit
                  (inv (US.v i))
                  (fun _ -> inv (US.v i + 1))
      = body i
    in
    L.for_loop start finish inv body //lift works for body; NS 12/10: Need to eta expand for the lift

let for_loop (start:US.t)
             (finish:US.t { US.v start <= US.v finish })
             (inv: nat_at_most finish -> vprop)
             (body:
                    (i:u32_between start finish ->
                          STT unit
                          (inv (US.v i))
                          (fun _ -> inv (US.v i + 1))))
  : STT unit
      (inv (US.v start))
val for_loop (start:US.t)
             (finish:US.t { US.v start <= US.v finish })
             (inv: nat_at_most finish -> vprop)
             (body:
                    (i:u32_between start finish ->
                          STT unit
                          (inv (US.v i))
                          (fun _ -> inv (US.v i + 1))))
  : STT unit
      (inv (US.v start))
      (fun _ -> inv (US.v finish))

    start: FStar.SizeT.t ->
    finish: FStar.SizeT.t{FStar.SizeT.v start <= FStar.SizeT.v finish} ->
    inv: (_: Steel.ST.Loops.nat_at_most finish -> Steel.Effect.Common.vprop) ->
    body: (i: Steel.ST.Loops.u32_between start finish -> Steel.ST.Effect.STT Prims.unit)
  -> Steel.ST.Effect.STT Prims.unit