file_name
stringlengths
5
52
name
stringlengths
4
95
original_source_type
stringlengths
0
23k
source_type
stringlengths
9
23k
source_definition
stringlengths
9
57.9k
source
dict
source_range
dict
file_context
stringlengths
0
721k
dependencies
dict
opens_and_abbrevs
listlengths
2
94
vconfig
dict
interleaved
bool
1 class
verbose_type
stringlengths
1
7.42k
effect
stringclasses
118 values
effect_flags
sequencelengths
0
2
mutual_with
sequencelengths
0
11
ideal_premises
sequencelengths
0
236
proof_features
sequencelengths
0
1
is_simple_lemma
bool
2 classes
is_div
bool
2 classes
is_proof
bool
2 classes
is_simply_typed
bool
2 classes
is_type
bool
2 classes
partial_definition
stringlengths
5
3.99k
completed_definiton
stringlengths
1
1.63M
isa_cross_project_example
bool
1 class
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.tcut
val tcut (t: term) : Tac binding
val tcut (t: term) : Tac binding
let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro ()
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 12, "end_line": 545, "start_col": 0, "start_line": 541 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.binding
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Tactics.NamedView.term", "FStar.Stubs.Tactics.V2.Builtins.intro", "FStar.Stubs.Reflection.V2.Data.binding", "Prims.unit", "FStar.Tactics.V2.Derived.apply", "FStar.Tactics.NamedView.binding", "FStar.Stubs.Reflection.Types.term", "FStar.Reflection.V2.Derived.mk_e_app", "Prims.Cons", "Prims.Nil", "FStar.Stubs.Reflection.Types.typ", "FStar.Tactics.V2.Derived.cur_goal" ]
[]
false
true
false
false
false
let tcut (t: term) : Tac binding =
let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro ()
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.intros'
val intros': Prims.unit -> Tac unit
val intros': Prims.unit -> Tac unit
let intros' () : Tac unit = let _ = intros () in ()
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 51, "end_line": 534, "start_col": 0, "start_line": 534 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "Prims.list", "FStar.Tactics.NamedView.binding", "FStar.Tactics.V2.Derived.intros" ]
[]
false
true
false
false
false
let intros' () : Tac unit =
let _ = intros () in ()
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.admit1
val admit1: Prims.unit -> Tac unit
val admit1: Prims.unit -> Tac unit
let admit1 () : Tac unit = tadmit ()
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 13, "end_line": 509, "start_col": 0, "start_line": 508 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`())
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V2.Derived.tadmit" ]
[]
false
true
false
false
false
let admit1 () : Tac unit =
tadmit ()
false
Spec.Ed25519.fst
Spec.Ed25519.secret_expand
val secret_expand (secret: lbytes 32) : (lbytes 32 & lbytes 32)
val secret_expand (secret: lbytes 32) : (lbytes 32 & lbytes 32)
let secret_expand (secret:lbytes 32) : (lbytes 32 & lbytes 32) = let h = Spec.Agile.Hash.hash Spec.Hash.Definitions.SHA2_512 secret in let h_low : lbytes 32 = slice h 0 32 in let h_high : lbytes 32 = slice h 32 64 in let h_low = h_low.[ 0] <- h_low.[0] &. u8 0xf8 in let h_low = h_low.[31] <- (h_low.[31] &. u8 127) |. u8 64 in h_low, h_high
{ "file_name": "specs/Spec.Ed25519.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 15, "end_line": 108, "start_col": 0, "start_line": 102 }
module Spec.Ed25519 open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Curve25519 module LE = Lib.Exponentiation module SE = Spec.Exponentiation module EL = Spec.Ed25519.Lemmas include Spec.Ed25519.PointOps #reset-options "--fuel 0 --ifuel 0 --z3rlimit 100" inline_for_extraction let size_signature: size_nat = 64 let q: n:nat{n < pow2 256} = assert_norm(pow2 252 + 27742317777372353535851937790883648493 < pow2 255 - 19); (pow2 252 + 27742317777372353535851937790883648493) // Group order let max_input_length_sha512 = Some?.v (Spec.Hash.Definitions.max_input_length Spec.Hash.Definitions.SHA2_512) let _: squash(max_input_length_sha512 > pow2 32 + 64) = assert_norm (max_input_length_sha512 > pow2 32 + 64) let sha512_modq (len:nat{len <= max_input_length_sha512}) (s:bytes{length s = len}) : n:nat{n < pow2 256} = nat_from_bytes_le (Spec.Agile.Hash.hash Spec.Hash.Definitions.SHA2_512 s) % q /// Point Multiplication let aff_point_c = p:aff_point{is_on_curve p} let aff_point_add_c (p:aff_point_c) (q:aff_point_c) : aff_point_c = EL.aff_point_add_lemma p q; aff_point_add p q let mk_ed25519_comm_monoid: LE.comm_monoid aff_point_c = { LE.one = aff_point_at_infinity; LE.mul = aff_point_add_c; LE.lemma_one = EL.aff_point_at_infinity_lemma; LE.lemma_mul_assoc = EL.aff_point_add_assoc_lemma; LE.lemma_mul_comm = EL.aff_point_add_comm_lemma; } let ext_point_c = p:ext_point{point_inv p} let mk_to_ed25519_comm_monoid : SE.to_comm_monoid ext_point_c = { SE.a_spec = aff_point_c; SE.comm_monoid = mk_ed25519_comm_monoid; SE.refl = (fun (x:ext_point_c) -> to_aff_point x); } val point_at_inifinity_c: SE.one_st ext_point_c mk_to_ed25519_comm_monoid let point_at_inifinity_c _ = EL.to_aff_point_at_infinity_lemma (); point_at_infinity val point_add_c: SE.mul_st ext_point_c mk_to_ed25519_comm_monoid let point_add_c p q = EL.to_aff_point_add_lemma p q; point_add p q val point_double_c: SE.sqr_st ext_point_c mk_to_ed25519_comm_monoid let point_double_c p = EL.to_aff_point_double_lemma p; point_double p let mk_ed25519_concrete_ops : SE.concrete_ops ext_point_c = { SE.to = mk_to_ed25519_comm_monoid; SE.one = point_at_inifinity_c; SE.mul = point_add_c; SE.sqr = point_double_c; } // [a]P let point_mul (a:lbytes 32) (p:ext_point_c) : ext_point_c = SE.exp_fw mk_ed25519_concrete_ops p 256 (nat_from_bytes_le a) 4 // [a1]P1 + [a2]P2 let point_mul_double (a1:lbytes 32) (p1:ext_point_c) (a2:lbytes 32) (p2:ext_point_c) : ext_point_c = SE.exp_double_fw mk_ed25519_concrete_ops p1 256 (nat_from_bytes_le a1) p2 (nat_from_bytes_le a2) 5 // [a]G let point_mul_g (a:lbytes 32) : ext_point_c = EL.g_is_on_curve (); point_mul a g // [a1]G + [a2]P let point_mul_double_g (a1:lbytes 32) (a2:lbytes 32) (p:ext_point_c) : ext_point_c = EL.g_is_on_curve (); point_mul_double a1 g a2 p // [a1]G - [a2]P let point_negate_mul_double_g (a1:lbytes 32) (a2:lbytes 32) (p:ext_point_c) : ext_point_c = let p1 = point_negate p in EL.to_aff_point_negate p; point_mul_double_g a1 a2 p1 /// Ed25519 API
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Exponentiation.fsti.checked", "Spec.Ed25519.PointOps.fst.checked", "Spec.Ed25519.Lemmas.fsti.checked", "Spec.Curve25519.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.Ed25519.fst" }
[ { "abbrev": false, "full_module": "Spec.Ed25519.PointOps", "short_module": null }, { "abbrev": true, "full_module": "Spec.Ed25519.Lemmas", "short_module": "EL" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
secret: Lib.ByteSequence.lbytes 32 -> Lib.ByteSequence.lbytes 32 * Lib.ByteSequence.lbytes 32
Prims.Tot
[ "total" ]
[]
[ "Lib.ByteSequence.lbytes", "FStar.Pervasives.Native.Mktuple2", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Prims.l_and", "Prims.eq2", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.upd", "Lib.IntTypes.logor", "Lib.IntTypes.logand", "Lib.Sequence.index", "Lib.IntTypes.mk_int", "Prims.l_Forall", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "Prims.pow2", "Prims.l_imp", "Prims.op_LessThan", "Prims.op_disEquality", "Prims.l_or", "FStar.Seq.Base.index", "Lib.Sequence.op_String_Assignment", "Lib.IntTypes.op_Bar_Dot", "Lib.IntTypes.op_Amp_Dot", "Lib.Sequence.op_String_Access", "Lib.IntTypes.u8", "Lib.Sequence.slice", "Lib.IntTypes.uint_t", "Spec.Hash.Definitions.hash_length'", "Spec.Hash.Definitions.SHA2_512", "Spec.Agile.Hash.hash", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
false
false
let secret_expand (secret: lbytes 32) : (lbytes 32 & lbytes 32) =
let h = Spec.Agile.Hash.hash Spec.Hash.Definitions.SHA2_512 secret in let h_low:lbytes 32 = slice h 0 32 in let h_high:lbytes 32 = slice h 32 64 in let h_low = h_low.[ 0 ] <- h_low.[ 0 ] &. u8 0xf8 in let h_low = h_low.[ 31 ] <- (h_low.[ 31 ] &. u8 127) |. u8 64 in h_low, h_high
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.pose
val pose (t: term) : Tac binding
val pose (t: term) : Tac binding
let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro ()
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 12, "end_line": 551, "start_col": 0, "start_line": 547 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.binding
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Tactics.NamedView.term", "FStar.Stubs.Tactics.V2.Builtins.intro", "FStar.Stubs.Reflection.V2.Data.binding", "Prims.unit", "FStar.Tactics.V2.Derived.exact", "FStar.Tactics.NamedView.binding", "FStar.Tactics.V2.Derived.flip", "FStar.Tactics.V2.Derived.apply" ]
[]
false
true
false
false
false
let pose (t: term) : Tac binding =
apply (`__cut); flip (); exact t; intro ()
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.intros
val intros: Prims.unit -> Tac (list binding)
val intros: Prims.unit -> Tac (list binding)
let intros () : Tac (list binding) = repeat intro
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 49, "end_line": 532, "start_col": 0, "start_line": 532 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac (Prims.list FStar.Tactics.NamedView.binding)
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V2.Derived.repeat", "FStar.Tactics.NamedView.binding", "FStar.Stubs.Tactics.V2.Builtins.intro", "Prims.list" ]
[]
false
true
false
false
false
let intros () : Tac (list binding) =
repeat intro
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.intro_as
val intro_as (s: string) : Tac binding
val intro_as (s: string) : Tac binding
let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 555, "start_col": 0, "start_line": 553 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Prims.string -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.binding
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.string", "FStar.Stubs.Tactics.V2.Builtins.rename_to", "FStar.Stubs.Reflection.V2.Data.binding", "FStar.Stubs.Tactics.V2.Builtins.intro", "FStar.Tactics.NamedView.binding" ]
[]
false
true
false
false
false
let intro_as (s: string) : Tac binding =
let b = intro () in rename_to b s
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.for_each_binding
val for_each_binding (f: (binding -> Tac 'a)) : Tac (list 'a)
val for_each_binding (f: (binding -> Tac 'a)) : Tac (list 'a)
let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ())
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 23, "end_line": 562, "start_col": 0, "start_line": 561 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: FStar.Tactics.NamedView.binding -> FStar.Tactics.Effect.Tac 'a) -> FStar.Tactics.Effect.Tac (Prims.list 'a)
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Tactics.NamedView.binding", "FStar.Tactics.Util.map", "Prims.list", "FStar.Tactics.V2.Derived.cur_vars" ]
[]
false
true
false
false
false
let for_each_binding (f: (binding -> Tac 'a)) : Tac (list 'a) =
map f (cur_vars ())
false
Spec.Ed25519.fst
Spec.Ed25519.sign_expanded
val sign_expanded (pub s prefix:lbytes 32) (msg:bytes{length msg <= max_size_t}) : lbytes 64
val sign_expanded (pub s prefix:lbytes 32) (msg:bytes{length msg <= max_size_t}) : lbytes 64
let sign_expanded pub s prefix msg = let len = length msg in let r = sha512_modq (32 + len) (Seq.append prefix msg) in let r' = point_mul_g (nat_to_bytes_le 32 r) in let rs = point_compress r' in let h = sha512_modq (64 + len) (Seq.append (concat rs pub) msg) in let s = (r + (h * nat_from_bytes_le s) % q) % q in concat #_ #32 #32 rs (nat_to_bytes_le 32 s)
{ "file_name": "specs/Spec.Ed25519.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 45, "end_line": 130, "start_col": 0, "start_line": 123 }
module Spec.Ed25519 open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Curve25519 module LE = Lib.Exponentiation module SE = Spec.Exponentiation module EL = Spec.Ed25519.Lemmas include Spec.Ed25519.PointOps #reset-options "--fuel 0 --ifuel 0 --z3rlimit 100" inline_for_extraction let size_signature: size_nat = 64 let q: n:nat{n < pow2 256} = assert_norm(pow2 252 + 27742317777372353535851937790883648493 < pow2 255 - 19); (pow2 252 + 27742317777372353535851937790883648493) // Group order let max_input_length_sha512 = Some?.v (Spec.Hash.Definitions.max_input_length Spec.Hash.Definitions.SHA2_512) let _: squash(max_input_length_sha512 > pow2 32 + 64) = assert_norm (max_input_length_sha512 > pow2 32 + 64) let sha512_modq (len:nat{len <= max_input_length_sha512}) (s:bytes{length s = len}) : n:nat{n < pow2 256} = nat_from_bytes_le (Spec.Agile.Hash.hash Spec.Hash.Definitions.SHA2_512 s) % q /// Point Multiplication let aff_point_c = p:aff_point{is_on_curve p} let aff_point_add_c (p:aff_point_c) (q:aff_point_c) : aff_point_c = EL.aff_point_add_lemma p q; aff_point_add p q let mk_ed25519_comm_monoid: LE.comm_monoid aff_point_c = { LE.one = aff_point_at_infinity; LE.mul = aff_point_add_c; LE.lemma_one = EL.aff_point_at_infinity_lemma; LE.lemma_mul_assoc = EL.aff_point_add_assoc_lemma; LE.lemma_mul_comm = EL.aff_point_add_comm_lemma; } let ext_point_c = p:ext_point{point_inv p} let mk_to_ed25519_comm_monoid : SE.to_comm_monoid ext_point_c = { SE.a_spec = aff_point_c; SE.comm_monoid = mk_ed25519_comm_monoid; SE.refl = (fun (x:ext_point_c) -> to_aff_point x); } val point_at_inifinity_c: SE.one_st ext_point_c mk_to_ed25519_comm_monoid let point_at_inifinity_c _ = EL.to_aff_point_at_infinity_lemma (); point_at_infinity val point_add_c: SE.mul_st ext_point_c mk_to_ed25519_comm_monoid let point_add_c p q = EL.to_aff_point_add_lemma p q; point_add p q val point_double_c: SE.sqr_st ext_point_c mk_to_ed25519_comm_monoid let point_double_c p = EL.to_aff_point_double_lemma p; point_double p let mk_ed25519_concrete_ops : SE.concrete_ops ext_point_c = { SE.to = mk_to_ed25519_comm_monoid; SE.one = point_at_inifinity_c; SE.mul = point_add_c; SE.sqr = point_double_c; } // [a]P let point_mul (a:lbytes 32) (p:ext_point_c) : ext_point_c = SE.exp_fw mk_ed25519_concrete_ops p 256 (nat_from_bytes_le a) 4 // [a1]P1 + [a2]P2 let point_mul_double (a1:lbytes 32) (p1:ext_point_c) (a2:lbytes 32) (p2:ext_point_c) : ext_point_c = SE.exp_double_fw mk_ed25519_concrete_ops p1 256 (nat_from_bytes_le a1) p2 (nat_from_bytes_le a2) 5 // [a]G let point_mul_g (a:lbytes 32) : ext_point_c = EL.g_is_on_curve (); point_mul a g // [a1]G + [a2]P let point_mul_double_g (a1:lbytes 32) (a2:lbytes 32) (p:ext_point_c) : ext_point_c = EL.g_is_on_curve (); point_mul_double a1 g a2 p // [a1]G - [a2]P let point_negate_mul_double_g (a1:lbytes 32) (a2:lbytes 32) (p:ext_point_c) : ext_point_c = let p1 = point_negate p in EL.to_aff_point_negate p; point_mul_double_g a1 a2 p1 /// Ed25519 API let secret_expand (secret:lbytes 32) : (lbytes 32 & lbytes 32) = let h = Spec.Agile.Hash.hash Spec.Hash.Definitions.SHA2_512 secret in let h_low : lbytes 32 = slice h 0 32 in let h_high : lbytes 32 = slice h 32 64 in let h_low = h_low.[ 0] <- h_low.[0] &. u8 0xf8 in let h_low = h_low.[31] <- (h_low.[31] &. u8 127) |. u8 64 in h_low, h_high let secret_to_public (secret:lbytes 32) : lbytes 32 = let a, dummy = secret_expand secret in point_compress (point_mul_g a) let expand_keys (secret:lbytes 32) : (lbytes 32 & lbytes 32 & lbytes 32) = let s, prefix = secret_expand secret in let pub = point_compress (point_mul_g s) in pub, s, prefix
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Exponentiation.fsti.checked", "Spec.Ed25519.PointOps.fst.checked", "Spec.Ed25519.Lemmas.fsti.checked", "Spec.Curve25519.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.Ed25519.fst" }
[ { "abbrev": false, "full_module": "Spec.Ed25519.PointOps", "short_module": null }, { "abbrev": true, "full_module": "Spec.Ed25519.Lemmas", "short_module": "EL" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
pub: Lib.ByteSequence.lbytes 32 -> s: Lib.ByteSequence.lbytes 32 -> prefix: Lib.ByteSequence.lbytes 32 -> msg: Lib.ByteSequence.bytes{Lib.Sequence.length msg <= Lib.IntTypes.max_size_t} -> Lib.ByteSequence.lbytes 64
Prims.Tot
[ "total" ]
[]
[ "Lib.ByteSequence.lbytes", "Lib.ByteSequence.bytes", "Prims.b2t", "Prims.op_LessThanOrEqual", "Lib.Sequence.length", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.IntTypes.max_size_t", "Lib.Sequence.concat", "Lib.ByteSequence.nat_to_bytes_le", "Prims.int", "Prims.op_Modulus", "Prims.op_Addition", "FStar.Mul.op_Star", "Lib.ByteSequence.nat_from_bytes_le", "Spec.Ed25519.q", "Prims.nat", "Prims.op_LessThan", "Prims.pow2", "Spec.Ed25519.sha512_modq", "FStar.Seq.Base.append", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Spec.Ed25519.PointOps.point_compress", "Spec.Ed25519.ext_point_c", "Spec.Ed25519.point_mul_g" ]
[]
false
false
false
false
false
let sign_expanded pub s prefix msg =
let len = length msg in let r = sha512_modq (32 + len) (Seq.append prefix msg) in let r' = point_mul_g (nat_to_bytes_le 32 r) in let rs = point_compress r' in let h = sha512_modq (64 + len) (Seq.append (concat rs pub) msg) in let s = (r + (h * nat_from_bytes_le s) % q) % q in concat #_ #32 #32 rs (nat_to_bytes_le 32 s)
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.__cut
val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b
val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b
let __cut a b f x = f x
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 31, "end_line": 539, "start_col": 8, "start_line": 539 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros'
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> b: Type -> f: (_: a -> b) -> x: a -> b
Prims.Tot
[ "total" ]
[]
[]
[]
false
false
false
true
false
let __cut a b f x =
f x
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.iseq
val iseq (ts: list (unit -> Tac unit)) : Tac unit
val iseq (ts: list (unit -> Tac unit)) : Tac unit
let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> ()
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 324, "start_col": 0, "start_line": 321 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ts: Prims.list (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit) -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.list", "Prims.unit", "FStar.Pervasives.Native.tuple2", "FStar.Tactics.V2.Derived.divide", "FStar.Tactics.V2.Derived.iseq" ]
[ "recursion" ]
false
true
false
false
false
let rec iseq (ts: list (unit -> Tac unit)) : Tac unit =
match ts with | t :: ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> ()
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.binder_sort
val binder_sort (b: binder) : Tot typ
val binder_sort (b: binder) : Tot typ
let binder_sort (b : binder) : Tot typ = b.sort
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 47, "end_line": 570, "start_col": 0, "start_line": 570 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: FStar.Tactics.NamedView.binder -> FStar.Stubs.Reflection.Types.typ
Prims.Tot
[ "total" ]
[]
[ "FStar.Tactics.NamedView.binder", "FStar.Tactics.NamedView.__proj__Mkbinder__item__sort", "FStar.Stubs.Reflection.Types.typ" ]
[]
false
false
false
true
false
let binder_sort (b: binder) : Tot typ =
b.sort
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.rewrite'
val rewrite' (x: binding) : Tac unit
val rewrite' (x: binding) : Tac unit
let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) ()
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 6, "end_line": 608, "start_col": 0, "start_line": 602 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.Tactics.NamedView.binding -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Tactics.NamedView.binding", "FStar.Tactics.V2.Derived.op_Less_Bar_Greater", "Prims.unit", "FStar.Stubs.Tactics.V2.Builtins.rewrite", "FStar.Tactics.V2.Derived.apply_lemma", "FStar.Stubs.Tactics.V2.Builtins.var_retype", "FStar.Tactics.V2.Derived.fail" ]
[]
false
true
false
false
false
let rewrite' (x: binding) : Tac unit =
((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) ()
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.rewrite_eqs_from_context
val rewrite_eqs_from_context: Prims.unit -> Tac unit
val rewrite_eqs_from_context: Prims.unit -> Tac unit
let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ())
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 48, "end_line": 632, "start_col": 0, "start_line": 631 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V2.Derived.rewrite_all_context_equalities", "Prims.list", "FStar.Tactics.NamedView.binding", "FStar.Tactics.V2.Derived.cur_vars" ]
[]
false
true
false
false
false
let rewrite_eqs_from_context () : Tac unit =
rewrite_all_context_equalities (cur_vars ())
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.assumption
val assumption: Prims.unit -> Tac unit
val assumption: Prims.unit -> Tac unit
let assumption () : Tac unit = __assumption_aux (cur_vars ())
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 585, "start_col": 0, "start_line": 584 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V2.Derived.__assumption_aux", "Prims.list", "FStar.Tactics.NamedView.binding", "FStar.Tactics.V2.Derived.cur_vars" ]
[]
false
true
false
false
false
let assumption () : Tac unit =
__assumption_aux (cur_vars ())
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.fresh_namedv
val fresh_namedv: Prims.unit -> Tac namedv
val fresh_namedv: Prims.unit -> Tac namedv
let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; })
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 4, "end_line": 404, "start_col": 0, "start_line": 398 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.namedv
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.NamedView.pack_namedv", "FStar.Stubs.Reflection.V2.Data.Mknamedv_view", "FStar.Sealed.seal", "FStar.Stubs.Reflection.Types.typ", "FStar.Tactics.NamedView.pack", "FStar.Tactics.NamedView.Tv_Unknown", "Prims.string", "Prims.op_Hat", "Prims.string_of_int", "FStar.Tactics.NamedView.namedv", "Prims.nat", "FStar.Stubs.Tactics.V2.Builtins.fresh" ]
[]
false
true
false
false
false
let fresh_namedv () : Tac namedv =
let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n })
false
Vale.AES.X64.AESopt.fst
Vale.AES.X64.AESopt.va_lemma_Loop6x_final
val va_lemma_Loop6x_final : va_b0:va_code -> va_s0:va_state -> alg:algorithm -> iv_b:buffer128 -> scratch_b:buffer128 -> key_words:(seq nat32) -> round_keys:(seq quad32) -> keys_b:buffer128 -> ctr_orig:quad32 -> init:quad32_6 -> ctrs:quad32_6 -> plain:quad32_6 -> inb:quad32 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_Loop6x_final alg) va_s0 /\ va_get_ok va_s0 /\ (sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 2 va_s0) (va_get_reg64 rR8 va_s0) iv_b 1 (va_get_mem_layout va_s0) Public /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 3 va_s0) (va_get_reg64 rRbp va_s0) scratch_b 9 (va_get_mem_layout va_s0) Secret /\ va_get_reg64 rRdi va_s0 + 96 < pow2_64 /\ va_get_reg64 rRsi va_s0 + 96 < pow2_64 /\ aes_reqs_offset alg key_words round_keys keys_b (va_get_reg64 rRcx va_s0) (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0) /\ init == map_six_of #quad32 #quad32 ctrs (fun (c:quad32) -> Vale.Def.Types_s.quad32_xor c (FStar.Seq.Base.index #Vale.Def.Types_s.quad32 round_keys 0)) /\ (va_get_xmm 9 va_s0, va_get_xmm 10 va_s0, va_get_xmm 11 va_s0, va_get_xmm 12 va_s0, va_get_xmm 13 va_s0, va_get_xmm 14 va_s0) == rounds_opaque_6 init round_keys (Vale.AES.AES_common_s.nr alg - 1) /\ va_get_reg64 rR13 va_s0 == Vale.Def.Types_s.reverse_bytes_nat64 (Vale.Arch.Types.hi64 inb) /\ va_get_reg64 rR12 va_s0 == Vale.Def.Types_s.reverse_bytes_nat64 (Vale.Arch.Types.lo64 inb) /\ (let rk = FStar.Seq.Base.index #quad32 round_keys (Vale.AES.AES_common_s.nr alg) in (va_get_xmm 2 va_s0, va_get_xmm 0 va_s0, va_get_xmm 5 va_s0, va_get_xmm 6 va_s0, va_get_xmm 7 va_s0, va_get_xmm 3 va_s0) == map_six_of #quad32 #quad32 plain (fun (p:quad32) -> Vale.Def.Types_s.quad32_xor rk p) /\ Vale.X64.Decls.buffer128_read scratch_b 8 (va_get_mem_heaplet 3 va_s0) == Vale.Def.Types_s.reverse_bytes_quad32 ctr_orig)))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (Vale.X64.Decls.modifies_buffer_specific128 scratch_b (va_get_mem_heaplet 3 va_s0) (va_get_mem_heaplet 3 va_sM) 7 7 /\ Vale.X64.Decls.buffer128_read scratch_b 7 (va_get_mem_heaplet 3 va_sM) == Vale.Def.Types_s.reverse_bytes_quad32 inb /\ (va_get_xmm 9 va_sM, va_get_xmm 10 va_sM, va_get_xmm 11 va_sM, va_get_xmm 12 va_sM, va_get_xmm 13 va_sM, va_get_xmm 14 va_sM) == map2_six_of #quad32 #quad32 #quad32 plain ctrs (fun (p:quad32) (c:quad32) -> Vale.Def.Types_s.quad32_xor p (Vale.AES.AES_s.aes_encrypt_LE alg key_words c)) /\ va_get_xmm 15 va_sM == FStar.Seq.Base.index #quad32 round_keys 0 /\ va_get_reg64 rRdi va_sM == va_get_reg64 rRdi va_s0 + 96 /\ va_get_reg64 rRsi va_sM == va_get_reg64 rRsi va_s0 + 96 /\ va_get_xmm 2 va_sM == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 16777216 /\ va_get_xmm 1 va_sM == Vale.X64.Decls.buffer128_read scratch_b 8 (va_get_mem_heaplet 3 va_s0) /\ (let ctr = Vale.Def.Words_s.__proj__Mkfour__item__lo0 ctr_orig `op_Modulus` 256 in ctr + 6 < 256 ==> (va_get_xmm 1 va_sM, va_get_xmm 0 va_sM, va_get_xmm 5 va_sM, va_get_xmm 6 va_sM, va_get_xmm 7 va_sM, va_get_xmm 3 va_sM) == xor_reverse_inc32lite_6 0 0 ctr_orig (va_get_xmm 15 va_sM))) /\ va_state_eq va_sM (va_update_mem_heaplet 3 va_sM (va_update_flags va_sM (va_update_xmm 15 va_sM (va_update_xmm 14 va_sM (va_update_xmm 13 va_sM (va_update_xmm 12 va_sM (va_update_xmm 11 va_sM (va_update_xmm 10 va_sM (va_update_xmm 9 va_sM (va_update_xmm 7 va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM (va_update_reg64 rR13 va_sM (va_update_reg64 rR12 va_sM (va_update_reg64 rR11 va_sM (va_update_reg64 rRsi va_sM (va_update_reg64 rRdi va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0)))))))))))))))))))))))))
val va_lemma_Loop6x_final : va_b0:va_code -> va_s0:va_state -> alg:algorithm -> iv_b:buffer128 -> scratch_b:buffer128 -> key_words:(seq nat32) -> round_keys:(seq quad32) -> keys_b:buffer128 -> ctr_orig:quad32 -> init:quad32_6 -> ctrs:quad32_6 -> plain:quad32_6 -> inb:quad32 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_Loop6x_final alg) va_s0 /\ va_get_ok va_s0 /\ (sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 2 va_s0) (va_get_reg64 rR8 va_s0) iv_b 1 (va_get_mem_layout va_s0) Public /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 3 va_s0) (va_get_reg64 rRbp va_s0) scratch_b 9 (va_get_mem_layout va_s0) Secret /\ va_get_reg64 rRdi va_s0 + 96 < pow2_64 /\ va_get_reg64 rRsi va_s0 + 96 < pow2_64 /\ aes_reqs_offset alg key_words round_keys keys_b (va_get_reg64 rRcx va_s0) (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0) /\ init == map_six_of #quad32 #quad32 ctrs (fun (c:quad32) -> Vale.Def.Types_s.quad32_xor c (FStar.Seq.Base.index #Vale.Def.Types_s.quad32 round_keys 0)) /\ (va_get_xmm 9 va_s0, va_get_xmm 10 va_s0, va_get_xmm 11 va_s0, va_get_xmm 12 va_s0, va_get_xmm 13 va_s0, va_get_xmm 14 va_s0) == rounds_opaque_6 init round_keys (Vale.AES.AES_common_s.nr alg - 1) /\ va_get_reg64 rR13 va_s0 == Vale.Def.Types_s.reverse_bytes_nat64 (Vale.Arch.Types.hi64 inb) /\ va_get_reg64 rR12 va_s0 == Vale.Def.Types_s.reverse_bytes_nat64 (Vale.Arch.Types.lo64 inb) /\ (let rk = FStar.Seq.Base.index #quad32 round_keys (Vale.AES.AES_common_s.nr alg) in (va_get_xmm 2 va_s0, va_get_xmm 0 va_s0, va_get_xmm 5 va_s0, va_get_xmm 6 va_s0, va_get_xmm 7 va_s0, va_get_xmm 3 va_s0) == map_six_of #quad32 #quad32 plain (fun (p:quad32) -> Vale.Def.Types_s.quad32_xor rk p) /\ Vale.X64.Decls.buffer128_read scratch_b 8 (va_get_mem_heaplet 3 va_s0) == Vale.Def.Types_s.reverse_bytes_quad32 ctr_orig)))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (Vale.X64.Decls.modifies_buffer_specific128 scratch_b (va_get_mem_heaplet 3 va_s0) (va_get_mem_heaplet 3 va_sM) 7 7 /\ Vale.X64.Decls.buffer128_read scratch_b 7 (va_get_mem_heaplet 3 va_sM) == Vale.Def.Types_s.reverse_bytes_quad32 inb /\ (va_get_xmm 9 va_sM, va_get_xmm 10 va_sM, va_get_xmm 11 va_sM, va_get_xmm 12 va_sM, va_get_xmm 13 va_sM, va_get_xmm 14 va_sM) == map2_six_of #quad32 #quad32 #quad32 plain ctrs (fun (p:quad32) (c:quad32) -> Vale.Def.Types_s.quad32_xor p (Vale.AES.AES_s.aes_encrypt_LE alg key_words c)) /\ va_get_xmm 15 va_sM == FStar.Seq.Base.index #quad32 round_keys 0 /\ va_get_reg64 rRdi va_sM == va_get_reg64 rRdi va_s0 + 96 /\ va_get_reg64 rRsi va_sM == va_get_reg64 rRsi va_s0 + 96 /\ va_get_xmm 2 va_sM == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 16777216 /\ va_get_xmm 1 va_sM == Vale.X64.Decls.buffer128_read scratch_b 8 (va_get_mem_heaplet 3 va_s0) /\ (let ctr = Vale.Def.Words_s.__proj__Mkfour__item__lo0 ctr_orig `op_Modulus` 256 in ctr + 6 < 256 ==> (va_get_xmm 1 va_sM, va_get_xmm 0 va_sM, va_get_xmm 5 va_sM, va_get_xmm 6 va_sM, va_get_xmm 7 va_sM, va_get_xmm 3 va_sM) == xor_reverse_inc32lite_6 0 0 ctr_orig (va_get_xmm 15 va_sM))) /\ va_state_eq va_sM (va_update_mem_heaplet 3 va_sM (va_update_flags va_sM (va_update_xmm 15 va_sM (va_update_xmm 14 va_sM (va_update_xmm 13 va_sM (va_update_xmm 12 va_sM (va_update_xmm 11 va_sM (va_update_xmm 10 va_sM (va_update_xmm 9 va_sM (va_update_xmm 7 va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM (va_update_reg64 rR13 va_sM (va_update_reg64 rR12 va_sM (va_update_reg64 rR11 va_sM (va_update_reg64 rRsi va_sM (va_update_reg64 rRdi va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0)))))))))))))))))))))))))
let va_lemma_Loop6x_final va_b0 va_s0 alg iv_b scratch_b key_words round_keys keys_b ctr_orig init ctrs plain inb = let (va_mods:va_mods_t) = [va_Mod_mem_heaplet 3; va_Mod_flags; va_Mod_xmm 15; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR13; va_Mod_reg64 rR12; va_Mod_reg64 rR11; va_Mod_reg64 rRsi; va_Mod_reg64 rRdi; va_Mod_ok; va_Mod_mem] in let va_qc = va_qcode_Loop6x_final va_mods alg iv_b scratch_b key_words round_keys keys_b ctr_orig init ctrs plain inb in let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_Loop6x_final alg) va_qc va_s0 (fun va_s0 va_sM va_g -> let () = va_g in label va_range1 "***** POSTCONDITION NOT MET AT line 589 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_get_ok va_sM) /\ (label va_range1 "***** POSTCONDITION NOT MET AT line 649 column 72 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (Vale.X64.Decls.modifies_buffer_specific128 scratch_b (va_get_mem_heaplet 3 va_s0) (va_get_mem_heaplet 3 va_sM) 7 7) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 652 column 73 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (Vale.X64.Decls.buffer128_read scratch_b 7 (va_get_mem_heaplet 3 va_sM) == Vale.Def.Types_s.reverse_bytes_quad32 inb) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 654 column 111 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" ((va_get_xmm 9 va_sM, va_get_xmm 10 va_sM, va_get_xmm 11 va_sM, va_get_xmm 12 va_sM, va_get_xmm 13 va_sM, va_get_xmm 14 va_sM) == map2_six_of #quad32 #quad32 #quad32 plain ctrs (fun (p:quad32) (c:quad32) -> Vale.Def.Types_s.quad32_xor p (Vale.AES.AES_s.aes_encrypt_LE alg key_words c))) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 655 column 39 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_get_xmm 15 va_sM == FStar.Seq.Base.index #quad32 round_keys 0) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 657 column 33 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_get_reg64 rRdi va_sM == va_get_reg64 rRdi va_s0 + 96) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 658 column 33 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_get_reg64 rRsi va_sM == va_get_reg64 rRsi va_s0 + 96) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 660 column 41 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_get_xmm 2 va_sM == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 16777216) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 662 column 55 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_get_xmm 1 va_sM == Vale.X64.Decls.buffer128_read scratch_b 8 (va_get_mem_heaplet 3 va_s0)) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 663 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (let ctr = Vale.Def.Words_s.__proj__Mkfour__item__lo0 ctr_orig `op_Modulus` 256 in label va_range1 "***** POSTCONDITION NOT MET AT line 665 column 60 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (ctr + 6 < 256 ==> (va_get_xmm 1 va_sM, va_get_xmm 0 va_sM, va_get_xmm 5 va_sM, va_get_xmm 6 va_sM, va_get_xmm 7 va_sM, va_get_xmm 3 va_sM) == xor_reverse_inc32lite_6 0 0 ctr_orig (va_get_xmm 15 va_sM))))) in assert_norm (va_qc.mods == va_mods); va_lemma_norm_mods ([va_Mod_mem_heaplet 3; va_Mod_flags; va_Mod_xmm 15; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR13; va_Mod_reg64 rR12; va_Mod_reg64 rR11; va_Mod_reg64 rRsi; va_Mod_reg64 rRdi; va_Mod_ok; va_Mod_mem]) va_sM va_s0; (va_sM, va_fM)
{ "file_name": "obj/Vale.AES.X64.AESopt.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 16, "end_line": 1665, "start_col": 0, "start_line": 1616 }
module Vale.AES.X64.AESopt open FStar.Mul open Vale.Def.Prop_s open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open FStar.Seq open Vale.Arch.Types open Vale.Arch.HeapImpl open Vale.AES.AES_s open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.State open Vale.X64.Decls open Vale.X64.InsBasic open Vale.X64.InsMem open Vale.X64.InsVector open Vale.X64.InsAes open Vale.X64.QuickCode open Vale.X64.QuickCodes open Vale.AES.AES_helpers //open Vale.Poly1305.Math // For lemma_poly_bits64() open Vale.AES.GCM_helpers open Vale.AES.GCTR_s open Vale.AES.GCTR open Vale.Arch.TypesNative open Vale.X64.CPU_Features_s open Vale.Math.Poly2_s open Vale.AES.GF128_s open Vale.AES.GF128 open Vale.AES.GHash open Vale.AES.X64.PolyOps open Vale.AES.X64.AESopt2 open Vale.AES.X64.AESGCM_expected_code open Vale.Transformers.Transform open FStar.Mul let add = Vale.Math.Poly2_s.add #reset-options "--z3rlimit 30" //-- finish_aes_encrypt_le val finish_aes_encrypt_le : alg:algorithm -> input_LE:quad32 -> key:(seq nat32) -> Lemma (requires (Vale.AES.AES_s.is_aes_key_LE alg key)) (ensures (Vale.AES.AES_s.aes_encrypt_LE alg key input_LE == Vale.AES.AES_s.eval_cipher alg input_LE (Vale.AES.AES_s.key_to_round_keys_LE alg key))) let finish_aes_encrypt_le alg input_LE key = Vale.AES.AES_s.aes_encrypt_LE_reveal (); Vale.AES.AES_s.eval_cipher_reveal (); () //-- //-- Load_two_lsb [@ "opaque_to_smt"] let va_code_Load_two_lsb dst = (va_Block (va_CCons (va_code_ZeroXmm dst) (va_CCons (va_code_PinsrqImm dst 2 0 (va_op_reg_opr64_reg64 rR11)) (va_CNil ())))) [@ "opaque_to_smt"] let va_codegen_success_Load_two_lsb dst = (va_pbool_and (va_codegen_success_ZeroXmm dst) (va_pbool_and (va_codegen_success_PinsrqImm dst 2 0 (va_op_reg_opr64_reg64 rR11)) (va_ttrue ()))) [@"opaque_to_smt"] let va_lemma_Load_two_lsb va_b0 va_s0 dst = va_reveal_opaque (`%va_code_Load_two_lsb) (va_code_Load_two_lsb dst); let (va_old_s:va_state) = va_s0 in let (va_b1:va_codes) = va_get_block va_b0 in let (va_s3, va_fc3) = va_lemma_ZeroXmm (va_hd va_b1) va_s0 dst in let va_b3 = va_tl va_b1 in Vale.Arch.Types.lemma_insert_nat64_nat32s (va_eval_xmm va_s3 dst) 2 0; assert (Vale.Arch.Types.two_to_nat32 (Vale.Def.Words_s.Mktwo #Vale.Def.Words_s.nat32 2 0) == 2); let (va_s6, va_fc6) = va_lemma_PinsrqImm (va_hd va_b3) va_s3 dst 2 0 (va_op_reg_opr64_reg64 rR11) in let va_b6 = va_tl va_b3 in let (va_sM, va_f6) = va_lemma_empty_total va_s6 va_b6 in let va_f3 = va_lemma_merge_total va_b3 va_s3 va_fc6 va_s6 va_f6 va_sM in let va_fM = va_lemma_merge_total va_b1 va_s0 va_fc3 va_s3 va_f3 va_sM in (va_sM, va_fM) [@"opaque_to_smt"] let va_wpProof_Load_two_lsb dst va_s0 va_k = let (va_sM, va_f0) = va_lemma_Load_two_lsb (va_code_Load_two_lsb dst) va_s0 dst in va_lemma_upd_update va_sM; assert (va_state_eq va_sM (va_update_flags va_sM (va_update_reg64 rR11 va_sM (va_update_ok va_sM (va_update_operand_xmm dst va_sM va_s0))))); va_lemma_norm_mods ([va_Mod_flags; va_Mod_reg64 rR11; va_mod_xmm dst]) va_sM va_s0; let va_g = () in (va_sM, va_f0, va_g) //-- //-- Load_0xc2_msb val va_code_Load_0xc2_msb : dst:va_operand_xmm -> Tot va_code [@ "opaque_to_smt"] let va_code_Load_0xc2_msb dst = (va_Block (va_CCons (va_code_ZeroXmm dst) (va_CCons (va_code_PinsrqImm dst 13979173243358019584 1 (va_op_reg_opr64_reg64 rR11)) (va_CNil ())))) val va_codegen_success_Load_0xc2_msb : dst:va_operand_xmm -> Tot va_pbool [@ "opaque_to_smt"] let va_codegen_success_Load_0xc2_msb dst = (va_pbool_and (va_codegen_success_ZeroXmm dst) (va_pbool_and (va_codegen_success_PinsrqImm dst 13979173243358019584 1 (va_op_reg_opr64_reg64 rR11)) (va_ttrue ()))) val va_lemma_Load_0xc2_msb : va_b0:va_code -> va_s0:va_state -> dst:va_operand_xmm -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_Load_0xc2_msb dst) va_s0 /\ va_is_dst_xmm dst va_s0 /\ va_get_ok va_s0 /\ sse_enabled)) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_eval_xmm va_sM dst == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 3254779904 /\ va_state_eq va_sM (va_update_flags va_sM (va_update_reg64 rR11 va_sM (va_update_ok va_sM (va_update_operand_xmm dst va_sM va_s0)))))) [@"opaque_to_smt"] let va_lemma_Load_0xc2_msb va_b0 va_s0 dst = va_reveal_opaque (`%va_code_Load_0xc2_msb) (va_code_Load_0xc2_msb dst); let (va_old_s:va_state) = va_s0 in let (va_b1:va_codes) = va_get_block va_b0 in let (va_s3, va_fc3) = va_lemma_ZeroXmm (va_hd va_b1) va_s0 dst in let va_b3 = va_tl va_b1 in assert (Vale.Arch.Types.two_to_nat32 (Vale.Def.Words_s.Mktwo #Vale.Def.Words_s.nat32 0 3254779904) == 13979173243358019584); Vale.Arch.Types.lemma_insert_nat64_nat32s (va_eval_xmm va_s3 dst) 0 3254779904; let (va_s6, va_fc6) = va_lemma_PinsrqImm (va_hd va_b3) va_s3 dst 13979173243358019584 1 (va_op_reg_opr64_reg64 rR11) in let va_b6 = va_tl va_b3 in let (va_sM, va_f6) = va_lemma_empty_total va_s6 va_b6 in let va_f3 = va_lemma_merge_total va_b3 va_s3 va_fc6 va_s6 va_f6 va_sM in let va_fM = va_lemma_merge_total va_b1 va_s0 va_fc3 va_s3 va_f3 va_sM in (va_sM, va_fM) [@ va_qattr] let va_wp_Load_0xc2_msb (dst:va_operand_xmm) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_is_dst_xmm dst va_s0 /\ va_get_ok va_s0 /\ sse_enabled /\ (forall (va_x_dst:va_value_xmm) (va_x_r11:nat64) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_reg64 rR11 va_x_r11 (va_upd_operand_xmm dst va_x_dst va_s0)) in va_get_ok va_sM /\ va_eval_xmm va_sM dst == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 3254779904 ==> va_k va_sM (()))) val va_wpProof_Load_0xc2_msb : dst:va_operand_xmm -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_Load_0xc2_msb dst va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Load_0xc2_msb dst) ([va_Mod_flags; va_Mod_reg64 rR11; va_mod_xmm dst]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@"opaque_to_smt"] let va_wpProof_Load_0xc2_msb dst va_s0 va_k = let (va_sM, va_f0) = va_lemma_Load_0xc2_msb (va_code_Load_0xc2_msb dst) va_s0 dst in va_lemma_upd_update va_sM; assert (va_state_eq va_sM (va_update_flags va_sM (va_update_reg64 rR11 va_sM (va_update_ok va_sM (va_update_operand_xmm dst va_sM va_s0))))); va_lemma_norm_mods ([va_Mod_flags; va_Mod_reg64 rR11; va_mod_xmm dst]) va_sM va_s0; let va_g = () in (va_sM, va_f0, va_g) [@ "opaque_to_smt" va_qattr] let va_quick_Load_0xc2_msb (dst:va_operand_xmm) : (va_quickCode unit (va_code_Load_0xc2_msb dst)) = (va_QProc (va_code_Load_0xc2_msb dst) ([va_Mod_flags; va_Mod_reg64 rR11; va_mod_xmm dst]) (va_wp_Load_0xc2_msb dst) (va_wpProof_Load_0xc2_msb dst)) //-- //-- Load_one_lsb [@ "opaque_to_smt"] let va_code_Load_one_lsb dst = (va_Block (va_CCons (va_code_ZeroXmm dst) (va_CCons (va_code_PinsrqImm dst 1 0 (va_op_reg_opr64_reg64 rR11)) (va_CNil ())))) [@ "opaque_to_smt"] let va_codegen_success_Load_one_lsb dst = (va_pbool_and (va_codegen_success_ZeroXmm dst) (va_pbool_and (va_codegen_success_PinsrqImm dst 1 0 (va_op_reg_opr64_reg64 rR11)) (va_ttrue ()))) [@"opaque_to_smt"] let va_lemma_Load_one_lsb va_b0 va_s0 dst = va_reveal_opaque (`%va_code_Load_one_lsb) (va_code_Load_one_lsb dst); let (va_old_s:va_state) = va_s0 in let (va_b1:va_codes) = va_get_block va_b0 in let (va_s3, va_fc3) = va_lemma_ZeroXmm (va_hd va_b1) va_s0 dst in let va_b3 = va_tl va_b1 in Vale.Arch.Types.lemma_insert_nat64_nat32s (va_eval_xmm va_s3 dst) 1 0; assert (Vale.Arch.Types.two_to_nat32 (Vale.Def.Words_s.Mktwo #Vale.Def.Words_s.nat32 1 0) == 1); let (va_s6, va_fc6) = va_lemma_PinsrqImm (va_hd va_b3) va_s3 dst 1 0 (va_op_reg_opr64_reg64 rR11) in let va_b6 = va_tl va_b3 in let (va_sM, va_f6) = va_lemma_empty_total va_s6 va_b6 in let va_f3 = va_lemma_merge_total va_b3 va_s3 va_fc6 va_s6 va_f6 va_sM in let va_fM = va_lemma_merge_total va_b1 va_s0 va_fc3 va_s3 va_f3 va_sM in (va_sM, va_fM) [@"opaque_to_smt"] let va_wpProof_Load_one_lsb dst va_s0 va_k = let (va_sM, va_f0) = va_lemma_Load_one_lsb (va_code_Load_one_lsb dst) va_s0 dst in va_lemma_upd_update va_sM; assert (va_state_eq va_sM (va_update_flags va_sM (va_update_reg64 rR11 va_sM (va_update_ok va_sM (va_update_operand_xmm dst va_sM va_s0))))); va_lemma_norm_mods ([va_Mod_flags; va_Mod_reg64 rR11; va_mod_xmm dst]) va_sM va_s0; let va_g = () in (va_sM, va_f0, va_g) //-- //-- Handle_ctr32 val va_code_Handle_ctr32 : va_dummy:unit -> Tot va_code [@ "opaque_to_smt" va_qattr] let va_code_Handle_ctr32 () = (va_Block (va_CCons (va_code_InitPshufbMask (va_op_xmm_xmm 0) (va_op_reg_opr64_reg64 rR11)) (va_CCons (va_code_VPshufb (va_op_xmm_xmm 6) (va_op_xmm_xmm 1) (va_op_xmm_xmm 0)) (va_CCons (va_code_Load_one_lsb (va_op_xmm_xmm 5)) (va_CCons (va_code_VPaddd (va_op_xmm_xmm 10) (va_op_xmm_xmm 6) (va_op_xmm_xmm 5)) (va_CCons (va_code_Load_two_lsb (va_op_xmm_xmm 5)) (va_CCons (va_code_VPaddd (va_op_xmm_xmm 11) (va_op_xmm_xmm 6) (va_op_xmm_xmm 5)) (va_CCons (va_code_VPaddd (va_op_xmm_xmm 12) (va_op_xmm_xmm 10) (va_op_xmm_xmm 5)) (va_CCons (va_code_VPshufb (va_op_xmm_xmm 10) (va_op_xmm_xmm 10) (va_op_xmm_xmm 0)) (va_CCons (va_code_VPaddd (va_op_xmm_xmm 13) (va_op_xmm_xmm 11) (va_op_xmm_xmm 5)) (va_CCons (va_code_VPshufb (va_op_xmm_xmm 11) (va_op_xmm_xmm 11) (va_op_xmm_xmm 0)) (va_CCons (va_code_VPxor (va_op_xmm_xmm 10) (va_op_xmm_xmm 10) (va_op_opr128_xmm 15)) (va_CCons (va_code_VPaddd (va_op_xmm_xmm 14) (va_op_xmm_xmm 12) (va_op_xmm_xmm 5)) (va_CCons (va_code_VPshufb (va_op_xmm_xmm 12) (va_op_xmm_xmm 12) (va_op_xmm_xmm 0)) (va_CCons (va_code_VPxor (va_op_xmm_xmm 11) (va_op_xmm_xmm 11) (va_op_opr128_xmm 15)) (va_CCons (va_code_VPaddd (va_op_xmm_xmm 1) (va_op_xmm_xmm 13) (va_op_xmm_xmm 5)) (va_CCons (va_code_VPshufb (va_op_xmm_xmm 13) (va_op_xmm_xmm 13) (va_op_xmm_xmm 0)) (va_CCons (va_code_VPshufb (va_op_xmm_xmm 14) (va_op_xmm_xmm 14) (va_op_xmm_xmm 0)) (va_CCons (va_code_VPshufb (va_op_xmm_xmm 1) (va_op_xmm_xmm 1) (va_op_xmm_xmm 0)) (va_CNil ())))))))))))))))))))) val va_codegen_success_Handle_ctr32 : va_dummy:unit -> Tot va_pbool [@ "opaque_to_smt" va_qattr] let va_codegen_success_Handle_ctr32 () = (va_pbool_and (va_codegen_success_InitPshufbMask (va_op_xmm_xmm 0) (va_op_reg_opr64_reg64 rR11)) (va_pbool_and (va_codegen_success_VPshufb (va_op_xmm_xmm 6) (va_op_xmm_xmm 1) (va_op_xmm_xmm 0)) (va_pbool_and (va_codegen_success_Load_one_lsb (va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_VPaddd (va_op_xmm_xmm 10) (va_op_xmm_xmm 6) (va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_Load_two_lsb (va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_VPaddd (va_op_xmm_xmm 11) (va_op_xmm_xmm 6) (va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_VPaddd (va_op_xmm_xmm 12) (va_op_xmm_xmm 10) (va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_VPshufb (va_op_xmm_xmm 10) (va_op_xmm_xmm 10) (va_op_xmm_xmm 0)) (va_pbool_and (va_codegen_success_VPaddd (va_op_xmm_xmm 13) (va_op_xmm_xmm 11) (va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_VPshufb (va_op_xmm_xmm 11) (va_op_xmm_xmm 11) (va_op_xmm_xmm 0)) (va_pbool_and (va_codegen_success_VPxor (va_op_xmm_xmm 10) (va_op_xmm_xmm 10) (va_op_opr128_xmm 15)) (va_pbool_and (va_codegen_success_VPaddd (va_op_xmm_xmm 14) (va_op_xmm_xmm 12) (va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_VPshufb (va_op_xmm_xmm 12) (va_op_xmm_xmm 12) (va_op_xmm_xmm 0)) (va_pbool_and (va_codegen_success_VPxor (va_op_xmm_xmm 11) (va_op_xmm_xmm 11) (va_op_opr128_xmm 15)) (va_pbool_and (va_codegen_success_VPaddd (va_op_xmm_xmm 1) (va_op_xmm_xmm 13) (va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_VPshufb (va_op_xmm_xmm 13) (va_op_xmm_xmm 13) (va_op_xmm_xmm 0)) (va_pbool_and (va_codegen_success_VPshufb (va_op_xmm_xmm 14) (va_op_xmm_xmm 14) (va_op_xmm_xmm 0)) (va_pbool_and (va_codegen_success_VPshufb (va_op_xmm_xmm 1) (va_op_xmm_xmm 1) (va_op_xmm_xmm 0)) (va_ttrue ()))))))))))))))))))) [@ "opaque_to_smt" va_qattr] let va_qcode_Handle_ctr32 (va_mods:va_mods_t) (ctr_BE:quad32) : (va_quickCode unit (va_code_Handle_ctr32 ())) = (qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 256 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_InitPshufbMask (va_op_xmm_xmm 0) (va_op_reg_opr64_reg64 rR11)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 257 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPshufb (va_op_xmm_xmm 6) (va_op_xmm_xmm 1) (va_op_xmm_xmm 0)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 261 column 17 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_Load_one_lsb (va_op_xmm_xmm 5)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 262 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPaddd (va_op_xmm_xmm 10) (va_op_xmm_xmm 6) (va_op_xmm_xmm 5)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 263 column 17 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_Load_two_lsb (va_op_xmm_xmm 5)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 264 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPaddd (va_op_xmm_xmm 11) (va_op_xmm_xmm 6) (va_op_xmm_xmm 5)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 265 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPaddd (va_op_xmm_xmm 12) (va_op_xmm_xmm 10) (va_op_xmm_xmm 5)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 266 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPshufb (va_op_xmm_xmm 10) (va_op_xmm_xmm 10) (va_op_xmm_xmm 0)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 267 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPaddd (va_op_xmm_xmm 13) (va_op_xmm_xmm 11) (va_op_xmm_xmm 5)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 268 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPshufb (va_op_xmm_xmm 11) (va_op_xmm_xmm 11) (va_op_xmm_xmm 0)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 269 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPxor (va_op_xmm_xmm 10) (va_op_xmm_xmm 10) (va_op_opr128_xmm 15)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 270 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPaddd (va_op_xmm_xmm 14) (va_op_xmm_xmm 12) (va_op_xmm_xmm 5)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 271 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPshufb (va_op_xmm_xmm 12) (va_op_xmm_xmm 12) (va_op_xmm_xmm 0)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 272 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPxor (va_op_xmm_xmm 11) (va_op_xmm_xmm 11) (va_op_opr128_xmm 15)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 273 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPaddd (va_op_xmm_xmm 1) (va_op_xmm_xmm 13) (va_op_xmm_xmm 5)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 274 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPshufb (va_op_xmm_xmm 13) (va_op_xmm_xmm 13) (va_op_xmm_xmm 0)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 275 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPshufb (va_op_xmm_xmm 14) (va_op_xmm_xmm 14) (va_op_xmm_xmm 0)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 276 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPshufb (va_op_xmm_xmm 1) (va_op_xmm_xmm 1) (va_op_xmm_xmm 0)) (va_QEmpty (()))))))))))))))))))))) val va_lemma_Handle_ctr32 : va_b0:va_code -> va_s0:va_state -> ctr_BE:quad32 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_Handle_ctr32 ()) va_s0 /\ va_get_ok va_s0 /\ (avx_enabled /\ sse_enabled /\ va_get_xmm 1 va_s0 == Vale.Def.Types_s.reverse_bytes_quad32 ctr_BE))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (va_get_xmm 10 va_sM, va_get_xmm 11 va_sM, va_get_xmm 12 va_sM, va_get_xmm 13 va_sM, va_get_xmm 14 va_sM, va_get_xmm 1 va_sM) == xor_reverse_inc32lite_6 2 1 ctr_BE (va_get_xmm 15 va_sM) /\ va_state_eq va_sM (va_update_flags va_sM (va_update_xmm 14 va_sM (va_update_xmm 13 va_sM (va_update_xmm 12 va_sM (va_update_xmm 11 va_sM (va_update_xmm 10 va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM (va_update_reg64 rR11 va_sM (va_update_ok va_sM va_s0))))))))))))))) [@"opaque_to_smt"] let va_lemma_Handle_ctr32 va_b0 va_s0 ctr_BE = let (va_mods:va_mods_t) = [va_Mod_flags; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR11; va_Mod_ok] in let va_qc = va_qcode_Handle_ctr32 va_mods ctr_BE in let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_Handle_ctr32 ()) va_qc va_s0 (fun va_s0 va_sM va_g -> let () = va_g in label va_range1 "***** POSTCONDITION NOT MET AT line 234 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_get_ok va_sM) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 254 column 107 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" ((va_get_xmm 10 va_sM, va_get_xmm 11 va_sM, va_get_xmm 12 va_sM, va_get_xmm 13 va_sM, va_get_xmm 14 va_sM, va_get_xmm 1 va_sM) == xor_reverse_inc32lite_6 2 1 ctr_BE (va_get_xmm 15 va_sM))) in assert_norm (va_qc.mods == va_mods); va_lemma_norm_mods ([va_Mod_flags; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR11; va_Mod_ok]) va_sM va_s0; (va_sM, va_fM) [@ va_qattr] let va_wp_Handle_ctr32 (ctr_BE:quad32) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ (avx_enabled /\ sse_enabled /\ va_get_xmm 1 va_s0 == Vale.Def.Types_s.reverse_bytes_quad32 ctr_BE) /\ (forall (va_x_r11:nat64) (va_x_xmm0:quad32) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm5:quad32) (va_x_xmm6:quad32) (va_x_xmm10:quad32) (va_x_xmm11:quad32) (va_x_xmm12:quad32) (va_x_xmm13:quad32) (va_x_xmm14:quad32) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_xmm 14 va_x_xmm14 (va_upd_xmm 13 va_x_xmm13 (va_upd_xmm 12 va_x_xmm12 (va_upd_xmm 11 va_x_xmm11 (va_upd_xmm 10 va_x_xmm10 (va_upd_xmm 6 va_x_xmm6 (va_upd_xmm 5 va_x_xmm5 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_xmm 0 va_x_xmm0 (va_upd_reg64 rR11 va_x_r11 va_s0))))))))))) in va_get_ok va_sM /\ (va_get_xmm 10 va_sM, va_get_xmm 11 va_sM, va_get_xmm 12 va_sM, va_get_xmm 13 va_sM, va_get_xmm 14 va_sM, va_get_xmm 1 va_sM) == xor_reverse_inc32lite_6 2 1 ctr_BE (va_get_xmm 15 va_sM) ==> va_k va_sM (()))) val va_wpProof_Handle_ctr32 : ctr_BE:quad32 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_Handle_ctr32 ctr_BE va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Handle_ctr32 ()) ([va_Mod_flags; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR11]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@"opaque_to_smt"] let va_wpProof_Handle_ctr32 ctr_BE va_s0 va_k = let (va_sM, va_f0) = va_lemma_Handle_ctr32 (va_code_Handle_ctr32 ()) va_s0 ctr_BE in va_lemma_upd_update va_sM; assert (va_state_eq va_sM (va_update_flags va_sM (va_update_xmm 14 va_sM (va_update_xmm 13 va_sM (va_update_xmm 12 va_sM (va_update_xmm 11 va_sM (va_update_xmm 10 va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM (va_update_reg64 rR11 va_sM (va_update_ok va_sM va_s0)))))))))))))); va_lemma_norm_mods ([va_Mod_flags; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR11]) va_sM va_s0; let va_g = () in (va_sM, va_f0, va_g) [@ "opaque_to_smt" va_qattr] let va_quick_Handle_ctr32 (ctr_BE:quad32) : (va_quickCode unit (va_code_Handle_ctr32 ())) = (va_QProc (va_code_Handle_ctr32 ()) ([va_Mod_flags; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR11]) (va_wp_Handle_ctr32 ctr_BE) (va_wpProof_Handle_ctr32 ctr_BE)) //-- //-- Loop6x_ctr_update val va_code_Loop6x_ctr_update : alg:algorithm -> Tot va_code [@ "opaque_to_smt" va_qattr] let va_code_Loop6x_ctr_update alg = (va_Block (va_CCons (va_code_Add64 (va_op_dst_opr64_reg64 rRbx) (va_const_opr64 6)) (va_CCons (va_IfElse (va_cmp_ge (va_op_cmp_reg64 rRbx) (va_const_cmp 256)) (va_Block (va_CCons (va_code_Load128_buffer (va_op_heaplet_mem_heaplet 0) (va_op_xmm_xmm 3) (va_op_reg_opr64_reg64 rR9) (0 - 32) Secret) (va_CCons (va_code_Handle_ctr32 ()) (va_CCons (va_code_Sub64 (va_op_dst_opr64_reg64 rRbx) (va_const_opr64 256)) (va_CNil ()))))) (va_Block (va_CCons (va_code_Load128_buffer (va_op_heaplet_mem_heaplet 0) (va_op_xmm_xmm 3) (va_op_reg_opr64_reg64 rR9) (0 - 32) Secret) (va_CCons (va_code_VPaddd (va_op_xmm_xmm 1) (va_op_xmm_xmm 2) (va_op_xmm_xmm 14)) (va_CCons (va_code_VPxor (va_op_xmm_xmm 10) (va_op_xmm_xmm 10) (va_op_opr128_xmm 15)) (va_CCons (va_code_VPxor (va_op_xmm_xmm 11) (va_op_xmm_xmm 11) (va_op_opr128_xmm 15)) (va_CNil ()))))))) (va_CNil ())))) val va_codegen_success_Loop6x_ctr_update : alg:algorithm -> Tot va_pbool [@ "opaque_to_smt" va_qattr] let va_codegen_success_Loop6x_ctr_update alg = (va_pbool_and (va_codegen_success_Add64 (va_op_dst_opr64_reg64 rRbx) (va_const_opr64 6)) (va_pbool_and (va_pbool_and (va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 0) (va_op_xmm_xmm 3) (va_op_reg_opr64_reg64 rR9) (0 - 32) Secret) (va_pbool_and (va_codegen_success_Handle_ctr32 ()) (va_pbool_and (va_codegen_success_Sub64 (va_op_dst_opr64_reg64 rRbx) (va_const_opr64 256)) (va_pbool_and (va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 0) (va_op_xmm_xmm 3) (va_op_reg_opr64_reg64 rR9) (0 - 32) Secret) (va_pbool_and (va_codegen_success_VPaddd (va_op_xmm_xmm 1) (va_op_xmm_xmm 2) (va_op_xmm_xmm 14)) (va_pbool_and (va_codegen_success_VPxor (va_op_xmm_xmm 10) (va_op_xmm_xmm 10) (va_op_opr128_xmm 15)) (va_codegen_success_VPxor (va_op_xmm_xmm 11) (va_op_xmm_xmm 11) (va_op_opr128_xmm 15)))))))) (va_ttrue ()))) [@ "opaque_to_smt" va_qattr] let va_qcode_Loop6x_ctr_update (va_mods:va_mods_t) (alg:algorithm) (h_LE:quad32) (key_words:(seq nat32)) (round_keys:(seq quad32)) (keys_b:buffer128) (hkeys_b:buffer128) (ctr_BE:quad32) : (va_quickCode unit (va_code_Loop6x_ctr_update alg)) = (qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (Vale.Def.Types_s.reverse_bytes_quad32 h_LE) in va_QBind va_range1 "***** PRECONDITION NOT MET AT line 339 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_Add64 (va_op_dst_opr64_reg64 rRbx) (va_const_opr64 6)) (fun (va_s:va_state) _ -> va_QBind va_range1 "***** PRECONDITION NOT MET AT line 340 column 8 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_qIf va_mods (Cmp_ge (va_op_cmp_reg64 rRbx) (va_const_cmp 256)) (qblock va_mods (fun (va_s:va_state) -> va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 341 column 23 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_Load128_buffer (va_op_heaplet_mem_heaplet 0) (va_op_xmm_xmm 3) (va_op_reg_opr64_reg64 rR9) (0 - 32) Secret hkeys_b 0) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 342 column 21 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_Handle_ctr32 ctr_BE) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 343 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_Sub64 (va_op_dst_opr64_reg64 rRbx) (va_const_opr64 256)) (va_QEmpty (())))))) (qblock va_mods (fun (va_s:va_state) -> va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 345 column 23 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_Load128_buffer (va_op_heaplet_mem_heaplet 0) (va_op_xmm_xmm 3) (va_op_reg_opr64_reg64 rR9) (0 - 32) Secret hkeys_b 0) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 346 column 15 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPaddd (va_op_xmm_xmm 1) (va_op_xmm_xmm 2) (va_op_xmm_xmm 14)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 347 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPxor (va_op_xmm_xmm 10) (va_op_xmm_xmm 10) (va_op_opr128_xmm 15)) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 348 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPxor (va_op_xmm_xmm 11) (va_op_xmm_xmm 11) (va_op_opr128_xmm 15)) (fun (va_s:va_state) _ -> let (va_arg36:Prims.nat) = va_get_reg64 rRbx va_old_s in let (va_arg35:Vale.Def.Types_s.quad32) = va_get_xmm 1 va_s in let (va_arg34:Vale.Def.Types_s.quad32) = va_get_xmm 14 va_s in let (va_arg33:Vale.Def.Types_s.quad32) = ctr_BE in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 349 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (fun (_:unit) -> Vale.AES.AES_helpers.lemma_msb_in_bounds va_arg33 va_arg34 va_arg35 va_arg36) (va_QEmpty (()))))))))) (fun (va_s:va_state) va_g -> va_QEmpty (()))))) val va_lemma_Loop6x_ctr_update : va_b0:va_code -> va_s0:va_state -> alg:algorithm -> h_LE:quad32 -> key_words:(seq nat32) -> round_keys:(seq quad32) -> keys_b:buffer128 -> hkeys_b:buffer128 -> ctr_BE:quad32 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_Loop6x_ctr_update alg) va_s0 /\ va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (Vale.Def.Types_s.reverse_bytes_quad32 h_LE) in sse_enabled /\ aes_reqs_offset alg key_words round_keys keys_b (va_get_reg64 rRcx va_s0) (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0) /\ va_get_xmm 2 va_s0 == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 16777216 /\ va_get_xmm 1 va_s0 == Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.GCTR.inc32lite ctr_BE 0) /\ va_get_reg64 rRbx va_s0 == Vale.Def.Words_s.__proj__Mkfour__item__lo0 ctr_BE `op_Modulus` 256 /\ va_get_xmm 9 va_s0 == Vale.Def.Types_s.quad32_xor (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.GCTR.inc32lite ctr_BE 0)) (va_get_xmm 15 va_s0) /\ (va_get_reg64 rRbx va_s0 + 6 < 256 ==> (va_get_xmm 9 va_s0, va_get_xmm 10 va_s0, va_get_xmm 11 va_s0, va_get_xmm 12 va_s0, va_get_xmm 13 va_s0, va_get_xmm 14 va_s0) == xor_reverse_inc32lite_6 1 0 ctr_BE (va_get_xmm 15 va_s0)) /\ hkeys_b_powers hkeys_b (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0) (va_get_reg64 rR9 va_s0 - 32) h))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (Vale.Def.Types_s.reverse_bytes_quad32 h_LE) in va_get_xmm 1 va_sM == Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.GCTR.inc32lite ctr_BE 6) /\ (0 <= va_get_reg64 rRbx va_sM /\ va_get_reg64 rRbx va_sM < 256) /\ va_get_reg64 rRbx va_sM == Vale.Def.Words_s.__proj__Mkfour__item__lo0 (Vale.AES.GCTR.inc32lite ctr_BE 6) `op_Modulus` 256 /\ (va_get_xmm 9 va_sM, va_get_xmm 10 va_sM, va_get_xmm 11 va_sM, va_get_xmm 12 va_sM, va_get_xmm 13 va_sM, va_get_xmm 14 va_sM) == xor_reverse_inc32lite_6 3 0 ctr_BE (va_get_xmm 15 va_sM) /\ va_get_xmm 3 va_sM == Vale.X64.Decls.buffer128_read hkeys_b 0 (va_get_mem_heaplet 0 va_sM)) /\ va_state_eq va_sM (va_update_flags va_sM (va_update_xmm 14 va_sM (va_update_xmm 13 va_sM (va_update_xmm 12 va_sM (va_update_xmm 11 va_sM (va_update_xmm 10 va_sM (va_update_xmm 9 va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM (va_update_xmm 3 va_sM (va_update_reg64 rR11 va_sM (va_update_reg64 rRbx va_sM (va_update_ok va_sM va_s0)))))))))))))))))) [@"opaque_to_smt"] let va_lemma_Loop6x_ctr_update va_b0 va_s0 alg h_LE key_words round_keys keys_b hkeys_b ctr_BE = let (va_mods:va_mods_t) = [va_Mod_flags; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_xmm 3; va_Mod_reg64 rR11; va_Mod_reg64 rRbx; va_Mod_ok] in let va_qc = va_qcode_Loop6x_ctr_update va_mods alg h_LE key_words round_keys keys_b hkeys_b ctr_BE in let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_Loop6x_ctr_update alg) va_qc va_s0 (fun va_s0 va_sM va_g -> let () = va_g in label va_range1 "***** POSTCONDITION NOT MET AT line 279 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_get_ok va_sM) /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (Vale.Def.Types_s.reverse_bytes_quad32 h_LE) in label va_range1 "***** POSTCONDITION NOT MET AT line 330 column 57 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_get_xmm 1 va_sM == Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.GCTR.inc32lite ctr_BE 6)) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 331 column 27 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (0 <= va_get_reg64 rRbx va_sM /\ va_get_reg64 rRbx va_sM < 256) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 332 column 50 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_get_reg64 rRbx va_sM == Vale.Def.Words_s.__proj__Mkfour__item__lo0 (Vale.AES.GCTR.inc32lite ctr_BE 6) `op_Modulus` 256) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 334 column 58 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" ((va_get_xmm 9 va_sM, va_get_xmm 10 va_sM, va_get_xmm 11 va_sM, va_get_xmm 12 va_sM, va_get_xmm 13 va_sM, va_get_xmm 14 va_sM) == xor_reverse_inc32lite_6 3 0 ctr_BE (va_get_xmm 15 va_sM)) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 335 column 50 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_get_xmm 3 va_sM == Vale.X64.Decls.buffer128_read hkeys_b 0 (va_get_mem_heaplet 0 va_sM)))) in assert_norm (va_qc.mods == va_mods); va_lemma_norm_mods ([va_Mod_flags; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_xmm 3; va_Mod_reg64 rR11; va_Mod_reg64 rRbx; va_Mod_ok]) va_sM va_s0; (va_sM, va_fM) [@ va_qattr] let va_wp_Loop6x_ctr_update (alg:algorithm) (h_LE:quad32) (key_words:(seq nat32)) (round_keys:(seq quad32)) (keys_b:buffer128) (hkeys_b:buffer128) (ctr_BE:quad32) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (Vale.Def.Types_s.reverse_bytes_quad32 h_LE) in sse_enabled /\ aes_reqs_offset alg key_words round_keys keys_b (va_get_reg64 rRcx va_s0) (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0) /\ va_get_xmm 2 va_s0 == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 16777216 /\ va_get_xmm 1 va_s0 == Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.GCTR.inc32lite ctr_BE 0) /\ va_get_reg64 rRbx va_s0 == Vale.Def.Words_s.__proj__Mkfour__item__lo0 ctr_BE `op_Modulus` 256 /\ va_get_xmm 9 va_s0 == Vale.Def.Types_s.quad32_xor (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.GCTR.inc32lite ctr_BE 0)) (va_get_xmm 15 va_s0) /\ (va_get_reg64 rRbx va_s0 + 6 < 256 ==> (va_get_xmm 9 va_s0, va_get_xmm 10 va_s0, va_get_xmm 11 va_s0, va_get_xmm 12 va_s0, va_get_xmm 13 va_s0, va_get_xmm 14 va_s0) == xor_reverse_inc32lite_6 1 0 ctr_BE (va_get_xmm 15 va_s0)) /\ hkeys_b_powers hkeys_b (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0) (va_get_reg64 rR9 va_s0 - 32) h) /\ (forall (va_x_rbx:nat64) (va_x_r11:nat64) (va_x_xmm3:quad32) (va_x_xmm0:quad32) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm5:quad32) (va_x_xmm6:quad32) (va_x_xmm9:quad32) (va_x_xmm10:quad32) (va_x_xmm11:quad32) (va_x_xmm12:quad32) (va_x_xmm13:quad32) (va_x_xmm14:quad32) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_xmm 14 va_x_xmm14 (va_upd_xmm 13 va_x_xmm13 (va_upd_xmm 12 va_x_xmm12 (va_upd_xmm 11 va_x_xmm11 (va_upd_xmm 10 va_x_xmm10 (va_upd_xmm 9 va_x_xmm9 (va_upd_xmm 6 va_x_xmm6 (va_upd_xmm 5 va_x_xmm5 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_xmm 0 va_x_xmm0 (va_upd_xmm 3 va_x_xmm3 (va_upd_reg64 rR11 va_x_r11 (va_upd_reg64 rRbx va_x_rbx va_s0)))))))))))))) in va_get_ok va_sM /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (Vale.Def.Types_s.reverse_bytes_quad32 h_LE) in va_get_xmm 1 va_sM == Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.GCTR.inc32lite ctr_BE 6) /\ (0 <= va_get_reg64 rRbx va_sM /\ va_get_reg64 rRbx va_sM < 256) /\ va_get_reg64 rRbx va_sM == Vale.Def.Words_s.__proj__Mkfour__item__lo0 (Vale.AES.GCTR.inc32lite ctr_BE 6) `op_Modulus` 256 /\ (va_get_xmm 9 va_sM, va_get_xmm 10 va_sM, va_get_xmm 11 va_sM, va_get_xmm 12 va_sM, va_get_xmm 13 va_sM, va_get_xmm 14 va_sM) == xor_reverse_inc32lite_6 3 0 ctr_BE (va_get_xmm 15 va_sM) /\ va_get_xmm 3 va_sM == Vale.X64.Decls.buffer128_read hkeys_b 0 (va_get_mem_heaplet 0 va_sM)) ==> va_k va_sM (()))) val va_wpProof_Loop6x_ctr_update : alg:algorithm -> h_LE:quad32 -> key_words:(seq nat32) -> round_keys:(seq quad32) -> keys_b:buffer128 -> hkeys_b:buffer128 -> ctr_BE:quad32 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_Loop6x_ctr_update alg h_LE key_words round_keys keys_b hkeys_b ctr_BE va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Loop6x_ctr_update alg) ([va_Mod_flags; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_xmm 3; va_Mod_reg64 rR11; va_Mod_reg64 rRbx]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@"opaque_to_smt"] let va_wpProof_Loop6x_ctr_update alg h_LE key_words round_keys keys_b hkeys_b ctr_BE va_s0 va_k = let (va_sM, va_f0) = va_lemma_Loop6x_ctr_update (va_code_Loop6x_ctr_update alg) va_s0 alg h_LE key_words round_keys keys_b hkeys_b ctr_BE in va_lemma_upd_update va_sM; assert (va_state_eq va_sM (va_update_flags va_sM (va_update_xmm 14 va_sM (va_update_xmm 13 va_sM (va_update_xmm 12 va_sM (va_update_xmm 11 va_sM (va_update_xmm 10 va_sM (va_update_xmm 9 va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM (va_update_xmm 3 va_sM (va_update_reg64 rR11 va_sM (va_update_reg64 rRbx va_sM (va_update_ok va_sM va_s0))))))))))))))))); va_lemma_norm_mods ([va_Mod_flags; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_xmm 3; va_Mod_reg64 rR11; va_Mod_reg64 rRbx]) va_sM va_s0; let va_g = () in (va_sM, va_f0, va_g) [@ "opaque_to_smt" va_qattr] let va_quick_Loop6x_ctr_update (alg:algorithm) (h_LE:quad32) (key_words:(seq nat32)) (round_keys:(seq quad32)) (keys_b:buffer128) (hkeys_b:buffer128) (ctr_BE:quad32) : (va_quickCode unit (va_code_Loop6x_ctr_update alg)) = (va_QProc (va_code_Loop6x_ctr_update alg) ([va_Mod_flags; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_xmm 3; va_Mod_reg64 rR11; va_Mod_reg64 rRbx]) (va_wp_Loop6x_ctr_update alg h_LE key_words round_keys keys_b hkeys_b ctr_BE) (va_wpProof_Loop6x_ctr_update alg h_LE key_words round_keys keys_b hkeys_b ctr_BE)) //-- //-- Loop6x_plain val va_code_Loop6x_plain : alg:algorithm -> rnd:nat -> rndkey:va_operand_xmm -> Tot va_code [@ "opaque_to_smt"] let va_code_Loop6x_plain alg rnd rndkey = (va_Block (va_CCons (va_code_Load128_buffer (va_op_heaplet_mem_heaplet 0) rndkey (va_op_reg_opr64_reg64 rRcx) (16 `op_Multiply` (rnd + 1) - 128) Secret) (va_CCons (va_code_VAESNI_enc (va_op_xmm_xmm 9) (va_op_xmm_xmm 9) rndkey) (va_CCons (va_code_VAESNI_enc (va_op_xmm_xmm 10) (va_op_xmm_xmm 10) rndkey) (va_CCons (va_code_VAESNI_enc (va_op_xmm_xmm 11) (va_op_xmm_xmm 11) rndkey) (va_CCons (va_code_VAESNI_enc (va_op_xmm_xmm 12) (va_op_xmm_xmm 12) rndkey) (va_CCons (va_code_VAESNI_enc (va_op_xmm_xmm 13) (va_op_xmm_xmm 13) rndkey) (va_CCons (va_code_VAESNI_enc (va_op_xmm_xmm 14) (va_op_xmm_xmm 14) rndkey) (va_CNil ()))))))))) val va_codegen_success_Loop6x_plain : alg:algorithm -> rnd:nat -> rndkey:va_operand_xmm -> Tot va_pbool [@ "opaque_to_smt"] let va_codegen_success_Loop6x_plain alg rnd rndkey = (va_pbool_and (va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 0) rndkey (va_op_reg_opr64_reg64 rRcx) (16 `op_Multiply` (rnd + 1) - 128) Secret) (va_pbool_and (va_codegen_success_VAESNI_enc (va_op_xmm_xmm 9) (va_op_xmm_xmm 9) rndkey) (va_pbool_and (va_codegen_success_VAESNI_enc (va_op_xmm_xmm 10) (va_op_xmm_xmm 10) rndkey) (va_pbool_and (va_codegen_success_VAESNI_enc (va_op_xmm_xmm 11) (va_op_xmm_xmm 11) rndkey) (va_pbool_and (va_codegen_success_VAESNI_enc (va_op_xmm_xmm 12) (va_op_xmm_xmm 12) rndkey) (va_pbool_and (va_codegen_success_VAESNI_enc (va_op_xmm_xmm 13) (va_op_xmm_xmm 13) rndkey) (va_pbool_and (va_codegen_success_VAESNI_enc (va_op_xmm_xmm 14) (va_op_xmm_xmm 14) rndkey) (va_ttrue ())))))))) val va_lemma_Loop6x_plain : va_b0:va_code -> va_s0:va_state -> alg:algorithm -> rnd:nat -> key_words:(seq nat32) -> round_keys:(seq quad32) -> keys_b:buffer128 -> init:quad32_6 -> rndkey:va_operand_xmm -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_Loop6x_plain alg rnd rndkey) va_s0 /\ va_is_dst_xmm rndkey va_s0 /\ va_get_ok va_s0 /\ (sse_enabled /\ (rndkey == 1 \/ rndkey == 2 \/ rndkey == 15) /\ aes_reqs_offset alg key_words round_keys keys_b (va_get_reg64 rRcx va_s0) (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0) /\ rnd + 1 < FStar.Seq.Base.length #quad32 round_keys /\ (va_get_xmm 9 va_s0, va_get_xmm 10 va_s0, va_get_xmm 11 va_s0, va_get_xmm 12 va_s0, va_get_xmm 13 va_s0, va_get_xmm 14 va_s0) == rounds_opaque_6 init round_keys rnd))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (va_get_xmm 9 va_sM, va_get_xmm 10 va_sM, va_get_xmm 11 va_sM, va_get_xmm 12 va_sM, va_get_xmm 13 va_sM, va_get_xmm 14 va_sM) == rounds_opaque_6 init round_keys (rnd + 1) /\ va_state_eq va_sM (va_update_flags va_sM (va_update_xmm 14 va_sM (va_update_xmm 13 va_sM (va_update_xmm 12 va_sM (va_update_xmm 11 va_sM (va_update_xmm 10 va_sM (va_update_xmm 9 va_sM (va_update_ok va_sM (va_update_operand_xmm rndkey va_sM va_s0))))))))))) [@"opaque_to_smt"] let va_lemma_Loop6x_plain va_b0 va_s0 alg rnd key_words round_keys keys_b init rndkey = va_reveal_opaque (`%va_code_Loop6x_plain) (va_code_Loop6x_plain alg rnd rndkey); let (va_old_s:va_state) = va_s0 in let (va_b1:va_codes) = va_get_block va_b0 in let (va_s9, va_fc9) = va_lemma_Load128_buffer (va_hd va_b1) va_s0 (va_op_heaplet_mem_heaplet 0) rndkey (va_op_reg_opr64_reg64 rRcx) (16 `op_Multiply` (rnd + 1) - 128) Secret keys_b (rnd + 1) in let va_b9 = va_tl va_b1 in let (va_s10, va_fc10) = va_lemma_VAESNI_enc (va_hd va_b9) va_s9 (va_op_xmm_xmm 9) (va_op_xmm_xmm 9) rndkey in let va_b10 = va_tl va_b9 in let (va_s11, va_fc11) = va_lemma_VAESNI_enc (va_hd va_b10) va_s10 (va_op_xmm_xmm 10) (va_op_xmm_xmm 10) rndkey in let va_b11 = va_tl va_b10 in let (va_s12, va_fc12) = va_lemma_VAESNI_enc (va_hd va_b11) va_s11 (va_op_xmm_xmm 11) (va_op_xmm_xmm 11) rndkey in let va_b12 = va_tl va_b11 in let (va_s13, va_fc13) = va_lemma_VAESNI_enc (va_hd va_b12) va_s12 (va_op_xmm_xmm 12) (va_op_xmm_xmm 12) rndkey in let va_b13 = va_tl va_b12 in let (va_s14, va_fc14) = va_lemma_VAESNI_enc (va_hd va_b13) va_s13 (va_op_xmm_xmm 13) (va_op_xmm_xmm 13) rndkey in let va_b14 = va_tl va_b13 in let (va_s15, va_fc15) = va_lemma_VAESNI_enc (va_hd va_b14) va_s14 (va_op_xmm_xmm 14) (va_op_xmm_xmm 14) rndkey in let va_b15 = va_tl va_b14 in Vale.AES.AES_s.eval_rounds_reveal (); Vale.AES.AES_helpers.commute_sub_bytes_shift_rows_forall (); let (va_sM, va_f15) = va_lemma_empty_total va_s15 va_b15 in let va_f14 = va_lemma_merge_total va_b14 va_s14 va_fc15 va_s15 va_f15 va_sM in let va_f13 = va_lemma_merge_total va_b13 va_s13 va_fc14 va_s14 va_f14 va_sM in let va_f12 = va_lemma_merge_total va_b12 va_s12 va_fc13 va_s13 va_f13 va_sM in let va_f11 = va_lemma_merge_total va_b11 va_s11 va_fc12 va_s12 va_f12 va_sM in let va_f10 = va_lemma_merge_total va_b10 va_s10 va_fc11 va_s11 va_f11 va_sM in let va_f9 = va_lemma_merge_total va_b9 va_s9 va_fc10 va_s10 va_f10 va_sM in let va_fM = va_lemma_merge_total va_b1 va_s0 va_fc9 va_s9 va_f9 va_sM in (va_sM, va_fM) [@ va_qattr] let va_wp_Loop6x_plain (alg:algorithm) (rnd:nat) (key_words:(seq nat32)) (round_keys:(seq quad32)) (keys_b:buffer128) (init:quad32_6) (rndkey:va_operand_xmm) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_is_dst_xmm rndkey va_s0 /\ va_get_ok va_s0 /\ (sse_enabled /\ (rndkey == 1 \/ rndkey == 2 \/ rndkey == 15) /\ aes_reqs_offset alg key_words round_keys keys_b (va_get_reg64 rRcx va_s0) (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0) /\ rnd + 1 < FStar.Seq.Base.length #quad32 round_keys /\ (va_get_xmm 9 va_s0, va_get_xmm 10 va_s0, va_get_xmm 11 va_s0, va_get_xmm 12 va_s0, va_get_xmm 13 va_s0, va_get_xmm 14 va_s0) == rounds_opaque_6 init round_keys rnd) /\ (forall (va_x_rndkey:va_value_xmm) (va_x_xmm9:quad32) (va_x_xmm10:quad32) (va_x_xmm11:quad32) (va_x_xmm12:quad32) (va_x_xmm13:quad32) (va_x_xmm14:quad32) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_xmm 14 va_x_xmm14 (va_upd_xmm 13 va_x_xmm13 (va_upd_xmm 12 va_x_xmm12 (va_upd_xmm 11 va_x_xmm11 (va_upd_xmm 10 va_x_xmm10 (va_upd_xmm 9 va_x_xmm9 (va_upd_operand_xmm rndkey va_x_rndkey va_s0))))))) in va_get_ok va_sM /\ (va_get_xmm 9 va_sM, va_get_xmm 10 va_sM, va_get_xmm 11 va_sM, va_get_xmm 12 va_sM, va_get_xmm 13 va_sM, va_get_xmm 14 va_sM) == rounds_opaque_6 init round_keys (rnd + 1) ==> va_k va_sM (()))) val va_wpProof_Loop6x_plain : alg:algorithm -> rnd:nat -> key_words:(seq nat32) -> round_keys:(seq quad32) -> keys_b:buffer128 -> init:quad32_6 -> rndkey:va_operand_xmm -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_Loop6x_plain alg rnd key_words round_keys keys_b init rndkey va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Loop6x_plain alg rnd rndkey) ([va_Mod_flags; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9; va_mod_xmm rndkey]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@"opaque_to_smt"] let va_wpProof_Loop6x_plain alg rnd key_words round_keys keys_b init rndkey va_s0 va_k = let (va_sM, va_f0) = va_lemma_Loop6x_plain (va_code_Loop6x_plain alg rnd rndkey) va_s0 alg rnd key_words round_keys keys_b init rndkey in va_lemma_upd_update va_sM; assert (va_state_eq va_sM (va_update_flags va_sM (va_update_xmm 14 va_sM (va_update_xmm 13 va_sM (va_update_xmm 12 va_sM (va_update_xmm 11 va_sM (va_update_xmm 10 va_sM (va_update_xmm 9 va_sM (va_update_ok va_sM (va_update_operand_xmm rndkey va_sM va_s0)))))))))); va_lemma_norm_mods ([va_Mod_flags; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9; va_mod_xmm rndkey]) va_sM va_s0; let va_g = () in (va_sM, va_f0, va_g) [@ "opaque_to_smt" va_qattr] let va_quick_Loop6x_plain (alg:algorithm) (rnd:nat) (key_words:(seq nat32)) (round_keys:(seq quad32)) (keys_b:buffer128) (init:quad32_6) (rndkey:va_operand_xmm) : (va_quickCode unit (va_code_Loop6x_plain alg rnd rndkey)) = (va_QProc (va_code_Loop6x_plain alg rnd rndkey) ([va_Mod_flags; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9; va_mod_xmm rndkey]) (va_wp_Loop6x_plain alg rnd key_words round_keys keys_b init rndkey) (va_wpProof_Loop6x_plain alg rnd key_words round_keys keys_b init rndkey)) //-- //-- Loop6x_preamble val va_code_Loop6x_preamble : alg:algorithm -> Tot va_code [@ "opaque_to_smt" va_qattr] let va_code_Loop6x_preamble alg = (va_Block (va_CCons (va_code_Loop6x_ctr_update alg) (va_CCons (va_code_Store128_buffer (va_op_heaplet_mem_heaplet 3) (va_op_reg_opr64_reg64 rRbp) (va_op_xmm_xmm 1) 128 Secret) (va_CCons (va_code_VPxor (va_op_xmm_xmm 12) (va_op_xmm_xmm 12) (va_op_opr128_xmm 15)) (va_CCons (va_code_VPxor (va_op_xmm_xmm 13) (va_op_xmm_xmm 13) (va_op_opr128_xmm 15)) (va_CCons (va_code_VPxor (va_op_xmm_xmm 14) (va_op_xmm_xmm 14) (va_op_opr128_xmm 15)) (va_CNil ()))))))) val va_codegen_success_Loop6x_preamble : alg:algorithm -> Tot va_pbool [@ "opaque_to_smt" va_qattr] let va_codegen_success_Loop6x_preamble alg = (va_pbool_and (va_codegen_success_Loop6x_ctr_update alg) (va_pbool_and (va_codegen_success_Store128_buffer (va_op_heaplet_mem_heaplet 3) (va_op_reg_opr64_reg64 rRbp) (va_op_xmm_xmm 1) 128 Secret) (va_pbool_and (va_codegen_success_VPxor (va_op_xmm_xmm 12) (va_op_xmm_xmm 12) (va_op_opr128_xmm 15)) (va_pbool_and (va_codegen_success_VPxor (va_op_xmm_xmm 13) (va_op_xmm_xmm 13) (va_op_opr128_xmm 15)) (va_pbool_and (va_codegen_success_VPxor (va_op_xmm_xmm 14) (va_op_xmm_xmm 14) (va_op_opr128_xmm 15)) (va_ttrue ())))))) [@ "opaque_to_smt" va_qattr] let va_qcode_Loop6x_preamble (va_mods:va_mods_t) (alg:algorithm) (h_LE:quad32) (iv_b:buffer128) (scratch_b:buffer128) (key_words:(seq nat32)) (round_keys:(seq quad32)) (keys_b:buffer128) (hkeys_b:buffer128) (ctr_BE:quad32) : (va_quickCode unit (va_code_Loop6x_preamble alg)) = (qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (Vale.Def.Types_s.reverse_bytes_quad32 h_LE) in va_QBind va_range1 "***** PRECONDITION NOT MET AT line 477 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_Loop6x_ctr_update alg h_LE key_words round_keys keys_b hkeys_b ctr_BE) (fun (va_s:va_state) _ -> let (va_arg43:(FStar.Seq.Base.seq Vale.Def.Types_s.quad32)) = round_keys in let (va_arg42:Vale.Def.Types_s.quad32) = va_get_xmm 9 va_s in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 479 column 23 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (fun (_:unit) -> Vale.AES.AES_helpers.init_rounds_opaque va_arg42 va_arg43) (let (va_arg41:(FStar.Seq.Base.seq Vale.Def.Types_s.quad32)) = round_keys in let (va_arg40:Vale.Def.Types_s.quad32) = va_get_xmm 10 va_s in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 480 column 23 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (fun (_:unit) -> Vale.AES.AES_helpers.init_rounds_opaque va_arg40 va_arg41) (let (va_arg39:(FStar.Seq.Base.seq Vale.Def.Types_s.quad32)) = round_keys in let (va_arg38:Vale.Def.Types_s.quad32) = va_get_xmm 11 va_s in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 481 column 23 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (fun (_:unit) -> Vale.AES.AES_helpers.init_rounds_opaque va_arg38 va_arg39) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 498 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_Store128_buffer (va_op_heaplet_mem_heaplet 3) (va_op_reg_opr64_reg64 rRbp) (va_op_xmm_xmm 1) 128 Secret scratch_b 8) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 499 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPxor (va_op_xmm_xmm 12) (va_op_xmm_xmm 12) (va_op_opr128_xmm 15)) (fun (va_s:va_state) _ -> let (va_arg37:(FStar.Seq.Base.seq Vale.Def.Types_s.quad32)) = round_keys in let (va_arg36:Vale.Def.Types_s.quad32) = va_get_xmm 12 va_s in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 499 column 54 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (fun (_:unit) -> Vale.AES.AES_helpers.init_rounds_opaque va_arg36 va_arg37) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 500 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPxor (va_op_xmm_xmm 13) (va_op_xmm_xmm 13) (va_op_opr128_xmm 15)) (fun (va_s:va_state) _ -> let (va_arg35:(FStar.Seq.Base.seq Vale.Def.Types_s.quad32)) = round_keys in let (va_arg34:Vale.Def.Types_s.quad32) = va_get_xmm 13 va_s in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 500 column 54 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (fun (_:unit) -> Vale.AES.AES_helpers.init_rounds_opaque va_arg34 va_arg35) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 501 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPxor (va_op_xmm_xmm 14) (va_op_xmm_xmm 14) (va_op_opr128_xmm 15)) (fun (va_s:va_state) _ -> let (va_arg33:(FStar.Seq.Base.seq Vale.Def.Types_s.quad32)) = round_keys in let (va_arg32:Vale.Def.Types_s.quad32) = va_get_xmm 14 va_s in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 501 column 54 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (fun (_:unit) -> Vale.AES.AES_helpers.init_rounds_opaque va_arg32 va_arg33) (va_QEmpty (())))))))))))))) val va_lemma_Loop6x_preamble : va_b0:va_code -> va_s0:va_state -> alg:algorithm -> h_LE:quad32 -> iv_b:buffer128 -> scratch_b:buffer128 -> key_words:(seq nat32) -> round_keys:(seq quad32) -> keys_b:buffer128 -> hkeys_b:buffer128 -> ctr_BE:quad32 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_Loop6x_preamble alg) va_s0 /\ va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (Vale.Def.Types_s.reverse_bytes_quad32 h_LE) in sse_enabled /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 3 va_s0) (va_get_reg64 rRbp va_s0) scratch_b 9 (va_get_mem_layout va_s0) Secret /\ aes_reqs_offset alg key_words round_keys keys_b (va_get_reg64 rRcx va_s0) (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0) /\ va_get_xmm 15 va_s0 == FStar.Seq.Base.index #quad32 round_keys 0 /\ va_get_xmm 2 va_s0 == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 16777216 /\ va_get_xmm 1 va_s0 == Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.GCTR.inc32lite ctr_BE 0) /\ va_get_reg64 rRbx va_s0 == Vale.Def.Words_s.__proj__Mkfour__item__lo0 ctr_BE `op_Modulus` 256 /\ va_get_xmm 9 va_s0 == Vale.Def.Types_s.quad32_xor (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.GCTR.inc32lite ctr_BE 0)) (va_get_xmm 15 va_s0) /\ (va_get_reg64 rRbx va_s0 + 6 < 256 ==> (va_get_xmm 9 va_s0, va_get_xmm 10 va_s0, va_get_xmm 11 va_s0, va_get_xmm 12 va_s0, va_get_xmm 13 va_s0, va_get_xmm 14 va_s0) == xor_reverse_inc32lite_6 1 0 ctr_BE (va_get_xmm 15 va_s0)) /\ hkeys_b_powers hkeys_b (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0) (va_get_reg64 rR9 va_s0 - 32) h))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (Vale.Def.Types_s.reverse_bytes_quad32 h_LE) in Vale.X64.Decls.modifies_buffer_specific128 scratch_b (va_get_mem_heaplet 3 va_s0) (va_get_mem_heaplet 3 va_sM) 8 8 /\ (let init = make_six_of #Vale.Def.Types_s.quad32 (fun (n:(va_int_range 0 5)) -> Vale.Def.Types_s.quad32_xor (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.GCTR.inc32lite ctr_BE n)) (va_get_xmm 15 va_sM)) in (va_get_xmm 9 va_sM, va_get_xmm 10 va_sM, va_get_xmm 11 va_sM, va_get_xmm 12 va_sM, va_get_xmm 13 va_sM, va_get_xmm 14 va_sM) == rounds_opaque_6 init round_keys 0 /\ Vale.X64.Decls.buffer128_read scratch_b 8 (va_get_mem_heaplet 3 va_sM) == Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.GCTR.inc32lite ctr_BE 6) /\ (0 <= va_get_reg64 rRbx va_sM /\ va_get_reg64 rRbx va_sM < 256) /\ va_get_reg64 rRbx va_sM == Vale.Def.Words_s.__proj__Mkfour__item__lo0 (Vale.AES.GCTR.inc32lite ctr_BE 6) `op_Modulus` 256 /\ va_get_xmm 3 va_sM == Vale.X64.Decls.buffer128_read hkeys_b 0 (va_get_mem_heaplet 0 va_s0))) /\ va_state_eq va_sM (va_update_flags va_sM (va_update_mem_heaplet 3 va_sM (va_update_xmm 14 va_sM (va_update_xmm 13 va_sM (va_update_xmm 12 va_sM (va_update_xmm 11 va_sM (va_update_xmm 10 va_sM (va_update_xmm 9 va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM (va_update_xmm 3 va_sM (va_update_reg64 rR11 va_sM (va_update_reg64 rRbx va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0)))))))))))))))))))) [@"opaque_to_smt"] let va_lemma_Loop6x_preamble va_b0 va_s0 alg h_LE iv_b scratch_b key_words round_keys keys_b hkeys_b ctr_BE = let (va_mods:va_mods_t) = [va_Mod_flags; va_Mod_mem_heaplet 3; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_xmm 3; va_Mod_reg64 rR11; va_Mod_reg64 rRbx; va_Mod_ok; va_Mod_mem] in let va_qc = va_qcode_Loop6x_preamble va_mods alg h_LE iv_b scratch_b key_words round_keys keys_b hkeys_b ctr_BE in let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_Loop6x_preamble alg) va_qc va_s0 (fun va_s0 va_sM va_g -> let () = va_g in label va_range1 "***** POSTCONDITION NOT MET AT line 402 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_get_ok va_sM) /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (Vale.Def.Types_s.reverse_bytes_quad32 h_LE) in label va_range1 "***** POSTCONDITION NOT MET AT line 459 column 72 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (Vale.X64.Decls.modifies_buffer_specific128 scratch_b (va_get_mem_heaplet 3 va_s0) (va_get_mem_heaplet 3 va_sM) 8 8) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 464 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (let init = make_six_of #Vale.Def.Types_s.quad32 (fun (n:(va_int_range 0 5)) -> Vale.Def.Types_s.quad32_xor (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.GCTR.inc32lite ctr_BE n)) (va_get_xmm 15 va_sM)) in label va_range1 "***** POSTCONDITION NOT MET AT line 466 column 102 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" ((va_get_xmm 9 va_sM, va_get_xmm 10 va_sM, va_get_xmm 11 va_sM, va_get_xmm 12 va_sM, va_get_xmm 13 va_sM, va_get_xmm 14 va_sM) == rounds_opaque_6 init round_keys 0) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 469 column 90 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (Vale.X64.Decls.buffer128_read scratch_b 8 (va_get_mem_heaplet 3 va_sM) == Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.GCTR.inc32lite ctr_BE 6)) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 472 column 27 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (0 <= va_get_reg64 rRbx va_sM /\ va_get_reg64 rRbx va_sM < 256) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 473 column 50 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_get_reg64 rRbx va_sM == Vale.Def.Words_s.__proj__Mkfour__item__lo0 (Vale.AES.GCTR.inc32lite ctr_BE 6) `op_Modulus` 256) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 475 column 55 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_get_xmm 3 va_sM == Vale.X64.Decls.buffer128_read hkeys_b 0 (va_get_mem_heaplet 0 va_s0))))) in assert_norm (va_qc.mods == va_mods); va_lemma_norm_mods ([va_Mod_flags; va_Mod_mem_heaplet 3; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_xmm 3; va_Mod_reg64 rR11; va_Mod_reg64 rRbx; va_Mod_ok; va_Mod_mem]) va_sM va_s0; (va_sM, va_fM) [@ va_qattr] let va_wp_Loop6x_preamble (alg:algorithm) (h_LE:quad32) (iv_b:buffer128) (scratch_b:buffer128) (key_words:(seq nat32)) (round_keys:(seq quad32)) (keys_b:buffer128) (hkeys_b:buffer128) (ctr_BE:quad32) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (Vale.Def.Types_s.reverse_bytes_quad32 h_LE) in sse_enabled /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 3 va_s0) (va_get_reg64 rRbp va_s0) scratch_b 9 (va_get_mem_layout va_s0) Secret /\ aes_reqs_offset alg key_words round_keys keys_b (va_get_reg64 rRcx va_s0) (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0) /\ va_get_xmm 15 va_s0 == FStar.Seq.Base.index #quad32 round_keys 0 /\ va_get_xmm 2 va_s0 == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 16777216 /\ va_get_xmm 1 va_s0 == Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.GCTR.inc32lite ctr_BE 0) /\ va_get_reg64 rRbx va_s0 == Vale.Def.Words_s.__proj__Mkfour__item__lo0 ctr_BE `op_Modulus` 256 /\ va_get_xmm 9 va_s0 == Vale.Def.Types_s.quad32_xor (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.GCTR.inc32lite ctr_BE 0)) (va_get_xmm 15 va_s0) /\ (va_get_reg64 rRbx va_s0 + 6 < 256 ==> (va_get_xmm 9 va_s0, va_get_xmm 10 va_s0, va_get_xmm 11 va_s0, va_get_xmm 12 va_s0, va_get_xmm 13 va_s0, va_get_xmm 14 va_s0) == xor_reverse_inc32lite_6 1 0 ctr_BE (va_get_xmm 15 va_s0)) /\ hkeys_b_powers hkeys_b (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0) (va_get_reg64 rR9 va_s0 - 32) h) /\ (forall (va_x_mem:vale_heap) (va_x_rbx:nat64) (va_x_r11:nat64) (va_x_xmm3:quad32) (va_x_xmm0:quad32) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm5:quad32) (va_x_xmm6:quad32) (va_x_xmm9:quad32) (va_x_xmm10:quad32) (va_x_xmm11:quad32) (va_x_xmm12:quad32) (va_x_xmm13:quad32) (va_x_xmm14:quad32) (va_x_heap3:vale_heap) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_mem_heaplet 3 va_x_heap3 (va_upd_xmm 14 va_x_xmm14 (va_upd_xmm 13 va_x_xmm13 (va_upd_xmm 12 va_x_xmm12 (va_upd_xmm 11 va_x_xmm11 (va_upd_xmm 10 va_x_xmm10 (va_upd_xmm 9 va_x_xmm9 (va_upd_xmm 6 va_x_xmm6 (va_upd_xmm 5 va_x_xmm5 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_xmm 0 va_x_xmm0 (va_upd_xmm 3 va_x_xmm3 (va_upd_reg64 rR11 va_x_r11 (va_upd_reg64 rRbx va_x_rbx (va_upd_mem va_x_mem va_s0)))))))))))))))) in va_get_ok va_sM /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (Vale.Def.Types_s.reverse_bytes_quad32 h_LE) in Vale.X64.Decls.modifies_buffer_specific128 scratch_b (va_get_mem_heaplet 3 va_s0) (va_get_mem_heaplet 3 va_sM) 8 8 /\ (let init = make_six_of #Vale.Def.Types_s.quad32 (fun (n:(va_int_range 0 5)) -> Vale.Def.Types_s.quad32_xor (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.GCTR.inc32lite ctr_BE n)) (va_get_xmm 15 va_sM)) in (va_get_xmm 9 va_sM, va_get_xmm 10 va_sM, va_get_xmm 11 va_sM, va_get_xmm 12 va_sM, va_get_xmm 13 va_sM, va_get_xmm 14 va_sM) == rounds_opaque_6 init round_keys 0 /\ Vale.X64.Decls.buffer128_read scratch_b 8 (va_get_mem_heaplet 3 va_sM) == Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.GCTR.inc32lite ctr_BE 6) /\ (0 <= va_get_reg64 rRbx va_sM /\ va_get_reg64 rRbx va_sM < 256) /\ va_get_reg64 rRbx va_sM == Vale.Def.Words_s.__proj__Mkfour__item__lo0 (Vale.AES.GCTR.inc32lite ctr_BE 6) `op_Modulus` 256 /\ va_get_xmm 3 va_sM == Vale.X64.Decls.buffer128_read hkeys_b 0 (va_get_mem_heaplet 0 va_s0))) ==> va_k va_sM (()))) val va_wpProof_Loop6x_preamble : alg:algorithm -> h_LE:quad32 -> iv_b:buffer128 -> scratch_b:buffer128 -> key_words:(seq nat32) -> round_keys:(seq quad32) -> keys_b:buffer128 -> hkeys_b:buffer128 -> ctr_BE:quad32 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_Loop6x_preamble alg h_LE iv_b scratch_b key_words round_keys keys_b hkeys_b ctr_BE va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Loop6x_preamble alg) ([va_Mod_flags; va_Mod_mem_heaplet 3; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_xmm 3; va_Mod_reg64 rR11; va_Mod_reg64 rRbx; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@"opaque_to_smt"] let va_wpProof_Loop6x_preamble alg h_LE iv_b scratch_b key_words round_keys keys_b hkeys_b ctr_BE va_s0 va_k = let (va_sM, va_f0) = va_lemma_Loop6x_preamble (va_code_Loop6x_preamble alg) va_s0 alg h_LE iv_b scratch_b key_words round_keys keys_b hkeys_b ctr_BE in va_lemma_upd_update va_sM; assert (va_state_eq va_sM (va_update_flags va_sM (va_update_mem_heaplet 3 va_sM (va_update_xmm 14 va_sM (va_update_xmm 13 va_sM (va_update_xmm 12 va_sM (va_update_xmm 11 va_sM (va_update_xmm 10 va_sM (va_update_xmm 9 va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM (va_update_xmm 3 va_sM (va_update_reg64 rR11 va_sM (va_update_reg64 rRbx va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0))))))))))))))))))); va_lemma_norm_mods ([va_Mod_flags; va_Mod_mem_heaplet 3; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_xmm 3; va_Mod_reg64 rR11; va_Mod_reg64 rRbx; va_Mod_mem]) va_sM va_s0; let va_g = () in (va_sM, va_f0, va_g) [@ "opaque_to_smt" va_qattr] let va_quick_Loop6x_preamble (alg:algorithm) (h_LE:quad32) (iv_b:buffer128) (scratch_b:buffer128) (key_words:(seq nat32)) (round_keys:(seq quad32)) (keys_b:buffer128) (hkeys_b:buffer128) (ctr_BE:quad32) : (va_quickCode unit (va_code_Loop6x_preamble alg)) = (va_QProc (va_code_Loop6x_preamble alg) ([va_Mod_flags; va_Mod_mem_heaplet 3; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_xmm 3; va_Mod_reg64 rR11; va_Mod_reg64 rRbx; va_Mod_mem]) (va_wp_Loop6x_preamble alg h_LE iv_b scratch_b key_words round_keys keys_b hkeys_b ctr_BE) (va_wpProof_Loop6x_preamble alg h_LE iv_b scratch_b key_words round_keys keys_b hkeys_b ctr_BE)) //-- //-- Loop6x_reverse128 val va_code_Loop6x_reverse128 : in0_offset:nat -> stack_offset:nat -> Tot va_code [@ "opaque_to_smt" va_qattr] let va_code_Loop6x_reverse128 in0_offset stack_offset = (va_Block (va_CCons (va_code_LoadBe64_buffer128 (va_op_heaplet_mem_heaplet 6) (va_op_reg_opr64_reg64 rR13) (va_op_reg_opr64_reg64 rR14) (in0_offset `op_Multiply` 16 + 8) Secret true) (va_CCons (va_code_LoadBe64_buffer128 (va_op_heaplet_mem_heaplet 6) (va_op_reg_opr64_reg64 rR12) (va_op_reg_opr64_reg64 rR14) (in0_offset `op_Multiply` 16) Secret false) (va_CCons (va_code_Store64_buffer128 (va_op_heaplet_mem_heaplet 3) (va_op_reg_opr64_reg64 rRbp) (va_op_reg_opr64_reg64 rR13) (stack_offset `op_Multiply` 16) Secret false) (va_CCons (va_code_Store64_buffer128 (va_op_heaplet_mem_heaplet 3) (va_op_reg_opr64_reg64 rRbp) (va_op_reg_opr64_reg64 rR12) (stack_offset `op_Multiply` 16 + 8) Secret true) (va_CNil ())))))) val va_codegen_success_Loop6x_reverse128 : in0_offset:nat -> stack_offset:nat -> Tot va_pbool [@ "opaque_to_smt" va_qattr] let va_codegen_success_Loop6x_reverse128 in0_offset stack_offset = (va_pbool_and (va_codegen_success_LoadBe64_buffer128 (va_op_heaplet_mem_heaplet 6) (va_op_reg_opr64_reg64 rR13) (va_op_reg_opr64_reg64 rR14) (in0_offset `op_Multiply` 16 + 8) Secret true) (va_pbool_and (va_codegen_success_LoadBe64_buffer128 (va_op_heaplet_mem_heaplet 6) (va_op_reg_opr64_reg64 rR12) (va_op_reg_opr64_reg64 rR14) (in0_offset `op_Multiply` 16) Secret false) (va_pbool_and (va_codegen_success_Store64_buffer128 (va_op_heaplet_mem_heaplet 3) (va_op_reg_opr64_reg64 rRbp) (va_op_reg_opr64_reg64 rR13) (stack_offset `op_Multiply` 16) Secret false) (va_pbool_and (va_codegen_success_Store64_buffer128 (va_op_heaplet_mem_heaplet 3) (va_op_reg_opr64_reg64 rRbp) (va_op_reg_opr64_reg64 rR12) (stack_offset `op_Multiply` 16 + 8) Secret true) (va_ttrue ()))))) [@ "opaque_to_smt" va_qattr] let va_qcode_Loop6x_reverse128 (va_mods:va_mods_t) (in0_offset:nat) (stack_offset:nat) (start:nat) (in0_b:buffer128) (scratch_b:buffer128) : (va_quickCode unit (va_code_Loop6x_reverse128 in0_offset stack_offset)) = (qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 527 column 23 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_LoadBe64_buffer128 (va_op_heaplet_mem_heaplet 6) (va_op_reg_opr64_reg64 rR13) (va_op_reg_opr64_reg64 rR14) (in0_offset `op_Multiply` 16 + 8) Secret true in0_b (start + in0_offset)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 528 column 23 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_LoadBe64_buffer128 (va_op_heaplet_mem_heaplet 6) (va_op_reg_opr64_reg64 rR12) (va_op_reg_opr64_reg64 rR14) (in0_offset `op_Multiply` 16) Secret false in0_b (start + in0_offset)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 529 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_Store64_buffer128 (va_op_heaplet_mem_heaplet 3) (va_op_reg_opr64_reg64 rRbp) (va_op_reg_opr64_reg64 rR13) (stack_offset `op_Multiply` 16) Secret false scratch_b stack_offset) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 530 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_Store64_buffer128 (va_op_heaplet_mem_heaplet 3) (va_op_reg_opr64_reg64 rRbp) (va_op_reg_opr64_reg64 rR12) (stack_offset `op_Multiply` 16 + 8) Secret true scratch_b stack_offset) (fun (va_s:va_state) _ -> let (va_arg10:Vale.Def.Types_s.quad32) = Vale.X64.Decls.buffer128_read scratch_b stack_offset (va_get_mem_heaplet 3 va_s) in let (va_arg9:Vale.Def.Types_s.quad32) = Vale.X64.Decls.buffer128_read scratch_b stack_offset (va_get_mem_heaplet 3 va_old_s) in let (va_arg8:Vale.Def.Types_s.quad32) = Vale.X64.Decls.buffer128_read in0_b (start + in0_offset) (va_get_mem_heaplet 6 va_old_s) in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 531 column 34 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (fun (_:unit) -> Vale.Arch.Types.lemma_reverse_bytes_quad32_64 va_arg8 va_arg9 va_arg10) (va_QEmpty (())))))))) val va_lemma_Loop6x_reverse128 : va_b0:va_code -> va_s0:va_state -> in0_offset:nat -> stack_offset:nat -> start:nat -> in0_b:buffer128 -> scratch_b:buffer128 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_Loop6x_reverse128 in0_offset stack_offset) va_s0 /\ va_get_ok va_s0 /\ (sse_enabled /\ movbe_enabled /\ Vale.X64.Decls.validSrcAddrsOffset128 (va_get_mem_heaplet 6 va_s0) (va_get_reg64 rR14 va_s0) in0_b start (in0_offset + 1) (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 3 va_s0) (va_get_reg64 rRbp va_s0) scratch_b (stack_offset + 1) (va_get_mem_layout va_s0) Secret))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (Vale.X64.Decls.modifies_buffer_specific128 scratch_b (va_get_mem_heaplet 3 va_s0) (va_get_mem_heaplet 3 va_sM) stack_offset stack_offset /\ Vale.X64.Decls.buffer128_read scratch_b stack_offset (va_get_mem_heaplet 3 va_sM) == Vale.Def.Types_s.reverse_bytes_quad32 (Vale.X64.Decls.buffer128_read in0_b (start + in0_offset) (va_get_mem_heaplet 6 va_s0))) /\ va_state_eq va_sM (va_update_mem_heaplet 3 va_sM (va_update_reg64 rR13 va_sM (va_update_reg64 rR12 va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0))))))) [@"opaque_to_smt"] let va_lemma_Loop6x_reverse128 va_b0 va_s0 in0_offset stack_offset start in0_b scratch_b = let (va_mods:va_mods_t) = [va_Mod_mem_heaplet 3; va_Mod_reg64 rR13; va_Mod_reg64 rR12; va_Mod_ok; va_Mod_mem] in let va_qc = va_qcode_Loop6x_reverse128 va_mods in0_offset stack_offset start in0_b scratch_b in let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_Loop6x_reverse128 in0_offset stack_offset) va_qc va_s0 (fun va_s0 va_sM va_g -> let () = va_g in label va_range1 "***** POSTCONDITION NOT MET AT line 504 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_get_ok va_sM) /\ (label va_range1 "***** POSTCONDITION NOT MET AT line 523 column 94 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (Vale.X64.Decls.modifies_buffer_specific128 scratch_b (va_get_mem_heaplet 3 va_s0) (va_get_mem_heaplet 3 va_sM) stack_offset stack_offset) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 525 column 88 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (Vale.X64.Decls.buffer128_read scratch_b stack_offset (va_get_mem_heaplet 3 va_sM) == Vale.Def.Types_s.reverse_bytes_quad32 (Vale.X64.Decls.buffer128_read in0_b (start + in0_offset) (va_get_mem_heaplet 6 va_s0))))) in assert_norm (va_qc.mods == va_mods); va_lemma_norm_mods ([va_Mod_mem_heaplet 3; va_Mod_reg64 rR13; va_Mod_reg64 rR12; va_Mod_ok; va_Mod_mem]) va_sM va_s0; (va_sM, va_fM) [@ va_qattr] let va_wp_Loop6x_reverse128 (in0_offset:nat) (stack_offset:nat) (start:nat) (in0_b:buffer128) (scratch_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ (sse_enabled /\ movbe_enabled /\ Vale.X64.Decls.validSrcAddrsOffset128 (va_get_mem_heaplet 6 va_s0) (va_get_reg64 rR14 va_s0) in0_b start (in0_offset + 1) (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 3 va_s0) (va_get_reg64 rRbp va_s0) scratch_b (stack_offset + 1) (va_get_mem_layout va_s0) Secret) /\ (forall (va_x_mem:vale_heap) (va_x_r12:nat64) (va_x_r13:nat64) (va_x_heap3:vale_heap) . let va_sM = va_upd_mem_heaplet 3 va_x_heap3 (va_upd_reg64 rR13 va_x_r13 (va_upd_reg64 rR12 va_x_r12 (va_upd_mem va_x_mem va_s0))) in va_get_ok va_sM /\ (Vale.X64.Decls.modifies_buffer_specific128 scratch_b (va_get_mem_heaplet 3 va_s0) (va_get_mem_heaplet 3 va_sM) stack_offset stack_offset /\ Vale.X64.Decls.buffer128_read scratch_b stack_offset (va_get_mem_heaplet 3 va_sM) == Vale.Def.Types_s.reverse_bytes_quad32 (Vale.X64.Decls.buffer128_read in0_b (start + in0_offset) (va_get_mem_heaplet 6 va_s0))) ==> va_k va_sM (()))) val va_wpProof_Loop6x_reverse128 : in0_offset:nat -> stack_offset:nat -> start:nat -> in0_b:buffer128 -> scratch_b:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_Loop6x_reverse128 in0_offset stack_offset start in0_b scratch_b va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Loop6x_reverse128 in0_offset stack_offset) ([va_Mod_mem_heaplet 3; va_Mod_reg64 rR13; va_Mod_reg64 rR12; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@"opaque_to_smt"] let va_wpProof_Loop6x_reverse128 in0_offset stack_offset start in0_b scratch_b va_s0 va_k = let (va_sM, va_f0) = va_lemma_Loop6x_reverse128 (va_code_Loop6x_reverse128 in0_offset stack_offset) va_s0 in0_offset stack_offset start in0_b scratch_b in va_lemma_upd_update va_sM; assert (va_state_eq va_sM (va_update_mem_heaplet 3 va_sM (va_update_reg64 rR13 va_sM (va_update_reg64 rR12 va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0)))))); va_lemma_norm_mods ([va_Mod_mem_heaplet 3; va_Mod_reg64 rR13; va_Mod_reg64 rR12; va_Mod_mem]) va_sM va_s0; let va_g = () in (va_sM, va_f0, va_g) [@ "opaque_to_smt" va_qattr] let va_quick_Loop6x_reverse128 (in0_offset:nat) (stack_offset:nat) (start:nat) (in0_b:buffer128) (scratch_b:buffer128) : (va_quickCode unit (va_code_Loop6x_reverse128 in0_offset stack_offset)) = (va_QProc (va_code_Loop6x_reverse128 in0_offset stack_offset) ([va_Mod_mem_heaplet 3; va_Mod_reg64 rR13; va_Mod_reg64 rR12; va_Mod_mem]) (va_wp_Loop6x_reverse128 in0_offset stack_offset start in0_b scratch_b) (va_wpProof_Loop6x_reverse128 in0_offset stack_offset start in0_b scratch_b)) //-- //-- Loop6x_round9 val va_code_Loop6x_round9 : alg:algorithm -> Tot va_code [@ "opaque_to_smt" va_qattr] let va_code_Loop6x_round9 alg = (va_Block (va_CCons (va_code_Store128_buffer (va_op_heaplet_mem_heaplet 3) (va_op_reg_opr64_reg64 rRbp) (va_op_xmm_xmm 7) 16 Secret) (va_CCons (va_code_Mem128_lemma ()) (va_CCons (va_code_VPxor (va_op_xmm_xmm 2) (va_op_xmm_xmm 1) (va_opr_code_Mem128 (va_op_heaplet_mem_heaplet 6) (va_op_reg64_reg64 rRdi) 0 Secret)) (va_CCons (va_code_Mem128_lemma ()) (va_CCons (va_code_VPxor (va_op_xmm_xmm 0) (va_op_xmm_xmm 1) (va_opr_code_Mem128 (va_op_heaplet_mem_heaplet 6) (va_op_reg64_reg64 rRdi) 16 Secret)) (va_CCons (va_code_Mem128_lemma ()) (va_CCons (va_code_VPxor (va_op_xmm_xmm 5) (va_op_xmm_xmm 1) (va_opr_code_Mem128 (va_op_heaplet_mem_heaplet 6) (va_op_reg64_reg64 rRdi) 32 Secret)) (va_CCons (va_code_Mem128_lemma ()) (va_CCons (va_code_VPxor (va_op_xmm_xmm 6) (va_op_xmm_xmm 1) (va_opr_code_Mem128 (va_op_heaplet_mem_heaplet 6) (va_op_reg64_reg64 rRdi) 48 Secret)) (va_CCons (va_code_Mem128_lemma ()) (va_CCons (va_code_VPxor (va_op_xmm_xmm 7) (va_op_xmm_xmm 1) (va_opr_code_Mem128 (va_op_heaplet_mem_heaplet 6) (va_op_reg64_reg64 rRdi) 64 Secret)) (va_CCons (va_code_Mem128_lemma ()) (va_CCons (va_code_VPxor (va_op_xmm_xmm 3) (va_op_xmm_xmm 1) (va_opr_code_Mem128 (va_op_heaplet_mem_heaplet 6) (va_op_reg64_reg64 rRdi) 80 Secret)) (va_CNil ()))))))))))))))) val va_codegen_success_Loop6x_round9 : alg:algorithm -> Tot va_pbool [@ "opaque_to_smt" va_qattr] let va_codegen_success_Loop6x_round9 alg = (va_pbool_and (va_codegen_success_Store128_buffer (va_op_heaplet_mem_heaplet 3) (va_op_reg_opr64_reg64 rRbp) (va_op_xmm_xmm 7) 16 Secret) (va_pbool_and (va_codegen_success_Mem128_lemma ()) (va_pbool_and (va_codegen_success_VPxor (va_op_xmm_xmm 2) (va_op_xmm_xmm 1) (va_opr_code_Mem128 (va_op_heaplet_mem_heaplet 6) (va_op_reg64_reg64 rRdi) 0 Secret)) (va_pbool_and (va_codegen_success_Mem128_lemma ()) (va_pbool_and (va_codegen_success_VPxor (va_op_xmm_xmm 0) (va_op_xmm_xmm 1) (va_opr_code_Mem128 (va_op_heaplet_mem_heaplet 6) (va_op_reg64_reg64 rRdi) 16 Secret)) (va_pbool_and (va_codegen_success_Mem128_lemma ()) (va_pbool_and (va_codegen_success_VPxor (va_op_xmm_xmm 5) (va_op_xmm_xmm 1) (va_opr_code_Mem128 (va_op_heaplet_mem_heaplet 6) (va_op_reg64_reg64 rRdi) 32 Secret)) (va_pbool_and (va_codegen_success_Mem128_lemma ()) (va_pbool_and (va_codegen_success_VPxor (va_op_xmm_xmm 6) (va_op_xmm_xmm 1) (va_opr_code_Mem128 (va_op_heaplet_mem_heaplet 6) (va_op_reg64_reg64 rRdi) 48 Secret)) (va_pbool_and (va_codegen_success_Mem128_lemma ()) (va_pbool_and (va_codegen_success_VPxor (va_op_xmm_xmm 7) (va_op_xmm_xmm 1) (va_opr_code_Mem128 (va_op_heaplet_mem_heaplet 6) (va_op_reg64_reg64 rRdi) 64 Secret)) (va_pbool_and (va_codegen_success_Mem128_lemma ()) (va_pbool_and (va_codegen_success_VPxor (va_op_xmm_xmm 3) (va_op_xmm_xmm 1) (va_opr_code_Mem128 (va_op_heaplet_mem_heaplet 6) (va_op_reg64_reg64 rRdi) 80 Secret)) (va_ttrue ())))))))))))))) [@ "opaque_to_smt" va_qattr] let va_qcode_Loop6x_round9 (va_mods:va_mods_t) (alg:algorithm) (count:nat) (in_b:buffer128) (scratch_b:buffer128) (key_words:(seq nat32)) (round_keys:(seq quad32)) (keys_b:buffer128) : (va_quickCode unit (va_code_Loop6x_round9 alg)) = (qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 567 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_Store128_buffer (va_op_heaplet_mem_heaplet 3) (va_op_reg_opr64_reg64 rRbp) (va_op_xmm_xmm 7) 16 Secret scratch_b 1) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 568 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_Mem128_lemma (va_op_heaplet_mem_heaplet 6) (va_op_reg64_reg64 rRdi) 0 Secret in_b (count `op_Multiply` 6 + 0)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 568 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPxor (va_op_xmm_xmm 2) (va_op_xmm_xmm 1) (va_opr_code_Mem128 (va_op_heaplet_mem_heaplet 6) (va_op_reg64_reg64 rRdi) 0 Secret)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 569 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_Mem128_lemma (va_op_heaplet_mem_heaplet 6) (va_op_reg64_reg64 rRdi) 16 Secret in_b (count `op_Multiply` 6 + 1)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 569 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPxor (va_op_xmm_xmm 0) (va_op_xmm_xmm 1) (va_opr_code_Mem128 (va_op_heaplet_mem_heaplet 6) (va_op_reg64_reg64 rRdi) 16 Secret)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 570 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_Mem128_lemma (va_op_heaplet_mem_heaplet 6) (va_op_reg64_reg64 rRdi) 32 Secret in_b (count `op_Multiply` 6 + 2)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 570 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPxor (va_op_xmm_xmm 5) (va_op_xmm_xmm 1) (va_opr_code_Mem128 (va_op_heaplet_mem_heaplet 6) (va_op_reg64_reg64 rRdi) 32 Secret)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 571 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_Mem128_lemma (va_op_heaplet_mem_heaplet 6) (va_op_reg64_reg64 rRdi) 48 Secret in_b (count `op_Multiply` 6 + 3)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 571 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPxor (va_op_xmm_xmm 6) (va_op_xmm_xmm 1) (va_opr_code_Mem128 (va_op_heaplet_mem_heaplet 6) (va_op_reg64_reg64 rRdi) 48 Secret)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 572 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_Mem128_lemma (va_op_heaplet_mem_heaplet 6) (va_op_reg64_reg64 rRdi) 64 Secret in_b (count `op_Multiply` 6 + 4)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 572 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPxor (va_op_xmm_xmm 7) (va_op_xmm_xmm 1) (va_opr_code_Mem128 (va_op_heaplet_mem_heaplet 6) (va_op_reg64_reg64 rRdi) 64 Secret)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 573 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_Mem128_lemma (va_op_heaplet_mem_heaplet 6) (va_op_reg64_reg64 rRdi) 80 Secret in_b (count `op_Multiply` 6 + 5)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 573 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPxor (va_op_xmm_xmm 3) (va_op_xmm_xmm 1) (va_opr_code_Mem128 (va_op_heaplet_mem_heaplet 6) (va_op_reg64_reg64 rRdi) 80 Secret)) (va_QEmpty (())))))))))))))))) val va_lemma_Loop6x_round9 : va_b0:va_code -> va_s0:va_state -> alg:algorithm -> count:nat -> in_b:buffer128 -> scratch_b:buffer128 -> key_words:(seq nat32) -> round_keys:(seq quad32) -> keys_b:buffer128 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_Loop6x_round9 alg) va_s0 /\ va_get_ok va_s0 /\ (sse_enabled /\ Vale.X64.Decls.validSrcAddrsOffset128 (va_get_mem_heaplet 6 va_s0) (va_get_reg64 rRdi va_s0) in_b (count `op_Multiply` 6) 6 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 3 va_s0) (va_get_reg64 rRbp va_s0) scratch_b 8 (va_get_mem_layout va_s0) Secret /\ aes_reqs_offset alg key_words round_keys keys_b (va_get_reg64 rRcx va_s0) (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0) /\ va_get_xmm 1 va_s0 == Vale.X64.Decls.buffer128_read keys_b (Vale.AES.AES_common_s.nr alg) (va_get_mem_heaplet 0 va_s0)))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (Vale.X64.Decls.modifies_buffer_specific128 scratch_b (va_get_mem_heaplet 3 va_s0) (va_get_mem_heaplet 3 va_sM) 1 1 /\ (va_get_xmm 2 va_sM, va_get_xmm 0 va_sM, va_get_xmm 5 va_sM, va_get_xmm 6 va_sM, va_get_xmm 7 va_sM, va_get_xmm 3 va_sM) == make_six_of #quad32 (fun (i:(va_int_range 0 5)) -> Vale.Def.Types_s.quad32_xor (FStar.Seq.Base.index #Vale.Def.Types_s.quad32 round_keys (Vale.AES.AES_common_s.nr alg)) (Vale.X64.Decls.buffer128_read in_b (count `op_Multiply` 6 + i) (va_get_mem_heaplet 6 va_sM))) /\ Vale.X64.Decls.buffer128_read scratch_b 1 (va_get_mem_heaplet 3 va_sM) == va_get_xmm 7 va_s0) /\ va_state_eq va_sM (va_update_mem_heaplet 3 va_sM (va_update_flags va_sM (va_update_xmm 7 va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0))))))))))))) [@"opaque_to_smt"] let va_lemma_Loop6x_round9 va_b0 va_s0 alg count in_b scratch_b key_words round_keys keys_b = let (va_mods:va_mods_t) = [va_Mod_mem_heaplet 3; va_Mod_flags; va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_ok; va_Mod_mem] in let va_qc = va_qcode_Loop6x_round9 va_mods alg count in_b scratch_b key_words round_keys keys_b in let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_Loop6x_round9 alg) va_qc va_s0 (fun va_s0 va_sM va_g -> let () = va_g in label va_range1 "***** POSTCONDITION NOT MET AT line 535 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_get_ok va_sM) /\ (label va_range1 "***** POSTCONDITION NOT MET AT line 561 column 72 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (Vale.X64.Decls.modifies_buffer_specific128 scratch_b (va_get_mem_heaplet 3 va_s0) (va_get_mem_heaplet 3 va_sM) 1 1) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 563 column 102 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" ((va_get_xmm 2 va_sM, va_get_xmm 0 va_sM, va_get_xmm 5 va_sM, va_get_xmm 6 va_sM, va_get_xmm 7 va_sM, va_get_xmm 3 va_sM) == make_six_of #quad32 (fun (i:(va_int_range 0 5)) -> Vale.Def.Types_s.quad32_xor (FStar.Seq.Base.index #Vale.Def.Types_s.quad32 round_keys (Vale.AES.AES_common_s.nr alg)) (Vale.X64.Decls.buffer128_read in_b (count `op_Multiply` 6 + i) (va_get_mem_heaplet 6 va_sM)))) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 564 column 55 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (Vale.X64.Decls.buffer128_read scratch_b 1 (va_get_mem_heaplet 3 va_sM) == va_get_xmm 7 va_s0))) in assert_norm (va_qc.mods == va_mods); va_lemma_norm_mods ([va_Mod_mem_heaplet 3; va_Mod_flags; va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_ok; va_Mod_mem]) va_sM va_s0; (va_sM, va_fM) [@ va_qattr] let va_wp_Loop6x_round9 (alg:algorithm) (count:nat) (in_b:buffer128) (scratch_b:buffer128) (key_words:(seq nat32)) (round_keys:(seq quad32)) (keys_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ (sse_enabled /\ Vale.X64.Decls.validSrcAddrsOffset128 (va_get_mem_heaplet 6 va_s0) (va_get_reg64 rRdi va_s0) in_b (count `op_Multiply` 6) 6 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 3 va_s0) (va_get_reg64 rRbp va_s0) scratch_b 8 (va_get_mem_layout va_s0) Secret /\ aes_reqs_offset alg key_words round_keys keys_b (va_get_reg64 rRcx va_s0) (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0) /\ va_get_xmm 1 va_s0 == Vale.X64.Decls.buffer128_read keys_b (Vale.AES.AES_common_s.nr alg) (va_get_mem_heaplet 0 va_s0)) /\ (forall (va_x_mem:vale_heap) (va_x_xmm0:quad32) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32) (va_x_xmm5:quad32) (va_x_xmm6:quad32) (va_x_xmm7:quad32) (va_x_efl:Vale.X64.Flags.t) (va_x_heap3:vale_heap) . let va_sM = va_upd_mem_heaplet 3 va_x_heap3 (va_upd_flags va_x_efl (va_upd_xmm 7 va_x_xmm7 (va_upd_xmm 6 va_x_xmm6 (va_upd_xmm 5 va_x_xmm5 (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_xmm 0 va_x_xmm0 (va_upd_mem va_x_mem va_s0))))))))) in va_get_ok va_sM /\ (Vale.X64.Decls.modifies_buffer_specific128 scratch_b (va_get_mem_heaplet 3 va_s0) (va_get_mem_heaplet 3 va_sM) 1 1 /\ (va_get_xmm 2 va_sM, va_get_xmm 0 va_sM, va_get_xmm 5 va_sM, va_get_xmm 6 va_sM, va_get_xmm 7 va_sM, va_get_xmm 3 va_sM) == make_six_of #quad32 (fun (i:(va_int_range 0 5)) -> Vale.Def.Types_s.quad32_xor (FStar.Seq.Base.index #Vale.Def.Types_s.quad32 round_keys (Vale.AES.AES_common_s.nr alg)) (Vale.X64.Decls.buffer128_read in_b (count `op_Multiply` 6 + i) (va_get_mem_heaplet 6 va_sM))) /\ Vale.X64.Decls.buffer128_read scratch_b 1 (va_get_mem_heaplet 3 va_sM) == va_get_xmm 7 va_s0) ==> va_k va_sM (()))) val va_wpProof_Loop6x_round9 : alg:algorithm -> count:nat -> in_b:buffer128 -> scratch_b:buffer128 -> key_words:(seq nat32) -> round_keys:(seq quad32) -> keys_b:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_Loop6x_round9 alg count in_b scratch_b key_words round_keys keys_b va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Loop6x_round9 alg) ([va_Mod_mem_heaplet 3; va_Mod_flags; va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@"opaque_to_smt"] let va_wpProof_Loop6x_round9 alg count in_b scratch_b key_words round_keys keys_b va_s0 va_k = let (va_sM, va_f0) = va_lemma_Loop6x_round9 (va_code_Loop6x_round9 alg) va_s0 alg count in_b scratch_b key_words round_keys keys_b in va_lemma_upd_update va_sM; assert (va_state_eq va_sM (va_update_mem_heaplet 3 va_sM (va_update_flags va_sM (va_update_xmm 7 va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0)))))))))))); va_lemma_norm_mods ([va_Mod_mem_heaplet 3; va_Mod_flags; va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_mem]) va_sM va_s0; let va_g = () in (va_sM, va_f0, va_g) [@ "opaque_to_smt" va_qattr] let va_quick_Loop6x_round9 (alg:algorithm) (count:nat) (in_b:buffer128) (scratch_b:buffer128) (key_words:(seq nat32)) (round_keys:(seq quad32)) (keys_b:buffer128) : (va_quickCode unit (va_code_Loop6x_round9 alg)) = (va_QProc (va_code_Loop6x_round9 alg) ([va_Mod_mem_heaplet 3; va_Mod_flags; va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_mem]) (va_wp_Loop6x_round9 alg count in_b scratch_b key_words round_keys keys_b) (va_wpProof_Loop6x_round9 alg count in_b scratch_b key_words round_keys keys_b)) //-- //-- load_one_msb val va_code_load_one_msb : va_dummy:unit -> Tot va_code [@ "opaque_to_smt" va_qattr] let va_code_load_one_msb () = (va_Block (va_CCons (va_code_ZeroXmm (va_op_xmm_xmm 2)) (va_CCons (va_code_PinsrqImm (va_op_xmm_xmm 2) 72057594037927936 1 (va_op_reg_opr64_reg64 rR11)) (va_CNil ())))) val va_codegen_success_load_one_msb : va_dummy:unit -> Tot va_pbool [@ "opaque_to_smt" va_qattr] let va_codegen_success_load_one_msb () = (va_pbool_and (va_codegen_success_ZeroXmm (va_op_xmm_xmm 2)) (va_pbool_and (va_codegen_success_PinsrqImm (va_op_xmm_xmm 2) 72057594037927936 1 (va_op_reg_opr64_reg64 rR11)) (va_ttrue ()))) [@ "opaque_to_smt" va_qattr] let va_qcode_load_one_msb (va_mods:va_mods_t) : (va_quickCode unit (va_code_load_one_msb ())) = (qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in va_QBind va_range1 "***** PRECONDITION NOT MET AT line 583 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_ZeroXmm (va_op_xmm_xmm 2)) (fun (va_s:va_state) _ -> va_qAssert va_range1 "***** PRECONDITION NOT MET AT line 584 column 5 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (Vale.Arch.Types.two_to_nat32 (Vale.Def.Words_s.Mktwo #Vale.Def.Words_s.nat32 0 16777216) == 72057594037927936) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 585 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_PinsrqImm (va_op_xmm_xmm 2) 72057594037927936 1 (va_op_reg_opr64_reg64 rR11)) (fun (va_s:va_state) _ -> va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 586 column 24 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (fun (_:unit) -> Vale.Def.Types_s.insert_nat64_reveal ()) (va_QEmpty (()))))))) val va_lemma_load_one_msb : va_b0:va_code -> va_s0:va_state -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_load_one_msb ()) va_s0 /\ va_get_ok va_s0 /\ sse_enabled)) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_get_xmm 2 va_sM == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 16777216 /\ va_state_eq va_sM (va_update_flags va_sM (va_update_xmm 2 va_sM (va_update_reg64 rR11 va_sM (va_update_ok va_sM va_s0)))))) [@"opaque_to_smt"] let va_lemma_load_one_msb va_b0 va_s0 = let (va_mods:va_mods_t) = [va_Mod_flags; va_Mod_xmm 2; va_Mod_reg64 rR11; va_Mod_ok] in let va_qc = va_qcode_load_one_msb va_mods in let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_load_one_msb ()) va_qc va_s0 (fun va_s0 va_sM va_g -> let () = va_g in label va_range1 "***** POSTCONDITION NOT MET AT line 576 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_get_ok va_sM) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 581 column 46 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_get_xmm 2 va_sM == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 16777216)) in assert_norm (va_qc.mods == va_mods); va_lemma_norm_mods ([va_Mod_flags; va_Mod_xmm 2; va_Mod_reg64 rR11; va_Mod_ok]) va_sM va_s0; (va_sM, va_fM) [@ va_qattr] let va_wp_load_one_msb (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ sse_enabled /\ (forall (va_x_r11:nat64) (va_x_xmm2:quad32) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_xmm 2 va_x_xmm2 (va_upd_reg64 rR11 va_x_r11 va_s0)) in va_get_ok va_sM /\ va_get_xmm 2 va_sM == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 16777216 ==> va_k va_sM (()))) val va_wpProof_load_one_msb : va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_load_one_msb va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_load_one_msb ()) ([va_Mod_flags; va_Mod_xmm 2; va_Mod_reg64 rR11]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@"opaque_to_smt"] let va_wpProof_load_one_msb va_s0 va_k = let (va_sM, va_f0) = va_lemma_load_one_msb (va_code_load_one_msb ()) va_s0 in va_lemma_upd_update va_sM; assert (va_state_eq va_sM (va_update_flags va_sM (va_update_xmm 2 va_sM (va_update_reg64 rR11 va_sM (va_update_ok va_sM va_s0))))); va_lemma_norm_mods ([va_Mod_flags; va_Mod_xmm 2; va_Mod_reg64 rR11]) va_sM va_s0; let va_g = () in (va_sM, va_f0, va_g) [@ "opaque_to_smt" va_qattr] let va_quick_load_one_msb () : (va_quickCode unit (va_code_load_one_msb ())) = (va_QProc (va_code_load_one_msb ()) ([va_Mod_flags; va_Mod_xmm 2; va_Mod_reg64 rR11]) va_wp_load_one_msb va_wpProof_load_one_msb) //-- //-- Loop6x_final [@ "opaque_to_smt" va_qattr] let va_code_Loop6x_final alg = (va_Block (va_CCons (va_code_Load128_buffer (va_op_heaplet_mem_heaplet 3) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64 rRbp) 128 Secret) (va_CCons (va_code_VAESNI_enc_last (va_op_xmm_xmm 9) (va_op_xmm_xmm 9) (va_op_xmm_xmm 2)) (va_CCons (va_code_load_one_msb ()) (va_CCons (va_code_VAESNI_enc_last (va_op_xmm_xmm 10) (va_op_xmm_xmm 10) (va_op_xmm_xmm 0)) (va_CCons (va_code_VPaddd (va_op_xmm_xmm 0) (va_op_xmm_xmm 1) (va_op_xmm_xmm 2)) (va_CCons (va_code_Store64_buffer128 (va_op_heaplet_mem_heaplet 3) (va_op_reg_opr64_reg64 rRbp) (va_op_reg_opr64_reg64 rR13) (7 `op_Multiply` 16) Secret false) (va_CCons (va_code_AddLea64 (va_op_dst_opr64_reg64 rRdi) (va_op_opr64_reg64 rRdi) (va_const_opr64 96)) (va_CCons (va_code_VAESNI_enc_last (va_op_xmm_xmm 11) (va_op_xmm_xmm 11) (va_op_xmm_xmm 5)) (va_CCons (va_code_VPaddd (va_op_xmm_xmm 5) (va_op_xmm_xmm 0) (va_op_xmm_xmm 2)) (va_CCons (va_code_Store64_buffer128 (va_op_heaplet_mem_heaplet 3) (va_op_reg_opr64_reg64 rRbp) (va_op_reg_opr64_reg64 rR12) (7 `op_Multiply` 16 + 8) Secret true) (va_CCons (va_code_AddLea64 (va_op_dst_opr64_reg64 rRsi) (va_op_opr64_reg64 rRsi) (va_const_opr64 96)) (va_CCons (va_code_Load128_buffer (va_op_heaplet_mem_heaplet 0) (va_op_xmm_xmm 15) (va_op_reg_opr64_reg64 rRcx) (0 - 128) Secret) (va_CCons (va_code_VAESNI_enc_last (va_op_xmm_xmm 12) (va_op_xmm_xmm 12) (va_op_xmm_xmm 6)) (va_CCons (va_code_VPaddd (va_op_xmm_xmm 6) (va_op_xmm_xmm 5) (va_op_xmm_xmm 2)) (va_CCons (va_code_VAESNI_enc_last (va_op_xmm_xmm 13) (va_op_xmm_xmm 13) (va_op_xmm_xmm 7)) (va_CCons (va_code_VPaddd (va_op_xmm_xmm 7) (va_op_xmm_xmm 6) (va_op_xmm_xmm 2)) (va_CCons (va_code_VAESNI_enc_last (va_op_xmm_xmm 14) (va_op_xmm_xmm 14) (va_op_xmm_xmm 3)) (va_CCons (va_code_VPaddd (va_op_xmm_xmm 3) (va_op_xmm_xmm 7) (va_op_xmm_xmm 2)) (va_CNil ())))))))))))))))))))) [@ "opaque_to_smt" va_qattr] let va_codegen_success_Loop6x_final alg = (va_pbool_and (va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 3) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64 rRbp) 128 Secret) (va_pbool_and (va_codegen_success_VAESNI_enc_last (va_op_xmm_xmm 9) (va_op_xmm_xmm 9) (va_op_xmm_xmm 2)) (va_pbool_and (va_codegen_success_load_one_msb ()) (va_pbool_and (va_codegen_success_VAESNI_enc_last (va_op_xmm_xmm 10) (va_op_xmm_xmm 10) (va_op_xmm_xmm 0)) (va_pbool_and (va_codegen_success_VPaddd (va_op_xmm_xmm 0) (va_op_xmm_xmm 1) (va_op_xmm_xmm 2)) (va_pbool_and (va_codegen_success_Store64_buffer128 (va_op_heaplet_mem_heaplet 3) (va_op_reg_opr64_reg64 rRbp) (va_op_reg_opr64_reg64 rR13) (7 `op_Multiply` 16) Secret false) (va_pbool_and (va_codegen_success_AddLea64 (va_op_dst_opr64_reg64 rRdi) (va_op_opr64_reg64 rRdi) (va_const_opr64 96)) (va_pbool_and (va_codegen_success_VAESNI_enc_last (va_op_xmm_xmm 11) (va_op_xmm_xmm 11) (va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_VPaddd (va_op_xmm_xmm 5) (va_op_xmm_xmm 0) (va_op_xmm_xmm 2)) (va_pbool_and (va_codegen_success_Store64_buffer128 (va_op_heaplet_mem_heaplet 3) (va_op_reg_opr64_reg64 rRbp) (va_op_reg_opr64_reg64 rR12) (7 `op_Multiply` 16 + 8) Secret true) (va_pbool_and (va_codegen_success_AddLea64 (va_op_dst_opr64_reg64 rRsi) (va_op_opr64_reg64 rRsi) (va_const_opr64 96)) (va_pbool_and (va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 0) (va_op_xmm_xmm 15) (va_op_reg_opr64_reg64 rRcx) (0 - 128) Secret) (va_pbool_and (va_codegen_success_VAESNI_enc_last (va_op_xmm_xmm 12) (va_op_xmm_xmm 12) (va_op_xmm_xmm 6)) (va_pbool_and (va_codegen_success_VPaddd (va_op_xmm_xmm 6) (va_op_xmm_xmm 5) (va_op_xmm_xmm 2)) (va_pbool_and (va_codegen_success_VAESNI_enc_last (va_op_xmm_xmm 13) (va_op_xmm_xmm 13) (va_op_xmm_xmm 7)) (va_pbool_and (va_codegen_success_VPaddd (va_op_xmm_xmm 7) (va_op_xmm_xmm 6) (va_op_xmm_xmm 2)) (va_pbool_and (va_codegen_success_VAESNI_enc_last (va_op_xmm_xmm 14) (va_op_xmm_xmm 14) (va_op_xmm_xmm 3)) (va_pbool_and (va_codegen_success_VPaddd (va_op_xmm_xmm 3) (va_op_xmm_xmm 7) (va_op_xmm_xmm 2)) (va_ttrue ()))))))))))))))))))) [@ "opaque_to_smt" va_qattr] let va_qcode_Loop6x_final (va_mods:va_mods_t) (alg:algorithm) (iv_b:buffer128) (scratch_b:buffer128) (key_words:(seq nat32)) (round_keys:(seq quad32)) (keys_b:buffer128) (ctr_orig:quad32) (init:quad32_6) (ctrs:quad32_6) (plain:quad32_6) (inb:quad32) : (va_quickCode unit (va_code_Loop6x_final alg)) = (qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 667 column 37 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_quad32_xor_commutes_forall ()) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 669 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_Load128_buffer (va_op_heaplet_mem_heaplet 3) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64 rRbp) 128 Secret scratch_b 8) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 671 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VAESNI_enc_last (va_op_xmm_xmm 9) (va_op_xmm_xmm 9) (va_op_xmm_xmm 2)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 672 column 17 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_load_one_msb ()) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 673 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VAESNI_enc_last (va_op_xmm_xmm 10) (va_op_xmm_xmm 10) (va_op_xmm_xmm 0)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 674 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPaddd (va_op_xmm_xmm 0) (va_op_xmm_xmm 1) (va_op_xmm_xmm 2)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 675 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_Store64_buffer128 (va_op_heaplet_mem_heaplet 3) (va_op_reg_opr64_reg64 rRbp) (va_op_reg_opr64_reg64 rR13) (7 `op_Multiply` 16) Secret false scratch_b 7) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 676 column 13 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_AddLea64 (va_op_dst_opr64_reg64 rRdi) (va_op_opr64_reg64 rRdi) (va_const_opr64 96)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 677 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VAESNI_enc_last (va_op_xmm_xmm 11) (va_op_xmm_xmm 11) (va_op_xmm_xmm 5)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 678 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPaddd (va_op_xmm_xmm 5) (va_op_xmm_xmm 0) (va_op_xmm_xmm 2)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 679 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_Store64_buffer128 (va_op_heaplet_mem_heaplet 3) (va_op_reg_opr64_reg64 rRbp) (va_op_reg_opr64_reg64 rR12) (7 `op_Multiply` 16 + 8) Secret true scratch_b 7) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 680 column 13 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_AddLea64 (va_op_dst_opr64_reg64 rRsi) (va_op_opr64_reg64 rRsi) (va_const_opr64 96)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 681 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_Load128_buffer (va_op_heaplet_mem_heaplet 0) (va_op_xmm_xmm 15) (va_op_reg_opr64_reg64 rRcx) (0 - 128) Secret keys_b 0) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 683 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VAESNI_enc_last (va_op_xmm_xmm 12) (va_op_xmm_xmm 12) (va_op_xmm_xmm 6)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 684 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPaddd (va_op_xmm_xmm 6) (va_op_xmm_xmm 5) (va_op_xmm_xmm 2)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 685 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VAESNI_enc_last (va_op_xmm_xmm 13) (va_op_xmm_xmm 13) (va_op_xmm_xmm 7)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 686 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPaddd (va_op_xmm_xmm 7) (va_op_xmm_xmm 6) (va_op_xmm_xmm 2)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 687 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VAESNI_enc_last (va_op_xmm_xmm 14) (va_op_xmm_xmm 14) (va_op_xmm_xmm 3)) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 688 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_quick_VPaddd (va_op_xmm_xmm 3) (va_op_xmm_xmm 7) (va_op_xmm_xmm 2)) (fun (va_s:va_state) _ -> let (va_arg117:(FStar.Seq.Base.seq Vale.Def.Types_s.quad32)) = round_keys in let (va_arg116:Vale.Def.Types_s.quad32) = va_get_xmm 9 va_s in let (va_arg115:Vale.Def.Types_s.quad32) = va_get_xmm 9 va_old_s in let (va_arg114:Vale.Def.Types_s.quad32) = __proj__Mktuple6__item___1 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 init in let (va_arg113:Vale.Def.Types_s.quad32) = __proj__Mktuple6__item___1 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 plain in let (va_arg112:Vale.Def.Types_s.quad32) = __proj__Mktuple6__item___1 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 ctrs in let (va_arg111:Vale.AES.AES_common_s.algorithm) = alg in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 690 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (fun (_:unit) -> Vale.AES.AES_helpers.finish_cipher_opt va_arg111 va_arg112 va_arg113 va_arg114 va_arg115 va_arg116 va_arg117) (let (va_arg110:(FStar.Seq.Base.seq Vale.Def.Types_s.quad32)) = round_keys in let (va_arg109:Vale.Def.Types_s.quad32) = va_get_xmm 10 va_s in let (va_arg108:Vale.Def.Types_s.quad32) = va_get_xmm 10 va_old_s in let (va_arg107:Vale.Def.Types_s.quad32) = __proj__Mktuple6__item___2 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 init in let (va_arg106:Vale.Def.Types_s.quad32) = __proj__Mktuple6__item___2 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 plain in let (va_arg105:Vale.Def.Types_s.quad32) = __proj__Mktuple6__item___2 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 ctrs in let (va_arg104:Vale.AES.AES_common_s.algorithm) = alg in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 691 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (fun (_:unit) -> Vale.AES.AES_helpers.finish_cipher_opt va_arg104 va_arg105 va_arg106 va_arg107 va_arg108 va_arg109 va_arg110) (let (va_arg103:(FStar.Seq.Base.seq Vale.Def.Types_s.quad32)) = round_keys in let (va_arg102:Vale.Def.Types_s.quad32) = va_get_xmm 11 va_s in let (va_arg101:Vale.Def.Types_s.quad32) = va_get_xmm 11 va_old_s in let (va_arg100:Vale.Def.Types_s.quad32) = __proj__Mktuple6__item___3 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 init in let (va_arg99:Vale.Def.Types_s.quad32) = __proj__Mktuple6__item___3 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 plain in let (va_arg98:Vale.Def.Types_s.quad32) = __proj__Mktuple6__item___3 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 ctrs in let (va_arg97:Vale.AES.AES_common_s.algorithm) = alg in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 692 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (fun (_:unit) -> Vale.AES.AES_helpers.finish_cipher_opt va_arg97 va_arg98 va_arg99 va_arg100 va_arg101 va_arg102 va_arg103) (let (va_arg96:(FStar.Seq.Base.seq Vale.Def.Types_s.quad32)) = round_keys in let (va_arg95:Vale.Def.Types_s.quad32) = va_get_xmm 12 va_s in let (va_arg94:Vale.Def.Types_s.quad32) = va_get_xmm 12 va_old_s in let (va_arg93:Vale.Def.Types_s.quad32) = __proj__Mktuple6__item___4 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 init in let (va_arg92:Vale.Def.Types_s.quad32) = __proj__Mktuple6__item___4 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 plain in let (va_arg91:Vale.Def.Types_s.quad32) = __proj__Mktuple6__item___4 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 ctrs in let (va_arg90:Vale.AES.AES_common_s.algorithm) = alg in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 693 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (fun (_:unit) -> Vale.AES.AES_helpers.finish_cipher_opt va_arg90 va_arg91 va_arg92 va_arg93 va_arg94 va_arg95 va_arg96) (let (va_arg89:(FStar.Seq.Base.seq Vale.Def.Types_s.quad32)) = round_keys in let (va_arg88:Vale.Def.Types_s.quad32) = va_get_xmm 13 va_s in let (va_arg87:Vale.Def.Types_s.quad32) = va_get_xmm 13 va_old_s in let (va_arg86:Vale.Def.Types_s.quad32) = __proj__Mktuple6__item___5 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 init in let (va_arg85:Vale.Def.Types_s.quad32) = __proj__Mktuple6__item___5 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 plain in let (va_arg84:Vale.Def.Types_s.quad32) = __proj__Mktuple6__item___5 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 ctrs in let (va_arg83:Vale.AES.AES_common_s.algorithm) = alg in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 694 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (fun (_:unit) -> Vale.AES.AES_helpers.finish_cipher_opt va_arg83 va_arg84 va_arg85 va_arg86 va_arg87 va_arg88 va_arg89) (let (va_arg82:(FStar.Seq.Base.seq Vale.Def.Types_s.quad32)) = round_keys in let (va_arg81:Vale.Def.Types_s.quad32) = va_get_xmm 14 va_s in let (va_arg80:Vale.Def.Types_s.quad32) = va_get_xmm 14 va_old_s in let (va_arg79:Vale.Def.Types_s.quad32) = __proj__Mktuple6__item___6 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 init in let (va_arg78:Vale.Def.Types_s.quad32) = __proj__Mktuple6__item___6 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 plain in let (va_arg77:Vale.Def.Types_s.quad32) = __proj__Mktuple6__item___6 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 ctrs in let (va_arg76:Vale.AES.AES_common_s.algorithm) = alg in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 695 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (fun (_:unit) -> Vale.AES.AES_helpers.finish_cipher_opt va_arg76 va_arg77 va_arg78 va_arg79 va_arg80 va_arg81 va_arg82) (va_QLemma va_range1 "***** PRECONDITION NOT MET AT line 696 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" ((fun (alg:algorithm) (input_LE:quad32) (key:(seq nat32)) -> Vale.AES.AES_s.is_aes_key_LE alg key) alg (__proj__Mktuple6__item___1 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 ctrs) key_words) (fun _ -> (fun (alg:algorithm) (input_LE:quad32) (key:(seq nat32)) -> Vale.AES.AES_s.aes_encrypt_LE alg key input_LE == Vale.AES.AES_s.eval_cipher alg input_LE (Vale.AES.AES_s.key_to_round_keys_LE alg key)) alg (__proj__Mktuple6__item___1 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 ctrs) key_words) (fun (_:unit) -> finish_aes_encrypt_le alg (__proj__Mktuple6__item___1 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 ctrs) key_words) (va_QLemma va_range1 "***** PRECONDITION NOT MET AT line 697 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" ((fun (alg:algorithm) (input_LE:quad32) (key:(seq nat32)) -> Vale.AES.AES_s.is_aes_key_LE alg key) alg (__proj__Mktuple6__item___2 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 ctrs) key_words) (fun _ -> (fun (alg:algorithm) (input_LE:quad32) (key:(seq nat32)) -> Vale.AES.AES_s.aes_encrypt_LE alg key input_LE == Vale.AES.AES_s.eval_cipher alg input_LE (Vale.AES.AES_s.key_to_round_keys_LE alg key)) alg (__proj__Mktuple6__item___2 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 ctrs) key_words) (fun (_:unit) -> finish_aes_encrypt_le alg (__proj__Mktuple6__item___2 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 ctrs) key_words) (va_QLemma va_range1 "***** PRECONDITION NOT MET AT line 698 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" ((fun (alg:algorithm) (input_LE:quad32) (key:(seq nat32)) -> Vale.AES.AES_s.is_aes_key_LE alg key) alg (__proj__Mktuple6__item___3 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 ctrs) key_words) (fun _ -> (fun (alg:algorithm) (input_LE:quad32) (key:(seq nat32)) -> Vale.AES.AES_s.aes_encrypt_LE alg key input_LE == Vale.AES.AES_s.eval_cipher alg input_LE (Vale.AES.AES_s.key_to_round_keys_LE alg key)) alg (__proj__Mktuple6__item___3 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 ctrs) key_words) (fun (_:unit) -> finish_aes_encrypt_le alg (__proj__Mktuple6__item___3 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 ctrs) key_words) (va_QLemma va_range1 "***** PRECONDITION NOT MET AT line 699 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" ((fun (alg:algorithm) (input_LE:quad32) (key:(seq nat32)) -> Vale.AES.AES_s.is_aes_key_LE alg key) alg (__proj__Mktuple6__item___4 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 ctrs) key_words) (fun _ -> (fun (alg:algorithm) (input_LE:quad32) (key:(seq nat32)) -> Vale.AES.AES_s.aes_encrypt_LE alg key input_LE == Vale.AES.AES_s.eval_cipher alg input_LE (Vale.AES.AES_s.key_to_round_keys_LE alg key)) alg (__proj__Mktuple6__item___4 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 ctrs) key_words) (fun (_:unit) -> finish_aes_encrypt_le alg (__proj__Mktuple6__item___4 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 ctrs) key_words) (va_QLemma va_range1 "***** PRECONDITION NOT MET AT line 700 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" ((fun (alg:algorithm) (input_LE:quad32) (key:(seq nat32)) -> Vale.AES.AES_s.is_aes_key_LE alg key) alg (__proj__Mktuple6__item___5 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 ctrs) key_words) (fun _ -> (fun (alg:algorithm) (input_LE:quad32) (key:(seq nat32)) -> Vale.AES.AES_s.aes_encrypt_LE alg key input_LE == Vale.AES.AES_s.eval_cipher alg input_LE (Vale.AES.AES_s.key_to_round_keys_LE alg key)) alg (__proj__Mktuple6__item___5 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 ctrs) key_words) (fun (_:unit) -> finish_aes_encrypt_le alg (__proj__Mktuple6__item___5 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 ctrs) key_words) (va_QLemma va_range1 "***** PRECONDITION NOT MET AT line 701 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" ((fun (alg:algorithm) (input_LE:quad32) (key:(seq nat32)) -> Vale.AES.AES_s.is_aes_key_LE alg key) alg (__proj__Mktuple6__item___6 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 ctrs) key_words) (fun _ -> (fun (alg:algorithm) (input_LE:quad32) (key:(seq nat32)) -> Vale.AES.AES_s.aes_encrypt_LE alg key input_LE == Vale.AES.AES_s.eval_cipher alg input_LE (Vale.AES.AES_s.key_to_round_keys_LE alg key)) alg (__proj__Mktuple6__item___6 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 ctrs) key_words) (fun (_:unit) -> finish_aes_encrypt_le alg (__proj__Mktuple6__item___6 #quad32 #quad32 #quad32 #quad32 #quad32 #quad32 ctrs) key_words) (let (va_arg75:Vale.Def.Types_s.quad32) = Vale.X64.Decls.buffer128_read scratch_b 7 (va_get_mem_heaplet 3 va_s) in let (va_arg74:Vale.Def.Types_s.quad32) = Vale.X64.Decls.buffer128_read scratch_b 7 (va_get_mem_heaplet 3 va_old_s) in let (va_arg73:Vale.Def.Types_s.quad32) = inb in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 703 column 34 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (fun (_:unit) -> Vale.Arch.Types.lemma_reverse_bytes_quad32_64 va_arg73 va_arg74 va_arg75) (let (va_arg72:Vale.Def.Types_s.quad32) = va_get_xmm 0 va_s in let (va_arg71:Vale.Def.Types_s.quad32) = va_get_xmm 1 va_s in let (va_arg70:Vale.Def.Types_s.quad32) = ctr_orig in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 705 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (fun (_:unit) -> Vale.AES.AES_helpers.lemma_incr_msb va_arg70 va_arg71 va_arg72 1) (let (va_arg69:Vale.Def.Types_s.quad32) = va_get_xmm 5 va_s in let (va_arg68:Vale.Def.Types_s.quad32) = va_get_xmm 1 va_s in let (va_arg67:Vale.Def.Types_s.quad32) = ctr_orig in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 706 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (fun (_:unit) -> Vale.AES.AES_helpers.lemma_incr_msb va_arg67 va_arg68 va_arg69 2) (let (va_arg66:Vale.Def.Types_s.quad32) = va_get_xmm 6 va_s in let (va_arg65:Vale.Def.Types_s.quad32) = va_get_xmm 1 va_s in let (va_arg64:Vale.Def.Types_s.quad32) = ctr_orig in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 707 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (fun (_:unit) -> Vale.AES.AES_helpers.lemma_incr_msb va_arg64 va_arg65 va_arg66 3) (let (va_arg63:Vale.Def.Types_s.quad32) = va_get_xmm 7 va_s in let (va_arg62:Vale.Def.Types_s.quad32) = va_get_xmm 1 va_s in let (va_arg61:Vale.Def.Types_s.quad32) = ctr_orig in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 708 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (fun (_:unit) -> Vale.AES.AES_helpers.lemma_incr_msb va_arg61 va_arg62 va_arg63 4) (let (va_arg60:Vale.Def.Types_s.quad32) = va_get_xmm 3 va_s in let (va_arg59:Vale.Def.Types_s.quad32) = va_get_xmm 1 va_s in let (va_arg58:Vale.Def.Types_s.quad32) = ctr_orig in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 709 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (fun (_:unit) -> Vale.AES.AES_helpers.lemma_incr_msb va_arg58 va_arg59 va_arg60 5) (va_QEmpty (()))))))))))))))))))))))))))))))))))))))))
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.QuickCodes.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.InsVector.fsti.checked", "Vale.X64.InsMem.fsti.checked", "Vale.X64.InsBasic.fsti.checked", "Vale.X64.InsAes.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Transformers.Transform.fsti.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.TypesNative.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.AES.X64.PolyOps.fsti.checked", "Vale.AES.X64.AESopt2.fsti.checked", "Vale.AES.X64.AESGCM_expected_code.fsti.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "Vale.AES.AES_helpers.fsti.checked", "Vale.AES.AES_common_s.fst.checked", "prims.fst.checked", "FStar.Seq.Base.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.X64.AESopt.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers.Transform", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.AESGCM_expected_code", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.AESopt2", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.PolyOps", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.TypesNative", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsAes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers.Transform", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.AESGCM_expected_code", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.AESopt2", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.PolyOps", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.TypesNative", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsAes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
va_b0: Vale.X64.Decls.va_code -> va_s0: Vale.X64.Decls.va_state -> alg: Vale.AES.AES_common_s.algorithm -> iv_b: Vale.X64.Memory.buffer128 -> scratch_b: Vale.X64.Memory.buffer128 -> key_words: FStar.Seq.Base.seq Vale.X64.Memory.nat32 -> round_keys: FStar.Seq.Base.seq Vale.X64.Decls.quad32 -> keys_b: Vale.X64.Memory.buffer128 -> ctr_orig: Vale.X64.Decls.quad32 -> init: Vale.AES.X64.AESopt.quad32_6 -> ctrs: Vale.AES.X64.AESopt.quad32_6 -> plain: Vale.AES.X64.AESopt.quad32_6 -> inb: Vale.X64.Decls.quad32 -> Prims.Ghost (Vale.X64.Decls.va_state * Vale.X64.Decls.va_fuel)
Prims.Ghost
[]
[]
[ "Vale.X64.Decls.va_code", "Vale.X64.Decls.va_state", "Vale.AES.AES_common_s.algorithm", "Vale.X64.Memory.buffer128", "FStar.Seq.Base.seq", "Vale.X64.Memory.nat32", "Vale.X64.Decls.quad32", "Vale.AES.X64.AESopt.quad32_6", "Vale.X64.QuickCodes.fuel", "Prims.unit", "FStar.Pervasives.Native.Mktuple2", "Vale.X64.Decls.va_fuel", "Vale.X64.QuickCode.va_lemma_norm_mods", "Prims.Cons", "Vale.X64.QuickCode.mod_t", "Vale.X64.QuickCode.va_Mod_mem_heaplet", "Vale.X64.QuickCode.va_Mod_flags", "Vale.X64.QuickCode.va_Mod_xmm", "Vale.X64.QuickCode.va_Mod_reg64", "Vale.X64.Machine_s.rR13", "Vale.X64.Machine_s.rR12", "Vale.X64.Machine_s.rR11", "Vale.X64.Machine_s.rRsi", "Vale.X64.Machine_s.rRdi", "Vale.X64.QuickCode.va_Mod_ok", "Vale.X64.QuickCode.va_Mod_mem", "Prims.Nil", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.list", "Vale.X64.QuickCode.__proj__QProc__item__mods", "Vale.AES.X64.AESopt.va_code_Loop6x_final", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.tuple3", "Vale.X64.State.vale_state", "Vale.X64.QuickCodes.va_wp_sound_code_norm", "Prims.l_and", "Vale.X64.QuickCodes.label", "Vale.X64.QuickCodes.va_range1", "Prims.b2t", "Vale.X64.Decls.va_get_ok", "Vale.X64.Decls.modifies_buffer_specific128", "Vale.X64.Decls.va_get_mem_heaplet", "Vale.Def.Types_s.quad32", "Vale.X64.Decls.buffer128_read", "Vale.Def.Types_s.reverse_bytes_quad32", "FStar.Pervasives.Native.tuple6", "FStar.Pervasives.Native.Mktuple6", "Vale.X64.Decls.va_get_xmm", "Vale.AES.X64.AESopt.map2_six_of", "Vale.Def.Types_s.quad32_xor", "Vale.AES.AES_s.aes_encrypt_LE", "FStar.Seq.Base.index", "Prims.int", "Vale.X64.Decls.va_get_reg64", "Prims.op_Addition", "Vale.Def.Words_s.four", "Vale.Def.Types_s.nat32", "Vale.Def.Words_s.Mkfour", "Prims.l_imp", "Prims.op_LessThan", "Vale.AES.X64.AESopt.xor_reverse_inc32lite_6", "Prims.op_Modulus", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Vale.X64.QuickCode.quickCode", "Vale.AES.X64.AESopt.va_qcode_Loop6x_final" ]
[]
false
false
false
false
false
let va_lemma_Loop6x_final va_b0 va_s0 alg iv_b scratch_b key_words round_keys keys_b ctr_orig init ctrs plain inb =
let va_mods:va_mods_t = [ va_Mod_mem_heaplet 3; va_Mod_flags; va_Mod_xmm 15; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR13; va_Mod_reg64 rR12; va_Mod_reg64 rR11; va_Mod_reg64 rRsi; va_Mod_reg64 rRdi; va_Mod_ok; va_Mod_mem ] in let va_qc = va_qcode_Loop6x_final va_mods alg iv_b scratch_b key_words round_keys keys_b ctr_orig init ctrs plain inb in let va_sM, va_fM, va_g = va_wp_sound_code_norm (va_code_Loop6x_final alg) va_qc va_s0 (fun va_s0 va_sM va_g -> let () = va_g in label va_range1 "***** POSTCONDITION NOT MET AT line 589 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_get_ok va_sM) /\ (label va_range1 "***** POSTCONDITION NOT MET AT line 649 column 72 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (Vale.X64.Decls.modifies_buffer_specific128 scratch_b (va_get_mem_heaplet 3 va_s0) (va_get_mem_heaplet 3 va_sM) 7 7) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 652 column 73 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (Vale.X64.Decls.buffer128_read scratch_b 7 (va_get_mem_heaplet 3 va_sM) == Vale.Def.Types_s.reverse_bytes_quad32 inb) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 654 column 111 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" ((va_get_xmm 9 va_sM, va_get_xmm 10 va_sM, va_get_xmm 11 va_sM, va_get_xmm 12 va_sM, va_get_xmm 13 va_sM, va_get_xmm 14 va_sM) == map2_six_of #quad32 #quad32 #quad32 plain ctrs (fun (p: quad32) (c: quad32) -> Vale.Def.Types_s.quad32_xor p (Vale.AES.AES_s.aes_encrypt_LE alg key_words c))) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 655 column 39 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_get_xmm 15 va_sM == FStar.Seq.Base.index #quad32 round_keys 0) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 657 column 33 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_get_reg64 rRdi va_sM == va_get_reg64 rRdi va_s0 + 96) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 658 column 33 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_get_reg64 rRsi va_sM == va_get_reg64 rRsi va_s0 + 96) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 660 column 41 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_get_xmm 2 va_sM == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 16777216) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 662 column 55 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (va_get_xmm 1 va_sM == Vale.X64.Decls.buffer128_read scratch_b 8 (va_get_mem_heaplet 3 va_s0)) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 663 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (let ctr = (Vale.Def.Words_s.__proj__Mkfour__item__lo0 ctr_orig) `op_Modulus` 256 in label va_range1 "***** POSTCONDITION NOT MET AT line 665 column 60 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/aes/Vale.AES.X64.AESopt.vaf *****" (ctr + 6 < 256 ==> (va_get_xmm 1 va_sM, va_get_xmm 0 va_sM, va_get_xmm 5 va_sM, va_get_xmm 6 va_sM, va_get_xmm 7 va_sM, va_get_xmm 3 va_sM) == xor_reverse_inc32lite_6 0 0 ctr_orig (va_get_xmm 15 va_sM))))) in assert_norm (va_qc.mods == va_mods); va_lemma_norm_mods ([ va_Mod_mem_heaplet 3; va_Mod_flags; va_Mod_xmm 15; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR13; va_Mod_reg64 rR12; va_Mod_reg64 rR11; va_Mod_reg64 rRsi; va_Mod_reg64 rRdi; va_Mod_ok; va_Mod_mem ]) va_sM va_s0; (va_sM, va_fM)
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.rewrite_equality
val rewrite_equality (t: term) : Tac unit
val rewrite_equality (t: term) : Tac unit
let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ())
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 40, "end_line": 635, "start_col": 0, "start_line": 634 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ())
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Tactics.NamedView.term", "FStar.Tactics.V2.Derived.try_rewrite_equality", "Prims.unit", "Prims.list", "FStar.Tactics.NamedView.binding", "FStar.Tactics.V2.Derived.cur_vars" ]
[]
false
true
false
false
false
let rewrite_equality (t: term) : Tac unit =
try_rewrite_equality t (cur_vars ())
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.mapAll
val mapAll (t: (unit -> Tac 'a)) : Tac (list 'a)
val mapAll (t: (unit -> Tac 'a)) : Tac (list 'a)
let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 66, "end_line": 344, "start_col": 0, "start_line": 341 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: (_: Prims.unit -> FStar.Tactics.Effect.Tac 'a) -> FStar.Tactics.Effect.Tac (Prims.list 'a)
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "Prims.Nil", "Prims.list", "FStar.Stubs.Tactics.Types.goal", "Prims.Cons", "FStar.Pervasives.Native.tuple2", "FStar.Tactics.V2.Derived.divide", "FStar.Tactics.V2.Derived.mapAll", "FStar.Tactics.V2.Derived.goals" ]
[ "recursion" ]
false
true
false
false
false
let rec mapAll (t: (unit -> Tac 'a)) : Tac (list 'a) =
match goals () with | [] -> [] | _ :: _ -> let h, t = divide 1 t (fun () -> mapAll t) in h :: t
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.unfold_def
val unfold_def (t: term) : Tac unit
val unfold_def (t: term) : Tac unit
let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv"
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 46, "end_line": 642, "start_col": 0, "start_line": 637 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ())
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Tactics.NamedView.term", "FStar.Stubs.Reflection.Types.fv", "FStar.Stubs.Tactics.V2.Builtins.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.delta_fully", "Prims.string", "Prims.Nil", "Prims.unit", "FStar.Stubs.Reflection.V2.Builtins.implode_qn", "FStar.Stubs.Reflection.V2.Builtins.inspect_fv", "FStar.Tactics.NamedView.named_term_view", "FStar.Tactics.V2.Derived.fail", "FStar.Tactics.NamedView.inspect" ]
[]
false
true
false
false
false
let unfold_def (t: term) : Tac unit =
match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv"
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.destruct_equality_implication
val destruct_equality_implication (t: term) : Tac (option (formula * term))
val destruct_equality_implication (t: term) : Tac (option (formula * term))
let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 15, "end_line": 595, "start_col": 0, "start_line": 587 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ())
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac (FStar.Pervasives.Native.option (FStar.Reflection.V2.Formula.formula * FStar.Tactics.NamedView.term))
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Tactics.NamedView.term", "FStar.Pervasives.Native.option", "FStar.Stubs.Reflection.Types.typ", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple2", "FStar.Reflection.V2.Formula.formula", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.None", "FStar.Reflection.V2.Formula.term_as_formula'", "FStar.Reflection.V2.Formula.term_as_formula" ]
[]
false
true
false
false
false
let destruct_equality_implication (t: term) : Tac (option (formula * term)) =
match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in (match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None) | _ -> None
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.iterAll
val iterAll (t: (unit -> Tac unit)) : Tac unit
val iterAll (t: (unit -> Tac unit)) : Tac unit
let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in ()
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 60, "end_line": 350, "start_col": 0, "start_line": 346 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit) -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Stubs.Tactics.Types.goal", "Prims.list", "FStar.Pervasives.Native.tuple2", "FStar.Tactics.V2.Derived.divide", "FStar.Tactics.V2.Derived.iterAll", "FStar.Tactics.V2.Derived.goals" ]
[ "recursion" ]
false
true
false
false
false
let rec iterAll (t: (unit -> Tac unit)) : Tac unit =
match goals () with | [] -> () | _ :: _ -> let _ = divide 1 t (fun () -> iterAll t) in ()
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.l_to_r
val l_to_r (lems: list term) : Tac unit
val l_to_r (lems: list term) : Tac unit
let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 28, "end_line": 653, "start_col": 0, "start_line": 647 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lems: Prims.list FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.list", "FStar.Tactics.NamedView.term", "FStar.Tactics.V2.Derived.pointwise", "Prims.unit", "FStar.Tactics.Util.fold_left", "FStar.Tactics.V2.Derived.or_else", "FStar.Tactics.V2.Derived.apply_lemma_rw", "FStar.Tactics.V2.Derived.trefl" ]
[]
false
true
false
false
false
let l_to_r (lems: list term) : Tac unit =
let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.fresh_binder_named
val fresh_binder_named (s: string) (t: typ) : Tac simple_binder
val fresh_binder_named (s: string) (t: typ) : Tac simple_binder
let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; }
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 414, "start_col": 0, "start_line": 406 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; })
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Prims.string -> t: FStar.Stubs.Reflection.Types.typ -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.simple_binder
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.string", "FStar.Stubs.Reflection.Types.typ", "FStar.Tactics.NamedView.Mkbinder", "FStar.Sealed.seal", "FStar.Stubs.Reflection.V2.Data.Q_Explicit", "Prims.Nil", "FStar.Tactics.NamedView.term", "FStar.Tactics.NamedView.simple_binder", "Prims.nat", "FStar.Stubs.Tactics.V2.Builtins.fresh" ]
[]
false
true
false
false
false
let fresh_binder_named (s: string) (t: typ) : Tac simple_binder =
let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] }
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.focus
val focus (t: (unit -> Tac 'a)) : Tac 'a
val focus (t: (unit -> Tac 'a)) : Tac 'a
let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 9, "end_line": 336, "start_col": 0, "start_line": 328 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: (_: Prims.unit -> FStar.Tactics.Effect.Tac 'a) -> FStar.Tactics.Effect.Tac 'a
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V2.Derived.fail", "FStar.Stubs.Tactics.Types.goal", "Prims.list", "FStar.Stubs.Tactics.V2.Builtins.set_smt_goals", "FStar.Tactics.V2.Derived.op_At", "FStar.Tactics.V2.Derived.smt_goals", "FStar.Stubs.Tactics.V2.Builtins.set_goals", "FStar.Tactics.V2.Derived.goals", "Prims.Nil", "Prims.Cons" ]
[]
false
true
false
false
false
let focus (t: (unit -> Tac 'a)) : Tac 'a =
match goals () with | [] -> fail "focus: no goals" | g :: gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.grewrite
val grewrite (t1 t2: term) : Tac unit
val grewrite (t1 t2: term) : Tac unit
let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ())
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 44, "end_line": 680, "start_col": 0, "start_line": 665 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2].
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t1: FStar.Tactics.NamedView.term -> t2: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Tactics.NamedView.term", "FStar.Tactics.V2.Derived.pointwise", "Prims.unit", "FStar.Tactics.V2.Derived.trefl", "Prims.bool", "FStar.Tactics.V2.Derived.try_with", "FStar.Tactics.V2.Derived.exact", "Prims.exn", "FStar.Pervasives.Native.option", "FStar.Stubs.Reflection.Types.typ", "Prims.nat", "FStar.Stubs.Reflection.Types.ctx_uvar_and_subst", "FStar.Tactics.NamedView.named_term_view", "FStar.Tactics.NamedView.inspect", "FStar.Reflection.V2.Formula.formula", "FStar.Reflection.V2.Formula.term_as_formula", "FStar.Tactics.V2.Derived.cur_goal", "FStar.Tactics.NamedView.pack", "FStar.Tactics.NamedView.Tv_Var", "FStar.Tactics.V2.SyntaxCoercions.binding_to_namedv", "FStar.Tactics.NamedView.binding", "FStar.Tactics.V2.Derived.tcut", "FStar.Tactics.V2.Derived.mk_sq_eq" ]
[]
false
true
false
false
false
let grewrite (t1 t2: term) : Tac unit =
let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> let is_uvar = match term_as_formula (cur_goal ()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ())
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.mk_sq_eq
val mk_sq_eq (t1 t2: term) : Tot term
val mk_sq_eq (t1 t2: term) : Tot term
let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2])
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 36, "end_line": 661, "start_col": 0, "start_line": 659 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t1: FStar.Tactics.NamedView.term -> t2: FStar.Tactics.NamedView.term -> FStar.Tactics.NamedView.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Tactics.NamedView.term", "FStar.Tactics.V2.Derived.mk_squash", "FStar.Reflection.V2.Derived.mk_e_app", "Prims.Cons", "FStar.Stubs.Reflection.Types.term", "Prims.Nil", "FStar.Tactics.NamedView.pack", "FStar.Tactics.NamedView.Tv_FVar", "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "FStar.Reflection.Const.eq2_qn" ]
[]
false
false
false
true
false
let mk_sq_eq (t1 t2: term) : Tot term =
let eq:term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2])
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.magic_dump
val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a
val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a
let magic_dump #a #x () = x
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 27, "end_line": 717, "start_col": 0, "start_line": 717 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> a
Prims.Tot
[ "total" ]
[]
[ "Prims.unit" ]
[]
false
false
false
true
false
let magic_dump #a #x () =
x
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.fresh_binder
val fresh_binder (t: typ) : Tac simple_binder
val fresh_binder (t: typ) : Tac simple_binder
let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; }
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 424, "start_col": 0, "start_line": 416 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Stubs.Reflection.Types.typ -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.simple_binder
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.typ", "FStar.Tactics.NamedView.Mkbinder", "FStar.Sealed.seal", "Prims.string", "Prims.op_Hat", "Prims.string_of_int", "FStar.Stubs.Reflection.V2.Data.Q_Explicit", "Prims.Nil", "FStar.Tactics.NamedView.term", "FStar.Tactics.NamedView.simple_binder", "Prims.nat", "FStar.Stubs.Tactics.V2.Builtins.fresh" ]
[]
false
true
false
false
false
let fresh_binder (t: typ) : Tac simple_binder =
let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] }
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.mk_squash
val mk_squash (t: term) : Tot term
val mk_squash (t: term) : Tot term
let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t]
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 657, "start_col": 0, "start_line": 655 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Tactics.NamedView.term -> FStar.Tactics.NamedView.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Tactics.NamedView.term", "FStar.Reflection.V2.Derived.mk_e_app", "Prims.Cons", "FStar.Stubs.Reflection.Types.term", "Prims.Nil", "FStar.Tactics.NamedView.pack", "FStar.Tactics.NamedView.Tv_FVar", "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "FStar.Reflection.Const.squash_qn" ]
[]
false
false
false
true
false
let mk_squash (t: term) : Tot term =
let sq:term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t]
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.grewrite_eq
val grewrite_eq (b: binding) : Tac unit
val grewrite_eq (b: binding) : Tac unit
let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 7, "end_line": 699, "start_col": 0, "start_line": 686 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: FStar.Tactics.NamedView.binding -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Tactics.NamedView.binding", "FStar.Pervasives.Native.option", "FStar.Stubs.Reflection.Types.typ", "FStar.Tactics.NamedView.term", "FStar.Tactics.V2.Derived.iseq", "Prims.Cons", "Prims.unit", "FStar.Tactics.V2.Derived.idtac", "FStar.Tactics.V2.Derived.exact", "FStar.Tactics.V2.SyntaxCoercions.binding_to_term", "Prims.Nil", "FStar.Tactics.V2.Derived.grewrite", "FStar.Reflection.V2.Formula.formula", "FStar.Tactics.V2.Derived.apply_lemma", "FStar.Tactics.V2.Derived.fail", "FStar.Reflection.V2.Formula.term_as_formula'", "FStar.Tactics.V2.Derived.type_of_binding", "FStar.Reflection.V2.Formula.term_as_formula" ]
[]
false
true
false
false
false
let grewrite_eq (b: binding) : Tac unit =
match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [ idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b) ] | _ -> fail "grewrite_eq: binder type is not an equality"
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.fresh_implicit_binder
val fresh_implicit_binder (t: typ) : Tac binder
val fresh_implicit_binder (t: typ) : Tac binder
let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; }
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 434, "start_col": 0, "start_line": 426 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Stubs.Reflection.Types.typ -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.binder
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.typ", "FStar.Tactics.NamedView.Mkbinder", "FStar.Sealed.seal", "Prims.string", "Prims.op_Hat", "Prims.string_of_int", "FStar.Stubs.Reflection.V2.Data.Q_Implicit", "Prims.Nil", "FStar.Tactics.NamedView.term", "FStar.Tactics.NamedView.binder", "Prims.nat", "FStar.Stubs.Tactics.V2.Builtins.fresh" ]
[]
false
true
false
false
false
let fresh_implicit_binder (t: typ) : Tac binder =
let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] }
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.admit_dump_t
val admit_dump_t: Prims.unit -> Tac unit
val admit_dump_t: Prims.unit -> Tac unit
let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit)
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 16, "end_line": 704, "start_col": 0, "start_line": 702 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V2.Derived.apply", "FStar.Stubs.Tactics.V2.Builtins.dump" ]
[]
false
true
false
false
false
let admit_dump_t () : Tac unit =
dump "Admitting"; apply (`admit)
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.admit_dump
val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a
val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a
let admit_dump #a #x () = x ()
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 707, "start_col": 0, "start_line": 707 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> Prims.Admit a
Prims.Admit
[]
[]
[ "Prims.unit" ]
[]
false
true
false
false
false
let admit_dump #a #x () =
x ()
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.change_sq
val change_sq (t1: term) : Tac unit
val change_sq (t1: term) : Tac unit
let change_sq (t1 : term) : Tac unit = change (mk_e_app (`squash) [t1])
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 36, "end_line": 726, "start_col": 0, "start_line": 725 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); () val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a let magic_dump #a #x () = x let change_with t1 t2 : Tac unit = focus (fun () -> grewrite t1 t2; iseq [idtac; trivial] )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t1: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Tactics.NamedView.term", "FStar.Stubs.Tactics.V2.Builtins.change", "FStar.Reflection.V2.Derived.mk_e_app", "Prims.Cons", "FStar.Stubs.Reflection.Types.term", "Prims.Nil", "Prims.unit" ]
[]
false
true
false
false
false
let change_sq (t1: term) : Tac unit =
change (mk_e_app (`squash) [t1])
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.fresh_namedv_named
val fresh_namedv_named (s: string) : Tac namedv
val fresh_namedv_named (s: string) : Tac namedv
let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; })
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 4, "end_line": 394, "start_col": 0, "start_line": 388 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ())
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Prims.string -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.namedv
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.string", "FStar.Tactics.NamedView.pack_namedv", "FStar.Stubs.Reflection.V2.Data.Mknamedv_view", "FStar.Sealed.seal", "FStar.Stubs.Reflection.Types.typ", "FStar.Tactics.NamedView.pack", "FStar.Tactics.NamedView.Tv_Unknown", "FStar.Tactics.NamedView.namedv", "Prims.nat", "FStar.Stubs.Tactics.V2.Builtins.fresh" ]
[]
false
true
false
false
false
let fresh_namedv_named (s: string) : Tac namedv =
let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n })
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.add_elem
val add_elem (t: (unit -> Tac 'a)) : Tac 'a
val add_elem (t: (unit -> Tac 'a)) : Tac 'a
let add_elem (t : unit -> Tac 'a) : Tac 'a = focus (fun () -> apply (`Cons); focus (fun () -> let x = t () in qed (); x ) )
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 747, "start_col": 0, "start_line": 740 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); () val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a let magic_dump #a #x () = x let change_with t1 t2 : Tac unit = focus (fun () -> grewrite t1 t2; iseq [idtac; trivial] ) let change_sq (t1 : term) : Tac unit = change (mk_e_app (`squash) [t1]) let finish_by (t : unit -> Tac 'a) : Tac 'a = let x = t () in or_else qed (fun () -> fail "finish_by: not finished"); x let solve_then #a #b (t1 : unit -> Tac a) (t2 : a -> Tac b) : Tac b = dup (); let x = focus (fun () -> finish_by t1) in let y = t2 x in trefl (); y
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: (_: Prims.unit -> FStar.Tactics.Effect.Tac 'a) -> FStar.Tactics.Effect.Tac 'a
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V2.Derived.focus", "FStar.Tactics.V2.Derived.qed", "FStar.Tactics.V2.Derived.apply" ]
[]
false
true
false
false
false
let add_elem (t: (unit -> Tac 'a)) : Tac 'a =
focus (fun () -> apply (`Cons); focus (fun () -> let x = t () in qed (); x))
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.magic_dump_t
val magic_dump_t: Prims.unit -> Tac unit
val magic_dump_t: Prims.unit -> Tac unit
let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); ()
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 4, "end_line": 714, "start_col": 0, "start_line": 710 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V2.Derived.exact", "FStar.Tactics.V2.Derived.apply", "FStar.Stubs.Tactics.V2.Builtins.dump" ]
[]
false
true
false
false
false
let magic_dump_t () : Tac unit =
dump "Admitting"; apply (`magic); exact (`()); ()
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.specialize
val specialize: #a: Type -> f: a -> l: list string -> unit -> Tac unit
val specialize: #a: Type -> f: a -> l: list string -> unit -> Tac unit
let specialize (#a:Type) (f:a) (l:list string) :unit -> Tac unit = fun () -> solve_then (fun () -> exact (quote f)) (fun () -> norm [delta_only l; iota; zeta])
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 96, "end_line": 765, "start_col": 0, "start_line": 764 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); () val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a let magic_dump #a #x () = x let change_with t1 t2 : Tac unit = focus (fun () -> grewrite t1 t2; iseq [idtac; trivial] ) let change_sq (t1 : term) : Tac unit = change (mk_e_app (`squash) [t1]) let finish_by (t : unit -> Tac 'a) : Tac 'a = let x = t () in or_else qed (fun () -> fail "finish_by: not finished"); x let solve_then #a #b (t1 : unit -> Tac a) (t2 : a -> Tac b) : Tac b = dup (); let x = focus (fun () -> finish_by t1) in let y = t2 x in trefl (); y let add_elem (t : unit -> Tac 'a) : Tac 'a = focus (fun () -> apply (`Cons); focus (fun () -> let x = t () in qed (); x ) ) (* * Specialize a function by partially evaluating it * For example: * let rec foo (l:list int) (x:int) :St int = match l with | [] -> x | hd::tl -> x + foo tl x let f :int -> St int = synth_by_tactic (specialize (foo [1; 2]) [%`foo]) * would make the definition of f as x + x + x * * f is the term that needs to be specialized * l is the list of names to be delta-ed
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: a -> l: Prims.list Prims.string -> _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.list", "Prims.string", "Prims.unit", "FStar.Tactics.V2.Derived.solve_then", "FStar.Tactics.V2.Derived.exact", "FStar.Tactics.NamedView.term", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Tactics.V2.Builtins.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.delta_only", "FStar.Pervasives.iota", "FStar.Pervasives.zeta", "Prims.Nil" ]
[]
false
true
false
false
false
let specialize (#a: Type) (f: a) (l: list string) : unit -> Tac unit =
fun () -> solve_then (fun () -> exact (quote f)) (fun () -> norm [delta_only l; iota; zeta])
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.solve_then
val solve_then (#a #b: _) (t1: (unit -> Tac a)) (t2: (a -> Tac b)) : Tac b
val solve_then (#a #b: _) (t1: (unit -> Tac a)) (t2: (a -> Tac b)) : Tac b
let solve_then #a #b (t1 : unit -> Tac a) (t2 : a -> Tac b) : Tac b = dup (); let x = focus (fun () -> finish_by t1) in let y = t2 x in trefl (); y
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 738, "start_col": 0, "start_line": 733 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); () val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a let magic_dump #a #x () = x let change_with t1 t2 : Tac unit = focus (fun () -> grewrite t1 t2; iseq [idtac; trivial] ) let change_sq (t1 : term) : Tac unit = change (mk_e_app (`squash) [t1]) let finish_by (t : unit -> Tac 'a) : Tac 'a = let x = t () in or_else qed (fun () -> fail "finish_by: not finished"); x
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t1: (_: Prims.unit -> FStar.Tactics.Effect.Tac a) -> t2: (_: a -> FStar.Tactics.Effect.Tac b) -> FStar.Tactics.Effect.Tac b
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V2.Derived.trefl", "FStar.Tactics.V2.Derived.focus", "FStar.Tactics.V2.Derived.finish_by", "FStar.Stubs.Tactics.V2.Builtins.dup" ]
[]
false
true
false
false
false
let solve_then #a #b (t1: (unit -> Tac a)) (t2: (a -> Tac b)) : Tac b =
dup (); let x = focus (fun () -> finish_by t1) in let y = t2 x in trefl (); y
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.finish_by
val finish_by (t: (unit -> Tac 'a)) : Tac 'a
val finish_by (t: (unit -> Tac 'a)) : Tac 'a
let finish_by (t : unit -> Tac 'a) : Tac 'a = let x = t () in or_else qed (fun () -> fail "finish_by: not finished"); x
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 731, "start_col": 0, "start_line": 728 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); () val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a let magic_dump #a #x () = x let change_with t1 t2 : Tac unit = focus (fun () -> grewrite t1 t2; iseq [idtac; trivial] ) let change_sq (t1 : term) : Tac unit = change (mk_e_app (`squash) [t1])
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: (_: Prims.unit -> FStar.Tactics.Effect.Tac 'a) -> FStar.Tactics.Effect.Tac 'a
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V2.Derived.or_else", "FStar.Tactics.V2.Derived.qed", "FStar.Tactics.V2.Derived.fail" ]
[]
false
true
false
false
false
let finish_by (t: (unit -> Tac 'a)) : Tac 'a =
let x = t () in or_else qed (fun () -> fail "finish_by: not finished"); x
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.guard
val guard (b: bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r))
val guard (b: bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r))
let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else ()
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 11, "end_line": 444, "start_col": 0, "start_line": 436 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Prims.bool -> FStar.Tactics.Effect.TacH Prims.unit
FStar.Tactics.Effect.TacH
[]
[]
[ "Prims.bool", "Prims.op_Negation", "FStar.Tactics.V2.Derived.fail", "Prims.unit", "FStar.Stubs.Tactics.Types.proofstate", "Prims.l_True", "FStar.Stubs.Tactics.Result.__result", "Prims.l_and", "Prims.b2t", "FStar.Stubs.Tactics.Result.uu___is_Success", "Prims.eq2", "FStar.Stubs.Tactics.Result.__proj__Success__item__ps", "FStar.Stubs.Tactics.Result.uu___is_Failed" ]
[]
false
true
false
false
false
let guard (b: bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) =
if not b then fail "guard failed"
false
Vale.Def.PossiblyMonad.fst
Vale.Def.PossiblyMonad.return
val return (#a: Type) (x: a) : possibly a
val return (#a: Type) (x: a) : possibly a
let return (#a:Type) (x:a) : possibly a = Ok x
{ "file_name": "vale/specs/defs/Vale.Def.PossiblyMonad.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 6, "end_line": 12, "start_col": 7, "start_line": 11 }
module Vale.Def.PossiblyMonad /// Similar to the [maybe] monad in Haskell (which is like the /// [option] type in F* and OCaml), but instead, we also store the /// reason for the error when the error occurs. type possibly 'a = | Ok : v:'a -> possibly 'a | Err : reason:string -> possibly 'a
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Def.PossiblyMonad.fst" }
[ { "abbrev": false, "full_module": "Vale.Def", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: a -> Vale.Def.PossiblyMonad.possibly a
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.PossiblyMonad.Ok", "Vale.Def.PossiblyMonad.possibly" ]
[]
false
false
false
true
false
let return (#a: Type) (x: a) : possibly a =
Ok x
false
Vale.Def.PossiblyMonad.fst
Vale.Def.PossiblyMonad.ttrue
val ttrue:pbool
val ttrue:pbool
let ttrue : pbool = Ok ()
{ "file_name": "vale/specs/defs/Vale.Def.PossiblyMonad.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 25, "end_line": 53, "start_col": 0, "start_line": 53 }
module Vale.Def.PossiblyMonad /// Similar to the [maybe] monad in Haskell (which is like the /// [option] type in F* and OCaml), but instead, we also store the /// reason for the error when the error occurs. type possibly 'a = | Ok : v:'a -> possibly 'a | Err : reason:string -> possibly 'a unfold let return (#a:Type) (x:a) : possibly a = Ok x unfold let (let+) (#a #b:Type) (x:possibly a) (f:a -> possibly b) : possibly b = match x with | Err s -> Err s | Ok x' -> f x' unfold let fail_with (#a:Type) (s:string) : possibly a = Err s unfold let unimplemented (#a:Type) (s:string) : possibly a = fail_with ("Unimplemented: " ^ s) (** Allows moving to a "looser" monad type, always *) unfold let loosen (#t1:Type) (#t2:Type{t1 `subtype_of` t2}) (x:possibly t1) : possibly t2 = match x with | Ok x' -> Ok x' | Err s -> Err s (** Allows moving to a "tighter" monad type, as long as the monad is guaranteed statically to be within this tighter type *) unfold let tighten (#t1:Type) (#t2:Type{t2 `subtype_of` t1}) (x:possibly t1{Ok? x ==> Ok?.v x `has_type` t2}) : possibly t2 = match x with | Ok x' -> Ok x' | Err s -> Err s (** [pbool] is a type that can be used instead of [bool] to hold on to a reason whenever it is [false]. To convert from a [pbool] to a bool, see [!!]. *) unfold type pbool = possibly unit (** [!!x] coerces a [pbool] into a [bool] by discarding any reason it holds on to and instead uses it solely as a boolean. *) unfold let (!!) (x:pbool) : bool = Ok? x (** [ttrue] is just the same as [true] but for a [pbool] *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Def.PossiblyMonad.fst" }
[ { "abbrev": false, "full_module": "Vale.Def", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.Def.PossiblyMonad.possibly Prims.unit
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.PossiblyMonad.Ok", "Prims.unit" ]
[]
false
false
false
true
false
let ttrue:pbool =
Ok ()
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.name_appears_in
val name_appears_in (nm: name) (t: term) : Tac bool
val name_appears_in (nm: name) (t: term) : Tac bool
let name_appears_in (nm:name) (t:term) : Tac bool = let ff (t : term) : Tac term = match inspect t with | Tv_FVar fv -> if inspect_fv fv = nm then raise Appears; t | tv -> pack tv in try ignore (V.visit_tm ff t); false with | Appears -> true | e -> raise e
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 16, "end_line": 871, "start_col": 0, "start_line": 860 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); () val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a let magic_dump #a #x () = x let change_with t1 t2 : Tac unit = focus (fun () -> grewrite t1 t2; iseq [idtac; trivial] ) let change_sq (t1 : term) : Tac unit = change (mk_e_app (`squash) [t1]) let finish_by (t : unit -> Tac 'a) : Tac 'a = let x = t () in or_else qed (fun () -> fail "finish_by: not finished"); x let solve_then #a #b (t1 : unit -> Tac a) (t2 : a -> Tac b) : Tac b = dup (); let x = focus (fun () -> finish_by t1) in let y = t2 x in trefl (); y let add_elem (t : unit -> Tac 'a) : Tac 'a = focus (fun () -> apply (`Cons); focus (fun () -> let x = t () in qed (); x ) ) (* * Specialize a function by partially evaluating it * For example: * let rec foo (l:list int) (x:int) :St int = match l with | [] -> x | hd::tl -> x + foo tl x let f :int -> St int = synth_by_tactic (specialize (foo [1; 2]) [%`foo]) * would make the definition of f as x + x + x * * f is the term that needs to be specialized * l is the list of names to be delta-ed *) let specialize (#a:Type) (f:a) (l:list string) :unit -> Tac unit = fun () -> solve_then (fun () -> exact (quote f)) (fun () -> norm [delta_only l; iota; zeta]) let tlabel (l:string) = match goals () with | [] -> fail "tlabel: no goals" | h::t -> set_goals (set_label l h :: t) let tlabel' (l:string) = match goals () with | [] -> fail "tlabel': no goals" | h::t -> let h = set_label (l ^ get_label h) h in set_goals (h :: t) let focus_all () : Tac unit = set_goals (goals () @ smt_goals ()); set_smt_goals [] private let rec extract_nth (n:nat) (l : list 'a) : option ('a * list 'a) = match n, l with | _, [] -> None | 0, hd::tl -> Some (hd, tl) | _, hd::tl -> begin match extract_nth (n-1) tl with | Some (hd', tl') -> Some (hd', hd::tl') | None -> None end let bump_nth (n:pos) : Tac unit = // n-1 since goal numbering begins at 1 match extract_nth (n - 1) (goals ()) with | None -> fail "bump_nth: not that many goals" | Some (h, t) -> set_goals (h :: t) let rec destruct_list (t : term) : Tac (list term) = let head, args = collect_app t in match inspect head, args with | Tv_FVar fv, [(a1, Q_Explicit); (a2, Q_Explicit)] | Tv_FVar fv, [(_, Q_Implicit); (a1, Q_Explicit); (a2, Q_Explicit)] -> if inspect_fv fv = cons_qn then a1 :: destruct_list a2 else raise NotAListLiteral | Tv_FVar fv, _ -> if inspect_fv fv = nil_qn then [] else raise NotAListLiteral | _ -> raise NotAListLiteral private let get_match_body () : Tac term = match unsquash_term (cur_goal ()) with | None -> fail "" | Some t -> match inspect_unascribe t with | Tv_Match sc _ _ -> sc | _ -> fail "Goal is not a match" private let rec last (x : list 'a) : Tac 'a = match x with | [] -> fail "last: empty list" | [x] -> x | _::xs -> last xs (** When the goal is [match e with | p1 -> e1 ... | pn -> en], destruct it into [n] goals for each possible case, including an hypothesis for [e] matching the corresponding pattern. *) let branch_on_match () : Tac unit = focus (fun () -> let x = get_match_body () in let _ = t_destruct x in iterAll (fun () -> let bs = repeat intro in let b = last bs in (* this one is the equality *) grewrite_eq b; norm [iota]) ) (** When the argument [i] is non-negative, [nth_var] grabs the nth binder in the current goal. When it is negative, it grabs the (-i-1)th binder counting from the end of the goal. That is, [nth_var (-1)] will return the last binder, [nth_var (-2)] the second to last, and so on. *) let nth_var (i:int) : Tac binding = let bs = cur_vars () in let k : int = if i >= 0 then i else List.Tot.Base.length bs + i in let k : nat = if k < 0 then fail "not enough binders" else k in match List.Tot.Base.nth bs k with | None -> fail "not enough binders" | Some b -> b exception Appears (** Decides whether a top-level name [nm] syntactically
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
nm: FStar.Stubs.Reflection.Types.name -> t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.bool
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.name", "FStar.Tactics.NamedView.term", "FStar.Tactics.V2.Derived.try_with", "Prims.bool", "Prims.unit", "FStar.Pervasives.ignore", "FStar.Stubs.Reflection.Types.term", "FStar.Tactics.Visit.visit_tm", "Prims.exn", "FStar.Tactics.Effect.raise", "FStar.Stubs.Reflection.Types.fv", "Prims.op_Equality", "FStar.Stubs.Reflection.V2.Builtins.inspect_fv", "FStar.Tactics.V2.Derived.Appears", "FStar.Tactics.NamedView.named_term_view", "FStar.Tactics.NamedView.pack", "FStar.Tactics.NamedView.inspect" ]
[]
false
true
false
false
false
let name_appears_in (nm: name) (t: term) : Tac bool =
let ff (t: term) : Tac term = match inspect t with | Tv_FVar fv -> if inspect_fv fv = nm then raise Appears; t | tv -> pack tv in try (ignore (V.visit_tm ff t); false) with | Appears -> true | e -> raise e
false
Vale.Def.PossiblyMonad.fst
Vale.Def.PossiblyMonad.unimplemented
val unimplemented (#a: Type) (s: string) : possibly a
val unimplemented (#a: Type) (s: string) : possibly a
let unimplemented (#a:Type) (s:string) : possibly a = fail_with ("Unimplemented: " ^ s)
{ "file_name": "vale/specs/defs/Vale.Def.PossiblyMonad.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 94, "end_line": 21, "start_col": 7, "start_line": 21 }
module Vale.Def.PossiblyMonad /// Similar to the [maybe] monad in Haskell (which is like the /// [option] type in F* and OCaml), but instead, we also store the /// reason for the error when the error occurs. type possibly 'a = | Ok : v:'a -> possibly 'a | Err : reason:string -> possibly 'a unfold let return (#a:Type) (x:a) : possibly a = Ok x unfold let (let+) (#a #b:Type) (x:possibly a) (f:a -> possibly b) : possibly b = match x with | Err s -> Err s | Ok x' -> f x' unfold let fail_with (#a:Type) (s:string) : possibly a = Err s
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Def.PossiblyMonad.fst" }
[ { "abbrev": false, "full_module": "Vale.Def", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Prims.string -> Vale.Def.PossiblyMonad.possibly a
Prims.Tot
[ "total" ]
[]
[ "Prims.string", "Vale.Def.PossiblyMonad.fail_with", "Prims.op_Hat", "Vale.Def.PossiblyMonad.possibly" ]
[]
false
false
false
true
false
let unimplemented (#a: Type) (s: string) : possibly a =
fail_with ("Unimplemented: " ^ s)
false
Vale.Def.PossiblyMonad.fst
Vale.Def.PossiblyMonad.fail_with
val fail_with (#a: Type) (s: string) : possibly a
val fail_with (#a: Type) (s: string) : possibly a
let fail_with (#a:Type) (s:string) : possibly a = Err s
{ "file_name": "vale/specs/defs/Vale.Def.PossiblyMonad.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 62, "end_line": 19, "start_col": 7, "start_line": 19 }
module Vale.Def.PossiblyMonad /// Similar to the [maybe] monad in Haskell (which is like the /// [option] type in F* and OCaml), but instead, we also store the /// reason for the error when the error occurs. type possibly 'a = | Ok : v:'a -> possibly 'a | Err : reason:string -> possibly 'a unfold let return (#a:Type) (x:a) : possibly a = Ok x unfold let (let+) (#a #b:Type) (x:possibly a) (f:a -> possibly b) : possibly b = match x with | Err s -> Err s | Ok x' -> f x'
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Def.PossiblyMonad.fst" }
[ { "abbrev": false, "full_module": "Vale.Def", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Prims.string -> Vale.Def.PossiblyMonad.possibly a
Prims.Tot
[ "total" ]
[]
[ "Prims.string", "Vale.Def.PossiblyMonad.Err", "Vale.Def.PossiblyMonad.possibly" ]
[]
false
false
false
true
false
let fail_with (#a: Type) (s: string) : possibly a =
Err s
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.repeat
val repeat (#a: Type) (t: (unit -> Tac a)) : Tac (list a)
val repeat (#a: Type) (t: (unit -> Tac a)) : Tac (list a)
let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 28, "end_line": 471, "start_col": 0, "start_line": 468 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: (_: Prims.unit -> FStar.Tactics.Effect.Tac a) -> FStar.Tactics.Effect.Tac (Prims.list a)
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "Prims.exn", "Prims.Nil", "Prims.list", "Prims.Cons", "FStar.Tactics.V2.Derived.repeat", "FStar.Pervasives.either", "FStar.Stubs.Tactics.V2.Builtins.catch" ]
[ "recursion" ]
false
true
false
false
false
let rec repeat (#a: Type) (t: (unit -> Tac a)) : Tac (list a) =
match catch t with | Inl _ -> [] | Inr x -> x :: repeat t
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.divide
val divide (n: int) (l: (unit -> Tac 'a)) (r: (unit -> Tac 'b)) : Tac ('a * 'b)
val divide (n: int) (l: (unit -> Tac 'a)) (r: (unit -> Tac 'b)) : Tac ('a * 'b)
let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y)
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 10, "end_line": 319, "start_col": 0, "start_line": 304 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.int -> l: (_: Prims.unit -> FStar.Tactics.Effect.Tac 'a) -> r: (_: Prims.unit -> FStar.Tactics.Effect.Tac 'b) -> FStar.Tactics.Effect.Tac ('a * 'b)
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.int", "Prims.unit", "Prims.list", "FStar.Stubs.Tactics.Types.goal", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple2", "FStar.Stubs.Tactics.V2.Builtins.set_smt_goals", "FStar.Tactics.V2.Derived.op_At", "FStar.Stubs.Tactics.V2.Builtins.set_goals", "FStar.Tactics.V2.Derived.smt_goals", "FStar.Tactics.V2.Derived.goals", "Prims.Nil", "FStar.List.Tot.Base.splitAt", "Prims.op_LessThan", "FStar.Tactics.V2.Derived.fail", "Prims.bool" ]
[]
false
true
false
false
false
let divide (n: int) (l: (unit -> Tac 'a)) (r: (unit -> Tac 'b)) : Tac ('a * 'b) =
if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y)
false
Vale.Def.PossiblyMonad.fst
Vale.Def.PossiblyMonad.ffalse
val ffalse (reason: string) : pbool
val ffalse (reason: string) : pbool
let ffalse (reason:string) : pbool = Err reason
{ "file_name": "vale/specs/defs/Vale.Def.PossiblyMonad.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 47, "end_line": 57, "start_col": 0, "start_line": 57 }
module Vale.Def.PossiblyMonad /// Similar to the [maybe] monad in Haskell (which is like the /// [option] type in F* and OCaml), but instead, we also store the /// reason for the error when the error occurs. type possibly 'a = | Ok : v:'a -> possibly 'a | Err : reason:string -> possibly 'a unfold let return (#a:Type) (x:a) : possibly a = Ok x unfold let (let+) (#a #b:Type) (x:possibly a) (f:a -> possibly b) : possibly b = match x with | Err s -> Err s | Ok x' -> f x' unfold let fail_with (#a:Type) (s:string) : possibly a = Err s unfold let unimplemented (#a:Type) (s:string) : possibly a = fail_with ("Unimplemented: " ^ s) (** Allows moving to a "looser" monad type, always *) unfold let loosen (#t1:Type) (#t2:Type{t1 `subtype_of` t2}) (x:possibly t1) : possibly t2 = match x with | Ok x' -> Ok x' | Err s -> Err s (** Allows moving to a "tighter" monad type, as long as the monad is guaranteed statically to be within this tighter type *) unfold let tighten (#t1:Type) (#t2:Type{t2 `subtype_of` t1}) (x:possibly t1{Ok? x ==> Ok?.v x `has_type` t2}) : possibly t2 = match x with | Ok x' -> Ok x' | Err s -> Err s (** [pbool] is a type that can be used instead of [bool] to hold on to a reason whenever it is [false]. To convert from a [pbool] to a bool, see [!!]. *) unfold type pbool = possibly unit (** [!!x] coerces a [pbool] into a [bool] by discarding any reason it holds on to and instead uses it solely as a boolean. *) unfold let (!!) (x:pbool) : bool = Ok? x (** [ttrue] is just the same as [true] but for a [pbool] *) unfold let ttrue : pbool = Ok () (** [ffalse] is the same as [false] but is for a [pbool] and thus requires a reason for being false. *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Def.PossiblyMonad.fst" }
[ { "abbrev": false, "full_module": "Vale.Def", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
reason: Prims.string -> Vale.Def.PossiblyMonad.pbool
Prims.Tot
[ "total" ]
[]
[ "Prims.string", "Vale.Def.PossiblyMonad.Err", "Prims.unit", "Vale.Def.PossiblyMonad.pbool" ]
[]
false
false
false
true
false
let ffalse (reason: string) : pbool =
Err reason
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.focus_all
val focus_all: Prims.unit -> Tac unit
val focus_all: Prims.unit -> Tac unit
let focus_all () : Tac unit = set_goals (goals () @ smt_goals ()); set_smt_goals []
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 20, "end_line": 782, "start_col": 0, "start_line": 780 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); () val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a let magic_dump #a #x () = x let change_with t1 t2 : Tac unit = focus (fun () -> grewrite t1 t2; iseq [idtac; trivial] ) let change_sq (t1 : term) : Tac unit = change (mk_e_app (`squash) [t1]) let finish_by (t : unit -> Tac 'a) : Tac 'a = let x = t () in or_else qed (fun () -> fail "finish_by: not finished"); x let solve_then #a #b (t1 : unit -> Tac a) (t2 : a -> Tac b) : Tac b = dup (); let x = focus (fun () -> finish_by t1) in let y = t2 x in trefl (); y let add_elem (t : unit -> Tac 'a) : Tac 'a = focus (fun () -> apply (`Cons); focus (fun () -> let x = t () in qed (); x ) ) (* * Specialize a function by partially evaluating it * For example: * let rec foo (l:list int) (x:int) :St int = match l with | [] -> x | hd::tl -> x + foo tl x let f :int -> St int = synth_by_tactic (specialize (foo [1; 2]) [%`foo]) * would make the definition of f as x + x + x * * f is the term that needs to be specialized * l is the list of names to be delta-ed *) let specialize (#a:Type) (f:a) (l:list string) :unit -> Tac unit = fun () -> solve_then (fun () -> exact (quote f)) (fun () -> norm [delta_only l; iota; zeta]) let tlabel (l:string) = match goals () with | [] -> fail "tlabel: no goals" | h::t -> set_goals (set_label l h :: t) let tlabel' (l:string) = match goals () with | [] -> fail "tlabel': no goals" | h::t -> let h = set_label (l ^ get_label h) h in set_goals (h :: t)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Stubs.Tactics.V2.Builtins.set_smt_goals", "Prims.Nil", "FStar.Stubs.Tactics.Types.goal", "FStar.Stubs.Tactics.V2.Builtins.set_goals", "Prims.list", "FStar.Tactics.V2.Derived.op_At", "FStar.Tactics.V2.Derived.smt_goals", "FStar.Tactics.V2.Derived.goals" ]
[]
false
true
false
false
false
let focus_all () : Tac unit =
set_goals (goals () @ smt_goals ()); set_smt_goals []
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.branch_on_match
val branch_on_match: Prims.unit -> Tac unit
val branch_on_match: Prims.unit -> Tac unit
let branch_on_match () : Tac unit = focus (fun () -> let x = get_match_body () in let _ = t_destruct x in iterAll (fun () -> let bs = repeat intro in let b = last bs in (* this one is the equality *) grewrite_eq b; norm [iota]) )
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 841, "start_col": 0, "start_line": 832 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); () val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a let magic_dump #a #x () = x let change_with t1 t2 : Tac unit = focus (fun () -> grewrite t1 t2; iseq [idtac; trivial] ) let change_sq (t1 : term) : Tac unit = change (mk_e_app (`squash) [t1]) let finish_by (t : unit -> Tac 'a) : Tac 'a = let x = t () in or_else qed (fun () -> fail "finish_by: not finished"); x let solve_then #a #b (t1 : unit -> Tac a) (t2 : a -> Tac b) : Tac b = dup (); let x = focus (fun () -> finish_by t1) in let y = t2 x in trefl (); y let add_elem (t : unit -> Tac 'a) : Tac 'a = focus (fun () -> apply (`Cons); focus (fun () -> let x = t () in qed (); x ) ) (* * Specialize a function by partially evaluating it * For example: * let rec foo (l:list int) (x:int) :St int = match l with | [] -> x | hd::tl -> x + foo tl x let f :int -> St int = synth_by_tactic (specialize (foo [1; 2]) [%`foo]) * would make the definition of f as x + x + x * * f is the term that needs to be specialized * l is the list of names to be delta-ed *) let specialize (#a:Type) (f:a) (l:list string) :unit -> Tac unit = fun () -> solve_then (fun () -> exact (quote f)) (fun () -> norm [delta_only l; iota; zeta]) let tlabel (l:string) = match goals () with | [] -> fail "tlabel: no goals" | h::t -> set_goals (set_label l h :: t) let tlabel' (l:string) = match goals () with | [] -> fail "tlabel': no goals" | h::t -> let h = set_label (l ^ get_label h) h in set_goals (h :: t) let focus_all () : Tac unit = set_goals (goals () @ smt_goals ()); set_smt_goals [] private let rec extract_nth (n:nat) (l : list 'a) : option ('a * list 'a) = match n, l with | _, [] -> None | 0, hd::tl -> Some (hd, tl) | _, hd::tl -> begin match extract_nth (n-1) tl with | Some (hd', tl') -> Some (hd', hd::tl') | None -> None end let bump_nth (n:pos) : Tac unit = // n-1 since goal numbering begins at 1 match extract_nth (n - 1) (goals ()) with | None -> fail "bump_nth: not that many goals" | Some (h, t) -> set_goals (h :: t) let rec destruct_list (t : term) : Tac (list term) = let head, args = collect_app t in match inspect head, args with | Tv_FVar fv, [(a1, Q_Explicit); (a2, Q_Explicit)] | Tv_FVar fv, [(_, Q_Implicit); (a1, Q_Explicit); (a2, Q_Explicit)] -> if inspect_fv fv = cons_qn then a1 :: destruct_list a2 else raise NotAListLiteral | Tv_FVar fv, _ -> if inspect_fv fv = nil_qn then [] else raise NotAListLiteral | _ -> raise NotAListLiteral private let get_match_body () : Tac term = match unsquash_term (cur_goal ()) with | None -> fail "" | Some t -> match inspect_unascribe t with | Tv_Match sc _ _ -> sc | _ -> fail "Goal is not a match" private let rec last (x : list 'a) : Tac 'a = match x with | [] -> fail "last: empty list" | [x] -> x | _::xs -> last xs (** When the goal is [match e with | p1 -> e1 ... | pn -> en], destruct it into [n] goals for each possible case, including an
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V2.Derived.focus", "FStar.Tactics.V2.Derived.iterAll", "FStar.Stubs.Tactics.V2.Builtins.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.iota", "Prims.Nil", "FStar.Tactics.V2.Derived.grewrite_eq", "FStar.Tactics.NamedView.binding", "FStar.Tactics.V2.Derived.last", "Prims.list", "FStar.Tactics.V2.Derived.repeat", "FStar.Stubs.Tactics.V2.Builtins.intro", "FStar.Pervasives.Native.tuple2", "FStar.Stubs.Reflection.Types.fv", "Prims.nat", "FStar.Stubs.Tactics.V2.Builtins.t_destruct", "FStar.Tactics.NamedView.term", "FStar.Tactics.V2.Derived.get_match_body" ]
[]
false
true
false
false
false
let branch_on_match () : Tac unit =
focus (fun () -> let x = get_match_body () in let _ = t_destruct x in iterAll (fun () -> let bs = repeat intro in let b = last bs in grewrite_eq b; norm [iota]))
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.__assumption_aux
val __assumption_aux (xs: list binding) : Tac unit
val __assumption_aux (xs: list binding) : Tac unit
let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 27, "end_line": 582, "start_col": 0, "start_line": 574 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
xs: Prims.list FStar.Tactics.NamedView.binding -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.list", "FStar.Tactics.NamedView.binding", "FStar.Tactics.V2.Derived.fail", "Prims.unit", "FStar.Tactics.V2.Derived.try_with", "FStar.Tactics.V2.Derived.exact", "FStar.Tactics.V2.SyntaxCoercions.binding_to_term", "Prims.exn", "FStar.Tactics.V2.Derived.apply", "FStar.Tactics.V2.Derived.__assumption_aux" ]
[ "recursion" ]
false
true
false
false
false
let rec __assumption_aux (xs: list binding) : Tac unit =
match xs with | [] -> fail "no assumption matches goal" | b :: bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.string_to_term_with_lb
val string_to_term_with_lb (letbindings: list (string * term)) (e: env) (t: string) : Tac term
val string_to_term_with_lb (letbindings: list (string * term)) (e: env) (t: string) : Tac term
let string_to_term_with_lb (letbindings: list (string * term)) (e: env) (t: string): Tac term = let e, lb_bindings : env * list (term & binding) = fold_left (fun (e, lb_bvs) (i, v) -> let e, b = push_bv_dsenv e i in e, (v, b)::lb_bvs ) (e, []) letbindings in let t = string_to_term e t in fold_left (fun t (i, b) -> pack (Tv_Let false [] (binding_to_simple_binder b) i t)) t lb_bindings
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 21, "end_line": 916, "start_col": 0, "start_line": 905 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); () val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a let magic_dump #a #x () = x let change_with t1 t2 : Tac unit = focus (fun () -> grewrite t1 t2; iseq [idtac; trivial] ) let change_sq (t1 : term) : Tac unit = change (mk_e_app (`squash) [t1]) let finish_by (t : unit -> Tac 'a) : Tac 'a = let x = t () in or_else qed (fun () -> fail "finish_by: not finished"); x let solve_then #a #b (t1 : unit -> Tac a) (t2 : a -> Tac b) : Tac b = dup (); let x = focus (fun () -> finish_by t1) in let y = t2 x in trefl (); y let add_elem (t : unit -> Tac 'a) : Tac 'a = focus (fun () -> apply (`Cons); focus (fun () -> let x = t () in qed (); x ) ) (* * Specialize a function by partially evaluating it * For example: * let rec foo (l:list int) (x:int) :St int = match l with | [] -> x | hd::tl -> x + foo tl x let f :int -> St int = synth_by_tactic (specialize (foo [1; 2]) [%`foo]) * would make the definition of f as x + x + x * * f is the term that needs to be specialized * l is the list of names to be delta-ed *) let specialize (#a:Type) (f:a) (l:list string) :unit -> Tac unit = fun () -> solve_then (fun () -> exact (quote f)) (fun () -> norm [delta_only l; iota; zeta]) let tlabel (l:string) = match goals () with | [] -> fail "tlabel: no goals" | h::t -> set_goals (set_label l h :: t) let tlabel' (l:string) = match goals () with | [] -> fail "tlabel': no goals" | h::t -> let h = set_label (l ^ get_label h) h in set_goals (h :: t) let focus_all () : Tac unit = set_goals (goals () @ smt_goals ()); set_smt_goals [] private let rec extract_nth (n:nat) (l : list 'a) : option ('a * list 'a) = match n, l with | _, [] -> None | 0, hd::tl -> Some (hd, tl) | _, hd::tl -> begin match extract_nth (n-1) tl with | Some (hd', tl') -> Some (hd', hd::tl') | None -> None end let bump_nth (n:pos) : Tac unit = // n-1 since goal numbering begins at 1 match extract_nth (n - 1) (goals ()) with | None -> fail "bump_nth: not that many goals" | Some (h, t) -> set_goals (h :: t) let rec destruct_list (t : term) : Tac (list term) = let head, args = collect_app t in match inspect head, args with | Tv_FVar fv, [(a1, Q_Explicit); (a2, Q_Explicit)] | Tv_FVar fv, [(_, Q_Implicit); (a1, Q_Explicit); (a2, Q_Explicit)] -> if inspect_fv fv = cons_qn then a1 :: destruct_list a2 else raise NotAListLiteral | Tv_FVar fv, _ -> if inspect_fv fv = nil_qn then [] else raise NotAListLiteral | _ -> raise NotAListLiteral private let get_match_body () : Tac term = match unsquash_term (cur_goal ()) with | None -> fail "" | Some t -> match inspect_unascribe t with | Tv_Match sc _ _ -> sc | _ -> fail "Goal is not a match" private let rec last (x : list 'a) : Tac 'a = match x with | [] -> fail "last: empty list" | [x] -> x | _::xs -> last xs (** When the goal is [match e with | p1 -> e1 ... | pn -> en], destruct it into [n] goals for each possible case, including an hypothesis for [e] matching the corresponding pattern. *) let branch_on_match () : Tac unit = focus (fun () -> let x = get_match_body () in let _ = t_destruct x in iterAll (fun () -> let bs = repeat intro in let b = last bs in (* this one is the equality *) grewrite_eq b; norm [iota]) ) (** When the argument [i] is non-negative, [nth_var] grabs the nth binder in the current goal. When it is negative, it grabs the (-i-1)th binder counting from the end of the goal. That is, [nth_var (-1)] will return the last binder, [nth_var (-2)] the second to last, and so on. *) let nth_var (i:int) : Tac binding = let bs = cur_vars () in let k : int = if i >= 0 then i else List.Tot.Base.length bs + i in let k : nat = if k < 0 then fail "not enough binders" else k in match List.Tot.Base.nth bs k with | None -> fail "not enough binders" | Some b -> b exception Appears (** Decides whether a top-level name [nm] syntactically appears in the term [t]. *) let name_appears_in (nm:name) (t:term) : Tac bool = let ff (t : term) : Tac term = match inspect t with | Tv_FVar fv -> if inspect_fv fv = nm then raise Appears; t | tv -> pack tv in try ignore (V.visit_tm ff t); false with | Appears -> true | e -> raise e (** [mk_abs [x1; ...; xn] t] returns the term [fun x1 ... xn -> t] *) let rec mk_abs (args : list binder) (t : term) : Tac term (decreases args) = match args with | [] -> t | a :: args' -> let t' = mk_abs args' t in pack (Tv_Abs a t') // GGG Needed? delete if not let namedv_to_simple_binder (n : namedv) : Tac simple_binder = let nv = inspect_namedv n in { ppname = nv.ppname; uniq = nv.uniq; sort = unseal nv.sort; (* GGG USINGSORT *) qual = Q_Explicit; attrs = []; } [@@coercion] let binding_to_simple_binder (b : binding) : Tot simple_binder = { ppname = b.ppname; uniq = b.uniq; sort = b.sort; qual = Q_Explicit; attrs = []; } (** [string_to_term_with_lb [(id1, t1); ...; (idn, tn)] e s] parses [s] as a term in environment [e] augmented with bindings
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
letbindings: Prims.list (Prims.string * FStar.Tactics.NamedView.term) -> e: FStar.Stubs.Reflection.Types.env -> t: Prims.string -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.term
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.list", "FStar.Pervasives.Native.tuple2", "Prims.string", "FStar.Tactics.NamedView.term", "FStar.Stubs.Reflection.Types.env", "FStar.Tactics.NamedView.binding", "FStar.Tactics.Util.fold_left", "FStar.Tactics.NamedView.pack", "FStar.Tactics.NamedView.Tv_Let", "Prims.Nil", "FStar.Tactics.V2.Derived.binding_to_simple_binder", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Tactics.V2.Builtins.string_to_term", "FStar.Stubs.Reflection.V2.Data.binding", "FStar.Pervasives.Native.Mktuple2", "Prims.Cons", "FStar.Stubs.Tactics.V2.Builtins.push_bv_dsenv" ]
[]
false
true
false
false
false
let string_to_term_with_lb (letbindings: list (string * term)) (e: env) (t: string) : Tac term =
let e, lb_bindings:env * list (term & binding) = fold_left (fun (e, lb_bvs) (i, v) -> let e, b = push_bv_dsenv e i in e, (v, b) :: lb_bvs) (e, []) letbindings in let t = string_to_term e t in fold_left (fun t (i, b) -> pack (Tv_Let false [] (binding_to_simple_binder b) i t)) t lb_bindings
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.try_with
val try_with (f: (unit -> Tac 'a)) (h: (exn -> Tac 'a)) : Tac 'a
val try_with (f: (unit -> Tac 'a)) (h: (exn -> Tac 'a)) : Tac 'a
let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 16, "end_line": 449, "start_col": 0, "start_line": 446 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: Prims.unit -> FStar.Tactics.Effect.Tac 'a) -> h: (_: Prims.exn -> FStar.Tactics.Effect.Tac 'a) -> FStar.Tactics.Effect.Tac 'a
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "Prims.exn", "FStar.Pervasives.either", "FStar.Stubs.Tactics.V2.Builtins.catch" ]
[]
false
true
false
false
false
let try_with (f: (unit -> Tac 'a)) (h: (exn -> Tac 'a)) : Tac 'a =
match catch f with | Inl e -> h e | Inr x -> x
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.smt_sync'
val smt_sync' (fuel ifuel: nat) : Tac unit
val smt_sync' (fuel ifuel: nat) : Tac unit
let smt_sync' (fuel ifuel : nat) : Tac unit = let vcfg = get_vconfig () in let vcfg' = { vcfg with initial_fuel = fuel; max_fuel = fuel ; initial_ifuel = ifuel; max_ifuel = ifuel } in t_smt_sync vcfg'
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 20, "end_line": 936, "start_col": 0, "start_line": 931 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); () val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a let magic_dump #a #x () = x let change_with t1 t2 : Tac unit = focus (fun () -> grewrite t1 t2; iseq [idtac; trivial] ) let change_sq (t1 : term) : Tac unit = change (mk_e_app (`squash) [t1]) let finish_by (t : unit -> Tac 'a) : Tac 'a = let x = t () in or_else qed (fun () -> fail "finish_by: not finished"); x let solve_then #a #b (t1 : unit -> Tac a) (t2 : a -> Tac b) : Tac b = dup (); let x = focus (fun () -> finish_by t1) in let y = t2 x in trefl (); y let add_elem (t : unit -> Tac 'a) : Tac 'a = focus (fun () -> apply (`Cons); focus (fun () -> let x = t () in qed (); x ) ) (* * Specialize a function by partially evaluating it * For example: * let rec foo (l:list int) (x:int) :St int = match l with | [] -> x | hd::tl -> x + foo tl x let f :int -> St int = synth_by_tactic (specialize (foo [1; 2]) [%`foo]) * would make the definition of f as x + x + x * * f is the term that needs to be specialized * l is the list of names to be delta-ed *) let specialize (#a:Type) (f:a) (l:list string) :unit -> Tac unit = fun () -> solve_then (fun () -> exact (quote f)) (fun () -> norm [delta_only l; iota; zeta]) let tlabel (l:string) = match goals () with | [] -> fail "tlabel: no goals" | h::t -> set_goals (set_label l h :: t) let tlabel' (l:string) = match goals () with | [] -> fail "tlabel': no goals" | h::t -> let h = set_label (l ^ get_label h) h in set_goals (h :: t) let focus_all () : Tac unit = set_goals (goals () @ smt_goals ()); set_smt_goals [] private let rec extract_nth (n:nat) (l : list 'a) : option ('a * list 'a) = match n, l with | _, [] -> None | 0, hd::tl -> Some (hd, tl) | _, hd::tl -> begin match extract_nth (n-1) tl with | Some (hd', tl') -> Some (hd', hd::tl') | None -> None end let bump_nth (n:pos) : Tac unit = // n-1 since goal numbering begins at 1 match extract_nth (n - 1) (goals ()) with | None -> fail "bump_nth: not that many goals" | Some (h, t) -> set_goals (h :: t) let rec destruct_list (t : term) : Tac (list term) = let head, args = collect_app t in match inspect head, args with | Tv_FVar fv, [(a1, Q_Explicit); (a2, Q_Explicit)] | Tv_FVar fv, [(_, Q_Implicit); (a1, Q_Explicit); (a2, Q_Explicit)] -> if inspect_fv fv = cons_qn then a1 :: destruct_list a2 else raise NotAListLiteral | Tv_FVar fv, _ -> if inspect_fv fv = nil_qn then [] else raise NotAListLiteral | _ -> raise NotAListLiteral private let get_match_body () : Tac term = match unsquash_term (cur_goal ()) with | None -> fail "" | Some t -> match inspect_unascribe t with | Tv_Match sc _ _ -> sc | _ -> fail "Goal is not a match" private let rec last (x : list 'a) : Tac 'a = match x with | [] -> fail "last: empty list" | [x] -> x | _::xs -> last xs (** When the goal is [match e with | p1 -> e1 ... | pn -> en], destruct it into [n] goals for each possible case, including an hypothesis for [e] matching the corresponding pattern. *) let branch_on_match () : Tac unit = focus (fun () -> let x = get_match_body () in let _ = t_destruct x in iterAll (fun () -> let bs = repeat intro in let b = last bs in (* this one is the equality *) grewrite_eq b; norm [iota]) ) (** When the argument [i] is non-negative, [nth_var] grabs the nth binder in the current goal. When it is negative, it grabs the (-i-1)th binder counting from the end of the goal. That is, [nth_var (-1)] will return the last binder, [nth_var (-2)] the second to last, and so on. *) let nth_var (i:int) : Tac binding = let bs = cur_vars () in let k : int = if i >= 0 then i else List.Tot.Base.length bs + i in let k : nat = if k < 0 then fail "not enough binders" else k in match List.Tot.Base.nth bs k with | None -> fail "not enough binders" | Some b -> b exception Appears (** Decides whether a top-level name [nm] syntactically appears in the term [t]. *) let name_appears_in (nm:name) (t:term) : Tac bool = let ff (t : term) : Tac term = match inspect t with | Tv_FVar fv -> if inspect_fv fv = nm then raise Appears; t | tv -> pack tv in try ignore (V.visit_tm ff t); false with | Appears -> true | e -> raise e (** [mk_abs [x1; ...; xn] t] returns the term [fun x1 ... xn -> t] *) let rec mk_abs (args : list binder) (t : term) : Tac term (decreases args) = match args with | [] -> t | a :: args' -> let t' = mk_abs args' t in pack (Tv_Abs a t') // GGG Needed? delete if not let namedv_to_simple_binder (n : namedv) : Tac simple_binder = let nv = inspect_namedv n in { ppname = nv.ppname; uniq = nv.uniq; sort = unseal nv.sort; (* GGG USINGSORT *) qual = Q_Explicit; attrs = []; } [@@coercion] let binding_to_simple_binder (b : binding) : Tot simple_binder = { ppname = b.ppname; uniq = b.uniq; sort = b.sort; qual = Q_Explicit; attrs = []; } (** [string_to_term_with_lb [(id1, t1); ...; (idn, tn)] e s] parses [s] as a term in environment [e] augmented with bindings [id1, t1], ..., [idn, tn]. *) let string_to_term_with_lb (letbindings: list (string * term)) (e: env) (t: string): Tac term = let e, lb_bindings : env * list (term & binding) = fold_left (fun (e, lb_bvs) (i, v) -> let e, b = push_bv_dsenv e i in e, (v, b)::lb_bvs ) (e, []) letbindings in let t = string_to_term e t in fold_left (fun t (i, b) -> pack (Tv_Let false [] (binding_to_simple_binder b) i t)) t lb_bindings private val lem_trans : (#a:Type) -> (#x:a) -> (#z:a) -> (#y:a) -> squash (x == y) -> squash (y == z) -> Lemma (x == z) private let lem_trans #a #x #z #y e1 e2 = () (** Transivity of equality: reduce [x == z] to [x == ?u] and [?u == z]. *) let trans () : Tac unit = apply_lemma (`lem_trans) (* Alias to just use the current vconfig *) let smt_sync () : Tac unit = t_smt_sync (get_vconfig ())
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
fuel: Prims.nat -> ifuel: Prims.nat -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.nat", "FStar.Stubs.Tactics.V2.Builtins.t_smt_sync", "Prims.unit", "FStar.VConfig.vconfig", "FStar.VConfig.Mkvconfig", "FStar.VConfig.__proj__Mkvconfig__item__detail_errors", "FStar.VConfig.__proj__Mkvconfig__item__detail_hint_replay", "FStar.VConfig.__proj__Mkvconfig__item__no_smt", "FStar.VConfig.__proj__Mkvconfig__item__quake_lo", "FStar.VConfig.__proj__Mkvconfig__item__quake_hi", "FStar.VConfig.__proj__Mkvconfig__item__quake_keep", "FStar.VConfig.__proj__Mkvconfig__item__retry", "FStar.VConfig.__proj__Mkvconfig__item__smtencoding_elim_box", "FStar.VConfig.__proj__Mkvconfig__item__smtencoding_nl_arith_repr", "FStar.VConfig.__proj__Mkvconfig__item__smtencoding_l_arith_repr", "FStar.VConfig.__proj__Mkvconfig__item__smtencoding_valid_intro", "FStar.VConfig.__proj__Mkvconfig__item__smtencoding_valid_elim", "FStar.VConfig.__proj__Mkvconfig__item__tcnorm", "FStar.VConfig.__proj__Mkvconfig__item__no_plugins", "FStar.VConfig.__proj__Mkvconfig__item__no_tactics", "FStar.VConfig.__proj__Mkvconfig__item__z3cliopt", "FStar.VConfig.__proj__Mkvconfig__item__z3smtopt", "FStar.VConfig.__proj__Mkvconfig__item__z3refresh", "FStar.VConfig.__proj__Mkvconfig__item__z3rlimit", "FStar.VConfig.__proj__Mkvconfig__item__z3rlimit_factor", "FStar.VConfig.__proj__Mkvconfig__item__z3seed", "FStar.VConfig.__proj__Mkvconfig__item__z3version", "FStar.VConfig.__proj__Mkvconfig__item__trivial_pre_for_unannotated_effectful_fns", "FStar.VConfig.__proj__Mkvconfig__item__reuse_hint_for", "FStar.Stubs.Tactics.V2.Builtins.get_vconfig" ]
[]
false
true
false
false
false
let smt_sync' (fuel ifuel: nat) : Tac unit =
let vcfg = get_vconfig () in let vcfg' = { vcfg with initial_fuel = fuel; max_fuel = fuel; initial_ifuel = ifuel; max_ifuel = ifuel } in t_smt_sync vcfg'
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.trans
val trans: Prims.unit -> Tac unit
val trans: Prims.unit -> Tac unit
let trans () : Tac unit = apply_lemma (`lem_trans)
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 50, "end_line": 925, "start_col": 0, "start_line": 925 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); () val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a let magic_dump #a #x () = x let change_with t1 t2 : Tac unit = focus (fun () -> grewrite t1 t2; iseq [idtac; trivial] ) let change_sq (t1 : term) : Tac unit = change (mk_e_app (`squash) [t1]) let finish_by (t : unit -> Tac 'a) : Tac 'a = let x = t () in or_else qed (fun () -> fail "finish_by: not finished"); x let solve_then #a #b (t1 : unit -> Tac a) (t2 : a -> Tac b) : Tac b = dup (); let x = focus (fun () -> finish_by t1) in let y = t2 x in trefl (); y let add_elem (t : unit -> Tac 'a) : Tac 'a = focus (fun () -> apply (`Cons); focus (fun () -> let x = t () in qed (); x ) ) (* * Specialize a function by partially evaluating it * For example: * let rec foo (l:list int) (x:int) :St int = match l with | [] -> x | hd::tl -> x + foo tl x let f :int -> St int = synth_by_tactic (specialize (foo [1; 2]) [%`foo]) * would make the definition of f as x + x + x * * f is the term that needs to be specialized * l is the list of names to be delta-ed *) let specialize (#a:Type) (f:a) (l:list string) :unit -> Tac unit = fun () -> solve_then (fun () -> exact (quote f)) (fun () -> norm [delta_only l; iota; zeta]) let tlabel (l:string) = match goals () with | [] -> fail "tlabel: no goals" | h::t -> set_goals (set_label l h :: t) let tlabel' (l:string) = match goals () with | [] -> fail "tlabel': no goals" | h::t -> let h = set_label (l ^ get_label h) h in set_goals (h :: t) let focus_all () : Tac unit = set_goals (goals () @ smt_goals ()); set_smt_goals [] private let rec extract_nth (n:nat) (l : list 'a) : option ('a * list 'a) = match n, l with | _, [] -> None | 0, hd::tl -> Some (hd, tl) | _, hd::tl -> begin match extract_nth (n-1) tl with | Some (hd', tl') -> Some (hd', hd::tl') | None -> None end let bump_nth (n:pos) : Tac unit = // n-1 since goal numbering begins at 1 match extract_nth (n - 1) (goals ()) with | None -> fail "bump_nth: not that many goals" | Some (h, t) -> set_goals (h :: t) let rec destruct_list (t : term) : Tac (list term) = let head, args = collect_app t in match inspect head, args with | Tv_FVar fv, [(a1, Q_Explicit); (a2, Q_Explicit)] | Tv_FVar fv, [(_, Q_Implicit); (a1, Q_Explicit); (a2, Q_Explicit)] -> if inspect_fv fv = cons_qn then a1 :: destruct_list a2 else raise NotAListLiteral | Tv_FVar fv, _ -> if inspect_fv fv = nil_qn then [] else raise NotAListLiteral | _ -> raise NotAListLiteral private let get_match_body () : Tac term = match unsquash_term (cur_goal ()) with | None -> fail "" | Some t -> match inspect_unascribe t with | Tv_Match sc _ _ -> sc | _ -> fail "Goal is not a match" private let rec last (x : list 'a) : Tac 'a = match x with | [] -> fail "last: empty list" | [x] -> x | _::xs -> last xs (** When the goal is [match e with | p1 -> e1 ... | pn -> en], destruct it into [n] goals for each possible case, including an hypothesis for [e] matching the corresponding pattern. *) let branch_on_match () : Tac unit = focus (fun () -> let x = get_match_body () in let _ = t_destruct x in iterAll (fun () -> let bs = repeat intro in let b = last bs in (* this one is the equality *) grewrite_eq b; norm [iota]) ) (** When the argument [i] is non-negative, [nth_var] grabs the nth binder in the current goal. When it is negative, it grabs the (-i-1)th binder counting from the end of the goal. That is, [nth_var (-1)] will return the last binder, [nth_var (-2)] the second to last, and so on. *) let nth_var (i:int) : Tac binding = let bs = cur_vars () in let k : int = if i >= 0 then i else List.Tot.Base.length bs + i in let k : nat = if k < 0 then fail "not enough binders" else k in match List.Tot.Base.nth bs k with | None -> fail "not enough binders" | Some b -> b exception Appears (** Decides whether a top-level name [nm] syntactically appears in the term [t]. *) let name_appears_in (nm:name) (t:term) : Tac bool = let ff (t : term) : Tac term = match inspect t with | Tv_FVar fv -> if inspect_fv fv = nm then raise Appears; t | tv -> pack tv in try ignore (V.visit_tm ff t); false with | Appears -> true | e -> raise e (** [mk_abs [x1; ...; xn] t] returns the term [fun x1 ... xn -> t] *) let rec mk_abs (args : list binder) (t : term) : Tac term (decreases args) = match args with | [] -> t | a :: args' -> let t' = mk_abs args' t in pack (Tv_Abs a t') // GGG Needed? delete if not let namedv_to_simple_binder (n : namedv) : Tac simple_binder = let nv = inspect_namedv n in { ppname = nv.ppname; uniq = nv.uniq; sort = unseal nv.sort; (* GGG USINGSORT *) qual = Q_Explicit; attrs = []; } [@@coercion] let binding_to_simple_binder (b : binding) : Tot simple_binder = { ppname = b.ppname; uniq = b.uniq; sort = b.sort; qual = Q_Explicit; attrs = []; } (** [string_to_term_with_lb [(id1, t1); ...; (idn, tn)] e s] parses [s] as a term in environment [e] augmented with bindings [id1, t1], ..., [idn, tn]. *) let string_to_term_with_lb (letbindings: list (string * term)) (e: env) (t: string): Tac term = let e, lb_bindings : env * list (term & binding) = fold_left (fun (e, lb_bvs) (i, v) -> let e, b = push_bv_dsenv e i in e, (v, b)::lb_bvs ) (e, []) letbindings in let t = string_to_term e t in fold_left (fun t (i, b) -> pack (Tv_Let false [] (binding_to_simple_binder b) i t)) t lb_bindings private val lem_trans : (#a:Type) -> (#x:a) -> (#z:a) -> (#y:a) -> squash (x == y) -> squash (y == z) -> Lemma (x == z) private let lem_trans #a #x #z #y e1 e2 = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V2.Derived.apply_lemma" ]
[]
false
true
false
false
false
let trans () : Tac unit =
apply_lemma (`lem_trans)
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.smt_sync
val smt_sync: Prims.unit -> Tac unit
val smt_sync: Prims.unit -> Tac unit
let smt_sync () : Tac unit = t_smt_sync (get_vconfig ())
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 56, "end_line": 928, "start_col": 0, "start_line": 928 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); () val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a let magic_dump #a #x () = x let change_with t1 t2 : Tac unit = focus (fun () -> grewrite t1 t2; iseq [idtac; trivial] ) let change_sq (t1 : term) : Tac unit = change (mk_e_app (`squash) [t1]) let finish_by (t : unit -> Tac 'a) : Tac 'a = let x = t () in or_else qed (fun () -> fail "finish_by: not finished"); x let solve_then #a #b (t1 : unit -> Tac a) (t2 : a -> Tac b) : Tac b = dup (); let x = focus (fun () -> finish_by t1) in let y = t2 x in trefl (); y let add_elem (t : unit -> Tac 'a) : Tac 'a = focus (fun () -> apply (`Cons); focus (fun () -> let x = t () in qed (); x ) ) (* * Specialize a function by partially evaluating it * For example: * let rec foo (l:list int) (x:int) :St int = match l with | [] -> x | hd::tl -> x + foo tl x let f :int -> St int = synth_by_tactic (specialize (foo [1; 2]) [%`foo]) * would make the definition of f as x + x + x * * f is the term that needs to be specialized * l is the list of names to be delta-ed *) let specialize (#a:Type) (f:a) (l:list string) :unit -> Tac unit = fun () -> solve_then (fun () -> exact (quote f)) (fun () -> norm [delta_only l; iota; zeta]) let tlabel (l:string) = match goals () with | [] -> fail "tlabel: no goals" | h::t -> set_goals (set_label l h :: t) let tlabel' (l:string) = match goals () with | [] -> fail "tlabel': no goals" | h::t -> let h = set_label (l ^ get_label h) h in set_goals (h :: t) let focus_all () : Tac unit = set_goals (goals () @ smt_goals ()); set_smt_goals [] private let rec extract_nth (n:nat) (l : list 'a) : option ('a * list 'a) = match n, l with | _, [] -> None | 0, hd::tl -> Some (hd, tl) | _, hd::tl -> begin match extract_nth (n-1) tl with | Some (hd', tl') -> Some (hd', hd::tl') | None -> None end let bump_nth (n:pos) : Tac unit = // n-1 since goal numbering begins at 1 match extract_nth (n - 1) (goals ()) with | None -> fail "bump_nth: not that many goals" | Some (h, t) -> set_goals (h :: t) let rec destruct_list (t : term) : Tac (list term) = let head, args = collect_app t in match inspect head, args with | Tv_FVar fv, [(a1, Q_Explicit); (a2, Q_Explicit)] | Tv_FVar fv, [(_, Q_Implicit); (a1, Q_Explicit); (a2, Q_Explicit)] -> if inspect_fv fv = cons_qn then a1 :: destruct_list a2 else raise NotAListLiteral | Tv_FVar fv, _ -> if inspect_fv fv = nil_qn then [] else raise NotAListLiteral | _ -> raise NotAListLiteral private let get_match_body () : Tac term = match unsquash_term (cur_goal ()) with | None -> fail "" | Some t -> match inspect_unascribe t with | Tv_Match sc _ _ -> sc | _ -> fail "Goal is not a match" private let rec last (x : list 'a) : Tac 'a = match x with | [] -> fail "last: empty list" | [x] -> x | _::xs -> last xs (** When the goal is [match e with | p1 -> e1 ... | pn -> en], destruct it into [n] goals for each possible case, including an hypothesis for [e] matching the corresponding pattern. *) let branch_on_match () : Tac unit = focus (fun () -> let x = get_match_body () in let _ = t_destruct x in iterAll (fun () -> let bs = repeat intro in let b = last bs in (* this one is the equality *) grewrite_eq b; norm [iota]) ) (** When the argument [i] is non-negative, [nth_var] grabs the nth binder in the current goal. When it is negative, it grabs the (-i-1)th binder counting from the end of the goal. That is, [nth_var (-1)] will return the last binder, [nth_var (-2)] the second to last, and so on. *) let nth_var (i:int) : Tac binding = let bs = cur_vars () in let k : int = if i >= 0 then i else List.Tot.Base.length bs + i in let k : nat = if k < 0 then fail "not enough binders" else k in match List.Tot.Base.nth bs k with | None -> fail "not enough binders" | Some b -> b exception Appears (** Decides whether a top-level name [nm] syntactically appears in the term [t]. *) let name_appears_in (nm:name) (t:term) : Tac bool = let ff (t : term) : Tac term = match inspect t with | Tv_FVar fv -> if inspect_fv fv = nm then raise Appears; t | tv -> pack tv in try ignore (V.visit_tm ff t); false with | Appears -> true | e -> raise e (** [mk_abs [x1; ...; xn] t] returns the term [fun x1 ... xn -> t] *) let rec mk_abs (args : list binder) (t : term) : Tac term (decreases args) = match args with | [] -> t | a :: args' -> let t' = mk_abs args' t in pack (Tv_Abs a t') // GGG Needed? delete if not let namedv_to_simple_binder (n : namedv) : Tac simple_binder = let nv = inspect_namedv n in { ppname = nv.ppname; uniq = nv.uniq; sort = unseal nv.sort; (* GGG USINGSORT *) qual = Q_Explicit; attrs = []; } [@@coercion] let binding_to_simple_binder (b : binding) : Tot simple_binder = { ppname = b.ppname; uniq = b.uniq; sort = b.sort; qual = Q_Explicit; attrs = []; } (** [string_to_term_with_lb [(id1, t1); ...; (idn, tn)] e s] parses [s] as a term in environment [e] augmented with bindings [id1, t1], ..., [idn, tn]. *) let string_to_term_with_lb (letbindings: list (string * term)) (e: env) (t: string): Tac term = let e, lb_bindings : env * list (term & binding) = fold_left (fun (e, lb_bvs) (i, v) -> let e, b = push_bv_dsenv e i in e, (v, b)::lb_bvs ) (e, []) letbindings in let t = string_to_term e t in fold_left (fun t (i, b) -> pack (Tv_Let false [] (binding_to_simple_binder b) i t)) t lb_bindings private val lem_trans : (#a:Type) -> (#x:a) -> (#z:a) -> (#y:a) -> squash (x == y) -> squash (y == z) -> Lemma (x == z) private let lem_trans #a #x #z #y e1 e2 = () (** Transivity of equality: reduce [x == z] to [x == ?u] and [?u == z]. *) let trans () : Tac unit = apply_lemma (`lem_trans)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Stubs.Tactics.V2.Builtins.t_smt_sync", "FStar.VConfig.vconfig", "FStar.Stubs.Tactics.V2.Builtins.get_vconfig" ]
[]
false
true
false
false
false
let smt_sync () : Tac unit =
t_smt_sync (get_vconfig ())
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.__eq_sym
val __eq_sym (#t: _) (a b: t) : Lemma ((a == b) == (b == a))
val __eq_sym (#t: _) (a b: t) : Lemma ((a == b) == (b == a))
let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a)
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 55, "end_line": 599, "start_col": 0, "start_line": 598 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: t -> b: t -> FStar.Pervasives.Lemma (ensures a == b == (b == a))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.PropositionalExtensionality.apply", "Prims.eq2", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.logical", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let __eq_sym #t (a: t) (b: t) : Lemma ((a == b) == (b == a)) =
FStar.PropositionalExtensionality.apply (a == b) (b == a)
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.try_rewrite_equality
val try_rewrite_equality (x: term) (bs: list binding) : Tac unit
val try_rewrite_equality (x: term) (bs: list binding) : Tac unit
let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 11, "end_line": 621, "start_col": 0, "start_line": 610 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.Tactics.NamedView.term -> bs: Prims.list FStar.Tactics.NamedView.binding -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Tactics.NamedView.term", "Prims.list", "FStar.Tactics.NamedView.binding", "Prims.unit", "FStar.Pervasives.Native.option", "FStar.Stubs.Reflection.Types.typ", "FStar.Stubs.Reflection.V2.Builtins.term_eq", "FStar.Stubs.Tactics.V2.Builtins.rewrite", "Prims.bool", "FStar.Tactics.V2.Derived.try_rewrite_equality", "FStar.Reflection.V2.Formula.formula", "FStar.Reflection.V2.Formula.term_as_formula", "FStar.Tactics.V2.Derived.type_of_binding" ]
[ "recursion" ]
false
true
false
false
false
let rec try_rewrite_equality (x: term) (bs: list binding) : Tac unit =
match bs with | [] -> () | x_t :: bs -> match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs
false
Vale.Def.PossiblyMonad.fst
Vale.Def.PossiblyMonad.tighten
val tighten (#t1: Type) (#t2: Type{t2 `subtype_of` t1}) (x: possibly t1 {Ok? x ==> (Ok?.v x) `has_type` t2}) : possibly t2
val tighten (#t1: Type) (#t2: Type{t2 `subtype_of` t1}) (x: possibly t1 {Ok? x ==> (Ok?.v x) `has_type` t2}) : possibly t2
let tighten (#t1:Type) (#t2:Type{t2 `subtype_of` t1}) (x:possibly t1{Ok? x ==> Ok?.v x `has_type` t2}) : possibly t2 = match x with | Ok x' -> Ok x' | Err s -> Err s
{ "file_name": "vale/specs/defs/Vale.Def.PossiblyMonad.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 18, "end_line": 38, "start_col": 0, "start_line": 34 }
module Vale.Def.PossiblyMonad /// Similar to the [maybe] monad in Haskell (which is like the /// [option] type in F* and OCaml), but instead, we also store the /// reason for the error when the error occurs. type possibly 'a = | Ok : v:'a -> possibly 'a | Err : reason:string -> possibly 'a unfold let return (#a:Type) (x:a) : possibly a = Ok x unfold let (let+) (#a #b:Type) (x:possibly a) (f:a -> possibly b) : possibly b = match x with | Err s -> Err s | Ok x' -> f x' unfold let fail_with (#a:Type) (s:string) : possibly a = Err s unfold let unimplemented (#a:Type) (s:string) : possibly a = fail_with ("Unimplemented: " ^ s) (** Allows moving to a "looser" monad type, always *) unfold let loosen (#t1:Type) (#t2:Type{t1 `subtype_of` t2}) (x:possibly t1) : possibly t2 = match x with | Ok x' -> Ok x' | Err s -> Err s (** Allows moving to a "tighter" monad type, as long as the monad is guaranteed statically to be within this tighter type *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Def.PossiblyMonad.fst" }
[ { "abbrev": false, "full_module": "Vale.Def", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Vale.Def.PossiblyMonad.possibly t1 {Ok? x ==> Prims.has_type (Ok?.v x) t2} -> Vale.Def.PossiblyMonad.possibly t2
Prims.Tot
[ "total" ]
[]
[ "Prims.subtype_of", "Vale.Def.PossiblyMonad.possibly", "Prims.l_imp", "Prims.b2t", "Vale.Def.PossiblyMonad.uu___is_Ok", "Prims.has_type", "Vale.Def.PossiblyMonad.__proj__Ok__item__v", "Vale.Def.PossiblyMonad.Ok", "Prims.string", "Vale.Def.PossiblyMonad.Err" ]
[]
false
false
false
false
false
let tighten (#t1: Type) (#t2: Type{t2 `subtype_of` t1}) (x: possibly t1 {Ok? x ==> (Ok?.v x) `has_type` t2}) : possibly t2 =
match x with | Ok x' -> Ok x' | Err s -> Err s
false
Vale.X64.Stack_Sems.fst
Vale.X64.Stack_Sems.stack_from_s
val stack_from_s (s:S.machine_stack) : vale_stack
val stack_from_s (s:S.machine_stack) : vale_stack
let stack_from_s s = s
{ "file_name": "vale/code/arch/x64/Vale.X64.Stack_Sems.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 22, "end_line": 7, "start_col": 0, "start_line": 7 }
module Vale.X64.Stack_Sems open FStar.Mul friend Vale.X64.Stack_i
{ "checked_file": "/", "dependencies": [ "Vale.X64.Stack_i.fst.checked", "Vale.Lib.Set.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Map.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Stack_Sems.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Vale.X64.Machine_Semantics_s.machine_stack -> Vale.X64.Stack_i.vale_stack
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_Semantics_s.machine_stack", "Vale.X64.Stack_i.vale_stack" ]
[]
false
false
false
true
false
let stack_from_s s =
s
false
Vale.Def.PossiblyMonad.fst
Vale.Def.PossiblyMonad.for_all
val for_all (f: ('a -> pbool)) (l: list 'a) : pbool
val for_all (f: ('a -> pbool)) (l: list 'a) : pbool
let rec for_all (f : 'a -> pbool) (l : list 'a) : pbool = match l with | [] -> ttrue | x :: xs -> f x &&. for_all f xs
{ "file_name": "vale/specs/defs/Vale.Def.PossiblyMonad.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 35, "end_line": 98, "start_col": 0, "start_line": 95 }
module Vale.Def.PossiblyMonad /// Similar to the [maybe] monad in Haskell (which is like the /// [option] type in F* and OCaml), but instead, we also store the /// reason for the error when the error occurs. type possibly 'a = | Ok : v:'a -> possibly 'a | Err : reason:string -> possibly 'a unfold let return (#a:Type) (x:a) : possibly a = Ok x unfold let (let+) (#a #b:Type) (x:possibly a) (f:a -> possibly b) : possibly b = match x with | Err s -> Err s | Ok x' -> f x' unfold let fail_with (#a:Type) (s:string) : possibly a = Err s unfold let unimplemented (#a:Type) (s:string) : possibly a = fail_with ("Unimplemented: " ^ s) (** Allows moving to a "looser" monad type, always *) unfold let loosen (#t1:Type) (#t2:Type{t1 `subtype_of` t2}) (x:possibly t1) : possibly t2 = match x with | Ok x' -> Ok x' | Err s -> Err s (** Allows moving to a "tighter" monad type, as long as the monad is guaranteed statically to be within this tighter type *) unfold let tighten (#t1:Type) (#t2:Type{t2 `subtype_of` t1}) (x:possibly t1{Ok? x ==> Ok?.v x `has_type` t2}) : possibly t2 = match x with | Ok x' -> Ok x' | Err s -> Err s (** [pbool] is a type that can be used instead of [bool] to hold on to a reason whenever it is [false]. To convert from a [pbool] to a bool, see [!!]. *) unfold type pbool = possibly unit (** [!!x] coerces a [pbool] into a [bool] by discarding any reason it holds on to and instead uses it solely as a boolean. *) unfold let (!!) (x:pbool) : bool = Ok? x (** [ttrue] is just the same as [true] but for a [pbool] *) unfold let ttrue : pbool = Ok () (** [ffalse] is the same as [false] but is for a [pbool] and thus requires a reason for being false. *) unfold let ffalse (reason:string) : pbool = Err reason (** [b /- r] is the same as [b] but as a [pbool] that is set to reason [r] if [b] is false. *) unfold let (/-) (b:bool) (reason:string) : pbool = if b then ttrue else ffalse reason (** [p /+> r] is the same as [p] but also appends [r] to the reason if it was false. *) unfold let (/+>) (p:pbool) (r:string) : pbool = match p with | Ok () -> Ok () | Err rr -> Err (rr ^ r) (** [p /+< r] is the same as [p] but also prepends [r] to the reason if it was false. *) unfold let (/+<) (p:pbool) (r:string) : pbool = match p with | Ok () -> Ok () | Err rr -> Err (r ^ rr) (** [&&.] is a short-circuiting logical-and. *) let (&&.) (x y:pbool) : pbool = match x with | Ok () -> y | Err reason -> Err reason (** [ ||. ] is a short-circuiting logical-or *) let ( ||. ) (x y:pbool) : pbool = match x with | Ok () -> Ok () | Err rx -> y /+< (rx ^ " and ") (** [for_all f l] runs [f] on all the elements of [l] and performs a
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Def.PossiblyMonad.fst" }
[ { "abbrev": false, "full_module": "Vale.Def", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: 'a -> Vale.Def.PossiblyMonad.pbool) -> l: Prims.list 'a -> Vale.Def.PossiblyMonad.pbool
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.PossiblyMonad.pbool", "Prims.list", "Vale.Def.PossiblyMonad.ttrue", "Vale.Def.PossiblyMonad.op_Amp_Amp_Dot", "Vale.Def.PossiblyMonad.for_all" ]
[ "recursion" ]
false
false
false
true
false
let rec for_all (f: ('a -> pbool)) (l: list 'a) : pbool =
match l with | [] -> ttrue | x :: xs -> f x &&. for_all f xs
false
Vale.Def.PossiblyMonad.fst
Vale.Def.PossiblyMonad.lemma_for_all_elim
val lemma_for_all_elim (f: ('a -> pbool)) (l: list 'a) : Lemma (requires !!(for_all f l)) (ensures (forall x. {:pattern (x `List.Tot.memP` l)} (x `List.Tot.memP` l) ==> !!(f x)))
val lemma_for_all_elim (f: ('a -> pbool)) (l: list 'a) : Lemma (requires !!(for_all f l)) (ensures (forall x. {:pattern (x `List.Tot.memP` l)} (x `List.Tot.memP` l) ==> !!(f x)))
let rec lemma_for_all_elim (f : 'a -> pbool) (l : list 'a) : Lemma (requires !!(for_all f l)) (ensures (forall x. {:pattern (x `List.Tot.memP` l)} (x `List.Tot.memP` l) ==> !!(f x))) = match l with | [] -> () | x :: xs -> lemma_for_all_elim f xs
{ "file_name": "vale/specs/defs/Vale.Def.PossiblyMonad.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 27, "end_line": 124, "start_col": 0, "start_line": 117 }
module Vale.Def.PossiblyMonad /// Similar to the [maybe] monad in Haskell (which is like the /// [option] type in F* and OCaml), but instead, we also store the /// reason for the error when the error occurs. type possibly 'a = | Ok : v:'a -> possibly 'a | Err : reason:string -> possibly 'a unfold let return (#a:Type) (x:a) : possibly a = Ok x unfold let (let+) (#a #b:Type) (x:possibly a) (f:a -> possibly b) : possibly b = match x with | Err s -> Err s | Ok x' -> f x' unfold let fail_with (#a:Type) (s:string) : possibly a = Err s unfold let unimplemented (#a:Type) (s:string) : possibly a = fail_with ("Unimplemented: " ^ s) (** Allows moving to a "looser" monad type, always *) unfold let loosen (#t1:Type) (#t2:Type{t1 `subtype_of` t2}) (x:possibly t1) : possibly t2 = match x with | Ok x' -> Ok x' | Err s -> Err s (** Allows moving to a "tighter" monad type, as long as the monad is guaranteed statically to be within this tighter type *) unfold let tighten (#t1:Type) (#t2:Type{t2 `subtype_of` t1}) (x:possibly t1{Ok? x ==> Ok?.v x `has_type` t2}) : possibly t2 = match x with | Ok x' -> Ok x' | Err s -> Err s (** [pbool] is a type that can be used instead of [bool] to hold on to a reason whenever it is [false]. To convert from a [pbool] to a bool, see [!!]. *) unfold type pbool = possibly unit (** [!!x] coerces a [pbool] into a [bool] by discarding any reason it holds on to and instead uses it solely as a boolean. *) unfold let (!!) (x:pbool) : bool = Ok? x (** [ttrue] is just the same as [true] but for a [pbool] *) unfold let ttrue : pbool = Ok () (** [ffalse] is the same as [false] but is for a [pbool] and thus requires a reason for being false. *) unfold let ffalse (reason:string) : pbool = Err reason (** [b /- r] is the same as [b] but as a [pbool] that is set to reason [r] if [b] is false. *) unfold let (/-) (b:bool) (reason:string) : pbool = if b then ttrue else ffalse reason (** [p /+> r] is the same as [p] but also appends [r] to the reason if it was false. *) unfold let (/+>) (p:pbool) (r:string) : pbool = match p with | Ok () -> Ok () | Err rr -> Err (rr ^ r) (** [p /+< r] is the same as [p] but also prepends [r] to the reason if it was false. *) unfold let (/+<) (p:pbool) (r:string) : pbool = match p with | Ok () -> Ok () | Err rr -> Err (r ^ rr) (** [&&.] is a short-circuiting logical-and. *) let (&&.) (x y:pbool) : pbool = match x with | Ok () -> y | Err reason -> Err reason (** [ ||. ] is a short-circuiting logical-or *) let ( ||. ) (x y:pbool) : pbool = match x with | Ok () -> Ok () | Err rx -> y /+< (rx ^ " and ") (** [for_all f l] runs [f] on all the elements of [l] and performs a short-circuit logical-and of all the results *) let rec for_all (f : 'a -> pbool) (l : list 'a) : pbool = match l with | [] -> ttrue | x :: xs -> f x &&. for_all f xs (** Change from a [forall] to a [for_all] *) let rec lemma_for_all_intro (f : 'a -> pbool) (l : list 'a) : Lemma (requires (forall x. {:pattern (x `List.Tot.memP` l)} (x `List.Tot.memP` l) ==> !!(f x))) (ensures !!(for_all f l)) = let open FStar.List.Tot in let aux l x : Lemma (requires (x `memP` l ==> !!(f x))) (ensures (Cons? l /\ x `memP` tl l ==> !!(f x))) = () in match l with | [] -> () | x :: xs -> FStar.Classical.forall_intro (FStar.Classical.move_requires (aux l)); lemma_for_all_intro f xs
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Def.PossiblyMonad.fst" }
[ { "abbrev": false, "full_module": "Vale.Def", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: 'a -> Vale.Def.PossiblyMonad.pbool) -> l: Prims.list 'a -> FStar.Pervasives.Lemma (requires !!(Vale.Def.PossiblyMonad.for_all f l)) (ensures forall (x: 'a). {:pattern FStar.List.Tot.Base.memP x l} FStar.List.Tot.Base.memP x l ==> !!(f x))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.PossiblyMonad.pbool", "Prims.list", "Vale.Def.PossiblyMonad.lemma_for_all_elim", "Prims.unit", "Prims.b2t", "Vale.Def.PossiblyMonad.op_Bang_Bang", "Vale.Def.PossiblyMonad.for_all", "Prims.squash", "Prims.l_Forall", "Prims.l_imp", "FStar.List.Tot.Base.memP", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_for_all_elim (f: ('a -> pbool)) (l: list 'a) : Lemma (requires !!(for_all f l)) (ensures (forall x. {:pattern (x `List.Tot.memP` l)} (x `List.Tot.memP` l) ==> !!(f x))) =
match l with | [] -> () | x :: xs -> lemma_for_all_elim f xs
false
Vale.Def.PossiblyMonad.fst
Vale.Def.PossiblyMonad.lemma_for_all_intro
val lemma_for_all_intro (f: ('a -> pbool)) (l: list 'a) : Lemma (requires (forall x. {:pattern (x `List.Tot.memP` l)} (x `List.Tot.memP` l) ==> !!(f x))) (ensures !!(for_all f l))
val lemma_for_all_intro (f: ('a -> pbool)) (l: list 'a) : Lemma (requires (forall x. {:pattern (x `List.Tot.memP` l)} (x `List.Tot.memP` l) ==> !!(f x))) (ensures !!(for_all f l))
let rec lemma_for_all_intro (f : 'a -> pbool) (l : list 'a) : Lemma (requires (forall x. {:pattern (x `List.Tot.memP` l)} (x `List.Tot.memP` l) ==> !!(f x))) (ensures !!(for_all f l)) = let open FStar.List.Tot in let aux l x : Lemma (requires (x `memP` l ==> !!(f x))) (ensures (Cons? l /\ x `memP` tl l ==> !!(f x))) = () in match l with | [] -> () | x :: xs -> FStar.Classical.forall_intro (FStar.Classical.move_requires (aux l)); lemma_for_all_intro f xs
{ "file_name": "vale/specs/defs/Vale.Def.PossiblyMonad.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 114, "start_col": 0, "start_line": 101 }
module Vale.Def.PossiblyMonad /// Similar to the [maybe] monad in Haskell (which is like the /// [option] type in F* and OCaml), but instead, we also store the /// reason for the error when the error occurs. type possibly 'a = | Ok : v:'a -> possibly 'a | Err : reason:string -> possibly 'a unfold let return (#a:Type) (x:a) : possibly a = Ok x unfold let (let+) (#a #b:Type) (x:possibly a) (f:a -> possibly b) : possibly b = match x with | Err s -> Err s | Ok x' -> f x' unfold let fail_with (#a:Type) (s:string) : possibly a = Err s unfold let unimplemented (#a:Type) (s:string) : possibly a = fail_with ("Unimplemented: " ^ s) (** Allows moving to a "looser" monad type, always *) unfold let loosen (#t1:Type) (#t2:Type{t1 `subtype_of` t2}) (x:possibly t1) : possibly t2 = match x with | Ok x' -> Ok x' | Err s -> Err s (** Allows moving to a "tighter" monad type, as long as the monad is guaranteed statically to be within this tighter type *) unfold let tighten (#t1:Type) (#t2:Type{t2 `subtype_of` t1}) (x:possibly t1{Ok? x ==> Ok?.v x `has_type` t2}) : possibly t2 = match x with | Ok x' -> Ok x' | Err s -> Err s (** [pbool] is a type that can be used instead of [bool] to hold on to a reason whenever it is [false]. To convert from a [pbool] to a bool, see [!!]. *) unfold type pbool = possibly unit (** [!!x] coerces a [pbool] into a [bool] by discarding any reason it holds on to and instead uses it solely as a boolean. *) unfold let (!!) (x:pbool) : bool = Ok? x (** [ttrue] is just the same as [true] but for a [pbool] *) unfold let ttrue : pbool = Ok () (** [ffalse] is the same as [false] but is for a [pbool] and thus requires a reason for being false. *) unfold let ffalse (reason:string) : pbool = Err reason (** [b /- r] is the same as [b] but as a [pbool] that is set to reason [r] if [b] is false. *) unfold let (/-) (b:bool) (reason:string) : pbool = if b then ttrue else ffalse reason (** [p /+> r] is the same as [p] but also appends [r] to the reason if it was false. *) unfold let (/+>) (p:pbool) (r:string) : pbool = match p with | Ok () -> Ok () | Err rr -> Err (rr ^ r) (** [p /+< r] is the same as [p] but also prepends [r] to the reason if it was false. *) unfold let (/+<) (p:pbool) (r:string) : pbool = match p with | Ok () -> Ok () | Err rr -> Err (r ^ rr) (** [&&.] is a short-circuiting logical-and. *) let (&&.) (x y:pbool) : pbool = match x with | Ok () -> y | Err reason -> Err reason (** [ ||. ] is a short-circuiting logical-or *) let ( ||. ) (x y:pbool) : pbool = match x with | Ok () -> Ok () | Err rx -> y /+< (rx ^ " and ") (** [for_all f l] runs [f] on all the elements of [l] and performs a short-circuit logical-and of all the results *) let rec for_all (f : 'a -> pbool) (l : list 'a) : pbool = match l with | [] -> ttrue | x :: xs -> f x &&. for_all f xs
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Def.PossiblyMonad.fst" }
[ { "abbrev": false, "full_module": "Vale.Def", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: 'a -> Vale.Def.PossiblyMonad.pbool) -> l: Prims.list 'a -> FStar.Pervasives.Lemma (requires forall (x: 'a). {:pattern FStar.List.Tot.Base.memP x l} FStar.List.Tot.Base.memP x l ==> !!(f x)) (ensures !!(Vale.Def.PossiblyMonad.for_all f l))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.PossiblyMonad.pbool", "Prims.list", "Vale.Def.PossiblyMonad.lemma_for_all_intro", "Prims.unit", "FStar.Classical.forall_intro", "Prims.l_imp", "FStar.List.Tot.Base.memP", "Prims.b2t", "Vale.Def.PossiblyMonad.op_Bang_Bang", "Prims.l_and", "Prims.uu___is_Cons", "FStar.List.Tot.Base.tl", "FStar.Classical.move_requires", "Vale.Def.PossiblyMonad.uu___is_Ok", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "Prims.l_Forall", "Vale.Def.PossiblyMonad.for_all" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_for_all_intro (f: ('a -> pbool)) (l: list 'a) : Lemma (requires (forall x. {:pattern (x `List.Tot.memP` l)} (x `List.Tot.memP` l) ==> !!(f x))) (ensures !!(for_all f l)) =
let open FStar.List.Tot in let aux l x : Lemma (requires (x `memP` l ==> !!(f x))) (ensures (Cons? l /\ x `memP` (tl l) ==> !!(f x))) = () in match l with | [] -> () | x :: xs -> FStar.Classical.forall_intro (FStar.Classical.move_requires (aux l)); lemma_for_all_intro f xs
false
Vale.Def.PossiblyMonad.fst
Vale.Def.PossiblyMonad.loosen
val loosen (#t1: Type) (#t2: Type{t1 `subtype_of` t2}) (x: possibly t1) : possibly t2
val loosen (#t1: Type) (#t2: Type{t1 `subtype_of` t2}) (x: possibly t1) : possibly t2
let loosen (#t1:Type) (#t2:Type{t1 `subtype_of` t2}) (x:possibly t1) : possibly t2 = match x with | Ok x' -> Ok x' | Err s -> Err s
{ "file_name": "vale/specs/defs/Vale.Def.PossiblyMonad.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 18, "end_line": 29, "start_col": 0, "start_line": 25 }
module Vale.Def.PossiblyMonad /// Similar to the [maybe] monad in Haskell (which is like the /// [option] type in F* and OCaml), but instead, we also store the /// reason for the error when the error occurs. type possibly 'a = | Ok : v:'a -> possibly 'a | Err : reason:string -> possibly 'a unfold let return (#a:Type) (x:a) : possibly a = Ok x unfold let (let+) (#a #b:Type) (x:possibly a) (f:a -> possibly b) : possibly b = match x with | Err s -> Err s | Ok x' -> f x' unfold let fail_with (#a:Type) (s:string) : possibly a = Err s unfold let unimplemented (#a:Type) (s:string) : possibly a = fail_with ("Unimplemented: " ^ s) (** Allows moving to a "looser" monad type, always *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Def.PossiblyMonad.fst" }
[ { "abbrev": false, "full_module": "Vale.Def", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Vale.Def.PossiblyMonad.possibly t1 -> Vale.Def.PossiblyMonad.possibly t2
Prims.Tot
[ "total" ]
[]
[ "Prims.subtype_of", "Vale.Def.PossiblyMonad.possibly", "Vale.Def.PossiblyMonad.Ok", "Prims.string", "Vale.Def.PossiblyMonad.Err" ]
[]
false
false
false
false
false
let loosen (#t1: Type) (#t2: Type{t1 `subtype_of` t2}) (x: possibly t1) : possibly t2 =
match x with | Ok x' -> Ok x' | Err s -> Err s
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.last
val last (x: list 'a) : Tac 'a
val last (x: list 'a) : Tac 'a
let rec last (x : list 'a) : Tac 'a = match x with | [] -> fail "last: empty list" | [x] -> x | _::xs -> last xs
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 22, "end_line": 827, "start_col": 8, "start_line": 823 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); () val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a let magic_dump #a #x () = x let change_with t1 t2 : Tac unit = focus (fun () -> grewrite t1 t2; iseq [idtac; trivial] ) let change_sq (t1 : term) : Tac unit = change (mk_e_app (`squash) [t1]) let finish_by (t : unit -> Tac 'a) : Tac 'a = let x = t () in or_else qed (fun () -> fail "finish_by: not finished"); x let solve_then #a #b (t1 : unit -> Tac a) (t2 : a -> Tac b) : Tac b = dup (); let x = focus (fun () -> finish_by t1) in let y = t2 x in trefl (); y let add_elem (t : unit -> Tac 'a) : Tac 'a = focus (fun () -> apply (`Cons); focus (fun () -> let x = t () in qed (); x ) ) (* * Specialize a function by partially evaluating it * For example: * let rec foo (l:list int) (x:int) :St int = match l with | [] -> x | hd::tl -> x + foo tl x let f :int -> St int = synth_by_tactic (specialize (foo [1; 2]) [%`foo]) * would make the definition of f as x + x + x * * f is the term that needs to be specialized * l is the list of names to be delta-ed *) let specialize (#a:Type) (f:a) (l:list string) :unit -> Tac unit = fun () -> solve_then (fun () -> exact (quote f)) (fun () -> norm [delta_only l; iota; zeta]) let tlabel (l:string) = match goals () with | [] -> fail "tlabel: no goals" | h::t -> set_goals (set_label l h :: t) let tlabel' (l:string) = match goals () with | [] -> fail "tlabel': no goals" | h::t -> let h = set_label (l ^ get_label h) h in set_goals (h :: t) let focus_all () : Tac unit = set_goals (goals () @ smt_goals ()); set_smt_goals [] private let rec extract_nth (n:nat) (l : list 'a) : option ('a * list 'a) = match n, l with | _, [] -> None | 0, hd::tl -> Some (hd, tl) | _, hd::tl -> begin match extract_nth (n-1) tl with | Some (hd', tl') -> Some (hd', hd::tl') | None -> None end let bump_nth (n:pos) : Tac unit = // n-1 since goal numbering begins at 1 match extract_nth (n - 1) (goals ()) with | None -> fail "bump_nth: not that many goals" | Some (h, t) -> set_goals (h :: t) let rec destruct_list (t : term) : Tac (list term) = let head, args = collect_app t in match inspect head, args with | Tv_FVar fv, [(a1, Q_Explicit); (a2, Q_Explicit)] | Tv_FVar fv, [(_, Q_Implicit); (a1, Q_Explicit); (a2, Q_Explicit)] -> if inspect_fv fv = cons_qn then a1 :: destruct_list a2 else raise NotAListLiteral | Tv_FVar fv, _ -> if inspect_fv fv = nil_qn then [] else raise NotAListLiteral | _ -> raise NotAListLiteral private let get_match_body () : Tac term = match unsquash_term (cur_goal ()) with | None -> fail "" | Some t -> match inspect_unascribe t with | Tv_Match sc _ _ -> sc | _ -> fail "Goal is not a match"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Prims.list 'a -> FStar.Tactics.Effect.Tac 'a
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.list", "FStar.Tactics.V2.Derived.fail", "FStar.Tactics.V2.Derived.last" ]
[ "recursion" ]
false
true
false
false
false
let rec last (x: list 'a) : Tac 'a =
match x with | [] -> fail "last: empty list" | [x] -> x | _ :: xs -> last xs
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.rewrite_all_context_equalities
val rewrite_all_context_equalities (bs: list binding) : Tac unit
val rewrite_all_context_equalities (bs: list binding) : Tac unit
let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 7, "end_line": 629, "start_col": 0, "start_line": 623 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
bs: Prims.list FStar.Tactics.NamedView.binding -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.list", "FStar.Tactics.NamedView.binding", "Prims.unit", "FStar.Tactics.V2.Derived.rewrite_all_context_equalities", "FStar.Tactics.V2.Derived.try_with", "FStar.Stubs.Tactics.V2.Builtins.rewrite", "Prims.exn" ]
[ "recursion" ]
false
true
false
false
false
let rec rewrite_all_context_equalities (bs: list binding) : Tac unit =
match bs with | [] -> () | x_t :: bs -> (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.revert_all
val revert_all (bs: list binding) : Tac unit
val revert_all (bs: list binding) : Tac unit
let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 26, "end_line": 568, "start_col": 0, "start_line": 564 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ())
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
bs: Prims.list FStar.Tactics.NamedView.binding -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.list", "FStar.Tactics.NamedView.binding", "Prims.unit", "FStar.Tactics.V2.Derived.revert_all", "FStar.Stubs.Tactics.V2.Builtins.revert" ]
[ "recursion" ]
false
true
false
false
false
let rec revert_all (bs: list binding) : Tac unit =
match bs with | [] -> () | _ :: tl -> revert (); revert_all tl
false
Vale.X64.Stack_Sems.fst
Vale.X64.Stack_Sems.stack_to_s
val stack_to_s (s:vale_stack) : S.machine_stack
val stack_to_s (s:vale_stack) : S.machine_stack
let stack_to_s s = s
{ "file_name": "vale/code/arch/x64/Vale.X64.Stack_Sems.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 20, "end_line": 6, "start_col": 0, "start_line": 6 }
module Vale.X64.Stack_Sems open FStar.Mul friend Vale.X64.Stack_i
{ "checked_file": "/", "dependencies": [ "Vale.X64.Stack_i.fst.checked", "Vale.Lib.Set.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Map.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Stack_Sems.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Vale.X64.Stack_i.vale_stack -> Vale.X64.Machine_Semantics_s.machine_stack
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Stack_i.vale_stack", "Vale.X64.Machine_Semantics_s.machine_stack" ]
[]
false
false
false
true
false
let stack_to_s s =
s
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.tlabel
val tlabel : l: Prims.string -> FStar.Tactics.Effect.Tac Prims.unit
let tlabel (l:string) = match goals () with | [] -> fail "tlabel: no goals" | h::t -> set_goals (set_label l h :: t)
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 38, "end_line": 771, "start_col": 0, "start_line": 767 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); () val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a let magic_dump #a #x () = x let change_with t1 t2 : Tac unit = focus (fun () -> grewrite t1 t2; iseq [idtac; trivial] ) let change_sq (t1 : term) : Tac unit = change (mk_e_app (`squash) [t1]) let finish_by (t : unit -> Tac 'a) : Tac 'a = let x = t () in or_else qed (fun () -> fail "finish_by: not finished"); x let solve_then #a #b (t1 : unit -> Tac a) (t2 : a -> Tac b) : Tac b = dup (); let x = focus (fun () -> finish_by t1) in let y = t2 x in trefl (); y let add_elem (t : unit -> Tac 'a) : Tac 'a = focus (fun () -> apply (`Cons); focus (fun () -> let x = t () in qed (); x ) ) (* * Specialize a function by partially evaluating it * For example: * let rec foo (l:list int) (x:int) :St int = match l with | [] -> x | hd::tl -> x + foo tl x let f :int -> St int = synth_by_tactic (specialize (foo [1; 2]) [%`foo]) * would make the definition of f as x + x + x * * f is the term that needs to be specialized * l is the list of names to be delta-ed *) let specialize (#a:Type) (f:a) (l:list string) :unit -> Tac unit = fun () -> solve_then (fun () -> exact (quote f)) (fun () -> norm [delta_only l; iota; zeta])
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Prims.string -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.string", "FStar.Tactics.V2.Derived.fail", "Prims.unit", "FStar.Stubs.Tactics.Types.goal", "Prims.list", "FStar.Stubs.Tactics.V2.Builtins.set_goals", "Prims.Cons", "FStar.Stubs.Tactics.Types.set_label", "FStar.Tactics.V2.Derived.goals" ]
[]
false
true
false
false
false
let tlabel (l: string) =
match goals () with | [] -> fail "tlabel: no goals" | h :: t -> set_goals (set_label l h :: t)
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.extract_nth
val extract_nth (n: nat) (l: list 'a) : option ('a * list 'a)
val extract_nth (n: nat) (l: list 'a) : option ('a * list 'a)
let rec extract_nth (n:nat) (l : list 'a) : option ('a * list 'a) = match n, l with | _, [] -> None | 0, hd::tl -> Some (hd, tl) | _, hd::tl -> begin match extract_nth (n-1) tl with | Some (hd', tl') -> Some (hd', hd::tl') | None -> None end
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 793, "start_col": 0, "start_line": 785 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); () val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a let magic_dump #a #x () = x let change_with t1 t2 : Tac unit = focus (fun () -> grewrite t1 t2; iseq [idtac; trivial] ) let change_sq (t1 : term) : Tac unit = change (mk_e_app (`squash) [t1]) let finish_by (t : unit -> Tac 'a) : Tac 'a = let x = t () in or_else qed (fun () -> fail "finish_by: not finished"); x let solve_then #a #b (t1 : unit -> Tac a) (t2 : a -> Tac b) : Tac b = dup (); let x = focus (fun () -> finish_by t1) in let y = t2 x in trefl (); y let add_elem (t : unit -> Tac 'a) : Tac 'a = focus (fun () -> apply (`Cons); focus (fun () -> let x = t () in qed (); x ) ) (* * Specialize a function by partially evaluating it * For example: * let rec foo (l:list int) (x:int) :St int = match l with | [] -> x | hd::tl -> x + foo tl x let f :int -> St int = synth_by_tactic (specialize (foo [1; 2]) [%`foo]) * would make the definition of f as x + x + x * * f is the term that needs to be specialized * l is the list of names to be delta-ed *) let specialize (#a:Type) (f:a) (l:list string) :unit -> Tac unit = fun () -> solve_then (fun () -> exact (quote f)) (fun () -> norm [delta_only l; iota; zeta]) let tlabel (l:string) = match goals () with | [] -> fail "tlabel: no goals" | h::t -> set_goals (set_label l h :: t) let tlabel' (l:string) = match goals () with | [] -> fail "tlabel': no goals" | h::t -> let h = set_label (l ^ get_label h) h in set_goals (h :: t) let focus_all () : Tac unit = set_goals (goals () @ smt_goals ()); set_smt_goals []
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.nat -> l: Prims.list 'a -> FStar.Pervasives.Native.option ('a * Prims.list 'a)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.list", "FStar.Pervasives.Native.Mktuple2", "Prims.int", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Some", "FStar.Tactics.V2.Derived.extract_nth", "Prims.op_Subtraction", "Prims.Cons", "FStar.Pervasives.Native.option" ]
[ "recursion" ]
false
false
false
true
false
let rec extract_nth (n: nat) (l: list 'a) : option ('a * list 'a) =
match n, l with | _, [] -> None | 0, hd :: tl -> Some (hd, tl) | _, hd :: tl -> match extract_nth (n - 1) tl with | Some (hd', tl') -> Some (hd', hd :: tl') | None -> None
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.binding_to_simple_binder
val binding_to_simple_binder (b: binding) : Tot simple_binder
val binding_to_simple_binder (b: binding) : Tot simple_binder
let binding_to_simple_binder (b : binding) : Tot simple_binder = { ppname = b.ppname; uniq = b.uniq; sort = b.sort; qual = Q_Explicit; attrs = []; }
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 900, "start_col": 0, "start_line": 893 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); () val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a let magic_dump #a #x () = x let change_with t1 t2 : Tac unit = focus (fun () -> grewrite t1 t2; iseq [idtac; trivial] ) let change_sq (t1 : term) : Tac unit = change (mk_e_app (`squash) [t1]) let finish_by (t : unit -> Tac 'a) : Tac 'a = let x = t () in or_else qed (fun () -> fail "finish_by: not finished"); x let solve_then #a #b (t1 : unit -> Tac a) (t2 : a -> Tac b) : Tac b = dup (); let x = focus (fun () -> finish_by t1) in let y = t2 x in trefl (); y let add_elem (t : unit -> Tac 'a) : Tac 'a = focus (fun () -> apply (`Cons); focus (fun () -> let x = t () in qed (); x ) ) (* * Specialize a function by partially evaluating it * For example: * let rec foo (l:list int) (x:int) :St int = match l with | [] -> x | hd::tl -> x + foo tl x let f :int -> St int = synth_by_tactic (specialize (foo [1; 2]) [%`foo]) * would make the definition of f as x + x + x * * f is the term that needs to be specialized * l is the list of names to be delta-ed *) let specialize (#a:Type) (f:a) (l:list string) :unit -> Tac unit = fun () -> solve_then (fun () -> exact (quote f)) (fun () -> norm [delta_only l; iota; zeta]) let tlabel (l:string) = match goals () with | [] -> fail "tlabel: no goals" | h::t -> set_goals (set_label l h :: t) let tlabel' (l:string) = match goals () with | [] -> fail "tlabel': no goals" | h::t -> let h = set_label (l ^ get_label h) h in set_goals (h :: t) let focus_all () : Tac unit = set_goals (goals () @ smt_goals ()); set_smt_goals [] private let rec extract_nth (n:nat) (l : list 'a) : option ('a * list 'a) = match n, l with | _, [] -> None | 0, hd::tl -> Some (hd, tl) | _, hd::tl -> begin match extract_nth (n-1) tl with | Some (hd', tl') -> Some (hd', hd::tl') | None -> None end let bump_nth (n:pos) : Tac unit = // n-1 since goal numbering begins at 1 match extract_nth (n - 1) (goals ()) with | None -> fail "bump_nth: not that many goals" | Some (h, t) -> set_goals (h :: t) let rec destruct_list (t : term) : Tac (list term) = let head, args = collect_app t in match inspect head, args with | Tv_FVar fv, [(a1, Q_Explicit); (a2, Q_Explicit)] | Tv_FVar fv, [(_, Q_Implicit); (a1, Q_Explicit); (a2, Q_Explicit)] -> if inspect_fv fv = cons_qn then a1 :: destruct_list a2 else raise NotAListLiteral | Tv_FVar fv, _ -> if inspect_fv fv = nil_qn then [] else raise NotAListLiteral | _ -> raise NotAListLiteral private let get_match_body () : Tac term = match unsquash_term (cur_goal ()) with | None -> fail "" | Some t -> match inspect_unascribe t with | Tv_Match sc _ _ -> sc | _ -> fail "Goal is not a match" private let rec last (x : list 'a) : Tac 'a = match x with | [] -> fail "last: empty list" | [x] -> x | _::xs -> last xs (** When the goal is [match e with | p1 -> e1 ... | pn -> en], destruct it into [n] goals for each possible case, including an hypothesis for [e] matching the corresponding pattern. *) let branch_on_match () : Tac unit = focus (fun () -> let x = get_match_body () in let _ = t_destruct x in iterAll (fun () -> let bs = repeat intro in let b = last bs in (* this one is the equality *) grewrite_eq b; norm [iota]) ) (** When the argument [i] is non-negative, [nth_var] grabs the nth binder in the current goal. When it is negative, it grabs the (-i-1)th binder counting from the end of the goal. That is, [nth_var (-1)] will return the last binder, [nth_var (-2)] the second to last, and so on. *) let nth_var (i:int) : Tac binding = let bs = cur_vars () in let k : int = if i >= 0 then i else List.Tot.Base.length bs + i in let k : nat = if k < 0 then fail "not enough binders" else k in match List.Tot.Base.nth bs k with | None -> fail "not enough binders" | Some b -> b exception Appears (** Decides whether a top-level name [nm] syntactically appears in the term [t]. *) let name_appears_in (nm:name) (t:term) : Tac bool = let ff (t : term) : Tac term = match inspect t with | Tv_FVar fv -> if inspect_fv fv = nm then raise Appears; t | tv -> pack tv in try ignore (V.visit_tm ff t); false with | Appears -> true | e -> raise e (** [mk_abs [x1; ...; xn] t] returns the term [fun x1 ... xn -> t] *) let rec mk_abs (args : list binder) (t : term) : Tac term (decreases args) = match args with | [] -> t | a :: args' -> let t' = mk_abs args' t in pack (Tv_Abs a t') // GGG Needed? delete if not let namedv_to_simple_binder (n : namedv) : Tac simple_binder = let nv = inspect_namedv n in { ppname = nv.ppname; uniq = nv.uniq; sort = unseal nv.sort; (* GGG USINGSORT *) qual = Q_Explicit; attrs = []; }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: FStar.Tactics.NamedView.binding -> FStar.Tactics.NamedView.simple_binder
Prims.Tot
[ "total" ]
[]
[ "FStar.Tactics.NamedView.binding", "FStar.Tactics.NamedView.Mkbinder", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinding__item__uniq", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinding__item__ppname", "FStar.Stubs.Reflection.V2.Data.__proj__Mkbinding__item__sort", "FStar.Stubs.Reflection.V2.Data.Q_Explicit", "Prims.Nil", "FStar.Tactics.NamedView.term", "FStar.Tactics.NamedView.simple_binder" ]
[]
false
false
false
true
false
let binding_to_simple_binder (b: binding) : Tot simple_binder =
{ ppname = b.ppname; uniq = b.uniq; sort = b.sort; qual = Q_Explicit; attrs = [] }
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.get_match_body
val get_match_body: Prims.unit -> Tac term
val get_match_body: Prims.unit -> Tac term
let get_match_body () : Tac term = match unsquash_term (cur_goal ()) with | None -> fail "" | Some t -> match inspect_unascribe t with | Tv_Match sc _ _ -> sc | _ -> fail "Goal is not a match"
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 46, "end_line": 821, "start_col": 8, "start_line": 816 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); () val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a let magic_dump #a #x () = x let change_with t1 t2 : Tac unit = focus (fun () -> grewrite t1 t2; iseq [idtac; trivial] ) let change_sq (t1 : term) : Tac unit = change (mk_e_app (`squash) [t1]) let finish_by (t : unit -> Tac 'a) : Tac 'a = let x = t () in or_else qed (fun () -> fail "finish_by: not finished"); x let solve_then #a #b (t1 : unit -> Tac a) (t2 : a -> Tac b) : Tac b = dup (); let x = focus (fun () -> finish_by t1) in let y = t2 x in trefl (); y let add_elem (t : unit -> Tac 'a) : Tac 'a = focus (fun () -> apply (`Cons); focus (fun () -> let x = t () in qed (); x ) ) (* * Specialize a function by partially evaluating it * For example: * let rec foo (l:list int) (x:int) :St int = match l with | [] -> x | hd::tl -> x + foo tl x let f :int -> St int = synth_by_tactic (specialize (foo [1; 2]) [%`foo]) * would make the definition of f as x + x + x * * f is the term that needs to be specialized * l is the list of names to be delta-ed *) let specialize (#a:Type) (f:a) (l:list string) :unit -> Tac unit = fun () -> solve_then (fun () -> exact (quote f)) (fun () -> norm [delta_only l; iota; zeta]) let tlabel (l:string) = match goals () with | [] -> fail "tlabel: no goals" | h::t -> set_goals (set_label l h :: t) let tlabel' (l:string) = match goals () with | [] -> fail "tlabel': no goals" | h::t -> let h = set_label (l ^ get_label h) h in set_goals (h :: t) let focus_all () : Tac unit = set_goals (goals () @ smt_goals ()); set_smt_goals [] private let rec extract_nth (n:nat) (l : list 'a) : option ('a * list 'a) = match n, l with | _, [] -> None | 0, hd::tl -> Some (hd, tl) | _, hd::tl -> begin match extract_nth (n-1) tl with | Some (hd', tl') -> Some (hd', hd::tl') | None -> None end let bump_nth (n:pos) : Tac unit = // n-1 since goal numbering begins at 1 match extract_nth (n - 1) (goals ()) with | None -> fail "bump_nth: not that many goals" | Some (h, t) -> set_goals (h :: t) let rec destruct_list (t : term) : Tac (list term) = let head, args = collect_app t in match inspect head, args with | Tv_FVar fv, [(a1, Q_Explicit); (a2, Q_Explicit)] | Tv_FVar fv, [(_, Q_Implicit); (a1, Q_Explicit); (a2, Q_Explicit)] -> if inspect_fv fv = cons_qn then a1 :: destruct_list a2 else raise NotAListLiteral | Tv_FVar fv, _ -> if inspect_fv fv = nil_qn then [] else raise NotAListLiteral | _ -> raise NotAListLiteral
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.term
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V2.Derived.fail", "FStar.Tactics.NamedView.term", "FStar.Stubs.Reflection.Types.term", "FStar.Pervasives.Native.option", "FStar.Tactics.NamedView.match_returns_ascription", "Prims.list", "FStar.Tactics.NamedView.branch", "FStar.Tactics.NamedView.named_term_view", "FStar.Tactics.NamedView.term_view", "Prims.b2t", "FStar.Tactics.NamedView.notAscription", "FStar.Tactics.V2.SyntaxHelpers.inspect_unascribe", "FStar.Reflection.V2.Derived.unsquash_term", "FStar.Tactics.V2.Derived.cur_goal", "FStar.Stubs.Reflection.Types.typ" ]
[]
false
true
false
false
false
let get_match_body () : Tac term =
match unsquash_term (cur_goal ()) with | None -> fail "" | Some t -> match inspect_unascribe t with | Tv_Match sc _ _ -> sc | _ -> fail "Goal is not a match"
false
ID3.fst
ID3.w0
val w0 (a : Type u#a) : Type u#(max 1 a)
val w0 (a : Type u#a) : Type u#(max 1 a)
let w0 a = (a -> Type0) -> Type0
{ "file_name": "examples/layeredeffects/ID3.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 32, "end_line": 5, "start_col": 0, "start_line": 5 }
module ID3 // The base type of WPs
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "ID3.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> Type
Prims.Tot
[ "total" ]
[]
[]
[]
false
false
false
true
true
let w0 a =
(a -> Type0) -> Type0
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.tlabel'
val tlabel' : l: Prims.string -> FStar.Tactics.Effect.Tac Prims.unit
let tlabel' (l:string) = match goals () with | [] -> fail "tlabel': no goals" | h::t -> let h = set_label (l ^ get_label h) h in set_goals (h :: t)
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 26, "end_line": 778, "start_col": 0, "start_line": 773 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); () val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a let magic_dump #a #x () = x let change_with t1 t2 : Tac unit = focus (fun () -> grewrite t1 t2; iseq [idtac; trivial] ) let change_sq (t1 : term) : Tac unit = change (mk_e_app (`squash) [t1]) let finish_by (t : unit -> Tac 'a) : Tac 'a = let x = t () in or_else qed (fun () -> fail "finish_by: not finished"); x let solve_then #a #b (t1 : unit -> Tac a) (t2 : a -> Tac b) : Tac b = dup (); let x = focus (fun () -> finish_by t1) in let y = t2 x in trefl (); y let add_elem (t : unit -> Tac 'a) : Tac 'a = focus (fun () -> apply (`Cons); focus (fun () -> let x = t () in qed (); x ) ) (* * Specialize a function by partially evaluating it * For example: * let rec foo (l:list int) (x:int) :St int = match l with | [] -> x | hd::tl -> x + foo tl x let f :int -> St int = synth_by_tactic (specialize (foo [1; 2]) [%`foo]) * would make the definition of f as x + x + x * * f is the term that needs to be specialized * l is the list of names to be delta-ed *) let specialize (#a:Type) (f:a) (l:list string) :unit -> Tac unit = fun () -> solve_then (fun () -> exact (quote f)) (fun () -> norm [delta_only l; iota; zeta]) let tlabel (l:string) = match goals () with | [] -> fail "tlabel: no goals" | h::t -> set_goals (set_label l h :: t)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Prims.string -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.string", "FStar.Tactics.V2.Derived.fail", "Prims.unit", "FStar.Stubs.Tactics.Types.goal", "Prims.list", "FStar.Stubs.Tactics.V2.Builtins.set_goals", "Prims.Cons", "FStar.Stubs.Tactics.Types.set_label", "Prims.op_Hat", "FStar.Stubs.Tactics.Types.get_label", "FStar.Tactics.V2.Derived.goals" ]
[]
false
true
false
false
false
let tlabel' (l: string) =
match goals () with | [] -> fail "tlabel': no goals" | h :: t -> let h = set_label (l ^ get_label h) h in set_goals (h :: t)
false
FStar.DM4F.Heap.IntStoreFixed.fsti
FStar.DM4F.Heap.IntStoreFixed.sel
val sel : h: FStar.DM4F.Heap.IntStoreFixed.heap -> i: FStar.DM4F.Heap.IntStoreFixed.id -> Prims.int
let sel = index
{ "file_name": "examples/dm4free/FStar.DM4F.Heap.IntStoreFixed.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 15, "end_line": 28, "start_col": 0, "start_line": 28 }
(* Copyright 2008-2018 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 FStar.DM4F.Heap.IntStoreFixed open FStar.Seq let store_size = 10 val id : eqtype val heap : eqtype val to_id (n:nat{n < store_size}) : id
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.DM4F.Heap.IntStoreFixed.fsti" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.DM4F.Heap.IntStoreFixed.heap -> i: FStar.DM4F.Heap.IntStoreFixed.id -> Prims.int
Prims.Tot
[ "total" ]
[]
[ "FStar.DM4F.Heap.IntStoreFixed.index" ]
[]
false
false
false
true
false
let sel =
index
false
ID3.fst
ID3.w
val w (a : Type u#a) : Type u#(max 1 a)
val w (a : Type u#a) : Type u#(max 1 a)
let w a = pure_wp a
{ "file_name": "examples/layeredeffects/ID3.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 12, "start_col": 0, "start_line": 12 }
module ID3 // The base type of WPs val w0 (a : Type u#a) : Type u#(max 1 a) let w0 a = (a -> Type0) -> Type0 // We require monotonicity of them let monotonic (w:w0 'a) = forall p1 p2. (forall x. p1 x ==> p2 x) ==> w p1 ==> w p2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "ID3.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> Type
Prims.Tot
[ "total" ]
[]
[ "Prims.pure_wp" ]
[]
false
false
false
true
true
let w a =
pure_wp a
false
FStar.DM4F.Heap.IntStoreFixed.fsti
FStar.DM4F.Heap.IntStoreFixed.store_size
val store_size : Prims.int
let store_size = 10
{ "file_name": "examples/dm4free/FStar.DM4F.Heap.IntStoreFixed.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 20, "start_col": 0, "start_line": 20 }
(* Copyright 2008-2018 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 FStar.DM4F.Heap.IntStoreFixed open FStar.Seq
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.DM4F.Heap.IntStoreFixed.fsti" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.int
Prims.Tot
[ "total" ]
[]
[]
[]
false
false
false
true
false
let store_size =
10
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.nth_var
val nth_var (i: int) : Tac binding
val nth_var (i: int) : Tac binding
let nth_var (i:int) : Tac binding = let bs = cur_vars () in let k : int = if i >= 0 then i else List.Tot.Base.length bs + i in let k : nat = if k < 0 then fail "not enough binders" else k in match List.Tot.Base.nth bs k with | None -> fail "not enough binders" | Some b -> b
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 15, "end_line": 854, "start_col": 0, "start_line": 848 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); () val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a let magic_dump #a #x () = x let change_with t1 t2 : Tac unit = focus (fun () -> grewrite t1 t2; iseq [idtac; trivial] ) let change_sq (t1 : term) : Tac unit = change (mk_e_app (`squash) [t1]) let finish_by (t : unit -> Tac 'a) : Tac 'a = let x = t () in or_else qed (fun () -> fail "finish_by: not finished"); x let solve_then #a #b (t1 : unit -> Tac a) (t2 : a -> Tac b) : Tac b = dup (); let x = focus (fun () -> finish_by t1) in let y = t2 x in trefl (); y let add_elem (t : unit -> Tac 'a) : Tac 'a = focus (fun () -> apply (`Cons); focus (fun () -> let x = t () in qed (); x ) ) (* * Specialize a function by partially evaluating it * For example: * let rec foo (l:list int) (x:int) :St int = match l with | [] -> x | hd::tl -> x + foo tl x let f :int -> St int = synth_by_tactic (specialize (foo [1; 2]) [%`foo]) * would make the definition of f as x + x + x * * f is the term that needs to be specialized * l is the list of names to be delta-ed *) let specialize (#a:Type) (f:a) (l:list string) :unit -> Tac unit = fun () -> solve_then (fun () -> exact (quote f)) (fun () -> norm [delta_only l; iota; zeta]) let tlabel (l:string) = match goals () with | [] -> fail "tlabel: no goals" | h::t -> set_goals (set_label l h :: t) let tlabel' (l:string) = match goals () with | [] -> fail "tlabel': no goals" | h::t -> let h = set_label (l ^ get_label h) h in set_goals (h :: t) let focus_all () : Tac unit = set_goals (goals () @ smt_goals ()); set_smt_goals [] private let rec extract_nth (n:nat) (l : list 'a) : option ('a * list 'a) = match n, l with | _, [] -> None | 0, hd::tl -> Some (hd, tl) | _, hd::tl -> begin match extract_nth (n-1) tl with | Some (hd', tl') -> Some (hd', hd::tl') | None -> None end let bump_nth (n:pos) : Tac unit = // n-1 since goal numbering begins at 1 match extract_nth (n - 1) (goals ()) with | None -> fail "bump_nth: not that many goals" | Some (h, t) -> set_goals (h :: t) let rec destruct_list (t : term) : Tac (list term) = let head, args = collect_app t in match inspect head, args with | Tv_FVar fv, [(a1, Q_Explicit); (a2, Q_Explicit)] | Tv_FVar fv, [(_, Q_Implicit); (a1, Q_Explicit); (a2, Q_Explicit)] -> if inspect_fv fv = cons_qn then a1 :: destruct_list a2 else raise NotAListLiteral | Tv_FVar fv, _ -> if inspect_fv fv = nil_qn then [] else raise NotAListLiteral | _ -> raise NotAListLiteral private let get_match_body () : Tac term = match unsquash_term (cur_goal ()) with | None -> fail "" | Some t -> match inspect_unascribe t with | Tv_Match sc _ _ -> sc | _ -> fail "Goal is not a match" private let rec last (x : list 'a) : Tac 'a = match x with | [] -> fail "last: empty list" | [x] -> x | _::xs -> last xs (** When the goal is [match e with | p1 -> e1 ... | pn -> en], destruct it into [n] goals for each possible case, including an hypothesis for [e] matching the corresponding pattern. *) let branch_on_match () : Tac unit = focus (fun () -> let x = get_match_body () in let _ = t_destruct x in iterAll (fun () -> let bs = repeat intro in let b = last bs in (* this one is the equality *) grewrite_eq b; norm [iota]) ) (** When the argument [i] is non-negative, [nth_var] grabs the nth binder in the current goal. When it is negative, it grabs the (-i-1)th binder counting from the end of the goal. That is, [nth_var (-1)] will return the last binder, [nth_var (-2)] the second to last, and
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
i: Prims.int -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.binding
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.int", "FStar.List.Tot.Base.nth", "FStar.Tactics.NamedView.binding", "FStar.Tactics.V2.Derived.fail", "Prims.nat", "Prims.op_LessThan", "Prims.bool", "Prims.op_GreaterThanOrEqual", "Prims.op_Addition", "FStar.List.Tot.Base.length", "Prims.list", "FStar.Tactics.V2.Derived.cur_vars" ]
[]
false
true
false
false
false
let nth_var (i: int) : Tac binding =
let bs = cur_vars () in let k:int = if i >= 0 then i else List.Tot.Base.length bs + i in let k:nat = if k < 0 then fail "not enough binders" else k in match List.Tot.Base.nth bs k with | None -> fail "not enough binders" | Some b -> b
false
ID3.fst
ID3.monotonic
val monotonic : w: ID3.w0 'a -> Prims.logical
let monotonic (w:w0 'a) = forall p1 p2. (forall x. p1 x ==> p2 x) ==> w p1 ==> w p2
{ "file_name": "examples/layeredeffects/ID3.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 59, "end_line": 9, "start_col": 0, "start_line": 8 }
module ID3 // The base type of WPs val w0 (a : Type u#a) : Type u#(max 1 a) let w0 a = (a -> Type0) -> Type0
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "ID3.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
w: ID3.w0 'a -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "ID3.w0", "Prims.l_Forall", "Prims.logical", "Prims.l_imp" ]
[]
false
false
false
true
true
let monotonic (w: w0 'a) =
forall p1 p2. (forall x. p1 x ==> p2 x) ==> w p1 ==> w p2
false
Hacl.Impl.P256.PointDouble.fst
Hacl.Impl.P256.PointDouble.point_double_6
val point_double_6 (x3 z3 t0 t1 t4:felem) : Stack unit (requires fun h -> live h x3 /\ live h z3 /\ live h t0 /\ live h t1 /\ live h t4 /\ LowStar.Monotonic.Buffer.all_disjoint [ loc x3; loc z3; loc t0; loc t1; loc t4 ] /\ as_nat h x3 < S.prime /\ as_nat h z3 < S.prime /\ as_nat h t1 < S.prime /\ as_nat h t4 < S.prime) (ensures fun h0 _ h1 -> modifies (loc x3 |+| loc z3 |+| loc t0) h0 h1 /\ as_nat h1 x3 < S.prime /\ as_nat h1 z3 < S.prime /\ as_nat h1 t0 < S.prime /\ (let t1_s = fmont_as_nat h0 t1 in let t4_s = fmont_as_nat h0 t4 in let x3_s = fmont_as_nat h0 x3 in let z3_s = fmont_as_nat h0 z3 in let t0_s = S.fadd t4_s t4_s in let z3_s = S.fmul t0_s z3_s in let x3_s = S.fsub x3_s z3_s in let z3_s = S.fmul t0_s t1_s in let z3_s = S.fadd z3_s z3_s in let z3_s = S.fadd z3_s z3_s in fmont_as_nat h1 z3 == z3_s /\ fmont_as_nat h1 x3 == x3_s /\ fmont_as_nat h1 t0 == t0_s))
val point_double_6 (x3 z3 t0 t1 t4:felem) : Stack unit (requires fun h -> live h x3 /\ live h z3 /\ live h t0 /\ live h t1 /\ live h t4 /\ LowStar.Monotonic.Buffer.all_disjoint [ loc x3; loc z3; loc t0; loc t1; loc t4 ] /\ as_nat h x3 < S.prime /\ as_nat h z3 < S.prime /\ as_nat h t1 < S.prime /\ as_nat h t4 < S.prime) (ensures fun h0 _ h1 -> modifies (loc x3 |+| loc z3 |+| loc t0) h0 h1 /\ as_nat h1 x3 < S.prime /\ as_nat h1 z3 < S.prime /\ as_nat h1 t0 < S.prime /\ (let t1_s = fmont_as_nat h0 t1 in let t4_s = fmont_as_nat h0 t4 in let x3_s = fmont_as_nat h0 x3 in let z3_s = fmont_as_nat h0 z3 in let t0_s = S.fadd t4_s t4_s in let z3_s = S.fmul t0_s z3_s in let x3_s = S.fsub x3_s z3_s in let z3_s = S.fmul t0_s t1_s in let z3_s = S.fadd z3_s z3_s in let z3_s = S.fadd z3_s z3_s in fmont_as_nat h1 z3 == z3_s /\ fmont_as_nat h1 x3 == x3_s /\ fmont_as_nat h1 t0 == t0_s))
let point_double_6 x3 z3 t0 t1 t4 = fdouble t0 t4; fmul z3 t0 z3; fsub x3 x3 z3; fmul z3 t0 t1; fdouble z3 z3; fdouble z3 z3
{ "file_name": "code/ecdsap256/Hacl.Impl.P256.PointDouble.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 15, "end_line": 191, "start_col": 0, "start_line": 185 }
module Hacl.Impl.P256.PointDouble open FStar.Mul open FStar.HyperStack.All open FStar.HyperStack module ST = FStar.HyperStack.ST open Lib.IntTypes open Lib.Buffer open Hacl.Impl.P256.Bignum open Hacl.Impl.P256.Field module S = Spec.P256 #set-options "--z3rlimit 50 --ifuel 0 --fuel 0" inline_for_extraction noextract val point_double_1 (t0 t1 t2 t3 t4:felem) (p:point) : Stack unit (requires fun h -> live h t0 /\ live h t1 /\ live h t2 /\ live h t3 /\ live h t4 /\ live h p /\ LowStar.Monotonic.Buffer.all_disjoint [loc t0; loc t1; loc t2; loc t3; loc t4; loc p ] /\ point_inv h p) (ensures fun h0 _ h1 -> modifies (loc t0 |+| loc t1 |+| loc t2 |+| loc t3 |+| loc t4) h0 h1 /\ as_nat h1 t0 < S.prime /\ as_nat h1 t1 < S.prime /\ as_nat h1 t2 < S.prime /\ as_nat h1 t3 < S.prime /\ as_nat h1 t4 < S.prime /\ (let x, y, z = from_mont_point (as_point_nat h0 p) in let t0_s = S.fmul x x in let t1_s = S.fmul y y in let t2_s = S.fmul z z in let t3_s = S.fmul x y in let t3_s = S.fadd t3_s t3_s in let t4_s = S.fmul y z in fmont_as_nat h1 t0 == t0_s /\ fmont_as_nat h1 t1 == t1_s /\ fmont_as_nat h1 t2 == t2_s /\ fmont_as_nat h1 t3 == t3_s /\ fmont_as_nat h1 t4 == t4_s)) let point_double_1 t0 t1 t2 t3 t4 p = let x, y, z = getx p, gety p, getz p in fsqr t0 x; fsqr t1 y; fsqr t2 z; fmul t3 x y; fdouble t3 t3; fmul t4 y z inline_for_extraction noextract val point_double_2 (x3 y3 z3 t2:felem) : Stack unit (requires fun h -> live h x3 /\ live h y3 /\ live h z3 /\ live h t2 /\ LowStar.Monotonic.Buffer.all_disjoint [ loc x3; loc y3; loc z3; loc t2 ] /\ as_nat h z3 < S.prime /\ as_nat h t2 < S.prime) (ensures fun h0 _ h1 -> modifies (loc x3 |+| loc y3 |+| loc z3) h0 h1 /\ as_nat h1 x3 < S.prime /\ as_nat h1 y3 < S.prime /\ as_nat h1 z3 < S.prime /\ (let z3_s = fmont_as_nat h0 z3 in let t2_s = fmont_as_nat h0 t2 in let z3_s = S.fadd z3_s z3_s in let y3_s = S.fmul S.b_coeff t2_s in let y3_s = S.fsub y3_s z3_s in let x3_s = S.fadd y3_s y3_s in let y3_s = S.fadd x3_s y3_s in fmont_as_nat h1 x3 == x3_s /\ fmont_as_nat h1 y3 == y3_s /\ fmont_as_nat h1 z3 == z3_s)) let point_double_2 x3 y3 z3 t2 = fdouble z3 z3; fmul_by_b_coeff y3 t2; fsub y3 y3 z3; fdouble x3 y3; fadd y3 x3 y3 inline_for_extraction noextract val point_double_3 (x3 y3 t1 t2 t3:felem) : Stack unit (requires fun h -> live h x3 /\ live h y3 /\ live h t1 /\ live h t2 /\ live h t3 /\ LowStar.Monotonic.Buffer.all_disjoint [ loc x3; loc y3; loc t1; loc t2; loc t3 ] /\ as_nat h t1 < S.prime /\ as_nat h t2 < S.prime /\ as_nat h t3 < S.prime /\ as_nat h y3 < S.prime) (ensures fun h0 _ h1 -> modifies (loc x3 |+| loc y3 |+| loc t2 |+| loc t3) h0 h1 /\ as_nat h1 x3 < S.prime /\ as_nat h1 y3 < S.prime /\ as_nat h1 t2 < S.prime /\ as_nat h1 t3 < S.prime /\ (let t1_s = fmont_as_nat h0 t1 in let t2_s = fmont_as_nat h0 t2 in let t3_s = fmont_as_nat h0 t3 in let y3_s = fmont_as_nat h0 y3 in let x3_s = S.fsub t1_s y3_s in let y3_s = S.fadd t1_s y3_s in let y3_s = S.fmul x3_s y3_s in let x3_s = S.fmul x3_s t3_s in let t3_s = S.fadd t2_s t2_s in let t2_s = S.fadd t2_s t3_s in fmont_as_nat h1 x3 == x3_s /\ fmont_as_nat h1 y3 == y3_s /\ fmont_as_nat h1 t2 == t2_s /\ fmont_as_nat h1 t3 == t3_s)) let point_double_3 x3 y3 t1 t2 t3 = fsub x3 t1 y3; fadd y3 t1 y3; fmul y3 x3 y3; fmul x3 x3 t3; fdouble t3 t2; fadd t2 t2 t3 inline_for_extraction noextract val point_double_4 (z3 t0 t2 t3:felem) : Stack unit (requires fun h -> live h z3 /\ live h t0 /\ live h t2 /\ live h t3 /\ LowStar.Monotonic.Buffer.all_disjoint [ loc z3; loc t0; loc t2; loc t3 ] /\ as_nat h z3 < S.prime /\ as_nat h t0 < S.prime /\ as_nat h t2 < S.prime) (ensures fun h0 _ h1 -> modifies (loc z3 |+| loc t3) h0 h1 /\ as_nat h1 z3 < S.prime /\ as_nat h1 t3 < S.prime /\ (let z3_s = fmont_as_nat h0 z3 in let t0_s = fmont_as_nat h0 t0 in let t2_s = fmont_as_nat h0 t2 in let z3_s = S.fmul S.b_coeff z3_s in let z3_s = S.fsub z3_s t2_s in let z3_s = S.fsub z3_s t0_s in let t3_s = S.fadd z3_s z3_s in let z3_s = S.fadd z3_s t3_s in fmont_as_nat h1 z3 == z3_s /\ fmont_as_nat h1 t3 == t3_s)) let point_double_4 z3 t0 t2 t3 = fmul_by_b_coeff z3 z3; fsub z3 z3 t2; fsub z3 z3 t0; fdouble t3 z3; fadd z3 z3 t3 inline_for_extraction noextract val point_double_5 (y3 z3 t0 t2 t3:felem) : Stack unit (requires fun h -> live h y3 /\ live h z3 /\ live h t0 /\ live h t2 /\ live h t3 /\ LowStar.Monotonic.Buffer.all_disjoint [ loc y3; loc z3; loc t0; loc t2; loc t3 ] /\ as_nat h y3 < S.prime /\ as_nat h z3 < S.prime /\ as_nat h t0 < S.prime /\ as_nat h t2 < S.prime) (ensures fun h0 _ h1 -> modifies (loc y3 |+| loc t0 |+| loc t3) h0 h1 /\ as_nat h1 y3 < S.prime /\ as_nat h1 t3 < S.prime /\ (let t0_s = fmont_as_nat h0 t0 in let t2_s = fmont_as_nat h0 t2 in let y3_s = fmont_as_nat h0 y3 in let z3_s = fmont_as_nat h0 z3 in let t3_s = S.fadd t0_s t0_s in let t0_s = S.fadd t3_s t0_s in let t0_s = S.fsub t0_s t2_s in let t0_s = S.fmul t0_s z3_s in let y3_s = S.fadd y3_s t0_s in fmont_as_nat h1 y3 == y3_s /\ fmont_as_nat h1 t0 == t0_s /\ fmont_as_nat h1 t3 == t3_s)) let point_double_5 y3 z3 t0 t2 t3 = fdouble t3 t0; fadd t0 t3 t0; fsub t0 t0 t2; fmul t0 t0 z3; fadd y3 y3 t0 inline_for_extraction noextract val point_double_6 (x3 z3 t0 t1 t4:felem) : Stack unit (requires fun h -> live h x3 /\ live h z3 /\ live h t0 /\ live h t1 /\ live h t4 /\ LowStar.Monotonic.Buffer.all_disjoint [ loc x3; loc z3; loc t0; loc t1; loc t4 ] /\ as_nat h x3 < S.prime /\ as_nat h z3 < S.prime /\ as_nat h t1 < S.prime /\ as_nat h t4 < S.prime) (ensures fun h0 _ h1 -> modifies (loc x3 |+| loc z3 |+| loc t0) h0 h1 /\ as_nat h1 x3 < S.prime /\ as_nat h1 z3 < S.prime /\ as_nat h1 t0 < S.prime /\ (let t1_s = fmont_as_nat h0 t1 in let t4_s = fmont_as_nat h0 t4 in let x3_s = fmont_as_nat h0 x3 in let z3_s = fmont_as_nat h0 z3 in let t0_s = S.fadd t4_s t4_s in let z3_s = S.fmul t0_s z3_s in let x3_s = S.fsub x3_s z3_s in let z3_s = S.fmul t0_s t1_s in let z3_s = S.fadd z3_s z3_s in let z3_s = S.fadd z3_s z3_s in fmont_as_nat h1 z3 == z3_s /\ fmont_as_nat h1 x3 == x3_s /\ fmont_as_nat h1 t0 == t0_s))
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.P256.Field.fsti.checked", "Hacl.Impl.P256.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": true, "source_file": "Hacl.Impl.P256.PointDouble.fst" }
[ { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Impl.P256.Field", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.P256.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Impl.P256.Point", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x3: Hacl.Impl.P256.Bignum.felem -> z3: Hacl.Impl.P256.Bignum.felem -> t0: Hacl.Impl.P256.Bignum.felem -> t1: Hacl.Impl.P256.Bignum.felem -> t4: Hacl.Impl.P256.Bignum.felem -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.P256.Bignum.felem", "Hacl.Impl.P256.Field.fdouble", "Prims.unit", "Hacl.Impl.P256.Field.fmul", "Hacl.Impl.P256.Field.fsub" ]
[]
false
true
false
false
false
let point_double_6 x3 z3 t0 t1 t4 =
fdouble t0 t4; fmul z3 t0 z3; fsub x3 x3 z3; fmul z3 t0 t1; fdouble z3 z3; fdouble z3 z3
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.namedv_to_simple_binder
val namedv_to_simple_binder (n: namedv) : Tac simple_binder
val namedv_to_simple_binder (n: namedv) : Tac simple_binder
let namedv_to_simple_binder (n : namedv) : Tac simple_binder = let nv = inspect_namedv n in { ppname = nv.ppname; uniq = nv.uniq; sort = unseal nv.sort; (* GGG USINGSORT *) qual = Q_Explicit; attrs = []; }
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 890, "start_col": 0, "start_line": 882 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); () val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a let magic_dump #a #x () = x let change_with t1 t2 : Tac unit = focus (fun () -> grewrite t1 t2; iseq [idtac; trivial] ) let change_sq (t1 : term) : Tac unit = change (mk_e_app (`squash) [t1]) let finish_by (t : unit -> Tac 'a) : Tac 'a = let x = t () in or_else qed (fun () -> fail "finish_by: not finished"); x let solve_then #a #b (t1 : unit -> Tac a) (t2 : a -> Tac b) : Tac b = dup (); let x = focus (fun () -> finish_by t1) in let y = t2 x in trefl (); y let add_elem (t : unit -> Tac 'a) : Tac 'a = focus (fun () -> apply (`Cons); focus (fun () -> let x = t () in qed (); x ) ) (* * Specialize a function by partially evaluating it * For example: * let rec foo (l:list int) (x:int) :St int = match l with | [] -> x | hd::tl -> x + foo tl x let f :int -> St int = synth_by_tactic (specialize (foo [1; 2]) [%`foo]) * would make the definition of f as x + x + x * * f is the term that needs to be specialized * l is the list of names to be delta-ed *) let specialize (#a:Type) (f:a) (l:list string) :unit -> Tac unit = fun () -> solve_then (fun () -> exact (quote f)) (fun () -> norm [delta_only l; iota; zeta]) let tlabel (l:string) = match goals () with | [] -> fail "tlabel: no goals" | h::t -> set_goals (set_label l h :: t) let tlabel' (l:string) = match goals () with | [] -> fail "tlabel': no goals" | h::t -> let h = set_label (l ^ get_label h) h in set_goals (h :: t) let focus_all () : Tac unit = set_goals (goals () @ smt_goals ()); set_smt_goals [] private let rec extract_nth (n:nat) (l : list 'a) : option ('a * list 'a) = match n, l with | _, [] -> None | 0, hd::tl -> Some (hd, tl) | _, hd::tl -> begin match extract_nth (n-1) tl with | Some (hd', tl') -> Some (hd', hd::tl') | None -> None end let bump_nth (n:pos) : Tac unit = // n-1 since goal numbering begins at 1 match extract_nth (n - 1) (goals ()) with | None -> fail "bump_nth: not that many goals" | Some (h, t) -> set_goals (h :: t) let rec destruct_list (t : term) : Tac (list term) = let head, args = collect_app t in match inspect head, args with | Tv_FVar fv, [(a1, Q_Explicit); (a2, Q_Explicit)] | Tv_FVar fv, [(_, Q_Implicit); (a1, Q_Explicit); (a2, Q_Explicit)] -> if inspect_fv fv = cons_qn then a1 :: destruct_list a2 else raise NotAListLiteral | Tv_FVar fv, _ -> if inspect_fv fv = nil_qn then [] else raise NotAListLiteral | _ -> raise NotAListLiteral private let get_match_body () : Tac term = match unsquash_term (cur_goal ()) with | None -> fail "" | Some t -> match inspect_unascribe t with | Tv_Match sc _ _ -> sc | _ -> fail "Goal is not a match" private let rec last (x : list 'a) : Tac 'a = match x with | [] -> fail "last: empty list" | [x] -> x | _::xs -> last xs (** When the goal is [match e with | p1 -> e1 ... | pn -> en], destruct it into [n] goals for each possible case, including an hypothesis for [e] matching the corresponding pattern. *) let branch_on_match () : Tac unit = focus (fun () -> let x = get_match_body () in let _ = t_destruct x in iterAll (fun () -> let bs = repeat intro in let b = last bs in (* this one is the equality *) grewrite_eq b; norm [iota]) ) (** When the argument [i] is non-negative, [nth_var] grabs the nth binder in the current goal. When it is negative, it grabs the (-i-1)th binder counting from the end of the goal. That is, [nth_var (-1)] will return the last binder, [nth_var (-2)] the second to last, and so on. *) let nth_var (i:int) : Tac binding = let bs = cur_vars () in let k : int = if i >= 0 then i else List.Tot.Base.length bs + i in let k : nat = if k < 0 then fail "not enough binders" else k in match List.Tot.Base.nth bs k with | None -> fail "not enough binders" | Some b -> b exception Appears (** Decides whether a top-level name [nm] syntactically appears in the term [t]. *) let name_appears_in (nm:name) (t:term) : Tac bool = let ff (t : term) : Tac term = match inspect t with | Tv_FVar fv -> if inspect_fv fv = nm then raise Appears; t | tv -> pack tv in try ignore (V.visit_tm ff t); false with | Appears -> true | e -> raise e (** [mk_abs [x1; ...; xn] t] returns the term [fun x1 ... xn -> t] *) let rec mk_abs (args : list binder) (t : term) : Tac term (decreases args) = match args with | [] -> t | a :: args' -> let t' = mk_abs args' t in pack (Tv_Abs a t')
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: FStar.Tactics.NamedView.namedv -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.simple_binder
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Tactics.NamedView.namedv", "FStar.Tactics.NamedView.Mkbinder", "FStar.Stubs.Reflection.V2.Data.__proj__Mknamedv_view__item__uniq", "FStar.Stubs.Reflection.V2.Data.__proj__Mknamedv_view__item__ppname", "FStar.Stubs.Reflection.V2.Data.Q_Explicit", "Prims.Nil", "FStar.Tactics.NamedView.term", "FStar.Tactics.NamedView.simple_binder", "FStar.Stubs.Reflection.Types.typ", "FStar.Tactics.Unseal.unseal", "FStar.Stubs.Reflection.V2.Data.__proj__Mknamedv_view__item__sort", "FStar.Tactics.NamedView.inspect_namedv" ]
[]
false
true
false
false
false
let namedv_to_simple_binder (n: namedv) : Tac simple_binder =
let nv = inspect_namedv n in { ppname = nv.ppname; uniq = nv.uniq; sort = unseal nv.sort; qual = Q_Explicit; attrs = [] }
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.bump_nth
val bump_nth (n: pos) : Tac unit
val bump_nth (n: pos) : Tac unit
let bump_nth (n:pos) : Tac unit = // n-1 since goal numbering begins at 1 match extract_nth (n - 1) (goals ()) with | None -> fail "bump_nth: not that many goals" | Some (h, t) -> set_goals (h :: t)
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 37, "end_line": 799, "start_col": 0, "start_line": 795 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); () val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a let magic_dump #a #x () = x let change_with t1 t2 : Tac unit = focus (fun () -> grewrite t1 t2; iseq [idtac; trivial] ) let change_sq (t1 : term) : Tac unit = change (mk_e_app (`squash) [t1]) let finish_by (t : unit -> Tac 'a) : Tac 'a = let x = t () in or_else qed (fun () -> fail "finish_by: not finished"); x let solve_then #a #b (t1 : unit -> Tac a) (t2 : a -> Tac b) : Tac b = dup (); let x = focus (fun () -> finish_by t1) in let y = t2 x in trefl (); y let add_elem (t : unit -> Tac 'a) : Tac 'a = focus (fun () -> apply (`Cons); focus (fun () -> let x = t () in qed (); x ) ) (* * Specialize a function by partially evaluating it * For example: * let rec foo (l:list int) (x:int) :St int = match l with | [] -> x | hd::tl -> x + foo tl x let f :int -> St int = synth_by_tactic (specialize (foo [1; 2]) [%`foo]) * would make the definition of f as x + x + x * * f is the term that needs to be specialized * l is the list of names to be delta-ed *) let specialize (#a:Type) (f:a) (l:list string) :unit -> Tac unit = fun () -> solve_then (fun () -> exact (quote f)) (fun () -> norm [delta_only l; iota; zeta]) let tlabel (l:string) = match goals () with | [] -> fail "tlabel: no goals" | h::t -> set_goals (set_label l h :: t) let tlabel' (l:string) = match goals () with | [] -> fail "tlabel': no goals" | h::t -> let h = set_label (l ^ get_label h) h in set_goals (h :: t) let focus_all () : Tac unit = set_goals (goals () @ smt_goals ()); set_smt_goals [] private let rec extract_nth (n:nat) (l : list 'a) : option ('a * list 'a) = match n, l with | _, [] -> None | 0, hd::tl -> Some (hd, tl) | _, hd::tl -> begin match extract_nth (n-1) tl with | Some (hd', tl') -> Some (hd', hd::tl') | None -> None end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.pos", "FStar.Tactics.V2.Derived.fail", "Prims.unit", "FStar.Stubs.Tactics.Types.goal", "Prims.list", "FStar.Stubs.Tactics.V2.Builtins.set_goals", "Prims.Cons", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "FStar.Tactics.V2.Derived.extract_nth", "Prims.op_Subtraction", "FStar.Tactics.V2.Derived.goals" ]
[]
false
true
false
false
false
let bump_nth (n: pos) : Tac unit =
match extract_nth (n - 1) (goals ()) with | None -> fail "bump_nth: not that many goals" | Some (h, t) -> set_goals (h :: t)
false
EtM.AE.fst
EtM.AE.log_entry
val log_entry : Type0
let log_entry = Plain.plain * cipher
{ "file_name": "examples/crypto/EtM.AE.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 36, "end_line": 39, "start_col": 0, "start_line": 39 }
(* Copyright 2008-2018 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 EtM.AE open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open FStar.HyperStack.ST module MAC = EtM.MAC open Platform.Bytes open CoreCrypto module CPA = EtM.CPA module MAC = EtM.MAC module Ideal = EtM.Ideal module Plain = EtM.Plain (*** Basic types ***) type rid = erid /// An AE cipher includes a mac tag type cipher = (CPA.cipher * MAC.tag)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.Map.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "EtM.Plain.fsti.checked", "EtM.MAC.fst.checked", "EtM.Ideal.fsti.checked", "EtM.CPA.fst.checked", "CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.AE.fst" }
[ { "abbrev": true, "full_module": "EtM.Plain", "short_module": "Plain" }, { "abbrev": true, "full_module": "EtM.Ideal", "short_module": "Ideal" }, { "abbrev": true, "full_module": "EtM.MAC", "short_module": "MAC" }, { "abbrev": true, "full_module": "EtM.CPA", "short_module": "CPA" }, { "abbrev": false, "full_module": "CoreCrypto", "short_module": null }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": true, "full_module": "EtM.MAC", "short_module": "MAC" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.tuple2", "EtM.Plain.plain", "EtM.AE.cipher" ]
[]
false
false
false
true
true
let log_entry =
Plain.plain * cipher
false
ID3.fst
ID3.l
val l: Prims.unit -> int
val l: Prims.unit -> int
let l () : int = reify (test_f ())
{ "file_name": "examples/layeredeffects/ID3.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 77, "start_col": 0, "start_line": 76 }
module ID3 // The base type of WPs val w0 (a : Type u#a) : Type u#(max 1 a) let w0 a = (a -> Type0) -> Type0 // We require monotonicity of them let monotonic (w:w0 'a) = forall p1 p2. (forall x. p1 x ==> p2 x) ==> w p1 ==> w p2 val w (a : Type u#a) : Type u#(max 1 a) let w a = pure_wp a let repr (a : Type) (wp : w a) : Type = v:a{forall p. wp p ==> p v} open FStar.Monotonic.Pure let return (a : Type) (x : a) : repr a (as_pure_wp (fun p -> p x)) = x unfold let bind_wp #a #b (wp_v:w a) (wp_f:a -> w b) : w b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wp_v (fun x -> wp_f x p)) let bind (a b : Type) (wp_v : w a) (wp_f: a -> w b) (v : repr a wp_v) (f : (x:a -> repr b (wp_f x))) : repr b (bind_wp wp_v wp_f) = f v let subcomp (a:Type) (wp1 wp2: w a) (f : repr a wp1) : Pure (repr a wp2) (requires (forall p. wp2 p ==> wp1 p)) (ensures fun _ -> True) = f unfold let if_then_else_wp #a (wp1 wp2:w a) (p:bool) = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> (p ==> wp1 post) /\ ((~p) ==> wp2 post)) let if_then_else (a : Type) (wp1 wp2 : w a) (f : repr a wp1) (g : repr a wp2) (p : bool) : Type = repr a (if_then_else_wp wp1 wp2 p) // requires to prove that // p ==> f <: (if_then_else p f g) // ~p ==> g <: (if_then_else p f g) // if the effect definition fails, add lemmas for the // above with smtpats total reifiable reflectable effect { ID (a:Type) (_ : w a) with {repr; return; bind; subcomp; if_then_else} } let lift_pure_nd (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp) : Pure (repr a wp) (requires (wp (fun _ -> True))) (ensures (fun _ -> True)) = elim_pure_wp_monotonicity_forall (); f () sub_effect PURE ~> ID = lift_pure_nd (* Checking that it's kind of usable *) val test_f : unit -> ID int (as_pure_wp (fun p -> p 5 /\ p 3)) let test_f () = 3 module T = FStar.Tactics.V2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "ID3.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> Prims.int
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "ID3.test_f", "Prims.int" ]
[]
false
false
false
true
false
let l () : int =
reify (test_f ())
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.mk_abs
val mk_abs (args: list binder) (t: term) : Tac term (decreases args)
val mk_abs (args: list binder) (t: term) : Tac term (decreases args)
let rec mk_abs (args : list binder) (t : term) : Tac term (decreases args) = match args with | [] -> t | a :: args' -> let t' = mk_abs args' t in pack (Tv_Abs a t')
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 22, "end_line": 879, "start_col": 0, "start_line": 874 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); () val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a let magic_dump #a #x () = x let change_with t1 t2 : Tac unit = focus (fun () -> grewrite t1 t2; iseq [idtac; trivial] ) let change_sq (t1 : term) : Tac unit = change (mk_e_app (`squash) [t1]) let finish_by (t : unit -> Tac 'a) : Tac 'a = let x = t () in or_else qed (fun () -> fail "finish_by: not finished"); x let solve_then #a #b (t1 : unit -> Tac a) (t2 : a -> Tac b) : Tac b = dup (); let x = focus (fun () -> finish_by t1) in let y = t2 x in trefl (); y let add_elem (t : unit -> Tac 'a) : Tac 'a = focus (fun () -> apply (`Cons); focus (fun () -> let x = t () in qed (); x ) ) (* * Specialize a function by partially evaluating it * For example: * let rec foo (l:list int) (x:int) :St int = match l with | [] -> x | hd::tl -> x + foo tl x let f :int -> St int = synth_by_tactic (specialize (foo [1; 2]) [%`foo]) * would make the definition of f as x + x + x * * f is the term that needs to be specialized * l is the list of names to be delta-ed *) let specialize (#a:Type) (f:a) (l:list string) :unit -> Tac unit = fun () -> solve_then (fun () -> exact (quote f)) (fun () -> norm [delta_only l; iota; zeta]) let tlabel (l:string) = match goals () with | [] -> fail "tlabel: no goals" | h::t -> set_goals (set_label l h :: t) let tlabel' (l:string) = match goals () with | [] -> fail "tlabel': no goals" | h::t -> let h = set_label (l ^ get_label h) h in set_goals (h :: t) let focus_all () : Tac unit = set_goals (goals () @ smt_goals ()); set_smt_goals [] private let rec extract_nth (n:nat) (l : list 'a) : option ('a * list 'a) = match n, l with | _, [] -> None | 0, hd::tl -> Some (hd, tl) | _, hd::tl -> begin match extract_nth (n-1) tl with | Some (hd', tl') -> Some (hd', hd::tl') | None -> None end let bump_nth (n:pos) : Tac unit = // n-1 since goal numbering begins at 1 match extract_nth (n - 1) (goals ()) with | None -> fail "bump_nth: not that many goals" | Some (h, t) -> set_goals (h :: t) let rec destruct_list (t : term) : Tac (list term) = let head, args = collect_app t in match inspect head, args with | Tv_FVar fv, [(a1, Q_Explicit); (a2, Q_Explicit)] | Tv_FVar fv, [(_, Q_Implicit); (a1, Q_Explicit); (a2, Q_Explicit)] -> if inspect_fv fv = cons_qn then a1 :: destruct_list a2 else raise NotAListLiteral | Tv_FVar fv, _ -> if inspect_fv fv = nil_qn then [] else raise NotAListLiteral | _ -> raise NotAListLiteral private let get_match_body () : Tac term = match unsquash_term (cur_goal ()) with | None -> fail "" | Some t -> match inspect_unascribe t with | Tv_Match sc _ _ -> sc | _ -> fail "Goal is not a match" private let rec last (x : list 'a) : Tac 'a = match x with | [] -> fail "last: empty list" | [x] -> x | _::xs -> last xs (** When the goal is [match e with | p1 -> e1 ... | pn -> en], destruct it into [n] goals for each possible case, including an hypothesis for [e] matching the corresponding pattern. *) let branch_on_match () : Tac unit = focus (fun () -> let x = get_match_body () in let _ = t_destruct x in iterAll (fun () -> let bs = repeat intro in let b = last bs in (* this one is the equality *) grewrite_eq b; norm [iota]) ) (** When the argument [i] is non-negative, [nth_var] grabs the nth binder in the current goal. When it is negative, it grabs the (-i-1)th binder counting from the end of the goal. That is, [nth_var (-1)] will return the last binder, [nth_var (-2)] the second to last, and so on. *) let nth_var (i:int) : Tac binding = let bs = cur_vars () in let k : int = if i >= 0 then i else List.Tot.Base.length bs + i in let k : nat = if k < 0 then fail "not enough binders" else k in match List.Tot.Base.nth bs k with | None -> fail "not enough binders" | Some b -> b exception Appears (** Decides whether a top-level name [nm] syntactically appears in the term [t]. *) let name_appears_in (nm:name) (t:term) : Tac bool = let ff (t : term) : Tac term = match inspect t with | Tv_FVar fv -> if inspect_fv fv = nm then raise Appears; t | tv -> pack tv in try ignore (V.visit_tm ff t); false with | Appears -> true | e -> raise e
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
args: Prims.list FStar.Tactics.NamedView.binder -> t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.term
FStar.Tactics.Effect.Tac
[ "" ]
[]
[ "Prims.list", "FStar.Tactics.NamedView.binder", "FStar.Tactics.NamedView.term", "FStar.Tactics.NamedView.pack", "FStar.Tactics.NamedView.Tv_Abs", "FStar.Tactics.V2.Derived.mk_abs" ]
[ "recursion" ]
false
true
false
false
false
let rec mk_abs (args: list binder) (t: term) : Tac term (decreases args) =
match args with | [] -> t | a :: args' -> let t' = mk_abs args' t in pack (Tv_Abs a t')
false
Steel.Primitive.ForkJoin.Unix.fst
Steel.Primitive.ForkJoin.Unix.triv_post
val triv_post (#a: Type) (req: vprop) (ens: post_t a) : ens_t req a ens
val triv_post (#a: Type) (req: vprop) (ens: post_t a) : ens_t req a ens
let triv_post (#a:Type) (req:vprop) (ens:post_t a) : ens_t req a ens = fun _ _ _ -> True
{ "file_name": "lib/steel/Steel.Primitive.ForkJoin.Unix.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 88, "end_line": 232, "start_col": 0, "start_line": 232 }
(* 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.Primitive.ForkJoin.Unix (* This module shows that it's possible to layer continuations on top of SteelT to get a direct style (or Unix style) fork/join. Very much a prototype for now. *) open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.Reference open Steel.Primitive.ForkJoin #set-options "--warn_error -330" //turn off the experimental feature warning #set-options "--ide_id_info_off" // (* Some helpers *) let change_slprop_equiv (p q : vprop) (proof : squash (p `equiv` q)) : SteelT unit p (fun _ -> q) = rewrite_slprop p q (fun _ -> proof; reveal_equiv p q) let change_slprop_imp (p q : vprop) (proof : squash (p `can_be_split` q)) : SteelT unit p (fun _ -> q) = rewrite_slprop p q (fun _ -> proof; reveal_can_be_split ()) (* Continuations into unit, but parametrized by the final heap * proposition and with an implicit framing. I think ideally these would * also be parametric in the final type (instead of being hardcoded to * unit) but that means fork needs to be extended to be polymorphic in * at least one of the branches. *) type steelK (t:Type u#aa) (framed:bool) (pre : vprop) (post:t->vprop) = #frame:vprop -> #postf:vprop -> f:(x:t -> SteelT unit (frame `star` post x) (fun _ -> postf)) -> SteelT unit (frame `star` pre) (fun _ -> postf) (* The classic continuation monad *) let return_ a (x:a) (#[@@@ framing_implicit] p: a -> vprop) : steelK a true (return_pre (p x)) p = fun k -> k x private let rearrange3 (p q r:vprop) : Lemma (((p `star` q) `star` r) `equiv` (p `star` (r `star` q))) = let open FStar.Tactics in assert (((p `star` q) `star` r) `equiv` (p `star` (r `star` q))) by (norm [delta_attr [`%__reduce__]]; canon' false (`true_p) (`true_p)) private let equiv_symmetric (p1 p2:vprop) : Lemma (requires p1 `equiv` p2) (ensures p2 `equiv` p1) = reveal_equiv p1 p2; equiv_symmetric (hp_of p1) (hp_of p2); reveal_equiv p2 p1 private let can_be_split_forall_frame (#a:Type) (p q:post_t a) (frame:vprop) (x:a) : Lemma (requires can_be_split_forall p q) (ensures (frame `star` p x) `can_be_split` (frame `star` q x)) = let frame = hp_of frame in let p = hp_of (p x) in let q = hp_of (q x) in reveal_can_be_split (); assert (slimp p q); slimp_star p q frame frame; Steel.Memory.star_commutative p frame; Steel.Memory.star_commutative q frame let bind (a:Type) (b:Type) (#framed_f:eqtype_as_type bool) (#framed_g:eqtype_as_type bool) (#[@@@ framing_implicit] pre_f:pre_t) (#[@@@ framing_implicit] post_f:post_t a) (#[@@@ framing_implicit] pre_g:a -> pre_t) (#[@@@ framing_implicit] post_g:post_t b) (#[@@@ framing_implicit] frame_f:vprop) (#[@@@ framing_implicit] frame_g:vprop) (#[@@@ framing_implicit] p:squash (can_be_split_forall (fun x -> post_f x `star` frame_f) (fun x -> pre_g x `star` frame_g))) (#[@@@ framing_implicit] m1 : squash (maybe_emp framed_f frame_f)) (#[@@@ framing_implicit] m2:squash (maybe_emp framed_g frame_g)) (f:steelK a framed_f pre_f post_f) (g:(x:a -> steelK b framed_g (pre_g x) post_g)) : steelK b true (pre_f `star` frame_f) (fun y -> post_g y `star` frame_g) = fun #frame (#post:vprop) (k:(y:b -> SteelT unit (frame `star` (post_g y `star` frame_g)) (fun _ -> post))) -> // Need SteelT unit (frame `star` (pre_f `star` frame_f)) (fun _ -> post) change_slprop_equiv (frame `star` (pre_f `star` frame_f)) ((frame `star` frame_f) `star` pre_f) (rearrange3 frame frame_f pre_f; equiv_symmetric ((frame `star` frame_f) `star` pre_f) (frame `star` (pre_f `star` frame_f)) ); f #(frame `star` frame_f) #post ((fun (x:a) -> // Need SteelT unit ((frame `star` frame_f) `star` post_f x) (fun _ -> post) change_slprop_imp (frame `star` (post_f x `star` frame_f)) (frame `star` (pre_g x `star` frame_g)) (can_be_split_forall_frame (fun x -> post_f x `star` frame_f) (fun x -> pre_g x `star` frame_g) frame x); g x #(frame `star` frame_g) #post ((fun (y:b) -> k y) <: (y:b -> SteelT unit ((frame `star` frame_g) `star` post_g y) (fun _ -> post))) ) <: (x:a -> SteelT unit ((frame `star` frame_f) `star` post_f x) (fun _ -> post))) let subcomp (a:Type) (#framed_f:eqtype_as_type bool) (#framed_g:eqtype_as_type bool) (#[@@@ framing_implicit] pre_f:pre_t) (#[@@@ framing_implicit] post_f:post_t a) (#[@@@ framing_implicit] pre_g:pre_t) (#[@@@ framing_implicit] post_g:post_t a) (#[@@@ framing_implicit] p1:squash (can_be_split pre_g pre_f)) (#[@@@ framing_implicit] p2:squash (can_be_split_forall post_f post_g)) (f:steelK a framed_f pre_f post_f) : Tot (steelK a framed_g pre_g post_g) = fun #frame #postf (k:(x:a -> SteelT unit (frame `star` post_g x) (fun _ -> postf))) -> change_slprop_imp pre_g pre_f (); f #frame #postf ((fun x -> change_slprop_imp (frame `star` post_f x) (frame `star` post_g x) (can_be_split_forall_frame post_f post_g frame x); k x) <: (x:a -> SteelT unit (frame `star` post_f x) (fun _ -> postf))) // let if_then_else (a:Type u#aa) // (#[@@@ framing_implicit] pre1:pre_t) // (#[@@@ framing_implicit] post1:post_t a) // (f : steelK a pre1 post1) // (g : steelK a pre1 post1) // (p:Type0) : Type = // steelK a pre1 post1 // We did not define a bind between Div and Steel, so we indicate // SteelKF as total to be able to reify and compose it when implementing fork // This module is intended as proof of concept total reifiable reflectable layered_effect { SteelKBase : a:Type -> framed:bool -> pre:vprop -> post:(a->vprop) -> Effect with repr = steelK; return = return_; bind = bind; subcomp = subcomp // if_then_else = if_then_else } effect SteelK (a:Type) (pre:pre_t) (post:post_t a) = SteelKBase a false pre post effect SteelKF (a:Type) (pre:pre_t) (post:post_t a) = SteelKBase a true pre post // We would need requires/ensures in SteelK to have a binding with Pure. // But for our example, Tot is here sufficient let bind_tot_steelK_ (a:Type) (b:Type) (#framed:eqtype_as_type bool) (#[@@@ framing_implicit] pre:pre_t) (#[@@@ framing_implicit] post:post_t b) (f:eqtype_as_type unit -> Tot a) (g:(x:a -> steelK b framed pre post)) : steelK b framed pre post = fun #frame #postf (k:(x:b -> SteelT unit (frame `star` post x) (fun _ -> postf))) -> let x = f () in g x #frame #postf k polymonadic_bind (PURE, SteelKBase) |> SteelKBase = bind_tot_steelK_ // (* Sanity check *) let test_lift #p #q (f : unit -> SteelK unit p (fun _ -> q)) : SteelK unit p (fun _ -> q) = (); f (); () (* Identity cont with frame, to eliminate a SteelK *) let idk (#frame:vprop) (#a:Type) (x:a) : SteelT a frame (fun x -> frame) = noop(); return x let kfork (#p:vprop) (#q:vprop) (f : unit -> SteelK unit p (fun _ -> q)) : SteelK (thread q) p (fun _ -> emp) = SteelK?.reflect ( fun (#frame:vprop) (#postf:vprop) (k : (x:(thread q) -> SteelT unit (frame `star` emp) (fun _ -> postf))) -> noop (); let t1 () : SteelT unit (emp `star` p) (fun _ -> q) = let r : steelK unit false p (fun _ -> q) = reify (f ()) in r #emp #q (fun _ -> idk()) in let t2 (t:thread q) () : SteelT unit frame (fun _ -> postf) = k t in let ff () : SteelT unit (p `star` frame) (fun _ -> postf) = fork #p #q #frame #postf t1 t2 in ff()) let kjoin (#p:vprop) (t : thread p) : SteelK unit emp (fun _ -> p) = SteelK?.reflect (fun #f k -> join t; k ()) (* Example *) assume val q : int -> vprop assume val f : unit -> SteelK unit emp (fun _ -> emp) assume val g : i:int -> SteelK unit emp (fun _ -> q i) assume val h : unit -> SteelK unit emp (fun _ -> emp) let example () : SteelK unit emp (fun _ -> q 1 `star` q 2) = let p1:thread (q 1) = kfork (fun () -> g 1) in let p2:thread (q 2) = kfork (fun () -> g 2) in kjoin p1; h(); kjoin p2 let as_steelk_repr' (a:Type) (pre:pre_t) (post:post_t a) (f:unit -> SteelT a pre post) : steelK a false pre post = fun #frame #postf (k:(x:a -> SteelT unit (frame `star` post x) (fun _ -> postf))) -> let x = f () in k x
{ "checked_file": "/", "dependencies": [ "Steel.Reference.fsti.checked", "Steel.Primitive.ForkJoin.fsti.checked", "Steel.Memory.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Steel.Primitive.ForkJoin.Unix.fst" }
[ { "abbrev": false, "full_module": "Steel.Primitive.ForkJoin", "short_module": null }, { "abbrev": false, "full_module": "Steel.Reference", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.Primitive.ForkJoin", "short_module": null }, { "abbrev": false, "full_module": "Steel.Primitive.ForkJoin", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
req: Steel.Effect.Common.vprop -> ens: Steel.Effect.Common.post_t a -> Steel.Effect.Common.ens_t req a ens
Prims.Tot
[ "total" ]
[]
[ "Steel.Effect.Common.vprop", "Steel.Effect.Common.post_t", "Steel.Effect.Common.rmem", "Prims.l_True", "Steel.Effect.Common.ens_t" ]
[]
false
false
false
false
false
let triv_post (#a: Type) (req: vprop) (ens: post_t a) : ens_t req a ens =
fun _ _ _ -> True
false
EtM.AE.fst
EtM.AE.mac_cpa_related
val mac_cpa_related : mac: EtM.MAC.log_entry -> cpa: EtM.CPA.log_entry -> Prims.logical
let mac_cpa_related (mac:EtM.MAC.log_entry) (cpa:EtM.CPA.log_entry) = CPA.Entry?.c cpa == fst mac
{ "file_name": "examples/crypto/EtM.AE.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 29, "end_line": 87, "start_col": 0, "start_line": 86 }
(* Copyright 2008-2018 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 EtM.AE open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open FStar.HyperStack.ST module MAC = EtM.MAC open Platform.Bytes open CoreCrypto module CPA = EtM.CPA module MAC = EtM.MAC module Ideal = EtM.Ideal module Plain = EtM.Plain (*** Basic types ***) type rid = erid /// An AE cipher includes a mac tag type cipher = (CPA.cipher * MAC.tag) /// An AE log pairs plain texts with MAC'd ciphers let log_entry = Plain.plain * cipher type log_t (r:rid) = m_rref r (seq log_entry) grows /// An AE key pairs an encryption key, ke, with a MAC'ing key, km, /// with an invariant ensuring that their memory footprints of their /// ideal state are disjoint. /// /// Aside from this, we have an AE log, which is a view of the two /// other logs. noeq type key = | Key: #region:rid -> ke:CPA.key { extends (CPA.Key?.region ke) region } -> km:MAC.key { extends (MAC.Key?.region km) region /\ disjoint( CPA.Key?.region ke) (MAC.Key?.region km) } -> log:log_t region -> key (** Accessors for the three logs **) /// ae log let get_log (h:mem) (k:key) = sel h k.log /// mac log let get_mac_log (h:mem) (k:key) = sel h (MAC.Key?.log k.km) /// cpa log let get_cpa_log (h:mem) (k:key) = sel h (CPA.Key?.log k.ke) (*** Main invariant on the ideal state ***) (** There are three components to this invariant 1. The CPA invariant (pairwise distinctness of IVs, notably) 2. mac_only_cpa_ciphers: The MAC log and CPA logs are related, in that the MAC log only contains entries for valid ciphers recorded the CPA log 3. mac_and_cpa_refine_ae: The AE log is a combined view of the MAC and CPA logs Each of its entries corresponds is combination of a single entry in the MAC log and another in the CPA log **)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.Map.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "EtM.Plain.fsti.checked", "EtM.MAC.fst.checked", "EtM.Ideal.fsti.checked", "EtM.CPA.fst.checked", "CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.AE.fst" }
[ { "abbrev": true, "full_module": "EtM.Plain", "short_module": "Plain" }, { "abbrev": true, "full_module": "EtM.Ideal", "short_module": "Ideal" }, { "abbrev": true, "full_module": "EtM.MAC", "short_module": "MAC" }, { "abbrev": true, "full_module": "EtM.CPA", "short_module": "CPA" }, { "abbrev": false, "full_module": "CoreCrypto", "short_module": null }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": true, "full_module": "EtM.MAC", "short_module": "MAC" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mac: EtM.MAC.log_entry -> cpa: EtM.CPA.log_entry -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "EtM.MAC.log_entry", "EtM.CPA.log_entry", "Prims.eq2", "EtM.CPA.cipher", "EtM.CPA.__proj__Entry__item__c", "FStar.Pervasives.Native.fst", "EtM.MAC.msg", "EtM.MAC.tag", "Prims.logical" ]
[]
false
false
false
true
true
let mac_cpa_related (mac: EtM.MAC.log_entry) (cpa: EtM.CPA.log_entry) =
CPA.Entry?.c cpa == fst mac
false
Steel.Primitive.ForkJoin.Unix.fst
Steel.Primitive.ForkJoin.Unix.triv_pre
val triv_pre (req: vprop) : req_t req
val triv_pre (req: vprop) : req_t req
let triv_pre (req:vprop) : req_t req = fun _ -> True
{ "file_name": "lib/steel/Steel.Primitive.ForkJoin.Unix.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 52, "end_line": 231, "start_col": 0, "start_line": 231 }
(* 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.Primitive.ForkJoin.Unix (* This module shows that it's possible to layer continuations on top of SteelT to get a direct style (or Unix style) fork/join. Very much a prototype for now. *) open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.Reference open Steel.Primitive.ForkJoin #set-options "--warn_error -330" //turn off the experimental feature warning #set-options "--ide_id_info_off" // (* Some helpers *) let change_slprop_equiv (p q : vprop) (proof : squash (p `equiv` q)) : SteelT unit p (fun _ -> q) = rewrite_slprop p q (fun _ -> proof; reveal_equiv p q) let change_slprop_imp (p q : vprop) (proof : squash (p `can_be_split` q)) : SteelT unit p (fun _ -> q) = rewrite_slprop p q (fun _ -> proof; reveal_can_be_split ()) (* Continuations into unit, but parametrized by the final heap * proposition and with an implicit framing. I think ideally these would * also be parametric in the final type (instead of being hardcoded to * unit) but that means fork needs to be extended to be polymorphic in * at least one of the branches. *) type steelK (t:Type u#aa) (framed:bool) (pre : vprop) (post:t->vprop) = #frame:vprop -> #postf:vprop -> f:(x:t -> SteelT unit (frame `star` post x) (fun _ -> postf)) -> SteelT unit (frame `star` pre) (fun _ -> postf) (* The classic continuation monad *) let return_ a (x:a) (#[@@@ framing_implicit] p: a -> vprop) : steelK a true (return_pre (p x)) p = fun k -> k x private let rearrange3 (p q r:vprop) : Lemma (((p `star` q) `star` r) `equiv` (p `star` (r `star` q))) = let open FStar.Tactics in assert (((p `star` q) `star` r) `equiv` (p `star` (r `star` q))) by (norm [delta_attr [`%__reduce__]]; canon' false (`true_p) (`true_p)) private let equiv_symmetric (p1 p2:vprop) : Lemma (requires p1 `equiv` p2) (ensures p2 `equiv` p1) = reveal_equiv p1 p2; equiv_symmetric (hp_of p1) (hp_of p2); reveal_equiv p2 p1 private let can_be_split_forall_frame (#a:Type) (p q:post_t a) (frame:vprop) (x:a) : Lemma (requires can_be_split_forall p q) (ensures (frame `star` p x) `can_be_split` (frame `star` q x)) = let frame = hp_of frame in let p = hp_of (p x) in let q = hp_of (q x) in reveal_can_be_split (); assert (slimp p q); slimp_star p q frame frame; Steel.Memory.star_commutative p frame; Steel.Memory.star_commutative q frame let bind (a:Type) (b:Type) (#framed_f:eqtype_as_type bool) (#framed_g:eqtype_as_type bool) (#[@@@ framing_implicit] pre_f:pre_t) (#[@@@ framing_implicit] post_f:post_t a) (#[@@@ framing_implicit] pre_g:a -> pre_t) (#[@@@ framing_implicit] post_g:post_t b) (#[@@@ framing_implicit] frame_f:vprop) (#[@@@ framing_implicit] frame_g:vprop) (#[@@@ framing_implicit] p:squash (can_be_split_forall (fun x -> post_f x `star` frame_f) (fun x -> pre_g x `star` frame_g))) (#[@@@ framing_implicit] m1 : squash (maybe_emp framed_f frame_f)) (#[@@@ framing_implicit] m2:squash (maybe_emp framed_g frame_g)) (f:steelK a framed_f pre_f post_f) (g:(x:a -> steelK b framed_g (pre_g x) post_g)) : steelK b true (pre_f `star` frame_f) (fun y -> post_g y `star` frame_g) = fun #frame (#post:vprop) (k:(y:b -> SteelT unit (frame `star` (post_g y `star` frame_g)) (fun _ -> post))) -> // Need SteelT unit (frame `star` (pre_f `star` frame_f)) (fun _ -> post) change_slprop_equiv (frame `star` (pre_f `star` frame_f)) ((frame `star` frame_f) `star` pre_f) (rearrange3 frame frame_f pre_f; equiv_symmetric ((frame `star` frame_f) `star` pre_f) (frame `star` (pre_f `star` frame_f)) ); f #(frame `star` frame_f) #post ((fun (x:a) -> // Need SteelT unit ((frame `star` frame_f) `star` post_f x) (fun _ -> post) change_slprop_imp (frame `star` (post_f x `star` frame_f)) (frame `star` (pre_g x `star` frame_g)) (can_be_split_forall_frame (fun x -> post_f x `star` frame_f) (fun x -> pre_g x `star` frame_g) frame x); g x #(frame `star` frame_g) #post ((fun (y:b) -> k y) <: (y:b -> SteelT unit ((frame `star` frame_g) `star` post_g y) (fun _ -> post))) ) <: (x:a -> SteelT unit ((frame `star` frame_f) `star` post_f x) (fun _ -> post))) let subcomp (a:Type) (#framed_f:eqtype_as_type bool) (#framed_g:eqtype_as_type bool) (#[@@@ framing_implicit] pre_f:pre_t) (#[@@@ framing_implicit] post_f:post_t a) (#[@@@ framing_implicit] pre_g:pre_t) (#[@@@ framing_implicit] post_g:post_t a) (#[@@@ framing_implicit] p1:squash (can_be_split pre_g pre_f)) (#[@@@ framing_implicit] p2:squash (can_be_split_forall post_f post_g)) (f:steelK a framed_f pre_f post_f) : Tot (steelK a framed_g pre_g post_g) = fun #frame #postf (k:(x:a -> SteelT unit (frame `star` post_g x) (fun _ -> postf))) -> change_slprop_imp pre_g pre_f (); f #frame #postf ((fun x -> change_slprop_imp (frame `star` post_f x) (frame `star` post_g x) (can_be_split_forall_frame post_f post_g frame x); k x) <: (x:a -> SteelT unit (frame `star` post_f x) (fun _ -> postf))) // let if_then_else (a:Type u#aa) // (#[@@@ framing_implicit] pre1:pre_t) // (#[@@@ framing_implicit] post1:post_t a) // (f : steelK a pre1 post1) // (g : steelK a pre1 post1) // (p:Type0) : Type = // steelK a pre1 post1 // We did not define a bind between Div and Steel, so we indicate // SteelKF as total to be able to reify and compose it when implementing fork // This module is intended as proof of concept total reifiable reflectable layered_effect { SteelKBase : a:Type -> framed:bool -> pre:vprop -> post:(a->vprop) -> Effect with repr = steelK; return = return_; bind = bind; subcomp = subcomp // if_then_else = if_then_else } effect SteelK (a:Type) (pre:pre_t) (post:post_t a) = SteelKBase a false pre post effect SteelKF (a:Type) (pre:pre_t) (post:post_t a) = SteelKBase a true pre post // We would need requires/ensures in SteelK to have a binding with Pure. // But for our example, Tot is here sufficient let bind_tot_steelK_ (a:Type) (b:Type) (#framed:eqtype_as_type bool) (#[@@@ framing_implicit] pre:pre_t) (#[@@@ framing_implicit] post:post_t b) (f:eqtype_as_type unit -> Tot a) (g:(x:a -> steelK b framed pre post)) : steelK b framed pre post = fun #frame #postf (k:(x:b -> SteelT unit (frame `star` post x) (fun _ -> postf))) -> let x = f () in g x #frame #postf k polymonadic_bind (PURE, SteelKBase) |> SteelKBase = bind_tot_steelK_ // (* Sanity check *) let test_lift #p #q (f : unit -> SteelK unit p (fun _ -> q)) : SteelK unit p (fun _ -> q) = (); f (); () (* Identity cont with frame, to eliminate a SteelK *) let idk (#frame:vprop) (#a:Type) (x:a) : SteelT a frame (fun x -> frame) = noop(); return x let kfork (#p:vprop) (#q:vprop) (f : unit -> SteelK unit p (fun _ -> q)) : SteelK (thread q) p (fun _ -> emp) = SteelK?.reflect ( fun (#frame:vprop) (#postf:vprop) (k : (x:(thread q) -> SteelT unit (frame `star` emp) (fun _ -> postf))) -> noop (); let t1 () : SteelT unit (emp `star` p) (fun _ -> q) = let r : steelK unit false p (fun _ -> q) = reify (f ()) in r #emp #q (fun _ -> idk()) in let t2 (t:thread q) () : SteelT unit frame (fun _ -> postf) = k t in let ff () : SteelT unit (p `star` frame) (fun _ -> postf) = fork #p #q #frame #postf t1 t2 in ff()) let kjoin (#p:vprop) (t : thread p) : SteelK unit emp (fun _ -> p) = SteelK?.reflect (fun #f k -> join t; k ()) (* Example *) assume val q : int -> vprop assume val f : unit -> SteelK unit emp (fun _ -> emp) assume val g : i:int -> SteelK unit emp (fun _ -> q i) assume val h : unit -> SteelK unit emp (fun _ -> emp) let example () : SteelK unit emp (fun _ -> q 1 `star` q 2) = let p1:thread (q 1) = kfork (fun () -> g 1) in let p2:thread (q 2) = kfork (fun () -> g 2) in kjoin p1; h(); kjoin p2 let as_steelk_repr' (a:Type) (pre:pre_t) (post:post_t a) (f:unit -> SteelT a pre post) : steelK a false pre post = fun #frame #postf (k:(x:a -> SteelT unit (frame `star` post x) (fun _ -> postf))) -> let x = f () in k x
{ "checked_file": "/", "dependencies": [ "Steel.Reference.fsti.checked", "Steel.Primitive.ForkJoin.fsti.checked", "Steel.Memory.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Steel.Primitive.ForkJoin.Unix.fst" }
[ { "abbrev": false, "full_module": "Steel.Primitive.ForkJoin", "short_module": null }, { "abbrev": false, "full_module": "Steel.Reference", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.Primitive.ForkJoin", "short_module": null }, { "abbrev": false, "full_module": "Steel.Primitive.ForkJoin", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
req: Steel.Effect.Common.vprop -> Steel.Effect.Common.req_t req
Prims.Tot
[ "total" ]
[]
[ "Steel.Effect.Common.vprop", "Steel.Effect.Common.rmem", "Prims.l_True", "Steel.Effect.Common.req_t" ]
[]
false
false
false
false
false
let triv_pre (req: vprop) : req_t req =
fun _ -> True
false
EtM.AE.fst
EtM.AE.get_log
val get_log : h: FStar.Monotonic.HyperStack.mem -> k: EtM.AE.key -> Prims.GTot (FStar.Seq.Base.seq EtM.AE.log_entry)
let get_log (h:mem) (k:key) = sel h k.log
{ "file_name": "examples/crypto/EtM.AE.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 13, "end_line": 59, "start_col": 0, "start_line": 58 }
(* Copyright 2008-2018 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 EtM.AE open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open FStar.HyperStack.ST module MAC = EtM.MAC open Platform.Bytes open CoreCrypto module CPA = EtM.CPA module MAC = EtM.MAC module Ideal = EtM.Ideal module Plain = EtM.Plain (*** Basic types ***) type rid = erid /// An AE cipher includes a mac tag type cipher = (CPA.cipher * MAC.tag) /// An AE log pairs plain texts with MAC'd ciphers let log_entry = Plain.plain * cipher type log_t (r:rid) = m_rref r (seq log_entry) grows /// An AE key pairs an encryption key, ke, with a MAC'ing key, km, /// with an invariant ensuring that their memory footprints of their /// ideal state are disjoint. /// /// Aside from this, we have an AE log, which is a view of the two /// other logs. noeq type key = | Key: #region:rid -> ke:CPA.key { extends (CPA.Key?.region ke) region } -> km:MAC.key { extends (MAC.Key?.region km) region /\ disjoint( CPA.Key?.region ke) (MAC.Key?.region km) } -> log:log_t region -> key (** Accessors for the three logs **)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.Map.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "EtM.Plain.fsti.checked", "EtM.MAC.fst.checked", "EtM.Ideal.fsti.checked", "EtM.CPA.fst.checked", "CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.AE.fst" }
[ { "abbrev": true, "full_module": "EtM.Plain", "short_module": "Plain" }, { "abbrev": true, "full_module": "EtM.Ideal", "short_module": "Ideal" }, { "abbrev": true, "full_module": "EtM.MAC", "short_module": "MAC" }, { "abbrev": true, "full_module": "EtM.CPA", "short_module": "CPA" }, { "abbrev": false, "full_module": "CoreCrypto", "short_module": null }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": true, "full_module": "EtM.MAC", "short_module": "MAC" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> k: EtM.AE.key -> Prims.GTot (FStar.Seq.Base.seq EtM.AE.log_entry)
Prims.GTot
[ "sometrivial" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "EtM.AE.key", "FStar.Monotonic.HyperStack.sel", "FStar.Seq.Base.seq", "EtM.AE.log_entry", "FStar.Monotonic.Seq.grows", "EtM.AE.__proj__Key__item__log" ]
[]
false
false
false
false
false
let get_log (h: mem) (k: key) =
sel h k.log
false
EtM.AE.fst
EtM.AE.get_cpa_log
val get_cpa_log : h: FStar.Monotonic.HyperStack.mem -> k: EtM.AE.key -> Prims.GTot (FStar.Seq.Base.seq EtM.CPA.log_entry)
let get_cpa_log (h:mem) (k:key) = sel h (CPA.Key?.log k.ke)
{ "file_name": "examples/crypto/EtM.AE.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 27, "end_line": 67, "start_col": 0, "start_line": 66 }
(* Copyright 2008-2018 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 EtM.AE open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open FStar.HyperStack.ST module MAC = EtM.MAC open Platform.Bytes open CoreCrypto module CPA = EtM.CPA module MAC = EtM.MAC module Ideal = EtM.Ideal module Plain = EtM.Plain (*** Basic types ***) type rid = erid /// An AE cipher includes a mac tag type cipher = (CPA.cipher * MAC.tag) /// An AE log pairs plain texts with MAC'd ciphers let log_entry = Plain.plain * cipher type log_t (r:rid) = m_rref r (seq log_entry) grows /// An AE key pairs an encryption key, ke, with a MAC'ing key, km, /// with an invariant ensuring that their memory footprints of their /// ideal state are disjoint. /// /// Aside from this, we have an AE log, which is a view of the two /// other logs. noeq type key = | Key: #region:rid -> ke:CPA.key { extends (CPA.Key?.region ke) region } -> km:MAC.key { extends (MAC.Key?.region km) region /\ disjoint( CPA.Key?.region ke) (MAC.Key?.region km) } -> log:log_t region -> key (** Accessors for the three logs **) /// ae log let get_log (h:mem) (k:key) = sel h k.log /// mac log let get_mac_log (h:mem) (k:key) = sel h (MAC.Key?.log k.km)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.Map.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "EtM.Plain.fsti.checked", "EtM.MAC.fst.checked", "EtM.Ideal.fsti.checked", "EtM.CPA.fst.checked", "CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.AE.fst" }
[ { "abbrev": true, "full_module": "EtM.Plain", "short_module": "Plain" }, { "abbrev": true, "full_module": "EtM.Ideal", "short_module": "Ideal" }, { "abbrev": true, "full_module": "EtM.MAC", "short_module": "MAC" }, { "abbrev": true, "full_module": "EtM.CPA", "short_module": "CPA" }, { "abbrev": false, "full_module": "CoreCrypto", "short_module": null }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": true, "full_module": "EtM.MAC", "short_module": "MAC" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> k: EtM.AE.key -> Prims.GTot (FStar.Seq.Base.seq EtM.CPA.log_entry)
Prims.GTot
[ "sometrivial" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "EtM.AE.key", "FStar.Monotonic.HyperStack.sel", "FStar.Seq.Base.seq", "EtM.CPA.log_entry", "FStar.Monotonic.Seq.grows", "EtM.CPA.__proj__Key__item__log", "EtM.AE.__proj__Key__item__ke" ]
[]
false
false
false
false
false
let get_cpa_log (h: mem) (k: key) =
sel h (CPA.Key?.log k.ke)
false
EtM.AE.fst
EtM.AE.get_mac_log
val get_mac_log : h: FStar.Monotonic.HyperStack.mem -> k: EtM.AE.key -> Prims.GTot (FStar.Seq.Base.seq EtM.MAC.log_entry)
let get_mac_log (h:mem) (k:key) = sel h (MAC.Key?.log k.km)
{ "file_name": "examples/crypto/EtM.AE.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 27, "end_line": 63, "start_col": 0, "start_line": 62 }
(* Copyright 2008-2018 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 EtM.AE open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open FStar.HyperStack.ST module MAC = EtM.MAC open Platform.Bytes open CoreCrypto module CPA = EtM.CPA module MAC = EtM.MAC module Ideal = EtM.Ideal module Plain = EtM.Plain (*** Basic types ***) type rid = erid /// An AE cipher includes a mac tag type cipher = (CPA.cipher * MAC.tag) /// An AE log pairs plain texts with MAC'd ciphers let log_entry = Plain.plain * cipher type log_t (r:rid) = m_rref r (seq log_entry) grows /// An AE key pairs an encryption key, ke, with a MAC'ing key, km, /// with an invariant ensuring that their memory footprints of their /// ideal state are disjoint. /// /// Aside from this, we have an AE log, which is a view of the two /// other logs. noeq type key = | Key: #region:rid -> ke:CPA.key { extends (CPA.Key?.region ke) region } -> km:MAC.key { extends (MAC.Key?.region km) region /\ disjoint( CPA.Key?.region ke) (MAC.Key?.region km) } -> log:log_t region -> key (** Accessors for the three logs **) /// ae log let get_log (h:mem) (k:key) = sel h k.log
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.Map.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "EtM.Plain.fsti.checked", "EtM.MAC.fst.checked", "EtM.Ideal.fsti.checked", "EtM.CPA.fst.checked", "CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.AE.fst" }
[ { "abbrev": true, "full_module": "EtM.Plain", "short_module": "Plain" }, { "abbrev": true, "full_module": "EtM.Ideal", "short_module": "Ideal" }, { "abbrev": true, "full_module": "EtM.MAC", "short_module": "MAC" }, { "abbrev": true, "full_module": "EtM.CPA", "short_module": "CPA" }, { "abbrev": false, "full_module": "CoreCrypto", "short_module": null }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": true, "full_module": "EtM.MAC", "short_module": "MAC" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> k: EtM.AE.key -> Prims.GTot (FStar.Seq.Base.seq EtM.MAC.log_entry)
Prims.GTot
[ "sometrivial" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "EtM.AE.key", "FStar.Monotonic.HyperStack.sel", "FStar.Seq.Base.seq", "EtM.MAC.log_entry", "FStar.Monotonic.Seq.grows", "EtM.MAC.__proj__Key__item__log", "EtM.AE.__proj__Key__item__km" ]
[]
false
false
false
false
false
let get_mac_log (h: mem) (k: key) =
sel h (MAC.Key?.log k.km)
false
FStar.Tactics.V2.Derived.fst
FStar.Tactics.V2.Derived.destruct_list
val destruct_list (t: term) : Tac (list term)
val destruct_list (t: term) : Tac (list term)
let rec destruct_list (t : term) : Tac (list term) = let head, args = collect_app t in match inspect head, args with | Tv_FVar fv, [(a1, Q_Explicit); (a2, Q_Explicit)] | Tv_FVar fv, [(_, Q_Implicit); (a1, Q_Explicit); (a2, Q_Explicit)] -> if inspect_fv fv = cons_qn then a1 :: destruct_list a2 else raise NotAListLiteral | Tv_FVar fv, _ -> if inspect_fv fv = nil_qn then [] else raise NotAListLiteral | _ -> raise NotAListLiteral
{ "file_name": "ulib/FStar.Tactics.V2.Derived.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 27, "end_line": 814, "start_col": 0, "start_line": 801 }
(* Copyright 2008-2018 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 FStar.Tactics.V2.Derived open FStar.Reflection.V2 open FStar.Reflection.V2.Formula open FStar.Tactics.Effect open FStar.Stubs.Tactics.Types open FStar.Stubs.Tactics.Result open FStar.Stubs.Tactics.V2.Builtins open FStar.Tactics.Util open FStar.Tactics.V2.SyntaxHelpers open FStar.VConfig open FStar.Tactics.NamedView open FStar.Tactics.V2.SyntaxCoercions module L = FStar.List.Tot.Base module V = FStar.Tactics.Visit private let (@) = L.op_At let name_of_bv (bv : bv) : Tac string = unseal ((inspect_bv bv).ppname) let bv_to_string (bv : bv) : Tac string = (* Could also print type...? *) name_of_bv bv let name_of_binder (b : binder) : Tac string = unseal b.ppname let binder_to_string (b : binder) : Tac string = // TODO: print aqual, attributes..? or no? name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" let binding_to_string (b : binding) : Tac string = unseal b.ppname let type_of_var (x : namedv) : Tac typ = unseal ((inspect_namedv x).sort) let type_of_binding (x : binding) : Tot typ = x.sort exception Goal_not_trivial let goals () : Tac (list goal) = goals_of (get ()) let smt_goals () : Tac (list goal) = smt_goals_of (get ()) let fail (#a:Type) (m:string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = raise #a (TacticFailure m) let fail_silently (#a:Type) (m:string) : TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = set_urgency 0; raise #a (TacticFailure m) (** Return the current *goal*, not its type. (Ignores SMT goals) *) let _cur_goal () : Tac goal = match goals () with | [] -> fail "no more goals" | g::_ -> g (** [cur_env] returns the current goal's environment *) let cur_env () : Tac env = goal_env (_cur_goal ()) (** [cur_goal] returns the current goal's type *) let cur_goal () : Tac typ = goal_type (_cur_goal ()) (** [cur_witness] returns the current goal's witness *) let cur_witness () : Tac term = goal_witness (_cur_goal ()) (** [cur_goal_safe] will always return the current goal, without failing. It must be statically verified that there indeed is a goal in order to call it. *) let cur_goal_safe () : TacH goal (requires (fun ps -> ~(goals_of ps == []))) (ensures (fun ps0 r -> exists g. r == Success g ps0)) = match goals_of (get ()) with | g :: _ -> g let cur_vars () : Tac (list binding) = vars_of_env (cur_env ()) (** Set the guard policy only locally, without affecting calling code *) let with_policy pol (f : unit -> Tac 'a) : Tac 'a = let old_pol = get_guard_policy () in set_guard_policy pol; let r = f () in set_guard_policy old_pol; r (** [exact e] will solve a goal [Gamma |- w : t] if [e] has type exactly [t] in [Gamma]. *) let exact (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true false t) (** [exact_with_ref e] will solve a goal [Gamma |- w : t] if [e] has type [t'] where [t'] is a subtype of [t] in [Gamma]. This is a more flexible variant of [exact]. *) let exact_with_ref (t : term) : Tac unit = with_policy SMT (fun () -> t_exact true true t) let trivial () : Tac unit = norm [iota; zeta; reify_; delta; primops; simplify; unmeta]; let g = cur_goal () in match term_as_formula g with | True_ -> exact (`()) | _ -> raise Goal_not_trivial (* Another hook to just run a tactic without goals, just by reusing `with_tactic` *) let run_tactic (t:unit -> Tac unit) : Pure unit (requires (set_range_of (with_tactic (fun () -> trivial (); t ()) (squash True)) (range_of t))) (ensures (fun _ -> True)) = () (** Ignore the current goal. If left unproven, this will fail after the tactic finishes. *) let dismiss () : Tac unit = match goals () with | [] -> fail "dismiss: no more goals" | _::gs -> set_goals gs (** Flip the order of the first two goals. *) let flip () : Tac unit = let gs = goals () in match goals () with | [] | [_] -> fail "flip: less than two goals" | g1::g2::gs -> set_goals (g2::g1::gs) (** Succeed if there are no more goals left, and fail otherwise. *) let qed () : Tac unit = match goals () with | [] -> () | _ -> fail "qed: not done!" (** [debug str] is similar to [print str], but will only print the message if the [--debug] option was given for the current module AND [--debug_level Tac] is on. *) let debug (m:string) : Tac unit = if debugging () then print m (** [smt] will mark the current goal for being solved through the SMT. This does not immediately run the SMT: it just dumps the goal in the SMT bin. Note, if you dump a proof-relevant goal there, the engine will later raise an error. *) let smt () : Tac unit = match goals (), smt_goals () with | [], _ -> fail "smt: no active goals" | g::gs, gs' -> begin set_goals gs; set_smt_goals (g :: gs') end let idtac () : Tac unit = () (** Push the current goal to the back. *) let later () : Tac unit = match goals () with | g::gs -> set_goals (gs @ [g]) | _ -> fail "later: no goals" (** [apply f] will attempt to produce a solution to the goal by an application of [f] to any amount of arguments (which need to be solved as further goals). The amount of arguments introduced is the least such that [f a_i] unifies with the goal's type. *) let apply (t : term) : Tac unit = t_apply true false false t let apply_noinst (t : term) : Tac unit = t_apply true true false t (** [apply_lemma l] will solve a goal of type [squash phi] when [l] is a Lemma ensuring [phi]. The arguments to [l] and its requires clause are introduced as new goals. As a small optimization, [unit] arguments are discharged by the engine. Just a thin wrapper around [t_apply_lemma]. *) let apply_lemma (t : term) : Tac unit = t_apply_lemma false false t (** See docs for [t_trefl] *) let trefl () : Tac unit = t_trefl false (** See docs for [t_trefl] *) let trefl_guard () : Tac unit = t_trefl true (** See docs for [t_commute_applied_match] *) let commute_applied_match () : Tac unit = t_commute_applied_match () (** Similar to [apply_lemma], but will not instantiate uvars in the goal while applying. *) let apply_lemma_noinst (t : term) : Tac unit = t_apply_lemma true false t let apply_lemma_rw (t : term) : Tac unit = t_apply_lemma false true t (** [apply_raw f] is like [apply], but will ask for all arguments regardless of whether they appear free in further goals. See the explanation in [t_apply]. *) let apply_raw (t : term) : Tac unit = t_apply false false false t (** Like [exact], but allows for the term [e] to have a type [t] only under some guard [g], adding the guard as a goal. *) let exact_guard (t : term) : Tac unit = with_policy Goal (fun () -> t_exact true false t) (** (TODO: explain better) When running [pointwise tau] For every subterm [t'] of the goal's type [t], the engine will build a goal [Gamma |= t' == ?u] and run [tau] on it. When the tactic proves the goal, the engine will rewrite [t'] for [?u] in the original goal type. This is done for every subterm, bottom-up. This allows to recurse over an unknown goal type. By inspecting the goal, the [tau] can then decide what to do (to not do anything, use [trefl]). *) let t_pointwise (d:direction) (tau : unit -> Tac unit) : Tac unit = let ctrl (t:term) : Tac (bool & ctrl_flag) = true, Continue in let rw () : Tac unit = tau () in ctrl_rewrite d ctrl rw (** [topdown_rewrite ctrl rw] is used to rewrite those sub-terms [t] of the goal on which [fst (ctrl t)] returns true. On each such sub-term, [rw] is presented with an equality of goal of the form [Gamma |= t == ?u]. When [rw] proves the goal, the engine will rewrite [t] for [?u] in the original goal type. The goal formula is traversed top-down and the traversal can be controlled by [snd (ctrl t)]: When [snd (ctrl t) = 0], the traversal continues down through the position in the goal term. When [snd (ctrl t) = 1], the traversal continues to the next sub-tree of the goal. When [snd (ctrl t) = 2], no more rewrites are performed in the goal. *) let topdown_rewrite (ctrl : term -> Tac (bool * int)) (rw:unit -> Tac unit) : Tac unit = let ctrl' (t:term) : Tac (bool & ctrl_flag) = let b, i = ctrl t in let f = match i with | 0 -> Continue | 1 -> Skip | 2 -> Abort | _ -> fail "topdown_rewrite: bad value from ctrl" in b, f in ctrl_rewrite TopDown ctrl' rw let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau let cur_module () : Tac name = moduleof (top_env ()) let open_modules () : Tac (list name) = env_open_modules (top_env ()) let fresh_uvar (o : option typ) : Tac term = let e = cur_env () in uvar_env e o let unify (t1 t2 : term) : Tac bool = let e = cur_env () in unify_env e t1 t2 let unify_guard (t1 t2 : term) : Tac bool = let e = cur_env () in unify_guard_env e t1 t2 let tmatch (t1 t2 : term) : Tac bool = let e = cur_env () in match_env e t1 t2 (** [divide n t1 t2] will split the current set of goals into the [n] first ones, and the rest. It then runs [t1] on the first set, and [t2] on the second, returning both results (and concatenating remaining goals). *) let divide (n:int) (l : unit -> Tac 'a) (r : unit -> Tac 'b) : Tac ('a * 'b) = if n < 0 then fail "divide: negative n"; let gs, sgs = goals (), smt_goals () in let gs1, gs2 = List.Tot.Base.splitAt n gs in set_goals gs1; set_smt_goals []; let x = l () in let gsl, sgsl = goals (), smt_goals () in set_goals gs2; set_smt_goals []; let y = r () in let gsr, sgsr = goals (), smt_goals () in set_goals (gsl @ gsr); set_smt_goals (sgs @ sgsl @ sgsr); (x, y) let rec iseq (ts : list (unit -> Tac unit)) : Tac unit = match ts with | t::ts -> let _ = divide 1 t (fun () -> iseq ts) in () | [] -> () (** [focus t] runs [t ()] on the current active goal, hiding all others and restoring them at the end. *) let focus (t : unit -> Tac 'a) : Tac 'a = match goals () with | [] -> fail "focus: no goals" | g::gs -> let sgs = smt_goals () in set_goals [g]; set_smt_goals []; let x = t () in set_goals (goals () @ gs); set_smt_goals (smt_goals () @ sgs); x (** Similar to [dump], but only dumping the current goal. *) let dump1 (m : string) = focus (fun () -> dump m) let rec mapAll (t : unit -> Tac 'a) : Tac (list 'a) = match goals () with | [] -> [] | _::_ -> let (h, t) = divide 1 t (fun () -> mapAll t) in h::t let rec iterAll (t : unit -> Tac unit) : Tac unit = (* Could use mapAll, but why even build that list *) match goals () with | [] -> () | _::_ -> let _ = divide 1 t (fun () -> iterAll t) in () let iterAllSMT (t : unit -> Tac unit) : Tac unit = let gs, sgs = goals (), smt_goals () in set_goals sgs; set_smt_goals []; iterAll t; let gs', sgs' = goals (), smt_goals () in set_goals gs; set_smt_goals (gs'@sgs') (** Runs tactic [t1] on the current goal, and then tactic [t2] on *each* subgoal produced by [t1]. Each invocation of [t2] runs on a proofstate with a single goal (they're "focused"). *) let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit = focus (fun () -> f (); iterAll g) let exact_args (qs : list aqualv) (t : term) : Tac unit = focus (fun () -> let n = List.Tot.Base.length qs in let uvs = repeatn n (fun () -> fresh_uvar None) in let t' = mk_app t (zip uvs qs) in exact t'; iter (fun uv -> if is_uvar uv then unshelve uv else ()) (L.rev uvs) ) let exact_n (n : int) (t : term) : Tac unit = exact_args (repeatn n (fun () -> Q_Explicit)) t (** [ngoals ()] returns the number of goals *) let ngoals () : Tac int = List.Tot.Base.length (goals ()) (** [ngoals_smt ()] returns the number of SMT goals *) let ngoals_smt () : Tac int = List.Tot.Base.length (smt_goals ()) (* sigh GGG fix names!! *) let fresh_namedv_named (s:string) : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n; }) (* Create a fresh bound variable (bv), using a generic name. See also [fresh_namedv_named]. *) let fresh_namedv () : Tac namedv = let n = fresh () in pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n; }) let fresh_binder_named (s : string) (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_binder (t : typ) : Tac simple_binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] ; } let fresh_implicit_binder (t : typ) : Tac binder = let n = fresh () in { ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] ; } let guard (b : bool) : TacH unit (requires (fun _ -> True)) (ensures (fun ps r -> if b then Success? r /\ Success?.ps r == ps else Failed? r)) (* ^ the proofstate on failure is not exactly equal (has the psc set) *) = if not b then fail "guard failed" else () let try_with (f : unit -> Tac 'a) (h : exn -> Tac 'a) : Tac 'a = match catch f with | Inl e -> h e | Inr x -> x let trytac (t : unit -> Tac 'a) : Tac (option 'a) = try Some (t ()) with | _ -> None let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a = try t1 () with | _ -> t2 () val (<|>) : (unit -> Tac 'a) -> (unit -> Tac 'a) -> (unit -> Tac 'a) let (<|>) t1 t2 = fun () -> or_else t1 t2 let first (ts : list (unit -> Tac 'a)) : Tac 'a = L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) = match catch t with | Inl _ -> [] | Inr x -> x :: repeat t let repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) = t () :: repeat t let repeat' (f : unit -> Tac 'a) : Tac unit = let _ = repeat f in () let norm_term (s : list norm_step) (t : term) : Tac term = let e = try cur_env () with | _ -> top_env () in norm_term_env e s t (** Join all of the SMT goals into one. This helps when all of them are expected to be similar, and therefore easier to prove at once by the SMT solver. TODO: would be nice to try to join them in a more meaningful way, as the order can matter. *) let join_all_smt_goals () = let gs, sgs = goals (), smt_goals () in set_smt_goals []; set_goals sgs; repeat' join; let sgs' = goals () in // should be a single one set_goals gs; set_smt_goals sgs' let discard (tau : unit -> Tac 'a) : unit -> Tac unit = fun () -> let _ = tau () in () // TODO: do we want some value out of this? let rec repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit = let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in () let tadmit () = tadmit_t (`()) let admit1 () : Tac unit = tadmit () let admit_all () : Tac unit = let _ = repeat tadmit in () (** [is_guard] returns whether the current goal arose from a typechecking guard *) let is_guard () : Tac bool = Stubs.Tactics.Types.is_guard (_cur_goal ()) let skip_guard () : Tac unit = if is_guard () then smt () else fail "" let guards_to_smt () : Tac unit = let _ = repeat skip_guard in () let simpl () : Tac unit = norm [simplify; primops] let whnf () : Tac unit = norm [weak; hnf; primops; delta] let compute () : Tac unit = norm [primops; iota; delta; zeta] let intros () : Tac (list binding) = repeat intro let intros' () : Tac unit = let _ = intros () in () let destruct tm : Tac unit = let _ = t_destruct tm in () let destruct_intros tm : Tac unit = seq (fun () -> let _ = t_destruct tm in ()) intros' private val __cut : (a:Type) -> (b:Type) -> (a -> b) -> a -> b private let __cut a b f x = f x let tcut (t:term) : Tac binding = let g = cur_goal () in let tt = mk_e_app (`__cut) [t; g] in apply tt; intro () let pose (t:term) : Tac binding = apply (`__cut); flip (); exact t; intro () let intro_as (s:string) : Tac binding = let b = intro () in rename_to b s let pose_as (s:string) (t:term) : Tac binding = let b = pose t in rename_to b s let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) = map f (cur_vars ()) let rec revert_all (bs:list binding) : Tac unit = match bs with | [] -> () | _::tl -> revert (); revert_all tl let binder_sort (b : binder) : Tot typ = b.sort // Cannot define this inside `assumption` due to #1091 private let rec __assumption_aux (xs : list binding) : Tac unit = match xs with | [] -> fail "no assumption matches goal" | b::bs -> try exact b with | _ -> try (apply (`FStar.Squash.return_squash); exact b) with | _ -> __assumption_aux bs let assumption () : Tac unit = __assumption_aux (cur_vars ()) let destruct_equality_implication (t:term) : Tac (option (formula * term)) = match term_as_formula t with | Implies lhs rhs -> let lhs = term_as_formula' lhs in begin match lhs with | Comp (Eq _) _ _ -> Some (lhs, rhs) | _ -> None end | _ -> None private let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) = FStar.PropositionalExtensionality.apply (a==b) (b==a) (** Like [rewrite], but works with equalities [v == e] and [e == v] *) let rewrite' (x:binding) : Tac unit = ((fun () -> rewrite x) <|> (fun () -> var_retype x; apply_lemma (`__eq_sym); rewrite x) <|> (fun () -> fail "rewrite' failed")) () let rec try_rewrite_equality (x:term) (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin match term_as_formula (type_of_binding x_t) with | Comp (Eq _) y _ -> if term_eq x y then rewrite x_t else try_rewrite_equality x bs | _ -> try_rewrite_equality x bs end let rec rewrite_all_context_equalities (bs:list binding) : Tac unit = match bs with | [] -> () | x_t::bs -> begin (try rewrite x_t with | _ -> ()); rewrite_all_context_equalities bs end let rewrite_eqs_from_context () : Tac unit = rewrite_all_context_equalities (cur_vars ()) let rewrite_equality (t:term) : Tac unit = try_rewrite_equality t (cur_vars ()) let unfold_def (t:term) : Tac unit = match inspect t with | Tv_FVar fv -> let n = implode_qn (inspect_fv fv) in norm [delta_fully [n]] | _ -> fail "unfold_def: term is not a fv" (** Rewrites left-to-right, and bottom-up, given a set of lemmas stating equalities. The lemmas need to prove *propositional* equalities, that is, using [==]. *) let l_to_r (lems:list term) : Tac unit = let first_or_trefl () : Tac unit = fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems () in pointwise first_or_trefl let mk_squash (t : term) : Tot term = let sq : term = pack (Tv_FVar (pack_fv squash_qn)) in mk_e_app sq [t] let mk_sq_eq (t1 t2 : term) : Tot term = let eq : term = pack (Tv_FVar (pack_fv eq2_qn)) in mk_squash (mk_e_app eq [t1; t2]) (** Rewrites all appearances of a term [t1] in the goal into [t2]. Creates a new goal for [t1 == t2]. *) let grewrite (t1 t2 : term) : Tac unit = let e = tcut (mk_sq_eq t1 t2) in let e = pack (Tv_Var e) in pointwise (fun () -> (* If the LHS is a uvar, do nothing, so we do not instantiate it. *) let is_uvar = match term_as_formula (cur_goal()) with | Comp (Eq _) lhs rhs -> (match inspect lhs with | Tv_Uvar _ _ -> true | _ -> false) | _ -> false in if is_uvar then trefl () else try exact e with | _ -> trefl ()) private let __un_sq_eq (#a:Type) (x y : a) (_ : (x == y)) : Lemma (x == y) = () (** A wrapper to [grewrite] which takes a binder of an equality type *) let grewrite_eq (b:binding) : Tac unit = match term_as_formula (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> exact b)] | _ -> begin match term_as_formula' (type_of_binding b) with | Comp (Eq _) l r -> grewrite l r; iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq); exact b)] | _ -> fail "grewrite_eq: binder type is not an equality" end private let admit_dump_t () : Tac unit = dump "Admitting"; apply (`admit) val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a let admit_dump #a #x () = x () private let magic_dump_t () : Tac unit = dump "Admitting"; apply (`magic); exact (`()); () val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a let magic_dump #a #x () = x let change_with t1 t2 : Tac unit = focus (fun () -> grewrite t1 t2; iseq [idtac; trivial] ) let change_sq (t1 : term) : Tac unit = change (mk_e_app (`squash) [t1]) let finish_by (t : unit -> Tac 'a) : Tac 'a = let x = t () in or_else qed (fun () -> fail "finish_by: not finished"); x let solve_then #a #b (t1 : unit -> Tac a) (t2 : a -> Tac b) : Tac b = dup (); let x = focus (fun () -> finish_by t1) in let y = t2 x in trefl (); y let add_elem (t : unit -> Tac 'a) : Tac 'a = focus (fun () -> apply (`Cons); focus (fun () -> let x = t () in qed (); x ) ) (* * Specialize a function by partially evaluating it * For example: * let rec foo (l:list int) (x:int) :St int = match l with | [] -> x | hd::tl -> x + foo tl x let f :int -> St int = synth_by_tactic (specialize (foo [1; 2]) [%`foo]) * would make the definition of f as x + x + x * * f is the term that needs to be specialized * l is the list of names to be delta-ed *) let specialize (#a:Type) (f:a) (l:list string) :unit -> Tac unit = fun () -> solve_then (fun () -> exact (quote f)) (fun () -> norm [delta_only l; iota; zeta]) let tlabel (l:string) = match goals () with | [] -> fail "tlabel: no goals" | h::t -> set_goals (set_label l h :: t) let tlabel' (l:string) = match goals () with | [] -> fail "tlabel': no goals" | h::t -> let h = set_label (l ^ get_label h) h in set_goals (h :: t) let focus_all () : Tac unit = set_goals (goals () @ smt_goals ()); set_smt_goals [] private let rec extract_nth (n:nat) (l : list 'a) : option ('a * list 'a) = match n, l with | _, [] -> None | 0, hd::tl -> Some (hd, tl) | _, hd::tl -> begin match extract_nth (n-1) tl with | Some (hd', tl') -> Some (hd', hd::tl') | None -> None end let bump_nth (n:pos) : Tac unit = // n-1 since goal numbering begins at 1 match extract_nth (n - 1) (goals ()) with | None -> fail "bump_nth: not that many goals" | Some (h, t) -> set_goals (h :: t)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.VConfig.fsti.checked", "FStar.Tactics.Visit.fst.checked", "FStar.Tactics.V2.SyntaxHelpers.fst.checked", "FStar.Tactics.V2.SyntaxCoercions.fst.checked", "FStar.Tactics.Util.fst.checked", "FStar.Tactics.NamedView.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Stubs.Tactics.V2.Builtins.fsti.checked", "FStar.Stubs.Tactics.Types.fsti.checked", "FStar.Stubs.Tactics.Result.fsti.checked", "FStar.Squash.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Range.fsti.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.Tactics.V2.Derived.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.Visit", "short_module": "V" }, { "abbrev": true, "full_module": "FStar.List.Tot.Base", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxCoercions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.NamedView", "short_module": null }, { "abbrev": false, "full_module": "FStar.VConfig", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2.SyntaxHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.V2.Builtins", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Result", "short_module": null }, { "abbrev": false, "full_module": "FStar.Stubs.Tactics.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac (Prims.list FStar.Tactics.NamedView.term)
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Tactics.NamedView.term", "Prims.list", "FStar.Stubs.Reflection.V2.Data.argv", "FStar.Stubs.Reflection.Types.fv", "FStar.Stubs.Reflection.Types.term", "Prims.op_Equality", "Prims.string", "FStar.Stubs.Reflection.V2.Builtins.inspect_fv", "FStar.Reflection.Const.cons_qn", "Prims.Cons", "FStar.Tactics.V2.Derived.destruct_list", "Prims.bool", "FStar.Tactics.Effect.raise", "FStar.Stubs.Tactics.Common.NotAListLiteral", "FStar.Pervasives.Native.tuple2", "FStar.Stubs.Reflection.V2.Data.aqualv", "FStar.Reflection.Const.nil_qn", "Prims.Nil", "FStar.Tactics.NamedView.named_term_view", "FStar.Pervasives.Native.Mktuple2", "FStar.Tactics.NamedView.inspect", "FStar.Tactics.V2.SyntaxHelpers.collect_app" ]
[ "recursion" ]
false
true
false
false
false
let rec destruct_list (t: term) : Tac (list term) =
let head, args = collect_app t in match inspect head, args with | Tv_FVar fv, [a1, Q_Explicit ; a2, Q_Explicit] | Tv_FVar fv, [_, Q_Implicit ; a1, Q_Explicit ; a2, Q_Explicit] -> if inspect_fv fv = cons_qn then a1 :: destruct_list a2 else raise NotAListLiteral | Tv_FVar fv, _ -> if inspect_fv fv = nil_qn then [] else raise NotAListLiteral | _ -> raise NotAListLiteral
false
Vale.X64.Stack_Sems.fst
Vale.X64.Stack_Sems.free_stack_same_load
val free_stack_same_load (start:int) (finish:int) (ptr:int) (h:S.machine_stack) : Lemma (requires S.valid_src_stack64 ptr h /\ (ptr >= finish \/ ptr + 8 <= start)) (ensures S.eval_stack ptr h == S.eval_stack ptr (S.free_stack' start finish h)) [SMTPat (S.eval_stack ptr (S.free_stack' start finish h))]
val free_stack_same_load (start:int) (finish:int) (ptr:int) (h:S.machine_stack) : Lemma (requires S.valid_src_stack64 ptr h /\ (ptr >= finish \/ ptr + 8 <= start)) (ensures S.eval_stack ptr h == S.eval_stack ptr (S.free_stack' start finish h)) [SMTPat (S.eval_stack ptr (S.free_stack' start finish h))]
let free_stack_same_load start finish ptr h = reveal_opaque (`%S.valid_addr64) S.valid_addr64; let S.Machine_stack _ mem = h in let S.Machine_stack _ mem' = S.free_stack' start finish h in Classical.forall_intro (Vale.Lib.Set.remove_between_reveal (Map.domain mem) start finish); S.get_heap_val64_reveal ()
{ "file_name": "vale/code/arch/x64/Vale.X64.Stack_Sems.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 21, "start_col": 0, "start_line": 16 }
module Vale.X64.Stack_Sems open FStar.Mul friend Vale.X64.Stack_i let stack_to_s s = s let stack_from_s s = s let lemma_stack_from_to s = () let lemma_stack_to_from s = () let equiv_valid_src_stack64 ptr h = () let equiv_load_stack64 ptr h = ()
{ "checked_file": "/", "dependencies": [ "Vale.X64.Stack_i.fst.checked", "Vale.Lib.Set.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Map.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Stack_Sems.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
start: Prims.int -> finish: Prims.int -> ptr: Prims.int -> h: Vale.X64.Machine_Semantics_s.machine_stack -> FStar.Pervasives.Lemma (requires Vale.X64.Machine_Semantics_s.valid_src_stack64 ptr h /\ (ptr >= finish \/ ptr + 8 <= start)) (ensures Vale.X64.Machine_Semantics_s.eval_stack ptr h == Vale.X64.Machine_Semantics_s.eval_stack ptr (Vale.X64.Machine_Semantics_s.free_stack' start finish h)) [ SMTPat (Vale.X64.Machine_Semantics_s.eval_stack ptr (Vale.X64.Machine_Semantics_s.free_stack' start finish h)) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.int", "Vale.X64.Machine_Semantics_s.machine_stack", "Vale.Def.Types_s.nat64", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Map.t", "Vale.Def.Types_s.nat8", "Vale.Arch.MachineHeap_s.get_heap_val64_reveal", "Prims.unit", "FStar.Classical.forall_intro", "Prims.l_and", "Prims.l_imp", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "Prims.op_Negation", "FStar.Set.mem", "Vale.Lib.Set.remove_between", "FStar.Map.domain", "Prims.l_or", "Prims.op_Equality", "Prims.bool", "Vale.Lib.Set.remove_between_reveal", "Vale.X64.Machine_Semantics_s.free_stack'", "FStar.Pervasives.reveal_opaque", "Vale.Arch.MachineHeap_s.machine_heap", "Vale.Arch.MachineHeap_s.valid_addr64" ]
[]
false
false
true
false
false
let free_stack_same_load start finish ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64; let S.Machine_stack _ mem = h in let S.Machine_stack _ mem' = S.free_stack' start finish h in Classical.forall_intro (Vale.Lib.Set.remove_between_reveal (Map.domain mem) start finish); S.get_heap_val64_reveal ()
false
EtM.AE.fst
EtM.AE.mac_and_cpa_refine_ae_entry
val mac_and_cpa_refine_ae_entry : ae: EtM.AE.log_entry -> mac: EtM.MAC.log_entry -> cpa: EtM.CPA.log_entry -> Prims.logical
let mac_and_cpa_refine_ae_entry (ae:log_entry) (mac:EtM.MAC.log_entry) (cpa:EtM.CPA.log_entry) = let p, c = ae in mac == c /\ CPA.Entry p (fst c) == cpa
{ "file_name": "examples/crypto/EtM.AE.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 138, "start_col": 0, "start_line": 133 }
(* Copyright 2008-2018 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 EtM.AE open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open FStar.HyperStack.ST module MAC = EtM.MAC open Platform.Bytes open CoreCrypto module CPA = EtM.CPA module MAC = EtM.MAC module Ideal = EtM.Ideal module Plain = EtM.Plain (*** Basic types ***) type rid = erid /// An AE cipher includes a mac tag type cipher = (CPA.cipher * MAC.tag) /// An AE log pairs plain texts with MAC'd ciphers let log_entry = Plain.plain * cipher type log_t (r:rid) = m_rref r (seq log_entry) grows /// An AE key pairs an encryption key, ke, with a MAC'ing key, km, /// with an invariant ensuring that their memory footprints of their /// ideal state are disjoint. /// /// Aside from this, we have an AE log, which is a view of the two /// other logs. noeq type key = | Key: #region:rid -> ke:CPA.key { extends (CPA.Key?.region ke) region } -> km:MAC.key { extends (MAC.Key?.region km) region /\ disjoint( CPA.Key?.region ke) (MAC.Key?.region km) } -> log:log_t region -> key (** Accessors for the three logs **) /// ae log let get_log (h:mem) (k:key) = sel h k.log /// mac log let get_mac_log (h:mem) (k:key) = sel h (MAC.Key?.log k.km) /// cpa log let get_cpa_log (h:mem) (k:key) = sel h (CPA.Key?.log k.ke) (*** Main invariant on the ideal state ***) (** There are three components to this invariant 1. The CPA invariant (pairwise distinctness of IVs, notably) 2. mac_only_cpa_ciphers: The MAC log and CPA logs are related, in that the MAC log only contains entries for valid ciphers recorded the CPA log 3. mac_and_cpa_refine_ae: The AE log is a combined view of the MAC and CPA logs Each of its entries corresponds is combination of a single entry in the MAC log and another in the CPA log **) let mac_cpa_related (mac:EtM.MAC.log_entry) (cpa:EtM.CPA.log_entry) = CPA.Entry?.c cpa == fst mac /// See the comment above, for part 2 of the invariant /// -- As in EtM.CPA, we state the invariant recursively /// matching entries up pointwise let rec mac_only_cpa_ciphers (macs:Seq.seq EtM.MAC.log_entry) (cpas:Seq.seq EtM.CPA.log_entry) : Tot Type0 (decreases (Seq.length macs)) = Seq.length macs == Seq.length cpas /\ (if Seq.length macs > 0 then let macs, mac = Seq.un_snoc macs in let cpas, cpa = Seq.un_snoc cpas in mac_cpa_related mac cpa /\ mac_only_cpa_ciphers macs cpas else True) /// A lemma to intro/elim the recursive predicate above let mac_only_cpa_ciphers_snoc (macs:Seq.seq EtM.MAC.log_entry) (mac:EtM.MAC.log_entry) (cpas:Seq.seq EtM.CPA.log_entry) (cpa:EtM.CPA.log_entry) : Lemma (mac_only_cpa_ciphers (snoc macs mac) (snoc cpas cpa) <==> (mac_only_cpa_ciphers macs cpas /\ mac_cpa_related mac cpa)) = un_snoc_snoc macs mac; un_snoc_snoc cpas cpa /// A lemma that shows that if an cipher is MAC'd /// then a corresponding entry must exists in the CPA log let rec mac_only_cpa_ciphers_mem (macs:Seq.seq EtM.MAC.log_entry) (cpas:Seq.seq EtM.CPA.log_entry) (c:cipher) : Lemma (requires (mac_only_cpa_ciphers macs cpas /\ Seq.mem c macs)) (ensures (exists p. Seq.mem (CPA.Entry p (fst c)) cpas)) (decreases (Seq.length macs)) = if Seq.length macs = 0 then () else let macs, mac = un_snoc macs in let cpas, cpa = un_snoc cpas in Seq.lemma_mem_snoc macs mac; Seq.lemma_mem_snoc cpas cpa; if mac = c then () else mac_only_cpa_ciphers_mem macs cpas c /// See part 3 of the invariant: /// -- An AE entry is related to a MAC and CPA entry /// if its plain text + cipher appears in the CPA entry
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.Map.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "EtM.Plain.fsti.checked", "EtM.MAC.fst.checked", "EtM.Ideal.fsti.checked", "EtM.CPA.fst.checked", "CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.AE.fst" }
[ { "abbrev": true, "full_module": "EtM.Plain", "short_module": "Plain" }, { "abbrev": true, "full_module": "EtM.Ideal", "short_module": "Ideal" }, { "abbrev": true, "full_module": "EtM.MAC", "short_module": "MAC" }, { "abbrev": true, "full_module": "EtM.CPA", "short_module": "CPA" }, { "abbrev": false, "full_module": "CoreCrypto", "short_module": null }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": true, "full_module": "EtM.MAC", "short_module": "MAC" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ae: EtM.AE.log_entry -> mac: EtM.MAC.log_entry -> cpa: EtM.CPA.log_entry -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "EtM.AE.log_entry", "EtM.MAC.log_entry", "EtM.CPA.log_entry", "EtM.Plain.plain", "EtM.AE.cipher", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.tuple2", "EtM.MAC.msg", "EtM.MAC.tag", "EtM.CPA.Entry", "FStar.Pervasives.Native.fst", "EtM.CPA.cipher", "Prims.logical" ]
[]
false
false
false
true
true
let mac_and_cpa_refine_ae_entry (ae: log_entry) (mac: EtM.MAC.log_entry) (cpa: EtM.CPA.log_entry) =
let p, c = ae in mac == c /\ CPA.Entry p (fst c) == cpa
false
EtM.AE.fst
EtM.AE.invariant
val invariant : h: FStar.Monotonic.HyperStack.mem -> k: EtM.AE.key -> Prims.GTot Prims.logical
let invariant (h:mem) (k:key) = let log = get_log h k in let mac_log = get_mac_log h k in let cpa_log = get_cpa_log h k in Map.contains (get_hmap h) k.region /\ Map.contains (get_hmap h) (MAC.Key?.region k.km) /\ Map.contains (get_hmap h) (CPA.Key?.region k.ke) /\ EtM.CPA.invariant (Key?.ke k) h /\ mac_only_cpa_ciphers (get_mac_log h k) (get_cpa_log h k) /\ mac_and_cpa_refine_ae (get_log h k) (get_mac_log h k) (get_cpa_log h k)
{ "file_name": "examples/crypto/EtM.AE.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 73, "end_line": 184, "start_col": 0, "start_line": 175 }
(* Copyright 2008-2018 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 EtM.AE open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open FStar.HyperStack.ST module MAC = EtM.MAC open Platform.Bytes open CoreCrypto module CPA = EtM.CPA module MAC = EtM.MAC module Ideal = EtM.Ideal module Plain = EtM.Plain (*** Basic types ***) type rid = erid /// An AE cipher includes a mac tag type cipher = (CPA.cipher * MAC.tag) /// An AE log pairs plain texts with MAC'd ciphers let log_entry = Plain.plain * cipher type log_t (r:rid) = m_rref r (seq log_entry) grows /// An AE key pairs an encryption key, ke, with a MAC'ing key, km, /// with an invariant ensuring that their memory footprints of their /// ideal state are disjoint. /// /// Aside from this, we have an AE log, which is a view of the two /// other logs. noeq type key = | Key: #region:rid -> ke:CPA.key { extends (CPA.Key?.region ke) region } -> km:MAC.key { extends (MAC.Key?.region km) region /\ disjoint( CPA.Key?.region ke) (MAC.Key?.region km) } -> log:log_t region -> key (** Accessors for the three logs **) /// ae log let get_log (h:mem) (k:key) = sel h k.log /// mac log let get_mac_log (h:mem) (k:key) = sel h (MAC.Key?.log k.km) /// cpa log let get_cpa_log (h:mem) (k:key) = sel h (CPA.Key?.log k.ke) (*** Main invariant on the ideal state ***) (** There are three components to this invariant 1. The CPA invariant (pairwise distinctness of IVs, notably) 2. mac_only_cpa_ciphers: The MAC log and CPA logs are related, in that the MAC log only contains entries for valid ciphers recorded the CPA log 3. mac_and_cpa_refine_ae: The AE log is a combined view of the MAC and CPA logs Each of its entries corresponds is combination of a single entry in the MAC log and another in the CPA log **) let mac_cpa_related (mac:EtM.MAC.log_entry) (cpa:EtM.CPA.log_entry) = CPA.Entry?.c cpa == fst mac /// See the comment above, for part 2 of the invariant /// -- As in EtM.CPA, we state the invariant recursively /// matching entries up pointwise let rec mac_only_cpa_ciphers (macs:Seq.seq EtM.MAC.log_entry) (cpas:Seq.seq EtM.CPA.log_entry) : Tot Type0 (decreases (Seq.length macs)) = Seq.length macs == Seq.length cpas /\ (if Seq.length macs > 0 then let macs, mac = Seq.un_snoc macs in let cpas, cpa = Seq.un_snoc cpas in mac_cpa_related mac cpa /\ mac_only_cpa_ciphers macs cpas else True) /// A lemma to intro/elim the recursive predicate above let mac_only_cpa_ciphers_snoc (macs:Seq.seq EtM.MAC.log_entry) (mac:EtM.MAC.log_entry) (cpas:Seq.seq EtM.CPA.log_entry) (cpa:EtM.CPA.log_entry) : Lemma (mac_only_cpa_ciphers (snoc macs mac) (snoc cpas cpa) <==> (mac_only_cpa_ciphers macs cpas /\ mac_cpa_related mac cpa)) = un_snoc_snoc macs mac; un_snoc_snoc cpas cpa /// A lemma that shows that if an cipher is MAC'd /// then a corresponding entry must exists in the CPA log let rec mac_only_cpa_ciphers_mem (macs:Seq.seq EtM.MAC.log_entry) (cpas:Seq.seq EtM.CPA.log_entry) (c:cipher) : Lemma (requires (mac_only_cpa_ciphers macs cpas /\ Seq.mem c macs)) (ensures (exists p. Seq.mem (CPA.Entry p (fst c)) cpas)) (decreases (Seq.length macs)) = if Seq.length macs = 0 then () else let macs, mac = un_snoc macs in let cpas, cpa = un_snoc cpas in Seq.lemma_mem_snoc macs mac; Seq.lemma_mem_snoc cpas cpa; if mac = c then () else mac_only_cpa_ciphers_mem macs cpas c /// See part 3 of the invariant: /// -- An AE entry is related to a MAC and CPA entry /// if its plain text + cipher appears in the CPA entry /// and its cipher+tag appear in the MAC table let mac_and_cpa_refine_ae_entry (ae:log_entry) (mac:EtM.MAC.log_entry) (cpa:EtM.CPA.log_entry) = let p, c = ae in mac == c /\ CPA.Entry p (fst c) == cpa /// See part 3 of the invariant: /// -- A pointwise lifting the relation between the entries in the three logs let rec mac_and_cpa_refine_ae (ae_entries:Seq.seq log_entry) (mac_entries:Seq.seq EtM.MAC.log_entry) (cpa_entries:Seq.seq EtM.CPA.log_entry) : Tot Type0 (decreases (Seq.length ae_entries)) = Seq.length ae_entries == Seq.length mac_entries /\ Seq.length mac_entries == Seq.length cpa_entries /\ (if Seq.length ae_entries <> 0 then let ae_prefix, ae_last = Seq.un_snoc ae_entries in let mac_prefix, mac_last = Seq.un_snoc mac_entries in let cpa_prefix, cpa_last = Seq.un_snoc cpa_entries in mac_and_cpa_refine_ae_entry ae_last mac_last cpa_last /\ mac_and_cpa_refine_ae ae_prefix mac_prefix cpa_prefix else True) /// A lemma to intro/elim the recursive predicate above let mac_and_cpa_refine_ae_snoc (ae_entries:Seq.seq log_entry) (mac_entries:Seq.seq EtM.MAC.log_entry) (cpa_entries:Seq.seq EtM.CPA.log_entry) (ae:log_entry) (mac:EtM.MAC.log_entry) (cpa:EtM.CPA.log_entry) : Lemma (mac_and_cpa_refine_ae (snoc ae_entries ae) (snoc mac_entries mac) (snoc cpa_entries cpa) <==> (mac_and_cpa_refine_ae ae_entries mac_entries cpa_entries /\ mac_and_cpa_refine_ae_entry ae mac cpa)) = Seq.un_snoc_snoc ae_entries ae; Seq.un_snoc_snoc mac_entries mac; Seq.un_snoc_snoc cpa_entries cpa /// The main invariant: /// -- A conjunction of the 3 components already mentioned
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.Map.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "EtM.Plain.fsti.checked", "EtM.MAC.fst.checked", "EtM.Ideal.fsti.checked", "EtM.CPA.fst.checked", "CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.AE.fst" }
[ { "abbrev": true, "full_module": "EtM.Plain", "short_module": "Plain" }, { "abbrev": true, "full_module": "EtM.Ideal", "short_module": "Ideal" }, { "abbrev": true, "full_module": "EtM.MAC", "short_module": "MAC" }, { "abbrev": true, "full_module": "EtM.CPA", "short_module": "CPA" }, { "abbrev": false, "full_module": "CoreCrypto", "short_module": null }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": true, "full_module": "EtM.MAC", "short_module": "MAC" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> k: EtM.AE.key -> Prims.GTot Prims.logical
Prims.GTot
[ "sometrivial" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "EtM.AE.key", "Prims.l_and", "Prims.b2t", "FStar.Map.contains", "FStar.Monotonic.HyperHeap.rid", "FStar.Monotonic.Heap.heap", "FStar.Monotonic.HyperStack.get_hmap", "EtM.AE.__proj__Key__item__region", "EtM.MAC.__proj__Key__item__region", "EtM.AE.__proj__Key__item__km", "EtM.CPA.__proj__Key__item__region", "EtM.AE.__proj__Key__item__ke", "EtM.CPA.invariant", "EtM.AE.mac_only_cpa_ciphers", "EtM.AE.get_mac_log", "EtM.AE.get_cpa_log", "EtM.AE.mac_and_cpa_refine_ae", "EtM.AE.get_log", "FStar.Seq.Base.seq", "EtM.CPA.log_entry", "EtM.MAC.log_entry", "EtM.AE.log_entry", "Prims.logical" ]
[]
false
false
false
false
true
let invariant (h: mem) (k: key) =
let log = get_log h k in let mac_log = get_mac_log h k in let cpa_log = get_cpa_log h k in Map.contains (get_hmap h) k.region /\ Map.contains (get_hmap h) (MAC.Key?.region k.km) /\ Map.contains (get_hmap h) (CPA.Key?.region k.ke) /\ EtM.CPA.invariant (Key?.ke k) h /\ mac_only_cpa_ciphers (get_mac_log h k) (get_cpa_log h k) /\ mac_and_cpa_refine_ae (get_log h k) (get_mac_log h k) (get_cpa_log h k)
false
Vale.X64.Stack_Sems.fst
Vale.X64.Stack_Sems.free_stack_same_load128
val free_stack_same_load128 (start:int) (finish:int) (ptr:int) (h:S.machine_stack) : Lemma (requires S.valid_src_stack128 ptr h /\ (ptr >= finish \/ ptr + 16 <= start)) (ensures S.eval_stack128 ptr h == S.eval_stack128 ptr (S.free_stack' start finish h)) [SMTPat (S.eval_stack128 ptr (S.free_stack' start finish h))]
val free_stack_same_load128 (start:int) (finish:int) (ptr:int) (h:S.machine_stack) : Lemma (requires S.valid_src_stack128 ptr h /\ (ptr >= finish \/ ptr + 16 <= start)) (ensures S.eval_stack128 ptr h == S.eval_stack128 ptr (S.free_stack' start finish h)) [SMTPat (S.eval_stack128 ptr (S.free_stack' start finish h))]
let free_stack_same_load128 start finish ptr h = reveal_opaque (`%S.valid_addr128) S.valid_addr128; let S.Machine_stack _ mem = h in let S.Machine_stack _ mem' = S.free_stack' start finish h in Classical.forall_intro (Vale.Lib.Set.remove_between_reveal (Map.domain mem) start finish); S.get_heap_val128_reveal (); S.get_heap_val32_reveal ()
{ "file_name": "vale/code/arch/x64/Vale.X64.Stack_Sems.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 41, "start_col": 0, "start_line": 35 }
module Vale.X64.Stack_Sems open FStar.Mul friend Vale.X64.Stack_i let stack_to_s s = s let stack_from_s s = s let lemma_stack_from_to s = () let lemma_stack_to_from s = () let equiv_valid_src_stack64 ptr h = () let equiv_load_stack64 ptr h = () let free_stack_same_load start finish ptr h = reveal_opaque (`%S.valid_addr64) S.valid_addr64; let S.Machine_stack _ mem = h in let S.Machine_stack _ mem' = S.free_stack' start finish h in Classical.forall_intro (Vale.Lib.Set.remove_between_reveal (Map.domain mem) start finish); S.get_heap_val64_reveal () let equiv_store_stack64 ptr v h = () let store64_same_init_rsp ptr v h = () let equiv_init_rsp h = () let equiv_free_stack start finish h = () let equiv_valid_src_stack128 ptr h = () let equiv_load_stack128 ptr h = ()
{ "checked_file": "/", "dependencies": [ "Vale.X64.Stack_i.fst.checked", "Vale.Lib.Set.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Map.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.X64.Stack_Sems.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "S" }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
start: Prims.int -> finish: Prims.int -> ptr: Prims.int -> h: Vale.X64.Machine_Semantics_s.machine_stack -> FStar.Pervasives.Lemma (requires Vale.X64.Machine_Semantics_s.valid_src_stack128 ptr h /\ (ptr >= finish \/ ptr + 16 <= start)) (ensures Vale.X64.Machine_Semantics_s.eval_stack128 ptr h == Vale.X64.Machine_Semantics_s.eval_stack128 ptr (Vale.X64.Machine_Semantics_s.free_stack' start finish h)) [ SMTPat (Vale.X64.Machine_Semantics_s.eval_stack128 ptr (Vale.X64.Machine_Semantics_s.free_stack' start finish h)) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.int", "Vale.X64.Machine_Semantics_s.machine_stack", "Vale.Def.Types_s.nat64", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Map.t", "Vale.Def.Types_s.nat8", "Vale.Arch.MachineHeap_s.get_heap_val32_reveal", "Prims.unit", "Vale.Arch.MachineHeap_s.get_heap_val128_reveal", "FStar.Classical.forall_intro", "Prims.l_and", "Prims.l_imp", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "Prims.op_Negation", "FStar.Set.mem", "Vale.Lib.Set.remove_between", "FStar.Map.domain", "Prims.l_or", "Prims.op_Equality", "Prims.bool", "Vale.Lib.Set.remove_between_reveal", "Vale.X64.Machine_Semantics_s.free_stack'", "FStar.Pervasives.reveal_opaque", "Vale.Arch.MachineHeap_s.machine_heap", "Vale.Arch.MachineHeap_s.valid_addr128" ]
[]
false
false
true
false
false
let free_stack_same_load128 start finish ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128; let S.Machine_stack _ mem = h in let S.Machine_stack _ mem' = S.free_stack' start finish h in Classical.forall_intro (Vale.Lib.Set.remove_between_reveal (Map.domain mem) start finish); S.get_heap_val128_reveal (); S.get_heap_val32_reveal ()
false
ID3.fst
ID3.bind_wp
val bind_wp (#a #b: _) (wp_v: w a) (wp_f: (a -> w b)) : w b
val bind_wp (#a #b: _) (wp_v: w a) (wp_f: (a -> w b)) : w b
let bind_wp #a #b (wp_v:w a) (wp_f:a -> w b) : w b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wp_v (fun x -> wp_f x p))
{ "file_name": "examples/layeredeffects/ID3.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 48, "end_line": 25, "start_col": 0, "start_line": 23 }
module ID3 // The base type of WPs val w0 (a : Type u#a) : Type u#(max 1 a) let w0 a = (a -> Type0) -> Type0 // We require monotonicity of them let monotonic (w:w0 'a) = forall p1 p2. (forall x. p1 x ==> p2 x) ==> w p1 ==> w p2 val w (a : Type u#a) : Type u#(max 1 a) let w a = pure_wp a let repr (a : Type) (wp : w a) : Type = v:a{forall p. wp p ==> p v} open FStar.Monotonic.Pure let return (a : Type) (x : a) : repr a (as_pure_wp (fun p -> p x)) = x
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "ID3.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
wp_v: ID3.w a -> wp_f: (_: a -> ID3.w b) -> ID3.w b
Prims.Tot
[ "total" ]
[]
[ "ID3.w", "FStar.Monotonic.Pure.as_pure_wp", "Prims.pure_post", "Prims.l_True", "Prims.pure_pre", "Prims.unit", "FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall" ]
[]
false
false
false
true
false
let bind_wp #a #b (wp_v: w a) (wp_f: (a -> w b)) : w b =
elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wp_v (fun x -> wp_f x p))
false
ID3.fst
ID3.bind
val bind (a b: Type) (wp_v: w a) (wp_f: (a -> w b)) (v: repr a wp_v) (f: (x: a -> repr b (wp_f x))) : repr b (bind_wp wp_v wp_f)
val bind (a b: Type) (wp_v: w a) (wp_f: (a -> w b)) (v: repr a wp_v) (f: (x: a -> repr b (wp_f x))) : repr b (bind_wp wp_v wp_f)
let bind (a b : Type) (wp_v : w a) (wp_f: a -> w b) (v : repr a wp_v) (f : (x:a -> repr b (wp_f x))) : repr b (bind_wp wp_v wp_f) = f v
{ "file_name": "examples/layeredeffects/ID3.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 31, "start_col": 0, "start_line": 27 }
module ID3 // The base type of WPs val w0 (a : Type u#a) : Type u#(max 1 a) let w0 a = (a -> Type0) -> Type0 // We require monotonicity of them let monotonic (w:w0 'a) = forall p1 p2. (forall x. p1 x ==> p2 x) ==> w p1 ==> w p2 val w (a : Type u#a) : Type u#(max 1 a) let w a = pure_wp a let repr (a : Type) (wp : w a) : Type = v:a{forall p. wp p ==> p v} open FStar.Monotonic.Pure let return (a : Type) (x : a) : repr a (as_pure_wp (fun p -> p x)) = x unfold let bind_wp #a #b (wp_v:w a) (wp_f:a -> w b) : w b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wp_v (fun x -> wp_f x p))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "ID3.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> b: Type -> wp_v: ID3.w a -> wp_f: (_: a -> ID3.w b) -> v: ID3.repr a wp_v -> f: (x: a -> ID3.repr b (wp_f x)) -> ID3.repr b (ID3.bind_wp wp_v wp_f)
Prims.Tot
[ "total" ]
[]
[ "ID3.w", "ID3.repr", "ID3.bind_wp" ]
[]
false
false
false
false
false
let bind (a b: Type) (wp_v: w a) (wp_f: (a -> w b)) (v: repr a wp_v) (f: (x: a -> repr b (wp_f x))) : repr b (bind_wp wp_v wp_f) =
f v
false