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
listlengths 0
2
| ideal_premises
listlengths 0
236
| mutual_with
listlengths 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
listlengths 0
1
| name
stringlengths 8
95
| source
dict | verbose_type
stringlengths 1
7.42k
| source_range
dict |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.bool",
"Prims.op_Negation",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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.V1.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.V1.Derived.guard
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 409,
"start_col": 4,
"start_line": 407
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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.V1.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.V1.Derived.fail
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 52,
"start_col": 4,
"start_line": 52
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.list",
"FStar.Pervasives.norm_step",
"FStar.Reflection.Types.term",
"FStar.Tactics.V1.Builtins.norm_term_env",
"FStar.Reflection.Types.env",
"FStar.Tactics.V1.Derived.try_with",
"Prims.unit",
"FStar.Tactics.V1.Derived.cur_env",
"Prims.exn",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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.V1.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.V1.Derived.norm_term
|
{
"file_name": "ulib/FStar.Tactics.V1.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.Reflection.Types.term
-> FStar.Tactics.Effect.Tac FStar.Reflection.Types.term
|
{
"end_col": 23,
"end_line": 449,
"start_col": 58,
"start_line": 444
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.list",
"Prims.unit",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.V1.Derived.divide",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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.V1.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.V1.Derived.iseq
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 313,
"start_col": 4,
"start_line": 311
}
|
FStar.Tactics.Effect.Tac
|
val trytac (t: (unit -> Tac 'a)) : Tac (option '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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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 trytac (t : unit -> Tac 'a) : Tac (option 'a) =
try Some (t ())
with
| _ -> None
|
val trytac (t: (unit -> Tac 'a)) : Tac (option 'a)
let trytac (t: (unit -> Tac 'a)) : Tac (option 'a) =
| true | null | false |
try Some (t ()) with | _ -> None
|
{
"checked_file": "FStar.Tactics.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.unit",
"FStar.Tactics.V1.Derived.try_with",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.Some",
"Prims.exn",
"FStar.Pervasives.Native.None"
] |
[] |
(*
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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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
| false | false |
FStar.Tactics.V1.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 trytac (t: (unit -> Tac 'a)) : Tac (option 'a)
|
[] |
FStar.Tactics.V1.Derived.trytac
|
{
"file_name": "ulib/FStar.Tactics.V1.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 (FStar.Pervasives.Native.option 'a)
|
{
"end_col": 15,
"end_line": 419,
"start_col": 4,
"start_line": 417
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.list",
"Prims.unit",
"FStar.List.Tot.Base.fold_right",
"FStar.Tactics.V1.Derived.op_Less_Bar_Greater",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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.V1.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.V1.Derived.first
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 431,
"start_col": 4,
"start_line": 431
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.unit",
"Prims.Nil",
"Prims.list",
"FStar.Tactics.Types.goal",
"Prims.Cons",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.V1.Derived.divide",
"FStar.Tactics.V1.Derived.mapAll",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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.V1.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.V1.Derived.mapAll
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 333,
"start_col": 4,
"start_line": 331
}
|
FStar.Tactics.Effect.Tac
|
val repeatseq (#a: Type) (t: (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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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 repeatseq (#a:Type) (t : unit -> Tac a) : Tac unit =
let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in ()
|
val repeatseq (#a: Type) (t: (unit -> Tac a)) : Tac unit
let rec repeatseq (#a: Type) (t: (unit -> Tac a)) : Tac unit =
| true | null | false |
let _ = trytac (fun () -> (discard t) `seq` (discard (fun () -> repeatseq t))) in
()
|
{
"checked_file": "FStar.Tactics.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.unit",
"FStar.Pervasives.Native.option",
"FStar.Tactics.V1.Derived.trytac",
"FStar.Tactics.V1.Derived.seq",
"FStar.Tactics.V1.Derived.discard",
"FStar.Tactics.V1.Derived.repeatseq"
] |
[] |
(*
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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 ()
| false | false |
FStar.Tactics.V1.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 repeatseq (#a: Type) (t: (unit -> Tac a)) : Tac unit
|
[
"recursion"
] |
FStar.Tactics.V1.Derived.repeatseq
|
{
"file_name": "ulib/FStar.Tactics.V1.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.unit
|
{
"end_col": 88,
"end_line": 469,
"start_col": 60,
"start_line": 468
}
|
FStar.Tactics.Effect.Tac
|
val repeat1 (#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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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 repeat1 (#a:Type) (t : unit -> Tac a) : Tac (list a) =
t () :: repeat t
|
val repeat1 (#a: Type) (t: (unit -> Tac a)) : Tac (list a)
let repeat1 (#a: Type) (t: (unit -> Tac a)) : Tac (list a) =
| true | null | false |
t () :: repeat t
|
{
"checked_file": "FStar.Tactics.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.unit",
"Prims.Cons",
"Prims.list",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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
| false | false |
FStar.Tactics.V1.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 repeat1 (#a: Type) (t: (unit -> Tac a)) : Tac (list a)
|
[] |
FStar.Tactics.V1.Derived.repeat1
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 20,
"end_line": 439,
"start_col": 4,
"start_line": 439
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.unit",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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.V1.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.V1.Derived.or_else
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 423,
"start_col": 4,
"start_line": 422
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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 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 join_all_smt_goals () =
| true | null | false |
let gs, sgs = goals (), smt_goals () in
set_smt_goals [];
set_goals sgs;
repeat' join;
let sgs' = goals () in
set_goals gs;
set_smt_goals sgs'
|
{
"checked_file": "FStar.Tactics.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.unit",
"Prims.list",
"FStar.Tactics.Types.goal",
"FStar.Tactics.V1.Builtins.set_smt_goals",
"FStar.Tactics.V1.Builtins.set_goals",
"FStar.Tactics.V1.Derived.goals",
"FStar.Tactics.V1.Derived.repeat'",
"FStar.Tactics.V1.Builtins.join",
"Prims.Nil",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Tactics.V1.Derived.smt_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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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
| false | false |
FStar.Tactics.V1.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 join_all_smt_goals : _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
|
[] |
FStar.Tactics.V1.Derived.join_all_smt_goals
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 20,
"end_line": 462,
"start_col": 27,
"start_line": 455
}
|
|
FStar.Tactics.Effect.Tac
|
val pose_as (s: string) (t: term) : 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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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 binder =
let b = pose t in
rename_to b s
|
val pose_as (s: string) (t: term) : Tac binder
let pose_as (s: string) (t: term) : Tac binder =
| true | null | false |
let b = pose t in
rename_to b s
|
{
"checked_file": "FStar.Tactics.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.string",
"FStar.Reflection.Types.term",
"FStar.Tactics.V1.Builtins.rename_to",
"FStar.Reflection.Types.binder",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
| false | false |
FStar.Tactics.V1.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 binder
|
[] |
FStar.Tactics.V1.Derived.pose_as
|
{
"file_name": "ulib/FStar.Tactics.V1.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
s: Prims.string -> t: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac FStar.Reflection.Types.binder
|
{
"end_col": 17,
"end_line": 524,
"start_col": 46,
"start_line": 522
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.unit",
"Prims.list",
"FStar.Tactics.V1.Derived.repeat",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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.V1.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.V1.Derived.admit_all
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 478,
"start_col": 29,
"start_line": 476
}
|
FStar.Tactics.Effect.Tac
|
val discard: tau: (unit -> Tac 'a) -> 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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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 discard (tau : unit -> Tac 'a) : unit -> Tac unit =
fun () -> let _ = tau () in ()
|
val discard: tau: (unit -> Tac 'a) -> unit -> Tac unit
let discard (tau: (unit -> Tac 'a)) : unit -> Tac unit =
| true | null | false |
fun () ->
let _ = tau () in
()
|
{
"checked_file": "FStar.Tactics.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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'
| false | false |
FStar.Tactics.V1.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 discard: tau: (unit -> Tac 'a) -> unit -> Tac unit
|
[] |
FStar.Tactics.V1.Derived.discard
|
{
"file_name": "ulib/FStar.Tactics.V1.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
tau: (_: Prims.unit -> FStar.Tactics.Effect.Tac 'a) -> _: Prims.unit
-> FStar.Tactics.Effect.Tac Prims.unit
|
{
"end_col": 34,
"end_line": 465,
"start_col": 4,
"start_line": 465
}
|
FStar.Tactics.Effect.Tac
|
val intros: Prims.unit -> Tac (list 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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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 binder) = repeat intro
|
val intros: Prims.unit -> Tac (list binder)
let intros () : Tac (list binder) =
| true | null | false |
repeat intro
|
{
"checked_file": "FStar.Tactics.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.unit",
"FStar.Tactics.V1.Derived.repeat",
"FStar.Reflection.Types.binder",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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.V1.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 binder)
|
[] |
FStar.Tactics.V1.Derived.intros
|
{
"file_name": "ulib/FStar.Tactics.V1.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.Reflection.Types.binder)
|
{
"end_col": 48,
"end_line": 497,
"start_col": 36,
"start_line": 497
}
|
FStar.Tactics.Effect.Tac
|
val binder_to_term (b: binder) : 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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
|
val binder_to_term (b: binder) : Tac term
let binder_to_term (b: binder) : Tac term =
| true | null | false |
let bview = inspect_binder b in
bv_to_term bview.binder_bv
|
{
"checked_file": "FStar.Tactics.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"FStar.Reflection.Types.binder",
"FStar.Tactics.V1.Derived.bv_to_term",
"FStar.Reflection.V1.Data.__proj__Mkbinder_view__item__binder_bv",
"FStar.Reflection.Types.term",
"FStar.Reflection.V1.Data.binder_view",
"Prims.precedes",
"FStar.Reflection.V1.Builtins.inspect_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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
| false | false |
FStar.Tactics.V1.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_term (b: binder) : Tac term
|
[] |
FStar.Tactics.V1.Derived.binder_to_term
|
{
"file_name": "ulib/FStar.Tactics.V1.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
b: FStar.Reflection.Types.binder -> FStar.Tactics.Effect.Tac FStar.Reflection.Types.term
|
{
"end_col": 28,
"end_line": 541,
"start_col": 44,
"start_line": 539
}
|
FStar.Tactics.Effect.Tac
|
val bv_to_term (bv: bv) : 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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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 bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
|
val bv_to_term (bv: bv) : Tac term
let bv_to_term (bv: bv) : Tac term =
| true | null | false |
pack (Tv_Var bv)
|
{
"checked_file": "FStar.Tactics.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"FStar.Reflection.Types.bv",
"FStar.Tactics.V1.Builtins.pack",
"FStar.Reflection.V1.Data.Tv_Var",
"FStar.Reflection.Types.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
| false | false |
FStar.Tactics.V1.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 bv_to_term (bv: bv) : Tac term
|
[] |
FStar.Tactics.V1.Derived.bv_to_term
|
{
"file_name": "ulib/FStar.Tactics.V1.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
bv: FStar.Reflection.Types.bv -> FStar.Tactics.Effect.Tac FStar.Reflection.Types.term
|
{
"end_col": 54,
"end_line": 536,
"start_col": 38,
"start_line": 536
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.unit",
"Prims.list",
"FStar.Reflection.Types.binder",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = repeat intro
| false | false |
FStar.Tactics.V1.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.V1.Derived.intros'
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 499,
"start_col": 27,
"start_line": 499
}
|
FStar.Tactics.Effect.Tac
|
val pose (t: term) : 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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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 binder =
apply (`__cut);
flip ();
exact t;
intro ()
|
val pose (t: term) : Tac binder
let pose (t: term) : Tac binder =
| true | null | false |
apply (`__cut);
flip ();
exact t;
intro ()
|
{
"checked_file": "FStar.Tactics.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"FStar.Reflection.Types.term",
"FStar.Tactics.V1.Builtins.intro",
"FStar.Reflection.Types.binder",
"Prims.unit",
"FStar.Tactics.V1.Derived.exact",
"FStar.Tactics.V1.Derived.flip",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
| false | false |
FStar.Tactics.V1.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 binder
|
[] |
FStar.Tactics.V1.Derived.pose
|
{
"file_name": "ulib/FStar.Tactics.V1.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
t: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac FStar.Reflection.Types.binder
|
{
"end_col": 12,
"end_line": 516,
"start_col": 4,
"start_line": 513
}
|
FStar.Tactics.Effect.Tac
|
val assumption: 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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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 assumption () : Tac unit =
__assumption_aux (cur_binders ())
|
val assumption: Prims.unit -> Tac unit
let assumption () : Tac unit =
| true | null | false |
__assumption_aux (cur_binders ())
|
{
"checked_file": "FStar.Tactics.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.unit",
"FStar.Tactics.V1.Derived.__assumption_aux",
"FStar.Reflection.Types.binders",
"FStar.Tactics.V1.Derived.cur_binders"
] |
[] |
(*
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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
| false | false |
FStar.Tactics.V1.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: Prims.unit -> Tac unit
|
[] |
FStar.Tactics.V1.Derived.assumption
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 37,
"end_line": 560,
"start_col": 4,
"start_line": 560
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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_binders ())
|
val rewrite_equality (t: term) : Tac unit
let rewrite_equality (t: term) : Tac unit =
| true | null | false |
try_rewrite_equality t (cur_binders ())
|
{
"checked_file": "FStar.Tactics.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"FStar.Reflection.Types.term",
"FStar.Tactics.V1.Derived.try_rewrite_equality",
"Prims.unit",
"FStar.Reflection.Types.binders",
"FStar.Tactics.V1.Derived.cur_binders"
] |
[] |
(*
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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs ->
begin match term_as_formula (type_of_binder 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:binders) : 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_binders ())
| false | false |
FStar.Tactics.V1.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.V1.Derived.rewrite_equality
|
{
"file_name": "ulib/FStar.Tactics.V1.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
t: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
|
{
"end_col": 43,
"end_line": 610,
"start_col": 4,
"start_line": 610
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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_binders ())
|
val rewrite_eqs_from_context: Prims.unit -> Tac unit
let rewrite_eqs_from_context () : Tac unit =
| true | null | false |
rewrite_all_context_equalities (cur_binders ())
|
{
"checked_file": "FStar.Tactics.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.unit",
"FStar.Tactics.V1.Derived.rewrite_all_context_equalities",
"FStar.Reflection.Types.binders",
"FStar.Tactics.V1.Derived.cur_binders"
] |
[] |
(*
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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs ->
begin match term_as_formula (type_of_binder 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:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs -> begin
(try rewrite x_t with | _ -> ());
rewrite_all_context_equalities bs
end
| false | false |
FStar.Tactics.V1.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.V1.Derived.rewrite_eqs_from_context
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 607,
"start_col": 4,
"start_line": 607
}
|
Prims.Tot
|
val mk_sq_eq (t1 t2: term) : 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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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) : term =
let eq : term = pack_ln (Tv_FVar (pack_fv eq2_qn)) in
mk_squash (mk_e_app eq [t1; t2])
|
val mk_sq_eq (t1 t2: term) : term
let mk_sq_eq (t1 t2: term) : term =
| false | null | false |
let eq:term = pack_ln (Tv_FVar (pack_fv eq2_qn)) in
mk_squash (mk_e_app eq [t1; t2])
|
{
"checked_file": "FStar.Tactics.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[
"total"
] |
[
"FStar.Reflection.Types.term",
"FStar.Tactics.V1.Derived.mk_squash",
"FStar.Reflection.V1.Derived.mk_e_app",
"Prims.Cons",
"Prims.Nil",
"FStar.Reflection.V1.Builtins.pack_ln",
"FStar.Reflection.V1.Data.Tv_FVar",
"FStar.Reflection.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs ->
begin match term_as_formula (type_of_binder 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:binders) : 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_binders ())
let rewrite_equality (t:term) : Tac unit =
try_rewrite_equality t (cur_binders ())
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) : term =
let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in
mk_e_app sq [t]
| false | true |
FStar.Tactics.V1.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) : term
|
[] |
FStar.Tactics.V1.Derived.mk_sq_eq
|
{
"file_name": "ulib/FStar.Tactics.V1.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
t1: FStar.Reflection.Types.term -> t2: FStar.Reflection.Types.term -> FStar.Reflection.Types.term
|
{
"end_col": 36,
"end_line": 636,
"start_col": 36,
"start_line": 634
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.unit",
"FStar.Tactics.V1.Derived.fail",
"FStar.Tactics.Types.goal",
"Prims.list",
"FStar.Tactics.V1.Builtins.set_goals",
"Prims.Cons",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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.V1.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.V1.Derived.flip
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 131,
"start_col": 24,
"start_line": 127
}
|
FStar.Tactics.Effect.Tac
|
val rewrite' (b: binder) : 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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
|
val rewrite' (b: binder) : Tac unit
let rewrite' (b: binder) : Tac unit =
| true | null | false |
((fun () -> rewrite b) <|>
(fun () ->
binder_retype b;
apply_lemma (`__eq_sym);
rewrite b) <|>
(fun () -> fail "rewrite' failed")) ()
|
{
"checked_file": "FStar.Tactics.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"FStar.Reflection.Types.binder",
"FStar.Tactics.V1.Derived.op_Less_Bar_Greater",
"Prims.unit",
"FStar.Tactics.V1.Builtins.rewrite",
"FStar.Tactics.V1.Derived.apply_lemma",
"FStar.Tactics.V1.Builtins.binder_retype",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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.V1.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' (b: binder) : Tac unit
|
[] |
FStar.Tactics.V1.Derived.rewrite'
|
{
"file_name": "ulib/FStar.Tactics.V1.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
b: FStar.Reflection.Types.binder -> FStar.Tactics.Effect.Tac Prims.unit
|
{
"end_col": 6,
"end_line": 583,
"start_col": 4,
"start_line": 578
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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_ln (Tv_Var (bv_of_binder 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_ln 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_ln (Tv_Var (bv_of_binder e)) in
pointwise (fun () ->
let is_uvar =
match term_as_formula (cur_goal ()) with
| Comp (Eq _) lhs rhs ->
(match inspect_ln lhs with
| Tv_Uvar _ _ -> true
| _ -> false)
| _ -> false
in
if is_uvar then trefl () else try exact e with | _ -> trefl ())
|
{
"checked_file": "FStar.Tactics.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"FStar.Reflection.Types.term",
"FStar.Tactics.V1.Derived.pointwise",
"Prims.unit",
"FStar.Tactics.V1.Derived.trefl",
"Prims.bool",
"FStar.Tactics.V1.Derived.try_with",
"FStar.Tactics.V1.Derived.exact",
"Prims.exn",
"FStar.Pervasives.Native.option",
"FStar.Reflection.Types.typ",
"FStar.Reflection.V1.Builtins.inspect_ln",
"Prims.nat",
"FStar.Reflection.Types.ctx_uvar_and_subst",
"FStar.Reflection.V1.Data.term_view",
"FStar.Reflection.V1.Formula.formula",
"FStar.Reflection.V1.Formula.term_as_formula",
"FStar.Tactics.V1.Derived.cur_goal",
"FStar.Reflection.V1.Builtins.pack_ln",
"FStar.Reflection.V1.Data.Tv_Var",
"FStar.Reflection.V1.Derived.bv_of_binder",
"FStar.Reflection.Types.binder",
"FStar.Tactics.V1.Derived.tcut",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs ->
begin match term_as_formula (type_of_binder 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:binders) : 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_binders ())
let rewrite_equality (t:term) : Tac unit =
try_rewrite_equality t (cur_binders ())
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) : term =
let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in
mk_e_app sq [t]
let mk_sq_eq (t1 t2 : term) : term =
let eq : term = pack_ln (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.V1.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.V1.Derived.grewrite
|
{
"file_name": "ulib/FStar.Tactics.V1.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
t1: FStar.Reflection.Types.term -> t2: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac Prims.unit
|
{
"end_col": 44,
"end_line": 655,
"start_col": 40,
"start_line": 640
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.string",
"FStar.Tactics.Effect.raise",
"FStar.Tactics.Common.TacticFailure",
"Prims.unit",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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.V1.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.V1.Derived.fail_silently
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 57,
"start_col": 4,
"start_line": 56
}
|
FStar.Tactics.Effect.Tac
|
val l_to_r (lems: list 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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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 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
|
val l_to_r (lems: list term) : Tac unit
let l_to_r (lems: list term) : Tac unit =
| true | null | false |
let first_or_trefl () : Tac unit =
fold_left (fun k l () -> (fun () -> apply_lemma_rw l) `or_else` k) trefl lems ()
in
pointwise first_or_trefl
|
{
"checked_file": "FStar.Tactics.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.list",
"FStar.Reflection.Types.term",
"FStar.Tactics.V1.Derived.pointwise",
"Prims.unit",
"FStar.Tactics.Util.fold_left",
"FStar.Tactics.V1.Derived.or_else",
"FStar.Tactics.V1.Derived.apply_lemma_rw",
"FStar.Tactics.V1.Derived.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs ->
begin match term_as_formula (type_of_binder 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:binders) : 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_binders ())
let rewrite_equality (t:term) : Tac unit =
try_rewrite_equality t (cur_binders ())
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
| false | false |
FStar.Tactics.V1.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 l_to_r (lems: list term) : Tac unit
|
[] |
FStar.Tactics.V1.Derived.l_to_r
|
{
"file_name": "ulib/FStar.Tactics.V1.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
lems: Prims.list FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
|
{
"end_col": 28,
"end_line": 628,
"start_col": 40,
"start_line": 622
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.list",
"FStar.Tactics.V1.Derived.fail",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs ->
begin match term_as_formula (type_of_binder 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:binders) : 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_binders ())
let rewrite_equality (t:term) : Tac unit =
try_rewrite_equality t (cur_binders ())
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) : term =
let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in
mk_e_app sq [t]
let mk_sq_eq (t1 t2 : term) : term =
let eq : term = pack_ln (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_ln (Tv_Var (bv_of_binder 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_ln 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:binder) : Tac unit =
match term_as_formula (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> exact (binder_to_term b))]
| _ ->
begin match term_as_formula' (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq);
exact (binder_to_term b))]
| _ ->
fail "grewrite_eq: binder type is not an equality"
end
private val push1 : (#p:Type) -> (#q:Type) ->
squash (p ==> q) ->
squash p ->
squash q
private let push1 #p #q f u = ()
private val push1' : (#p:Type) -> (#q:Type) ->
(p ==> q) ->
squash p ->
squash q
private let push1' #p #q f u = ()
(*
* Some easier applying, which should prevent frustration
* (or cause more when it doesn't do what you wanted to)
*)
val apply_squash_or_lem : d:nat -> term -> Tac unit
let rec apply_squash_or_lem d t =
(* Before anything, try a vanilla apply and apply_lemma *)
try apply t with | _ ->
try apply (`FStar.Squash.return_squash); apply t with | _ ->
try apply_lemma t with | _ ->
// Fuel cutoff, just in case.
if d <= 0 then fail "mapply: out of fuel" else begin
let ty = tc (cur_env ()) t in
let tys, c = collect_arr ty in
match inspect_comp c with
| C_Lemma pre post _ ->
begin
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' post with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
| C_Total rt ->
begin match unsquash_term rt with
(* If the function returns a squash, just apply it, since our goals are squashed *)
| Some rt ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
(* If not, we can try to introduce the squash ourselves first *)
| None ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
apply (`FStar.Squash.return_squash);
apply t
end
end
| _ -> fail "mapply: can't apply (2)"
end
(* `m` is for `magic` *)
let mapply (t : term) : Tac unit =
apply_squash_or_lem 10 t
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_ln 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.V1.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.V1.Derived.last
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 885,
"start_col": 4,
"start_line": 882
}
|
FStar.Tactics.Effect.Tac
|
val admit_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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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_t () : Tac unit =
dump "Admitting";
apply (`admit)
|
val admit_dump_t: Prims.unit -> Tac unit
let admit_dump_t () : Tac unit =
| true | null | false |
dump "Admitting";
apply (`admit)
|
{
"checked_file": "FStar.Tactics.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.unit",
"FStar.Tactics.V1.Derived.apply",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs ->
begin match term_as_formula (type_of_binder 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:binders) : 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_binders ())
let rewrite_equality (t:term) : Tac unit =
try_rewrite_equality t (cur_binders ())
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) : term =
let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in
mk_e_app sq [t]
let mk_sq_eq (t1 t2 : term) : term =
let eq : term = pack_ln (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_ln (Tv_Var (bv_of_binder 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_ln 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:binder) : Tac unit =
match term_as_formula (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> exact (binder_to_term b))]
| _ ->
begin match term_as_formula' (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq);
exact (binder_to_term b))]
| _ ->
fail "grewrite_eq: binder type is not an equality"
end
private val push1 : (#p:Type) -> (#q:Type) ->
squash (p ==> q) ->
squash p ->
squash q
private let push1 #p #q f u = ()
private val push1' : (#p:Type) -> (#q:Type) ->
(p ==> q) ->
squash p ->
squash q
private let push1' #p #q f u = ()
(*
* Some easier applying, which should prevent frustration
* (or cause more when it doesn't do what you wanted to)
*)
val apply_squash_or_lem : d:nat -> term -> Tac unit
let rec apply_squash_or_lem d t =
(* Before anything, try a vanilla apply and apply_lemma *)
try apply t with | _ ->
try apply (`FStar.Squash.return_squash); apply t with | _ ->
try apply_lemma t with | _ ->
// Fuel cutoff, just in case.
if d <= 0 then fail "mapply: out of fuel" else begin
let ty = tc (cur_env ()) t in
let tys, c = collect_arr ty in
match inspect_comp c with
| C_Lemma pre post _ ->
begin
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' post with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
| C_Total rt ->
begin match unsquash_term rt with
(* If the function returns a squash, just apply it, since our goals are squashed *)
| Some rt ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
(* If not, we can try to introduce the squash ourselves first *)
| None ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
apply (`FStar.Squash.return_squash);
apply t
end
end
| _ -> fail "mapply: can't apply (2)"
end
(* `m` is for `magic` *)
let mapply (t : term) : Tac unit =
apply_squash_or_lem 10 t
private
| false | false |
FStar.Tactics.V1.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_t: Prims.unit -> Tac unit
|
[] |
FStar.Tactics.V1.Derived.admit_dump_t
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 762,
"start_col": 2,
"start_line": 761
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs ->
begin match term_as_formula (type_of_binder 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:binders) : 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_binders ())
let rewrite_equality (t:term) : Tac unit =
try_rewrite_equality t (cur_binders ())
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) : term =
let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in
mk_e_app sq [t]
let mk_sq_eq (t1 t2 : term) : term =
let eq : term = pack_ln (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_ln (Tv_Var (bv_of_binder 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_ln 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:binder) : Tac unit =
match term_as_formula (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> exact (binder_to_term b))]
| _ ->
begin match term_as_formula' (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq);
exact (binder_to_term b))]
| _ ->
fail "grewrite_eq: binder type is not an equality"
end
private val push1 : (#p:Type) -> (#q:Type) ->
squash (p ==> q) ->
squash p ->
squash q
private let push1 #p #q f u = ()
private val push1' : (#p:Type) -> (#q:Type) ->
(p ==> q) ->
squash p ->
squash q
private let push1' #p #q f u = ()
(*
* Some easier applying, which should prevent frustration
* (or cause more when it doesn't do what you wanted to)
*)
val apply_squash_or_lem : d:nat -> term -> Tac unit
let rec apply_squash_or_lem d t =
(* Before anything, try a vanilla apply and apply_lemma *)
try apply t with | _ ->
try apply (`FStar.Squash.return_squash); apply t with | _ ->
try apply_lemma t with | _ ->
// Fuel cutoff, just in case.
if d <= 0 then fail "mapply: out of fuel" else begin
let ty = tc (cur_env ()) t in
let tys, c = collect_arr ty in
match inspect_comp c with
| C_Lemma pre post _ ->
begin
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' post with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
| C_Total rt ->
begin match unsquash_term rt with
(* If the function returns a squash, just apply it, since our goals are squashed *)
| Some rt ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
(* If not, we can try to introduce the squash ourselves first *)
| None ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
apply (`FStar.Squash.return_squash);
apply t
end
end
| _ -> fail "mapply: can't apply (2)"
end
(* `m` is for `magic` *)
let mapply (t : term) : Tac unit =
apply_squash_or_lem 10 t
private
let admit_dump_t () : Tac unit =
dump "Admitting";
apply (`admit)
| false | false |
FStar.Tactics.V1.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.V1.Derived.admit_dump
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 765,
"start_col": 26,
"start_line": 765
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.unit",
"FStar.Tactics.V1.Derived.exact",
"FStar.Tactics.V1.Derived.apply",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs ->
begin match term_as_formula (type_of_binder 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:binders) : 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_binders ())
let rewrite_equality (t:term) : Tac unit =
try_rewrite_equality t (cur_binders ())
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) : term =
let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in
mk_e_app sq [t]
let mk_sq_eq (t1 t2 : term) : term =
let eq : term = pack_ln (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_ln (Tv_Var (bv_of_binder 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_ln 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:binder) : Tac unit =
match term_as_formula (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> exact (binder_to_term b))]
| _ ->
begin match term_as_formula' (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq);
exact (binder_to_term b))]
| _ ->
fail "grewrite_eq: binder type is not an equality"
end
private val push1 : (#p:Type) -> (#q:Type) ->
squash (p ==> q) ->
squash p ->
squash q
private let push1 #p #q f u = ()
private val push1' : (#p:Type) -> (#q:Type) ->
(p ==> q) ->
squash p ->
squash q
private let push1' #p #q f u = ()
(*
* Some easier applying, which should prevent frustration
* (or cause more when it doesn't do what you wanted to)
*)
val apply_squash_or_lem : d:nat -> term -> Tac unit
let rec apply_squash_or_lem d t =
(* Before anything, try a vanilla apply and apply_lemma *)
try apply t with | _ ->
try apply (`FStar.Squash.return_squash); apply t with | _ ->
try apply_lemma t with | _ ->
// Fuel cutoff, just in case.
if d <= 0 then fail "mapply: out of fuel" else begin
let ty = tc (cur_env ()) t in
let tys, c = collect_arr ty in
match inspect_comp c with
| C_Lemma pre post _ ->
begin
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' post with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
| C_Total rt ->
begin match unsquash_term rt with
(* If the function returns a squash, just apply it, since our goals are squashed *)
| Some rt ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
(* If not, we can try to introduce the squash ourselves first *)
| None ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
apply (`FStar.Squash.return_squash);
apply t
end
end
| _ -> fail "mapply: can't apply (2)"
end
(* `m` is for `magic` *)
let mapply (t : term) : Tac unit =
apply_squash_or_lem 10 t
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.V1.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.V1.Derived.magic_dump_t
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 772,
"start_col": 2,
"start_line": 769
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.unit",
"Prims.list",
"FStar.Tactics.Types.goal",
"FStar.Tactics.V1.Derived.fail",
"FStar.Tactics.V1.Builtins.set_smt_goals",
"Prims.Cons",
"FStar.Tactics.V1.Builtins.set_goals",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Tactics.V1.Derived.smt_goals",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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.V1.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.V1.Derived.smt
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 156,
"start_col": 4,
"start_line": 150
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs ->
begin match term_as_formula (type_of_binder 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:binders) : 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_binders ())
let rewrite_equality (t:term) : Tac unit =
try_rewrite_equality t (cur_binders ())
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) : term =
let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in
mk_e_app sq [t]
let mk_sq_eq (t1 t2 : term) : term =
let eq : term = pack_ln (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_ln (Tv_Var (bv_of_binder 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_ln 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:binder) : Tac unit =
match term_as_formula (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> exact (binder_to_term b))]
| _ ->
begin match term_as_formula' (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq);
exact (binder_to_term b))]
| _ ->
fail "grewrite_eq: binder type is not an equality"
end
private val push1 : (#p:Type) -> (#q:Type) ->
squash (p ==> q) ->
squash p ->
squash q
private let push1 #p #q f u = ()
private val push1' : (#p:Type) -> (#q:Type) ->
(p ==> q) ->
squash p ->
squash q
private let push1' #p #q f u = ()
(*
* Some easier applying, which should prevent frustration
* (or cause more when it doesn't do what you wanted to)
*)
val apply_squash_or_lem : d:nat -> term -> Tac unit
let rec apply_squash_or_lem d t =
(* Before anything, try a vanilla apply and apply_lemma *)
try apply t with | _ ->
try apply (`FStar.Squash.return_squash); apply t with | _ ->
try apply_lemma t with | _ ->
// Fuel cutoff, just in case.
if d <= 0 then fail "mapply: out of fuel" else begin
let ty = tc (cur_env ()) t in
let tys, c = collect_arr ty in
match inspect_comp c with
| C_Lemma pre post _ ->
begin
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' post with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
| C_Total rt ->
begin match unsquash_term rt with
(* If the function returns a squash, just apply it, since our goals are squashed *)
| Some rt ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
(* If not, we can try to introduce the squash ourselves first *)
| None ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
apply (`FStar.Squash.return_squash);
apply t
end
end
| _ -> fail "mapply: can't apply (2)"
end
(* `m` is for `magic` *)
let mapply (t : term) : Tac unit =
apply_squash_or_lem 10 t
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.V1.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.V1.Derived.magic_dump
|
{
"file_name": "ulib/FStar.Tactics.V1.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
_: Prims.unit -> a
|
{
"end_col": 27,
"end_line": 775,
"start_col": 26,
"start_line": 775
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"FStar.Reflection.Types.term",
"FStar.Tactics.V1.Builtins.change",
"FStar.Reflection.V1.Derived.mk_e_app",
"Prims.Cons",
"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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs ->
begin match term_as_formula (type_of_binder 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:binders) : 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_binders ())
let rewrite_equality (t:term) : Tac unit =
try_rewrite_equality t (cur_binders ())
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) : term =
let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in
mk_e_app sq [t]
let mk_sq_eq (t1 t2 : term) : term =
let eq : term = pack_ln (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_ln (Tv_Var (bv_of_binder 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_ln 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:binder) : Tac unit =
match term_as_formula (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> exact (binder_to_term b))]
| _ ->
begin match term_as_formula' (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq);
exact (binder_to_term b))]
| _ ->
fail "grewrite_eq: binder type is not an equality"
end
private val push1 : (#p:Type) -> (#q:Type) ->
squash (p ==> q) ->
squash p ->
squash q
private let push1 #p #q f u = ()
private val push1' : (#p:Type) -> (#q:Type) ->
(p ==> q) ->
squash p ->
squash q
private let push1' #p #q f u = ()
(*
* Some easier applying, which should prevent frustration
* (or cause more when it doesn't do what you wanted to)
*)
val apply_squash_or_lem : d:nat -> term -> Tac unit
let rec apply_squash_or_lem d t =
(* Before anything, try a vanilla apply and apply_lemma *)
try apply t with | _ ->
try apply (`FStar.Squash.return_squash); apply t with | _ ->
try apply_lemma t with | _ ->
// Fuel cutoff, just in case.
if d <= 0 then fail "mapply: out of fuel" else begin
let ty = tc (cur_env ()) t in
let tys, c = collect_arr ty in
match inspect_comp c with
| C_Lemma pre post _ ->
begin
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' post with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
| C_Total rt ->
begin match unsquash_term rt with
(* If the function returns a squash, just apply it, since our goals are squashed *)
| Some rt ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
(* If not, we can try to introduce the squash ourselves first *)
| None ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
apply (`FStar.Squash.return_squash);
apply t
end
end
| _ -> fail "mapply: can't apply (2)"
end
(* `m` is for `magic` *)
let mapply (t : term) : Tac unit =
apply_squash_or_lem 10 t
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.V1.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.V1.Derived.change_sq
|
{
"file_name": "ulib/FStar.Tactics.V1.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
t1: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
|
{
"end_col": 36,
"end_line": 784,
"start_col": 4,
"start_line": 784
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.unit",
"FStar.Tactics.V1.Derived.or_else",
"FStar.Tactics.V1.Derived.qed",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs ->
begin match term_as_formula (type_of_binder 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:binders) : 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_binders ())
let rewrite_equality (t:term) : Tac unit =
try_rewrite_equality t (cur_binders ())
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) : term =
let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in
mk_e_app sq [t]
let mk_sq_eq (t1 t2 : term) : term =
let eq : term = pack_ln (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_ln (Tv_Var (bv_of_binder 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_ln 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:binder) : Tac unit =
match term_as_formula (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> exact (binder_to_term b))]
| _ ->
begin match term_as_formula' (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq);
exact (binder_to_term b))]
| _ ->
fail "grewrite_eq: binder type is not an equality"
end
private val push1 : (#p:Type) -> (#q:Type) ->
squash (p ==> q) ->
squash p ->
squash q
private let push1 #p #q f u = ()
private val push1' : (#p:Type) -> (#q:Type) ->
(p ==> q) ->
squash p ->
squash q
private let push1' #p #q f u = ()
(*
* Some easier applying, which should prevent frustration
* (or cause more when it doesn't do what you wanted to)
*)
val apply_squash_or_lem : d:nat -> term -> Tac unit
let rec apply_squash_or_lem d t =
(* Before anything, try a vanilla apply and apply_lemma *)
try apply t with | _ ->
try apply (`FStar.Squash.return_squash); apply t with | _ ->
try apply_lemma t with | _ ->
// Fuel cutoff, just in case.
if d <= 0 then fail "mapply: out of fuel" else begin
let ty = tc (cur_env ()) t in
let tys, c = collect_arr ty in
match inspect_comp c with
| C_Lemma pre post _ ->
begin
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' post with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
| C_Total rt ->
begin match unsquash_term rt with
(* If the function returns a squash, just apply it, since our goals are squashed *)
| Some rt ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
(* If not, we can try to introduce the squash ourselves first *)
| None ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
apply (`FStar.Squash.return_squash);
apply t
end
end
| _ -> fail "mapply: can't apply (2)"
end
(* `m` is for `magic` *)
let mapply (t : term) : Tac unit =
apply_squash_or_lem 10 t
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.V1.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.V1.Derived.finish_by
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 789,
"start_col": 45,
"start_line": 786
}
|
FStar.Tactics.Effect.Tac
|
val focus_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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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_all () : Tac unit =
set_goals (goals () @ smt_goals ());
set_smt_goals []
|
val focus_all: Prims.unit -> Tac unit
let focus_all () : Tac unit =
| true | null | false |
set_goals (goals () @ smt_goals ());
set_smt_goals []
|
{
"checked_file": "FStar.Tactics.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.unit",
"FStar.Tactics.V1.Builtins.set_smt_goals",
"Prims.Nil",
"FStar.Tactics.Types.goal",
"FStar.Tactics.V1.Builtins.set_goals",
"Prims.list",
"FStar.Tactics.V1.Derived.op_At",
"FStar.Tactics.V1.Derived.smt_goals",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs ->
begin match term_as_formula (type_of_binder 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:binders) : 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_binders ())
let rewrite_equality (t:term) : Tac unit =
try_rewrite_equality t (cur_binders ())
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) : term =
let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in
mk_e_app sq [t]
let mk_sq_eq (t1 t2 : term) : term =
let eq : term = pack_ln (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_ln (Tv_Var (bv_of_binder 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_ln 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:binder) : Tac unit =
match term_as_formula (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> exact (binder_to_term b))]
| _ ->
begin match term_as_formula' (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq);
exact (binder_to_term b))]
| _ ->
fail "grewrite_eq: binder type is not an equality"
end
private val push1 : (#p:Type) -> (#q:Type) ->
squash (p ==> q) ->
squash p ->
squash q
private let push1 #p #q f u = ()
private val push1' : (#p:Type) -> (#q:Type) ->
(p ==> q) ->
squash p ->
squash q
private let push1' #p #q f u = ()
(*
* Some easier applying, which should prevent frustration
* (or cause more when it doesn't do what you wanted to)
*)
val apply_squash_or_lem : d:nat -> term -> Tac unit
let rec apply_squash_or_lem d t =
(* Before anything, try a vanilla apply and apply_lemma *)
try apply t with | _ ->
try apply (`FStar.Squash.return_squash); apply t with | _ ->
try apply_lemma t with | _ ->
// Fuel cutoff, just in case.
if d <= 0 then fail "mapply: out of fuel" else begin
let ty = tc (cur_env ()) t in
let tys, c = collect_arr ty in
match inspect_comp c with
| C_Lemma pre post _ ->
begin
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' post with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
| C_Total rt ->
begin match unsquash_term rt with
(* If the function returns a squash, just apply it, since our goals are squashed *)
| Some rt ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
(* If not, we can try to introduce the squash ourselves first *)
| None ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
apply (`FStar.Squash.return_squash);
apply t
end
end
| _ -> fail "mapply: can't apply (2)"
end
(* `m` is for `magic` *)
let mapply (t : term) : Tac unit =
apply_squash_or_lem 10 t
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)
| false | false |
FStar.Tactics.V1.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_all: Prims.unit -> Tac unit
|
[] |
FStar.Tactics.V1.Derived.focus_all
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 20,
"end_line": 840,
"start_col": 4,
"start_line": 839
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.list",
"Prims.string",
"Prims.unit",
"FStar.Tactics.V1.Derived.solve_then",
"FStar.Tactics.V1.Derived.exact",
"FStar.Reflection.Types.term",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs ->
begin match term_as_formula (type_of_binder 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:binders) : 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_binders ())
let rewrite_equality (t:term) : Tac unit =
try_rewrite_equality t (cur_binders ())
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) : term =
let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in
mk_e_app sq [t]
let mk_sq_eq (t1 t2 : term) : term =
let eq : term = pack_ln (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_ln (Tv_Var (bv_of_binder 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_ln 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:binder) : Tac unit =
match term_as_formula (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> exact (binder_to_term b))]
| _ ->
begin match term_as_formula' (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq);
exact (binder_to_term b))]
| _ ->
fail "grewrite_eq: binder type is not an equality"
end
private val push1 : (#p:Type) -> (#q:Type) ->
squash (p ==> q) ->
squash p ->
squash q
private let push1 #p #q f u = ()
private val push1' : (#p:Type) -> (#q:Type) ->
(p ==> q) ->
squash p ->
squash q
private let push1' #p #q f u = ()
(*
* Some easier applying, which should prevent frustration
* (or cause more when it doesn't do what you wanted to)
*)
val apply_squash_or_lem : d:nat -> term -> Tac unit
let rec apply_squash_or_lem d t =
(* Before anything, try a vanilla apply and apply_lemma *)
try apply t with | _ ->
try apply (`FStar.Squash.return_squash); apply t with | _ ->
try apply_lemma t with | _ ->
// Fuel cutoff, just in case.
if d <= 0 then fail "mapply: out of fuel" else begin
let ty = tc (cur_env ()) t in
let tys, c = collect_arr ty in
match inspect_comp c with
| C_Lemma pre post _ ->
begin
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' post with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
| C_Total rt ->
begin match unsquash_term rt with
(* If the function returns a squash, just apply it, since our goals are squashed *)
| Some rt ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
(* If not, we can try to introduce the squash ourselves first *)
| None ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
apply (`FStar.Squash.return_squash);
apply t
end
end
| _ -> fail "mapply: can't apply (2)"
end
(* `m` is for `magic` *)
let mapply (t : term) : Tac unit =
apply_squash_or_lem 10 t
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.V1.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.V1.Derived.specialize
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 823,
"start_col": 4,
"start_line": 823
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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.V1.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.V1.Derived.cur_goal_safe
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 80,
"start_col": 3,
"start_line": 79
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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_ln t with
| Tv_FVar fv ->
if inspect_fv fv = nm then
raise Appears;
t
| _ -> t
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_ln t with
| Tv_FVar fv ->
if inspect_fv fv = nm then raise Appears;
t
| _ -> t
in
try
(ignore (V.visit_tm ff t);
false)
with
| Appears -> true
| e -> raise e
|
{
"checked_file": "FStar.Tactics.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"FStar.Reflection.Types.name",
"FStar.Reflection.Types.term",
"FStar.Tactics.V1.Derived.try_with",
"Prims.bool",
"Prims.unit",
"FStar.Pervasives.ignore",
"FStar.Tactics.Visit.visit_tm",
"Prims.exn",
"FStar.Tactics.Effect.raise",
"FStar.Reflection.V1.Builtins.inspect_ln",
"FStar.Reflection.Types.fv",
"Prims.op_Equality",
"FStar.Reflection.V1.Builtins.inspect_fv",
"FStar.Tactics.V1.Derived.Appears",
"FStar.Reflection.V1.Data.term_view"
] |
[] |
(*
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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs ->
begin match term_as_formula (type_of_binder 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:binders) : 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_binders ())
let rewrite_equality (t:term) : Tac unit =
try_rewrite_equality t (cur_binders ())
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) : term =
let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in
mk_e_app sq [t]
let mk_sq_eq (t1 t2 : term) : term =
let eq : term = pack_ln (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_ln (Tv_Var (bv_of_binder 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_ln 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:binder) : Tac unit =
match term_as_formula (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> exact (binder_to_term b))]
| _ ->
begin match term_as_formula' (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq);
exact (binder_to_term b))]
| _ ->
fail "grewrite_eq: binder type is not an equality"
end
private val push1 : (#p:Type) -> (#q:Type) ->
squash (p ==> q) ->
squash p ->
squash q
private let push1 #p #q f u = ()
private val push1' : (#p:Type) -> (#q:Type) ->
(p ==> q) ->
squash p ->
squash q
private let push1' #p #q f u = ()
(*
* Some easier applying, which should prevent frustration
* (or cause more when it doesn't do what you wanted to)
*)
val apply_squash_or_lem : d:nat -> term -> Tac unit
let rec apply_squash_or_lem d t =
(* Before anything, try a vanilla apply and apply_lemma *)
try apply t with | _ ->
try apply (`FStar.Squash.return_squash); apply t with | _ ->
try apply_lemma t with | _ ->
// Fuel cutoff, just in case.
if d <= 0 then fail "mapply: out of fuel" else begin
let ty = tc (cur_env ()) t in
let tys, c = collect_arr ty in
match inspect_comp c with
| C_Lemma pre post _ ->
begin
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' post with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
| C_Total rt ->
begin match unsquash_term rt with
(* If the function returns a squash, just apply it, since our goals are squashed *)
| Some rt ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
(* If not, we can try to introduce the squash ourselves first *)
| None ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
apply (`FStar.Squash.return_squash);
apply t
end
end
| _ -> fail "mapply: can't apply (2)"
end
(* `m` is for `magic` *)
let mapply (t : term) : Tac unit =
apply_squash_or_lem 10 t
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_ln 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_binder (i:int) : Tac binder =
let bs = cur_binders () 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.V1.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.V1.Derived.name_appears_in
|
{
"file_name": "ulib/FStar.Tactics.V1.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
nm: FStar.Reflection.Types.name -> t: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac Prims.bool
|
{
"end_col": 16,
"end_line": 929,
"start_col": 51,
"start_line": 918
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.unit",
"FStar.Tactics.V1.Derived.trefl",
"FStar.Tactics.V1.Derived.focus",
"FStar.Tactics.V1.Derived.finish_by",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs ->
begin match term_as_formula (type_of_binder 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:binders) : 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_binders ())
let rewrite_equality (t:term) : Tac unit =
try_rewrite_equality t (cur_binders ())
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) : term =
let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in
mk_e_app sq [t]
let mk_sq_eq (t1 t2 : term) : term =
let eq : term = pack_ln (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_ln (Tv_Var (bv_of_binder 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_ln 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:binder) : Tac unit =
match term_as_formula (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> exact (binder_to_term b))]
| _ ->
begin match term_as_formula' (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq);
exact (binder_to_term b))]
| _ ->
fail "grewrite_eq: binder type is not an equality"
end
private val push1 : (#p:Type) -> (#q:Type) ->
squash (p ==> q) ->
squash p ->
squash q
private let push1 #p #q f u = ()
private val push1' : (#p:Type) -> (#q:Type) ->
(p ==> q) ->
squash p ->
squash q
private let push1' #p #q f u = ()
(*
* Some easier applying, which should prevent frustration
* (or cause more when it doesn't do what you wanted to)
*)
val apply_squash_or_lem : d:nat -> term -> Tac unit
let rec apply_squash_or_lem d t =
(* Before anything, try a vanilla apply and apply_lemma *)
try apply t with | _ ->
try apply (`FStar.Squash.return_squash); apply t with | _ ->
try apply_lemma t with | _ ->
// Fuel cutoff, just in case.
if d <= 0 then fail "mapply: out of fuel" else begin
let ty = tc (cur_env ()) t in
let tys, c = collect_arr ty in
match inspect_comp c with
| C_Lemma pre post _ ->
begin
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' post with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
| C_Total rt ->
begin match unsquash_term rt with
(* If the function returns a squash, just apply it, since our goals are squashed *)
| Some rt ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
(* If not, we can try to introduce the squash ourselves first *)
| None ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
apply (`FStar.Squash.return_squash);
apply t
end
end
| _ -> fail "mapply: can't apply (2)"
end
(* `m` is for `magic` *)
let mapply (t : term) : Tac unit =
apply_squash_or_lem 10 t
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.V1.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.V1.Derived.solve_then
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 796,
"start_col": 4,
"start_line": 792
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.unit",
"FStar.Tactics.V1.Derived.fail",
"FStar.Tactics.Types.goal",
"Prims.list",
"FStar.Tactics.V1.Builtins.set_goals",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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.V1.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.V1.Derived.dismiss
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 124,
"start_col": 4,
"start_line": 122
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.unit",
"FStar.Tactics.Types.goal",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.V1.Derived.divide",
"FStar.Tactics.V1.Derived.iterAll",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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.V1.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.V1.Derived.iterAll
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 339,
"start_col": 4,
"start_line": 337
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.unit",
"FStar.Tactics.V1.Derived.fail",
"FStar.Tactics.Types.goal",
"Prims.list",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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.V1.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.V1.Derived._cur_goal
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 63,
"start_col": 4,
"start_line": 61
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.unit",
"FStar.Tactics.V1.Derived.fail",
"FStar.Tactics.Types.goal",
"Prims.list",
"FStar.Tactics.V1.Builtins.set_smt_goals",
"FStar.Tactics.V1.Derived.op_At",
"FStar.Tactics.V1.Derived.smt_goals",
"FStar.Tactics.V1.Builtins.set_goals",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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.V1.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.V1.Derived.focus
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 325,
"start_col": 4,
"start_line": 318
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.int",
"Prims.unit",
"Prims.list",
"FStar.Tactics.Types.goal",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.V1.Builtins.set_smt_goals",
"FStar.Tactics.V1.Derived.op_At",
"FStar.Tactics.V1.Builtins.set_goals",
"FStar.Tactics.V1.Derived.smt_goals",
"FStar.Tactics.V1.Derived.goals",
"Prims.Nil",
"FStar.List.Tot.Base.splitAt",
"Prims.op_LessThan",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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.V1.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.V1.Derived.divide
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 308,
"start_col": 4,
"start_line": 294
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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.V1.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.V1.Derived.__eq_sym
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 574,
"start_col": 2,
"start_line": 574
}
|
FStar.Tactics.Effect.Tac
|
val __assumption_aux (bs: binders) : 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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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 (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
|
val __assumption_aux (bs: binders) : Tac unit
let rec __assumption_aux (bs: binders) : Tac unit =
| true | null | false |
match bs with
| [] -> fail "no assumption matches goal"
| b :: bs ->
let t = binder_to_term b in
try exact t
with
| _ ->
try
(apply (`FStar.Squash.return_squash);
exact t)
with
| _ -> __assumption_aux bs
|
{
"checked_file": "FStar.Tactics.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"FStar.Reflection.Types.binders",
"FStar.Tactics.V1.Derived.fail",
"Prims.unit",
"FStar.Reflection.Types.binder",
"Prims.list",
"FStar.Tactics.V1.Derived.try_with",
"FStar.Tactics.V1.Derived.exact",
"Prims.exn",
"FStar.Tactics.V1.Derived.apply",
"FStar.Tactics.V1.Derived.__assumption_aux",
"FStar.Reflection.Types.term",
"FStar.Tactics.V1.Derived.binder_to_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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
| false | false |
FStar.Tactics.V1.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 (bs: binders) : Tac unit
|
[
"recursion"
] |
FStar.Tactics.V1.Derived.__assumption_aux
|
{
"file_name": "ulib/FStar.Tactics.V1.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
bs: FStar.Reflection.Types.binders -> FStar.Tactics.Effect.Tac Prims.unit
|
{
"end_col": 27,
"end_line": 557,
"start_col": 4,
"start_line": 549
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.unit",
"Prims.exn",
"FStar.Pervasives.either",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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.V1.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.V1.Derived.try_with
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 414,
"start_col": 4,
"start_line": 412
}
|
FStar.Tactics.Effect.Tac
|
val rewrite_all_context_equalities (bs: binders) : 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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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:binders) : 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: binders) : Tac unit
let rec rewrite_all_context_equalities (bs: binders) : 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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"FStar.Reflection.Types.binders",
"Prims.unit",
"FStar.Reflection.Types.binder",
"Prims.list",
"FStar.Tactics.V1.Derived.rewrite_all_context_equalities",
"FStar.Tactics.V1.Derived.try_with",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs ->
begin match term_as_formula (type_of_binder 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.V1.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: binders) : Tac unit
|
[
"recursion"
] |
FStar.Tactics.V1.Derived.rewrite_all_context_equalities
|
{
"file_name": "ulib/FStar.Tactics.V1.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
bs: FStar.Reflection.Types.binders -> FStar.Tactics.Effect.Tac Prims.unit
|
{
"end_col": 7,
"end_line": 604,
"start_col": 4,
"start_line": 599
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.unit",
"Prims.exn",
"Prims.Nil",
"Prims.list",
"Prims.Cons",
"FStar.Tactics.V1.Derived.repeat",
"FStar.Pervasives.either",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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.V1.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.V1.Derived.repeat
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 436,
"start_col": 4,
"start_line": 434
}
|
FStar.Tactics.Effect.Tac
|
val try_rewrite_equality (x: term) (bs: binders) : 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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs ->
begin match term_as_formula (type_of_binder 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: binders) : Tac unit
let rec try_rewrite_equality (x: term) (bs: binders) : Tac unit =
| true | null | false |
match bs with
| [] -> ()
| x_t :: bs ->
match term_as_formula (type_of_binder 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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"FStar.Reflection.Types.term",
"FStar.Reflection.Types.binders",
"Prims.unit",
"FStar.Reflection.Types.binder",
"Prims.list",
"FStar.Pervasives.Native.option",
"FStar.Reflection.Types.typ",
"FStar.Reflection.V1.Builtins.term_eq",
"FStar.Tactics.V1.Builtins.rewrite",
"Prims.bool",
"FStar.Tactics.V1.Derived.try_rewrite_equality",
"FStar.Reflection.V1.Formula.formula",
"FStar.Reflection.V1.Formula.term_as_formula",
"FStar.Reflection.V1.Derived.type_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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
| false | false |
FStar.Tactics.V1.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: binders) : Tac unit
|
[
"recursion"
] |
FStar.Tactics.V1.Derived.try_rewrite_equality
|
{
"file_name": "ulib/FStar.Tactics.V1.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
x: FStar.Reflection.Types.term -> bs: FStar.Reflection.Types.binders
-> FStar.Tactics.Effect.Tac Prims.unit
|
{
"end_col": 11,
"end_line": 596,
"start_col": 4,
"start_line": 586
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.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.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs ->
begin match term_as_formula (type_of_binder 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:binders) : 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_binders ())
let rewrite_equality (t:term) : Tac unit =
try_rewrite_equality t (cur_binders ())
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) : term =
let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in
mk_e_app sq [t]
let mk_sq_eq (t1 t2 : term) : term =
let eq : term = pack_ln (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_ln (Tv_Var (bv_of_binder 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_ln 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:binder) : Tac unit =
match term_as_formula (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> exact (binder_to_term b))]
| _ ->
begin match term_as_formula' (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq);
exact (binder_to_term b))]
| _ ->
fail "grewrite_eq: binder type is not an equality"
end
private val push1 : (#p:Type) -> (#q:Type) ->
squash (p ==> q) ->
squash p ->
squash q
private let push1 #p #q f u = ()
private val push1' : (#p:Type) -> (#q:Type) ->
(p ==> q) ->
squash p ->
squash q
private let push1' #p #q f u = ()
(*
* Some easier applying, which should prevent frustration
* (or cause more when it doesn't do what you wanted to)
*)
val apply_squash_or_lem : d:nat -> term -> Tac unit
let rec apply_squash_or_lem d t =
(* Before anything, try a vanilla apply and apply_lemma *)
try apply t with | _ ->
try apply (`FStar.Squash.return_squash); apply t with | _ ->
try apply_lemma t with | _ ->
// Fuel cutoff, just in case.
if d <= 0 then fail "mapply: out of fuel" else begin
let ty = tc (cur_env ()) t in
let tys, c = collect_arr ty in
match inspect_comp c with
| C_Lemma pre post _ ->
begin
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' post with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
| C_Total rt ->
begin match unsquash_term rt with
(* If the function returns a squash, just apply it, since our goals are squashed *)
| Some rt ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
(* If not, we can try to introduce the squash ourselves first *)
| None ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
apply (`FStar.Squash.return_squash);
apply t
end
end
| _ -> fail "mapply: can't apply (2)"
end
(* `m` is for `magic` *)
let mapply (t : term) : Tac unit =
apply_squash_or_lem 10 t
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.V1.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.V1.Derived.extract_nth
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 851,
"start_col": 2,
"start_line": 844
}
|
FStar.Tactics.Effect.Tac
|
val apply_squash_or_lem : d:nat -> 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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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 apply_squash_or_lem d t =
(* Before anything, try a vanilla apply and apply_lemma *)
try apply t with | _ ->
try apply (`FStar.Squash.return_squash); apply t with | _ ->
try apply_lemma t with | _ ->
// Fuel cutoff, just in case.
if d <= 0 then fail "mapply: out of fuel" else begin
let ty = tc (cur_env ()) t in
let tys, c = collect_arr ty in
match inspect_comp c with
| C_Lemma pre post _ ->
begin
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' post with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
| C_Total rt ->
begin match unsquash_term rt with
(* If the function returns a squash, just apply it, since our goals are squashed *)
| Some rt ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
(* If not, we can try to introduce the squash ourselves first *)
| None ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
apply (`FStar.Squash.return_squash);
apply t
end
end
| _ -> fail "mapply: can't apply (2)"
end
|
val apply_squash_or_lem : d:nat -> term -> Tac unit
let rec apply_squash_or_lem d t =
| true | null | false |
try apply t
with
| _ ->
try
(apply (`FStar.Squash.return_squash);
apply t)
with
| _ ->
try apply_lemma t
with
| _ ->
if d <= 0
then fail "mapply: out of fuel"
else
let ty = tc (cur_env ()) t in
let tys, c = collect_arr ty in
match inspect_comp c with
| C_Lemma pre post _ ->
let post = `((`#post) ()) in
let post = norm_term [] post in
(match term_as_formula' post with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d - 1) t
| _ -> fail "mapply: can't apply (1)")
| C_Total rt ->
(match unsquash_term rt with
| Some rt ->
let rt = norm_term [] rt in
(match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d - 1) t
| _ -> fail "mapply: can't apply (1)")
| None ->
let rt = norm_term [] rt in
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d - 1) t
| _ ->
apply (`FStar.Squash.return_squash);
apply t)
| _ -> fail "mapply: can't apply (2)"
|
{
"checked_file": "FStar.Tactics.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.nat",
"FStar.Reflection.Types.term",
"FStar.Tactics.V1.Derived.try_with",
"Prims.unit",
"FStar.Tactics.V1.Derived.apply",
"Prims.exn",
"FStar.Tactics.V1.Derived.apply_lemma",
"Prims.op_LessThanOrEqual",
"FStar.Tactics.V1.Derived.fail",
"Prims.bool",
"Prims.list",
"FStar.Reflection.Types.typ",
"FStar.Reflection.Types.comp",
"FStar.Reflection.V1.Builtins.inspect_comp",
"FStar.Tactics.V1.Derived.apply_squash_or_lem",
"Prims.op_Subtraction",
"FStar.Reflection.V1.Formula.formula",
"FStar.Reflection.V1.Formula.term_as_formula'",
"FStar.Tactics.V1.Derived.norm_term",
"Prims.Nil",
"FStar.Pervasives.norm_step",
"FStar.Reflection.V1.Derived.unsquash_term",
"FStar.Reflection.V1.Data.comp_view",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.V1.SyntaxHelpers.collect_arr",
"FStar.Tactics.V1.Builtins.tc",
"FStar.Reflection.Types.env",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs ->
begin match term_as_formula (type_of_binder 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:binders) : 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_binders ())
let rewrite_equality (t:term) : Tac unit =
try_rewrite_equality t (cur_binders ())
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) : term =
let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in
mk_e_app sq [t]
let mk_sq_eq (t1 t2 : term) : term =
let eq : term = pack_ln (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_ln (Tv_Var (bv_of_binder 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_ln 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:binder) : Tac unit =
match term_as_formula (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> exact (binder_to_term b))]
| _ ->
begin match term_as_formula' (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq);
exact (binder_to_term b))]
| _ ->
fail "grewrite_eq: binder type is not an equality"
end
private val push1 : (#p:Type) -> (#q:Type) ->
squash (p ==> q) ->
squash p ->
squash q
private let push1 #p #q f u = ()
private val push1' : (#p:Type) -> (#q:Type) ->
(p ==> q) ->
squash p ->
squash q
private let push1' #p #q f u = ()
(*
* Some easier applying, which should prevent frustration
* (or cause more when it doesn't do what you wanted to)
*)
val apply_squash_or_lem : d:nat -> term -> Tac unit
let rec apply_squash_or_lem d t =
| false | false |
FStar.Tactics.V1.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_squash_or_lem : d:nat -> term -> Tac unit
|
[
"recursion"
] |
FStar.Tactics.V1.Derived.apply_squash_or_lem
|
{
"file_name": "ulib/FStar.Tactics.V1.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
d: Prims.nat -> t: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
|
{
"end_col": 7,
"end_line": 752,
"start_col": 4,
"start_line": 695
}
|
FStar.Tactics.Effect.Tac
|
val nth_binder (i: int) : 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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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_binder (i:int) : Tac binder =
let bs = cur_binders () 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_binder (i: int) : Tac binder
let nth_binder (i: int) : Tac binder =
| true | null | false |
let bs = cur_binders () 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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.int",
"FStar.List.Tot.Base.nth",
"FStar.Reflection.Types.binder",
"FStar.Tactics.V1.Derived.fail",
"Prims.nat",
"Prims.op_LessThan",
"Prims.bool",
"Prims.op_GreaterThanOrEqual",
"Prims.op_Addition",
"FStar.List.Tot.Base.length",
"FStar.Reflection.Types.binders",
"FStar.Tactics.V1.Derived.cur_binders"
] |
[] |
(*
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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs ->
begin match term_as_formula (type_of_binder 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:binders) : 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_binders ())
let rewrite_equality (t:term) : Tac unit =
try_rewrite_equality t (cur_binders ())
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) : term =
let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in
mk_e_app sq [t]
let mk_sq_eq (t1 t2 : term) : term =
let eq : term = pack_ln (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_ln (Tv_Var (bv_of_binder 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_ln 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:binder) : Tac unit =
match term_as_formula (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> exact (binder_to_term b))]
| _ ->
begin match term_as_formula' (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq);
exact (binder_to_term b))]
| _ ->
fail "grewrite_eq: binder type is not an equality"
end
private val push1 : (#p:Type) -> (#q:Type) ->
squash (p ==> q) ->
squash p ->
squash q
private let push1 #p #q f u = ()
private val push1' : (#p:Type) -> (#q:Type) ->
(p ==> q) ->
squash p ->
squash q
private let push1' #p #q f u = ()
(*
* Some easier applying, which should prevent frustration
* (or cause more when it doesn't do what you wanted to)
*)
val apply_squash_or_lem : d:nat -> term -> Tac unit
let rec apply_squash_or_lem d t =
(* Before anything, try a vanilla apply and apply_lemma *)
try apply t with | _ ->
try apply (`FStar.Squash.return_squash); apply t with | _ ->
try apply_lemma t with | _ ->
// Fuel cutoff, just in case.
if d <= 0 then fail "mapply: out of fuel" else begin
let ty = tc (cur_env ()) t in
let tys, c = collect_arr ty in
match inspect_comp c with
| C_Lemma pre post _ ->
begin
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' post with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
| C_Total rt ->
begin match unsquash_term rt with
(* If the function returns a squash, just apply it, since our goals are squashed *)
| Some rt ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
(* If not, we can try to introduce the squash ourselves first *)
| None ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
apply (`FStar.Squash.return_squash);
apply t
end
end
| _ -> fail "mapply: can't apply (2)"
end
(* `m` is for `magic` *)
let mapply (t : term) : Tac unit =
apply_squash_or_lem 10 t
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_ln 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.V1.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_binder (i: int) : Tac binder
|
[] |
FStar.Tactics.V1.Derived.nth_binder
|
{
"file_name": "ulib/FStar.Tactics.V1.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
i: Prims.int -> FStar.Tactics.Effect.Tac FStar.Reflection.Types.binder
|
{
"end_col": 15,
"end_line": 912,
"start_col": 37,
"start_line": 906
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.pos",
"FStar.Tactics.V1.Derived.fail",
"Prims.unit",
"FStar.Tactics.Types.goal",
"Prims.list",
"FStar.Tactics.V1.Builtins.set_goals",
"Prims.Cons",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.V1.Derived.extract_nth",
"Prims.op_Subtraction",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs ->
begin match term_as_formula (type_of_binder 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:binders) : 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_binders ())
let rewrite_equality (t:term) : Tac unit =
try_rewrite_equality t (cur_binders ())
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) : term =
let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in
mk_e_app sq [t]
let mk_sq_eq (t1 t2 : term) : term =
let eq : term = pack_ln (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_ln (Tv_Var (bv_of_binder 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_ln 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:binder) : Tac unit =
match term_as_formula (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> exact (binder_to_term b))]
| _ ->
begin match term_as_formula' (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq);
exact (binder_to_term b))]
| _ ->
fail "grewrite_eq: binder type is not an equality"
end
private val push1 : (#p:Type) -> (#q:Type) ->
squash (p ==> q) ->
squash p ->
squash q
private let push1 #p #q f u = ()
private val push1' : (#p:Type) -> (#q:Type) ->
(p ==> q) ->
squash p ->
squash q
private let push1' #p #q f u = ()
(*
* Some easier applying, which should prevent frustration
* (or cause more when it doesn't do what you wanted to)
*)
val apply_squash_or_lem : d:nat -> term -> Tac unit
let rec apply_squash_or_lem d t =
(* Before anything, try a vanilla apply and apply_lemma *)
try apply t with | _ ->
try apply (`FStar.Squash.return_squash); apply t with | _ ->
try apply_lemma t with | _ ->
// Fuel cutoff, just in case.
if d <= 0 then fail "mapply: out of fuel" else begin
let ty = tc (cur_env ()) t in
let tys, c = collect_arr ty in
match inspect_comp c with
| C_Lemma pre post _ ->
begin
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' post with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
| C_Total rt ->
begin match unsquash_term rt with
(* If the function returns a squash, just apply it, since our goals are squashed *)
| Some rt ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
(* If not, we can try to introduce the squash ourselves first *)
| None ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
apply (`FStar.Squash.return_squash);
apply t
end
end
| _ -> fail "mapply: can't apply (2)"
end
(* `m` is for `magic` *)
let mapply (t : term) : Tac unit =
apply_squash_or_lem 10 t
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.V1.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.V1.Derived.bump_nth
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 857,
"start_col": 2,
"start_line": 855
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[
""
] |
[
"Prims.list",
"FStar.Reflection.Types.binder",
"FStar.Reflection.Types.term",
"FStar.Tactics.V1.Builtins.pack",
"FStar.Reflection.V1.Data.Tv_Abs",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs ->
begin match term_as_formula (type_of_binder 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:binders) : 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_binders ())
let rewrite_equality (t:term) : Tac unit =
try_rewrite_equality t (cur_binders ())
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) : term =
let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in
mk_e_app sq [t]
let mk_sq_eq (t1 t2 : term) : term =
let eq : term = pack_ln (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_ln (Tv_Var (bv_of_binder 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_ln 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:binder) : Tac unit =
match term_as_formula (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> exact (binder_to_term b))]
| _ ->
begin match term_as_formula' (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq);
exact (binder_to_term b))]
| _ ->
fail "grewrite_eq: binder type is not an equality"
end
private val push1 : (#p:Type) -> (#q:Type) ->
squash (p ==> q) ->
squash p ->
squash q
private let push1 #p #q f u = ()
private val push1' : (#p:Type) -> (#q:Type) ->
(p ==> q) ->
squash p ->
squash q
private let push1' #p #q f u = ()
(*
* Some easier applying, which should prevent frustration
* (or cause more when it doesn't do what you wanted to)
*)
val apply_squash_or_lem : d:nat -> term -> Tac unit
let rec apply_squash_or_lem d t =
(* Before anything, try a vanilla apply and apply_lemma *)
try apply t with | _ ->
try apply (`FStar.Squash.return_squash); apply t with | _ ->
try apply_lemma t with | _ ->
// Fuel cutoff, just in case.
if d <= 0 then fail "mapply: out of fuel" else begin
let ty = tc (cur_env ()) t in
let tys, c = collect_arr ty in
match inspect_comp c with
| C_Lemma pre post _ ->
begin
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' post with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
| C_Total rt ->
begin match unsquash_term rt with
(* If the function returns a squash, just apply it, since our goals are squashed *)
| Some rt ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
(* If not, we can try to introduce the squash ourselves first *)
| None ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
apply (`FStar.Squash.return_squash);
apply t
end
end
| _ -> fail "mapply: can't apply (2)"
end
(* `m` is for `magic` *)
let mapply (t : term) : Tac unit =
apply_squash_or_lem 10 t
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_ln 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_binder (i:int) : Tac binder =
let bs = cur_binders () 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_ln t with
| Tv_FVar fv ->
if inspect_fv fv = nm then
raise Appears;
t
| _ -> t
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.V1.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.V1.Derived.mk_abs
|
{
"file_name": "ulib/FStar.Tactics.V1.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
args: Prims.list FStar.Reflection.Types.binder -> t: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac FStar.Reflection.Types.term
|
{
"end_col": 22,
"end_line": 937,
"start_col": 2,
"start_line": 933
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.unit",
"FStar.Tactics.V1.Derived.fail",
"FStar.Reflection.Types.term",
"FStar.Pervasives.Native.option",
"FStar.Reflection.Types.match_returns_ascription",
"Prims.list",
"FStar.Reflection.V1.Data.branch",
"FStar.Reflection.V1.Data.term_view",
"Prims.b2t",
"FStar.Reflection.V1.Data.notAscription",
"FStar.Tactics.V1.SyntaxHelpers.inspect_unascribe",
"FStar.Reflection.V1.Derived.unsquash_term",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs ->
begin match term_as_formula (type_of_binder 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:binders) : 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_binders ())
let rewrite_equality (t:term) : Tac unit =
try_rewrite_equality t (cur_binders ())
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) : term =
let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in
mk_e_app sq [t]
let mk_sq_eq (t1 t2 : term) : term =
let eq : term = pack_ln (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_ln (Tv_Var (bv_of_binder 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_ln 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:binder) : Tac unit =
match term_as_formula (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> exact (binder_to_term b))]
| _ ->
begin match term_as_formula' (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq);
exact (binder_to_term b))]
| _ ->
fail "grewrite_eq: binder type is not an equality"
end
private val push1 : (#p:Type) -> (#q:Type) ->
squash (p ==> q) ->
squash p ->
squash q
private let push1 #p #q f u = ()
private val push1' : (#p:Type) -> (#q:Type) ->
(p ==> q) ->
squash p ->
squash q
private let push1' #p #q f u = ()
(*
* Some easier applying, which should prevent frustration
* (or cause more when it doesn't do what you wanted to)
*)
val apply_squash_or_lem : d:nat -> term -> Tac unit
let rec apply_squash_or_lem d t =
(* Before anything, try a vanilla apply and apply_lemma *)
try apply t with | _ ->
try apply (`FStar.Squash.return_squash); apply t with | _ ->
try apply_lemma t with | _ ->
// Fuel cutoff, just in case.
if d <= 0 then fail "mapply: out of fuel" else begin
let ty = tc (cur_env ()) t in
let tys, c = collect_arr ty in
match inspect_comp c with
| C_Lemma pre post _ ->
begin
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' post with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
| C_Total rt ->
begin match unsquash_term rt with
(* If the function returns a squash, just apply it, since our goals are squashed *)
| Some rt ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
(* If not, we can try to introduce the squash ourselves first *)
| None ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
apply (`FStar.Squash.return_squash);
apply t
end
end
| _ -> fail "mapply: can't apply (2)"
end
(* `m` is for `magic` *)
let mapply (t : term) : Tac unit =
apply_squash_or_lem 10 t
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_ln 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.V1.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.V1.Derived.get_match_body
|
{
"file_name": "ulib/FStar.Tactics.V1.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.term
|
{
"end_col": 46,
"end_line": 879,
"start_col": 2,
"start_line": 875
}
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.string",
"FStar.Tactics.V1.Derived.fail",
"Prims.unit",
"FStar.Tactics.Types.goal",
"Prims.list",
"FStar.Tactics.V1.Builtins.set_goals",
"Prims.Cons",
"FStar.Tactics.Types.set_label",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs ->
begin match term_as_formula (type_of_binder 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:binders) : 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_binders ())
let rewrite_equality (t:term) : Tac unit =
try_rewrite_equality t (cur_binders ())
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) : term =
let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in
mk_e_app sq [t]
let mk_sq_eq (t1 t2 : term) : term =
let eq : term = pack_ln (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_ln (Tv_Var (bv_of_binder 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_ln 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:binder) : Tac unit =
match term_as_formula (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> exact (binder_to_term b))]
| _ ->
begin match term_as_formula' (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq);
exact (binder_to_term b))]
| _ ->
fail "grewrite_eq: binder type is not an equality"
end
private val push1 : (#p:Type) -> (#q:Type) ->
squash (p ==> q) ->
squash p ->
squash q
private let push1 #p #q f u = ()
private val push1' : (#p:Type) -> (#q:Type) ->
(p ==> q) ->
squash p ->
squash q
private let push1' #p #q f u = ()
(*
* Some easier applying, which should prevent frustration
* (or cause more when it doesn't do what you wanted to)
*)
val apply_squash_or_lem : d:nat -> term -> Tac unit
let rec apply_squash_or_lem d t =
(* Before anything, try a vanilla apply and apply_lemma *)
try apply t with | _ ->
try apply (`FStar.Squash.return_squash); apply t with | _ ->
try apply_lemma t with | _ ->
// Fuel cutoff, just in case.
if d <= 0 then fail "mapply: out of fuel" else begin
let ty = tc (cur_env ()) t in
let tys, c = collect_arr ty in
match inspect_comp c with
| C_Lemma pre post _ ->
begin
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' post with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
| C_Total rt ->
begin match unsquash_term rt with
(* If the function returns a squash, just apply it, since our goals are squashed *)
| Some rt ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
(* If not, we can try to introduce the squash ourselves first *)
| None ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
apply (`FStar.Squash.return_squash);
apply t
end
end
| _ -> fail "mapply: can't apply (2)"
end
(* `m` is for `magic` *)
let mapply (t : term) : Tac unit =
apply_squash_or_lem 10 t
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.V1.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.V1.Derived.tlabel
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 829,
"start_col": 4,
"start_line": 826
}
|
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"Prims.string",
"FStar.Tactics.V1.Derived.fail",
"Prims.unit",
"FStar.Tactics.Types.goal",
"Prims.list",
"FStar.Tactics.V1.Builtins.set_goals",
"Prims.Cons",
"FStar.Tactics.Types.set_label",
"Prims.op_Hat",
"FStar.Tactics.Types.get_label",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs ->
begin match term_as_formula (type_of_binder 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:binders) : 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_binders ())
let rewrite_equality (t:term) : Tac unit =
try_rewrite_equality t (cur_binders ())
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) : term =
let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in
mk_e_app sq [t]
let mk_sq_eq (t1 t2 : term) : term =
let eq : term = pack_ln (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_ln (Tv_Var (bv_of_binder 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_ln 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:binder) : Tac unit =
match term_as_formula (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> exact (binder_to_term b))]
| _ ->
begin match term_as_formula' (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq);
exact (binder_to_term b))]
| _ ->
fail "grewrite_eq: binder type is not an equality"
end
private val push1 : (#p:Type) -> (#q:Type) ->
squash (p ==> q) ->
squash p ->
squash q
private let push1 #p #q f u = ()
private val push1' : (#p:Type) -> (#q:Type) ->
(p ==> q) ->
squash p ->
squash q
private let push1' #p #q f u = ()
(*
* Some easier applying, which should prevent frustration
* (or cause more when it doesn't do what you wanted to)
*)
val apply_squash_or_lem : d:nat -> term -> Tac unit
let rec apply_squash_or_lem d t =
(* Before anything, try a vanilla apply and apply_lemma *)
try apply t with | _ ->
try apply (`FStar.Squash.return_squash); apply t with | _ ->
try apply_lemma t with | _ ->
// Fuel cutoff, just in case.
if d <= 0 then fail "mapply: out of fuel" else begin
let ty = tc (cur_env ()) t in
let tys, c = collect_arr ty in
match inspect_comp c with
| C_Lemma pre post _ ->
begin
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' post with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
| C_Total rt ->
begin match unsquash_term rt with
(* If the function returns a squash, just apply it, since our goals are squashed *)
| Some rt ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
(* If not, we can try to introduce the squash ourselves first *)
| None ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
apply (`FStar.Squash.return_squash);
apply t
end
end
| _ -> fail "mapply: can't apply (2)"
end
(* `m` is for `magic` *)
let mapply (t : term) : Tac unit =
apply_squash_or_lem 10 t
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.V1.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.V1.Derived.tlabel'
|
{
"file_name": "ulib/FStar.Tactics.V1.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": 836,
"start_col": 4,
"start_line": 832
}
|
|
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.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1.Builtins",
"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.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"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_ln 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_ln 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.V1.Derived.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V1.SyntaxHelpers.fst.checked",
"FStar.Tactics.V1.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Types.fsti.checked",
"FStar.Tactics.Result.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V1.Formula.fst.checked",
"FStar.Reflection.V1.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.V1.Derived.fst"
}
|
[] |
[
"FStar.Reflection.Types.term",
"Prims.list",
"FStar.Reflection.V1.Data.argv",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Reflection.V1.Data.term_view",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.V1.Data.aqualv",
"FStar.Reflection.V1.Builtins.inspect_ln",
"FStar.Reflection.Types.fv",
"Prims.op_Equality",
"Prims.string",
"FStar.Reflection.V1.Builtins.inspect_fv",
"FStar.Reflection.Const.cons_qn",
"Prims.Cons",
"FStar.Tactics.V1.Derived.destruct_list",
"Prims.bool",
"FStar.Tactics.Effect.raise",
"FStar.Tactics.Common.NotAListLiteral",
"FStar.Reflection.Const.nil_qn",
"Prims.Nil",
"FStar.Tactics.V1.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.V1.Derived
open FStar.Reflection.V1
open FStar.Reflection.V1.Formula
open FStar.Tactics.Types
open FStar.Tactics.Effect
open FStar.Tactics.Result
open FStar.Tactics.Util
open FStar.Tactics.V1.Builtins
open FStar.Tactics.V1.SyntaxHelpers
open FStar.VConfig
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).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 =
name_of_bv (bv_of_binder b)
let binder_to_string (b : binder) : Tac string =
bv_to_string (bv_of_binder b) //TODO: print aqual, attributes
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
(** [cur_binders] returns the list of binders in the current goal. *)
let cur_binders () : Tac binders =
binders_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 ())
(* Create a fresh bound variable (bv), using a generic name. See also
[fresh_bv_named]. *)
let fresh_bv () : Tac bv =
(* These bvs are fresh anyway through a separate counter,
* but adding the integer allows for more readability when
* generating code *)
let i = fresh () in
fresh_bv_named ("x" ^ string_of_int i)
let fresh_binder_named nm t : Tac binder =
mk_binder (fresh_bv_named nm) t
let fresh_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_binder_named ("x" ^ string_of_int i) t
let fresh_implicit_binder_named nm t : Tac binder =
mk_implicit_binder (fresh_bv_named nm) t
let fresh_implicit_binder t : Tac binder =
(* See comment in fresh_bv *)
let i = fresh () in
fresh_implicit_binder_named ("x" ^ string_of_int i) t
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 binder) = 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 binder =
let g = cur_goal () in
let tt = mk_e_app (`__cut) [t; g] in
apply tt;
intro ()
let pose (t:term) : Tac binder =
apply (`__cut);
flip ();
exact t;
intro ()
let intro_as (s:string) : Tac binder =
let b = intro () in
rename_to b s
let pose_as (s:string) (t:term) : Tac binder =
let b = pose t in
rename_to b s
let for_each_binder (f : binder -> Tac 'a) : Tac (list 'a) =
map f (cur_binders ())
let rec revert_all (bs:binders) : Tac unit =
match bs with
| [] -> ()
| _::tl -> revert ();
revert_all tl
(* Some syntax utility functions *)
let bv_to_term (bv : bv) : Tac term = pack (Tv_Var bv)
[@@coercion]
let binder_to_term (b : binder) : Tac term =
let bview = inspect_binder b in
bv_to_term bview.binder_bv
let binder_sort (b : binder) : Tac typ =
(inspect_binder b).binder_sort
// Cannot define this inside `assumption` due to #1091
private
let rec __assumption_aux (bs : binders) : Tac unit =
match bs with
| [] ->
fail "no assumption matches goal"
| b::bs ->
let t = binder_to_term b in
try exact t with | _ ->
try (apply (`FStar.Squash.return_squash);
exact t) with | _ ->
__assumption_aux bs
let assumption () : Tac unit =
__assumption_aux (cur_binders ())
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' (b:binder) : Tac unit =
((fun () -> rewrite b)
<|> (fun () -> binder_retype b;
apply_lemma (`__eq_sym);
rewrite b)
<|> (fun () -> fail "rewrite' failed"))
()
let rec try_rewrite_equality (x:term) (bs:binders) : Tac unit =
match bs with
| [] -> ()
| x_t::bs ->
begin match term_as_formula (type_of_binder 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:binders) : 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_binders ())
let rewrite_equality (t:term) : Tac unit =
try_rewrite_equality t (cur_binders ())
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) : term =
let sq : term = pack_ln (Tv_FVar (pack_fv squash_qn)) in
mk_e_app sq [t]
let mk_sq_eq (t1 t2 : term) : term =
let eq : term = pack_ln (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_ln (Tv_Var (bv_of_binder 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_ln 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:binder) : Tac unit =
match term_as_formula (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> exact (binder_to_term b))]
| _ ->
begin match term_as_formula' (type_of_binder b) with
| Comp (Eq _) l r ->
grewrite l r;
iseq [idtac; (fun () -> apply_lemma (`__un_sq_eq);
exact (binder_to_term b))]
| _ ->
fail "grewrite_eq: binder type is not an equality"
end
private val push1 : (#p:Type) -> (#q:Type) ->
squash (p ==> q) ->
squash p ->
squash q
private let push1 #p #q f u = ()
private val push1' : (#p:Type) -> (#q:Type) ->
(p ==> q) ->
squash p ->
squash q
private let push1' #p #q f u = ()
(*
* Some easier applying, which should prevent frustration
* (or cause more when it doesn't do what you wanted to)
*)
val apply_squash_or_lem : d:nat -> term -> Tac unit
let rec apply_squash_or_lem d t =
(* Before anything, try a vanilla apply and apply_lemma *)
try apply t with | _ ->
try apply (`FStar.Squash.return_squash); apply t with | _ ->
try apply_lemma t with | _ ->
// Fuel cutoff, just in case.
if d <= 0 then fail "mapply: out of fuel" else begin
let ty = tc (cur_env ()) t in
let tys, c = collect_arr ty in
match inspect_comp c with
| C_Lemma pre post _ ->
begin
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' post with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
| C_Total rt ->
begin match unsquash_term rt with
(* If the function returns a squash, just apply it, since our goals are squashed *)
| Some rt ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
fail "mapply: can't apply (1)"
end
(* If not, we can try to introduce the squash ourselves first *)
| None ->
// DUPLICATED, refactor!
begin
let rt = norm_term [] rt in
(* Is the lemma an implication? We can try to intro *)
match term_as_formula' rt with
| Implies p q ->
apply_lemma (`push1);
apply_squash_or_lem (d-1) t
| _ ->
apply (`FStar.Squash.return_squash);
apply t
end
end
| _ -> fail "mapply: can't apply (2)"
end
(* `m` is for `magic` *)
let mapply (t : term) : Tac unit =
apply_squash_or_lem 10 t
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.V1.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.V1.Derived.destruct_list
|
{
"file_name": "ulib/FStar.Tactics.V1.Derived.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
t: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac (Prims.list FStar.Reflection.Types.term)
|
{
"end_col": 27,
"end_line": 872,
"start_col": 52,
"start_line": 859
}
|
FStar.HyperStack.ST.Stack
|
val load_acc4:
acc:felem 4
-> b:lbuffer uint8 64ul
-> Stack unit
(requires fun h ->
live h acc /\ live h b /\ disjoint acc b /\
felem_fits h acc (2, 2, 2, 2, 2))
(ensures fun h0 _ h1 ->
modifies (loc acc) h0 h1 /\
felem_fits h1 acc (3, 3, 3, 3, 3) /\
feval h1 acc == Vec.load_acc4 (as_seq h0 b) (feval h0 acc).[0])
|
[
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Field32xN",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Poly1305.Vec",
"short_module": "Vec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Poly1305.Field32xN.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Poly1305.Field32xN",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"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 load_acc4 acc b =
push_frame();
let e = create 5ul (zero 4) in
load_blocks e b;
let acc0 = acc.(0ul) in
let acc1 = acc.(1ul) in
let acc2 = acc.(2ul) in
let acc3 = acc.(3ul) in
let acc4 = acc.(4ul) in
let e0 = e.(0ul) in
let e1 = e.(1ul) in
let e2 = e.(2ul) in
let e3 = e.(3ul) in
let e4 = e.(4ul) in
let (acc0, acc1, acc2, acc3, acc4) =
load_acc5_4 (acc0, acc1, acc2, acc3, acc4) (e0, e1, e2, e3, e4) in
acc.(0ul) <- acc0;
acc.(1ul) <- acc1;
acc.(2ul) <- acc2;
acc.(3ul) <- acc3;
acc.(4ul) <- acc4;
pop_frame()
|
val load_acc4:
acc:felem 4
-> b:lbuffer uint8 64ul
-> Stack unit
(requires fun h ->
live h acc /\ live h b /\ disjoint acc b /\
felem_fits h acc (2, 2, 2, 2, 2))
(ensures fun h0 _ h1 ->
modifies (loc acc) h0 h1 /\
felem_fits h1 acc (3, 3, 3, 3, 3) /\
feval h1 acc == Vec.load_acc4 (as_seq h0 b) (feval h0 acc).[0])
let load_acc4 acc b =
| true | null | false |
push_frame ();
let e = create 5ul (zero 4) in
load_blocks e b;
let acc0 = acc.(0ul) in
let acc1 = acc.(1ul) in
let acc2 = acc.(2ul) in
let acc3 = acc.(3ul) in
let acc4 = acc.(4ul) in
let e0 = e.(0ul) in
let e1 = e.(1ul) in
let e2 = e.(2ul) in
let e3 = e.(3ul) in
let e4 = e.(4ul) in
let acc0, acc1, acc2, acc3, acc4 =
load_acc5_4 (acc0, acc1, acc2, acc3, acc4) (e0, e1, e2, e3, e4)
in
acc.(0ul) <- acc0;
acc.(1ul) <- acc1;
acc.(2ul) <- acc2;
acc.(3ul) <- acc3;
acc.(4ul) <- acc4;
pop_frame ()
|
{
"checked_file": "Hacl.Impl.Poly1305.Field32xN_256.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Poly1305.Vec.fst.checked",
"Hacl.Spec.Poly1305.Field32xN.Lemmas.fst.checked",
"Hacl.Spec.Poly1305.Field32xN.fst.checked",
"Hacl.Impl.Poly1305.Field32xN.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Poly1305.Field32xN_256.fst"
}
|
[] |
[
"Hacl.Impl.Poly1305.Field32xN.felem",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Hacl.Spec.Poly1305.Field32xN.uint64xN",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Lib.Buffer.op_Array_Assignment",
"Hacl.Spec.Poly1305.Field32xN.felem5",
"Hacl.Spec.Poly1305.Field32xN.load_acc5_4",
"FStar.Pervasives.Native.Mktuple5",
"Lib.Buffer.op_Array_Access",
"Lib.Buffer.MUT",
"Hacl.Impl.Poly1305.Field32xN.load_blocks",
"Lib.Buffer.lbuffer_t",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.create",
"Hacl.Spec.Poly1305.Field32xN.zero",
"FStar.HyperStack.ST.push_frame"
] |
[] |
module Hacl.Impl.Poly1305.Field32xN_256
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
include Hacl.Spec.Poly1305.Field32xN
open Hacl.Spec.Poly1305.Field32xN.Lemmas
module Vec = Hacl.Spec.Poly1305.Vec
module ST = FStar.HyperStack.ST
open Hacl.Impl.Poly1305.Field32xN
/// Note: on fstar-master, we extract everything in a single invocation of
/// KaRaMeL. However, we cannot mix in the same C file functions that cannot
/// assume avx2 and functions that demand it, because the compiler will optimize
/// the fallback version with avx2 instructions, which will in turn generate
/// illegal instruction errors on some target machines.
///
/// The load_accN variants pose a problem, because they all end up in the same
/// file when, really, they should be in separate files to allow compiling each
/// C translation unit with the same flags.
///
/// One way to solve this problem is to mark them noextract
/// inline_for_extraction, as was done previously. Another way would be to fix
/// KaRaMeL to allow moving functions in a given module to other modules. A
/// third, more mundame fix is to split these functions in separate modules and
/// package them with their top-level bundle file, which will achieve the same
/// effect.
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50 --using_facts_from '* -FStar.Seq'"
val load_acc4:
acc:felem 4
-> b:lbuffer uint8 64ul
-> Stack unit
(requires fun h ->
live h acc /\ live h b /\ disjoint acc b /\
felem_fits h acc (2, 2, 2, 2, 2))
(ensures fun h0 _ h1 ->
modifies (loc acc) h0 h1 /\
felem_fits h1 acc (3, 3, 3, 3, 3) /\
feval h1 acc == Vec.load_acc4 (as_seq h0 b) (feval h0 acc).[0])
| false | false |
Hacl.Impl.Poly1305.Field32xN_256.fst
|
{
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
}
| null |
val load_acc4:
acc:felem 4
-> b:lbuffer uint8 64ul
-> Stack unit
(requires fun h ->
live h acc /\ live h b /\ disjoint acc b /\
felem_fits h acc (2, 2, 2, 2, 2))
(ensures fun h0 _ h1 ->
modifies (loc acc) h0 h1 /\
felem_fits h1 acc (3, 3, 3, 3, 3) /\
feval h1 acc == Vec.load_acc4 (as_seq h0 b) (feval h0 acc).[0])
|
[] |
Hacl.Impl.Poly1305.Field32xN_256.load_acc4
|
{
"file_name": "code/poly1305/Hacl.Impl.Poly1305.Field32xN_256.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
}
|
acc: Hacl.Impl.Poly1305.Field32xN.felem 4 -> b: Lib.Buffer.lbuffer Lib.IntTypes.uint8 64ul
-> FStar.HyperStack.ST.Stack Prims.unit
|
{
"end_col": 13,
"end_line": 71,
"start_col": 2,
"start_line": 49
}
|
FStar.HyperStack.ST.Stack
|
val fmul_r4_normalize:
out:felem 4
-> p:precomp_r 4
-> Stack unit
(requires fun h ->
live h out /\ live h p /\
felem_fits h out (3, 3, 3, 3, 3) /\
load_precompute_r_post h p)
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
felem_fits h1 out (2, 2, 2, 2, 2) /\
(let r = feval h0 (gsub p 0ul 5ul) in
(feval h1 out).[0] == Vec.normalize_4 r.[0] (feval h0 out)))
|
[
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Field32xN",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Poly1305.Vec",
"short_module": "Vec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Poly1305.Field32xN.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Poly1305.Field32xN",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"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 fmul_r4_normalize out p =
let r = sub p 0ul 5ul in
let r_5 = sub p 5ul 5ul in
let r4 = sub p 10ul 5ul in
let a0 = out.(0ul) in
let a1 = out.(1ul) in
let a2 = out.(2ul) in
let a3 = out.(3ul) in
let a4 = out.(4ul) in
let r10 = r.(0ul) in
let r11 = r.(1ul) in
let r12 = r.(2ul) in
let r13 = r.(3ul) in
let r14 = r.(4ul) in
let r150 = r_5.(0ul) in
let r151 = r_5.(1ul) in
let r152 = r_5.(2ul) in
let r153 = r_5.(3ul) in
let r154 = r_5.(4ul) in
let r40 = r4.(0ul) in
let r41 = r4.(1ul) in
let r42 = r4.(2ul) in
let r43 = r4.(3ul) in
let r44 = r4.(4ul) in
let (o0, o1, o2, o3, o4) =
fmul_r4_normalize5 (a0, a1, a2, a3, a4) (r10, r11, r12, r13, r14)
(r150, r151, r152, r153, r154) (r40, r41, r42, r43, r44) in
out.(0ul) <- o0;
out.(1ul) <- o1;
out.(2ul) <- o2;
out.(3ul) <- o3;
out.(4ul) <- o4
|
val fmul_r4_normalize:
out:felem 4
-> p:precomp_r 4
-> Stack unit
(requires fun h ->
live h out /\ live h p /\
felem_fits h out (3, 3, 3, 3, 3) /\
load_precompute_r_post h p)
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
felem_fits h1 out (2, 2, 2, 2, 2) /\
(let r = feval h0 (gsub p 0ul 5ul) in
(feval h1 out).[0] == Vec.normalize_4 r.[0] (feval h0 out)))
let fmul_r4_normalize out p =
| true | null | false |
let r = sub p 0ul 5ul in
let r_5 = sub p 5ul 5ul in
let r4 = sub p 10ul 5ul in
let a0 = out.(0ul) in
let a1 = out.(1ul) in
let a2 = out.(2ul) in
let a3 = out.(3ul) in
let a4 = out.(4ul) in
let r10 = r.(0ul) in
let r11 = r.(1ul) in
let r12 = r.(2ul) in
let r13 = r.(3ul) in
let r14 = r.(4ul) in
let r150 = r_5.(0ul) in
let r151 = r_5.(1ul) in
let r152 = r_5.(2ul) in
let r153 = r_5.(3ul) in
let r154 = r_5.(4ul) in
let r40 = r4.(0ul) in
let r41 = r4.(1ul) in
let r42 = r4.(2ul) in
let r43 = r4.(3ul) in
let r44 = r4.(4ul) in
let o0, o1, o2, o3, o4 =
fmul_r4_normalize5 (a0, a1, a2, a3, a4)
(r10, r11, r12, r13, r14)
(r150, r151, r152, r153, r154)
(r40, r41, r42, r43, r44)
in
out.(0ul) <- o0;
out.(1ul) <- o1;
out.(2ul) <- o2;
out.(3ul) <- o3;
out.(4ul) <- o4
|
{
"checked_file": "Hacl.Impl.Poly1305.Field32xN_256.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Poly1305.Vec.fst.checked",
"Hacl.Spec.Poly1305.Field32xN.Lemmas.fst.checked",
"Hacl.Spec.Poly1305.Field32xN.fst.checked",
"Hacl.Impl.Poly1305.Field32xN.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Poly1305.Field32xN_256.fst"
}
|
[] |
[
"Hacl.Impl.Poly1305.Field32xN.felem",
"Hacl.Impl.Poly1305.Field32xN.precomp_r",
"Hacl.Spec.Poly1305.Field32xN.uint64xN",
"Lib.Buffer.op_Array_Assignment",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"Hacl.Spec.Poly1305.Field32xN.felem5",
"Hacl.Spec.Poly1305.Field32xN.fmul_r4_normalize5",
"FStar.Pervasives.Native.Mktuple5",
"Lib.Buffer.op_Array_Access",
"Lib.Buffer.MUT",
"Lib.Buffer.lbuffer_t",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.sub"
] |
[] |
module Hacl.Impl.Poly1305.Field32xN_256
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
include Hacl.Spec.Poly1305.Field32xN
open Hacl.Spec.Poly1305.Field32xN.Lemmas
module Vec = Hacl.Spec.Poly1305.Vec
module ST = FStar.HyperStack.ST
open Hacl.Impl.Poly1305.Field32xN
/// Note: on fstar-master, we extract everything in a single invocation of
/// KaRaMeL. However, we cannot mix in the same C file functions that cannot
/// assume avx2 and functions that demand it, because the compiler will optimize
/// the fallback version with avx2 instructions, which will in turn generate
/// illegal instruction errors on some target machines.
///
/// The load_accN variants pose a problem, because they all end up in the same
/// file when, really, they should be in separate files to allow compiling each
/// C translation unit with the same flags.
///
/// One way to solve this problem is to mark them noextract
/// inline_for_extraction, as was done previously. Another way would be to fix
/// KaRaMeL to allow moving functions in a given module to other modules. A
/// third, more mundame fix is to split these functions in separate modules and
/// package them with their top-level bundle file, which will achieve the same
/// effect.
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50 --using_facts_from '* -FStar.Seq'"
val load_acc4:
acc:felem 4
-> b:lbuffer uint8 64ul
-> Stack unit
(requires fun h ->
live h acc /\ live h b /\ disjoint acc b /\
felem_fits h acc (2, 2, 2, 2, 2))
(ensures fun h0 _ h1 ->
modifies (loc acc) h0 h1 /\
felem_fits h1 acc (3, 3, 3, 3, 3) /\
feval h1 acc == Vec.load_acc4 (as_seq h0 b) (feval h0 acc).[0])
let load_acc4 acc b =
push_frame();
let e = create 5ul (zero 4) in
load_blocks e b;
let acc0 = acc.(0ul) in
let acc1 = acc.(1ul) in
let acc2 = acc.(2ul) in
let acc3 = acc.(3ul) in
let acc4 = acc.(4ul) in
let e0 = e.(0ul) in
let e1 = e.(1ul) in
let e2 = e.(2ul) in
let e3 = e.(3ul) in
let e4 = e.(4ul) in
let (acc0, acc1, acc2, acc3, acc4) =
load_acc5_4 (acc0, acc1, acc2, acc3, acc4) (e0, e1, e2, e3, e4) in
acc.(0ul) <- acc0;
acc.(1ul) <- acc1;
acc.(2ul) <- acc2;
acc.(3ul) <- acc3;
acc.(4ul) <- acc4;
pop_frame()
val fmul_r4_normalize:
out:felem 4
-> p:precomp_r 4
-> Stack unit
(requires fun h ->
live h out /\ live h p /\
felem_fits h out (3, 3, 3, 3, 3) /\
load_precompute_r_post h p)
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
felem_fits h1 out (2, 2, 2, 2, 2) /\
(let r = feval h0 (gsub p 0ul 5ul) in
| false | false |
Hacl.Impl.Poly1305.Field32xN_256.fst
|
{
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
}
| null |
val fmul_r4_normalize:
out:felem 4
-> p:precomp_r 4
-> Stack unit
(requires fun h ->
live h out /\ live h p /\
felem_fits h out (3, 3, 3, 3, 3) /\
load_precompute_r_post h p)
(ensures fun h0 _ h1 ->
modifies (loc out) h0 h1 /\
felem_fits h1 out (2, 2, 2, 2, 2) /\
(let r = feval h0 (gsub p 0ul 5ul) in
(feval h1 out).[0] == Vec.normalize_4 r.[0] (feval h0 out)))
|
[] |
Hacl.Impl.Poly1305.Field32xN_256.fmul_r4_normalize
|
{
"file_name": "code/poly1305/Hacl.Impl.Poly1305.Field32xN_256.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
}
|
out: Hacl.Impl.Poly1305.Field32xN.felem 4 -> p: Hacl.Impl.Poly1305.Field32xN.precomp_r 4
-> FStar.HyperStack.ST.Stack Prims.unit
|
{
"end_col": 17,
"end_line": 123,
"start_col": 29,
"start_line": 87
}
|
Prims.Tot
|
[
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"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 (<<:) (l: list 'a) (r: 'r)
= forallP (fun x -> x << r) l
|
let op_Less_Less_Colon (l: list 'a) (r: 'r) =
| false | null | false |
forallP (fun x -> x << r) l
|
{
"checked_file": "FStar.Reflection.V2.Derived.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Reflection.V2.Derived.fst.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.Lemmas.fst"
}
|
[
"total"
] |
[
"Prims.list",
"FStar.Reflection.V2.Derived.Lemmas.forallP",
"Prims.precedes"
] |
[] |
(*
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.Reflection.V2.Derived.Lemmas
open FStar.Reflection.Types
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Reflection.V2.Derived
open FStar.List.Tot
let rec forall_list (p:'a -> Type) (l:list 'a) : Type =
match l with
| [] -> True
| x::xs -> p x /\ forall_list p xs
let forallP (p: 'a -> Type) (l: list 'a): Type
= forall (x: 'a). memP x l ==> p x
// Precedence relation on the element of a list
| false | false |
FStar.Reflection.V2.Derived.Lemmas.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 op_Less_Less_Colon : l: Prims.list 'a -> r: 'r -> Type0
|
[] |
FStar.Reflection.V2.Derived.Lemmas.op_Less_Less_Colon
|
{
"file_name": "ulib/FStar.Reflection.V2.Derived.Lemmas.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
l: Prims.list 'a -> r: 'r -> Type0
|
{
"end_col": 31,
"end_line": 33,
"start_col": 4,
"start_line": 33
}
|
|
FStar.Pervasives.Lemma
|
val collect_app_order : (t:term) ->
Lemma (ensures (forall (f:term). forall (s:list argv). (f,s) == collect_app_ln t ==>
(f << t /\ s <<: t)
\/ (f == t /\ s == [])))
|
[
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"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 collect_app_order t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' [r] t l
| _ -> ()
|
val collect_app_order : (t:term) ->
Lemma (ensures (forall (f:term). forall (s:list argv). (f,s) == collect_app_ln t ==>
(f << t /\ s <<: t)
\/ (f == t /\ s == [])))
let collect_app_order t =
| false | null | true |
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' [r] t l
| _ -> ()
|
{
"checked_file": "FStar.Reflection.V2.Derived.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Reflection.V2.Derived.fst.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.Lemmas.fst"
}
|
[
"lemma"
] |
[
"FStar.Reflection.Types.term",
"FStar.Reflection.V2.Derived.inspect_ln_unascribe",
"FStar.Reflection.V2.Data.argv",
"FStar.Reflection.V2.Derived.Lemmas.collect_app_order'",
"Prims.Cons",
"Prims.Nil",
"FStar.Reflection.V2.Data.term_view",
"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.Reflection.V2.Derived.Lemmas
open FStar.Reflection.Types
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Reflection.V2.Derived
open FStar.List.Tot
let rec forall_list (p:'a -> Type) (l:list 'a) : Type =
match l with
| [] -> True
| x::xs -> p x /\ forall_list p xs
let forallP (p: 'a -> Type) (l: list 'a): Type
= forall (x: 'a). memP x l ==> p x
// Precedence relation on the element of a list
unfold let (<<:) (l: list 'a) (r: 'r)
= forallP (fun x -> x << r) l
// A glorified `id`
val list_ref : (#a:Type) -> (#p:(a -> Type)) -> (l:list a) ->
Pure (list (x:a{p x}))
(requires (forallP p l))
(ensures (fun _ -> True))
let rec list_ref #a #p l =
match l with
| [] -> []
| x::xs -> x :: list_ref #a #p xs
val collect_app_order' : (args:list argv) -> (tt:term) -> (t:term) ->
Lemma (requires args <<: tt /\ t << tt)
(ensures (let fn, args' = collect_app_ln' args t in
args' <<: tt /\ fn << tt))
(decreases t)
let rec collect_app_order' args tt t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' (r::args) tt l
| _ -> ()
val collect_app_order : (t:term) ->
Lemma (ensures (forall (f:term). forall (s:list argv). (f,s) == collect_app_ln t ==>
(f << t /\ s <<: t)
\/ (f == t /\ s == [])))
| false | false |
FStar.Reflection.V2.Derived.Lemmas.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 collect_app_order : (t:term) ->
Lemma (ensures (forall (f:term). forall (s:list argv). (f,s) == collect_app_ln t ==>
(f << t /\ s <<: t)
\/ (f == t /\ s == [])))
|
[] |
FStar.Reflection.V2.Derived.Lemmas.collect_app_order
|
{
"file_name": "ulib/FStar.Reflection.V2.Derived.Lemmas.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
t: FStar.Reflection.Types.term
-> FStar.Pervasives.Lemma
(ensures
forall (f: FStar.Reflection.Types.term) (s: Prims.list FStar.Reflection.V2.Data.argv).
FStar.Pervasives.Native.Mktuple2 f s == FStar.Reflection.V2.Derived.collect_app_ln t ==>
f << t /\ s <<: t \/ f == t /\ s == [])
|
{
"end_col": 13,
"end_line": 62,
"start_col": 4,
"start_line": 60
}
|
Prims.Pure
|
val list_ref : (#a:Type) -> (#p:(a -> Type)) -> (l:list a) ->
Pure (list (x:a{p x}))
(requires (forallP p l))
(ensures (fun _ -> True))
|
[
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"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 list_ref #a #p l =
match l with
| [] -> []
| x::xs -> x :: list_ref #a #p xs
|
val list_ref : (#a:Type) -> (#p:(a -> Type)) -> (l:list a) ->
Pure (list (x:a{p x}))
(requires (forallP p l))
(ensures (fun _ -> True))
let rec list_ref #a #p l =
| false | null | false |
match l with
| [] -> []
| x :: xs -> x :: list_ref #a #p xs
|
{
"checked_file": "FStar.Reflection.V2.Derived.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Reflection.V2.Derived.fst.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.Lemmas.fst"
}
|
[] |
[
"Prims.list",
"Prims.Nil",
"Prims.Cons",
"FStar.Reflection.V2.Derived.Lemmas.list_ref"
] |
[] |
(*
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.Reflection.V2.Derived.Lemmas
open FStar.Reflection.Types
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Reflection.V2.Derived
open FStar.List.Tot
let rec forall_list (p:'a -> Type) (l:list 'a) : Type =
match l with
| [] -> True
| x::xs -> p x /\ forall_list p xs
let forallP (p: 'a -> Type) (l: list 'a): Type
= forall (x: 'a). memP x l ==> p x
// Precedence relation on the element of a list
unfold let (<<:) (l: list 'a) (r: 'r)
= forallP (fun x -> x << r) l
// A glorified `id`
val list_ref : (#a:Type) -> (#p:(a -> Type)) -> (l:list a) ->
Pure (list (x:a{p x}))
(requires (forallP p l))
(ensures (fun _ -> True))
| false | false |
FStar.Reflection.V2.Derived.Lemmas.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 list_ref : (#a:Type) -> (#p:(a -> Type)) -> (l:list a) ->
Pure (list (x:a{p x}))
(requires (forallP p l))
(ensures (fun _ -> True))
|
[
"recursion"
] |
FStar.Reflection.V2.Derived.Lemmas.list_ref
|
{
"file_name": "ulib/FStar.Reflection.V2.Derived.Lemmas.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
l: Prims.list a -> Prims.Pure (Prims.list (x: a{p x}))
|
{
"end_col": 37,
"end_line": 43,
"start_col": 4,
"start_line": 41
}
|
Prims.Tot
|
val collect_arr_ln_bs_ref : (t:term) -> list (bd:binder{bd << t})
* (c:comp{ c == pack_comp (C_Total t) \/ c << t})
|
[
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"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 collect_arr_ln_bs_ref t =
let bds, c = collect_arr_ln_bs t in
collect_arr_ln_bs_order t;
list_ref bds, c
|
val collect_arr_ln_bs_ref : (t:term) -> list (bd:binder{bd << t})
* (c:comp{ c == pack_comp (C_Total t) \/ c << t})
let collect_arr_ln_bs_ref t =
| false | null | false |
let bds, c = collect_arr_ln_bs t in
collect_arr_ln_bs_order t;
list_ref bds, c
|
{
"checked_file": "FStar.Reflection.V2.Derived.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Reflection.V2.Derived.fst.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.Lemmas.fst"
}
|
[
"total"
] |
[
"FStar.Reflection.Types.term",
"Prims.list",
"FStar.Reflection.Types.binder",
"FStar.Reflection.Types.comp",
"FStar.Pervasives.Native.Mktuple2",
"Prims.precedes",
"Prims.l_or",
"Prims.eq2",
"FStar.Reflection.V2.Builtins.pack_comp",
"FStar.Reflection.V2.Data.C_Total",
"FStar.Reflection.V2.Derived.Lemmas.list_ref",
"Prims.unit",
"FStar.Reflection.V2.Derived.Lemmas.collect_arr_ln_bs_order",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.V2.Derived.collect_arr_ln_bs"
] |
[] |
(*
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.Reflection.V2.Derived.Lemmas
open FStar.Reflection.Types
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Reflection.V2.Derived
open FStar.List.Tot
let rec forall_list (p:'a -> Type) (l:list 'a) : Type =
match l with
| [] -> True
| x::xs -> p x /\ forall_list p xs
let forallP (p: 'a -> Type) (l: list 'a): Type
= forall (x: 'a). memP x l ==> p x
// Precedence relation on the element of a list
unfold let (<<:) (l: list 'a) (r: 'r)
= forallP (fun x -> x << r) l
// A glorified `id`
val list_ref : (#a:Type) -> (#p:(a -> Type)) -> (l:list a) ->
Pure (list (x:a{p x}))
(requires (forallP p l))
(ensures (fun _ -> True))
let rec list_ref #a #p l =
match l with
| [] -> []
| x::xs -> x :: list_ref #a #p xs
val collect_app_order' : (args:list argv) -> (tt:term) -> (t:term) ->
Lemma (requires args <<: tt /\ t << tt)
(ensures (let fn, args' = collect_app_ln' args t in
args' <<: tt /\ fn << tt))
(decreases t)
let rec collect_app_order' args tt t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' (r::args) tt l
| _ -> ()
val collect_app_order : (t:term) ->
Lemma (ensures (forall (f:term). forall (s:list argv). (f,s) == collect_app_ln t ==>
(f << t /\ s <<: t)
\/ (f == t /\ s == [])))
let collect_app_order t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' [r] t l
| _ -> ()
val collect_app_ref : (t:term) -> (h:term{h == t \/ h << t}) * list (a:argv{fst a << t})
let collect_app_ref t =
let h, a = collect_app_ln t in
collect_app_order t;
h, list_ref a
(**** [collect_abs_ln t] is smaller than [t] *)
let rec collect_abs_order' (bds: binders) (tt t: term)
: Lemma (requires t << tt /\ bds <<: tt)
(ensures (let bds', body = collect_abs' bds t in
(bds' <<: tt /\ body << tt)))
(decreases t)
= match inspect_ln_unascribe t with
| Tv_Abs b body -> collect_abs_order' (b::bds) tt body
| _ -> ()
val collect_abs_ln_order : (t:term) ->
Lemma (ensures forall bds body.
(bds, body) == collect_abs_ln t ==>
(body << t /\ bds <<: t)
\/ (body == t /\ bds == [])
)
let collect_abs_ln_order t =
match inspect_ln_unascribe t with
| Tv_Abs b body -> collect_abs_order' [b] t body;
let bds, body = collect_abs' [] t in
Classical.forall_intro (rev_memP bds)
| _ -> ()
val collect_abs_ln_ref : (t:term) -> list (bd:binder{bd << t}) * (body:term{body == t \/ body << t})
let collect_abs_ln_ref t =
let bds, body = collect_abs_ln t in
collect_abs_ln_order t;
list_ref bds, body
(**** [collect_arr_ln_bs t] is smaller than [t] *)
let rec collect_arr_order' (bds: binders) (tt: term) (c: comp)
: Lemma (requires c << tt /\ bds <<: tt)
(ensures (let bds', c' = collect_arr' bds c in
bds' <<: tt /\ c' << tt))
(decreases c)
= match inspect_comp c with
| C_Total ret ->
( match inspect_ln_unascribe ret with
| Tv_Arrow b c -> collect_arr_order' (b::bds) tt c
| _ -> ())
| _ -> ()
val collect_arr_ln_bs_order : (t:term) ->
Lemma (ensures forall bds c.
(bds, c) == collect_arr_ln_bs t ==>
(c << t /\ bds <<: t)
\/ (c == pack_comp (C_Total t) /\ bds == [])
)
let collect_arr_ln_bs_order t =
match inspect_ln_unascribe t with
| Tv_Arrow b c -> collect_arr_order' [b] t c;
Classical.forall_intro_2 (rev_memP #binder);
inspect_pack_comp_inv (C_Total t)
| _ -> inspect_pack_comp_inv (C_Total t)
val collect_arr_ln_bs_ref : (t:term) -> list (bd:binder{bd << t})
| false | false |
FStar.Reflection.V2.Derived.Lemmas.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 collect_arr_ln_bs_ref : (t:term) -> list (bd:binder{bd << t})
* (c:comp{ c == pack_comp (C_Total t) \/ c << t})
|
[] |
FStar.Reflection.V2.Derived.Lemmas.collect_arr_ln_bs_ref
|
{
"file_name": "ulib/FStar.Reflection.V2.Derived.Lemmas.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
t: FStar.Reflection.Types.term
-> Prims.list (bd: FStar.Reflection.Types.binder{bd << t}) *
c:
FStar.Reflection.Types.comp
{c == FStar.Reflection.V2.Builtins.pack_comp (FStar.Reflection.V2.Data.C_Total t) \/ c << t}
|
{
"end_col": 19,
"end_line": 132,
"start_col": 29,
"start_line": 129
}
|
Prims.Tot
|
val collect_app_ref : (t:term) -> (h:term{h == t \/ h << t}) * list (a:argv{fst a << t})
|
[
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"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 collect_app_ref t =
let h, a = collect_app_ln t in
collect_app_order t;
h, list_ref a
|
val collect_app_ref : (t:term) -> (h:term{h == t \/ h << t}) * list (a:argv{fst a << t})
let collect_app_ref t =
| false | null | false |
let h, a = collect_app_ln t in
collect_app_order t;
h, list_ref a
|
{
"checked_file": "FStar.Reflection.V2.Derived.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Reflection.V2.Derived.fst.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.Lemmas.fst"
}
|
[
"total"
] |
[
"FStar.Reflection.Types.term",
"Prims.list",
"FStar.Reflection.V2.Data.argv",
"FStar.Pervasives.Native.Mktuple2",
"Prims.l_or",
"Prims.eq2",
"Prims.precedes",
"FStar.Pervasives.Native.fst",
"FStar.Reflection.V2.Data.aqualv",
"FStar.Reflection.V2.Derived.Lemmas.list_ref",
"Prims.unit",
"FStar.Reflection.V2.Derived.Lemmas.collect_app_order",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.V2.Derived.collect_app_ln"
] |
[] |
(*
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.Reflection.V2.Derived.Lemmas
open FStar.Reflection.Types
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Reflection.V2.Derived
open FStar.List.Tot
let rec forall_list (p:'a -> Type) (l:list 'a) : Type =
match l with
| [] -> True
| x::xs -> p x /\ forall_list p xs
let forallP (p: 'a -> Type) (l: list 'a): Type
= forall (x: 'a). memP x l ==> p x
// Precedence relation on the element of a list
unfold let (<<:) (l: list 'a) (r: 'r)
= forallP (fun x -> x << r) l
// A glorified `id`
val list_ref : (#a:Type) -> (#p:(a -> Type)) -> (l:list a) ->
Pure (list (x:a{p x}))
(requires (forallP p l))
(ensures (fun _ -> True))
let rec list_ref #a #p l =
match l with
| [] -> []
| x::xs -> x :: list_ref #a #p xs
val collect_app_order' : (args:list argv) -> (tt:term) -> (t:term) ->
Lemma (requires args <<: tt /\ t << tt)
(ensures (let fn, args' = collect_app_ln' args t in
args' <<: tt /\ fn << tt))
(decreases t)
let rec collect_app_order' args tt t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' (r::args) tt l
| _ -> ()
val collect_app_order : (t:term) ->
Lemma (ensures (forall (f:term). forall (s:list argv). (f,s) == collect_app_ln t ==>
(f << t /\ s <<: t)
\/ (f == t /\ s == [])))
let collect_app_order t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' [r] t l
| _ -> ()
| false | false |
FStar.Reflection.V2.Derived.Lemmas.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 collect_app_ref : (t:term) -> (h:term{h == t \/ h << t}) * list (a:argv{fst a << t})
|
[] |
FStar.Reflection.V2.Derived.Lemmas.collect_app_ref
|
{
"file_name": "ulib/FStar.Reflection.V2.Derived.Lemmas.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
t: FStar.Reflection.Types.term
-> h:
FStar.Reflection.Types.term{h == t \/ h << t} *
Prims.list (a: FStar.Reflection.V2.Data.argv{FStar.Pervasives.Native.fst a << t})
|
{
"end_col": 17,
"end_line": 68,
"start_col": 23,
"start_line": 65
}
|
Prims.Tot
|
val collect_abs_ln_ref : (t:term) -> list (bd:binder{bd << t}) * (body:term{body == t \/ body << t})
|
[
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"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 collect_abs_ln_ref t =
let bds, body = collect_abs_ln t in
collect_abs_ln_order t;
list_ref bds, body
|
val collect_abs_ln_ref : (t:term) -> list (bd:binder{bd << t}) * (body:term{body == t \/ body << t})
let collect_abs_ln_ref t =
| false | null | false |
let bds, body = collect_abs_ln t in
collect_abs_ln_order t;
list_ref bds, body
|
{
"checked_file": "FStar.Reflection.V2.Derived.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Reflection.V2.Derived.fst.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.Lemmas.fst"
}
|
[
"total"
] |
[
"FStar.Reflection.Types.term",
"Prims.list",
"FStar.Reflection.Types.binder",
"FStar.Pervasives.Native.Mktuple2",
"Prims.precedes",
"Prims.l_or",
"Prims.eq2",
"FStar.Reflection.V2.Derived.Lemmas.list_ref",
"Prims.unit",
"FStar.Reflection.V2.Derived.Lemmas.collect_abs_ln_order",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.V2.Derived.collect_abs_ln"
] |
[] |
(*
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.Reflection.V2.Derived.Lemmas
open FStar.Reflection.Types
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Reflection.V2.Derived
open FStar.List.Tot
let rec forall_list (p:'a -> Type) (l:list 'a) : Type =
match l with
| [] -> True
| x::xs -> p x /\ forall_list p xs
let forallP (p: 'a -> Type) (l: list 'a): Type
= forall (x: 'a). memP x l ==> p x
// Precedence relation on the element of a list
unfold let (<<:) (l: list 'a) (r: 'r)
= forallP (fun x -> x << r) l
// A glorified `id`
val list_ref : (#a:Type) -> (#p:(a -> Type)) -> (l:list a) ->
Pure (list (x:a{p x}))
(requires (forallP p l))
(ensures (fun _ -> True))
let rec list_ref #a #p l =
match l with
| [] -> []
| x::xs -> x :: list_ref #a #p xs
val collect_app_order' : (args:list argv) -> (tt:term) -> (t:term) ->
Lemma (requires args <<: tt /\ t << tt)
(ensures (let fn, args' = collect_app_ln' args t in
args' <<: tt /\ fn << tt))
(decreases t)
let rec collect_app_order' args tt t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' (r::args) tt l
| _ -> ()
val collect_app_order : (t:term) ->
Lemma (ensures (forall (f:term). forall (s:list argv). (f,s) == collect_app_ln t ==>
(f << t /\ s <<: t)
\/ (f == t /\ s == [])))
let collect_app_order t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' [r] t l
| _ -> ()
val collect_app_ref : (t:term) -> (h:term{h == t \/ h << t}) * list (a:argv{fst a << t})
let collect_app_ref t =
let h, a = collect_app_ln t in
collect_app_order t;
h, list_ref a
(**** [collect_abs_ln t] is smaller than [t] *)
let rec collect_abs_order' (bds: binders) (tt t: term)
: Lemma (requires t << tt /\ bds <<: tt)
(ensures (let bds', body = collect_abs' bds t in
(bds' <<: tt /\ body << tt)))
(decreases t)
= match inspect_ln_unascribe t with
| Tv_Abs b body -> collect_abs_order' (b::bds) tt body
| _ -> ()
val collect_abs_ln_order : (t:term) ->
Lemma (ensures forall bds body.
(bds, body) == collect_abs_ln t ==>
(body << t /\ bds <<: t)
\/ (body == t /\ bds == [])
)
let collect_abs_ln_order t =
match inspect_ln_unascribe t with
| Tv_Abs b body -> collect_abs_order' [b] t body;
let bds, body = collect_abs' [] t in
Classical.forall_intro (rev_memP bds)
| _ -> ()
| false | false |
FStar.Reflection.V2.Derived.Lemmas.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 collect_abs_ln_ref : (t:term) -> list (bd:binder{bd << t}) * (body:term{body == t \/ body << t})
|
[] |
FStar.Reflection.V2.Derived.Lemmas.collect_abs_ln_ref
|
{
"file_name": "ulib/FStar.Reflection.V2.Derived.Lemmas.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
t: FStar.Reflection.Types.term
-> Prims.list (bd: FStar.Reflection.Types.binder{bd << t}) *
body:
FStar.Reflection.Types.term{body == t \/ body << t}
|
{
"end_col": 22,
"end_line": 97,
"start_col": 26,
"start_line": 94
}
|
FStar.Pervasives.Lemma
|
val collect_abs_ln_order : (t:term) ->
Lemma (ensures forall bds body.
(bds, body) == collect_abs_ln t ==>
(body << t /\ bds <<: t)
\/ (body == t /\ bds == [])
)
|
[
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"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 collect_abs_ln_order t =
match inspect_ln_unascribe t with
| Tv_Abs b body -> collect_abs_order' [b] t body;
let bds, body = collect_abs' [] t in
Classical.forall_intro (rev_memP bds)
| _ -> ()
|
val collect_abs_ln_order : (t:term) ->
Lemma (ensures forall bds body.
(bds, body) == collect_abs_ln t ==>
(body << t /\ bds <<: t)
\/ (body == t /\ bds == [])
)
let collect_abs_ln_order t =
| false | null | true |
match inspect_ln_unascribe t with
| Tv_Abs b body ->
collect_abs_order' [b] t body;
let bds, body = collect_abs' [] t in
Classical.forall_intro (rev_memP bds)
| _ -> ()
|
{
"checked_file": "FStar.Reflection.V2.Derived.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Reflection.V2.Derived.fst.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.Lemmas.fst"
}
|
[
"lemma"
] |
[
"FStar.Reflection.Types.term",
"FStar.Reflection.V2.Derived.inspect_ln_unascribe",
"FStar.Reflection.Types.binder",
"Prims.list",
"FStar.Classical.forall_intro",
"Prims.l_iff",
"FStar.List.Tot.Base.memP",
"FStar.List.Tot.Base.rev",
"FStar.List.Tot.Properties.rev_memP",
"Prims.unit",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.V2.Derived.collect_abs'",
"Prims.Nil",
"FStar.Reflection.V2.Derived.Lemmas.collect_abs_order'",
"Prims.Cons",
"FStar.Reflection.V2.Data.term_view"
] |
[] |
(*
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.Reflection.V2.Derived.Lemmas
open FStar.Reflection.Types
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Reflection.V2.Derived
open FStar.List.Tot
let rec forall_list (p:'a -> Type) (l:list 'a) : Type =
match l with
| [] -> True
| x::xs -> p x /\ forall_list p xs
let forallP (p: 'a -> Type) (l: list 'a): Type
= forall (x: 'a). memP x l ==> p x
// Precedence relation on the element of a list
unfold let (<<:) (l: list 'a) (r: 'r)
= forallP (fun x -> x << r) l
// A glorified `id`
val list_ref : (#a:Type) -> (#p:(a -> Type)) -> (l:list a) ->
Pure (list (x:a{p x}))
(requires (forallP p l))
(ensures (fun _ -> True))
let rec list_ref #a #p l =
match l with
| [] -> []
| x::xs -> x :: list_ref #a #p xs
val collect_app_order' : (args:list argv) -> (tt:term) -> (t:term) ->
Lemma (requires args <<: tt /\ t << tt)
(ensures (let fn, args' = collect_app_ln' args t in
args' <<: tt /\ fn << tt))
(decreases t)
let rec collect_app_order' args tt t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' (r::args) tt l
| _ -> ()
val collect_app_order : (t:term) ->
Lemma (ensures (forall (f:term). forall (s:list argv). (f,s) == collect_app_ln t ==>
(f << t /\ s <<: t)
\/ (f == t /\ s == [])))
let collect_app_order t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' [r] t l
| _ -> ()
val collect_app_ref : (t:term) -> (h:term{h == t \/ h << t}) * list (a:argv{fst a << t})
let collect_app_ref t =
let h, a = collect_app_ln t in
collect_app_order t;
h, list_ref a
(**** [collect_abs_ln t] is smaller than [t] *)
let rec collect_abs_order' (bds: binders) (tt t: term)
: Lemma (requires t << tt /\ bds <<: tt)
(ensures (let bds', body = collect_abs' bds t in
(bds' <<: tt /\ body << tt)))
(decreases t)
= match inspect_ln_unascribe t with
| Tv_Abs b body -> collect_abs_order' (b::bds) tt body
| _ -> ()
val collect_abs_ln_order : (t:term) ->
Lemma (ensures forall bds body.
(bds, body) == collect_abs_ln t ==>
(body << t /\ bds <<: t)
\/ (body == t /\ bds == [])
)
| false | false |
FStar.Reflection.V2.Derived.Lemmas.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 collect_abs_ln_order : (t:term) ->
Lemma (ensures forall bds body.
(bds, body) == collect_abs_ln t ==>
(body << t /\ bds <<: t)
\/ (body == t /\ bds == [])
)
|
[] |
FStar.Reflection.V2.Derived.Lemmas.collect_abs_ln_order
|
{
"file_name": "ulib/FStar.Reflection.V2.Derived.Lemmas.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
t: FStar.Reflection.Types.term
-> FStar.Pervasives.Lemma
(ensures
forall (bds: Prims.list FStar.Reflection.Types.binder) (body: FStar.Reflection.Types.term).
FStar.Pervasives.Native.Mktuple2 bds body == FStar.Reflection.V2.Derived.collect_abs_ln t ==>
body << t /\ bds <<: t \/ body == t /\ bds == [])
|
{
"end_col": 13,
"end_line": 91,
"start_col": 4,
"start_line": 87
}
|
FStar.Pervasives.Lemma
|
val collect_abs_order' (bds: binders) (tt t: term)
: Lemma (requires t << tt /\ bds <<: tt)
(ensures
(let bds', body = collect_abs' bds t in
(bds' <<: tt /\ body << tt)))
(decreases t)
|
[
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"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 collect_abs_order' (bds: binders) (tt t: term)
: Lemma (requires t << tt /\ bds <<: tt)
(ensures (let bds', body = collect_abs' bds t in
(bds' <<: tt /\ body << tt)))
(decreases t)
= match inspect_ln_unascribe t with
| Tv_Abs b body -> collect_abs_order' (b::bds) tt body
| _ -> ()
|
val collect_abs_order' (bds: binders) (tt t: term)
: Lemma (requires t << tt /\ bds <<: tt)
(ensures
(let bds', body = collect_abs' bds t in
(bds' <<: tt /\ body << tt)))
(decreases t)
let rec collect_abs_order' (bds: binders) (tt t: term)
: Lemma (requires t << tt /\ bds <<: tt)
(ensures
(let bds', body = collect_abs' bds t in
(bds' <<: tt /\ body << tt)))
(decreases t) =
| false | null | true |
match inspect_ln_unascribe t with
| Tv_Abs b body -> collect_abs_order' (b :: bds) tt body
| _ -> ()
|
{
"checked_file": "FStar.Reflection.V2.Derived.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Reflection.V2.Derived.fst.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.Lemmas.fst"
}
|
[
"lemma",
""
] |
[
"FStar.Reflection.Types.binders",
"FStar.Reflection.Types.term",
"FStar.Reflection.V2.Derived.inspect_ln_unascribe",
"FStar.Reflection.Types.binder",
"FStar.Reflection.V2.Derived.Lemmas.collect_abs_order'",
"Prims.Cons",
"FStar.Reflection.V2.Data.term_view",
"Prims.unit",
"Prims.l_and",
"Prims.precedes",
"FStar.Reflection.V2.Derived.Lemmas.op_Less_Less_Colon",
"Prims.squash",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.V2.Derived.collect_abs'",
"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.Reflection.V2.Derived.Lemmas
open FStar.Reflection.Types
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Reflection.V2.Derived
open FStar.List.Tot
let rec forall_list (p:'a -> Type) (l:list 'a) : Type =
match l with
| [] -> True
| x::xs -> p x /\ forall_list p xs
let forallP (p: 'a -> Type) (l: list 'a): Type
= forall (x: 'a). memP x l ==> p x
// Precedence relation on the element of a list
unfold let (<<:) (l: list 'a) (r: 'r)
= forallP (fun x -> x << r) l
// A glorified `id`
val list_ref : (#a:Type) -> (#p:(a -> Type)) -> (l:list a) ->
Pure (list (x:a{p x}))
(requires (forallP p l))
(ensures (fun _ -> True))
let rec list_ref #a #p l =
match l with
| [] -> []
| x::xs -> x :: list_ref #a #p xs
val collect_app_order' : (args:list argv) -> (tt:term) -> (t:term) ->
Lemma (requires args <<: tt /\ t << tt)
(ensures (let fn, args' = collect_app_ln' args t in
args' <<: tt /\ fn << tt))
(decreases t)
let rec collect_app_order' args tt t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' (r::args) tt l
| _ -> ()
val collect_app_order : (t:term) ->
Lemma (ensures (forall (f:term). forall (s:list argv). (f,s) == collect_app_ln t ==>
(f << t /\ s <<: t)
\/ (f == t /\ s == [])))
let collect_app_order t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' [r] t l
| _ -> ()
val collect_app_ref : (t:term) -> (h:term{h == t \/ h << t}) * list (a:argv{fst a << t})
let collect_app_ref t =
let h, a = collect_app_ln t in
collect_app_order t;
h, list_ref a
(**** [collect_abs_ln t] is smaller than [t] *)
let rec collect_abs_order' (bds: binders) (tt t: term)
: Lemma (requires t << tt /\ bds <<: tt)
(ensures (let bds', body = collect_abs' bds t in
(bds' <<: tt /\ body << tt)))
| false | false |
FStar.Reflection.V2.Derived.Lemmas.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 collect_abs_order' (bds: binders) (tt t: term)
: Lemma (requires t << tt /\ bds <<: tt)
(ensures
(let bds', body = collect_abs' bds t in
(bds' <<: tt /\ body << tt)))
(decreases t)
|
[
"recursion"
] |
FStar.Reflection.V2.Derived.Lemmas.collect_abs_order'
|
{
"file_name": "ulib/FStar.Reflection.V2.Derived.Lemmas.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
bds: FStar.Reflection.Types.binders ->
tt: FStar.Reflection.Types.term ->
t: FStar.Reflection.Types.term
-> FStar.Pervasives.Lemma (requires t << tt /\ bds <<: tt)
(ensures
(let _ = FStar.Reflection.V2.Derived.collect_abs' bds t in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ bds' body = _ in
bds' <<: tt /\ body << tt)
<:
Type0))
(decreases t)
|
{
"end_col": 13,
"end_line": 78,
"start_col": 4,
"start_line": 76
}
|
FStar.Pervasives.Lemma
|
val collect_arr_order' (bds: binders) (tt: term) (c: comp)
: Lemma (requires c << tt /\ bds <<: tt)
(ensures
(let bds', c' = collect_arr' bds c in
bds' <<: tt /\ c' << tt))
(decreases c)
|
[
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"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 collect_arr_order' (bds: binders) (tt: term) (c: comp)
: Lemma (requires c << tt /\ bds <<: tt)
(ensures (let bds', c' = collect_arr' bds c in
bds' <<: tt /\ c' << tt))
(decreases c)
= match inspect_comp c with
| C_Total ret ->
( match inspect_ln_unascribe ret with
| Tv_Arrow b c -> collect_arr_order' (b::bds) tt c
| _ -> ())
| _ -> ()
|
val collect_arr_order' (bds: binders) (tt: term) (c: comp)
: Lemma (requires c << tt /\ bds <<: tt)
(ensures
(let bds', c' = collect_arr' bds c in
bds' <<: tt /\ c' << tt))
(decreases c)
let rec collect_arr_order' (bds: binders) (tt: term) (c: comp)
: Lemma (requires c << tt /\ bds <<: tt)
(ensures
(let bds', c' = collect_arr' bds c in
bds' <<: tt /\ c' << tt))
(decreases c) =
| false | null | true |
match inspect_comp c with
| C_Total ret ->
(match inspect_ln_unascribe ret with
| Tv_Arrow b c -> collect_arr_order' (b :: bds) tt c
| _ -> ())
| _ -> ()
|
{
"checked_file": "FStar.Reflection.V2.Derived.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Reflection.V2.Derived.fst.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.Lemmas.fst"
}
|
[
"lemma",
""
] |
[
"FStar.Reflection.Types.binders",
"FStar.Reflection.Types.term",
"FStar.Reflection.Types.comp",
"FStar.Reflection.V2.Builtins.inspect_comp",
"FStar.Reflection.Types.typ",
"FStar.Reflection.V2.Derived.inspect_ln_unascribe",
"FStar.Reflection.Types.binder",
"FStar.Reflection.V2.Derived.Lemmas.collect_arr_order'",
"Prims.Cons",
"FStar.Reflection.V2.Data.term_view",
"Prims.unit",
"FStar.Reflection.V2.Data.comp_view",
"Prims.l_and",
"Prims.precedes",
"FStar.Reflection.V2.Derived.Lemmas.op_Less_Less_Colon",
"Prims.squash",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.V2.Derived.collect_arr'",
"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.Reflection.V2.Derived.Lemmas
open FStar.Reflection.Types
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Reflection.V2.Derived
open FStar.List.Tot
let rec forall_list (p:'a -> Type) (l:list 'a) : Type =
match l with
| [] -> True
| x::xs -> p x /\ forall_list p xs
let forallP (p: 'a -> Type) (l: list 'a): Type
= forall (x: 'a). memP x l ==> p x
// Precedence relation on the element of a list
unfold let (<<:) (l: list 'a) (r: 'r)
= forallP (fun x -> x << r) l
// A glorified `id`
val list_ref : (#a:Type) -> (#p:(a -> Type)) -> (l:list a) ->
Pure (list (x:a{p x}))
(requires (forallP p l))
(ensures (fun _ -> True))
let rec list_ref #a #p l =
match l with
| [] -> []
| x::xs -> x :: list_ref #a #p xs
val collect_app_order' : (args:list argv) -> (tt:term) -> (t:term) ->
Lemma (requires args <<: tt /\ t << tt)
(ensures (let fn, args' = collect_app_ln' args t in
args' <<: tt /\ fn << tt))
(decreases t)
let rec collect_app_order' args tt t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' (r::args) tt l
| _ -> ()
val collect_app_order : (t:term) ->
Lemma (ensures (forall (f:term). forall (s:list argv). (f,s) == collect_app_ln t ==>
(f << t /\ s <<: t)
\/ (f == t /\ s == [])))
let collect_app_order t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' [r] t l
| _ -> ()
val collect_app_ref : (t:term) -> (h:term{h == t \/ h << t}) * list (a:argv{fst a << t})
let collect_app_ref t =
let h, a = collect_app_ln t in
collect_app_order t;
h, list_ref a
(**** [collect_abs_ln t] is smaller than [t] *)
let rec collect_abs_order' (bds: binders) (tt t: term)
: Lemma (requires t << tt /\ bds <<: tt)
(ensures (let bds', body = collect_abs' bds t in
(bds' <<: tt /\ body << tt)))
(decreases t)
= match inspect_ln_unascribe t with
| Tv_Abs b body -> collect_abs_order' (b::bds) tt body
| _ -> ()
val collect_abs_ln_order : (t:term) ->
Lemma (ensures forall bds body.
(bds, body) == collect_abs_ln t ==>
(body << t /\ bds <<: t)
\/ (body == t /\ bds == [])
)
let collect_abs_ln_order t =
match inspect_ln_unascribe t with
| Tv_Abs b body -> collect_abs_order' [b] t body;
let bds, body = collect_abs' [] t in
Classical.forall_intro (rev_memP bds)
| _ -> ()
val collect_abs_ln_ref : (t:term) -> list (bd:binder{bd << t}) * (body:term{body == t \/ body << t})
let collect_abs_ln_ref t =
let bds, body = collect_abs_ln t in
collect_abs_ln_order t;
list_ref bds, body
(**** [collect_arr_ln_bs t] is smaller than [t] *)
let rec collect_arr_order' (bds: binders) (tt: term) (c: comp)
: Lemma (requires c << tt /\ bds <<: tt)
(ensures (let bds', c' = collect_arr' bds c in
bds' <<: tt /\ c' << tt))
| false | false |
FStar.Reflection.V2.Derived.Lemmas.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 collect_arr_order' (bds: binders) (tt: term) (c: comp)
: Lemma (requires c << tt /\ bds <<: tt)
(ensures
(let bds', c' = collect_arr' bds c in
bds' <<: tt /\ c' << tt))
(decreases c)
|
[
"recursion"
] |
FStar.Reflection.V2.Derived.Lemmas.collect_arr_order'
|
{
"file_name": "ulib/FStar.Reflection.V2.Derived.Lemmas.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
bds: FStar.Reflection.Types.binders ->
tt: FStar.Reflection.Types.term ->
c: FStar.Reflection.Types.comp
-> FStar.Pervasives.Lemma (requires c << tt /\ bds <<: tt)
(ensures
(let _ = FStar.Reflection.V2.Derived.collect_arr' bds c in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ bds' c' = _ in
bds' <<: tt /\ c' << tt)
<:
Type0))
(decreases c)
|
{
"end_col": 13,
"end_line": 112,
"start_col": 4,
"start_line": 107
}
|
FStar.Pervasives.Lemma
|
val collect_arr_ln_bs_order : (t:term) ->
Lemma (ensures forall bds c.
(bds, c) == collect_arr_ln_bs t ==>
(c << t /\ bds <<: t)
\/ (c == pack_comp (C_Total t) /\ bds == [])
)
|
[
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"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 collect_arr_ln_bs_order t =
match inspect_ln_unascribe t with
| Tv_Arrow b c -> collect_arr_order' [b] t c;
Classical.forall_intro_2 (rev_memP #binder);
inspect_pack_comp_inv (C_Total t)
| _ -> inspect_pack_comp_inv (C_Total t)
|
val collect_arr_ln_bs_order : (t:term) ->
Lemma (ensures forall bds c.
(bds, c) == collect_arr_ln_bs t ==>
(c << t /\ bds <<: t)
\/ (c == pack_comp (C_Total t) /\ bds == [])
)
let collect_arr_ln_bs_order t =
| false | null | true |
match inspect_ln_unascribe t with
| Tv_Arrow b c ->
collect_arr_order' [b] t c;
Classical.forall_intro_2 (rev_memP #binder);
inspect_pack_comp_inv (C_Total t)
| _ -> inspect_pack_comp_inv (C_Total t)
|
{
"checked_file": "FStar.Reflection.V2.Derived.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Reflection.V2.Derived.fst.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.Lemmas.fst"
}
|
[
"lemma"
] |
[
"FStar.Reflection.Types.term",
"FStar.Reflection.V2.Derived.inspect_ln_unascribe",
"FStar.Reflection.Types.binder",
"FStar.Reflection.Types.comp",
"FStar.Reflection.V2.Builtins.inspect_pack_comp_inv",
"FStar.Reflection.V2.Data.C_Total",
"Prims.unit",
"FStar.Classical.forall_intro_2",
"Prims.list",
"Prims.l_iff",
"FStar.List.Tot.Base.memP",
"FStar.List.Tot.Base.rev",
"FStar.List.Tot.Properties.rev_memP",
"FStar.Reflection.V2.Derived.Lemmas.collect_arr_order'",
"Prims.Cons",
"Prims.Nil",
"FStar.Reflection.V2.Data.term_view"
] |
[] |
(*
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.Reflection.V2.Derived.Lemmas
open FStar.Reflection.Types
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Reflection.V2.Derived
open FStar.List.Tot
let rec forall_list (p:'a -> Type) (l:list 'a) : Type =
match l with
| [] -> True
| x::xs -> p x /\ forall_list p xs
let forallP (p: 'a -> Type) (l: list 'a): Type
= forall (x: 'a). memP x l ==> p x
// Precedence relation on the element of a list
unfold let (<<:) (l: list 'a) (r: 'r)
= forallP (fun x -> x << r) l
// A glorified `id`
val list_ref : (#a:Type) -> (#p:(a -> Type)) -> (l:list a) ->
Pure (list (x:a{p x}))
(requires (forallP p l))
(ensures (fun _ -> True))
let rec list_ref #a #p l =
match l with
| [] -> []
| x::xs -> x :: list_ref #a #p xs
val collect_app_order' : (args:list argv) -> (tt:term) -> (t:term) ->
Lemma (requires args <<: tt /\ t << tt)
(ensures (let fn, args' = collect_app_ln' args t in
args' <<: tt /\ fn << tt))
(decreases t)
let rec collect_app_order' args tt t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' (r::args) tt l
| _ -> ()
val collect_app_order : (t:term) ->
Lemma (ensures (forall (f:term). forall (s:list argv). (f,s) == collect_app_ln t ==>
(f << t /\ s <<: t)
\/ (f == t /\ s == [])))
let collect_app_order t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' [r] t l
| _ -> ()
val collect_app_ref : (t:term) -> (h:term{h == t \/ h << t}) * list (a:argv{fst a << t})
let collect_app_ref t =
let h, a = collect_app_ln t in
collect_app_order t;
h, list_ref a
(**** [collect_abs_ln t] is smaller than [t] *)
let rec collect_abs_order' (bds: binders) (tt t: term)
: Lemma (requires t << tt /\ bds <<: tt)
(ensures (let bds', body = collect_abs' bds t in
(bds' <<: tt /\ body << tt)))
(decreases t)
= match inspect_ln_unascribe t with
| Tv_Abs b body -> collect_abs_order' (b::bds) tt body
| _ -> ()
val collect_abs_ln_order : (t:term) ->
Lemma (ensures forall bds body.
(bds, body) == collect_abs_ln t ==>
(body << t /\ bds <<: t)
\/ (body == t /\ bds == [])
)
let collect_abs_ln_order t =
match inspect_ln_unascribe t with
| Tv_Abs b body -> collect_abs_order' [b] t body;
let bds, body = collect_abs' [] t in
Classical.forall_intro (rev_memP bds)
| _ -> ()
val collect_abs_ln_ref : (t:term) -> list (bd:binder{bd << t}) * (body:term{body == t \/ body << t})
let collect_abs_ln_ref t =
let bds, body = collect_abs_ln t in
collect_abs_ln_order t;
list_ref bds, body
(**** [collect_arr_ln_bs t] is smaller than [t] *)
let rec collect_arr_order' (bds: binders) (tt: term) (c: comp)
: Lemma (requires c << tt /\ bds <<: tt)
(ensures (let bds', c' = collect_arr' bds c in
bds' <<: tt /\ c' << tt))
(decreases c)
= match inspect_comp c with
| C_Total ret ->
( match inspect_ln_unascribe ret with
| Tv_Arrow b c -> collect_arr_order' (b::bds) tt c
| _ -> ())
| _ -> ()
val collect_arr_ln_bs_order : (t:term) ->
Lemma (ensures forall bds c.
(bds, c) == collect_arr_ln_bs t ==>
(c << t /\ bds <<: t)
\/ (c == pack_comp (C_Total t) /\ bds == [])
)
| false | false |
FStar.Reflection.V2.Derived.Lemmas.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 collect_arr_ln_bs_order : (t:term) ->
Lemma (ensures forall bds c.
(bds, c) == collect_arr_ln_bs t ==>
(c << t /\ bds <<: t)
\/ (c == pack_comp (C_Total t) /\ bds == [])
)
|
[] |
FStar.Reflection.V2.Derived.Lemmas.collect_arr_ln_bs_order
|
{
"file_name": "ulib/FStar.Reflection.V2.Derived.Lemmas.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
t: FStar.Reflection.Types.term
-> FStar.Pervasives.Lemma
(ensures
forall (bds: Prims.list FStar.Reflection.Types.binder) (c: FStar.Reflection.Types.comp).
FStar.Pervasives.Native.Mktuple2 bds c == FStar.Reflection.V2.Derived.collect_arr_ln_bs t ==>
c << t /\ bds <<: t \/
c == FStar.Reflection.V2.Builtins.pack_comp (FStar.Reflection.V2.Data.C_Total t) /\
bds == [])
|
{
"end_col": 42,
"end_line": 125,
"start_col": 2,
"start_line": 121
}
|
FStar.Pervasives.Lemma
|
val collect_app_order' : (args:list argv) -> (tt:term) -> (t:term) ->
Lemma (requires args <<: tt /\ t << tt)
(ensures (let fn, args' = collect_app_ln' args t in
args' <<: tt /\ fn << tt))
(decreases t)
|
[
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Derived",
"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 collect_app_order' args tt t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' (r::args) tt l
| _ -> ()
|
val collect_app_order' : (args:list argv) -> (tt:term) -> (t:term) ->
Lemma (requires args <<: tt /\ t << tt)
(ensures (let fn, args' = collect_app_ln' args t in
args' <<: tt /\ fn << tt))
(decreases t)
let rec collect_app_order' args tt t =
| false | null | true |
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' (r :: args) tt l
| _ -> ()
|
{
"checked_file": "FStar.Reflection.V2.Derived.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Reflection.V2.Derived.fst.checked",
"FStar.Reflection.V2.Data.fsti.checked",
"FStar.Reflection.V2.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V2.Derived.Lemmas.fst"
}
|
[
"lemma",
""
] |
[
"Prims.list",
"FStar.Reflection.V2.Data.argv",
"FStar.Reflection.Types.term",
"FStar.Reflection.V2.Derived.inspect_ln_unascribe",
"FStar.Reflection.V2.Derived.Lemmas.collect_app_order'",
"Prims.Cons",
"FStar.Reflection.V2.Data.term_view",
"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.Reflection.V2.Derived.Lemmas
open FStar.Reflection.Types
open FStar.Reflection.V2.Builtins
open FStar.Reflection.V2.Data
open FStar.Reflection.V2.Derived
open FStar.List.Tot
let rec forall_list (p:'a -> Type) (l:list 'a) : Type =
match l with
| [] -> True
| x::xs -> p x /\ forall_list p xs
let forallP (p: 'a -> Type) (l: list 'a): Type
= forall (x: 'a). memP x l ==> p x
// Precedence relation on the element of a list
unfold let (<<:) (l: list 'a) (r: 'r)
= forallP (fun x -> x << r) l
// A glorified `id`
val list_ref : (#a:Type) -> (#p:(a -> Type)) -> (l:list a) ->
Pure (list (x:a{p x}))
(requires (forallP p l))
(ensures (fun _ -> True))
let rec list_ref #a #p l =
match l with
| [] -> []
| x::xs -> x :: list_ref #a #p xs
val collect_app_order' : (args:list argv) -> (tt:term) -> (t:term) ->
Lemma (requires args <<: tt /\ t << tt)
(ensures (let fn, args' = collect_app_ln' args t in
args' <<: tt /\ fn << tt))
(decreases t)
| false | false |
FStar.Reflection.V2.Derived.Lemmas.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 collect_app_order' : (args:list argv) -> (tt:term) -> (t:term) ->
Lemma (requires args <<: tt /\ t << tt)
(ensures (let fn, args' = collect_app_ln' args t in
args' <<: tt /\ fn << tt))
(decreases t)
|
[
"recursion"
] |
FStar.Reflection.V2.Derived.Lemmas.collect_app_order'
|
{
"file_name": "ulib/FStar.Reflection.V2.Derived.Lemmas.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
args: Prims.list FStar.Reflection.V2.Data.argv ->
tt: FStar.Reflection.Types.term ->
t: FStar.Reflection.Types.term
-> FStar.Pervasives.Lemma (requires args <<: tt /\ t << tt)
(ensures
(let _ = FStar.Reflection.V2.Derived.collect_app_ln' args t in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ fn args' = _ in
args' <<: tt /\ fn << tt)
<:
Type0))
(decreases t)
|
{
"end_col": 13,
"end_line": 53,
"start_col": 4,
"start_line": 51
}
|
Prims.GTot
|
val frameOf (#a: _) (b: buffer a) : GTot HS.rid
|
[
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
|
val frameOf (#a: _) (b: buffer a) : GTot HS.rid
let frameOf #a (b: buffer a) : GTot HS.rid =
| false | null | false |
HS.frameOf (content b)
|
{
"checked_file": "FStar.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
}
|
[
"sometrivial"
] |
[
"FStar.Buffer.buffer",
"FStar.Monotonic.HyperStack.frameOf",
"FStar.Buffer.lseq",
"FStar.Buffer.max_length",
"FStar.Heap.trivial_preorder",
"FStar.Buffer.content",
"FStar.Monotonic.HyperHeap.rid"
] |
[] |
(*
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.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
| false | false |
FStar.Buffer.fst
|
{
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"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 frameOf (#a: _) (b: buffer a) : GTot HS.rid
|
[] |
FStar.Buffer.frameOf
|
{
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
b: FStar.Buffer.buffer a -> Prims.GTot FStar.Monotonic.HyperHeap.rid
|
{
"end_col": 66,
"end_line": 70,
"start_col": 44,
"start_line": 70
}
|
Prims.Tot
|
[
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
|
let disjoint_from_bufs #a (b: buffer a) (bufs: TSet.set abuffer) =
| false | null | false |
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
|
{
"checked_file": "FStar.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
}
|
[
"total"
] |
[
"FStar.Buffer.buffer",
"FStar.TSet.set",
"FStar.Buffer.abuffer",
"Prims.l_Forall",
"Prims.l_imp",
"FStar.TSet.mem",
"FStar.Buffer.disjoint",
"FStar.Buffer.__proj__Buff__item__t",
"FStar.Buffer.__proj__Buff__item__b",
"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.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
| false | false |
FStar.Buffer.fst
|
{
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"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 disjoint_from_bufs : b: FStar.Buffer.buffer a -> bufs: FStar.TSet.set FStar.Buffer.abuffer -> Prims.logical
|
[] |
FStar.Buffer.disjoint_from_bufs
|
{
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
b: FStar.Buffer.buffer a -> bufs: FStar.TSet.set FStar.Buffer.abuffer -> Prims.logical
|
{
"end_col": 49,
"end_line": 191,
"start_col": 2,
"start_line": 191
}
|
|
Prims.Tot
|
val only (#t: _) (b: buffer t) : Tot (TSet.set abuffer)
|
[
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
|
val only (#t: _) (b: buffer t) : Tot (TSet.set abuffer)
let only #t (b: buffer t) : Tot (TSet.set abuffer) =
| false | null | false |
FStar.TSet.singleton (Buff #t b)
|
{
"checked_file": "FStar.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
}
|
[
"total"
] |
[
"FStar.Buffer.buffer",
"FStar.TSet.singleton",
"FStar.Buffer.abuffer",
"FStar.Buffer.Buff",
"FStar.TSet.set"
] |
[] |
(*
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.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
| false | false |
FStar.Buffer.fst
|
{
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"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 only (#t: _) (b: buffer t) : Tot (TSet.set abuffer)
|
[] |
FStar.Buffer.only
|
{
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
b: FStar.Buffer.buffer t -> FStar.TSet.set FStar.Buffer.abuffer
|
{
"end_col": 84,
"end_line": 155,
"start_col": 52,
"start_line": 155
}
|
Prims.GTot
|
val unmapped_in (#a: _) (b: buffer a) (h: mem) : GTot Type0
|
[
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
|
val unmapped_in (#a: _) (b: buffer a) (h: mem) : GTot Type0
let unmapped_in #a (b: buffer a) (h: mem) : GTot Type0 =
| false | null | false |
unused_in b h
|
{
"checked_file": "FStar.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
}
|
[
"sometrivial"
] |
[
"FStar.Buffer.buffer",
"FStar.Monotonic.HyperStack.mem",
"FStar.Buffer.unused_in"
] |
[] |
(*
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.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
| false | false |
FStar.Buffer.fst
|
{
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"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 unmapped_in (#a: _) (b: buffer a) (h: mem) : GTot Type0
|
[] |
FStar.Buffer.unmapped_in
|
{
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
b: FStar.Buffer.buffer a -> h: FStar.Monotonic.HyperStack.mem -> Prims.GTot Type0
|
{
"end_col": 68,
"end_line": 74,
"start_col": 55,
"start_line": 74
}
|
Prims.Tot
|
[
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
|
let disjoint_ref_3 a r r' r'' =
| false | null | false |
disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
|
{
"checked_file": "FStar.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
}
|
[
"total"
] |
[
"FStar.Buffer.buffer",
"FStar.HyperStack.ST.reference",
"Prims.l_and",
"FStar.Buffer.disjoint_ref_1",
"FStar.Buffer.disjoint_ref_2",
"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.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
| false | false |
FStar.Buffer.fst
|
{
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"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 disjoint_ref_3 : a: FStar.Buffer.buffer _ ->
r: FStar.HyperStack.ST.reference _ ->
r': FStar.HyperStack.ST.reference _ ->
r'': FStar.HyperStack.ST.reference _
-> Prims.logical
|
[] |
FStar.Buffer.disjoint_ref_3
|
{
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
a: FStar.Buffer.buffer _ ->
r: FStar.HyperStack.ST.reference _ ->
r': FStar.HyperStack.ST.reference _ ->
r'': FStar.HyperStack.ST.reference _
-> Prims.logical
|
{
"end_col": 77,
"end_line": 208,
"start_col": 32,
"start_line": 208
}
|
|
Prims.Tot
|
[
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 op_Bang_Bang = TSet.singleton
|
let op_Bang_Bang =
| false | null | false |
TSet.singleton
|
{
"checked_file": "FStar.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
}
|
[
"total"
] |
[
"FStar.TSet.singleton",
"FStar.TSet.set"
] |
[] |
(*
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.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
| false | false |
FStar.Buffer.fst
|
{
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"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 op_Bang_Bang : x: _ -> FStar.TSet.set _
|
[] |
FStar.Buffer.op_Bang_Bang
|
{
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
x: _ -> FStar.TSet.set _
|
{
"end_col": 33,
"end_line": 159,
"start_col": 19,
"start_line": 159
}
|
|
Prims.Tot
|
val modifies_3 (#a #a' #a'': Type) (b: buffer a) (b': buffer a') (b'': buffer a'') (h0 h1: mem)
: Type0
|
[
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
|
val modifies_3 (#a #a' #a'': Type) (b: buffer a) (b': buffer a') (b'': buffer a'') (h0 h1: mem)
: Type0
let modifies_3 (#a #a' #a'': Type) (b: buffer a) (b': buffer a') (b'': buffer a'') (h0 h1: mem)
: Type0 =
| false | null | false |
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
let rid' = frameOf b' in
let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/
(rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\
modifies_buf_1 rid'' b'' h0 h1 /\
HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1) \/
(rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\
HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1) \/
(rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\
modifies_buf_1 rid' b' h0 h1 /\
HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1) \/
(rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\
HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid'))
(Set.singleton rid''))
h0
h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\
modifies_buf_1 rid'' b'' h0 h1)))
|
{
"checked_file": "FStar.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
}
|
[
"total"
] |
[
"FStar.Buffer.buffer",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Prims.eq2",
"FStar.Monotonic.HyperHeap.rid",
"FStar.Monotonic.HyperStack.get_tip",
"Prims.l_or",
"FStar.Buffer.modifies_buf_3",
"FStar.Monotonic.HyperStack.modifies_one",
"Prims.l_not",
"FStar.Buffer.modifies_buf_2",
"FStar.Buffer.modifies_buf_1",
"FStar.Monotonic.HyperStack.modifies",
"FStar.Set.union",
"FStar.Set.singleton",
"FStar.Buffer.frameOf"
] |
[] |
(*
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.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
| false | false |
FStar.Buffer.fst
|
{
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"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 modifies_3 (#a #a' #a'': Type) (b: buffer a) (b': buffer a') (b'': buffer a'') (h0 h1: mem)
: Type0
|
[] |
FStar.Buffer.modifies_3
|
{
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
b: FStar.Buffer.buffer a ->
b': FStar.Buffer.buffer a' ->
b'': FStar.Buffer.buffer a'' ->
h0: FStar.Monotonic.HyperStack.mem ->
h1: FStar.Monotonic.HyperStack.mem
-> Type0
|
{
"end_col": 105,
"end_line": 420,
"start_col": 2,
"start_line": 409
}
|
Prims.GTot
|
val content (#a: _) (b: buffer a) : GTot (reference (lseq a (max_length b)))
|
[
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
|
val content (#a: _) (b: buffer a) : GTot (reference (lseq a (max_length b)))
let content #a (b: buffer a) : GTot (reference (lseq a (max_length b))) =
| false | null | false |
b.content
|
{
"checked_file": "FStar.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
}
|
[
"sometrivial"
] |
[
"FStar.Buffer.buffer",
"FStar.Buffer.__proj__MkBuffer__item__content",
"FStar.HyperStack.ST.reference",
"FStar.Buffer.lseq",
"FStar.Buffer.max_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.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
| false | false |
FStar.Buffer.fst
|
{
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"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 content (#a: _) (b: buffer a) : GTot (reference (lseq a (max_length b)))
|
[] |
FStar.Buffer.content
|
{
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
b: FStar.Buffer.buffer a
-> Prims.GTot (FStar.HyperStack.ST.reference (FStar.Buffer.lseq a (FStar.Buffer.max_length b)))
|
{
"end_col": 54,
"end_line": 65,
"start_col": 45,
"start_line": 65
}
|
Prims.GTot
|
[
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 as_ref #a (b:buffer a) = as_ref (content b)
|
let as_ref #a (b: buffer a) =
| false | null | false |
as_ref (content b)
|
{
"checked_file": "FStar.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
}
|
[
"sometrivial"
] |
[
"FStar.Buffer.buffer",
"FStar.Monotonic.HyperStack.as_ref",
"FStar.Buffer.lseq",
"FStar.Buffer.max_length",
"FStar.Heap.trivial_preorder",
"FStar.Buffer.content",
"FStar.Monotonic.Heap.mref"
] |
[] |
(*
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.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
| false | false |
FStar.Buffer.fst
|
{
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"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 as_ref : b: FStar.Buffer.buffer a
-> Prims.GTot
(FStar.Monotonic.Heap.mref (FStar.Buffer.lseq a (FStar.Buffer.max_length b))
(FStar.Heap.trivial_preorder (FStar.Buffer.lseq a (FStar.Buffer.max_length b))))
|
[] |
FStar.Buffer.as_ref
|
{
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
b: FStar.Buffer.buffer a
-> Prims.GTot
(FStar.Monotonic.Heap.mref (FStar.Buffer.lseq a (FStar.Buffer.max_length b))
(FStar.Heap.trivial_preorder (FStar.Buffer.lseq a (FStar.Buffer.max_length b))))
|
{
"end_col": 47,
"end_line": 68,
"start_col": 29,
"start_line": 68
}
|
|
Prims.GTot
|
[
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 as_addr #a (b:buffer a) = as_addr (content b)
|
let as_addr #a (b: buffer a) =
| false | null | false |
as_addr (content b)
|
{
"checked_file": "FStar.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
}
|
[
"sometrivial"
] |
[
"FStar.Buffer.buffer",
"FStar.Monotonic.HyperStack.as_addr",
"FStar.Buffer.lseq",
"FStar.Buffer.max_length",
"FStar.Heap.trivial_preorder",
"FStar.Buffer.content",
"Prims.pos"
] |
[] |
(*
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.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
| false | false |
FStar.Buffer.fst
|
{
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"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 as_addr : b: FStar.Buffer.buffer a -> Prims.GTot Prims.pos
|
[] |
FStar.Buffer.as_addr
|
{
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
b: FStar.Buffer.buffer a -> Prims.GTot Prims.pos
|
{
"end_col": 49,
"end_line": 69,
"start_col": 30,
"start_line": 69
}
|
|
Prims.Tot
|
[
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
|
let modifies_buf_3
(#t: Type)
(#t': Type)
(#t'': Type)
rid
(b: buffer t)
(b': buffer t')
(b'': buffer t'')
h
h'
=
| false | null | false |
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\
(forall (#tt: Type) (bb: buffer tt).
(frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==>
equal h bb h' bb /\ live h' bb)
|
{
"checked_file": "FStar.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
}
|
[
"total"
] |
[
"FStar.Monotonic.HyperHeap.rid",
"FStar.Buffer.buffer",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"FStar.Monotonic.HyperStack.modifies_ref",
"FStar.Buffer.to_set_3",
"FStar.Buffer.as_addr",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.eq2",
"FStar.Buffer.frameOf",
"FStar.Buffer.live",
"FStar.Buffer.disjoint",
"FStar.Buffer.equal",
"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.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
| false | false |
FStar.Buffer.fst
|
{
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"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 modifies_buf_3 : rid: FStar.Monotonic.HyperHeap.rid ->
b: FStar.Buffer.buffer t ->
b': FStar.Buffer.buffer t' ->
b'': FStar.Buffer.buffer t'' ->
h: FStar.Monotonic.HyperStack.mem ->
h': FStar.Monotonic.HyperStack.mem
-> Prims.logical
|
[] |
FStar.Buffer.modifies_buf_3
|
{
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
rid: FStar.Monotonic.HyperHeap.rid ->
b: FStar.Buffer.buffer t ->
b': FStar.Buffer.buffer t' ->
b'': FStar.Buffer.buffer t'' ->
h: FStar.Monotonic.HyperStack.mem ->
h': FStar.Monotonic.HyperStack.mem
-> Prims.logical
|
{
"end_col": 42,
"end_line": 260,
"start_col": 2,
"start_line": 258
}
|
|
Prims.Tot
|
[
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
|
let modifies_buf_2 (#t: Type) (#t': Type) rid (b: buffer t) (b': buffer t') h h' =
| false | null | false |
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\
(forall (#tt: Type) (bb: buffer tt).
(frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==>
equal h bb h' bb /\ live h' bb)
|
{
"checked_file": "FStar.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
}
|
[
"total"
] |
[
"FStar.Monotonic.HyperHeap.rid",
"FStar.Buffer.buffer",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"FStar.Monotonic.HyperStack.modifies_ref",
"FStar.Buffer.to_set_2",
"FStar.Buffer.as_addr",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.eq2",
"FStar.Buffer.frameOf",
"FStar.Buffer.live",
"FStar.Buffer.disjoint",
"FStar.Buffer.equal",
"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.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
| false | false |
FStar.Buffer.fst
|
{
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"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 modifies_buf_2 : rid: FStar.Monotonic.HyperHeap.rid ->
b: FStar.Buffer.buffer t ->
b': FStar.Buffer.buffer t' ->
h: FStar.Monotonic.HyperStack.mem ->
h': FStar.Monotonic.HyperStack.mem
-> Prims.logical
|
[] |
FStar.Buffer.modifies_buf_2
|
{
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
rid: FStar.Monotonic.HyperHeap.rid ->
b: FStar.Buffer.buffer t ->
b': FStar.Buffer.buffer t' ->
h: FStar.Monotonic.HyperStack.mem ->
h': FStar.Monotonic.HyperStack.mem
-> Prims.logical
|
{
"end_col": 42,
"end_line": 253,
"start_col": 2,
"start_line": 251
}
|
|
FStar.Pervasives.Lemma
|
val includes_as_seq (#a h1 h2: _) (x y: buffer a)
: Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
|
[
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
|
val includes_as_seq (#a h1 h2: _) (x y: buffer a)
: Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y)) =
| false | null | true |
Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
|
{
"checked_file": "FStar.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
}
|
[
"lemma"
] |
[
"FStar.Monotonic.HyperStack.mem",
"FStar.Buffer.buffer",
"FStar.Seq.Properties.slice_slice",
"FStar.Buffer.sel",
"FStar.Buffer.idx",
"Prims.op_Addition",
"FStar.Buffer.length",
"Prims.op_Subtraction",
"Prims.unit",
"Prims.l_and",
"FStar.Buffer.includes",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.Buffer.as_seq",
"Prims.squash",
"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.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
| false | false |
FStar.Buffer.fst
|
{
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"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 includes_as_seq (#a h1 h2: _) (x y: buffer a)
: Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
|
[] |
FStar.Buffer.includes_as_seq
|
{
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
h1: FStar.Monotonic.HyperStack.mem ->
h2: FStar.Monotonic.HyperStack.mem ->
x: FStar.Buffer.buffer a ->
y: FStar.Buffer.buffer a
-> FStar.Pervasives.Lemma
(requires FStar.Buffer.includes x y /\ FStar.Buffer.as_seq h1 x == FStar.Buffer.as_seq h2 x)
(ensures FStar.Buffer.as_seq h1 y == FStar.Buffer.as_seq h2 y)
|
{
"end_col": 99,
"end_line": 112,
"start_col": 2,
"start_line": 111
}
|
Prims.Tot
|
[
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
|
let modifies_buf_4
(#t: Type)
(#t': Type)
(#t'': Type)
(#t''': Type)
rid
(b: buffer t)
(b': buffer t')
(b'': buffer t'')
(b''': buffer t''')
h
h'
=
| false | null | false |
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\
(forall (#tt: Type) (bb: buffer tt).
(frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\
disjoint b''' bb) ==>
equal h bb h' bb /\ live h' bb)
|
{
"checked_file": "FStar.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
}
|
[
"total"
] |
[
"FStar.Monotonic.HyperHeap.rid",
"FStar.Buffer.buffer",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"FStar.Monotonic.HyperStack.modifies_ref",
"FStar.Buffer.to_set_4",
"FStar.Buffer.as_addr",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.eq2",
"FStar.Buffer.frameOf",
"FStar.Buffer.live",
"FStar.Buffer.disjoint",
"FStar.Buffer.equal",
"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.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
| false | false |
FStar.Buffer.fst
|
{
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"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 modifies_buf_4 : rid: FStar.Monotonic.HyperHeap.rid ->
b: FStar.Buffer.buffer t ->
b': FStar.Buffer.buffer t' ->
b'': FStar.Buffer.buffer t'' ->
b''': FStar.Buffer.buffer t''' ->
h: FStar.Monotonic.HyperStack.mem ->
h': FStar.Monotonic.HyperStack.mem
-> Prims.logical
|
[] |
FStar.Buffer.modifies_buf_4
|
{
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
rid: FStar.Monotonic.HyperHeap.rid ->
b: FStar.Buffer.buffer t ->
b': FStar.Buffer.buffer t' ->
b'': FStar.Buffer.buffer t'' ->
b''': FStar.Buffer.buffer t''' ->
h: FStar.Monotonic.HyperStack.mem ->
h': FStar.Monotonic.HyperStack.mem
-> Prims.logical
|
{
"end_col": 42,
"end_line": 268,
"start_col": 2,
"start_line": 266
}
|
|
Prims.GTot
|
val freeable (#a: Type) (b: buffer a) : GTot Type0
|
[
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
|
val freeable (#a: Type) (b: buffer a) : GTot Type0
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
| false | null | false |
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
|
{
"checked_file": "FStar.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
}
|
[
"sometrivial"
] |
[
"FStar.Buffer.buffer",
"Prims.l_and",
"Prims.b2t",
"FStar.Monotonic.HyperStack.is_mm",
"FStar.Buffer.lseq",
"FStar.UInt32.v",
"FStar.Buffer.__proj__MkBuffer__item__max_length",
"FStar.Heap.trivial_preorder",
"FStar.Buffer.__proj__MkBuffer__item__content",
"FStar.HyperStack.ST.is_eternal_region",
"FStar.Buffer.frameOf",
"Prims.eq2",
"Prims.int",
"FStar.Buffer.idx"
] |
[] |
(*
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.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
| false | false |
FStar.Buffer.fst
|
{
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"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 freeable (#a: Type) (b: buffer a) : GTot Type0
|
[] |
FStar.Buffer.freeable
|
{
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
b: FStar.Buffer.buffer a -> Prims.GTot Type0
|
{
"end_col": 64,
"end_line": 905,
"start_col": 2,
"start_line": 905
}
|
Prims.Tot
|
val join
(#t: _)
(b: buffer t)
(b':
buffer t
{ b.max_length == b'.max_length /\ b.content === b'.content /\
idx b + length b == idx b' })
: Tot (buffer t)
|
[
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 join #t (b:buffer t) (b':buffer t{b.max_length == b'.max_length /\ b.content === b'.content /\ idx b + length b == idx b'}) : Tot (buffer t)
= MkBuffer (b.max_length) (b.content) (b.idx) (FStar.UInt32.(b.length +^ b'.length))
|
val join
(#t: _)
(b: buffer t)
(b':
buffer t
{ b.max_length == b'.max_length /\ b.content === b'.content /\
idx b + length b == idx b' })
: Tot (buffer t)
let join
#t
(b: buffer t)
(b':
buffer t
{ b.max_length == b'.max_length /\ b.content === b'.content /\
idx b + length b == idx b' })
: Tot (buffer t) =
| false | null | false |
MkBuffer (b.max_length) (b.content) (b.idx) (let open FStar.UInt32 in b.length +^ b'.length)
|
{
"checked_file": "FStar.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
}
|
[
"total"
] |
[
"FStar.Buffer.buffer",
"Prims.l_and",
"Prims.eq2",
"FStar.UInt32.t",
"FStar.Buffer.__proj__MkBuffer__item__max_length",
"Prims.op_Equals_Equals_Equals",
"FStar.HyperStack.ST.reference",
"FStar.Buffer.lseq",
"FStar.UInt32.v",
"FStar.Buffer.__proj__MkBuffer__item__content",
"Prims.int",
"Prims.op_Addition",
"FStar.Buffer.idx",
"FStar.Buffer.length",
"FStar.Buffer.MkBuffer",
"FStar.Buffer.__proj__MkBuffer__item__idx",
"FStar.UInt32.op_Plus_Hat",
"FStar.Buffer.__proj__MkBuffer__item__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.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
(** This function allocates a buffer into a manually-managed buffer in a heap
* region, meaning that the client must call rfree in order to avoid memory
* leaks. It translates to C as a straight malloc. *)
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
= rcreate_common r init len true
#reset-options
(** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *)
let rfree (#a:Type) (b:buffer a)
:ST unit (requires (fun h0 -> live h0 b /\ freeable b))
(ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
= rfree b.content
(* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *)
(* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *)
(* (requires (fun h -> True)) *)
(* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *)
(* let create_null #a init len = *)
(* push_frame(); *)
(* let r = create init len in *)
(* pop_frame(); *)
(* r *)
#reset-options "--initial_fuel 0 --max_fuel 0"
// ocaml-only, used for conversions to Platform.bytes
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
(*/\ r == as_seq #a h1 b *) ))
let to_seq #a b l =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v l)
// ocaml-only, used for conversions to Platform.bytes
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\
r == as_seq #a h1 b ))
let to_seq_full #a b =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v b.length)
val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> live h0 b /\ h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let index #a b n =
let s = !b.content in
Seq.index s (v b.idx + v n)
(** REMARK: the proof of this lemma relies crucially on the `a == a'` condition
// in `disjoint`, and on the pattern in `Seq.slice_upd` *)
private let lemma_aux_0
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt)
:Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb))
(ensures (live h0 b /\ live h0 bb /\
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ()
#set-options "--z3rlimit 10"
private let lemma_aux_1
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_0 b n z h0 tt))
#reset-options "--initial_fuel 0 --max_fuel 0"
private let lemma_aux_2
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_1 b n z h0))
private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a
-> h0:mem -> Lemma
(requires (live h0 b))
(ensures (live h0 b
/\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) ))
[SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))]
let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0
val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
let upd #a b n z =
let h0 = HST.get () in
let s0 = !b.content in
let s = Seq.upd s0 (v b.idx + v n) z in
b.content := s;
lemma_aux b n z h0;
let h = HST.get() in
Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b));
Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z
val sub: #a:Type -> b:buffer a -> i:UInt32.t
-> len:UInt32.t{v i + v len <= length b}
-> Tot (b':buffer a{b `includes` b' /\ length b' == v len})
let sub #a b i len =
assert (v i + v b.idx < pow2 n); // was formerly a precondition
MkBuffer b.max_length b.content (i +^ b.idx) len
let sub_sub
(#a: Type)
(b: buffer a)
(i1: UInt32.t)
(len1: UInt32.t{v i1 + v len1 <= length b})
(i2: UInt32.t)
(len2: UInt32.t {v i2 + v len2 <= v len1})
: Lemma
(ensures (sub (sub b i1 len1) i2 len2 == sub b (i1 +^ i2) len2))
= ()
let sub_zero_length
(#a: Type)
(b: buffer a)
: Lemma
(ensures (sub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b))
= ()
let lemma_sub_spec (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (sub b i len); SMTPat (live h b)]
= Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len))
let lemma_sub_spec' (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (live h (sub b i len))]
= lemma_sub_spec b i len h
val offset: #a:Type -> b:buffer a
-> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length}
-> Tot (b':buffer a{b `includes` b'})
let offset #a b i =
MkBuffer b.max_length b.content (i +^ b.idx) (b.length -^ i)
let lemma_offset_spec (#a:Type) (b:buffer a)
(i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length})
h : Lemma
(requires True)
(ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b)))
[SMTPatOr [[SMTPat (as_seq h (offset b i))];
[SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]]
= Seq.lemma_eq_intro (as_seq h (offset b i)) (Seq.slice (as_seq h b) (v i) (length b))
private val eq_lemma1:
#a:eqtype
-> b1:buffer a
-> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> h:mem
-> Lemma
(requires (forall (j:nat). j < v len ==> get h b1 j == get h b2 j))
(ensures equal h (sub b1 0ul len) h (sub b2 0ul len))
[SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))]
let eq_lemma1 #a b1 b2 len h =
Seq.lemma_eq_intro (as_seq h (sub b1 0ul len)) (as_seq h (sub b2 0ul len))
#reset-options "--z3rlimit 20"
private val eq_lemma2:
#a:eqtype
-> b1:buffer a
-> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> h:mem
-> Lemma
(requires equal h (sub b1 0ul len) h (sub b2 0ul len))
(ensures (forall (j:nat). j < v len ==> get h b1 j == get h b2 j))
[SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))]
let eq_lemma2 #a b1 b2 len h =
let s1 = as_seq h (sub b1 0ul len) in
let s2 = as_seq h (sub b2 0ul len) in
cut (forall (j:nat). j < v len ==> get h b1 j == Seq.index s1 j);
cut (forall (j:nat). j < v len ==> get h b2 j == Seq.index s2 j)
(** Corresponds to memcmp for `eqtype` *)
val eqb: #a:eqtype -> b1:buffer a -> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> ST bool
(requires (fun h -> live h b1 /\ live h b2))
(ensures (fun h0 z h1 -> h1 == h0 /\
(z <==> equal h0 (sub b1 0ul len) h0 (sub b2 0ul len))))
let rec eqb #a b1 b2 len =
if len =^ 0ul then true
else
let len' = len -^ 1ul in
if index b1 len' = index b2 len' then
eqb b1 b2 len'
else
false
(**
// Defining operators for buffer accesses as specified at
// https://github.com/FStarLang/FStar/wiki/Parsing-and-operator-precedence
// *)
(* JP: if the [val] is not specified, there's an issue with these functions
// * taking an extra unification parameter at extraction-time... *)
val op_Array_Access: #a:Type -> b:buffer a -> n:UInt32.t{v n<length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let op_Array_Access #a b n = index #a b n
val op_Array_Assignment: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
let op_Array_Assignment #a b n z = upd #a b n z
let lemma_modifies_one_trans_1 (#a:Type) (b:buffer a) (h0:mem) (h1:mem) (h2:mem): Lemma
(requires (modifies_one (frameOf b) h0 h1 /\ modifies_one (frameOf b) h1 h2))
(ensures (modifies_one (frameOf b) h0 h2))
[SMTPat (modifies_one (frameOf b) h0 h1); SMTPat (modifies_one (frameOf b) h1 h2)]
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(** Corresponds to memcpy *)
val blit: #t:Type
-> a:buffer t
-> idx_a:UInt32.t{v idx_a <= length a}
-> b:buffer t{disjoint a b}
-> idx_b:UInt32.t{v idx_b <= length b}
-> len:UInt32.t{v idx_a + v len <= length a /\ v idx_b + v len <= length b}
-> Stack unit
(requires (fun h -> live h a /\ live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h0 a /\ live h1 b /\ live h1 a /\ modifies_1 b h0 h1
/\ Seq.slice (as_seq h1 b) (v idx_b) (v idx_b + v len) ==
Seq.slice (as_seq h0 a) (v idx_a) (v idx_a + v len)
/\ Seq.slice (as_seq h1 b) 0 (v idx_b) ==
Seq.slice (as_seq h0 b) 0 (v idx_b)
/\ Seq.slice (as_seq h1 b) (v idx_b+v len) (length b) ==
Seq.slice (as_seq h0 b) (v idx_b+v len) (length b) ))
let rec blit #t a idx_a b idx_b len =
let h0 = HST.get () in
if len =^ 0ul then ()
else
begin
let len' = len -^ 1ul in
blit #t a idx_a b idx_b len';
let z = a.(idx_a +^ len') in
b.(idx_b +^ len') <- z;
let h1 = HST.get() in
Seq.snoc_slice_index (as_seq h1 b) (v idx_b) (v idx_b + v len');
Seq.cons_head_tail (Seq.slice (as_seq h0 b) (v idx_b + v len') (length b));
Seq.cons_head_tail (Seq.slice (as_seq h1 b) (v idx_b + v len') (length b))
end
(** Corresponds to memset *)
val fill: #t:Type
-> b:buffer t
-> z:t
-> len:UInt32.t{v len <= length b}
-> Stack unit
(requires (fun h -> live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ modifies_1 b h0 h1
/\ Seq.slice (as_seq h1 b) 0 (v len) == Seq.create (v len) z
/\ Seq.slice (as_seq h1 b) (v len) (length b) ==
Seq.slice (as_seq h0 b) (v len) (length b) ))
let rec fill #t b z len =
let h0 = HST.get () in
if len =^ 0ul then ()
else
begin
let len' = len -^ 1ul in
fill #t b z len';
b.(len') <- z;
let h = HST.get() in
Seq.snoc_slice_index (as_seq h b) 0 (v len');
Seq.lemma_tail_slice (as_seq h b) (v len') (length b)
end;
let h1 = HST.get() in
Seq.lemma_eq_intro (Seq.slice (as_seq h1 b) 0 (v len)) (Seq.create (v len) z)
let split #t (b:buffer t) (i:UInt32.t{v i <= length b}) : Tot (buffer t * buffer t)
= sub b 0ul i, offset b i
| false | false |
FStar.Buffer.fst
|
{
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
}
| null |
val join
(#t: _)
(b: buffer t)
(b':
buffer t
{ b.max_length == b'.max_length /\ b.content === b'.content /\
idx b + length b == idx b' })
: Tot (buffer t)
|
[] |
FStar.Buffer.join
|
{
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
b: FStar.Buffer.buffer t ->
b':
FStar.Buffer.buffer t
{ MkBuffer?.max_length b == MkBuffer?.max_length b' /\
MkBuffer?.content b === MkBuffer?.content b' /\
FStar.Buffer.idx b + FStar.Buffer.length b == FStar.Buffer.idx b' }
-> FStar.Buffer.buffer t
|
{
"end_col": 86,
"end_line": 1219,
"start_col": 4,
"start_line": 1219
}
|
FStar.HyperStack.ST.ST
|
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
|
[
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 rcreate #a r init len = rcreate_common r init len false
|
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len =
| true | null | false |
rcreate_common r init len false
|
{
"checked_file": "FStar.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
}
|
[] |
[
"FStar.Monotonic.HyperHeap.rid",
"FStar.UInt32.t",
"FStar.Buffer.rcreate_common",
"FStar.Buffer.buffer"
] |
[] |
(*
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.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
| false | false |
FStar.Buffer.fst
|
{
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"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 rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
|
[] |
FStar.Buffer.rcreate
|
{
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
r: FStar.Monotonic.HyperHeap.rid -> init: a -> len: FStar.UInt32.t
-> FStar.HyperStack.ST.ST (FStar.Buffer.buffer a)
|
{
"end_col": 59,
"end_line": 898,
"start_col": 28,
"start_line": 898
}
|
FStar.HyperStack.ST.StackInline
|
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
|
[
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
|
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
| true | null | false |
let content:reference (lseq a (v len)) = salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get () in
assert (Seq.equal (as_seq h b) (sel h b));
b
|
{
"checked_file": "FStar.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
}
|
[] |
[
"FStar.UInt32.t",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Buffer.as_seq",
"FStar.Buffer.sel",
"FStar.Buffer.buffer",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"FStar.Buffer._buffer",
"FStar.Buffer.MkBuffer",
"FStar.UInt32.__uint_to_t",
"FStar.HyperStack.ST.reference",
"FStar.Buffer.lseq",
"FStar.UInt32.v",
"FStar.HyperStack.ST.salloc",
"FStar.Heap.trivial_preorder",
"FStar.Seq.Base.create",
"FStar.HyperStack.ST.mstackref"
] |
[] |
(*
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.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
| false | false |
FStar.Buffer.fst
|
{
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"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 create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
|
[] |
FStar.Buffer.create
|
{
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
init: a -> len: FStar.UInt32.t -> FStar.HyperStack.ST.StackInline (FStar.Buffer.buffer a)
|
{
"end_col": 3,
"end_line": 822,
"start_col": 24,
"start_line": 816
}
|
FStar.HyperStack.ST.Stack
|
val op_Array_Access: #a:Type -> b:buffer a -> n:UInt32.t{v n<length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
|
[
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 op_Array_Access #a b n = index #a b n
|
val op_Array_Access: #a:Type -> b:buffer a -> n:UInt32.t{v n<length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let op_Array_Access #a b n =
| true | null | false |
index #a b n
|
{
"checked_file": "FStar.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
}
|
[] |
[
"FStar.Buffer.buffer",
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt32.v",
"FStar.Buffer.length",
"FStar.Buffer.index"
] |
[] |
(*
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.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
(** This function allocates a buffer into a manually-managed buffer in a heap
* region, meaning that the client must call rfree in order to avoid memory
* leaks. It translates to C as a straight malloc. *)
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
= rcreate_common r init len true
#reset-options
(** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *)
let rfree (#a:Type) (b:buffer a)
:ST unit (requires (fun h0 -> live h0 b /\ freeable b))
(ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
= rfree b.content
(* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *)
(* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *)
(* (requires (fun h -> True)) *)
(* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *)
(* let create_null #a init len = *)
(* push_frame(); *)
(* let r = create init len in *)
(* pop_frame(); *)
(* r *)
#reset-options "--initial_fuel 0 --max_fuel 0"
// ocaml-only, used for conversions to Platform.bytes
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
(*/\ r == as_seq #a h1 b *) ))
let to_seq #a b l =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v l)
// ocaml-only, used for conversions to Platform.bytes
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\
r == as_seq #a h1 b ))
let to_seq_full #a b =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v b.length)
val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> live h0 b /\ h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let index #a b n =
let s = !b.content in
Seq.index s (v b.idx + v n)
(** REMARK: the proof of this lemma relies crucially on the `a == a'` condition
// in `disjoint`, and on the pattern in `Seq.slice_upd` *)
private let lemma_aux_0
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt)
:Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb))
(ensures (live h0 b /\ live h0 bb /\
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ()
#set-options "--z3rlimit 10"
private let lemma_aux_1
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_0 b n z h0 tt))
#reset-options "--initial_fuel 0 --max_fuel 0"
private let lemma_aux_2
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_1 b n z h0))
private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a
-> h0:mem -> Lemma
(requires (live h0 b))
(ensures (live h0 b
/\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) ))
[SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))]
let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0
val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
let upd #a b n z =
let h0 = HST.get () in
let s0 = !b.content in
let s = Seq.upd s0 (v b.idx + v n) z in
b.content := s;
lemma_aux b n z h0;
let h = HST.get() in
Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b));
Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z
val sub: #a:Type -> b:buffer a -> i:UInt32.t
-> len:UInt32.t{v i + v len <= length b}
-> Tot (b':buffer a{b `includes` b' /\ length b' == v len})
let sub #a b i len =
assert (v i + v b.idx < pow2 n); // was formerly a precondition
MkBuffer b.max_length b.content (i +^ b.idx) len
let sub_sub
(#a: Type)
(b: buffer a)
(i1: UInt32.t)
(len1: UInt32.t{v i1 + v len1 <= length b})
(i2: UInt32.t)
(len2: UInt32.t {v i2 + v len2 <= v len1})
: Lemma
(ensures (sub (sub b i1 len1) i2 len2 == sub b (i1 +^ i2) len2))
= ()
let sub_zero_length
(#a: Type)
(b: buffer a)
: Lemma
(ensures (sub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b))
= ()
let lemma_sub_spec (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (sub b i len); SMTPat (live h b)]
= Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len))
let lemma_sub_spec' (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (live h (sub b i len))]
= lemma_sub_spec b i len h
val offset: #a:Type -> b:buffer a
-> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length}
-> Tot (b':buffer a{b `includes` b'})
let offset #a b i =
MkBuffer b.max_length b.content (i +^ b.idx) (b.length -^ i)
let lemma_offset_spec (#a:Type) (b:buffer a)
(i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length})
h : Lemma
(requires True)
(ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b)))
[SMTPatOr [[SMTPat (as_seq h (offset b i))];
[SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]]
= Seq.lemma_eq_intro (as_seq h (offset b i)) (Seq.slice (as_seq h b) (v i) (length b))
private val eq_lemma1:
#a:eqtype
-> b1:buffer a
-> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> h:mem
-> Lemma
(requires (forall (j:nat). j < v len ==> get h b1 j == get h b2 j))
(ensures equal h (sub b1 0ul len) h (sub b2 0ul len))
[SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))]
let eq_lemma1 #a b1 b2 len h =
Seq.lemma_eq_intro (as_seq h (sub b1 0ul len)) (as_seq h (sub b2 0ul len))
#reset-options "--z3rlimit 20"
private val eq_lemma2:
#a:eqtype
-> b1:buffer a
-> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> h:mem
-> Lemma
(requires equal h (sub b1 0ul len) h (sub b2 0ul len))
(ensures (forall (j:nat). j < v len ==> get h b1 j == get h b2 j))
[SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))]
let eq_lemma2 #a b1 b2 len h =
let s1 = as_seq h (sub b1 0ul len) in
let s2 = as_seq h (sub b2 0ul len) in
cut (forall (j:nat). j < v len ==> get h b1 j == Seq.index s1 j);
cut (forall (j:nat). j < v len ==> get h b2 j == Seq.index s2 j)
(** Corresponds to memcmp for `eqtype` *)
val eqb: #a:eqtype -> b1:buffer a -> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> ST bool
(requires (fun h -> live h b1 /\ live h b2))
(ensures (fun h0 z h1 -> h1 == h0 /\
(z <==> equal h0 (sub b1 0ul len) h0 (sub b2 0ul len))))
let rec eqb #a b1 b2 len =
if len =^ 0ul then true
else
let len' = len -^ 1ul in
if index b1 len' = index b2 len' then
eqb b1 b2 len'
else
false
(**
// Defining operators for buffer accesses as specified at
// https://github.com/FStarLang/FStar/wiki/Parsing-and-operator-precedence
// *)
(* JP: if the [val] is not specified, there's an issue with these functions
// * taking an extra unification parameter at extraction-time... *)
val op_Array_Access: #a:Type -> b:buffer a -> n:UInt32.t{v n<length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> h1 == h0
| false | false |
FStar.Buffer.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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
}
| null |
val op_Array_Access: #a:Type -> b:buffer a -> n:UInt32.t{v n<length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
|
[] |
FStar.Buffer.op_Array_Access
|
{
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
b: FStar.Buffer.buffer a -> n: FStar.UInt32.t{FStar.UInt32.v n < FStar.Buffer.length b}
-> FStar.HyperStack.ST.Stack a
|
{
"end_col": 41,
"end_line": 1140,
"start_col": 29,
"start_line": 1140
}
|
Prims.GTot
|
val length (#a: _) (b: buffer a) : GTot nat
|
[
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 length #a (b:buffer a) : GTot nat = v b.length
|
val length (#a: _) (b: buffer a) : GTot nat
let length #a (b: buffer a) : GTot nat =
| false | null | false |
v b.length
|
{
"checked_file": "FStar.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
}
|
[
"sometrivial"
] |
[
"FStar.Buffer.buffer",
"FStar.UInt32.v",
"FStar.Buffer.__proj__MkBuffer__item__length",
"Prims.nat"
] |
[] |
(*
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.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
| false | false |
FStar.Buffer.fst
|
{
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"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 length (#a: _) (b: buffer a) : GTot nat
|
[] |
FStar.Buffer.length
|
{
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
b: FStar.Buffer.buffer a -> Prims.GTot Prims.nat
|
{
"end_col": 50,
"end_line": 60,
"start_col": 40,
"start_line": 60
}
|
Prims.GTot
|
val idx (#a: _) (b: buffer a) : GTot nat
|
[
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 idx #a (b:buffer a) : GTot nat = v b.idx
|
val idx (#a: _) (b: buffer a) : GTot nat
let idx #a (b: buffer a) : GTot nat =
| false | null | false |
v b.idx
|
{
"checked_file": "FStar.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
}
|
[
"sometrivial"
] |
[
"FStar.Buffer.buffer",
"FStar.UInt32.v",
"FStar.Buffer.__proj__MkBuffer__item__idx",
"Prims.nat"
] |
[] |
(*
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.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
| false | false |
FStar.Buffer.fst
|
{
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"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 idx (#a: _) (b: buffer a) : GTot nat
|
[] |
FStar.Buffer.idx
|
{
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
b: FStar.Buffer.buffer a -> Prims.GTot Prims.nat
|
{
"end_col": 44,
"end_line": 61,
"start_col": 37,
"start_line": 61
}
|
FStar.Pervasives.Lemma
|
val lemma_offset_spec
(#a: Type)
(b: buffer a)
(i: UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length})
(h: _)
: Lemma (requires True)
(ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b)))
[
SMTPatOr
[[SMTPat (as_seq h (offset b i))]; [SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]
]
|
[
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 lemma_offset_spec (#a:Type) (b:buffer a)
(i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length})
h : Lemma
(requires True)
(ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b)))
[SMTPatOr [[SMTPat (as_seq h (offset b i))];
[SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]]
= Seq.lemma_eq_intro (as_seq h (offset b i)) (Seq.slice (as_seq h b) (v i) (length b))
|
val lemma_offset_spec
(#a: Type)
(b: buffer a)
(i: UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length})
(h: _)
: Lemma (requires True)
(ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b)))
[
SMTPatOr
[[SMTPat (as_seq h (offset b i))]; [SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]
]
let lemma_offset_spec
(#a: Type)
(b: buffer a)
(i: UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length})
h
: Lemma (requires True)
(ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b)))
[
SMTPatOr
[[SMTPat (as_seq h (offset b i))]; [SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]
] =
| false | null | true |
Seq.lemma_eq_intro (as_seq h (offset b i)) (Seq.slice (as_seq h b) (v i) (length b))
|
{
"checked_file": "FStar.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
}
|
[
"lemma"
] |
[
"FStar.Buffer.buffer",
"FStar.UInt32.t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Addition",
"FStar.UInt32.v",
"FStar.Buffer.__proj__MkBuffer__item__idx",
"Prims.pow2",
"FStar.UInt32.n",
"Prims.op_LessThanOrEqual",
"FStar.Buffer.__proj__MkBuffer__item__length",
"FStar.Monotonic.HyperStack.mem",
"FStar.Seq.Base.lemma_eq_intro",
"FStar.Buffer.as_seq",
"FStar.Buffer.offset",
"FStar.Seq.Base.slice",
"FStar.Buffer.length",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat_or",
"Prims.list",
"FStar.Pervasives.smt_pat",
"Prims.nat",
"FStar.Seq.Base.length",
"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.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
(** This function allocates a buffer into a manually-managed buffer in a heap
* region, meaning that the client must call rfree in order to avoid memory
* leaks. It translates to C as a straight malloc. *)
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
= rcreate_common r init len true
#reset-options
(** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *)
let rfree (#a:Type) (b:buffer a)
:ST unit (requires (fun h0 -> live h0 b /\ freeable b))
(ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
= rfree b.content
(* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *)
(* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *)
(* (requires (fun h -> True)) *)
(* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *)
(* let create_null #a init len = *)
(* push_frame(); *)
(* let r = create init len in *)
(* pop_frame(); *)
(* r *)
#reset-options "--initial_fuel 0 --max_fuel 0"
// ocaml-only, used for conversions to Platform.bytes
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
(*/\ r == as_seq #a h1 b *) ))
let to_seq #a b l =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v l)
// ocaml-only, used for conversions to Platform.bytes
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\
r == as_seq #a h1 b ))
let to_seq_full #a b =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v b.length)
val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> live h0 b /\ h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let index #a b n =
let s = !b.content in
Seq.index s (v b.idx + v n)
(** REMARK: the proof of this lemma relies crucially on the `a == a'` condition
// in `disjoint`, and on the pattern in `Seq.slice_upd` *)
private let lemma_aux_0
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt)
:Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb))
(ensures (live h0 b /\ live h0 bb /\
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ()
#set-options "--z3rlimit 10"
private let lemma_aux_1
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_0 b n z h0 tt))
#reset-options "--initial_fuel 0 --max_fuel 0"
private let lemma_aux_2
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_1 b n z h0))
private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a
-> h0:mem -> Lemma
(requires (live h0 b))
(ensures (live h0 b
/\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) ))
[SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))]
let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0
val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
let upd #a b n z =
let h0 = HST.get () in
let s0 = !b.content in
let s = Seq.upd s0 (v b.idx + v n) z in
b.content := s;
lemma_aux b n z h0;
let h = HST.get() in
Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b));
Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z
val sub: #a:Type -> b:buffer a -> i:UInt32.t
-> len:UInt32.t{v i + v len <= length b}
-> Tot (b':buffer a{b `includes` b' /\ length b' == v len})
let sub #a b i len =
assert (v i + v b.idx < pow2 n); // was formerly a precondition
MkBuffer b.max_length b.content (i +^ b.idx) len
let sub_sub
(#a: Type)
(b: buffer a)
(i1: UInt32.t)
(len1: UInt32.t{v i1 + v len1 <= length b})
(i2: UInt32.t)
(len2: UInt32.t {v i2 + v len2 <= v len1})
: Lemma
(ensures (sub (sub b i1 len1) i2 len2 == sub b (i1 +^ i2) len2))
= ()
let sub_zero_length
(#a: Type)
(b: buffer a)
: Lemma
(ensures (sub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b))
= ()
let lemma_sub_spec (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (sub b i len); SMTPat (live h b)]
= Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len))
let lemma_sub_spec' (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (live h (sub b i len))]
= lemma_sub_spec b i len h
val offset: #a:Type -> b:buffer a
-> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length}
-> Tot (b':buffer a{b `includes` b'})
let offset #a b i =
MkBuffer b.max_length b.content (i +^ b.idx) (b.length -^ i)
let lemma_offset_spec (#a:Type) (b:buffer a)
(i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length})
h : Lemma
(requires True)
(ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b)))
[SMTPatOr [[SMTPat (as_seq h (offset b i))];
| false | false |
FStar.Buffer.fst
|
{
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"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 lemma_offset_spec
(#a: Type)
(b: buffer a)
(i: UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length})
(h: _)
: Lemma (requires True)
(ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b)))
[
SMTPatOr
[[SMTPat (as_seq h (offset b i))]; [SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]
]
|
[] |
FStar.Buffer.lemma_offset_spec
|
{
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
b: FStar.Buffer.buffer a ->
i:
FStar.UInt32.t
{ FStar.UInt32.v i + FStar.UInt32.v (MkBuffer?.idx b) < Prims.pow2 FStar.UInt32.n /\
FStar.UInt32.v i <= FStar.UInt32.v (MkBuffer?.length b) } ->
h: FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(ensures
FStar.Buffer.as_seq h (FStar.Buffer.offset b i) ==
FStar.Seq.Base.slice (FStar.Buffer.as_seq h b) (FStar.UInt32.v i) (FStar.Buffer.length b))
[
SMTPatOr [
[SMTPat (FStar.Buffer.as_seq h (FStar.Buffer.offset b i))];
[
SMTPat (FStar.Seq.Base.slice (FStar.Buffer.as_seq h b)
(FStar.UInt32.v i)
(FStar.Buffer.length b))
]
]
]
|
{
"end_col": 88,
"end_line": 1081,
"start_col": 4,
"start_line": 1081
}
|
Prims.GTot
|
val max_length (#a: _) (b: buffer a) : GTot nat
|
[
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 max_length #a (b:buffer a) : GTot nat = v b.max_length
|
val max_length (#a: _) (b: buffer a) : GTot nat
let max_length #a (b: buffer a) : GTot nat =
| false | null | false |
v b.max_length
|
{
"checked_file": "FStar.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
}
|
[
"sometrivial"
] |
[
"FStar.Buffer.buffer",
"FStar.UInt32.v",
"FStar.Buffer.__proj__MkBuffer__item__max_length",
"Prims.nat"
] |
[] |
(*
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.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
| false | false |
FStar.Buffer.fst
|
{
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"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 max_length (#a: _) (b: buffer a) : GTot nat
|
[] |
FStar.Buffer.max_length
|
{
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
b: FStar.Buffer.buffer a -> Prims.GTot Prims.nat
|
{
"end_col": 58,
"end_line": 59,
"start_col": 44,
"start_line": 59
}
|
Prims.GTot
|
val disjoint (#a #a': _) (x: buffer a) (y: buffer a') : GTot Type0
|
[
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
|
val disjoint (#a #a': _) (x: buffer a) (y: buffer a') : GTot Type0
let disjoint #a #a' (x: buffer a) (y: buffer a') : GTot Type0 =
| false | null | false |
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/
(a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
|
{
"checked_file": "FStar.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
}
|
[
"sometrivial"
] |
[
"FStar.Buffer.buffer",
"Prims.l_or",
"Prims.l_not",
"Prims.eq2",
"FStar.Monotonic.HyperHeap.rid",
"FStar.Buffer.frameOf",
"Prims.pos",
"FStar.Buffer.as_addr",
"Prims.l_and",
"FStar.UInt32.t",
"FStar.Buffer.__proj__MkBuffer__item__max_length",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.Buffer.idx",
"FStar.Buffer.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.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
| false | false |
FStar.Buffer.fst
|
{
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"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 disjoint (#a #a': _) (x: buffer a) (y: buffer a') : GTot Type0
|
[] |
FStar.Buffer.disjoint
|
{
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
x: FStar.Buffer.buffer a -> y: FStar.Buffer.buffer a' -> Prims.GTot Type0
|
{
"end_col": 62,
"end_line": 124,
"start_col": 2,
"start_line": 122
}
|
Prims.GTot
|
val live (#a: _) (h: mem) (b: buffer a) : GTot Type0
|
[
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
|
val live (#a: _) (h: mem) (b: buffer a) : GTot Type0
let live #a (h: mem) (b: buffer a) : GTot Type0 =
| false | null | false |
HS.contains h b.content
|
{
"checked_file": "FStar.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
}
|
[
"sometrivial"
] |
[
"FStar.Monotonic.HyperStack.mem",
"FStar.Buffer.buffer",
"FStar.Monotonic.HyperStack.contains",
"FStar.Buffer.lseq",
"FStar.UInt32.v",
"FStar.Buffer.__proj__MkBuffer__item__max_length",
"FStar.Heap.trivial_preorder",
"FStar.Buffer.__proj__MkBuffer__item__content"
] |
[] |
(*
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.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
| false | false |
FStar.Buffer.fst
|
{
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"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 live (#a: _) (h: mem) (b: buffer a) : GTot Type0
|
[] |
FStar.Buffer.live
|
{
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
h: FStar.Monotonic.HyperStack.mem -> b: FStar.Buffer.buffer a -> Prims.GTot Type0
|
{
"end_col": 71,
"end_line": 73,
"start_col": 48,
"start_line": 73
}
|
Prims.Tot
|
[
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 op_Plus_Plus = TSet.union
|
let op_Plus_Plus =
| false | null | false |
TSet.union
|
{
"checked_file": "FStar.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
}
|
[
"total"
] |
[
"FStar.TSet.union",
"FStar.TSet.set"
] |
[] |
(*
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.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
| false | false |
FStar.Buffer.fst
|
{
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"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 op_Plus_Plus : x: FStar.TSet.set _ -> y: FStar.TSet.set _ -> FStar.TSet.set _
|
[] |
FStar.Buffer.op_Plus_Plus
|
{
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
}
|
x: FStar.TSet.set _ -> y: FStar.TSet.set _ -> FStar.TSet.set _
|
{
"end_col": 29,
"end_line": 160,
"start_col": 19,
"start_line": 160
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.