file_name
stringlengths
5
52
name
stringlengths
4
95
original_source_type
stringlengths
0
23k
source_type
stringlengths
9
23k
source_definition
stringlengths
9
57.9k
source
dict
source_range
dict
file_context
stringlengths
0
721k
dependencies
dict
opens_and_abbrevs
listlengths
2
94
vconfig
dict
interleaved
bool
1 class
verbose_type
stringlengths
1
7.42k
effect
stringclasses
118 values
effect_flags
sequencelengths
0
2
mutual_with
sequencelengths
0
11
ideal_premises
sequencelengths
0
236
proof_features
sequencelengths
0
1
is_simple_lemma
bool
2 classes
is_div
bool
2 classes
is_proof
bool
2 classes
is_simply_typed
bool
2 classes
is_type
bool
2 classes
partial_definition
stringlengths
5
3.99k
completed_definiton
stringlengths
1
1.63M
isa_cross_project_example
bool
1 class
LowParse.Spec.Enum.fst
LowParse.Spec.Enum.enum_repr_of_key_cons'
val enum_repr_of_key_cons' (key repr: eqtype) (e: enum key repr) (u: unit{Cons? e}) (f: enum_repr_of_key'_t (enum_tail' e)) : Tot (enum_repr_of_key'_t e)
val enum_repr_of_key_cons' (key repr: eqtype) (e: enum key repr) (u: unit{Cons? e}) (f: enum_repr_of_key'_t (enum_tail' e)) : Tot (enum_repr_of_key'_t e)
let enum_repr_of_key_cons' (key repr: eqtype) (e: enum key repr) (u: unit { Cons? e } ) (f : enum_repr_of_key'_t (enum_tail' e)) : Tot (enum_repr_of_key'_t e) = enum_repr_of_key_cons e f
{ "file_name": "src/lowparse/LowParse.Spec.Enum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 27, "end_line": 1239, "start_col": 0, "start_line": 1233 }
module LowParse.Spec.Enum include LowParse.Spec.Combinators module L = FStar.List.Tot [@Norm] let rec list_map (#a #b: Type) (f: (a -> Tot b)) (l: list a) : Tot (l' : list b { l' == L.map f l } ) = match l with | [] -> [] | a :: q -> f a :: list_map f q type enum (key: eqtype) (repr: eqtype) = (l: list (key * repr) { L.noRepeats (list_map fst l) /\ L.noRepeats (list_map snd l) }) [@Norm] let rec list_mem (#t: eqtype) (x: t) (l: list t) : Tot (y: bool { y == true <==> L.mem x l == true } ) = match l with | [] -> false | a :: q -> (x = a || list_mem x q) inline_for_extraction let enum_key (#key #repr: eqtype) (e: enum key repr) : Tot eqtype = (s: key { list_mem s (list_map fst e) } ) inline_for_extraction let make_enum_key (#key #repr: eqtype) (e: enum key repr) (k: key) : Pure (enum_key e) (requires (list_mem k (list_map fst e))) (ensures (fun k' -> k == (k' <: key))) = k inline_for_extraction let enum_repr (#key #repr: eqtype) (e: enum key repr) : Tot eqtype = (r: repr { list_mem r (list_map snd e) } ) let flip (#a #b: Type) (c: (a * b)) : Tot (b * a) = let (ca, cb) = c in (cb, ca) let rec map_flip_flip (#a #b: Type) (l: list (a * b)) : Lemma (list_map flip (list_map flip l) == l) = match l with | [] -> () | _ :: q -> map_flip_flip q let rec map_fst_flip (#a #b: Type) (l: list (a * b)) : Lemma (list_map fst (list_map flip l) == list_map snd l) = match l with | [] -> () | _ :: q -> map_fst_flip q let rec map_snd_flip (#a #b: Type) (l: list (a * b)) : Lemma (list_map snd (list_map flip l) == list_map fst l) = match l with | [] -> () | _ :: q -> map_snd_flip q let rec assoc_mem_snd (#a #b: eqtype) (l: list (a * b)) (x: a) (y: b) : Lemma (requires (L.assoc x l == Some y)) (ensures (list_mem y (list_map snd l) == true)) (decreases l) = let ((x', y') :: l') = l in if x' = x then () else assoc_mem_snd l' x y let rec assoc_flip_elim (#a #b: eqtype) (l: list (a * b)) (y: b) (x: a) : Lemma (requires ( L.noRepeats (list_map fst l) /\ L.noRepeats (list_map snd l) /\ L.assoc y (list_map flip l) == Some x )) (ensures ( L.assoc x l == Some y )) (decreases l) = let ((x', y') :: l') = l in if y' = y then () else begin if x' = x then begin assert (list_mem x' (list_map fst l') == false); assoc_mem_snd (list_map flip l') y x; map_snd_flip l'; assert False end else assoc_flip_elim l' y x end let rec assoc_flip_intro (#a #b: eqtype) (l: list (a * b)) (y: b) (x: a) : Lemma (requires ( L.noRepeats (list_map fst l) /\ L.noRepeats (list_map snd l) /\ L.assoc x l == Some y )) (ensures ( L.assoc y (list_map flip l) == Some x )) = map_fst_flip l; map_snd_flip l; map_flip_flip l; assoc_flip_elim (list_map flip l) x y let enum_key_of_repr (#key #repr: eqtype) (e: enum key repr) (r: enum_repr e) : Pure (enum_key e) (requires True) (ensures (fun y -> L.assoc y e == Some r)) = map_fst_flip e; let e' = list_map #(key * repr) #(repr * key) flip e in L.assoc_mem r e'; let k = Some?.v (L.assoc r e') in assoc_flip_elim e r k; L.assoc_mem k e; (k <: enum_key e) let parse_enum_key_cond (#key #repr: eqtype) (e: enum key repr) (r: repr) : GTot bool = list_mem r (list_map snd e) let parse_enum_key_synth (#key #repr: eqtype) (e: enum key repr) (r: repr { parse_enum_key_cond e r == true } ) : GTot (enum_key e) = enum_key_of_repr e r let parse_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) : Tot (parser (parse_filter_kind k) (enum_key e)) = (p `parse_filter` parse_enum_key_cond e ) `parse_synth` parse_enum_key_synth e let enum_repr_of_key (#key #repr: eqtype) (e: enum key repr) (k: enum_key e) : Pure (enum_repr e) (requires True) (ensures (fun r -> L.assoc k e == Some r)) = L.assoc_mem k e; let r = Some?.v (L.assoc k e) in assoc_flip_intro e r k; L.assoc_mem r (list_map flip e); map_fst_flip e; (r <: enum_repr e) let enum_repr_of_key_of_repr (#key #repr: eqtype) (e: enum key repr) (r: enum_repr e) : Lemma (enum_repr_of_key e (enum_key_of_repr e r) == r) = () let enum_key_of_repr_of_key (#key #repr: eqtype) (e: enum key repr) (k: enum_key e) : Lemma (enum_key_of_repr e (enum_repr_of_key e k) == k) = assoc_flip_intro e (enum_repr_of_key e k) k let serialize_enum_key_synth_recip (#key #repr: eqtype) (e: enum key repr) (k: enum_key e) : GTot (r: repr { parse_enum_key_cond e r == true } ) = enum_repr_of_key e k let serialize_enum_key_synth_inverse (#key #repr: eqtype) (e: enum key repr) : Lemma (synth_inverse (parse_enum_key_synth e) (serialize_enum_key_synth_recip e)) = Classical.forall_intro (enum_key_of_repr_of_key e) let serialize_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (s: serializer p) (e: enum key repr) : Tot (serializer (parse_enum_key p e)) = serialize_enum_key_synth_inverse e; serialize_synth (parse_filter p (parse_enum_key_cond e)) (parse_enum_key_synth e) (serialize_filter s (parse_enum_key_cond e)) (serialize_enum_key_synth_recip e) () let serialize_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (s: serializer p) (e: enum key repr) (x: enum_key e) : Lemma (serialize (serialize_enum_key p s e) x == serialize s (enum_repr_of_key e x)) = serialize_enum_key_synth_inverse e; serialize_synth_eq (parse_filter p (parse_enum_key_cond e)) (parse_enum_key_synth e) (serialize_filter s (parse_enum_key_cond e)) (serialize_enum_key_synth_recip e) () x inline_for_extraction let unknown_enum_repr (#key #repr: eqtype) (e: enum key repr) : Tot Type = (r: repr { list_mem r (list_map snd e) == false } ) type maybe_enum_key (#key #repr: eqtype) (e: enum key repr) = | Known of (enum_key e) | Unknown of (unknown_enum_repr e) let maybe_enum_key_of_repr (#key #repr: eqtype) (e: enum key repr) (r: repr) : Tot (maybe_enum_key e) = if list_mem r (list_map snd e) then Known (enum_key_of_repr e r) else Unknown r let parse_maybe_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) : Tot (parser k (maybe_enum_key e)) = p `parse_synth` (maybe_enum_key_of_repr e) let parse_maybe_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) (input: bytes) : Lemma (parse (parse_maybe_enum_key p e) input == (match parse p input with | Some (x, consumed) -> Some (maybe_enum_key_of_repr e x, consumed) | _ -> None )) = parse_synth_eq p (maybe_enum_key_of_repr e) input let parse_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) (input: bytes) : Lemma (parse (parse_enum_key p e) input == (match parse p input with | Some (x, consumed) -> begin match maybe_enum_key_of_repr e x with | Known k -> Some (k, consumed) | _ -> None end | _ -> None )) = parse_filter_eq p (parse_enum_key_cond e) input; parse_synth_eq (p `parse_filter` parse_enum_key_cond e) (parse_enum_key_synth e) input let repr_of_maybe_enum_key (#key #repr: eqtype) (e: enum key repr) (x: maybe_enum_key e) : Tot (r: repr { maybe_enum_key_of_repr e r == x } ) = match x with | Known k' -> enum_key_of_repr_of_key e k' ; enum_repr_of_key e k' | Unknown r -> r let serialize_maybe_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (s: serializer p) (e: enum key repr) : Tot (serializer (parse_maybe_enum_key p e)) = serialize_synth p (maybe_enum_key_of_repr e) s (repr_of_maybe_enum_key e) () let serialize_maybe_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (s: serializer p) (e: enum key repr) (x: maybe_enum_key e) : Lemma (serialize (serialize_maybe_enum_key p s e) x == serialize s (repr_of_maybe_enum_key e x)) = serialize_synth_eq p (maybe_enum_key_of_repr e) s (repr_of_maybe_enum_key e) () x let is_total_enum (#key: eqtype) (#repr: eqtype) (l: list (key * repr)) : GTot Type0 = forall (k: key) . {:pattern (list_mem k (list_map fst l))} list_mem k (list_map fst l) let total_enum (key: eqtype) (repr: eqtype) : Tot eqtype = (l: enum key repr { is_total_enum l } ) let synth_total_enum_key (#key: eqtype) (#repr: eqtype) (l: total_enum key repr) (k: enum_key l) : Tot key = let k' : key = k in k' let parse_total_enum_key (#k: parser_kind) (#key: eqtype) (#repr: eqtype) (p: parser k repr) (l: total_enum key repr) : Tot (parser (parse_filter_kind k) key) = parse_enum_key p l `parse_synth` (synth_total_enum_key l) let synth_total_enum_key_recip (#key: eqtype) (#repr: eqtype) (l: total_enum key repr) (k: key) : Tot (k' : enum_key l { synth_total_enum_key l k' == k } ) = k let serialize_total_enum_key (#k: parser_kind) (#key: eqtype) (#repr: eqtype) (p: parser k repr) (s: serializer p) (l: total_enum key repr) : Tot (serializer (parse_total_enum_key p l)) = serialize_synth (parse_enum_key p l) (synth_total_enum_key l) (serialize_enum_key p s l) (synth_total_enum_key_recip l) () type maybe_total_enum_key (#key #repr: eqtype) (e: total_enum key repr) = | TotalKnown of key | TotalUnknown of (unknown_enum_repr e) let maybe_total_enum_key_of_repr (#key #repr: eqtype) (e: total_enum key repr) (r: repr) : Tot (maybe_total_enum_key e) = if list_mem r (list_map snd e) then TotalKnown (enum_key_of_repr e r) else TotalUnknown r let parse_maybe_total_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: total_enum key repr) : Tot (parser k (maybe_total_enum_key e)) = p `parse_synth` (maybe_total_enum_key_of_repr e) let repr_of_maybe_total_enum_key (#key #repr: eqtype) (e: total_enum key repr) (k: maybe_total_enum_key e) : Tot (r: repr { maybe_total_enum_key_of_repr e r == k } ) = match k with | TotalKnown k' -> enum_key_of_repr_of_key e k' ; enum_repr_of_key e k' | TotalUnknown r -> r let serialize_maybe_total_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (s: serializer p) (e: total_enum key repr) : Tot (serializer (parse_maybe_total_enum_key p e)) = serialize_synth p (maybe_total_enum_key_of_repr e) s (repr_of_maybe_total_enum_key e) () inline_for_extraction let maybe_enum_key_of_total (#key #repr: eqtype) (e: total_enum key repr) (k: maybe_total_enum_key e) : Tot (maybe_enum_key e) = match k with | TotalKnown ek -> Known (ek <: key) | TotalUnknown r -> Unknown r inline_for_extraction let total_of_maybe_enum_key (#key #repr: eqtype) (e: total_enum key repr) (k: maybe_enum_key e) : Tot (maybe_total_enum_key e) = match k with | Known ek -> TotalKnown (ek <: key) | Unknown r -> TotalUnknown r let maybe_total_enum_key_of_repr_eq (#key #repr: eqtype) (e: total_enum key repr) (r: repr) : Lemma (maybe_total_enum_key_of_repr e r == total_of_maybe_enum_key e (maybe_enum_key_of_repr e r)) = () let parse_maybe_total_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: total_enum key repr) (input: bytes) : Lemma (parse (parse_maybe_total_enum_key p e) input == (parse (parse_maybe_enum_key p e `parse_synth` total_of_maybe_enum_key e) input)) = parse_synth_eq p (maybe_total_enum_key_of_repr e) input; parse_synth_eq (parse_maybe_enum_key p e) (total_of_maybe_enum_key e) input; parse_synth_eq p (maybe_enum_key_of_repr e) input (* Destructors *) (* Universal destructor *) let r_reflexive_prop (t: Type) (r: (t -> t -> GTot Type0)) : GTot Type0 = forall (x: t) . {:pattern (r x x)} r x x inline_for_extraction let r_reflexive_t (t: Type) (r: (t -> t -> GTot Type0)) : Tot Type = (x: t) -> Lemma (r x x) let r_reflexive_t_elim (t: Type) (r: (t -> t -> GTot Type0)) (phi: r_reflexive_t t r) : Lemma (r_reflexive_prop t r) = Classical.forall_intro phi let r_transitive_prop (t: Type) (r: (t -> t -> GTot Type0)) : GTot Type0 = forall (x y z: t) . {:pattern (r x y); (r y z)} (r x y /\ r y z) ==> r x z inline_for_extraction let r_transitive_t (t: Type) (r: (t -> t -> GTot Type0)) : Tot Type = (x: t) -> (y: t) -> (z: t) -> Lemma ((r x y /\ r y z) ==> r x z) let r_transitive_t_elim (t: Type) (r: (t -> t -> GTot Type0)) (phi: r_transitive_t t r) : Lemma (r_transitive_prop t r) = Classical.forall_intro_3 phi inline_for_extraction let if_combinator (t: Type) (eq: (t -> t -> GTot Type0)) : Tot Type = (cond: bool) -> (sv_true: (cond_true cond -> Tot t)) -> (sv_false: (cond_false cond -> Tot t)) -> Tot (y: t { eq y (if cond then sv_true () else sv_false ()) } ) inline_for_extraction let default_if (t: Type) : Tot (if_combinator t (eq2 #t)) = fun (cond: bool) (s_true: (cond_true cond -> Tot t)) (s_false: (cond_false cond -> Tot t)) -> (if cond then s_true () else s_false ()) <: (y: t { y == (if cond then s_true () else s_false ()) } ) let feq (u v: Type) (eq: (v -> v -> GTot Type0)) (f1 f2: (u -> Tot v)) : GTot Type0 = (forall (x: u) . {:pattern (f1 x); (f2 x)} eq (f1 x) (f2 x)) (* #!$% patterns on forall, the following proofs should be trivial and now they aren't *) let feq_elim (u v: Type) (eq: (v -> v -> GTot Type0)) (f1 f2: (u -> Tot v)) (x: u) : Lemma (requires (feq u v eq f1 f2)) (ensures (f1 x `eq` f2 x)) = () let feq_intro (u v: Type) (eq: (v -> v -> GTot Type0)) (f1 f2: (u -> Tot v)) (phi: (x: u) -> Lemma (f1 x `eq` f2 x)) : Lemma (feq _ _ eq f1 f2) = Classical.forall_intro phi let feq_trans (u v: Type) (eq: (v -> v -> GTot Type0)) : Pure (r_transitive_t _ (feq _ _ eq)) (requires (r_transitive_prop _ eq)) (ensures (fun _ -> True)) = let phi (f1 f2 f3: (u -> Tot v)) : Lemma (requires (feq _ _ eq f1 f2 /\ feq _ _ eq f2 f3)) (ensures (feq _ _ eq f1 f3)) = feq_intro _ _ eq f1 f3 (fun x -> assert (f1 x `eq` f2 x /\ f2 x `eq` f3 x)) in let phi2 (f1 f2 f3: (u -> Tot v)) : Lemma ((feq _ _ eq f1 f2 /\ feq _ _ eq f2 f3) ==> feq _ _ eq f1 f3) = Classical.move_requires (phi f1 f2) f3 in phi2 inline_for_extraction let fif (u v: Type) (eq: (v -> v -> GTot Type0)) (ifc: if_combinator v eq) : Tot (if_combinator (u -> Tot v) (feq u v eq)) = fun (cond: bool) (s_true: (cond_true cond -> u -> Tot v)) (s_false: (cond_false cond -> u -> Tot v)) (x: u) -> ifc cond (fun h -> s_true () x) (fun h -> s_false () x) inline_for_extraction let enum_destr_t (t: Type) (#key #repr: eqtype) (e: enum key repr) : Tot Type = (eq: (t -> t -> GTot Type0)) -> (ift: if_combinator t eq) -> (eq_refl: r_reflexive_t _ eq) -> (eq_trans: r_transitive_t _ eq) -> (f: ((x: enum_key e) -> Tot t)) -> (x: enum_key e) -> Tot (y: t { eq y (f x) } ) inline_for_extraction let enum_tail' (#key #repr: eqtype) (e: enum key repr) : Pure (enum key repr) (requires True) (ensures (fun y -> Cons? e ==> (let (_ :: y') = e in y == y'))) = match e with _ :: y -> y | _ -> [] inline_for_extraction let enum_tail (#key #repr: eqtype) (e: enum key repr) : Tot (enum key repr) = enum_tail' e inline_for_extraction let enum_destr_cons (t: Type) (#key #repr: eqtype) (e: enum key repr) (g: enum_destr_t t (enum_tail' e)) : Pure (enum_destr_t t e) (requires (Cons? e)) (ensures (fun _ -> True)) = fun (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) -> [@inline_let] let _ = r_reflexive_t_elim _ _ eq_refl in [@inline_let] let _ = r_transitive_t_elim _ _ eq_trans in (fun (e' : list (key * repr) { e' == e } ) -> match e' with | (k, _) :: _ -> (fun (f: (enum_key e -> Tot t)) (x: enum_key e) -> (( [@inline_let] let f' : (enum_key (enum_tail' e) -> Tot t) = (fun (x' : enum_key (enum_tail' e)) -> [@inline_let] let (x_ : enum_key e) = (x' <: key) in f x_ ) in [@inline_let] let (y: t) = ift ((k <: key) = x) (fun h -> f k) (fun h -> [@inline_let] let x' : enum_key (enum_tail' e) = (x <: key) in (g eq ift eq_refl eq_trans f' x' <: t)) in y ) <: (y: t { eq y (f x) } ))) ) e inline_for_extraction let enum_destr_cons' (t: Type) (key repr: eqtype) (e: enum key repr) (u: unit { Cons? e } ) (g: enum_destr_t t (enum_tail e)) : Tot (enum_destr_t t e) = enum_destr_cons t e g inline_for_extraction let enum_destr_cons_nil (t: Type) (#key #repr: eqtype) (e: enum key repr) : Pure (enum_destr_t t e) (requires (Cons? e /\ Nil? (enum_tail' e))) (ensures (fun _ -> True)) = fun (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) -> [@inline_let] let _ = r_reflexive_t_elim _ _ eq_refl in (fun (e' : list (key * repr) { e' == e } ) -> match e' with | (k, _) :: _ -> (fun (f: (enum_key e -> Tot t)) (x: enum_key e) -> (( f k ) <: (y: t { eq y (f x) } ))) ) e inline_for_extraction let enum_destr_cons_nil' (t: Type) (key repr: eqtype) (e: enum key repr) (u1: unit { Cons? e } ) (u2: unit { Nil? (enum_tail e) } ) : Tot (enum_destr_t t e) = enum_destr_cons_nil t e (* Dependent destructor *) inline_for_extraction let dep_enum_destr (#key #repr: eqtype) (e: enum key repr) (v: (enum_key e -> Tot (Type u#a))) : Tot (Type) = (v_eq: ((k: enum_key e) -> v k -> v k -> GTot Type0)) -> (v_if: ((k: enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) -> (v_eq_refl: ((k: enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) -> (v_eq_trans: ((k: enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) -> (f: ((k: enum_key e) -> Tot (v k))) -> (k: enum_key e) -> Tot (y: v k { v_eq k y (f k) } ) module L = FStar.List.Tot inline_for_extraction let dep_enum_destr_cons (#key #repr: eqtype) (e: enum key repr) (u: squash (Cons? e)) (v: (enum_key e -> Tot Type)) (destr: dep_enum_destr (enum_tail e) (fun (k' : enum_key (enum_tail e)) -> v (k' <: key))) : Tot (dep_enum_destr e v) = match e with | ((k, _) :: _) -> fun (v_eq: ((k: enum_key e) -> v k -> v k -> GTot Type0)) (v_if: ((k: enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) (v_eq_refl: ((k: enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) (v_eq_trans: ((k: enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) (f: ((k: enum_key e) -> Tot (v k))) (k' : enum_key e) -> [@inline_let] let _ = r_reflexive_t_elim (v k') (v_eq k') (v_eq_refl k') in [@inline_let] let _ = r_transitive_t_elim (v k') (v_eq k') (v_eq_trans k') in [@inline_let] let y : v k' = v_if k' (k = k') (fun _ -> [@inline_let] let y : v k' = f k in y ) (fun _ -> [@inline_let] let v' (k: enum_key (enum_tail e)) : Tot Type = v (k <: key) in [@inline_let] let v'_eq (k: enum_key (enum_tail e)) : Tot (v' k -> v' k -> GTot Type0) = v_eq (k <: key) in [@inline_let] let v'_if (k: enum_key (enum_tail e)) : Tot (if_combinator (v' k) (v'_eq k)) = v_if (k <: key) in [@inline_let] let v'_eq_refl (k: enum_key (enum_tail e)) : Tot (r_reflexive_t _ (v'_eq k)) = v_eq_refl (k <: key) in [@inline_let] let v'_eq_trans (k: enum_key (enum_tail e)) : Tot (r_transitive_t _ (v'_eq k)) = v_eq_trans (k <: key) in [@inline_let] let f' (k: enum_key (enum_tail e)) : Tot (v' k) = f (k <: key) in [@inline_let] let k' : key = k' in [@inline_let] let _ = assert (k' <> k) in [@inline_let] let _ = assert (L.mem k' (L.map fst (enum_tail e))) in [@inline_let] let (y: v' k') = destr v'_eq v'_if v'_eq_refl v'_eq_trans f' k' in y ) in (y <: (y: v k' { v_eq k' y (f k') } )) inline_for_extraction let dep_enum_destr_cons_nil (#key #repr: eqtype) (e: enum key repr) (u: squash (Cons? e /\ Nil? (enum_tail e))) (v: (enum_key e -> Tot Type)) : Tot (dep_enum_destr e v) = match e with | ((k, _) :: _) -> fun (v_eq: ((k: enum_key e) -> v k -> v k -> GTot Type0)) (v_if: ((k: enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) (v_eq_refl: ((k: enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) (v_eq_trans: ((k: enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) (f: ((k: enum_key e) -> Tot (v k))) (k' : enum_key e) -> [@inline_let] let _ = r_reflexive_t_elim (v k') (v_eq k') (v_eq_refl k') in [@inline_let] let _ = r_transitive_t_elim (v k') (v_eq k') (v_eq_trans k') in [@inline_let] let y : v k' = f k in (y <: (y: v k' { v_eq k' y (f k') } )) (* Destructor from the representation *) let maybe_enum_key_of_repr_not_in (#key #repr: eqtype) (e: enum key repr) (l: list (key * repr)) (x: repr) : GTot Type0 = (~ (L.mem x (L.map snd l))) let list_rev_cons (#t: Type) (a: t) (q: list t) : Lemma (L.rev (a :: q) == L.rev q `L.append` [a]) = L.rev_rev' (a :: q); L.rev_rev' q let list_append_rev_cons (#t: Type) (l1: list t) (x: t) (l2: list t) : Lemma (L.append (L.rev l1) (x :: l2) == L.append (L.rev (x :: l1)) l2) = list_rev_cons x l1; L.append_assoc (L.rev l1) [x] l2 let rec assoc_append_flip_l_intro (#key #repr: eqtype) (l1 l2: list (key * repr)) (y: repr) (x: key) : Lemma (requires (L.noRepeats (L.map snd (L.append l1 l2)) /\ L.assoc y (L.map flip l2) == Some x)) (ensures (L.assoc y (L.map flip (l1 `L.append` l2)) == Some x)) = match l1 with | [] -> () | (_, r') :: q -> L.assoc_mem y (L.map flip l2); map_fst_flip l2; L.map_append snd l1 l2; L.noRepeats_append_elim (L.map snd l1) (L.map snd l2); assoc_append_flip_l_intro q l2 y x inline_for_extraction let maybe_enum_destr_t' (t: Type) (#key #repr: eqtype) (e: enum key repr) (l1 l2: list (key * repr)) (u1: squash (e == L.append (L.rev l1) l2)) : Tot Type = (eq: (t -> t -> GTot Type0)) -> (ift: if_combinator t eq) -> (eq_refl: r_reflexive_t _ eq) -> (eq_trans: r_transitive_t _ eq) -> (f: ((x: maybe_enum_key e) -> Tot t)) -> (x: repr { maybe_enum_key_of_repr_not_in e l1 x } ) -> Tot (y: t { eq y (f (maybe_enum_key_of_repr e x)) } ) inline_for_extraction let maybe_enum_destr_t (t: Type) (#key #repr: eqtype) (e: enum key repr) : Tot Type = (eq: (t -> t -> GTot Type0)) -> (ift: if_combinator t eq) -> (eq_refl: r_reflexive_t _ eq) -> (eq_trans: r_transitive_t _ eq) -> (f: ((x: maybe_enum_key e) -> Tot t)) -> (x: repr) -> Tot (y: t { eq y (f (maybe_enum_key_of_repr e x)) } ) inline_for_extraction let destr_maybe_total_enum_repr (#t: Type) (#key #repr: eqtype) (e: total_enum key repr) (destr: maybe_enum_destr_t t e) (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) (f: ((x: maybe_total_enum_key e) -> Tot t)) (x: repr) : Tot (y: t { eq y (f (maybe_total_enum_key_of_repr e x)) } ) = destr eq ift eq_refl eq_trans (fun y -> f (total_of_maybe_enum_key e y)) x inline_for_extraction let maybe_enum_destr_t_intro (t: Type) (#key #repr: eqtype) (e: enum key repr) (f: maybe_enum_destr_t' t e [] e ()) : Tot (maybe_enum_destr_t t e) = f let maybe_enum_key_of_repr_not_in_cons (#key #repr: eqtype) (e: enum key repr) (k: key) (r: repr) (l: list (key * repr)) (x: repr) : Lemma (requires (maybe_enum_key_of_repr_not_in e l x /\ x <> r)) (ensures (maybe_enum_key_of_repr_not_in e ((k, r) :: l) x)) = () [@Norm] inline_for_extraction let list_hd (#t: Type) (l: list t { Cons? l } ) = match l with | a :: _ -> a [@Norm] inline_for_extraction let list_tl (#t: Type) (l: list t { Cons? l } ) = match l with | _ :: q -> q inline_for_extraction let maybe_enum_destr_cons (t: Type) (#key #repr: eqtype) (e: enum key repr) (l1: list (key * repr)) (l2: list (key * repr)) (u1: squash (Cons? l2 /\ e == L.append (L.rev l1) l2)) (g: (maybe_enum_destr_t' t e (list_hd l2 :: l1) (list_tl l2) (list_append_rev_cons l1 (list_hd l2) (list_tl l2)))) : Tot (maybe_enum_destr_t' t e l1 l2 u1) = fun (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) (f: (maybe_enum_key e -> Tot t)) -> [@inline_let] let _ = r_reflexive_t_elim _ _ eq_refl in [@inline_let] let _ = r_transitive_t_elim _ _ eq_trans in match list_hd l2 with | (k, r) -> [@inline_let] let _ : squash (L.mem k (L.map fst e)) = L.append_mem (L.map fst (L.rev l1)) (L.map fst l2) k; L.map_append fst (L.rev l1) (l2); () in [@inline_let] let (_ : squash (maybe_enum_key_of_repr e r == Known k)) = L.append_mem (L.map snd (L.rev l1)) (L.map snd (l2)) r; L.map_append snd (L.rev l1) (l2); assoc_append_flip_l_intro (L.rev l1) (l2) r k; () in fun (x: repr { maybe_enum_key_of_repr_not_in e l1 x } ) -> (( ift (x = r) (fun h -> f (Known k)) (fun h -> g eq ift eq_refl eq_trans f x) ) <: (y: t { eq y (f (maybe_enum_key_of_repr e x)) } )) let rec list_rev_map (#t1 #t2: Type) (f: t1 -> Tot t2) (l: list t1) : Lemma (L.rev (L.map f l) == L.map f (L.rev l)) = match l with | [] -> () | a :: q -> list_rev_cons a q; list_rev_cons (f a) (L.map f q); list_rev_map f q; L.map_append f (L.rev q) [a] inline_for_extraction let maybe_enum_destr_nil (t: Type) (#key #repr: eqtype) (e: enum key repr) (l1: list (key * repr)) (l2: list (key * repr)) (u1: squash (Nil? l2 /\ e == L.append (L.rev l1) [])) : Tot (maybe_enum_destr_t' t e l1 l2 u1) = fun (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) (f: (maybe_enum_key e -> Tot t)) -> [@inline_let] let _ = r_reflexive_t_elim _ _ eq_refl in [@inline_let] let _ = r_transitive_t_elim _ _ eq_trans in fun (x: repr { maybe_enum_key_of_repr_not_in e l1 x } ) -> (( L.append_l_nil (L.rev l1); list_rev_map snd l1; L.rev_mem (L.map snd l1) x; f (Unknown x) ) <: (y: t { eq y (f (maybe_enum_key_of_repr e x)) } )) [@Norm] let rec mk_maybe_enum_destr' (t: Type) (#key #repr: eqtype) (e: enum key repr) (l1: list (key * repr)) (l2: list (key * repr)) (u: squash (e == L.rev l1 `L.append` l2)) : Tot (maybe_enum_destr_t' t e l1 l2 u) (decreases l2) = match l2 with | [] -> maybe_enum_destr_nil t e l1 l2 u | _ -> [@inline_let] let _ = list_append_rev_cons l1 (list_hd l2) (list_tl l2) in maybe_enum_destr_cons t e l1 l2 u (mk_maybe_enum_destr' t e (list_hd l2 :: l1) (list_tl l2) u) [@Norm] let mk_maybe_enum_destr (t: Type) (#key #repr: eqtype) (e: enum key repr) : Tot (maybe_enum_destr_t t e) = maybe_enum_destr_t_intro t e (mk_maybe_enum_destr' t e [] e ()) (* dependent representation-based destructor *) inline_for_extraction let dep_maybe_enum_destr_t (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) : Tot Type = (v_eq: ((k: maybe_enum_key e) -> v k -> v k -> GTot Type0)) -> (v_if: ((k: maybe_enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) -> (v_eq_refl: ((k: maybe_enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) -> (v_eq_trans: ((k: maybe_enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) -> (f: ((k: maybe_enum_key e) -> Tot (v k))) -> (r: repr) -> Tot (y: v (maybe_enum_key_of_repr e r) { v_eq (maybe_enum_key_of_repr e r) y (f (maybe_enum_key_of_repr e r)) } ) inline_for_extraction let dep_maybe_enum_destr_t' (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) (l1 l2: list (key * repr)) (u1: squash (e == L.append (L.rev l1) l2)) : Tot Type = (v_eq: ((k: maybe_enum_key e) -> v k -> v k -> GTot Type0)) -> (v_if: ((k: maybe_enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) -> (v_eq_refl: ((k: maybe_enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) -> (v_eq_trans: ((k: maybe_enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) -> (f: ((k: maybe_enum_key e) -> Tot (v k))) -> (r: repr { maybe_enum_key_of_repr_not_in e l1 r } ) -> Tot (y: v (maybe_enum_key_of_repr e r) { v_eq (maybe_enum_key_of_repr e r) y (f (maybe_enum_key_of_repr e r)) } ) inline_for_extraction let dep_maybe_enum_destr_t_intro (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) (d: dep_maybe_enum_destr_t' e v [] e ()) : Tot (dep_maybe_enum_destr_t e v) = d inline_for_extraction let dep_maybe_enum_destr_cons (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) (l1: list (key * repr)) (l2: list (key * repr)) (u1: squash (Cons? l2 /\ e == L.append (L.rev l1) l2)) (g: (dep_maybe_enum_destr_t' e v (list_hd l2 :: l1) (list_tl l2) (list_append_rev_cons l1 (list_hd l2) (list_tl l2)))) : Tot (dep_maybe_enum_destr_t' e v l1 l2 u1) = fun (v_eq: ((k: maybe_enum_key e) -> v k -> v k -> GTot Type0)) (v_if: ((k: maybe_enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) (v_eq_refl: ((k: maybe_enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) (v_eq_trans: ((k: maybe_enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) (f: ((k: maybe_enum_key e) -> Tot (v k))) -> match list_hd l2 with | (k, r) -> [@inline_let] let _ : squash (L.mem k (L.map fst e)) = L.append_mem (L.map fst (L.rev l1)) (L.map fst l2) k; L.map_append fst (L.rev l1) (l2); () in [@inline_let] let (_ : squash (maybe_enum_key_of_repr e r == Known k)) = L.append_mem (L.map snd (L.rev l1)) (L.map snd (l2)) r; L.map_append snd (L.rev l1) (l2); assoc_append_flip_l_intro (L.rev l1) (l2) r k; () in fun (x: repr { maybe_enum_key_of_repr_not_in e l1 x } ) -> //NS: y is linear in the continuation after erasure; inline it [@inline_let] let y : v (maybe_enum_key_of_repr e x) = v_if (maybe_enum_key_of_repr e x) // TODO: Since we cannot make this argument ghost, we need to make the user aware of the fact that this argument must not be extracted. (x = r) (fun h -> f (Known k)) (fun h -> g v_eq v_if v_eq_refl v_eq_trans f x) in [@inline_let] let _ : squash (v_eq (maybe_enum_key_of_repr e x) y (f (maybe_enum_key_of_repr e x))) = if x = r then () else v_eq_trans (maybe_enum_key_of_repr e x) y (g v_eq v_if v_eq_refl v_eq_trans f x) (f (maybe_enum_key_of_repr e x)) in (y <: (y: v (maybe_enum_key_of_repr e x) { v_eq (maybe_enum_key_of_repr e x) y (f (maybe_enum_key_of_repr e x)) } )) inline_for_extraction let dep_maybe_enum_destr_nil (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) (l1: list (key * repr)) (l2: list (key * repr)) (u1: squash (Nil? l2 /\ e == L.append (L.rev l1) [])) : Tot (dep_maybe_enum_destr_t' e v l1 l2 u1) = fun (v_eq: ((k: maybe_enum_key e) -> v k -> v k -> GTot Type0)) (v_if: ((k: maybe_enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) (v_eq_refl: ((k: maybe_enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) (v_eq_trans: ((k: maybe_enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) (f: ((k: maybe_enum_key e) -> Tot (v k))) (x: repr { maybe_enum_key_of_repr_not_in e l1 x } ) -> (( L.append_l_nil (L.rev l1); list_rev_map snd l1; L.rev_mem (L.map snd l1) x; assert (Unknown x == maybe_enum_key_of_repr e x); //NS: y is linear in the continuation after erasure [@inline_let] let y : v (maybe_enum_key_of_repr e x) = f (Unknown x) in [@inline_let] let _ = v_eq_refl (maybe_enum_key_of_repr e x) (f (maybe_enum_key_of_repr e x)) in y ) <: (y: v (maybe_enum_key_of_repr e x) { v_eq (maybe_enum_key_of_repr e x) y (f (maybe_enum_key_of_repr e x)) } )) [@Norm] let rec mk_dep_maybe_enum_destr' (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) (l1: list (key * repr)) (l2: list (key * repr)) (u1: squash (e == L.append (L.rev l1) l2)) : Tot (dep_maybe_enum_destr_t' e v l1 l2 u1) (decreases l2) = match l2 with | [] -> dep_maybe_enum_destr_nil e v l1 l2 u1 | _ -> dep_maybe_enum_destr_cons e v l1 l2 u1 (mk_dep_maybe_enum_destr' e v (list_hd l2 :: l1) (list_tl l2) (list_append_rev_cons l1 (list_hd l2) (list_tl l2))) [@Norm] let mk_dep_maybe_enum_destr (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) = dep_maybe_enum_destr_t_intro e v (mk_dep_maybe_enum_destr' e v [] e ()) (* Eliminators and destructors for verification purposes *) let rec list_forallp (#t: Type) (p: t -> GTot Type0) (l: list t) : GTot Type0 = match l with | [] -> True | a :: q -> p a /\ list_forallp p q let rec list_forallp_mem (#t: eqtype) (p: t -> GTot Type0) (l: list t) : Lemma (list_forallp p l <==> (forall x . L.mem x l ==> p x)) = match l with | [] -> () | _ :: q -> list_forallp_mem p q inline_for_extraction let destruct_maybe_enum_key (#key #value: eqtype) (e: enum key value) (f: maybe_enum_key e -> Tot Type) (f_known: ( (x: key) -> (u: squash (list_mem x (list_map fst e))) -> Tot (f (Known x)) )) (f_unknown: ( (x: value) -> (u: squash (list_mem x (list_map snd e) == false)) -> Tot (f (Unknown x)) )) (x: maybe_enum_key e) : Tot (f x) = match x with | Known x' -> f_known x' () | Unknown x' -> f_unknown x' () let forall_maybe_enum_key (#key #value: eqtype) (e: enum key value) (f: maybe_enum_key e -> GTot Type0) (f_known: squash (list_forallp (fun (x: key) -> list_mem x (list_map fst e) /\ f (Known x)) (list_map fst e))) (f_unknown: ( (x: value) -> Tot (squash (list_mem x (list_map snd e) == false ==> f (Unknown x))) )) : Tot (squash (forall (x: maybe_enum_key e) . f x)) = let g (x: maybe_enum_key e) : Lemma (f x) = let u : squash (f x) = destruct_maybe_enum_key e (fun y -> squash (f y)) (fun x' u -> list_forallp_mem (fun (x: key) -> list_mem x (list_map fst e) /\ f (Known x)) (list_map fst e)) (fun x' u -> f_unknown x') x in assert (f x) in Classical.forall_intro g (* Converting enum keys to their representation, using combinators *) let enum_repr_of_key'_t (#key #repr: eqtype) (e: enum key repr) : Tot Type = (x: enum_key e) -> Tot (r: enum_repr e { r == enum_repr_of_key e x } ) inline_for_extraction let enum_repr_of_key_cons (#key #repr: eqtype) (e: enum key repr) (f : enum_repr_of_key'_t (enum_tail' e)) : Pure (enum_repr_of_key'_t e) (requires (Cons? e)) (ensures (fun _ -> True)) = (fun (e' : list (key * repr) { e' == e } ) -> match e' with | (k, r) :: _ -> (fun (x: enum_key e) -> ( if k = x then (r <: repr) else (f (x <: key) <: repr) ) <: (r: enum_repr e { enum_repr_of_key e x == r } ))) e
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.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": "LowParse.Spec.Enum.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
key: Prims.eqtype -> repr: Prims.eqtype -> e: LowParse.Spec.Enum.enum key repr -> u1105: u1107: Prims.unit{Cons? e} -> f: LowParse.Spec.Enum.enum_repr_of_key'_t (LowParse.Spec.Enum.enum_tail' e) -> LowParse.Spec.Enum.enum_repr_of_key'_t e
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "LowParse.Spec.Enum.enum", "Prims.unit", "Prims.b2t", "Prims.uu___is_Cons", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Enum.enum_repr_of_key'_t", "LowParse.Spec.Enum.enum_tail'", "LowParse.Spec.Enum.enum_repr_of_key_cons" ]
[]
false
false
false
false
false
let enum_repr_of_key_cons' (key repr: eqtype) (e: enum key repr) (u: unit{Cons? e}) (f: enum_repr_of_key'_t (enum_tail' e)) : Tot (enum_repr_of_key'_t e) =
enum_repr_of_key_cons e f
false
LowParse.Spec.Enum.fst
LowParse.Spec.Enum.maybe_enum_destr_cons
val maybe_enum_destr_cons (t: Type) (#key #repr: eqtype) (e: enum key repr) (l1 l2: list (key * repr)) (u1: squash (Cons? l2 /\ e == L.append (L.rev l1) l2)) (g: (maybe_enum_destr_t' t e (list_hd l2 :: l1) (list_tl l2) (list_append_rev_cons l1 (list_hd l2) (list_tl l2)))) : Tot (maybe_enum_destr_t' t e l1 l2 u1)
val maybe_enum_destr_cons (t: Type) (#key #repr: eqtype) (e: enum key repr) (l1 l2: list (key * repr)) (u1: squash (Cons? l2 /\ e == L.append (L.rev l1) l2)) (g: (maybe_enum_destr_t' t e (list_hd l2 :: l1) (list_tl l2) (list_append_rev_cons l1 (list_hd l2) (list_tl l2)))) : Tot (maybe_enum_destr_t' t e l1 l2 u1)
let maybe_enum_destr_cons (t: Type) (#key #repr: eqtype) (e: enum key repr) (l1: list (key * repr)) (l2: list (key * repr)) (u1: squash (Cons? l2 /\ e == L.append (L.rev l1) l2)) (g: (maybe_enum_destr_t' t e (list_hd l2 :: l1) (list_tl l2) (list_append_rev_cons l1 (list_hd l2) (list_tl l2)))) : Tot (maybe_enum_destr_t' t e l1 l2 u1) = fun (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) (f: (maybe_enum_key e -> Tot t)) -> [@inline_let] let _ = r_reflexive_t_elim _ _ eq_refl in [@inline_let] let _ = r_transitive_t_elim _ _ eq_trans in match list_hd l2 with | (k, r) -> [@inline_let] let _ : squash (L.mem k (L.map fst e)) = L.append_mem (L.map fst (L.rev l1)) (L.map fst l2) k; L.map_append fst (L.rev l1) (l2); () in [@inline_let] let (_ : squash (maybe_enum_key_of_repr e r == Known k)) = L.append_mem (L.map snd (L.rev l1)) (L.map snd (l2)) r; L.map_append snd (L.rev l1) (l2); assoc_append_flip_l_intro (L.rev l1) (l2) r k; () in fun (x: repr { maybe_enum_key_of_repr_not_in e l1 x } ) -> (( ift (x = r) (fun h -> f (Known k)) (fun h -> g eq ift eq_refl eq_trans f x) ) <: (y: t { eq y (f (maybe_enum_key_of_repr e x)) } ))
{ "file_name": "src/lowparse/LowParse.Spec.Enum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 57, "end_line": 943, "start_col": 0, "start_line": 909 }
module LowParse.Spec.Enum include LowParse.Spec.Combinators module L = FStar.List.Tot [@Norm] let rec list_map (#a #b: Type) (f: (a -> Tot b)) (l: list a) : Tot (l' : list b { l' == L.map f l } ) = match l with | [] -> [] | a :: q -> f a :: list_map f q type enum (key: eqtype) (repr: eqtype) = (l: list (key * repr) { L.noRepeats (list_map fst l) /\ L.noRepeats (list_map snd l) }) [@Norm] let rec list_mem (#t: eqtype) (x: t) (l: list t) : Tot (y: bool { y == true <==> L.mem x l == true } ) = match l with | [] -> false | a :: q -> (x = a || list_mem x q) inline_for_extraction let enum_key (#key #repr: eqtype) (e: enum key repr) : Tot eqtype = (s: key { list_mem s (list_map fst e) } ) inline_for_extraction let make_enum_key (#key #repr: eqtype) (e: enum key repr) (k: key) : Pure (enum_key e) (requires (list_mem k (list_map fst e))) (ensures (fun k' -> k == (k' <: key))) = k inline_for_extraction let enum_repr (#key #repr: eqtype) (e: enum key repr) : Tot eqtype = (r: repr { list_mem r (list_map snd e) } ) let flip (#a #b: Type) (c: (a * b)) : Tot (b * a) = let (ca, cb) = c in (cb, ca) let rec map_flip_flip (#a #b: Type) (l: list (a * b)) : Lemma (list_map flip (list_map flip l) == l) = match l with | [] -> () | _ :: q -> map_flip_flip q let rec map_fst_flip (#a #b: Type) (l: list (a * b)) : Lemma (list_map fst (list_map flip l) == list_map snd l) = match l with | [] -> () | _ :: q -> map_fst_flip q let rec map_snd_flip (#a #b: Type) (l: list (a * b)) : Lemma (list_map snd (list_map flip l) == list_map fst l) = match l with | [] -> () | _ :: q -> map_snd_flip q let rec assoc_mem_snd (#a #b: eqtype) (l: list (a * b)) (x: a) (y: b) : Lemma (requires (L.assoc x l == Some y)) (ensures (list_mem y (list_map snd l) == true)) (decreases l) = let ((x', y') :: l') = l in if x' = x then () else assoc_mem_snd l' x y let rec assoc_flip_elim (#a #b: eqtype) (l: list (a * b)) (y: b) (x: a) : Lemma (requires ( L.noRepeats (list_map fst l) /\ L.noRepeats (list_map snd l) /\ L.assoc y (list_map flip l) == Some x )) (ensures ( L.assoc x l == Some y )) (decreases l) = let ((x', y') :: l') = l in if y' = y then () else begin if x' = x then begin assert (list_mem x' (list_map fst l') == false); assoc_mem_snd (list_map flip l') y x; map_snd_flip l'; assert False end else assoc_flip_elim l' y x end let rec assoc_flip_intro (#a #b: eqtype) (l: list (a * b)) (y: b) (x: a) : Lemma (requires ( L.noRepeats (list_map fst l) /\ L.noRepeats (list_map snd l) /\ L.assoc x l == Some y )) (ensures ( L.assoc y (list_map flip l) == Some x )) = map_fst_flip l; map_snd_flip l; map_flip_flip l; assoc_flip_elim (list_map flip l) x y let enum_key_of_repr (#key #repr: eqtype) (e: enum key repr) (r: enum_repr e) : Pure (enum_key e) (requires True) (ensures (fun y -> L.assoc y e == Some r)) = map_fst_flip e; let e' = list_map #(key * repr) #(repr * key) flip e in L.assoc_mem r e'; let k = Some?.v (L.assoc r e') in assoc_flip_elim e r k; L.assoc_mem k e; (k <: enum_key e) let parse_enum_key_cond (#key #repr: eqtype) (e: enum key repr) (r: repr) : GTot bool = list_mem r (list_map snd e) let parse_enum_key_synth (#key #repr: eqtype) (e: enum key repr) (r: repr { parse_enum_key_cond e r == true } ) : GTot (enum_key e) = enum_key_of_repr e r let parse_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) : Tot (parser (parse_filter_kind k) (enum_key e)) = (p `parse_filter` parse_enum_key_cond e ) `parse_synth` parse_enum_key_synth e let enum_repr_of_key (#key #repr: eqtype) (e: enum key repr) (k: enum_key e) : Pure (enum_repr e) (requires True) (ensures (fun r -> L.assoc k e == Some r)) = L.assoc_mem k e; let r = Some?.v (L.assoc k e) in assoc_flip_intro e r k; L.assoc_mem r (list_map flip e); map_fst_flip e; (r <: enum_repr e) let enum_repr_of_key_of_repr (#key #repr: eqtype) (e: enum key repr) (r: enum_repr e) : Lemma (enum_repr_of_key e (enum_key_of_repr e r) == r) = () let enum_key_of_repr_of_key (#key #repr: eqtype) (e: enum key repr) (k: enum_key e) : Lemma (enum_key_of_repr e (enum_repr_of_key e k) == k) = assoc_flip_intro e (enum_repr_of_key e k) k let serialize_enum_key_synth_recip (#key #repr: eqtype) (e: enum key repr) (k: enum_key e) : GTot (r: repr { parse_enum_key_cond e r == true } ) = enum_repr_of_key e k let serialize_enum_key_synth_inverse (#key #repr: eqtype) (e: enum key repr) : Lemma (synth_inverse (parse_enum_key_synth e) (serialize_enum_key_synth_recip e)) = Classical.forall_intro (enum_key_of_repr_of_key e) let serialize_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (s: serializer p) (e: enum key repr) : Tot (serializer (parse_enum_key p e)) = serialize_enum_key_synth_inverse e; serialize_synth (parse_filter p (parse_enum_key_cond e)) (parse_enum_key_synth e) (serialize_filter s (parse_enum_key_cond e)) (serialize_enum_key_synth_recip e) () let serialize_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (s: serializer p) (e: enum key repr) (x: enum_key e) : Lemma (serialize (serialize_enum_key p s e) x == serialize s (enum_repr_of_key e x)) = serialize_enum_key_synth_inverse e; serialize_synth_eq (parse_filter p (parse_enum_key_cond e)) (parse_enum_key_synth e) (serialize_filter s (parse_enum_key_cond e)) (serialize_enum_key_synth_recip e) () x inline_for_extraction let unknown_enum_repr (#key #repr: eqtype) (e: enum key repr) : Tot Type = (r: repr { list_mem r (list_map snd e) == false } ) type maybe_enum_key (#key #repr: eqtype) (e: enum key repr) = | Known of (enum_key e) | Unknown of (unknown_enum_repr e) let maybe_enum_key_of_repr (#key #repr: eqtype) (e: enum key repr) (r: repr) : Tot (maybe_enum_key e) = if list_mem r (list_map snd e) then Known (enum_key_of_repr e r) else Unknown r let parse_maybe_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) : Tot (parser k (maybe_enum_key e)) = p `parse_synth` (maybe_enum_key_of_repr e) let parse_maybe_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) (input: bytes) : Lemma (parse (parse_maybe_enum_key p e) input == (match parse p input with | Some (x, consumed) -> Some (maybe_enum_key_of_repr e x, consumed) | _ -> None )) = parse_synth_eq p (maybe_enum_key_of_repr e) input let parse_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) (input: bytes) : Lemma (parse (parse_enum_key p e) input == (match parse p input with | Some (x, consumed) -> begin match maybe_enum_key_of_repr e x with | Known k -> Some (k, consumed) | _ -> None end | _ -> None )) = parse_filter_eq p (parse_enum_key_cond e) input; parse_synth_eq (p `parse_filter` parse_enum_key_cond e) (parse_enum_key_synth e) input let repr_of_maybe_enum_key (#key #repr: eqtype) (e: enum key repr) (x: maybe_enum_key e) : Tot (r: repr { maybe_enum_key_of_repr e r == x } ) = match x with | Known k' -> enum_key_of_repr_of_key e k' ; enum_repr_of_key e k' | Unknown r -> r let serialize_maybe_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (s: serializer p) (e: enum key repr) : Tot (serializer (parse_maybe_enum_key p e)) = serialize_synth p (maybe_enum_key_of_repr e) s (repr_of_maybe_enum_key e) () let serialize_maybe_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (s: serializer p) (e: enum key repr) (x: maybe_enum_key e) : Lemma (serialize (serialize_maybe_enum_key p s e) x == serialize s (repr_of_maybe_enum_key e x)) = serialize_synth_eq p (maybe_enum_key_of_repr e) s (repr_of_maybe_enum_key e) () x let is_total_enum (#key: eqtype) (#repr: eqtype) (l: list (key * repr)) : GTot Type0 = forall (k: key) . {:pattern (list_mem k (list_map fst l))} list_mem k (list_map fst l) let total_enum (key: eqtype) (repr: eqtype) : Tot eqtype = (l: enum key repr { is_total_enum l } ) let synth_total_enum_key (#key: eqtype) (#repr: eqtype) (l: total_enum key repr) (k: enum_key l) : Tot key = let k' : key = k in k' let parse_total_enum_key (#k: parser_kind) (#key: eqtype) (#repr: eqtype) (p: parser k repr) (l: total_enum key repr) : Tot (parser (parse_filter_kind k) key) = parse_enum_key p l `parse_synth` (synth_total_enum_key l) let synth_total_enum_key_recip (#key: eqtype) (#repr: eqtype) (l: total_enum key repr) (k: key) : Tot (k' : enum_key l { synth_total_enum_key l k' == k } ) = k let serialize_total_enum_key (#k: parser_kind) (#key: eqtype) (#repr: eqtype) (p: parser k repr) (s: serializer p) (l: total_enum key repr) : Tot (serializer (parse_total_enum_key p l)) = serialize_synth (parse_enum_key p l) (synth_total_enum_key l) (serialize_enum_key p s l) (synth_total_enum_key_recip l) () type maybe_total_enum_key (#key #repr: eqtype) (e: total_enum key repr) = | TotalKnown of key | TotalUnknown of (unknown_enum_repr e) let maybe_total_enum_key_of_repr (#key #repr: eqtype) (e: total_enum key repr) (r: repr) : Tot (maybe_total_enum_key e) = if list_mem r (list_map snd e) then TotalKnown (enum_key_of_repr e r) else TotalUnknown r let parse_maybe_total_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: total_enum key repr) : Tot (parser k (maybe_total_enum_key e)) = p `parse_synth` (maybe_total_enum_key_of_repr e) let repr_of_maybe_total_enum_key (#key #repr: eqtype) (e: total_enum key repr) (k: maybe_total_enum_key e) : Tot (r: repr { maybe_total_enum_key_of_repr e r == k } ) = match k with | TotalKnown k' -> enum_key_of_repr_of_key e k' ; enum_repr_of_key e k' | TotalUnknown r -> r let serialize_maybe_total_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (s: serializer p) (e: total_enum key repr) : Tot (serializer (parse_maybe_total_enum_key p e)) = serialize_synth p (maybe_total_enum_key_of_repr e) s (repr_of_maybe_total_enum_key e) () inline_for_extraction let maybe_enum_key_of_total (#key #repr: eqtype) (e: total_enum key repr) (k: maybe_total_enum_key e) : Tot (maybe_enum_key e) = match k with | TotalKnown ek -> Known (ek <: key) | TotalUnknown r -> Unknown r inline_for_extraction let total_of_maybe_enum_key (#key #repr: eqtype) (e: total_enum key repr) (k: maybe_enum_key e) : Tot (maybe_total_enum_key e) = match k with | Known ek -> TotalKnown (ek <: key) | Unknown r -> TotalUnknown r let maybe_total_enum_key_of_repr_eq (#key #repr: eqtype) (e: total_enum key repr) (r: repr) : Lemma (maybe_total_enum_key_of_repr e r == total_of_maybe_enum_key e (maybe_enum_key_of_repr e r)) = () let parse_maybe_total_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: total_enum key repr) (input: bytes) : Lemma (parse (parse_maybe_total_enum_key p e) input == (parse (parse_maybe_enum_key p e `parse_synth` total_of_maybe_enum_key e) input)) = parse_synth_eq p (maybe_total_enum_key_of_repr e) input; parse_synth_eq (parse_maybe_enum_key p e) (total_of_maybe_enum_key e) input; parse_synth_eq p (maybe_enum_key_of_repr e) input (* Destructors *) (* Universal destructor *) let r_reflexive_prop (t: Type) (r: (t -> t -> GTot Type0)) : GTot Type0 = forall (x: t) . {:pattern (r x x)} r x x inline_for_extraction let r_reflexive_t (t: Type) (r: (t -> t -> GTot Type0)) : Tot Type = (x: t) -> Lemma (r x x) let r_reflexive_t_elim (t: Type) (r: (t -> t -> GTot Type0)) (phi: r_reflexive_t t r) : Lemma (r_reflexive_prop t r) = Classical.forall_intro phi let r_transitive_prop (t: Type) (r: (t -> t -> GTot Type0)) : GTot Type0 = forall (x y z: t) . {:pattern (r x y); (r y z)} (r x y /\ r y z) ==> r x z inline_for_extraction let r_transitive_t (t: Type) (r: (t -> t -> GTot Type0)) : Tot Type = (x: t) -> (y: t) -> (z: t) -> Lemma ((r x y /\ r y z) ==> r x z) let r_transitive_t_elim (t: Type) (r: (t -> t -> GTot Type0)) (phi: r_transitive_t t r) : Lemma (r_transitive_prop t r) = Classical.forall_intro_3 phi inline_for_extraction let if_combinator (t: Type) (eq: (t -> t -> GTot Type0)) : Tot Type = (cond: bool) -> (sv_true: (cond_true cond -> Tot t)) -> (sv_false: (cond_false cond -> Tot t)) -> Tot (y: t { eq y (if cond then sv_true () else sv_false ()) } ) inline_for_extraction let default_if (t: Type) : Tot (if_combinator t (eq2 #t)) = fun (cond: bool) (s_true: (cond_true cond -> Tot t)) (s_false: (cond_false cond -> Tot t)) -> (if cond then s_true () else s_false ()) <: (y: t { y == (if cond then s_true () else s_false ()) } ) let feq (u v: Type) (eq: (v -> v -> GTot Type0)) (f1 f2: (u -> Tot v)) : GTot Type0 = (forall (x: u) . {:pattern (f1 x); (f2 x)} eq (f1 x) (f2 x)) (* #!$% patterns on forall, the following proofs should be trivial and now they aren't *) let feq_elim (u v: Type) (eq: (v -> v -> GTot Type0)) (f1 f2: (u -> Tot v)) (x: u) : Lemma (requires (feq u v eq f1 f2)) (ensures (f1 x `eq` f2 x)) = () let feq_intro (u v: Type) (eq: (v -> v -> GTot Type0)) (f1 f2: (u -> Tot v)) (phi: (x: u) -> Lemma (f1 x `eq` f2 x)) : Lemma (feq _ _ eq f1 f2) = Classical.forall_intro phi let feq_trans (u v: Type) (eq: (v -> v -> GTot Type0)) : Pure (r_transitive_t _ (feq _ _ eq)) (requires (r_transitive_prop _ eq)) (ensures (fun _ -> True)) = let phi (f1 f2 f3: (u -> Tot v)) : Lemma (requires (feq _ _ eq f1 f2 /\ feq _ _ eq f2 f3)) (ensures (feq _ _ eq f1 f3)) = feq_intro _ _ eq f1 f3 (fun x -> assert (f1 x `eq` f2 x /\ f2 x `eq` f3 x)) in let phi2 (f1 f2 f3: (u -> Tot v)) : Lemma ((feq _ _ eq f1 f2 /\ feq _ _ eq f2 f3) ==> feq _ _ eq f1 f3) = Classical.move_requires (phi f1 f2) f3 in phi2 inline_for_extraction let fif (u v: Type) (eq: (v -> v -> GTot Type0)) (ifc: if_combinator v eq) : Tot (if_combinator (u -> Tot v) (feq u v eq)) = fun (cond: bool) (s_true: (cond_true cond -> u -> Tot v)) (s_false: (cond_false cond -> u -> Tot v)) (x: u) -> ifc cond (fun h -> s_true () x) (fun h -> s_false () x) inline_for_extraction let enum_destr_t (t: Type) (#key #repr: eqtype) (e: enum key repr) : Tot Type = (eq: (t -> t -> GTot Type0)) -> (ift: if_combinator t eq) -> (eq_refl: r_reflexive_t _ eq) -> (eq_trans: r_transitive_t _ eq) -> (f: ((x: enum_key e) -> Tot t)) -> (x: enum_key e) -> Tot (y: t { eq y (f x) } ) inline_for_extraction let enum_tail' (#key #repr: eqtype) (e: enum key repr) : Pure (enum key repr) (requires True) (ensures (fun y -> Cons? e ==> (let (_ :: y') = e in y == y'))) = match e with _ :: y -> y | _ -> [] inline_for_extraction let enum_tail (#key #repr: eqtype) (e: enum key repr) : Tot (enum key repr) = enum_tail' e inline_for_extraction let enum_destr_cons (t: Type) (#key #repr: eqtype) (e: enum key repr) (g: enum_destr_t t (enum_tail' e)) : Pure (enum_destr_t t e) (requires (Cons? e)) (ensures (fun _ -> True)) = fun (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) -> [@inline_let] let _ = r_reflexive_t_elim _ _ eq_refl in [@inline_let] let _ = r_transitive_t_elim _ _ eq_trans in (fun (e' : list (key * repr) { e' == e } ) -> match e' with | (k, _) :: _ -> (fun (f: (enum_key e -> Tot t)) (x: enum_key e) -> (( [@inline_let] let f' : (enum_key (enum_tail' e) -> Tot t) = (fun (x' : enum_key (enum_tail' e)) -> [@inline_let] let (x_ : enum_key e) = (x' <: key) in f x_ ) in [@inline_let] let (y: t) = ift ((k <: key) = x) (fun h -> f k) (fun h -> [@inline_let] let x' : enum_key (enum_tail' e) = (x <: key) in (g eq ift eq_refl eq_trans f' x' <: t)) in y ) <: (y: t { eq y (f x) } ))) ) e inline_for_extraction let enum_destr_cons' (t: Type) (key repr: eqtype) (e: enum key repr) (u: unit { Cons? e } ) (g: enum_destr_t t (enum_tail e)) : Tot (enum_destr_t t e) = enum_destr_cons t e g inline_for_extraction let enum_destr_cons_nil (t: Type) (#key #repr: eqtype) (e: enum key repr) : Pure (enum_destr_t t e) (requires (Cons? e /\ Nil? (enum_tail' e))) (ensures (fun _ -> True)) = fun (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) -> [@inline_let] let _ = r_reflexive_t_elim _ _ eq_refl in (fun (e' : list (key * repr) { e' == e } ) -> match e' with | (k, _) :: _ -> (fun (f: (enum_key e -> Tot t)) (x: enum_key e) -> (( f k ) <: (y: t { eq y (f x) } ))) ) e inline_for_extraction let enum_destr_cons_nil' (t: Type) (key repr: eqtype) (e: enum key repr) (u1: unit { Cons? e } ) (u2: unit { Nil? (enum_tail e) } ) : Tot (enum_destr_t t e) = enum_destr_cons_nil t e (* Dependent destructor *) inline_for_extraction let dep_enum_destr (#key #repr: eqtype) (e: enum key repr) (v: (enum_key e -> Tot (Type u#a))) : Tot (Type) = (v_eq: ((k: enum_key e) -> v k -> v k -> GTot Type0)) -> (v_if: ((k: enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) -> (v_eq_refl: ((k: enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) -> (v_eq_trans: ((k: enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) -> (f: ((k: enum_key e) -> Tot (v k))) -> (k: enum_key e) -> Tot (y: v k { v_eq k y (f k) } ) module L = FStar.List.Tot inline_for_extraction let dep_enum_destr_cons (#key #repr: eqtype) (e: enum key repr) (u: squash (Cons? e)) (v: (enum_key e -> Tot Type)) (destr: dep_enum_destr (enum_tail e) (fun (k' : enum_key (enum_tail e)) -> v (k' <: key))) : Tot (dep_enum_destr e v) = match e with | ((k, _) :: _) -> fun (v_eq: ((k: enum_key e) -> v k -> v k -> GTot Type0)) (v_if: ((k: enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) (v_eq_refl: ((k: enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) (v_eq_trans: ((k: enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) (f: ((k: enum_key e) -> Tot (v k))) (k' : enum_key e) -> [@inline_let] let _ = r_reflexive_t_elim (v k') (v_eq k') (v_eq_refl k') in [@inline_let] let _ = r_transitive_t_elim (v k') (v_eq k') (v_eq_trans k') in [@inline_let] let y : v k' = v_if k' (k = k') (fun _ -> [@inline_let] let y : v k' = f k in y ) (fun _ -> [@inline_let] let v' (k: enum_key (enum_tail e)) : Tot Type = v (k <: key) in [@inline_let] let v'_eq (k: enum_key (enum_tail e)) : Tot (v' k -> v' k -> GTot Type0) = v_eq (k <: key) in [@inline_let] let v'_if (k: enum_key (enum_tail e)) : Tot (if_combinator (v' k) (v'_eq k)) = v_if (k <: key) in [@inline_let] let v'_eq_refl (k: enum_key (enum_tail e)) : Tot (r_reflexive_t _ (v'_eq k)) = v_eq_refl (k <: key) in [@inline_let] let v'_eq_trans (k: enum_key (enum_tail e)) : Tot (r_transitive_t _ (v'_eq k)) = v_eq_trans (k <: key) in [@inline_let] let f' (k: enum_key (enum_tail e)) : Tot (v' k) = f (k <: key) in [@inline_let] let k' : key = k' in [@inline_let] let _ = assert (k' <> k) in [@inline_let] let _ = assert (L.mem k' (L.map fst (enum_tail e))) in [@inline_let] let (y: v' k') = destr v'_eq v'_if v'_eq_refl v'_eq_trans f' k' in y ) in (y <: (y: v k' { v_eq k' y (f k') } )) inline_for_extraction let dep_enum_destr_cons_nil (#key #repr: eqtype) (e: enum key repr) (u: squash (Cons? e /\ Nil? (enum_tail e))) (v: (enum_key e -> Tot Type)) : Tot (dep_enum_destr e v) = match e with | ((k, _) :: _) -> fun (v_eq: ((k: enum_key e) -> v k -> v k -> GTot Type0)) (v_if: ((k: enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) (v_eq_refl: ((k: enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) (v_eq_trans: ((k: enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) (f: ((k: enum_key e) -> Tot (v k))) (k' : enum_key e) -> [@inline_let] let _ = r_reflexive_t_elim (v k') (v_eq k') (v_eq_refl k') in [@inline_let] let _ = r_transitive_t_elim (v k') (v_eq k') (v_eq_trans k') in [@inline_let] let y : v k' = f k in (y <: (y: v k' { v_eq k' y (f k') } )) (* Destructor from the representation *) let maybe_enum_key_of_repr_not_in (#key #repr: eqtype) (e: enum key repr) (l: list (key * repr)) (x: repr) : GTot Type0 = (~ (L.mem x (L.map snd l))) let list_rev_cons (#t: Type) (a: t) (q: list t) : Lemma (L.rev (a :: q) == L.rev q `L.append` [a]) = L.rev_rev' (a :: q); L.rev_rev' q let list_append_rev_cons (#t: Type) (l1: list t) (x: t) (l2: list t) : Lemma (L.append (L.rev l1) (x :: l2) == L.append (L.rev (x :: l1)) l2) = list_rev_cons x l1; L.append_assoc (L.rev l1) [x] l2 let rec assoc_append_flip_l_intro (#key #repr: eqtype) (l1 l2: list (key * repr)) (y: repr) (x: key) : Lemma (requires (L.noRepeats (L.map snd (L.append l1 l2)) /\ L.assoc y (L.map flip l2) == Some x)) (ensures (L.assoc y (L.map flip (l1 `L.append` l2)) == Some x)) = match l1 with | [] -> () | (_, r') :: q -> L.assoc_mem y (L.map flip l2); map_fst_flip l2; L.map_append snd l1 l2; L.noRepeats_append_elim (L.map snd l1) (L.map snd l2); assoc_append_flip_l_intro q l2 y x inline_for_extraction let maybe_enum_destr_t' (t: Type) (#key #repr: eqtype) (e: enum key repr) (l1 l2: list (key * repr)) (u1: squash (e == L.append (L.rev l1) l2)) : Tot Type = (eq: (t -> t -> GTot Type0)) -> (ift: if_combinator t eq) -> (eq_refl: r_reflexive_t _ eq) -> (eq_trans: r_transitive_t _ eq) -> (f: ((x: maybe_enum_key e) -> Tot t)) -> (x: repr { maybe_enum_key_of_repr_not_in e l1 x } ) -> Tot (y: t { eq y (f (maybe_enum_key_of_repr e x)) } ) inline_for_extraction let maybe_enum_destr_t (t: Type) (#key #repr: eqtype) (e: enum key repr) : Tot Type = (eq: (t -> t -> GTot Type0)) -> (ift: if_combinator t eq) -> (eq_refl: r_reflexive_t _ eq) -> (eq_trans: r_transitive_t _ eq) -> (f: ((x: maybe_enum_key e) -> Tot t)) -> (x: repr) -> Tot (y: t { eq y (f (maybe_enum_key_of_repr e x)) } ) inline_for_extraction let destr_maybe_total_enum_repr (#t: Type) (#key #repr: eqtype) (e: total_enum key repr) (destr: maybe_enum_destr_t t e) (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) (f: ((x: maybe_total_enum_key e) -> Tot t)) (x: repr) : Tot (y: t { eq y (f (maybe_total_enum_key_of_repr e x)) } ) = destr eq ift eq_refl eq_trans (fun y -> f (total_of_maybe_enum_key e y)) x inline_for_extraction let maybe_enum_destr_t_intro (t: Type) (#key #repr: eqtype) (e: enum key repr) (f: maybe_enum_destr_t' t e [] e ()) : Tot (maybe_enum_destr_t t e) = f let maybe_enum_key_of_repr_not_in_cons (#key #repr: eqtype) (e: enum key repr) (k: key) (r: repr) (l: list (key * repr)) (x: repr) : Lemma (requires (maybe_enum_key_of_repr_not_in e l x /\ x <> r)) (ensures (maybe_enum_key_of_repr_not_in e ((k, r) :: l) x)) = () [@Norm] inline_for_extraction let list_hd (#t: Type) (l: list t { Cons? l } ) = match l with | a :: _ -> a [@Norm] inline_for_extraction let list_tl (#t: Type) (l: list t { Cons? l } ) = match l with | _ :: q -> q
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.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": "LowParse.Spec.Enum.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Type -> e: LowParse.Spec.Enum.enum key repr -> l1: Prims.list (key * repr) -> l2: Prims.list (key * repr) -> u1: Prims.squash (Cons? l2 /\ e == FStar.List.Tot.Base.rev l1 @ l2) -> g: LowParse.Spec.Enum.maybe_enum_destr_t' t e (LowParse.Spec.Enum.list_hd l2 :: l1) (LowParse.Spec.Enum.list_tl l2) (LowParse.Spec.Enum.list_append_rev_cons l1 (LowParse.Spec.Enum.list_hd l2) (LowParse.Spec.Enum.list_tl l2)) -> LowParse.Spec.Enum.maybe_enum_destr_t' t e l1 l2 u1
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "LowParse.Spec.Enum.enum", "Prims.list", "FStar.Pervasives.Native.tuple2", "Prims.squash", "Prims.l_and", "Prims.b2t", "Prims.uu___is_Cons", "Prims.eq2", "FStar.List.Tot.Base.append", "FStar.List.Tot.Base.rev", "LowParse.Spec.Enum.maybe_enum_destr_t'", "Prims.Cons", "LowParse.Spec.Enum.list_hd", "LowParse.Spec.Enum.list_tl", "LowParse.Spec.Enum.list_append_rev_cons", "LowParse.Spec.Enum.if_combinator", "LowParse.Spec.Enum.r_reflexive_t", "LowParse.Spec.Enum.r_transitive_t", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Enum.maybe_enum_key_of_repr_not_in", "Prims.op_Equality", "LowParse.Spec.Combinators.cond_true", "LowParse.Spec.Enum.Known", "LowParse.Spec.Combinators.cond_false", "LowParse.Spec.Enum.maybe_enum_key_of_repr", "Prims.unit", "LowParse.Spec.Enum.assoc_append_flip_l_intro", "FStar.List.Tot.Properties.map_append", "FStar.Pervasives.Native.snd", "FStar.List.Tot.Properties.append_mem", "FStar.List.Tot.Base.map", "FStar.List.Tot.Base.mem", "FStar.Pervasives.Native.fst", "LowParse.Spec.Enum.r_transitive_t_elim", "LowParse.Spec.Enum.r_reflexive_t_elim" ]
[]
false
false
false
false
false
let maybe_enum_destr_cons (t: Type) (#key #repr: eqtype) (e: enum key repr) (l1 l2: list (key * repr)) (u1: squash (Cons? l2 /\ e == L.append (L.rev l1) l2)) (g: (maybe_enum_destr_t' t e (list_hd l2 :: l1) (list_tl l2) (list_append_rev_cons l1 (list_hd l2) (list_tl l2)))) : Tot (maybe_enum_destr_t' t e l1 l2 u1) =
fun (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) (f: (maybe_enum_key e -> Tot t)) -> [@@ inline_let ]let _ = r_reflexive_t_elim _ _ eq_refl in [@@ inline_let ]let _ = r_transitive_t_elim _ _ eq_trans in match list_hd l2 with | k, r -> [@@ inline_let ]let _:squash (L.mem k (L.map fst e)) = L.append_mem (L.map fst (L.rev l1)) (L.map fst l2) k; L.map_append fst (L.rev l1) (l2); () in [@@ inline_let ]let _:squash (maybe_enum_key_of_repr e r == Known k) = L.append_mem (L.map snd (L.rev l1)) (L.map snd (l2)) r; L.map_append snd (L.rev l1) (l2); assoc_append_flip_l_intro (L.rev l1) (l2) r k; () in fun (x: repr{maybe_enum_key_of_repr_not_in e l1 x}) -> ((ift (x = r) (fun h -> f (Known k)) (fun h -> g eq ift eq_refl eq_trans f x)) <: (y: t{eq y (f (maybe_enum_key_of_repr e x))}))
false
LowParse.Spec.Enum.fst
LowParse.Spec.Enum.destruct_maybe_enum_key
val destruct_maybe_enum_key (#key #value: eqtype) (e: enum key value) (f: (maybe_enum_key e -> Tot Type)) (f_known: (x: key -> u: squash (list_mem x (list_map fst e)) -> Tot (f (Known x)))) (f_unknown: (x: value -> u: squash (list_mem x (list_map snd e) == false) -> Tot (f (Unknown x)))) (x: maybe_enum_key e) : Tot (f x)
val destruct_maybe_enum_key (#key #value: eqtype) (e: enum key value) (f: (maybe_enum_key e -> Tot Type)) (f_known: (x: key -> u: squash (list_mem x (list_map fst e)) -> Tot (f (Known x)))) (f_unknown: (x: value -> u: squash (list_mem x (list_map snd e) == false) -> Tot (f (Unknown x)))) (x: maybe_enum_key e) : Tot (f x)
let destruct_maybe_enum_key (#key #value: eqtype) (e: enum key value) (f: maybe_enum_key e -> Tot Type) (f_known: ( (x: key) -> (u: squash (list_mem x (list_map fst e))) -> Tot (f (Known x)) )) (f_unknown: ( (x: value) -> (u: squash (list_mem x (list_map snd e) == false)) -> Tot (f (Unknown x)) )) (x: maybe_enum_key e) : Tot (f x) = match x with | Known x' -> f_known x' () | Unknown x' -> f_unknown x' ()
{ "file_name": "src/lowparse/LowParse.Spec.Enum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 33, "end_line": 1179, "start_col": 0, "start_line": 1161 }
module LowParse.Spec.Enum include LowParse.Spec.Combinators module L = FStar.List.Tot [@Norm] let rec list_map (#a #b: Type) (f: (a -> Tot b)) (l: list a) : Tot (l' : list b { l' == L.map f l } ) = match l with | [] -> [] | a :: q -> f a :: list_map f q type enum (key: eqtype) (repr: eqtype) = (l: list (key * repr) { L.noRepeats (list_map fst l) /\ L.noRepeats (list_map snd l) }) [@Norm] let rec list_mem (#t: eqtype) (x: t) (l: list t) : Tot (y: bool { y == true <==> L.mem x l == true } ) = match l with | [] -> false | a :: q -> (x = a || list_mem x q) inline_for_extraction let enum_key (#key #repr: eqtype) (e: enum key repr) : Tot eqtype = (s: key { list_mem s (list_map fst e) } ) inline_for_extraction let make_enum_key (#key #repr: eqtype) (e: enum key repr) (k: key) : Pure (enum_key e) (requires (list_mem k (list_map fst e))) (ensures (fun k' -> k == (k' <: key))) = k inline_for_extraction let enum_repr (#key #repr: eqtype) (e: enum key repr) : Tot eqtype = (r: repr { list_mem r (list_map snd e) } ) let flip (#a #b: Type) (c: (a * b)) : Tot (b * a) = let (ca, cb) = c in (cb, ca) let rec map_flip_flip (#a #b: Type) (l: list (a * b)) : Lemma (list_map flip (list_map flip l) == l) = match l with | [] -> () | _ :: q -> map_flip_flip q let rec map_fst_flip (#a #b: Type) (l: list (a * b)) : Lemma (list_map fst (list_map flip l) == list_map snd l) = match l with | [] -> () | _ :: q -> map_fst_flip q let rec map_snd_flip (#a #b: Type) (l: list (a * b)) : Lemma (list_map snd (list_map flip l) == list_map fst l) = match l with | [] -> () | _ :: q -> map_snd_flip q let rec assoc_mem_snd (#a #b: eqtype) (l: list (a * b)) (x: a) (y: b) : Lemma (requires (L.assoc x l == Some y)) (ensures (list_mem y (list_map snd l) == true)) (decreases l) = let ((x', y') :: l') = l in if x' = x then () else assoc_mem_snd l' x y let rec assoc_flip_elim (#a #b: eqtype) (l: list (a * b)) (y: b) (x: a) : Lemma (requires ( L.noRepeats (list_map fst l) /\ L.noRepeats (list_map snd l) /\ L.assoc y (list_map flip l) == Some x )) (ensures ( L.assoc x l == Some y )) (decreases l) = let ((x', y') :: l') = l in if y' = y then () else begin if x' = x then begin assert (list_mem x' (list_map fst l') == false); assoc_mem_snd (list_map flip l') y x; map_snd_flip l'; assert False end else assoc_flip_elim l' y x end let rec assoc_flip_intro (#a #b: eqtype) (l: list (a * b)) (y: b) (x: a) : Lemma (requires ( L.noRepeats (list_map fst l) /\ L.noRepeats (list_map snd l) /\ L.assoc x l == Some y )) (ensures ( L.assoc y (list_map flip l) == Some x )) = map_fst_flip l; map_snd_flip l; map_flip_flip l; assoc_flip_elim (list_map flip l) x y let enum_key_of_repr (#key #repr: eqtype) (e: enum key repr) (r: enum_repr e) : Pure (enum_key e) (requires True) (ensures (fun y -> L.assoc y e == Some r)) = map_fst_flip e; let e' = list_map #(key * repr) #(repr * key) flip e in L.assoc_mem r e'; let k = Some?.v (L.assoc r e') in assoc_flip_elim e r k; L.assoc_mem k e; (k <: enum_key e) let parse_enum_key_cond (#key #repr: eqtype) (e: enum key repr) (r: repr) : GTot bool = list_mem r (list_map snd e) let parse_enum_key_synth (#key #repr: eqtype) (e: enum key repr) (r: repr { parse_enum_key_cond e r == true } ) : GTot (enum_key e) = enum_key_of_repr e r let parse_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) : Tot (parser (parse_filter_kind k) (enum_key e)) = (p `parse_filter` parse_enum_key_cond e ) `parse_synth` parse_enum_key_synth e let enum_repr_of_key (#key #repr: eqtype) (e: enum key repr) (k: enum_key e) : Pure (enum_repr e) (requires True) (ensures (fun r -> L.assoc k e == Some r)) = L.assoc_mem k e; let r = Some?.v (L.assoc k e) in assoc_flip_intro e r k; L.assoc_mem r (list_map flip e); map_fst_flip e; (r <: enum_repr e) let enum_repr_of_key_of_repr (#key #repr: eqtype) (e: enum key repr) (r: enum_repr e) : Lemma (enum_repr_of_key e (enum_key_of_repr e r) == r) = () let enum_key_of_repr_of_key (#key #repr: eqtype) (e: enum key repr) (k: enum_key e) : Lemma (enum_key_of_repr e (enum_repr_of_key e k) == k) = assoc_flip_intro e (enum_repr_of_key e k) k let serialize_enum_key_synth_recip (#key #repr: eqtype) (e: enum key repr) (k: enum_key e) : GTot (r: repr { parse_enum_key_cond e r == true } ) = enum_repr_of_key e k let serialize_enum_key_synth_inverse (#key #repr: eqtype) (e: enum key repr) : Lemma (synth_inverse (parse_enum_key_synth e) (serialize_enum_key_synth_recip e)) = Classical.forall_intro (enum_key_of_repr_of_key e) let serialize_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (s: serializer p) (e: enum key repr) : Tot (serializer (parse_enum_key p e)) = serialize_enum_key_synth_inverse e; serialize_synth (parse_filter p (parse_enum_key_cond e)) (parse_enum_key_synth e) (serialize_filter s (parse_enum_key_cond e)) (serialize_enum_key_synth_recip e) () let serialize_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (s: serializer p) (e: enum key repr) (x: enum_key e) : Lemma (serialize (serialize_enum_key p s e) x == serialize s (enum_repr_of_key e x)) = serialize_enum_key_synth_inverse e; serialize_synth_eq (parse_filter p (parse_enum_key_cond e)) (parse_enum_key_synth e) (serialize_filter s (parse_enum_key_cond e)) (serialize_enum_key_synth_recip e) () x inline_for_extraction let unknown_enum_repr (#key #repr: eqtype) (e: enum key repr) : Tot Type = (r: repr { list_mem r (list_map snd e) == false } ) type maybe_enum_key (#key #repr: eqtype) (e: enum key repr) = | Known of (enum_key e) | Unknown of (unknown_enum_repr e) let maybe_enum_key_of_repr (#key #repr: eqtype) (e: enum key repr) (r: repr) : Tot (maybe_enum_key e) = if list_mem r (list_map snd e) then Known (enum_key_of_repr e r) else Unknown r let parse_maybe_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) : Tot (parser k (maybe_enum_key e)) = p `parse_synth` (maybe_enum_key_of_repr e) let parse_maybe_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) (input: bytes) : Lemma (parse (parse_maybe_enum_key p e) input == (match parse p input with | Some (x, consumed) -> Some (maybe_enum_key_of_repr e x, consumed) | _ -> None )) = parse_synth_eq p (maybe_enum_key_of_repr e) input let parse_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) (input: bytes) : Lemma (parse (parse_enum_key p e) input == (match parse p input with | Some (x, consumed) -> begin match maybe_enum_key_of_repr e x with | Known k -> Some (k, consumed) | _ -> None end | _ -> None )) = parse_filter_eq p (parse_enum_key_cond e) input; parse_synth_eq (p `parse_filter` parse_enum_key_cond e) (parse_enum_key_synth e) input let repr_of_maybe_enum_key (#key #repr: eqtype) (e: enum key repr) (x: maybe_enum_key e) : Tot (r: repr { maybe_enum_key_of_repr e r == x } ) = match x with | Known k' -> enum_key_of_repr_of_key e k' ; enum_repr_of_key e k' | Unknown r -> r let serialize_maybe_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (s: serializer p) (e: enum key repr) : Tot (serializer (parse_maybe_enum_key p e)) = serialize_synth p (maybe_enum_key_of_repr e) s (repr_of_maybe_enum_key e) () let serialize_maybe_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (s: serializer p) (e: enum key repr) (x: maybe_enum_key e) : Lemma (serialize (serialize_maybe_enum_key p s e) x == serialize s (repr_of_maybe_enum_key e x)) = serialize_synth_eq p (maybe_enum_key_of_repr e) s (repr_of_maybe_enum_key e) () x let is_total_enum (#key: eqtype) (#repr: eqtype) (l: list (key * repr)) : GTot Type0 = forall (k: key) . {:pattern (list_mem k (list_map fst l))} list_mem k (list_map fst l) let total_enum (key: eqtype) (repr: eqtype) : Tot eqtype = (l: enum key repr { is_total_enum l } ) let synth_total_enum_key (#key: eqtype) (#repr: eqtype) (l: total_enum key repr) (k: enum_key l) : Tot key = let k' : key = k in k' let parse_total_enum_key (#k: parser_kind) (#key: eqtype) (#repr: eqtype) (p: parser k repr) (l: total_enum key repr) : Tot (parser (parse_filter_kind k) key) = parse_enum_key p l `parse_synth` (synth_total_enum_key l) let synth_total_enum_key_recip (#key: eqtype) (#repr: eqtype) (l: total_enum key repr) (k: key) : Tot (k' : enum_key l { synth_total_enum_key l k' == k } ) = k let serialize_total_enum_key (#k: parser_kind) (#key: eqtype) (#repr: eqtype) (p: parser k repr) (s: serializer p) (l: total_enum key repr) : Tot (serializer (parse_total_enum_key p l)) = serialize_synth (parse_enum_key p l) (synth_total_enum_key l) (serialize_enum_key p s l) (synth_total_enum_key_recip l) () type maybe_total_enum_key (#key #repr: eqtype) (e: total_enum key repr) = | TotalKnown of key | TotalUnknown of (unknown_enum_repr e) let maybe_total_enum_key_of_repr (#key #repr: eqtype) (e: total_enum key repr) (r: repr) : Tot (maybe_total_enum_key e) = if list_mem r (list_map snd e) then TotalKnown (enum_key_of_repr e r) else TotalUnknown r let parse_maybe_total_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: total_enum key repr) : Tot (parser k (maybe_total_enum_key e)) = p `parse_synth` (maybe_total_enum_key_of_repr e) let repr_of_maybe_total_enum_key (#key #repr: eqtype) (e: total_enum key repr) (k: maybe_total_enum_key e) : Tot (r: repr { maybe_total_enum_key_of_repr e r == k } ) = match k with | TotalKnown k' -> enum_key_of_repr_of_key e k' ; enum_repr_of_key e k' | TotalUnknown r -> r let serialize_maybe_total_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (s: serializer p) (e: total_enum key repr) : Tot (serializer (parse_maybe_total_enum_key p e)) = serialize_synth p (maybe_total_enum_key_of_repr e) s (repr_of_maybe_total_enum_key e) () inline_for_extraction let maybe_enum_key_of_total (#key #repr: eqtype) (e: total_enum key repr) (k: maybe_total_enum_key e) : Tot (maybe_enum_key e) = match k with | TotalKnown ek -> Known (ek <: key) | TotalUnknown r -> Unknown r inline_for_extraction let total_of_maybe_enum_key (#key #repr: eqtype) (e: total_enum key repr) (k: maybe_enum_key e) : Tot (maybe_total_enum_key e) = match k with | Known ek -> TotalKnown (ek <: key) | Unknown r -> TotalUnknown r let maybe_total_enum_key_of_repr_eq (#key #repr: eqtype) (e: total_enum key repr) (r: repr) : Lemma (maybe_total_enum_key_of_repr e r == total_of_maybe_enum_key e (maybe_enum_key_of_repr e r)) = () let parse_maybe_total_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: total_enum key repr) (input: bytes) : Lemma (parse (parse_maybe_total_enum_key p e) input == (parse (parse_maybe_enum_key p e `parse_synth` total_of_maybe_enum_key e) input)) = parse_synth_eq p (maybe_total_enum_key_of_repr e) input; parse_synth_eq (parse_maybe_enum_key p e) (total_of_maybe_enum_key e) input; parse_synth_eq p (maybe_enum_key_of_repr e) input (* Destructors *) (* Universal destructor *) let r_reflexive_prop (t: Type) (r: (t -> t -> GTot Type0)) : GTot Type0 = forall (x: t) . {:pattern (r x x)} r x x inline_for_extraction let r_reflexive_t (t: Type) (r: (t -> t -> GTot Type0)) : Tot Type = (x: t) -> Lemma (r x x) let r_reflexive_t_elim (t: Type) (r: (t -> t -> GTot Type0)) (phi: r_reflexive_t t r) : Lemma (r_reflexive_prop t r) = Classical.forall_intro phi let r_transitive_prop (t: Type) (r: (t -> t -> GTot Type0)) : GTot Type0 = forall (x y z: t) . {:pattern (r x y); (r y z)} (r x y /\ r y z) ==> r x z inline_for_extraction let r_transitive_t (t: Type) (r: (t -> t -> GTot Type0)) : Tot Type = (x: t) -> (y: t) -> (z: t) -> Lemma ((r x y /\ r y z) ==> r x z) let r_transitive_t_elim (t: Type) (r: (t -> t -> GTot Type0)) (phi: r_transitive_t t r) : Lemma (r_transitive_prop t r) = Classical.forall_intro_3 phi inline_for_extraction let if_combinator (t: Type) (eq: (t -> t -> GTot Type0)) : Tot Type = (cond: bool) -> (sv_true: (cond_true cond -> Tot t)) -> (sv_false: (cond_false cond -> Tot t)) -> Tot (y: t { eq y (if cond then sv_true () else sv_false ()) } ) inline_for_extraction let default_if (t: Type) : Tot (if_combinator t (eq2 #t)) = fun (cond: bool) (s_true: (cond_true cond -> Tot t)) (s_false: (cond_false cond -> Tot t)) -> (if cond then s_true () else s_false ()) <: (y: t { y == (if cond then s_true () else s_false ()) } ) let feq (u v: Type) (eq: (v -> v -> GTot Type0)) (f1 f2: (u -> Tot v)) : GTot Type0 = (forall (x: u) . {:pattern (f1 x); (f2 x)} eq (f1 x) (f2 x)) (* #!$% patterns on forall, the following proofs should be trivial and now they aren't *) let feq_elim (u v: Type) (eq: (v -> v -> GTot Type0)) (f1 f2: (u -> Tot v)) (x: u) : Lemma (requires (feq u v eq f1 f2)) (ensures (f1 x `eq` f2 x)) = () let feq_intro (u v: Type) (eq: (v -> v -> GTot Type0)) (f1 f2: (u -> Tot v)) (phi: (x: u) -> Lemma (f1 x `eq` f2 x)) : Lemma (feq _ _ eq f1 f2) = Classical.forall_intro phi let feq_trans (u v: Type) (eq: (v -> v -> GTot Type0)) : Pure (r_transitive_t _ (feq _ _ eq)) (requires (r_transitive_prop _ eq)) (ensures (fun _ -> True)) = let phi (f1 f2 f3: (u -> Tot v)) : Lemma (requires (feq _ _ eq f1 f2 /\ feq _ _ eq f2 f3)) (ensures (feq _ _ eq f1 f3)) = feq_intro _ _ eq f1 f3 (fun x -> assert (f1 x `eq` f2 x /\ f2 x `eq` f3 x)) in let phi2 (f1 f2 f3: (u -> Tot v)) : Lemma ((feq _ _ eq f1 f2 /\ feq _ _ eq f2 f3) ==> feq _ _ eq f1 f3) = Classical.move_requires (phi f1 f2) f3 in phi2 inline_for_extraction let fif (u v: Type) (eq: (v -> v -> GTot Type0)) (ifc: if_combinator v eq) : Tot (if_combinator (u -> Tot v) (feq u v eq)) = fun (cond: bool) (s_true: (cond_true cond -> u -> Tot v)) (s_false: (cond_false cond -> u -> Tot v)) (x: u) -> ifc cond (fun h -> s_true () x) (fun h -> s_false () x) inline_for_extraction let enum_destr_t (t: Type) (#key #repr: eqtype) (e: enum key repr) : Tot Type = (eq: (t -> t -> GTot Type0)) -> (ift: if_combinator t eq) -> (eq_refl: r_reflexive_t _ eq) -> (eq_trans: r_transitive_t _ eq) -> (f: ((x: enum_key e) -> Tot t)) -> (x: enum_key e) -> Tot (y: t { eq y (f x) } ) inline_for_extraction let enum_tail' (#key #repr: eqtype) (e: enum key repr) : Pure (enum key repr) (requires True) (ensures (fun y -> Cons? e ==> (let (_ :: y') = e in y == y'))) = match e with _ :: y -> y | _ -> [] inline_for_extraction let enum_tail (#key #repr: eqtype) (e: enum key repr) : Tot (enum key repr) = enum_tail' e inline_for_extraction let enum_destr_cons (t: Type) (#key #repr: eqtype) (e: enum key repr) (g: enum_destr_t t (enum_tail' e)) : Pure (enum_destr_t t e) (requires (Cons? e)) (ensures (fun _ -> True)) = fun (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) -> [@inline_let] let _ = r_reflexive_t_elim _ _ eq_refl in [@inline_let] let _ = r_transitive_t_elim _ _ eq_trans in (fun (e' : list (key * repr) { e' == e } ) -> match e' with | (k, _) :: _ -> (fun (f: (enum_key e -> Tot t)) (x: enum_key e) -> (( [@inline_let] let f' : (enum_key (enum_tail' e) -> Tot t) = (fun (x' : enum_key (enum_tail' e)) -> [@inline_let] let (x_ : enum_key e) = (x' <: key) in f x_ ) in [@inline_let] let (y: t) = ift ((k <: key) = x) (fun h -> f k) (fun h -> [@inline_let] let x' : enum_key (enum_tail' e) = (x <: key) in (g eq ift eq_refl eq_trans f' x' <: t)) in y ) <: (y: t { eq y (f x) } ))) ) e inline_for_extraction let enum_destr_cons' (t: Type) (key repr: eqtype) (e: enum key repr) (u: unit { Cons? e } ) (g: enum_destr_t t (enum_tail e)) : Tot (enum_destr_t t e) = enum_destr_cons t e g inline_for_extraction let enum_destr_cons_nil (t: Type) (#key #repr: eqtype) (e: enum key repr) : Pure (enum_destr_t t e) (requires (Cons? e /\ Nil? (enum_tail' e))) (ensures (fun _ -> True)) = fun (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) -> [@inline_let] let _ = r_reflexive_t_elim _ _ eq_refl in (fun (e' : list (key * repr) { e' == e } ) -> match e' with | (k, _) :: _ -> (fun (f: (enum_key e -> Tot t)) (x: enum_key e) -> (( f k ) <: (y: t { eq y (f x) } ))) ) e inline_for_extraction let enum_destr_cons_nil' (t: Type) (key repr: eqtype) (e: enum key repr) (u1: unit { Cons? e } ) (u2: unit { Nil? (enum_tail e) } ) : Tot (enum_destr_t t e) = enum_destr_cons_nil t e (* Dependent destructor *) inline_for_extraction let dep_enum_destr (#key #repr: eqtype) (e: enum key repr) (v: (enum_key e -> Tot (Type u#a))) : Tot (Type) = (v_eq: ((k: enum_key e) -> v k -> v k -> GTot Type0)) -> (v_if: ((k: enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) -> (v_eq_refl: ((k: enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) -> (v_eq_trans: ((k: enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) -> (f: ((k: enum_key e) -> Tot (v k))) -> (k: enum_key e) -> Tot (y: v k { v_eq k y (f k) } ) module L = FStar.List.Tot inline_for_extraction let dep_enum_destr_cons (#key #repr: eqtype) (e: enum key repr) (u: squash (Cons? e)) (v: (enum_key e -> Tot Type)) (destr: dep_enum_destr (enum_tail e) (fun (k' : enum_key (enum_tail e)) -> v (k' <: key))) : Tot (dep_enum_destr e v) = match e with | ((k, _) :: _) -> fun (v_eq: ((k: enum_key e) -> v k -> v k -> GTot Type0)) (v_if: ((k: enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) (v_eq_refl: ((k: enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) (v_eq_trans: ((k: enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) (f: ((k: enum_key e) -> Tot (v k))) (k' : enum_key e) -> [@inline_let] let _ = r_reflexive_t_elim (v k') (v_eq k') (v_eq_refl k') in [@inline_let] let _ = r_transitive_t_elim (v k') (v_eq k') (v_eq_trans k') in [@inline_let] let y : v k' = v_if k' (k = k') (fun _ -> [@inline_let] let y : v k' = f k in y ) (fun _ -> [@inline_let] let v' (k: enum_key (enum_tail e)) : Tot Type = v (k <: key) in [@inline_let] let v'_eq (k: enum_key (enum_tail e)) : Tot (v' k -> v' k -> GTot Type0) = v_eq (k <: key) in [@inline_let] let v'_if (k: enum_key (enum_tail e)) : Tot (if_combinator (v' k) (v'_eq k)) = v_if (k <: key) in [@inline_let] let v'_eq_refl (k: enum_key (enum_tail e)) : Tot (r_reflexive_t _ (v'_eq k)) = v_eq_refl (k <: key) in [@inline_let] let v'_eq_trans (k: enum_key (enum_tail e)) : Tot (r_transitive_t _ (v'_eq k)) = v_eq_trans (k <: key) in [@inline_let] let f' (k: enum_key (enum_tail e)) : Tot (v' k) = f (k <: key) in [@inline_let] let k' : key = k' in [@inline_let] let _ = assert (k' <> k) in [@inline_let] let _ = assert (L.mem k' (L.map fst (enum_tail e))) in [@inline_let] let (y: v' k') = destr v'_eq v'_if v'_eq_refl v'_eq_trans f' k' in y ) in (y <: (y: v k' { v_eq k' y (f k') } )) inline_for_extraction let dep_enum_destr_cons_nil (#key #repr: eqtype) (e: enum key repr) (u: squash (Cons? e /\ Nil? (enum_tail e))) (v: (enum_key e -> Tot Type)) : Tot (dep_enum_destr e v) = match e with | ((k, _) :: _) -> fun (v_eq: ((k: enum_key e) -> v k -> v k -> GTot Type0)) (v_if: ((k: enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) (v_eq_refl: ((k: enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) (v_eq_trans: ((k: enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) (f: ((k: enum_key e) -> Tot (v k))) (k' : enum_key e) -> [@inline_let] let _ = r_reflexive_t_elim (v k') (v_eq k') (v_eq_refl k') in [@inline_let] let _ = r_transitive_t_elim (v k') (v_eq k') (v_eq_trans k') in [@inline_let] let y : v k' = f k in (y <: (y: v k' { v_eq k' y (f k') } )) (* Destructor from the representation *) let maybe_enum_key_of_repr_not_in (#key #repr: eqtype) (e: enum key repr) (l: list (key * repr)) (x: repr) : GTot Type0 = (~ (L.mem x (L.map snd l))) let list_rev_cons (#t: Type) (a: t) (q: list t) : Lemma (L.rev (a :: q) == L.rev q `L.append` [a]) = L.rev_rev' (a :: q); L.rev_rev' q let list_append_rev_cons (#t: Type) (l1: list t) (x: t) (l2: list t) : Lemma (L.append (L.rev l1) (x :: l2) == L.append (L.rev (x :: l1)) l2) = list_rev_cons x l1; L.append_assoc (L.rev l1) [x] l2 let rec assoc_append_flip_l_intro (#key #repr: eqtype) (l1 l2: list (key * repr)) (y: repr) (x: key) : Lemma (requires (L.noRepeats (L.map snd (L.append l1 l2)) /\ L.assoc y (L.map flip l2) == Some x)) (ensures (L.assoc y (L.map flip (l1 `L.append` l2)) == Some x)) = match l1 with | [] -> () | (_, r') :: q -> L.assoc_mem y (L.map flip l2); map_fst_flip l2; L.map_append snd l1 l2; L.noRepeats_append_elim (L.map snd l1) (L.map snd l2); assoc_append_flip_l_intro q l2 y x inline_for_extraction let maybe_enum_destr_t' (t: Type) (#key #repr: eqtype) (e: enum key repr) (l1 l2: list (key * repr)) (u1: squash (e == L.append (L.rev l1) l2)) : Tot Type = (eq: (t -> t -> GTot Type0)) -> (ift: if_combinator t eq) -> (eq_refl: r_reflexive_t _ eq) -> (eq_trans: r_transitive_t _ eq) -> (f: ((x: maybe_enum_key e) -> Tot t)) -> (x: repr { maybe_enum_key_of_repr_not_in e l1 x } ) -> Tot (y: t { eq y (f (maybe_enum_key_of_repr e x)) } ) inline_for_extraction let maybe_enum_destr_t (t: Type) (#key #repr: eqtype) (e: enum key repr) : Tot Type = (eq: (t -> t -> GTot Type0)) -> (ift: if_combinator t eq) -> (eq_refl: r_reflexive_t _ eq) -> (eq_trans: r_transitive_t _ eq) -> (f: ((x: maybe_enum_key e) -> Tot t)) -> (x: repr) -> Tot (y: t { eq y (f (maybe_enum_key_of_repr e x)) } ) inline_for_extraction let destr_maybe_total_enum_repr (#t: Type) (#key #repr: eqtype) (e: total_enum key repr) (destr: maybe_enum_destr_t t e) (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) (f: ((x: maybe_total_enum_key e) -> Tot t)) (x: repr) : Tot (y: t { eq y (f (maybe_total_enum_key_of_repr e x)) } ) = destr eq ift eq_refl eq_trans (fun y -> f (total_of_maybe_enum_key e y)) x inline_for_extraction let maybe_enum_destr_t_intro (t: Type) (#key #repr: eqtype) (e: enum key repr) (f: maybe_enum_destr_t' t e [] e ()) : Tot (maybe_enum_destr_t t e) = f let maybe_enum_key_of_repr_not_in_cons (#key #repr: eqtype) (e: enum key repr) (k: key) (r: repr) (l: list (key * repr)) (x: repr) : Lemma (requires (maybe_enum_key_of_repr_not_in e l x /\ x <> r)) (ensures (maybe_enum_key_of_repr_not_in e ((k, r) :: l) x)) = () [@Norm] inline_for_extraction let list_hd (#t: Type) (l: list t { Cons? l } ) = match l with | a :: _ -> a [@Norm] inline_for_extraction let list_tl (#t: Type) (l: list t { Cons? l } ) = match l with | _ :: q -> q inline_for_extraction let maybe_enum_destr_cons (t: Type) (#key #repr: eqtype) (e: enum key repr) (l1: list (key * repr)) (l2: list (key * repr)) (u1: squash (Cons? l2 /\ e == L.append (L.rev l1) l2)) (g: (maybe_enum_destr_t' t e (list_hd l2 :: l1) (list_tl l2) (list_append_rev_cons l1 (list_hd l2) (list_tl l2)))) : Tot (maybe_enum_destr_t' t e l1 l2 u1) = fun (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) (f: (maybe_enum_key e -> Tot t)) -> [@inline_let] let _ = r_reflexive_t_elim _ _ eq_refl in [@inline_let] let _ = r_transitive_t_elim _ _ eq_trans in match list_hd l2 with | (k, r) -> [@inline_let] let _ : squash (L.mem k (L.map fst e)) = L.append_mem (L.map fst (L.rev l1)) (L.map fst l2) k; L.map_append fst (L.rev l1) (l2); () in [@inline_let] let (_ : squash (maybe_enum_key_of_repr e r == Known k)) = L.append_mem (L.map snd (L.rev l1)) (L.map snd (l2)) r; L.map_append snd (L.rev l1) (l2); assoc_append_flip_l_intro (L.rev l1) (l2) r k; () in fun (x: repr { maybe_enum_key_of_repr_not_in e l1 x } ) -> (( ift (x = r) (fun h -> f (Known k)) (fun h -> g eq ift eq_refl eq_trans f x) ) <: (y: t { eq y (f (maybe_enum_key_of_repr e x)) } )) let rec list_rev_map (#t1 #t2: Type) (f: t1 -> Tot t2) (l: list t1) : Lemma (L.rev (L.map f l) == L.map f (L.rev l)) = match l with | [] -> () | a :: q -> list_rev_cons a q; list_rev_cons (f a) (L.map f q); list_rev_map f q; L.map_append f (L.rev q) [a] inline_for_extraction let maybe_enum_destr_nil (t: Type) (#key #repr: eqtype) (e: enum key repr) (l1: list (key * repr)) (l2: list (key * repr)) (u1: squash (Nil? l2 /\ e == L.append (L.rev l1) [])) : Tot (maybe_enum_destr_t' t e l1 l2 u1) = fun (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) (f: (maybe_enum_key e -> Tot t)) -> [@inline_let] let _ = r_reflexive_t_elim _ _ eq_refl in [@inline_let] let _ = r_transitive_t_elim _ _ eq_trans in fun (x: repr { maybe_enum_key_of_repr_not_in e l1 x } ) -> (( L.append_l_nil (L.rev l1); list_rev_map snd l1; L.rev_mem (L.map snd l1) x; f (Unknown x) ) <: (y: t { eq y (f (maybe_enum_key_of_repr e x)) } )) [@Norm] let rec mk_maybe_enum_destr' (t: Type) (#key #repr: eqtype) (e: enum key repr) (l1: list (key * repr)) (l2: list (key * repr)) (u: squash (e == L.rev l1 `L.append` l2)) : Tot (maybe_enum_destr_t' t e l1 l2 u) (decreases l2) = match l2 with | [] -> maybe_enum_destr_nil t e l1 l2 u | _ -> [@inline_let] let _ = list_append_rev_cons l1 (list_hd l2) (list_tl l2) in maybe_enum_destr_cons t e l1 l2 u (mk_maybe_enum_destr' t e (list_hd l2 :: l1) (list_tl l2) u) [@Norm] let mk_maybe_enum_destr (t: Type) (#key #repr: eqtype) (e: enum key repr) : Tot (maybe_enum_destr_t t e) = maybe_enum_destr_t_intro t e (mk_maybe_enum_destr' t e [] e ()) (* dependent representation-based destructor *) inline_for_extraction let dep_maybe_enum_destr_t (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) : Tot Type = (v_eq: ((k: maybe_enum_key e) -> v k -> v k -> GTot Type0)) -> (v_if: ((k: maybe_enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) -> (v_eq_refl: ((k: maybe_enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) -> (v_eq_trans: ((k: maybe_enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) -> (f: ((k: maybe_enum_key e) -> Tot (v k))) -> (r: repr) -> Tot (y: v (maybe_enum_key_of_repr e r) { v_eq (maybe_enum_key_of_repr e r) y (f (maybe_enum_key_of_repr e r)) } ) inline_for_extraction let dep_maybe_enum_destr_t' (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) (l1 l2: list (key * repr)) (u1: squash (e == L.append (L.rev l1) l2)) : Tot Type = (v_eq: ((k: maybe_enum_key e) -> v k -> v k -> GTot Type0)) -> (v_if: ((k: maybe_enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) -> (v_eq_refl: ((k: maybe_enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) -> (v_eq_trans: ((k: maybe_enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) -> (f: ((k: maybe_enum_key e) -> Tot (v k))) -> (r: repr { maybe_enum_key_of_repr_not_in e l1 r } ) -> Tot (y: v (maybe_enum_key_of_repr e r) { v_eq (maybe_enum_key_of_repr e r) y (f (maybe_enum_key_of_repr e r)) } ) inline_for_extraction let dep_maybe_enum_destr_t_intro (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) (d: dep_maybe_enum_destr_t' e v [] e ()) : Tot (dep_maybe_enum_destr_t e v) = d inline_for_extraction let dep_maybe_enum_destr_cons (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) (l1: list (key * repr)) (l2: list (key * repr)) (u1: squash (Cons? l2 /\ e == L.append (L.rev l1) l2)) (g: (dep_maybe_enum_destr_t' e v (list_hd l2 :: l1) (list_tl l2) (list_append_rev_cons l1 (list_hd l2) (list_tl l2)))) : Tot (dep_maybe_enum_destr_t' e v l1 l2 u1) = fun (v_eq: ((k: maybe_enum_key e) -> v k -> v k -> GTot Type0)) (v_if: ((k: maybe_enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) (v_eq_refl: ((k: maybe_enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) (v_eq_trans: ((k: maybe_enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) (f: ((k: maybe_enum_key e) -> Tot (v k))) -> match list_hd l2 with | (k, r) -> [@inline_let] let _ : squash (L.mem k (L.map fst e)) = L.append_mem (L.map fst (L.rev l1)) (L.map fst l2) k; L.map_append fst (L.rev l1) (l2); () in [@inline_let] let (_ : squash (maybe_enum_key_of_repr e r == Known k)) = L.append_mem (L.map snd (L.rev l1)) (L.map snd (l2)) r; L.map_append snd (L.rev l1) (l2); assoc_append_flip_l_intro (L.rev l1) (l2) r k; () in fun (x: repr { maybe_enum_key_of_repr_not_in e l1 x } ) -> //NS: y is linear in the continuation after erasure; inline it [@inline_let] let y : v (maybe_enum_key_of_repr e x) = v_if (maybe_enum_key_of_repr e x) // TODO: Since we cannot make this argument ghost, we need to make the user aware of the fact that this argument must not be extracted. (x = r) (fun h -> f (Known k)) (fun h -> g v_eq v_if v_eq_refl v_eq_trans f x) in [@inline_let] let _ : squash (v_eq (maybe_enum_key_of_repr e x) y (f (maybe_enum_key_of_repr e x))) = if x = r then () else v_eq_trans (maybe_enum_key_of_repr e x) y (g v_eq v_if v_eq_refl v_eq_trans f x) (f (maybe_enum_key_of_repr e x)) in (y <: (y: v (maybe_enum_key_of_repr e x) { v_eq (maybe_enum_key_of_repr e x) y (f (maybe_enum_key_of_repr e x)) } )) inline_for_extraction let dep_maybe_enum_destr_nil (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) (l1: list (key * repr)) (l2: list (key * repr)) (u1: squash (Nil? l2 /\ e == L.append (L.rev l1) [])) : Tot (dep_maybe_enum_destr_t' e v l1 l2 u1) = fun (v_eq: ((k: maybe_enum_key e) -> v k -> v k -> GTot Type0)) (v_if: ((k: maybe_enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) (v_eq_refl: ((k: maybe_enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) (v_eq_trans: ((k: maybe_enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) (f: ((k: maybe_enum_key e) -> Tot (v k))) (x: repr { maybe_enum_key_of_repr_not_in e l1 x } ) -> (( L.append_l_nil (L.rev l1); list_rev_map snd l1; L.rev_mem (L.map snd l1) x; assert (Unknown x == maybe_enum_key_of_repr e x); //NS: y is linear in the continuation after erasure [@inline_let] let y : v (maybe_enum_key_of_repr e x) = f (Unknown x) in [@inline_let] let _ = v_eq_refl (maybe_enum_key_of_repr e x) (f (maybe_enum_key_of_repr e x)) in y ) <: (y: v (maybe_enum_key_of_repr e x) { v_eq (maybe_enum_key_of_repr e x) y (f (maybe_enum_key_of_repr e x)) } )) [@Norm] let rec mk_dep_maybe_enum_destr' (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) (l1: list (key * repr)) (l2: list (key * repr)) (u1: squash (e == L.append (L.rev l1) l2)) : Tot (dep_maybe_enum_destr_t' e v l1 l2 u1) (decreases l2) = match l2 with | [] -> dep_maybe_enum_destr_nil e v l1 l2 u1 | _ -> dep_maybe_enum_destr_cons e v l1 l2 u1 (mk_dep_maybe_enum_destr' e v (list_hd l2 :: l1) (list_tl l2) (list_append_rev_cons l1 (list_hd l2) (list_tl l2))) [@Norm] let mk_dep_maybe_enum_destr (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) = dep_maybe_enum_destr_t_intro e v (mk_dep_maybe_enum_destr' e v [] e ()) (* Eliminators and destructors for verification purposes *) let rec list_forallp (#t: Type) (p: t -> GTot Type0) (l: list t) : GTot Type0 = match l with | [] -> True | a :: q -> p a /\ list_forallp p q let rec list_forallp_mem (#t: eqtype) (p: t -> GTot Type0) (l: list t) : Lemma (list_forallp p l <==> (forall x . L.mem x l ==> p x)) = match l with | [] -> () | _ :: q -> list_forallp_mem p q
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.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": "LowParse.Spec.Enum.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
e: LowParse.Spec.Enum.enum key value -> f: (_: LowParse.Spec.Enum.maybe_enum_key e -> Type) -> f_known: ( x: key -> u1075: Prims.squash (LowParse.Spec.Enum.list_mem x (LowParse.Spec.Enum.list_map FStar.Pervasives.Native.fst e)) -> f (LowParse.Spec.Enum.Known x)) -> f_unknown: ( x: value -> u1077: Prims.squash (LowParse.Spec.Enum.list_mem x (LowParse.Spec.Enum.list_map FStar.Pervasives.Native.snd e) == false) -> f (LowParse.Spec.Enum.Unknown x)) -> x: LowParse.Spec.Enum.maybe_enum_key e -> f x
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "LowParse.Spec.Enum.enum", "LowParse.Spec.Enum.maybe_enum_key", "Prims.squash", "Prims.b2t", "LowParse.Spec.Enum.list_mem", "LowParse.Spec.Enum.list_map", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.fst", "LowParse.Spec.Enum.Known", "Prims.eq2", "Prims.bool", "FStar.Pervasives.Native.snd", "LowParse.Spec.Enum.Unknown", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Enum.unknown_enum_repr" ]
[]
false
false
false
false
false
let destruct_maybe_enum_key (#key #value: eqtype) (e: enum key value) (f: (maybe_enum_key e -> Tot Type)) (f_known: (x: key -> u: squash (list_mem x (list_map fst e)) -> Tot (f (Known x)))) (f_unknown: (x: value -> u: squash (list_mem x (list_map snd e) == false) -> Tot (f (Unknown x)))) (x: maybe_enum_key e) : Tot (f x) =
match x with | Known x' -> f_known x' () | Unknown x' -> f_unknown x' ()
false
LowParse.Spec.Enum.fst
LowParse.Spec.Enum.enum_repr_of_key_append_cons
val enum_repr_of_key_append_cons (#key #repr: eqtype) (e: enum key repr) (l1: list (key & repr)) (kr: (key & repr)) (l2: list (key & repr)) : Lemma (requires (e == l1 `L.append` (kr :: l2))) (ensures (list_mem (fst kr) (list_map fst e) /\ enum_repr_of_key e (fst kr) == snd kr /\ list_mem (snd kr) (list_map snd e) /\ enum_key_of_repr e (snd kr) == fst kr))
val enum_repr_of_key_append_cons (#key #repr: eqtype) (e: enum key repr) (l1: list (key & repr)) (kr: (key & repr)) (l2: list (key & repr)) : Lemma (requires (e == l1 `L.append` (kr :: l2))) (ensures (list_mem (fst kr) (list_map fst e) /\ enum_repr_of_key e (fst kr) == snd kr /\ list_mem (snd kr) (list_map snd e) /\ enum_key_of_repr e (snd kr) == fst kr))
let enum_repr_of_key_append_cons (#key #repr: eqtype) (e: enum key repr) (l1: list (key & repr)) (kr: (key & repr)) (l2: list (key & repr)) : Lemma (requires (e == l1 `L.append` (kr :: l2))) (ensures (list_mem (fst kr) (list_map fst e) /\ enum_repr_of_key e (fst kr) == snd kr /\ list_mem (snd kr) (list_map snd e) /\ enum_key_of_repr e (snd kr) == fst kr)) = L.map_append fst l1 (kr :: l2); L.noRepeats_append_elim (L.map fst l1) (L.map fst (kr :: l2)); L.assoc_mem (fst kr) l1; L.assoc_mem (fst kr) e; L.assoc_append_elim_l (fst kr) l1 (kr :: l2); enum_key_of_repr_of_key e (fst kr)
{ "file_name": "src/lowparse/LowParse.Spec.Enum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 36, "end_line": 1277, "start_col": 0, "start_line": 1263 }
module LowParse.Spec.Enum include LowParse.Spec.Combinators module L = FStar.List.Tot [@Norm] let rec list_map (#a #b: Type) (f: (a -> Tot b)) (l: list a) : Tot (l' : list b { l' == L.map f l } ) = match l with | [] -> [] | a :: q -> f a :: list_map f q type enum (key: eqtype) (repr: eqtype) = (l: list (key * repr) { L.noRepeats (list_map fst l) /\ L.noRepeats (list_map snd l) }) [@Norm] let rec list_mem (#t: eqtype) (x: t) (l: list t) : Tot (y: bool { y == true <==> L.mem x l == true } ) = match l with | [] -> false | a :: q -> (x = a || list_mem x q) inline_for_extraction let enum_key (#key #repr: eqtype) (e: enum key repr) : Tot eqtype = (s: key { list_mem s (list_map fst e) } ) inline_for_extraction let make_enum_key (#key #repr: eqtype) (e: enum key repr) (k: key) : Pure (enum_key e) (requires (list_mem k (list_map fst e))) (ensures (fun k' -> k == (k' <: key))) = k inline_for_extraction let enum_repr (#key #repr: eqtype) (e: enum key repr) : Tot eqtype = (r: repr { list_mem r (list_map snd e) } ) let flip (#a #b: Type) (c: (a * b)) : Tot (b * a) = let (ca, cb) = c in (cb, ca) let rec map_flip_flip (#a #b: Type) (l: list (a * b)) : Lemma (list_map flip (list_map flip l) == l) = match l with | [] -> () | _ :: q -> map_flip_flip q let rec map_fst_flip (#a #b: Type) (l: list (a * b)) : Lemma (list_map fst (list_map flip l) == list_map snd l) = match l with | [] -> () | _ :: q -> map_fst_flip q let rec map_snd_flip (#a #b: Type) (l: list (a * b)) : Lemma (list_map snd (list_map flip l) == list_map fst l) = match l with | [] -> () | _ :: q -> map_snd_flip q let rec assoc_mem_snd (#a #b: eqtype) (l: list (a * b)) (x: a) (y: b) : Lemma (requires (L.assoc x l == Some y)) (ensures (list_mem y (list_map snd l) == true)) (decreases l) = let ((x', y') :: l') = l in if x' = x then () else assoc_mem_snd l' x y let rec assoc_flip_elim (#a #b: eqtype) (l: list (a * b)) (y: b) (x: a) : Lemma (requires ( L.noRepeats (list_map fst l) /\ L.noRepeats (list_map snd l) /\ L.assoc y (list_map flip l) == Some x )) (ensures ( L.assoc x l == Some y )) (decreases l) = let ((x', y') :: l') = l in if y' = y then () else begin if x' = x then begin assert (list_mem x' (list_map fst l') == false); assoc_mem_snd (list_map flip l') y x; map_snd_flip l'; assert False end else assoc_flip_elim l' y x end let rec assoc_flip_intro (#a #b: eqtype) (l: list (a * b)) (y: b) (x: a) : Lemma (requires ( L.noRepeats (list_map fst l) /\ L.noRepeats (list_map snd l) /\ L.assoc x l == Some y )) (ensures ( L.assoc y (list_map flip l) == Some x )) = map_fst_flip l; map_snd_flip l; map_flip_flip l; assoc_flip_elim (list_map flip l) x y let enum_key_of_repr (#key #repr: eqtype) (e: enum key repr) (r: enum_repr e) : Pure (enum_key e) (requires True) (ensures (fun y -> L.assoc y e == Some r)) = map_fst_flip e; let e' = list_map #(key * repr) #(repr * key) flip e in L.assoc_mem r e'; let k = Some?.v (L.assoc r e') in assoc_flip_elim e r k; L.assoc_mem k e; (k <: enum_key e) let parse_enum_key_cond (#key #repr: eqtype) (e: enum key repr) (r: repr) : GTot bool = list_mem r (list_map snd e) let parse_enum_key_synth (#key #repr: eqtype) (e: enum key repr) (r: repr { parse_enum_key_cond e r == true } ) : GTot (enum_key e) = enum_key_of_repr e r let parse_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) : Tot (parser (parse_filter_kind k) (enum_key e)) = (p `parse_filter` parse_enum_key_cond e ) `parse_synth` parse_enum_key_synth e let enum_repr_of_key (#key #repr: eqtype) (e: enum key repr) (k: enum_key e) : Pure (enum_repr e) (requires True) (ensures (fun r -> L.assoc k e == Some r)) = L.assoc_mem k e; let r = Some?.v (L.assoc k e) in assoc_flip_intro e r k; L.assoc_mem r (list_map flip e); map_fst_flip e; (r <: enum_repr e) let enum_repr_of_key_of_repr (#key #repr: eqtype) (e: enum key repr) (r: enum_repr e) : Lemma (enum_repr_of_key e (enum_key_of_repr e r) == r) = () let enum_key_of_repr_of_key (#key #repr: eqtype) (e: enum key repr) (k: enum_key e) : Lemma (enum_key_of_repr e (enum_repr_of_key e k) == k) = assoc_flip_intro e (enum_repr_of_key e k) k let serialize_enum_key_synth_recip (#key #repr: eqtype) (e: enum key repr) (k: enum_key e) : GTot (r: repr { parse_enum_key_cond e r == true } ) = enum_repr_of_key e k let serialize_enum_key_synth_inverse (#key #repr: eqtype) (e: enum key repr) : Lemma (synth_inverse (parse_enum_key_synth e) (serialize_enum_key_synth_recip e)) = Classical.forall_intro (enum_key_of_repr_of_key e) let serialize_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (s: serializer p) (e: enum key repr) : Tot (serializer (parse_enum_key p e)) = serialize_enum_key_synth_inverse e; serialize_synth (parse_filter p (parse_enum_key_cond e)) (parse_enum_key_synth e) (serialize_filter s (parse_enum_key_cond e)) (serialize_enum_key_synth_recip e) () let serialize_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (s: serializer p) (e: enum key repr) (x: enum_key e) : Lemma (serialize (serialize_enum_key p s e) x == serialize s (enum_repr_of_key e x)) = serialize_enum_key_synth_inverse e; serialize_synth_eq (parse_filter p (parse_enum_key_cond e)) (parse_enum_key_synth e) (serialize_filter s (parse_enum_key_cond e)) (serialize_enum_key_synth_recip e) () x inline_for_extraction let unknown_enum_repr (#key #repr: eqtype) (e: enum key repr) : Tot Type = (r: repr { list_mem r (list_map snd e) == false } ) type maybe_enum_key (#key #repr: eqtype) (e: enum key repr) = | Known of (enum_key e) | Unknown of (unknown_enum_repr e) let maybe_enum_key_of_repr (#key #repr: eqtype) (e: enum key repr) (r: repr) : Tot (maybe_enum_key e) = if list_mem r (list_map snd e) then Known (enum_key_of_repr e r) else Unknown r let parse_maybe_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) : Tot (parser k (maybe_enum_key e)) = p `parse_synth` (maybe_enum_key_of_repr e) let parse_maybe_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) (input: bytes) : Lemma (parse (parse_maybe_enum_key p e) input == (match parse p input with | Some (x, consumed) -> Some (maybe_enum_key_of_repr e x, consumed) | _ -> None )) = parse_synth_eq p (maybe_enum_key_of_repr e) input let parse_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) (input: bytes) : Lemma (parse (parse_enum_key p e) input == (match parse p input with | Some (x, consumed) -> begin match maybe_enum_key_of_repr e x with | Known k -> Some (k, consumed) | _ -> None end | _ -> None )) = parse_filter_eq p (parse_enum_key_cond e) input; parse_synth_eq (p `parse_filter` parse_enum_key_cond e) (parse_enum_key_synth e) input let repr_of_maybe_enum_key (#key #repr: eqtype) (e: enum key repr) (x: maybe_enum_key e) : Tot (r: repr { maybe_enum_key_of_repr e r == x } ) = match x with | Known k' -> enum_key_of_repr_of_key e k' ; enum_repr_of_key e k' | Unknown r -> r let serialize_maybe_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (s: serializer p) (e: enum key repr) : Tot (serializer (parse_maybe_enum_key p e)) = serialize_synth p (maybe_enum_key_of_repr e) s (repr_of_maybe_enum_key e) () let serialize_maybe_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (s: serializer p) (e: enum key repr) (x: maybe_enum_key e) : Lemma (serialize (serialize_maybe_enum_key p s e) x == serialize s (repr_of_maybe_enum_key e x)) = serialize_synth_eq p (maybe_enum_key_of_repr e) s (repr_of_maybe_enum_key e) () x let is_total_enum (#key: eqtype) (#repr: eqtype) (l: list (key * repr)) : GTot Type0 = forall (k: key) . {:pattern (list_mem k (list_map fst l))} list_mem k (list_map fst l) let total_enum (key: eqtype) (repr: eqtype) : Tot eqtype = (l: enum key repr { is_total_enum l } ) let synth_total_enum_key (#key: eqtype) (#repr: eqtype) (l: total_enum key repr) (k: enum_key l) : Tot key = let k' : key = k in k' let parse_total_enum_key (#k: parser_kind) (#key: eqtype) (#repr: eqtype) (p: parser k repr) (l: total_enum key repr) : Tot (parser (parse_filter_kind k) key) = parse_enum_key p l `parse_synth` (synth_total_enum_key l) let synth_total_enum_key_recip (#key: eqtype) (#repr: eqtype) (l: total_enum key repr) (k: key) : Tot (k' : enum_key l { synth_total_enum_key l k' == k } ) = k let serialize_total_enum_key (#k: parser_kind) (#key: eqtype) (#repr: eqtype) (p: parser k repr) (s: serializer p) (l: total_enum key repr) : Tot (serializer (parse_total_enum_key p l)) = serialize_synth (parse_enum_key p l) (synth_total_enum_key l) (serialize_enum_key p s l) (synth_total_enum_key_recip l) () type maybe_total_enum_key (#key #repr: eqtype) (e: total_enum key repr) = | TotalKnown of key | TotalUnknown of (unknown_enum_repr e) let maybe_total_enum_key_of_repr (#key #repr: eqtype) (e: total_enum key repr) (r: repr) : Tot (maybe_total_enum_key e) = if list_mem r (list_map snd e) then TotalKnown (enum_key_of_repr e r) else TotalUnknown r let parse_maybe_total_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: total_enum key repr) : Tot (parser k (maybe_total_enum_key e)) = p `parse_synth` (maybe_total_enum_key_of_repr e) let repr_of_maybe_total_enum_key (#key #repr: eqtype) (e: total_enum key repr) (k: maybe_total_enum_key e) : Tot (r: repr { maybe_total_enum_key_of_repr e r == k } ) = match k with | TotalKnown k' -> enum_key_of_repr_of_key e k' ; enum_repr_of_key e k' | TotalUnknown r -> r let serialize_maybe_total_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (s: serializer p) (e: total_enum key repr) : Tot (serializer (parse_maybe_total_enum_key p e)) = serialize_synth p (maybe_total_enum_key_of_repr e) s (repr_of_maybe_total_enum_key e) () inline_for_extraction let maybe_enum_key_of_total (#key #repr: eqtype) (e: total_enum key repr) (k: maybe_total_enum_key e) : Tot (maybe_enum_key e) = match k with | TotalKnown ek -> Known (ek <: key) | TotalUnknown r -> Unknown r inline_for_extraction let total_of_maybe_enum_key (#key #repr: eqtype) (e: total_enum key repr) (k: maybe_enum_key e) : Tot (maybe_total_enum_key e) = match k with | Known ek -> TotalKnown (ek <: key) | Unknown r -> TotalUnknown r let maybe_total_enum_key_of_repr_eq (#key #repr: eqtype) (e: total_enum key repr) (r: repr) : Lemma (maybe_total_enum_key_of_repr e r == total_of_maybe_enum_key e (maybe_enum_key_of_repr e r)) = () let parse_maybe_total_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: total_enum key repr) (input: bytes) : Lemma (parse (parse_maybe_total_enum_key p e) input == (parse (parse_maybe_enum_key p e `parse_synth` total_of_maybe_enum_key e) input)) = parse_synth_eq p (maybe_total_enum_key_of_repr e) input; parse_synth_eq (parse_maybe_enum_key p e) (total_of_maybe_enum_key e) input; parse_synth_eq p (maybe_enum_key_of_repr e) input (* Destructors *) (* Universal destructor *) let r_reflexive_prop (t: Type) (r: (t -> t -> GTot Type0)) : GTot Type0 = forall (x: t) . {:pattern (r x x)} r x x inline_for_extraction let r_reflexive_t (t: Type) (r: (t -> t -> GTot Type0)) : Tot Type = (x: t) -> Lemma (r x x) let r_reflexive_t_elim (t: Type) (r: (t -> t -> GTot Type0)) (phi: r_reflexive_t t r) : Lemma (r_reflexive_prop t r) = Classical.forall_intro phi let r_transitive_prop (t: Type) (r: (t -> t -> GTot Type0)) : GTot Type0 = forall (x y z: t) . {:pattern (r x y); (r y z)} (r x y /\ r y z) ==> r x z inline_for_extraction let r_transitive_t (t: Type) (r: (t -> t -> GTot Type0)) : Tot Type = (x: t) -> (y: t) -> (z: t) -> Lemma ((r x y /\ r y z) ==> r x z) let r_transitive_t_elim (t: Type) (r: (t -> t -> GTot Type0)) (phi: r_transitive_t t r) : Lemma (r_transitive_prop t r) = Classical.forall_intro_3 phi inline_for_extraction let if_combinator (t: Type) (eq: (t -> t -> GTot Type0)) : Tot Type = (cond: bool) -> (sv_true: (cond_true cond -> Tot t)) -> (sv_false: (cond_false cond -> Tot t)) -> Tot (y: t { eq y (if cond then sv_true () else sv_false ()) } ) inline_for_extraction let default_if (t: Type) : Tot (if_combinator t (eq2 #t)) = fun (cond: bool) (s_true: (cond_true cond -> Tot t)) (s_false: (cond_false cond -> Tot t)) -> (if cond then s_true () else s_false ()) <: (y: t { y == (if cond then s_true () else s_false ()) } ) let feq (u v: Type) (eq: (v -> v -> GTot Type0)) (f1 f2: (u -> Tot v)) : GTot Type0 = (forall (x: u) . {:pattern (f1 x); (f2 x)} eq (f1 x) (f2 x)) (* #!$% patterns on forall, the following proofs should be trivial and now they aren't *) let feq_elim (u v: Type) (eq: (v -> v -> GTot Type0)) (f1 f2: (u -> Tot v)) (x: u) : Lemma (requires (feq u v eq f1 f2)) (ensures (f1 x `eq` f2 x)) = () let feq_intro (u v: Type) (eq: (v -> v -> GTot Type0)) (f1 f2: (u -> Tot v)) (phi: (x: u) -> Lemma (f1 x `eq` f2 x)) : Lemma (feq _ _ eq f1 f2) = Classical.forall_intro phi let feq_trans (u v: Type) (eq: (v -> v -> GTot Type0)) : Pure (r_transitive_t _ (feq _ _ eq)) (requires (r_transitive_prop _ eq)) (ensures (fun _ -> True)) = let phi (f1 f2 f3: (u -> Tot v)) : Lemma (requires (feq _ _ eq f1 f2 /\ feq _ _ eq f2 f3)) (ensures (feq _ _ eq f1 f3)) = feq_intro _ _ eq f1 f3 (fun x -> assert (f1 x `eq` f2 x /\ f2 x `eq` f3 x)) in let phi2 (f1 f2 f3: (u -> Tot v)) : Lemma ((feq _ _ eq f1 f2 /\ feq _ _ eq f2 f3) ==> feq _ _ eq f1 f3) = Classical.move_requires (phi f1 f2) f3 in phi2 inline_for_extraction let fif (u v: Type) (eq: (v -> v -> GTot Type0)) (ifc: if_combinator v eq) : Tot (if_combinator (u -> Tot v) (feq u v eq)) = fun (cond: bool) (s_true: (cond_true cond -> u -> Tot v)) (s_false: (cond_false cond -> u -> Tot v)) (x: u) -> ifc cond (fun h -> s_true () x) (fun h -> s_false () x) inline_for_extraction let enum_destr_t (t: Type) (#key #repr: eqtype) (e: enum key repr) : Tot Type = (eq: (t -> t -> GTot Type0)) -> (ift: if_combinator t eq) -> (eq_refl: r_reflexive_t _ eq) -> (eq_trans: r_transitive_t _ eq) -> (f: ((x: enum_key e) -> Tot t)) -> (x: enum_key e) -> Tot (y: t { eq y (f x) } ) inline_for_extraction let enum_tail' (#key #repr: eqtype) (e: enum key repr) : Pure (enum key repr) (requires True) (ensures (fun y -> Cons? e ==> (let (_ :: y') = e in y == y'))) = match e with _ :: y -> y | _ -> [] inline_for_extraction let enum_tail (#key #repr: eqtype) (e: enum key repr) : Tot (enum key repr) = enum_tail' e inline_for_extraction let enum_destr_cons (t: Type) (#key #repr: eqtype) (e: enum key repr) (g: enum_destr_t t (enum_tail' e)) : Pure (enum_destr_t t e) (requires (Cons? e)) (ensures (fun _ -> True)) = fun (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) -> [@inline_let] let _ = r_reflexive_t_elim _ _ eq_refl in [@inline_let] let _ = r_transitive_t_elim _ _ eq_trans in (fun (e' : list (key * repr) { e' == e } ) -> match e' with | (k, _) :: _ -> (fun (f: (enum_key e -> Tot t)) (x: enum_key e) -> (( [@inline_let] let f' : (enum_key (enum_tail' e) -> Tot t) = (fun (x' : enum_key (enum_tail' e)) -> [@inline_let] let (x_ : enum_key e) = (x' <: key) in f x_ ) in [@inline_let] let (y: t) = ift ((k <: key) = x) (fun h -> f k) (fun h -> [@inline_let] let x' : enum_key (enum_tail' e) = (x <: key) in (g eq ift eq_refl eq_trans f' x' <: t)) in y ) <: (y: t { eq y (f x) } ))) ) e inline_for_extraction let enum_destr_cons' (t: Type) (key repr: eqtype) (e: enum key repr) (u: unit { Cons? e } ) (g: enum_destr_t t (enum_tail e)) : Tot (enum_destr_t t e) = enum_destr_cons t e g inline_for_extraction let enum_destr_cons_nil (t: Type) (#key #repr: eqtype) (e: enum key repr) : Pure (enum_destr_t t e) (requires (Cons? e /\ Nil? (enum_tail' e))) (ensures (fun _ -> True)) = fun (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) -> [@inline_let] let _ = r_reflexive_t_elim _ _ eq_refl in (fun (e' : list (key * repr) { e' == e } ) -> match e' with | (k, _) :: _ -> (fun (f: (enum_key e -> Tot t)) (x: enum_key e) -> (( f k ) <: (y: t { eq y (f x) } ))) ) e inline_for_extraction let enum_destr_cons_nil' (t: Type) (key repr: eqtype) (e: enum key repr) (u1: unit { Cons? e } ) (u2: unit { Nil? (enum_tail e) } ) : Tot (enum_destr_t t e) = enum_destr_cons_nil t e (* Dependent destructor *) inline_for_extraction let dep_enum_destr (#key #repr: eqtype) (e: enum key repr) (v: (enum_key e -> Tot (Type u#a))) : Tot (Type) = (v_eq: ((k: enum_key e) -> v k -> v k -> GTot Type0)) -> (v_if: ((k: enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) -> (v_eq_refl: ((k: enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) -> (v_eq_trans: ((k: enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) -> (f: ((k: enum_key e) -> Tot (v k))) -> (k: enum_key e) -> Tot (y: v k { v_eq k y (f k) } ) module L = FStar.List.Tot inline_for_extraction let dep_enum_destr_cons (#key #repr: eqtype) (e: enum key repr) (u: squash (Cons? e)) (v: (enum_key e -> Tot Type)) (destr: dep_enum_destr (enum_tail e) (fun (k' : enum_key (enum_tail e)) -> v (k' <: key))) : Tot (dep_enum_destr e v) = match e with | ((k, _) :: _) -> fun (v_eq: ((k: enum_key e) -> v k -> v k -> GTot Type0)) (v_if: ((k: enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) (v_eq_refl: ((k: enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) (v_eq_trans: ((k: enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) (f: ((k: enum_key e) -> Tot (v k))) (k' : enum_key e) -> [@inline_let] let _ = r_reflexive_t_elim (v k') (v_eq k') (v_eq_refl k') in [@inline_let] let _ = r_transitive_t_elim (v k') (v_eq k') (v_eq_trans k') in [@inline_let] let y : v k' = v_if k' (k = k') (fun _ -> [@inline_let] let y : v k' = f k in y ) (fun _ -> [@inline_let] let v' (k: enum_key (enum_tail e)) : Tot Type = v (k <: key) in [@inline_let] let v'_eq (k: enum_key (enum_tail e)) : Tot (v' k -> v' k -> GTot Type0) = v_eq (k <: key) in [@inline_let] let v'_if (k: enum_key (enum_tail e)) : Tot (if_combinator (v' k) (v'_eq k)) = v_if (k <: key) in [@inline_let] let v'_eq_refl (k: enum_key (enum_tail e)) : Tot (r_reflexive_t _ (v'_eq k)) = v_eq_refl (k <: key) in [@inline_let] let v'_eq_trans (k: enum_key (enum_tail e)) : Tot (r_transitive_t _ (v'_eq k)) = v_eq_trans (k <: key) in [@inline_let] let f' (k: enum_key (enum_tail e)) : Tot (v' k) = f (k <: key) in [@inline_let] let k' : key = k' in [@inline_let] let _ = assert (k' <> k) in [@inline_let] let _ = assert (L.mem k' (L.map fst (enum_tail e))) in [@inline_let] let (y: v' k') = destr v'_eq v'_if v'_eq_refl v'_eq_trans f' k' in y ) in (y <: (y: v k' { v_eq k' y (f k') } )) inline_for_extraction let dep_enum_destr_cons_nil (#key #repr: eqtype) (e: enum key repr) (u: squash (Cons? e /\ Nil? (enum_tail e))) (v: (enum_key e -> Tot Type)) : Tot (dep_enum_destr e v) = match e with | ((k, _) :: _) -> fun (v_eq: ((k: enum_key e) -> v k -> v k -> GTot Type0)) (v_if: ((k: enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) (v_eq_refl: ((k: enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) (v_eq_trans: ((k: enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) (f: ((k: enum_key e) -> Tot (v k))) (k' : enum_key e) -> [@inline_let] let _ = r_reflexive_t_elim (v k') (v_eq k') (v_eq_refl k') in [@inline_let] let _ = r_transitive_t_elim (v k') (v_eq k') (v_eq_trans k') in [@inline_let] let y : v k' = f k in (y <: (y: v k' { v_eq k' y (f k') } )) (* Destructor from the representation *) let maybe_enum_key_of_repr_not_in (#key #repr: eqtype) (e: enum key repr) (l: list (key * repr)) (x: repr) : GTot Type0 = (~ (L.mem x (L.map snd l))) let list_rev_cons (#t: Type) (a: t) (q: list t) : Lemma (L.rev (a :: q) == L.rev q `L.append` [a]) = L.rev_rev' (a :: q); L.rev_rev' q let list_append_rev_cons (#t: Type) (l1: list t) (x: t) (l2: list t) : Lemma (L.append (L.rev l1) (x :: l2) == L.append (L.rev (x :: l1)) l2) = list_rev_cons x l1; L.append_assoc (L.rev l1) [x] l2 let rec assoc_append_flip_l_intro (#key #repr: eqtype) (l1 l2: list (key * repr)) (y: repr) (x: key) : Lemma (requires (L.noRepeats (L.map snd (L.append l1 l2)) /\ L.assoc y (L.map flip l2) == Some x)) (ensures (L.assoc y (L.map flip (l1 `L.append` l2)) == Some x)) = match l1 with | [] -> () | (_, r') :: q -> L.assoc_mem y (L.map flip l2); map_fst_flip l2; L.map_append snd l1 l2; L.noRepeats_append_elim (L.map snd l1) (L.map snd l2); assoc_append_flip_l_intro q l2 y x inline_for_extraction let maybe_enum_destr_t' (t: Type) (#key #repr: eqtype) (e: enum key repr) (l1 l2: list (key * repr)) (u1: squash (e == L.append (L.rev l1) l2)) : Tot Type = (eq: (t -> t -> GTot Type0)) -> (ift: if_combinator t eq) -> (eq_refl: r_reflexive_t _ eq) -> (eq_trans: r_transitive_t _ eq) -> (f: ((x: maybe_enum_key e) -> Tot t)) -> (x: repr { maybe_enum_key_of_repr_not_in e l1 x } ) -> Tot (y: t { eq y (f (maybe_enum_key_of_repr e x)) } ) inline_for_extraction let maybe_enum_destr_t (t: Type) (#key #repr: eqtype) (e: enum key repr) : Tot Type = (eq: (t -> t -> GTot Type0)) -> (ift: if_combinator t eq) -> (eq_refl: r_reflexive_t _ eq) -> (eq_trans: r_transitive_t _ eq) -> (f: ((x: maybe_enum_key e) -> Tot t)) -> (x: repr) -> Tot (y: t { eq y (f (maybe_enum_key_of_repr e x)) } ) inline_for_extraction let destr_maybe_total_enum_repr (#t: Type) (#key #repr: eqtype) (e: total_enum key repr) (destr: maybe_enum_destr_t t e) (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) (f: ((x: maybe_total_enum_key e) -> Tot t)) (x: repr) : Tot (y: t { eq y (f (maybe_total_enum_key_of_repr e x)) } ) = destr eq ift eq_refl eq_trans (fun y -> f (total_of_maybe_enum_key e y)) x inline_for_extraction let maybe_enum_destr_t_intro (t: Type) (#key #repr: eqtype) (e: enum key repr) (f: maybe_enum_destr_t' t e [] e ()) : Tot (maybe_enum_destr_t t e) = f let maybe_enum_key_of_repr_not_in_cons (#key #repr: eqtype) (e: enum key repr) (k: key) (r: repr) (l: list (key * repr)) (x: repr) : Lemma (requires (maybe_enum_key_of_repr_not_in e l x /\ x <> r)) (ensures (maybe_enum_key_of_repr_not_in e ((k, r) :: l) x)) = () [@Norm] inline_for_extraction let list_hd (#t: Type) (l: list t { Cons? l } ) = match l with | a :: _ -> a [@Norm] inline_for_extraction let list_tl (#t: Type) (l: list t { Cons? l } ) = match l with | _ :: q -> q inline_for_extraction let maybe_enum_destr_cons (t: Type) (#key #repr: eqtype) (e: enum key repr) (l1: list (key * repr)) (l2: list (key * repr)) (u1: squash (Cons? l2 /\ e == L.append (L.rev l1) l2)) (g: (maybe_enum_destr_t' t e (list_hd l2 :: l1) (list_tl l2) (list_append_rev_cons l1 (list_hd l2) (list_tl l2)))) : Tot (maybe_enum_destr_t' t e l1 l2 u1) = fun (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) (f: (maybe_enum_key e -> Tot t)) -> [@inline_let] let _ = r_reflexive_t_elim _ _ eq_refl in [@inline_let] let _ = r_transitive_t_elim _ _ eq_trans in match list_hd l2 with | (k, r) -> [@inline_let] let _ : squash (L.mem k (L.map fst e)) = L.append_mem (L.map fst (L.rev l1)) (L.map fst l2) k; L.map_append fst (L.rev l1) (l2); () in [@inline_let] let (_ : squash (maybe_enum_key_of_repr e r == Known k)) = L.append_mem (L.map snd (L.rev l1)) (L.map snd (l2)) r; L.map_append snd (L.rev l1) (l2); assoc_append_flip_l_intro (L.rev l1) (l2) r k; () in fun (x: repr { maybe_enum_key_of_repr_not_in e l1 x } ) -> (( ift (x = r) (fun h -> f (Known k)) (fun h -> g eq ift eq_refl eq_trans f x) ) <: (y: t { eq y (f (maybe_enum_key_of_repr e x)) } )) let rec list_rev_map (#t1 #t2: Type) (f: t1 -> Tot t2) (l: list t1) : Lemma (L.rev (L.map f l) == L.map f (L.rev l)) = match l with | [] -> () | a :: q -> list_rev_cons a q; list_rev_cons (f a) (L.map f q); list_rev_map f q; L.map_append f (L.rev q) [a] inline_for_extraction let maybe_enum_destr_nil (t: Type) (#key #repr: eqtype) (e: enum key repr) (l1: list (key * repr)) (l2: list (key * repr)) (u1: squash (Nil? l2 /\ e == L.append (L.rev l1) [])) : Tot (maybe_enum_destr_t' t e l1 l2 u1) = fun (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) (f: (maybe_enum_key e -> Tot t)) -> [@inline_let] let _ = r_reflexive_t_elim _ _ eq_refl in [@inline_let] let _ = r_transitive_t_elim _ _ eq_trans in fun (x: repr { maybe_enum_key_of_repr_not_in e l1 x } ) -> (( L.append_l_nil (L.rev l1); list_rev_map snd l1; L.rev_mem (L.map snd l1) x; f (Unknown x) ) <: (y: t { eq y (f (maybe_enum_key_of_repr e x)) } )) [@Norm] let rec mk_maybe_enum_destr' (t: Type) (#key #repr: eqtype) (e: enum key repr) (l1: list (key * repr)) (l2: list (key * repr)) (u: squash (e == L.rev l1 `L.append` l2)) : Tot (maybe_enum_destr_t' t e l1 l2 u) (decreases l2) = match l2 with | [] -> maybe_enum_destr_nil t e l1 l2 u | _ -> [@inline_let] let _ = list_append_rev_cons l1 (list_hd l2) (list_tl l2) in maybe_enum_destr_cons t e l1 l2 u (mk_maybe_enum_destr' t e (list_hd l2 :: l1) (list_tl l2) u) [@Norm] let mk_maybe_enum_destr (t: Type) (#key #repr: eqtype) (e: enum key repr) : Tot (maybe_enum_destr_t t e) = maybe_enum_destr_t_intro t e (mk_maybe_enum_destr' t e [] e ()) (* dependent representation-based destructor *) inline_for_extraction let dep_maybe_enum_destr_t (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) : Tot Type = (v_eq: ((k: maybe_enum_key e) -> v k -> v k -> GTot Type0)) -> (v_if: ((k: maybe_enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) -> (v_eq_refl: ((k: maybe_enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) -> (v_eq_trans: ((k: maybe_enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) -> (f: ((k: maybe_enum_key e) -> Tot (v k))) -> (r: repr) -> Tot (y: v (maybe_enum_key_of_repr e r) { v_eq (maybe_enum_key_of_repr e r) y (f (maybe_enum_key_of_repr e r)) } ) inline_for_extraction let dep_maybe_enum_destr_t' (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) (l1 l2: list (key * repr)) (u1: squash (e == L.append (L.rev l1) l2)) : Tot Type = (v_eq: ((k: maybe_enum_key e) -> v k -> v k -> GTot Type0)) -> (v_if: ((k: maybe_enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) -> (v_eq_refl: ((k: maybe_enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) -> (v_eq_trans: ((k: maybe_enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) -> (f: ((k: maybe_enum_key e) -> Tot (v k))) -> (r: repr { maybe_enum_key_of_repr_not_in e l1 r } ) -> Tot (y: v (maybe_enum_key_of_repr e r) { v_eq (maybe_enum_key_of_repr e r) y (f (maybe_enum_key_of_repr e r)) } ) inline_for_extraction let dep_maybe_enum_destr_t_intro (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) (d: dep_maybe_enum_destr_t' e v [] e ()) : Tot (dep_maybe_enum_destr_t e v) = d inline_for_extraction let dep_maybe_enum_destr_cons (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) (l1: list (key * repr)) (l2: list (key * repr)) (u1: squash (Cons? l2 /\ e == L.append (L.rev l1) l2)) (g: (dep_maybe_enum_destr_t' e v (list_hd l2 :: l1) (list_tl l2) (list_append_rev_cons l1 (list_hd l2) (list_tl l2)))) : Tot (dep_maybe_enum_destr_t' e v l1 l2 u1) = fun (v_eq: ((k: maybe_enum_key e) -> v k -> v k -> GTot Type0)) (v_if: ((k: maybe_enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) (v_eq_refl: ((k: maybe_enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) (v_eq_trans: ((k: maybe_enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) (f: ((k: maybe_enum_key e) -> Tot (v k))) -> match list_hd l2 with | (k, r) -> [@inline_let] let _ : squash (L.mem k (L.map fst e)) = L.append_mem (L.map fst (L.rev l1)) (L.map fst l2) k; L.map_append fst (L.rev l1) (l2); () in [@inline_let] let (_ : squash (maybe_enum_key_of_repr e r == Known k)) = L.append_mem (L.map snd (L.rev l1)) (L.map snd (l2)) r; L.map_append snd (L.rev l1) (l2); assoc_append_flip_l_intro (L.rev l1) (l2) r k; () in fun (x: repr { maybe_enum_key_of_repr_not_in e l1 x } ) -> //NS: y is linear in the continuation after erasure; inline it [@inline_let] let y : v (maybe_enum_key_of_repr e x) = v_if (maybe_enum_key_of_repr e x) // TODO: Since we cannot make this argument ghost, we need to make the user aware of the fact that this argument must not be extracted. (x = r) (fun h -> f (Known k)) (fun h -> g v_eq v_if v_eq_refl v_eq_trans f x) in [@inline_let] let _ : squash (v_eq (maybe_enum_key_of_repr e x) y (f (maybe_enum_key_of_repr e x))) = if x = r then () else v_eq_trans (maybe_enum_key_of_repr e x) y (g v_eq v_if v_eq_refl v_eq_trans f x) (f (maybe_enum_key_of_repr e x)) in (y <: (y: v (maybe_enum_key_of_repr e x) { v_eq (maybe_enum_key_of_repr e x) y (f (maybe_enum_key_of_repr e x)) } )) inline_for_extraction let dep_maybe_enum_destr_nil (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) (l1: list (key * repr)) (l2: list (key * repr)) (u1: squash (Nil? l2 /\ e == L.append (L.rev l1) [])) : Tot (dep_maybe_enum_destr_t' e v l1 l2 u1) = fun (v_eq: ((k: maybe_enum_key e) -> v k -> v k -> GTot Type0)) (v_if: ((k: maybe_enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) (v_eq_refl: ((k: maybe_enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) (v_eq_trans: ((k: maybe_enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) (f: ((k: maybe_enum_key e) -> Tot (v k))) (x: repr { maybe_enum_key_of_repr_not_in e l1 x } ) -> (( L.append_l_nil (L.rev l1); list_rev_map snd l1; L.rev_mem (L.map snd l1) x; assert (Unknown x == maybe_enum_key_of_repr e x); //NS: y is linear in the continuation after erasure [@inline_let] let y : v (maybe_enum_key_of_repr e x) = f (Unknown x) in [@inline_let] let _ = v_eq_refl (maybe_enum_key_of_repr e x) (f (maybe_enum_key_of_repr e x)) in y ) <: (y: v (maybe_enum_key_of_repr e x) { v_eq (maybe_enum_key_of_repr e x) y (f (maybe_enum_key_of_repr e x)) } )) [@Norm] let rec mk_dep_maybe_enum_destr' (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) (l1: list (key * repr)) (l2: list (key * repr)) (u1: squash (e == L.append (L.rev l1) l2)) : Tot (dep_maybe_enum_destr_t' e v l1 l2 u1) (decreases l2) = match l2 with | [] -> dep_maybe_enum_destr_nil e v l1 l2 u1 | _ -> dep_maybe_enum_destr_cons e v l1 l2 u1 (mk_dep_maybe_enum_destr' e v (list_hd l2 :: l1) (list_tl l2) (list_append_rev_cons l1 (list_hd l2) (list_tl l2))) [@Norm] let mk_dep_maybe_enum_destr (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) = dep_maybe_enum_destr_t_intro e v (mk_dep_maybe_enum_destr' e v [] e ()) (* Eliminators and destructors for verification purposes *) let rec list_forallp (#t: Type) (p: t -> GTot Type0) (l: list t) : GTot Type0 = match l with | [] -> True | a :: q -> p a /\ list_forallp p q let rec list_forallp_mem (#t: eqtype) (p: t -> GTot Type0) (l: list t) : Lemma (list_forallp p l <==> (forall x . L.mem x l ==> p x)) = match l with | [] -> () | _ :: q -> list_forallp_mem p q inline_for_extraction let destruct_maybe_enum_key (#key #value: eqtype) (e: enum key value) (f: maybe_enum_key e -> Tot Type) (f_known: ( (x: key) -> (u: squash (list_mem x (list_map fst e))) -> Tot (f (Known x)) )) (f_unknown: ( (x: value) -> (u: squash (list_mem x (list_map snd e) == false)) -> Tot (f (Unknown x)) )) (x: maybe_enum_key e) : Tot (f x) = match x with | Known x' -> f_known x' () | Unknown x' -> f_unknown x' () let forall_maybe_enum_key (#key #value: eqtype) (e: enum key value) (f: maybe_enum_key e -> GTot Type0) (f_known: squash (list_forallp (fun (x: key) -> list_mem x (list_map fst e) /\ f (Known x)) (list_map fst e))) (f_unknown: ( (x: value) -> Tot (squash (list_mem x (list_map snd e) == false ==> f (Unknown x))) )) : Tot (squash (forall (x: maybe_enum_key e) . f x)) = let g (x: maybe_enum_key e) : Lemma (f x) = let u : squash (f x) = destruct_maybe_enum_key e (fun y -> squash (f y)) (fun x' u -> list_forallp_mem (fun (x: key) -> list_mem x (list_map fst e) /\ f (Known x)) (list_map fst e)) (fun x' u -> f_unknown x') x in assert (f x) in Classical.forall_intro g (* Converting enum keys to their representation, using combinators *) let enum_repr_of_key'_t (#key #repr: eqtype) (e: enum key repr) : Tot Type = (x: enum_key e) -> Tot (r: enum_repr e { r == enum_repr_of_key e x } ) inline_for_extraction let enum_repr_of_key_cons (#key #repr: eqtype) (e: enum key repr) (f : enum_repr_of_key'_t (enum_tail' e)) : Pure (enum_repr_of_key'_t e) (requires (Cons? e)) (ensures (fun _ -> True)) = (fun (e' : list (key * repr) { e' == e } ) -> match e' with | (k, r) :: _ -> (fun (x: enum_key e) -> ( if k = x then (r <: repr) else (f (x <: key) <: repr) ) <: (r: enum_repr e { enum_repr_of_key e x == r } ))) e inline_for_extraction let enum_repr_of_key_cons' (key repr: eqtype) (e: enum key repr) (u: unit { Cons? e } ) (f : enum_repr_of_key'_t (enum_tail' e)) : Tot (enum_repr_of_key'_t e) = enum_repr_of_key_cons e f inline_for_extraction let enum_repr_of_key_cons_nil (#key #repr: eqtype) (e: enum key repr) : Pure (enum_repr_of_key'_t e) (requires (Cons? e /\ Nil? (enum_tail' e))) (ensures (fun _ -> True)) = (fun (e' : list (key * repr) { e' == e } ) -> match e' with | [(k, r)] -> (fun (x: enum_key e) -> (r <: (r: enum_repr e { enum_repr_of_key e x == r } )))) e inline_for_extraction let enum_repr_of_key_cons_nil' (key repr: eqtype) (e: enum key repr) (u1: unit { Cons? e } ) (u2: unit { Nil? (enum_tail' e) } ) : Tot (enum_repr_of_key'_t e) = enum_repr_of_key_cons_nil e
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.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": "LowParse.Spec.Enum.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
e: LowParse.Spec.Enum.enum key repr -> l1: Prims.list (key * repr) -> kr: (key * repr) -> l2: Prims.list (key * repr) -> FStar.Pervasives.Lemma (requires e == l1 @ kr :: l2) (ensures LowParse.Spec.Enum.list_mem (FStar.Pervasives.Native.fst kr) (LowParse.Spec.Enum.list_map FStar.Pervasives.Native.fst e) /\ LowParse.Spec.Enum.enum_repr_of_key e (FStar.Pervasives.Native.fst kr) == FStar.Pervasives.Native.snd kr /\ LowParse.Spec.Enum.list_mem (FStar.Pervasives.Native.snd kr) (LowParse.Spec.Enum.list_map FStar.Pervasives.Native.snd e) /\ LowParse.Spec.Enum.enum_key_of_repr e (FStar.Pervasives.Native.snd kr) == FStar.Pervasives.Native.fst kr)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.eqtype", "LowParse.Spec.Enum.enum", "Prims.list", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Enum.enum_key_of_repr_of_key", "FStar.Pervasives.Native.fst", "Prims.unit", "FStar.List.Tot.Properties.assoc_append_elim_l", "Prims.Cons", "FStar.List.Tot.Properties.assoc_mem", "FStar.List.Tot.Properties.noRepeats_append_elim", "FStar.List.Tot.Base.map", "FStar.List.Tot.Properties.map_append", "Prims.eq2", "FStar.List.Tot.Base.append", "Prims.squash", "Prims.l_and", "Prims.b2t", "LowParse.Spec.Enum.list_mem", "LowParse.Spec.Enum.list_map", "LowParse.Spec.Enum.enum_repr_of_key", "FStar.Pervasives.Native.snd", "LowParse.Spec.Enum.enum_key_of_repr", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let enum_repr_of_key_append_cons (#key #repr: eqtype) (e: enum key repr) (l1: list (key & repr)) (kr: (key & repr)) (l2: list (key & repr)) : Lemma (requires (e == l1 `L.append` (kr :: l2))) (ensures (list_mem (fst kr) (list_map fst e) /\ enum_repr_of_key e (fst kr) == snd kr /\ list_mem (snd kr) (list_map snd e) /\ enum_key_of_repr e (snd kr) == fst kr)) =
L.map_append fst l1 (kr :: l2); L.noRepeats_append_elim (L.map fst l1) (L.map fst (kr :: l2)); L.assoc_mem (fst kr) l1; L.assoc_mem (fst kr) e; L.assoc_append_elim_l (fst kr) l1 (kr :: l2); enum_key_of_repr_of_key e (fst kr)
false
LowParse.Spec.Enum.fst
LowParse.Spec.Enum.enum_repr_of_key_cons_nil
val enum_repr_of_key_cons_nil (#key #repr: eqtype) (e: enum key repr) : Pure (enum_repr_of_key'_t e) (requires (Cons? e /\ Nil? (enum_tail' e))) (ensures (fun _ -> True))
val enum_repr_of_key_cons_nil (#key #repr: eqtype) (e: enum key repr) : Pure (enum_repr_of_key'_t e) (requires (Cons? e /\ Nil? (enum_tail' e))) (ensures (fun _ -> True))
let enum_repr_of_key_cons_nil (#key #repr: eqtype) (e: enum key repr) : Pure (enum_repr_of_key'_t e) (requires (Cons? e /\ Nil? (enum_tail' e))) (ensures (fun _ -> True)) = (fun (e' : list (key * repr) { e' == e } ) -> match e' with | [(k, r)] -> (fun (x: enum_key e) -> (r <: (r: enum_repr e { enum_repr_of_key e x == r } )))) e
{ "file_name": "src/lowparse/LowParse.Spec.Enum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 6, "end_line": 1252, "start_col": 0, "start_line": 1242 }
module LowParse.Spec.Enum include LowParse.Spec.Combinators module L = FStar.List.Tot [@Norm] let rec list_map (#a #b: Type) (f: (a -> Tot b)) (l: list a) : Tot (l' : list b { l' == L.map f l } ) = match l with | [] -> [] | a :: q -> f a :: list_map f q type enum (key: eqtype) (repr: eqtype) = (l: list (key * repr) { L.noRepeats (list_map fst l) /\ L.noRepeats (list_map snd l) }) [@Norm] let rec list_mem (#t: eqtype) (x: t) (l: list t) : Tot (y: bool { y == true <==> L.mem x l == true } ) = match l with | [] -> false | a :: q -> (x = a || list_mem x q) inline_for_extraction let enum_key (#key #repr: eqtype) (e: enum key repr) : Tot eqtype = (s: key { list_mem s (list_map fst e) } ) inline_for_extraction let make_enum_key (#key #repr: eqtype) (e: enum key repr) (k: key) : Pure (enum_key e) (requires (list_mem k (list_map fst e))) (ensures (fun k' -> k == (k' <: key))) = k inline_for_extraction let enum_repr (#key #repr: eqtype) (e: enum key repr) : Tot eqtype = (r: repr { list_mem r (list_map snd e) } ) let flip (#a #b: Type) (c: (a * b)) : Tot (b * a) = let (ca, cb) = c in (cb, ca) let rec map_flip_flip (#a #b: Type) (l: list (a * b)) : Lemma (list_map flip (list_map flip l) == l) = match l with | [] -> () | _ :: q -> map_flip_flip q let rec map_fst_flip (#a #b: Type) (l: list (a * b)) : Lemma (list_map fst (list_map flip l) == list_map snd l) = match l with | [] -> () | _ :: q -> map_fst_flip q let rec map_snd_flip (#a #b: Type) (l: list (a * b)) : Lemma (list_map snd (list_map flip l) == list_map fst l) = match l with | [] -> () | _ :: q -> map_snd_flip q let rec assoc_mem_snd (#a #b: eqtype) (l: list (a * b)) (x: a) (y: b) : Lemma (requires (L.assoc x l == Some y)) (ensures (list_mem y (list_map snd l) == true)) (decreases l) = let ((x', y') :: l') = l in if x' = x then () else assoc_mem_snd l' x y let rec assoc_flip_elim (#a #b: eqtype) (l: list (a * b)) (y: b) (x: a) : Lemma (requires ( L.noRepeats (list_map fst l) /\ L.noRepeats (list_map snd l) /\ L.assoc y (list_map flip l) == Some x )) (ensures ( L.assoc x l == Some y )) (decreases l) = let ((x', y') :: l') = l in if y' = y then () else begin if x' = x then begin assert (list_mem x' (list_map fst l') == false); assoc_mem_snd (list_map flip l') y x; map_snd_flip l'; assert False end else assoc_flip_elim l' y x end let rec assoc_flip_intro (#a #b: eqtype) (l: list (a * b)) (y: b) (x: a) : Lemma (requires ( L.noRepeats (list_map fst l) /\ L.noRepeats (list_map snd l) /\ L.assoc x l == Some y )) (ensures ( L.assoc y (list_map flip l) == Some x )) = map_fst_flip l; map_snd_flip l; map_flip_flip l; assoc_flip_elim (list_map flip l) x y let enum_key_of_repr (#key #repr: eqtype) (e: enum key repr) (r: enum_repr e) : Pure (enum_key e) (requires True) (ensures (fun y -> L.assoc y e == Some r)) = map_fst_flip e; let e' = list_map #(key * repr) #(repr * key) flip e in L.assoc_mem r e'; let k = Some?.v (L.assoc r e') in assoc_flip_elim e r k; L.assoc_mem k e; (k <: enum_key e) let parse_enum_key_cond (#key #repr: eqtype) (e: enum key repr) (r: repr) : GTot bool = list_mem r (list_map snd e) let parse_enum_key_synth (#key #repr: eqtype) (e: enum key repr) (r: repr { parse_enum_key_cond e r == true } ) : GTot (enum_key e) = enum_key_of_repr e r let parse_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) : Tot (parser (parse_filter_kind k) (enum_key e)) = (p `parse_filter` parse_enum_key_cond e ) `parse_synth` parse_enum_key_synth e let enum_repr_of_key (#key #repr: eqtype) (e: enum key repr) (k: enum_key e) : Pure (enum_repr e) (requires True) (ensures (fun r -> L.assoc k e == Some r)) = L.assoc_mem k e; let r = Some?.v (L.assoc k e) in assoc_flip_intro e r k; L.assoc_mem r (list_map flip e); map_fst_flip e; (r <: enum_repr e) let enum_repr_of_key_of_repr (#key #repr: eqtype) (e: enum key repr) (r: enum_repr e) : Lemma (enum_repr_of_key e (enum_key_of_repr e r) == r) = () let enum_key_of_repr_of_key (#key #repr: eqtype) (e: enum key repr) (k: enum_key e) : Lemma (enum_key_of_repr e (enum_repr_of_key e k) == k) = assoc_flip_intro e (enum_repr_of_key e k) k let serialize_enum_key_synth_recip (#key #repr: eqtype) (e: enum key repr) (k: enum_key e) : GTot (r: repr { parse_enum_key_cond e r == true } ) = enum_repr_of_key e k let serialize_enum_key_synth_inverse (#key #repr: eqtype) (e: enum key repr) : Lemma (synth_inverse (parse_enum_key_synth e) (serialize_enum_key_synth_recip e)) = Classical.forall_intro (enum_key_of_repr_of_key e) let serialize_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (s: serializer p) (e: enum key repr) : Tot (serializer (parse_enum_key p e)) = serialize_enum_key_synth_inverse e; serialize_synth (parse_filter p (parse_enum_key_cond e)) (parse_enum_key_synth e) (serialize_filter s (parse_enum_key_cond e)) (serialize_enum_key_synth_recip e) () let serialize_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (s: serializer p) (e: enum key repr) (x: enum_key e) : Lemma (serialize (serialize_enum_key p s e) x == serialize s (enum_repr_of_key e x)) = serialize_enum_key_synth_inverse e; serialize_synth_eq (parse_filter p (parse_enum_key_cond e)) (parse_enum_key_synth e) (serialize_filter s (parse_enum_key_cond e)) (serialize_enum_key_synth_recip e) () x inline_for_extraction let unknown_enum_repr (#key #repr: eqtype) (e: enum key repr) : Tot Type = (r: repr { list_mem r (list_map snd e) == false } ) type maybe_enum_key (#key #repr: eqtype) (e: enum key repr) = | Known of (enum_key e) | Unknown of (unknown_enum_repr e) let maybe_enum_key_of_repr (#key #repr: eqtype) (e: enum key repr) (r: repr) : Tot (maybe_enum_key e) = if list_mem r (list_map snd e) then Known (enum_key_of_repr e r) else Unknown r let parse_maybe_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) : Tot (parser k (maybe_enum_key e)) = p `parse_synth` (maybe_enum_key_of_repr e) let parse_maybe_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) (input: bytes) : Lemma (parse (parse_maybe_enum_key p e) input == (match parse p input with | Some (x, consumed) -> Some (maybe_enum_key_of_repr e x, consumed) | _ -> None )) = parse_synth_eq p (maybe_enum_key_of_repr e) input let parse_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) (input: bytes) : Lemma (parse (parse_enum_key p e) input == (match parse p input with | Some (x, consumed) -> begin match maybe_enum_key_of_repr e x with | Known k -> Some (k, consumed) | _ -> None end | _ -> None )) = parse_filter_eq p (parse_enum_key_cond e) input; parse_synth_eq (p `parse_filter` parse_enum_key_cond e) (parse_enum_key_synth e) input let repr_of_maybe_enum_key (#key #repr: eqtype) (e: enum key repr) (x: maybe_enum_key e) : Tot (r: repr { maybe_enum_key_of_repr e r == x } ) = match x with | Known k' -> enum_key_of_repr_of_key e k' ; enum_repr_of_key e k' | Unknown r -> r let serialize_maybe_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (s: serializer p) (e: enum key repr) : Tot (serializer (parse_maybe_enum_key p e)) = serialize_synth p (maybe_enum_key_of_repr e) s (repr_of_maybe_enum_key e) () let serialize_maybe_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (s: serializer p) (e: enum key repr) (x: maybe_enum_key e) : Lemma (serialize (serialize_maybe_enum_key p s e) x == serialize s (repr_of_maybe_enum_key e x)) = serialize_synth_eq p (maybe_enum_key_of_repr e) s (repr_of_maybe_enum_key e) () x let is_total_enum (#key: eqtype) (#repr: eqtype) (l: list (key * repr)) : GTot Type0 = forall (k: key) . {:pattern (list_mem k (list_map fst l))} list_mem k (list_map fst l) let total_enum (key: eqtype) (repr: eqtype) : Tot eqtype = (l: enum key repr { is_total_enum l } ) let synth_total_enum_key (#key: eqtype) (#repr: eqtype) (l: total_enum key repr) (k: enum_key l) : Tot key = let k' : key = k in k' let parse_total_enum_key (#k: parser_kind) (#key: eqtype) (#repr: eqtype) (p: parser k repr) (l: total_enum key repr) : Tot (parser (parse_filter_kind k) key) = parse_enum_key p l `parse_synth` (synth_total_enum_key l) let synth_total_enum_key_recip (#key: eqtype) (#repr: eqtype) (l: total_enum key repr) (k: key) : Tot (k' : enum_key l { synth_total_enum_key l k' == k } ) = k let serialize_total_enum_key (#k: parser_kind) (#key: eqtype) (#repr: eqtype) (p: parser k repr) (s: serializer p) (l: total_enum key repr) : Tot (serializer (parse_total_enum_key p l)) = serialize_synth (parse_enum_key p l) (synth_total_enum_key l) (serialize_enum_key p s l) (synth_total_enum_key_recip l) () type maybe_total_enum_key (#key #repr: eqtype) (e: total_enum key repr) = | TotalKnown of key | TotalUnknown of (unknown_enum_repr e) let maybe_total_enum_key_of_repr (#key #repr: eqtype) (e: total_enum key repr) (r: repr) : Tot (maybe_total_enum_key e) = if list_mem r (list_map snd e) then TotalKnown (enum_key_of_repr e r) else TotalUnknown r let parse_maybe_total_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: total_enum key repr) : Tot (parser k (maybe_total_enum_key e)) = p `parse_synth` (maybe_total_enum_key_of_repr e) let repr_of_maybe_total_enum_key (#key #repr: eqtype) (e: total_enum key repr) (k: maybe_total_enum_key e) : Tot (r: repr { maybe_total_enum_key_of_repr e r == k } ) = match k with | TotalKnown k' -> enum_key_of_repr_of_key e k' ; enum_repr_of_key e k' | TotalUnknown r -> r let serialize_maybe_total_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (s: serializer p) (e: total_enum key repr) : Tot (serializer (parse_maybe_total_enum_key p e)) = serialize_synth p (maybe_total_enum_key_of_repr e) s (repr_of_maybe_total_enum_key e) () inline_for_extraction let maybe_enum_key_of_total (#key #repr: eqtype) (e: total_enum key repr) (k: maybe_total_enum_key e) : Tot (maybe_enum_key e) = match k with | TotalKnown ek -> Known (ek <: key) | TotalUnknown r -> Unknown r inline_for_extraction let total_of_maybe_enum_key (#key #repr: eqtype) (e: total_enum key repr) (k: maybe_enum_key e) : Tot (maybe_total_enum_key e) = match k with | Known ek -> TotalKnown (ek <: key) | Unknown r -> TotalUnknown r let maybe_total_enum_key_of_repr_eq (#key #repr: eqtype) (e: total_enum key repr) (r: repr) : Lemma (maybe_total_enum_key_of_repr e r == total_of_maybe_enum_key e (maybe_enum_key_of_repr e r)) = () let parse_maybe_total_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: total_enum key repr) (input: bytes) : Lemma (parse (parse_maybe_total_enum_key p e) input == (parse (parse_maybe_enum_key p e `parse_synth` total_of_maybe_enum_key e) input)) = parse_synth_eq p (maybe_total_enum_key_of_repr e) input; parse_synth_eq (parse_maybe_enum_key p e) (total_of_maybe_enum_key e) input; parse_synth_eq p (maybe_enum_key_of_repr e) input (* Destructors *) (* Universal destructor *) let r_reflexive_prop (t: Type) (r: (t -> t -> GTot Type0)) : GTot Type0 = forall (x: t) . {:pattern (r x x)} r x x inline_for_extraction let r_reflexive_t (t: Type) (r: (t -> t -> GTot Type0)) : Tot Type = (x: t) -> Lemma (r x x) let r_reflexive_t_elim (t: Type) (r: (t -> t -> GTot Type0)) (phi: r_reflexive_t t r) : Lemma (r_reflexive_prop t r) = Classical.forall_intro phi let r_transitive_prop (t: Type) (r: (t -> t -> GTot Type0)) : GTot Type0 = forall (x y z: t) . {:pattern (r x y); (r y z)} (r x y /\ r y z) ==> r x z inline_for_extraction let r_transitive_t (t: Type) (r: (t -> t -> GTot Type0)) : Tot Type = (x: t) -> (y: t) -> (z: t) -> Lemma ((r x y /\ r y z) ==> r x z) let r_transitive_t_elim (t: Type) (r: (t -> t -> GTot Type0)) (phi: r_transitive_t t r) : Lemma (r_transitive_prop t r) = Classical.forall_intro_3 phi inline_for_extraction let if_combinator (t: Type) (eq: (t -> t -> GTot Type0)) : Tot Type = (cond: bool) -> (sv_true: (cond_true cond -> Tot t)) -> (sv_false: (cond_false cond -> Tot t)) -> Tot (y: t { eq y (if cond then sv_true () else sv_false ()) } ) inline_for_extraction let default_if (t: Type) : Tot (if_combinator t (eq2 #t)) = fun (cond: bool) (s_true: (cond_true cond -> Tot t)) (s_false: (cond_false cond -> Tot t)) -> (if cond then s_true () else s_false ()) <: (y: t { y == (if cond then s_true () else s_false ()) } ) let feq (u v: Type) (eq: (v -> v -> GTot Type0)) (f1 f2: (u -> Tot v)) : GTot Type0 = (forall (x: u) . {:pattern (f1 x); (f2 x)} eq (f1 x) (f2 x)) (* #!$% patterns on forall, the following proofs should be trivial and now they aren't *) let feq_elim (u v: Type) (eq: (v -> v -> GTot Type0)) (f1 f2: (u -> Tot v)) (x: u) : Lemma (requires (feq u v eq f1 f2)) (ensures (f1 x `eq` f2 x)) = () let feq_intro (u v: Type) (eq: (v -> v -> GTot Type0)) (f1 f2: (u -> Tot v)) (phi: (x: u) -> Lemma (f1 x `eq` f2 x)) : Lemma (feq _ _ eq f1 f2) = Classical.forall_intro phi let feq_trans (u v: Type) (eq: (v -> v -> GTot Type0)) : Pure (r_transitive_t _ (feq _ _ eq)) (requires (r_transitive_prop _ eq)) (ensures (fun _ -> True)) = let phi (f1 f2 f3: (u -> Tot v)) : Lemma (requires (feq _ _ eq f1 f2 /\ feq _ _ eq f2 f3)) (ensures (feq _ _ eq f1 f3)) = feq_intro _ _ eq f1 f3 (fun x -> assert (f1 x `eq` f2 x /\ f2 x `eq` f3 x)) in let phi2 (f1 f2 f3: (u -> Tot v)) : Lemma ((feq _ _ eq f1 f2 /\ feq _ _ eq f2 f3) ==> feq _ _ eq f1 f3) = Classical.move_requires (phi f1 f2) f3 in phi2 inline_for_extraction let fif (u v: Type) (eq: (v -> v -> GTot Type0)) (ifc: if_combinator v eq) : Tot (if_combinator (u -> Tot v) (feq u v eq)) = fun (cond: bool) (s_true: (cond_true cond -> u -> Tot v)) (s_false: (cond_false cond -> u -> Tot v)) (x: u) -> ifc cond (fun h -> s_true () x) (fun h -> s_false () x) inline_for_extraction let enum_destr_t (t: Type) (#key #repr: eqtype) (e: enum key repr) : Tot Type = (eq: (t -> t -> GTot Type0)) -> (ift: if_combinator t eq) -> (eq_refl: r_reflexive_t _ eq) -> (eq_trans: r_transitive_t _ eq) -> (f: ((x: enum_key e) -> Tot t)) -> (x: enum_key e) -> Tot (y: t { eq y (f x) } ) inline_for_extraction let enum_tail' (#key #repr: eqtype) (e: enum key repr) : Pure (enum key repr) (requires True) (ensures (fun y -> Cons? e ==> (let (_ :: y') = e in y == y'))) = match e with _ :: y -> y | _ -> [] inline_for_extraction let enum_tail (#key #repr: eqtype) (e: enum key repr) : Tot (enum key repr) = enum_tail' e inline_for_extraction let enum_destr_cons (t: Type) (#key #repr: eqtype) (e: enum key repr) (g: enum_destr_t t (enum_tail' e)) : Pure (enum_destr_t t e) (requires (Cons? e)) (ensures (fun _ -> True)) = fun (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) -> [@inline_let] let _ = r_reflexive_t_elim _ _ eq_refl in [@inline_let] let _ = r_transitive_t_elim _ _ eq_trans in (fun (e' : list (key * repr) { e' == e } ) -> match e' with | (k, _) :: _ -> (fun (f: (enum_key e -> Tot t)) (x: enum_key e) -> (( [@inline_let] let f' : (enum_key (enum_tail' e) -> Tot t) = (fun (x' : enum_key (enum_tail' e)) -> [@inline_let] let (x_ : enum_key e) = (x' <: key) in f x_ ) in [@inline_let] let (y: t) = ift ((k <: key) = x) (fun h -> f k) (fun h -> [@inline_let] let x' : enum_key (enum_tail' e) = (x <: key) in (g eq ift eq_refl eq_trans f' x' <: t)) in y ) <: (y: t { eq y (f x) } ))) ) e inline_for_extraction let enum_destr_cons' (t: Type) (key repr: eqtype) (e: enum key repr) (u: unit { Cons? e } ) (g: enum_destr_t t (enum_tail e)) : Tot (enum_destr_t t e) = enum_destr_cons t e g inline_for_extraction let enum_destr_cons_nil (t: Type) (#key #repr: eqtype) (e: enum key repr) : Pure (enum_destr_t t e) (requires (Cons? e /\ Nil? (enum_tail' e))) (ensures (fun _ -> True)) = fun (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) -> [@inline_let] let _ = r_reflexive_t_elim _ _ eq_refl in (fun (e' : list (key * repr) { e' == e } ) -> match e' with | (k, _) :: _ -> (fun (f: (enum_key e -> Tot t)) (x: enum_key e) -> (( f k ) <: (y: t { eq y (f x) } ))) ) e inline_for_extraction let enum_destr_cons_nil' (t: Type) (key repr: eqtype) (e: enum key repr) (u1: unit { Cons? e } ) (u2: unit { Nil? (enum_tail e) } ) : Tot (enum_destr_t t e) = enum_destr_cons_nil t e (* Dependent destructor *) inline_for_extraction let dep_enum_destr (#key #repr: eqtype) (e: enum key repr) (v: (enum_key e -> Tot (Type u#a))) : Tot (Type) = (v_eq: ((k: enum_key e) -> v k -> v k -> GTot Type0)) -> (v_if: ((k: enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) -> (v_eq_refl: ((k: enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) -> (v_eq_trans: ((k: enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) -> (f: ((k: enum_key e) -> Tot (v k))) -> (k: enum_key e) -> Tot (y: v k { v_eq k y (f k) } ) module L = FStar.List.Tot inline_for_extraction let dep_enum_destr_cons (#key #repr: eqtype) (e: enum key repr) (u: squash (Cons? e)) (v: (enum_key e -> Tot Type)) (destr: dep_enum_destr (enum_tail e) (fun (k' : enum_key (enum_tail e)) -> v (k' <: key))) : Tot (dep_enum_destr e v) = match e with | ((k, _) :: _) -> fun (v_eq: ((k: enum_key e) -> v k -> v k -> GTot Type0)) (v_if: ((k: enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) (v_eq_refl: ((k: enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) (v_eq_trans: ((k: enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) (f: ((k: enum_key e) -> Tot (v k))) (k' : enum_key e) -> [@inline_let] let _ = r_reflexive_t_elim (v k') (v_eq k') (v_eq_refl k') in [@inline_let] let _ = r_transitive_t_elim (v k') (v_eq k') (v_eq_trans k') in [@inline_let] let y : v k' = v_if k' (k = k') (fun _ -> [@inline_let] let y : v k' = f k in y ) (fun _ -> [@inline_let] let v' (k: enum_key (enum_tail e)) : Tot Type = v (k <: key) in [@inline_let] let v'_eq (k: enum_key (enum_tail e)) : Tot (v' k -> v' k -> GTot Type0) = v_eq (k <: key) in [@inline_let] let v'_if (k: enum_key (enum_tail e)) : Tot (if_combinator (v' k) (v'_eq k)) = v_if (k <: key) in [@inline_let] let v'_eq_refl (k: enum_key (enum_tail e)) : Tot (r_reflexive_t _ (v'_eq k)) = v_eq_refl (k <: key) in [@inline_let] let v'_eq_trans (k: enum_key (enum_tail e)) : Tot (r_transitive_t _ (v'_eq k)) = v_eq_trans (k <: key) in [@inline_let] let f' (k: enum_key (enum_tail e)) : Tot (v' k) = f (k <: key) in [@inline_let] let k' : key = k' in [@inline_let] let _ = assert (k' <> k) in [@inline_let] let _ = assert (L.mem k' (L.map fst (enum_tail e))) in [@inline_let] let (y: v' k') = destr v'_eq v'_if v'_eq_refl v'_eq_trans f' k' in y ) in (y <: (y: v k' { v_eq k' y (f k') } )) inline_for_extraction let dep_enum_destr_cons_nil (#key #repr: eqtype) (e: enum key repr) (u: squash (Cons? e /\ Nil? (enum_tail e))) (v: (enum_key e -> Tot Type)) : Tot (dep_enum_destr e v) = match e with | ((k, _) :: _) -> fun (v_eq: ((k: enum_key e) -> v k -> v k -> GTot Type0)) (v_if: ((k: enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) (v_eq_refl: ((k: enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) (v_eq_trans: ((k: enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) (f: ((k: enum_key e) -> Tot (v k))) (k' : enum_key e) -> [@inline_let] let _ = r_reflexive_t_elim (v k') (v_eq k') (v_eq_refl k') in [@inline_let] let _ = r_transitive_t_elim (v k') (v_eq k') (v_eq_trans k') in [@inline_let] let y : v k' = f k in (y <: (y: v k' { v_eq k' y (f k') } )) (* Destructor from the representation *) let maybe_enum_key_of_repr_not_in (#key #repr: eqtype) (e: enum key repr) (l: list (key * repr)) (x: repr) : GTot Type0 = (~ (L.mem x (L.map snd l))) let list_rev_cons (#t: Type) (a: t) (q: list t) : Lemma (L.rev (a :: q) == L.rev q `L.append` [a]) = L.rev_rev' (a :: q); L.rev_rev' q let list_append_rev_cons (#t: Type) (l1: list t) (x: t) (l2: list t) : Lemma (L.append (L.rev l1) (x :: l2) == L.append (L.rev (x :: l1)) l2) = list_rev_cons x l1; L.append_assoc (L.rev l1) [x] l2 let rec assoc_append_flip_l_intro (#key #repr: eqtype) (l1 l2: list (key * repr)) (y: repr) (x: key) : Lemma (requires (L.noRepeats (L.map snd (L.append l1 l2)) /\ L.assoc y (L.map flip l2) == Some x)) (ensures (L.assoc y (L.map flip (l1 `L.append` l2)) == Some x)) = match l1 with | [] -> () | (_, r') :: q -> L.assoc_mem y (L.map flip l2); map_fst_flip l2; L.map_append snd l1 l2; L.noRepeats_append_elim (L.map snd l1) (L.map snd l2); assoc_append_flip_l_intro q l2 y x inline_for_extraction let maybe_enum_destr_t' (t: Type) (#key #repr: eqtype) (e: enum key repr) (l1 l2: list (key * repr)) (u1: squash (e == L.append (L.rev l1) l2)) : Tot Type = (eq: (t -> t -> GTot Type0)) -> (ift: if_combinator t eq) -> (eq_refl: r_reflexive_t _ eq) -> (eq_trans: r_transitive_t _ eq) -> (f: ((x: maybe_enum_key e) -> Tot t)) -> (x: repr { maybe_enum_key_of_repr_not_in e l1 x } ) -> Tot (y: t { eq y (f (maybe_enum_key_of_repr e x)) } ) inline_for_extraction let maybe_enum_destr_t (t: Type) (#key #repr: eqtype) (e: enum key repr) : Tot Type = (eq: (t -> t -> GTot Type0)) -> (ift: if_combinator t eq) -> (eq_refl: r_reflexive_t _ eq) -> (eq_trans: r_transitive_t _ eq) -> (f: ((x: maybe_enum_key e) -> Tot t)) -> (x: repr) -> Tot (y: t { eq y (f (maybe_enum_key_of_repr e x)) } ) inline_for_extraction let destr_maybe_total_enum_repr (#t: Type) (#key #repr: eqtype) (e: total_enum key repr) (destr: maybe_enum_destr_t t e) (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) (f: ((x: maybe_total_enum_key e) -> Tot t)) (x: repr) : Tot (y: t { eq y (f (maybe_total_enum_key_of_repr e x)) } ) = destr eq ift eq_refl eq_trans (fun y -> f (total_of_maybe_enum_key e y)) x inline_for_extraction let maybe_enum_destr_t_intro (t: Type) (#key #repr: eqtype) (e: enum key repr) (f: maybe_enum_destr_t' t e [] e ()) : Tot (maybe_enum_destr_t t e) = f let maybe_enum_key_of_repr_not_in_cons (#key #repr: eqtype) (e: enum key repr) (k: key) (r: repr) (l: list (key * repr)) (x: repr) : Lemma (requires (maybe_enum_key_of_repr_not_in e l x /\ x <> r)) (ensures (maybe_enum_key_of_repr_not_in e ((k, r) :: l) x)) = () [@Norm] inline_for_extraction let list_hd (#t: Type) (l: list t { Cons? l } ) = match l with | a :: _ -> a [@Norm] inline_for_extraction let list_tl (#t: Type) (l: list t { Cons? l } ) = match l with | _ :: q -> q inline_for_extraction let maybe_enum_destr_cons (t: Type) (#key #repr: eqtype) (e: enum key repr) (l1: list (key * repr)) (l2: list (key * repr)) (u1: squash (Cons? l2 /\ e == L.append (L.rev l1) l2)) (g: (maybe_enum_destr_t' t e (list_hd l2 :: l1) (list_tl l2) (list_append_rev_cons l1 (list_hd l2) (list_tl l2)))) : Tot (maybe_enum_destr_t' t e l1 l2 u1) = fun (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) (f: (maybe_enum_key e -> Tot t)) -> [@inline_let] let _ = r_reflexive_t_elim _ _ eq_refl in [@inline_let] let _ = r_transitive_t_elim _ _ eq_trans in match list_hd l2 with | (k, r) -> [@inline_let] let _ : squash (L.mem k (L.map fst e)) = L.append_mem (L.map fst (L.rev l1)) (L.map fst l2) k; L.map_append fst (L.rev l1) (l2); () in [@inline_let] let (_ : squash (maybe_enum_key_of_repr e r == Known k)) = L.append_mem (L.map snd (L.rev l1)) (L.map snd (l2)) r; L.map_append snd (L.rev l1) (l2); assoc_append_flip_l_intro (L.rev l1) (l2) r k; () in fun (x: repr { maybe_enum_key_of_repr_not_in e l1 x } ) -> (( ift (x = r) (fun h -> f (Known k)) (fun h -> g eq ift eq_refl eq_trans f x) ) <: (y: t { eq y (f (maybe_enum_key_of_repr e x)) } )) let rec list_rev_map (#t1 #t2: Type) (f: t1 -> Tot t2) (l: list t1) : Lemma (L.rev (L.map f l) == L.map f (L.rev l)) = match l with | [] -> () | a :: q -> list_rev_cons a q; list_rev_cons (f a) (L.map f q); list_rev_map f q; L.map_append f (L.rev q) [a] inline_for_extraction let maybe_enum_destr_nil (t: Type) (#key #repr: eqtype) (e: enum key repr) (l1: list (key * repr)) (l2: list (key * repr)) (u1: squash (Nil? l2 /\ e == L.append (L.rev l1) [])) : Tot (maybe_enum_destr_t' t e l1 l2 u1) = fun (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) (f: (maybe_enum_key e -> Tot t)) -> [@inline_let] let _ = r_reflexive_t_elim _ _ eq_refl in [@inline_let] let _ = r_transitive_t_elim _ _ eq_trans in fun (x: repr { maybe_enum_key_of_repr_not_in e l1 x } ) -> (( L.append_l_nil (L.rev l1); list_rev_map snd l1; L.rev_mem (L.map snd l1) x; f (Unknown x) ) <: (y: t { eq y (f (maybe_enum_key_of_repr e x)) } )) [@Norm] let rec mk_maybe_enum_destr' (t: Type) (#key #repr: eqtype) (e: enum key repr) (l1: list (key * repr)) (l2: list (key * repr)) (u: squash (e == L.rev l1 `L.append` l2)) : Tot (maybe_enum_destr_t' t e l1 l2 u) (decreases l2) = match l2 with | [] -> maybe_enum_destr_nil t e l1 l2 u | _ -> [@inline_let] let _ = list_append_rev_cons l1 (list_hd l2) (list_tl l2) in maybe_enum_destr_cons t e l1 l2 u (mk_maybe_enum_destr' t e (list_hd l2 :: l1) (list_tl l2) u) [@Norm] let mk_maybe_enum_destr (t: Type) (#key #repr: eqtype) (e: enum key repr) : Tot (maybe_enum_destr_t t e) = maybe_enum_destr_t_intro t e (mk_maybe_enum_destr' t e [] e ()) (* dependent representation-based destructor *) inline_for_extraction let dep_maybe_enum_destr_t (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) : Tot Type = (v_eq: ((k: maybe_enum_key e) -> v k -> v k -> GTot Type0)) -> (v_if: ((k: maybe_enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) -> (v_eq_refl: ((k: maybe_enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) -> (v_eq_trans: ((k: maybe_enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) -> (f: ((k: maybe_enum_key e) -> Tot (v k))) -> (r: repr) -> Tot (y: v (maybe_enum_key_of_repr e r) { v_eq (maybe_enum_key_of_repr e r) y (f (maybe_enum_key_of_repr e r)) } ) inline_for_extraction let dep_maybe_enum_destr_t' (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) (l1 l2: list (key * repr)) (u1: squash (e == L.append (L.rev l1) l2)) : Tot Type = (v_eq: ((k: maybe_enum_key e) -> v k -> v k -> GTot Type0)) -> (v_if: ((k: maybe_enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) -> (v_eq_refl: ((k: maybe_enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) -> (v_eq_trans: ((k: maybe_enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) -> (f: ((k: maybe_enum_key e) -> Tot (v k))) -> (r: repr { maybe_enum_key_of_repr_not_in e l1 r } ) -> Tot (y: v (maybe_enum_key_of_repr e r) { v_eq (maybe_enum_key_of_repr e r) y (f (maybe_enum_key_of_repr e r)) } ) inline_for_extraction let dep_maybe_enum_destr_t_intro (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) (d: dep_maybe_enum_destr_t' e v [] e ()) : Tot (dep_maybe_enum_destr_t e v) = d inline_for_extraction let dep_maybe_enum_destr_cons (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) (l1: list (key * repr)) (l2: list (key * repr)) (u1: squash (Cons? l2 /\ e == L.append (L.rev l1) l2)) (g: (dep_maybe_enum_destr_t' e v (list_hd l2 :: l1) (list_tl l2) (list_append_rev_cons l1 (list_hd l2) (list_tl l2)))) : Tot (dep_maybe_enum_destr_t' e v l1 l2 u1) = fun (v_eq: ((k: maybe_enum_key e) -> v k -> v k -> GTot Type0)) (v_if: ((k: maybe_enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) (v_eq_refl: ((k: maybe_enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) (v_eq_trans: ((k: maybe_enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) (f: ((k: maybe_enum_key e) -> Tot (v k))) -> match list_hd l2 with | (k, r) -> [@inline_let] let _ : squash (L.mem k (L.map fst e)) = L.append_mem (L.map fst (L.rev l1)) (L.map fst l2) k; L.map_append fst (L.rev l1) (l2); () in [@inline_let] let (_ : squash (maybe_enum_key_of_repr e r == Known k)) = L.append_mem (L.map snd (L.rev l1)) (L.map snd (l2)) r; L.map_append snd (L.rev l1) (l2); assoc_append_flip_l_intro (L.rev l1) (l2) r k; () in fun (x: repr { maybe_enum_key_of_repr_not_in e l1 x } ) -> //NS: y is linear in the continuation after erasure; inline it [@inline_let] let y : v (maybe_enum_key_of_repr e x) = v_if (maybe_enum_key_of_repr e x) // TODO: Since we cannot make this argument ghost, we need to make the user aware of the fact that this argument must not be extracted. (x = r) (fun h -> f (Known k)) (fun h -> g v_eq v_if v_eq_refl v_eq_trans f x) in [@inline_let] let _ : squash (v_eq (maybe_enum_key_of_repr e x) y (f (maybe_enum_key_of_repr e x))) = if x = r then () else v_eq_trans (maybe_enum_key_of_repr e x) y (g v_eq v_if v_eq_refl v_eq_trans f x) (f (maybe_enum_key_of_repr e x)) in (y <: (y: v (maybe_enum_key_of_repr e x) { v_eq (maybe_enum_key_of_repr e x) y (f (maybe_enum_key_of_repr e x)) } )) inline_for_extraction let dep_maybe_enum_destr_nil (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) (l1: list (key * repr)) (l2: list (key * repr)) (u1: squash (Nil? l2 /\ e == L.append (L.rev l1) [])) : Tot (dep_maybe_enum_destr_t' e v l1 l2 u1) = fun (v_eq: ((k: maybe_enum_key e) -> v k -> v k -> GTot Type0)) (v_if: ((k: maybe_enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) (v_eq_refl: ((k: maybe_enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) (v_eq_trans: ((k: maybe_enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) (f: ((k: maybe_enum_key e) -> Tot (v k))) (x: repr { maybe_enum_key_of_repr_not_in e l1 x } ) -> (( L.append_l_nil (L.rev l1); list_rev_map snd l1; L.rev_mem (L.map snd l1) x; assert (Unknown x == maybe_enum_key_of_repr e x); //NS: y is linear in the continuation after erasure [@inline_let] let y : v (maybe_enum_key_of_repr e x) = f (Unknown x) in [@inline_let] let _ = v_eq_refl (maybe_enum_key_of_repr e x) (f (maybe_enum_key_of_repr e x)) in y ) <: (y: v (maybe_enum_key_of_repr e x) { v_eq (maybe_enum_key_of_repr e x) y (f (maybe_enum_key_of_repr e x)) } )) [@Norm] let rec mk_dep_maybe_enum_destr' (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) (l1: list (key * repr)) (l2: list (key * repr)) (u1: squash (e == L.append (L.rev l1) l2)) : Tot (dep_maybe_enum_destr_t' e v l1 l2 u1) (decreases l2) = match l2 with | [] -> dep_maybe_enum_destr_nil e v l1 l2 u1 | _ -> dep_maybe_enum_destr_cons e v l1 l2 u1 (mk_dep_maybe_enum_destr' e v (list_hd l2 :: l1) (list_tl l2) (list_append_rev_cons l1 (list_hd l2) (list_tl l2))) [@Norm] let mk_dep_maybe_enum_destr (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) = dep_maybe_enum_destr_t_intro e v (mk_dep_maybe_enum_destr' e v [] e ()) (* Eliminators and destructors for verification purposes *) let rec list_forallp (#t: Type) (p: t -> GTot Type0) (l: list t) : GTot Type0 = match l with | [] -> True | a :: q -> p a /\ list_forallp p q let rec list_forallp_mem (#t: eqtype) (p: t -> GTot Type0) (l: list t) : Lemma (list_forallp p l <==> (forall x . L.mem x l ==> p x)) = match l with | [] -> () | _ :: q -> list_forallp_mem p q inline_for_extraction let destruct_maybe_enum_key (#key #value: eqtype) (e: enum key value) (f: maybe_enum_key e -> Tot Type) (f_known: ( (x: key) -> (u: squash (list_mem x (list_map fst e))) -> Tot (f (Known x)) )) (f_unknown: ( (x: value) -> (u: squash (list_mem x (list_map snd e) == false)) -> Tot (f (Unknown x)) )) (x: maybe_enum_key e) : Tot (f x) = match x with | Known x' -> f_known x' () | Unknown x' -> f_unknown x' () let forall_maybe_enum_key (#key #value: eqtype) (e: enum key value) (f: maybe_enum_key e -> GTot Type0) (f_known: squash (list_forallp (fun (x: key) -> list_mem x (list_map fst e) /\ f (Known x)) (list_map fst e))) (f_unknown: ( (x: value) -> Tot (squash (list_mem x (list_map snd e) == false ==> f (Unknown x))) )) : Tot (squash (forall (x: maybe_enum_key e) . f x)) = let g (x: maybe_enum_key e) : Lemma (f x) = let u : squash (f x) = destruct_maybe_enum_key e (fun y -> squash (f y)) (fun x' u -> list_forallp_mem (fun (x: key) -> list_mem x (list_map fst e) /\ f (Known x)) (list_map fst e)) (fun x' u -> f_unknown x') x in assert (f x) in Classical.forall_intro g (* Converting enum keys to their representation, using combinators *) let enum_repr_of_key'_t (#key #repr: eqtype) (e: enum key repr) : Tot Type = (x: enum_key e) -> Tot (r: enum_repr e { r == enum_repr_of_key e x } ) inline_for_extraction let enum_repr_of_key_cons (#key #repr: eqtype) (e: enum key repr) (f : enum_repr_of_key'_t (enum_tail' e)) : Pure (enum_repr_of_key'_t e) (requires (Cons? e)) (ensures (fun _ -> True)) = (fun (e' : list (key * repr) { e' == e } ) -> match e' with | (k, r) :: _ -> (fun (x: enum_key e) -> ( if k = x then (r <: repr) else (f (x <: key) <: repr) ) <: (r: enum_repr e { enum_repr_of_key e x == r } ))) e inline_for_extraction let enum_repr_of_key_cons' (key repr: eqtype) (e: enum key repr) (u: unit { Cons? e } ) (f : enum_repr_of_key'_t (enum_tail' e)) : Tot (enum_repr_of_key'_t e) = enum_repr_of_key_cons e f
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.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": "LowParse.Spec.Enum.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
e: LowParse.Spec.Enum.enum key repr -> Prims.Pure (LowParse.Spec.Enum.enum_repr_of_key'_t e)
Prims.Pure
[]
[]
[ "Prims.eqtype", "LowParse.Spec.Enum.enum", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Enum.enum_repr", "Prims.eq2", "LowParse.Spec.Enum.enum_repr_of_key", "LowParse.Spec.Enum.enum_repr_of_key'_t", "Prims.l_and", "Prims.b2t", "Prims.uu___is_Cons", "FStar.Pervasives.Native.tuple2", "Prims.uu___is_Nil", "LowParse.Spec.Enum.enum_tail'", "Prims.l_True" ]
[]
false
false
false
false
false
let enum_repr_of_key_cons_nil (#key #repr: eqtype) (e: enum key repr) : Pure (enum_repr_of_key'_t e) (requires (Cons? e /\ Nil? (enum_tail' e))) (ensures (fun _ -> True)) =
(fun (e': list (key * repr) {e' == e}) -> match e' with | [k, r] -> (fun (x: enum_key e) -> (r <: (r: enum_repr e {enum_repr_of_key e x == r})))) e
false
LowParse.Spec.Enum.fst
LowParse.Spec.Enum.enum_repr_of_key_cons
val enum_repr_of_key_cons (#key #repr: eqtype) (e: enum key repr) (f: enum_repr_of_key'_t (enum_tail' e)) : Pure (enum_repr_of_key'_t e) (requires (Cons? e)) (ensures (fun _ -> True))
val enum_repr_of_key_cons (#key #repr: eqtype) (e: enum key repr) (f: enum_repr_of_key'_t (enum_tail' e)) : Pure (enum_repr_of_key'_t e) (requires (Cons? e)) (ensures (fun _ -> True))
let enum_repr_of_key_cons (#key #repr: eqtype) (e: enum key repr) (f : enum_repr_of_key'_t (enum_tail' e)) : Pure (enum_repr_of_key'_t e) (requires (Cons? e)) (ensures (fun _ -> True)) = (fun (e' : list (key * repr) { e' == e } ) -> match e' with | (k, r) :: _ -> (fun (x: enum_key e) -> ( if k = x then (r <: repr) else (f (x <: key) <: repr) ) <: (r: enum_repr e { enum_repr_of_key e x == r } ))) e
{ "file_name": "src/lowparse/LowParse.Spec.Enum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 6, "end_line": 1230, "start_col": 0, "start_line": 1216 }
module LowParse.Spec.Enum include LowParse.Spec.Combinators module L = FStar.List.Tot [@Norm] let rec list_map (#a #b: Type) (f: (a -> Tot b)) (l: list a) : Tot (l' : list b { l' == L.map f l } ) = match l with | [] -> [] | a :: q -> f a :: list_map f q type enum (key: eqtype) (repr: eqtype) = (l: list (key * repr) { L.noRepeats (list_map fst l) /\ L.noRepeats (list_map snd l) }) [@Norm] let rec list_mem (#t: eqtype) (x: t) (l: list t) : Tot (y: bool { y == true <==> L.mem x l == true } ) = match l with | [] -> false | a :: q -> (x = a || list_mem x q) inline_for_extraction let enum_key (#key #repr: eqtype) (e: enum key repr) : Tot eqtype = (s: key { list_mem s (list_map fst e) } ) inline_for_extraction let make_enum_key (#key #repr: eqtype) (e: enum key repr) (k: key) : Pure (enum_key e) (requires (list_mem k (list_map fst e))) (ensures (fun k' -> k == (k' <: key))) = k inline_for_extraction let enum_repr (#key #repr: eqtype) (e: enum key repr) : Tot eqtype = (r: repr { list_mem r (list_map snd e) } ) let flip (#a #b: Type) (c: (a * b)) : Tot (b * a) = let (ca, cb) = c in (cb, ca) let rec map_flip_flip (#a #b: Type) (l: list (a * b)) : Lemma (list_map flip (list_map flip l) == l) = match l with | [] -> () | _ :: q -> map_flip_flip q let rec map_fst_flip (#a #b: Type) (l: list (a * b)) : Lemma (list_map fst (list_map flip l) == list_map snd l) = match l with | [] -> () | _ :: q -> map_fst_flip q let rec map_snd_flip (#a #b: Type) (l: list (a * b)) : Lemma (list_map snd (list_map flip l) == list_map fst l) = match l with | [] -> () | _ :: q -> map_snd_flip q let rec assoc_mem_snd (#a #b: eqtype) (l: list (a * b)) (x: a) (y: b) : Lemma (requires (L.assoc x l == Some y)) (ensures (list_mem y (list_map snd l) == true)) (decreases l) = let ((x', y') :: l') = l in if x' = x then () else assoc_mem_snd l' x y let rec assoc_flip_elim (#a #b: eqtype) (l: list (a * b)) (y: b) (x: a) : Lemma (requires ( L.noRepeats (list_map fst l) /\ L.noRepeats (list_map snd l) /\ L.assoc y (list_map flip l) == Some x )) (ensures ( L.assoc x l == Some y )) (decreases l) = let ((x', y') :: l') = l in if y' = y then () else begin if x' = x then begin assert (list_mem x' (list_map fst l') == false); assoc_mem_snd (list_map flip l') y x; map_snd_flip l'; assert False end else assoc_flip_elim l' y x end let rec assoc_flip_intro (#a #b: eqtype) (l: list (a * b)) (y: b) (x: a) : Lemma (requires ( L.noRepeats (list_map fst l) /\ L.noRepeats (list_map snd l) /\ L.assoc x l == Some y )) (ensures ( L.assoc y (list_map flip l) == Some x )) = map_fst_flip l; map_snd_flip l; map_flip_flip l; assoc_flip_elim (list_map flip l) x y let enum_key_of_repr (#key #repr: eqtype) (e: enum key repr) (r: enum_repr e) : Pure (enum_key e) (requires True) (ensures (fun y -> L.assoc y e == Some r)) = map_fst_flip e; let e' = list_map #(key * repr) #(repr * key) flip e in L.assoc_mem r e'; let k = Some?.v (L.assoc r e') in assoc_flip_elim e r k; L.assoc_mem k e; (k <: enum_key e) let parse_enum_key_cond (#key #repr: eqtype) (e: enum key repr) (r: repr) : GTot bool = list_mem r (list_map snd e) let parse_enum_key_synth (#key #repr: eqtype) (e: enum key repr) (r: repr { parse_enum_key_cond e r == true } ) : GTot (enum_key e) = enum_key_of_repr e r let parse_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) : Tot (parser (parse_filter_kind k) (enum_key e)) = (p `parse_filter` parse_enum_key_cond e ) `parse_synth` parse_enum_key_synth e let enum_repr_of_key (#key #repr: eqtype) (e: enum key repr) (k: enum_key e) : Pure (enum_repr e) (requires True) (ensures (fun r -> L.assoc k e == Some r)) = L.assoc_mem k e; let r = Some?.v (L.assoc k e) in assoc_flip_intro e r k; L.assoc_mem r (list_map flip e); map_fst_flip e; (r <: enum_repr e) let enum_repr_of_key_of_repr (#key #repr: eqtype) (e: enum key repr) (r: enum_repr e) : Lemma (enum_repr_of_key e (enum_key_of_repr e r) == r) = () let enum_key_of_repr_of_key (#key #repr: eqtype) (e: enum key repr) (k: enum_key e) : Lemma (enum_key_of_repr e (enum_repr_of_key e k) == k) = assoc_flip_intro e (enum_repr_of_key e k) k let serialize_enum_key_synth_recip (#key #repr: eqtype) (e: enum key repr) (k: enum_key e) : GTot (r: repr { parse_enum_key_cond e r == true } ) = enum_repr_of_key e k let serialize_enum_key_synth_inverse (#key #repr: eqtype) (e: enum key repr) : Lemma (synth_inverse (parse_enum_key_synth e) (serialize_enum_key_synth_recip e)) = Classical.forall_intro (enum_key_of_repr_of_key e) let serialize_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (s: serializer p) (e: enum key repr) : Tot (serializer (parse_enum_key p e)) = serialize_enum_key_synth_inverse e; serialize_synth (parse_filter p (parse_enum_key_cond e)) (parse_enum_key_synth e) (serialize_filter s (parse_enum_key_cond e)) (serialize_enum_key_synth_recip e) () let serialize_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (s: serializer p) (e: enum key repr) (x: enum_key e) : Lemma (serialize (serialize_enum_key p s e) x == serialize s (enum_repr_of_key e x)) = serialize_enum_key_synth_inverse e; serialize_synth_eq (parse_filter p (parse_enum_key_cond e)) (parse_enum_key_synth e) (serialize_filter s (parse_enum_key_cond e)) (serialize_enum_key_synth_recip e) () x inline_for_extraction let unknown_enum_repr (#key #repr: eqtype) (e: enum key repr) : Tot Type = (r: repr { list_mem r (list_map snd e) == false } ) type maybe_enum_key (#key #repr: eqtype) (e: enum key repr) = | Known of (enum_key e) | Unknown of (unknown_enum_repr e) let maybe_enum_key_of_repr (#key #repr: eqtype) (e: enum key repr) (r: repr) : Tot (maybe_enum_key e) = if list_mem r (list_map snd e) then Known (enum_key_of_repr e r) else Unknown r let parse_maybe_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) : Tot (parser k (maybe_enum_key e)) = p `parse_synth` (maybe_enum_key_of_repr e) let parse_maybe_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) (input: bytes) : Lemma (parse (parse_maybe_enum_key p e) input == (match parse p input with | Some (x, consumed) -> Some (maybe_enum_key_of_repr e x, consumed) | _ -> None )) = parse_synth_eq p (maybe_enum_key_of_repr e) input let parse_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) (input: bytes) : Lemma (parse (parse_enum_key p e) input == (match parse p input with | Some (x, consumed) -> begin match maybe_enum_key_of_repr e x with | Known k -> Some (k, consumed) | _ -> None end | _ -> None )) = parse_filter_eq p (parse_enum_key_cond e) input; parse_synth_eq (p `parse_filter` parse_enum_key_cond e) (parse_enum_key_synth e) input let repr_of_maybe_enum_key (#key #repr: eqtype) (e: enum key repr) (x: maybe_enum_key e) : Tot (r: repr { maybe_enum_key_of_repr e r == x } ) = match x with | Known k' -> enum_key_of_repr_of_key e k' ; enum_repr_of_key e k' | Unknown r -> r let serialize_maybe_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (s: serializer p) (e: enum key repr) : Tot (serializer (parse_maybe_enum_key p e)) = serialize_synth p (maybe_enum_key_of_repr e) s (repr_of_maybe_enum_key e) () let serialize_maybe_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (s: serializer p) (e: enum key repr) (x: maybe_enum_key e) : Lemma (serialize (serialize_maybe_enum_key p s e) x == serialize s (repr_of_maybe_enum_key e x)) = serialize_synth_eq p (maybe_enum_key_of_repr e) s (repr_of_maybe_enum_key e) () x let is_total_enum (#key: eqtype) (#repr: eqtype) (l: list (key * repr)) : GTot Type0 = forall (k: key) . {:pattern (list_mem k (list_map fst l))} list_mem k (list_map fst l) let total_enum (key: eqtype) (repr: eqtype) : Tot eqtype = (l: enum key repr { is_total_enum l } ) let synth_total_enum_key (#key: eqtype) (#repr: eqtype) (l: total_enum key repr) (k: enum_key l) : Tot key = let k' : key = k in k' let parse_total_enum_key (#k: parser_kind) (#key: eqtype) (#repr: eqtype) (p: parser k repr) (l: total_enum key repr) : Tot (parser (parse_filter_kind k) key) = parse_enum_key p l `parse_synth` (synth_total_enum_key l) let synth_total_enum_key_recip (#key: eqtype) (#repr: eqtype) (l: total_enum key repr) (k: key) : Tot (k' : enum_key l { synth_total_enum_key l k' == k } ) = k let serialize_total_enum_key (#k: parser_kind) (#key: eqtype) (#repr: eqtype) (p: parser k repr) (s: serializer p) (l: total_enum key repr) : Tot (serializer (parse_total_enum_key p l)) = serialize_synth (parse_enum_key p l) (synth_total_enum_key l) (serialize_enum_key p s l) (synth_total_enum_key_recip l) () type maybe_total_enum_key (#key #repr: eqtype) (e: total_enum key repr) = | TotalKnown of key | TotalUnknown of (unknown_enum_repr e) let maybe_total_enum_key_of_repr (#key #repr: eqtype) (e: total_enum key repr) (r: repr) : Tot (maybe_total_enum_key e) = if list_mem r (list_map snd e) then TotalKnown (enum_key_of_repr e r) else TotalUnknown r let parse_maybe_total_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: total_enum key repr) : Tot (parser k (maybe_total_enum_key e)) = p `parse_synth` (maybe_total_enum_key_of_repr e) let repr_of_maybe_total_enum_key (#key #repr: eqtype) (e: total_enum key repr) (k: maybe_total_enum_key e) : Tot (r: repr { maybe_total_enum_key_of_repr e r == k } ) = match k with | TotalKnown k' -> enum_key_of_repr_of_key e k' ; enum_repr_of_key e k' | TotalUnknown r -> r let serialize_maybe_total_enum_key (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (s: serializer p) (e: total_enum key repr) : Tot (serializer (parse_maybe_total_enum_key p e)) = serialize_synth p (maybe_total_enum_key_of_repr e) s (repr_of_maybe_total_enum_key e) () inline_for_extraction let maybe_enum_key_of_total (#key #repr: eqtype) (e: total_enum key repr) (k: maybe_total_enum_key e) : Tot (maybe_enum_key e) = match k with | TotalKnown ek -> Known (ek <: key) | TotalUnknown r -> Unknown r inline_for_extraction let total_of_maybe_enum_key (#key #repr: eqtype) (e: total_enum key repr) (k: maybe_enum_key e) : Tot (maybe_total_enum_key e) = match k with | Known ek -> TotalKnown (ek <: key) | Unknown r -> TotalUnknown r let maybe_total_enum_key_of_repr_eq (#key #repr: eqtype) (e: total_enum key repr) (r: repr) : Lemma (maybe_total_enum_key_of_repr e r == total_of_maybe_enum_key e (maybe_enum_key_of_repr e r)) = () let parse_maybe_total_enum_key_eq (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: total_enum key repr) (input: bytes) : Lemma (parse (parse_maybe_total_enum_key p e) input == (parse (parse_maybe_enum_key p e `parse_synth` total_of_maybe_enum_key e) input)) = parse_synth_eq p (maybe_total_enum_key_of_repr e) input; parse_synth_eq (parse_maybe_enum_key p e) (total_of_maybe_enum_key e) input; parse_synth_eq p (maybe_enum_key_of_repr e) input (* Destructors *) (* Universal destructor *) let r_reflexive_prop (t: Type) (r: (t -> t -> GTot Type0)) : GTot Type0 = forall (x: t) . {:pattern (r x x)} r x x inline_for_extraction let r_reflexive_t (t: Type) (r: (t -> t -> GTot Type0)) : Tot Type = (x: t) -> Lemma (r x x) let r_reflexive_t_elim (t: Type) (r: (t -> t -> GTot Type0)) (phi: r_reflexive_t t r) : Lemma (r_reflexive_prop t r) = Classical.forall_intro phi let r_transitive_prop (t: Type) (r: (t -> t -> GTot Type0)) : GTot Type0 = forall (x y z: t) . {:pattern (r x y); (r y z)} (r x y /\ r y z) ==> r x z inline_for_extraction let r_transitive_t (t: Type) (r: (t -> t -> GTot Type0)) : Tot Type = (x: t) -> (y: t) -> (z: t) -> Lemma ((r x y /\ r y z) ==> r x z) let r_transitive_t_elim (t: Type) (r: (t -> t -> GTot Type0)) (phi: r_transitive_t t r) : Lemma (r_transitive_prop t r) = Classical.forall_intro_3 phi inline_for_extraction let if_combinator (t: Type) (eq: (t -> t -> GTot Type0)) : Tot Type = (cond: bool) -> (sv_true: (cond_true cond -> Tot t)) -> (sv_false: (cond_false cond -> Tot t)) -> Tot (y: t { eq y (if cond then sv_true () else sv_false ()) } ) inline_for_extraction let default_if (t: Type) : Tot (if_combinator t (eq2 #t)) = fun (cond: bool) (s_true: (cond_true cond -> Tot t)) (s_false: (cond_false cond -> Tot t)) -> (if cond then s_true () else s_false ()) <: (y: t { y == (if cond then s_true () else s_false ()) } ) let feq (u v: Type) (eq: (v -> v -> GTot Type0)) (f1 f2: (u -> Tot v)) : GTot Type0 = (forall (x: u) . {:pattern (f1 x); (f2 x)} eq (f1 x) (f2 x)) (* #!$% patterns on forall, the following proofs should be trivial and now they aren't *) let feq_elim (u v: Type) (eq: (v -> v -> GTot Type0)) (f1 f2: (u -> Tot v)) (x: u) : Lemma (requires (feq u v eq f1 f2)) (ensures (f1 x `eq` f2 x)) = () let feq_intro (u v: Type) (eq: (v -> v -> GTot Type0)) (f1 f2: (u -> Tot v)) (phi: (x: u) -> Lemma (f1 x `eq` f2 x)) : Lemma (feq _ _ eq f1 f2) = Classical.forall_intro phi let feq_trans (u v: Type) (eq: (v -> v -> GTot Type0)) : Pure (r_transitive_t _ (feq _ _ eq)) (requires (r_transitive_prop _ eq)) (ensures (fun _ -> True)) = let phi (f1 f2 f3: (u -> Tot v)) : Lemma (requires (feq _ _ eq f1 f2 /\ feq _ _ eq f2 f3)) (ensures (feq _ _ eq f1 f3)) = feq_intro _ _ eq f1 f3 (fun x -> assert (f1 x `eq` f2 x /\ f2 x `eq` f3 x)) in let phi2 (f1 f2 f3: (u -> Tot v)) : Lemma ((feq _ _ eq f1 f2 /\ feq _ _ eq f2 f3) ==> feq _ _ eq f1 f3) = Classical.move_requires (phi f1 f2) f3 in phi2 inline_for_extraction let fif (u v: Type) (eq: (v -> v -> GTot Type0)) (ifc: if_combinator v eq) : Tot (if_combinator (u -> Tot v) (feq u v eq)) = fun (cond: bool) (s_true: (cond_true cond -> u -> Tot v)) (s_false: (cond_false cond -> u -> Tot v)) (x: u) -> ifc cond (fun h -> s_true () x) (fun h -> s_false () x) inline_for_extraction let enum_destr_t (t: Type) (#key #repr: eqtype) (e: enum key repr) : Tot Type = (eq: (t -> t -> GTot Type0)) -> (ift: if_combinator t eq) -> (eq_refl: r_reflexive_t _ eq) -> (eq_trans: r_transitive_t _ eq) -> (f: ((x: enum_key e) -> Tot t)) -> (x: enum_key e) -> Tot (y: t { eq y (f x) } ) inline_for_extraction let enum_tail' (#key #repr: eqtype) (e: enum key repr) : Pure (enum key repr) (requires True) (ensures (fun y -> Cons? e ==> (let (_ :: y') = e in y == y'))) = match e with _ :: y -> y | _ -> [] inline_for_extraction let enum_tail (#key #repr: eqtype) (e: enum key repr) : Tot (enum key repr) = enum_tail' e inline_for_extraction let enum_destr_cons (t: Type) (#key #repr: eqtype) (e: enum key repr) (g: enum_destr_t t (enum_tail' e)) : Pure (enum_destr_t t e) (requires (Cons? e)) (ensures (fun _ -> True)) = fun (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) -> [@inline_let] let _ = r_reflexive_t_elim _ _ eq_refl in [@inline_let] let _ = r_transitive_t_elim _ _ eq_trans in (fun (e' : list (key * repr) { e' == e } ) -> match e' with | (k, _) :: _ -> (fun (f: (enum_key e -> Tot t)) (x: enum_key e) -> (( [@inline_let] let f' : (enum_key (enum_tail' e) -> Tot t) = (fun (x' : enum_key (enum_tail' e)) -> [@inline_let] let (x_ : enum_key e) = (x' <: key) in f x_ ) in [@inline_let] let (y: t) = ift ((k <: key) = x) (fun h -> f k) (fun h -> [@inline_let] let x' : enum_key (enum_tail' e) = (x <: key) in (g eq ift eq_refl eq_trans f' x' <: t)) in y ) <: (y: t { eq y (f x) } ))) ) e inline_for_extraction let enum_destr_cons' (t: Type) (key repr: eqtype) (e: enum key repr) (u: unit { Cons? e } ) (g: enum_destr_t t (enum_tail e)) : Tot (enum_destr_t t e) = enum_destr_cons t e g inline_for_extraction let enum_destr_cons_nil (t: Type) (#key #repr: eqtype) (e: enum key repr) : Pure (enum_destr_t t e) (requires (Cons? e /\ Nil? (enum_tail' e))) (ensures (fun _ -> True)) = fun (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) -> [@inline_let] let _ = r_reflexive_t_elim _ _ eq_refl in (fun (e' : list (key * repr) { e' == e } ) -> match e' with | (k, _) :: _ -> (fun (f: (enum_key e -> Tot t)) (x: enum_key e) -> (( f k ) <: (y: t { eq y (f x) } ))) ) e inline_for_extraction let enum_destr_cons_nil' (t: Type) (key repr: eqtype) (e: enum key repr) (u1: unit { Cons? e } ) (u2: unit { Nil? (enum_tail e) } ) : Tot (enum_destr_t t e) = enum_destr_cons_nil t e (* Dependent destructor *) inline_for_extraction let dep_enum_destr (#key #repr: eqtype) (e: enum key repr) (v: (enum_key e -> Tot (Type u#a))) : Tot (Type) = (v_eq: ((k: enum_key e) -> v k -> v k -> GTot Type0)) -> (v_if: ((k: enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) -> (v_eq_refl: ((k: enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) -> (v_eq_trans: ((k: enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) -> (f: ((k: enum_key e) -> Tot (v k))) -> (k: enum_key e) -> Tot (y: v k { v_eq k y (f k) } ) module L = FStar.List.Tot inline_for_extraction let dep_enum_destr_cons (#key #repr: eqtype) (e: enum key repr) (u: squash (Cons? e)) (v: (enum_key e -> Tot Type)) (destr: dep_enum_destr (enum_tail e) (fun (k' : enum_key (enum_tail e)) -> v (k' <: key))) : Tot (dep_enum_destr e v) = match e with | ((k, _) :: _) -> fun (v_eq: ((k: enum_key e) -> v k -> v k -> GTot Type0)) (v_if: ((k: enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) (v_eq_refl: ((k: enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) (v_eq_trans: ((k: enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) (f: ((k: enum_key e) -> Tot (v k))) (k' : enum_key e) -> [@inline_let] let _ = r_reflexive_t_elim (v k') (v_eq k') (v_eq_refl k') in [@inline_let] let _ = r_transitive_t_elim (v k') (v_eq k') (v_eq_trans k') in [@inline_let] let y : v k' = v_if k' (k = k') (fun _ -> [@inline_let] let y : v k' = f k in y ) (fun _ -> [@inline_let] let v' (k: enum_key (enum_tail e)) : Tot Type = v (k <: key) in [@inline_let] let v'_eq (k: enum_key (enum_tail e)) : Tot (v' k -> v' k -> GTot Type0) = v_eq (k <: key) in [@inline_let] let v'_if (k: enum_key (enum_tail e)) : Tot (if_combinator (v' k) (v'_eq k)) = v_if (k <: key) in [@inline_let] let v'_eq_refl (k: enum_key (enum_tail e)) : Tot (r_reflexive_t _ (v'_eq k)) = v_eq_refl (k <: key) in [@inline_let] let v'_eq_trans (k: enum_key (enum_tail e)) : Tot (r_transitive_t _ (v'_eq k)) = v_eq_trans (k <: key) in [@inline_let] let f' (k: enum_key (enum_tail e)) : Tot (v' k) = f (k <: key) in [@inline_let] let k' : key = k' in [@inline_let] let _ = assert (k' <> k) in [@inline_let] let _ = assert (L.mem k' (L.map fst (enum_tail e))) in [@inline_let] let (y: v' k') = destr v'_eq v'_if v'_eq_refl v'_eq_trans f' k' in y ) in (y <: (y: v k' { v_eq k' y (f k') } )) inline_for_extraction let dep_enum_destr_cons_nil (#key #repr: eqtype) (e: enum key repr) (u: squash (Cons? e /\ Nil? (enum_tail e))) (v: (enum_key e -> Tot Type)) : Tot (dep_enum_destr e v) = match e with | ((k, _) :: _) -> fun (v_eq: ((k: enum_key e) -> v k -> v k -> GTot Type0)) (v_if: ((k: enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) (v_eq_refl: ((k: enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) (v_eq_trans: ((k: enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) (f: ((k: enum_key e) -> Tot (v k))) (k' : enum_key e) -> [@inline_let] let _ = r_reflexive_t_elim (v k') (v_eq k') (v_eq_refl k') in [@inline_let] let _ = r_transitive_t_elim (v k') (v_eq k') (v_eq_trans k') in [@inline_let] let y : v k' = f k in (y <: (y: v k' { v_eq k' y (f k') } )) (* Destructor from the representation *) let maybe_enum_key_of_repr_not_in (#key #repr: eqtype) (e: enum key repr) (l: list (key * repr)) (x: repr) : GTot Type0 = (~ (L.mem x (L.map snd l))) let list_rev_cons (#t: Type) (a: t) (q: list t) : Lemma (L.rev (a :: q) == L.rev q `L.append` [a]) = L.rev_rev' (a :: q); L.rev_rev' q let list_append_rev_cons (#t: Type) (l1: list t) (x: t) (l2: list t) : Lemma (L.append (L.rev l1) (x :: l2) == L.append (L.rev (x :: l1)) l2) = list_rev_cons x l1; L.append_assoc (L.rev l1) [x] l2 let rec assoc_append_flip_l_intro (#key #repr: eqtype) (l1 l2: list (key * repr)) (y: repr) (x: key) : Lemma (requires (L.noRepeats (L.map snd (L.append l1 l2)) /\ L.assoc y (L.map flip l2) == Some x)) (ensures (L.assoc y (L.map flip (l1 `L.append` l2)) == Some x)) = match l1 with | [] -> () | (_, r') :: q -> L.assoc_mem y (L.map flip l2); map_fst_flip l2; L.map_append snd l1 l2; L.noRepeats_append_elim (L.map snd l1) (L.map snd l2); assoc_append_flip_l_intro q l2 y x inline_for_extraction let maybe_enum_destr_t' (t: Type) (#key #repr: eqtype) (e: enum key repr) (l1 l2: list (key * repr)) (u1: squash (e == L.append (L.rev l1) l2)) : Tot Type = (eq: (t -> t -> GTot Type0)) -> (ift: if_combinator t eq) -> (eq_refl: r_reflexive_t _ eq) -> (eq_trans: r_transitive_t _ eq) -> (f: ((x: maybe_enum_key e) -> Tot t)) -> (x: repr { maybe_enum_key_of_repr_not_in e l1 x } ) -> Tot (y: t { eq y (f (maybe_enum_key_of_repr e x)) } ) inline_for_extraction let maybe_enum_destr_t (t: Type) (#key #repr: eqtype) (e: enum key repr) : Tot Type = (eq: (t -> t -> GTot Type0)) -> (ift: if_combinator t eq) -> (eq_refl: r_reflexive_t _ eq) -> (eq_trans: r_transitive_t _ eq) -> (f: ((x: maybe_enum_key e) -> Tot t)) -> (x: repr) -> Tot (y: t { eq y (f (maybe_enum_key_of_repr e x)) } ) inline_for_extraction let destr_maybe_total_enum_repr (#t: Type) (#key #repr: eqtype) (e: total_enum key repr) (destr: maybe_enum_destr_t t e) (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) (f: ((x: maybe_total_enum_key e) -> Tot t)) (x: repr) : Tot (y: t { eq y (f (maybe_total_enum_key_of_repr e x)) } ) = destr eq ift eq_refl eq_trans (fun y -> f (total_of_maybe_enum_key e y)) x inline_for_extraction let maybe_enum_destr_t_intro (t: Type) (#key #repr: eqtype) (e: enum key repr) (f: maybe_enum_destr_t' t e [] e ()) : Tot (maybe_enum_destr_t t e) = f let maybe_enum_key_of_repr_not_in_cons (#key #repr: eqtype) (e: enum key repr) (k: key) (r: repr) (l: list (key * repr)) (x: repr) : Lemma (requires (maybe_enum_key_of_repr_not_in e l x /\ x <> r)) (ensures (maybe_enum_key_of_repr_not_in e ((k, r) :: l) x)) = () [@Norm] inline_for_extraction let list_hd (#t: Type) (l: list t { Cons? l } ) = match l with | a :: _ -> a [@Norm] inline_for_extraction let list_tl (#t: Type) (l: list t { Cons? l } ) = match l with | _ :: q -> q inline_for_extraction let maybe_enum_destr_cons (t: Type) (#key #repr: eqtype) (e: enum key repr) (l1: list (key * repr)) (l2: list (key * repr)) (u1: squash (Cons? l2 /\ e == L.append (L.rev l1) l2)) (g: (maybe_enum_destr_t' t e (list_hd l2 :: l1) (list_tl l2) (list_append_rev_cons l1 (list_hd l2) (list_tl l2)))) : Tot (maybe_enum_destr_t' t e l1 l2 u1) = fun (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) (f: (maybe_enum_key e -> Tot t)) -> [@inline_let] let _ = r_reflexive_t_elim _ _ eq_refl in [@inline_let] let _ = r_transitive_t_elim _ _ eq_trans in match list_hd l2 with | (k, r) -> [@inline_let] let _ : squash (L.mem k (L.map fst e)) = L.append_mem (L.map fst (L.rev l1)) (L.map fst l2) k; L.map_append fst (L.rev l1) (l2); () in [@inline_let] let (_ : squash (maybe_enum_key_of_repr e r == Known k)) = L.append_mem (L.map snd (L.rev l1)) (L.map snd (l2)) r; L.map_append snd (L.rev l1) (l2); assoc_append_flip_l_intro (L.rev l1) (l2) r k; () in fun (x: repr { maybe_enum_key_of_repr_not_in e l1 x } ) -> (( ift (x = r) (fun h -> f (Known k)) (fun h -> g eq ift eq_refl eq_trans f x) ) <: (y: t { eq y (f (maybe_enum_key_of_repr e x)) } )) let rec list_rev_map (#t1 #t2: Type) (f: t1 -> Tot t2) (l: list t1) : Lemma (L.rev (L.map f l) == L.map f (L.rev l)) = match l with | [] -> () | a :: q -> list_rev_cons a q; list_rev_cons (f a) (L.map f q); list_rev_map f q; L.map_append f (L.rev q) [a] inline_for_extraction let maybe_enum_destr_nil (t: Type) (#key #repr: eqtype) (e: enum key repr) (l1: list (key * repr)) (l2: list (key * repr)) (u1: squash (Nil? l2 /\ e == L.append (L.rev l1) [])) : Tot (maybe_enum_destr_t' t e l1 l2 u1) = fun (eq: (t -> t -> GTot Type0)) (ift: if_combinator t eq) (eq_refl: r_reflexive_t _ eq) (eq_trans: r_transitive_t _ eq) (f: (maybe_enum_key e -> Tot t)) -> [@inline_let] let _ = r_reflexive_t_elim _ _ eq_refl in [@inline_let] let _ = r_transitive_t_elim _ _ eq_trans in fun (x: repr { maybe_enum_key_of_repr_not_in e l1 x } ) -> (( L.append_l_nil (L.rev l1); list_rev_map snd l1; L.rev_mem (L.map snd l1) x; f (Unknown x) ) <: (y: t { eq y (f (maybe_enum_key_of_repr e x)) } )) [@Norm] let rec mk_maybe_enum_destr' (t: Type) (#key #repr: eqtype) (e: enum key repr) (l1: list (key * repr)) (l2: list (key * repr)) (u: squash (e == L.rev l1 `L.append` l2)) : Tot (maybe_enum_destr_t' t e l1 l2 u) (decreases l2) = match l2 with | [] -> maybe_enum_destr_nil t e l1 l2 u | _ -> [@inline_let] let _ = list_append_rev_cons l1 (list_hd l2) (list_tl l2) in maybe_enum_destr_cons t e l1 l2 u (mk_maybe_enum_destr' t e (list_hd l2 :: l1) (list_tl l2) u) [@Norm] let mk_maybe_enum_destr (t: Type) (#key #repr: eqtype) (e: enum key repr) : Tot (maybe_enum_destr_t t e) = maybe_enum_destr_t_intro t e (mk_maybe_enum_destr' t e [] e ()) (* dependent representation-based destructor *) inline_for_extraction let dep_maybe_enum_destr_t (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) : Tot Type = (v_eq: ((k: maybe_enum_key e) -> v k -> v k -> GTot Type0)) -> (v_if: ((k: maybe_enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) -> (v_eq_refl: ((k: maybe_enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) -> (v_eq_trans: ((k: maybe_enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) -> (f: ((k: maybe_enum_key e) -> Tot (v k))) -> (r: repr) -> Tot (y: v (maybe_enum_key_of_repr e r) { v_eq (maybe_enum_key_of_repr e r) y (f (maybe_enum_key_of_repr e r)) } ) inline_for_extraction let dep_maybe_enum_destr_t' (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) (l1 l2: list (key * repr)) (u1: squash (e == L.append (L.rev l1) l2)) : Tot Type = (v_eq: ((k: maybe_enum_key e) -> v k -> v k -> GTot Type0)) -> (v_if: ((k: maybe_enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) -> (v_eq_refl: ((k: maybe_enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) -> (v_eq_trans: ((k: maybe_enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) -> (f: ((k: maybe_enum_key e) -> Tot (v k))) -> (r: repr { maybe_enum_key_of_repr_not_in e l1 r } ) -> Tot (y: v (maybe_enum_key_of_repr e r) { v_eq (maybe_enum_key_of_repr e r) y (f (maybe_enum_key_of_repr e r)) } ) inline_for_extraction let dep_maybe_enum_destr_t_intro (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) (d: dep_maybe_enum_destr_t' e v [] e ()) : Tot (dep_maybe_enum_destr_t e v) = d inline_for_extraction let dep_maybe_enum_destr_cons (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) (l1: list (key * repr)) (l2: list (key * repr)) (u1: squash (Cons? l2 /\ e == L.append (L.rev l1) l2)) (g: (dep_maybe_enum_destr_t' e v (list_hd l2 :: l1) (list_tl l2) (list_append_rev_cons l1 (list_hd l2) (list_tl l2)))) : Tot (dep_maybe_enum_destr_t' e v l1 l2 u1) = fun (v_eq: ((k: maybe_enum_key e) -> v k -> v k -> GTot Type0)) (v_if: ((k: maybe_enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) (v_eq_refl: ((k: maybe_enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) (v_eq_trans: ((k: maybe_enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) (f: ((k: maybe_enum_key e) -> Tot (v k))) -> match list_hd l2 with | (k, r) -> [@inline_let] let _ : squash (L.mem k (L.map fst e)) = L.append_mem (L.map fst (L.rev l1)) (L.map fst l2) k; L.map_append fst (L.rev l1) (l2); () in [@inline_let] let (_ : squash (maybe_enum_key_of_repr e r == Known k)) = L.append_mem (L.map snd (L.rev l1)) (L.map snd (l2)) r; L.map_append snd (L.rev l1) (l2); assoc_append_flip_l_intro (L.rev l1) (l2) r k; () in fun (x: repr { maybe_enum_key_of_repr_not_in e l1 x } ) -> //NS: y is linear in the continuation after erasure; inline it [@inline_let] let y : v (maybe_enum_key_of_repr e x) = v_if (maybe_enum_key_of_repr e x) // TODO: Since we cannot make this argument ghost, we need to make the user aware of the fact that this argument must not be extracted. (x = r) (fun h -> f (Known k)) (fun h -> g v_eq v_if v_eq_refl v_eq_trans f x) in [@inline_let] let _ : squash (v_eq (maybe_enum_key_of_repr e x) y (f (maybe_enum_key_of_repr e x))) = if x = r then () else v_eq_trans (maybe_enum_key_of_repr e x) y (g v_eq v_if v_eq_refl v_eq_trans f x) (f (maybe_enum_key_of_repr e x)) in (y <: (y: v (maybe_enum_key_of_repr e x) { v_eq (maybe_enum_key_of_repr e x) y (f (maybe_enum_key_of_repr e x)) } )) inline_for_extraction let dep_maybe_enum_destr_nil (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) (l1: list (key * repr)) (l2: list (key * repr)) (u1: squash (Nil? l2 /\ e == L.append (L.rev l1) [])) : Tot (dep_maybe_enum_destr_t' e v l1 l2 u1) = fun (v_eq: ((k: maybe_enum_key e) -> v k -> v k -> GTot Type0)) (v_if: ((k: maybe_enum_key e) -> Tot (if_combinator (v k) (v_eq k)))) (v_eq_refl: ((k: maybe_enum_key e) -> Tot (r_reflexive_t _ (v_eq k)))) (v_eq_trans: ((k: maybe_enum_key e) -> Tot (r_transitive_t _ (v_eq k)))) (f: ((k: maybe_enum_key e) -> Tot (v k))) (x: repr { maybe_enum_key_of_repr_not_in e l1 x } ) -> (( L.append_l_nil (L.rev l1); list_rev_map snd l1; L.rev_mem (L.map snd l1) x; assert (Unknown x == maybe_enum_key_of_repr e x); //NS: y is linear in the continuation after erasure [@inline_let] let y : v (maybe_enum_key_of_repr e x) = f (Unknown x) in [@inline_let] let _ = v_eq_refl (maybe_enum_key_of_repr e x) (f (maybe_enum_key_of_repr e x)) in y ) <: (y: v (maybe_enum_key_of_repr e x) { v_eq (maybe_enum_key_of_repr e x) y (f (maybe_enum_key_of_repr e x)) } )) [@Norm] let rec mk_dep_maybe_enum_destr' (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) (l1: list (key * repr)) (l2: list (key * repr)) (u1: squash (e == L.append (L.rev l1) l2)) : Tot (dep_maybe_enum_destr_t' e v l1 l2 u1) (decreases l2) = match l2 with | [] -> dep_maybe_enum_destr_nil e v l1 l2 u1 | _ -> dep_maybe_enum_destr_cons e v l1 l2 u1 (mk_dep_maybe_enum_destr' e v (list_hd l2 :: l1) (list_tl l2) (list_append_rev_cons l1 (list_hd l2) (list_tl l2))) [@Norm] let mk_dep_maybe_enum_destr (#key #repr: eqtype) (e: enum key repr) (v: (maybe_enum_key e -> Tot Type)) = dep_maybe_enum_destr_t_intro e v (mk_dep_maybe_enum_destr' e v [] e ()) (* Eliminators and destructors for verification purposes *) let rec list_forallp (#t: Type) (p: t -> GTot Type0) (l: list t) : GTot Type0 = match l with | [] -> True | a :: q -> p a /\ list_forallp p q let rec list_forallp_mem (#t: eqtype) (p: t -> GTot Type0) (l: list t) : Lemma (list_forallp p l <==> (forall x . L.mem x l ==> p x)) = match l with | [] -> () | _ :: q -> list_forallp_mem p q inline_for_extraction let destruct_maybe_enum_key (#key #value: eqtype) (e: enum key value) (f: maybe_enum_key e -> Tot Type) (f_known: ( (x: key) -> (u: squash (list_mem x (list_map fst e))) -> Tot (f (Known x)) )) (f_unknown: ( (x: value) -> (u: squash (list_mem x (list_map snd e) == false)) -> Tot (f (Unknown x)) )) (x: maybe_enum_key e) : Tot (f x) = match x with | Known x' -> f_known x' () | Unknown x' -> f_unknown x' () let forall_maybe_enum_key (#key #value: eqtype) (e: enum key value) (f: maybe_enum_key e -> GTot Type0) (f_known: squash (list_forallp (fun (x: key) -> list_mem x (list_map fst e) /\ f (Known x)) (list_map fst e))) (f_unknown: ( (x: value) -> Tot (squash (list_mem x (list_map snd e) == false ==> f (Unknown x))) )) : Tot (squash (forall (x: maybe_enum_key e) . f x)) = let g (x: maybe_enum_key e) : Lemma (f x) = let u : squash (f x) = destruct_maybe_enum_key e (fun y -> squash (f y)) (fun x' u -> list_forallp_mem (fun (x: key) -> list_mem x (list_map fst e) /\ f (Known x)) (list_map fst e)) (fun x' u -> f_unknown x') x in assert (f x) in Classical.forall_intro g (* Converting enum keys to their representation, using combinators *) let enum_repr_of_key'_t (#key #repr: eqtype) (e: enum key repr) : Tot Type = (x: enum_key e) -> Tot (r: enum_repr e { r == enum_repr_of_key e x } )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.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": "LowParse.Spec.Enum.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
e: LowParse.Spec.Enum.enum key repr -> f: LowParse.Spec.Enum.enum_repr_of_key'_t (LowParse.Spec.Enum.enum_tail' e) -> Prims.Pure (LowParse.Spec.Enum.enum_repr_of_key'_t e)
Prims.Pure
[]
[]
[ "Prims.eqtype", "LowParse.Spec.Enum.enum", "LowParse.Spec.Enum.enum_repr_of_key'_t", "LowParse.Spec.Enum.enum_tail'", "Prims.list", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Enum.enum_key", "Prims.op_Equality", "Prims.bool", "LowParse.Spec.Enum.enum_repr", "Prims.eq2", "LowParse.Spec.Enum.enum_repr_of_key", "Prims.b2t", "Prims.uu___is_Cons", "Prims.l_True" ]
[]
false
false
false
false
false
let enum_repr_of_key_cons (#key #repr: eqtype) (e: enum key repr) (f: enum_repr_of_key'_t (enum_tail' e)) : Pure (enum_repr_of_key'_t e) (requires (Cons? e)) (ensures (fun _ -> True)) =
(fun (e': list (key * repr) {e' == e}) -> match e' with | (k, r) :: _ -> (fun (x: enum_key e) -> (if k = x then (r <: repr) else (f (x <: key) <: repr)) <: (r: enum_repr e {enum_repr_of_key e x == r}))) e
false
Hacl.Bignum.Definitions.fst
Hacl.Bignum.Definitions.limb_t
val limb_t : Type0
let limb_t = S.limb_t
{ "file_name": "code/bignum/Hacl.Bignum.Definitions.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 21, "end_line": 23, "start_col": 0, "start_line": 23 }
module Hacl.Bignum.Definitions open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module S = Hacl.Spec.Bignum.Definitions #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract val blocks: x:size_t{v x > 0} -> m:size_t{v m > 0} -> r:size_t{v r == S.blocks (v x) (v m)} let blocks x m = (x -. 1ul) /. m +. 1ul inline_for_extraction noextract val blocks0: x:size_t -> m:size_t{v m > 0} -> r:size_t{v r == S.blocks0 (v x) (v m)} let blocks0 x m = if x =. 0ul then 1ul else (x -. 1ul) /. m +. 1ul
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Definitions.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "S" }, { "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.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t" ]
[]
false
false
false
true
true
let limb_t =
S.limb_t
false
Hacl.Bignum.Definitions.fst
Hacl.Bignum.Definitions.limb
val limb : t: Hacl.Bignum.Definitions.limb_t -> Type0
let limb (t:limb_t) = S.limb t
{ "file_name": "code/bignum/Hacl.Bignum.Definitions.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 30, "end_line": 26, "start_col": 0, "start_line": 26 }
module Hacl.Bignum.Definitions open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module S = Hacl.Spec.Bignum.Definitions #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract val blocks: x:size_t{v x > 0} -> m:size_t{v m > 0} -> r:size_t{v r == S.blocks (v x) (v m)} let blocks x m = (x -. 1ul) /. m +. 1ul inline_for_extraction noextract val blocks0: x:size_t -> m:size_t{v m > 0} -> r:size_t{v r == S.blocks0 (v x) (v m)} let blocks0 x m = if x =. 0ul then 1ul else (x -. 1ul) /. m +. 1ul inline_for_extraction noextract let limb_t = S.limb_t
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Definitions.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "S" }, { "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.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Hacl.Bignum.Definitions.limb_t -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.Definitions.limb" ]
[]
false
false
false
true
true
let limb (t: limb_t) =
S.limb t
false
Hacl.Bignum.Definitions.fst
Hacl.Bignum.Definitions.lbignum
val lbignum : t: Hacl.Bignum.Definitions.limb_t -> len: Lib.IntTypes.size_t -> Type0
let lbignum (t:limb_t) len = lbuffer (limb t) len
{ "file_name": "code/bignum/Hacl.Bignum.Definitions.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 49, "end_line": 29, "start_col": 0, "start_line": 29 }
module Hacl.Bignum.Definitions open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module S = Hacl.Spec.Bignum.Definitions #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract val blocks: x:size_t{v x > 0} -> m:size_t{v m > 0} -> r:size_t{v r == S.blocks (v x) (v m)} let blocks x m = (x -. 1ul) /. m +. 1ul inline_for_extraction noextract val blocks0: x:size_t -> m:size_t{v m > 0} -> r:size_t{v r == S.blocks0 (v x) (v m)} let blocks0 x m = if x =. 0ul then 1ul else (x -. 1ul) /. m +. 1ul inline_for_extraction noextract let limb_t = S.limb_t inline_for_extraction noextract let limb (t:limb_t) = S.limb t
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Definitions.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "S" }, { "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.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Hacl.Bignum.Definitions.limb_t -> len: Lib.IntTypes.size_t -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Lib.Buffer.lbuffer", "Hacl.Bignum.Definitions.limb" ]
[]
false
false
false
true
true
let lbignum (t: limb_t) len =
lbuffer (limb t) len
false
FStar.UInt32.fst
FStar.UInt32.v
val v (x:t) : Tot (uint_t n)
val v (x:t) : Tot (uint_t n)
let v x = x.v
{ "file_name": "ulib/FStar.UInt32.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 13, "end_line": 28, "start_col": 0, "start_line": 28 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt32 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" type t : eqtype = | Mk: v:uint_t n -> t
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "FStar.UInt32.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "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 } ]
{ "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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.UInt32.t -> FStar.UInt.uint_t FStar.UInt32.n
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "FStar.UInt32.__proj__Mk__item__v", "FStar.UInt.uint_t", "FStar.UInt32.n" ]
[]
false
false
false
true
false
let v x =
x.v
false
FStar.UInt32.fst
FStar.UInt32.uint_to_t
val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x))
val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x))
let uint_to_t x = Mk x
{ "file_name": "ulib/FStar.UInt32.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 22, "end_line": 31, "start_col": 0, "start_line": 31 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt32 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" type t : eqtype = | Mk: v:uint_t n -> t let v x = x.v
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "FStar.UInt32.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "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 } ]
{ "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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.UInt.uint_t FStar.UInt32.n -> Prims.Pure FStar.UInt32.t
Prims.Pure
[]
[]
[ "FStar.UInt.uint_t", "FStar.UInt32.n", "FStar.UInt32.Mk", "FStar.UInt32.t" ]
[]
false
false
false
false
false
let uint_to_t x =
Mk x
false
FStar.UInt32.fst
FStar.UInt32.one
val one : x:t{v x = 1}
val one : x:t{v x = 1}
let one = uint_to_t 1
{ "file_name": "ulib/FStar.UInt32.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 21, "end_line": 41, "start_col": 0, "start_line": 41 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt32 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" type t : eqtype = | Mk: v:uint_t n -> t let v x = x.v irreducible let uint_to_t x = Mk x let uv_inv _ = () let vu_inv _ = () let v_inj _ _ = () let zero = uint_to_t 0
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "FStar.UInt32.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "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 } ]
{ "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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.UInt32.t{FStar.UInt32.v x = 1}
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.uint_to_t" ]
[]
false
false
false
false
false
let one =
uint_to_t 1
false
Hacl.Bignum.Definitions.fst
Hacl.Bignum.Definitions.blocks
val blocks: x:size_t{v x > 0} -> m:size_t{v m > 0} -> r:size_t{v r == S.blocks (v x) (v m)}
val blocks: x:size_t{v x > 0} -> m:size_t{v m > 0} -> r:size_t{v r == S.blocks (v x) (v m)}
let blocks x m = (x -. 1ul) /. m +. 1ul
{ "file_name": "code/bignum/Hacl.Bignum.Definitions.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 39, "end_line": 16, "start_col": 0, "start_line": 16 }
module Hacl.Bignum.Definitions open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module S = Hacl.Spec.Bignum.Definitions #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Definitions.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "S" }, { "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.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Lib.IntTypes.size_t{Lib.IntTypes.v x > 0} -> m: Lib.IntTypes.size_t{Lib.IntTypes.v m > 0} -> r: Lib.IntTypes.size_t { Lib.IntTypes.v r == Hacl.Spec.Bignum.Definitions.blocks (Lib.IntTypes.v x) (Lib.IntTypes.v m) }
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.op_Plus_Dot", "Lib.IntTypes.op_Slash_Dot", "Lib.IntTypes.op_Subtraction_Dot", "FStar.UInt32.__uint_to_t", "Prims.eq2", "Prims.int", "Prims.l_or", "Lib.IntTypes.range", "Prims.l_and", "Prims.op_LessThanOrEqual", "Lib.IntTypes.max_size_t", "FStar.Mul.op_Star", "Hacl.Spec.Bignum.Definitions.blocks" ]
[]
false
false
false
false
false
let blocks x m =
(x -. 1ul) /. m +. 1ul
false
FStar.UInt32.fst
FStar.UInt32.zero
val zero : x:t{v x = 0}
val zero : x:t{v x = 0}
let zero = uint_to_t 0
{ "file_name": "ulib/FStar.UInt32.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 22, "end_line": 39, "start_col": 0, "start_line": 39 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt32 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" type t : eqtype = | Mk: v:uint_t n -> t let v x = x.v irreducible let uint_to_t x = Mk x let uv_inv _ = () let vu_inv _ = () let v_inj _ _ = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "FStar.UInt32.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "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 } ]
{ "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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.UInt32.t{FStar.UInt32.v x = 0}
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.uint_to_t" ]
[]
false
false
false
false
false
let zero =
uint_to_t 0
false
FStar.UInt32.fst
FStar.UInt32.add
val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c))
val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c))
let add a b = Mk (add (v a) (v b))
{ "file_name": "ulib/FStar.UInt32.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 43, "start_col": 0, "start_line": 43 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt32 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" type t : eqtype = | Mk: v:uint_t n -> t let v x = x.v irreducible let uint_to_t x = Mk x let uv_inv _ = () let vu_inv _ = () let v_inj _ _ = () let zero = uint_to_t 0 let one = uint_to_t 1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "FStar.UInt32.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "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 } ]
{ "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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt32.t -> b: FStar.UInt32.t -> Prims.Pure FStar.UInt32.t
Prims.Pure
[]
[]
[ "FStar.UInt32.t", "FStar.UInt32.Mk", "FStar.UInt.add", "FStar.UInt32.n", "FStar.UInt32.v" ]
[]
false
false
false
false
false
let add a b =
Mk (add (v a) (v b))
false
Hacl.Bignum.Definitions.fst
Hacl.Bignum.Definitions.blocks0
val blocks0: x:size_t -> m:size_t{v m > 0} -> r:size_t{v r == S.blocks0 (v x) (v m)}
val blocks0: x:size_t -> m:size_t{v m > 0} -> r:size_t{v r == S.blocks0 (v x) (v m)}
let blocks0 x m = if x =. 0ul then 1ul else (x -. 1ul) /. m +. 1ul
{ "file_name": "code/bignum/Hacl.Bignum.Definitions.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 66, "end_line": 20, "start_col": 0, "start_line": 20 }
module Hacl.Bignum.Definitions open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module S = Hacl.Spec.Bignum.Definitions #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract val blocks: x:size_t{v x > 0} -> m:size_t{v m > 0} -> r:size_t{v r == S.blocks (v x) (v m)} let blocks x m = (x -. 1ul) /. m +. 1ul inline_for_extraction noextract
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Definitions.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "S" }, { "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.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Lib.IntTypes.size_t -> m: Lib.IntTypes.size_t{Lib.IntTypes.v m > 0} -> r: Lib.IntTypes.size_t { Lib.IntTypes.v r == Hacl.Spec.Bignum.Definitions.blocks0 (Lib.IntTypes.v x) (Lib.IntTypes.v m) }
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.op_Equals_Dot", "FStar.UInt32.__uint_to_t", "Prims.bool", "Lib.IntTypes.op_Plus_Dot", "Lib.IntTypes.op_Slash_Dot", "Lib.IntTypes.op_Subtraction_Dot", "Prims.eq2", "Prims.int", "Prims.l_or", "Lib.IntTypes.range", "Prims.l_and", "Prims.op_LessThanOrEqual", "Lib.IntTypes.max_size_t", "FStar.Mul.op_Star", "Hacl.Spec.Bignum.Definitions.blocks0" ]
[]
false
false
false
false
false
let blocks0 x m =
if x =. 0ul then 1ul else (x -. 1ul) /. m +. 1ul
false
FStar.UInt32.fst
FStar.UInt32.add_mod
val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c))
val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c))
let add_mod a b = Mk (add_mod (v a) (v b))
{ "file_name": "ulib/FStar.UInt32.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 42, "end_line": 47, "start_col": 0, "start_line": 47 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt32 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" type t : eqtype = | Mk: v:uint_t n -> t let v x = x.v irreducible let uint_to_t x = Mk x let uv_inv _ = () let vu_inv _ = () let v_inj _ _ = () let zero = uint_to_t 0 let one = uint_to_t 1 let add a b = Mk (add (v a) (v b)) let add_underspec a b = Mk (add_underspec (v a) (v b))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "FStar.UInt32.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "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 } ]
{ "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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt32.t -> b: FStar.UInt32.t -> Prims.Pure FStar.UInt32.t
Prims.Pure
[]
[]
[ "FStar.UInt32.t", "FStar.UInt32.Mk", "FStar.UInt.add_mod", "FStar.UInt32.n", "FStar.UInt32.v" ]
[]
false
false
false
false
false
let add_mod a b =
Mk (add_mod (v a) (v b))
false
FStar.UInt32.fst
FStar.UInt32.mul_underspec
val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c))
val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c))
let mul_underspec a b = Mk (mul_underspec (v a) (v b))
{ "file_name": "ulib/FStar.UInt32.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 54, "end_line": 57, "start_col": 0, "start_line": 57 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt32 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" type t : eqtype = | Mk: v:uint_t n -> t let v x = x.v irreducible let uint_to_t x = Mk x let uv_inv _ = () let vu_inv _ = () let v_inj _ _ = () let zero = uint_to_t 0 let one = uint_to_t 1 let add a b = Mk (add (v a) (v b)) let add_underspec a b = Mk (add_underspec (v a) (v b)) let add_mod a b = Mk (add_mod (v a) (v b)) let sub a b = Mk (sub (v a) (v b)) let sub_underspec a b = Mk (sub_underspec (v a) (v b)) let sub_mod a b = Mk (sub_mod (v a) (v b)) let mul a b = Mk (mul (v a) (v b))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "FStar.UInt32.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "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 } ]
{ "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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt32.t -> b: FStar.UInt32.t -> Prims.Pure FStar.UInt32.t
Prims.Pure
[]
[]
[ "FStar.UInt32.t", "FStar.UInt32.Mk", "FStar.UInt.mul_underspec", "FStar.UInt32.n", "FStar.UInt32.v" ]
[]
false
false
false
false
false
let mul_underspec a b =
Mk (mul_underspec (v a) (v b))
false
FStar.UInt32.fst
FStar.UInt32.sub_mod
val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c))
val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c))
let sub_mod a b = Mk (sub_mod (v a) (v b))
{ "file_name": "ulib/FStar.UInt32.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 42, "end_line": 53, "start_col": 0, "start_line": 53 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt32 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" type t : eqtype = | Mk: v:uint_t n -> t let v x = x.v irreducible let uint_to_t x = Mk x let uv_inv _ = () let vu_inv _ = () let v_inj _ _ = () let zero = uint_to_t 0 let one = uint_to_t 1 let add a b = Mk (add (v a) (v b)) let add_underspec a b = Mk (add_underspec (v a) (v b)) let add_mod a b = Mk (add_mod (v a) (v b)) let sub a b = Mk (sub (v a) (v b)) let sub_underspec a b = Mk (sub_underspec (v a) (v b))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "FStar.UInt32.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "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 } ]
{ "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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt32.t -> b: FStar.UInt32.t -> Prims.Pure FStar.UInt32.t
Prims.Pure
[]
[]
[ "FStar.UInt32.t", "FStar.UInt32.Mk", "FStar.UInt.sub_mod", "FStar.UInt32.n", "FStar.UInt32.v" ]
[]
false
false
false
false
false
let sub_mod a b =
Mk (sub_mod (v a) (v b))
false
FStar.UInt32.fst
FStar.UInt32.sub
val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c))
val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c))
let sub a b = Mk (sub (v a) (v b))
{ "file_name": "ulib/FStar.UInt32.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 49, "start_col": 0, "start_line": 49 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt32 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" type t : eqtype = | Mk: v:uint_t n -> t let v x = x.v irreducible let uint_to_t x = Mk x let uv_inv _ = () let vu_inv _ = () let v_inj _ _ = () let zero = uint_to_t 0 let one = uint_to_t 1 let add a b = Mk (add (v a) (v b)) let add_underspec a b = Mk (add_underspec (v a) (v b)) let add_mod a b = Mk (add_mod (v a) (v b))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "FStar.UInt32.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "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 } ]
{ "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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt32.t -> b: FStar.UInt32.t -> Prims.Pure FStar.UInt32.t
Prims.Pure
[]
[]
[ "FStar.UInt32.t", "FStar.UInt32.Mk", "FStar.UInt.sub", "FStar.UInt32.n", "FStar.UInt32.v" ]
[]
false
false
false
false
false
let sub a b =
Mk (sub (v a) (v b))
false
FStar.UInt32.fst
FStar.UInt32.add_underspec
val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c))
val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c))
let add_underspec a b = Mk (add_underspec (v a) (v b))
{ "file_name": "ulib/FStar.UInt32.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 54, "end_line": 45, "start_col": 0, "start_line": 45 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt32 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" type t : eqtype = | Mk: v:uint_t n -> t let v x = x.v irreducible let uint_to_t x = Mk x let uv_inv _ = () let vu_inv _ = () let v_inj _ _ = () let zero = uint_to_t 0 let one = uint_to_t 1 let add a b = Mk (add (v a) (v b))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "FStar.UInt32.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "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 } ]
{ "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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt32.t -> b: FStar.UInt32.t -> Prims.Pure FStar.UInt32.t
Prims.Pure
[]
[]
[ "FStar.UInt32.t", "FStar.UInt32.Mk", "FStar.UInt.add_underspec", "FStar.UInt32.n", "FStar.UInt32.v" ]
[]
false
false
false
false
false
let add_underspec a b =
Mk (add_underspec (v a) (v b))
false
FStar.UInt32.fst
FStar.UInt32.lognot
val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z))
val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z))
let lognot x = Mk (lognot (v x))
{ "file_name": "ulib/FStar.UInt32.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 32, "end_line": 71, "start_col": 0, "start_line": 71 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt32 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" type t : eqtype = | Mk: v:uint_t n -> t let v x = x.v irreducible let uint_to_t x = Mk x let uv_inv _ = () let vu_inv _ = () let v_inj _ _ = () let zero = uint_to_t 0 let one = uint_to_t 1 let add a b = Mk (add (v a) (v b)) let add_underspec a b = Mk (add_underspec (v a) (v b)) let add_mod a b = Mk (add_mod (v a) (v b)) let sub a b = Mk (sub (v a) (v b)) let sub_underspec a b = Mk (sub_underspec (v a) (v b)) let sub_mod a b = Mk (sub_mod (v a) (v b)) let mul a b = Mk (mul (v a) (v b)) let mul_underspec a b = Mk (mul_underspec (v a) (v b)) let mul_mod a b = Mk (mul_mod (v a) (v b)) let div a b = Mk (div (v a) (v b)) let rem a b = Mk (mod (v a) (v b)) let logand x y = Mk (logand (v x) (v y)) let logxor x y = Mk (logxor (v x) (v y)) let logor x y = Mk (logor (v x) (v y))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "FStar.UInt32.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "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 } ]
{ "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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.UInt32.t -> Prims.Pure FStar.UInt32.t
Prims.Pure
[]
[]
[ "FStar.UInt32.t", "FStar.UInt32.Mk", "FStar.UInt.lognot", "FStar.UInt32.n", "FStar.UInt32.v" ]
[]
false
false
false
false
false
let lognot x =
Mk (lognot (v x))
false
FStar.UInt32.fst
FStar.UInt32.sub_underspec
val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c))
val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c))
let sub_underspec a b = Mk (sub_underspec (v a) (v b))
{ "file_name": "ulib/FStar.UInt32.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 54, "end_line": 51, "start_col": 0, "start_line": 51 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt32 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" type t : eqtype = | Mk: v:uint_t n -> t let v x = x.v irreducible let uint_to_t x = Mk x let uv_inv _ = () let vu_inv _ = () let v_inj _ _ = () let zero = uint_to_t 0 let one = uint_to_t 1 let add a b = Mk (add (v a) (v b)) let add_underspec a b = Mk (add_underspec (v a) (v b)) let add_mod a b = Mk (add_mod (v a) (v b)) let sub a b = Mk (sub (v a) (v b))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "FStar.UInt32.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "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 } ]
{ "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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt32.t -> b: FStar.UInt32.t -> Prims.Pure FStar.UInt32.t
Prims.Pure
[]
[]
[ "FStar.UInt32.t", "FStar.UInt32.Mk", "FStar.UInt.sub_underspec", "FStar.UInt32.n", "FStar.UInt32.v" ]
[]
false
false
false
false
false
let sub_underspec a b =
Mk (sub_underspec (v a) (v b))
false
FStar.UInt32.fst
FStar.UInt32.rem
val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c))
val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c))
let rem a b = Mk (mod (v a) (v b))
{ "file_name": "ulib/FStar.UInt32.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 63, "start_col": 0, "start_line": 63 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt32 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" type t : eqtype = | Mk: v:uint_t n -> t let v x = x.v irreducible let uint_to_t x = Mk x let uv_inv _ = () let vu_inv _ = () let v_inj _ _ = () let zero = uint_to_t 0 let one = uint_to_t 1 let add a b = Mk (add (v a) (v b)) let add_underspec a b = Mk (add_underspec (v a) (v b)) let add_mod a b = Mk (add_mod (v a) (v b)) let sub a b = Mk (sub (v a) (v b)) let sub_underspec a b = Mk (sub_underspec (v a) (v b)) let sub_mod a b = Mk (sub_mod (v a) (v b)) let mul a b = Mk (mul (v a) (v b)) let mul_underspec a b = Mk (mul_underspec (v a) (v b)) let mul_mod a b = Mk (mul_mod (v a) (v b)) let div a b = Mk (div (v a) (v b))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "FStar.UInt32.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "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 } ]
{ "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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt32.t -> b: FStar.UInt32.t{FStar.UInt32.v b <> 0} -> Prims.Pure FStar.UInt32.t
Prims.Pure
[]
[]
[ "FStar.UInt32.t", "Prims.b2t", "Prims.op_disEquality", "Prims.int", "FStar.UInt32.v", "FStar.UInt32.Mk", "FStar.UInt.mod", "FStar.UInt32.n" ]
[]
false
false
false
false
false
let rem a b =
Mk (mod (v a) (v b))
false
FStar.UInt32.fst
FStar.UInt32.mul
val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c))
val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c))
let mul a b = Mk (mul (v a) (v b))
{ "file_name": "ulib/FStar.UInt32.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 55, "start_col": 0, "start_line": 55 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt32 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" type t : eqtype = | Mk: v:uint_t n -> t let v x = x.v irreducible let uint_to_t x = Mk x let uv_inv _ = () let vu_inv _ = () let v_inj _ _ = () let zero = uint_to_t 0 let one = uint_to_t 1 let add a b = Mk (add (v a) (v b)) let add_underspec a b = Mk (add_underspec (v a) (v b)) let add_mod a b = Mk (add_mod (v a) (v b)) let sub a b = Mk (sub (v a) (v b)) let sub_underspec a b = Mk (sub_underspec (v a) (v b)) let sub_mod a b = Mk (sub_mod (v a) (v b))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "FStar.UInt32.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "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 } ]
{ "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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt32.t -> b: FStar.UInt32.t -> Prims.Pure FStar.UInt32.t
Prims.Pure
[]
[]
[ "FStar.UInt32.t", "FStar.UInt32.Mk", "FStar.UInt.mul", "FStar.UInt32.n", "FStar.UInt32.v" ]
[]
false
false
false
false
false
let mul a b =
Mk (mul (v a) (v b))
false
FStar.UInt32.fst
FStar.UInt32.mul_mod
val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c))
val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c))
let mul_mod a b = Mk (mul_mod (v a) (v b))
{ "file_name": "ulib/FStar.UInt32.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 42, "end_line": 59, "start_col": 0, "start_line": 59 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt32 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" type t : eqtype = | Mk: v:uint_t n -> t let v x = x.v irreducible let uint_to_t x = Mk x let uv_inv _ = () let vu_inv _ = () let v_inj _ _ = () let zero = uint_to_t 0 let one = uint_to_t 1 let add a b = Mk (add (v a) (v b)) let add_underspec a b = Mk (add_underspec (v a) (v b)) let add_mod a b = Mk (add_mod (v a) (v b)) let sub a b = Mk (sub (v a) (v b)) let sub_underspec a b = Mk (sub_underspec (v a) (v b)) let sub_mod a b = Mk (sub_mod (v a) (v b)) let mul a b = Mk (mul (v a) (v b)) let mul_underspec a b = Mk (mul_underspec (v a) (v b))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "FStar.UInt32.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "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 } ]
{ "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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt32.t -> b: FStar.UInt32.t -> Prims.Pure FStar.UInt32.t
Prims.Pure
[]
[]
[ "FStar.UInt32.t", "FStar.UInt32.Mk", "FStar.UInt.mul_mod", "FStar.UInt32.n", "FStar.UInt32.v" ]
[]
false
false
false
false
false
let mul_mod a b =
Mk (mul_mod (v a) (v b))
false
FStar.UInt32.fst
FStar.UInt32.logor
val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z))
val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z))
let logor x y = Mk (logor (v x) (v y))
{ "file_name": "ulib/FStar.UInt32.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 38, "end_line": 69, "start_col": 0, "start_line": 69 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt32 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" type t : eqtype = | Mk: v:uint_t n -> t let v x = x.v irreducible let uint_to_t x = Mk x let uv_inv _ = () let vu_inv _ = () let v_inj _ _ = () let zero = uint_to_t 0 let one = uint_to_t 1 let add a b = Mk (add (v a) (v b)) let add_underspec a b = Mk (add_underspec (v a) (v b)) let add_mod a b = Mk (add_mod (v a) (v b)) let sub a b = Mk (sub (v a) (v b)) let sub_underspec a b = Mk (sub_underspec (v a) (v b)) let sub_mod a b = Mk (sub_mod (v a) (v b)) let mul a b = Mk (mul (v a) (v b)) let mul_underspec a b = Mk (mul_underspec (v a) (v b)) let mul_mod a b = Mk (mul_mod (v a) (v b)) let div a b = Mk (div (v a) (v b)) let rem a b = Mk (mod (v a) (v b)) let logand x y = Mk (logand (v x) (v y)) let logxor x y = Mk (logxor (v x) (v y))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "FStar.UInt32.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "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 } ]
{ "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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.UInt32.t -> y: FStar.UInt32.t -> Prims.Pure FStar.UInt32.t
Prims.Pure
[]
[]
[ "FStar.UInt32.t", "FStar.UInt32.Mk", "FStar.UInt.logor", "FStar.UInt32.n", "FStar.UInt32.v" ]
[]
false
false
false
false
false
let logor x y =
Mk (logor (v x) (v y))
false
FStar.UInt32.fst
FStar.UInt32.logand
val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z))
val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z))
let logand x y = Mk (logand (v x) (v y))
{ "file_name": "ulib/FStar.UInt32.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 40, "end_line": 65, "start_col": 0, "start_line": 65 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt32 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" type t : eqtype = | Mk: v:uint_t n -> t let v x = x.v irreducible let uint_to_t x = Mk x let uv_inv _ = () let vu_inv _ = () let v_inj _ _ = () let zero = uint_to_t 0 let one = uint_to_t 1 let add a b = Mk (add (v a) (v b)) let add_underspec a b = Mk (add_underspec (v a) (v b)) let add_mod a b = Mk (add_mod (v a) (v b)) let sub a b = Mk (sub (v a) (v b)) let sub_underspec a b = Mk (sub_underspec (v a) (v b)) let sub_mod a b = Mk (sub_mod (v a) (v b)) let mul a b = Mk (mul (v a) (v b)) let mul_underspec a b = Mk (mul_underspec (v a) (v b)) let mul_mod a b = Mk (mul_mod (v a) (v b)) let div a b = Mk (div (v a) (v b)) let rem a b = Mk (mod (v a) (v b))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "FStar.UInt32.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "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 } ]
{ "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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.UInt32.t -> y: FStar.UInt32.t -> Prims.Pure FStar.UInt32.t
Prims.Pure
[]
[]
[ "FStar.UInt32.t", "FStar.UInt32.Mk", "FStar.UInt.logand", "FStar.UInt32.n", "FStar.UInt32.v" ]
[]
false
false
false
false
false
let logand x y =
Mk (logand (v x) (v y))
false
FStar.UInt32.fst
FStar.UInt32.logxor
val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z))
val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z))
let logxor x y = Mk (logxor (v x) (v y))
{ "file_name": "ulib/FStar.UInt32.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 40, "end_line": 67, "start_col": 0, "start_line": 67 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt32 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" type t : eqtype = | Mk: v:uint_t n -> t let v x = x.v irreducible let uint_to_t x = Mk x let uv_inv _ = () let vu_inv _ = () let v_inj _ _ = () let zero = uint_to_t 0 let one = uint_to_t 1 let add a b = Mk (add (v a) (v b)) let add_underspec a b = Mk (add_underspec (v a) (v b)) let add_mod a b = Mk (add_mod (v a) (v b)) let sub a b = Mk (sub (v a) (v b)) let sub_underspec a b = Mk (sub_underspec (v a) (v b)) let sub_mod a b = Mk (sub_mod (v a) (v b)) let mul a b = Mk (mul (v a) (v b)) let mul_underspec a b = Mk (mul_underspec (v a) (v b)) let mul_mod a b = Mk (mul_mod (v a) (v b)) let div a b = Mk (div (v a) (v b)) let rem a b = Mk (mod (v a) (v b)) let logand x y = Mk (logand (v x) (v y))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "FStar.UInt32.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "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 } ]
{ "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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.UInt32.t -> y: FStar.UInt32.t -> Prims.Pure FStar.UInt32.t
Prims.Pure
[]
[]
[ "FStar.UInt32.t", "FStar.UInt32.Mk", "FStar.UInt.logxor", "FStar.UInt32.n", "FStar.UInt32.v" ]
[]
false
false
false
false
false
let logxor x y =
Mk (logxor (v x) (v y))
false
OWGCounter.fst
OWGCounter.incr_main
val incr_main (#v: G.erased int) (r: ref int) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm (v + 2))
val incr_main (#v: G.erased int) (r: ref int) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm (v + 2))
let incr_main (#v:G.erased int) (r:ref int) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm (v + 2)) = //allocate the two contribution references let r1 = ghost_alloc_pt (G.hide 0) in let r2 = ghost_alloc_pt v in //split their permissions into half ghost_share_pt r1; rewrite_slprop (ghost_pts_to r1 (P.half_perm P.full_perm) 0 `star` ghost_pts_to r1 (P.half_perm P.full_perm) 0) (ghost_pts_to r1 half_perm 0 `star` ghost_pts_to r1 half_perm 0) (fun _ -> ()); ghost_share_pt r2; rewrite_slprop (ghost_pts_to r2 (P.half_perm P.full_perm) v `star` ghost_pts_to r2 (P.half_perm P.full_perm) v) (ghost_pts_to r2 half_perm v `star` ghost_pts_to r2 half_perm v) (fun _ -> ()); //rewrite the value of `r` to bring it in the shape as expected by the lock rewrite_slprop (pts_to r full_perm v) (pts_to r full_perm (fst (0, G.reveal v) + (snd (0, G.reveal v)))) (fun _ -> ()); //create the lock intro_exists (0, G.reveal v) (lock_inv_pred r r1 r2); let l = new_lock (lock_inv r r1 r2) in let _ = par (incr r r1 r2 true l 0) (incr r r2 r1 false l v) in //take the lock acquire l; let w = witness_exists () in //AR: TODO: these annotations are troubling ghost_gather_pt #_ #_ #_ #_ #(G.hide 1) #(G.hide (fst w)) r1; ghost_gather_pt #_ #_ #_ #_ #(G.hide (v + 1)) #(G.hide (snd w)) r2; drop (ghost_pts_to r1 _ _); drop (ghost_pts_to r2 _ _); rewrite_slprop (pts_to r full_perm (fst w + snd w)) (pts_to r full_perm (v + 2)) (fun _ -> ())
{ "file_name": "share/steel/examples/steel/OWGCounter.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 32, "end_line": 286, "start_col": 0, "start_line": 236 }
(* Copyright 2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) (* * An implementation of the parallel counter presented by Owicki and Gries * "Verifying properties of parallel programs: An axiomatic approach.", CACM'76 * * In this example, the main thread forks two worker thread that both * increment a shared counter. The goal of the example is to show that * after both the worker threads are done, the value of the counter is * its original value + 2. * * See http://pm.inf.ethz.ch/publications/getpdf.php for an implementation * of the OWG counters in the Chalice framework. *) module OWGCounter module G = FStar.Ghost open Steel.Memory open Steel.FractionalPermission open Steel.Reference open Steel.SpinLock open Steel.Effect.Atomic open Steel.Effect module R = Steel.Reference module P = Steel.FractionalPermission module A = Steel.Effect.Atomic #set-options "--ide_id_info_off --using_facts_from '* -FStar.Tactics -FStar.Reflection' --fuel 0 --ifuel 0" let half_perm = half_perm full_perm (* Some basic wrappers to avoid issues with normalization. TODO: The frame inference tactic should not normalize fst and snd*) noextract let fst = fst noextract let snd = snd /// The core invariant of the Owicki-Gries counter, shared by the two parties. /// The concrete counter [r] is shared, and the full permission is stored in the invariant. /// Each party also has half permission to their own ghost counter [r1] or [r2], ensuring that /// only them can modify it by retrieving the other half of the permission when accessing the invariant. /// The `__reduce__` attribute indicates the frame inference tactic to unfold this predicate for frame inference only [@@ __reduce__] let lock_inv_slprop (r:ref int) (r1 r2:ghost_ref int) (w:int & int) = ghost_pts_to r1 half_perm (fst w) `star` ghost_pts_to r2 half_perm (snd w) `star` pts_to r full_perm (fst w + snd w) [@@ __reduce__] let lock_inv_pred (r:ref int) (r1 r2:ghost_ref int) = fun (x:int & int) -> lock_inv_slprop r r1 r2 x /// The actual invariant, existentially quantifying over the values currently stored in the two ghost references [@@ __reduce__] let lock_inv (r:ref int) (r1 r2:ghost_ref int) : vprop = h_exists (lock_inv_pred r r1 r2) #push-options "--warn_error -271 --fuel 1 --ifuel 1" /// A helper lemma to reason about the lock invariant let lock_inv_equiv_lemma (r:ref int) (r1 r2:ghost_ref int) : Lemma (lock_inv r r1 r2 `equiv` lock_inv r r2 r1) = let aux (r:ref int) (r1 r2:ghost_ref int) (m:mem) : Lemma (requires interp (hp_of (lock_inv r r1 r2)) m) (ensures interp (hp_of (lock_inv r r2 r1)) m) [SMTPat ()] = assert ( Steel.Memory.h_exists #(int & int) (fun x -> hp_of (lock_inv_pred r r1 r2 x)) == h_exists_sl #(int & int) (lock_inv_pred r r1 r2)) by (FStar.Tactics.norm [delta_only [`%h_exists_sl]]); let w : G.erased (int & int) = id_elim_exists (fun x -> hp_of (lock_inv_pred r r1 r2 x)) m in assert ((ghost_pts_to r1 half_perm (snd (snd w, fst w)) `star` ghost_pts_to r2 half_perm (fst (snd w, fst w)) `star` pts_to r full_perm (fst (snd w, fst w) + snd (snd w, fst w))) `equiv` (ghost_pts_to r2 half_perm (fst (snd w, fst w)) `star` ghost_pts_to r1 half_perm (snd (snd w, fst w)) `star` pts_to r full_perm (fst (snd w, fst w) + snd (snd w, fst w)))) by (FStar.Tactics.norm [delta_attr [`%__steel_reduce__]]; canon' false (`true_p) (`true_p)); reveal_equiv (ghost_pts_to r1 half_perm (snd (snd w, fst w)) `star` ghost_pts_to r2 half_perm (fst (snd w, fst w)) `star` pts_to r full_perm (fst (snd w, fst w) + snd (snd w, fst w))) (ghost_pts_to r2 half_perm (fst (snd w, fst w)) `star` ghost_pts_to r1 half_perm (snd (snd w, fst w)) `star` pts_to r full_perm (fst (snd w, fst w) + snd (snd w, fst w))); assert (interp (hp_of (lock_inv_pred r r2 r1 (snd w, fst w))) m); intro_h_exists (snd w, fst w) (fun x -> hp_of (lock_inv_pred r r2 r1 x)) m; assert (interp (Steel.Memory.h_exists (fun x -> hp_of (lock_inv_pred r r2 r1 x))) m); assert ( Steel.Memory.h_exists #(int & int) (fun x -> hp_of (lock_inv_pred r r2 r1 x)) == h_exists_sl #(int & int) (lock_inv_pred r r2 r1)) by (FStar.Tactics.norm [delta_only [`%h_exists_sl]]) in reveal_equiv (lock_inv r r1 r2) (lock_inv r r2 r1) #pop-options /// Acquiring the shared lock invariant inline_for_extraction noextract let og_acquire (r:ref int) (r_mine r_other:ghost_ref int) (b:G.erased bool) (l:lock (lock_inv r (if b then r_mine else r_other) (if b then r_other else r_mine))) : SteelT unit emp (fun _ -> lock_inv r r_mine r_other) = acquire l; if b then begin rewrite_slprop (lock_inv r (if b then r_mine else r_other) (if b then r_other else r_mine)) (lock_inv r r_mine r_other) (fun _ -> ()); () end else begin rewrite_slprop (lock_inv r (if b then r_mine else r_other) (if b then r_other else r_mine)) (lock_inv r r_other r_mine) (fun _ -> ()); lock_inv_equiv_lemma r r_other r_mine; rewrite_slprop (lock_inv r r_other r_mine) (lock_inv r r_mine r_other) (fun _ -> reveal_equiv (lock_inv r r_other r_mine) (lock_inv r r_mine r_other)) end /// Releasing the shared lock invariant inline_for_extraction noextract let og_release (r:ref int) (r_mine r_other:ghost_ref int) (b:G.erased bool) (l:lock (lock_inv r (if b then r_mine else r_other) (if b then r_other else r_mine))) : SteelT unit (lock_inv r r_mine r_other) (fun _ -> emp) = if b then begin rewrite_slprop (lock_inv r r_mine r_other) (lock_inv r (if b then r_mine else r_other) (if b then r_other else r_mine)) (fun _ -> ()); () end else begin lock_inv_equiv_lemma r r_mine r_other; rewrite_slprop (lock_inv r r_mine r_other) (lock_inv r r_other r_mine) (fun _ -> reveal_equiv (lock_inv r r_mine r_other) (lock_inv r r_other r_mine)); rewrite_slprop (lock_inv r r_other r_mine) (lock_inv r (if b then r_mine else r_other) (if b then r_other else r_mine)) (fun _ -> ()) end; release l inline_for_extraction noextract let incr_ctr (#v:G.erased int) (r:ref int) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm (v+1)) = let n = R.read_pt r in R.write_pt r (n+1); rewrite_slprop (pts_to r full_perm (n + 1)) (pts_to r full_perm (v+1)) (fun _ -> ()) inline_for_extraction noextract let rewrite_perm(#a:Type) (#v:G.erased a) (r:ghost_ref a) (p1 p2:P.perm) : Steel unit (ghost_pts_to r p1 v) (fun _ -> ghost_pts_to r p2 v) (fun _ -> p1 == p2) (fun _ _ _ -> True) = rewrite_slprop (ghost_pts_to r p1 v) (ghost_pts_to r p2 v) (fun _ -> ()) inline_for_extraction noextract let incr_ghost_contrib (#v1 #v2:G.erased int) (r:ghost_ref int) : Steel unit (ghost_pts_to r half_perm v1 `star` ghost_pts_to r half_perm v2) (fun _ -> ghost_pts_to r half_perm (v1+1) `star` ghost_pts_to r half_perm (v2+1)) (fun _ -> True) (fun _ _ _ -> v1 == v2) = ghost_gather_pt #_ #_ #half_perm #half_perm #v1 #v2 r; rewrite_perm r (sum_perm half_perm half_perm) full_perm; ghost_write_pt r (v1+1); ghost_share_pt r; rewrite_slprop (ghost_pts_to r (P.half_perm P.full_perm) (v1+1) `star` ghost_pts_to r (P.half_perm P.full_perm) (v1+1)) (ghost_pts_to r half_perm (v1+1) `star` ghost_pts_to r half_perm (v2+1)) (fun _ -> ()) let incr (r:ref int) (r_mine r_other:ghost_ref int) (b:G.erased bool) (l:lock (lock_inv r (if b then r_mine else r_other) (if b then r_other else r_mine))) (n_ghost:G.erased int) () : SteelT unit (ghost_pts_to r_mine half_perm n_ghost) (fun _ -> ghost_pts_to r_mine half_perm (n_ghost + 1)) = og_acquire r r_mine r_other b l; let w : G.erased (int & int) = witness_exists () in incr_ctr r; incr_ghost_contrib #n_ghost #(fst w) r_mine; rewrite_slprop (pts_to r full_perm ((fst w + snd w) + 1)) (pts_to r full_perm ((fst w + 1) + snd w)) (fun _ -> ()); intro_exists (fst w + 1, snd w) (lock_inv_pred r r_mine r_other); og_release r r_mine r_other b l
{ "checked_file": "/", "dependencies": [ "Steel.SpinLock.fsti.checked", "Steel.Reference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "OWGCounter.fst" }
[ { "abbrev": true, "full_module": "Steel.Effect.Atomic", "short_module": "A" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": true, "full_module": "Steel.Reference", "short_module": "R" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.SpinLock", "short_module": null }, { "abbrev": false, "full_module": "Steel.Reference", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Steel.Reference.ref Prims.int -> Steel.Effect.SteelT Prims.unit
Steel.Effect.SteelT
[]
[]
[ "FStar.Ghost.erased", "Prims.int", "Steel.Reference.ref", "Steel.Effect.Atomic.rewrite_slprop", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Reference.pts_to", "Steel.FractionalPermission.full_perm", "Prims.op_Addition", "OWGCounter.fst", "FStar.Ghost.reveal", "FStar.Pervasives.Native.tuple2", "OWGCounter.snd", "Steel.Memory.mem", "Prims.unit", "Steel.Effect.Atomic.drop", "Steel.Reference.ghost_pts_to", "Steel.FractionalPermission.sum_perm", "OWGCounter.half_perm", "Steel.Reference.ghost_gather_pt", "Steel.Effect.Atomic.witness_exists", "Steel.Effect.Common.VStar", "Steel.Effect.Common.vprop", "Steel.SpinLock.acquire", "OWGCounter.lock_inv", "Steel.Effect.par", "OWGCounter.incr", "Prims.bool", "Steel.SpinLock.lock", "Steel.SpinLock.new_lock", "Steel.Effect.Atomic.intro_exists", "FStar.Pervasives.Native.Mktuple2", "OWGCounter.lock_inv_pred", "Steel.Effect.Common.star", "Steel.FractionalPermission.half_perm", "Steel.Reference.ghost_share_pt", "Steel.Reference.ghost_ref", "Steel.Reference.ghost_alloc_pt" ]
[]
false
true
false
false
false
let incr_main (#v: G.erased int) (r: ref int) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm (v + 2)) =
let r1 = ghost_alloc_pt (G.hide 0) in let r2 = ghost_alloc_pt v in ghost_share_pt r1; rewrite_slprop ((ghost_pts_to r1 (P.half_perm P.full_perm) 0) `star` (ghost_pts_to r1 (P.half_perm P.full_perm) 0)) ((ghost_pts_to r1 half_perm 0) `star` (ghost_pts_to r1 half_perm 0)) (fun _ -> ()); ghost_share_pt r2; rewrite_slprop ((ghost_pts_to r2 (P.half_perm P.full_perm) v) `star` (ghost_pts_to r2 (P.half_perm P.full_perm) v)) ((ghost_pts_to r2 half_perm v) `star` (ghost_pts_to r2 half_perm v)) (fun _ -> ()); rewrite_slprop (pts_to r full_perm v) (pts_to r full_perm (fst (0, G.reveal v) + (snd (0, G.reveal v)))) (fun _ -> ()); intro_exists (0, G.reveal v) (lock_inv_pred r r1 r2); let l = new_lock (lock_inv r r1 r2) in let _ = par (incr r r1 r2 true l 0) (incr r r2 r1 false l v) in acquire l; let w = witness_exists () in ghost_gather_pt #_ #_ #_ #_ #(G.hide 1) #(G.hide (fst w)) r1; ghost_gather_pt #_ #_ #_ #_ #(G.hide (v + 1)) #(G.hide (snd w)) r2; drop (ghost_pts_to r1 _ _); drop (ghost_pts_to r2 _ _); rewrite_slprop (pts_to r full_perm (fst w + snd w)) (pts_to r full_perm (v + 2)) (fun _ -> ())
false
FStar.UInt32.fst
FStar.UInt32.div
val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c))
val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c))
let div a b = Mk (div (v a) (v b))
{ "file_name": "ulib/FStar.UInt32.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 61, "start_col": 0, "start_line": 61 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt32 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" type t : eqtype = | Mk: v:uint_t n -> t let v x = x.v irreducible let uint_to_t x = Mk x let uv_inv _ = () let vu_inv _ = () let v_inj _ _ = () let zero = uint_to_t 0 let one = uint_to_t 1 let add a b = Mk (add (v a) (v b)) let add_underspec a b = Mk (add_underspec (v a) (v b)) let add_mod a b = Mk (add_mod (v a) (v b)) let sub a b = Mk (sub (v a) (v b)) let sub_underspec a b = Mk (sub_underspec (v a) (v b)) let sub_mod a b = Mk (sub_mod (v a) (v b)) let mul a b = Mk (mul (v a) (v b)) let mul_underspec a b = Mk (mul_underspec (v a) (v b)) let mul_mod a b = Mk (mul_mod (v a) (v b))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "FStar.UInt32.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "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 } ]
{ "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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt32.t -> b: FStar.UInt32.t{FStar.UInt32.v b <> 0} -> Prims.Pure FStar.UInt32.t
Prims.Pure
[]
[]
[ "FStar.UInt32.t", "Prims.b2t", "Prims.op_disEquality", "Prims.int", "FStar.UInt32.v", "FStar.UInt32.Mk", "FStar.UInt.div", "FStar.UInt32.n" ]
[]
false
false
false
false
false
let div a b =
Mk (div (v a) (v b))
false
FStar.UInt32.fst
FStar.UInt32.shift_left
val shift_left (a:t) (s:t) : Pure t (requires (v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (v s) = v c))
val shift_left (a:t) (s:t) : Pure t (requires (v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (v s) = v c))
let shift_left a s = Mk (shift_left (v a) (v s))
{ "file_name": "ulib/FStar.UInt32.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 48, "end_line": 77, "start_col": 0, "start_line": 77 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt32 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" type t : eqtype = | Mk: v:uint_t n -> t let v x = x.v irreducible let uint_to_t x = Mk x let uv_inv _ = () let vu_inv _ = () let v_inj _ _ = () let zero = uint_to_t 0 let one = uint_to_t 1 let add a b = Mk (add (v a) (v b)) let add_underspec a b = Mk (add_underspec (v a) (v b)) let add_mod a b = Mk (add_mod (v a) (v b)) let sub a b = Mk (sub (v a) (v b)) let sub_underspec a b = Mk (sub_underspec (v a) (v b)) let sub_mod a b = Mk (sub_mod (v a) (v b)) let mul a b = Mk (mul (v a) (v b)) let mul_underspec a b = Mk (mul_underspec (v a) (v b)) let mul_mod a b = Mk (mul_mod (v a) (v b)) let div a b = Mk (div (v a) (v b)) let rem a b = Mk (mod (v a) (v b)) let logand x y = Mk (logand (v x) (v y)) let logxor x y = Mk (logxor (v x) (v y)) let logor x y = Mk (logor (v x) (v y)) let lognot x = Mk (lognot (v x)) let shift_right a s = Mk (shift_right (v a) (v s)) #push-options "--z3rlimit 80 --fuel 1" //AR: working around the interleaving semantics of pragmas
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "FStar.UInt32.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "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": 80, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt32.t -> s: FStar.UInt32.t -> Prims.Pure FStar.UInt32.t
Prims.Pure
[]
[]
[ "FStar.UInt32.t", "FStar.UInt32.Mk", "FStar.UInt.shift_left", "FStar.UInt32.n", "FStar.UInt32.v" ]
[]
false
false
false
false
false
let shift_left a s =
Mk (shift_left (v a) (v s))
false
Steel.ST.C.Types.Union.fsti
Steel.ST.C.Types.Union.ununion_field_and_drop
val ununion_field_and_drop (#opened: _) (#tn #tf: Type0) (#n: string) (#fields: field_description_t tf) (r: ref (union0 tn n fields)) (field: field_t fields) (#t': Type0) (#td': typedef t') (#v': Ghost.erased t') (r': ref td') : STGhost (Ghost.erased (union_t0 tn n fields)) opened ((has_union_field r field r') `star` (pts_to r' v')) (fun res -> pts_to r res) True (fun res -> t' == fields.fd_type field /\ td' == fields.fd_typedef field /\ Ghost.reveal res == union_set_field tn n fields field (coerce_eq () (Ghost.reveal v')))
val ununion_field_and_drop (#opened: _) (#tn #tf: Type0) (#n: string) (#fields: field_description_t tf) (r: ref (union0 tn n fields)) (field: field_t fields) (#t': Type0) (#td': typedef t') (#v': Ghost.erased t') (r': ref td') : STGhost (Ghost.erased (union_t0 tn n fields)) opened ((has_union_field r field r') `star` (pts_to r' v')) (fun res -> pts_to r res) True (fun res -> t' == fields.fd_type field /\ td' == fields.fd_typedef field /\ Ghost.reveal res == union_set_field tn n fields field (coerce_eq () (Ghost.reveal v')))
let ununion_field_and_drop (#opened: _) (#tn: Type0) (#tf: Type0) (#n: string) (#fields: field_description_t tf) (r: ref (union0 tn n fields)) (field: field_t fields) (#t': Type0) (#td': typedef t') (#v': Ghost.erased t') (r': ref td') : STGhost (Ghost.erased (union_t0 tn n fields)) opened (has_union_field r field r' `star` pts_to r' v') (fun res -> pts_to r res) True (fun res -> t' == fields.fd_type field /\ td' == fields.fd_typedef field /\ Ghost.reveal res == union_set_field tn n fields field (coerce_eq () (Ghost.reveal v')) ) = let res = ununion_field r field r' in drop (has_union_field _ _ _); res
{ "file_name": "lib/steel/c/Steel.ST.C.Types.Union.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 5, "end_line": 458, "start_col": 0, "start_line": 435 }
module Steel.ST.C.Types.Union open Steel.ST.Util include Steel.ST.C.Types.Fields open Steel.C.Typestring module P = Steel.FractionalPermission [@@noextract_to "krml"] // primitive val define_union0 (tn: Type0) (#tf: Type0) (n: string) (fields: field_description_t tf) : Tot Type0 inline_for_extraction [@@noextract_to "krml"] let define_union (n: string) (#tf: Type0) (#tn: Type0) (#[solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: field_description_t tf) : Tot Type0 = define_union0 tn #tf n fields // To be extracted as: union t [@@noextract_to "krml"] // primitive val union_t0 (tn: Type0) (#tf: Type0) (n: string) (fields: field_description_t tf) : Tot Type0 inline_for_extraction [@@noextract_to "krml"] let union_t (#tf: Type0) (n: string) (#tn: Type0) (# [solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: field_description_t tf) : Tot Type0 = union_t0 tn #tf n fields val union_set_field (tn: Type0) (#tf: Type0) (n: string) (fields: field_description_t tf) (f: field_t fields) (v: fields.fd_type f) : GTot (union_t0 tn n fields) val union_get_case (#tn: Type0) (#tf: Type0) (#n: string) (#fields: field_description_t tf) (u: union_t0 tn n fields) : GTot (option (field_t fields)) val union_get_field (#tn: Type0) (#tf: Type0) (#n: string) (#fields: field_description_t tf) (u: union_t0 tn n fields) (field: field_t fields) : Ghost (fields.fd_type field) (requires (union_get_case u == Some field)) (ensures (fun _ -> True)) val union_get_field_same (tn: Type0) (#tf: Type0) (n: string) (fields: field_description_t tf) (field: field_t fields) (v: fields.fd_type field) : Lemma (requires (~ (v == unknown (fields.fd_typedef field)))) (ensures ( let u = union_set_field tn n fields field v in union_get_case u == Some field /\ union_get_field u field == v )) [SMTPatOr [ [SMTPat (union_get_case (union_set_field tn n fields field v))]; [SMTPat (union_get_field (union_set_field tn n fields field v) field)]; ]] val union_set_field_same (#tn: Type0) (#tf: Type0) (#n: string) (#fields: field_description_t tf) (s: union_t0 tn n fields) (field: field_t fields) : Lemma (requires (union_get_case s == Some field)) (ensures ( union_set_field tn n fields field (union_get_field s field) == s )) [SMTPat (union_set_field tn n fields (union_get_field s field))] [@@noextract_to "krml"] // proof-only val union0 (tn: Type0) (#tf: Type0) (n: string) (fields: field_description_t tf) : Tot (typedef (union_t0 tn n fields)) inline_for_extraction [@@noextract_to "krml"; norm_field_attr] // proof-only let union (#tf: Type0) (n: string) (#tn: Type0) (# [solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: field_description_t tf) : Tot (typedef (union_t0 tn n fields)) = union0 tn #tf n fields val union_get_case_unknown (tn: Type0) (#tf: Type0) (n: string) (fields: field_description_t tf) : Lemma (union_get_case (unknown (union0 tn n fields)) == None) [SMTPat (unknown (union0 tn n fields))] val union_set_field_unknown (tn: Type0) (#tf: Type0) (n: string) (fields: field_description_t tf) (field: field_t fields) : Lemma (union_set_field tn n fields field (unknown (fields.fd_typedef field)) == unknown (union0 tn n fields)) [SMTPat (union_set_field tn n fields field (unknown (fields.fd_typedef field)))] val union_get_case_uninitialized (tn: Type0) (#tf: Type0) (n: string) (fields: field_description_t tf) : Lemma (union_get_case (uninitialized (union0 tn n fields)) == None) [SMTPat (uninitialized (union0 tn n fields))] val mk_fraction_union_get_case (#tn: Type0) (#tf: Type0) (#n: string) (#fields: field_description_t tf) (s: union_t0 tn n fields) (p: P.perm) : Lemma (requires (fractionable (union0 tn n fields) s)) (ensures ( union_get_case (mk_fraction (union0 tn n fields) s p) == union_get_case s )) [SMTPat (union_get_case (mk_fraction (union0 tn n fields) s p))] val fractionable_union_get_field (#tn: Type0) (#tf: Type0) (#n: string) (#fields: field_description_t tf) (s: union_t0 tn n fields) (field: field_t fields) : Lemma (requires (union_get_case s == Some field)) (ensures ( fractionable (union0 tn n fields) s <==> fractionable (fields.fd_typedef field) (union_get_field s field) )) [SMTPat (fractionable (union0 tn n fields) s); SMTPat (union_get_field s field)] val mk_fraction_union_get_field (#tn: Type0) (#tf: Type0) (#n: string) (#fields: field_description_t tf) (s: union_t0 tn n fields) (p: P.perm) (field: field_t fields) : Lemma (requires (fractionable (union0 tn n fields) s /\ union_get_case s == Some field)) (ensures (union_get_field (mk_fraction (union0 tn n fields) s p) field == mk_fraction (fields.fd_typedef field) (union_get_field s field) p)) [SMTPat (union_get_field (mk_fraction (union0 tn n fields) s p) field)] val mk_fraction_union_set_field (tn: Type0) (#tf: Type0) (n: string) (fields: field_description_t tf) (field: field_t fields) (v: fields.fd_type field) (p: P.perm) : Lemma (requires (fractionable (fields.fd_typedef field) v)) (ensures ( fractionable (union0 tn n fields) (union_set_field tn n fields field v) /\ mk_fraction (union0 tn n fields) (union_set_field tn n fields field v) p == union_set_field tn n fields field (mk_fraction (fields.fd_typedef field) v p) )) val full_union (#tn: Type0) (#tf: Type0) (#n: string) (#fields: field_description_t tf) (s: union_t0 tn n fields) (field: field_t fields) : Lemma (requires (union_get_case s == Some field)) (ensures ( full (union0 tn n fields) s <==> full (fields.fd_typedef field) (union_get_field s field) )) [SMTPat (full (union0 tn n fields) s); SMTPat (union_get_field s field)] let full_union_set_field_intro (#tn: Type0) (#tf: Type0) (#n: string) (#fields: field_description_t tf) (field: field_t fields) (v: fields.fd_type field) : Lemma (requires (full (fields.fd_typedef field) v)) (ensures ( full (union0 tn n fields) (union_set_field tn n fields field v) )) = full_union (union_set_field tn n fields field v) field let full_union_set_field_elim (#tn: Type0) (#tf: Type0) (#n: string) (#fields: field_description_t tf) (field: field_t fields) (v: fields.fd_type field) : Lemma (requires ( full (union0 tn n fields) (union_set_field tn n fields field v) )) (ensures ( full (fields.fd_typedef field) v )) = full_union (union_set_field tn n fields field v) field let full_union_set_field (#tn: Type0) (#tf: Type0) (#n: string) (#fields: field_description_t tf) (field: field_t fields) (v: fields.fd_type field) : Lemma (requires True) (ensures ( full (union0 tn n fields) (union_set_field tn n fields field v) <==> full (fields.fd_typedef field) v )) [SMTPat (full (union0 tn n fields) (union_set_field tn n fields field v))] = Classical.move_requires (full_union_set_field_intro #tn #tf #n #fields field) v; Classical.move_requires (full_union_set_field_elim #tn #tf #n #fields field) v val has_union_field (#tn: Type0) (#tf: Type0) (#n: string) (#fields: field_description_t tf) (r: ref (union0 tn n fields)) (field: field_t fields) (#t': Type0) (#td': typedef t') (r': ref td') : Tot vprop val has_union_field_prop (#opened: _) (#tn: Type0) (#tf: Type0) (#n: string) (#fields: field_description_t tf) (r: ref (union0 tn n fields)) (field: field_t fields) (#t': Type0) (#td': typedef t') (r': ref td') : STGhost unit opened (has_union_field r field r') (fun _ -> has_union_field r field r') True (fun _ -> t' == fields.fd_type field /\ td' == fields.fd_typedef field ) val has_union_field_dup (#opened: _) (#tn: Type0) (#tf: Type0) (#n: string) (#fields: nonempty_field_description_t tf) (r: ref (union0 tn n fields)) (field: field_t fields) (#t': Type0) (#td': typedef t') (r': ref td') : STGhostT unit opened (has_union_field r field r') (fun _ -> has_union_field r field r' `star` has_union_field r field r') val has_union_field_inj (#opened: _) (#tn: Type0) (#tf: Type0) (#n: string) (#fields: nonempty_field_description_t tf) (r: ref (union0 tn n fields)) (field: field_t fields) (#t1: Type0) (#td1: typedef t1) (r1: ref td1) (#t2: Type0) (#td2: typedef t2) (r2: ref td2) : STGhostT (squash (t1 == t2 /\ td1 == td2)) opened (has_union_field r field r1 `star` has_union_field r field r2) (fun _ -> has_union_field r field r1 `star` has_union_field r field r2 `star` ref_equiv r1 (coerce_eq () r2)) val has_union_field_equiv_from (#opened: _) (#tn: Type0) (#tf: Type0) (#n: string) (#fields: nonempty_field_description_t tf) (r1 r2: ref (union0 tn n fields)) (field: field_t fields) (#t': Type0) (#td': typedef t') (r': ref td') : STGhostT unit opened (has_union_field r1 field r' `star` ref_equiv r1 r2) (fun _ -> has_union_field r2 field r' `star` ref_equiv r1 r2) val has_union_field_equiv_to (#opened: _) (#tn: Type0) (#tf: Type0) (#n: string) (#fields: nonempty_field_description_t tf) (r: ref (union0 tn n fields)) (field: field_t fields) (#t': Type0) (#td': typedef t') (r1 r2: ref td') : STGhostT unit opened (has_union_field r field r1 `star` ref_equiv r1 r2) (fun _ -> has_union_field r field r2 `star` ref_equiv r1 r2) val ghost_union_field_focus (#opened: _) (#tn: Type0) (#tf: Type0) (#n: string) (#fields: field_description_t tf) (#v: Ghost.erased (union_t0 tn n fields)) (r: ref (union0 tn n fields)) (field: field_t fields {union_get_case v == Some field}) (#t': Type0) (#td': typedef t') (r': ref td') : STGhostT (squash ( t' == fields.fd_type field /\ td' == fields.fd_typedef field )) opened (has_union_field r field r' `star` pts_to r v) (fun _ -> has_union_field r field r' `star` pts_to r' (Ghost.hide (coerce_eq () (union_get_field v field)))) val ghost_union_field (#opened: _) (#tn: Type0) (#tf: Type0) (#n: string) (#fields: field_description_t tf) (#v: Ghost.erased (union_t0 tn n fields)) (r: ref (union0 tn n fields)) (field: field_t fields {union_get_case v == Some field}) : STGhostT (Ghost.erased (ref (fields.fd_typedef field))) opened (pts_to r v) (fun r' -> has_union_field r field r' `star` pts_to r' (union_get_field v field)) [@@noextract_to "krml"] // primitive val union_field0 (#tn: Type0) (#tf: Type0) (t': Type0) (#n: string) (#fields: field_description_t tf) (#v: Ghost.erased (union_t0 tn n fields)) (r: ref (union0 tn n fields)) (field: field_t fields {union_get_case v == Some field}) (td': typedef t' { t' == fields.fd_type field /\ td' == fields.fd_typedef field }) : STT (ref td') (pts_to r v) (fun r' -> has_union_field r field r' `star` pts_to r' (Ghost.hide (coerce_eq () (union_get_field v field)))) inline_for_extraction [@@noextract_to "krml"] let union_field1 (#tn: Type0) (#tf: Type0) (t': Type0) (#n: string) (#fields: field_description_t tf) (#v: Ghost.erased (union_t0 tn n fields)) (r: ref (union0 tn n fields)) (field: field_t fields {union_get_case v == Some field}) (td': typedef t') (sq_t': squash (t' == fields.fd_type field)) (sq_td': squash (td' == fields.fd_typedef field)) : STT (ref td') (pts_to r v) (fun r' -> has_union_field r field r' `star` pts_to r' (union_get_field v field)) = union_field0 t' r field td' inline_for_extraction [@@noextract_to "krml"] // primitive let union_field (#tn: Type0) (#tf: Type0) (#n: string) (#fields: field_description_t tf) (#v: Ghost.erased (union_t0 tn n fields)) (r: ref (union0 tn n fields)) (field: field_t fields {union_get_case v == Some field}) (#t': Type0) (#td': typedef t') (# [ norm_fields () ] sq_t': squash (t' == fields.fd_type field)) (# [ norm_fields () ] sq_td': squash (td' == fields.fd_typedef field)) () : STT (ref td') (pts_to r v) (fun r' -> has_union_field r field r' `star` pts_to r' (union_get_field v field)) = union_field0 t' r field td' val ununion_field (#opened: _) (#tn: Type0) (#tf: Type0) (#n: string) (#fields: field_description_t tf) (r: ref (union0 tn n fields)) (field: field_t fields) (#t': Type0) (#td': typedef t') (#v': Ghost.erased t') (r': ref td') : STGhost (Ghost.erased (union_t0 tn n fields)) opened (has_union_field r field r' `star` pts_to r' v') (fun res -> has_union_field r field r' `star` pts_to r res) True (fun res -> t' == fields.fd_type field /\ td' == fields.fd_typedef field /\ Ghost.reveal res == union_set_field tn n fields field (coerce_eq () (Ghost.reveal v')) )
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.C.Types.Fields.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.C.Typestring.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.C.Types.Union.fsti" }
[ { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.C.Typestring", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types.Fields", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Steel.ST.C.Types.Base.ref (Steel.ST.C.Types.Union.union0 tn n fields) -> field: Steel.ST.C.Types.Fields.field_t fields -> r': Steel.ST.C.Types.Base.ref td' -> Steel.ST.Effect.Ghost.STGhost (FStar.Ghost.erased (Steel.ST.C.Types.Union.union_t0 tn n fields))
Steel.ST.Effect.Ghost.STGhost
[]
[]
[ "Steel.Memory.inames", "Prims.string", "Steel.ST.C.Types.Fields.field_description_t", "Steel.ST.C.Types.Base.ref", "Steel.ST.C.Types.Union.union_t0", "Steel.ST.C.Types.Union.union0", "Steel.ST.C.Types.Fields.field_t", "Steel.ST.C.Types.Base.typedef", "FStar.Ghost.erased", "Prims.unit", "Steel.ST.Util.drop", "Steel.ST.C.Types.Union.has_union_field", "Steel.ST.C.Types.Union.ununion_field", "Steel.Effect.Common.star", "Steel.ST.C.Types.Base.pts_to", "Steel.Effect.Common.vprop", "Prims.l_True", "Prims.l_and", "Prims.eq2", "Steel.ST.C.Types.Fields.__proj__Mkfield_description_t__item__fd_type", "Steel.ST.C.Types.Fields.__proj__Mkfield_description_t__item__fd_typedef", "FStar.Ghost.reveal", "Steel.ST.C.Types.Union.union_set_field", "FStar.Pervasives.coerce_eq" ]
[]
false
true
false
false
false
let ununion_field_and_drop (#opened: _) (#tn #tf: Type0) (#n: string) (#fields: field_description_t tf) (r: ref (union0 tn n fields)) (field: field_t fields) (#t': Type0) (#td': typedef t') (#v': Ghost.erased t') (r': ref td') : STGhost (Ghost.erased (union_t0 tn n fields)) opened ((has_union_field r field r') `star` (pts_to r' v')) (fun res -> pts_to r res) True (fun res -> t' == fields.fd_type field /\ td' == fields.fd_typedef field /\ Ghost.reveal res == union_set_field tn n fields field (coerce_eq () (Ghost.reveal v'))) =
let res = ununion_field r field r' in drop (has_union_field _ _ _); res
false
FStar.UInt32.fst
FStar.UInt32.shift_right
val shift_right (a:t) (s:t) : Pure t (requires (v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (v s) = v c))
val shift_right (a:t) (s:t) : Pure t (requires (v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (v s) = v c))
let shift_right a s = Mk (shift_right (v a) (v s))
{ "file_name": "ulib/FStar.UInt32.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 50, "end_line": 73, "start_col": 0, "start_line": 73 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt32 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" type t : eqtype = | Mk: v:uint_t n -> t let v x = x.v irreducible let uint_to_t x = Mk x let uv_inv _ = () let vu_inv _ = () let v_inj _ _ = () let zero = uint_to_t 0 let one = uint_to_t 1 let add a b = Mk (add (v a) (v b)) let add_underspec a b = Mk (add_underspec (v a) (v b)) let add_mod a b = Mk (add_mod (v a) (v b)) let sub a b = Mk (sub (v a) (v b)) let sub_underspec a b = Mk (sub_underspec (v a) (v b)) let sub_mod a b = Mk (sub_mod (v a) (v b)) let mul a b = Mk (mul (v a) (v b)) let mul_underspec a b = Mk (mul_underspec (v a) (v b)) let mul_mod a b = Mk (mul_mod (v a) (v b)) let div a b = Mk (div (v a) (v b)) let rem a b = Mk (mod (v a) (v b)) let logand x y = Mk (logand (v x) (v y)) let logxor x y = Mk (logxor (v x) (v y)) let logor x y = Mk (logor (v x) (v y)) let lognot x = Mk (lognot (v x))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "FStar.UInt32.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "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 } ]
{ "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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt32.t -> s: FStar.UInt32.t -> Prims.Pure FStar.UInt32.t
Prims.Pure
[]
[]
[ "FStar.UInt32.t", "FStar.UInt32.Mk", "FStar.UInt.shift_right", "FStar.UInt32.n", "FStar.UInt32.v" ]
[]
false
false
false
false
false
let shift_right a s =
Mk (shift_right (v a) (v s))
false
Hacl.Bignum.Definitions.fst
Hacl.Bignum.Definitions.bn_v
val bn_v: #t:limb_t -> #len:size_t -> h:mem -> b:lbignum t len -> GTot nat
val bn_v: #t:limb_t -> #len:size_t -> h:mem -> b:lbignum t len -> GTot nat
let bn_v #t #len h b = S.bn_v #t #(v len) (as_seq h b)
{ "file_name": "code/bignum/Hacl.Bignum.Definitions.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 54, "end_line": 33, "start_col": 0, "start_line": 33 }
module Hacl.Bignum.Definitions open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module S = Hacl.Spec.Bignum.Definitions #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract val blocks: x:size_t{v x > 0} -> m:size_t{v m > 0} -> r:size_t{v r == S.blocks (v x) (v m)} let blocks x m = (x -. 1ul) /. m +. 1ul inline_for_extraction noextract val blocks0: x:size_t -> m:size_t{v m > 0} -> r:size_t{v r == S.blocks0 (v x) (v m)} let blocks0 x m = if x =. 0ul then 1ul else (x -. 1ul) /. m +. 1ul inline_for_extraction noextract let limb_t = S.limb_t inline_for_extraction noextract let limb (t:limb_t) = S.limb t inline_for_extraction noextract let lbignum (t:limb_t) len = lbuffer (limb t) len noextract
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Definitions.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "S" }, { "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.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> b: Hacl.Bignum.Definitions.lbignum t len -> Prims.GTot Prims.nat
Prims.GTot
[ "sometrivial" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "FStar.Monotonic.HyperStack.mem", "Hacl.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.bn_v", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Hacl.Bignum.Definitions.limb", "Prims.nat" ]
[]
false
false
false
false
false
let bn_v #t #len h b =
S.bn_v #t #(v len) (as_seq h b)
false
FStar.UInt32.fst
FStar.UInt32.lemma_sub_msbs
val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b))))
val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b))))
let lemma_sub_msbs a b = from_vec_propriety (to_vec (v a)) 1; from_vec_propriety (to_vec (v b)) 1; from_vec_propriety (to_vec (v (sub_mod a b))) 1
{ "file_name": "ulib/FStar.UInt32.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 53, "end_line": 82, "start_col": 0, "start_line": 79 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt32 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" type t : eqtype = | Mk: v:uint_t n -> t let v x = x.v irreducible let uint_to_t x = Mk x let uv_inv _ = () let vu_inv _ = () let v_inj _ _ = () let zero = uint_to_t 0 let one = uint_to_t 1 let add a b = Mk (add (v a) (v b)) let add_underspec a b = Mk (add_underspec (v a) (v b)) let add_mod a b = Mk (add_mod (v a) (v b)) let sub a b = Mk (sub (v a) (v b)) let sub_underspec a b = Mk (sub_underspec (v a) (v b)) let sub_mod a b = Mk (sub_mod (v a) (v b)) let mul a b = Mk (mul (v a) (v b)) let mul_underspec a b = Mk (mul_underspec (v a) (v b)) let mul_mod a b = Mk (mul_mod (v a) (v b)) let div a b = Mk (div (v a) (v b)) let rem a b = Mk (mod (v a) (v b)) let logand x y = Mk (logand (v x) (v y)) let logxor x y = Mk (logxor (v x) (v y)) let logor x y = Mk (logor (v x) (v y)) let lognot x = Mk (lognot (v x)) let shift_right a s = Mk (shift_right (v a) (v s)) #push-options "--z3rlimit 80 --fuel 1" //AR: working around the interleaving semantics of pragmas let shift_left a s = Mk (shift_left (v a) (v s))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "FStar.UInt32.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "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": 80, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt32.t -> b: FStar.UInt32.t -> FStar.Pervasives.Lemma (ensures FStar.UInt.msb (FStar.UInt32.v a) = FStar.UInt.msb (FStar.UInt32.v b) ==> (FStar.UInt32.v a < FStar.UInt32.v b <==> FStar.UInt.msb (FStar.UInt32.v (FStar.UInt32.sub_mod a b))))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.UInt32.t", "FStar.UInt.from_vec_propriety", "FStar.UInt32.n", "FStar.UInt.to_vec", "FStar.UInt32.v", "FStar.UInt32.sub_mod", "Prims.unit" ]
[]
true
false
true
false
false
let lemma_sub_msbs a b =
from_vec_propriety (to_vec (v a)) 1; from_vec_propriety (to_vec (v b)) 1; from_vec_propriety (to_vec (v (sub_mod a b))) 1
false
Vale.SHA2.Wrapper.fst
Vale.SHA2.Wrapper.sigma256_1_0
val sigma256_1_0: x:nat32 -> Tot (nat32)
val sigma256_1_0: x:nat32 -> Tot (nat32)
let sigma256_1_0 x = v (_Sigma0 SHA2_256 (uint_to_t x))
{ "file_name": "vale/specs/crypto/Vale.SHA2.Wrapper.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 55, "end_line": 13, "start_col": 0, "start_line": 13 }
module Vale.SHA2.Wrapper open FStar.UInt32 open Spec.Agile.Hash open Spec.SHA2 friend Lib.IntTypes friend Spec.SHA2 let sigma256_0_0 x = v (_sigma0 SHA2_256 (uint_to_t x)) let sigma256_0_1 x = v (_sigma1 SHA2_256 (uint_to_t x))
{ "checked_file": "/", "dependencies": [ "Spec.SHA2.fst.checked", "Spec.SHA2.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.IntTypes.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Vale.SHA2.Wrapper.fst" }
[ { "abbrev": false, "full_module": "Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile.Hash", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Vale.SHA2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Vale.Def.Words_s.nat32 -> Vale.Def.Words_s.nat32
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat32", "FStar.UInt32.v", "Spec.SHA2._Sigma0", "Spec.Hash.Definitions.SHA2_256", "FStar.UInt32.uint_to_t" ]
[]
false
false
false
true
false
let sigma256_1_0 x =
v (_Sigma0 SHA2_256 (uint_to_t x))
false
Vale.SHA2.Wrapper.fst
Vale.SHA2.Wrapper.ch256
val ch256: x:nat32 -> y:nat32 -> z:nat32 -> Tot (nat32)
val ch256: x:nat32 -> y:nat32 -> z:nat32 -> Tot (nat32)
let ch256 x y z = v (_Ch SHA2_256 (uint_to_t x) (uint_to_t y) (uint_to_t z))
{ "file_name": "vale/specs/crypto/Vale.SHA2.Wrapper.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 76, "end_line": 17, "start_col": 0, "start_line": 17 }
module Vale.SHA2.Wrapper open FStar.UInt32 open Spec.Agile.Hash open Spec.SHA2 friend Lib.IntTypes friend Spec.SHA2 let sigma256_0_0 x = v (_sigma0 SHA2_256 (uint_to_t x)) let sigma256_0_1 x = v (_sigma1 SHA2_256 (uint_to_t x)) let sigma256_1_0 x = v (_Sigma0 SHA2_256 (uint_to_t x)) let sigma256_1_1 x = v (_Sigma1 SHA2_256 (uint_to_t x))
{ "checked_file": "/", "dependencies": [ "Spec.SHA2.fst.checked", "Spec.SHA2.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.IntTypes.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Vale.SHA2.Wrapper.fst" }
[ { "abbrev": false, "full_module": "Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile.Hash", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Vale.SHA2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Vale.Def.Words_s.nat32 -> y: Vale.Def.Words_s.nat32 -> z: Vale.Def.Words_s.nat32 -> Vale.Def.Words_s.nat32
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat32", "FStar.UInt32.v", "Spec.SHA2._Ch", "Spec.Hash.Definitions.SHA2_256", "FStar.UInt32.uint_to_t" ]
[]
false
false
false
true
false
let ch256 x y z =
v (_Ch SHA2_256 (uint_to_t x) (uint_to_t y) (uint_to_t z))
false
Vale.SHA2.Wrapper.fst
Vale.SHA2.Wrapper.sigma256_0_1
val sigma256_0_1: x:nat32 -> Tot (nat32)
val sigma256_0_1: x:nat32 -> Tot (nat32)
let sigma256_0_1 x = v (_sigma1 SHA2_256 (uint_to_t x))
{ "file_name": "vale/specs/crypto/Vale.SHA2.Wrapper.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 55, "end_line": 11, "start_col": 0, "start_line": 11 }
module Vale.SHA2.Wrapper open FStar.UInt32 open Spec.Agile.Hash open Spec.SHA2 friend Lib.IntTypes friend Spec.SHA2 let sigma256_0_0 x = v (_sigma0 SHA2_256 (uint_to_t x))
{ "checked_file": "/", "dependencies": [ "Spec.SHA2.fst.checked", "Spec.SHA2.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.IntTypes.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Vale.SHA2.Wrapper.fst" }
[ { "abbrev": false, "full_module": "Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile.Hash", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Vale.SHA2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Vale.Def.Words_s.nat32 -> Vale.Def.Words_s.nat32
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat32", "FStar.UInt32.v", "Spec.SHA2._sigma1", "Spec.Hash.Definitions.SHA2_256", "FStar.UInt32.uint_to_t" ]
[]
false
false
false
true
false
let sigma256_0_1 x =
v (_sigma1 SHA2_256 (uint_to_t x))
false
Vale.SHA2.Wrapper.fst
Vale.SHA2.Wrapper.sigma256_1_1
val sigma256_1_1: x:nat32 -> Tot (nat32)
val sigma256_1_1: x:nat32 -> Tot (nat32)
let sigma256_1_1 x = v (_Sigma1 SHA2_256 (uint_to_t x))
{ "file_name": "vale/specs/crypto/Vale.SHA2.Wrapper.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 55, "end_line": 15, "start_col": 0, "start_line": 15 }
module Vale.SHA2.Wrapper open FStar.UInt32 open Spec.Agile.Hash open Spec.SHA2 friend Lib.IntTypes friend Spec.SHA2 let sigma256_0_0 x = v (_sigma0 SHA2_256 (uint_to_t x)) let sigma256_0_1 x = v (_sigma1 SHA2_256 (uint_to_t x)) let sigma256_1_0 x = v (_Sigma0 SHA2_256 (uint_to_t x))
{ "checked_file": "/", "dependencies": [ "Spec.SHA2.fst.checked", "Spec.SHA2.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.IntTypes.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Vale.SHA2.Wrapper.fst" }
[ { "abbrev": false, "full_module": "Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile.Hash", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Vale.SHA2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Vale.Def.Words_s.nat32 -> Vale.Def.Words_s.nat32
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat32", "FStar.UInt32.v", "Spec.SHA2._Sigma1", "Spec.Hash.Definitions.SHA2_256", "FStar.UInt32.uint_to_t" ]
[]
false
false
false
true
false
let sigma256_1_1 x =
v (_Sigma1 SHA2_256 (uint_to_t x))
false
Vale.SHA2.Wrapper.fst
Vale.SHA2.Wrapper.maj256
val maj256: x:nat32 -> y:nat32 -> z:nat32 -> Tot (nat32)
val maj256: x:nat32 -> y:nat32 -> z:nat32 -> Tot (nat32)
let maj256 x y z = v (_Maj SHA2_256 (uint_to_t x) (uint_to_t y) (uint_to_t z))
{ "file_name": "vale/specs/crypto/Vale.SHA2.Wrapper.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 78, "end_line": 19, "start_col": 0, "start_line": 19 }
module Vale.SHA2.Wrapper open FStar.UInt32 open Spec.Agile.Hash open Spec.SHA2 friend Lib.IntTypes friend Spec.SHA2 let sigma256_0_0 x = v (_sigma0 SHA2_256 (uint_to_t x)) let sigma256_0_1 x = v (_sigma1 SHA2_256 (uint_to_t x)) let sigma256_1_0 x = v (_Sigma0 SHA2_256 (uint_to_t x)) let sigma256_1_1 x = v (_Sigma1 SHA2_256 (uint_to_t x)) let ch256 x y z = v (_Ch SHA2_256 (uint_to_t x) (uint_to_t y) (uint_to_t z))
{ "checked_file": "/", "dependencies": [ "Spec.SHA2.fst.checked", "Spec.SHA2.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.IntTypes.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Vale.SHA2.Wrapper.fst" }
[ { "abbrev": false, "full_module": "Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile.Hash", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Vale.SHA2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Vale.Def.Words_s.nat32 -> y: Vale.Def.Words_s.nat32 -> z: Vale.Def.Words_s.nat32 -> Vale.Def.Words_s.nat32
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat32", "FStar.UInt32.v", "Spec.SHA2._Maj", "Spec.Hash.Definitions.SHA2_256", "FStar.UInt32.uint_to_t" ]
[]
false
false
false
true
false
let maj256 x y z =
v (_Maj SHA2_256 (uint_to_t x) (uint_to_t y) (uint_to_t z))
false
EtM.CPA.fst
EtM.CPA.ivsize
val ivsize : Prims.int
let ivsize = CC.blockSize CC.AES_128_CBC
{ "file_name": "examples/crypto/EtM.CPA.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 40, "end_line": 34, "start_col": 0, "start_line": 34 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module EtM.CPA open FStar.HyperStack.ST open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open EtM.Ideal open Platform.Bytes module CC = EtM.CoreCrypto module B = Platform.Bytes open EtM.Plain type rid = erid (*** Basic types ***)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked", "EtM.Plain.fsti.checked", "EtM.Ideal.fsti.checked", "EtM.CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.CPA.fst" }
[ { "abbrev": false, "full_module": "EtM.Plain", "short_module": null }, { "abbrev": true, "full_module": "Platform.Bytes", "short_module": "B" }, { "abbrev": true, "full_module": "EtM.CoreCrypto", "short_module": "CC" }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": false, "full_module": "EtM.Ideal", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.int
Prims.Tot
[ "total" ]
[]
[ "CoreCrypto.blockSize", "CoreCrypto.AES_128_CBC" ]
[]
false
false
false
true
false
let ivsize =
CC.blockSize CC.AES_128_CBC
false
EtM.CPA.fst
EtM.CPA.keysize
val keysize : Prims.int
let keysize = 16
{ "file_name": "examples/crypto/EtM.CPA.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 16, "end_line": 38, "start_col": 0, "start_line": 38 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module EtM.CPA open FStar.HyperStack.ST open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open EtM.Ideal open Platform.Bytes module CC = EtM.CoreCrypto module B = Platform.Bytes open EtM.Plain type rid = erid (*** Basic types ***) /// Initialization vectors: bytes of a given size let ivsize = CC.blockSize CC.AES_128_CBC let iv = lbytes ivsize
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked", "EtM.Plain.fsti.checked", "EtM.Ideal.fsti.checked", "EtM.CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.CPA.fst" }
[ { "abbrev": false, "full_module": "EtM.Plain", "short_module": null }, { "abbrev": true, "full_module": "Platform.Bytes", "short_module": "B" }, { "abbrev": true, "full_module": "EtM.CoreCrypto", "short_module": "CC" }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": false, "full_module": "EtM.Ideal", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.int
Prims.Tot
[ "total" ]
[]
[]
[]
false
false
false
true
false
let keysize =
16
false
EtM.CPA.fst
EtM.CPA.cipher
val cipher : Type0
let cipher = (b:bytes{B.length b >= ivsize})
{ "file_name": "examples/crypto/EtM.CPA.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 44, "end_line": 44, "start_col": 0, "start_line": 44 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module EtM.CPA open FStar.HyperStack.ST open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open EtM.Ideal open Platform.Bytes module CC = EtM.CoreCrypto module B = Platform.Bytes open EtM.Plain type rid = erid (*** Basic types ***) /// Initialization vectors: bytes of a given size let ivsize = CC.blockSize CC.AES_128_CBC let iv = lbytes ivsize /// Raw keys for AES 128 let keysize = 16 let aes_key = lbytes keysize /// Cipher-texts are a concatenation of the IV and the AES cipher /// -- we underspecify its length
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked", "EtM.Plain.fsti.checked", "EtM.Ideal.fsti.checked", "EtM.CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.CPA.fst" }
[ { "abbrev": false, "full_module": "EtM.Plain", "short_module": null }, { "abbrev": true, "full_module": "Platform.Bytes", "short_module": "B" }, { "abbrev": true, "full_module": "EtM.CoreCrypto", "short_module": "CC" }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": false, "full_module": "EtM.Ideal", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Platform.Bytes.bytes", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "Platform.Bytes.length", "EtM.CPA.ivsize" ]
[]
false
false
false
true
true
let cipher =
(b: bytes{B.length b >= ivsize})
false
Vale.SHA2.Wrapper.fst
Vale.SHA2.Wrapper.sigma256_0_0
val sigma256_0_0: x:nat32 -> Tot (nat32)
val sigma256_0_0: x:nat32 -> Tot (nat32)
let sigma256_0_0 x = v (_sigma0 SHA2_256 (uint_to_t x))
{ "file_name": "vale/specs/crypto/Vale.SHA2.Wrapper.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 55, "end_line": 9, "start_col": 0, "start_line": 9 }
module Vale.SHA2.Wrapper open FStar.UInt32 open Spec.Agile.Hash open Spec.SHA2 friend Lib.IntTypes friend Spec.SHA2
{ "checked_file": "/", "dependencies": [ "Spec.SHA2.fst.checked", "Spec.SHA2.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.IntTypes.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Vale.SHA2.Wrapper.fst" }
[ { "abbrev": false, "full_module": "Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile.Hash", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Vale.SHA2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Vale.Def.Words_s.nat32 -> Vale.Def.Words_s.nat32
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat32", "FStar.UInt32.v", "Spec.SHA2._sigma0", "Spec.Hash.Definitions.SHA2_256", "FStar.UInt32.uint_to_t" ]
[]
false
false
false
true
false
let sigma256_0_0 x =
v (_sigma0 SHA2_256 (uint_to_t x))
false
EtM.CPA.fst
EtM.CPA.log
val log (k: key) (h: mem) : GTot (seq log_entry)
val log (k: key) (h: mem) : GTot (seq log_entry)
let log (k:key) (h:mem) : GTot (seq log_entry) = sel h (Key?.log k)
{ "file_name": "examples/crypto/EtM.CPA.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 22, "end_line": 103, "start_col": 0, "start_line": 101 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module EtM.CPA open FStar.HyperStack.ST open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open EtM.Ideal open Platform.Bytes module CC = EtM.CoreCrypto module B = Platform.Bytes open EtM.Plain type rid = erid (*** Basic types ***) /// Initialization vectors: bytes of a given size let ivsize = CC.blockSize CC.AES_128_CBC let iv = lbytes ivsize /// Raw keys for AES 128 let keysize = 16 let aes_key = lbytes keysize /// Cipher-texts are a concatenation of the IV and the AES cipher /// -- we underspecify its length /// -- MK says: minimal cipher length twice blocksize? let cipher = (b:bytes{B.length b >= ivsize}) (*** Ideal state ***) /// CPA log entries are pairs of a plain text and its corresponding cipher type log_entry = | Entry: plain:plain -> c:cipher -> log_entry /// Recover the IV from an entry by splitting out a prefix of the cipher let iv_of_entry (Entry _ c) : iv = fst (B.split c ivsize) /// Recover the AES cipher from an entry by splitting out a suffix of the cipher let raw_cipher (Entry _ c) : bytes = snd (B.split c ivsize) /// A lemma inverting the iv+cipher construction let split_entry (p:plain) (c:cipher) (iv:iv) (r:bytes) : Lemma (iv_of_entry (Entry p (iv@|r)) == iv /\ raw_cipher (Entry p (iv@|r)) == r) = assert (Seq.equal (iv_of_entry (Entry p (iv@|r))) iv); assert (Seq.equal (raw_cipher (Entry p (iv@|r))) r) /// A lemma showing that entries that differ on their IVs differ on their ciphers /// -- because append is injective on both its arguments let iv_of_entry_inj (e1 e2:log_entry) : Lemma (iv_of_entry e1 <> iv_of_entry e2 ==> Entry?.c e1 <> Entry?.c e2) = let iv1, r1 = iv_of_entry e1, raw_cipher e1 in let iv2, r2 = iv_of_entry e2, raw_cipher e2 in FStar.Classical.move_requires (Platform.Bytes.lemma_append_inj iv1 r1 iv2) r2 /// A key includes the raw AES key but also an monotonic log of entries /// representing the ideal state noeq type key = | Key: #region:rid -> raw:aes_key -> log:Monotonic.Seq.log_t region log_entry -> key (** Exercise: (conceptually easy; technically difficult) The type `key` above contains a reference to an ideal log unconditionally. However, this log is redundant when not idealizing. Revise the `key` type as shown below and propagate it through the development. noeq type key = | Key: #region:rid -> raw:aes_key -> log:(if Ideal.ind_cpa then Monotonic.Seq.log_t region log_entry else unit) -> key **)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked", "EtM.Plain.fsti.checked", "EtM.Ideal.fsti.checked", "EtM.CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.CPA.fst" }
[ { "abbrev": false, "full_module": "EtM.Plain", "short_module": null }, { "abbrev": true, "full_module": "Platform.Bytes", "short_module": "B" }, { "abbrev": true, "full_module": "EtM.CoreCrypto", "short_module": "CC" }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": false, "full_module": "EtM.Ideal", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k: EtM.CPA.key -> h: FStar.Monotonic.HyperStack.mem -> Prims.GTot (FStar.Seq.Base.seq EtM.CPA.log_entry)
Prims.GTot
[ "sometrivial" ]
[]
[ "EtM.CPA.key", "FStar.Monotonic.HyperStack.mem", "FStar.Monotonic.HyperStack.sel", "FStar.Seq.Base.seq", "EtM.CPA.log_entry", "FStar.Monotonic.Seq.grows", "EtM.CPA.__proj__Key__item__log" ]
[]
false
false
false
false
false
let log (k: key) (h: mem) : GTot (seq log_entry) =
sel h (Key?.log k)
false
EtM.CPA.fst
EtM.CPA.iv
val iv : Type0
let iv = lbytes ivsize
{ "file_name": "examples/crypto/EtM.CPA.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 22, "end_line": 35, "start_col": 0, "start_line": 35 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module EtM.CPA open FStar.HyperStack.ST open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open EtM.Ideal open Platform.Bytes module CC = EtM.CoreCrypto module B = Platform.Bytes open EtM.Plain type rid = erid (*** Basic types ***) /// Initialization vectors: bytes of a given size
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked", "EtM.Plain.fsti.checked", "EtM.Ideal.fsti.checked", "EtM.CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.CPA.fst" }
[ { "abbrev": false, "full_module": "EtM.Plain", "short_module": null }, { "abbrev": true, "full_module": "Platform.Bytes", "short_module": "B" }, { "abbrev": true, "full_module": "EtM.CoreCrypto", "short_module": "CC" }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": false, "full_module": "EtM.Ideal", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Platform.Bytes.lbytes", "EtM.CPA.ivsize" ]
[]
false
false
false
true
true
let iv =
lbytes ivsize
false
EtM.CPA.fst
EtM.CPA.iv_of_entry
val iv_of_entry : _: EtM.CPA.log_entry -> EtM.CPA.iv
let iv_of_entry (Entry _ c) : iv = fst (B.split c ivsize)
{ "file_name": "examples/crypto/EtM.CPA.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 57, "end_line": 55, "start_col": 0, "start_line": 55 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module EtM.CPA open FStar.HyperStack.ST open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open EtM.Ideal open Platform.Bytes module CC = EtM.CoreCrypto module B = Platform.Bytes open EtM.Plain type rid = erid (*** Basic types ***) /// Initialization vectors: bytes of a given size let ivsize = CC.blockSize CC.AES_128_CBC let iv = lbytes ivsize /// Raw keys for AES 128 let keysize = 16 let aes_key = lbytes keysize /// Cipher-texts are a concatenation of the IV and the AES cipher /// -- we underspecify its length /// -- MK says: minimal cipher length twice blocksize? let cipher = (b:bytes{B.length b >= ivsize}) (*** Ideal state ***) /// CPA log entries are pairs of a plain text and its corresponding cipher type log_entry = | Entry: plain:plain -> c:cipher -> log_entry
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked", "EtM.Plain.fsti.checked", "EtM.Ideal.fsti.checked", "EtM.CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.CPA.fst" }
[ { "abbrev": false, "full_module": "EtM.Plain", "short_module": null }, { "abbrev": true, "full_module": "Platform.Bytes", "short_module": "B" }, { "abbrev": true, "full_module": "EtM.CoreCrypto", "short_module": "CC" }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": false, "full_module": "EtM.Ideal", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: EtM.CPA.log_entry -> EtM.CPA.iv
Prims.Tot
[ "total" ]
[]
[ "EtM.CPA.log_entry", "EtM.Plain.plain", "EtM.CPA.cipher", "FStar.Pervasives.Native.fst", "Platform.Bytes.bytes", "Platform.Bytes.split", "EtM.CPA.ivsize", "EtM.CPA.iv" ]
[]
false
false
false
true
false
let iv_of_entry (Entry _ c) : iv =
fst (B.split c ivsize)
false
EtM.CPA.fst
EtM.CPA.raw_cipher
val raw_cipher : _: EtM.CPA.log_entry -> Platform.Bytes.bytes
let raw_cipher (Entry _ c) : bytes = snd (B.split c ivsize)
{ "file_name": "examples/crypto/EtM.CPA.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 59, "end_line": 58, "start_col": 0, "start_line": 58 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module EtM.CPA open FStar.HyperStack.ST open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open EtM.Ideal open Platform.Bytes module CC = EtM.CoreCrypto module B = Platform.Bytes open EtM.Plain type rid = erid (*** Basic types ***) /// Initialization vectors: bytes of a given size let ivsize = CC.blockSize CC.AES_128_CBC let iv = lbytes ivsize /// Raw keys for AES 128 let keysize = 16 let aes_key = lbytes keysize /// Cipher-texts are a concatenation of the IV and the AES cipher /// -- we underspecify its length /// -- MK says: minimal cipher length twice blocksize? let cipher = (b:bytes{B.length b >= ivsize}) (*** Ideal state ***) /// CPA log entries are pairs of a plain text and its corresponding cipher type log_entry = | Entry: plain:plain -> c:cipher -> log_entry /// Recover the IV from an entry by splitting out a prefix of the cipher let iv_of_entry (Entry _ c) : iv = fst (B.split c ivsize)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked", "EtM.Plain.fsti.checked", "EtM.Ideal.fsti.checked", "EtM.CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.CPA.fst" }
[ { "abbrev": false, "full_module": "EtM.Plain", "short_module": null }, { "abbrev": true, "full_module": "Platform.Bytes", "short_module": "B" }, { "abbrev": true, "full_module": "EtM.CoreCrypto", "short_module": "CC" }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": false, "full_module": "EtM.Ideal", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: EtM.CPA.log_entry -> Platform.Bytes.bytes
Prims.Tot
[ "total" ]
[]
[ "EtM.CPA.log_entry", "EtM.Plain.plain", "EtM.CPA.cipher", "FStar.Pervasives.Native.snd", "Platform.Bytes.bytes", "Platform.Bytes.split", "EtM.CPA.ivsize" ]
[]
false
false
false
true
false
let raw_cipher (Entry _ c) : bytes =
snd (B.split c ivsize)
false
EtM.CPA.fst
EtM.CPA.invariant
val invariant : k: EtM.CPA.key -> h: FStar.Monotonic.HyperStack.mem -> Prims.logical
let invariant (k:key) (h:mem) = let Key raw_key lg = k in let log = log k h in contains h lg /\ //<-- technical: the log must be allocated pairwise_distinct_ivs log /\ cipher_functional_correctness raw_key log
{ "file_name": "examples/crypto/EtM.CPA.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 45, "end_line": 178, "start_col": 0, "start_line": 173 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module EtM.CPA open FStar.HyperStack.ST open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open EtM.Ideal open Platform.Bytes module CC = EtM.CoreCrypto module B = Platform.Bytes open EtM.Plain type rid = erid (*** Basic types ***) /// Initialization vectors: bytes of a given size let ivsize = CC.blockSize CC.AES_128_CBC let iv = lbytes ivsize /// Raw keys for AES 128 let keysize = 16 let aes_key = lbytes keysize /// Cipher-texts are a concatenation of the IV and the AES cipher /// -- we underspecify its length /// -- MK says: minimal cipher length twice blocksize? let cipher = (b:bytes{B.length b >= ivsize}) (*** Ideal state ***) /// CPA log entries are pairs of a plain text and its corresponding cipher type log_entry = | Entry: plain:plain -> c:cipher -> log_entry /// Recover the IV from an entry by splitting out a prefix of the cipher let iv_of_entry (Entry _ c) : iv = fst (B.split c ivsize) /// Recover the AES cipher from an entry by splitting out a suffix of the cipher let raw_cipher (Entry _ c) : bytes = snd (B.split c ivsize) /// A lemma inverting the iv+cipher construction let split_entry (p:plain) (c:cipher) (iv:iv) (r:bytes) : Lemma (iv_of_entry (Entry p (iv@|r)) == iv /\ raw_cipher (Entry p (iv@|r)) == r) = assert (Seq.equal (iv_of_entry (Entry p (iv@|r))) iv); assert (Seq.equal (raw_cipher (Entry p (iv@|r))) r) /// A lemma showing that entries that differ on their IVs differ on their ciphers /// -- because append is injective on both its arguments let iv_of_entry_inj (e1 e2:log_entry) : Lemma (iv_of_entry e1 <> iv_of_entry e2 ==> Entry?.c e1 <> Entry?.c e2) = let iv1, r1 = iv_of_entry e1, raw_cipher e1 in let iv2, r2 = iv_of_entry e2, raw_cipher e2 in FStar.Classical.move_requires (Platform.Bytes.lemma_append_inj iv1 r1 iv2) r2 /// A key includes the raw AES key but also an monotonic log of entries /// representing the ideal state noeq type key = | Key: #region:rid -> raw:aes_key -> log:Monotonic.Seq.log_t region log_entry -> key (** Exercise: (conceptually easy; technically difficult) The type `key` above contains a reference to an ideal log unconditionally. However, this log is redundant when not idealizing. Revise the `key` type as shown below and propagate it through the development. noeq type key = | Key: #region:rid -> raw:aes_key -> log:(if Ideal.ind_cpa then Monotonic.Seq.log_t region log_entry else unit) -> key **) /// An accessor for the log in state h let log (k:key) (h:mem) : GTot (seq log_entry) = sel h (Key?.log k) (*** Invariants on the ideal state ***) (** Informally, there are two main components to the invariant: 1. The IVs in the log are pairwise-distinct. We rely on this to obtain an injectivity property in EtM.AE, using it to relate the CPA and MAC logs to the composite AE log. 2. The ciphers in each entry are required to be valid encryptions of the corresponding plain texts and IVs **) /// --------------------------------------- /// Invariant part 1: distinctness of IVs /// --------------------------------------- let iv_not_in (iv:iv) (log:seq log_entry) = forall (e:log_entry{Seq.mem e log}). iv_of_entry e <> iv /// We state pairwise-distinctness of IVs in this recursive form /// It makes it more convenient to work with as we /// append each new entry (aka snoc) to the end of the log let rec pairwise_distinct_ivs (log:seq log_entry) : Tot Type0 (decreases (Seq.length log)) = if Seq.length log > 0 then let log, tl = Seq.un_snoc log in pairwise_distinct_ivs log /\ iv_not_in (iv_of_entry tl) log else True /// A simple lemma to introduce and eliminate pairwise_distinct_ivs let pairwise_snoc (cpas:Seq.seq log_entry) (tl:log_entry) : Lemma ((pairwise_distinct_ivs cpas /\ iv_not_in (iv_of_entry tl) cpas) <==> (pairwise_distinct_ivs (Seq.snoc cpas tl))) = un_snoc_snoc cpas tl /// It's convenient to lift the pairwise-distinctness of IVs to /// pairwise distinctness of the cipher texts let invert_pairwise (cpas:Seq.seq log_entry) (e:log_entry) (c:cipher) : Lemma (requires (pairwise_distinct_ivs (snoc cpas e) /\ Entry?.c e == c)) (ensures (forall e'. Seq.mem e' cpas ==> Entry?.c e' <> c)) = pairwise_snoc cpas e; FStar.Classical.forall_intro (iv_of_entry_inj e) /// ----------------------------------------- /// Invariant part 2: correctness of ciphers /// ----------------------------------------- /// Each entry contains a valid AES encryption /// /// -- A wrinkle is that when ind_cpa, rather than encrypting the /// plaintext we just encrypt zeros let entry_functional_correctness (raw_key:bytes) (e:log_entry) : Type0 = let iv = iv_of_entry e in let c = raw_cipher e in let plain = Entry?.plain e in let p = if ind_cpa then createBytes (length plain) 0z else repr plain in c == CC.block_encrypt_spec CC.AES_128_CBC raw_key iv p /// Lifting the correctness of individual entries pointwise to correctness of the entire log let cipher_functional_correctness (raw_key:bytes) (log:seq log_entry) = forall (e:log_entry{Seq.mem e log}). {:pattern (Seq.mem e log)} entry_functional_correctness raw_key e /// The invariant is the conjunction of distinctness and correctness /// -- Together with a technical requirement of the log actually
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked", "EtM.Plain.fsti.checked", "EtM.Ideal.fsti.checked", "EtM.CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.CPA.fst" }
[ { "abbrev": false, "full_module": "EtM.Plain", "short_module": null }, { "abbrev": true, "full_module": "Platform.Bytes", "short_module": "B" }, { "abbrev": true, "full_module": "EtM.CoreCrypto", "short_module": "CC" }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": false, "full_module": "EtM.Ideal", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k: EtM.CPA.key -> h: FStar.Monotonic.HyperStack.mem -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "EtM.CPA.key", "FStar.Monotonic.HyperStack.mem", "EtM.CPA.rid", "EtM.CPA.aes_key", "FStar.Monotonic.Seq.log_t", "EtM.CPA.log_entry", "Prims.l_and", "FStar.Monotonic.HyperStack.contains", "FStar.Seq.Base.seq", "FStar.Monotonic.Seq.grows", "EtM.CPA.pairwise_distinct_ivs", "EtM.CPA.cipher_functional_correctness", "EtM.CPA.log", "Prims.logical" ]
[]
false
false
false
true
true
let invariant (k: key) (h: mem) =
let Key raw_key lg = k in let log = log k h in contains h lg /\ pairwise_distinct_ivs log /\ cipher_functional_correctness raw_key log
false
EtM.CPA.fst
EtM.CPA.aes_key
val aes_key : Type0
let aes_key = lbytes keysize
{ "file_name": "examples/crypto/EtM.CPA.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 28, "end_line": 39, "start_col": 0, "start_line": 39 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module EtM.CPA open FStar.HyperStack.ST open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open EtM.Ideal open Platform.Bytes module CC = EtM.CoreCrypto module B = Platform.Bytes open EtM.Plain type rid = erid (*** Basic types ***) /// Initialization vectors: bytes of a given size let ivsize = CC.blockSize CC.AES_128_CBC let iv = lbytes ivsize /// Raw keys for AES 128
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked", "EtM.Plain.fsti.checked", "EtM.Ideal.fsti.checked", "EtM.CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.CPA.fst" }
[ { "abbrev": false, "full_module": "EtM.Plain", "short_module": null }, { "abbrev": true, "full_module": "Platform.Bytes", "short_module": "B" }, { "abbrev": true, "full_module": "EtM.CoreCrypto", "short_module": "CC" }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": false, "full_module": "EtM.Ideal", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Platform.Bytes.lbytes", "EtM.CPA.keysize" ]
[]
false
false
false
true
true
let aes_key =
lbytes keysize
false
EtM.CPA.fst
EtM.CPA.pairwise_distinct_ivs
val pairwise_distinct_ivs (log: seq log_entry) : Tot Type0 (decreases (Seq.length log))
val pairwise_distinct_ivs (log: seq log_entry) : Tot Type0 (decreases (Seq.length log))
let rec pairwise_distinct_ivs (log:seq log_entry) : Tot Type0 (decreases (Seq.length log)) = if Seq.length log > 0 then let log, tl = Seq.un_snoc log in pairwise_distinct_ivs log /\ iv_not_in (iv_of_entry tl) log else True
{ "file_name": "examples/crypto/EtM.CPA.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 11, "end_line": 133, "start_col": 0, "start_line": 127 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module EtM.CPA open FStar.HyperStack.ST open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open EtM.Ideal open Platform.Bytes module CC = EtM.CoreCrypto module B = Platform.Bytes open EtM.Plain type rid = erid (*** Basic types ***) /// Initialization vectors: bytes of a given size let ivsize = CC.blockSize CC.AES_128_CBC let iv = lbytes ivsize /// Raw keys for AES 128 let keysize = 16 let aes_key = lbytes keysize /// Cipher-texts are a concatenation of the IV and the AES cipher /// -- we underspecify its length /// -- MK says: minimal cipher length twice blocksize? let cipher = (b:bytes{B.length b >= ivsize}) (*** Ideal state ***) /// CPA log entries are pairs of a plain text and its corresponding cipher type log_entry = | Entry: plain:plain -> c:cipher -> log_entry /// Recover the IV from an entry by splitting out a prefix of the cipher let iv_of_entry (Entry _ c) : iv = fst (B.split c ivsize) /// Recover the AES cipher from an entry by splitting out a suffix of the cipher let raw_cipher (Entry _ c) : bytes = snd (B.split c ivsize) /// A lemma inverting the iv+cipher construction let split_entry (p:plain) (c:cipher) (iv:iv) (r:bytes) : Lemma (iv_of_entry (Entry p (iv@|r)) == iv /\ raw_cipher (Entry p (iv@|r)) == r) = assert (Seq.equal (iv_of_entry (Entry p (iv@|r))) iv); assert (Seq.equal (raw_cipher (Entry p (iv@|r))) r) /// A lemma showing that entries that differ on their IVs differ on their ciphers /// -- because append is injective on both its arguments let iv_of_entry_inj (e1 e2:log_entry) : Lemma (iv_of_entry e1 <> iv_of_entry e2 ==> Entry?.c e1 <> Entry?.c e2) = let iv1, r1 = iv_of_entry e1, raw_cipher e1 in let iv2, r2 = iv_of_entry e2, raw_cipher e2 in FStar.Classical.move_requires (Platform.Bytes.lemma_append_inj iv1 r1 iv2) r2 /// A key includes the raw AES key but also an monotonic log of entries /// representing the ideal state noeq type key = | Key: #region:rid -> raw:aes_key -> log:Monotonic.Seq.log_t region log_entry -> key (** Exercise: (conceptually easy; technically difficult) The type `key` above contains a reference to an ideal log unconditionally. However, this log is redundant when not idealizing. Revise the `key` type as shown below and propagate it through the development. noeq type key = | Key: #region:rid -> raw:aes_key -> log:(if Ideal.ind_cpa then Monotonic.Seq.log_t region log_entry else unit) -> key **) /// An accessor for the log in state h let log (k:key) (h:mem) : GTot (seq log_entry) = sel h (Key?.log k) (*** Invariants on the ideal state ***) (** Informally, there are two main components to the invariant: 1. The IVs in the log are pairwise-distinct. We rely on this to obtain an injectivity property in EtM.AE, using it to relate the CPA and MAC logs to the composite AE log. 2. The ciphers in each entry are required to be valid encryptions of the corresponding plain texts and IVs **) /// --------------------------------------- /// Invariant part 1: distinctness of IVs /// --------------------------------------- let iv_not_in (iv:iv) (log:seq log_entry) = forall (e:log_entry{Seq.mem e log}). iv_of_entry e <> iv /// We state pairwise-distinctness of IVs in this recursive form /// It makes it more convenient to work with as we
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked", "EtM.Plain.fsti.checked", "EtM.Ideal.fsti.checked", "EtM.CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.CPA.fst" }
[ { "abbrev": false, "full_module": "EtM.Plain", "short_module": null }, { "abbrev": true, "full_module": "Platform.Bytes", "short_module": "B" }, { "abbrev": true, "full_module": "EtM.CoreCrypto", "short_module": "CC" }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": false, "full_module": "EtM.Ideal", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
log: FStar.Seq.Base.seq EtM.CPA.log_entry -> Prims.Tot Type0
Prims.Tot
[ "total", "" ]
[]
[ "FStar.Seq.Base.seq", "EtM.CPA.log_entry", "Prims.op_GreaterThan", "FStar.Seq.Base.length", "Prims.l_and", "EtM.CPA.pairwise_distinct_ivs", "EtM.CPA.iv_not_in", "EtM.CPA.iv_of_entry", "FStar.Pervasives.Native.tuple2", "Prims.eq2", "FStar.Seq.Properties.snoc", "FStar.Pervasives.Native.fst", "FStar.Pervasives.Native.snd", "FStar.Seq.Properties.un_snoc", "Prims.bool", "Prims.l_True" ]
[ "recursion" ]
false
false
false
true
true
let rec pairwise_distinct_ivs (log: seq log_entry) : Tot Type0 (decreases (Seq.length log)) =
if Seq.length log > 0 then let log, tl = Seq.un_snoc log in pairwise_distinct_ivs log /\ iv_not_in (iv_of_entry tl) log else True
false
EtM.CPA.fst
EtM.CPA.iv_not_in
val iv_not_in : iv: EtM.CPA.iv -> log: FStar.Seq.Base.seq EtM.CPA.log_entry -> Prims.logical
let iv_not_in (iv:iv) (log:seq log_entry) = forall (e:log_entry{Seq.mem e log}). iv_of_entry e <> iv
{ "file_name": "examples/crypto/EtM.CPA.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 60, "end_line": 122, "start_col": 0, "start_line": 121 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module EtM.CPA open FStar.HyperStack.ST open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open EtM.Ideal open Platform.Bytes module CC = EtM.CoreCrypto module B = Platform.Bytes open EtM.Plain type rid = erid (*** Basic types ***) /// Initialization vectors: bytes of a given size let ivsize = CC.blockSize CC.AES_128_CBC let iv = lbytes ivsize /// Raw keys for AES 128 let keysize = 16 let aes_key = lbytes keysize /// Cipher-texts are a concatenation of the IV and the AES cipher /// -- we underspecify its length /// -- MK says: minimal cipher length twice blocksize? let cipher = (b:bytes{B.length b >= ivsize}) (*** Ideal state ***) /// CPA log entries are pairs of a plain text and its corresponding cipher type log_entry = | Entry: plain:plain -> c:cipher -> log_entry /// Recover the IV from an entry by splitting out a prefix of the cipher let iv_of_entry (Entry _ c) : iv = fst (B.split c ivsize) /// Recover the AES cipher from an entry by splitting out a suffix of the cipher let raw_cipher (Entry _ c) : bytes = snd (B.split c ivsize) /// A lemma inverting the iv+cipher construction let split_entry (p:plain) (c:cipher) (iv:iv) (r:bytes) : Lemma (iv_of_entry (Entry p (iv@|r)) == iv /\ raw_cipher (Entry p (iv@|r)) == r) = assert (Seq.equal (iv_of_entry (Entry p (iv@|r))) iv); assert (Seq.equal (raw_cipher (Entry p (iv@|r))) r) /// A lemma showing that entries that differ on their IVs differ on their ciphers /// -- because append is injective on both its arguments let iv_of_entry_inj (e1 e2:log_entry) : Lemma (iv_of_entry e1 <> iv_of_entry e2 ==> Entry?.c e1 <> Entry?.c e2) = let iv1, r1 = iv_of_entry e1, raw_cipher e1 in let iv2, r2 = iv_of_entry e2, raw_cipher e2 in FStar.Classical.move_requires (Platform.Bytes.lemma_append_inj iv1 r1 iv2) r2 /// A key includes the raw AES key but also an monotonic log of entries /// representing the ideal state noeq type key = | Key: #region:rid -> raw:aes_key -> log:Monotonic.Seq.log_t region log_entry -> key (** Exercise: (conceptually easy; technically difficult) The type `key` above contains a reference to an ideal log unconditionally. However, this log is redundant when not idealizing. Revise the `key` type as shown below and propagate it through the development. noeq type key = | Key: #region:rid -> raw:aes_key -> log:(if Ideal.ind_cpa then Monotonic.Seq.log_t region log_entry else unit) -> key **) /// An accessor for the log in state h let log (k:key) (h:mem) : GTot (seq log_entry) = sel h (Key?.log k) (*** Invariants on the ideal state ***) (** Informally, there are two main components to the invariant: 1. The IVs in the log are pairwise-distinct. We rely on this to obtain an injectivity property in EtM.AE, using it to relate the CPA and MAC logs to the composite AE log. 2. The ciphers in each entry are required to be valid encryptions of the corresponding plain texts and IVs **) /// --------------------------------------- /// Invariant part 1: distinctness of IVs /// ---------------------------------------
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked", "EtM.Plain.fsti.checked", "EtM.Ideal.fsti.checked", "EtM.CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.CPA.fst" }
[ { "abbrev": false, "full_module": "EtM.Plain", "short_module": null }, { "abbrev": true, "full_module": "Platform.Bytes", "short_module": "B" }, { "abbrev": true, "full_module": "EtM.CoreCrypto", "short_module": "CC" }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": false, "full_module": "EtM.Ideal", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
iv: EtM.CPA.iv -> log: FStar.Seq.Base.seq EtM.CPA.log_entry -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "EtM.CPA.iv", "FStar.Seq.Base.seq", "EtM.CPA.log_entry", "Prims.l_Forall", "Prims.b2t", "FStar.Seq.Properties.mem", "Prims.op_disEquality", "EtM.CPA.iv_of_entry", "Prims.logical" ]
[]
false
false
false
true
true
let iv_not_in (iv: iv) (log: seq log_entry) =
forall (e: log_entry{Seq.mem e log}). iv_of_entry e <> iv
false
EtM.CPA.fst
EtM.CPA.split_entry
val split_entry (p: plain) (c: cipher) (iv: iv) (r: bytes) : Lemma (iv_of_entry (Entry p (iv @| r)) == iv /\ raw_cipher (Entry p (iv @| r)) == r)
val split_entry (p: plain) (c: cipher) (iv: iv) (r: bytes) : Lemma (iv_of_entry (Entry p (iv @| r)) == iv /\ raw_cipher (Entry p (iv @| r)) == r)
let split_entry (p:plain) (c:cipher) (iv:iv) (r:bytes) : Lemma (iv_of_entry (Entry p (iv@|r)) == iv /\ raw_cipher (Entry p (iv@|r)) == r) = assert (Seq.equal (iv_of_entry (Entry p (iv@|r))) iv); assert (Seq.equal (raw_cipher (Entry p (iv@|r))) r)
{ "file_name": "examples/crypto/EtM.CPA.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 56, "end_line": 65, "start_col": 0, "start_line": 61 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module EtM.CPA open FStar.HyperStack.ST open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open EtM.Ideal open Platform.Bytes module CC = EtM.CoreCrypto module B = Platform.Bytes open EtM.Plain type rid = erid (*** Basic types ***) /// Initialization vectors: bytes of a given size let ivsize = CC.blockSize CC.AES_128_CBC let iv = lbytes ivsize /// Raw keys for AES 128 let keysize = 16 let aes_key = lbytes keysize /// Cipher-texts are a concatenation of the IV and the AES cipher /// -- we underspecify its length /// -- MK says: minimal cipher length twice blocksize? let cipher = (b:bytes{B.length b >= ivsize}) (*** Ideal state ***) /// CPA log entries are pairs of a plain text and its corresponding cipher type log_entry = | Entry: plain:plain -> c:cipher -> log_entry /// Recover the IV from an entry by splitting out a prefix of the cipher let iv_of_entry (Entry _ c) : iv = fst (B.split c ivsize) /// Recover the AES cipher from an entry by splitting out a suffix of the cipher let raw_cipher (Entry _ c) : bytes = snd (B.split c ivsize)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked", "EtM.Plain.fsti.checked", "EtM.Ideal.fsti.checked", "EtM.CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.CPA.fst" }
[ { "abbrev": false, "full_module": "EtM.Plain", "short_module": null }, { "abbrev": true, "full_module": "Platform.Bytes", "short_module": "B" }, { "abbrev": true, "full_module": "EtM.CoreCrypto", "short_module": "CC" }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": false, "full_module": "EtM.Ideal", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: EtM.Plain.plain -> c: EtM.CPA.cipher -> iv: EtM.CPA.iv -> r: Platform.Bytes.bytes -> FStar.Pervasives.Lemma (ensures EtM.CPA.iv_of_entry (EtM.CPA.Entry p (iv @| r)) == iv /\ EtM.CPA.raw_cipher (EtM.CPA.Entry p (iv @| r)) == r)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "EtM.Plain.plain", "EtM.CPA.cipher", "EtM.CPA.iv", "Platform.Bytes.bytes", "Prims._assert", "FStar.Seq.Base.equal", "Platform.Bytes.byte", "EtM.CPA.raw_cipher", "EtM.CPA.Entry", "Platform.Bytes.op_At_Bar", "Prims.unit", "EtM.CPA.iv_of_entry", "Prims.l_True", "Prims.squash", "Prims.l_and", "Prims.eq2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let split_entry (p: plain) (c: cipher) (iv: iv) (r: bytes) : Lemma (iv_of_entry (Entry p (iv @| r)) == iv /\ raw_cipher (Entry p (iv @| r)) == r) =
assert (Seq.equal (iv_of_entry (Entry p (iv @| r))) iv); assert (Seq.equal (raw_cipher (Entry p (iv @| r))) r)
false
EtM.CPA.fst
EtM.CPA.iv_of_entry_inj
val iv_of_entry_inj (e1 e2: log_entry) : Lemma (iv_of_entry e1 <> iv_of_entry e2 ==> Entry?.c e1 <> Entry?.c e2)
val iv_of_entry_inj (e1 e2: log_entry) : Lemma (iv_of_entry e1 <> iv_of_entry e2 ==> Entry?.c e1 <> Entry?.c e2)
let iv_of_entry_inj (e1 e2:log_entry) : Lemma (iv_of_entry e1 <> iv_of_entry e2 ==> Entry?.c e1 <> Entry?.c e2) = let iv1, r1 = iv_of_entry e1, raw_cipher e1 in let iv2, r2 = iv_of_entry e2, raw_cipher e2 in FStar.Classical.move_requires (Platform.Bytes.lemma_append_inj iv1 r1 iv2) r2
{ "file_name": "examples/crypto/EtM.CPA.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 81, "end_line": 74, "start_col": 0, "start_line": 69 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module EtM.CPA open FStar.HyperStack.ST open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open EtM.Ideal open Platform.Bytes module CC = EtM.CoreCrypto module B = Platform.Bytes open EtM.Plain type rid = erid (*** Basic types ***) /// Initialization vectors: bytes of a given size let ivsize = CC.blockSize CC.AES_128_CBC let iv = lbytes ivsize /// Raw keys for AES 128 let keysize = 16 let aes_key = lbytes keysize /// Cipher-texts are a concatenation of the IV and the AES cipher /// -- we underspecify its length /// -- MK says: minimal cipher length twice blocksize? let cipher = (b:bytes{B.length b >= ivsize}) (*** Ideal state ***) /// CPA log entries are pairs of a plain text and its corresponding cipher type log_entry = | Entry: plain:plain -> c:cipher -> log_entry /// Recover the IV from an entry by splitting out a prefix of the cipher let iv_of_entry (Entry _ c) : iv = fst (B.split c ivsize) /// Recover the AES cipher from an entry by splitting out a suffix of the cipher let raw_cipher (Entry _ c) : bytes = snd (B.split c ivsize) /// A lemma inverting the iv+cipher construction let split_entry (p:plain) (c:cipher) (iv:iv) (r:bytes) : Lemma (iv_of_entry (Entry p (iv@|r)) == iv /\ raw_cipher (Entry p (iv@|r)) == r) = assert (Seq.equal (iv_of_entry (Entry p (iv@|r))) iv); assert (Seq.equal (raw_cipher (Entry p (iv@|r))) r) /// A lemma showing that entries that differ on their IVs differ on their ciphers
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked", "EtM.Plain.fsti.checked", "EtM.Ideal.fsti.checked", "EtM.CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.CPA.fst" }
[ { "abbrev": false, "full_module": "EtM.Plain", "short_module": null }, { "abbrev": true, "full_module": "Platform.Bytes", "short_module": "B" }, { "abbrev": true, "full_module": "EtM.CoreCrypto", "short_module": "CC" }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": false, "full_module": "EtM.Ideal", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
e1: EtM.CPA.log_entry -> e2: EtM.CPA.log_entry -> FStar.Pervasives.Lemma (ensures EtM.CPA.iv_of_entry e1 <> EtM.CPA.iv_of_entry e2 ==> Entry?.c e1 <> Entry?.c e2)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "EtM.CPA.log_entry", "Platform.Bytes.bytes", "FStar.Classical.move_requires", "Prims.l_or", "Prims.b2t", "Prims.op_Equality", "Prims.nat", "FStar.Seq.Base.length", "Platform.Bytes.byte", "FStar.Seq.Base.equal", "FStar.Seq.Base.append", "Prims.l_and", "Platform.Bytes.lemma_append_inj", "Prims.unit", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2", "EtM.CPA.iv_of_entry", "EtM.CPA.raw_cipher", "Prims.l_True", "Prims.squash", "Prims.l_imp", "Prims.op_disEquality", "EtM.CPA.iv", "EtM.CPA.cipher", "EtM.CPA.__proj__Entry__item__c", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let iv_of_entry_inj (e1 e2: log_entry) : Lemma (iv_of_entry e1 <> iv_of_entry e2 ==> Entry?.c e1 <> Entry?.c e2) =
let iv1, r1 = iv_of_entry e1, raw_cipher e1 in let iv2, r2 = iv_of_entry e2, raw_cipher e2 in FStar.Classical.move_requires (Platform.Bytes.lemma_append_inj iv1 r1 iv2) r2
false
EtM.CPA.fst
EtM.CPA.invert_pairwise
val invert_pairwise (cpas: Seq.seq log_entry) (e: log_entry) (c: cipher) : Lemma (requires (pairwise_distinct_ivs (snoc cpas e) /\ Entry?.c e == c)) (ensures (forall e'. Seq.mem e' cpas ==> Entry?.c e' <> c))
val invert_pairwise (cpas: Seq.seq log_entry) (e: log_entry) (c: cipher) : Lemma (requires (pairwise_distinct_ivs (snoc cpas e) /\ Entry?.c e == c)) (ensures (forall e'. Seq.mem e' cpas ==> Entry?.c e' <> c))
let invert_pairwise (cpas:Seq.seq log_entry) (e:log_entry) (c:cipher) : Lemma (requires (pairwise_distinct_ivs (snoc cpas e) /\ Entry?.c e == c)) (ensures (forall e'. Seq.mem e' cpas ==> Entry?.c e' <> c)) = pairwise_snoc cpas e; FStar.Classical.forall_intro (iv_of_entry_inj e)
{ "file_name": "examples/crypto/EtM.CPA.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 54, "end_line": 148, "start_col": 0, "start_line": 143 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module EtM.CPA open FStar.HyperStack.ST open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open EtM.Ideal open Platform.Bytes module CC = EtM.CoreCrypto module B = Platform.Bytes open EtM.Plain type rid = erid (*** Basic types ***) /// Initialization vectors: bytes of a given size let ivsize = CC.blockSize CC.AES_128_CBC let iv = lbytes ivsize /// Raw keys for AES 128 let keysize = 16 let aes_key = lbytes keysize /// Cipher-texts are a concatenation of the IV and the AES cipher /// -- we underspecify its length /// -- MK says: minimal cipher length twice blocksize? let cipher = (b:bytes{B.length b >= ivsize}) (*** Ideal state ***) /// CPA log entries are pairs of a plain text and its corresponding cipher type log_entry = | Entry: plain:plain -> c:cipher -> log_entry /// Recover the IV from an entry by splitting out a prefix of the cipher let iv_of_entry (Entry _ c) : iv = fst (B.split c ivsize) /// Recover the AES cipher from an entry by splitting out a suffix of the cipher let raw_cipher (Entry _ c) : bytes = snd (B.split c ivsize) /// A lemma inverting the iv+cipher construction let split_entry (p:plain) (c:cipher) (iv:iv) (r:bytes) : Lemma (iv_of_entry (Entry p (iv@|r)) == iv /\ raw_cipher (Entry p (iv@|r)) == r) = assert (Seq.equal (iv_of_entry (Entry p (iv@|r))) iv); assert (Seq.equal (raw_cipher (Entry p (iv@|r))) r) /// A lemma showing that entries that differ on their IVs differ on their ciphers /// -- because append is injective on both its arguments let iv_of_entry_inj (e1 e2:log_entry) : Lemma (iv_of_entry e1 <> iv_of_entry e2 ==> Entry?.c e1 <> Entry?.c e2) = let iv1, r1 = iv_of_entry e1, raw_cipher e1 in let iv2, r2 = iv_of_entry e2, raw_cipher e2 in FStar.Classical.move_requires (Platform.Bytes.lemma_append_inj iv1 r1 iv2) r2 /// A key includes the raw AES key but also an monotonic log of entries /// representing the ideal state noeq type key = | Key: #region:rid -> raw:aes_key -> log:Monotonic.Seq.log_t region log_entry -> key (** Exercise: (conceptually easy; technically difficult) The type `key` above contains a reference to an ideal log unconditionally. However, this log is redundant when not idealizing. Revise the `key` type as shown below and propagate it through the development. noeq type key = | Key: #region:rid -> raw:aes_key -> log:(if Ideal.ind_cpa then Monotonic.Seq.log_t region log_entry else unit) -> key **) /// An accessor for the log in state h let log (k:key) (h:mem) : GTot (seq log_entry) = sel h (Key?.log k) (*** Invariants on the ideal state ***) (** Informally, there are two main components to the invariant: 1. The IVs in the log are pairwise-distinct. We rely on this to obtain an injectivity property in EtM.AE, using it to relate the CPA and MAC logs to the composite AE log. 2. The ciphers in each entry are required to be valid encryptions of the corresponding plain texts and IVs **) /// --------------------------------------- /// Invariant part 1: distinctness of IVs /// --------------------------------------- let iv_not_in (iv:iv) (log:seq log_entry) = forall (e:log_entry{Seq.mem e log}). iv_of_entry e <> iv /// We state pairwise-distinctness of IVs in this recursive form /// It makes it more convenient to work with as we /// append each new entry (aka snoc) to the end of the log let rec pairwise_distinct_ivs (log:seq log_entry) : Tot Type0 (decreases (Seq.length log)) = if Seq.length log > 0 then let log, tl = Seq.un_snoc log in pairwise_distinct_ivs log /\ iv_not_in (iv_of_entry tl) log else True /// A simple lemma to introduce and eliminate pairwise_distinct_ivs let pairwise_snoc (cpas:Seq.seq log_entry) (tl:log_entry) : Lemma ((pairwise_distinct_ivs cpas /\ iv_not_in (iv_of_entry tl) cpas) <==> (pairwise_distinct_ivs (Seq.snoc cpas tl))) = un_snoc_snoc cpas tl /// It's convenient to lift the pairwise-distinctness of IVs to
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked", "EtM.Plain.fsti.checked", "EtM.Ideal.fsti.checked", "EtM.CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.CPA.fst" }
[ { "abbrev": false, "full_module": "EtM.Plain", "short_module": null }, { "abbrev": true, "full_module": "Platform.Bytes", "short_module": "B" }, { "abbrev": true, "full_module": "EtM.CoreCrypto", "short_module": "CC" }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": false, "full_module": "EtM.Ideal", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cpas: FStar.Seq.Base.seq EtM.CPA.log_entry -> e: EtM.CPA.log_entry -> c: EtM.CPA.cipher -> FStar.Pervasives.Lemma (requires EtM.CPA.pairwise_distinct_ivs (FStar.Monotonic.Seq.snoc cpas e) /\ Entry?.c e == c) (ensures forall (e': EtM.CPA.log_entry). FStar.Seq.Properties.mem e' cpas ==> Entry?.c e' <> c )
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Seq.Base.seq", "EtM.CPA.log_entry", "EtM.CPA.cipher", "FStar.Classical.forall_intro", "Prims.l_imp", "Prims.b2t", "Prims.op_disEquality", "EtM.CPA.iv", "EtM.CPA.iv_of_entry", "EtM.CPA.__proj__Entry__item__c", "EtM.CPA.iv_of_entry_inj", "Prims.unit", "EtM.CPA.pairwise_snoc", "Prims.l_and", "EtM.CPA.pairwise_distinct_ivs", "FStar.Monotonic.Seq.snoc", "Prims.eq2", "Prims.squash", "Prims.l_Forall", "FStar.Seq.Properties.mem", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let invert_pairwise (cpas: Seq.seq log_entry) (e: log_entry) (c: cipher) : Lemma (requires (pairwise_distinct_ivs (snoc cpas e) /\ Entry?.c e == c)) (ensures (forall e'. Seq.mem e' cpas ==> Entry?.c e' <> c)) =
pairwise_snoc cpas e; FStar.Classical.forall_intro (iv_of_entry_inj e)
false
EtM.CPA.fst
EtM.CPA.pairwise_snoc
val pairwise_snoc (cpas: Seq.seq log_entry) (tl: log_entry) : Lemma ((pairwise_distinct_ivs cpas /\ iv_not_in (iv_of_entry tl) cpas) <==> (pairwise_distinct_ivs (Seq.snoc cpas tl)))
val pairwise_snoc (cpas: Seq.seq log_entry) (tl: log_entry) : Lemma ((pairwise_distinct_ivs cpas /\ iv_not_in (iv_of_entry tl) cpas) <==> (pairwise_distinct_ivs (Seq.snoc cpas tl)))
let pairwise_snoc (cpas:Seq.seq log_entry) (tl:log_entry) : Lemma ((pairwise_distinct_ivs cpas /\ iv_not_in (iv_of_entry tl) cpas) <==> (pairwise_distinct_ivs (Seq.snoc cpas tl))) = un_snoc_snoc cpas tl
{ "file_name": "examples/crypto/EtM.CPA.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 26, "end_line": 139, "start_col": 0, "start_line": 136 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module EtM.CPA open FStar.HyperStack.ST open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open EtM.Ideal open Platform.Bytes module CC = EtM.CoreCrypto module B = Platform.Bytes open EtM.Plain type rid = erid (*** Basic types ***) /// Initialization vectors: bytes of a given size let ivsize = CC.blockSize CC.AES_128_CBC let iv = lbytes ivsize /// Raw keys for AES 128 let keysize = 16 let aes_key = lbytes keysize /// Cipher-texts are a concatenation of the IV and the AES cipher /// -- we underspecify its length /// -- MK says: minimal cipher length twice blocksize? let cipher = (b:bytes{B.length b >= ivsize}) (*** Ideal state ***) /// CPA log entries are pairs of a plain text and its corresponding cipher type log_entry = | Entry: plain:plain -> c:cipher -> log_entry /// Recover the IV from an entry by splitting out a prefix of the cipher let iv_of_entry (Entry _ c) : iv = fst (B.split c ivsize) /// Recover the AES cipher from an entry by splitting out a suffix of the cipher let raw_cipher (Entry _ c) : bytes = snd (B.split c ivsize) /// A lemma inverting the iv+cipher construction let split_entry (p:plain) (c:cipher) (iv:iv) (r:bytes) : Lemma (iv_of_entry (Entry p (iv@|r)) == iv /\ raw_cipher (Entry p (iv@|r)) == r) = assert (Seq.equal (iv_of_entry (Entry p (iv@|r))) iv); assert (Seq.equal (raw_cipher (Entry p (iv@|r))) r) /// A lemma showing that entries that differ on their IVs differ on their ciphers /// -- because append is injective on both its arguments let iv_of_entry_inj (e1 e2:log_entry) : Lemma (iv_of_entry e1 <> iv_of_entry e2 ==> Entry?.c e1 <> Entry?.c e2) = let iv1, r1 = iv_of_entry e1, raw_cipher e1 in let iv2, r2 = iv_of_entry e2, raw_cipher e2 in FStar.Classical.move_requires (Platform.Bytes.lemma_append_inj iv1 r1 iv2) r2 /// A key includes the raw AES key but also an monotonic log of entries /// representing the ideal state noeq type key = | Key: #region:rid -> raw:aes_key -> log:Monotonic.Seq.log_t region log_entry -> key (** Exercise: (conceptually easy; technically difficult) The type `key` above contains a reference to an ideal log unconditionally. However, this log is redundant when not idealizing. Revise the `key` type as shown below and propagate it through the development. noeq type key = | Key: #region:rid -> raw:aes_key -> log:(if Ideal.ind_cpa then Monotonic.Seq.log_t region log_entry else unit) -> key **) /// An accessor for the log in state h let log (k:key) (h:mem) : GTot (seq log_entry) = sel h (Key?.log k) (*** Invariants on the ideal state ***) (** Informally, there are two main components to the invariant: 1. The IVs in the log are pairwise-distinct. We rely on this to obtain an injectivity property in EtM.AE, using it to relate the CPA and MAC logs to the composite AE log. 2. The ciphers in each entry are required to be valid encryptions of the corresponding plain texts and IVs **) /// --------------------------------------- /// Invariant part 1: distinctness of IVs /// --------------------------------------- let iv_not_in (iv:iv) (log:seq log_entry) = forall (e:log_entry{Seq.mem e log}). iv_of_entry e <> iv /// We state pairwise-distinctness of IVs in this recursive form /// It makes it more convenient to work with as we /// append each new entry (aka snoc) to the end of the log let rec pairwise_distinct_ivs (log:seq log_entry) : Tot Type0 (decreases (Seq.length log)) = if Seq.length log > 0 then let log, tl = Seq.un_snoc log in pairwise_distinct_ivs log /\ iv_not_in (iv_of_entry tl) log else True
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked", "EtM.Plain.fsti.checked", "EtM.Ideal.fsti.checked", "EtM.CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.CPA.fst" }
[ { "abbrev": false, "full_module": "EtM.Plain", "short_module": null }, { "abbrev": true, "full_module": "Platform.Bytes", "short_module": "B" }, { "abbrev": true, "full_module": "EtM.CoreCrypto", "short_module": "CC" }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": false, "full_module": "EtM.Ideal", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cpas: FStar.Seq.Base.seq EtM.CPA.log_entry -> tl: EtM.CPA.log_entry -> FStar.Pervasives.Lemma (ensures EtM.CPA.pairwise_distinct_ivs cpas /\ EtM.CPA.iv_not_in (EtM.CPA.iv_of_entry tl) cpas <==> EtM.CPA.pairwise_distinct_ivs (FStar.Seq.Properties.snoc cpas tl))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Seq.Base.seq", "EtM.CPA.log_entry", "FStar.Seq.Properties.un_snoc_snoc", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_iff", "Prims.l_and", "EtM.CPA.pairwise_distinct_ivs", "EtM.CPA.iv_not_in", "EtM.CPA.iv_of_entry", "FStar.Seq.Properties.snoc", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let pairwise_snoc (cpas: Seq.seq log_entry) (tl: log_entry) : Lemma ((pairwise_distinct_ivs cpas /\ iv_not_in (iv_of_entry tl) cpas) <==> (pairwise_distinct_ivs (Seq.snoc cpas tl))) =
un_snoc_snoc cpas tl
false
EtM.CPA.fst
EtM.CPA.cipher_functional_correctness
val cipher_functional_correctness : raw_key: Platform.Bytes.bytes -> log: FStar.Seq.Base.seq EtM.CPA.log_entry -> Prims.logical
let cipher_functional_correctness (raw_key:bytes) (log:seq log_entry) = forall (e:log_entry{Seq.mem e log}). {:pattern (Seq.mem e log)} entry_functional_correctness raw_key e
{ "file_name": "examples/crypto/EtM.CPA.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 44, "end_line": 168, "start_col": 0, "start_line": 166 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module EtM.CPA open FStar.HyperStack.ST open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open EtM.Ideal open Platform.Bytes module CC = EtM.CoreCrypto module B = Platform.Bytes open EtM.Plain type rid = erid (*** Basic types ***) /// Initialization vectors: bytes of a given size let ivsize = CC.blockSize CC.AES_128_CBC let iv = lbytes ivsize /// Raw keys for AES 128 let keysize = 16 let aes_key = lbytes keysize /// Cipher-texts are a concatenation of the IV and the AES cipher /// -- we underspecify its length /// -- MK says: minimal cipher length twice blocksize? let cipher = (b:bytes{B.length b >= ivsize}) (*** Ideal state ***) /// CPA log entries are pairs of a plain text and its corresponding cipher type log_entry = | Entry: plain:plain -> c:cipher -> log_entry /// Recover the IV from an entry by splitting out a prefix of the cipher let iv_of_entry (Entry _ c) : iv = fst (B.split c ivsize) /// Recover the AES cipher from an entry by splitting out a suffix of the cipher let raw_cipher (Entry _ c) : bytes = snd (B.split c ivsize) /// A lemma inverting the iv+cipher construction let split_entry (p:plain) (c:cipher) (iv:iv) (r:bytes) : Lemma (iv_of_entry (Entry p (iv@|r)) == iv /\ raw_cipher (Entry p (iv@|r)) == r) = assert (Seq.equal (iv_of_entry (Entry p (iv@|r))) iv); assert (Seq.equal (raw_cipher (Entry p (iv@|r))) r) /// A lemma showing that entries that differ on their IVs differ on their ciphers /// -- because append is injective on both its arguments let iv_of_entry_inj (e1 e2:log_entry) : Lemma (iv_of_entry e1 <> iv_of_entry e2 ==> Entry?.c e1 <> Entry?.c e2) = let iv1, r1 = iv_of_entry e1, raw_cipher e1 in let iv2, r2 = iv_of_entry e2, raw_cipher e2 in FStar.Classical.move_requires (Platform.Bytes.lemma_append_inj iv1 r1 iv2) r2 /// A key includes the raw AES key but also an monotonic log of entries /// representing the ideal state noeq type key = | Key: #region:rid -> raw:aes_key -> log:Monotonic.Seq.log_t region log_entry -> key (** Exercise: (conceptually easy; technically difficult) The type `key` above contains a reference to an ideal log unconditionally. However, this log is redundant when not idealizing. Revise the `key` type as shown below and propagate it through the development. noeq type key = | Key: #region:rid -> raw:aes_key -> log:(if Ideal.ind_cpa then Monotonic.Seq.log_t region log_entry else unit) -> key **) /// An accessor for the log in state h let log (k:key) (h:mem) : GTot (seq log_entry) = sel h (Key?.log k) (*** Invariants on the ideal state ***) (** Informally, there are two main components to the invariant: 1. The IVs in the log are pairwise-distinct. We rely on this to obtain an injectivity property in EtM.AE, using it to relate the CPA and MAC logs to the composite AE log. 2. The ciphers in each entry are required to be valid encryptions of the corresponding plain texts and IVs **) /// --------------------------------------- /// Invariant part 1: distinctness of IVs /// --------------------------------------- let iv_not_in (iv:iv) (log:seq log_entry) = forall (e:log_entry{Seq.mem e log}). iv_of_entry e <> iv /// We state pairwise-distinctness of IVs in this recursive form /// It makes it more convenient to work with as we /// append each new entry (aka snoc) to the end of the log let rec pairwise_distinct_ivs (log:seq log_entry) : Tot Type0 (decreases (Seq.length log)) = if Seq.length log > 0 then let log, tl = Seq.un_snoc log in pairwise_distinct_ivs log /\ iv_not_in (iv_of_entry tl) log else True /// A simple lemma to introduce and eliminate pairwise_distinct_ivs let pairwise_snoc (cpas:Seq.seq log_entry) (tl:log_entry) : Lemma ((pairwise_distinct_ivs cpas /\ iv_not_in (iv_of_entry tl) cpas) <==> (pairwise_distinct_ivs (Seq.snoc cpas tl))) = un_snoc_snoc cpas tl /// It's convenient to lift the pairwise-distinctness of IVs to /// pairwise distinctness of the cipher texts let invert_pairwise (cpas:Seq.seq log_entry) (e:log_entry) (c:cipher) : Lemma (requires (pairwise_distinct_ivs (snoc cpas e) /\ Entry?.c e == c)) (ensures (forall e'. Seq.mem e' cpas ==> Entry?.c e' <> c)) = pairwise_snoc cpas e; FStar.Classical.forall_intro (iv_of_entry_inj e) /// ----------------------------------------- /// Invariant part 2: correctness of ciphers /// ----------------------------------------- /// Each entry contains a valid AES encryption /// /// -- A wrinkle is that when ind_cpa, rather than encrypting the /// plaintext we just encrypt zeros let entry_functional_correctness (raw_key:bytes) (e:log_entry) : Type0 = let iv = iv_of_entry e in let c = raw_cipher e in let plain = Entry?.plain e in let p = if ind_cpa then createBytes (length plain) 0z else repr plain in c == CC.block_encrypt_spec CC.AES_128_CBC raw_key iv p
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked", "EtM.Plain.fsti.checked", "EtM.Ideal.fsti.checked", "EtM.CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.CPA.fst" }
[ { "abbrev": false, "full_module": "EtM.Plain", "short_module": null }, { "abbrev": true, "full_module": "Platform.Bytes", "short_module": "B" }, { "abbrev": true, "full_module": "EtM.CoreCrypto", "short_module": "CC" }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": false, "full_module": "EtM.Ideal", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
raw_key: Platform.Bytes.bytes -> log: FStar.Seq.Base.seq EtM.CPA.log_entry -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Platform.Bytes.bytes", "FStar.Seq.Base.seq", "EtM.CPA.log_entry", "Prims.l_Forall", "Prims.b2t", "FStar.Seq.Properties.mem", "EtM.CPA.entry_functional_correctness", "Prims.logical" ]
[]
false
false
false
true
true
let cipher_functional_correctness (raw_key: bytes) (log: seq log_entry) =
forall (e: log_entry{Seq.mem e log}). {:pattern (Seq.mem e log)} entry_functional_correctness raw_key e
false
EtM.CPA.fst
EtM.CPA.entry_functional_correctness
val entry_functional_correctness (raw_key: bytes) (e: log_entry) : Type0
val entry_functional_correctness (raw_key: bytes) (e: log_entry) : Type0
let entry_functional_correctness (raw_key:bytes) (e:log_entry) : Type0 = let iv = iv_of_entry e in let c = raw_cipher e in let plain = Entry?.plain e in let p = if ind_cpa then createBytes (length plain) 0z else repr plain in c == CC.block_encrypt_spec CC.AES_128_CBC raw_key iv p
{ "file_name": "examples/crypto/EtM.CPA.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 59, "end_line": 163, "start_col": 0, "start_line": 158 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module EtM.CPA open FStar.HyperStack.ST open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open EtM.Ideal open Platform.Bytes module CC = EtM.CoreCrypto module B = Platform.Bytes open EtM.Plain type rid = erid (*** Basic types ***) /// Initialization vectors: bytes of a given size let ivsize = CC.blockSize CC.AES_128_CBC let iv = lbytes ivsize /// Raw keys for AES 128 let keysize = 16 let aes_key = lbytes keysize /// Cipher-texts are a concatenation of the IV and the AES cipher /// -- we underspecify its length /// -- MK says: minimal cipher length twice blocksize? let cipher = (b:bytes{B.length b >= ivsize}) (*** Ideal state ***) /// CPA log entries are pairs of a plain text and its corresponding cipher type log_entry = | Entry: plain:plain -> c:cipher -> log_entry /// Recover the IV from an entry by splitting out a prefix of the cipher let iv_of_entry (Entry _ c) : iv = fst (B.split c ivsize) /// Recover the AES cipher from an entry by splitting out a suffix of the cipher let raw_cipher (Entry _ c) : bytes = snd (B.split c ivsize) /// A lemma inverting the iv+cipher construction let split_entry (p:plain) (c:cipher) (iv:iv) (r:bytes) : Lemma (iv_of_entry (Entry p (iv@|r)) == iv /\ raw_cipher (Entry p (iv@|r)) == r) = assert (Seq.equal (iv_of_entry (Entry p (iv@|r))) iv); assert (Seq.equal (raw_cipher (Entry p (iv@|r))) r) /// A lemma showing that entries that differ on their IVs differ on their ciphers /// -- because append is injective on both its arguments let iv_of_entry_inj (e1 e2:log_entry) : Lemma (iv_of_entry e1 <> iv_of_entry e2 ==> Entry?.c e1 <> Entry?.c e2) = let iv1, r1 = iv_of_entry e1, raw_cipher e1 in let iv2, r2 = iv_of_entry e2, raw_cipher e2 in FStar.Classical.move_requires (Platform.Bytes.lemma_append_inj iv1 r1 iv2) r2 /// A key includes the raw AES key but also an monotonic log of entries /// representing the ideal state noeq type key = | Key: #region:rid -> raw:aes_key -> log:Monotonic.Seq.log_t region log_entry -> key (** Exercise: (conceptually easy; technically difficult) The type `key` above contains a reference to an ideal log unconditionally. However, this log is redundant when not idealizing. Revise the `key` type as shown below and propagate it through the development. noeq type key = | Key: #region:rid -> raw:aes_key -> log:(if Ideal.ind_cpa then Monotonic.Seq.log_t region log_entry else unit) -> key **) /// An accessor for the log in state h let log (k:key) (h:mem) : GTot (seq log_entry) = sel h (Key?.log k) (*** Invariants on the ideal state ***) (** Informally, there are two main components to the invariant: 1. The IVs in the log are pairwise-distinct. We rely on this to obtain an injectivity property in EtM.AE, using it to relate the CPA and MAC logs to the composite AE log. 2. The ciphers in each entry are required to be valid encryptions of the corresponding plain texts and IVs **) /// --------------------------------------- /// Invariant part 1: distinctness of IVs /// --------------------------------------- let iv_not_in (iv:iv) (log:seq log_entry) = forall (e:log_entry{Seq.mem e log}). iv_of_entry e <> iv /// We state pairwise-distinctness of IVs in this recursive form /// It makes it more convenient to work with as we /// append each new entry (aka snoc) to the end of the log let rec pairwise_distinct_ivs (log:seq log_entry) : Tot Type0 (decreases (Seq.length log)) = if Seq.length log > 0 then let log, tl = Seq.un_snoc log in pairwise_distinct_ivs log /\ iv_not_in (iv_of_entry tl) log else True /// A simple lemma to introduce and eliminate pairwise_distinct_ivs let pairwise_snoc (cpas:Seq.seq log_entry) (tl:log_entry) : Lemma ((pairwise_distinct_ivs cpas /\ iv_not_in (iv_of_entry tl) cpas) <==> (pairwise_distinct_ivs (Seq.snoc cpas tl))) = un_snoc_snoc cpas tl /// It's convenient to lift the pairwise-distinctness of IVs to /// pairwise distinctness of the cipher texts let invert_pairwise (cpas:Seq.seq log_entry) (e:log_entry) (c:cipher) : Lemma (requires (pairwise_distinct_ivs (snoc cpas e) /\ Entry?.c e == c)) (ensures (forall e'. Seq.mem e' cpas ==> Entry?.c e' <> c)) = pairwise_snoc cpas e; FStar.Classical.forall_intro (iv_of_entry_inj e) /// ----------------------------------------- /// Invariant part 2: correctness of ciphers /// ----------------------------------------- /// Each entry contains a valid AES encryption /// /// -- A wrinkle is that when ind_cpa, rather than encrypting the
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked", "EtM.Plain.fsti.checked", "EtM.Ideal.fsti.checked", "EtM.CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.CPA.fst" }
[ { "abbrev": false, "full_module": "EtM.Plain", "short_module": null }, { "abbrev": true, "full_module": "Platform.Bytes", "short_module": "B" }, { "abbrev": true, "full_module": "EtM.CoreCrypto", "short_module": "CC" }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": false, "full_module": "EtM.Ideal", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
raw_key: Platform.Bytes.bytes -> e: EtM.CPA.log_entry -> Type0
Prims.Tot
[ "total" ]
[]
[ "Platform.Bytes.bytes", "EtM.CPA.log_entry", "Prims.eq2", "EtM.CoreCrypto.block_encrypt_spec", "CoreCrypto.AES_128_CBC", "EtM.Ideal.ind_cpa", "Platform.Bytes.createBytes", "EtM.Plain.length", "FStar.UInt8.__uint_to_t", "Prims.bool", "EtM.Plain.repr", "EtM.Plain.plain", "EtM.CPA.__proj__Entry__item__plain", "EtM.CPA.raw_cipher", "EtM.CPA.iv", "EtM.CPA.iv_of_entry" ]
[]
false
false
false
true
true
let entry_functional_correctness (raw_key: bytes) (e: log_entry) : Type0 =
let iv = iv_of_entry e in let c = raw_cipher e in let plain = Entry?.plain e in let p = if ind_cpa then createBytes (length plain) 0uy else repr plain in c == CC.block_encrypt_spec CC.AES_128_CBC raw_key iv p
false
EtM.CPA.fst
EtM.CPA.encrypt
val encrypt (k: key) (m: plain) : ST cipher (requires (invariant k)) (ensures (fun h0 c h1 -> (let log0 = log k h0 in let log1 = log k h1 in invariant k h1 /\ modifies_one k.region h0 h1 /\ contains h1 k.log /\ log1 == snoc log0 (Entry m c))))
val encrypt (k: key) (m: plain) : ST cipher (requires (invariant k)) (ensures (fun h0 c h1 -> (let log0 = log k h0 in let log1 = log k h1 in invariant k h1 /\ modifies_one k.region h0 h1 /\ contains h1 k.log /\ log1 == snoc log0 (Entry m c))))
let encrypt (k:key) (m:plain) : ST cipher (requires (invariant k)) (ensures (fun h0 c h1 -> (let log0 = log k h0 in let log1 = log k h1 in invariant k h1 /\ modifies_one k.region h0 h1 /\ contains h1 k.log /\ log1 == snoc log0 (Entry m c)))) = let iv = fresh_iv k in let text = if ind_cpa then createBytes (length m) 0z else repr m in let raw_c = CC.block_enc CC.AES_128_CBC k.raw iv text in let c = iv@|raw_c in let e = Entry m c in split_entry m c iv raw_c; assert (entry_functional_correctness k.raw e); let h0 = FStar.HyperStack.ST.get () in write_at_end k.log e; let h1 = FStar.HyperStack.ST.get () in lemma_mem_snoc (log k h0) e; pairwise_snoc (log k h0) e; c
{ "file_name": "examples/crypto/EtM.CPA.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 239, "start_col": 0, "start_line": 215 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module EtM.CPA open FStar.HyperStack.ST open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open EtM.Ideal open Platform.Bytes module CC = EtM.CoreCrypto module B = Platform.Bytes open EtM.Plain type rid = erid (*** Basic types ***) /// Initialization vectors: bytes of a given size let ivsize = CC.blockSize CC.AES_128_CBC let iv = lbytes ivsize /// Raw keys for AES 128 let keysize = 16 let aes_key = lbytes keysize /// Cipher-texts are a concatenation of the IV and the AES cipher /// -- we underspecify its length /// -- MK says: minimal cipher length twice blocksize? let cipher = (b:bytes{B.length b >= ivsize}) (*** Ideal state ***) /// CPA log entries are pairs of a plain text and its corresponding cipher type log_entry = | Entry: plain:plain -> c:cipher -> log_entry /// Recover the IV from an entry by splitting out a prefix of the cipher let iv_of_entry (Entry _ c) : iv = fst (B.split c ivsize) /// Recover the AES cipher from an entry by splitting out a suffix of the cipher let raw_cipher (Entry _ c) : bytes = snd (B.split c ivsize) /// A lemma inverting the iv+cipher construction let split_entry (p:plain) (c:cipher) (iv:iv) (r:bytes) : Lemma (iv_of_entry (Entry p (iv@|r)) == iv /\ raw_cipher (Entry p (iv@|r)) == r) = assert (Seq.equal (iv_of_entry (Entry p (iv@|r))) iv); assert (Seq.equal (raw_cipher (Entry p (iv@|r))) r) /// A lemma showing that entries that differ on their IVs differ on their ciphers /// -- because append is injective on both its arguments let iv_of_entry_inj (e1 e2:log_entry) : Lemma (iv_of_entry e1 <> iv_of_entry e2 ==> Entry?.c e1 <> Entry?.c e2) = let iv1, r1 = iv_of_entry e1, raw_cipher e1 in let iv2, r2 = iv_of_entry e2, raw_cipher e2 in FStar.Classical.move_requires (Platform.Bytes.lemma_append_inj iv1 r1 iv2) r2 /// A key includes the raw AES key but also an monotonic log of entries /// representing the ideal state noeq type key = | Key: #region:rid -> raw:aes_key -> log:Monotonic.Seq.log_t region log_entry -> key (** Exercise: (conceptually easy; technically difficult) The type `key` above contains a reference to an ideal log unconditionally. However, this log is redundant when not idealizing. Revise the `key` type as shown below and propagate it through the development. noeq type key = | Key: #region:rid -> raw:aes_key -> log:(if Ideal.ind_cpa then Monotonic.Seq.log_t region log_entry else unit) -> key **) /// An accessor for the log in state h let log (k:key) (h:mem) : GTot (seq log_entry) = sel h (Key?.log k) (*** Invariants on the ideal state ***) (** Informally, there are two main components to the invariant: 1. The IVs in the log are pairwise-distinct. We rely on this to obtain an injectivity property in EtM.AE, using it to relate the CPA and MAC logs to the composite AE log. 2. The ciphers in each entry are required to be valid encryptions of the corresponding plain texts and IVs **) /// --------------------------------------- /// Invariant part 1: distinctness of IVs /// --------------------------------------- let iv_not_in (iv:iv) (log:seq log_entry) = forall (e:log_entry{Seq.mem e log}). iv_of_entry e <> iv /// We state pairwise-distinctness of IVs in this recursive form /// It makes it more convenient to work with as we /// append each new entry (aka snoc) to the end of the log let rec pairwise_distinct_ivs (log:seq log_entry) : Tot Type0 (decreases (Seq.length log)) = if Seq.length log > 0 then let log, tl = Seq.un_snoc log in pairwise_distinct_ivs log /\ iv_not_in (iv_of_entry tl) log else True /// A simple lemma to introduce and eliminate pairwise_distinct_ivs let pairwise_snoc (cpas:Seq.seq log_entry) (tl:log_entry) : Lemma ((pairwise_distinct_ivs cpas /\ iv_not_in (iv_of_entry tl) cpas) <==> (pairwise_distinct_ivs (Seq.snoc cpas tl))) = un_snoc_snoc cpas tl /// It's convenient to lift the pairwise-distinctness of IVs to /// pairwise distinctness of the cipher texts let invert_pairwise (cpas:Seq.seq log_entry) (e:log_entry) (c:cipher) : Lemma (requires (pairwise_distinct_ivs (snoc cpas e) /\ Entry?.c e == c)) (ensures (forall e'. Seq.mem e' cpas ==> Entry?.c e' <> c)) = pairwise_snoc cpas e; FStar.Classical.forall_intro (iv_of_entry_inj e) /// ----------------------------------------- /// Invariant part 2: correctness of ciphers /// ----------------------------------------- /// Each entry contains a valid AES encryption /// /// -- A wrinkle is that when ind_cpa, rather than encrypting the /// plaintext we just encrypt zeros let entry_functional_correctness (raw_key:bytes) (e:log_entry) : Type0 = let iv = iv_of_entry e in let c = raw_cipher e in let plain = Entry?.plain e in let p = if ind_cpa then createBytes (length plain) 0z else repr plain in c == CC.block_encrypt_spec CC.AES_128_CBC raw_key iv p /// Lifting the correctness of individual entries pointwise to correctness of the entire log let cipher_functional_correctness (raw_key:bytes) (log:seq log_entry) = forall (e:log_entry{Seq.mem e log}). {:pattern (Seq.mem e log)} entry_functional_correctness raw_key e /// The invariant is the conjunction of distinctness and correctness /// -- Together with a technical requirement of the log actually /// being present in the memory let invariant (k:key) (h:mem) = let Key raw_key lg = k in let log = log k h in contains h lg /\ //<-- technical: the log must be allocated pairwise_distinct_ivs log /\ cipher_functional_correctness raw_key log (*** The main interface: keygen, encrypt, decrypt ***) /// keygen: allocating a new key /// -- Caller provides a parent region in which to allocate the ideal log /// -- Returns a fresh key satisfying its invariant whose log is initially empty let keygen (parent:rid) : ST key (requires (fun _ -> HyperStack.ST.witnessed (region_contains_pred parent))) (ensures (fun m0 k m1 -> modifies Set.empty m0 m1 /\ extends k.region parent /\ fresh_region k.region m0 m1 /\ log k m1 == Seq.empty /\ invariant k m1)) = let raw = CC.random keysize in let region = new_region parent in let log = alloc_mref_seq region Seq.empty in Key #region raw log /// A primitive to sample a fresh iv distinct from others /// Exercise: Implement this, e.g, by simply incrementing a counter /// Or by sampling and retrying assume val fresh_iv (k:key) : ST iv (requires (fun h -> True)) (ensures (fun h0 iv h1 -> h0 == h1 /\ iv_not_in iv (log k h0))) /// encrypt: /// -- requires a key initially in the invariant /// -- ensures that only the key's region is modified
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked", "EtM.Plain.fsti.checked", "EtM.Ideal.fsti.checked", "EtM.CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.CPA.fst" }
[ { "abbrev": false, "full_module": "EtM.Plain", "short_module": null }, { "abbrev": true, "full_module": "Platform.Bytes", "short_module": "B" }, { "abbrev": true, "full_module": "EtM.CoreCrypto", "short_module": "CC" }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": false, "full_module": "EtM.Ideal", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k: EtM.CPA.key -> m: EtM.Plain.plain -> FStar.HyperStack.ST.ST EtM.CPA.cipher
FStar.HyperStack.ST.ST
[]
[]
[ "EtM.CPA.key", "EtM.Plain.plain", "Prims.unit", "EtM.CPA.pairwise_snoc", "EtM.CPA.log", "FStar.Seq.Properties.lemma_mem_snoc", "EtM.CPA.log_entry", "EtM.CPA.cipher", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "FStar.Monotonic.Seq.write_at_end", "EtM.CPA.__proj__Key__item__region", "EtM.CPA.__proj__Key__item__log", "Prims._assert", "EtM.CPA.entry_functional_correctness", "EtM.CPA.__proj__Key__item__raw", "EtM.CPA.split_entry", "EtM.CPA.Entry", "Platform.Bytes.bytes", "Platform.Bytes.op_At_Bar", "Prims.eq2", "EtM.CoreCrypto.block_encrypt_spec", "CoreCrypto.AES_128_CBC", "EtM.CoreCrypto.block_enc", "EtM.Ideal.ind_cpa", "Platform.Bytes.createBytes", "EtM.Plain.length", "FStar.UInt8.__uint_to_t", "Prims.bool", "EtM.Plain.repr", "EtM.CPA.iv", "EtM.CPA.fresh_iv", "EtM.CPA.invariant", "Prims.l_and", "FStar.Monotonic.HyperStack.modifies_one", "FStar.Monotonic.HyperStack.contains", "FStar.Seq.Base.seq", "FStar.Monotonic.Seq.grows", "FStar.Monotonic.Seq.snoc" ]
[]
false
true
false
false
false
let encrypt (k: key) (m: plain) : ST cipher (requires (invariant k)) (ensures (fun h0 c h1 -> (let log0 = log k h0 in let log1 = log k h1 in invariant k h1 /\ modifies_one k.region h0 h1 /\ contains h1 k.log /\ log1 == snoc log0 (Entry m c)))) =
let iv = fresh_iv k in let text = if ind_cpa then createBytes (length m) 0uy else repr m in let raw_c = CC.block_enc CC.AES_128_CBC k.raw iv text in let c = iv @| raw_c in let e = Entry m c in split_entry m c iv raw_c; assert (entry_functional_correctness k.raw e); let h0 = FStar.HyperStack.ST.get () in write_at_end k.log e; let h1 = FStar.HyperStack.ST.get () in lemma_mem_snoc (log k h0) e; pairwise_snoc (log k h0) e; c
false
EtM.CPA.fst
EtM.CPA.keygen
val keygen (parent: rid) : ST key (requires (fun _ -> HyperStack.ST.witnessed (region_contains_pred parent))) (ensures (fun m0 k m1 -> modifies Set.empty m0 m1 /\ extends k.region parent /\ fresh_region k.region m0 m1 /\ log k m1 == Seq.empty /\ invariant k m1))
val keygen (parent: rid) : ST key (requires (fun _ -> HyperStack.ST.witnessed (region_contains_pred parent))) (ensures (fun m0 k m1 -> modifies Set.empty m0 m1 /\ extends k.region parent /\ fresh_region k.region m0 m1 /\ log k m1 == Seq.empty /\ invariant k m1))
let keygen (parent:rid) : ST key (requires (fun _ -> HyperStack.ST.witnessed (region_contains_pred parent))) (ensures (fun m0 k m1 -> modifies Set.empty m0 m1 /\ extends k.region parent /\ fresh_region k.region m0 m1 /\ log k m1 == Seq.empty /\ invariant k m1)) = let raw = CC.random keysize in let region = new_region parent in let log = alloc_mref_seq region Seq.empty in Key #region raw log
{ "file_name": "examples/crypto/EtM.CPA.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 21, "end_line": 198, "start_col": 0, "start_line": 186 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module EtM.CPA open FStar.HyperStack.ST open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open EtM.Ideal open Platform.Bytes module CC = EtM.CoreCrypto module B = Platform.Bytes open EtM.Plain type rid = erid (*** Basic types ***) /// Initialization vectors: bytes of a given size let ivsize = CC.blockSize CC.AES_128_CBC let iv = lbytes ivsize /// Raw keys for AES 128 let keysize = 16 let aes_key = lbytes keysize /// Cipher-texts are a concatenation of the IV and the AES cipher /// -- we underspecify its length /// -- MK says: minimal cipher length twice blocksize? let cipher = (b:bytes{B.length b >= ivsize}) (*** Ideal state ***) /// CPA log entries are pairs of a plain text and its corresponding cipher type log_entry = | Entry: plain:plain -> c:cipher -> log_entry /// Recover the IV from an entry by splitting out a prefix of the cipher let iv_of_entry (Entry _ c) : iv = fst (B.split c ivsize) /// Recover the AES cipher from an entry by splitting out a suffix of the cipher let raw_cipher (Entry _ c) : bytes = snd (B.split c ivsize) /// A lemma inverting the iv+cipher construction let split_entry (p:plain) (c:cipher) (iv:iv) (r:bytes) : Lemma (iv_of_entry (Entry p (iv@|r)) == iv /\ raw_cipher (Entry p (iv@|r)) == r) = assert (Seq.equal (iv_of_entry (Entry p (iv@|r))) iv); assert (Seq.equal (raw_cipher (Entry p (iv@|r))) r) /// A lemma showing that entries that differ on their IVs differ on their ciphers /// -- because append is injective on both its arguments let iv_of_entry_inj (e1 e2:log_entry) : Lemma (iv_of_entry e1 <> iv_of_entry e2 ==> Entry?.c e1 <> Entry?.c e2) = let iv1, r1 = iv_of_entry e1, raw_cipher e1 in let iv2, r2 = iv_of_entry e2, raw_cipher e2 in FStar.Classical.move_requires (Platform.Bytes.lemma_append_inj iv1 r1 iv2) r2 /// A key includes the raw AES key but also an monotonic log of entries /// representing the ideal state noeq type key = | Key: #region:rid -> raw:aes_key -> log:Monotonic.Seq.log_t region log_entry -> key (** Exercise: (conceptually easy; technically difficult) The type `key` above contains a reference to an ideal log unconditionally. However, this log is redundant when not idealizing. Revise the `key` type as shown below and propagate it through the development. noeq type key = | Key: #region:rid -> raw:aes_key -> log:(if Ideal.ind_cpa then Monotonic.Seq.log_t region log_entry else unit) -> key **) /// An accessor for the log in state h let log (k:key) (h:mem) : GTot (seq log_entry) = sel h (Key?.log k) (*** Invariants on the ideal state ***) (** Informally, there are two main components to the invariant: 1. The IVs in the log are pairwise-distinct. We rely on this to obtain an injectivity property in EtM.AE, using it to relate the CPA and MAC logs to the composite AE log. 2. The ciphers in each entry are required to be valid encryptions of the corresponding plain texts and IVs **) /// --------------------------------------- /// Invariant part 1: distinctness of IVs /// --------------------------------------- let iv_not_in (iv:iv) (log:seq log_entry) = forall (e:log_entry{Seq.mem e log}). iv_of_entry e <> iv /// We state pairwise-distinctness of IVs in this recursive form /// It makes it more convenient to work with as we /// append each new entry (aka snoc) to the end of the log let rec pairwise_distinct_ivs (log:seq log_entry) : Tot Type0 (decreases (Seq.length log)) = if Seq.length log > 0 then let log, tl = Seq.un_snoc log in pairwise_distinct_ivs log /\ iv_not_in (iv_of_entry tl) log else True /// A simple lemma to introduce and eliminate pairwise_distinct_ivs let pairwise_snoc (cpas:Seq.seq log_entry) (tl:log_entry) : Lemma ((pairwise_distinct_ivs cpas /\ iv_not_in (iv_of_entry tl) cpas) <==> (pairwise_distinct_ivs (Seq.snoc cpas tl))) = un_snoc_snoc cpas tl /// It's convenient to lift the pairwise-distinctness of IVs to /// pairwise distinctness of the cipher texts let invert_pairwise (cpas:Seq.seq log_entry) (e:log_entry) (c:cipher) : Lemma (requires (pairwise_distinct_ivs (snoc cpas e) /\ Entry?.c e == c)) (ensures (forall e'. Seq.mem e' cpas ==> Entry?.c e' <> c)) = pairwise_snoc cpas e; FStar.Classical.forall_intro (iv_of_entry_inj e) /// ----------------------------------------- /// Invariant part 2: correctness of ciphers /// ----------------------------------------- /// Each entry contains a valid AES encryption /// /// -- A wrinkle is that when ind_cpa, rather than encrypting the /// plaintext we just encrypt zeros let entry_functional_correctness (raw_key:bytes) (e:log_entry) : Type0 = let iv = iv_of_entry e in let c = raw_cipher e in let plain = Entry?.plain e in let p = if ind_cpa then createBytes (length plain) 0z else repr plain in c == CC.block_encrypt_spec CC.AES_128_CBC raw_key iv p /// Lifting the correctness of individual entries pointwise to correctness of the entire log let cipher_functional_correctness (raw_key:bytes) (log:seq log_entry) = forall (e:log_entry{Seq.mem e log}). {:pattern (Seq.mem e log)} entry_functional_correctness raw_key e /// The invariant is the conjunction of distinctness and correctness /// -- Together with a technical requirement of the log actually /// being present in the memory let invariant (k:key) (h:mem) = let Key raw_key lg = k in let log = log k h in contains h lg /\ //<-- technical: the log must be allocated pairwise_distinct_ivs log /\ cipher_functional_correctness raw_key log (*** The main interface: keygen, encrypt, decrypt ***) /// keygen: allocating a new key /// -- Caller provides a parent region in which to allocate the ideal log
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked", "EtM.Plain.fsti.checked", "EtM.Ideal.fsti.checked", "EtM.CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.CPA.fst" }
[ { "abbrev": false, "full_module": "EtM.Plain", "short_module": null }, { "abbrev": true, "full_module": "Platform.Bytes", "short_module": "B" }, { "abbrev": true, "full_module": "EtM.CoreCrypto", "short_module": "CC" }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": false, "full_module": "EtM.Ideal", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
parent: EtM.CPA.rid -> FStar.HyperStack.ST.ST EtM.CPA.key
FStar.HyperStack.ST.ST
[]
[]
[ "EtM.CPA.rid", "EtM.CPA.Key", "EtM.CPA.key", "FStar.HyperStack.ST.m_rref", "FStar.Seq.Base.seq", "EtM.CPA.log_entry", "FStar.Monotonic.Seq.grows", "FStar.Monotonic.Seq.alloc_mref_seq", "FStar.Seq.Base.empty", "FStar.Monotonic.HyperHeap.rid", "FStar.HyperStack.ST.new_region", "Platform.Bytes.lbytes", "EtM.CPA.keysize", "CoreCrypto.random", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.witnessed", "FStar.HyperStack.ST.region_contains_pred", "Prims.l_and", "FStar.Monotonic.HyperStack.modifies", "FStar.Set.empty", "Prims.b2t", "FStar.Monotonic.HyperHeap.extends", "EtM.CPA.__proj__Key__item__region", "FStar.Monotonic.HyperStack.fresh_region", "Prims.eq2", "EtM.CPA.log", "EtM.CPA.invariant" ]
[]
false
true
false
false
false
let keygen (parent: rid) : ST key (requires (fun _ -> HyperStack.ST.witnessed (region_contains_pred parent))) (ensures (fun m0 k m1 -> modifies Set.empty m0 m1 /\ extends k.region parent /\ fresh_region k.region m0 m1 /\ log k m1 == Seq.empty /\ invariant k m1)) =
let raw = CC.random keysize in let region = new_region parent in let log = alloc_mref_seq region Seq.empty in Key #region raw log
false
EtM.CPA.fst
EtM.CPA.find_entry
val find_entry (log: seq log_entry) (c: cipher) : Pure log_entry (requires (exists p. Seq.mem (Entry p c) log)) (ensures (fun e -> Seq.mem e log /\ Entry?.c e == c))
val find_entry (log: seq log_entry) (c: cipher) : Pure log_entry (requires (exists p. Seq.mem (Entry p c) log)) (ensures (fun e -> Seq.mem e log /\ Entry?.c e == c))
let find_entry (log:seq log_entry) (c:cipher) : Pure log_entry (requires (exists p. Seq.mem (Entry p c) log)) (ensures (fun e -> Seq.mem e log /\ Entry?.c e == c)) = let entry_has_cipher (c:cipher) (e:log_entry) = Entry?.c e = c in let eopt = Seq.seq_find (entry_has_cipher c) log in FStar.Classical.exists_elim (Some? eopt /\ Seq.mem (Some?.v eopt) log /\ entry_has_cipher c (Some?.v eopt)) () (fun (p:plain{Seq.mem (Entry p c) log}) -> Seq.find_mem log (entry_has_cipher c) (Entry p c)); Some?.v eopt
{ "file_name": "examples/crypto/EtM.CPA.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 16, "end_line": 256, "start_col": 0, "start_line": 246 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module EtM.CPA open FStar.HyperStack.ST open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open EtM.Ideal open Platform.Bytes module CC = EtM.CoreCrypto module B = Platform.Bytes open EtM.Plain type rid = erid (*** Basic types ***) /// Initialization vectors: bytes of a given size let ivsize = CC.blockSize CC.AES_128_CBC let iv = lbytes ivsize /// Raw keys for AES 128 let keysize = 16 let aes_key = lbytes keysize /// Cipher-texts are a concatenation of the IV and the AES cipher /// -- we underspecify its length /// -- MK says: minimal cipher length twice blocksize? let cipher = (b:bytes{B.length b >= ivsize}) (*** Ideal state ***) /// CPA log entries are pairs of a plain text and its corresponding cipher type log_entry = | Entry: plain:plain -> c:cipher -> log_entry /// Recover the IV from an entry by splitting out a prefix of the cipher let iv_of_entry (Entry _ c) : iv = fst (B.split c ivsize) /// Recover the AES cipher from an entry by splitting out a suffix of the cipher let raw_cipher (Entry _ c) : bytes = snd (B.split c ivsize) /// A lemma inverting the iv+cipher construction let split_entry (p:plain) (c:cipher) (iv:iv) (r:bytes) : Lemma (iv_of_entry (Entry p (iv@|r)) == iv /\ raw_cipher (Entry p (iv@|r)) == r) = assert (Seq.equal (iv_of_entry (Entry p (iv@|r))) iv); assert (Seq.equal (raw_cipher (Entry p (iv@|r))) r) /// A lemma showing that entries that differ on their IVs differ on their ciphers /// -- because append is injective on both its arguments let iv_of_entry_inj (e1 e2:log_entry) : Lemma (iv_of_entry e1 <> iv_of_entry e2 ==> Entry?.c e1 <> Entry?.c e2) = let iv1, r1 = iv_of_entry e1, raw_cipher e1 in let iv2, r2 = iv_of_entry e2, raw_cipher e2 in FStar.Classical.move_requires (Platform.Bytes.lemma_append_inj iv1 r1 iv2) r2 /// A key includes the raw AES key but also an monotonic log of entries /// representing the ideal state noeq type key = | Key: #region:rid -> raw:aes_key -> log:Monotonic.Seq.log_t region log_entry -> key (** Exercise: (conceptually easy; technically difficult) The type `key` above contains a reference to an ideal log unconditionally. However, this log is redundant when not idealizing. Revise the `key` type as shown below and propagate it through the development. noeq type key = | Key: #region:rid -> raw:aes_key -> log:(if Ideal.ind_cpa then Monotonic.Seq.log_t region log_entry else unit) -> key **) /// An accessor for the log in state h let log (k:key) (h:mem) : GTot (seq log_entry) = sel h (Key?.log k) (*** Invariants on the ideal state ***) (** Informally, there are two main components to the invariant: 1. The IVs in the log are pairwise-distinct. We rely on this to obtain an injectivity property in EtM.AE, using it to relate the CPA and MAC logs to the composite AE log. 2. The ciphers in each entry are required to be valid encryptions of the corresponding plain texts and IVs **) /// --------------------------------------- /// Invariant part 1: distinctness of IVs /// --------------------------------------- let iv_not_in (iv:iv) (log:seq log_entry) = forall (e:log_entry{Seq.mem e log}). iv_of_entry e <> iv /// We state pairwise-distinctness of IVs in this recursive form /// It makes it more convenient to work with as we /// append each new entry (aka snoc) to the end of the log let rec pairwise_distinct_ivs (log:seq log_entry) : Tot Type0 (decreases (Seq.length log)) = if Seq.length log > 0 then let log, tl = Seq.un_snoc log in pairwise_distinct_ivs log /\ iv_not_in (iv_of_entry tl) log else True /// A simple lemma to introduce and eliminate pairwise_distinct_ivs let pairwise_snoc (cpas:Seq.seq log_entry) (tl:log_entry) : Lemma ((pairwise_distinct_ivs cpas /\ iv_not_in (iv_of_entry tl) cpas) <==> (pairwise_distinct_ivs (Seq.snoc cpas tl))) = un_snoc_snoc cpas tl /// It's convenient to lift the pairwise-distinctness of IVs to /// pairwise distinctness of the cipher texts let invert_pairwise (cpas:Seq.seq log_entry) (e:log_entry) (c:cipher) : Lemma (requires (pairwise_distinct_ivs (snoc cpas e) /\ Entry?.c e == c)) (ensures (forall e'. Seq.mem e' cpas ==> Entry?.c e' <> c)) = pairwise_snoc cpas e; FStar.Classical.forall_intro (iv_of_entry_inj e) /// ----------------------------------------- /// Invariant part 2: correctness of ciphers /// ----------------------------------------- /// Each entry contains a valid AES encryption /// /// -- A wrinkle is that when ind_cpa, rather than encrypting the /// plaintext we just encrypt zeros let entry_functional_correctness (raw_key:bytes) (e:log_entry) : Type0 = let iv = iv_of_entry e in let c = raw_cipher e in let plain = Entry?.plain e in let p = if ind_cpa then createBytes (length plain) 0z else repr plain in c == CC.block_encrypt_spec CC.AES_128_CBC raw_key iv p /// Lifting the correctness of individual entries pointwise to correctness of the entire log let cipher_functional_correctness (raw_key:bytes) (log:seq log_entry) = forall (e:log_entry{Seq.mem e log}). {:pattern (Seq.mem e log)} entry_functional_correctness raw_key e /// The invariant is the conjunction of distinctness and correctness /// -- Together with a technical requirement of the log actually /// being present in the memory let invariant (k:key) (h:mem) = let Key raw_key lg = k in let log = log k h in contains h lg /\ //<-- technical: the log must be allocated pairwise_distinct_ivs log /\ cipher_functional_correctness raw_key log (*** The main interface: keygen, encrypt, decrypt ***) /// keygen: allocating a new key /// -- Caller provides a parent region in which to allocate the ideal log /// -- Returns a fresh key satisfying its invariant whose log is initially empty let keygen (parent:rid) : ST key (requires (fun _ -> HyperStack.ST.witnessed (region_contains_pred parent))) (ensures (fun m0 k m1 -> modifies Set.empty m0 m1 /\ extends k.region parent /\ fresh_region k.region m0 m1 /\ log k m1 == Seq.empty /\ invariant k m1)) = let raw = CC.random keysize in let region = new_region parent in let log = alloc_mref_seq region Seq.empty in Key #region raw log /// A primitive to sample a fresh iv distinct from others /// Exercise: Implement this, e.g, by simply incrementing a counter /// Or by sampling and retrying assume val fresh_iv (k:key) : ST iv (requires (fun h -> True)) (ensures (fun h0 iv h1 -> h0 == h1 /\ iv_not_in iv (log k h0))) /// encrypt: /// -- requires a key initially in the invariant /// -- ensures that only the key's region is modified /// and that the the key's log grows by just one entry let encrypt (k:key) (m:plain) : ST cipher (requires (invariant k)) (ensures (fun h0 c h1 -> (let log0 = log k h0 in let log1 = log k h1 in invariant k h1 /\ modifies_one k.region h0 h1 /\ contains h1 k.log /\ log1 == snoc log0 (Entry m c)))) = let iv = fresh_iv k in let text = if ind_cpa then createBytes (length m) 0z else repr m in let raw_c = CC.block_enc CC.AES_128_CBC k.raw iv text in let c = iv@|raw_c in let e = Entry m c in split_entry m c iv raw_c; assert (entry_functional_correctness k.raw e); let h0 = FStar.HyperStack.ST.get () in write_at_end k.log e; let h1 = FStar.HyperStack.ST.get () in lemma_mem_snoc (log k h0) e; pairwise_snoc (log k h0) e; c /// find_entry: An auxiliary function with a somewhat technical proof /// -- We search for an entry in a log that contains a cipher using /// a left-to-right scan of the sequence provide by Seq.seq_find /// -- Knowing that a the cipher exists in the log (via Seq.mem)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked", "EtM.Plain.fsti.checked", "EtM.Ideal.fsti.checked", "EtM.CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.CPA.fst" }
[ { "abbrev": false, "full_module": "EtM.Plain", "short_module": null }, { "abbrev": true, "full_module": "Platform.Bytes", "short_module": "B" }, { "abbrev": true, "full_module": "EtM.CoreCrypto", "short_module": "CC" }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": false, "full_module": "EtM.Ideal", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
log: FStar.Seq.Base.seq EtM.CPA.log_entry -> c: EtM.CPA.cipher -> Prims.Pure EtM.CPA.log_entry
Prims.Pure
[]
[]
[ "FStar.Seq.Base.seq", "EtM.CPA.log_entry", "EtM.CPA.cipher", "FStar.Pervasives.Native.__proj__Some__item__v", "Prims.unit", "FStar.Classical.exists_elim", "Prims.l_and", "Prims.b2t", "FStar.Pervasives.Native.uu___is_Some", "FStar.Seq.Properties.mem", "EtM.Plain.plain", "EtM.CPA.Entry", "FStar.Seq.Properties.find_mem", "Prims.squash", "FStar.Pervasives.Native.option", "FStar.Seq.Properties.seq_find", "Prims.bool", "Prims.op_Equality", "EtM.CPA.__proj__Entry__item__c", "Prims.l_Exists", "Prims.eq2" ]
[]
false
false
false
false
false
let find_entry (log: seq log_entry) (c: cipher) : Pure log_entry (requires (exists p. Seq.mem (Entry p c) log)) (ensures (fun e -> Seq.mem e log /\ Entry?.c e == c)) =
let entry_has_cipher (c: cipher) (e: log_entry) = Entry?.c e = c in let eopt = Seq.seq_find (entry_has_cipher c) log in FStar.Classical.exists_elim (Some? eopt /\ Seq.mem (Some?.v eopt) log /\ entry_has_cipher c (Some?.v eopt)) () (fun (p: plain{Seq.mem (Entry p c) log}) -> Seq.find_mem log (entry_has_cipher c) (Entry p c)); Some?.v eopt
false
HaclExample2.fst
HaclExample2.do_something_with_limbs
val do_something_with_limbs (#v: Ghost.erased (Seq.seq (scalar_t U64.t))) (a: array (scalar U64.t)) : ST (Ghost.erased (Seq.seq (scalar_t U64.t))) (array_pts_to a v) (fun v' -> array_pts_to a v') (requires array_length a == 5 /\ full_seq (scalar U64.t) v) (ensures (fun v' -> full_seq (scalar U64.t) v'))
val do_something_with_limbs (#v: Ghost.erased (Seq.seq (scalar_t U64.t))) (a: array (scalar U64.t)) : ST (Ghost.erased (Seq.seq (scalar_t U64.t))) (array_pts_to a v) (fun v' -> array_pts_to a v') (requires array_length a == 5 /\ full_seq (scalar U64.t) v) (ensures (fun v' -> full_seq (scalar U64.t) v'))
let do_something_with_limbs (#v: Ghost.erased (Seq.seq (scalar_t U64.t))) (a: array (scalar U64.t)) : ST (Ghost.erased (Seq.seq (scalar_t U64.t))) (array_pts_to a v) (fun v' -> array_pts_to a v') (requires array_length a == 5 /\ full_seq (scalar U64.t) v ) (ensures (fun v' -> full_seq (scalar U64.t) v' )) = let p = array_cell a 2sz in write p 0uL; unarray_cell _ _ _; drop (has_array_cell _ _ _); return _
{ "file_name": "share/steel/examples/steelc/HaclExample2.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 10, "end_line": 59, "start_col": 0, "start_line": 42 }
module HaclExample2 open Steel.ST.GenElim open Steel.ST.C.Types open Steel.C.Typenat open Steel.C.Typestring module SZ = FStar.SizeT module U64 = FStar.UInt64 (** In this file we demonstrate how Steel could be used to manipulate the following data type used in Hacl*: https://github.com/project-everest/hacl-star/blob/master/code/poly1305/Hacl.Impl.Poly1305.fsti#L18 This Low* definition amounts to the struct definition struct poly1305_ctx { uint64_t limbs[5]; uint64_t precomp[20]; }; and, with our new model of structs and arrays and pointer-to-field, can be expresesd directly in Steel. See PointStruct.fst for more detailed explanations of the various definitions needed below. *) noextract inline_for_extraction let five = normalize (nat_t_of_nat 5) noextract inline_for_extraction let twenty = normalize (nat_t_of_nat 20) noextract inline_for_extraction let comp_name = normalize (mk_string_t "HaclExample2.comp") noextract inline_for_extraction [@@norm_field_attr] let comp_fields = field_description_cons "limbs" (base_array0 five (scalar U64.t) 5sz) ( field_description_cons "precomp" (base_array0 twenty (scalar U64.t) 20sz) ( field_description_nil )) noextract inline_for_extraction let comp = struct0 comp_name "HaclExample2.comp" comp_fields let _ = define_struct0 comp_name "HaclExample2.comp" comp_fields (** To demonstrate how our model could be used, we write a simple function that takes pointers to the limbs and precomp fields and passes them to helper functions (which in this case simply set on element of the corresponding array to zero) *)
{ "checked_file": "/", "dependencies": [ "Steel.ST.GenElim.fsti.checked", "Steel.ST.C.Types.fst.checked", "Steel.C.Typestring.fsti.checked", "Steel.C.Typenat.fsti.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "HaclExample2.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "Steel.C.Typestring", "short_module": null }, { "abbrev": false, "full_module": "Steel.C.Typenat", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenElim", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Steel.ST.C.Types.Array.array (Steel.ST.C.Types.Scalar.scalar FStar.UInt64.t) -> Steel.ST.Effect.ST (FStar.Ghost.erased (FStar.Seq.Base.seq (Steel.ST.C.Types.Scalar.scalar_t FStar.UInt64.t)))
Steel.ST.Effect.ST
[]
[]
[ "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Steel.ST.C.Types.Scalar.scalar_t", "FStar.UInt64.t", "Steel.ST.C.Types.Array.array", "Steel.ST.C.Types.Scalar.scalar", "Steel.ST.Util.return", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.ST.C.Types.Array.array_pts_to", "Steel.Effect.Common.vprop", "FStar.Seq.Base.upd", "FStar.Ghost.reveal", "Steel.ST.C.Types.Base.unknown", "Steel.ST.C.Types.Base.mk_fraction", "Steel.ST.C.Types.Scalar.mk_scalar", "FStar.UInt64.__uint_to_t", "Steel.FractionalPermission.full_perm", "Prims.unit", "Steel.ST.Util.drop", "Steel.ST.C.Types.Array.has_array_cell", "FStar.SizeT.__uint_to_t", "Steel.ST.C.Types.Array.unarray_cell", "Prims.squash", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.SizeT.v", "FStar.Seq.Base.length", "Prims.eq2", "Prims.nat", "FStar.SizeT.t", "FStar.Pervasives.dsnd", "Steel.ST.C.Types.Array.array_ptr", "Steel.ST.C.Types.Array.array_len_t", "Steel.ST.C.Types.Scalar.write", "FStar.Seq.Base.index", "Steel.ST.C.Types.Base.ref", "FStar.SizeT.uint_to_t", "Steel.ST.C.Types.Array.array_cell", "Prims.int", "Steel.ST.C.Types.Array.array_length", "Steel.ST.C.Types.Array.full_seq", "Prims.l_True" ]
[]
false
true
false
false
false
let do_something_with_limbs (#v: Ghost.erased (Seq.seq (scalar_t U64.t))) (a: array (scalar U64.t)) : ST (Ghost.erased (Seq.seq (scalar_t U64.t))) (array_pts_to a v) (fun v' -> array_pts_to a v') (requires array_length a == 5 /\ full_seq (scalar U64.t) v) (ensures (fun v' -> full_seq (scalar U64.t) v')) =
let p = array_cell a 2sz in write p 0uL; unarray_cell _ _ _; drop (has_array_cell _ _ _); return _
false
EtM.CPA.fst
EtM.CPA.decrypt
val decrypt (k: key) (c: cipher) : ST plain (requires (fun h0 -> let log = log k h0 in invariant k h0 /\ (b2t ind_cpa_rest_adv ==> (exists p. Seq.mem (Entry p c) log)))) (ensures (fun h0 res h1 -> let log = log k h1 in modifies_none h0 h1 /\ invariant k h1 /\ (b2t ind_cpa_rest_adv ==> Seq.mem (Entry res c) log)))
val decrypt (k: key) (c: cipher) : ST plain (requires (fun h0 -> let log = log k h0 in invariant k h0 /\ (b2t ind_cpa_rest_adv ==> (exists p. Seq.mem (Entry p c) log)))) (ensures (fun h0 res h1 -> let log = log k h1 in modifies_none h0 h1 /\ invariant k h1 /\ (b2t ind_cpa_rest_adv ==> Seq.mem (Entry res c) log)))
let decrypt (k:key) (c:cipher) : ST plain (requires (fun h0 -> let log = log k h0 in invariant k h0 /\ (b2t ind_cpa_rest_adv ==> (exists p. Seq.mem (Entry p c) log)))) (ensures (fun h0 res h1 -> let log = log k h1 in modifies_none h0 h1 /\ invariant k h1 /\ (b2t ind_cpa_rest_adv ==> Seq.mem (Entry res c) log))) = let Key raw_key log = k in let iv,c' = split c ivsize in let raw_plain = CC.block_dec CC.AES_128_CBC raw_key iv c' in if ind_cpa_rest_adv then let log = !log in let Entry plain _ = find_entry log c in split_entry plain c iv c'; if not ind_cpa then begin //no correction necessary: raw_plain is the correct plain text already CC.enc_dec_inverses CC.AES_128_CBC raw_key iv (repr plain); assert (repr plain == raw_plain); plain end else begin let zeroes = createBytes (length plain) 0z in CC.enc_dec_inverses CC.AES_128_CBC raw_key iv zeroes; assert (raw_plain == zeroes); plain end else coerce raw_plain
{ "file_name": "examples/crypto/EtM.CPA.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 23, "end_line": 295, "start_col": 0, "start_line": 265 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module EtM.CPA open FStar.HyperStack.ST open FStar.Seq open FStar.Monotonic.Seq open FStar.HyperStack open EtM.Ideal open Platform.Bytes module CC = EtM.CoreCrypto module B = Platform.Bytes open EtM.Plain type rid = erid (*** Basic types ***) /// Initialization vectors: bytes of a given size let ivsize = CC.blockSize CC.AES_128_CBC let iv = lbytes ivsize /// Raw keys for AES 128 let keysize = 16 let aes_key = lbytes keysize /// Cipher-texts are a concatenation of the IV and the AES cipher /// -- we underspecify its length /// -- MK says: minimal cipher length twice blocksize? let cipher = (b:bytes{B.length b >= ivsize}) (*** Ideal state ***) /// CPA log entries are pairs of a plain text and its corresponding cipher type log_entry = | Entry: plain:plain -> c:cipher -> log_entry /// Recover the IV from an entry by splitting out a prefix of the cipher let iv_of_entry (Entry _ c) : iv = fst (B.split c ivsize) /// Recover the AES cipher from an entry by splitting out a suffix of the cipher let raw_cipher (Entry _ c) : bytes = snd (B.split c ivsize) /// A lemma inverting the iv+cipher construction let split_entry (p:plain) (c:cipher) (iv:iv) (r:bytes) : Lemma (iv_of_entry (Entry p (iv@|r)) == iv /\ raw_cipher (Entry p (iv@|r)) == r) = assert (Seq.equal (iv_of_entry (Entry p (iv@|r))) iv); assert (Seq.equal (raw_cipher (Entry p (iv@|r))) r) /// A lemma showing that entries that differ on their IVs differ on their ciphers /// -- because append is injective on both its arguments let iv_of_entry_inj (e1 e2:log_entry) : Lemma (iv_of_entry e1 <> iv_of_entry e2 ==> Entry?.c e1 <> Entry?.c e2) = let iv1, r1 = iv_of_entry e1, raw_cipher e1 in let iv2, r2 = iv_of_entry e2, raw_cipher e2 in FStar.Classical.move_requires (Platform.Bytes.lemma_append_inj iv1 r1 iv2) r2 /// A key includes the raw AES key but also an monotonic log of entries /// representing the ideal state noeq type key = | Key: #region:rid -> raw:aes_key -> log:Monotonic.Seq.log_t region log_entry -> key (** Exercise: (conceptually easy; technically difficult) The type `key` above contains a reference to an ideal log unconditionally. However, this log is redundant when not idealizing. Revise the `key` type as shown below and propagate it through the development. noeq type key = | Key: #region:rid -> raw:aes_key -> log:(if Ideal.ind_cpa then Monotonic.Seq.log_t region log_entry else unit) -> key **) /// An accessor for the log in state h let log (k:key) (h:mem) : GTot (seq log_entry) = sel h (Key?.log k) (*** Invariants on the ideal state ***) (** Informally, there are two main components to the invariant: 1. The IVs in the log are pairwise-distinct. We rely on this to obtain an injectivity property in EtM.AE, using it to relate the CPA and MAC logs to the composite AE log. 2. The ciphers in each entry are required to be valid encryptions of the corresponding plain texts and IVs **) /// --------------------------------------- /// Invariant part 1: distinctness of IVs /// --------------------------------------- let iv_not_in (iv:iv) (log:seq log_entry) = forall (e:log_entry{Seq.mem e log}). iv_of_entry e <> iv /// We state pairwise-distinctness of IVs in this recursive form /// It makes it more convenient to work with as we /// append each new entry (aka snoc) to the end of the log let rec pairwise_distinct_ivs (log:seq log_entry) : Tot Type0 (decreases (Seq.length log)) = if Seq.length log > 0 then let log, tl = Seq.un_snoc log in pairwise_distinct_ivs log /\ iv_not_in (iv_of_entry tl) log else True /// A simple lemma to introduce and eliminate pairwise_distinct_ivs let pairwise_snoc (cpas:Seq.seq log_entry) (tl:log_entry) : Lemma ((pairwise_distinct_ivs cpas /\ iv_not_in (iv_of_entry tl) cpas) <==> (pairwise_distinct_ivs (Seq.snoc cpas tl))) = un_snoc_snoc cpas tl /// It's convenient to lift the pairwise-distinctness of IVs to /// pairwise distinctness of the cipher texts let invert_pairwise (cpas:Seq.seq log_entry) (e:log_entry) (c:cipher) : Lemma (requires (pairwise_distinct_ivs (snoc cpas e) /\ Entry?.c e == c)) (ensures (forall e'. Seq.mem e' cpas ==> Entry?.c e' <> c)) = pairwise_snoc cpas e; FStar.Classical.forall_intro (iv_of_entry_inj e) /// ----------------------------------------- /// Invariant part 2: correctness of ciphers /// ----------------------------------------- /// Each entry contains a valid AES encryption /// /// -- A wrinkle is that when ind_cpa, rather than encrypting the /// plaintext we just encrypt zeros let entry_functional_correctness (raw_key:bytes) (e:log_entry) : Type0 = let iv = iv_of_entry e in let c = raw_cipher e in let plain = Entry?.plain e in let p = if ind_cpa then createBytes (length plain) 0z else repr plain in c == CC.block_encrypt_spec CC.AES_128_CBC raw_key iv p /// Lifting the correctness of individual entries pointwise to correctness of the entire log let cipher_functional_correctness (raw_key:bytes) (log:seq log_entry) = forall (e:log_entry{Seq.mem e log}). {:pattern (Seq.mem e log)} entry_functional_correctness raw_key e /// The invariant is the conjunction of distinctness and correctness /// -- Together with a technical requirement of the log actually /// being present in the memory let invariant (k:key) (h:mem) = let Key raw_key lg = k in let log = log k h in contains h lg /\ //<-- technical: the log must be allocated pairwise_distinct_ivs log /\ cipher_functional_correctness raw_key log (*** The main interface: keygen, encrypt, decrypt ***) /// keygen: allocating a new key /// -- Caller provides a parent region in which to allocate the ideal log /// -- Returns a fresh key satisfying its invariant whose log is initially empty let keygen (parent:rid) : ST key (requires (fun _ -> HyperStack.ST.witnessed (region_contains_pred parent))) (ensures (fun m0 k m1 -> modifies Set.empty m0 m1 /\ extends k.region parent /\ fresh_region k.region m0 m1 /\ log k m1 == Seq.empty /\ invariant k m1)) = let raw = CC.random keysize in let region = new_region parent in let log = alloc_mref_seq region Seq.empty in Key #region raw log /// A primitive to sample a fresh iv distinct from others /// Exercise: Implement this, e.g, by simply incrementing a counter /// Or by sampling and retrying assume val fresh_iv (k:key) : ST iv (requires (fun h -> True)) (ensures (fun h0 iv h1 -> h0 == h1 /\ iv_not_in iv (log k h0))) /// encrypt: /// -- requires a key initially in the invariant /// -- ensures that only the key's region is modified /// and that the the key's log grows by just one entry let encrypt (k:key) (m:plain) : ST cipher (requires (invariant k)) (ensures (fun h0 c h1 -> (let log0 = log k h0 in let log1 = log k h1 in invariant k h1 /\ modifies_one k.region h0 h1 /\ contains h1 k.log /\ log1 == snoc log0 (Entry m c)))) = let iv = fresh_iv k in let text = if ind_cpa then createBytes (length m) 0z else repr m in let raw_c = CC.block_enc CC.AES_128_CBC k.raw iv text in let c = iv@|raw_c in let e = Entry m c in split_entry m c iv raw_c; assert (entry_functional_correctness k.raw e); let h0 = FStar.HyperStack.ST.get () in write_at_end k.log e; let h1 = FStar.HyperStack.ST.get () in lemma_mem_snoc (log k h0) e; pairwise_snoc (log k h0) e; c /// find_entry: An auxiliary function with a somewhat technical proof /// -- We search for an entry in a log that contains a cipher using /// a left-to-right scan of the sequence provide by Seq.seq_find /// -- Knowing that a the cipher exists in the log (via Seq.mem) /// guarantees that this scan will succeed. let find_entry (log:seq log_entry) (c:cipher) : Pure log_entry (requires (exists p. Seq.mem (Entry p c) log)) (ensures (fun e -> Seq.mem e log /\ Entry?.c e == c)) = let entry_has_cipher (c:cipher) (e:log_entry) = Entry?.c e = c in let eopt = Seq.seq_find (entry_has_cipher c) log in FStar.Classical.exists_elim (Some? eopt /\ Seq.mem (Some?.v eopt) log /\ entry_has_cipher c (Some?.v eopt)) () (fun (p:plain{Seq.mem (Entry p c) log}) -> Seq.find_mem log (entry_has_cipher c) (Entry p c)); Some?.v eopt /// decrypt: /// -- An important pre-condition of decrypt is that when idealizing /// (ind_cpa_rest_adv), we need to know that the cipher being decrypted /// is actually the valid encryption of some plain text already in the log. /// /// -- This allow us to prove that the plain text returned is a
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Platform.Bytes.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Seq.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Classical.fsti.checked", "EtM.Plain.fsti.checked", "EtM.Ideal.fsti.checked", "EtM.CoreCrypto.fst.checked" ], "interface_file": false, "source_file": "EtM.CPA.fst" }
[ { "abbrev": false, "full_module": "EtM.Plain", "short_module": null }, { "abbrev": true, "full_module": "Platform.Bytes", "short_module": "B" }, { "abbrev": true, "full_module": "EtM.CoreCrypto", "short_module": "CC" }, { "abbrev": false, "full_module": "Platform.Bytes", "short_module": null }, { "abbrev": false, "full_module": "EtM.Ideal", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "EtM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k: EtM.CPA.key -> c: EtM.CPA.cipher -> FStar.HyperStack.ST.ST EtM.Plain.plain
FStar.HyperStack.ST.ST
[]
[]
[ "EtM.CPA.key", "EtM.CPA.cipher", "EtM.CPA.rid", "EtM.CPA.aes_key", "FStar.Monotonic.Seq.log_t", "EtM.CPA.log_entry", "Platform.Bytes.bytes", "EtM.Ideal.ind_cpa_rest_adv", "EtM.Plain.plain", "Prims.op_Negation", "EtM.Ideal.ind_cpa", "Prims.unit", "Prims._assert", "Prims.eq2", "Prims.l_or", "EtM.Plain.reveal", "EtM.CoreCrypto.block_decrypt_spec", "CoreCrypto.AES_128_CBC", "EtM.Plain.repr", "EtM.CoreCrypto.enc_dec_inverses", "Prims.bool", "Prims.b2t", "Prims.op_Equality", "Prims.nat", "Platform.Bytes.length", "EtM.Plain.length", "Platform.Bytes.lbytes", "Platform.Bytes.createBytes", "FStar.UInt8.__uint_to_t", "EtM.CPA.split_entry", "EtM.CPA.find_entry", "FStar.Seq.Base.seq", "FStar.HyperStack.ST.op_Bang", "FStar.Monotonic.Seq.grows", "EtM.Plain.coerce", "EtM.CoreCrypto.block_dec", "FStar.Pervasives.Native.tuple2", "Prims.l_and", "FStar.Seq.Base.length", "FStar.UInt8.t", "FStar.Pervasives.Native.fst", "EtM.CPA.ivsize", "Prims.int", "FStar.Pervasives.Native.snd", "Prims.op_Subtraction", "Platform.Bytes.split", "FStar.Monotonic.HyperStack.mem", "EtM.CPA.invariant", "Prims.l_imp", "Prims.l_Exists", "FStar.Seq.Properties.mem", "EtM.CPA.Entry", "EtM.CPA.log", "FStar.HyperStack.ST.modifies_none" ]
[]
false
true
false
false
false
let decrypt (k: key) (c: cipher) : ST plain (requires (fun h0 -> let log = log k h0 in invariant k h0 /\ (b2t ind_cpa_rest_adv ==> (exists p. Seq.mem (Entry p c) log)))) (ensures (fun h0 res h1 -> let log = log k h1 in modifies_none h0 h1 /\ invariant k h1 /\ (b2t ind_cpa_rest_adv ==> Seq.mem (Entry res c) log))) =
let Key raw_key log = k in let iv, c' = split c ivsize in let raw_plain = CC.block_dec CC.AES_128_CBC raw_key iv c' in if ind_cpa_rest_adv then let log = !log in let Entry plain _ = find_entry log c in split_entry plain c iv c'; if not ind_cpa then (CC.enc_dec_inverses CC.AES_128_CBC raw_key iv (repr plain); assert (repr plain == raw_plain); plain) else let zeroes = createBytes (length plain) 0uy in CC.enc_dec_inverses CC.AES_128_CBC raw_key iv zeroes; assert (raw_plain == zeroes); plain else coerce raw_plain
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.unsquash_equality
val unsquash_equality (t: term) : Tac (option (term & term))
val unsquash_equality (t: term) : Tac (option (term & term))
let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 30, "start_col": 0, "start_line": 26 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`())
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac (FStar.Pervasives.Native.option (FStar.Stubs.Reflection.Types.term * FStar.Stubs.Reflection.Types.term))
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Pervasives.Native.option", "FStar.Stubs.Reflection.Types.typ", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2", "FStar.Reflection.V1.Formula.formula", "FStar.Pervasives.Native.None", "FStar.Reflection.V1.Formula.term_as_formula" ]
[]
false
true
false
false
false
let unsquash_equality (t: term) : Tac (option (term & term)) =
match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.is_focus_on_term
val is_focus_on_term : term -> Tac bool
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 52, "end_line": 64, "start_col": 0, "start_line": 64 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging. val pp_explore_print_goal : unit -> Tac unit let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f () /// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which /// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.bool
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Reflection.V1.Derived.is_fvar", "Prims.bool" ]
[]
false
true
false
false
false
let is_focus_on_term t =
is_fvar t (`%focus_on_term)
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.end_proof
val end_proof : _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
let end_proof () = tadmit_t (`())
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 16, "end_line": 24, "start_col": 0, "start_line": 23 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Stubs.Tactics.V1.Builtins.tadmit_t" ]
[]
false
true
false
false
false
let end_proof () =
tadmit_t (`())
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.term_is_assert_or_assume
val term_is_assert_or_assume : term -> Tac (option term)
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t = match inspect t with | Tv_App hd (a, Q_Explicit) -> if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume] then Some a else None | _ -> None
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 13, "end_line": 75, "start_col": 0, "start_line": 69 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging. val pp_explore_print_goal : unit -> Tac unit let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f () /// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which /// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*) val is_focus_on_term : term -> Tac bool let is_focus_on_term t = is_fvar t (`%focus_on_term) /// Check if a term is an assertion or an assumption and return its content /// if it is the case.
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac (FStar.Pervasives.Native.option FStar.Stubs.Reflection.Types.term)
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Reflection.V1.Derived.is_any_fvar", "Prims.Cons", "Prims.string", "Prims.Nil", "FStar.Pervasives.Native.Some", "Prims.bool", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option", "FStar.Stubs.Reflection.V1.Data.term_view", "FStar.Stubs.Tactics.V1.Builtins.inspect" ]
[]
false
true
false
false
false
let term_is_assert_or_assume t =
match inspect t with | Tv_App hd (a, Q_Explicit) -> if is_any_fvar a [`%assert; `%FStar.Pervasives.assert_norm; `%assume] then Some a else None | _ -> None
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.pp_explore_print_goal
val pp_explore_print_goal : unit -> Tac unit
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f ()
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 28, "end_line": 59, "start_col": 0, "start_line": 55 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging.
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.InteractiveHelpers.PostProcess.pp_explore", "FStar.InteractiveHelpers.ExploreTerm.explorer", "FStar.InteractiveHelpers.Base.genv", "Prims.list", "FStar.Pervasives.Native.tuple2", "FStar.Stubs.Reflection.V1.Data.term_view", "FStar.Pervasives.Native.option", "FStar.InteractiveHelpers.ExploreTerm.typ_or_comp", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Tactics.Types.ctrl_flag", "FStar.Stubs.Tactics.Types.Continue" ]
[]
false
true
false
false
false
let pp_explore_print_goal () =
let f:explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f ()
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.pp_explore
val pp_explore (dbg dfs: bool) (#a: Type0) (f: explorer a) (x: a) : Tac unit
val pp_explore (dbg dfs: bool) (#a: Type0) (f: explorer a) (x: a) : Tac unit
let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 49, "start_col": 0, "start_line": 33 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "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": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
dbg: Prims.bool -> dfs: Prims.bool -> f: FStar.InteractiveHelpers.ExploreTerm.explorer a -> x: a -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.bool", "FStar.InteractiveHelpers.ExploreTerm.explorer", "FStar.Stubs.Reflection.Types.term", "FStar.InteractiveHelpers.PostProcess.end_proof", "Prims.unit", "FStar.Pervasives.Native.tuple2", "FStar.Stubs.Tactics.Types.ctrl_flag", "FStar.InteractiveHelpers.ExploreTerm.explore_term", "Prims.Nil", "FStar.InteractiveHelpers.Base.genv", "FStar.Stubs.Reflection.V1.Data.term_view", "FStar.InteractiveHelpers.Base.print_dbg", "Prims.string", "Prims.op_Hat", "FStar.Stubs.Tactics.V1.Builtins.term_to_string", "FStar.InteractiveHelpers.Base.mk_genv", "FStar.Stubs.Reflection.Types.bv", "FStar.Pervasives.Native.tuple3", "FStar.Stubs.Reflection.Types.typ", "FStar.Pervasives.Native.option", "FStar.InteractiveHelpers.ExploreTerm.typ_or_comp", "Prims.l_imp", "Prims.b2t", "FStar.Pervasives.Native.uu___is_Some", "FStar.InteractiveHelpers.ExploreTerm.uu___is_TC_Comp", "FStar.Pervasives.Native.__proj__Some__item__v", "FStar.InteractiveHelpers.ExploreTerm.safe_typ_or_comp", "FStar.InteractiveHelpers.Base.mfail", "FStar.InteractiveHelpers.PostProcess.unsquash_equality", "FStar.Stubs.Reflection.Types.env", "FStar.Tactics.V1.Derived.cur_env", "FStar.Tactics.V1.Derived.cur_goal" ]
[]
false
true
false
false
false
let pp_explore (dbg dfs: bool) (#a: Type0) (f: explorer a) (x: a) : Tac unit =
let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality"
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.mk_exploration_result
val mk_exploration_result : ge: FStar.InteractiveHelpers.Base.genv -> parents: Prims.list (FStar.InteractiveHelpers.Base.genv * FStar.Stubs.Reflection.V1.Data.term_view) -> tgt_comp: FStar.Pervasives.Native.option FStar.InteractiveHelpers.ExploreTerm.typ_or_comp -> res: _ -> FStar.InteractiveHelpers.PostProcess.exploration_result _
let mk_exploration_result = Mkexploration_result
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 48, "end_line": 93, "start_col": 0, "start_line": 93 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging. val pp_explore_print_goal : unit -> Tac unit let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f () /// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which /// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*) val is_focus_on_term : term -> Tac bool let is_focus_on_term t = is_fvar t (`%focus_on_term) /// Check if a term is an assertion or an assumption and return its content /// if it is the case. val term_is_assert_or_assume : term -> Tac (option term) let term_is_assert_or_assume t = match inspect t with | Tv_App hd (a, Q_Explicit) -> if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume] then Some a else None | _ -> None /// Check if the given term view is of the form: 'let _ = focus_on_term in body' /// Returns 'body' if it is the case. val is_focused_term : term_view -> Tac (option term) let is_focused_term tv = match tv with | Tv_Let recf attrs _ _ def body -> if is_focus_on_term def then Some body else None | _ -> None noeq type exploration_result (a : Type)= { ge : genv; parents : list (genv & term_view); tgt_comp : option typ_or_comp; res : a; }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ge: FStar.InteractiveHelpers.Base.genv -> parents: Prims.list (FStar.InteractiveHelpers.Base.genv * FStar.Stubs.Reflection.V1.Data.term_view) -> tgt_comp: FStar.Pervasives.Native.option FStar.InteractiveHelpers.ExploreTerm.typ_or_comp -> res: _ -> FStar.InteractiveHelpers.PostProcess.exploration_result _
Prims.Tot
[ "total" ]
[]
[ "FStar.InteractiveHelpers.PostProcess.Mkexploration_result", "FStar.InteractiveHelpers.Base.genv", "Prims.list", "FStar.Pervasives.Native.tuple2", "FStar.Stubs.Reflection.V1.Data.term_view", "FStar.Pervasives.Native.option", "FStar.InteractiveHelpers.ExploreTerm.typ_or_comp", "FStar.InteractiveHelpers.PostProcess.exploration_result" ]
[]
false
false
false
true
false
let mk_exploration_result =
Mkexploration_result
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.is_focused_term
val is_focused_term : term_view -> Tac (option term)
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv = match tv with | Tv_Let recf attrs _ _ def body -> if is_focus_on_term def then Some body else None | _ -> None
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 13, "end_line": 84, "start_col": 0, "start_line": 80 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging. val pp_explore_print_goal : unit -> Tac unit let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f () /// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which /// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*) val is_focus_on_term : term -> Tac bool let is_focus_on_term t = is_fvar t (`%focus_on_term) /// Check if a term is an assertion or an assumption and return its content /// if it is the case. val term_is_assert_or_assume : term -> Tac (option term) let term_is_assert_or_assume t = match inspect t with | Tv_App hd (a, Q_Explicit) -> if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume] then Some a else None | _ -> None /// Check if the given term view is of the form: 'let _ = focus_on_term in body' /// Returns 'body' if it is the case.
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
tv: FStar.Stubs.Reflection.V1.Data.term_view -> FStar.Tactics.Effect.Tac (FStar.Pervasives.Native.option FStar.Stubs.Reflection.Types.term)
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.V1.Data.term_view", "Prims.bool", "Prims.list", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.Types.bv", "FStar.Stubs.Reflection.Types.typ", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option", "FStar.InteractiveHelpers.PostProcess.is_focus_on_term" ]
[]
false
true
false
false
false
let is_focused_term tv =
match tv with | Tv_Let recf attrs _ _ def body -> if is_focus_on_term def then Some body else None | _ -> None
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.pred_explorer
val pred_explorer : a: Type -> Type0
let pred_explorer (a:Type) = genv -> list (genv & term_view) -> option typ_or_comp -> term_view -> Tac (option a)
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 16, "end_line": 97, "start_col": 0, "start_line": 95 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging. val pp_explore_print_goal : unit -> Tac unit let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f () /// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which /// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*) val is_focus_on_term : term -> Tac bool let is_focus_on_term t = is_fvar t (`%focus_on_term) /// Check if a term is an assertion or an assumption and return its content /// if it is the case. val term_is_assert_or_assume : term -> Tac (option term) let term_is_assert_or_assume t = match inspect t with | Tv_App hd (a, Q_Explicit) -> if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume] then Some a else None | _ -> None /// Check if the given term view is of the form: 'let _ = focus_on_term in body' /// Returns 'body' if it is the case. val is_focused_term : term_view -> Tac (option term) let is_focused_term tv = match tv with | Tv_Let recf attrs _ _ def body -> if is_focus_on_term def then Some body else None | _ -> None noeq type exploration_result (a : Type)= { ge : genv; parents : list (genv & term_view); tgt_comp : option typ_or_comp; res : a; } let mk_exploration_result = Mkexploration_result
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.InteractiveHelpers.Base.genv", "Prims.list", "FStar.Pervasives.Native.tuple2", "FStar.Stubs.Reflection.V1.Data.term_view", "FStar.Pervasives.Native.option", "FStar.InteractiveHelpers.ExploreTerm.typ_or_comp" ]
[]
false
false
false
true
true
let pred_explorer (a: Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view -> Tac (option a)
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.find_predicated_term
val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result a))
val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result a))
let find_predicated_term #a pred dbg dfs ge pl opt_c t = fst (explore_term dbg dfs #(option (exploration_result a)) (find_predicated_term_explorer #a pred dbg) None ge pl opt_c t)
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 39, "end_line": 118, "start_col": 0, "start_line": 115 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging. val pp_explore_print_goal : unit -> Tac unit let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f () /// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which /// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*) val is_focus_on_term : term -> Tac bool let is_focus_on_term t = is_fvar t (`%focus_on_term) /// Check if a term is an assertion or an assumption and return its content /// if it is the case. val term_is_assert_or_assume : term -> Tac (option term) let term_is_assert_or_assume t = match inspect t with | Tv_App hd (a, Q_Explicit) -> if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume] then Some a else None | _ -> None /// Check if the given term view is of the form: 'let _ = focus_on_term in body' /// Returns 'body' if it is the case. val is_focused_term : term_view -> Tac (option term) let is_focused_term tv = match tv with | Tv_Let recf attrs _ _ def body -> if is_focus_on_term def then Some body else None | _ -> None noeq type exploration_result (a : Type)= { ge : genv; parents : list (genv & term_view); tgt_comp : option typ_or_comp; res : a; } let mk_exploration_result = Mkexploration_result let pred_explorer (a:Type) = genv -> list (genv & term_view) -> option typ_or_comp -> term_view -> Tac (option a) val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool -> explorer (option (exploration_result a)) let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t = if Some? acc then mfail "find_focused_term_explorer: non empty accumulator"; if dbg then begin print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t) end; match pred ge pl opt_c t with | Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort | None -> None, Continue val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
pred: FStar.InteractiveHelpers.PostProcess.pred_explorer a -> dbg: Prims.bool -> dfs: Prims.bool -> ge: FStar.InteractiveHelpers.Base.genv -> pl: Prims.list (FStar.InteractiveHelpers.Base.genv * FStar.Stubs.Reflection.V1.Data.term_view) -> opt_c: FStar.Pervasives.Native.option FStar.InteractiveHelpers.ExploreTerm.typ_or_comp -> t: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac (FStar.Pervasives.Native.option (FStar.InteractiveHelpers.PostProcess.exploration_result a))
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.InteractiveHelpers.PostProcess.pred_explorer", "Prims.bool", "FStar.InteractiveHelpers.Base.genv", "Prims.list", "FStar.Pervasives.Native.tuple2", "FStar.Stubs.Reflection.V1.Data.term_view", "FStar.Pervasives.Native.option", "FStar.InteractiveHelpers.ExploreTerm.typ_or_comp", "FStar.Stubs.Reflection.Types.term", "FStar.Pervasives.Native.fst", "FStar.InteractiveHelpers.PostProcess.exploration_result", "FStar.Stubs.Tactics.Types.ctrl_flag", "FStar.InteractiveHelpers.ExploreTerm.explore_term", "FStar.InteractiveHelpers.PostProcess.find_predicated_term_explorer", "FStar.Pervasives.Native.None" ]
[]
false
true
false
false
false
let find_predicated_term #a pred dbg dfs ge pl opt_c t =
fst (explore_term dbg dfs #(option (exploration_result a)) (find_predicated_term_explorer #a pred dbg) None ge pl opt_c t)
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.find_focused_term
val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result term))
val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result term))
let find_focused_term dbg dfs ge pl opt_c t = find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 76, "end_line": 127, "start_col": 0, "start_line": 126 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging. val pp_explore_print_goal : unit -> Tac unit let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f () /// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which /// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*) val is_focus_on_term : term -> Tac bool let is_focus_on_term t = is_fvar t (`%focus_on_term) /// Check if a term is an assertion or an assumption and return its content /// if it is the case. val term_is_assert_or_assume : term -> Tac (option term) let term_is_assert_or_assume t = match inspect t with | Tv_App hd (a, Q_Explicit) -> if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume] then Some a else None | _ -> None /// Check if the given term view is of the form: 'let _ = focus_on_term in body' /// Returns 'body' if it is the case. val is_focused_term : term_view -> Tac (option term) let is_focused_term tv = match tv with | Tv_Let recf attrs _ _ def body -> if is_focus_on_term def then Some body else None | _ -> None noeq type exploration_result (a : Type)= { ge : genv; parents : list (genv & term_view); tgt_comp : option typ_or_comp; res : a; } let mk_exploration_result = Mkexploration_result let pred_explorer (a:Type) = genv -> list (genv & term_view) -> option typ_or_comp -> term_view -> Tac (option a) val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool -> explorer (option (exploration_result a)) let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t = if Some? acc then mfail "find_focused_term_explorer: non empty accumulator"; if dbg then begin print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t) end; match pred ge pl opt_c t with | Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort | None -> None, Continue val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result a)) let find_predicated_term #a pred dbg dfs ge pl opt_c t = fst (explore_term dbg dfs #(option (exploration_result a)) (find_predicated_term_explorer #a pred dbg) None ge pl opt_c t) val _is_focused_term_explorer : pred_explorer term let _is_focused_term_explorer ge pl opt_c tv = is_focused_term tv val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
dbg: Prims.bool -> dfs: Prims.bool -> ge: FStar.InteractiveHelpers.Base.genv -> pl: Prims.list (FStar.InteractiveHelpers.Base.genv * FStar.Stubs.Reflection.V1.Data.term_view) -> opt_c: FStar.Pervasives.Native.option FStar.InteractiveHelpers.ExploreTerm.typ_or_comp -> t: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac (FStar.Pervasives.Native.option (FStar.InteractiveHelpers.PostProcess.exploration_result FStar.Stubs.Reflection.Types.term ))
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.bool", "FStar.InteractiveHelpers.Base.genv", "Prims.list", "FStar.Pervasives.Native.tuple2", "FStar.Stubs.Reflection.V1.Data.term_view", "FStar.Pervasives.Native.option", "FStar.InteractiveHelpers.ExploreTerm.typ_or_comp", "FStar.Stubs.Reflection.Types.term", "FStar.InteractiveHelpers.PostProcess.find_predicated_term", "FStar.InteractiveHelpers.PostProcess._is_focused_term_explorer", "FStar.InteractiveHelpers.PostProcess.exploration_result" ]
[]
false
true
false
false
false
let find_focused_term dbg dfs ge pl opt_c t =
find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess._is_focused_term_explorer
val _is_focused_term_explorer : pred_explorer term
val _is_focused_term_explorer : pred_explorer term
let _is_focused_term_explorer ge pl opt_c tv = is_focused_term tv
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 20, "end_line": 122, "start_col": 0, "start_line": 121 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging. val pp_explore_print_goal : unit -> Tac unit let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f () /// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which /// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*) val is_focus_on_term : term -> Tac bool let is_focus_on_term t = is_fvar t (`%focus_on_term) /// Check if a term is an assertion or an assumption and return its content /// if it is the case. val term_is_assert_or_assume : term -> Tac (option term) let term_is_assert_or_assume t = match inspect t with | Tv_App hd (a, Q_Explicit) -> if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume] then Some a else None | _ -> None /// Check if the given term view is of the form: 'let _ = focus_on_term in body' /// Returns 'body' if it is the case. val is_focused_term : term_view -> Tac (option term) let is_focused_term tv = match tv with | Tv_Let recf attrs _ _ def body -> if is_focus_on_term def then Some body else None | _ -> None noeq type exploration_result (a : Type)= { ge : genv; parents : list (genv & term_view); tgt_comp : option typ_or_comp; res : a; } let mk_exploration_result = Mkexploration_result let pred_explorer (a:Type) = genv -> list (genv & term_view) -> option typ_or_comp -> term_view -> Tac (option a) val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool -> explorer (option (exploration_result a)) let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t = if Some? acc then mfail "find_focused_term_explorer: non empty accumulator"; if dbg then begin print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t) end; match pred ge pl opt_c t with | Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort | None -> None, Continue val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result a)) let find_predicated_term #a pred dbg dfs ge pl opt_c t = fst (explore_term dbg dfs #(option (exploration_result a)) (find_predicated_term_explorer #a pred dbg) None ge pl opt_c t)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
FStar.InteractiveHelpers.PostProcess.pred_explorer FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.InteractiveHelpers.Base.genv", "Prims.list", "FStar.Pervasives.Native.tuple2", "FStar.Stubs.Reflection.V1.Data.term_view", "FStar.Pervasives.Native.option", "FStar.InteractiveHelpers.ExploreTerm.typ_or_comp", "FStar.InteractiveHelpers.PostProcess.is_focused_term", "FStar.Stubs.Reflection.Types.term" ]
[]
false
false
false
true
false
let _is_focused_term_explorer ge pl opt_c tv =
is_focused_term tv
false
Hacl.HKDF.Blake2s_128.fst
Hacl.HKDF.Blake2s_128.expand_blake2s_128
val expand_blake2s_128:expand_st Blake2S
val expand_blake2s_128:expand_st Blake2S
let expand_blake2s_128: expand_st Blake2S = mk_expand Blake2S Hacl.HMAC.Blake2s_128.compute_blake2s_128
{ "file_name": "code/hkdf/Hacl.HKDF.Blake2s_128.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 61, "end_line": 17, "start_col": 0, "start_line": 16 }
module Hacl.HKDF.Blake2s_128 open Spec.Hash.Definitions open Hacl.HKDF #set-options "--z3rlimit 20 --fuel 0 --ifuel 0" [@@ Comment "Expand pseudorandom key to desired length. @param okm Pointer to `len` bytes of memory where output keying material is written to. @param prk Pointer to at least `HashLen` bytes of memory where pseudorandom key is read from. Usually, this points to the output from the extract step. @param prklen Length of pseudorandom key. @param info Pointer to `infolen` bytes of memory where context and application specific information is read from. Can be a zero-length string. @param infolen Length of context and application specific information.
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Hacl.HMAC.Blake2s_128.fst.checked", "Hacl.HKDF.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.HKDF.Blake2s_128.fst" }
[ { "abbrev": false, "full_module": "Hacl.HKDF", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HKDF", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HKDF", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.HKDF.expand_st Spec.Hash.Definitions.Blake2S
Prims.Tot
[ "total" ]
[]
[ "Hacl.HKDF.mk_expand", "Spec.Hash.Definitions.Blake2S", "Hacl.HMAC.Blake2s_128.compute_blake2s_128" ]
[]
false
false
false
true
false
let expand_blake2s_128:expand_st Blake2S =
mk_expand Blake2S Hacl.HMAC.Blake2s_128.compute_blake2s_128
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.pp_analyze_effectful_term
val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit
val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit
let pp_analyze_effectful_term dbg with_gpre with_gpost () = try let res = find_focused_term_in_current_goal dbg in analyze_effectful_term dbg with_gpre with_gpost res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 89, "end_line": 251, "start_col": 0, "start_line": 245 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging. val pp_explore_print_goal : unit -> Tac unit let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f () /// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which /// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*) val is_focus_on_term : term -> Tac bool let is_focus_on_term t = is_fvar t (`%focus_on_term) /// Check if a term is an assertion or an assumption and return its content /// if it is the case. val term_is_assert_or_assume : term -> Tac (option term) let term_is_assert_or_assume t = match inspect t with | Tv_App hd (a, Q_Explicit) -> if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume] then Some a else None | _ -> None /// Check if the given term view is of the form: 'let _ = focus_on_term in body' /// Returns 'body' if it is the case. val is_focused_term : term_view -> Tac (option term) let is_focused_term tv = match tv with | Tv_Let recf attrs _ _ def body -> if is_focus_on_term def then Some body else None | _ -> None noeq type exploration_result (a : Type)= { ge : genv; parents : list (genv & term_view); tgt_comp : option typ_or_comp; res : a; } let mk_exploration_result = Mkexploration_result let pred_explorer (a:Type) = genv -> list (genv & term_view) -> option typ_or_comp -> term_view -> Tac (option a) val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool -> explorer (option (exploration_result a)) let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t = if Some? acc then mfail "find_focused_term_explorer: non empty accumulator"; if dbg then begin print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t) end; match pred ge pl opt_c t with | Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort | None -> None, Continue val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result a)) let find_predicated_term #a pred dbg dfs ge pl opt_c t = fst (explore_term dbg dfs #(option (exploration_result a)) (find_predicated_term_explorer #a pred dbg) None ge pl opt_c t) val _is_focused_term_explorer : pred_explorer term let _is_focused_term_explorer ge pl opt_c tv = is_focused_term tv val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result term)) let find_focused_term dbg dfs ge pl opt_c t = find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_term_in_current_goal : bool -> Tac (exploration_result term) let find_focused_term_in_current_goal dbg = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); begin match find_focused_term dbg true ge [] c l with | Some res -> print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); res | None -> mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: " ^ term_to_string g) end | _ -> mfail "find_focused_term_in_current_goal: not a squashed equality" end /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term) let find_focused_assert_in_current_goal dbg = print_dbg dbg ("[> find_focused_assert_in_current_goal"); let res = find_focused_term_in_current_goal dbg in print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); (* Check that it is an assert or an assume, retrieve the assertion *) let res' = match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> let ge' = genv_push_bv res.ge bv0 ty false None in ({ res with res = fterm; ge = ge' }) | _ -> res in begin match term_is_assert_or_assume res'.res with | None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res) | Some tm -> { res' with res = tm } end (*** Analyze effectful term *) /// Analyze a term in order to print properly instantiated pre/postconditions /// and type conditions. /// with_globals states whether to analyze the target pre/post together with the /// focused term. val analyze_effectful_term : dbg:bool -> with_gpre:bool -> with_gpost:bool -> res:exploration_result term -> Tac unit let analyze_effectful_term dbg with_gpre with_gpost res = let ge = res.ge in let opt_c = res.tgt_comp in (* Analyze the effectful term and check whether it is a 'let' or not *) let ge1, studied_term, info, ret_bv, shadowed_bv, is_let = begin match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> (* Before pushing the binder, check if it shadows another variable. * If it is the case, we will need it to correctly output the pre * and post-assertions (because for the pre-assertions the variable * will not be shadowed yet, while it will be the case for the post- * assertions) *) print_dbg dbg ("Restraining to: " ^ term_to_string fterm); let shadowed_bv : option bv = match genv_get_from_name ge (name_of_bv bv0) with | None -> None | Some (sbv, _) -> Some (fst sbv) in let ge1 = genv_push_bv ge bv0 ty false None in (* If the bv name is "uu___", introduce a fresh variable and use it instead: * the underscore might have been introduced when desugaring a let using * tuples. If doing that is not necessary, the introduced variable will * not appear in the generated assertions anyway. *) let ge2, (bv1 : bv) = let bvv0 = inspect_bv bv0 in let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *) then genv_push_fresh_bv ge1 "ret" ty else ge1, bv0 in let info = compute_eterm_info dbg ge2.env fterm in (ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true) | _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false) end in print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term); print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1); (* Check if the considered term is an assert, in which case we will only * display the precondition (otherwise we introduce too many assertions * in the context) *) let is_assert = Some? (term_is_assert_or_assume studied_term) in (* Instantiate the refinements *) (* TODO: use bv rather than term for ret_arg *) let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in let parents = List.Tot.map snd res.parents in let ge2, asserts = eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let is_assert info ret_arg opt_c parents [] in (* Simplify and filter *) let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in (* Introduce fresh variables for the shadowed ones and substitute *) let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in (* If not a let, insert all the assertions before the term *) let asserts = if is_let then asserts else mk_assertions (List.Tot.append asserts.pres asserts.posts) [] in (* Print *) printout_success ge3 asserts [@plugin]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
dbg: Prims.bool -> with_gpre: Prims.bool -> with_gpost: Prims.bool -> _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.bool", "Prims.unit", "FStar.Tactics.V1.Derived.try_with", "FStar.InteractiveHelpers.PostProcess.end_proof", "FStar.InteractiveHelpers.PostProcess.analyze_effectful_term", "FStar.InteractiveHelpers.PostProcess.exploration_result", "FStar.Stubs.Reflection.Types.term", "FStar.InteractiveHelpers.PostProcess.find_focused_term_in_current_goal", "Prims.exn", "Prims.string", "FStar.InteractiveHelpers.Output.printout_failure", "FStar.Tactics.Effect.raise" ]
[]
false
true
false
false
false
let pp_analyze_effectful_term dbg with_gpre with_gpost () =
try let res = find_focused_term_in_current_goal dbg in analyze_effectful_term dbg with_gpre with_gpost res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> raise err
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.remove_b2t
val remove_b2t : term -> Tac term
val remove_b2t : term -> Tac term
let remove_b2t (t:term) : Tac term = match inspect t with | Tv_App hd (a, Q_Explicit) -> begin match inspect hd with | Tv_FVar fv -> if fv_eq_name fv b2t_qn then a else t | _ -> t end | _ -> t
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 10, "end_line": 273, "start_col": 0, "start_line": 265 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging. val pp_explore_print_goal : unit -> Tac unit let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f () /// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which /// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*) val is_focus_on_term : term -> Tac bool let is_focus_on_term t = is_fvar t (`%focus_on_term) /// Check if a term is an assertion or an assumption and return its content /// if it is the case. val term_is_assert_or_assume : term -> Tac (option term) let term_is_assert_or_assume t = match inspect t with | Tv_App hd (a, Q_Explicit) -> if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume] then Some a else None | _ -> None /// Check if the given term view is of the form: 'let _ = focus_on_term in body' /// Returns 'body' if it is the case. val is_focused_term : term_view -> Tac (option term) let is_focused_term tv = match tv with | Tv_Let recf attrs _ _ def body -> if is_focus_on_term def then Some body else None | _ -> None noeq type exploration_result (a : Type)= { ge : genv; parents : list (genv & term_view); tgt_comp : option typ_or_comp; res : a; } let mk_exploration_result = Mkexploration_result let pred_explorer (a:Type) = genv -> list (genv & term_view) -> option typ_or_comp -> term_view -> Tac (option a) val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool -> explorer (option (exploration_result a)) let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t = if Some? acc then mfail "find_focused_term_explorer: non empty accumulator"; if dbg then begin print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t) end; match pred ge pl opt_c t with | Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort | None -> None, Continue val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result a)) let find_predicated_term #a pred dbg dfs ge pl opt_c t = fst (explore_term dbg dfs #(option (exploration_result a)) (find_predicated_term_explorer #a pred dbg) None ge pl opt_c t) val _is_focused_term_explorer : pred_explorer term let _is_focused_term_explorer ge pl opt_c tv = is_focused_term tv val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result term)) let find_focused_term dbg dfs ge pl opt_c t = find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_term_in_current_goal : bool -> Tac (exploration_result term) let find_focused_term_in_current_goal dbg = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); begin match find_focused_term dbg true ge [] c l with | Some res -> print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); res | None -> mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: " ^ term_to_string g) end | _ -> mfail "find_focused_term_in_current_goal: not a squashed equality" end /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term) let find_focused_assert_in_current_goal dbg = print_dbg dbg ("[> find_focused_assert_in_current_goal"); let res = find_focused_term_in_current_goal dbg in print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); (* Check that it is an assert or an assume, retrieve the assertion *) let res' = match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> let ge' = genv_push_bv res.ge bv0 ty false None in ({ res with res = fterm; ge = ge' }) | _ -> res in begin match term_is_assert_or_assume res'.res with | None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res) | Some tm -> { res' with res = tm } end (*** Analyze effectful term *) /// Analyze a term in order to print properly instantiated pre/postconditions /// and type conditions. /// with_globals states whether to analyze the target pre/post together with the /// focused term. val analyze_effectful_term : dbg:bool -> with_gpre:bool -> with_gpost:bool -> res:exploration_result term -> Tac unit let analyze_effectful_term dbg with_gpre with_gpost res = let ge = res.ge in let opt_c = res.tgt_comp in (* Analyze the effectful term and check whether it is a 'let' or not *) let ge1, studied_term, info, ret_bv, shadowed_bv, is_let = begin match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> (* Before pushing the binder, check if it shadows another variable. * If it is the case, we will need it to correctly output the pre * and post-assertions (because for the pre-assertions the variable * will not be shadowed yet, while it will be the case for the post- * assertions) *) print_dbg dbg ("Restraining to: " ^ term_to_string fterm); let shadowed_bv : option bv = match genv_get_from_name ge (name_of_bv bv0) with | None -> None | Some (sbv, _) -> Some (fst sbv) in let ge1 = genv_push_bv ge bv0 ty false None in (* If the bv name is "uu___", introduce a fresh variable and use it instead: * the underscore might have been introduced when desugaring a let using * tuples. If doing that is not necessary, the introduced variable will * not appear in the generated assertions anyway. *) let ge2, (bv1 : bv) = let bvv0 = inspect_bv bv0 in let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *) then genv_push_fresh_bv ge1 "ret" ty else ge1, bv0 in let info = compute_eterm_info dbg ge2.env fterm in (ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true) | _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false) end in print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term); print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1); (* Check if the considered term is an assert, in which case we will only * display the precondition (otherwise we introduce too many assertions * in the context) *) let is_assert = Some? (term_is_assert_or_assume studied_term) in (* Instantiate the refinements *) (* TODO: use bv rather than term for ret_arg *) let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in let parents = List.Tot.map snd res.parents in let ge2, asserts = eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let is_assert info ret_arg opt_c parents [] in (* Simplify and filter *) let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in (* Introduce fresh variables for the shadowed ones and substitute *) let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in (* If not a let, insert all the assertions before the term *) let asserts = if is_let then asserts else mk_assertions (List.Tot.append asserts.pres asserts.posts) [] in (* Print *) printout_success ge3 asserts [@plugin] val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit let pp_analyze_effectful_term dbg with_gpre with_gpost () = try let res = find_focused_term_in_current_goal dbg in analyze_effectful_term dbg with_gpre with_gpost res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err (*** Split conjunctions *) /// Split an assert made of conjunctions so that there is one assert per /// conjunction. We try to be a bit smart. For instance, if the assertion is of /// the form: /// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An); /// We generate: /// [> assert(let Construct x1 ... xn = e in A1); /// [> ... /// [> assert(let Construct x1 ... xn = e in An); /// Remove ``b2t`` if it is the head of the term
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac FStar.Stubs.Reflection.Types.term
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.Types.fv", "FStar.InteractiveHelpers.Base.fv_eq_name", "FStar.Reflection.Const.b2t_qn", "Prims.bool", "FStar.Stubs.Reflection.V1.Data.term_view", "FStar.Stubs.Tactics.V1.Builtins.inspect" ]
[]
false
true
false
false
false
let remove_b2t (t: term) : Tac term =
match inspect t with | Tv_App hd (a, Q_Explicit) -> (match inspect hd with | Tv_FVar fv -> if fv_eq_name fv b2t_qn then a else t | _ -> t) | _ -> t
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.split_conjunctions_under_match
val split_conjunctions_under_match : bool -> term -> Tac (list term)
val split_conjunctions_under_match : bool -> term -> Tac (list term)
let split_conjunctions_under_match dbg t = let t1 = remove_b2t t in print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1); match inspect t1 with | Tv_Match scrut ret_opt [(pat, br)] -> let tl = split_conjunctions br in map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl | _ -> (* Not of the proper shape: return the original term *) [t]
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 7, "end_line": 322, "start_col": 0, "start_line": 313 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging. val pp_explore_print_goal : unit -> Tac unit let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f () /// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which /// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*) val is_focus_on_term : term -> Tac bool let is_focus_on_term t = is_fvar t (`%focus_on_term) /// Check if a term is an assertion or an assumption and return its content /// if it is the case. val term_is_assert_or_assume : term -> Tac (option term) let term_is_assert_or_assume t = match inspect t with | Tv_App hd (a, Q_Explicit) -> if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume] then Some a else None | _ -> None /// Check if the given term view is of the form: 'let _ = focus_on_term in body' /// Returns 'body' if it is the case. val is_focused_term : term_view -> Tac (option term) let is_focused_term tv = match tv with | Tv_Let recf attrs _ _ def body -> if is_focus_on_term def then Some body else None | _ -> None noeq type exploration_result (a : Type)= { ge : genv; parents : list (genv & term_view); tgt_comp : option typ_or_comp; res : a; } let mk_exploration_result = Mkexploration_result let pred_explorer (a:Type) = genv -> list (genv & term_view) -> option typ_or_comp -> term_view -> Tac (option a) val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool -> explorer (option (exploration_result a)) let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t = if Some? acc then mfail "find_focused_term_explorer: non empty accumulator"; if dbg then begin print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t) end; match pred ge pl opt_c t with | Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort | None -> None, Continue val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result a)) let find_predicated_term #a pred dbg dfs ge pl opt_c t = fst (explore_term dbg dfs #(option (exploration_result a)) (find_predicated_term_explorer #a pred dbg) None ge pl opt_c t) val _is_focused_term_explorer : pred_explorer term let _is_focused_term_explorer ge pl opt_c tv = is_focused_term tv val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result term)) let find_focused_term dbg dfs ge pl opt_c t = find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_term_in_current_goal : bool -> Tac (exploration_result term) let find_focused_term_in_current_goal dbg = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); begin match find_focused_term dbg true ge [] c l with | Some res -> print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); res | None -> mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: " ^ term_to_string g) end | _ -> mfail "find_focused_term_in_current_goal: not a squashed equality" end /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term) let find_focused_assert_in_current_goal dbg = print_dbg dbg ("[> find_focused_assert_in_current_goal"); let res = find_focused_term_in_current_goal dbg in print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); (* Check that it is an assert or an assume, retrieve the assertion *) let res' = match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> let ge' = genv_push_bv res.ge bv0 ty false None in ({ res with res = fterm; ge = ge' }) | _ -> res in begin match term_is_assert_or_assume res'.res with | None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res) | Some tm -> { res' with res = tm } end (*** Analyze effectful term *) /// Analyze a term in order to print properly instantiated pre/postconditions /// and type conditions. /// with_globals states whether to analyze the target pre/post together with the /// focused term. val analyze_effectful_term : dbg:bool -> with_gpre:bool -> with_gpost:bool -> res:exploration_result term -> Tac unit let analyze_effectful_term dbg with_gpre with_gpost res = let ge = res.ge in let opt_c = res.tgt_comp in (* Analyze the effectful term and check whether it is a 'let' or not *) let ge1, studied_term, info, ret_bv, shadowed_bv, is_let = begin match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> (* Before pushing the binder, check if it shadows another variable. * If it is the case, we will need it to correctly output the pre * and post-assertions (because for the pre-assertions the variable * will not be shadowed yet, while it will be the case for the post- * assertions) *) print_dbg dbg ("Restraining to: " ^ term_to_string fterm); let shadowed_bv : option bv = match genv_get_from_name ge (name_of_bv bv0) with | None -> None | Some (sbv, _) -> Some (fst sbv) in let ge1 = genv_push_bv ge bv0 ty false None in (* If the bv name is "uu___", introduce a fresh variable and use it instead: * the underscore might have been introduced when desugaring a let using * tuples. If doing that is not necessary, the introduced variable will * not appear in the generated assertions anyway. *) let ge2, (bv1 : bv) = let bvv0 = inspect_bv bv0 in let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *) then genv_push_fresh_bv ge1 "ret" ty else ge1, bv0 in let info = compute_eterm_info dbg ge2.env fterm in (ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true) | _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false) end in print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term); print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1); (* Check if the considered term is an assert, in which case we will only * display the precondition (otherwise we introduce too many assertions * in the context) *) let is_assert = Some? (term_is_assert_or_assume studied_term) in (* Instantiate the refinements *) (* TODO: use bv rather than term for ret_arg *) let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in let parents = List.Tot.map snd res.parents in let ge2, asserts = eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let is_assert info ret_arg opt_c parents [] in (* Simplify and filter *) let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in (* Introduce fresh variables for the shadowed ones and substitute *) let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in (* If not a let, insert all the assertions before the term *) let asserts = if is_let then asserts else mk_assertions (List.Tot.append asserts.pres asserts.posts) [] in (* Print *) printout_success ge3 asserts [@plugin] val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit let pp_analyze_effectful_term dbg with_gpre with_gpost () = try let res = find_focused_term_in_current_goal dbg in analyze_effectful_term dbg with_gpre with_gpost res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err (*** Split conjunctions *) /// Split an assert made of conjunctions so that there is one assert per /// conjunction. We try to be a bit smart. For instance, if the assertion is of /// the form: /// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An); /// We generate: /// [> assert(let Construct x1 ... xn = e in A1); /// [> ... /// [> assert(let Construct x1 ... xn = e in An); /// Remove ``b2t`` if it is the head of the term val remove_b2t : term -> Tac term let remove_b2t (t:term) : Tac term = match inspect t with | Tv_App hd (a, Q_Explicit) -> begin match inspect hd with | Tv_FVar fv -> if fv_eq_name fv b2t_qn then a else t | _ -> t end | _ -> t // TODO: gather all the functions like split_conjunctions, is_eq... /// Try to destruct a term of the form '_ && _' or '_ /\ _' val is_conjunction : term -> Tac (option (term & term)) let is_conjunction t = let t = remove_b2t t in let hd, params = collect_app t in match params with | [(x,Q_Explicit);(y,Q_Explicit)] -> begin match inspect hd with | Tv_FVar fv -> let fvn = inspect_fv fv in if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"] then Some (x, y) else None | _ -> None end | _ -> None val split_conjunctions : term -> Tac (list term) let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) = match is_conjunction t with | None -> t :: ls | Some (l, r) -> let ls1 = _split_conjunctions ls r in let ls2 = _split_conjunctions ls1 l in ls2 let split_conjunctions t = _split_conjunctions [] t /// Split a term of the form: /// [> let Constuct x1 ... xn = x in A1 /\ ... /\ Am /// into m terms: /// [> let Constuct x1 ... xn = x in A1 /// ... /// [> let Constuct x1 ... xn = x in Am val split_conjunctions_under_match : bool -> term -> Tac (list term)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
dbg: Prims.bool -> t: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac (Prims.list FStar.Stubs.Reflection.Types.term)
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.bool", "FStar.Stubs.Reflection.Types.term", "FStar.Pervasives.Native.option", "FStar.Stubs.Reflection.Types.match_returns_ascription", "FStar.Stubs.Reflection.V1.Data.pattern", "FStar.Tactics.Util.map", "FStar.Stubs.Tactics.V1.Builtins.pack", "FStar.Stubs.Reflection.V1.Data.Tv_Match", "Prims.Cons", "FStar.Stubs.Reflection.V1.Data.branch", "FStar.Pervasives.Native.Mktuple2", "Prims.Nil", "Prims.list", "FStar.InteractiveHelpers.PostProcess.split_conjunctions", "FStar.Stubs.Reflection.V1.Data.term_view", "FStar.Stubs.Tactics.V1.Builtins.inspect", "Prims.unit", "FStar.InteractiveHelpers.Base.print_dbg", "Prims.string", "Prims.op_Hat", "FStar.InteractiveHelpers.Base.term_construct", "FStar.InteractiveHelpers.PostProcess.remove_b2t" ]
[]
false
true
false
false
false
let split_conjunctions_under_match dbg t =
let t1 = remove_b2t t in print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1); match inspect t1 with | Tv_Match scrut ret_opt [pat, br] -> let tl = split_conjunctions br in map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl | _ -> [t]
false
Hacl.HKDF.Blake2s_128.fst
Hacl.HKDF.Blake2s_128.extract_blake2s_128
val extract_blake2s_128:extract_st Blake2S
val extract_blake2s_128:extract_st Blake2S
let extract_blake2s_128: extract_st Blake2S = mk_extract Blake2S Hacl.HMAC.Blake2s_128.compute_blake2s_128
{ "file_name": "code/hkdf/Hacl.HKDF.Blake2s_128.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 62, "end_line": 27, "start_col": 0, "start_line": 26 }
module Hacl.HKDF.Blake2s_128 open Spec.Hash.Definitions open Hacl.HKDF #set-options "--z3rlimit 20 --fuel 0 --ifuel 0" [@@ Comment "Expand pseudorandom key to desired length. @param okm Pointer to `len` bytes of memory where output keying material is written to. @param prk Pointer to at least `HashLen` bytes of memory where pseudorandom key is read from. Usually, this points to the output from the extract step. @param prklen Length of pseudorandom key. @param info Pointer to `infolen` bytes of memory where context and application specific information is read from. Can be a zero-length string. @param infolen Length of context and application specific information. @param len Length of output keying material."] let expand_blake2s_128: expand_st Blake2S = mk_expand Blake2S Hacl.HMAC.Blake2s_128.compute_blake2s_128 [@@ Comment "Extract a fixed-length pseudorandom key from input keying material. @param prk Pointer to `HashLen` bytes of memory where pseudorandom key is written to. @param salt Pointer to `saltlen` bytes of memory where salt value is read from. @param saltlen Length of salt value. @param ikm Pointer to `ikmlen` bytes of memory where input keying material is read from.
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Hacl.HMAC.Blake2s_128.fst.checked", "Hacl.HKDF.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.HKDF.Blake2s_128.fst" }
[ { "abbrev": false, "full_module": "Hacl.HKDF", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HKDF", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HKDF", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.HKDF.extract_st Spec.Hash.Definitions.Blake2S
Prims.Tot
[ "total" ]
[]
[ "Hacl.HKDF.mk_extract", "Spec.Hash.Definitions.Blake2S", "Hacl.HMAC.Blake2s_128.compute_blake2s_128" ]
[]
false
false
false
true
false
let extract_blake2s_128:extract_st Blake2S =
mk_extract Blake2S Hacl.HMAC.Blake2s_128.compute_blake2s_128
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.split_assert_conjs
val split_assert_conjs : bool -> exploration_result term -> Tac unit
val split_assert_conjs : bool -> exploration_result term -> Tac unit
let split_assert_conjs dbg res = let ge0 = res.ge in (* Simplify the term (it may be an abstraction applied to some parameters) *) let t = norm_term_env ge0.env simpl_norm_steps res.res in (* Split the conjunctions *) let conjs = split_conjunctions t in (* If there is only one conjunction, check if it is of the following form * and try to split: * [> let Construct x1 .. xn = x in A1 /\ ... /\ Am *) let conjs = if List.length conjs = 1 then split_conjunctions_under_match dbg t else conjs in let asserts = mk_assertions conjs [] in (* Print *) printout_success ge0 asserts
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 341, "start_col": 0, "start_line": 325 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging. val pp_explore_print_goal : unit -> Tac unit let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f () /// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which /// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*) val is_focus_on_term : term -> Tac bool let is_focus_on_term t = is_fvar t (`%focus_on_term) /// Check if a term is an assertion or an assumption and return its content /// if it is the case. val term_is_assert_or_assume : term -> Tac (option term) let term_is_assert_or_assume t = match inspect t with | Tv_App hd (a, Q_Explicit) -> if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume] then Some a else None | _ -> None /// Check if the given term view is of the form: 'let _ = focus_on_term in body' /// Returns 'body' if it is the case. val is_focused_term : term_view -> Tac (option term) let is_focused_term tv = match tv with | Tv_Let recf attrs _ _ def body -> if is_focus_on_term def then Some body else None | _ -> None noeq type exploration_result (a : Type)= { ge : genv; parents : list (genv & term_view); tgt_comp : option typ_or_comp; res : a; } let mk_exploration_result = Mkexploration_result let pred_explorer (a:Type) = genv -> list (genv & term_view) -> option typ_or_comp -> term_view -> Tac (option a) val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool -> explorer (option (exploration_result a)) let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t = if Some? acc then mfail "find_focused_term_explorer: non empty accumulator"; if dbg then begin print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t) end; match pred ge pl opt_c t with | Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort | None -> None, Continue val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result a)) let find_predicated_term #a pred dbg dfs ge pl opt_c t = fst (explore_term dbg dfs #(option (exploration_result a)) (find_predicated_term_explorer #a pred dbg) None ge pl opt_c t) val _is_focused_term_explorer : pred_explorer term let _is_focused_term_explorer ge pl opt_c tv = is_focused_term tv val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result term)) let find_focused_term dbg dfs ge pl opt_c t = find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_term_in_current_goal : bool -> Tac (exploration_result term) let find_focused_term_in_current_goal dbg = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); begin match find_focused_term dbg true ge [] c l with | Some res -> print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); res | None -> mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: " ^ term_to_string g) end | _ -> mfail "find_focused_term_in_current_goal: not a squashed equality" end /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term) let find_focused_assert_in_current_goal dbg = print_dbg dbg ("[> find_focused_assert_in_current_goal"); let res = find_focused_term_in_current_goal dbg in print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); (* Check that it is an assert or an assume, retrieve the assertion *) let res' = match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> let ge' = genv_push_bv res.ge bv0 ty false None in ({ res with res = fterm; ge = ge' }) | _ -> res in begin match term_is_assert_or_assume res'.res with | None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res) | Some tm -> { res' with res = tm } end (*** Analyze effectful term *) /// Analyze a term in order to print properly instantiated pre/postconditions /// and type conditions. /// with_globals states whether to analyze the target pre/post together with the /// focused term. val analyze_effectful_term : dbg:bool -> with_gpre:bool -> with_gpost:bool -> res:exploration_result term -> Tac unit let analyze_effectful_term dbg with_gpre with_gpost res = let ge = res.ge in let opt_c = res.tgt_comp in (* Analyze the effectful term and check whether it is a 'let' or not *) let ge1, studied_term, info, ret_bv, shadowed_bv, is_let = begin match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> (* Before pushing the binder, check if it shadows another variable. * If it is the case, we will need it to correctly output the pre * and post-assertions (because for the pre-assertions the variable * will not be shadowed yet, while it will be the case for the post- * assertions) *) print_dbg dbg ("Restraining to: " ^ term_to_string fterm); let shadowed_bv : option bv = match genv_get_from_name ge (name_of_bv bv0) with | None -> None | Some (sbv, _) -> Some (fst sbv) in let ge1 = genv_push_bv ge bv0 ty false None in (* If the bv name is "uu___", introduce a fresh variable and use it instead: * the underscore might have been introduced when desugaring a let using * tuples. If doing that is not necessary, the introduced variable will * not appear in the generated assertions anyway. *) let ge2, (bv1 : bv) = let bvv0 = inspect_bv bv0 in let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *) then genv_push_fresh_bv ge1 "ret" ty else ge1, bv0 in let info = compute_eterm_info dbg ge2.env fterm in (ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true) | _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false) end in print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term); print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1); (* Check if the considered term is an assert, in which case we will only * display the precondition (otherwise we introduce too many assertions * in the context) *) let is_assert = Some? (term_is_assert_or_assume studied_term) in (* Instantiate the refinements *) (* TODO: use bv rather than term for ret_arg *) let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in let parents = List.Tot.map snd res.parents in let ge2, asserts = eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let is_assert info ret_arg opt_c parents [] in (* Simplify and filter *) let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in (* Introduce fresh variables for the shadowed ones and substitute *) let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in (* If not a let, insert all the assertions before the term *) let asserts = if is_let then asserts else mk_assertions (List.Tot.append asserts.pres asserts.posts) [] in (* Print *) printout_success ge3 asserts [@plugin] val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit let pp_analyze_effectful_term dbg with_gpre with_gpost () = try let res = find_focused_term_in_current_goal dbg in analyze_effectful_term dbg with_gpre with_gpost res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err (*** Split conjunctions *) /// Split an assert made of conjunctions so that there is one assert per /// conjunction. We try to be a bit smart. For instance, if the assertion is of /// the form: /// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An); /// We generate: /// [> assert(let Construct x1 ... xn = e in A1); /// [> ... /// [> assert(let Construct x1 ... xn = e in An); /// Remove ``b2t`` if it is the head of the term val remove_b2t : term -> Tac term let remove_b2t (t:term) : Tac term = match inspect t with | Tv_App hd (a, Q_Explicit) -> begin match inspect hd with | Tv_FVar fv -> if fv_eq_name fv b2t_qn then a else t | _ -> t end | _ -> t // TODO: gather all the functions like split_conjunctions, is_eq... /// Try to destruct a term of the form '_ && _' or '_ /\ _' val is_conjunction : term -> Tac (option (term & term)) let is_conjunction t = let t = remove_b2t t in let hd, params = collect_app t in match params with | [(x,Q_Explicit);(y,Q_Explicit)] -> begin match inspect hd with | Tv_FVar fv -> let fvn = inspect_fv fv in if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"] then Some (x, y) else None | _ -> None end | _ -> None val split_conjunctions : term -> Tac (list term) let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) = match is_conjunction t with | None -> t :: ls | Some (l, r) -> let ls1 = _split_conjunctions ls r in let ls2 = _split_conjunctions ls1 l in ls2 let split_conjunctions t = _split_conjunctions [] t /// Split a term of the form: /// [> let Constuct x1 ... xn = x in A1 /\ ... /\ Am /// into m terms: /// [> let Constuct x1 ... xn = x in A1 /// ... /// [> let Constuct x1 ... xn = x in Am val split_conjunctions_under_match : bool -> term -> Tac (list term) let split_conjunctions_under_match dbg t = let t1 = remove_b2t t in print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1); match inspect t1 with | Tv_Match scrut ret_opt [(pat, br)] -> let tl = split_conjunctions br in map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl | _ -> (* Not of the proper shape: return the original term *) [t]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
dbg: Prims.bool -> res: FStar.InteractiveHelpers.PostProcess.exploration_result FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.bool", "FStar.InteractiveHelpers.PostProcess.exploration_result", "FStar.Stubs.Reflection.Types.term", "FStar.InteractiveHelpers.Output.printout_success", "Prims.unit", "FStar.InteractiveHelpers.Propositions.assertions", "FStar.InteractiveHelpers.Propositions.mk_assertions", "Prims.Nil", "FStar.InteractiveHelpers.Propositions.proposition", "Prims.list", "Prims.op_Equality", "Prims.int", "FStar.List.Tot.Base.length", "FStar.InteractiveHelpers.PostProcess.split_conjunctions_under_match", "FStar.InteractiveHelpers.PostProcess.split_conjunctions", "FStar.Stubs.Tactics.V1.Builtins.norm_term_env", "FStar.InteractiveHelpers.Base.__proj__Mkgenv__item__env", "FStar.InteractiveHelpers.Propositions.simpl_norm_steps", "FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__res", "FStar.InteractiveHelpers.Base.genv", "FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__ge" ]
[]
false
true
false
false
false
let split_assert_conjs dbg res =
let ge0 = res.ge in let t = norm_term_env ge0.env simpl_norm_steps res.res in let conjs = split_conjunctions t in let conjs = if List.length conjs = 1 then split_conjunctions_under_match dbg t else conjs in let asserts = mk_assertions conjs [] in printout_success ge0 asserts
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.pp_split_assert_conjs
val pp_split_assert_conjs : bool -> unit -> Tac unit
val pp_split_assert_conjs : bool -> unit -> Tac unit
let pp_split_assert_conjs dbg () = try let res = find_focused_assert_in_current_goal dbg in split_assert_conjs dbg res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 89, "end_line": 351, "start_col": 0, "start_line": 345 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging. val pp_explore_print_goal : unit -> Tac unit let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f () /// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which /// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*) val is_focus_on_term : term -> Tac bool let is_focus_on_term t = is_fvar t (`%focus_on_term) /// Check if a term is an assertion or an assumption and return its content /// if it is the case. val term_is_assert_or_assume : term -> Tac (option term) let term_is_assert_or_assume t = match inspect t with | Tv_App hd (a, Q_Explicit) -> if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume] then Some a else None | _ -> None /// Check if the given term view is of the form: 'let _ = focus_on_term in body' /// Returns 'body' if it is the case. val is_focused_term : term_view -> Tac (option term) let is_focused_term tv = match tv with | Tv_Let recf attrs _ _ def body -> if is_focus_on_term def then Some body else None | _ -> None noeq type exploration_result (a : Type)= { ge : genv; parents : list (genv & term_view); tgt_comp : option typ_or_comp; res : a; } let mk_exploration_result = Mkexploration_result let pred_explorer (a:Type) = genv -> list (genv & term_view) -> option typ_or_comp -> term_view -> Tac (option a) val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool -> explorer (option (exploration_result a)) let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t = if Some? acc then mfail "find_focused_term_explorer: non empty accumulator"; if dbg then begin print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t) end; match pred ge pl opt_c t with | Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort | None -> None, Continue val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result a)) let find_predicated_term #a pred dbg dfs ge pl opt_c t = fst (explore_term dbg dfs #(option (exploration_result a)) (find_predicated_term_explorer #a pred dbg) None ge pl opt_c t) val _is_focused_term_explorer : pred_explorer term let _is_focused_term_explorer ge pl opt_c tv = is_focused_term tv val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result term)) let find_focused_term dbg dfs ge pl opt_c t = find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_term_in_current_goal : bool -> Tac (exploration_result term) let find_focused_term_in_current_goal dbg = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); begin match find_focused_term dbg true ge [] c l with | Some res -> print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); res | None -> mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: " ^ term_to_string g) end | _ -> mfail "find_focused_term_in_current_goal: not a squashed equality" end /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term) let find_focused_assert_in_current_goal dbg = print_dbg dbg ("[> find_focused_assert_in_current_goal"); let res = find_focused_term_in_current_goal dbg in print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); (* Check that it is an assert or an assume, retrieve the assertion *) let res' = match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> let ge' = genv_push_bv res.ge bv0 ty false None in ({ res with res = fterm; ge = ge' }) | _ -> res in begin match term_is_assert_or_assume res'.res with | None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res) | Some tm -> { res' with res = tm } end (*** Analyze effectful term *) /// Analyze a term in order to print properly instantiated pre/postconditions /// and type conditions. /// with_globals states whether to analyze the target pre/post together with the /// focused term. val analyze_effectful_term : dbg:bool -> with_gpre:bool -> with_gpost:bool -> res:exploration_result term -> Tac unit let analyze_effectful_term dbg with_gpre with_gpost res = let ge = res.ge in let opt_c = res.tgt_comp in (* Analyze the effectful term and check whether it is a 'let' or not *) let ge1, studied_term, info, ret_bv, shadowed_bv, is_let = begin match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> (* Before pushing the binder, check if it shadows another variable. * If it is the case, we will need it to correctly output the pre * and post-assertions (because for the pre-assertions the variable * will not be shadowed yet, while it will be the case for the post- * assertions) *) print_dbg dbg ("Restraining to: " ^ term_to_string fterm); let shadowed_bv : option bv = match genv_get_from_name ge (name_of_bv bv0) with | None -> None | Some (sbv, _) -> Some (fst sbv) in let ge1 = genv_push_bv ge bv0 ty false None in (* If the bv name is "uu___", introduce a fresh variable and use it instead: * the underscore might have been introduced when desugaring a let using * tuples. If doing that is not necessary, the introduced variable will * not appear in the generated assertions anyway. *) let ge2, (bv1 : bv) = let bvv0 = inspect_bv bv0 in let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *) then genv_push_fresh_bv ge1 "ret" ty else ge1, bv0 in let info = compute_eterm_info dbg ge2.env fterm in (ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true) | _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false) end in print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term); print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1); (* Check if the considered term is an assert, in which case we will only * display the precondition (otherwise we introduce too many assertions * in the context) *) let is_assert = Some? (term_is_assert_or_assume studied_term) in (* Instantiate the refinements *) (* TODO: use bv rather than term for ret_arg *) let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in let parents = List.Tot.map snd res.parents in let ge2, asserts = eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let is_assert info ret_arg opt_c parents [] in (* Simplify and filter *) let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in (* Introduce fresh variables for the shadowed ones and substitute *) let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in (* If not a let, insert all the assertions before the term *) let asserts = if is_let then asserts else mk_assertions (List.Tot.append asserts.pres asserts.posts) [] in (* Print *) printout_success ge3 asserts [@plugin] val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit let pp_analyze_effectful_term dbg with_gpre with_gpost () = try let res = find_focused_term_in_current_goal dbg in analyze_effectful_term dbg with_gpre with_gpost res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err (*** Split conjunctions *) /// Split an assert made of conjunctions so that there is one assert per /// conjunction. We try to be a bit smart. For instance, if the assertion is of /// the form: /// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An); /// We generate: /// [> assert(let Construct x1 ... xn = e in A1); /// [> ... /// [> assert(let Construct x1 ... xn = e in An); /// Remove ``b2t`` if it is the head of the term val remove_b2t : term -> Tac term let remove_b2t (t:term) : Tac term = match inspect t with | Tv_App hd (a, Q_Explicit) -> begin match inspect hd with | Tv_FVar fv -> if fv_eq_name fv b2t_qn then a else t | _ -> t end | _ -> t // TODO: gather all the functions like split_conjunctions, is_eq... /// Try to destruct a term of the form '_ && _' or '_ /\ _' val is_conjunction : term -> Tac (option (term & term)) let is_conjunction t = let t = remove_b2t t in let hd, params = collect_app t in match params with | [(x,Q_Explicit);(y,Q_Explicit)] -> begin match inspect hd with | Tv_FVar fv -> let fvn = inspect_fv fv in if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"] then Some (x, y) else None | _ -> None end | _ -> None val split_conjunctions : term -> Tac (list term) let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) = match is_conjunction t with | None -> t :: ls | Some (l, r) -> let ls1 = _split_conjunctions ls r in let ls2 = _split_conjunctions ls1 l in ls2 let split_conjunctions t = _split_conjunctions [] t /// Split a term of the form: /// [> let Constuct x1 ... xn = x in A1 /\ ... /\ Am /// into m terms: /// [> let Constuct x1 ... xn = x in A1 /// ... /// [> let Constuct x1 ... xn = x in Am val split_conjunctions_under_match : bool -> term -> Tac (list term) let split_conjunctions_under_match dbg t = let t1 = remove_b2t t in print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1); match inspect t1 with | Tv_Match scrut ret_opt [(pat, br)] -> let tl = split_conjunctions br in map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl | _ -> (* Not of the proper shape: return the original term *) [t] val split_assert_conjs : bool -> exploration_result term -> Tac unit let split_assert_conjs dbg res = let ge0 = res.ge in (* Simplify the term (it may be an abstraction applied to some parameters) *) let t = norm_term_env ge0.env simpl_norm_steps res.res in (* Split the conjunctions *) let conjs = split_conjunctions t in (* If there is only one conjunction, check if it is of the following form * and try to split: * [> let Construct x1 .. xn = x in A1 /\ ... /\ Am *) let conjs = if List.length conjs = 1 then split_conjunctions_under_match dbg t else conjs in let asserts = mk_assertions conjs [] in (* Print *) printout_success ge0 asserts [@plugin]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
dbg: Prims.bool -> _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.bool", "Prims.unit", "FStar.Tactics.V1.Derived.try_with", "FStar.InteractiveHelpers.PostProcess.end_proof", "FStar.InteractiveHelpers.PostProcess.split_assert_conjs", "FStar.InteractiveHelpers.PostProcess.exploration_result", "FStar.Stubs.Reflection.Types.term", "FStar.InteractiveHelpers.PostProcess.find_focused_assert_in_current_goal", "Prims.exn", "Prims.string", "FStar.InteractiveHelpers.Output.printout_failure", "FStar.Tactics.Effect.raise" ]
[]
false
true
false
false
false
let pp_split_assert_conjs dbg () =
try let res = find_focused_assert_in_current_goal dbg in split_assert_conjs dbg res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> raise err
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.find_subequality
val find_subequality : bool -> term -> term -> Tac (option term)
val find_subequality : bool -> term -> term -> Tac (option term)
let find_subequality dbg tm p = print_dbg dbg ("[> find_subequality:" ^ "\n- ter : " ^ term_to_string tm ^ "\n- props: " ^ term_to_string p); let conjuncts = split_conjunctions p in print_dbg dbg ("Conjuncts:\n" ^ list_to_string term_to_string conjuncts); tryPick (is_equality_for_term dbg tm) conjuncts
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 49, "end_line": 462, "start_col": 0, "start_line": 456 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging. val pp_explore_print_goal : unit -> Tac unit let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f () /// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which /// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*) val is_focus_on_term : term -> Tac bool let is_focus_on_term t = is_fvar t (`%focus_on_term) /// Check if a term is an assertion or an assumption and return its content /// if it is the case. val term_is_assert_or_assume : term -> Tac (option term) let term_is_assert_or_assume t = match inspect t with | Tv_App hd (a, Q_Explicit) -> if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume] then Some a else None | _ -> None /// Check if the given term view is of the form: 'let _ = focus_on_term in body' /// Returns 'body' if it is the case. val is_focused_term : term_view -> Tac (option term) let is_focused_term tv = match tv with | Tv_Let recf attrs _ _ def body -> if is_focus_on_term def then Some body else None | _ -> None noeq type exploration_result (a : Type)= { ge : genv; parents : list (genv & term_view); tgt_comp : option typ_or_comp; res : a; } let mk_exploration_result = Mkexploration_result let pred_explorer (a:Type) = genv -> list (genv & term_view) -> option typ_or_comp -> term_view -> Tac (option a) val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool -> explorer (option (exploration_result a)) let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t = if Some? acc then mfail "find_focused_term_explorer: non empty accumulator"; if dbg then begin print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t) end; match pred ge pl opt_c t with | Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort | None -> None, Continue val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result a)) let find_predicated_term #a pred dbg dfs ge pl opt_c t = fst (explore_term dbg dfs #(option (exploration_result a)) (find_predicated_term_explorer #a pred dbg) None ge pl opt_c t) val _is_focused_term_explorer : pred_explorer term let _is_focused_term_explorer ge pl opt_c tv = is_focused_term tv val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result term)) let find_focused_term dbg dfs ge pl opt_c t = find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_term_in_current_goal : bool -> Tac (exploration_result term) let find_focused_term_in_current_goal dbg = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); begin match find_focused_term dbg true ge [] c l with | Some res -> print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); res | None -> mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: " ^ term_to_string g) end | _ -> mfail "find_focused_term_in_current_goal: not a squashed equality" end /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term) let find_focused_assert_in_current_goal dbg = print_dbg dbg ("[> find_focused_assert_in_current_goal"); let res = find_focused_term_in_current_goal dbg in print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); (* Check that it is an assert or an assume, retrieve the assertion *) let res' = match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> let ge' = genv_push_bv res.ge bv0 ty false None in ({ res with res = fterm; ge = ge' }) | _ -> res in begin match term_is_assert_or_assume res'.res with | None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res) | Some tm -> { res' with res = tm } end (*** Analyze effectful term *) /// Analyze a term in order to print properly instantiated pre/postconditions /// and type conditions. /// with_globals states whether to analyze the target pre/post together with the /// focused term. val analyze_effectful_term : dbg:bool -> with_gpre:bool -> with_gpost:bool -> res:exploration_result term -> Tac unit let analyze_effectful_term dbg with_gpre with_gpost res = let ge = res.ge in let opt_c = res.tgt_comp in (* Analyze the effectful term and check whether it is a 'let' or not *) let ge1, studied_term, info, ret_bv, shadowed_bv, is_let = begin match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> (* Before pushing the binder, check if it shadows another variable. * If it is the case, we will need it to correctly output the pre * and post-assertions (because for the pre-assertions the variable * will not be shadowed yet, while it will be the case for the post- * assertions) *) print_dbg dbg ("Restraining to: " ^ term_to_string fterm); let shadowed_bv : option bv = match genv_get_from_name ge (name_of_bv bv0) with | None -> None | Some (sbv, _) -> Some (fst sbv) in let ge1 = genv_push_bv ge bv0 ty false None in (* If the bv name is "uu___", introduce a fresh variable and use it instead: * the underscore might have been introduced when desugaring a let using * tuples. If doing that is not necessary, the introduced variable will * not appear in the generated assertions anyway. *) let ge2, (bv1 : bv) = let bvv0 = inspect_bv bv0 in let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *) then genv_push_fresh_bv ge1 "ret" ty else ge1, bv0 in let info = compute_eterm_info dbg ge2.env fterm in (ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true) | _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false) end in print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term); print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1); (* Check if the considered term is an assert, in which case we will only * display the precondition (otherwise we introduce too many assertions * in the context) *) let is_assert = Some? (term_is_assert_or_assume studied_term) in (* Instantiate the refinements *) (* TODO: use bv rather than term for ret_arg *) let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in let parents = List.Tot.map snd res.parents in let ge2, asserts = eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let is_assert info ret_arg opt_c parents [] in (* Simplify and filter *) let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in (* Introduce fresh variables for the shadowed ones and substitute *) let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in (* If not a let, insert all the assertions before the term *) let asserts = if is_let then asserts else mk_assertions (List.Tot.append asserts.pres asserts.posts) [] in (* Print *) printout_success ge3 asserts [@plugin] val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit let pp_analyze_effectful_term dbg with_gpre with_gpost () = try let res = find_focused_term_in_current_goal dbg in analyze_effectful_term dbg with_gpre with_gpost res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err (*** Split conjunctions *) /// Split an assert made of conjunctions so that there is one assert per /// conjunction. We try to be a bit smart. For instance, if the assertion is of /// the form: /// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An); /// We generate: /// [> assert(let Construct x1 ... xn = e in A1); /// [> ... /// [> assert(let Construct x1 ... xn = e in An); /// Remove ``b2t`` if it is the head of the term val remove_b2t : term -> Tac term let remove_b2t (t:term) : Tac term = match inspect t with | Tv_App hd (a, Q_Explicit) -> begin match inspect hd with | Tv_FVar fv -> if fv_eq_name fv b2t_qn then a else t | _ -> t end | _ -> t // TODO: gather all the functions like split_conjunctions, is_eq... /// Try to destruct a term of the form '_ && _' or '_ /\ _' val is_conjunction : term -> Tac (option (term & term)) let is_conjunction t = let t = remove_b2t t in let hd, params = collect_app t in match params with | [(x,Q_Explicit);(y,Q_Explicit)] -> begin match inspect hd with | Tv_FVar fv -> let fvn = inspect_fv fv in if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"] then Some (x, y) else None | _ -> None end | _ -> None val split_conjunctions : term -> Tac (list term) let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) = match is_conjunction t with | None -> t :: ls | Some (l, r) -> let ls1 = _split_conjunctions ls r in let ls2 = _split_conjunctions ls1 l in ls2 let split_conjunctions t = _split_conjunctions [] t /// Split a term of the form: /// [> let Constuct x1 ... xn = x in A1 /\ ... /\ Am /// into m terms: /// [> let Constuct x1 ... xn = x in A1 /// ... /// [> let Constuct x1 ... xn = x in Am val split_conjunctions_under_match : bool -> term -> Tac (list term) let split_conjunctions_under_match dbg t = let t1 = remove_b2t t in print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1); match inspect t1 with | Tv_Match scrut ret_opt [(pat, br)] -> let tl = split_conjunctions br in map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl | _ -> (* Not of the proper shape: return the original term *) [t] val split_assert_conjs : bool -> exploration_result term -> Tac unit let split_assert_conjs dbg res = let ge0 = res.ge in (* Simplify the term (it may be an abstraction applied to some parameters) *) let t = norm_term_env ge0.env simpl_norm_steps res.res in (* Split the conjunctions *) let conjs = split_conjunctions t in (* If there is only one conjunction, check if it is of the following form * and try to split: * [> let Construct x1 .. xn = x in A1 /\ ... /\ Am *) let conjs = if List.length conjs = 1 then split_conjunctions_under_match dbg t else conjs in let asserts = mk_assertions conjs [] in (* Print *) printout_success ge0 asserts [@plugin] val pp_split_assert_conjs : bool -> unit -> Tac unit let pp_split_assert_conjs dbg () = try let res = find_focused_assert_in_current_goal dbg in split_assert_conjs dbg res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err (*** Term unfolding in assert *) /// Unfold/rewrite a term in an assert. /// If the term is a (recursive) top-level identifier, unfold it. /// Otherwise look for an equality or a pure let-binding to replace it with. /// If the assert is an equality, unfold/rewrite only on the side chosen by the user. // TODO: use "kind" keyword rather than type above /// An equality kind noeq type eq_kind = | Eq_Dec : typ -> eq_kind (* = *) | Eq_Undec : typ -> eq_kind (* == *) | Eq_Hetero : typ -> typ -> eq_kind (* === *) /// Deconstruct an equality // We use our own construct because ``term_as_formula`` doesn't always work // TODO: update ``term_as_formula`` val is_eq : bool -> term -> Tac (option (eq_kind & term & term)) let is_eq dbg t = let t = remove_b2t t in print_dbg dbg ("[> is_eq: " ^ term_to_string t); let hd, params = collect_app t in print_dbg dbg ("- hd:\n" ^ term_to_string hd); print_dbg dbg ("- parameters:\n" ^ list_to_string (fun (x, y) -> term_to_string x) params); match inspect hd with | Tv_FVar fv -> begin match params with | [(a,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] -> if is_any_fvar a [`%Prims.op_Equality; `%Prims.equals; "Prims.op_Equals"] then Some ((Eq_Dec a), x, y) else if is_any_fvar a [`%Prims.eq2; "Prims.op_Equals_Equals"] then Some ((Eq_Undec a), x, y) else None | [(a,Q_Implicit);(b,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] -> if is_fvar a (`%Prims.op_Equals_Equals_Equals) then Some ((Eq_Hetero a b), x, y) else None | _ -> None end | _ -> None /// Reconstruct an equality val mk_eq : eq_kind -> term -> term -> Tot term let mk_eq k t1 t2 = match k with | Eq_Dec ty -> mk_app (`Prims.op_Equality) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)] | Eq_Undec ty -> mk_app (`Prims.eq2) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)] | Eq_Hetero ty1 ty2 -> mk_app Prims.(`( === )) [(ty1, Q_Implicit); (ty2, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)] let formula_construct (f : formula) : Tac string = match f with | True_ -> "True_" | False_ -> "False_" | Comp _ _ _ -> "Comp" | And _ _ -> "And" | Or _ _ -> "Or" | Not _ -> "Not" | Implies _ _ -> "Implies" | Iff _ _ -> "Iff" | Forall _ _ _ -> "Forall" | Exists _ _ _ -> "Exists" | App _ _ -> "Apply" | Name _ -> "Name" | FV _ -> "FV" | IntLit _ -> "IntLit" | F_Unknown -> "F_Unknown" /// Check if a proposition is an equality which can be used to rewrite a term. /// Return the operand of the equality which the term is equal to if it is the case. val is_equality_for_term : bool -> term -> term -> Tac (option term) let is_equality_for_term dbg tm p = print_dbg dbg ("[> is_equality_for_term:" ^ "\n- term: " ^ term_to_string tm ^ "\n- prop: " ^ term_to_string p); (* Specialize equality for bv - TODO: not sure if necessary, but I had problems * in the past *) let check_eq : term -> Tac bool = match inspect tm with | Tv_Var bv -> (fun tm' -> match inspect tm' with | Tv_Var bv' -> bv_eq bv bv' | _ -> false) | _ -> (fun tm' -> term_eq tm tm') in match is_eq dbg p with | Some (ekind, l, r) -> (* We ignore heterogeneous equality, because it risks to cause havoc at * typing after substitution *) print_dbg dbg ("Term is eq: " ^ term_to_string l ^ " = " ^ term_to_string r); if Eq_Hetero? ekind then begin print_dbg dbg "Ignoring heterogeneous equality"; None end else if check_eq l then Some r else if check_eq r then Some l else None | _ -> print_dbg dbg "Term is not eq"; None
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
dbg: Prims.bool -> tm: FStar.Stubs.Reflection.Types.term -> p: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac (FStar.Pervasives.Native.option FStar.Stubs.Reflection.Types.term)
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.bool", "FStar.Stubs.Reflection.Types.term", "FStar.Tactics.Util.tryPick", "FStar.InteractiveHelpers.PostProcess.is_equality_for_term", "FStar.Pervasives.Native.option", "Prims.unit", "FStar.InteractiveHelpers.Base.print_dbg", "Prims.string", "Prims.op_Hat", "FStar.InteractiveHelpers.Base.list_to_string", "FStar.Stubs.Tactics.V1.Builtins.term_to_string", "Prims.list", "FStar.InteractiveHelpers.PostProcess.split_conjunctions" ]
[]
false
true
false
false
false
let find_subequality dbg tm p =
print_dbg dbg ("[> find_subequality:" ^ "\n- ter : " ^ term_to_string tm ^ "\n- props: " ^ term_to_string p); let conjuncts = split_conjunctions p in print_dbg dbg ("Conjuncts:\n" ^ list_to_string term_to_string conjuncts); tryPick (is_equality_for_term dbg tm) conjuncts
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.strip_implicit_parameters
val strip_implicit_parameters : term -> Tac term
val strip_implicit_parameters : term -> Tac term
let rec strip_implicit_parameters tm = match inspect tm with | Tv_App hd (a,qualif) -> if Q_Implicit? qualif then strip_implicit_parameters hd else tm | _ -> tm
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 11, "end_line": 597, "start_col": 0, "start_line": 593 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging. val pp_explore_print_goal : unit -> Tac unit let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f () /// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which /// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*) val is_focus_on_term : term -> Tac bool let is_focus_on_term t = is_fvar t (`%focus_on_term) /// Check if a term is an assertion or an assumption and return its content /// if it is the case. val term_is_assert_or_assume : term -> Tac (option term) let term_is_assert_or_assume t = match inspect t with | Tv_App hd (a, Q_Explicit) -> if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume] then Some a else None | _ -> None /// Check if the given term view is of the form: 'let _ = focus_on_term in body' /// Returns 'body' if it is the case. val is_focused_term : term_view -> Tac (option term) let is_focused_term tv = match tv with | Tv_Let recf attrs _ _ def body -> if is_focus_on_term def then Some body else None | _ -> None noeq type exploration_result (a : Type)= { ge : genv; parents : list (genv & term_view); tgt_comp : option typ_or_comp; res : a; } let mk_exploration_result = Mkexploration_result let pred_explorer (a:Type) = genv -> list (genv & term_view) -> option typ_or_comp -> term_view -> Tac (option a) val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool -> explorer (option (exploration_result a)) let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t = if Some? acc then mfail "find_focused_term_explorer: non empty accumulator"; if dbg then begin print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t) end; match pred ge pl opt_c t with | Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort | None -> None, Continue val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result a)) let find_predicated_term #a pred dbg dfs ge pl opt_c t = fst (explore_term dbg dfs #(option (exploration_result a)) (find_predicated_term_explorer #a pred dbg) None ge pl opt_c t) val _is_focused_term_explorer : pred_explorer term let _is_focused_term_explorer ge pl opt_c tv = is_focused_term tv val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result term)) let find_focused_term dbg dfs ge pl opt_c t = find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_term_in_current_goal : bool -> Tac (exploration_result term) let find_focused_term_in_current_goal dbg = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); begin match find_focused_term dbg true ge [] c l with | Some res -> print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); res | None -> mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: " ^ term_to_string g) end | _ -> mfail "find_focused_term_in_current_goal: not a squashed equality" end /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term) let find_focused_assert_in_current_goal dbg = print_dbg dbg ("[> find_focused_assert_in_current_goal"); let res = find_focused_term_in_current_goal dbg in print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); (* Check that it is an assert or an assume, retrieve the assertion *) let res' = match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> let ge' = genv_push_bv res.ge bv0 ty false None in ({ res with res = fterm; ge = ge' }) | _ -> res in begin match term_is_assert_or_assume res'.res with | None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res) | Some tm -> { res' with res = tm } end (*** Analyze effectful term *) /// Analyze a term in order to print properly instantiated pre/postconditions /// and type conditions. /// with_globals states whether to analyze the target pre/post together with the /// focused term. val analyze_effectful_term : dbg:bool -> with_gpre:bool -> with_gpost:bool -> res:exploration_result term -> Tac unit let analyze_effectful_term dbg with_gpre with_gpost res = let ge = res.ge in let opt_c = res.tgt_comp in (* Analyze the effectful term and check whether it is a 'let' or not *) let ge1, studied_term, info, ret_bv, shadowed_bv, is_let = begin match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> (* Before pushing the binder, check if it shadows another variable. * If it is the case, we will need it to correctly output the pre * and post-assertions (because for the pre-assertions the variable * will not be shadowed yet, while it will be the case for the post- * assertions) *) print_dbg dbg ("Restraining to: " ^ term_to_string fterm); let shadowed_bv : option bv = match genv_get_from_name ge (name_of_bv bv0) with | None -> None | Some (sbv, _) -> Some (fst sbv) in let ge1 = genv_push_bv ge bv0 ty false None in (* If the bv name is "uu___", introduce a fresh variable and use it instead: * the underscore might have been introduced when desugaring a let using * tuples. If doing that is not necessary, the introduced variable will * not appear in the generated assertions anyway. *) let ge2, (bv1 : bv) = let bvv0 = inspect_bv bv0 in let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *) then genv_push_fresh_bv ge1 "ret" ty else ge1, bv0 in let info = compute_eterm_info dbg ge2.env fterm in (ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true) | _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false) end in print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term); print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1); (* Check if the considered term is an assert, in which case we will only * display the precondition (otherwise we introduce too many assertions * in the context) *) let is_assert = Some? (term_is_assert_or_assume studied_term) in (* Instantiate the refinements *) (* TODO: use bv rather than term for ret_arg *) let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in let parents = List.Tot.map snd res.parents in let ge2, asserts = eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let is_assert info ret_arg opt_c parents [] in (* Simplify and filter *) let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in (* Introduce fresh variables for the shadowed ones and substitute *) let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in (* If not a let, insert all the assertions before the term *) let asserts = if is_let then asserts else mk_assertions (List.Tot.append asserts.pres asserts.posts) [] in (* Print *) printout_success ge3 asserts [@plugin] val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit let pp_analyze_effectful_term dbg with_gpre with_gpost () = try let res = find_focused_term_in_current_goal dbg in analyze_effectful_term dbg with_gpre with_gpost res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err (*** Split conjunctions *) /// Split an assert made of conjunctions so that there is one assert per /// conjunction. We try to be a bit smart. For instance, if the assertion is of /// the form: /// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An); /// We generate: /// [> assert(let Construct x1 ... xn = e in A1); /// [> ... /// [> assert(let Construct x1 ... xn = e in An); /// Remove ``b2t`` if it is the head of the term val remove_b2t : term -> Tac term let remove_b2t (t:term) : Tac term = match inspect t with | Tv_App hd (a, Q_Explicit) -> begin match inspect hd with | Tv_FVar fv -> if fv_eq_name fv b2t_qn then a else t | _ -> t end | _ -> t // TODO: gather all the functions like split_conjunctions, is_eq... /// Try to destruct a term of the form '_ && _' or '_ /\ _' val is_conjunction : term -> Tac (option (term & term)) let is_conjunction t = let t = remove_b2t t in let hd, params = collect_app t in match params with | [(x,Q_Explicit);(y,Q_Explicit)] -> begin match inspect hd with | Tv_FVar fv -> let fvn = inspect_fv fv in if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"] then Some (x, y) else None | _ -> None end | _ -> None val split_conjunctions : term -> Tac (list term) let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) = match is_conjunction t with | None -> t :: ls | Some (l, r) -> let ls1 = _split_conjunctions ls r in let ls2 = _split_conjunctions ls1 l in ls2 let split_conjunctions t = _split_conjunctions [] t /// Split a term of the form: /// [> let Constuct x1 ... xn = x in A1 /\ ... /\ Am /// into m terms: /// [> let Constuct x1 ... xn = x in A1 /// ... /// [> let Constuct x1 ... xn = x in Am val split_conjunctions_under_match : bool -> term -> Tac (list term) let split_conjunctions_under_match dbg t = let t1 = remove_b2t t in print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1); match inspect t1 with | Tv_Match scrut ret_opt [(pat, br)] -> let tl = split_conjunctions br in map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl | _ -> (* Not of the proper shape: return the original term *) [t] val split_assert_conjs : bool -> exploration_result term -> Tac unit let split_assert_conjs dbg res = let ge0 = res.ge in (* Simplify the term (it may be an abstraction applied to some parameters) *) let t = norm_term_env ge0.env simpl_norm_steps res.res in (* Split the conjunctions *) let conjs = split_conjunctions t in (* If there is only one conjunction, check if it is of the following form * and try to split: * [> let Construct x1 .. xn = x in A1 /\ ... /\ Am *) let conjs = if List.length conjs = 1 then split_conjunctions_under_match dbg t else conjs in let asserts = mk_assertions conjs [] in (* Print *) printout_success ge0 asserts [@plugin] val pp_split_assert_conjs : bool -> unit -> Tac unit let pp_split_assert_conjs dbg () = try let res = find_focused_assert_in_current_goal dbg in split_assert_conjs dbg res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err (*** Term unfolding in assert *) /// Unfold/rewrite a term in an assert. /// If the term is a (recursive) top-level identifier, unfold it. /// Otherwise look for an equality or a pure let-binding to replace it with. /// If the assert is an equality, unfold/rewrite only on the side chosen by the user. // TODO: use "kind" keyword rather than type above /// An equality kind noeq type eq_kind = | Eq_Dec : typ -> eq_kind (* = *) | Eq_Undec : typ -> eq_kind (* == *) | Eq_Hetero : typ -> typ -> eq_kind (* === *) /// Deconstruct an equality // We use our own construct because ``term_as_formula`` doesn't always work // TODO: update ``term_as_formula`` val is_eq : bool -> term -> Tac (option (eq_kind & term & term)) let is_eq dbg t = let t = remove_b2t t in print_dbg dbg ("[> is_eq: " ^ term_to_string t); let hd, params = collect_app t in print_dbg dbg ("- hd:\n" ^ term_to_string hd); print_dbg dbg ("- parameters:\n" ^ list_to_string (fun (x, y) -> term_to_string x) params); match inspect hd with | Tv_FVar fv -> begin match params with | [(a,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] -> if is_any_fvar a [`%Prims.op_Equality; `%Prims.equals; "Prims.op_Equals"] then Some ((Eq_Dec a), x, y) else if is_any_fvar a [`%Prims.eq2; "Prims.op_Equals_Equals"] then Some ((Eq_Undec a), x, y) else None | [(a,Q_Implicit);(b,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] -> if is_fvar a (`%Prims.op_Equals_Equals_Equals) then Some ((Eq_Hetero a b), x, y) else None | _ -> None end | _ -> None /// Reconstruct an equality val mk_eq : eq_kind -> term -> term -> Tot term let mk_eq k t1 t2 = match k with | Eq_Dec ty -> mk_app (`Prims.op_Equality) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)] | Eq_Undec ty -> mk_app (`Prims.eq2) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)] | Eq_Hetero ty1 ty2 -> mk_app Prims.(`( === )) [(ty1, Q_Implicit); (ty2, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)] let formula_construct (f : formula) : Tac string = match f with | True_ -> "True_" | False_ -> "False_" | Comp _ _ _ -> "Comp" | And _ _ -> "And" | Or _ _ -> "Or" | Not _ -> "Not" | Implies _ _ -> "Implies" | Iff _ _ -> "Iff" | Forall _ _ _ -> "Forall" | Exists _ _ _ -> "Exists" | App _ _ -> "Apply" | Name _ -> "Name" | FV _ -> "FV" | IntLit _ -> "IntLit" | F_Unknown -> "F_Unknown" /// Check if a proposition is an equality which can be used to rewrite a term. /// Return the operand of the equality which the term is equal to if it is the case. val is_equality_for_term : bool -> term -> term -> Tac (option term) let is_equality_for_term dbg tm p = print_dbg dbg ("[> is_equality_for_term:" ^ "\n- term: " ^ term_to_string tm ^ "\n- prop: " ^ term_to_string p); (* Specialize equality for bv - TODO: not sure if necessary, but I had problems * in the past *) let check_eq : term -> Tac bool = match inspect tm with | Tv_Var bv -> (fun tm' -> match inspect tm' with | Tv_Var bv' -> bv_eq bv bv' | _ -> false) | _ -> (fun tm' -> term_eq tm tm') in match is_eq dbg p with | Some (ekind, l, r) -> (* We ignore heterogeneous equality, because it risks to cause havoc at * typing after substitution *) print_dbg dbg ("Term is eq: " ^ term_to_string l ^ " = " ^ term_to_string r); if Eq_Hetero? ekind then begin print_dbg dbg "Ignoring heterogeneous equality"; None end else if check_eq l then Some r else if check_eq r then Some l else None | _ -> print_dbg dbg "Term is not eq"; None val find_subequality : bool -> term -> term -> Tac (option term) let find_subequality dbg tm p = print_dbg dbg ("[> find_subequality:" ^ "\n- ter : " ^ term_to_string tm ^ "\n- props: " ^ term_to_string p); let conjuncts = split_conjunctions p in print_dbg dbg ("Conjuncts:\n" ^ list_to_string term_to_string conjuncts); tryPick (is_equality_for_term dbg tm) conjuncts /// Look for an equality in a postcondition which can be used for rewriting. val find_equality_from_post : bool -> genv -> term -> bv -> typ -> term -> effect_info -> list term_view -> list term_view -> Tac (genv & option term) let find_equality_from_post dbg ge0 tm let_bv let_bvty ret_value einfo parents children = print_dbg dbg "[> find_equality_from_post"; let tinfo = get_type_info_from_type let_bvty in (* Compute the post-condition *) let ge1, _, post_prop = pre_post_to_propositions dbg ge0 einfo.ei_type ret_value (Some (mk_binder let_bv let_bvty)) tinfo einfo.ei_pre einfo.ei_post parents children in print_dbg dbg ("Computed post: " ^ option_to_string term_to_string post_prop); (* Look for an equality in the post *) let res = match post_prop with | None -> None | Some p -> find_subequality dbg tm p in (* If we found something, we return the updated environment, * otherwise we can return the original one *) match res with | None -> ge0, None | Some tm -> ge1, Some tm /// Given a list of parent terms (as generated by ``explore_term``), look for an /// equality given by a post-condition which can be used to replace a term. val find_context_equality : dbg:bool -> ge0:genv -> tm:term -> parents:list term_view -> children:list term_view -> Tac (genv & option term) /// Auxiliary function which actually performs the search let rec find_context_equality_aux dbg ge0 tm (opt_bv : option bv) (parents children : list term_view) : Tac (genv & option term) = match parents with | [] -> ge0, None | tv :: parents' -> print_dbg dbg ("[> find_context_equality:\n" ^ "- term : " ^ term_to_string tm ^ "\n" ^ "- parent: " ^ term_to_string tv); (* We only consider let-bindings *) match tv with | Tv_Let _ _ bv' ty def _ -> print_dbg dbg "Is Tv_Let"; let tm_info = compute_eterm_info dbg ge0.env def in let einfo = tm_info.einfo in (* If the searched term is a bv and the current let is the one which * introduces it: * - if the term is effectful, use it * - otherwise, try to use its postcondition. If we don't find any * equalities, some there *) let let_bv_is_tm = match opt_bv with | Some tm_bv -> bv_eq tm_bv bv' | None -> false in if let_bv_is_tm && effect_type_is_pure einfo.ei_type then ge0, Some def else let ret_value = pack (Tv_Var bv') in begin match find_equality_from_post dbg ge0 tm bv' ty ret_value einfo parents children with | ge1, Some p -> ge1, Some p | _, None -> find_context_equality_aux dbg ge0 tm opt_bv parents' (tv :: children) end | _ -> find_context_equality_aux dbg ge0 tm opt_bv parents' (tv :: children) let find_context_equality dbg ge0 tm parents children = let opt_bv = match inspect tm with | Tv_Var bv -> Some bv | _ -> None in find_context_equality_aux dbg ge0 tm opt_bv parents children /// Replace a subterm by another term val replace_term_in : bool -> term -> term -> term -> Tac term let rec replace_term_in dbg from_term to_term tm = if term_eq from_term tm then to_term else match inspect tm with | Tv_Var _ | Tv_BVar _ | Tv_FVar _ -> tm | Tv_App hd (a, qual) -> let a' = replace_term_in dbg from_term to_term a in let hd' = replace_term_in dbg from_term to_term hd in pack (Tv_App hd' (a', qual)) | Tv_Abs br body -> let body' = replace_term_in dbg from_term to_term body in pack (Tv_Abs br body') | Tv_Arrow br c0 -> tm (* TODO: we might want to explore that *) | Tv_Type _ -> tm | Tv_Refine bv sort ref -> let sort' = replace_term_in dbg from_term to_term sort in let ref' = replace_term_in dbg from_term to_term ref in pack (Tv_Refine bv sort' ref') | Tv_Const _ -> tm | Tv_Uvar _ _ -> tm | Tv_Let recf attrs bv ty def body -> (* GM 2023-04-27: leaving ty untouched, old code did not descend into sort. *) let def' = replace_term_in dbg from_term to_term def in let body' = replace_term_in dbg from_term to_term body in pack (Tv_Let recf attrs bv ty def' body') | Tv_Match scrutinee ret_opt branches -> //AR: TODO: account for the returns annotation (* Auxiliary function to explore the branches *) let explore_branch (br : branch) : Tac branch = (* Only explore the branch body *) let pat, body = br in let body' = replace_term_in dbg from_term to_term body in (pat, body') in let scrutinee' = replace_term_in dbg from_term to_term scrutinee in let branches' = map explore_branch branches in pack (Tv_Match scrutinee' ret_opt branches') | Tv_AscribedT e ty tac use_eq -> let e' = replace_term_in dbg from_term to_term e in let ty' = replace_term_in dbg from_term to_term ty in pack (Tv_AscribedT e' ty' tac use_eq) | Tv_AscribedC e c tac use_eq -> let e' = replace_term_in dbg from_term to_term e in pack (Tv_AscribedC e' c tac use_eq) | _ -> (* Unknown *) tm
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
tm: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac FStar.Stubs.Reflection.Types.term
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V1.Data.aqualv", "FStar.Stubs.Reflection.V1.Data.uu___is_Q_Implicit", "FStar.InteractiveHelpers.PostProcess.strip_implicit_parameters", "Prims.bool", "FStar.Stubs.Reflection.V1.Data.term_view", "FStar.Stubs.Tactics.V1.Builtins.inspect" ]
[ "recursion" ]
false
true
false
false
false
let rec strip_implicit_parameters tm =
match inspect tm with | Tv_App hd (a, qualif) -> if Q_Implicit? qualif then strip_implicit_parameters hd else tm | _ -> tm
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.pp_unfold_in_assert_or_assume
val pp_unfold_in_assert_or_assume : bool -> unit -> Tac unit
val pp_unfold_in_assert_or_assume : bool -> unit -> Tac unit
let pp_unfold_in_assert_or_assume dbg () = try let res = find_focused_assert_in_current_goal dbg in unfold_in_assert_or_assume dbg res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 89, "end_line": 745, "start_col": 0, "start_line": 739 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging. val pp_explore_print_goal : unit -> Tac unit let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f () /// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which /// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*) val is_focus_on_term : term -> Tac bool let is_focus_on_term t = is_fvar t (`%focus_on_term) /// Check if a term is an assertion or an assumption and return its content /// if it is the case. val term_is_assert_or_assume : term -> Tac (option term) let term_is_assert_or_assume t = match inspect t with | Tv_App hd (a, Q_Explicit) -> if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume] then Some a else None | _ -> None /// Check if the given term view is of the form: 'let _ = focus_on_term in body' /// Returns 'body' if it is the case. val is_focused_term : term_view -> Tac (option term) let is_focused_term tv = match tv with | Tv_Let recf attrs _ _ def body -> if is_focus_on_term def then Some body else None | _ -> None noeq type exploration_result (a : Type)= { ge : genv; parents : list (genv & term_view); tgt_comp : option typ_or_comp; res : a; } let mk_exploration_result = Mkexploration_result let pred_explorer (a:Type) = genv -> list (genv & term_view) -> option typ_or_comp -> term_view -> Tac (option a) val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool -> explorer (option (exploration_result a)) let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t = if Some? acc then mfail "find_focused_term_explorer: non empty accumulator"; if dbg then begin print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t) end; match pred ge pl opt_c t with | Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort | None -> None, Continue val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result a)) let find_predicated_term #a pred dbg dfs ge pl opt_c t = fst (explore_term dbg dfs #(option (exploration_result a)) (find_predicated_term_explorer #a pred dbg) None ge pl opt_c t) val _is_focused_term_explorer : pred_explorer term let _is_focused_term_explorer ge pl opt_c tv = is_focused_term tv val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result term)) let find_focused_term dbg dfs ge pl opt_c t = find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_term_in_current_goal : bool -> Tac (exploration_result term) let find_focused_term_in_current_goal dbg = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); begin match find_focused_term dbg true ge [] c l with | Some res -> print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); res | None -> mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: " ^ term_to_string g) end | _ -> mfail "find_focused_term_in_current_goal: not a squashed equality" end /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term) let find_focused_assert_in_current_goal dbg = print_dbg dbg ("[> find_focused_assert_in_current_goal"); let res = find_focused_term_in_current_goal dbg in print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); (* Check that it is an assert or an assume, retrieve the assertion *) let res' = match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> let ge' = genv_push_bv res.ge bv0 ty false None in ({ res with res = fterm; ge = ge' }) | _ -> res in begin match term_is_assert_or_assume res'.res with | None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res) | Some tm -> { res' with res = tm } end (*** Analyze effectful term *) /// Analyze a term in order to print properly instantiated pre/postconditions /// and type conditions. /// with_globals states whether to analyze the target pre/post together with the /// focused term. val analyze_effectful_term : dbg:bool -> with_gpre:bool -> with_gpost:bool -> res:exploration_result term -> Tac unit let analyze_effectful_term dbg with_gpre with_gpost res = let ge = res.ge in let opt_c = res.tgt_comp in (* Analyze the effectful term and check whether it is a 'let' or not *) let ge1, studied_term, info, ret_bv, shadowed_bv, is_let = begin match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> (* Before pushing the binder, check if it shadows another variable. * If it is the case, we will need it to correctly output the pre * and post-assertions (because for the pre-assertions the variable * will not be shadowed yet, while it will be the case for the post- * assertions) *) print_dbg dbg ("Restraining to: " ^ term_to_string fterm); let shadowed_bv : option bv = match genv_get_from_name ge (name_of_bv bv0) with | None -> None | Some (sbv, _) -> Some (fst sbv) in let ge1 = genv_push_bv ge bv0 ty false None in (* If the bv name is "uu___", introduce a fresh variable and use it instead: * the underscore might have been introduced when desugaring a let using * tuples. If doing that is not necessary, the introduced variable will * not appear in the generated assertions anyway. *) let ge2, (bv1 : bv) = let bvv0 = inspect_bv bv0 in let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *) then genv_push_fresh_bv ge1 "ret" ty else ge1, bv0 in let info = compute_eterm_info dbg ge2.env fterm in (ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true) | _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false) end in print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term); print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1); (* Check if the considered term is an assert, in which case we will only * display the precondition (otherwise we introduce too many assertions * in the context) *) let is_assert = Some? (term_is_assert_or_assume studied_term) in (* Instantiate the refinements *) (* TODO: use bv rather than term for ret_arg *) let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in let parents = List.Tot.map snd res.parents in let ge2, asserts = eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let is_assert info ret_arg opt_c parents [] in (* Simplify and filter *) let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in (* Introduce fresh variables for the shadowed ones and substitute *) let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in (* If not a let, insert all the assertions before the term *) let asserts = if is_let then asserts else mk_assertions (List.Tot.append asserts.pres asserts.posts) [] in (* Print *) printout_success ge3 asserts [@plugin] val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit let pp_analyze_effectful_term dbg with_gpre with_gpost () = try let res = find_focused_term_in_current_goal dbg in analyze_effectful_term dbg with_gpre with_gpost res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err (*** Split conjunctions *) /// Split an assert made of conjunctions so that there is one assert per /// conjunction. We try to be a bit smart. For instance, if the assertion is of /// the form: /// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An); /// We generate: /// [> assert(let Construct x1 ... xn = e in A1); /// [> ... /// [> assert(let Construct x1 ... xn = e in An); /// Remove ``b2t`` if it is the head of the term val remove_b2t : term -> Tac term let remove_b2t (t:term) : Tac term = match inspect t with | Tv_App hd (a, Q_Explicit) -> begin match inspect hd with | Tv_FVar fv -> if fv_eq_name fv b2t_qn then a else t | _ -> t end | _ -> t // TODO: gather all the functions like split_conjunctions, is_eq... /// Try to destruct a term of the form '_ && _' or '_ /\ _' val is_conjunction : term -> Tac (option (term & term)) let is_conjunction t = let t = remove_b2t t in let hd, params = collect_app t in match params with | [(x,Q_Explicit);(y,Q_Explicit)] -> begin match inspect hd with | Tv_FVar fv -> let fvn = inspect_fv fv in if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"] then Some (x, y) else None | _ -> None end | _ -> None val split_conjunctions : term -> Tac (list term) let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) = match is_conjunction t with | None -> t :: ls | Some (l, r) -> let ls1 = _split_conjunctions ls r in let ls2 = _split_conjunctions ls1 l in ls2 let split_conjunctions t = _split_conjunctions [] t /// Split a term of the form: /// [> let Constuct x1 ... xn = x in A1 /\ ... /\ Am /// into m terms: /// [> let Constuct x1 ... xn = x in A1 /// ... /// [> let Constuct x1 ... xn = x in Am val split_conjunctions_under_match : bool -> term -> Tac (list term) let split_conjunctions_under_match dbg t = let t1 = remove_b2t t in print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1); match inspect t1 with | Tv_Match scrut ret_opt [(pat, br)] -> let tl = split_conjunctions br in map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl | _ -> (* Not of the proper shape: return the original term *) [t] val split_assert_conjs : bool -> exploration_result term -> Tac unit let split_assert_conjs dbg res = let ge0 = res.ge in (* Simplify the term (it may be an abstraction applied to some parameters) *) let t = norm_term_env ge0.env simpl_norm_steps res.res in (* Split the conjunctions *) let conjs = split_conjunctions t in (* If there is only one conjunction, check if it is of the following form * and try to split: * [> let Construct x1 .. xn = x in A1 /\ ... /\ Am *) let conjs = if List.length conjs = 1 then split_conjunctions_under_match dbg t else conjs in let asserts = mk_assertions conjs [] in (* Print *) printout_success ge0 asserts [@plugin] val pp_split_assert_conjs : bool -> unit -> Tac unit let pp_split_assert_conjs dbg () = try let res = find_focused_assert_in_current_goal dbg in split_assert_conjs dbg res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err (*** Term unfolding in assert *) /// Unfold/rewrite a term in an assert. /// If the term is a (recursive) top-level identifier, unfold it. /// Otherwise look for an equality or a pure let-binding to replace it with. /// If the assert is an equality, unfold/rewrite only on the side chosen by the user. // TODO: use "kind" keyword rather than type above /// An equality kind noeq type eq_kind = | Eq_Dec : typ -> eq_kind (* = *) | Eq_Undec : typ -> eq_kind (* == *) | Eq_Hetero : typ -> typ -> eq_kind (* === *) /// Deconstruct an equality // We use our own construct because ``term_as_formula`` doesn't always work // TODO: update ``term_as_formula`` val is_eq : bool -> term -> Tac (option (eq_kind & term & term)) let is_eq dbg t = let t = remove_b2t t in print_dbg dbg ("[> is_eq: " ^ term_to_string t); let hd, params = collect_app t in print_dbg dbg ("- hd:\n" ^ term_to_string hd); print_dbg dbg ("- parameters:\n" ^ list_to_string (fun (x, y) -> term_to_string x) params); match inspect hd with | Tv_FVar fv -> begin match params with | [(a,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] -> if is_any_fvar a [`%Prims.op_Equality; `%Prims.equals; "Prims.op_Equals"] then Some ((Eq_Dec a), x, y) else if is_any_fvar a [`%Prims.eq2; "Prims.op_Equals_Equals"] then Some ((Eq_Undec a), x, y) else None | [(a,Q_Implicit);(b,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] -> if is_fvar a (`%Prims.op_Equals_Equals_Equals) then Some ((Eq_Hetero a b), x, y) else None | _ -> None end | _ -> None /// Reconstruct an equality val mk_eq : eq_kind -> term -> term -> Tot term let mk_eq k t1 t2 = match k with | Eq_Dec ty -> mk_app (`Prims.op_Equality) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)] | Eq_Undec ty -> mk_app (`Prims.eq2) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)] | Eq_Hetero ty1 ty2 -> mk_app Prims.(`( === )) [(ty1, Q_Implicit); (ty2, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)] let formula_construct (f : formula) : Tac string = match f with | True_ -> "True_" | False_ -> "False_" | Comp _ _ _ -> "Comp" | And _ _ -> "And" | Or _ _ -> "Or" | Not _ -> "Not" | Implies _ _ -> "Implies" | Iff _ _ -> "Iff" | Forall _ _ _ -> "Forall" | Exists _ _ _ -> "Exists" | App _ _ -> "Apply" | Name _ -> "Name" | FV _ -> "FV" | IntLit _ -> "IntLit" | F_Unknown -> "F_Unknown" /// Check if a proposition is an equality which can be used to rewrite a term. /// Return the operand of the equality which the term is equal to if it is the case. val is_equality_for_term : bool -> term -> term -> Tac (option term) let is_equality_for_term dbg tm p = print_dbg dbg ("[> is_equality_for_term:" ^ "\n- term: " ^ term_to_string tm ^ "\n- prop: " ^ term_to_string p); (* Specialize equality for bv - TODO: not sure if necessary, but I had problems * in the past *) let check_eq : term -> Tac bool = match inspect tm with | Tv_Var bv -> (fun tm' -> match inspect tm' with | Tv_Var bv' -> bv_eq bv bv' | _ -> false) | _ -> (fun tm' -> term_eq tm tm') in match is_eq dbg p with | Some (ekind, l, r) -> (* We ignore heterogeneous equality, because it risks to cause havoc at * typing after substitution *) print_dbg dbg ("Term is eq: " ^ term_to_string l ^ " = " ^ term_to_string r); if Eq_Hetero? ekind then begin print_dbg dbg "Ignoring heterogeneous equality"; None end else if check_eq l then Some r else if check_eq r then Some l else None | _ -> print_dbg dbg "Term is not eq"; None val find_subequality : bool -> term -> term -> Tac (option term) let find_subequality dbg tm p = print_dbg dbg ("[> find_subequality:" ^ "\n- ter : " ^ term_to_string tm ^ "\n- props: " ^ term_to_string p); let conjuncts = split_conjunctions p in print_dbg dbg ("Conjuncts:\n" ^ list_to_string term_to_string conjuncts); tryPick (is_equality_for_term dbg tm) conjuncts /// Look for an equality in a postcondition which can be used for rewriting. val find_equality_from_post : bool -> genv -> term -> bv -> typ -> term -> effect_info -> list term_view -> list term_view -> Tac (genv & option term) let find_equality_from_post dbg ge0 tm let_bv let_bvty ret_value einfo parents children = print_dbg dbg "[> find_equality_from_post"; let tinfo = get_type_info_from_type let_bvty in (* Compute the post-condition *) let ge1, _, post_prop = pre_post_to_propositions dbg ge0 einfo.ei_type ret_value (Some (mk_binder let_bv let_bvty)) tinfo einfo.ei_pre einfo.ei_post parents children in print_dbg dbg ("Computed post: " ^ option_to_string term_to_string post_prop); (* Look for an equality in the post *) let res = match post_prop with | None -> None | Some p -> find_subequality dbg tm p in (* If we found something, we return the updated environment, * otherwise we can return the original one *) match res with | None -> ge0, None | Some tm -> ge1, Some tm /// Given a list of parent terms (as generated by ``explore_term``), look for an /// equality given by a post-condition which can be used to replace a term. val find_context_equality : dbg:bool -> ge0:genv -> tm:term -> parents:list term_view -> children:list term_view -> Tac (genv & option term) /// Auxiliary function which actually performs the search let rec find_context_equality_aux dbg ge0 tm (opt_bv : option bv) (parents children : list term_view) : Tac (genv & option term) = match parents with | [] -> ge0, None | tv :: parents' -> print_dbg dbg ("[> find_context_equality:\n" ^ "- term : " ^ term_to_string tm ^ "\n" ^ "- parent: " ^ term_to_string tv); (* We only consider let-bindings *) match tv with | Tv_Let _ _ bv' ty def _ -> print_dbg dbg "Is Tv_Let"; let tm_info = compute_eterm_info dbg ge0.env def in let einfo = tm_info.einfo in (* If the searched term is a bv and the current let is the one which * introduces it: * - if the term is effectful, use it * - otherwise, try to use its postcondition. If we don't find any * equalities, some there *) let let_bv_is_tm = match opt_bv with | Some tm_bv -> bv_eq tm_bv bv' | None -> false in if let_bv_is_tm && effect_type_is_pure einfo.ei_type then ge0, Some def else let ret_value = pack (Tv_Var bv') in begin match find_equality_from_post dbg ge0 tm bv' ty ret_value einfo parents children with | ge1, Some p -> ge1, Some p | _, None -> find_context_equality_aux dbg ge0 tm opt_bv parents' (tv :: children) end | _ -> find_context_equality_aux dbg ge0 tm opt_bv parents' (tv :: children) let find_context_equality dbg ge0 tm parents children = let opt_bv = match inspect tm with | Tv_Var bv -> Some bv | _ -> None in find_context_equality_aux dbg ge0 tm opt_bv parents children /// Replace a subterm by another term val replace_term_in : bool -> term -> term -> term -> Tac term let rec replace_term_in dbg from_term to_term tm = if term_eq from_term tm then to_term else match inspect tm with | Tv_Var _ | Tv_BVar _ | Tv_FVar _ -> tm | Tv_App hd (a, qual) -> let a' = replace_term_in dbg from_term to_term a in let hd' = replace_term_in dbg from_term to_term hd in pack (Tv_App hd' (a', qual)) | Tv_Abs br body -> let body' = replace_term_in dbg from_term to_term body in pack (Tv_Abs br body') | Tv_Arrow br c0 -> tm (* TODO: we might want to explore that *) | Tv_Type _ -> tm | Tv_Refine bv sort ref -> let sort' = replace_term_in dbg from_term to_term sort in let ref' = replace_term_in dbg from_term to_term ref in pack (Tv_Refine bv sort' ref') | Tv_Const _ -> tm | Tv_Uvar _ _ -> tm | Tv_Let recf attrs bv ty def body -> (* GM 2023-04-27: leaving ty untouched, old code did not descend into sort. *) let def' = replace_term_in dbg from_term to_term def in let body' = replace_term_in dbg from_term to_term body in pack (Tv_Let recf attrs bv ty def' body') | Tv_Match scrutinee ret_opt branches -> //AR: TODO: account for the returns annotation (* Auxiliary function to explore the branches *) let explore_branch (br : branch) : Tac branch = (* Only explore the branch body *) let pat, body = br in let body' = replace_term_in dbg from_term to_term body in (pat, body') in let scrutinee' = replace_term_in dbg from_term to_term scrutinee in let branches' = map explore_branch branches in pack (Tv_Match scrutinee' ret_opt branches') | Tv_AscribedT e ty tac use_eq -> let e' = replace_term_in dbg from_term to_term e in let ty' = replace_term_in dbg from_term to_term ty in pack (Tv_AscribedT e' ty' tac use_eq) | Tv_AscribedC e c tac use_eq -> let e' = replace_term_in dbg from_term to_term e in pack (Tv_AscribedC e' c tac use_eq) | _ -> (* Unknown *) tm val strip_implicit_parameters : term -> Tac term let rec strip_implicit_parameters tm = match inspect tm with | Tv_App hd (a,qualif) -> if Q_Implicit? qualif then strip_implicit_parameters hd else tm | _ -> tm val unfold_in_assert_or_assume : bool -> exploration_result term -> Tac unit let unfold_in_assert_or_assume dbg ares = print_dbg dbg ("[> unfold_in_assert_or_assume:\n" ^ term_to_string ares.res); (* Find the focused term inside the assert, and on which side of the * equality if the assert is an equality *) let find_focused_in_term t = find_focused_term dbg false ares.ge ares.parents ares.tgt_comp t in let find_in_whole_term () : Tac _ = match find_focused_in_term ares.res with | Some res -> ares.res, res, (fun x -> x <: Tac term), true | None -> mfail "unfold_in_assert_or_assume: could not find a focused term in the assert" in (* - subterm: the subterm of the assertion in which we found the focused term * (if an equality, left or right operand, otherwise whole assertion) * - unf_res: the result of the exploration for the focused term inside the * assertion, which gives the term to unfold * - rebuild: a Tot function which, given a term, rebuilds the equality by * replacing the above subterm with the given term * - insert_before: whether to insert the new assertion before or after the * current assertion in the user file *) let subterm, unf_res, (rebuild : term -> Tac term), insert_before = let _ = print_dbg dbg ("Assertion: " ^ term_to_string ares.res) in match is_eq dbg ares.res with | Some (kd, l, r) -> print_dbg dbg "The assertion is an equality"; begin match find_focused_in_term l with | Some res -> print_dbg dbg ("Found focused term in left operand:" ^ "\n- left : " ^ term_to_string l ^ "\n- right : " ^ term_to_string r ^ "\n- focused: " ^ term_to_string res.res); let rebuild t : Tac term = mk_eq kd t r in l, res, rebuild, true | None -> begin match find_focused_in_term r with | Some res -> print_dbg dbg ("Found focused term in right operand:" ^ "\n- left : " ^ term_to_string l ^ "\n- right : " ^ term_to_string r ^ "\n- focused: " ^ term_to_string res.res); let rebuild (t : term) : Tac term = mk_eq kd l t in r, res, rebuild, false | None -> mfail "unfold_in_assert_or_assume: could not find a focused term in the assert" end end | None -> print_dbg dbg "The assertion is not an equality"; find_in_whole_term () in print_dbg dbg ("Found subterm in assertion/assumption:\n" ^ "- subterm: " ^ term_to_string subterm ^ "\n" ^ "- focused term: " ^ term_to_string unf_res.res); (* Unfold the term *) let res_view = inspect unf_res.res in let ge1, opt_unf_tm = match res_view with | Tv_FVar fv -> print_dbg dbg ("The focused term is a top identifier: " ^ fv_to_string fv); (* The easy case: just use the normalizer *) let fname = flatten_name (inspect_fv fv) in let subterm' = norm_term_env ares.ge.env [delta_only [fname]; zeta] subterm in print_dbg dbg ("Normalized subterm: " ^ term_to_string subterm'); ares.ge, Some subterm' | _ -> (* Look for an equality given by a previous post-condition. In the case * the term is a bv, we can also use the let-binding which introduces it, * if it is pure. *) let parents = List.Tot.map snd ares.parents in let opt_bvty : option (bv & typ) = match res_view with | Tv_Var bv -> print_dbg dbg ("The focused term is a local variable: " ^ bv_to_string bv); (* Check that the binder was not introduced by an abstraction inside the assertion *) if not (Some? (genv_get ares.ge bv)) then mfail "unfold_in_assert_or_assume: can't unfold a variable locally introduced in an assertion"; Some (bv, pack_ln Tv_Unknown) // FIXME | _ -> print_dbg dbg ("The focused term is an arbitrary term: " ^ term_to_string unf_res.res); None in let ge1, eq_tm = find_context_equality dbg ares.ge unf_res.res parents [] in (* Check if we found an equality *) let opt_eq_tm = match eq_tm with | Some eq_tm -> Some eq_tm | _ -> None in (* Apply it *) let subterm' = match opt_bvty, opt_eq_tm with | Some bvty, Some eq_tm -> Some (apply_subst ge1.env subterm [(bvty, eq_tm)]) | None, Some eq_tm -> Some (replace_term_in dbg unf_res.res eq_tm subterm) | _ -> None in ge1, subterm' in (* If we couldn't unfold the term, check if it is a top-level identifier with * implicit parameters (it may happen that the user calls the command on a * top-level identifier which has implicit parameters without providing * those parameters, in which case the focused term is the identifier applied * to those implicits inferred by F*, and thus an app and not an fvar). * Note that so far we have no way to check if the implicit parameters have * been explicitly provided by the user or not, which is why we can't do better * than greedy tests.*) let ge2, unf_tm = match opt_unf_tm with | Some unf_tm -> ge1, unf_tm | None -> begin match inspect (strip_implicit_parameters unf_res.res) with | Tv_FVar fv -> print_dbg dbg ("The focused term is a top identifier with implicit parameters: " ^ fv_to_string fv); (* The easy case: just use the normalizer *) let fname = flatten_name (inspect_fv fv) in let subterm' = norm_term_env ge1.env [delta_only [fname]; zeta] subterm in print_dbg dbg ("Normalized subterm: " ^ term_to_string subterm'); ge1, subterm' | _ -> mfail ("unfold_in_assert_or_assume: " ^ "couldn't find equalities with which to rewrite: " ^ term_to_string unf_res.res) end in (* Create the assertions to output *) let final_assert = rebuild unf_tm in let final_assert = prettify_term dbg final_assert in print_dbg dbg ("-> Final assertion:\n" ^ term_to_string final_assert); let asserts = if insert_before then mk_assertions [final_assert] [] else mk_assertions [] [final_assert] in (* Introduce fresh variables for the shadowed ones and substitute *) let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 None asserts in (* Output *) printout_success ge3 asserts [@plugin]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
dbg: Prims.bool -> _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.bool", "Prims.unit", "FStar.Tactics.V1.Derived.try_with", "FStar.InteractiveHelpers.PostProcess.end_proof", "FStar.InteractiveHelpers.PostProcess.unfold_in_assert_or_assume", "FStar.InteractiveHelpers.PostProcess.exploration_result", "FStar.Stubs.Reflection.Types.term", "FStar.InteractiveHelpers.PostProcess.find_focused_assert_in_current_goal", "Prims.exn", "Prims.string", "FStar.InteractiveHelpers.Output.printout_failure", "FStar.Tactics.Effect.raise" ]
[]
false
true
false
false
false
let pp_unfold_in_assert_or_assume dbg () =
try let res = find_focused_assert_in_current_goal dbg in unfold_in_assert_or_assume dbg res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> raise err
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.is_equality_for_term
val is_equality_for_term : bool -> term -> term -> Tac (option term)
val is_equality_for_term : bool -> term -> term -> Tac (option term)
let is_equality_for_term dbg tm p = print_dbg dbg ("[> is_equality_for_term:" ^ "\n- term: " ^ term_to_string tm ^ "\n- prop: " ^ term_to_string p); (* Specialize equality for bv - TODO: not sure if necessary, but I had problems * in the past *) let check_eq : term -> Tac bool = match inspect tm with | Tv_Var bv -> (fun tm' -> match inspect tm' with | Tv_Var bv' -> bv_eq bv bv' | _ -> false) | _ -> (fun tm' -> term_eq tm tm') in match is_eq dbg p with | Some (ekind, l, r) -> (* We ignore heterogeneous equality, because it risks to cause havoc at * typing after substitution *) print_dbg dbg ("Term is eq: " ^ term_to_string l ^ " = " ^ term_to_string r); if Eq_Hetero? ekind then begin print_dbg dbg "Ignoring heterogeneous equality"; None end else if check_eq l then Some r else if check_eq r then Some l else None | _ -> print_dbg dbg "Term is not eq"; None
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 8, "end_line": 453, "start_col": 0, "start_line": 426 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging. val pp_explore_print_goal : unit -> Tac unit let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f () /// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which /// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*) val is_focus_on_term : term -> Tac bool let is_focus_on_term t = is_fvar t (`%focus_on_term) /// Check if a term is an assertion or an assumption and return its content /// if it is the case. val term_is_assert_or_assume : term -> Tac (option term) let term_is_assert_or_assume t = match inspect t with | Tv_App hd (a, Q_Explicit) -> if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume] then Some a else None | _ -> None /// Check if the given term view is of the form: 'let _ = focus_on_term in body' /// Returns 'body' if it is the case. val is_focused_term : term_view -> Tac (option term) let is_focused_term tv = match tv with | Tv_Let recf attrs _ _ def body -> if is_focus_on_term def then Some body else None | _ -> None noeq type exploration_result (a : Type)= { ge : genv; parents : list (genv & term_view); tgt_comp : option typ_or_comp; res : a; } let mk_exploration_result = Mkexploration_result let pred_explorer (a:Type) = genv -> list (genv & term_view) -> option typ_or_comp -> term_view -> Tac (option a) val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool -> explorer (option (exploration_result a)) let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t = if Some? acc then mfail "find_focused_term_explorer: non empty accumulator"; if dbg then begin print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t) end; match pred ge pl opt_c t with | Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort | None -> None, Continue val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result a)) let find_predicated_term #a pred dbg dfs ge pl opt_c t = fst (explore_term dbg dfs #(option (exploration_result a)) (find_predicated_term_explorer #a pred dbg) None ge pl opt_c t) val _is_focused_term_explorer : pred_explorer term let _is_focused_term_explorer ge pl opt_c tv = is_focused_term tv val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result term)) let find_focused_term dbg dfs ge pl opt_c t = find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_term_in_current_goal : bool -> Tac (exploration_result term) let find_focused_term_in_current_goal dbg = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); begin match find_focused_term dbg true ge [] c l with | Some res -> print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); res | None -> mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: " ^ term_to_string g) end | _ -> mfail "find_focused_term_in_current_goal: not a squashed equality" end /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term) let find_focused_assert_in_current_goal dbg = print_dbg dbg ("[> find_focused_assert_in_current_goal"); let res = find_focused_term_in_current_goal dbg in print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); (* Check that it is an assert or an assume, retrieve the assertion *) let res' = match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> let ge' = genv_push_bv res.ge bv0 ty false None in ({ res with res = fterm; ge = ge' }) | _ -> res in begin match term_is_assert_or_assume res'.res with | None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res) | Some tm -> { res' with res = tm } end (*** Analyze effectful term *) /// Analyze a term in order to print properly instantiated pre/postconditions /// and type conditions. /// with_globals states whether to analyze the target pre/post together with the /// focused term. val analyze_effectful_term : dbg:bool -> with_gpre:bool -> with_gpost:bool -> res:exploration_result term -> Tac unit let analyze_effectful_term dbg with_gpre with_gpost res = let ge = res.ge in let opt_c = res.tgt_comp in (* Analyze the effectful term and check whether it is a 'let' or not *) let ge1, studied_term, info, ret_bv, shadowed_bv, is_let = begin match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> (* Before pushing the binder, check if it shadows another variable. * If it is the case, we will need it to correctly output the pre * and post-assertions (because for the pre-assertions the variable * will not be shadowed yet, while it will be the case for the post- * assertions) *) print_dbg dbg ("Restraining to: " ^ term_to_string fterm); let shadowed_bv : option bv = match genv_get_from_name ge (name_of_bv bv0) with | None -> None | Some (sbv, _) -> Some (fst sbv) in let ge1 = genv_push_bv ge bv0 ty false None in (* If the bv name is "uu___", introduce a fresh variable and use it instead: * the underscore might have been introduced when desugaring a let using * tuples. If doing that is not necessary, the introduced variable will * not appear in the generated assertions anyway. *) let ge2, (bv1 : bv) = let bvv0 = inspect_bv bv0 in let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *) then genv_push_fresh_bv ge1 "ret" ty else ge1, bv0 in let info = compute_eterm_info dbg ge2.env fterm in (ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true) | _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false) end in print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term); print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1); (* Check if the considered term is an assert, in which case we will only * display the precondition (otherwise we introduce too many assertions * in the context) *) let is_assert = Some? (term_is_assert_or_assume studied_term) in (* Instantiate the refinements *) (* TODO: use bv rather than term for ret_arg *) let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in let parents = List.Tot.map snd res.parents in let ge2, asserts = eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let is_assert info ret_arg opt_c parents [] in (* Simplify and filter *) let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in (* Introduce fresh variables for the shadowed ones and substitute *) let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in (* If not a let, insert all the assertions before the term *) let asserts = if is_let then asserts else mk_assertions (List.Tot.append asserts.pres asserts.posts) [] in (* Print *) printout_success ge3 asserts [@plugin] val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit let pp_analyze_effectful_term dbg with_gpre with_gpost () = try let res = find_focused_term_in_current_goal dbg in analyze_effectful_term dbg with_gpre with_gpost res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err (*** Split conjunctions *) /// Split an assert made of conjunctions so that there is one assert per /// conjunction. We try to be a bit smart. For instance, if the assertion is of /// the form: /// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An); /// We generate: /// [> assert(let Construct x1 ... xn = e in A1); /// [> ... /// [> assert(let Construct x1 ... xn = e in An); /// Remove ``b2t`` if it is the head of the term val remove_b2t : term -> Tac term let remove_b2t (t:term) : Tac term = match inspect t with | Tv_App hd (a, Q_Explicit) -> begin match inspect hd with | Tv_FVar fv -> if fv_eq_name fv b2t_qn then a else t | _ -> t end | _ -> t // TODO: gather all the functions like split_conjunctions, is_eq... /// Try to destruct a term of the form '_ && _' or '_ /\ _' val is_conjunction : term -> Tac (option (term & term)) let is_conjunction t = let t = remove_b2t t in let hd, params = collect_app t in match params with | [(x,Q_Explicit);(y,Q_Explicit)] -> begin match inspect hd with | Tv_FVar fv -> let fvn = inspect_fv fv in if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"] then Some (x, y) else None | _ -> None end | _ -> None val split_conjunctions : term -> Tac (list term) let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) = match is_conjunction t with | None -> t :: ls | Some (l, r) -> let ls1 = _split_conjunctions ls r in let ls2 = _split_conjunctions ls1 l in ls2 let split_conjunctions t = _split_conjunctions [] t /// Split a term of the form: /// [> let Constuct x1 ... xn = x in A1 /\ ... /\ Am /// into m terms: /// [> let Constuct x1 ... xn = x in A1 /// ... /// [> let Constuct x1 ... xn = x in Am val split_conjunctions_under_match : bool -> term -> Tac (list term) let split_conjunctions_under_match dbg t = let t1 = remove_b2t t in print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1); match inspect t1 with | Tv_Match scrut ret_opt [(pat, br)] -> let tl = split_conjunctions br in map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl | _ -> (* Not of the proper shape: return the original term *) [t] val split_assert_conjs : bool -> exploration_result term -> Tac unit let split_assert_conjs dbg res = let ge0 = res.ge in (* Simplify the term (it may be an abstraction applied to some parameters) *) let t = norm_term_env ge0.env simpl_norm_steps res.res in (* Split the conjunctions *) let conjs = split_conjunctions t in (* If there is only one conjunction, check if it is of the following form * and try to split: * [> let Construct x1 .. xn = x in A1 /\ ... /\ Am *) let conjs = if List.length conjs = 1 then split_conjunctions_under_match dbg t else conjs in let asserts = mk_assertions conjs [] in (* Print *) printout_success ge0 asserts [@plugin] val pp_split_assert_conjs : bool -> unit -> Tac unit let pp_split_assert_conjs dbg () = try let res = find_focused_assert_in_current_goal dbg in split_assert_conjs dbg res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err (*** Term unfolding in assert *) /// Unfold/rewrite a term in an assert. /// If the term is a (recursive) top-level identifier, unfold it. /// Otherwise look for an equality or a pure let-binding to replace it with. /// If the assert is an equality, unfold/rewrite only on the side chosen by the user. // TODO: use "kind" keyword rather than type above /// An equality kind noeq type eq_kind = | Eq_Dec : typ -> eq_kind (* = *) | Eq_Undec : typ -> eq_kind (* == *) | Eq_Hetero : typ -> typ -> eq_kind (* === *) /// Deconstruct an equality // We use our own construct because ``term_as_formula`` doesn't always work // TODO: update ``term_as_formula`` val is_eq : bool -> term -> Tac (option (eq_kind & term & term)) let is_eq dbg t = let t = remove_b2t t in print_dbg dbg ("[> is_eq: " ^ term_to_string t); let hd, params = collect_app t in print_dbg dbg ("- hd:\n" ^ term_to_string hd); print_dbg dbg ("- parameters:\n" ^ list_to_string (fun (x, y) -> term_to_string x) params); match inspect hd with | Tv_FVar fv -> begin match params with | [(a,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] -> if is_any_fvar a [`%Prims.op_Equality; `%Prims.equals; "Prims.op_Equals"] then Some ((Eq_Dec a), x, y) else if is_any_fvar a [`%Prims.eq2; "Prims.op_Equals_Equals"] then Some ((Eq_Undec a), x, y) else None | [(a,Q_Implicit);(b,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] -> if is_fvar a (`%Prims.op_Equals_Equals_Equals) then Some ((Eq_Hetero a b), x, y) else None | _ -> None end | _ -> None /// Reconstruct an equality val mk_eq : eq_kind -> term -> term -> Tot term let mk_eq k t1 t2 = match k with | Eq_Dec ty -> mk_app (`Prims.op_Equality) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)] | Eq_Undec ty -> mk_app (`Prims.eq2) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)] | Eq_Hetero ty1 ty2 -> mk_app Prims.(`( === )) [(ty1, Q_Implicit); (ty2, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)] let formula_construct (f : formula) : Tac string = match f with | True_ -> "True_" | False_ -> "False_" | Comp _ _ _ -> "Comp" | And _ _ -> "And" | Or _ _ -> "Or" | Not _ -> "Not" | Implies _ _ -> "Implies" | Iff _ _ -> "Iff" | Forall _ _ _ -> "Forall" | Exists _ _ _ -> "Exists" | App _ _ -> "Apply" | Name _ -> "Name" | FV _ -> "FV" | IntLit _ -> "IntLit" | F_Unknown -> "F_Unknown" /// Check if a proposition is an equality which can be used to rewrite a term. /// Return the operand of the equality which the term is equal to if it is the case.
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
dbg: Prims.bool -> tm: FStar.Stubs.Reflection.Types.term -> p: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac (FStar.Pervasives.Native.option FStar.Stubs.Reflection.Types.term)
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.bool", "FStar.Stubs.Reflection.Types.term", "FStar.InteractiveHelpers.PostProcess.eq_kind", "FStar.InteractiveHelpers.PostProcess.uu___is_Eq_Hetero", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option", "Prims.unit", "FStar.InteractiveHelpers.Base.print_dbg", "FStar.Pervasives.Native.Some", "Prims.string", "Prims.op_Hat", "FStar.Stubs.Tactics.V1.Builtins.term_to_string", "FStar.Pervasives.Native.tuple3", "FStar.InteractiveHelpers.PostProcess.is_eq", "FStar.Stubs.Reflection.Types.bv", "FStar.InteractiveHelpers.Base.bv_eq", "FStar.Stubs.Reflection.V1.Data.term_view", "FStar.Stubs.Tactics.V1.Builtins.inspect", "FStar.InteractiveHelpers.Effectful.term_eq" ]
[]
false
true
false
false
false
let is_equality_for_term dbg tm p =
print_dbg dbg ("[> is_equality_for_term:" ^ "\n- term: " ^ term_to_string tm ^ "\n- prop: " ^ term_to_string p); let check_eq: term -> Tac bool = match inspect tm with | Tv_Var bv -> (fun tm' -> match inspect tm' with | Tv_Var bv' -> bv_eq bv bv' | _ -> false) | _ -> (fun tm' -> term_eq tm tm') in match is_eq dbg p with | Some (ekind, l, r) -> print_dbg dbg ("Term is eq: " ^ term_to_string l ^ " = " ^ term_to_string r); if Eq_Hetero? ekind then (print_dbg dbg "Ignoring heterogeneous equality"; None) else if check_eq l then Some r else if check_eq r then Some l else None | _ -> print_dbg dbg "Term is not eq"; None
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.find_predicated_term_explorer
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool -> explorer (option (exploration_result a))
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool -> explorer (option (exploration_result a))
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t = if Some? acc then mfail "find_focused_term_explorer: non empty accumulator"; if dbg then begin print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t) end; match pred ge pl opt_c t with | Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort | None -> None, Continue
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 26, "end_line": 109, "start_col": 0, "start_line": 101 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging. val pp_explore_print_goal : unit -> Tac unit let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f () /// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which /// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*) val is_focus_on_term : term -> Tac bool let is_focus_on_term t = is_fvar t (`%focus_on_term) /// Check if a term is an assertion or an assumption and return its content /// if it is the case. val term_is_assert_or_assume : term -> Tac (option term) let term_is_assert_or_assume t = match inspect t with | Tv_App hd (a, Q_Explicit) -> if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume] then Some a else None | _ -> None /// Check if the given term view is of the form: 'let _ = focus_on_term in body' /// Returns 'body' if it is the case. val is_focused_term : term_view -> Tac (option term) let is_focused_term tv = match tv with | Tv_Let recf attrs _ _ def body -> if is_focus_on_term def then Some body else None | _ -> None noeq type exploration_result (a : Type)= { ge : genv; parents : list (genv & term_view); tgt_comp : option typ_or_comp; res : a; } let mk_exploration_result = Mkexploration_result let pred_explorer (a:Type) = genv -> list (genv & term_view) -> option typ_or_comp -> term_view -> Tac (option a) val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
pred: FStar.InteractiveHelpers.PostProcess.pred_explorer a -> dbg: Prims.bool -> FStar.InteractiveHelpers.ExploreTerm.explorer (FStar.Pervasives.Native.option (FStar.InteractiveHelpers.PostProcess.exploration_result a))
Prims.Tot
[ "total" ]
[]
[ "FStar.InteractiveHelpers.PostProcess.pred_explorer", "Prims.bool", "FStar.Pervasives.Native.option", "FStar.InteractiveHelpers.PostProcess.exploration_result", "FStar.InteractiveHelpers.Base.genv", "Prims.list", "FStar.Pervasives.Native.tuple2", "FStar.Stubs.Reflection.V1.Data.term_view", "FStar.InteractiveHelpers.ExploreTerm.typ_or_comp", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Tactics.Types.ctrl_flag", "FStar.Pervasives.Native.Some", "FStar.InteractiveHelpers.PostProcess.mk_exploration_result", "FStar.Stubs.Tactics.Types.Abort", "FStar.Pervasives.Native.None", "FStar.Stubs.Tactics.Types.Continue", "Prims.unit", "FStar.Stubs.Tactics.V1.Builtins.print", "Prims.string", "Prims.op_Hat", "FStar.Stubs.Tactics.V1.Builtins.term_to_string", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Tactics.V1.Builtins.pack", "FStar.InteractiveHelpers.Base.term_view_construct", "FStar.Pervasives.Native.uu___is_Some", "FStar.InteractiveHelpers.Base.mfail" ]
[]
false
false
false
true
false
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t =
if Some? acc then mfail "find_focused_term_explorer: non empty accumulator"; if dbg then print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t); match pred ge pl opt_c t with | Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort | None -> None, Continue
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.find_focused_term_in_current_goal
val find_focused_term_in_current_goal : bool -> Tac (exploration_result term)
val find_focused_term_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_term_in_current_goal dbg = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); begin match find_focused_term dbg true ge [] c l with | Some res -> print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); res | None -> mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: " ^ term_to_string g) end | _ -> mfail "find_focused_term_in_current_goal: not a squashed equality" end
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 149, "start_col": 0, "start_line": 131 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging. val pp_explore_print_goal : unit -> Tac unit let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f () /// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which /// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*) val is_focus_on_term : term -> Tac bool let is_focus_on_term t = is_fvar t (`%focus_on_term) /// Check if a term is an assertion or an assumption and return its content /// if it is the case. val term_is_assert_or_assume : term -> Tac (option term) let term_is_assert_or_assume t = match inspect t with | Tv_App hd (a, Q_Explicit) -> if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume] then Some a else None | _ -> None /// Check if the given term view is of the form: 'let _ = focus_on_term in body' /// Returns 'body' if it is the case. val is_focused_term : term_view -> Tac (option term) let is_focused_term tv = match tv with | Tv_Let recf attrs _ _ def body -> if is_focus_on_term def then Some body else None | _ -> None noeq type exploration_result (a : Type)= { ge : genv; parents : list (genv & term_view); tgt_comp : option typ_or_comp; res : a; } let mk_exploration_result = Mkexploration_result let pred_explorer (a:Type) = genv -> list (genv & term_view) -> option typ_or_comp -> term_view -> Tac (option a) val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool -> explorer (option (exploration_result a)) let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t = if Some? acc then mfail "find_focused_term_explorer: non empty accumulator"; if dbg then begin print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t) end; match pred ge pl opt_c t with | Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort | None -> None, Continue val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result a)) let find_predicated_term #a pred dbg dfs ge pl opt_c t = fst (explore_term dbg dfs #(option (exploration_result a)) (find_predicated_term_explorer #a pred dbg) None ge pl opt_c t) val _is_focused_term_explorer : pred_explorer term let _is_focused_term_explorer ge pl opt_c tv = is_focused_term tv val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result term)) let find_focused_term dbg dfs ge pl opt_c t = find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t /// This function raises a MetaAnalysis exception if it can't find a focused term
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
dbg: Prims.bool -> FStar.Tactics.Effect.Tac (FStar.InteractiveHelpers.PostProcess.exploration_result FStar.Stubs.Reflection.Types.term)
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.bool", "FStar.Stubs.Reflection.Types.term", "FStar.InteractiveHelpers.PostProcess.exploration_result", "Prims.unit", "FStar.InteractiveHelpers.Base.print_dbg", "Prims.string", "Prims.op_Hat", "FStar.Stubs.Tactics.V1.Builtins.term_to_string", "FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__res", "FStar.InteractiveHelpers.Base.mfail", "FStar.Pervasives.Native.option", "FStar.InteractiveHelpers.PostProcess.find_focused_term", "Prims.Nil", "FStar.Pervasives.Native.tuple2", "FStar.InteractiveHelpers.Base.genv", "FStar.Stubs.Reflection.V1.Data.term_view", "FStar.InteractiveHelpers.Base.mk_genv", "FStar.Stubs.Reflection.Types.bv", "FStar.Pervasives.Native.tuple3", "FStar.Stubs.Reflection.Types.typ", "FStar.InteractiveHelpers.ExploreTerm.typ_or_comp", "Prims.l_imp", "Prims.b2t", "FStar.Pervasives.Native.uu___is_Some", "FStar.InteractiveHelpers.ExploreTerm.uu___is_TC_Comp", "FStar.Pervasives.Native.__proj__Some__item__v", "FStar.InteractiveHelpers.ExploreTerm.safe_typ_or_comp", "FStar.InteractiveHelpers.PostProcess.unsquash_equality", "FStar.Stubs.Reflection.Types.env", "FStar.Tactics.V1.Derived.cur_env", "FStar.Tactics.V1.Derived.cur_goal" ]
[]
false
true
false
false
false
let find_focused_term_in_current_goal dbg =
let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g); match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); (match find_focused_term dbg true ge [] c l with | Some res -> print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); res | None -> mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: " ^ term_to_string g)) | _ -> mfail "find_focused_term_in_current_goal: not a squashed equality"
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.replace_term_in
val replace_term_in : bool -> term -> term -> term -> Tac term
val replace_term_in : bool -> term -> term -> term -> Tac term
let rec replace_term_in dbg from_term to_term tm = if term_eq from_term tm then to_term else match inspect tm with | Tv_Var _ | Tv_BVar _ | Tv_FVar _ -> tm | Tv_App hd (a, qual) -> let a' = replace_term_in dbg from_term to_term a in let hd' = replace_term_in dbg from_term to_term hd in pack (Tv_App hd' (a', qual)) | Tv_Abs br body -> let body' = replace_term_in dbg from_term to_term body in pack (Tv_Abs br body') | Tv_Arrow br c0 -> tm (* TODO: we might want to explore that *) | Tv_Type _ -> tm | Tv_Refine bv sort ref -> let sort' = replace_term_in dbg from_term to_term sort in let ref' = replace_term_in dbg from_term to_term ref in pack (Tv_Refine bv sort' ref') | Tv_Const _ -> tm | Tv_Uvar _ _ -> tm | Tv_Let recf attrs bv ty def body -> (* GM 2023-04-27: leaving ty untouched, old code did not descend into sort. *) let def' = replace_term_in dbg from_term to_term def in let body' = replace_term_in dbg from_term to_term body in pack (Tv_Let recf attrs bv ty def' body') | Tv_Match scrutinee ret_opt branches -> //AR: TODO: account for the returns annotation (* Auxiliary function to explore the branches *) let explore_branch (br : branch) : Tac branch = (* Only explore the branch body *) let pat, body = br in let body' = replace_term_in dbg from_term to_term body in (pat, body') in let scrutinee' = replace_term_in dbg from_term to_term scrutinee in let branches' = map explore_branch branches in pack (Tv_Match scrutinee' ret_opt branches') | Tv_AscribedT e ty tac use_eq -> let e' = replace_term_in dbg from_term to_term e in let ty' = replace_term_in dbg from_term to_term ty in pack (Tv_AscribedT e' ty' tac use_eq) | Tv_AscribedC e c tac use_eq -> let e' = replace_term_in dbg from_term to_term e in pack (Tv_AscribedC e' c tac use_eq) | _ -> (* Unknown *) tm
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 6, "end_line": 590, "start_col": 0, "start_line": 545 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging. val pp_explore_print_goal : unit -> Tac unit let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f () /// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which /// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*) val is_focus_on_term : term -> Tac bool let is_focus_on_term t = is_fvar t (`%focus_on_term) /// Check if a term is an assertion or an assumption and return its content /// if it is the case. val term_is_assert_or_assume : term -> Tac (option term) let term_is_assert_or_assume t = match inspect t with | Tv_App hd (a, Q_Explicit) -> if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume] then Some a else None | _ -> None /// Check if the given term view is of the form: 'let _ = focus_on_term in body' /// Returns 'body' if it is the case. val is_focused_term : term_view -> Tac (option term) let is_focused_term tv = match tv with | Tv_Let recf attrs _ _ def body -> if is_focus_on_term def then Some body else None | _ -> None noeq type exploration_result (a : Type)= { ge : genv; parents : list (genv & term_view); tgt_comp : option typ_or_comp; res : a; } let mk_exploration_result = Mkexploration_result let pred_explorer (a:Type) = genv -> list (genv & term_view) -> option typ_or_comp -> term_view -> Tac (option a) val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool -> explorer (option (exploration_result a)) let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t = if Some? acc then mfail "find_focused_term_explorer: non empty accumulator"; if dbg then begin print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t) end; match pred ge pl opt_c t with | Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort | None -> None, Continue val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result a)) let find_predicated_term #a pred dbg dfs ge pl opt_c t = fst (explore_term dbg dfs #(option (exploration_result a)) (find_predicated_term_explorer #a pred dbg) None ge pl opt_c t) val _is_focused_term_explorer : pred_explorer term let _is_focused_term_explorer ge pl opt_c tv = is_focused_term tv val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result term)) let find_focused_term dbg dfs ge pl opt_c t = find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_term_in_current_goal : bool -> Tac (exploration_result term) let find_focused_term_in_current_goal dbg = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); begin match find_focused_term dbg true ge [] c l with | Some res -> print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); res | None -> mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: " ^ term_to_string g) end | _ -> mfail "find_focused_term_in_current_goal: not a squashed equality" end /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term) let find_focused_assert_in_current_goal dbg = print_dbg dbg ("[> find_focused_assert_in_current_goal"); let res = find_focused_term_in_current_goal dbg in print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); (* Check that it is an assert or an assume, retrieve the assertion *) let res' = match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> let ge' = genv_push_bv res.ge bv0 ty false None in ({ res with res = fterm; ge = ge' }) | _ -> res in begin match term_is_assert_or_assume res'.res with | None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res) | Some tm -> { res' with res = tm } end (*** Analyze effectful term *) /// Analyze a term in order to print properly instantiated pre/postconditions /// and type conditions. /// with_globals states whether to analyze the target pre/post together with the /// focused term. val analyze_effectful_term : dbg:bool -> with_gpre:bool -> with_gpost:bool -> res:exploration_result term -> Tac unit let analyze_effectful_term dbg with_gpre with_gpost res = let ge = res.ge in let opt_c = res.tgt_comp in (* Analyze the effectful term and check whether it is a 'let' or not *) let ge1, studied_term, info, ret_bv, shadowed_bv, is_let = begin match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> (* Before pushing the binder, check if it shadows another variable. * If it is the case, we will need it to correctly output the pre * and post-assertions (because for the pre-assertions the variable * will not be shadowed yet, while it will be the case for the post- * assertions) *) print_dbg dbg ("Restraining to: " ^ term_to_string fterm); let shadowed_bv : option bv = match genv_get_from_name ge (name_of_bv bv0) with | None -> None | Some (sbv, _) -> Some (fst sbv) in let ge1 = genv_push_bv ge bv0 ty false None in (* If the bv name is "uu___", introduce a fresh variable and use it instead: * the underscore might have been introduced when desugaring a let using * tuples. If doing that is not necessary, the introduced variable will * not appear in the generated assertions anyway. *) let ge2, (bv1 : bv) = let bvv0 = inspect_bv bv0 in let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *) then genv_push_fresh_bv ge1 "ret" ty else ge1, bv0 in let info = compute_eterm_info dbg ge2.env fterm in (ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true) | _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false) end in print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term); print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1); (* Check if the considered term is an assert, in which case we will only * display the precondition (otherwise we introduce too many assertions * in the context) *) let is_assert = Some? (term_is_assert_or_assume studied_term) in (* Instantiate the refinements *) (* TODO: use bv rather than term for ret_arg *) let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in let parents = List.Tot.map snd res.parents in let ge2, asserts = eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let is_assert info ret_arg opt_c parents [] in (* Simplify and filter *) let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in (* Introduce fresh variables for the shadowed ones and substitute *) let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in (* If not a let, insert all the assertions before the term *) let asserts = if is_let then asserts else mk_assertions (List.Tot.append asserts.pres asserts.posts) [] in (* Print *) printout_success ge3 asserts [@plugin] val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit let pp_analyze_effectful_term dbg with_gpre with_gpost () = try let res = find_focused_term_in_current_goal dbg in analyze_effectful_term dbg with_gpre with_gpost res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err (*** Split conjunctions *) /// Split an assert made of conjunctions so that there is one assert per /// conjunction. We try to be a bit smart. For instance, if the assertion is of /// the form: /// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An); /// We generate: /// [> assert(let Construct x1 ... xn = e in A1); /// [> ... /// [> assert(let Construct x1 ... xn = e in An); /// Remove ``b2t`` if it is the head of the term val remove_b2t : term -> Tac term let remove_b2t (t:term) : Tac term = match inspect t with | Tv_App hd (a, Q_Explicit) -> begin match inspect hd with | Tv_FVar fv -> if fv_eq_name fv b2t_qn then a else t | _ -> t end | _ -> t // TODO: gather all the functions like split_conjunctions, is_eq... /// Try to destruct a term of the form '_ && _' or '_ /\ _' val is_conjunction : term -> Tac (option (term & term)) let is_conjunction t = let t = remove_b2t t in let hd, params = collect_app t in match params with | [(x,Q_Explicit);(y,Q_Explicit)] -> begin match inspect hd with | Tv_FVar fv -> let fvn = inspect_fv fv in if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"] then Some (x, y) else None | _ -> None end | _ -> None val split_conjunctions : term -> Tac (list term) let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) = match is_conjunction t with | None -> t :: ls | Some (l, r) -> let ls1 = _split_conjunctions ls r in let ls2 = _split_conjunctions ls1 l in ls2 let split_conjunctions t = _split_conjunctions [] t /// Split a term of the form: /// [> let Constuct x1 ... xn = x in A1 /\ ... /\ Am /// into m terms: /// [> let Constuct x1 ... xn = x in A1 /// ... /// [> let Constuct x1 ... xn = x in Am val split_conjunctions_under_match : bool -> term -> Tac (list term) let split_conjunctions_under_match dbg t = let t1 = remove_b2t t in print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1); match inspect t1 with | Tv_Match scrut ret_opt [(pat, br)] -> let tl = split_conjunctions br in map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl | _ -> (* Not of the proper shape: return the original term *) [t] val split_assert_conjs : bool -> exploration_result term -> Tac unit let split_assert_conjs dbg res = let ge0 = res.ge in (* Simplify the term (it may be an abstraction applied to some parameters) *) let t = norm_term_env ge0.env simpl_norm_steps res.res in (* Split the conjunctions *) let conjs = split_conjunctions t in (* If there is only one conjunction, check if it is of the following form * and try to split: * [> let Construct x1 .. xn = x in A1 /\ ... /\ Am *) let conjs = if List.length conjs = 1 then split_conjunctions_under_match dbg t else conjs in let asserts = mk_assertions conjs [] in (* Print *) printout_success ge0 asserts [@plugin] val pp_split_assert_conjs : bool -> unit -> Tac unit let pp_split_assert_conjs dbg () = try let res = find_focused_assert_in_current_goal dbg in split_assert_conjs dbg res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err (*** Term unfolding in assert *) /// Unfold/rewrite a term in an assert. /// If the term is a (recursive) top-level identifier, unfold it. /// Otherwise look for an equality or a pure let-binding to replace it with. /// If the assert is an equality, unfold/rewrite only on the side chosen by the user. // TODO: use "kind" keyword rather than type above /// An equality kind noeq type eq_kind = | Eq_Dec : typ -> eq_kind (* = *) | Eq_Undec : typ -> eq_kind (* == *) | Eq_Hetero : typ -> typ -> eq_kind (* === *) /// Deconstruct an equality // We use our own construct because ``term_as_formula`` doesn't always work // TODO: update ``term_as_formula`` val is_eq : bool -> term -> Tac (option (eq_kind & term & term)) let is_eq dbg t = let t = remove_b2t t in print_dbg dbg ("[> is_eq: " ^ term_to_string t); let hd, params = collect_app t in print_dbg dbg ("- hd:\n" ^ term_to_string hd); print_dbg dbg ("- parameters:\n" ^ list_to_string (fun (x, y) -> term_to_string x) params); match inspect hd with | Tv_FVar fv -> begin match params with | [(a,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] -> if is_any_fvar a [`%Prims.op_Equality; `%Prims.equals; "Prims.op_Equals"] then Some ((Eq_Dec a), x, y) else if is_any_fvar a [`%Prims.eq2; "Prims.op_Equals_Equals"] then Some ((Eq_Undec a), x, y) else None | [(a,Q_Implicit);(b,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] -> if is_fvar a (`%Prims.op_Equals_Equals_Equals) then Some ((Eq_Hetero a b), x, y) else None | _ -> None end | _ -> None /// Reconstruct an equality val mk_eq : eq_kind -> term -> term -> Tot term let mk_eq k t1 t2 = match k with | Eq_Dec ty -> mk_app (`Prims.op_Equality) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)] | Eq_Undec ty -> mk_app (`Prims.eq2) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)] | Eq_Hetero ty1 ty2 -> mk_app Prims.(`( === )) [(ty1, Q_Implicit); (ty2, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)] let formula_construct (f : formula) : Tac string = match f with | True_ -> "True_" | False_ -> "False_" | Comp _ _ _ -> "Comp" | And _ _ -> "And" | Or _ _ -> "Or" | Not _ -> "Not" | Implies _ _ -> "Implies" | Iff _ _ -> "Iff" | Forall _ _ _ -> "Forall" | Exists _ _ _ -> "Exists" | App _ _ -> "Apply" | Name _ -> "Name" | FV _ -> "FV" | IntLit _ -> "IntLit" | F_Unknown -> "F_Unknown" /// Check if a proposition is an equality which can be used to rewrite a term. /// Return the operand of the equality which the term is equal to if it is the case. val is_equality_for_term : bool -> term -> term -> Tac (option term) let is_equality_for_term dbg tm p = print_dbg dbg ("[> is_equality_for_term:" ^ "\n- term: " ^ term_to_string tm ^ "\n- prop: " ^ term_to_string p); (* Specialize equality for bv - TODO: not sure if necessary, but I had problems * in the past *) let check_eq : term -> Tac bool = match inspect tm with | Tv_Var bv -> (fun tm' -> match inspect tm' with | Tv_Var bv' -> bv_eq bv bv' | _ -> false) | _ -> (fun tm' -> term_eq tm tm') in match is_eq dbg p with | Some (ekind, l, r) -> (* We ignore heterogeneous equality, because it risks to cause havoc at * typing after substitution *) print_dbg dbg ("Term is eq: " ^ term_to_string l ^ " = " ^ term_to_string r); if Eq_Hetero? ekind then begin print_dbg dbg "Ignoring heterogeneous equality"; None end else if check_eq l then Some r else if check_eq r then Some l else None | _ -> print_dbg dbg "Term is not eq"; None val find_subequality : bool -> term -> term -> Tac (option term) let find_subequality dbg tm p = print_dbg dbg ("[> find_subequality:" ^ "\n- ter : " ^ term_to_string tm ^ "\n- props: " ^ term_to_string p); let conjuncts = split_conjunctions p in print_dbg dbg ("Conjuncts:\n" ^ list_to_string term_to_string conjuncts); tryPick (is_equality_for_term dbg tm) conjuncts /// Look for an equality in a postcondition which can be used for rewriting. val find_equality_from_post : bool -> genv -> term -> bv -> typ -> term -> effect_info -> list term_view -> list term_view -> Tac (genv & option term) let find_equality_from_post dbg ge0 tm let_bv let_bvty ret_value einfo parents children = print_dbg dbg "[> find_equality_from_post"; let tinfo = get_type_info_from_type let_bvty in (* Compute the post-condition *) let ge1, _, post_prop = pre_post_to_propositions dbg ge0 einfo.ei_type ret_value (Some (mk_binder let_bv let_bvty)) tinfo einfo.ei_pre einfo.ei_post parents children in print_dbg dbg ("Computed post: " ^ option_to_string term_to_string post_prop); (* Look for an equality in the post *) let res = match post_prop with | None -> None | Some p -> find_subequality dbg tm p in (* If we found something, we return the updated environment, * otherwise we can return the original one *) match res with | None -> ge0, None | Some tm -> ge1, Some tm /// Given a list of parent terms (as generated by ``explore_term``), look for an /// equality given by a post-condition which can be used to replace a term. val find_context_equality : dbg:bool -> ge0:genv -> tm:term -> parents:list term_view -> children:list term_view -> Tac (genv & option term) /// Auxiliary function which actually performs the search let rec find_context_equality_aux dbg ge0 tm (opt_bv : option bv) (parents children : list term_view) : Tac (genv & option term) = match parents with | [] -> ge0, None | tv :: parents' -> print_dbg dbg ("[> find_context_equality:\n" ^ "- term : " ^ term_to_string tm ^ "\n" ^ "- parent: " ^ term_to_string tv); (* We only consider let-bindings *) match tv with | Tv_Let _ _ bv' ty def _ -> print_dbg dbg "Is Tv_Let"; let tm_info = compute_eterm_info dbg ge0.env def in let einfo = tm_info.einfo in (* If the searched term is a bv and the current let is the one which * introduces it: * - if the term is effectful, use it * - otherwise, try to use its postcondition. If we don't find any * equalities, some there *) let let_bv_is_tm = match opt_bv with | Some tm_bv -> bv_eq tm_bv bv' | None -> false in if let_bv_is_tm && effect_type_is_pure einfo.ei_type then ge0, Some def else let ret_value = pack (Tv_Var bv') in begin match find_equality_from_post dbg ge0 tm bv' ty ret_value einfo parents children with | ge1, Some p -> ge1, Some p | _, None -> find_context_equality_aux dbg ge0 tm opt_bv parents' (tv :: children) end | _ -> find_context_equality_aux dbg ge0 tm opt_bv parents' (tv :: children) let find_context_equality dbg ge0 tm parents children = let opt_bv = match inspect tm with | Tv_Var bv -> Some bv | _ -> None in find_context_equality_aux dbg ge0 tm opt_bv parents children /// Replace a subterm by another term
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
dbg: Prims.bool -> from_term: FStar.Stubs.Reflection.Types.term -> to_term: FStar.Stubs.Reflection.Types.term -> tm: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac FStar.Stubs.Reflection.Types.term
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.bool", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.Types.bv", "FStar.Stubs.Reflection.Types.fv", "FStar.Stubs.Reflection.V1.Data.aqualv", "FStar.Stubs.Tactics.V1.Builtins.pack", "FStar.Stubs.Reflection.V1.Data.Tv_App", "FStar.Pervasives.Native.Mktuple2", "FStar.InteractiveHelpers.PostProcess.replace_term_in", "FStar.Stubs.Reflection.Types.binder", "FStar.Stubs.Reflection.V1.Data.Tv_Abs", "FStar.Stubs.Reflection.Types.comp", "FStar.Stubs.Reflection.Types.universe", "FStar.Stubs.Reflection.Types.typ", "FStar.Stubs.Reflection.V1.Data.Tv_Refine", "FStar.Stubs.Reflection.V1.Data.vconst", "Prims.nat", "FStar.Stubs.Reflection.Types.ctx_uvar_and_subst", "Prims.list", "FStar.Stubs.Reflection.V1.Data.Tv_Let", "FStar.Pervasives.Native.option", "FStar.Stubs.Reflection.Types.match_returns_ascription", "FStar.Stubs.Reflection.V1.Data.branch", "FStar.Stubs.Reflection.V1.Data.Tv_Match", "FStar.Tactics.Util.map", "FStar.Stubs.Reflection.V1.Data.pattern", "FStar.Stubs.Reflection.V1.Data.Tv_AscribedT", "FStar.Stubs.Reflection.V1.Data.Tv_AscribedC", "FStar.Stubs.Reflection.V1.Data.term_view", "FStar.Stubs.Tactics.V1.Builtins.inspect", "FStar.InteractiveHelpers.Effectful.term_eq" ]
[ "recursion" ]
false
true
false
false
false
let rec replace_term_in dbg from_term to_term tm =
if term_eq from_term tm then to_term else match inspect tm with | Tv_Var _ | Tv_BVar _ | Tv_FVar _ -> tm | Tv_App hd (a, qual) -> let a' = replace_term_in dbg from_term to_term a in let hd' = replace_term_in dbg from_term to_term hd in pack (Tv_App hd' (a', qual)) | Tv_Abs br body -> let body' = replace_term_in dbg from_term to_term body in pack (Tv_Abs br body') | Tv_Arrow br c0 -> tm | Tv_Type _ -> tm | Tv_Refine bv sort ref -> let sort' = replace_term_in dbg from_term to_term sort in let ref' = replace_term_in dbg from_term to_term ref in pack (Tv_Refine bv sort' ref') | Tv_Const _ -> tm | Tv_Uvar _ _ -> tm | Tv_Let recf attrs bv ty def body -> let def' = replace_term_in dbg from_term to_term def in let body' = replace_term_in dbg from_term to_term body in pack (Tv_Let recf attrs bv ty def' body') | Tv_Match scrutinee ret_opt branches -> let explore_branch (br: branch) : Tac branch = let pat, body = br in let body' = replace_term_in dbg from_term to_term body in (pat, body') in let scrutinee' = replace_term_in dbg from_term to_term scrutinee in let branches' = map explore_branch branches in pack (Tv_Match scrutinee' ret_opt branches') | Tv_AscribedT e ty tac use_eq -> let e' = replace_term_in dbg from_term to_term e in let ty' = replace_term_in dbg from_term to_term ty in pack (Tv_AscribedT e' ty' tac use_eq) | Tv_AscribedC e c tac use_eq -> let e' = replace_term_in dbg from_term to_term e in pack (Tv_AscribedC e' c tac use_eq) | _ -> tm
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess._split_conjunctions
val _split_conjunctions (ls: list term) (t: term) : Tac (list term)
val _split_conjunctions (ls: list term) (t: term) : Tac (list term)
let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) = match is_conjunction t with | None -> t :: ls | Some (l, r) -> let ls1 = _split_conjunctions ls r in let ls2 = _split_conjunctions ls1 l in ls2
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 7, "end_line": 300, "start_col": 0, "start_line": 294 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging. val pp_explore_print_goal : unit -> Tac unit let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f () /// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which /// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*) val is_focus_on_term : term -> Tac bool let is_focus_on_term t = is_fvar t (`%focus_on_term) /// Check if a term is an assertion or an assumption and return its content /// if it is the case. val term_is_assert_or_assume : term -> Tac (option term) let term_is_assert_or_assume t = match inspect t with | Tv_App hd (a, Q_Explicit) -> if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume] then Some a else None | _ -> None /// Check if the given term view is of the form: 'let _ = focus_on_term in body' /// Returns 'body' if it is the case. val is_focused_term : term_view -> Tac (option term) let is_focused_term tv = match tv with | Tv_Let recf attrs _ _ def body -> if is_focus_on_term def then Some body else None | _ -> None noeq type exploration_result (a : Type)= { ge : genv; parents : list (genv & term_view); tgt_comp : option typ_or_comp; res : a; } let mk_exploration_result = Mkexploration_result let pred_explorer (a:Type) = genv -> list (genv & term_view) -> option typ_or_comp -> term_view -> Tac (option a) val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool -> explorer (option (exploration_result a)) let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t = if Some? acc then mfail "find_focused_term_explorer: non empty accumulator"; if dbg then begin print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t) end; match pred ge pl opt_c t with | Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort | None -> None, Continue val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result a)) let find_predicated_term #a pred dbg dfs ge pl opt_c t = fst (explore_term dbg dfs #(option (exploration_result a)) (find_predicated_term_explorer #a pred dbg) None ge pl opt_c t) val _is_focused_term_explorer : pred_explorer term let _is_focused_term_explorer ge pl opt_c tv = is_focused_term tv val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result term)) let find_focused_term dbg dfs ge pl opt_c t = find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_term_in_current_goal : bool -> Tac (exploration_result term) let find_focused_term_in_current_goal dbg = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); begin match find_focused_term dbg true ge [] c l with | Some res -> print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); res | None -> mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: " ^ term_to_string g) end | _ -> mfail "find_focused_term_in_current_goal: not a squashed equality" end /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term) let find_focused_assert_in_current_goal dbg = print_dbg dbg ("[> find_focused_assert_in_current_goal"); let res = find_focused_term_in_current_goal dbg in print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); (* Check that it is an assert or an assume, retrieve the assertion *) let res' = match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> let ge' = genv_push_bv res.ge bv0 ty false None in ({ res with res = fterm; ge = ge' }) | _ -> res in begin match term_is_assert_or_assume res'.res with | None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res) | Some tm -> { res' with res = tm } end (*** Analyze effectful term *) /// Analyze a term in order to print properly instantiated pre/postconditions /// and type conditions. /// with_globals states whether to analyze the target pre/post together with the /// focused term. val analyze_effectful_term : dbg:bool -> with_gpre:bool -> with_gpost:bool -> res:exploration_result term -> Tac unit let analyze_effectful_term dbg with_gpre with_gpost res = let ge = res.ge in let opt_c = res.tgt_comp in (* Analyze the effectful term and check whether it is a 'let' or not *) let ge1, studied_term, info, ret_bv, shadowed_bv, is_let = begin match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> (* Before pushing the binder, check if it shadows another variable. * If it is the case, we will need it to correctly output the pre * and post-assertions (because for the pre-assertions the variable * will not be shadowed yet, while it will be the case for the post- * assertions) *) print_dbg dbg ("Restraining to: " ^ term_to_string fterm); let shadowed_bv : option bv = match genv_get_from_name ge (name_of_bv bv0) with | None -> None | Some (sbv, _) -> Some (fst sbv) in let ge1 = genv_push_bv ge bv0 ty false None in (* If the bv name is "uu___", introduce a fresh variable and use it instead: * the underscore might have been introduced when desugaring a let using * tuples. If doing that is not necessary, the introduced variable will * not appear in the generated assertions anyway. *) let ge2, (bv1 : bv) = let bvv0 = inspect_bv bv0 in let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *) then genv_push_fresh_bv ge1 "ret" ty else ge1, bv0 in let info = compute_eterm_info dbg ge2.env fterm in (ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true) | _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false) end in print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term); print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1); (* Check if the considered term is an assert, in which case we will only * display the precondition (otherwise we introduce too many assertions * in the context) *) let is_assert = Some? (term_is_assert_or_assume studied_term) in (* Instantiate the refinements *) (* TODO: use bv rather than term for ret_arg *) let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in let parents = List.Tot.map snd res.parents in let ge2, asserts = eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let is_assert info ret_arg opt_c parents [] in (* Simplify and filter *) let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in (* Introduce fresh variables for the shadowed ones and substitute *) let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in (* If not a let, insert all the assertions before the term *) let asserts = if is_let then asserts else mk_assertions (List.Tot.append asserts.pres asserts.posts) [] in (* Print *) printout_success ge3 asserts [@plugin] val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit let pp_analyze_effectful_term dbg with_gpre with_gpost () = try let res = find_focused_term_in_current_goal dbg in analyze_effectful_term dbg with_gpre with_gpost res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err (*** Split conjunctions *) /// Split an assert made of conjunctions so that there is one assert per /// conjunction. We try to be a bit smart. For instance, if the assertion is of /// the form: /// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An); /// We generate: /// [> assert(let Construct x1 ... xn = e in A1); /// [> ... /// [> assert(let Construct x1 ... xn = e in An); /// Remove ``b2t`` if it is the head of the term val remove_b2t : term -> Tac term let remove_b2t (t:term) : Tac term = match inspect t with | Tv_App hd (a, Q_Explicit) -> begin match inspect hd with | Tv_FVar fv -> if fv_eq_name fv b2t_qn then a else t | _ -> t end | _ -> t // TODO: gather all the functions like split_conjunctions, is_eq... /// Try to destruct a term of the form '_ && _' or '_ /\ _' val is_conjunction : term -> Tac (option (term & term)) let is_conjunction t = let t = remove_b2t t in let hd, params = collect_app t in match params with | [(x,Q_Explicit);(y,Q_Explicit)] -> begin match inspect hd with | Tv_FVar fv -> let fvn = inspect_fv fv in if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"] then Some (x, y) else None | _ -> None end | _ -> None val split_conjunctions : term -> Tac (list term)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ls: Prims.list FStar.Stubs.Reflection.Types.term -> t: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac (Prims.list FStar.Stubs.Reflection.Types.term)
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.list", "FStar.Stubs.Reflection.Types.term", "Prims.Cons", "FStar.InteractiveHelpers.PostProcess._split_conjunctions", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "FStar.InteractiveHelpers.PostProcess.is_conjunction" ]
[ "recursion" ]
false
true
false
false
false
let rec _split_conjunctions (ls: list term) (t: term) : Tac (list term) =
match is_conjunction t with | None -> t :: ls | Some (l, r) -> let ls1 = _split_conjunctions ls r in let ls2 = _split_conjunctions ls1 l in ls2
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.is_eq
val is_eq : bool -> term -> Tac (option (eq_kind & term & term))
val is_eq : bool -> term -> Tac (option (eq_kind & term & term))
let is_eq dbg t = let t = remove_b2t t in print_dbg dbg ("[> is_eq: " ^ term_to_string t); let hd, params = collect_app t in print_dbg dbg ("- hd:\n" ^ term_to_string hd); print_dbg dbg ("- parameters:\n" ^ list_to_string (fun (x, y) -> term_to_string x) params); match inspect hd with | Tv_FVar fv -> begin match params with | [(a,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] -> if is_any_fvar a [`%Prims.op_Equality; `%Prims.equals; "Prims.op_Equals"] then Some ((Eq_Dec a), x, y) else if is_any_fvar a [`%Prims.eq2; "Prims.op_Equals_Equals"] then Some ((Eq_Undec a), x, y) else None | [(a,Q_Implicit);(b,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] -> if is_fvar a (`%Prims.op_Equals_Equals_Equals) then Some ((Eq_Hetero a b), x, y) else None | _ -> None end | _ -> None
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 13, "end_line": 391, "start_col": 0, "start_line": 370 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging. val pp_explore_print_goal : unit -> Tac unit let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f () /// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which /// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*) val is_focus_on_term : term -> Tac bool let is_focus_on_term t = is_fvar t (`%focus_on_term) /// Check if a term is an assertion or an assumption and return its content /// if it is the case. val term_is_assert_or_assume : term -> Tac (option term) let term_is_assert_or_assume t = match inspect t with | Tv_App hd (a, Q_Explicit) -> if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume] then Some a else None | _ -> None /// Check if the given term view is of the form: 'let _ = focus_on_term in body' /// Returns 'body' if it is the case. val is_focused_term : term_view -> Tac (option term) let is_focused_term tv = match tv with | Tv_Let recf attrs _ _ def body -> if is_focus_on_term def then Some body else None | _ -> None noeq type exploration_result (a : Type)= { ge : genv; parents : list (genv & term_view); tgt_comp : option typ_or_comp; res : a; } let mk_exploration_result = Mkexploration_result let pred_explorer (a:Type) = genv -> list (genv & term_view) -> option typ_or_comp -> term_view -> Tac (option a) val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool -> explorer (option (exploration_result a)) let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t = if Some? acc then mfail "find_focused_term_explorer: non empty accumulator"; if dbg then begin print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t) end; match pred ge pl opt_c t with | Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort | None -> None, Continue val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result a)) let find_predicated_term #a pred dbg dfs ge pl opt_c t = fst (explore_term dbg dfs #(option (exploration_result a)) (find_predicated_term_explorer #a pred dbg) None ge pl opt_c t) val _is_focused_term_explorer : pred_explorer term let _is_focused_term_explorer ge pl opt_c tv = is_focused_term tv val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result term)) let find_focused_term dbg dfs ge pl opt_c t = find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_term_in_current_goal : bool -> Tac (exploration_result term) let find_focused_term_in_current_goal dbg = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); begin match find_focused_term dbg true ge [] c l with | Some res -> print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); res | None -> mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: " ^ term_to_string g) end | _ -> mfail "find_focused_term_in_current_goal: not a squashed equality" end /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term) let find_focused_assert_in_current_goal dbg = print_dbg dbg ("[> find_focused_assert_in_current_goal"); let res = find_focused_term_in_current_goal dbg in print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); (* Check that it is an assert or an assume, retrieve the assertion *) let res' = match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> let ge' = genv_push_bv res.ge bv0 ty false None in ({ res with res = fterm; ge = ge' }) | _ -> res in begin match term_is_assert_or_assume res'.res with | None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res) | Some tm -> { res' with res = tm } end (*** Analyze effectful term *) /// Analyze a term in order to print properly instantiated pre/postconditions /// and type conditions. /// with_globals states whether to analyze the target pre/post together with the /// focused term. val analyze_effectful_term : dbg:bool -> with_gpre:bool -> with_gpost:bool -> res:exploration_result term -> Tac unit let analyze_effectful_term dbg with_gpre with_gpost res = let ge = res.ge in let opt_c = res.tgt_comp in (* Analyze the effectful term and check whether it is a 'let' or not *) let ge1, studied_term, info, ret_bv, shadowed_bv, is_let = begin match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> (* Before pushing the binder, check if it shadows another variable. * If it is the case, we will need it to correctly output the pre * and post-assertions (because for the pre-assertions the variable * will not be shadowed yet, while it will be the case for the post- * assertions) *) print_dbg dbg ("Restraining to: " ^ term_to_string fterm); let shadowed_bv : option bv = match genv_get_from_name ge (name_of_bv bv0) with | None -> None | Some (sbv, _) -> Some (fst sbv) in let ge1 = genv_push_bv ge bv0 ty false None in (* If the bv name is "uu___", introduce a fresh variable and use it instead: * the underscore might have been introduced when desugaring a let using * tuples. If doing that is not necessary, the introduced variable will * not appear in the generated assertions anyway. *) let ge2, (bv1 : bv) = let bvv0 = inspect_bv bv0 in let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *) then genv_push_fresh_bv ge1 "ret" ty else ge1, bv0 in let info = compute_eterm_info dbg ge2.env fterm in (ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true) | _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false) end in print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term); print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1); (* Check if the considered term is an assert, in which case we will only * display the precondition (otherwise we introduce too many assertions * in the context) *) let is_assert = Some? (term_is_assert_or_assume studied_term) in (* Instantiate the refinements *) (* TODO: use bv rather than term for ret_arg *) let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in let parents = List.Tot.map snd res.parents in let ge2, asserts = eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let is_assert info ret_arg opt_c parents [] in (* Simplify and filter *) let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in (* Introduce fresh variables for the shadowed ones and substitute *) let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in (* If not a let, insert all the assertions before the term *) let asserts = if is_let then asserts else mk_assertions (List.Tot.append asserts.pres asserts.posts) [] in (* Print *) printout_success ge3 asserts [@plugin] val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit let pp_analyze_effectful_term dbg with_gpre with_gpost () = try let res = find_focused_term_in_current_goal dbg in analyze_effectful_term dbg with_gpre with_gpost res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err (*** Split conjunctions *) /// Split an assert made of conjunctions so that there is one assert per /// conjunction. We try to be a bit smart. For instance, if the assertion is of /// the form: /// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An); /// We generate: /// [> assert(let Construct x1 ... xn = e in A1); /// [> ... /// [> assert(let Construct x1 ... xn = e in An); /// Remove ``b2t`` if it is the head of the term val remove_b2t : term -> Tac term let remove_b2t (t:term) : Tac term = match inspect t with | Tv_App hd (a, Q_Explicit) -> begin match inspect hd with | Tv_FVar fv -> if fv_eq_name fv b2t_qn then a else t | _ -> t end | _ -> t // TODO: gather all the functions like split_conjunctions, is_eq... /// Try to destruct a term of the form '_ && _' or '_ /\ _' val is_conjunction : term -> Tac (option (term & term)) let is_conjunction t = let t = remove_b2t t in let hd, params = collect_app t in match params with | [(x,Q_Explicit);(y,Q_Explicit)] -> begin match inspect hd with | Tv_FVar fv -> let fvn = inspect_fv fv in if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"] then Some (x, y) else None | _ -> None end | _ -> None val split_conjunctions : term -> Tac (list term) let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) = match is_conjunction t with | None -> t :: ls | Some (l, r) -> let ls1 = _split_conjunctions ls r in let ls2 = _split_conjunctions ls1 l in ls2 let split_conjunctions t = _split_conjunctions [] t /// Split a term of the form: /// [> let Constuct x1 ... xn = x in A1 /\ ... /\ Am /// into m terms: /// [> let Constuct x1 ... xn = x in A1 /// ... /// [> let Constuct x1 ... xn = x in Am val split_conjunctions_under_match : bool -> term -> Tac (list term) let split_conjunctions_under_match dbg t = let t1 = remove_b2t t in print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1); match inspect t1 with | Tv_Match scrut ret_opt [(pat, br)] -> let tl = split_conjunctions br in map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl | _ -> (* Not of the proper shape: return the original term *) [t] val split_assert_conjs : bool -> exploration_result term -> Tac unit let split_assert_conjs dbg res = let ge0 = res.ge in (* Simplify the term (it may be an abstraction applied to some parameters) *) let t = norm_term_env ge0.env simpl_norm_steps res.res in (* Split the conjunctions *) let conjs = split_conjunctions t in (* If there is only one conjunction, check if it is of the following form * and try to split: * [> let Construct x1 .. xn = x in A1 /\ ... /\ Am *) let conjs = if List.length conjs = 1 then split_conjunctions_under_match dbg t else conjs in let asserts = mk_assertions conjs [] in (* Print *) printout_success ge0 asserts [@plugin] val pp_split_assert_conjs : bool -> unit -> Tac unit let pp_split_assert_conjs dbg () = try let res = find_focused_assert_in_current_goal dbg in split_assert_conjs dbg res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err (*** Term unfolding in assert *) /// Unfold/rewrite a term in an assert. /// If the term is a (recursive) top-level identifier, unfold it. /// Otherwise look for an equality or a pure let-binding to replace it with. /// If the assert is an equality, unfold/rewrite only on the side chosen by the user. // TODO: use "kind" keyword rather than type above /// An equality kind noeq type eq_kind = | Eq_Dec : typ -> eq_kind (* = *) | Eq_Undec : typ -> eq_kind (* == *) | Eq_Hetero : typ -> typ -> eq_kind (* === *) /// Deconstruct an equality // We use our own construct because ``term_as_formula`` doesn't always work // TODO: update ``term_as_formula``
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
dbg: Prims.bool -> t: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac (FStar.Pervasives.Native.option ((FStar.InteractiveHelpers.PostProcess.eq_kind * FStar.Stubs.Reflection.Types.term) * FStar.Stubs.Reflection.Types.term))
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.bool", "FStar.Stubs.Reflection.Types.term", "Prims.list", "FStar.Stubs.Reflection.V1.Data.argv", "FStar.Stubs.Reflection.Types.fv", "FStar.Reflection.V1.Derived.is_any_fvar", "Prims.Cons", "Prims.string", "Prims.Nil", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple3", "FStar.InteractiveHelpers.PostProcess.eq_kind", "FStar.Pervasives.Native.Mktuple3", "FStar.InteractiveHelpers.PostProcess.Eq_Dec", "FStar.InteractiveHelpers.PostProcess.Eq_Undec", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option", "FStar.Reflection.V1.Derived.is_fvar", "FStar.InteractiveHelpers.PostProcess.Eq_Hetero", "FStar.Stubs.Reflection.V1.Data.term_view", "FStar.Stubs.Tactics.V1.Builtins.inspect", "Prims.unit", "FStar.InteractiveHelpers.Base.print_dbg", "Prims.op_Hat", "FStar.InteractiveHelpers.Base.list_to_string", "FStar.Pervasives.Native.tuple2", "FStar.Stubs.Reflection.V1.Data.aqualv", "FStar.Stubs.Tactics.V1.Builtins.term_to_string", "FStar.Tactics.V1.SyntaxHelpers.collect_app", "FStar.InteractiveHelpers.PostProcess.remove_b2t" ]
[]
false
true
false
false
false
let is_eq dbg t =
let t = remove_b2t t in print_dbg dbg ("[> is_eq: " ^ term_to_string t); let hd, params = collect_app t in print_dbg dbg ("- hd:\n" ^ term_to_string hd); print_dbg dbg ("- parameters:\n" ^ list_to_string (fun (x, y) -> term_to_string x) params); match inspect hd with | Tv_FVar fv -> (match params with | [a, Q_Implicit ; x, Q_Explicit ; y, Q_Explicit] -> if is_any_fvar a [`%Prims.op_Equality; `%Prims.equals; "Prims.op_Equals"] then Some ((Eq_Dec a), x, y) else if is_any_fvar a [`%Prims.eq2; "Prims.op_Equals_Equals"] then Some ((Eq_Undec a), x, y) else None | [a, Q_Implicit ; b, Q_Implicit ; x, Q_Explicit ; y, Q_Explicit] -> if is_fvar a (`%Prims.op_Equals_Equals_Equals) then Some ((Eq_Hetero a b), x, y) else None | _ -> None) | _ -> None
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.find_focused_assert_in_current_goal
val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term)
val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_assert_in_current_goal dbg = print_dbg dbg ("[> find_focused_assert_in_current_goal"); let res = find_focused_term_in_current_goal dbg in print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); (* Check that it is an assert or an assume, retrieve the assertion *) let res' = match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> let ge' = genv_push_bv res.ge bv0 ty false None in ({ res with res = fterm; ge = ge' }) | _ -> res in begin match term_is_assert_or_assume res'.res with | None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res) | Some tm -> { res' with res = tm } end
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 168, "start_col": 0, "start_line": 153 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging. val pp_explore_print_goal : unit -> Tac unit let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f () /// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which /// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*) val is_focus_on_term : term -> Tac bool let is_focus_on_term t = is_fvar t (`%focus_on_term) /// Check if a term is an assertion or an assumption and return its content /// if it is the case. val term_is_assert_or_assume : term -> Tac (option term) let term_is_assert_or_assume t = match inspect t with | Tv_App hd (a, Q_Explicit) -> if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume] then Some a else None | _ -> None /// Check if the given term view is of the form: 'let _ = focus_on_term in body' /// Returns 'body' if it is the case. val is_focused_term : term_view -> Tac (option term) let is_focused_term tv = match tv with | Tv_Let recf attrs _ _ def body -> if is_focus_on_term def then Some body else None | _ -> None noeq type exploration_result (a : Type)= { ge : genv; parents : list (genv & term_view); tgt_comp : option typ_or_comp; res : a; } let mk_exploration_result = Mkexploration_result let pred_explorer (a:Type) = genv -> list (genv & term_view) -> option typ_or_comp -> term_view -> Tac (option a) val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool -> explorer (option (exploration_result a)) let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t = if Some? acc then mfail "find_focused_term_explorer: non empty accumulator"; if dbg then begin print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t) end; match pred ge pl opt_c t with | Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort | None -> None, Continue val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result a)) let find_predicated_term #a pred dbg dfs ge pl opt_c t = fst (explore_term dbg dfs #(option (exploration_result a)) (find_predicated_term_explorer #a pred dbg) None ge pl opt_c t) val _is_focused_term_explorer : pred_explorer term let _is_focused_term_explorer ge pl opt_c tv = is_focused_term tv val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result term)) let find_focused_term dbg dfs ge pl opt_c t = find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_term_in_current_goal : bool -> Tac (exploration_result term) let find_focused_term_in_current_goal dbg = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); begin match find_focused_term dbg true ge [] c l with | Some res -> print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); res | None -> mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: " ^ term_to_string g) end | _ -> mfail "find_focused_term_in_current_goal: not a squashed equality" end /// This function raises a MetaAnalysis exception if it can't find a focused term
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
dbg: Prims.bool -> FStar.Tactics.Effect.Tac (FStar.InteractiveHelpers.PostProcess.exploration_result FStar.Stubs.Reflection.Types.term)
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.bool", "FStar.InteractiveHelpers.Base.mfail", "FStar.InteractiveHelpers.PostProcess.exploration_result", "FStar.Stubs.Reflection.Types.term", "Prims.string", "Prims.op_Hat", "FStar.Stubs.Tactics.V1.Builtins.term_to_string", "FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__res", "FStar.InteractiveHelpers.PostProcess.Mkexploration_result", "FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__ge", "FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__parents", "FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__tgt_comp", "FStar.Pervasives.Native.option", "FStar.InteractiveHelpers.PostProcess.term_is_assert_or_assume", "Prims.list", "FStar.Stubs.Reflection.Types.bv", "FStar.Stubs.Reflection.Types.typ", "FStar.InteractiveHelpers.Base.genv", "FStar.InteractiveHelpers.Base.genv_push_bv", "FStar.Pervasives.Native.None", "FStar.Stubs.Reflection.V1.Data.term_view", "FStar.Stubs.Tactics.V1.Builtins.inspect", "Prims.unit", "FStar.InteractiveHelpers.Base.print_dbg", "FStar.InteractiveHelpers.PostProcess.find_focused_term_in_current_goal" ]
[]
false
true
false
false
false
let find_focused_assert_in_current_goal dbg =
print_dbg dbg ("[> find_focused_assert_in_current_goal"); let res = find_focused_term_in_current_goal dbg in print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); let res' = match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> let ge' = genv_push_bv res.ge bv0 ty false None in ({ res with res = fterm; ge = ge' }) | _ -> res in match term_is_assert_or_assume res'.res with | None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res) | Some tm -> { res' with res = tm }
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.is_conjunction
val is_conjunction : term -> Tac (option (term & term))
val is_conjunction : term -> Tac (option (term & term))
let is_conjunction t = let t = remove_b2t t in let hd, params = collect_app t in match params with | [(x,Q_Explicit);(y,Q_Explicit)] -> begin match inspect hd with | Tv_FVar fv -> let fvn = inspect_fv fv in if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"] then Some (x, y) else None | _ -> None end | _ -> None
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 13, "end_line": 290, "start_col": 0, "start_line": 278 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging. val pp_explore_print_goal : unit -> Tac unit let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f () /// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which /// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*) val is_focus_on_term : term -> Tac bool let is_focus_on_term t = is_fvar t (`%focus_on_term) /// Check if a term is an assertion or an assumption and return its content /// if it is the case. val term_is_assert_or_assume : term -> Tac (option term) let term_is_assert_or_assume t = match inspect t with | Tv_App hd (a, Q_Explicit) -> if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume] then Some a else None | _ -> None /// Check if the given term view is of the form: 'let _ = focus_on_term in body' /// Returns 'body' if it is the case. val is_focused_term : term_view -> Tac (option term) let is_focused_term tv = match tv with | Tv_Let recf attrs _ _ def body -> if is_focus_on_term def then Some body else None | _ -> None noeq type exploration_result (a : Type)= { ge : genv; parents : list (genv & term_view); tgt_comp : option typ_or_comp; res : a; } let mk_exploration_result = Mkexploration_result let pred_explorer (a:Type) = genv -> list (genv & term_view) -> option typ_or_comp -> term_view -> Tac (option a) val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool -> explorer (option (exploration_result a)) let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t = if Some? acc then mfail "find_focused_term_explorer: non empty accumulator"; if dbg then begin print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t) end; match pred ge pl opt_c t with | Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort | None -> None, Continue val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result a)) let find_predicated_term #a pred dbg dfs ge pl opt_c t = fst (explore_term dbg dfs #(option (exploration_result a)) (find_predicated_term_explorer #a pred dbg) None ge pl opt_c t) val _is_focused_term_explorer : pred_explorer term let _is_focused_term_explorer ge pl opt_c tv = is_focused_term tv val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result term)) let find_focused_term dbg dfs ge pl opt_c t = find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_term_in_current_goal : bool -> Tac (exploration_result term) let find_focused_term_in_current_goal dbg = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); begin match find_focused_term dbg true ge [] c l with | Some res -> print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); res | None -> mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: " ^ term_to_string g) end | _ -> mfail "find_focused_term_in_current_goal: not a squashed equality" end /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term) let find_focused_assert_in_current_goal dbg = print_dbg dbg ("[> find_focused_assert_in_current_goal"); let res = find_focused_term_in_current_goal dbg in print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); (* Check that it is an assert or an assume, retrieve the assertion *) let res' = match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> let ge' = genv_push_bv res.ge bv0 ty false None in ({ res with res = fterm; ge = ge' }) | _ -> res in begin match term_is_assert_or_assume res'.res with | None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res) | Some tm -> { res' with res = tm } end (*** Analyze effectful term *) /// Analyze a term in order to print properly instantiated pre/postconditions /// and type conditions. /// with_globals states whether to analyze the target pre/post together with the /// focused term. val analyze_effectful_term : dbg:bool -> with_gpre:bool -> with_gpost:bool -> res:exploration_result term -> Tac unit let analyze_effectful_term dbg with_gpre with_gpost res = let ge = res.ge in let opt_c = res.tgt_comp in (* Analyze the effectful term and check whether it is a 'let' or not *) let ge1, studied_term, info, ret_bv, shadowed_bv, is_let = begin match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> (* Before pushing the binder, check if it shadows another variable. * If it is the case, we will need it to correctly output the pre * and post-assertions (because for the pre-assertions the variable * will not be shadowed yet, while it will be the case for the post- * assertions) *) print_dbg dbg ("Restraining to: " ^ term_to_string fterm); let shadowed_bv : option bv = match genv_get_from_name ge (name_of_bv bv0) with | None -> None | Some (sbv, _) -> Some (fst sbv) in let ge1 = genv_push_bv ge bv0 ty false None in (* If the bv name is "uu___", introduce a fresh variable and use it instead: * the underscore might have been introduced when desugaring a let using * tuples. If doing that is not necessary, the introduced variable will * not appear in the generated assertions anyway. *) let ge2, (bv1 : bv) = let bvv0 = inspect_bv bv0 in let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *) then genv_push_fresh_bv ge1 "ret" ty else ge1, bv0 in let info = compute_eterm_info dbg ge2.env fterm in (ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true) | _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false) end in print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term); print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1); (* Check if the considered term is an assert, in which case we will only * display the precondition (otherwise we introduce too many assertions * in the context) *) let is_assert = Some? (term_is_assert_or_assume studied_term) in (* Instantiate the refinements *) (* TODO: use bv rather than term for ret_arg *) let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in let parents = List.Tot.map snd res.parents in let ge2, asserts = eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let is_assert info ret_arg opt_c parents [] in (* Simplify and filter *) let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in (* Introduce fresh variables for the shadowed ones and substitute *) let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in (* If not a let, insert all the assertions before the term *) let asserts = if is_let then asserts else mk_assertions (List.Tot.append asserts.pres asserts.posts) [] in (* Print *) printout_success ge3 asserts [@plugin] val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit let pp_analyze_effectful_term dbg with_gpre with_gpost () = try let res = find_focused_term_in_current_goal dbg in analyze_effectful_term dbg with_gpre with_gpost res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err (*** Split conjunctions *) /// Split an assert made of conjunctions so that there is one assert per /// conjunction. We try to be a bit smart. For instance, if the assertion is of /// the form: /// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An); /// We generate: /// [> assert(let Construct x1 ... xn = e in A1); /// [> ... /// [> assert(let Construct x1 ... xn = e in An); /// Remove ``b2t`` if it is the head of the term val remove_b2t : term -> Tac term let remove_b2t (t:term) : Tac term = match inspect t with | Tv_App hd (a, Q_Explicit) -> begin match inspect hd with | Tv_FVar fv -> if fv_eq_name fv b2t_qn then a else t | _ -> t end | _ -> t // TODO: gather all the functions like split_conjunctions, is_eq... /// Try to destruct a term of the form '_ && _' or '_ /\ _'
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac (FStar.Pervasives.Native.option (FStar.Stubs.Reflection.Types.term * FStar.Stubs.Reflection.Types.term))
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Stubs.Reflection.Types.term", "Prims.list", "FStar.Stubs.Reflection.V1.Data.argv", "FStar.Stubs.Reflection.Types.fv", "Prims.op_BarBar", "Prims.op_Equality", "Prims.string", "FStar.Reflection.Const.and_qn", "Prims.Cons", "Prims.Nil", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2", "Prims.bool", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option", "FStar.Stubs.Reflection.Types.name", "FStar.Stubs.Reflection.V1.Builtins.inspect_fv", "FStar.Stubs.Reflection.V1.Data.term_view", "FStar.Stubs.Tactics.V1.Builtins.inspect", "FStar.Tactics.V1.SyntaxHelpers.collect_app", "FStar.InteractiveHelpers.PostProcess.remove_b2t" ]
[]
false
true
false
false
false
let is_conjunction t =
let t = remove_b2t t in let hd, params = collect_app t in match params with | [x, Q_Explicit ; y, Q_Explicit] -> (match inspect hd with | Tv_FVar fv -> let fvn = inspect_fv fv in if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"] then Some (x, y) else None | _ -> None) | _ -> None
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.formula_construct
val formula_construct (f: formula) : Tac string
val formula_construct (f: formula) : Tac string
let formula_construct (f : formula) : Tac string = match f with | True_ -> "True_" | False_ -> "False_" | Comp _ _ _ -> "Comp" | And _ _ -> "And" | Or _ _ -> "Or" | Not _ -> "Not" | Implies _ _ -> "Implies" | Iff _ _ -> "Iff" | Forall _ _ _ -> "Forall" | Exists _ _ _ -> "Exists" | App _ _ -> "Apply" | Name _ -> "Name" | FV _ -> "FV" | IntLit _ -> "IntLit" | F_Unknown -> "F_Unknown"
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 421, "start_col": 0, "start_line": 405 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging. val pp_explore_print_goal : unit -> Tac unit let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f () /// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which /// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*) val is_focus_on_term : term -> Tac bool let is_focus_on_term t = is_fvar t (`%focus_on_term) /// Check if a term is an assertion or an assumption and return its content /// if it is the case. val term_is_assert_or_assume : term -> Tac (option term) let term_is_assert_or_assume t = match inspect t with | Tv_App hd (a, Q_Explicit) -> if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume] then Some a else None | _ -> None /// Check if the given term view is of the form: 'let _ = focus_on_term in body' /// Returns 'body' if it is the case. val is_focused_term : term_view -> Tac (option term) let is_focused_term tv = match tv with | Tv_Let recf attrs _ _ def body -> if is_focus_on_term def then Some body else None | _ -> None noeq type exploration_result (a : Type)= { ge : genv; parents : list (genv & term_view); tgt_comp : option typ_or_comp; res : a; } let mk_exploration_result = Mkexploration_result let pred_explorer (a:Type) = genv -> list (genv & term_view) -> option typ_or_comp -> term_view -> Tac (option a) val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool -> explorer (option (exploration_result a)) let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t = if Some? acc then mfail "find_focused_term_explorer: non empty accumulator"; if dbg then begin print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t) end; match pred ge pl opt_c t with | Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort | None -> None, Continue val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result a)) let find_predicated_term #a pred dbg dfs ge pl opt_c t = fst (explore_term dbg dfs #(option (exploration_result a)) (find_predicated_term_explorer #a pred dbg) None ge pl opt_c t) val _is_focused_term_explorer : pred_explorer term let _is_focused_term_explorer ge pl opt_c tv = is_focused_term tv val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result term)) let find_focused_term dbg dfs ge pl opt_c t = find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_term_in_current_goal : bool -> Tac (exploration_result term) let find_focused_term_in_current_goal dbg = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); begin match find_focused_term dbg true ge [] c l with | Some res -> print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); res | None -> mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: " ^ term_to_string g) end | _ -> mfail "find_focused_term_in_current_goal: not a squashed equality" end /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term) let find_focused_assert_in_current_goal dbg = print_dbg dbg ("[> find_focused_assert_in_current_goal"); let res = find_focused_term_in_current_goal dbg in print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); (* Check that it is an assert or an assume, retrieve the assertion *) let res' = match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> let ge' = genv_push_bv res.ge bv0 ty false None in ({ res with res = fterm; ge = ge' }) | _ -> res in begin match term_is_assert_or_assume res'.res with | None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res) | Some tm -> { res' with res = tm } end (*** Analyze effectful term *) /// Analyze a term in order to print properly instantiated pre/postconditions /// and type conditions. /// with_globals states whether to analyze the target pre/post together with the /// focused term. val analyze_effectful_term : dbg:bool -> with_gpre:bool -> with_gpost:bool -> res:exploration_result term -> Tac unit let analyze_effectful_term dbg with_gpre with_gpost res = let ge = res.ge in let opt_c = res.tgt_comp in (* Analyze the effectful term and check whether it is a 'let' or not *) let ge1, studied_term, info, ret_bv, shadowed_bv, is_let = begin match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> (* Before pushing the binder, check if it shadows another variable. * If it is the case, we will need it to correctly output the pre * and post-assertions (because for the pre-assertions the variable * will not be shadowed yet, while it will be the case for the post- * assertions) *) print_dbg dbg ("Restraining to: " ^ term_to_string fterm); let shadowed_bv : option bv = match genv_get_from_name ge (name_of_bv bv0) with | None -> None | Some (sbv, _) -> Some (fst sbv) in let ge1 = genv_push_bv ge bv0 ty false None in (* If the bv name is "uu___", introduce a fresh variable and use it instead: * the underscore might have been introduced when desugaring a let using * tuples. If doing that is not necessary, the introduced variable will * not appear in the generated assertions anyway. *) let ge2, (bv1 : bv) = let bvv0 = inspect_bv bv0 in let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *) then genv_push_fresh_bv ge1 "ret" ty else ge1, bv0 in let info = compute_eterm_info dbg ge2.env fterm in (ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true) | _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false) end in print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term); print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1); (* Check if the considered term is an assert, in which case we will only * display the precondition (otherwise we introduce too many assertions * in the context) *) let is_assert = Some? (term_is_assert_or_assume studied_term) in (* Instantiate the refinements *) (* TODO: use bv rather than term for ret_arg *) let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in let parents = List.Tot.map snd res.parents in let ge2, asserts = eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let is_assert info ret_arg opt_c parents [] in (* Simplify and filter *) let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in (* Introduce fresh variables for the shadowed ones and substitute *) let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in (* If not a let, insert all the assertions before the term *) let asserts = if is_let then asserts else mk_assertions (List.Tot.append asserts.pres asserts.posts) [] in (* Print *) printout_success ge3 asserts [@plugin] val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit let pp_analyze_effectful_term dbg with_gpre with_gpost () = try let res = find_focused_term_in_current_goal dbg in analyze_effectful_term dbg with_gpre with_gpost res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err (*** Split conjunctions *) /// Split an assert made of conjunctions so that there is one assert per /// conjunction. We try to be a bit smart. For instance, if the assertion is of /// the form: /// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An); /// We generate: /// [> assert(let Construct x1 ... xn = e in A1); /// [> ... /// [> assert(let Construct x1 ... xn = e in An); /// Remove ``b2t`` if it is the head of the term val remove_b2t : term -> Tac term let remove_b2t (t:term) : Tac term = match inspect t with | Tv_App hd (a, Q_Explicit) -> begin match inspect hd with | Tv_FVar fv -> if fv_eq_name fv b2t_qn then a else t | _ -> t end | _ -> t // TODO: gather all the functions like split_conjunctions, is_eq... /// Try to destruct a term of the form '_ && _' or '_ /\ _' val is_conjunction : term -> Tac (option (term & term)) let is_conjunction t = let t = remove_b2t t in let hd, params = collect_app t in match params with | [(x,Q_Explicit);(y,Q_Explicit)] -> begin match inspect hd with | Tv_FVar fv -> let fvn = inspect_fv fv in if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"] then Some (x, y) else None | _ -> None end | _ -> None val split_conjunctions : term -> Tac (list term) let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) = match is_conjunction t with | None -> t :: ls | Some (l, r) -> let ls1 = _split_conjunctions ls r in let ls2 = _split_conjunctions ls1 l in ls2 let split_conjunctions t = _split_conjunctions [] t /// Split a term of the form: /// [> let Constuct x1 ... xn = x in A1 /\ ... /\ Am /// into m terms: /// [> let Constuct x1 ... xn = x in A1 /// ... /// [> let Constuct x1 ... xn = x in Am val split_conjunctions_under_match : bool -> term -> Tac (list term) let split_conjunctions_under_match dbg t = let t1 = remove_b2t t in print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1); match inspect t1 with | Tv_Match scrut ret_opt [(pat, br)] -> let tl = split_conjunctions br in map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl | _ -> (* Not of the proper shape: return the original term *) [t] val split_assert_conjs : bool -> exploration_result term -> Tac unit let split_assert_conjs dbg res = let ge0 = res.ge in (* Simplify the term (it may be an abstraction applied to some parameters) *) let t = norm_term_env ge0.env simpl_norm_steps res.res in (* Split the conjunctions *) let conjs = split_conjunctions t in (* If there is only one conjunction, check if it is of the following form * and try to split: * [> let Construct x1 .. xn = x in A1 /\ ... /\ Am *) let conjs = if List.length conjs = 1 then split_conjunctions_under_match dbg t else conjs in let asserts = mk_assertions conjs [] in (* Print *) printout_success ge0 asserts [@plugin] val pp_split_assert_conjs : bool -> unit -> Tac unit let pp_split_assert_conjs dbg () = try let res = find_focused_assert_in_current_goal dbg in split_assert_conjs dbg res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err (*** Term unfolding in assert *) /// Unfold/rewrite a term in an assert. /// If the term is a (recursive) top-level identifier, unfold it. /// Otherwise look for an equality or a pure let-binding to replace it with. /// If the assert is an equality, unfold/rewrite only on the side chosen by the user. // TODO: use "kind" keyword rather than type above /// An equality kind noeq type eq_kind = | Eq_Dec : typ -> eq_kind (* = *) | Eq_Undec : typ -> eq_kind (* == *) | Eq_Hetero : typ -> typ -> eq_kind (* === *) /// Deconstruct an equality // We use our own construct because ``term_as_formula`` doesn't always work // TODO: update ``term_as_formula`` val is_eq : bool -> term -> Tac (option (eq_kind & term & term)) let is_eq dbg t = let t = remove_b2t t in print_dbg dbg ("[> is_eq: " ^ term_to_string t); let hd, params = collect_app t in print_dbg dbg ("- hd:\n" ^ term_to_string hd); print_dbg dbg ("- parameters:\n" ^ list_to_string (fun (x, y) -> term_to_string x) params); match inspect hd with | Tv_FVar fv -> begin match params with | [(a,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] -> if is_any_fvar a [`%Prims.op_Equality; `%Prims.equals; "Prims.op_Equals"] then Some ((Eq_Dec a), x, y) else if is_any_fvar a [`%Prims.eq2; "Prims.op_Equals_Equals"] then Some ((Eq_Undec a), x, y) else None | [(a,Q_Implicit);(b,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] -> if is_fvar a (`%Prims.op_Equals_Equals_Equals) then Some ((Eq_Hetero a b), x, y) else None | _ -> None end | _ -> None /// Reconstruct an equality val mk_eq : eq_kind -> term -> term -> Tot term let mk_eq k t1 t2 = match k with | Eq_Dec ty -> mk_app (`Prims.op_Equality) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)] | Eq_Undec ty -> mk_app (`Prims.eq2) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)] | Eq_Hetero ty1 ty2 -> mk_app Prims.(`( === )) [(ty1, Q_Implicit); (ty2, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: FStar.Reflection.V1.Formula.formula -> FStar.Tactics.Effect.Tac Prims.string
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Reflection.V1.Formula.formula", "FStar.Reflection.V1.Formula.comparison", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.Types.bv", "FStar.Stubs.Reflection.Types.typ", "FStar.Stubs.Reflection.Types.fv", "Prims.int", "Prims.string" ]
[]
false
true
false
false
false
let formula_construct (f: formula) : Tac string =
match f with | True_ -> "True_" | False_ -> "False_" | Comp _ _ _ -> "Comp" | And _ _ -> "And" | Or _ _ -> "Or" | Not _ -> "Not" | Implies _ _ -> "Implies" | Iff _ _ -> "Iff" | Forall _ _ _ -> "Forall" | Exists _ _ _ -> "Exists" | App _ _ -> "Apply" | Name _ -> "Name" | FV _ -> "FV" | IntLit _ -> "IntLit" | F_Unknown -> "F_Unknown"
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.mk_eq
val mk_eq : eq_kind -> term -> term -> Tot term
val mk_eq : eq_kind -> term -> term -> Tot term
let mk_eq k t1 t2 = match k with | Eq_Dec ty -> mk_app (`Prims.op_Equality) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)] | Eq_Undec ty -> mk_app (`Prims.eq2) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)] | Eq_Hetero ty1 ty2 -> mk_app Prims.(`( === )) [(ty1, Q_Implicit); (ty2, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)]
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 64, "end_line": 403, "start_col": 0, "start_line": 395 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging. val pp_explore_print_goal : unit -> Tac unit let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f () /// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which /// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*) val is_focus_on_term : term -> Tac bool let is_focus_on_term t = is_fvar t (`%focus_on_term) /// Check if a term is an assertion or an assumption and return its content /// if it is the case. val term_is_assert_or_assume : term -> Tac (option term) let term_is_assert_or_assume t = match inspect t with | Tv_App hd (a, Q_Explicit) -> if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume] then Some a else None | _ -> None /// Check if the given term view is of the form: 'let _ = focus_on_term in body' /// Returns 'body' if it is the case. val is_focused_term : term_view -> Tac (option term) let is_focused_term tv = match tv with | Tv_Let recf attrs _ _ def body -> if is_focus_on_term def then Some body else None | _ -> None noeq type exploration_result (a : Type)= { ge : genv; parents : list (genv & term_view); tgt_comp : option typ_or_comp; res : a; } let mk_exploration_result = Mkexploration_result let pred_explorer (a:Type) = genv -> list (genv & term_view) -> option typ_or_comp -> term_view -> Tac (option a) val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool -> explorer (option (exploration_result a)) let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t = if Some? acc then mfail "find_focused_term_explorer: non empty accumulator"; if dbg then begin print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t) end; match pred ge pl opt_c t with | Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort | None -> None, Continue val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result a)) let find_predicated_term #a pred dbg dfs ge pl opt_c t = fst (explore_term dbg dfs #(option (exploration_result a)) (find_predicated_term_explorer #a pred dbg) None ge pl opt_c t) val _is_focused_term_explorer : pred_explorer term let _is_focused_term_explorer ge pl opt_c tv = is_focused_term tv val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result term)) let find_focused_term dbg dfs ge pl opt_c t = find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_term_in_current_goal : bool -> Tac (exploration_result term) let find_focused_term_in_current_goal dbg = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); begin match find_focused_term dbg true ge [] c l with | Some res -> print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); res | None -> mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: " ^ term_to_string g) end | _ -> mfail "find_focused_term_in_current_goal: not a squashed equality" end /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term) let find_focused_assert_in_current_goal dbg = print_dbg dbg ("[> find_focused_assert_in_current_goal"); let res = find_focused_term_in_current_goal dbg in print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); (* Check that it is an assert or an assume, retrieve the assertion *) let res' = match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> let ge' = genv_push_bv res.ge bv0 ty false None in ({ res with res = fterm; ge = ge' }) | _ -> res in begin match term_is_assert_or_assume res'.res with | None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res) | Some tm -> { res' with res = tm } end (*** Analyze effectful term *) /// Analyze a term in order to print properly instantiated pre/postconditions /// and type conditions. /// with_globals states whether to analyze the target pre/post together with the /// focused term. val analyze_effectful_term : dbg:bool -> with_gpre:bool -> with_gpost:bool -> res:exploration_result term -> Tac unit let analyze_effectful_term dbg with_gpre with_gpost res = let ge = res.ge in let opt_c = res.tgt_comp in (* Analyze the effectful term and check whether it is a 'let' or not *) let ge1, studied_term, info, ret_bv, shadowed_bv, is_let = begin match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> (* Before pushing the binder, check if it shadows another variable. * If it is the case, we will need it to correctly output the pre * and post-assertions (because for the pre-assertions the variable * will not be shadowed yet, while it will be the case for the post- * assertions) *) print_dbg dbg ("Restraining to: " ^ term_to_string fterm); let shadowed_bv : option bv = match genv_get_from_name ge (name_of_bv bv0) with | None -> None | Some (sbv, _) -> Some (fst sbv) in let ge1 = genv_push_bv ge bv0 ty false None in (* If the bv name is "uu___", introduce a fresh variable and use it instead: * the underscore might have been introduced when desugaring a let using * tuples. If doing that is not necessary, the introduced variable will * not appear in the generated assertions anyway. *) let ge2, (bv1 : bv) = let bvv0 = inspect_bv bv0 in let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *) then genv_push_fresh_bv ge1 "ret" ty else ge1, bv0 in let info = compute_eterm_info dbg ge2.env fterm in (ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true) | _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false) end in print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term); print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1); (* Check if the considered term is an assert, in which case we will only * display the precondition (otherwise we introduce too many assertions * in the context) *) let is_assert = Some? (term_is_assert_or_assume studied_term) in (* Instantiate the refinements *) (* TODO: use bv rather than term for ret_arg *) let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in let parents = List.Tot.map snd res.parents in let ge2, asserts = eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let is_assert info ret_arg opt_c parents [] in (* Simplify and filter *) let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in (* Introduce fresh variables for the shadowed ones and substitute *) let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in (* If not a let, insert all the assertions before the term *) let asserts = if is_let then asserts else mk_assertions (List.Tot.append asserts.pres asserts.posts) [] in (* Print *) printout_success ge3 asserts [@plugin] val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit let pp_analyze_effectful_term dbg with_gpre with_gpost () = try let res = find_focused_term_in_current_goal dbg in analyze_effectful_term dbg with_gpre with_gpost res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err (*** Split conjunctions *) /// Split an assert made of conjunctions so that there is one assert per /// conjunction. We try to be a bit smart. For instance, if the assertion is of /// the form: /// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An); /// We generate: /// [> assert(let Construct x1 ... xn = e in A1); /// [> ... /// [> assert(let Construct x1 ... xn = e in An); /// Remove ``b2t`` if it is the head of the term val remove_b2t : term -> Tac term let remove_b2t (t:term) : Tac term = match inspect t with | Tv_App hd (a, Q_Explicit) -> begin match inspect hd with | Tv_FVar fv -> if fv_eq_name fv b2t_qn then a else t | _ -> t end | _ -> t // TODO: gather all the functions like split_conjunctions, is_eq... /// Try to destruct a term of the form '_ && _' or '_ /\ _' val is_conjunction : term -> Tac (option (term & term)) let is_conjunction t = let t = remove_b2t t in let hd, params = collect_app t in match params with | [(x,Q_Explicit);(y,Q_Explicit)] -> begin match inspect hd with | Tv_FVar fv -> let fvn = inspect_fv fv in if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"] then Some (x, y) else None | _ -> None end | _ -> None val split_conjunctions : term -> Tac (list term) let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) = match is_conjunction t with | None -> t :: ls | Some (l, r) -> let ls1 = _split_conjunctions ls r in let ls2 = _split_conjunctions ls1 l in ls2 let split_conjunctions t = _split_conjunctions [] t /// Split a term of the form: /// [> let Constuct x1 ... xn = x in A1 /\ ... /\ Am /// into m terms: /// [> let Constuct x1 ... xn = x in A1 /// ... /// [> let Constuct x1 ... xn = x in Am val split_conjunctions_under_match : bool -> term -> Tac (list term) let split_conjunctions_under_match dbg t = let t1 = remove_b2t t in print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1); match inspect t1 with | Tv_Match scrut ret_opt [(pat, br)] -> let tl = split_conjunctions br in map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl | _ -> (* Not of the proper shape: return the original term *) [t] val split_assert_conjs : bool -> exploration_result term -> Tac unit let split_assert_conjs dbg res = let ge0 = res.ge in (* Simplify the term (it may be an abstraction applied to some parameters) *) let t = norm_term_env ge0.env simpl_norm_steps res.res in (* Split the conjunctions *) let conjs = split_conjunctions t in (* If there is only one conjunction, check if it is of the following form * and try to split: * [> let Construct x1 .. xn = x in A1 /\ ... /\ Am *) let conjs = if List.length conjs = 1 then split_conjunctions_under_match dbg t else conjs in let asserts = mk_assertions conjs [] in (* Print *) printout_success ge0 asserts [@plugin] val pp_split_assert_conjs : bool -> unit -> Tac unit let pp_split_assert_conjs dbg () = try let res = find_focused_assert_in_current_goal dbg in split_assert_conjs dbg res; end_proof () with | MetaAnalysis msg -> printout_failure msg; end_proof () | err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err (*** Term unfolding in assert *) /// Unfold/rewrite a term in an assert. /// If the term is a (recursive) top-level identifier, unfold it. /// Otherwise look for an equality or a pure let-binding to replace it with. /// If the assert is an equality, unfold/rewrite only on the side chosen by the user. // TODO: use "kind" keyword rather than type above /// An equality kind noeq type eq_kind = | Eq_Dec : typ -> eq_kind (* = *) | Eq_Undec : typ -> eq_kind (* == *) | Eq_Hetero : typ -> typ -> eq_kind (* === *) /// Deconstruct an equality // We use our own construct because ``term_as_formula`` doesn't always work // TODO: update ``term_as_formula`` val is_eq : bool -> term -> Tac (option (eq_kind & term & term)) let is_eq dbg t = let t = remove_b2t t in print_dbg dbg ("[> is_eq: " ^ term_to_string t); let hd, params = collect_app t in print_dbg dbg ("- hd:\n" ^ term_to_string hd); print_dbg dbg ("- parameters:\n" ^ list_to_string (fun (x, y) -> term_to_string x) params); match inspect hd with | Tv_FVar fv -> begin match params with | [(a,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] -> if is_any_fvar a [`%Prims.op_Equality; `%Prims.equals; "Prims.op_Equals"] then Some ((Eq_Dec a), x, y) else if is_any_fvar a [`%Prims.eq2; "Prims.op_Equals_Equals"] then Some ((Eq_Undec a), x, y) else None | [(a,Q_Implicit);(b,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] -> if is_fvar a (`%Prims.op_Equals_Equals_Equals) then Some ((Eq_Hetero a b), x, y) else None | _ -> None end | _ -> None /// Reconstruct an equality
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k: FStar.InteractiveHelpers.PostProcess.eq_kind -> t1: FStar.Stubs.Reflection.Types.term -> t2: FStar.Stubs.Reflection.Types.term -> FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.InteractiveHelpers.PostProcess.eq_kind", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.Types.typ", "FStar.Reflection.V1.Derived.mk_app", "Prims.Cons", "FStar.Stubs.Reflection.V1.Data.argv", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.V1.Data.aqualv", "FStar.Stubs.Reflection.V1.Data.Q_Implicit", "FStar.Stubs.Reflection.V1.Data.Q_Explicit", "Prims.Nil" ]
[]
false
false
false
true
false
let mk_eq k t1 t2 =
match k with | Eq_Dec ty -> mk_app (`Prims.op_Equality) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)] | Eq_Undec ty -> mk_app (`Prims.eq2) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)] | Eq_Hetero ty1 ty2 -> mk_app Prims.(`( === )) [(ty1, Q_Implicit); (ty2, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)]
false
FStar.InteractiveHelpers.PostProcess.fst
FStar.InteractiveHelpers.PostProcess.analyze_effectful_term
val analyze_effectful_term : dbg:bool -> with_gpre:bool -> with_gpost:bool -> res:exploration_result term -> Tac unit
val analyze_effectful_term : dbg:bool -> with_gpre:bool -> with_gpost:bool -> res:exploration_result term -> Tac unit
let analyze_effectful_term dbg with_gpre with_gpost res = let ge = res.ge in let opt_c = res.tgt_comp in (* Analyze the effectful term and check whether it is a 'let' or not *) let ge1, studied_term, info, ret_bv, shadowed_bv, is_let = begin match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> (* Before pushing the binder, check if it shadows another variable. * If it is the case, we will need it to correctly output the pre * and post-assertions (because for the pre-assertions the variable * will not be shadowed yet, while it will be the case for the post- * assertions) *) print_dbg dbg ("Restraining to: " ^ term_to_string fterm); let shadowed_bv : option bv = match genv_get_from_name ge (name_of_bv bv0) with | None -> None | Some (sbv, _) -> Some (fst sbv) in let ge1 = genv_push_bv ge bv0 ty false None in (* If the bv name is "uu___", introduce a fresh variable and use it instead: * the underscore might have been introduced when desugaring a let using * tuples. If doing that is not necessary, the introduced variable will * not appear in the generated assertions anyway. *) let ge2, (bv1 : bv) = let bvv0 = inspect_bv bv0 in let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *) then genv_push_fresh_bv ge1 "ret" ty else ge1, bv0 in let info = compute_eterm_info dbg ge2.env fterm in (ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true) | _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false) end in print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term); print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1); (* Check if the considered term is an assert, in which case we will only * display the precondition (otherwise we introduce too many assertions * in the context) *) let is_assert = Some? (term_is_assert_or_assume studied_term) in (* Instantiate the refinements *) (* TODO: use bv rather than term for ret_arg *) let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in let parents = List.Tot.map snd res.parents in let ge2, asserts = eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let is_assert info ret_arg opt_c parents [] in (* Simplify and filter *) let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in (* Introduce fresh variables for the shadowed ones and substitute *) let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in (* If not a let, insert all the assertions before the term *) let asserts = if is_let then asserts else mk_assertions (List.Tot.append asserts.pres asserts.posts) [] in (* Print *) printout_success ge3 asserts
{ "file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 241, "start_col": 0, "start_line": 183 }
module FStar.InteractiveHelpers.PostProcess open FStar.List open FStar.Tactics open FStar.Mul open FStar.InteractiveHelpers.Base open FStar.InteractiveHelpers.ExploreTerm open FStar.InteractiveHelpers.Propositions open FStar.InteractiveHelpers.Effectful open FStar.InteractiveHelpers.Output /// The high-level post-processing tactics, used to retrieve some specific /// information from the context and generate output which can be exploited /// on the IDE side. #push-options "--z3rlimit 15 --fuel 0 --ifuel 1" (*** General utilities *) /// We declare some identifiers that we will use to guide the meta processing assume type meta_info assume val focus_on_term : meta_info let end_proof () = tadmit_t (`()) let unsquash_equality (t:term) : Tac (option (term & term)) = begin match term_as_formula t with | Comp (Eq _) l r -> Some (l, r) | _ -> None end #push-options "--ifuel 2" let pp_explore (dbg dfs : bool) (#a : Type0) (f : explorer a) (x : a) : Tac unit = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); let x = explore_term dbg dfs #a f x ge [] c l in end_proof () | _ -> mfail "pp_explore: not a squashed equality" end #pop-options /// This function goes through the goal, which is presumed to be a squashed equality, /// and prints all the subterms of its left operand. Very useful for debugging. val pp_explore_print_goal : unit -> Tac unit let pp_explore_print_goal () = let f : explorer unit = fun _ _ _ _ _ -> ((), Continue) in pp_explore true false f () /// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which /// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*) val is_focus_on_term : term -> Tac bool let is_focus_on_term t = is_fvar t (`%focus_on_term) /// Check if a term is an assertion or an assumption and return its content /// if it is the case. val term_is_assert_or_assume : term -> Tac (option term) let term_is_assert_or_assume t = match inspect t with | Tv_App hd (a, Q_Explicit) -> if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume] then Some a else None | _ -> None /// Check if the given term view is of the form: 'let _ = focus_on_term in body' /// Returns 'body' if it is the case. val is_focused_term : term_view -> Tac (option term) let is_focused_term tv = match tv with | Tv_Let recf attrs _ _ def body -> if is_focus_on_term def then Some body else None | _ -> None noeq type exploration_result (a : Type)= { ge : genv; parents : list (genv & term_view); tgt_comp : option typ_or_comp; res : a; } let mk_exploration_result = Mkexploration_result let pred_explorer (a:Type) = genv -> list (genv & term_view) -> option typ_or_comp -> term_view -> Tac (option a) val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool -> explorer (option (exploration_result a)) let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t = if Some? acc then mfail "find_focused_term_explorer: non empty accumulator"; if dbg then begin print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t) end; match pred ge pl opt_c t with | Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort | None -> None, Continue val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result a)) let find_predicated_term #a pred dbg dfs ge pl opt_c t = fst (explore_term dbg dfs #(option (exploration_result a)) (find_predicated_term_explorer #a pred dbg) None ge pl opt_c t) val _is_focused_term_explorer : pred_explorer term let _is_focused_term_explorer ge pl opt_c tv = is_focused_term tv val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term -> Tac (option (exploration_result term)) let find_focused_term dbg dfs ge pl opt_c t = find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_term_in_current_goal : bool -> Tac (exploration_result term) let find_focused_term_in_current_goal dbg = let g = cur_goal () in let e = cur_env () in print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g); begin match unsquash_equality g with | Some (l, _) -> let c = safe_typ_or_comp dbg e l in let ge = mk_genv e [] [] in print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l); begin match find_focused_term dbg true ge [] c l with | Some res -> print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); res | None -> mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: " ^ term_to_string g) end | _ -> mfail "find_focused_term_in_current_goal: not a squashed equality" end /// This function raises a MetaAnalysis exception if it can't find a focused term val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term) let find_focused_assert_in_current_goal dbg = print_dbg dbg ("[> find_focused_assert_in_current_goal"); let res = find_focused_term_in_current_goal dbg in print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res); (* Check that it is an assert or an assume, retrieve the assertion *) let res' = match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> let ge' = genv_push_bv res.ge bv0 ty false None in ({ res with res = fterm; ge = ge' }) | _ -> res in begin match term_is_assert_or_assume res'.res with | None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res) | Some tm -> { res' with res = tm } end (*** Analyze effectful term *) /// Analyze a term in order to print properly instantiated pre/postconditions /// and type conditions. /// with_globals states whether to analyze the target pre/post together with the /// focused term. val analyze_effectful_term : dbg:bool -> with_gpre:bool -> with_gpost:bool -> res:exploration_result term -> Tac unit
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.InteractiveHelpers.Propositions.fst.checked", "FStar.InteractiveHelpers.Output.fst.checked", "FStar.InteractiveHelpers.ExploreTerm.fst.checked", "FStar.InteractiveHelpers.Effectful.fst.checked", "FStar.InteractiveHelpers.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.InteractiveHelpers.PostProcess.fst" }
[ { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Output", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Effectful", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Propositions", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.ExploreTerm", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.List", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.InteractiveHelpers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
dbg: Prims.bool -> with_gpre: Prims.bool -> with_gpost: Prims.bool -> res: FStar.InteractiveHelpers.PostProcess.exploration_result FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.bool", "FStar.InteractiveHelpers.PostProcess.exploration_result", "FStar.Stubs.Reflection.Types.term", "FStar.InteractiveHelpers.Base.genv", "FStar.InteractiveHelpers.Effectful.eterm_info", "FStar.Pervasives.Native.option", "FStar.Stubs.Reflection.Types.bv", "FStar.InteractiveHelpers.Propositions.assertions", "FStar.InteractiveHelpers.Output.printout_success", "Prims.unit", "FStar.InteractiveHelpers.Propositions.mk_assertions", "FStar.List.Tot.Base.append", "FStar.InteractiveHelpers.Propositions.proposition", "FStar.InteractiveHelpers.Propositions.__proj__Mkassertions__item__pres", "FStar.InteractiveHelpers.Propositions.__proj__Mkassertions__item__posts", "Prims.Nil", "FStar.Pervasives.Native.tuple2", "FStar.InteractiveHelpers.Output.subst_shadowed_with_abs_in_assertions", "FStar.InteractiveHelpers.Propositions.simp_filter_assertions", "FStar.InteractiveHelpers.Base.__proj__Mkgenv__item__env", "FStar.InteractiveHelpers.Propositions.simpl_norm_steps", "FStar.InteractiveHelpers.Effectful.eterm_info_to_assertions", "FStar.Stubs.Reflection.V1.Data.term_view", "Prims.list", "FStar.List.Tot.Base.map", "FStar.Pervasives.Native.snd", "FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__parents", "FStar.InteractiveHelpers.Base.opt_tapply", "FStar.Stubs.Tactics.V1.Builtins.pack", "FStar.Stubs.Reflection.V1.Data.Tv_Var", "FStar.Pervasives.Native.uu___is_Some", "FStar.InteractiveHelpers.PostProcess.term_is_assert_or_assume", "FStar.InteractiveHelpers.Base.print_dbg", "Prims.string", "Prims.op_Hat", "FStar.InteractiveHelpers.Base.genv_to_string", "FStar.InteractiveHelpers.Base.term_construct", "FStar.Pervasives.Native.tuple6", "FStar.Stubs.Reflection.Types.typ", "FStar.Pervasives.Native.Mktuple6", "FStar.Pervasives.Native.Some", "FStar.InteractiveHelpers.Effectful.compute_eterm_info", "FStar.InteractiveHelpers.Base.genv_push_fresh_bv", "FStar.Pervasives.Native.Mktuple2", "Prims.op_Equality", "FStar.Tactics.Unseal.unseal", "FStar.Stubs.Reflection.V1.Data.__proj__Mkbv_view__item__bv_ppname", "FStar.InteractiveHelpers.Base.abv_to_string", "FStar.Stubs.Reflection.V1.Data.bv_view", "Prims.precedes", "FStar.Stubs.Reflection.V1.Builtins.inspect_bv", "FStar.InteractiveHelpers.Base.genv_push_bv", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.fst", "FStar.InteractiveHelpers.Base.genv_get_from_name", "FStar.Tactics.V1.Derived.name_of_bv", "FStar.Stubs.Tactics.V1.Builtins.term_to_string", "FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__res", "FStar.Stubs.Tactics.V1.Builtins.inspect", "FStar.InteractiveHelpers.ExploreTerm.typ_or_comp", "FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__tgt_comp", "FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__ge" ]
[]
false
true
false
false
false
let analyze_effectful_term dbg with_gpre with_gpost res =
let ge = res.ge in let opt_c = res.tgt_comp in let ge1, studied_term, info, ret_bv, shadowed_bv, is_let = match inspect res.res with | Tv_Let _ _ bv0 ty fterm _ -> print_dbg dbg ("Restraining to: " ^ term_to_string fterm); let shadowed_bv:option bv = match genv_get_from_name ge (name_of_bv bv0) with | None -> None | Some (sbv, _) -> Some (fst sbv) in let ge1 = genv_push_bv ge bv0 ty false None in let ge2, (bv1: bv) = let bvv0 = inspect_bv bv0 in let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in if unseal bvv0.bv_ppname = "uu___" then genv_push_fresh_bv ge1 "ret" ty else ge1, bv0 in let info = compute_eterm_info dbg ge2.env fterm in (ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true) | _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false) in print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term); print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1); let is_assert = Some? (term_is_assert_or_assume studied_term) in let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in let parents = List.Tot.map snd res.parents in let ge2, asserts = eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let is_assert info ret_arg opt_c parents [] in let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in let asserts = if is_let then asserts else mk_assertions (List.Tot.append asserts.pres asserts.posts) [] in printout_success ge3 asserts
false
Vale.Transformers.Locations.fsti
Vale.Transformers.Locations.location_eq
val location_eq : Type0
let location_eq = l:location{location_val_t l == FStar.Universe.raise_t (location_val_eqt l)}
{ "file_name": "vale/code/lib/transformers/Vale.Transformers.Locations.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 93, "end_line": 74, "start_col": 0, "start_line": 74 }
module Vale.Transformers.Locations open Vale.X64.Bytes_Code_s open Vale.X64.Instruction_s open Vale.X64.Instructions_s open Vale.X64.Machine_Semantics_s open Vale.X64.Machine_s open Vale.X64.Print_s open Vale.Def.PossiblyMonad module L = FStar.List.Tot (** An [location] is a portion of the [machine_state] that may be independently modified and/or accessed. *) val location : eqtype unfold type locations = list location (** [disjoint_location a1 a2] is true whenever locations [a1] and [a2] are disjoint. When not disjoint, it gives a reason for why not. *) val disjoint_location : location -> location -> pbool (** Disjointness is the same as syntactic equality on the locations. *) val auto_lemma_disjoint_location : a1:location -> a2:location -> Lemma (ensures (!!(disjoint_location a1 a2) = (a1 <> a2))) [SMTPat (!!(disjoint_location a1 a2))] (** Disjointness of a [location] from [locations] *) let disjoint_location_from_locations (a:location) (l:locations) : pbool = for_all (fun b -> disjoint_location a b ) l (** Disjointness of [locations] *) let disjoint_locations (l1 l2:locations) : pbool = for_all (fun x -> disjoint_location_from_locations x l2 ) l1 (** [disjoint_locations] is symmetric *) let rec lemma_disjoint_locations_symmetric l1 l2 : Lemma (ensures ( (!!(disjoint_locations l1 l2) = !!(disjoint_locations l2 l1)))) (decreases %[L.length l1 + L.length l2]) = match l1, l2 with | [], [] -> () | [], x :: xs | x :: xs, [] -> lemma_disjoint_locations_symmetric xs [] | x :: xs, y :: ys -> lemma_disjoint_locations_symmetric l1 ys; lemma_disjoint_locations_symmetric xs l2; lemma_disjoint_locations_symmetric xs ys (** Inversion lemma based on FStar.Universe.downgrade_val_raise_val, with more liberal SMTPat *) val downgrade_val_raise_val_u0_u1 : #a:Type0 -> x:a -> Lemma (ensures FStar.Universe.downgrade_val u#0 u#1 (FStar.Universe.raise_val x) == x) [SMTPat (FStar.Universe.raise_val x)] (** [location_val_t a] is the type of the value represented by the location [a]. *) val location_val_t : location -> Type u#1 (** Same as location_val_t in cases where location_val_t is an eqtype, otherwise arbitrary *) val location_val_eqt : location -> eqtype
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instructions_s.fsti.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Def.PossiblyMonad.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "Vale.Transformers.Locations.fsti" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Vale.Def.PossiblyMonad", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Print_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instructions_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Vale.Def.PossiblyMonad", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Print_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instructions_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Vale.Transformers.Locations.location", "Prims.eq2", "Vale.Transformers.Locations.location_val_t", "FStar.Universe.raise_t", "Vale.Transformers.Locations.location_val_eqt" ]
[]
false
false
false
true
true
let location_eq =
l: location{location_val_t l == FStar.Universe.raise_t (location_val_eqt l)}
false
Vale.Transformers.Locations.fsti
Vale.Transformers.Locations.disjoint_location_from_locations
val disjoint_location_from_locations (a: location) (l: locations) : pbool
val disjoint_location_from_locations (a: location) (l: locations) : pbool
let disjoint_location_from_locations (a:location) (l:locations) : pbool = for_all (fun b -> disjoint_location a b ) l
{ "file_name": "vale/code/lib/transformers/Vale.Transformers.Locations.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 7, "end_line": 36, "start_col": 0, "start_line": 33 }
module Vale.Transformers.Locations open Vale.X64.Bytes_Code_s open Vale.X64.Instruction_s open Vale.X64.Instructions_s open Vale.X64.Machine_Semantics_s open Vale.X64.Machine_s open Vale.X64.Print_s open Vale.Def.PossiblyMonad module L = FStar.List.Tot (** An [location] is a portion of the [machine_state] that may be independently modified and/or accessed. *) val location : eqtype unfold type locations = list location (** [disjoint_location a1 a2] is true whenever locations [a1] and [a2] are disjoint. When not disjoint, it gives a reason for why not. *) val disjoint_location : location -> location -> pbool (** Disjointness is the same as syntactic equality on the locations. *) val auto_lemma_disjoint_location : a1:location -> a2:location -> Lemma (ensures (!!(disjoint_location a1 a2) = (a1 <> a2))) [SMTPat (!!(disjoint_location a1 a2))]
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instructions_s.fsti.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Def.PossiblyMonad.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "Vale.Transformers.Locations.fsti" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Vale.Def.PossiblyMonad", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Print_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instructions_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Vale.Def.PossiblyMonad", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Print_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instructions_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Transformers.Locations.location -> l: Vale.Transformers.Locations.locations -> Vale.Def.PossiblyMonad.pbool
Prims.Tot
[ "total" ]
[]
[ "Vale.Transformers.Locations.location", "Vale.Transformers.Locations.locations", "Vale.Def.PossiblyMonad.for_all", "Vale.Transformers.Locations.disjoint_location", "Vale.Def.PossiblyMonad.pbool" ]
[]
false
false
false
true
false
let disjoint_location_from_locations (a: location) (l: locations) : pbool =
for_all (fun b -> disjoint_location a b) l
false
Vale.Transformers.Locations.fsti
Vale.Transformers.Locations.disjoint_locations
val disjoint_locations (l1 l2: locations) : pbool
val disjoint_locations (l1 l2: locations) : pbool
let disjoint_locations (l1 l2:locations) : pbool = for_all (fun x -> disjoint_location_from_locations x l2 ) l1
{ "file_name": "vale/code/lib/transformers/Vale.Transformers.Locations.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 6, "end_line": 42, "start_col": 0, "start_line": 39 }
module Vale.Transformers.Locations open Vale.X64.Bytes_Code_s open Vale.X64.Instruction_s open Vale.X64.Instructions_s open Vale.X64.Machine_Semantics_s open Vale.X64.Machine_s open Vale.X64.Print_s open Vale.Def.PossiblyMonad module L = FStar.List.Tot (** An [location] is a portion of the [machine_state] that may be independently modified and/or accessed. *) val location : eqtype unfold type locations = list location (** [disjoint_location a1 a2] is true whenever locations [a1] and [a2] are disjoint. When not disjoint, it gives a reason for why not. *) val disjoint_location : location -> location -> pbool (** Disjointness is the same as syntactic equality on the locations. *) val auto_lemma_disjoint_location : a1:location -> a2:location -> Lemma (ensures (!!(disjoint_location a1 a2) = (a1 <> a2))) [SMTPat (!!(disjoint_location a1 a2))] (** Disjointness of a [location] from [locations] *) let disjoint_location_from_locations (a:location) (l:locations) : pbool = for_all (fun b -> disjoint_location a b ) l
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instructions_s.fsti.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Def.PossiblyMonad.fst.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "Vale.Transformers.Locations.fsti" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Vale.Def.PossiblyMonad", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Print_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instructions_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Vale.Def.PossiblyMonad", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Print_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instructions_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l1: Vale.Transformers.Locations.locations -> l2: Vale.Transformers.Locations.locations -> Vale.Def.PossiblyMonad.pbool
Prims.Tot
[ "total" ]
[]
[ "Vale.Transformers.Locations.locations", "Vale.Def.PossiblyMonad.for_all", "Vale.Transformers.Locations.location", "Vale.Transformers.Locations.disjoint_location_from_locations", "Vale.Def.PossiblyMonad.pbool" ]
[]
false
false
false
true
false
let disjoint_locations (l1 l2: locations) : pbool =
for_all (fun x -> disjoint_location_from_locations x l2) l1
false