effect
stringclasses 48
values | original_source_type
stringlengths 0
23k
| opens_and_abbrevs
listlengths 2
92
| isa_cross_project_example
bool 1
class | source_definition
stringlengths 9
57.9k
| partial_definition
stringlengths 7
23.3k
| is_div
bool 2
classes | is_type
null | is_proof
bool 2
classes | completed_definiton
stringlengths 1
250k
| dependencies
dict | effect_flags
sequencelengths 0
2
| ideal_premises
sequencelengths 0
236
| mutual_with
sequencelengths 0
11
| file_context
stringlengths 0
407k
| interleaved
bool 1
class | is_simply_typed
bool 2
classes | file_name
stringlengths 5
48
| vconfig
dict | is_simple_lemma
null | source_type
stringlengths 10
23k
| proof_features
sequencelengths 0
1
| name
stringlengths 8
95
| source
dict | verbose_type
stringlengths 1
7.42k
| source_range
dict |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
FStar.Tactics.Effect.Tac | val trefl_guard: Prims.unit -> Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let trefl_guard () : Tac unit =
t_trefl true | val trefl_guard: Prims.unit -> Tac unit
let trefl_guard () : Tac unit = | true | null | false | t_trefl true | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Builtins.t_trefl"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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] *) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val trefl_guard: Prims.unit -> Tac unit | [] | FStar.Tactics.V2.Derived.trefl_guard | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 14,
"end_line": 200,
"start_col": 2,
"start_line": 200
} |
FStar.Tactics.Effect.Tac | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let dump1 (m : string) = focus (fun () -> dump m) | let dump1 (m: string) = | true | null | false | focus (fun () -> dump m) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.string",
"FStar.Tactics.V2.Derived.focus",
"Prims.unit",
"FStar.Tactics.V2.Builtins.dump"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val dump1 : m: Prims.string -> FStar.Tactics.Effect.Tac Prims.unit | [] | FStar.Tactics.V2.Derived.dump1 | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | m: Prims.string -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 49,
"end_line": 339,
"start_col": 25,
"start_line": 339
} |
|
FStar.Tactics.Effect.Tac | val debug (m: string) : Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let debug (m:string) : Tac unit =
if debugging () then print m | val debug (m: string) : Tac unit
let debug (m: string) : Tac unit = | true | null | false | if debugging () then print m | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.string",
"FStar.Tactics.V2.Builtins.print",
"Prims.unit",
"Prims.bool",
"FStar.Tactics.V2.Builtins.debugging"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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. *) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val debug (m: string) : Tac unit | [] | FStar.Tactics.V2.Derived.debug | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | m: Prims.string -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 32,
"end_line": 154,
"start_col": 4,
"start_line": 154
} |
FStar.Tactics.Effect.Tac | val smt_goals: Prims.unit -> Tac (list goal) | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let smt_goals () : Tac (list goal) = smt_goals_of (get ()) | val smt_goals: Prims.unit -> Tac (list goal)
let smt_goals () : Tac (list goal) = | true | null | false | smt_goals_of (get ()) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.Types.smt_goals_of",
"Prims.list",
"FStar.Tactics.Types.goal",
"FStar.Tactics.Types.proofstate",
"FStar.Tactics.Effect.get"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val smt_goals: Prims.unit -> Tac (list goal) | [] | FStar.Tactics.V2.Derived.smt_goals | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac (Prims.list FStar.Tactics.Types.goal) | {
"end_col": 58,
"end_line": 60,
"start_col": 37,
"start_line": 60
} |
FStar.Tactics.Effect.Tac | val cur_goal: Prims.unit -> Tac typ | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let cur_goal () : Tac typ = goal_type (_cur_goal ()) | val cur_goal: Prims.unit -> Tac typ
let cur_goal () : Tac typ = | true | null | false | goal_type (_cur_goal ()) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.Types.goal_type",
"FStar.Reflection.Types.typ",
"FStar.Tactics.Types.goal",
"FStar.Tactics.V2.Derived._cur_goal"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 ()) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val cur_goal: Prims.unit -> Tac typ | [] | FStar.Tactics.V2.Derived.cur_goal | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac FStar.Reflection.Types.typ | {
"end_col": 52,
"end_line": 81,
"start_col": 28,
"start_line": 81
} |
FStar.Tactics.Effect.Tac | val fresh_uvar (o: option typ) : Tac term | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let fresh_uvar (o : option typ) : Tac term =
let e = cur_env () in
uvar_env e o | val fresh_uvar (o: option typ) : Tac term
let fresh_uvar (o: option typ) : Tac term = | true | null | false | let e = cur_env () in
uvar_env e o | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"FStar.Pervasives.Native.option",
"FStar.Reflection.Types.typ",
"FStar.Tactics.V2.Builtins.uvar_env",
"FStar.Reflection.Types.term",
"FStar.Reflection.Types.env",
"FStar.Tactics.V2.Derived.cur_env",
"FStar.Tactics.NamedView.term"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 ()) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val fresh_uvar (o: option typ) : Tac term | [] | FStar.Tactics.V2.Derived.fresh_uvar | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | o: FStar.Pervasives.Native.option FStar.Reflection.Types.typ
-> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.term | {
"end_col": 16,
"end_line": 287,
"start_col": 44,
"start_line": 285
} |
FStar.Tactics.Effect.Tac | val exact_guard (t: term) : Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let exact_guard (t : term) : Tac unit =
with_policy Goal (fun () -> t_exact true false t) | val exact_guard (t: term) : Tac unit
let exact_guard (t: term) : Tac unit = | true | null | false | with_policy Goal (fun () -> t_exact true false t) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.Derived.with_policy",
"Prims.unit",
"FStar.Tactics.Types.Goal",
"FStar.Tactics.V2.Builtins.t_exact"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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. *) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val exact_guard (t: term) : Tac unit | [] | FStar.Tactics.V2.Derived.exact_guard | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 53,
"end_line": 223,
"start_col": 4,
"start_line": 223
} |
FStar.Tactics.Effect.Tac | val tmatch (t1 t2: term) : Tac bool | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let tmatch (t1 t2 : term) : Tac bool =
let e = cur_env () in
match_env e t1 t2 | val tmatch (t1 t2: term) : Tac bool
let tmatch (t1 t2: term) : Tac bool = | true | null | false | let e = cur_env () in
match_env e t1 t2 | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.Builtins.match_env",
"Prims.bool",
"FStar.Reflection.Types.env",
"FStar.Tactics.V2.Derived.cur_env"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val tmatch (t1 t2: term) : Tac bool | [] | FStar.Tactics.V2.Derived.tmatch | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t1: FStar.Tactics.NamedView.term -> t2: FStar.Tactics.NamedView.term
-> FStar.Tactics.Effect.Tac Prims.bool | {
"end_col": 21,
"end_line": 299,
"start_col": 38,
"start_line": 297
} |
FStar.Tactics.Effect.Tac | val cur_witness: Prims.unit -> Tac term | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let cur_witness () : Tac term = goal_witness (_cur_goal ()) | val cur_witness: Prims.unit -> Tac term
let cur_witness () : Tac term = | true | null | false | goal_witness (_cur_goal ()) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.Types.goal_witness",
"FStar.Tactics.NamedView.term",
"FStar.Tactics.Types.goal",
"FStar.Tactics.V2.Derived._cur_goal"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 ()) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val cur_witness: Prims.unit -> Tac term | [] | FStar.Tactics.V2.Derived.cur_witness | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.term | {
"end_col": 59,
"end_line": 84,
"start_col": 32,
"start_line": 84
} |
FStar.Tactics.Effect.Tac | val apply_lemma_rw (t: term) : Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let apply_lemma_rw (t : term) : Tac unit =
t_apply_lemma false true t | val apply_lemma_rw (t: term) : Tac unit
let apply_lemma_rw (t: term) : Tac unit = | true | null | false | t_apply_lemma false true t | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.Builtins.t_apply_lemma",
"Prims.unit"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val apply_lemma_rw (t: term) : Tac unit | [] | FStar.Tactics.V2.Derived.apply_lemma_rw | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 30,
"end_line": 212,
"start_col": 4,
"start_line": 212
} |
FStar.Tactics.Effect.Tac | val apply_lemma (t: term) : Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let apply_lemma (t : term) : Tac unit =
t_apply_lemma false false t | val apply_lemma (t: term) : Tac unit
let apply_lemma (t: term) : Tac unit = | true | null | false | t_apply_lemma false false t | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.Builtins.t_apply_lemma",
"Prims.unit"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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]. *) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val apply_lemma (t: term) : Tac unit | [] | FStar.Tactics.V2.Derived.apply_lemma | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 31,
"end_line": 192,
"start_col": 4,
"start_line": 192
} |
FStar.Tactics.Effect.Tac | val pointwise' (tau: (unit -> Tac unit)) : Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let pointwise' (tau : unit -> Tac unit) : Tac unit = t_pointwise TopDown tau | val pointwise' (tau: (unit -> Tac unit)) : Tac unit
let pointwise' (tau: (unit -> Tac unit)) : Tac unit = | true | null | false | t_pointwise TopDown tau | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.t_pointwise",
"FStar.Tactics.Types.TopDown"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val pointwise' (tau: (unit -> Tac unit)) : Tac unit | [] | FStar.Tactics.V2.Derived.pointwise' | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | tau: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit) -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 77,
"end_line": 277,
"start_col": 53,
"start_line": 277
} |
FStar.Tactics.Effect.Tac | val pointwise (tau: (unit -> Tac unit)) : Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let pointwise (tau : unit -> Tac unit) : Tac unit = t_pointwise BottomUp tau | val pointwise (tau: (unit -> Tac unit)) : Tac unit
let pointwise (tau: (unit -> Tac unit)) : Tac unit = | true | null | false | t_pointwise BottomUp tau | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.t_pointwise",
"FStar.Tactics.Types.BottomUp"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val pointwise (tau: (unit -> Tac unit)) : Tac unit | [] | FStar.Tactics.V2.Derived.pointwise | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | tau: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit) -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 77,
"end_line": 276,
"start_col": 53,
"start_line": 276
} |
FStar.Tactics.Effect.Tac | val exact (t: term) : Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let exact (t : term) : Tac unit =
with_policy SMT (fun () -> t_exact true false t) | val exact (t: term) : Tac unit
let exact (t: term) : Tac unit = | true | null | false | with_policy SMT (fun () -> t_exact true false t) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.Derived.with_policy",
"Prims.unit",
"FStar.Tactics.Types.SMT",
"FStar.Tactics.V2.Builtins.t_exact"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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]. *) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val exact (t: term) : Tac unit | [] | FStar.Tactics.V2.Derived.exact | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 52,
"end_line": 108,
"start_col": 4,
"start_line": 108
} |
FStar.Tactics.Effect.Tac | val cur_module: Prims.unit -> Tac name | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let cur_module () : Tac name =
moduleof (top_env ()) | val cur_module: Prims.unit -> Tac name
let cur_module () : Tac name = | true | null | false | moduleof (top_env ()) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Reflection.V2.Builtins.moduleof",
"FStar.Reflection.Types.name",
"FStar.Reflection.Types.env",
"FStar.Tactics.V2.Builtins.top_env"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val cur_module: Prims.unit -> Tac name | [] | FStar.Tactics.V2.Derived.cur_module | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac FStar.Reflection.Types.name | {
"end_col": 25,
"end_line": 280,
"start_col": 4,
"start_line": 280
} |
FStar.Tactics.Effect.Tac | val binder_to_string (b: binder) : Tac string | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | 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 ^ ")" | val binder_to_string (b: binder) : Tac string
let binder_to_string (b: binder) : Tac string = | true | null | false | name_of_binder b ^ "@@" ^ string_of_int b.uniq ^ "::(" ^ term_to_string b.sort ^ ")" | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"FStar.Tactics.NamedView.binder",
"Prims.op_Hat",
"Prims.string",
"Prims.string_of_int",
"FStar.Tactics.NamedView.__proj__Mkbinder__item__uniq",
"FStar.Tactics.V2.Builtins.term_to_string",
"FStar.Tactics.NamedView.__proj__Mkbinder__item__sort",
"FStar.Tactics.V2.Derived.name_of_binder"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 = | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val binder_to_string (b: binder) : Tac string | [] | FStar.Tactics.V2.Derived.binder_to_string | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | b: FStar.Tactics.NamedView.binder -> FStar.Tactics.Effect.Tac Prims.string | {
"end_col": 86,
"end_line": 46,
"start_col": 2,
"start_line": 46
} |
FStar.Tactics.Effect.Tac | val cur_vars: Prims.unit -> Tac (list binding) | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let cur_vars () : Tac (list binding) =
vars_of_env (cur_env ()) | val cur_vars: Prims.unit -> Tac (list binding)
let cur_vars () : Tac (list binding) = | true | null | false | vars_of_env (cur_env ()) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Reflection.V2.Builtins.vars_of_env",
"Prims.list",
"FStar.Tactics.NamedView.binding",
"FStar.Reflection.Types.env",
"FStar.Tactics.V2.Derived.cur_env"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val cur_vars: Prims.unit -> Tac (list binding) | [] | FStar.Tactics.V2.Derived.cur_vars | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac (Prims.list FStar.Tactics.NamedView.binding) | {
"end_col": 28,
"end_line": 95,
"start_col": 4,
"start_line": 95
} |
FStar.Tactics.Effect.Tac | val later: Prims.unit -> Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let later () : Tac unit =
match goals () with
| g::gs -> set_goals (gs @ [g])
| _ -> fail "later: no goals" | val later: Prims.unit -> Tac unit
let later () : Tac unit = | true | null | false | match goals () with
| g :: gs -> set_goals (gs @ [g])
| _ -> fail "later: no goals" | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.Types.goal",
"Prims.list",
"FStar.Tactics.V2.Builtins.set_goals",
"FStar.Tactics.V2.Derived.op_At",
"Prims.Cons",
"Prims.Nil",
"FStar.Tactics.V2.Derived.fail",
"FStar.Tactics.V2.Derived.goals"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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. *) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val later: Prims.unit -> Tac unit | [] | FStar.Tactics.V2.Derived.later | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 33,
"end_line": 175,
"start_col": 4,
"start_line": 173
} |
FStar.Tactics.Effect.Tac | val iterAllSMT (t: (unit -> Tac unit)) : Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | 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') | val iterAllSMT (t: (unit -> Tac unit)) : Tac unit
let iterAllSMT (t: (unit -> Tac unit)) : Tac unit = | true | null | false | 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') | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"Prims.list",
"FStar.Tactics.Types.goal",
"FStar.Tactics.V2.Builtins.set_smt_goals",
"FStar.Tactics.V2.Derived.op_At",
"FStar.Tactics.V2.Builtins.set_goals",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Tactics.V2.Derived.smt_goals",
"FStar.Tactics.V2.Derived.goals",
"FStar.Tactics.V2.Derived.iterAll",
"Prims.Nil"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 () | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val iterAllSMT (t: (unit -> Tac unit)) : Tac unit | [] | FStar.Tactics.V2.Derived.iterAllSMT | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit) -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 28,
"end_line": 359,
"start_col": 50,
"start_line": 352
} |
FStar.Tactics.Effect.Tac | val trivial: Prims.unit -> Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | 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 | val trivial: Prims.unit -> Tac unit
let trivial () : Tac unit = | true | null | false | 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 | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.exact",
"FStar.Reflection.V2.Formula.formula",
"FStar.Tactics.Effect.raise",
"FStar.Tactics.V2.Derived.Goal_not_trivial",
"FStar.Reflection.V2.Formula.term_as_formula",
"FStar.Reflection.Types.typ",
"FStar.Tactics.V2.Derived.cur_goal",
"FStar.Tactics.V2.Builtins.norm",
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.iota",
"FStar.Pervasives.zeta",
"FStar.Pervasives.reify_",
"FStar.Pervasives.delta",
"FStar.Pervasives.primops",
"FStar.Pervasives.simplify",
"FStar.Pervasives.unmeta",
"Prims.Nil"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val trivial: Prims.unit -> Tac unit | [] | FStar.Tactics.V2.Derived.trivial | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 31,
"end_line": 121,
"start_col": 2,
"start_line": 117
} |
FStar.Tactics.Effect.Tac | val t_pointwise (d: direction) (tau: (unit -> Tac unit)) : Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | 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 | val t_pointwise (d: direction) (tau: (unit -> Tac unit)) : Tac unit
let t_pointwise (d: direction) (tau: (unit -> Tac unit)) : Tac unit = | true | null | false | let ctrl (t: term) : Tac (bool & ctrl_flag) = true, Continue in
let rw () : Tac unit = tau () in
ctrl_rewrite d ctrl rw | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"FStar.Tactics.Types.direction",
"Prims.unit",
"FStar.Tactics.V2.Builtins.ctrl_rewrite",
"FStar.Tactics.NamedView.term",
"FStar.Pervasives.Native.tuple2",
"Prims.bool",
"FStar.Tactics.Types.ctrl_flag",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Tactics.Types.Continue"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val t_pointwise (d: direction) (tau: (unit -> Tac unit)) : Tac unit | [] | FStar.Tactics.V2.Derived.t_pointwise | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | d: FStar.Tactics.Types.direction -> tau: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit)
-> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 24,
"end_line": 239,
"start_col": 67,
"start_line": 232
} |
FStar.Tactics.Effect.Tac | val exact_args (qs: list aqualv) (t: term) : Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | 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)
) | val exact_args (qs: list aqualv) (t: term) : Tac unit
let exact_args (qs: list aqualv) (t: term) : Tac unit = | true | null | false | 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) (L.rev uvs)) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.list",
"FStar.Reflection.V2.Data.aqualv",
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.Derived.focus",
"Prims.unit",
"FStar.Tactics.Util.iter",
"FStar.Reflection.Types.term",
"FStar.Reflection.V2.Derived.is_uvar",
"FStar.Tactics.V2.Builtins.unshelve",
"Prims.bool",
"FStar.List.Tot.Base.rev",
"FStar.Tactics.V2.Derived.exact",
"FStar.Reflection.V2.Derived.mk_app",
"FStar.Reflection.V2.Data.argv",
"FStar.Tactics.Util.zip",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.Util.repeatn",
"FStar.Tactics.V2.Derived.fresh_uvar",
"FStar.Pervasives.Native.None",
"FStar.Reflection.Types.typ",
"Prims.nat",
"FStar.List.Tot.Base.length"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val exact_args (qs: list aqualv) (t: term) : Tac unit | [] | FStar.Tactics.V2.Derived.exact_args | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | qs: Prims.list FStar.Reflection.V2.Data.aqualv -> t: FStar.Tactics.NamedView.term
-> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 5,
"end_line": 376,
"start_col": 4,
"start_line": 368
} |
FStar.Tactics.Effect.Tac | val seq (f g: (unit -> Tac unit)) : Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let seq (f : unit -> Tac unit) (g : unit -> Tac unit) : Tac unit =
focus (fun () -> f (); iterAll g) | val seq (f g: (unit -> Tac unit)) : Tac unit
let seq (f g: (unit -> Tac unit)) : Tac unit = | true | null | false | focus (fun () ->
f ();
iterAll g) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.focus",
"FStar.Tactics.V2.Derived.iterAll"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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"). *) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val seq (f g: (unit -> Tac unit)) : Tac unit | [] | FStar.Tactics.V2.Derived.seq | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
f: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit) ->
g: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit)
-> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 37,
"end_line": 365,
"start_col": 4,
"start_line": 365
} |
FStar.Tactics.Effect.Tac | val exact_n (n: int) (t: term) : Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let exact_n (n : int) (t : term) : Tac unit =
exact_args (repeatn n (fun () -> Q_Explicit)) t | val exact_n (n: int) (t: term) : Tac unit
let exact_n (n: int) (t: term) : Tac unit = | true | null | false | exact_args (repeatn n (fun () -> Q_Explicit)) t | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.int",
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.Derived.exact_args",
"Prims.unit",
"Prims.list",
"FStar.Reflection.V2.Data.aqualv",
"FStar.Tactics.Util.repeatn",
"FStar.Reflection.V2.Data.Q_Explicit"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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)
) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val exact_n (n: int) (t: term) : Tac unit | [] | FStar.Tactics.V2.Derived.exact_n | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | n: Prims.int -> t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 51,
"end_line": 379,
"start_col": 4,
"start_line": 379
} |
FStar.Tactics.Effect.Tac | val (<|>) : (unit -> Tac 'a) ->
(unit -> Tac 'a) ->
(unit -> Tac 'a) | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let (<|>) t1 t2 = fun () -> or_else t1 t2 | val (<|>) : (unit -> Tac 'a) ->
(unit -> Tac 'a) ->
(unit -> Tac 'a)
let op_Less_Bar_Greater t1 t2 = | true | null | false | fun () -> or_else t1 t2 | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.or_else"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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) -> | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val (<|>) : (unit -> Tac 'a) ->
(unit -> Tac 'a) ->
(unit -> Tac 'a) | [] | FStar.Tactics.V2.Derived.op_Less_Bar_Greater | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
t1: (_: Prims.unit -> FStar.Tactics.Effect.Tac 'a) ->
t2: (_: Prims.unit -> FStar.Tactics.Effect.Tac 'a) ->
_: Prims.unit
-> FStar.Tactics.Effect.Tac 'a | {
"end_col": 41,
"end_line": 463,
"start_col": 18,
"start_line": 463
} |
FStar.Tactics.Effect.Tac | val norm_term (s: list norm_step) (t: term) : Tac term | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | 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 | val norm_term (s: list norm_step) (t: term) : Tac term
let norm_term (s: list norm_step) (t: term) : Tac term = | true | null | false | let e = try cur_env () with | _ -> top_env () in
norm_term_env e s t | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.list",
"FStar.Pervasives.norm_step",
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.Builtins.norm_term_env",
"FStar.Reflection.Types.term",
"FStar.Reflection.Types.env",
"FStar.Tactics.V2.Derived.try_with",
"Prims.unit",
"FStar.Tactics.V2.Derived.cur_env",
"Prims.exn",
"FStar.Tactics.V2.Builtins.top_env"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 () | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val norm_term (s: list norm_step) (t: term) : Tac term | [] | FStar.Tactics.V2.Derived.norm_term | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: Prims.list FStar.Pervasives.norm_step -> t: FStar.Tactics.NamedView.term
-> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.term | {
"end_col": 23,
"end_line": 484,
"start_col": 58,
"start_line": 479
} |
FStar.Tactics.Effect.Tac | val admit1: Prims.unit -> Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let admit1 () : Tac unit =
tadmit () | val admit1: Prims.unit -> Tac unit
let admit1 () : Tac unit = | true | null | false | tadmit () | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.tadmit"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 (`()) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val admit1: Prims.unit -> Tac unit | [] | FStar.Tactics.V2.Derived.admit1 | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 13,
"end_line": 509,
"start_col": 4,
"start_line": 509
} |
FStar.Tactics.Effect.Tac | val namedv_to_simple_binder (n: namedv) : Tac simple_binder | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | 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; (* GGG USINGSORT *)
qual = Q_Explicit;
attrs = [];
} | val namedv_to_simple_binder (n: namedv) : Tac simple_binder
let namedv_to_simple_binder (n: namedv) : Tac simple_binder = | true | null | false | let nv = inspect_namedv n in
{ ppname = nv.ppname; uniq = nv.uniq; sort = unseal nv.sort; qual = Q_Explicit; attrs = [] } | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"FStar.Tactics.NamedView.namedv",
"FStar.Tactics.NamedView.Mkbinder",
"FStar.Reflection.V2.Data.__proj__Mknamedv_view__item__uniq",
"FStar.Reflection.V2.Data.__proj__Mknamedv_view__item__ppname",
"FStar.Reflection.V2.Data.Q_Explicit",
"Prims.Nil",
"FStar.Tactics.NamedView.term",
"FStar.Tactics.NamedView.simple_binder",
"FStar.Reflection.Types.typ",
"FStar.Tactics.Unseal.unseal",
"FStar.Reflection.V2.Data.__proj__Mknamedv_view__item__sort",
"FStar.Tactics.NamedView.inspect_namedv"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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_binder] 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_binder (-1)]
will return the last binder, [nth_binder (-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') | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val namedv_to_simple_binder (n: namedv) : Tac simple_binder | [] | FStar.Tactics.V2.Derived.namedv_to_simple_binder | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | n: FStar.Tactics.NamedView.namedv -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.simple_binder | {
"end_col": 3,
"end_line": 890,
"start_col": 62,
"start_line": 882
} |
FStar.Tactics.Effect.Tac | val __assumption_aux (xs: list binding) : Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | 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 | val __assumption_aux (xs: list binding) : Tac unit
let rec __assumption_aux (xs: list binding) : Tac unit = | true | null | false | 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": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"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"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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 | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val __assumption_aux (xs: list binding) : Tac unit | [
"recursion"
] | FStar.Tactics.V2.Derived.__assumption_aux | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | xs: Prims.list FStar.Tactics.NamedView.binding -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 27,
"end_line": 582,
"start_col": 4,
"start_line": 575
} |
FStar.Tactics.Effect.Tac | val first (ts: list (unit -> Tac 'a)) : Tac 'a | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let first (ts : list (unit -> Tac 'a)) : Tac 'a =
L.fold_right (<|>) ts (fun () -> fail "no tactics to try") () | val first (ts: list (unit -> Tac 'a)) : Tac 'a
let first (ts: list (unit -> Tac 'a)) : Tac 'a = | true | null | false | L.fold_right ( <|> ) ts (fun () -> fail "no tactics to try") () | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.list",
"Prims.unit",
"FStar.List.Tot.Base.fold_right",
"FStar.Tactics.V2.Derived.op_Less_Bar_Greater",
"FStar.Tactics.V2.Derived.fail"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val first (ts: list (unit -> Tac 'a)) : Tac 'a | [] | FStar.Tactics.V2.Derived.first | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | ts: Prims.list (_: Prims.unit -> FStar.Tactics.Effect.Tac 'a) -> FStar.Tactics.Effect.Tac 'a | {
"end_col": 65,
"end_line": 466,
"start_col": 4,
"start_line": 466
} |
FStar.Tactics.Effect.Tac | val fresh_namedv: Prims.unit -> Tac namedv | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | 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;
}) | val fresh_namedv: Prims.unit -> Tac namedv
let fresh_namedv () : Tac namedv = | true | null | false | let n = fresh () in
pack_namedv ({ ppname = seal ("x" ^ string_of_int n); sort = seal (pack Tv_Unknown); uniq = n }) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.NamedView.pack_namedv",
"FStar.Reflection.V2.Data.Mknamedv_view",
"FStar.Sealed.seal",
"FStar.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.Tactics.V2.Builtins.fresh"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val fresh_namedv: Prims.unit -> Tac namedv | [] | FStar.Tactics.V2.Derived.fresh_namedv | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.namedv | {
"end_col": 4,
"end_line": 404,
"start_col": 34,
"start_line": 398
} |
FStar.Tactics.Effect.Tac | val repeat' (f: (unit -> Tac 'a)) : Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let repeat' (f : unit -> Tac 'a) : Tac unit =
let _ = repeat f in () | val repeat' (f: (unit -> Tac 'a)) : Tac unit
let repeat' (f: (unit -> Tac 'a)) : Tac unit = | true | null | false | let _ = repeat f in
() | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"Prims.list",
"FStar.Tactics.V2.Derived.repeat"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val repeat' (f: (unit -> Tac 'a)) : Tac unit | [] | FStar.Tactics.V2.Derived.repeat' | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | f: (_: Prims.unit -> FStar.Tactics.Effect.Tac 'a) -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 26,
"end_line": 477,
"start_col": 45,
"start_line": 476
} |
FStar.Tactics.Effect.Tac | val or_else (#a: Type) (t1 t2: (unit -> Tac a)) : Tac a | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let or_else (#a:Type) (t1 : unit -> Tac a) (t2 : unit -> Tac a) : Tac a =
try t1 ()
with | _ -> t2 () | val or_else (#a: Type) (t1 t2: (unit -> Tac a)) : Tac a
let or_else (#a: Type) (t1 t2: (unit -> Tac a)) : Tac a = | true | null | false | try t1 () with | _ -> t2 () | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.try_with",
"Prims.exn"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val or_else (#a: Type) (t1 t2: (unit -> Tac a)) : Tac a | [] | FStar.Tactics.V2.Derived.or_else | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
t1: (_: Prims.unit -> FStar.Tactics.Effect.Tac a) ->
t2: (_: Prims.unit -> FStar.Tactics.Effect.Tac a)
-> FStar.Tactics.Effect.Tac a | {
"end_col": 21,
"end_line": 458,
"start_col": 4,
"start_line": 457
} |
FStar.Tactics.Effect.Tac | val compute: Prims.unit -> Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let compute () : Tac unit = norm [primops; iota; delta; zeta] | val compute: Prims.unit -> Tac unit
let compute () : Tac unit = | true | null | false | norm [primops; iota; delta; zeta] | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Builtins.norm",
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.primops",
"FStar.Pervasives.iota",
"FStar.Pervasives.delta",
"FStar.Pervasives.zeta",
"Prims.Nil"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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] | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val compute: Prims.unit -> Tac unit | [] | FStar.Tactics.V2.Derived.compute | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 61,
"end_line": 530,
"start_col": 28,
"start_line": 530
} |
FStar.Tactics.Effect.Tac | val intros': Prims.unit -> Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let intros' () : Tac unit = let _ = intros () in () | val intros': Prims.unit -> Tac unit
let intros' () : Tac unit = | true | null | false | let _ = intros () in
() | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"Prims.list",
"FStar.Tactics.NamedView.binding",
"FStar.Tactics.V2.Derived.intros"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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 | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val intros': Prims.unit -> Tac unit | [] | FStar.Tactics.V2.Derived.intros' | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 51,
"end_line": 534,
"start_col": 27,
"start_line": 534
} |
FStar.Tactics.Effect.Tac | val tcut (t: term) : Tac binding | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let tcut (t:term) : Tac binding =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro () | val tcut (t: term) : Tac binding
let tcut (t: term) : Tac binding = | true | null | false | let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro () | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.Builtins.intro",
"FStar.Reflection.V2.Data.binding",
"Prims.unit",
"FStar.Tactics.V2.Derived.apply",
"FStar.Tactics.NamedView.binding",
"FStar.Reflection.Types.term",
"FStar.Reflection.V2.Derived.mk_e_app",
"Prims.Cons",
"Prims.Nil",
"FStar.Reflection.Types.typ",
"FStar.Tactics.V2.Derived.cur_goal"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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 | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val tcut (t: term) : Tac binding | [] | FStar.Tactics.V2.Derived.tcut | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.binding | {
"end_col": 12,
"end_line": 545,
"start_col": 33,
"start_line": 541
} |
FStar.Tactics.Effect.Tac | val pose (t: term) : Tac binding | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let pose (t:term) : Tac binding =
apply (`__cut);
flip ();
exact t;
intro () | val pose (t: term) : Tac binding
let pose (t: term) : Tac binding = | true | null | false | apply (`__cut);
flip ();
exact t;
intro () | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.Builtins.intro",
"FStar.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"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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 () | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val pose (t: term) : Tac binding | [] | FStar.Tactics.V2.Derived.pose | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.binding | {
"end_col": 12,
"end_line": 551,
"start_col": 4,
"start_line": 548
} |
FStar.Tactics.Effect.Tac | val admit_all: Prims.unit -> Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let admit_all () : Tac unit =
let _ = repeat tadmit in
() | val admit_all: Prims.unit -> Tac unit
let admit_all () : Tac unit = | true | null | false | let _ = repeat tadmit in
() | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"Prims.list",
"FStar.Tactics.V2.Derived.repeat",
"FStar.Tactics.V2.Derived.tadmit"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 () | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val admit_all: Prims.unit -> Tac unit | [] | FStar.Tactics.V2.Derived.admit_all | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 6,
"end_line": 513,
"start_col": 29,
"start_line": 511
} |
FStar.Tactics.Effect.Tac | val skip_guard: Prims.unit -> Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let skip_guard () : Tac unit =
if is_guard ()
then smt ()
else fail "" | val skip_guard: Prims.unit -> Tac unit
let skip_guard () : Tac unit = | true | null | false | if is_guard () then smt () else fail "" | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.smt",
"Prims.bool",
"FStar.Tactics.V2.Derived.fail",
"FStar.Tactics.V2.Derived.is_guard"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
Tactics.Types.is_guard (_cur_goal ()) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val skip_guard: Prims.unit -> Tac unit | [] | FStar.Tactics.V2.Derived.skip_guard | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 16,
"end_line": 522,
"start_col": 4,
"start_line": 520
} |
FStar.Tactics.Effect.Tac | val intros: Prims.unit -> Tac (list binding) | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let intros () : Tac (list binding) = repeat intro | val intros: Prims.unit -> Tac (list binding)
let intros () : Tac (list binding) = | true | null | false | repeat intro | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.repeat",
"FStar.Tactics.NamedView.binding",
"FStar.Tactics.V2.Builtins.intro",
"Prims.list"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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] | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val intros: Prims.unit -> Tac (list binding) | [] | FStar.Tactics.V2.Derived.intros | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac (Prims.list FStar.Tactics.NamedView.binding) | {
"end_col": 49,
"end_line": 532,
"start_col": 37,
"start_line": 532
} |
FStar.Tactics.Effect.Tac | val revert_all (bs: list binding) : Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let rec revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl | val revert_all (bs: list binding) : Tac unit
let rec revert_all (bs: list binding) : Tac unit = | true | null | false | match bs with
| [] -> ()
| _ :: tl ->
revert ();
revert_all tl | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.list",
"FStar.Tactics.NamedView.binding",
"Prims.unit",
"FStar.Tactics.V2.Derived.revert_all",
"FStar.Tactics.V2.Builtins.revert"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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 ()) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val revert_all (bs: list binding) : Tac unit | [
"recursion"
] | FStar.Tactics.V2.Derived.revert_all | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | bs: Prims.list FStar.Tactics.NamedView.binding -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 26,
"end_line": 568,
"start_col": 4,
"start_line": 565
} |
FStar.Tactics.Effect.Tac | val pose_as (s: string) (t: term) : Tac binding | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let pose_as (s:string) (t:term) : Tac binding =
let b = pose t in
rename_to b s | val pose_as (s: string) (t: term) : Tac binding
let pose_as (s: string) (t: term) : Tac binding = | true | null | false | let b = pose t in
rename_to b s | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.string",
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.Builtins.rename_to",
"FStar.Reflection.V2.Data.binding",
"FStar.Tactics.NamedView.binding",
"FStar.Tactics.V2.Derived.pose"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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 | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val pose_as (s: string) (t: term) : Tac binding | [] | FStar.Tactics.V2.Derived.pose_as | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: Prims.string -> t: FStar.Tactics.NamedView.term
-> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.binding | {
"end_col": 17,
"end_line": 559,
"start_col": 47,
"start_line": 557
} |
FStar.Tactics.Effect.Tac | val for_each_binding (f: (binding -> Tac 'a)) : Tac (list 'a) | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let for_each_binding (f : binding -> Tac 'a) : Tac (list 'a) =
map f (cur_vars ()) | val for_each_binding (f: (binding -> Tac 'a)) : Tac (list 'a)
let for_each_binding (f: (binding -> Tac 'a)) : Tac (list 'a) = | true | null | false | map f (cur_vars ()) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"FStar.Tactics.NamedView.binding",
"FStar.Tactics.Util.map",
"Prims.list",
"FStar.Tactics.V2.Derived.cur_vars"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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 | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val for_each_binding (f: (binding -> Tac 'a)) : Tac (list 'a) | [] | FStar.Tactics.V2.Derived.for_each_binding | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | f: (_: FStar.Tactics.NamedView.binding -> FStar.Tactics.Effect.Tac 'a)
-> FStar.Tactics.Effect.Tac (Prims.list 'a) | {
"end_col": 23,
"end_line": 562,
"start_col": 4,
"start_line": 562
} |
Prims.Tot | val binder_sort (b: binder) : Tot typ | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let binder_sort (b : binder) : Tot typ = b.sort | val binder_sort (b: binder) : Tot typ
let binder_sort (b: binder) : Tot typ = | false | null | false | b.sort | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [
"total"
] | [
"FStar.Tactics.NamedView.binder",
"FStar.Tactics.NamedView.__proj__Mkbinder__item__sort",
"FStar.Reflection.Types.typ"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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 | false | true | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val binder_sort (b: binder) : Tot typ | [] | FStar.Tactics.V2.Derived.binder_sort | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | b: FStar.Tactics.NamedView.binder -> FStar.Reflection.Types.typ | {
"end_col": 47,
"end_line": 570,
"start_col": 41,
"start_line": 570
} |
FStar.Tactics.Effect.Tac | val bump_nth (n: pos) : Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | 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) | val bump_nth (n: pos) : Tac unit
let bump_nth (n: pos) : Tac unit = | true | null | false | match extract_nth (n - 1) (goals ()) with
| None -> fail "bump_nth: not that many goals"
| Some (h, t) -> set_goals (h :: t) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.pos",
"FStar.Tactics.V2.Derived.fail",
"Prims.unit",
"FStar.Tactics.Types.goal",
"Prims.list",
"FStar.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"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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 = | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val bump_nth (n: pos) : Tac unit | [] | FStar.Tactics.V2.Derived.bump_nth | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | n: Prims.pos -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 37,
"end_line": 799,
"start_col": 2,
"start_line": 797
} |
FStar.Tactics.Effect.Tac | val rewrite' (x: binding) : Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let rewrite' (x:binding) : Tac unit =
((fun () -> rewrite x)
<|> (fun () -> var_retype x;
apply_lemma (`__eq_sym);
rewrite x)
<|> (fun () -> fail "rewrite' failed"))
() | val rewrite' (x: binding) : Tac unit
let rewrite' (x: binding) : Tac unit = | true | null | false | ((fun () -> rewrite x) <|>
(fun () ->
var_retype x;
apply_lemma (`__eq_sym);
rewrite x) <|>
(fun () -> fail "rewrite' failed")) () | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"FStar.Tactics.NamedView.binding",
"FStar.Tactics.V2.Derived.op_Less_Bar_Greater",
"Prims.unit",
"FStar.Tactics.V2.Builtins.rewrite",
"FStar.Tactics.V2.Derived.apply_lemma",
"FStar.Tactics.V2.Builtins.var_retype",
"FStar.Tactics.V2.Derived.fail"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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] *) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val rewrite' (x: binding) : Tac unit | [] | FStar.Tactics.V2.Derived.rewrite' | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: FStar.Tactics.NamedView.binding -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 6,
"end_line": 608,
"start_col": 4,
"start_line": 603
} |
FStar.Tactics.Effect.Tac | val _cur_goal: Prims.unit -> Tac goal | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let _cur_goal () : Tac goal =
match goals () with
| [] -> fail "no more goals"
| g::_ -> g | val _cur_goal: Prims.unit -> Tac goal
let _cur_goal () : Tac goal = | true | null | false | match goals () with
| [] -> fail "no more goals"
| g :: _ -> g | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.fail",
"FStar.Tactics.Types.goal",
"Prims.list",
"FStar.Tactics.V2.Derived.goals"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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) *) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val _cur_goal: Prims.unit -> Tac goal | [] | FStar.Tactics.V2.Derived._cur_goal | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac FStar.Tactics.Types.goal | {
"end_col": 15,
"end_line": 75,
"start_col": 4,
"start_line": 73
} |
FStar.Tactics.Effect.Tac | val dismiss: Prims.unit -> Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let dismiss () : Tac unit =
match goals () with
| [] -> fail "dismiss: no more goals"
| _::gs -> set_goals gs | val dismiss: Prims.unit -> Tac unit
let dismiss () : Tac unit = | true | null | false | match goals () with
| [] -> fail "dismiss: no more goals"
| _ :: gs -> set_goals gs | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.fail",
"FStar.Tactics.Types.goal",
"Prims.list",
"FStar.Tactics.V2.Builtins.set_goals",
"FStar.Tactics.V2.Derived.goals"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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. *) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val dismiss: Prims.unit -> Tac unit | [] | FStar.Tactics.V2.Derived.dismiss | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 27,
"end_line": 135,
"start_col": 4,
"start_line": 133
} |
FStar.Pervasives.Lemma | val __eq_sym (#t: _) (a b: t) : Lemma ((a == b) == (b == a)) | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let __eq_sym #t (a b : t) : Lemma ((a == b) == (b == a)) =
FStar.PropositionalExtensionality.apply (a==b) (b==a) | val __eq_sym (#t: _) (a b: t) : Lemma ((a == b) == (b == a))
let __eq_sym #t (a: t) (b: t) : Lemma ((a == b) == (b == a)) = | false | null | true | FStar.PropositionalExtensionality.apply (a == b) (b == a) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [
"lemma"
] | [
"FStar.PropositionalExtensionality.apply",
"Prims.eq2",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.logical",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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 | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val __eq_sym (#t: _) (a b: t) : Lemma ((a == b) == (b == a)) | [] | FStar.Tactics.V2.Derived.__eq_sym | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: t -> b: t -> FStar.Pervasives.Lemma (ensures a == b == (b == a)) | {
"end_col": 55,
"end_line": 599,
"start_col": 2,
"start_line": 599
} |
FStar.Tactics.Effect.Tac | val try_with (f: (unit -> Tac 'a)) (h: (exn -> Tac 'a)) : Tac 'a | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | 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 | 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 = | true | null | false | match catch f with
| Inl e -> h e
| Inr x -> x | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"Prims.exn",
"FStar.Pervasives.either",
"FStar.Tactics.V2.Builtins.catch"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 () | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val try_with (f: (unit -> Tac 'a)) (h: (exn -> Tac 'a)) : Tac 'a | [] | FStar.Tactics.V2.Derived.try_with | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
f: (_: Prims.unit -> FStar.Tactics.Effect.Tac 'a) ->
h: (_: Prims.exn -> FStar.Tactics.Effect.Tac 'a)
-> FStar.Tactics.Effect.Tac 'a | {
"end_col": 16,
"end_line": 449,
"start_col": 4,
"start_line": 447
} |
FStar.Tactics.Effect.Tac | val mk_abs (args: list binder) (t: term) : Tac term (decreases args) | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | 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') | 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) = | true | null | false | match args with
| [] -> t
| a :: args' ->
let t' = mk_abs args' t in
pack (Tv_Abs a t') | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [
""
] | [
"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"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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_binder] 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_binder (-1)]
will return the last binder, [nth_binder (-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] *) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val mk_abs (args: list binder) (t: term) : Tac term (decreases args) | [
"recursion"
] | FStar.Tactics.V2.Derived.mk_abs | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | args: Prims.list FStar.Tactics.NamedView.binder -> t: FStar.Tactics.NamedView.term
-> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.term | {
"end_col": 22,
"end_line": 879,
"start_col": 2,
"start_line": 875
} |
FStar.Tactics.Effect.Tac | val nth_var (i: int) : Tac binding | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | 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 | val nth_var (i: int) : Tac binding
let nth_var (i: int) : Tac binding = | true | null | false | 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 | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"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"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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_binder] 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_binder (-1)]
will return the last binder, [nth_binder (-2)] the second to last, and | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val nth_var (i: int) : Tac binding | [] | FStar.Tactics.V2.Derived.nth_var | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | i: Prims.int -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.binding | {
"end_col": 15,
"end_line": 854,
"start_col": 35,
"start_line": 848
} |
FStar.Tactics.Effect.Tac | val rewrite_eqs_from_context: Prims.unit -> Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let rewrite_eqs_from_context () : Tac unit =
rewrite_all_context_equalities (cur_vars ()) | val rewrite_eqs_from_context: Prims.unit -> Tac unit
let rewrite_eqs_from_context () : Tac unit = | true | null | false | rewrite_all_context_equalities (cur_vars ()) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.rewrite_all_context_equalities",
"Prims.list",
"FStar.Tactics.NamedView.binding",
"FStar.Tactics.V2.Derived.cur_vars"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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 | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val rewrite_eqs_from_context: Prims.unit -> Tac unit | [] | FStar.Tactics.V2.Derived.rewrite_eqs_from_context | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 48,
"end_line": 632,
"start_col": 4,
"start_line": 632
} |
Prims.Tot | val mk_sq_eq (t1 t2: term) : Tot term | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | 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]) | val mk_sq_eq (t1 t2: term) : Tot term
let mk_sq_eq (t1 t2: term) : Tot term = | false | null | false | let eq:term = pack (Tv_FVar (pack_fv eq2_qn)) in
mk_squash (mk_e_app eq [t1; t2]) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [
"total"
] | [
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.Derived.mk_squash",
"FStar.Reflection.V2.Derived.mk_e_app",
"Prims.Cons",
"FStar.Reflection.Types.term",
"Prims.Nil",
"FStar.Tactics.NamedView.pack",
"FStar.Tactics.NamedView.Tv_FVar",
"FStar.Reflection.V2.Builtins.pack_fv",
"FStar.Reflection.Const.eq2_qn"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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] | false | true | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val mk_sq_eq (t1 t2: term) : Tot term | [] | FStar.Tactics.V2.Derived.mk_sq_eq | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t1: FStar.Tactics.NamedView.term -> t2: FStar.Tactics.NamedView.term -> FStar.Tactics.NamedView.term | {
"end_col": 36,
"end_line": 661,
"start_col": 40,
"start_line": 659
} |
FStar.Tactics.Effect.Tac | val magic_dump_t: Prims.unit -> Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let magic_dump_t () : Tac unit =
dump "Admitting";
apply (`magic);
exact (`());
() | val magic_dump_t: Prims.unit -> Tac unit
let magic_dump_t () : Tac unit = | true | null | false | dump "Admitting";
apply (`magic);
exact (`());
() | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.exact",
"FStar.Tactics.V2.Derived.apply",
"FStar.Tactics.V2.Builtins.dump"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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 | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val magic_dump_t: Prims.unit -> Tac unit | [] | FStar.Tactics.V2.Derived.magic_dump_t | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 4,
"end_line": 714,
"start_col": 2,
"start_line": 711
} |
FStar.Tactics.Effect.Tac | val finish_by (t: (unit -> Tac 'a)) : Tac 'a | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let finish_by (t : unit -> Tac 'a) : Tac 'a =
let x = t () in
or_else qed (fun () -> fail "finish_by: not finished");
x | val finish_by (t: (unit -> Tac 'a)) : Tac 'a
let finish_by (t: (unit -> Tac 'a)) : Tac 'a = | true | null | false | let x = t () in
or_else qed (fun () -> fail "finish_by: not finished");
x | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.or_else",
"FStar.Tactics.V2.Derived.qed",
"FStar.Tactics.V2.Derived.fail"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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]) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val finish_by (t: (unit -> Tac 'a)) : Tac 'a | [] | FStar.Tactics.V2.Derived.finish_by | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: (_: Prims.unit -> FStar.Tactics.Effect.Tac 'a) -> FStar.Tactics.Effect.Tac 'a | {
"end_col": 5,
"end_line": 731,
"start_col": 45,
"start_line": 728
} |
Prims.Admit | val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let admit_dump #a #x () = x () | val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a
let admit_dump #a #x () = | true | null | false | x () | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val admit_dump : #a:Type -> (#[admit_dump_t ()] x : (unit -> Admit a)) -> unit -> Admit a | [] | FStar.Tactics.V2.Derived.admit_dump | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> Prims.Admit a | {
"end_col": 30,
"end_line": 707,
"start_col": 26,
"start_line": 707
} |
FStar.Tactics.Effect.Tac | val rewrite_equality (t: term) : Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let rewrite_equality (t:term) : Tac unit =
try_rewrite_equality t (cur_vars ()) | val rewrite_equality (t: term) : Tac unit
let rewrite_equality (t: term) : Tac unit = | true | null | false | try_rewrite_equality t (cur_vars ()) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"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"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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 ()) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val rewrite_equality (t: term) : Tac unit | [] | FStar.Tactics.V2.Derived.rewrite_equality | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 40,
"end_line": 635,
"start_col": 4,
"start_line": 635
} |
FStar.Tactics.Effect.Tac | val change_sq (t1: term) : Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let change_sq (t1 : term) : Tac unit =
change (mk_e_app (`squash) [t1]) | val change_sq (t1: term) : Tac unit
let change_sq (t1: term) : Tac unit = | true | null | false | change (mk_e_app (`squash) [t1]) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.Builtins.change",
"FStar.Reflection.V2.Derived.mk_e_app",
"Prims.Cons",
"FStar.Reflection.Types.term",
"Prims.Nil",
"Prims.unit"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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]
) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val change_sq (t1: term) : Tac unit | [] | FStar.Tactics.V2.Derived.change_sq | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t1: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 36,
"end_line": 726,
"start_col": 4,
"start_line": 726
} |
FStar.Tactics.Effect.Tac | val iseq (ts: list (unit -> Tac unit)) : Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let rec iseq (ts : list (unit -> Tac unit)) : Tac unit =
match ts with
| t::ts -> let _ = divide 1 t (fun () -> iseq ts) in ()
| [] -> () | val iseq (ts: list (unit -> Tac unit)) : Tac unit
let rec iseq (ts: list (unit -> Tac unit)) : Tac unit = | true | null | false | match ts with
| t :: ts ->
let _ = divide 1 t (fun () -> iseq ts) in
()
| [] -> () | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.list",
"Prims.unit",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.V2.Derived.divide",
"FStar.Tactics.V2.Derived.iseq"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val iseq (ts: list (unit -> Tac unit)) : Tac unit | [
"recursion"
] | FStar.Tactics.V2.Derived.iseq | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | ts: Prims.list (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit)
-> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 17,
"end_line": 324,
"start_col": 4,
"start_line": 322
} |
FStar.Tactics.Effect.Tac | val solve_then (#a #b: _) (t1: (unit -> Tac a)) (t2: (a -> Tac b)) : Tac b | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | 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 | 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 = | true | null | false | dup ();
let x = focus (fun () -> finish_by t1) in
let y = t2 x in
trefl ();
y | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.trefl",
"FStar.Tactics.V2.Derived.focus",
"FStar.Tactics.V2.Derived.finish_by",
"FStar.Tactics.V2.Builtins.dup"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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 | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val solve_then (#a #b: _) (t1: (unit -> Tac a)) (t2: (a -> Tac b)) : Tac b | [] | FStar.Tactics.V2.Derived.solve_then | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t1: (_: Prims.unit -> FStar.Tactics.Effect.Tac a) -> t2: (_: a -> FStar.Tactics.Effect.Tac b)
-> FStar.Tactics.Effect.Tac b | {
"end_col": 5,
"end_line": 738,
"start_col": 4,
"start_line": 734
} |
FStar.Tactics.Effect.Tac | val grewrite (t1 t2: term) : Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | 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 () ->
(* 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 ()) | val grewrite (t1 t2: term) : Tac unit
let grewrite (t1 t2: term) : Tac unit = | true | null | false | 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 ()) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"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.Reflection.Types.typ",
"Prims.nat",
"FStar.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"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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]. | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val grewrite (t1 t2: term) : Tac unit | [] | FStar.Tactics.V2.Derived.grewrite | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t1: FStar.Tactics.NamedView.term -> t2: FStar.Tactics.NamedView.term
-> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 44,
"end_line": 680,
"start_col": 40,
"start_line": 665
} |
FStar.Tactics.Effect.Tac | val specialize: #a: Type -> f: a -> l: list string -> unit -> Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | 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]) | val specialize: #a: Type -> f: a -> l: list string -> unit -> Tac unit
let specialize (#a: Type) (f: a) (l: list string) : unit -> Tac unit = | true | null | false | fun () -> solve_then (fun () -> exact (quote f)) (fun () -> norm [delta_only l; iota; zeta]) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.list",
"Prims.string",
"Prims.unit",
"FStar.Tactics.V2.Derived.solve_then",
"FStar.Tactics.V2.Derived.exact",
"FStar.Tactics.NamedView.term",
"FStar.Reflection.Types.term",
"FStar.Tactics.V2.Builtins.norm",
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.delta_only",
"FStar.Pervasives.iota",
"FStar.Pervasives.zeta",
"Prims.Nil"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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
*) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val specialize: #a: Type -> f: a -> l: list string -> unit -> Tac unit | [] | FStar.Tactics.V2.Derived.specialize | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | f: a -> l: Prims.list Prims.string -> _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 96,
"end_line": 765,
"start_col": 4,
"start_line": 765
} |
FStar.Tactics.Effect.TacH | val cur_goal_safe: Prims.unit
-> TacH goal
(requires (fun ps -> ~(goals_of ps == [])))
(ensures (fun ps0 r -> exists g. r == Success g ps0)) | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | 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 | val cur_goal_safe: Prims.unit
-> TacH goal
(requires (fun ps -> ~(goals_of ps == [])))
(ensures (fun ps0 r -> exists g. r == Success g ps0))
let cur_goal_safe ()
: TacH goal
(requires (fun ps -> ~(goals_of ps == [])))
(ensures (fun ps0 r -> exists g. r == Success g ps0)) = | true | null | false | match goals_of (get ()) with | g :: _ -> g | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.Types.goal",
"Prims.list",
"FStar.Tactics.Types.goals_of",
"FStar.Tactics.Types.proofstate",
"FStar.Tactics.Effect.get",
"Prims.l_not",
"Prims.eq2",
"Prims.Nil",
"FStar.Tactics.Result.__result",
"Prims.l_Exists",
"FStar.Tactics.Result.Success"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 == []))) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val cur_goal_safe: Prims.unit
-> TacH goal
(requires (fun ps -> ~(goals_of ps == [])))
(ensures (fun ps0 r -> exists g. r == Success g ps0)) | [] | FStar.Tactics.V2.Derived.cur_goal_safe | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.TacH FStar.Tactics.Types.goal | {
"end_col": 16,
"end_line": 92,
"start_col": 3,
"start_line": 91
} |
FStar.Tactics.Effect.Tac | val grewrite_eq (b: binding) : Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | 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)]
| _ ->
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 | val grewrite_eq (b: binding) : Tac unit
let grewrite_eq (b: binding) : Tac unit = | true | null | false | 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" | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"FStar.Tactics.NamedView.binding",
"FStar.Pervasives.Native.option",
"FStar.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"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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 *) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val grewrite_eq (b: binding) : Tac unit | [] | FStar.Tactics.V2.Derived.grewrite_eq | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | b: FStar.Tactics.NamedView.binding -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 7,
"end_line": 699,
"start_col": 2,
"start_line": 687
} |
Prims.Tot | val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let magic_dump #a #x () = x | val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a
let magic_dump #a #x () = | false | null | false | x | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [
"total"
] | [
"Prims.unit"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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 (`());
() | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val magic_dump : #a:Type -> (#[magic_dump_t ()] x : a) -> unit -> Tot a | [] | FStar.Tactics.V2.Derived.magic_dump | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> a | {
"end_col": 27,
"end_line": 717,
"start_col": 26,
"start_line": 717
} |
FStar.Tactics.Effect.Tac | val trans: Prims.unit -> Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let trans () : Tac unit = apply_lemma (`lem_trans) | val trans: Prims.unit -> Tac unit
let trans () : Tac unit = | true | null | false | apply_lemma (`lem_trans) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.apply_lemma"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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_binder] 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_binder (-1)]
will return the last binder, [nth_binder (-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 = () | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val trans: Prims.unit -> Tac unit | [] | FStar.Tactics.V2.Derived.trans | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 50,
"end_line": 925,
"start_col": 26,
"start_line": 925
} |
FStar.Tactics.Effect.Tac | val smt_sync: Prims.unit -> Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let smt_sync () : Tac unit = t_smt_sync (get_vconfig ()) | val smt_sync: Prims.unit -> Tac unit
let smt_sync () : Tac unit = | true | null | false | t_smt_sync (get_vconfig ()) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Builtins.t_smt_sync",
"FStar.VConfig.vconfig",
"FStar.Tactics.V2.Builtins.get_vconfig"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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_binder] 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_binder (-1)]
will return the last binder, [nth_binder (-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) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val smt_sync: Prims.unit -> Tac unit | [] | FStar.Tactics.V2.Derived.smt_sync | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 56,
"end_line": 928,
"start_col": 29,
"start_line": 928
} |
FStar.Tactics.Effect.Tac | val branch_on_match: Prims.unit -> Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | 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 (* this one is the equality *)
grewrite_eq b;
norm [iota])
) | val branch_on_match: Prims.unit -> Tac unit
let branch_on_match () : Tac unit = | true | null | false | 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])) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.focus",
"FStar.Tactics.V2.Derived.iterAll",
"FStar.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.Tactics.V2.Builtins.intro",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.Types.fv",
"Prims.nat",
"FStar.Tactics.V2.Builtins.t_destruct",
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.Derived.get_match_body"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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. *) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val branch_on_match: Prims.unit -> Tac unit | [] | FStar.Tactics.V2.Derived.branch_on_match | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 5,
"end_line": 841,
"start_col": 4,
"start_line": 833
} |
FStar.Tactics.Effect.Tac | val smt: Prims.unit -> Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | 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 | val smt: Prims.unit -> Tac unit
let smt () : Tac unit = | true | null | false | match goals (), smt_goals () with
| [], _ -> fail "smt: no active goals"
| g :: gs, gs' ->
set_goals gs;
set_smt_goals (g :: gs') | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"Prims.list",
"FStar.Tactics.Types.goal",
"FStar.Tactics.V2.Derived.fail",
"FStar.Tactics.V2.Builtins.set_smt_goals",
"Prims.Cons",
"FStar.Tactics.V2.Builtins.set_goals",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Tactics.V2.Derived.smt_goals",
"FStar.Tactics.V2.Derived.goals"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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. *) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val smt: Prims.unit -> Tac unit | [] | FStar.Tactics.V2.Derived.smt | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 11,
"end_line": 167,
"start_col": 4,
"start_line": 161
} |
FStar.Tactics.Effect.Tac | val name_appears_in (nm: name) (t: term) : Tac bool | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | 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 | val name_appears_in (nm: name) (t: term) : Tac bool
let name_appears_in (nm: name) (t: term) : Tac bool = | true | null | false | 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": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"FStar.Reflection.Types.name",
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.Derived.try_with",
"Prims.bool",
"Prims.unit",
"FStar.Pervasives.ignore",
"FStar.Reflection.Types.term",
"FStar.Tactics.Visit.visit_tm",
"Prims.exn",
"FStar.Tactics.Effect.raise",
"FStar.Reflection.Types.fv",
"Prims.op_Equality",
"FStar.Reflection.V2.Builtins.inspect_fv",
"FStar.Tactics.V2.Derived.Appears",
"FStar.Tactics.NamedView.named_term_view",
"FStar.Tactics.NamedView.pack",
"FStar.Tactics.NamedView.inspect"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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_binder] 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_binder (-1)]
will return the last binder, [nth_binder (-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 | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val name_appears_in (nm: name) (t: term) : Tac bool | [] | FStar.Tactics.V2.Derived.name_appears_in | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | nm: FStar.Reflection.Types.name -> t: FStar.Tactics.NamedView.term
-> FStar.Tactics.Effect.Tac Prims.bool | {
"end_col": 16,
"end_line": 871,
"start_col": 51,
"start_line": 860
} |
FStar.Tactics.Effect.TAC | val fail (#a: Type) (m: string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let fail (#a:Type) (m:string)
: TAC a (fun ps post -> post (Failed (TacticFailure m) ps))
= raise #a (TacticFailure m) | val fail (#a: Type) (m: string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps))
let fail (#a: Type) (m: string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) = | true | null | false | raise #a (TacticFailure m) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.string",
"FStar.Tactics.Effect.raise",
"FStar.Tactics.Common.TacticFailure",
"FStar.Tactics.Types.proofstate",
"FStar.Tactics.Result.__result",
"FStar.Tactics.Result.Failed"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val fail (#a: Type) (m: string) : TAC a (fun ps post -> post (Failed (TacticFailure m) ps)) | [] | FStar.Tactics.V2.Derived.fail | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | m: Prims.string -> FStar.Tactics.Effect.TAC a | {
"end_col": 30,
"end_line": 64,
"start_col": 4,
"start_line": 64
} |
FStar.Tactics.Effect.Tac | val smt_sync' (fuel ifuel: nat) : Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | 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' | val smt_sync' (fuel ifuel: nat) : Tac unit
let smt_sync' (fuel ifuel: nat) : Tac unit = | true | null | false | 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' | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.nat",
"FStar.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.Tactics.V2.Builtins.get_vconfig"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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_binder] 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_binder (-1)]
will return the last binder, [nth_binder (-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 ()) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val smt_sync' (fuel ifuel: nat) : Tac unit | [] | FStar.Tactics.V2.Derived.smt_sync' | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | fuel: Prims.nat -> ifuel: Prims.nat -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 20,
"end_line": 936,
"start_col": 45,
"start_line": 931
} |
FStar.Tactics.Effect.Tac | val string_to_term_with_lb (letbindings: list (string * term)) (e: env) (t: string) : Tac term | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | 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 | 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 = | true | null | false | 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 | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.string",
"FStar.Tactics.NamedView.term",
"FStar.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.Reflection.Types.term",
"FStar.Tactics.V2.Builtins.string_to_term",
"FStar.Reflection.V2.Data.binding",
"FStar.Pervasives.Native.Mktuple2",
"Prims.Cons",
"FStar.Tactics.V2.Builtins.push_bv_dsenv"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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_binder] 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_binder (-1)]
will return the last binder, [nth_binder (-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)) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val string_to_term_with_lb (letbindings: list (string * term)) (e: env) (t: string) : Tac term | [] | FStar.Tactics.V2.Derived.string_to_term_with_lb | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
letbindings: Prims.list (Prims.string * FStar.Tactics.NamedView.term) ->
e: FStar.Reflection.Types.env ->
t: Prims.string
-> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.term | {
"end_col": 21,
"end_line": 916,
"start_col": 3,
"start_line": 908
} |
FStar.Tactics.Effect.Tac | val iterAll (t: (unit -> Tac unit)) : Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | 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 () | val iterAll (t: (unit -> Tac unit)) : Tac unit
let rec iterAll (t: (unit -> Tac unit)) : Tac unit = | true | null | false | match goals () with
| [] -> ()
| _ :: _ ->
let _ = divide 1 t (fun () -> iterAll t) in
() | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.Types.goal",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.V2.Derived.divide",
"FStar.Tactics.V2.Derived.iterAll",
"FStar.Tactics.V2.Derived.goals"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 = | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val iterAll (t: (unit -> Tac unit)) : Tac unit | [
"recursion"
] | FStar.Tactics.V2.Derived.iterAll | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit) -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 60,
"end_line": 350,
"start_col": 4,
"start_line": 348
} |
FStar.Tactics.Effect.TAC | val fail_silently (#a: Type) (m: string)
: TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | 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) | val fail_silently (#a: Type) (m: string)
: TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps))
let fail_silently (#a: Type) (m: string)
: TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) = | true | null | false | set_urgency 0;
raise #a (TacticFailure m) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.string",
"FStar.Tactics.Effect.raise",
"FStar.Tactics.Common.TacticFailure",
"Prims.unit",
"FStar.Tactics.V2.Builtins.set_urgency",
"FStar.Tactics.Types.proofstate",
"FStar.Tactics.Result.__result",
"Prims.l_Forall",
"FStar.Tactics.Result.Failed",
"Prims.logical"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val fail_silently (#a: Type) (m: string)
: TAC a (fun _ post -> forall ps. post (Failed (TacticFailure m) ps)) | [] | FStar.Tactics.V2.Derived.fail_silently | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | m: Prims.string -> FStar.Tactics.Effect.TAC a | {
"end_col": 30,
"end_line": 69,
"start_col": 4,
"start_line": 68
} |
FStar.Tactics.Effect.Tac | val flip: Prims.unit -> Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | 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) | val flip: Prims.unit -> Tac unit
let flip () : Tac unit = | true | null | false | let gs = goals () in
match goals () with
| [] | [_] -> fail "flip: less than two goals"
| g1 :: g2 :: gs -> set_goals (g2 :: g1 :: gs) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.fail",
"FStar.Tactics.Types.goal",
"Prims.list",
"FStar.Tactics.V2.Builtins.set_goals",
"Prims.Cons",
"FStar.Tactics.V2.Derived.goals"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val flip: Prims.unit -> Tac unit | [] | FStar.Tactics.V2.Derived.flip | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 42,
"end_line": 142,
"start_col": 24,
"start_line": 138
} |
FStar.Tactics.Effect.Tac | val focus (t: (unit -> Tac 'a)) : Tac 'a | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | 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 | val focus (t: (unit -> Tac 'a)) : Tac 'a
let focus (t: (unit -> Tac 'a)) : Tac 'a = | true | null | false | 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 | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.fail",
"FStar.Tactics.Types.goal",
"Prims.list",
"FStar.Tactics.V2.Builtins.set_smt_goals",
"FStar.Tactics.V2.Derived.op_At",
"FStar.Tactics.V2.Derived.smt_goals",
"FStar.Tactics.V2.Builtins.set_goals",
"FStar.Tactics.V2.Derived.goals",
"Prims.Nil",
"Prims.Cons"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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. *) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val focus (t: (unit -> Tac 'a)) : Tac 'a | [] | FStar.Tactics.V2.Derived.focus | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: (_: Prims.unit -> FStar.Tactics.Effect.Tac 'a) -> FStar.Tactics.Effect.Tac 'a | {
"end_col": 9,
"end_line": 336,
"start_col": 4,
"start_line": 329
} |
FStar.Tactics.Effect.Tac | val mapAll (t: (unit -> Tac 'a)) : Tac (list 'a) | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | 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 | val mapAll (t: (unit -> Tac 'a)) : Tac (list 'a)
let rec mapAll (t: (unit -> Tac 'a)) : Tac (list 'a) = | true | null | false | match goals () with
| [] -> []
| _ :: _ ->
let h, t = divide 1 t (fun () -> mapAll t) in
h :: t | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"Prims.Nil",
"Prims.list",
"FStar.Tactics.Types.goal",
"Prims.Cons",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.V2.Derived.divide",
"FStar.Tactics.V2.Derived.mapAll",
"FStar.Tactics.V2.Derived.goals"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val mapAll (t: (unit -> Tac 'a)) : Tac (list 'a) | [
"recursion"
] | FStar.Tactics.V2.Derived.mapAll | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: (_: Prims.unit -> FStar.Tactics.Effect.Tac 'a) -> FStar.Tactics.Effect.Tac (Prims.list 'a) | {
"end_col": 66,
"end_line": 344,
"start_col": 4,
"start_line": 342
} |
FStar.Tactics.Effect.Tac | val divide (n: int) (l: (unit -> Tac 'a)) (r: (unit -> Tac 'b)) : Tac ('a * 'b) | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | 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) | 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) = | true | null | false | 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": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.int",
"Prims.unit",
"Prims.list",
"FStar.Tactics.Types.goal",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.V2.Builtins.set_smt_goals",
"FStar.Tactics.V2.Derived.op_At",
"FStar.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"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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). *) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val divide (n: int) (l: (unit -> Tac 'a)) (r: (unit -> Tac 'b)) : Tac ('a * 'b) | [] | FStar.Tactics.V2.Derived.divide | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
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) | {
"end_col": 10,
"end_line": 319,
"start_col": 4,
"start_line": 305
} |
FStar.Tactics.Effect.Tac | val fresh_namedv_named (s: string) : Tac namedv | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | 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;
}) | val fresh_namedv_named (s: string) : Tac namedv
let fresh_namedv_named (s: string) : Tac namedv = | true | null | false | let n = fresh () in
pack_namedv ({ ppname = seal s; sort = seal (pack Tv_Unknown); uniq = n }) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.string",
"FStar.Tactics.NamedView.pack_namedv",
"FStar.Reflection.V2.Data.Mknamedv_view",
"FStar.Sealed.seal",
"FStar.Reflection.Types.typ",
"FStar.Tactics.NamedView.pack",
"FStar.Tactics.NamedView.Tv_Unknown",
"FStar.Tactics.NamedView.namedv",
"Prims.nat",
"FStar.Tactics.V2.Builtins.fresh"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 ()) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val fresh_namedv_named (s: string) : Tac namedv | [] | FStar.Tactics.V2.Derived.fresh_namedv_named | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: Prims.string -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.namedv | {
"end_col": 4,
"end_line": 394,
"start_col": 48,
"start_line": 388
} |
FStar.Tactics.Effect.Tac | val fresh_implicit_binder (t: typ) : Tac binder | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | 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 = [] ;
} | val fresh_implicit_binder (t: typ) : Tac binder
let fresh_implicit_binder (t: typ) : Tac binder = | true | null | false | let n = fresh () in
{ ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Implicit; attrs = [] } | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"FStar.Reflection.Types.typ",
"FStar.Tactics.NamedView.Mkbinder",
"FStar.Sealed.seal",
"Prims.string",
"Prims.op_Hat",
"Prims.string_of_int",
"FStar.Reflection.V2.Data.Q_Implicit",
"Prims.Nil",
"FStar.Tactics.NamedView.term",
"FStar.Tactics.NamedView.binder",
"Prims.nat",
"FStar.Tactics.V2.Builtins.fresh"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 = [] ;
} | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val fresh_implicit_binder (t: typ) : Tac binder | [] | FStar.Tactics.V2.Derived.fresh_implicit_binder | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Reflection.Types.typ -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.binder | {
"end_col": 3,
"end_line": 434,
"start_col": 50,
"start_line": 426
} |
FStar.Tactics.Effect.Tac | val fresh_binder (t: typ) : Tac simple_binder | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | 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 = [] ;
} | val fresh_binder (t: typ) : Tac simple_binder
let fresh_binder (t: typ) : Tac simple_binder = | true | null | false | let n = fresh () in
{ ppname = seal ("x" ^ string_of_int n); sort = t; uniq = n; qual = Q_Explicit; attrs = [] } | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"FStar.Reflection.Types.typ",
"FStar.Tactics.NamedView.Mkbinder",
"FStar.Sealed.seal",
"Prims.string",
"Prims.op_Hat",
"Prims.string_of_int",
"FStar.Reflection.V2.Data.Q_Explicit",
"Prims.Nil",
"FStar.Tactics.NamedView.term",
"FStar.Tactics.NamedView.simple_binder",
"Prims.nat",
"FStar.Tactics.V2.Builtins.fresh"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 = [] ;
} | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val fresh_binder (t: typ) : Tac simple_binder | [] | FStar.Tactics.V2.Derived.fresh_binder | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Reflection.Types.typ -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.simple_binder | {
"end_col": 3,
"end_line": 424,
"start_col": 48,
"start_line": 416
} |
FStar.Tactics.Effect.TacH | 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)) | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | 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))
(* ^ the proofstate on failure is not exactly equal (has the psc set) *)
=
if not b then
fail "guard failed"
else () | 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)) = | true | null | false | if not b then fail "guard failed" | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.bool",
"Prims.op_Negation",
"FStar.Tactics.V2.Derived.fail",
"Prims.unit",
"FStar.Tactics.Types.proofstate",
"Prims.l_True",
"FStar.Tactics.Result.__result",
"Prims.l_and",
"Prims.b2t",
"FStar.Tactics.Result.uu___is_Success",
"Prims.eq2",
"FStar.Tactics.Result.__proj__Success__item__ps",
"FStar.Tactics.Result.uu___is_Failed"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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) *) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | 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)) | [] | FStar.Tactics.V2.Derived.guard | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | b: Prims.bool -> FStar.Tactics.Effect.TacH Prims.unit | {
"end_col": 11,
"end_line": 444,
"start_col": 4,
"start_line": 442
} |
FStar.Tactics.Effect.Tac | val fresh_binder_named (s: string) (t: typ) : Tac simple_binder | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | 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 = [] ;
} | val fresh_binder_named (s: string) (t: typ) : Tac simple_binder
let fresh_binder_named (s: string) (t: typ) : Tac simple_binder = | true | null | false | let n = fresh () in
{ ppname = seal s; sort = t; uniq = n; qual = Q_Explicit; attrs = [] } | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.string",
"FStar.Reflection.Types.typ",
"FStar.Tactics.NamedView.Mkbinder",
"FStar.Sealed.seal",
"FStar.Reflection.V2.Data.Q_Explicit",
"Prims.Nil",
"FStar.Tactics.NamedView.term",
"FStar.Tactics.NamedView.simple_binder",
"Prims.nat",
"FStar.Tactics.V2.Builtins.fresh"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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;
}) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val fresh_binder_named (s: string) (t: typ) : Tac simple_binder | [] | FStar.Tactics.V2.Derived.fresh_binder_named | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: Prims.string -> t: FStar.Reflection.Types.typ
-> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.simple_binder | {
"end_col": 3,
"end_line": 414,
"start_col": 67,
"start_line": 406
} |
FStar.Tactics.Effect.Tac | val repeat (#a: Type) (t: (unit -> Tac a)) : Tac (list a) | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let rec repeat (#a:Type) (t : unit -> Tac a) : Tac (list a) =
match catch t with
| Inl _ -> []
| Inr x -> x :: repeat t | val repeat (#a: Type) (t: (unit -> Tac a)) : Tac (list a)
let rec repeat (#a: Type) (t: (unit -> Tac a)) : Tac (list a) = | true | null | false | match catch t with
| Inl _ -> []
| Inr x -> x :: repeat t | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"Prims.exn",
"Prims.Nil",
"Prims.list",
"Prims.Cons",
"FStar.Tactics.V2.Derived.repeat",
"FStar.Pervasives.either",
"FStar.Tactics.V2.Builtins.catch"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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") () | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val repeat (#a: Type) (t: (unit -> Tac a)) : Tac (list a) | [
"recursion"
] | FStar.Tactics.V2.Derived.repeat | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: (_: Prims.unit -> FStar.Tactics.Effect.Tac a) -> FStar.Tactics.Effect.Tac (Prims.list a) | {
"end_col": 28,
"end_line": 471,
"start_col": 4,
"start_line": 469
} |
FStar.Tactics.Effect.Tac | val try_rewrite_equality (x: term) (bs: list binding) : Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | 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 | val try_rewrite_equality (x: term) (bs: list binding) : Tac unit
let rec try_rewrite_equality (x: term) (bs: list binding) : Tac unit = | true | null | false | 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 | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"FStar.Tactics.NamedView.term",
"Prims.list",
"FStar.Tactics.NamedView.binding",
"Prims.unit",
"FStar.Pervasives.Native.option",
"FStar.Reflection.Types.typ",
"FStar.Reflection.V2.Builtins.term_eq",
"FStar.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"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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"))
() | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val try_rewrite_equality (x: term) (bs: list binding) : Tac unit | [
"recursion"
] | FStar.Tactics.V2.Derived.try_rewrite_equality | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: FStar.Tactics.NamedView.term -> bs: Prims.list FStar.Tactics.NamedView.binding
-> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 11,
"end_line": 621,
"start_col": 4,
"start_line": 611
} |
FStar.Tactics.Effect.Tac | val rewrite_all_context_equalities (bs: list binding) : Tac unit | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | 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 | val rewrite_all_context_equalities (bs: list binding) : Tac unit
let rec rewrite_all_context_equalities (bs: list binding) : Tac unit = | true | null | false | match bs with
| [] -> ()
| x_t :: bs ->
(try rewrite x_t with | _ -> ());
rewrite_all_context_equalities bs | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.list",
"FStar.Tactics.NamedView.binding",
"Prims.unit",
"FStar.Tactics.V2.Derived.rewrite_all_context_equalities",
"FStar.Tactics.V2.Derived.try_with",
"FStar.Tactics.V2.Builtins.rewrite",
"Prims.exn"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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 | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val rewrite_all_context_equalities (bs: list binding) : Tac unit | [
"recursion"
] | FStar.Tactics.V2.Derived.rewrite_all_context_equalities | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | bs: Prims.list FStar.Tactics.NamedView.binding -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 7,
"end_line": 629,
"start_col": 4,
"start_line": 624
} |
Prims.Tot | val binding_to_simple_binder (b: binding) : Tot simple_binder | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let binding_to_simple_binder (b : binding) : Tot simple_binder =
{
ppname = b.ppname;
uniq = b.uniq;
sort = b.sort;
qual = Q_Explicit;
attrs = [];
} | val binding_to_simple_binder (b: binding) : Tot simple_binder
let binding_to_simple_binder (b: binding) : Tot simple_binder = | false | null | false | { ppname = b.ppname; uniq = b.uniq; sort = b.sort; qual = Q_Explicit; attrs = [] } | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [
"total"
] | [
"FStar.Tactics.NamedView.binding",
"FStar.Tactics.NamedView.Mkbinder",
"FStar.Reflection.V2.Data.__proj__Mkbinding__item__uniq",
"FStar.Reflection.V2.Data.__proj__Mkbinding__item__ppname",
"FStar.Reflection.V2.Data.__proj__Mkbinding__item__sort",
"FStar.Reflection.V2.Data.Q_Explicit",
"Prims.Nil",
"FStar.Tactics.NamedView.term",
"FStar.Tactics.NamedView.simple_binder"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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_binder] 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_binder (-1)]
will return the last binder, [nth_binder (-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 = | false | true | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val binding_to_simple_binder (b: binding) : Tot simple_binder | [] | FStar.Tactics.V2.Derived.binding_to_simple_binder | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | b: FStar.Tactics.NamedView.binding -> FStar.Tactics.NamedView.simple_binder | {
"end_col": 16,
"end_line": 899,
"start_col": 4,
"start_line": 895
} |
FStar.Tactics.Effect.Tac | val get_match_body: Prims.unit -> Tac term | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | 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" | val get_match_body: Prims.unit -> Tac term
let get_match_body () : Tac term = | true | null | false | 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": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.fail",
"FStar.Tactics.NamedView.term",
"FStar.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.Reflection.Types.typ"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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 | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val get_match_body: Prims.unit -> Tac term | [] | FStar.Tactics.V2.Derived.get_match_body | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.term | {
"end_col": 46,
"end_line": 821,
"start_col": 2,
"start_line": 817
} |
FStar.Tactics.Effect.Tac | val last (x: list 'a) : Tac 'a | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let rec last (x : list 'a) : Tac 'a =
match x with
| [] -> fail "last: empty list"
| [x] -> x
| _::xs -> last xs | val last (x: list 'a) : Tac 'a
let rec last (x: list 'a) : Tac 'a = | true | null | false | match x with
| [] -> fail "last: empty list"
| [x] -> x
| _ :: xs -> last xs | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.list",
"FStar.Tactics.V2.Derived.fail",
"FStar.Tactics.V2.Derived.last"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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" | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val last (x: list 'a) : Tac 'a | [
"recursion"
] | FStar.Tactics.V2.Derived.last | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: Prims.list 'a -> FStar.Tactics.Effect.Tac 'a | {
"end_col": 22,
"end_line": 827,
"start_col": 4,
"start_line": 824
} |
Prims.Tot | val extract_nth (n: nat) (l: list 'a) : option ('a * list 'a) | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | 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 -> begin
match extract_nth (n-1) tl with
| Some (hd', tl') -> Some (hd', hd::tl')
| None -> None
end | 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) = | false | null | false | 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 | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [
"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"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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 | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val extract_nth (n: nat) (l: list 'a) : option ('a * list 'a) | [
"recursion"
] | FStar.Tactics.V2.Derived.extract_nth | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | n: Prims.nat -> l: Prims.list 'a -> FStar.Pervasives.Native.option ('a * Prims.list 'a) | {
"end_col": 5,
"end_line": 793,
"start_col": 2,
"start_line": 786
} |
FStar.Tactics.Effect.Tac | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | 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) | let tlabel' (l: string) = | true | null | false | 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": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.string",
"FStar.Tactics.V2.Derived.fail",
"Prims.unit",
"FStar.Tactics.Types.goal",
"Prims.list",
"FStar.Tactics.V2.Builtins.set_goals",
"Prims.Cons",
"FStar.Tactics.Types.set_label",
"Prims.op_Hat",
"FStar.Tactics.Types.get_label",
"FStar.Tactics.V2.Derived.goals"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val tlabel' : l: Prims.string -> FStar.Tactics.Effect.Tac Prims.unit | [] | FStar.Tactics.V2.Derived.tlabel' | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | l: Prims.string -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 26,
"end_line": 778,
"start_col": 4,
"start_line": 774
} |
|
FStar.Tactics.Effect.Tac | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | false | let tlabel (l:string) =
match goals () with
| [] -> fail "tlabel: no goals"
| h::t ->
set_goals (set_label l h :: t) | let tlabel (l: string) = | true | null | false | match goals () with
| [] -> fail "tlabel: no goals"
| h :: t -> set_goals (set_label l h :: t) | {
"checked_file": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"Prims.string",
"FStar.Tactics.V2.Derived.fail",
"Prims.unit",
"FStar.Tactics.Types.goal",
"Prims.list",
"FStar.Tactics.V2.Builtins.set_goals",
"Prims.Cons",
"FStar.Tactics.Types.set_label",
"FStar.Tactics.V2.Derived.goals"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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]) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val tlabel : l: Prims.string -> FStar.Tactics.Effect.Tac Prims.unit | [] | FStar.Tactics.V2.Derived.tlabel | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | l: Prims.string -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 38,
"end_line": 771,
"start_col": 4,
"start_line": 768
} |
|
FStar.Tactics.Effect.Tac | val destruct_list (t: term) : Tac (list term) | [
{
"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.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"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
}
] | 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 | val destruct_list (t: term) : Tac (list term)
let rec destruct_list (t: term) : Tac (list term) = | true | null | false | 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": "FStar.Tactics.V2.Derived.fst.checked",
"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.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.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"
} | [] | [
"FStar.Tactics.NamedView.term",
"Prims.list",
"FStar.Reflection.V2.Data.argv",
"FStar.Reflection.Types.fv",
"FStar.Reflection.Types.term",
"Prims.op_Equality",
"Prims.string",
"FStar.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.Tactics.Common.NotAListLiteral",
"FStar.Pervasives.Native.tuple2",
"FStar.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"
] | [] | (*
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.Types
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.Result
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 =
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) | false | false | FStar.Tactics.V2.Derived.fst | {
"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"
} | null | val destruct_list (t: term) : Tac (list term) | [
"recursion"
] | FStar.Tactics.V2.Derived.destruct_list | {
"file_name": "ulib/FStar.Tactics.V2.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Tactics.NamedView.term
-> FStar.Tactics.Effect.Tac (Prims.list FStar.Tactics.NamedView.term) | {
"end_col": 27,
"end_line": 814,
"start_col": 52,
"start_line": 801
} |
Prims.Tot | val stack_to_s (s:vale_stack) : S.machine_stack | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"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
}
] | false | let stack_to_s s = s | val stack_to_s (s:vale_stack) : S.machine_stack
let stack_to_s s = | false | null | false | s | {
"checked_file": "Vale.X64.Stack_Sems.fst.checked",
"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"
} | [
"total"
] | [
"Vale.X64.Stack_i.vale_stack",
"Vale.X64.Machine_Semantics_s.machine_stack"
] | [] | module Vale.X64.Stack_Sems
open FStar.Mul
friend Vale.X64.Stack_i | false | true | Vale.X64.Stack_Sems.fst | {
"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"
} | null | val stack_to_s (s:vale_stack) : S.machine_stack | [] | Vale.X64.Stack_Sems.stack_to_s | {
"file_name": "vale/code/arch/x64/Vale.X64.Stack_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | s: Vale.X64.Stack_i.vale_stack -> Vale.X64.Machine_Semantics_s.machine_stack | {
"end_col": 20,
"end_line": 6,
"start_col": 19,
"start_line": 6
} |
Prims.Tot | val stack_from_s (s:S.machine_stack) : vale_stack | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"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
}
] | false | let stack_from_s s = s | val stack_from_s (s:S.machine_stack) : vale_stack
let stack_from_s s = | false | null | false | s | {
"checked_file": "Vale.X64.Stack_Sems.fst.checked",
"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"
} | [
"total"
] | [
"Vale.X64.Machine_Semantics_s.machine_stack",
"Vale.X64.Stack_i.vale_stack"
] | [] | module Vale.X64.Stack_Sems
open FStar.Mul
friend Vale.X64.Stack_i | false | true | Vale.X64.Stack_Sems.fst | {
"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"
} | null | val stack_from_s (s:S.machine_stack) : vale_stack | [] | Vale.X64.Stack_Sems.stack_from_s | {
"file_name": "vale/code/arch/x64/Vale.X64.Stack_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | s: Vale.X64.Machine_Semantics_s.machine_stack -> Vale.X64.Stack_i.vale_stack | {
"end_col": 22,
"end_line": 7,
"start_col": 21,
"start_line": 7
} |
FStar.Pervasives.Lemma | 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))] | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"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
}
] | 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 () | 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 = | false | null | true | 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 () | {
"checked_file": "Vale.X64.Stack_Sems.fst.checked",
"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"
} | [
"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"
] | [] | 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 = () | false | false | Vale.X64.Stack_Sems.fst | {
"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"
} | null | 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))] | [] | Vale.X64.Stack_Sems.free_stack_same_load | {
"file_name": "vale/code/arch/x64/Vale.X64.Stack_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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))
] | {
"end_col": 28,
"end_line": 21,
"start_col": 2,
"start_line": 17
} |
FStar.Pervasives.Lemma | 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))] | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"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
}
] | 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 () | 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 = | false | null | true | 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 () | {
"checked_file": "Vale.X64.Stack_Sems.fst.checked",
"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"
} | [
"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"
] | [] | 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 = () | false | false | Vale.X64.Stack_Sems.fst | {
"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"
} | null | 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))] | [] | Vale.X64.Stack_Sems.free_stack_same_load128 | {
"file_name": "vale/code/arch/x64/Vale.X64.Stack_Sems.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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))
] | {
"end_col": 28,
"end_line": 41,
"start_col": 2,
"start_line": 36
} |
Prims.Tot | val return (#a: Type) (x: a) : possibly a | [
{
"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
}
] | false | let return (#a:Type) (x:a) : possibly a =
Ok x | val return (#a: Type) (x: a) : possibly a
let return (#a: Type) (x: a) : possibly a = | false | null | false | Ok x | {
"checked_file": "Vale.Def.PossiblyMonad.fst.checked",
"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"
} | [
"total"
] | [
"Vale.Def.PossiblyMonad.Ok",
"Vale.Def.PossiblyMonad.possibly"
] | [] | 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 | false | false | Vale.Def.PossiblyMonad.fst | {
"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"
} | null | val return (#a: Type) (x: a) : possibly a | [] | Vale.Def.PossiblyMonad.return | {
"file_name": "vale/specs/defs/Vale.Def.PossiblyMonad.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: a -> Vale.Def.PossiblyMonad.possibly a | {
"end_col": 6,
"end_line": 12,
"start_col": 2,
"start_line": 12
} |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.