val mtac: Prims.unit -> Tac unit
val mtac: Prims.unit -> Tac unit
let mtac () : Tac unit =
  let is_eq_goal g : Tac bool =
    match term_as_formula' (goal_type g) with
    | Comp (Eq _) _ _ -> true
    | _ -> false in
  let is_squash_goal g : Tac bool =
    match term_as_formula' (goal_type g) with
    | App t _ -> is_fvar t (`%squash)
    | _ -> false in
  let rec separate_eq_and_squash_goals gs : Tac (list goal & list goal & list goal) =
    match gs with
    | [] -> [], [], []
    | g::tl ->
      let eq_goals, squash_goals, rest_goals = separate_eq_and_squash_goals tl in
      if is_eq_goal g then g::eq_goals, squash_goals, rest_goals
      else if is_squash_goal g then eq_goals, g::squash_goals, rest_goals
      else eq_goals, squash_goals, g::rest_goals in

  let eq_goals, squash_goals, rest_goals = separate_eq_and_squash_goals (goals ()) in
  set_goals eq_goals;
  iterAll (fun () -> trefl ());
  set_goals squash_goals;
  iterAll (fun () -> smt ());
  set_goals rest_goals;
  iterAll (fun () -> dismiss ())
(*
   Copyright 2008-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 IteSoundness

(*
 * This module intentionally admits goals etc., so silence warnings
 *)
#set-options "--warn_error -274 --warn_error -296 --warn_error -242"

(*
 * This module provides unit tests for checking the soundness of the layered
 *   effects if-then-else combinator using a tactic
 *)

open FStar.Tactics.V2

let unit : Type0 = unit
irreducible let an_attr : unit = ()

(*
 * First a layer over PURE
 * This works without the tactic too, but just to illustrate
 *)

type repr (a:Type) (wp:pure_wp a) = unit -> PURE a wp

open FStar.Monotonic.Pure

unfold
let return_wp (#a:Type) (x:a) : pure_wp a = as_pure_wp (fun p -> p x)
let return (a:Type) (x:a) : repr a (return_wp x) = fun () -> x

unfold
let bind_wp (#a #b:Type) (wp1:pure_wp a) (wp2:a -> pure_wp b) : pure_wp b =
  elim_pure_wp_monotonicity_forall ();
  as_pure_wp (fun p -> wp1 (fun x -> wp2 x p))
let bind (a b:Type) (wp1:pure_wp a) (wp2:a -> pure_wp b)
  (f:repr a wp1)
  (g:(x:a -> repr b (wp2 x)))
  : repr b (bind_wp wp1 wp2)
  = FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall ();
    fun () ->
    let x = f () in
    g x ()

let subcomp (a:Type) (wp1 wp2:pure_wp a) (f:repr a wp1)
  : Pure (repr a wp2)
      (requires forall p. wp2 p ==> wp1 p)
      (ensures fun _ -> True)
  = f

unfold
let ite_wp (#a:Type) (wp_then wp_else:pure_wp a) (b:bool) : pure_wp a =
  elim_pure_wp_monotonicity_forall ();
  as_pure_wp (fun p -> (b ==> wp_then p) /\ ((~ b) ==> wp_else p))
let if_then_else (a:Type) (wp_then wp_else:pure_wp a)
  (f:repr a wp_then) (g:repr a wp_else)
  (b:bool)
  : Type = repr a (ite_wp wp_then wp_else b)

(*
 * The tactic that will solve the implicits and guard for if-then-else soundness
 *)
/
prims.fst.checked FStar.Tactics.V2.fst.checked FStar.Pervasives.Native.fst.checked FStar.Pervasives.fsti.checked FStar.Monotonic.Pure.fst.checked
IteSoundness.fst
_: Prims.unit -> FStar.Tactics.Effect.Tac IteSoundness.unit
Prims.unit Prims.list FStar.Stubs.Tactics.Types.goal FStar.Tactics.V2.Derived.iterAll FStar.Tactics.V2.Derived.dismiss FStar.Stubs.Tactics.V2.Builtins.set_goals IteSoundness.unit FStar.Tactics.V2.Derived.smt FStar.Tactics.V2.Derived.trefl FStar.Pervasives.Native.tuple3 FStar.Tactics.V2.Derived.goals FStar.Pervasives.Native.Mktuple3 Prims.Nil Prims.Cons Prims.bool FStar.Tactics.NamedView.term FStar.Reflection.V2.Derived.is_fvar FStar.Reflection.V2.Formula.formula FStar.Reflection.V2.Formula.term_as_formula' FStar.Stubs.Tactics.Types.goal_type FStar.Pervasives.Native.option FStar.Stubs.Reflection.Types.typ
let mtac () : Tac unit =
  
let is_eq_goal g : Tac bool =
  match term_as_formula' (goal_type g) with
  | Comp (Eq _) _ _ -> true
  | _ -> false
in
let is_squash_goal g : Tac bool =
  match term_as_formula' (goal_type g) with
  | App t _ -> is_fvar t (`%squash)
  | _ -> false
in
let rec separate_eq_and_squash_goals gs : Tac (list goal & list goal & list goal) =
  match gs with
  | [] -> [], [], []
  | g :: tl ->
    let eq_goals, squash_goals, rest_goals = separate_eq_and_squash_goals tl in
    if is_eq_goal g
    then g :: eq_goals, squash_goals, rest_goals
    else
      if is_squash_goal g
      then eq_goals, g :: squash_goals, rest_goals
      else eq_goals, squash_goals, g :: rest_goals
in
let eq_goals, squash_goals, rest_goals = separate_eq_and_squash_goals (goals ()) in
set_goals eq_goals;
iterAll (fun () -> trefl ());
set_goals squash_goals;
iterAll (fun () -> smt ());
set_goals rest_goals;
iterAll (fun () -> dismiss ())