effect
stringclasses
48 values
original_source_type
stringlengths
0
23k
opens_and_abbrevs
listlengths
2
92
isa_cross_project_example
bool
1 class
source_definition
stringlengths
9
57.9k
partial_definition
stringlengths
7
23.3k
is_div
bool
2 classes
is_type
null
is_proof
bool
2 classes
completed_definiton
stringlengths
1
250k
dependencies
dict
effect_flags
sequencelengths
0
2
ideal_premises
sequencelengths
0
236
mutual_with
sequencelengths
0
11
file_context
stringlengths
0
407k
interleaved
bool
1 class
is_simply_typed
bool
2 classes
file_name
stringlengths
5
48
vconfig
dict
is_simple_lemma
null
source_type
stringlengths
10
23k
proof_features
sequencelengths
0
1
name
stringlengths
8
95
source
dict
verbose_type
stringlengths
1
7.42k
source_range
dict
Prims.Tot
val fmul_be_f: #f:field -> x:felem f -> i:nat{i < bits f.t} -> res_y:tuple2 (felem f) (felem f) -> felem f & felem f
[ { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let fmul_be_f #f x i (res, y) = let res = mask_add x y res i in let y = mask_shift_right_mod y in (res, y)
val fmul_be_f: #f:field -> x:felem f -> i:nat{i < bits f.t} -> res_y:tuple2 (felem f) (felem f) -> felem f & felem f let fmul_be_f #f x i (res, y) =
false
null
false
let res = mask_add x y res i in let y = mask_shift_right_mod y in (res, y)
{ "checked_file": "Spec.GaloisField.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Spec.GaloisField.fst" }
[ "total" ]
[ "Spec.GaloisField.field", "Spec.GaloisField.felem", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.bits", "Spec.GaloisField.__proj__GF__item__t", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2", "Prims.eq2", "Lib.IntTypes.int_t", "Lib.IntTypes.SEC", "Prims.op_Equality", "Prims.int", "Lib.IntTypes.v", "Spec.GaloisField.get_ith_bit", "Prims.op_Subtraction", "Spec.GaloisField.fadd", "Lib.IntTypes.shift_right", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Spec.GaloisField.__proj__GF__item__irred", "Prims.bool", "Spec.GaloisField.mask_shift_right_mod", "Spec.GaloisField.mask_add" ]
[]
module Spec.GaloisField open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Lib.ByteSequence (* We represent GF(2^n) by uint_t along with some irreducible polynomial also of type uint_t *) (* Consequently this module is specialized for GF(8/16/32/64/128) but can be generalized to other sizes if needed *) #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0" noeq type field = | GF: t:inttype{unsigned t /\ t <> U1} -> irred: uint_t t SEC -> field let gf t irred = GF t irred type felem (f:field) = uint_t f.t SEC let to_felem (#f:field) (n:nat{n <= maxint f.t}) : felem f = uint #f.t #SEC n let from_felem (#f:field) (e:felem f) : n:nat{n <= maxint f.t} = uint_v #f.t #SEC e let zero (#f:field) : felem f = to_felem 0 let one (#f:field) : felem f = to_felem 1 let load_felem_be (#f:field) (b:lbytes (numbytes f.t)) : felem f = uint_from_bytes_be #f.t #SEC b let store_felem_be (#f:field) (e:felem f): lbytes (numbytes f.t) = uint_to_bytes_be #f.t #SEC e let reverse (#t:inttype{unsigned t}) (a:uint_t t SEC) : uint_t t SEC = repeati (bits t) (fun i u -> u |. (((a >>. size i) &. uint #t #SEC 1) <<. (size (bits t - 1 - i)))) (uint #t #SEC 0) let load_felem_le (#f:field) (b:lbytes (numbytes f.t)) : felem f = reverse #f.t (load_felem_be #f b) let store_felem_le (#f:field) (e:felem f) : lbytes (numbytes f.t) = store_felem_be #f (reverse #f.t e) let fadd (#f:field) (a:felem f) (b:felem f) : felem f = a ^. b let op_Plus_At #f e1 e2 = fadd #f e1 e2 let fmul (#f:field) (a:felem f) (b:felem f) : felem f = let one = one #f in let zero = zero #f in let (p,a,b) = repeati (bits f.t - 1) (fun i (p,a,b) -> let b0 = eq_mask #f.t (b &. one) one in let p = p ^. (b0 &. a) in let carry_mask = eq_mask #f.t (a >>. size (bits f.t - 1)) one in let a = a <<. size 1 in let a = a ^. (carry_mask &. f.irred) in let b = b >>. size 1 in (p,a,b)) (zero,a,b) in let b0 = eq_mask #f.t (b &. one) one in let p = p ^. (b0 &. a) in p let op_Star_At #f e1 e2 = fmul #f e1 e2 val get_ith_bit: #f:field -> x:felem f -> i:nat{i < bits f.t} -> Tot (r:felem f{v r == v x / pow2 (bits f.t - 1 - i) % 2}) let get_ith_bit #f x i = logand_mask (x >>. size (bits f.t - 1 - i)) one 1; (x >>. size (bits f.t - 1 - i)) &. one val mask_add: #f:field -> x:felem f -> y:felem f -> res:felem f -> i:nat{i < bits f.t} -> Tot (r:felem f{r == (if v (get_ith_bit x i) = 1 then res `fadd` y else res)}) let mask_add #f x y res i = logxor_lemma res zero; res `fadd` (y &. eq_mask #f.t (get_ith_bit x i) one) val mask_shift_right_mod: #f:field -> y:felem f -> Tot (r:felem f{r == (if v (get_ith_bit y (bits f.t - 1)) = 1 then (y >>. 1ul) `fadd` f.irred else (y >>. 1ul))}) let mask_shift_right_mod #f y = logxor_lemma (y >>. 1ul) zero; (y >>. 1ul) `fadd` (f.irred &. eq_mask #f.t (get_ith_bit y (bits f.t - 1)) one)
false
false
Spec.GaloisField.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val fmul_be_f: #f:field -> x:felem f -> i:nat{i < bits f.t} -> res_y:tuple2 (felem f) (felem f) -> felem f & felem f
[]
Spec.GaloisField.fmul_be_f
{ "file_name": "specs/Spec.GaloisField.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
x: Spec.GaloisField.felem f -> i: Prims.nat{i < Lib.IntTypes.bits (GF?.t f)} -> res_y: (Spec.GaloisField.felem f * Spec.GaloisField.felem f) -> Spec.GaloisField.felem f * Spec.GaloisField.felem f
{ "end_col": 10, "end_line": 76, "start_col": 31, "start_line": 73 }
Prims.Tot
val store_felem_be (#f: field) (e: felem f) : lbytes (numbytes f.t)
[ { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let store_felem_be (#f:field) (e:felem f): lbytes (numbytes f.t) = uint_to_bytes_be #f.t #SEC e
val store_felem_be (#f: field) (e: felem f) : lbytes (numbytes f.t) let store_felem_be (#f: field) (e: felem f) : lbytes (numbytes f.t) =
false
null
false
uint_to_bytes_be #f.t #SEC e
{ "checked_file": "Spec.GaloisField.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Spec.GaloisField.fst" }
[ "total" ]
[ "Spec.GaloisField.field", "Spec.GaloisField.felem", "Lib.ByteSequence.uint_to_bytes_be", "Spec.GaloisField.__proj__GF__item__t", "Lib.IntTypes.SEC", "Lib.ByteSequence.lbytes", "Lib.IntTypes.numbytes" ]
[]
module Spec.GaloisField open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Lib.ByteSequence (* We represent GF(2^n) by uint_t along with some irreducible polynomial also of type uint_t *) (* Consequently this module is specialized for GF(8/16/32/64/128) but can be generalized to other sizes if needed *) #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0" noeq type field = | GF: t:inttype{unsigned t /\ t <> U1} -> irred: uint_t t SEC -> field let gf t irred = GF t irred type felem (f:field) = uint_t f.t SEC let to_felem (#f:field) (n:nat{n <= maxint f.t}) : felem f = uint #f.t #SEC n let from_felem (#f:field) (e:felem f) : n:nat{n <= maxint f.t} = uint_v #f.t #SEC e let zero (#f:field) : felem f = to_felem 0 let one (#f:field) : felem f = to_felem 1
false
false
Spec.GaloisField.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val store_felem_be (#f: field) (e: felem f) : lbytes (numbytes f.t)
[]
Spec.GaloisField.store_felem_be
{ "file_name": "specs/Spec.GaloisField.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
e: Spec.GaloisField.felem f -> Lib.ByteSequence.lbytes (Lib.IntTypes.numbytes (GF?.t f))
{ "end_col": 95, "end_line": 24, "start_col": 67, "start_line": 24 }
Prims.Tot
val load_felem_le (#f: field) (b: lbytes (numbytes f.t)) : felem f
[ { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let load_felem_le (#f:field) (b:lbytes (numbytes f.t)) : felem f = reverse #f.t (load_felem_be #f b)
val load_felem_le (#f: field) (b: lbytes (numbytes f.t)) : felem f let load_felem_le (#f: field) (b: lbytes (numbytes f.t)) : felem f =
false
null
false
reverse #f.t (load_felem_be #f b)
{ "checked_file": "Spec.GaloisField.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Spec.GaloisField.fst" }
[ "total" ]
[ "Spec.GaloisField.field", "Lib.ByteSequence.lbytes", "Lib.IntTypes.numbytes", "Spec.GaloisField.__proj__GF__item__t", "Spec.GaloisField.reverse", "Spec.GaloisField.load_felem_be", "Spec.GaloisField.felem" ]
[]
module Spec.GaloisField open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Lib.ByteSequence (* We represent GF(2^n) by uint_t along with some irreducible polynomial also of type uint_t *) (* Consequently this module is specialized for GF(8/16/32/64/128) but can be generalized to other sizes if needed *) #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0" noeq type field = | GF: t:inttype{unsigned t /\ t <> U1} -> irred: uint_t t SEC -> field let gf t irred = GF t irred type felem (f:field) = uint_t f.t SEC let to_felem (#f:field) (n:nat{n <= maxint f.t}) : felem f = uint #f.t #SEC n let from_felem (#f:field) (e:felem f) : n:nat{n <= maxint f.t} = uint_v #f.t #SEC e let zero (#f:field) : felem f = to_felem 0 let one (#f:field) : felem f = to_felem 1 let load_felem_be (#f:field) (b:lbytes (numbytes f.t)) : felem f = uint_from_bytes_be #f.t #SEC b let store_felem_be (#f:field) (e:felem f): lbytes (numbytes f.t) = uint_to_bytes_be #f.t #SEC e let reverse (#t:inttype{unsigned t}) (a:uint_t t SEC) : uint_t t SEC = repeati (bits t) (fun i u -> u |. (((a >>. size i) &. uint #t #SEC 1) <<. (size (bits t - 1 - i)))) (uint #t #SEC 0)
false
false
Spec.GaloisField.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val load_felem_le (#f: field) (b: lbytes (numbytes f.t)) : felem f
[]
Spec.GaloisField.load_felem_le
{ "file_name": "specs/Spec.GaloisField.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Lib.ByteSequence.lbytes (Lib.IntTypes.numbytes (GF?.t f)) -> Spec.GaloisField.felem f
{ "end_col": 100, "end_line": 30, "start_col": 67, "start_line": 30 }
Prims.Tot
val store_felem_le (#f: field) (e: felem f) : lbytes (numbytes f.t)
[ { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let store_felem_le (#f:field) (e:felem f) : lbytes (numbytes f.t) = store_felem_be #f (reverse #f.t e)
val store_felem_le (#f: field) (e: felem f) : lbytes (numbytes f.t) let store_felem_le (#f: field) (e: felem f) : lbytes (numbytes f.t) =
false
null
false
store_felem_be #f (reverse #f.t e)
{ "checked_file": "Spec.GaloisField.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Spec.GaloisField.fst" }
[ "total" ]
[ "Spec.GaloisField.field", "Spec.GaloisField.felem", "Spec.GaloisField.store_felem_be", "Spec.GaloisField.reverse", "Spec.GaloisField.__proj__GF__item__t", "Lib.ByteSequence.lbytes", "Lib.IntTypes.numbytes" ]
[]
module Spec.GaloisField open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Lib.ByteSequence (* We represent GF(2^n) by uint_t along with some irreducible polynomial also of type uint_t *) (* Consequently this module is specialized for GF(8/16/32/64/128) but can be generalized to other sizes if needed *) #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0" noeq type field = | GF: t:inttype{unsigned t /\ t <> U1} -> irred: uint_t t SEC -> field let gf t irred = GF t irred type felem (f:field) = uint_t f.t SEC let to_felem (#f:field) (n:nat{n <= maxint f.t}) : felem f = uint #f.t #SEC n let from_felem (#f:field) (e:felem f) : n:nat{n <= maxint f.t} = uint_v #f.t #SEC e let zero (#f:field) : felem f = to_felem 0 let one (#f:field) : felem f = to_felem 1 let load_felem_be (#f:field) (b:lbytes (numbytes f.t)) : felem f = uint_from_bytes_be #f.t #SEC b let store_felem_be (#f:field) (e:felem f): lbytes (numbytes f.t) = uint_to_bytes_be #f.t #SEC e let reverse (#t:inttype{unsigned t}) (a:uint_t t SEC) : uint_t t SEC = repeati (bits t) (fun i u -> u |. (((a >>. size i) &. uint #t #SEC 1) <<. (size (bits t - 1 - i)))) (uint #t #SEC 0)
false
false
Spec.GaloisField.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val store_felem_le (#f: field) (e: felem f) : lbytes (numbytes f.t)
[]
Spec.GaloisField.store_felem_le
{ "file_name": "specs/Spec.GaloisField.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
e: Spec.GaloisField.felem f -> Lib.ByteSequence.lbytes (Lib.IntTypes.numbytes (GF?.t f))
{ "end_col": 102, "end_line": 31, "start_col": 68, "start_line": 31 }
Prims.Tot
val get_ith_bit: #f:field -> x:felem f -> i:nat{i < bits f.t} -> Tot (r:felem f{v r == v x / pow2 (bits f.t - 1 - i) % 2})
[ { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let get_ith_bit #f x i = logand_mask (x >>. size (bits f.t - 1 - i)) one 1; (x >>. size (bits f.t - 1 - i)) &. one
val get_ith_bit: #f:field -> x:felem f -> i:nat{i < bits f.t} -> Tot (r:felem f{v r == v x / pow2 (bits f.t - 1 - i) % 2}) let get_ith_bit #f x i =
false
null
false
logand_mask (x >>. size (bits f.t - 1 - i)) one 1; (x >>. size (bits f.t - 1 - i)) &. one
{ "checked_file": "Spec.GaloisField.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Spec.GaloisField.fst" }
[ "total" ]
[ "Spec.GaloisField.field", "Spec.GaloisField.felem", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.bits", "Spec.GaloisField.__proj__GF__item__t", "Lib.IntTypes.op_Amp_Dot", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Greater_Greater_Dot", "Lib.IntTypes.size", "Prims.op_Subtraction", "Spec.GaloisField.one", "Prims.unit", "Lib.IntTypes.logand_mask", "Prims.eq2", "Prims.int", "Lib.IntTypes.v", "Prims.op_Modulus", "Prims.op_Division", "Prims.pow2" ]
[]
module Spec.GaloisField open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Lib.ByteSequence (* We represent GF(2^n) by uint_t along with some irreducible polynomial also of type uint_t *) (* Consequently this module is specialized for GF(8/16/32/64/128) but can be generalized to other sizes if needed *) #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0" noeq type field = | GF: t:inttype{unsigned t /\ t <> U1} -> irred: uint_t t SEC -> field let gf t irred = GF t irred type felem (f:field) = uint_t f.t SEC let to_felem (#f:field) (n:nat{n <= maxint f.t}) : felem f = uint #f.t #SEC n let from_felem (#f:field) (e:felem f) : n:nat{n <= maxint f.t} = uint_v #f.t #SEC e let zero (#f:field) : felem f = to_felem 0 let one (#f:field) : felem f = to_felem 1 let load_felem_be (#f:field) (b:lbytes (numbytes f.t)) : felem f = uint_from_bytes_be #f.t #SEC b let store_felem_be (#f:field) (e:felem f): lbytes (numbytes f.t) = uint_to_bytes_be #f.t #SEC e let reverse (#t:inttype{unsigned t}) (a:uint_t t SEC) : uint_t t SEC = repeati (bits t) (fun i u -> u |. (((a >>. size i) &. uint #t #SEC 1) <<. (size (bits t - 1 - i)))) (uint #t #SEC 0) let load_felem_le (#f:field) (b:lbytes (numbytes f.t)) : felem f = reverse #f.t (load_felem_be #f b) let store_felem_le (#f:field) (e:felem f) : lbytes (numbytes f.t) = store_felem_be #f (reverse #f.t e) let fadd (#f:field) (a:felem f) (b:felem f) : felem f = a ^. b let op_Plus_At #f e1 e2 = fadd #f e1 e2 let fmul (#f:field) (a:felem f) (b:felem f) : felem f = let one = one #f in let zero = zero #f in let (p,a,b) = repeati (bits f.t - 1) (fun i (p,a,b) -> let b0 = eq_mask #f.t (b &. one) one in let p = p ^. (b0 &. a) in let carry_mask = eq_mask #f.t (a >>. size (bits f.t - 1)) one in let a = a <<. size 1 in let a = a ^. (carry_mask &. f.irred) in let b = b >>. size 1 in (p,a,b)) (zero,a,b) in let b0 = eq_mask #f.t (b &. one) one in let p = p ^. (b0 &. a) in p let op_Star_At #f e1 e2 = fmul #f e1 e2 val get_ith_bit: #f:field -> x:felem f -> i:nat{i < bits f.t} -> Tot (r:felem f{v r == v x / pow2 (bits f.t - 1 - i) % 2})
false
false
Spec.GaloisField.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val get_ith_bit: #f:field -> x:felem f -> i:nat{i < bits f.t} -> Tot (r:felem f{v r == v x / pow2 (bits f.t - 1 - i) % 2})
[]
Spec.GaloisField.get_ith_bit
{ "file_name": "specs/Spec.GaloisField.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
x: Spec.GaloisField.felem f -> i: Prims.nat{i < Lib.IntTypes.bits (GF?.t f)} -> r: Spec.GaloisField.felem f {Lib.IntTypes.v r == Lib.IntTypes.v x / Prims.pow2 (Lib.IntTypes.bits (GF?.t f) - 1 - i) % 2}
{ "end_col": 40, "end_line": 57, "start_col": 2, "start_line": 56 }
Prims.Tot
val load_felem_be (#f: field) (b: lbytes (numbytes f.t)) : felem f
[ { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let load_felem_be (#f:field) (b:lbytes (numbytes f.t)) : felem f = uint_from_bytes_be #f.t #SEC b
val load_felem_be (#f: field) (b: lbytes (numbytes f.t)) : felem f let load_felem_be (#f: field) (b: lbytes (numbytes f.t)) : felem f =
false
null
false
uint_from_bytes_be #f.t #SEC b
{ "checked_file": "Spec.GaloisField.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Spec.GaloisField.fst" }
[ "total" ]
[ "Spec.GaloisField.field", "Lib.ByteSequence.lbytes", "Lib.IntTypes.numbytes", "Spec.GaloisField.__proj__GF__item__t", "Lib.ByteSequence.uint_from_bytes_be", "Lib.IntTypes.SEC", "Spec.GaloisField.felem" ]
[]
module Spec.GaloisField open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Lib.ByteSequence (* We represent GF(2^n) by uint_t along with some irreducible polynomial also of type uint_t *) (* Consequently this module is specialized for GF(8/16/32/64/128) but can be generalized to other sizes if needed *) #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0" noeq type field = | GF: t:inttype{unsigned t /\ t <> U1} -> irred: uint_t t SEC -> field let gf t irred = GF t irred type felem (f:field) = uint_t f.t SEC let to_felem (#f:field) (n:nat{n <= maxint f.t}) : felem f = uint #f.t #SEC n let from_felem (#f:field) (e:felem f) : n:nat{n <= maxint f.t} = uint_v #f.t #SEC e let zero (#f:field) : felem f = to_felem 0 let one (#f:field) : felem f = to_felem 1
false
false
Spec.GaloisField.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val load_felem_be (#f: field) (b: lbytes (numbytes f.t)) : felem f
[]
Spec.GaloisField.load_felem_be
{ "file_name": "specs/Spec.GaloisField.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Lib.ByteSequence.lbytes (Lib.IntTypes.numbytes (GF?.t f)) -> Spec.GaloisField.felem f
{ "end_col": 97, "end_line": 23, "start_col": 67, "start_line": 23 }
Prims.Tot
val mask_shift_right_mod: #f:field -> y:felem f -> Tot (r:felem f{r == (if v (get_ith_bit y (bits f.t - 1)) = 1 then (y >>. 1ul) `fadd` f.irred else (y >>. 1ul))})
[ { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mask_shift_right_mod #f y = logxor_lemma (y >>. 1ul) zero; (y >>. 1ul) `fadd` (f.irred &. eq_mask #f.t (get_ith_bit y (bits f.t - 1)) one)
val mask_shift_right_mod: #f:field -> y:felem f -> Tot (r:felem f{r == (if v (get_ith_bit y (bits f.t - 1)) = 1 then (y >>. 1ul) `fadd` f.irred else (y >>. 1ul))}) let mask_shift_right_mod #f y =
false
null
false
logxor_lemma (y >>. 1ul) zero; (y >>. 1ul) `fadd` (f.irred &. eq_mask #f.t (get_ith_bit y (bits f.t - 1)) one)
{ "checked_file": "Spec.GaloisField.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Spec.GaloisField.fst" }
[ "total" ]
[ "Spec.GaloisField.field", "Spec.GaloisField.felem", "Spec.GaloisField.fadd", "Lib.IntTypes.op_Greater_Greater_Dot", "Spec.GaloisField.__proj__GF__item__t", "Lib.IntTypes.SEC", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.op_Amp_Dot", "Spec.GaloisField.__proj__GF__item__irred", "Lib.IntTypes.eq_mask", "Spec.GaloisField.get_ith_bit", "Prims.op_Subtraction", "Lib.IntTypes.bits", "Spec.GaloisField.one", "Prims.unit", "Lib.IntTypes.logxor_lemma", "Spec.GaloisField.zero", "Prims.eq2", "Lib.IntTypes.int_t", "Prims.op_Equality", "Prims.int", "Lib.IntTypes.v", "Prims.bool" ]
[]
module Spec.GaloisField open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Lib.ByteSequence (* We represent GF(2^n) by uint_t along with some irreducible polynomial also of type uint_t *) (* Consequently this module is specialized for GF(8/16/32/64/128) but can be generalized to other sizes if needed *) #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0" noeq type field = | GF: t:inttype{unsigned t /\ t <> U1} -> irred: uint_t t SEC -> field let gf t irred = GF t irred type felem (f:field) = uint_t f.t SEC let to_felem (#f:field) (n:nat{n <= maxint f.t}) : felem f = uint #f.t #SEC n let from_felem (#f:field) (e:felem f) : n:nat{n <= maxint f.t} = uint_v #f.t #SEC e let zero (#f:field) : felem f = to_felem 0 let one (#f:field) : felem f = to_felem 1 let load_felem_be (#f:field) (b:lbytes (numbytes f.t)) : felem f = uint_from_bytes_be #f.t #SEC b let store_felem_be (#f:field) (e:felem f): lbytes (numbytes f.t) = uint_to_bytes_be #f.t #SEC e let reverse (#t:inttype{unsigned t}) (a:uint_t t SEC) : uint_t t SEC = repeati (bits t) (fun i u -> u |. (((a >>. size i) &. uint #t #SEC 1) <<. (size (bits t - 1 - i)))) (uint #t #SEC 0) let load_felem_le (#f:field) (b:lbytes (numbytes f.t)) : felem f = reverse #f.t (load_felem_be #f b) let store_felem_le (#f:field) (e:felem f) : lbytes (numbytes f.t) = store_felem_be #f (reverse #f.t e) let fadd (#f:field) (a:felem f) (b:felem f) : felem f = a ^. b let op_Plus_At #f e1 e2 = fadd #f e1 e2 let fmul (#f:field) (a:felem f) (b:felem f) : felem f = let one = one #f in let zero = zero #f in let (p,a,b) = repeati (bits f.t - 1) (fun i (p,a,b) -> let b0 = eq_mask #f.t (b &. one) one in let p = p ^. (b0 &. a) in let carry_mask = eq_mask #f.t (a >>. size (bits f.t - 1)) one in let a = a <<. size 1 in let a = a ^. (carry_mask &. f.irred) in let b = b >>. size 1 in (p,a,b)) (zero,a,b) in let b0 = eq_mask #f.t (b &. one) one in let p = p ^. (b0 &. a) in p let op_Star_At #f e1 e2 = fmul #f e1 e2 val get_ith_bit: #f:field -> x:felem f -> i:nat{i < bits f.t} -> Tot (r:felem f{v r == v x / pow2 (bits f.t - 1 - i) % 2}) let get_ith_bit #f x i = logand_mask (x >>. size (bits f.t - 1 - i)) one 1; (x >>. size (bits f.t - 1 - i)) &. one val mask_add: #f:field -> x:felem f -> y:felem f -> res:felem f -> i:nat{i < bits f.t} -> Tot (r:felem f{r == (if v (get_ith_bit x i) = 1 then res `fadd` y else res)}) let mask_add #f x y res i = logxor_lemma res zero; res `fadd` (y &. eq_mask #f.t (get_ith_bit x i) one) val mask_shift_right_mod: #f:field -> y:felem f -> Tot (r:felem f{r == (if v (get_ith_bit y (bits f.t - 1)) = 1 then (y >>. 1ul) `fadd` f.irred else (y >>. 1ul))})
false
false
Spec.GaloisField.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mask_shift_right_mod: #f:field -> y:felem f -> Tot (r:felem f{r == (if v (get_ith_bit y (bits f.t - 1)) = 1 then (y >>. 1ul) `fadd` f.irred else (y >>. 1ul))})
[]
Spec.GaloisField.mask_shift_right_mod
{ "file_name": "specs/Spec.GaloisField.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
y: Spec.GaloisField.felem f -> r: Spec.GaloisField.felem f { r == (match Lib.IntTypes.v (Spec.GaloisField.get_ith_bit y (Lib.IntTypes.bits (GF?.t f) - 1)) = 1 with | true -> Spec.GaloisField.fadd (y >>. 1ul) (GF?.irred f) | _ -> y >>. 1ul) }
{ "end_col": 81, "end_line": 69, "start_col": 2, "start_line": 68 }
Prims.Tot
val ghash_incremental0 (h y_prev: quad32) (x: seq quad32) : quad32
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let ghash_incremental0 (h:quad32) (y_prev:quad32) (x:seq quad32) : quad32 = if length x > 0 then ghash_incremental h y_prev x else y_prev
val ghash_incremental0 (h y_prev: quad32) (x: seq quad32) : quad32 let ghash_incremental0 (h y_prev: quad32) (x: seq quad32) : quad32 =
false
null
false
if length x > 0 then ghash_incremental h y_prev x else y_prev
{ "checked_file": "Vale.AES.GHash_BE.fsti.checked", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.OptPublic_BE.fsti.checked", "Vale.AES.GHash_BE_s.fst.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.GCM_helpers_BE.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.GHash_BE.fsti" }
[ "total" ]
[ "Vale.Def.Types_s.quad32", "FStar.Seq.Base.seq", "Prims.op_GreaterThan", "FStar.Seq.Base.length", "Vale.AES.GHash_BE.ghash_incremental", "Prims.bool" ]
[]
module Vale.AES.GHash_BE open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GHash_BE_s open Vale.AES.GF128_s open Vale.AES.GCTR_BE_s open Vale.AES.GCM_helpers_BE open Vale.Lib.Seqs_s open Vale.Lib.Seqs open FStar.Seq open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.AES.GF128 open FStar.Mul open FStar.Calc open Vale.AES.OptPublic_BE open Vale.Math.Poly2.Words open Vale.Math.Poly2.Lemmas open Vale.Def.Words.Seq_s #reset-options let poly128 = p:poly{degree p < 128} let fun_seq_quad32_BE_poly128 (s:seq quad32) : (int -> poly128) = fun (i:int) -> if 0 <= i && i < length s then of_quad32 (index s i) else zero let rec ghash_poly (h:poly) (init:poly) (data:int -> poly128) (j:int) (k:int) : Tot poly (decreases (k - j)) = if k <= j then init else gf128_mul_rev (ghash_poly h init data j (k - 1) +. data (k - 1)) h val g_power (a:poly) (n:nat) : poly val lemma_g_power_1 (a:poly) : Lemma (g_power a 1 == a) val lemma_g_power_n (a:poly) (n:pos) : Lemma (g_power a (n + 1) == a *~ g_power a n) val gf128_power (h:poly) (n:nat) : poly val lemma_gf128_power (h:poly) (n:nat) : Lemma (gf128_power h n == shift_key_1 128 gf128_modulus_low_terms (g_power h n)) let hkeys_reqs_priv (hkeys:seq quad32) (h_BE:quad32) : Vale.Def.Prop_s.prop0 = let h = of_quad32 h_BE in length hkeys >= 3 /\ index hkeys 2 == h_BE /\ of_quad32 (index hkeys 0) == gf128_power h 1 /\ of_quad32 (index hkeys 1) == gf128_power h 2 val lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) // Unrolled series of n ghash computations let rec ghash_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = gf128_power h (n + 1) in if m = 0 then (prev +. d) *. p else ghash_unroll h prev data k (m - 1) (n + 1) +. d *. p // Unrolled series of n ghash computations in reverse order (last to first) let rec ghash_unroll_back (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : poly = let d = data (k + (n - 1 - m)) in let p = gf128_power h (m + 1) in let v = if m = n - 1 then prev +. d else d in if m = 0 then v *. p else ghash_unroll_back h prev data k n (m - 1) +. v *. p val lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) val lemma_ghash_poly_of_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m 0) gf128_modulus == ghash_poly h prev data k (k + m + 1) ) let rec ghash_incremental_def (h_BE:quad32) (y_prev:quad32) (x:seq quad32) : Tot quad32 (decreases %[length x]) = if length x = 0 then y_prev else let y_i_minus_1 = ghash_incremental_def h_BE y_prev (all_but_last x) in let x_i = last x in let xor_BE = quad32_xor y_i_minus_1 x_i in gf128_mul_BE xor_BE h_BE [@"opaque_to_smt"] let ghash_incremental = opaque_make ghash_incremental_def irreducible let ghash_incremental_reveal = opaque_revealer (`%ghash_incremental) ghash_incremental ghash_incremental_def val lemma_ghash_incremental_poly (h_BE:quad32) (y_prev:quad32) (x:seq quad32) : Lemma (ensures of_quad32 (ghash_incremental h_BE y_prev x) == ghash_poly (of_quad32 h_BE) (of_quad32 y_prev) (fun_seq_quad32_BE_poly128 x) 0 (length x) ) // avoids need for extra fuel val lemma_ghash_incremental_def_0 (h_BE:quad32) (y_prev:quad32) (x:seq quad32) : Lemma (requires length x == 0) (ensures ghash_incremental_def h_BE y_prev x == y_prev) [SMTPat (ghash_incremental_def h_BE y_prev x)] val ghash_incremental_to_ghash (h:quad32) (x:seq quad32) : Lemma (requires length x > 0) (ensures ghash_incremental h (Mkfour 0 0 0 0) x == ghash_BE h x) (decreases %[length x]) val lemma_hash_append (h:quad32) (y_prev:quad32) (a b:ghash_plain_BE) : Lemma (ensures ghash_incremental h y_prev (append a b) == (let y_a = ghash_incremental h y_prev a in ghash_incremental h y_a b)) (decreases %[length b])
false
true
Vale.AES.GHash_BE.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ghash_incremental0 (h y_prev: quad32) (x: seq quad32) : quad32
[]
Vale.AES.GHash_BE.ghash_incremental0
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: Vale.Def.Types_s.quad32 -> y_prev: Vale.Def.Types_s.quad32 -> x: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> Vale.Def.Types_s.quad32
{ "end_col": 63, "end_line": 117, "start_col": 2, "start_line": 117 }
Prims.Tot
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let poly128 = p:poly{degree p < 128}
let poly128 =
false
null
false
p: poly{degree p < 128}
{ "checked_file": "Vale.AES.GHash_BE.fsti.checked", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.OptPublic_BE.fsti.checked", "Vale.AES.GHash_BE_s.fst.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.GCM_helpers_BE.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.GHash_BE.fsti" }
[ "total" ]
[ "Vale.Math.Poly2_s.poly", "Prims.b2t", "Prims.op_LessThan", "Vale.Math.Poly2_s.degree" ]
[]
module Vale.AES.GHash_BE open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GHash_BE_s open Vale.AES.GF128_s open Vale.AES.GCTR_BE_s open Vale.AES.GCM_helpers_BE open Vale.Lib.Seqs_s open Vale.Lib.Seqs open FStar.Seq open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.AES.GF128 open FStar.Mul open FStar.Calc open Vale.AES.OptPublic_BE open Vale.Math.Poly2.Words open Vale.Math.Poly2.Lemmas open Vale.Def.Words.Seq_s #reset-options
false
true
Vale.AES.GHash_BE.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val poly128 : Type0
[]
Vale.AES.GHash_BE.poly128
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 36, "end_line": 28, "start_col": 14, "start_line": 28 }
Prims.Tot
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let ghash_incremental = opaque_make ghash_incremental_def
let ghash_incremental =
false
null
false
opaque_make ghash_incremental_def
{ "checked_file": "Vale.AES.GHash_BE.fsti.checked", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.OptPublic_BE.fsti.checked", "Vale.AES.GHash_BE_s.fst.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.GCM_helpers_BE.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.GHash_BE.fsti" }
[ "total" ]
[ "Vale.Def.Opaque_s.opaque_make", "Vale.Def.Types_s.quad32", "FStar.Seq.Base.seq", "Vale.AES.GHash_BE.ghash_incremental_def" ]
[]
module Vale.AES.GHash_BE open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GHash_BE_s open Vale.AES.GF128_s open Vale.AES.GCTR_BE_s open Vale.AES.GCM_helpers_BE open Vale.Lib.Seqs_s open Vale.Lib.Seqs open FStar.Seq open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.AES.GF128 open FStar.Mul open FStar.Calc open Vale.AES.OptPublic_BE open Vale.Math.Poly2.Words open Vale.Math.Poly2.Lemmas open Vale.Def.Words.Seq_s #reset-options let poly128 = p:poly{degree p < 128} let fun_seq_quad32_BE_poly128 (s:seq quad32) : (int -> poly128) = fun (i:int) -> if 0 <= i && i < length s then of_quad32 (index s i) else zero let rec ghash_poly (h:poly) (init:poly) (data:int -> poly128) (j:int) (k:int) : Tot poly (decreases (k - j)) = if k <= j then init else gf128_mul_rev (ghash_poly h init data j (k - 1) +. data (k - 1)) h val g_power (a:poly) (n:nat) : poly val lemma_g_power_1 (a:poly) : Lemma (g_power a 1 == a) val lemma_g_power_n (a:poly) (n:pos) : Lemma (g_power a (n + 1) == a *~ g_power a n) val gf128_power (h:poly) (n:nat) : poly val lemma_gf128_power (h:poly) (n:nat) : Lemma (gf128_power h n == shift_key_1 128 gf128_modulus_low_terms (g_power h n)) let hkeys_reqs_priv (hkeys:seq quad32) (h_BE:quad32) : Vale.Def.Prop_s.prop0 = let h = of_quad32 h_BE in length hkeys >= 3 /\ index hkeys 2 == h_BE /\ of_quad32 (index hkeys 0) == gf128_power h 1 /\ of_quad32 (index hkeys 1) == gf128_power h 2 val lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) // Unrolled series of n ghash computations let rec ghash_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = gf128_power h (n + 1) in if m = 0 then (prev +. d) *. p else ghash_unroll h prev data k (m - 1) (n + 1) +. d *. p // Unrolled series of n ghash computations in reverse order (last to first) let rec ghash_unroll_back (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : poly = let d = data (k + (n - 1 - m)) in let p = gf128_power h (m + 1) in let v = if m = n - 1 then prev +. d else d in if m = 0 then v *. p else ghash_unroll_back h prev data k n (m - 1) +. v *. p val lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) val lemma_ghash_poly_of_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m 0) gf128_modulus == ghash_poly h prev data k (k + m + 1) ) let rec ghash_incremental_def (h_BE:quad32) (y_prev:quad32) (x:seq quad32) : Tot quad32 (decreases %[length x]) = if length x = 0 then y_prev else let y_i_minus_1 = ghash_incremental_def h_BE y_prev (all_but_last x) in let x_i = last x in let xor_BE = quad32_xor y_i_minus_1 x_i in
false
true
Vale.AES.GHash_BE.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ghash_incremental : _: Vale.Def.Types_s.quad32 -> _: Vale.Def.Types_s.quad32 -> _: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> Prims.Tot Vale.Def.Types_s.quad32
[]
Vale.AES.GHash_BE.ghash_incremental
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
_: Vale.Def.Types_s.quad32 -> _: Vale.Def.Types_s.quad32 -> _: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> Prims.Tot Vale.Def.Types_s.quad32
{ "end_col": 76, "end_line": 87, "start_col": 43, "start_line": 87 }
FStar.Pervasives.Lemma
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let ghash_incremental_reveal = opaque_revealer (`%ghash_incremental) ghash_incremental ghash_incremental_def
let ghash_incremental_reveal =
false
null
true
opaque_revealer (`%ghash_incremental) ghash_incremental ghash_incremental_def
{ "checked_file": "Vale.AES.GHash_BE.fsti.checked", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.OptPublic_BE.fsti.checked", "Vale.AES.GHash_BE_s.fst.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.GCM_helpers_BE.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.GHash_BE.fsti" }
[ "lemma" ]
[ "Vale.Def.Opaque_s.opaque_revealer", "Vale.Def.Types_s.quad32", "FStar.Seq.Base.seq", "Vale.AES.GHash_BE.ghash_incremental", "Vale.AES.GHash_BE.ghash_incremental_def" ]
[]
module Vale.AES.GHash_BE open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GHash_BE_s open Vale.AES.GF128_s open Vale.AES.GCTR_BE_s open Vale.AES.GCM_helpers_BE open Vale.Lib.Seqs_s open Vale.Lib.Seqs open FStar.Seq open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.AES.GF128 open FStar.Mul open FStar.Calc open Vale.AES.OptPublic_BE open Vale.Math.Poly2.Words open Vale.Math.Poly2.Lemmas open Vale.Def.Words.Seq_s #reset-options let poly128 = p:poly{degree p < 128} let fun_seq_quad32_BE_poly128 (s:seq quad32) : (int -> poly128) = fun (i:int) -> if 0 <= i && i < length s then of_quad32 (index s i) else zero let rec ghash_poly (h:poly) (init:poly) (data:int -> poly128) (j:int) (k:int) : Tot poly (decreases (k - j)) = if k <= j then init else gf128_mul_rev (ghash_poly h init data j (k - 1) +. data (k - 1)) h val g_power (a:poly) (n:nat) : poly val lemma_g_power_1 (a:poly) : Lemma (g_power a 1 == a) val lemma_g_power_n (a:poly) (n:pos) : Lemma (g_power a (n + 1) == a *~ g_power a n) val gf128_power (h:poly) (n:nat) : poly val lemma_gf128_power (h:poly) (n:nat) : Lemma (gf128_power h n == shift_key_1 128 gf128_modulus_low_terms (g_power h n)) let hkeys_reqs_priv (hkeys:seq quad32) (h_BE:quad32) : Vale.Def.Prop_s.prop0 = let h = of_quad32 h_BE in length hkeys >= 3 /\ index hkeys 2 == h_BE /\ of_quad32 (index hkeys 0) == gf128_power h 1 /\ of_quad32 (index hkeys 1) == gf128_power h 2 val lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) // Unrolled series of n ghash computations let rec ghash_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = gf128_power h (n + 1) in if m = 0 then (prev +. d) *. p else ghash_unroll h prev data k (m - 1) (n + 1) +. d *. p // Unrolled series of n ghash computations in reverse order (last to first) let rec ghash_unroll_back (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : poly = let d = data (k + (n - 1 - m)) in let p = gf128_power h (m + 1) in let v = if m = n - 1 then prev +. d else d in if m = 0 then v *. p else ghash_unroll_back h prev data k n (m - 1) +. v *. p val lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) val lemma_ghash_poly_of_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m 0) gf128_modulus == ghash_poly h prev data k (k + m + 1) ) let rec ghash_incremental_def (h_BE:quad32) (y_prev:quad32) (x:seq quad32) : Tot quad32 (decreases %[length x]) = if length x = 0 then y_prev else let y_i_minus_1 = ghash_incremental_def h_BE y_prev (all_but_last x) in let x_i = last x in let xor_BE = quad32_xor y_i_minus_1 x_i in gf128_mul_BE xor_BE h_BE
false
false
Vale.AES.GHash_BE.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ghash_incremental_reveal : _: Prims.unit -> FStar.Pervasives.Lemma (ensures Vale.AES.GHash_BE.ghash_incremental == Vale.AES.GHash_BE.ghash_incremental_def)
[]
Vale.AES.GHash_BE.ghash_incremental_reveal
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
_: Prims.unit -> FStar.Pervasives.Lemma (ensures Vale.AES.GHash_BE.ghash_incremental == Vale.AES.GHash_BE.ghash_incremental_def)
{ "end_col": 120, "end_line": 88, "start_col": 43, "start_line": 88 }
Prims.Tot
val hkeys_reqs_priv (hkeys: seq quad32) (h_BE: quad32) : Vale.Def.Prop_s.prop0
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let hkeys_reqs_priv (hkeys:seq quad32) (h_BE:quad32) : Vale.Def.Prop_s.prop0 = let h = of_quad32 h_BE in length hkeys >= 3 /\ index hkeys 2 == h_BE /\ of_quad32 (index hkeys 0) == gf128_power h 1 /\ of_quad32 (index hkeys 1) == gf128_power h 2
val hkeys_reqs_priv (hkeys: seq quad32) (h_BE: quad32) : Vale.Def.Prop_s.prop0 let hkeys_reqs_priv (hkeys: seq quad32) (h_BE: quad32) : Vale.Def.Prop_s.prop0 =
false
null
false
let h = of_quad32 h_BE in length hkeys >= 3 /\ index hkeys 2 == h_BE /\ of_quad32 (index hkeys 0) == gf128_power h 1 /\ of_quad32 (index hkeys 1) == gf128_power h 2
{ "checked_file": "Vale.AES.GHash_BE.fsti.checked", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.OptPublic_BE.fsti.checked", "Vale.AES.GHash_BE_s.fst.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.GCM_helpers_BE.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.GHash_BE.fsti" }
[ "total" ]
[ "FStar.Seq.Base.seq", "Vale.Def.Types_s.quad32", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Seq.Base.length", "Prims.eq2", "FStar.Seq.Base.index", "Vale.Math.Poly2_s.poly", "Vale.Math.Poly2.Bits_s.of_quad32", "Vale.AES.GHash_BE.gf128_power", "Vale.Def.Prop_s.prop0" ]
[]
module Vale.AES.GHash_BE open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GHash_BE_s open Vale.AES.GF128_s open Vale.AES.GCTR_BE_s open Vale.AES.GCM_helpers_BE open Vale.Lib.Seqs_s open Vale.Lib.Seqs open FStar.Seq open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.AES.GF128 open FStar.Mul open FStar.Calc open Vale.AES.OptPublic_BE open Vale.Math.Poly2.Words open Vale.Math.Poly2.Lemmas open Vale.Def.Words.Seq_s #reset-options let poly128 = p:poly{degree p < 128} let fun_seq_quad32_BE_poly128 (s:seq quad32) : (int -> poly128) = fun (i:int) -> if 0 <= i && i < length s then of_quad32 (index s i) else zero let rec ghash_poly (h:poly) (init:poly) (data:int -> poly128) (j:int) (k:int) : Tot poly (decreases (k - j)) = if k <= j then init else gf128_mul_rev (ghash_poly h init data j (k - 1) +. data (k - 1)) h val g_power (a:poly) (n:nat) : poly val lemma_g_power_1 (a:poly) : Lemma (g_power a 1 == a) val lemma_g_power_n (a:poly) (n:pos) : Lemma (g_power a (n + 1) == a *~ g_power a n) val gf128_power (h:poly) (n:nat) : poly val lemma_gf128_power (h:poly) (n:nat) : Lemma (gf128_power h n == shift_key_1 128 gf128_modulus_low_terms (g_power h n))
false
true
Vale.AES.GHash_BE.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val hkeys_reqs_priv (hkeys: seq quad32) (h_BE: quad32) : Vale.Def.Prop_s.prop0
[]
Vale.AES.GHash_BE.hkeys_reqs_priv
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
hkeys: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> h_BE: Vale.Def.Types_s.quad32 -> Vale.Def.Prop_s.prop0
{ "end_col": 46, "end_line": 51, "start_col": 3, "start_line": 46 }
Prims.Tot
val fun_seq_quad32_BE_poly128 (s: seq quad32) : (int -> poly128)
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let fun_seq_quad32_BE_poly128 (s:seq quad32) : (int -> poly128) = fun (i:int) -> if 0 <= i && i < length s then of_quad32 (index s i) else zero
val fun_seq_quad32_BE_poly128 (s: seq quad32) : (int -> poly128) let fun_seq_quad32_BE_poly128 (s: seq quad32) : (int -> poly128) =
false
null
false
fun (i: int) -> if 0 <= i && i < length s then of_quad32 (index s i) else zero
{ "checked_file": "Vale.AES.GHash_BE.fsti.checked", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.OptPublic_BE.fsti.checked", "Vale.AES.GHash_BE_s.fst.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.GCM_helpers_BE.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.GHash_BE.fsti" }
[ "total" ]
[ "FStar.Seq.Base.seq", "Vale.Def.Types_s.quad32", "Prims.int", "Prims.op_AmpAmp", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "FStar.Seq.Base.length", "Vale.Math.Poly2.Bits_s.of_quad32", "FStar.Seq.Base.index", "Prims.bool", "Vale.Math.Poly2_s.zero", "Vale.AES.GHash_BE.poly128" ]
[]
module Vale.AES.GHash_BE open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GHash_BE_s open Vale.AES.GF128_s open Vale.AES.GCTR_BE_s open Vale.AES.GCM_helpers_BE open Vale.Lib.Seqs_s open Vale.Lib.Seqs open FStar.Seq open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.AES.GF128 open FStar.Mul open FStar.Calc open Vale.AES.OptPublic_BE open Vale.Math.Poly2.Words open Vale.Math.Poly2.Lemmas open Vale.Def.Words.Seq_s #reset-options let poly128 = p:poly{degree p < 128}
false
true
Vale.AES.GHash_BE.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val fun_seq_quad32_BE_poly128 (s: seq quad32) : (int -> poly128)
[]
Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> _: Prims.int -> Vale.AES.GHash_BE.poly128
{ "end_col": 79, "end_line": 31, "start_col": 2, "start_line": 31 }
Prims.Tot
val ghash_poly (h init: poly) (data: (int -> poly128)) (j k: int) : Tot poly (decreases (k - j))
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec ghash_poly (h:poly) (init:poly) (data:int -> poly128) (j:int) (k:int) : Tot poly (decreases (k - j)) = if k <= j then init else gf128_mul_rev (ghash_poly h init data j (k - 1) +. data (k - 1)) h
val ghash_poly (h init: poly) (data: (int -> poly128)) (j k: int) : Tot poly (decreases (k - j)) let rec ghash_poly (h init: poly) (data: (int -> poly128)) (j k: int) : Tot poly (decreases (k - j)) =
false
null
false
if k <= j then init else gf128_mul_rev (ghash_poly h init data j (k - 1) +. data (k - 1)) h
{ "checked_file": "Vale.AES.GHash_BE.fsti.checked", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.OptPublic_BE.fsti.checked", "Vale.AES.GHash_BE_s.fst.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.GCM_helpers_BE.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.GHash_BE.fsti" }
[ "total", "" ]
[ "Vale.Math.Poly2_s.poly", "Prims.int", "Vale.AES.GHash_BE.poly128", "Prims.op_LessThanOrEqual", "Prims.bool", "Vale.AES.GF128.gf128_mul_rev", "Vale.Math.Poly2.op_Plus_Dot", "Vale.AES.GHash_BE.ghash_poly", "Prims.op_Subtraction" ]
[]
module Vale.AES.GHash_BE open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GHash_BE_s open Vale.AES.GF128_s open Vale.AES.GCTR_BE_s open Vale.AES.GCM_helpers_BE open Vale.Lib.Seqs_s open Vale.Lib.Seqs open FStar.Seq open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.AES.GF128 open FStar.Mul open FStar.Calc open Vale.AES.OptPublic_BE open Vale.Math.Poly2.Words open Vale.Math.Poly2.Lemmas open Vale.Def.Words.Seq_s #reset-options let poly128 = p:poly{degree p < 128} let fun_seq_quad32_BE_poly128 (s:seq quad32) : (int -> poly128) = fun (i:int) -> if 0 <= i && i < length s then of_quad32 (index s i) else zero
false
true
Vale.AES.GHash_BE.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ghash_poly (h init: poly) (data: (int -> poly128)) (j k: int) : Tot poly (decreases (k - j))
[ "recursion" ]
Vale.AES.GHash_BE.ghash_poly
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: Vale.Math.Poly2_s.poly -> init: Vale.Math.Poly2_s.poly -> data: (_: Prims.int -> Vale.AES.GHash_BE.poly128) -> j: Prims.int -> k: Prims.int -> Prims.Tot Vale.Math.Poly2_s.poly
{ "end_col": 68, "end_line": 35, "start_col": 2, "start_line": 34 }
Prims.Tot
val ghash_incremental_def (h_BE y_prev: quad32) (x: seq quad32) : Tot quad32 (decreases %[length x])
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec ghash_incremental_def (h_BE:quad32) (y_prev:quad32) (x:seq quad32) : Tot quad32 (decreases %[length x]) = if length x = 0 then y_prev else let y_i_minus_1 = ghash_incremental_def h_BE y_prev (all_but_last x) in let x_i = last x in let xor_BE = quad32_xor y_i_minus_1 x_i in gf128_mul_BE xor_BE h_BE
val ghash_incremental_def (h_BE y_prev: quad32) (x: seq quad32) : Tot quad32 (decreases %[length x]) let rec ghash_incremental_def (h_BE y_prev: quad32) (x: seq quad32) : Tot quad32 (decreases %[length x]) =
false
null
false
if length x = 0 then y_prev else let y_i_minus_1 = ghash_incremental_def h_BE y_prev (all_but_last x) in let x_i = last x in let xor_BE = quad32_xor y_i_minus_1 x_i in gf128_mul_BE xor_BE h_BE
{ "checked_file": "Vale.AES.GHash_BE.fsti.checked", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.OptPublic_BE.fsti.checked", "Vale.AES.GHash_BE_s.fst.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.GCM_helpers_BE.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.GHash_BE.fsti" }
[ "total", "" ]
[ "Vale.Def.Types_s.quad32", "FStar.Seq.Base.seq", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "Prims.bool", "Vale.AES.GHash_BE_s.gf128_mul_BE", "Vale.Def.Types_s.quad32_xor", "FStar.Seq.Properties.last", "Vale.AES.GHash_BE.ghash_incremental_def", "Vale.Lib.Seqs_s.all_but_last" ]
[]
module Vale.AES.GHash_BE open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GHash_BE_s open Vale.AES.GF128_s open Vale.AES.GCTR_BE_s open Vale.AES.GCM_helpers_BE open Vale.Lib.Seqs_s open Vale.Lib.Seqs open FStar.Seq open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.AES.GF128 open FStar.Mul open FStar.Calc open Vale.AES.OptPublic_BE open Vale.Math.Poly2.Words open Vale.Math.Poly2.Lemmas open Vale.Def.Words.Seq_s #reset-options let poly128 = p:poly{degree p < 128} let fun_seq_quad32_BE_poly128 (s:seq quad32) : (int -> poly128) = fun (i:int) -> if 0 <= i && i < length s then of_quad32 (index s i) else zero let rec ghash_poly (h:poly) (init:poly) (data:int -> poly128) (j:int) (k:int) : Tot poly (decreases (k - j)) = if k <= j then init else gf128_mul_rev (ghash_poly h init data j (k - 1) +. data (k - 1)) h val g_power (a:poly) (n:nat) : poly val lemma_g_power_1 (a:poly) : Lemma (g_power a 1 == a) val lemma_g_power_n (a:poly) (n:pos) : Lemma (g_power a (n + 1) == a *~ g_power a n) val gf128_power (h:poly) (n:nat) : poly val lemma_gf128_power (h:poly) (n:nat) : Lemma (gf128_power h n == shift_key_1 128 gf128_modulus_low_terms (g_power h n)) let hkeys_reqs_priv (hkeys:seq quad32) (h_BE:quad32) : Vale.Def.Prop_s.prop0 = let h = of_quad32 h_BE in length hkeys >= 3 /\ index hkeys 2 == h_BE /\ of_quad32 (index hkeys 0) == gf128_power h 1 /\ of_quad32 (index hkeys 1) == gf128_power h 2 val lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) // Unrolled series of n ghash computations let rec ghash_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = gf128_power h (n + 1) in if m = 0 then (prev +. d) *. p else ghash_unroll h prev data k (m - 1) (n + 1) +. d *. p // Unrolled series of n ghash computations in reverse order (last to first) let rec ghash_unroll_back (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : poly = let d = data (k + (n - 1 - m)) in let p = gf128_power h (m + 1) in let v = if m = n - 1 then prev +. d else d in if m = 0 then v *. p else ghash_unroll_back h prev data k n (m - 1) +. v *. p val lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) val lemma_ghash_poly_of_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m 0) gf128_modulus == ghash_poly h prev data k (k + m + 1) )
false
true
Vale.AES.GHash_BE.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ghash_incremental_def (h_BE y_prev: quad32) (x: seq quad32) : Tot quad32 (decreases %[length x])
[ "recursion" ]
Vale.AES.GHash_BE.ghash_incremental_def
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h_BE: Vale.Def.Types_s.quad32 -> y_prev: Vale.Def.Types_s.quad32 -> x: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> Prims.Tot Vale.Def.Types_s.quad32
{ "end_col": 26, "end_line": 86, "start_col": 2, "start_line": 82 }
Prims.Tot
val ghash_unroll (h prev: poly) (data: (int -> poly128)) (k: int) (m n: nat) : poly
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec ghash_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = gf128_power h (n + 1) in if m = 0 then (prev +. d) *. p else ghash_unroll h prev data k (m - 1) (n + 1) +. d *. p
val ghash_unroll (h prev: poly) (data: (int -> poly128)) (k: int) (m n: nat) : poly let rec ghash_unroll (h prev: poly) (data: (int -> poly128)) (k: int) (m n: nat) : poly =
false
null
false
let d = data (k + m) in let p = gf128_power h (n + 1) in if m = 0 then (prev +. d) *. p else ghash_unroll h prev data k (m - 1) (n + 1) +. d *. p
{ "checked_file": "Vale.AES.GHash_BE.fsti.checked", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.OptPublic_BE.fsti.checked", "Vale.AES.GHash_BE_s.fst.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.GCM_helpers_BE.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.GHash_BE.fsti" }
[ "total" ]
[ "Vale.Math.Poly2_s.poly", "Prims.int", "Vale.AES.GHash_BE.poly128", "Prims.nat", "Prims.op_Equality", "Vale.Math.Poly2.op_Star_Dot", "Vale.Math.Poly2.op_Plus_Dot", "Prims.bool", "Vale.AES.GHash_BE.ghash_unroll", "Prims.op_Subtraction", "Prims.op_Addition", "Vale.AES.GHash_BE.gf128_power" ]
[]
module Vale.AES.GHash_BE open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GHash_BE_s open Vale.AES.GF128_s open Vale.AES.GCTR_BE_s open Vale.AES.GCM_helpers_BE open Vale.Lib.Seqs_s open Vale.Lib.Seqs open FStar.Seq open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.AES.GF128 open FStar.Mul open FStar.Calc open Vale.AES.OptPublic_BE open Vale.Math.Poly2.Words open Vale.Math.Poly2.Lemmas open Vale.Def.Words.Seq_s #reset-options let poly128 = p:poly{degree p < 128} let fun_seq_quad32_BE_poly128 (s:seq quad32) : (int -> poly128) = fun (i:int) -> if 0 <= i && i < length s then of_quad32 (index s i) else zero let rec ghash_poly (h:poly) (init:poly) (data:int -> poly128) (j:int) (k:int) : Tot poly (decreases (k - j)) = if k <= j then init else gf128_mul_rev (ghash_poly h init data j (k - 1) +. data (k - 1)) h val g_power (a:poly) (n:nat) : poly val lemma_g_power_1 (a:poly) : Lemma (g_power a 1 == a) val lemma_g_power_n (a:poly) (n:pos) : Lemma (g_power a (n + 1) == a *~ g_power a n) val gf128_power (h:poly) (n:nat) : poly val lemma_gf128_power (h:poly) (n:nat) : Lemma (gf128_power h n == shift_key_1 128 gf128_modulus_low_terms (g_power h n)) let hkeys_reqs_priv (hkeys:seq quad32) (h_BE:quad32) : Vale.Def.Prop_s.prop0 = let h = of_quad32 h_BE in length hkeys >= 3 /\ index hkeys 2 == h_BE /\ of_quad32 (index hkeys 0) == gf128_power h 1 /\ of_quad32 (index hkeys 1) == gf128_power h 2 val lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE)
false
true
Vale.AES.GHash_BE.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ghash_unroll (h prev: poly) (data: (int -> poly128)) (k: int) (m n: nat) : poly
[ "recursion" ]
Vale.AES.GHash_BE.ghash_unroll
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: Vale.Math.Poly2_s.poly -> prev: Vale.Math.Poly2_s.poly -> data: (_: Prims.int -> Vale.AES.GHash_BE.poly128) -> k: Prims.int -> m: Prims.nat -> n: Prims.nat -> Vale.Math.Poly2_s.poly
{ "end_col": 54, "end_line": 61, "start_col": 90, "start_line": 57 }
FStar.Pervasives.Lemma
val lemma_add_mul_zero_low (a0 a1 b0 b1: poly) : Lemma (requires a1 == zero \/ b1 == zero) (ensures add (mul a0 b0) (mul a1 b1) == mul a0 b0)
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_add_mul_zero_low (a0 a1 b0 b1:poly) : Lemma (requires a1 == zero \/ b1 == zero) (ensures add (mul a0 b0) (mul a1 b1) == mul a0 b0) = lemma_mul_commute a1 b1; lemma_mul_zero a1; lemma_mul_zero b1; lemma_add_zero (mul a0 b0)
val lemma_add_mul_zero_low (a0 a1 b0 b1: poly) : Lemma (requires a1 == zero \/ b1 == zero) (ensures add (mul a0 b0) (mul a1 b1) == mul a0 b0) let lemma_add_mul_zero_low (a0 a1 b0 b1: poly) : Lemma (requires a1 == zero \/ b1 == zero) (ensures add (mul a0 b0) (mul a1 b1) == mul a0 b0) =
false
null
true
lemma_mul_commute a1 b1; lemma_mul_zero a1; lemma_mul_zero b1; lemma_add_zero (mul a0 b0)
{ "checked_file": "Vale.AES.GHash_BE.fsti.checked", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.OptPublic_BE.fsti.checked", "Vale.AES.GHash_BE_s.fst.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.GCM_helpers_BE.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.GHash_BE.fsti" }
[ "lemma" ]
[ "Vale.Math.Poly2_s.poly", "Vale.Math.Poly2.lemma_add_zero", "Vale.Math.Poly2_s.mul", "Prims.unit", "Vale.Math.Poly2.lemma_mul_zero", "Vale.Math.Poly2.lemma_mul_commute", "Prims.l_or", "Prims.eq2", "Vale.Math.Poly2_s.zero", "Prims.squash", "Vale.Math.Poly2_s.add", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GHash_BE open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GHash_BE_s open Vale.AES.GF128_s open Vale.AES.GCTR_BE_s open Vale.AES.GCM_helpers_BE open Vale.Lib.Seqs_s open Vale.Lib.Seqs open FStar.Seq open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.AES.GF128 open FStar.Mul open FStar.Calc open Vale.AES.OptPublic_BE open Vale.Math.Poly2.Words open Vale.Math.Poly2.Lemmas open Vale.Def.Words.Seq_s #reset-options let poly128 = p:poly{degree p < 128} let fun_seq_quad32_BE_poly128 (s:seq quad32) : (int -> poly128) = fun (i:int) -> if 0 <= i && i < length s then of_quad32 (index s i) else zero let rec ghash_poly (h:poly) (init:poly) (data:int -> poly128) (j:int) (k:int) : Tot poly (decreases (k - j)) = if k <= j then init else gf128_mul_rev (ghash_poly h init data j (k - 1) +. data (k - 1)) h val g_power (a:poly) (n:nat) : poly val lemma_g_power_1 (a:poly) : Lemma (g_power a 1 == a) val lemma_g_power_n (a:poly) (n:pos) : Lemma (g_power a (n + 1) == a *~ g_power a n) val gf128_power (h:poly) (n:nat) : poly val lemma_gf128_power (h:poly) (n:nat) : Lemma (gf128_power h n == shift_key_1 128 gf128_modulus_low_terms (g_power h n)) let hkeys_reqs_priv (hkeys:seq quad32) (h_BE:quad32) : Vale.Def.Prop_s.prop0 = let h = of_quad32 h_BE in length hkeys >= 3 /\ index hkeys 2 == h_BE /\ of_quad32 (index hkeys 0) == gf128_power h 1 /\ of_quad32 (index hkeys 1) == gf128_power h 2 val lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) // Unrolled series of n ghash computations let rec ghash_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = gf128_power h (n + 1) in if m = 0 then (prev +. d) *. p else ghash_unroll h prev data k (m - 1) (n + 1) +. d *. p // Unrolled series of n ghash computations in reverse order (last to first) let rec ghash_unroll_back (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : poly = let d = data (k + (n - 1 - m)) in let p = gf128_power h (m + 1) in let v = if m = n - 1 then prev +. d else d in if m = 0 then v *. p else ghash_unroll_back h prev data k n (m - 1) +. v *. p val lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) val lemma_ghash_poly_of_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m 0) gf128_modulus == ghash_poly h prev data k (k + m + 1) ) let rec ghash_incremental_def (h_BE:quad32) (y_prev:quad32) (x:seq quad32) : Tot quad32 (decreases %[length x]) = if length x = 0 then y_prev else let y_i_minus_1 = ghash_incremental_def h_BE y_prev (all_but_last x) in let x_i = last x in let xor_BE = quad32_xor y_i_minus_1 x_i in gf128_mul_BE xor_BE h_BE [@"opaque_to_smt"] let ghash_incremental = opaque_make ghash_incremental_def irreducible let ghash_incremental_reveal = opaque_revealer (`%ghash_incremental) ghash_incremental ghash_incremental_def val lemma_ghash_incremental_poly (h_BE:quad32) (y_prev:quad32) (x:seq quad32) : Lemma (ensures of_quad32 (ghash_incremental h_BE y_prev x) == ghash_poly (of_quad32 h_BE) (of_quad32 y_prev) (fun_seq_quad32_BE_poly128 x) 0 (length x) ) // avoids need for extra fuel val lemma_ghash_incremental_def_0 (h_BE:quad32) (y_prev:quad32) (x:seq quad32) : Lemma (requires length x == 0) (ensures ghash_incremental_def h_BE y_prev x == y_prev) [SMTPat (ghash_incremental_def h_BE y_prev x)] val ghash_incremental_to_ghash (h:quad32) (x:seq quad32) : Lemma (requires length x > 0) (ensures ghash_incremental h (Mkfour 0 0 0 0) x == ghash_BE h x) (decreases %[length x]) val lemma_hash_append (h:quad32) (y_prev:quad32) (a b:ghash_plain_BE) : Lemma (ensures ghash_incremental h y_prev (append a b) == (let y_a = ghash_incremental h y_prev a in ghash_incremental h y_a b)) (decreases %[length b]) let ghash_incremental0 (h:quad32) (y_prev:quad32) (x:seq quad32) : quad32 = if length x > 0 then ghash_incremental h y_prev x else y_prev val lemma_ghash_incremental0_append (h y0 y1 y2:quad32) (s1 s2:seq quad32) : Lemma (requires y1 = ghash_incremental0 h y0 s1 /\ y2 = ghash_incremental0 h y1 s2) (ensures y2 = ghash_incremental0 h y0 (s1 @| s2)) val lemma_hash_append2 (h y_init y_mid y_final:quad32) (s1:seq quad32) (q:quad32) : Lemma (requires y_mid = ghash_incremental0 h y_init s1 /\ y_final = ghash_incremental h y_mid (create 1 q)) (ensures y_final == ghash_incremental h y_init (s1 @| (create 1 q))) val ghash_incremental_bytes_pure_no_extra (old_io io h:quad32) (in_quads:seq quad32) (num_bytes:nat64) : Lemma (requires io = ghash_incremental0 h old_io in_quads) (ensures length in_quads == (num_bytes / 16) /\ num_bytes % 16 == 0 ==> (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE in_quads)) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in num_bytes > 0 ==> length input_quads > 0 /\ io == ghash_incremental h old_io input_quads)) #reset-options "--z3rlimit 30" val lemma_ghash_incremental_bytes_extra_helper (h y_init y_mid y_final:quad32) (input:seq quad32) (final final_padded:quad32) (num_bytes:nat) : Lemma (requires (1 <= num_bytes /\ num_bytes < 16 * length input /\ 16 * (length input - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ //4096 * num_bytes < pow2_32 /\ (let num_blocks = num_bytes / 16 in let full_blocks = slice input 0 num_blocks in y_mid = ghash_incremental0 h y_init full_blocks /\ final == index input num_blocks /\ (let padded_bytes = pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16)) in length padded_bytes == 16 /\ final_padded == be_bytes_to_quad32 padded_bytes /\ y_final = ghash_incremental h y_mid (create 1 final_padded))))) (ensures (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE input)) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in length padded_bytes == 16 * length input_quads /\ y_final == ghash_incremental h y_init input_quads)) val lemma_ghash_incremental_bytes_extra_helper_alt (h y_init y_mid y_final:quad32) (input_blocks:seq quad32) (final final_padded:quad32) (num_bytes:nat) : Lemma (requires (1 <= num_bytes /\ num_bytes < 16 * (length input_blocks) + 16 /\ 16 * (length input_blocks) < num_bytes /\ num_bytes % 16 <> 0 /\ y_mid = ghash_incremental0 h y_init input_blocks /\ (let padded_bytes = pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16)) in length padded_bytes == 16 /\ final_padded == be_bytes_to_quad32 padded_bytes /\ y_final = ghash_incremental h y_mid (create 1 final_padded)))) (ensures (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append input_blocks (create 1 final)))) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in length padded_bytes == 16 * length input_quads /\ y_final == ghash_incremental h y_init input_quads)) let lemma_add_mul_zero_low (a0 a1 b0 b1:poly) : Lemma (requires a1 == zero \/ b1 == zero) (ensures add (mul a0 b0) (mul a1 b1) == mul a0 b0)
false
false
Vale.AES.GHash_BE.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_add_mul_zero_low (a0 a1 b0 b1: poly) : Lemma (requires a1 == zero \/ b1 == zero) (ensures add (mul a0 b0) (mul a1 b1) == mul a0 b0)
[]
Vale.AES.GHash_BE.lemma_add_mul_zero_low
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a0: Vale.Math.Poly2_s.poly -> a1: Vale.Math.Poly2_s.poly -> b0: Vale.Math.Poly2_s.poly -> b1: Vale.Math.Poly2_s.poly -> FStar.Pervasives.Lemma (requires a1 == Vale.Math.Poly2_s.zero \/ b1 == Vale.Math.Poly2_s.zero) (ensures Vale.Math.Poly2_s.add (Vale.Math.Poly2_s.mul a0 b0) (Vale.Math.Poly2_s.mul a1 b1) == Vale.Math.Poly2_s.mul a0 b0)
{ "end_col": 28, "end_line": 182, "start_col": 2, "start_line": 179 }
FStar.Pervasives.Lemma
val lemma_add_mul_zero_high (a0 a1 b0 b1: poly) : Lemma (requires a0 == zero \/ b0 == zero) (ensures add (mul a0 b0) (mul a1 b1) == mul a1 b1)
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_add_mul_zero_high (a0 a1 b0 b1:poly) : Lemma (requires a0 == zero \/ b0 == zero) (ensures add (mul a0 b0) (mul a1 b1) == mul a1 b1) = lemma_mul_commute a0 b0; lemma_mul_zero a0; lemma_mul_zero b0; lemma_add_commute (mul a0 b0) (mul a1 b1); lemma_add_zero (mul a1 b1)
val lemma_add_mul_zero_high (a0 a1 b0 b1: poly) : Lemma (requires a0 == zero \/ b0 == zero) (ensures add (mul a0 b0) (mul a1 b1) == mul a1 b1) let lemma_add_mul_zero_high (a0 a1 b0 b1: poly) : Lemma (requires a0 == zero \/ b0 == zero) (ensures add (mul a0 b0) (mul a1 b1) == mul a1 b1) =
false
null
true
lemma_mul_commute a0 b0; lemma_mul_zero a0; lemma_mul_zero b0; lemma_add_commute (mul a0 b0) (mul a1 b1); lemma_add_zero (mul a1 b1)
{ "checked_file": "Vale.AES.GHash_BE.fsti.checked", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.OptPublic_BE.fsti.checked", "Vale.AES.GHash_BE_s.fst.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.GCM_helpers_BE.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.GHash_BE.fsti" }
[ "lemma" ]
[ "Vale.Math.Poly2_s.poly", "Vale.Math.Poly2.lemma_add_zero", "Vale.Math.Poly2_s.mul", "Prims.unit", "Vale.Math.Poly2.lemma_add_commute", "Vale.Math.Poly2.lemma_mul_zero", "Vale.Math.Poly2.lemma_mul_commute", "Prims.l_or", "Prims.eq2", "Vale.Math.Poly2_s.zero", "Prims.squash", "Vale.Math.Poly2_s.add", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GHash_BE open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GHash_BE_s open Vale.AES.GF128_s open Vale.AES.GCTR_BE_s open Vale.AES.GCM_helpers_BE open Vale.Lib.Seqs_s open Vale.Lib.Seqs open FStar.Seq open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.AES.GF128 open FStar.Mul open FStar.Calc open Vale.AES.OptPublic_BE open Vale.Math.Poly2.Words open Vale.Math.Poly2.Lemmas open Vale.Def.Words.Seq_s #reset-options let poly128 = p:poly{degree p < 128} let fun_seq_quad32_BE_poly128 (s:seq quad32) : (int -> poly128) = fun (i:int) -> if 0 <= i && i < length s then of_quad32 (index s i) else zero let rec ghash_poly (h:poly) (init:poly) (data:int -> poly128) (j:int) (k:int) : Tot poly (decreases (k - j)) = if k <= j then init else gf128_mul_rev (ghash_poly h init data j (k - 1) +. data (k - 1)) h val g_power (a:poly) (n:nat) : poly val lemma_g_power_1 (a:poly) : Lemma (g_power a 1 == a) val lemma_g_power_n (a:poly) (n:pos) : Lemma (g_power a (n + 1) == a *~ g_power a n) val gf128_power (h:poly) (n:nat) : poly val lemma_gf128_power (h:poly) (n:nat) : Lemma (gf128_power h n == shift_key_1 128 gf128_modulus_low_terms (g_power h n)) let hkeys_reqs_priv (hkeys:seq quad32) (h_BE:quad32) : Vale.Def.Prop_s.prop0 = let h = of_quad32 h_BE in length hkeys >= 3 /\ index hkeys 2 == h_BE /\ of_quad32 (index hkeys 0) == gf128_power h 1 /\ of_quad32 (index hkeys 1) == gf128_power h 2 val lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) // Unrolled series of n ghash computations let rec ghash_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = gf128_power h (n + 1) in if m = 0 then (prev +. d) *. p else ghash_unroll h prev data k (m - 1) (n + 1) +. d *. p // Unrolled series of n ghash computations in reverse order (last to first) let rec ghash_unroll_back (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : poly = let d = data (k + (n - 1 - m)) in let p = gf128_power h (m + 1) in let v = if m = n - 1 then prev +. d else d in if m = 0 then v *. p else ghash_unroll_back h prev data k n (m - 1) +. v *. p val lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) val lemma_ghash_poly_of_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m 0) gf128_modulus == ghash_poly h prev data k (k + m + 1) ) let rec ghash_incremental_def (h_BE:quad32) (y_prev:quad32) (x:seq quad32) : Tot quad32 (decreases %[length x]) = if length x = 0 then y_prev else let y_i_minus_1 = ghash_incremental_def h_BE y_prev (all_but_last x) in let x_i = last x in let xor_BE = quad32_xor y_i_minus_1 x_i in gf128_mul_BE xor_BE h_BE [@"opaque_to_smt"] let ghash_incremental = opaque_make ghash_incremental_def irreducible let ghash_incremental_reveal = opaque_revealer (`%ghash_incremental) ghash_incremental ghash_incremental_def val lemma_ghash_incremental_poly (h_BE:quad32) (y_prev:quad32) (x:seq quad32) : Lemma (ensures of_quad32 (ghash_incremental h_BE y_prev x) == ghash_poly (of_quad32 h_BE) (of_quad32 y_prev) (fun_seq_quad32_BE_poly128 x) 0 (length x) ) // avoids need for extra fuel val lemma_ghash_incremental_def_0 (h_BE:quad32) (y_prev:quad32) (x:seq quad32) : Lemma (requires length x == 0) (ensures ghash_incremental_def h_BE y_prev x == y_prev) [SMTPat (ghash_incremental_def h_BE y_prev x)] val ghash_incremental_to_ghash (h:quad32) (x:seq quad32) : Lemma (requires length x > 0) (ensures ghash_incremental h (Mkfour 0 0 0 0) x == ghash_BE h x) (decreases %[length x]) val lemma_hash_append (h:quad32) (y_prev:quad32) (a b:ghash_plain_BE) : Lemma (ensures ghash_incremental h y_prev (append a b) == (let y_a = ghash_incremental h y_prev a in ghash_incremental h y_a b)) (decreases %[length b]) let ghash_incremental0 (h:quad32) (y_prev:quad32) (x:seq quad32) : quad32 = if length x > 0 then ghash_incremental h y_prev x else y_prev val lemma_ghash_incremental0_append (h y0 y1 y2:quad32) (s1 s2:seq quad32) : Lemma (requires y1 = ghash_incremental0 h y0 s1 /\ y2 = ghash_incremental0 h y1 s2) (ensures y2 = ghash_incremental0 h y0 (s1 @| s2)) val lemma_hash_append2 (h y_init y_mid y_final:quad32) (s1:seq quad32) (q:quad32) : Lemma (requires y_mid = ghash_incremental0 h y_init s1 /\ y_final = ghash_incremental h y_mid (create 1 q)) (ensures y_final == ghash_incremental h y_init (s1 @| (create 1 q))) val ghash_incremental_bytes_pure_no_extra (old_io io h:quad32) (in_quads:seq quad32) (num_bytes:nat64) : Lemma (requires io = ghash_incremental0 h old_io in_quads) (ensures length in_quads == (num_bytes / 16) /\ num_bytes % 16 == 0 ==> (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE in_quads)) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in num_bytes > 0 ==> length input_quads > 0 /\ io == ghash_incremental h old_io input_quads)) #reset-options "--z3rlimit 30" val lemma_ghash_incremental_bytes_extra_helper (h y_init y_mid y_final:quad32) (input:seq quad32) (final final_padded:quad32) (num_bytes:nat) : Lemma (requires (1 <= num_bytes /\ num_bytes < 16 * length input /\ 16 * (length input - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ //4096 * num_bytes < pow2_32 /\ (let num_blocks = num_bytes / 16 in let full_blocks = slice input 0 num_blocks in y_mid = ghash_incremental0 h y_init full_blocks /\ final == index input num_blocks /\ (let padded_bytes = pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16)) in length padded_bytes == 16 /\ final_padded == be_bytes_to_quad32 padded_bytes /\ y_final = ghash_incremental h y_mid (create 1 final_padded))))) (ensures (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE input)) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in length padded_bytes == 16 * length input_quads /\ y_final == ghash_incremental h y_init input_quads)) val lemma_ghash_incremental_bytes_extra_helper_alt (h y_init y_mid y_final:quad32) (input_blocks:seq quad32) (final final_padded:quad32) (num_bytes:nat) : Lemma (requires (1 <= num_bytes /\ num_bytes < 16 * (length input_blocks) + 16 /\ 16 * (length input_blocks) < num_bytes /\ num_bytes % 16 <> 0 /\ y_mid = ghash_incremental0 h y_init input_blocks /\ (let padded_bytes = pad_to_128_bits (slice (be_quad32_to_bytes final) 0 (num_bytes % 16)) in length padded_bytes == 16 /\ final_padded == be_bytes_to_quad32 padded_bytes /\ y_final = ghash_incremental h y_mid (create 1 final_padded)))) (ensures (let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append input_blocks (create 1 final)))) 0 num_bytes in let padded_bytes = pad_to_128_bits input_bytes in let input_quads = be_bytes_to_seq_quad32 padded_bytes in length padded_bytes == 16 * length input_quads /\ y_final == ghash_incremental h y_init input_quads)) let lemma_add_mul_zero_low (a0 a1 b0 b1:poly) : Lemma (requires a1 == zero \/ b1 == zero) (ensures add (mul a0 b0) (mul a1 b1) == mul a0 b0) = lemma_mul_commute a1 b1; lemma_mul_zero a1; lemma_mul_zero b1; lemma_add_zero (mul a0 b0) let lemma_add_mul_zero_high (a0 a1 b0 b1:poly) : Lemma (requires a0 == zero \/ b0 == zero) (ensures add (mul a0 b0) (mul a1 b1) == mul a1 b1)
false
false
Vale.AES.GHash_BE.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_add_mul_zero_high (a0 a1 b0 b1: poly) : Lemma (requires a0 == zero \/ b0 == zero) (ensures add (mul a0 b0) (mul a1 b1) == mul a1 b1)
[]
Vale.AES.GHash_BE.lemma_add_mul_zero_high
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a0: Vale.Math.Poly2_s.poly -> a1: Vale.Math.Poly2_s.poly -> b0: Vale.Math.Poly2_s.poly -> b1: Vale.Math.Poly2_s.poly -> FStar.Pervasives.Lemma (requires a0 == Vale.Math.Poly2_s.zero \/ b0 == Vale.Math.Poly2_s.zero) (ensures Vale.Math.Poly2_s.add (Vale.Math.Poly2_s.mul a0 b0) (Vale.Math.Poly2_s.mul a1 b1) == Vale.Math.Poly2_s.mul a1 b1)
{ "end_col": 28, "end_line": 192, "start_col": 2, "start_line": 188 }
Prims.Tot
val ghash_unroll_back (h prev: poly) (data: (int -> poly128)) (k: int) (n m: nat) : poly
[ { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic_BE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers_BE", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec ghash_unroll_back (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : poly = let d = data (k + (n - 1 - m)) in let p = gf128_power h (m + 1) in let v = if m = n - 1 then prev +. d else d in if m = 0 then v *. p else ghash_unroll_back h prev data k n (m - 1) +. v *. p
val ghash_unroll_back (h prev: poly) (data: (int -> poly128)) (k: int) (n m: nat) : poly let rec ghash_unroll_back (h prev: poly) (data: (int -> poly128)) (k: int) (n m: nat) : poly =
false
null
false
let d = data (k + (n - 1 - m)) in let p = gf128_power h (m + 1) in let v = if m = n - 1 then prev +. d else d in if m = 0 then v *. p else ghash_unroll_back h prev data k n (m - 1) +. v *. p
{ "checked_file": "Vale.AES.GHash_BE.fsti.checked", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Words.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.OptPublic_BE.fsti.checked", "Vale.AES.GHash_BE_s.fst.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.GCM_helpers_BE.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.GHash_BE.fsti" }
[ "total" ]
[ "Vale.Math.Poly2_s.poly", "Prims.int", "Vale.AES.GHash_BE.poly128", "Prims.nat", "Prims.op_Equality", "Vale.Math.Poly2.op_Star_Dot", "Prims.bool", "Vale.Math.Poly2.op_Plus_Dot", "Vale.AES.GHash_BE.ghash_unroll_back", "Prims.op_Subtraction", "Vale.AES.GHash_BE.gf128_power", "Prims.op_Addition" ]
[]
module Vale.AES.GHash_BE open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GHash_BE_s open Vale.AES.GF128_s open Vale.AES.GCTR_BE_s open Vale.AES.GCM_helpers_BE open Vale.Lib.Seqs_s open Vale.Lib.Seqs open FStar.Seq open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.AES.GF128 open FStar.Mul open FStar.Calc open Vale.AES.OptPublic_BE open Vale.Math.Poly2.Words open Vale.Math.Poly2.Lemmas open Vale.Def.Words.Seq_s #reset-options let poly128 = p:poly{degree p < 128} let fun_seq_quad32_BE_poly128 (s:seq quad32) : (int -> poly128) = fun (i:int) -> if 0 <= i && i < length s then of_quad32 (index s i) else zero let rec ghash_poly (h:poly) (init:poly) (data:int -> poly128) (j:int) (k:int) : Tot poly (decreases (k - j)) = if k <= j then init else gf128_mul_rev (ghash_poly h init data j (k - 1) +. data (k - 1)) h val g_power (a:poly) (n:nat) : poly val lemma_g_power_1 (a:poly) : Lemma (g_power a 1 == a) val lemma_g_power_n (a:poly) (n:pos) : Lemma (g_power a (n + 1) == a *~ g_power a n) val gf128_power (h:poly) (n:nat) : poly val lemma_gf128_power (h:poly) (n:nat) : Lemma (gf128_power h n == shift_key_1 128 gf128_modulus_low_terms (g_power h n)) let hkeys_reqs_priv (hkeys:seq quad32) (h_BE:quad32) : Vale.Def.Prop_s.prop0 = let h = of_quad32 h_BE in length hkeys >= 3 /\ index hkeys 2 == h_BE /\ of_quad32 (index hkeys 0) == gf128_power h 1 /\ of_quad32 (index hkeys 1) == gf128_power h 2 val lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) // Unrolled series of n ghash computations let rec ghash_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = gf128_power h (n + 1) in if m = 0 then (prev +. d) *. p else ghash_unroll h prev data k (m - 1) (n + 1) +. d *. p
false
true
Vale.AES.GHash_BE.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ghash_unroll_back (h prev: poly) (data: (int -> poly128)) (k: int) (n m: nat) : poly
[ "recursion" ]
Vale.AES.GHash_BE.ghash_unroll_back
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash_BE.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: Vale.Math.Poly2_s.poly -> prev: Vale.Math.Poly2_s.poly -> data: (_: Prims.int -> Vale.AES.GHash_BE.poly128) -> k: Prims.int -> n: Prims.nat -> m: Prims.nat -> Vale.Math.Poly2_s.poly
{ "end_col": 53, "end_line": 69, "start_col": 95, "start_line": 64 }
Prims.Tot
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Lib.LinkedList", "short_module": "LL1" }, { "abbrev": true, "full_module": "LowStar.Lib.LinkedList2", "short_module": "LL2" }, { "abbrev": true, "full_module": "FStar.Map", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.Lib", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let map (k: eqtype) v = M.t k (option v)
let map (k: eqtype) v =
false
null
false
M.t k (option v)
{ "checked_file": "LowStar.Lib.AssocList.fsti.checked", "dependencies": [ "prims.fst.checked", "LowStar.Lib.LinkedList2.fst.checked", "LowStar.Lib.LinkedList.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Lib.AssocList.fsti" }
[ "total" ]
[ "Prims.eqtype", "FStar.Map.t", "FStar.Pervasives.Native.option" ]
[]
module LowStar.Lib.AssocList /// A Low*, stateful associative list that exposes a map-like interface. module B = LowStar.Buffer module HS = FStar.HyperStack module G = FStar.Ghost module L = FStar.List.Tot module U32 = FStar.UInt32 module ST = FStar.HyperStack.ST module M = FStar.Map module LL2 = LowStar.Lib.LinkedList2 module LL1 = LowStar.Lib.LinkedList open FStar.HyperStack.ST open LowStar.BufferOps /// Types, invariants /// ----------------- val t: eqtype -> Type0 -> Type0 /// Rather than force clients to provide a dummy value for the type (which would /// allow us to do something like initialize an empty map with ``restrict (const /// default)``, we use an option.
false
true
LowStar.Lib.AssocList.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val map : k: Prims.eqtype -> v: Type -> Type
[]
LowStar.Lib.AssocList.map
{ "file_name": "krmllib/LowStar.Lib.AssocList.fsti", "git_rev": "a7be2a7c43eca637ceb57fe8f3ffd16fc6627ebd", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
k: Prims.eqtype -> v: Type -> Type
{ "end_col": 18, "end_line": 28, "start_col": 2, "start_line": 28 }
Prims.Tot
val solve (#a: Type) (#[tcresolve ()] ev: a) : Tot a
[ { "abbrev": false, "full_module": "FStar.Reflection.Types (* for `decls` *)", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let solve (#a:Type) (#[tcresolve ()] ev : a) : Tot a = ev
val solve (#a: Type) (#[tcresolve ()] ev: a) : Tot a let solve (#a: Type) (#[tcresolve ()] ev: a) : Tot a =
false
null
false
ev
{ "checked_file": "FStar.Tactics.Typeclasses.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Reflection.Types.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.Tactics.Typeclasses.fsti" }
[ "total" ]
[]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.Typeclasses open FStar.Tactics.Effect open FStar.Reflection.Types (* for `decls` *) (* The attribute that marks classes *) val tcclass : unit (* The attribute that marks instances *) val tcinstance : unit (* The attribute that marks class fields to signal that no method should be generated for them *) val no_method : unit (* The typeclass resolution metaprogram. This is a plugin, clients can run this tactics without having to know its definition in the .fst *) val tcresolve : unit -> Tac unit (* The metaprogram to generate class methods. Also a plugin. This is inserted automatically by the desugaring phase for any `class` declaration. *) val mk_class (nm:string) : Tac decls
false
false
FStar.Tactics.Typeclasses.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val solve (#a: Type) (#[tcresolve ()] ev: a) : Tot a
[]
FStar.Tactics.Typeclasses.solve
{ "file_name": "ulib/FStar.Tactics.Typeclasses.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a
{ "end_col": 64, "end_line": 41, "start_col": 62, "start_line": 41 }
Steel.ST.Effect.Ghost.STGhost
val scalar_unique (#opened: _) (#t: Type) (v1 v2: t) (p1 p2: P.perm) (r: ref (scalar t)) : STGhost unit opened ((pts_to r (mk_fraction (scalar t) (mk_scalar v1) p1)) `star` (pts_to r (mk_fraction (scalar t) (mk_scalar v2) p2))) (fun _ -> (pts_to r (mk_fraction (scalar t) (mk_scalar v1) p1)) `star` (pts_to r (mk_fraction (scalar t) (mk_scalar v2) p2))) (True) (fun _ -> v1 == v2 /\ (p1 `P.sum_perm` p2) `P.lesser_equal_perm` P.full_perm)
[ { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST.C.Types.Base", "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 } ]
false
let scalar_unique (#opened: _) (#t: Type) (v1 v2: t) (p1 p2: P.perm) (r: ref (scalar t)) : STGhost unit opened (pts_to r (mk_fraction (scalar t) (mk_scalar v1) p1) `star` pts_to r (mk_fraction (scalar t) (mk_scalar v2) p2)) (fun _ -> pts_to r (mk_fraction (scalar t) (mk_scalar v1) p1) `star` pts_to r (mk_fraction (scalar t) (mk_scalar v2) p2)) (True) (fun _ -> v1 == v2 /\ (p1 `P.sum_perm` p2) `P.lesser_equal_perm` P.full_perm) = fractional_permissions_theorem (mk_scalar v1) (mk_scalar v2) p1 p2 r; mk_scalar_inj v1 v2 P.full_perm P.full_perm
val scalar_unique (#opened: _) (#t: Type) (v1 v2: t) (p1 p2: P.perm) (r: ref (scalar t)) : STGhost unit opened ((pts_to r (mk_fraction (scalar t) (mk_scalar v1) p1)) `star` (pts_to r (mk_fraction (scalar t) (mk_scalar v2) p2))) (fun _ -> (pts_to r (mk_fraction (scalar t) (mk_scalar v1) p1)) `star` (pts_to r (mk_fraction (scalar t) (mk_scalar v2) p2))) (True) (fun _ -> v1 == v2 /\ (p1 `P.sum_perm` p2) `P.lesser_equal_perm` P.full_perm) let scalar_unique (#opened: _) (#t: Type) (v1 v2: t) (p1 p2: P.perm) (r: ref (scalar t)) : STGhost unit opened ((pts_to r (mk_fraction (scalar t) (mk_scalar v1) p1)) `star` (pts_to r (mk_fraction (scalar t) (mk_scalar v2) p2))) (fun _ -> (pts_to r (mk_fraction (scalar t) (mk_scalar v1) p1)) `star` (pts_to r (mk_fraction (scalar t) (mk_scalar v2) p2))) (True) (fun _ -> v1 == v2 /\ (p1 `P.sum_perm` p2) `P.lesser_equal_perm` P.full_perm) =
true
null
false
fractional_permissions_theorem (mk_scalar v1) (mk_scalar v2) p1 p2 r; mk_scalar_inj v1 v2 P.full_perm P.full_perm
{ "checked_file": "Steel.ST.C.Types.Scalar.fsti.checked", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.C.Types.Base.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.C.Types.Scalar.fsti" }
[]
[ "Steel.Memory.inames", "Steel.FractionalPermission.perm", "Steel.ST.C.Types.Base.ref", "Steel.ST.C.Types.Scalar.scalar_t", "Steel.ST.C.Types.Scalar.scalar", "Steel.ST.C.Types.Scalar.mk_scalar_inj", "Steel.FractionalPermission.full_perm", "Prims.unit", "Steel.ST.C.Types.Base.fractional_permissions_theorem", "Steel.ST.C.Types.Scalar.mk_scalar", "Steel.Effect.Common.star", "Steel.ST.C.Types.Base.pts_to", "FStar.Ghost.hide", "Steel.ST.C.Types.Base.mk_fraction", "Steel.Effect.Common.vprop", "Prims.l_True", "Prims.l_and", "Prims.eq2", "Prims.b2t", "Steel.FractionalPermission.lesser_equal_perm", "Steel.FractionalPermission.sum_perm" ]
[]
module Steel.ST.C.Types.Scalar open Steel.ST.Util include Steel.ST.C.Types.Base module P = Steel.FractionalPermission // To be extracted as: t [@@noextract_to "krml"] // primitive val scalar_t ( [@@@strictly_positive] t: Type0) : Type0 [@@noextract_to "krml"] // proof-only val scalar (t: Type) : typedef (scalar_t t) val mk_scalar (#t: Type) (v: t) : Ghost (scalar_t t) (requires True) (ensures (fun y -> fractionable (scalar t) y /\ full (scalar t) y )) val mk_scalar_fractionable (#t: Type) (v: t) (p: P.perm) : Lemma (requires (fractionable (scalar t) (mk_fraction (scalar t) (mk_scalar v) p))) (ensures (p `P.lesser_equal_perm` P.full_perm)) val mk_scalar_inj (#t: Type) (v1 v2: t) (p1 p2: P.perm) : Lemma (requires (mk_fraction (scalar t) (mk_scalar v1) p1 == mk_fraction (scalar t) (mk_scalar v2) p2)) (ensures (v1 == v2 /\ p1 == p2)) [SMTPat [mk_fraction (scalar t) (mk_scalar v1) p1; mk_fraction (scalar t) (mk_scalar v2) p2]] let scalar_unique (#opened: _) (#t: Type) (v1 v2: t) (p1 p2: P.perm) (r: ref (scalar t)) : STGhost unit opened (pts_to r (mk_fraction (scalar t) (mk_scalar v1) p1) `star` pts_to r (mk_fraction (scalar t) (mk_scalar v2) p2)) (fun _ -> pts_to r (mk_fraction (scalar t) (mk_scalar v1) p1) `star` pts_to r (mk_fraction (scalar t) (mk_scalar v2) p2)) (True)
false
false
Steel.ST.C.Types.Scalar.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val scalar_unique (#opened: _) (#t: Type) (v1 v2: t) (p1 p2: P.perm) (r: ref (scalar t)) : STGhost unit opened ((pts_to r (mk_fraction (scalar t) (mk_scalar v1) p1)) `star` (pts_to r (mk_fraction (scalar t) (mk_scalar v2) p2))) (fun _ -> (pts_to r (mk_fraction (scalar t) (mk_scalar v1) p1)) `star` (pts_to r (mk_fraction (scalar t) (mk_scalar v2) p2))) (True) (fun _ -> v1 == v2 /\ (p1 `P.sum_perm` p2) `P.lesser_equal_perm` P.full_perm)
[]
Steel.ST.C.Types.Scalar.scalar_unique
{ "file_name": "lib/steel/c/Steel.ST.C.Types.Scalar.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
v1: t -> v2: t -> p1: Steel.FractionalPermission.perm -> p2: Steel.FractionalPermission.perm -> r: Steel.ST.C.Types.Base.ref (Steel.ST.C.Types.Scalar.scalar t) -> Steel.ST.Effect.Ghost.STGhost Prims.unit
{ "end_col": 45, "end_line": 48, "start_col": 2, "start_line": 47 }
Steel.ST.Effect.ST
val read (#t: Type) (#v: Ghost.erased (scalar_t t)) (r: ref (scalar t)) : ST t (pts_to r v) (fun _ -> pts_to r v) (exists v0 p. Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0) p) (fun v1 -> forall v0 p. Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0) p ==> v0 == v1 )
[ { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST.C.Types.Base", "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 } ]
false
let read (#t: Type) (#v: Ghost.erased (scalar_t t)) (r: ref (scalar t)) : ST t (pts_to r v) (fun _ -> pts_to r v) (exists v0 p . Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0) p) (fun v1 -> forall v0 p . (* {:pattern (mk_fraction (scalar t) (mk_scalar v0) p)} *) Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0) p ==> v0 == v1) = let v0 = FStar.IndefiniteDescription.indefinite_description_tot _ (fun v0 -> exists p . Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0) p) in let p = FStar.IndefiniteDescription.indefinite_description_tot _ (fun p -> Ghost.reveal v == mk_fraction (scalar t) (mk_scalar (Ghost.reveal v0)) p) in let prf v0' p' : Lemma (requires (Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0') p')) (ensures (v0' == Ghost.reveal v0 /\ p' == Ghost.reveal p)) = mk_scalar_inj (Ghost.reveal v0) v0' p p' in let prf' v0' p' : Lemma (Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0') p' ==> (v0' == Ghost.reveal v0 /\ p' == Ghost.reveal p)) = Classical.move_requires (prf v0') p' in Classical.forall_intro_2 prf'; rewrite (pts_to _ _) (pts_to r (mk_fraction (scalar t) (mk_scalar (Ghost.reveal v0)) p)); let v1 = read0 r in rewrite (pts_to _ _) (pts_to r v); return v1
val read (#t: Type) (#v: Ghost.erased (scalar_t t)) (r: ref (scalar t)) : ST t (pts_to r v) (fun _ -> pts_to r v) (exists v0 p. Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0) p) (fun v1 -> forall v0 p. Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0) p ==> v0 == v1 ) let read (#t: Type) (#v: Ghost.erased (scalar_t t)) (r: ref (scalar t)) : ST t (pts_to r v) (fun _ -> pts_to r v) (exists v0 p. Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0) p) (fun v1 -> forall v0 p. Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0) p ==> v0 == v1 ) =
true
null
false
let v0 = FStar.IndefiniteDescription.indefinite_description_tot _ (fun v0 -> exists p. Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0) p) in let p = FStar.IndefiniteDescription.indefinite_description_tot _ (fun p -> Ghost.reveal v == mk_fraction (scalar t) (mk_scalar (Ghost.reveal v0)) p) in let prf v0' p' : Lemma (requires (Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0') p')) (ensures (v0' == Ghost.reveal v0 /\ p' == Ghost.reveal p)) = mk_scalar_inj (Ghost.reveal v0) v0' p p' in let prf' v0' p' : Lemma (Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0') p' ==> (v0' == Ghost.reveal v0 /\ p' == Ghost.reveal p)) = Classical.move_requires (prf v0') p' in Classical.forall_intro_2 prf'; rewrite (pts_to _ _) (pts_to r (mk_fraction (scalar t) (mk_scalar (Ghost.reveal v0)) p)); let v1 = read0 r in rewrite (pts_to _ _) (pts_to r v); return v1
{ "checked_file": "Steel.ST.C.Types.Scalar.fsti.checked", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.C.Types.Base.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.C.Types.Scalar.fsti" }
[]
[ "FStar.Ghost.erased", "Steel.ST.C.Types.Scalar.scalar_t", "Steel.ST.C.Types.Base.ref", "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.Base.pts_to", "Steel.Effect.Common.vprop", "Prims.unit", "Steel.ST.Util.rewrite", "Steel.ST.C.Types.Base.mk_fraction", "Steel.ST.C.Types.Scalar.mk_scalar", "FStar.Ghost.reveal", "Steel.FractionalPermission.perm", "Steel.ST.C.Types.Scalar.read0", "FStar.Classical.forall_intro_2", "Prims.l_imp", "Prims.eq2", "Prims.l_and", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "FStar.Classical.move_requires", "Steel.ST.C.Types.Scalar.mk_scalar_inj", "FStar.IndefiniteDescription.indefinite_description_tot", "Prims.prop", "Prims.l_Exists", "Prims.l_Forall" ]
[]
module Steel.ST.C.Types.Scalar open Steel.ST.Util include Steel.ST.C.Types.Base module P = Steel.FractionalPermission // To be extracted as: t [@@noextract_to "krml"] // primitive val scalar_t ( [@@@strictly_positive] t: Type0) : Type0 [@@noextract_to "krml"] // proof-only val scalar (t: Type) : typedef (scalar_t t) val mk_scalar (#t: Type) (v: t) : Ghost (scalar_t t) (requires True) (ensures (fun y -> fractionable (scalar t) y /\ full (scalar t) y )) val mk_scalar_fractionable (#t: Type) (v: t) (p: P.perm) : Lemma (requires (fractionable (scalar t) (mk_fraction (scalar t) (mk_scalar v) p))) (ensures (p `P.lesser_equal_perm` P.full_perm)) val mk_scalar_inj (#t: Type) (v1 v2: t) (p1 p2: P.perm) : Lemma (requires (mk_fraction (scalar t) (mk_scalar v1) p1 == mk_fraction (scalar t) (mk_scalar v2) p2)) (ensures (v1 == v2 /\ p1 == p2)) [SMTPat [mk_fraction (scalar t) (mk_scalar v1) p1; mk_fraction (scalar t) (mk_scalar v2) p2]] let scalar_unique (#opened: _) (#t: Type) (v1 v2: t) (p1 p2: P.perm) (r: ref (scalar t)) : STGhost unit opened (pts_to r (mk_fraction (scalar t) (mk_scalar v1) p1) `star` pts_to r (mk_fraction (scalar t) (mk_scalar v2) p2)) (fun _ -> pts_to r (mk_fraction (scalar t) (mk_scalar v1) p1) `star` pts_to r (mk_fraction (scalar t) (mk_scalar v2) p2)) (True) (fun _ -> v1 == v2 /\ (p1 `P.sum_perm` p2) `P.lesser_equal_perm` P.full_perm) = fractional_permissions_theorem (mk_scalar v1) (mk_scalar v2) p1 p2 r; mk_scalar_inj v1 v2 P.full_perm P.full_perm [@@noextract_to "krml"] // primitive val read0 (#t: Type) (#v: Ghost.erased t) (#p: P.perm) (r: ref (scalar t)) : ST t (pts_to r (mk_fraction (scalar t) (mk_scalar (Ghost.reveal v)) p)) (fun _ -> pts_to r (mk_fraction (scalar t) (mk_scalar (Ghost.reveal v)) p)) (True) (fun v' -> v' == Ghost.reveal v) let mk_fraction_full_scalar (#t: Type) (v: t) : Lemma (mk_scalar v == mk_fraction (scalar t) (mk_scalar v) P.full_perm) [SMTPat (mk_scalar v)] = () val get_scalar_value (#t: Type) (c: scalar_t t) : GTot (option t) val get_scalar_value_mk_fraction (#t: Type) (c: scalar_t t) (p: perm) : Lemma (requires (fractionable (scalar t) c)) (ensures (get_scalar_value (mk_fraction (scalar t) c p) == get_scalar_value c)) [SMTPat (get_scalar_value (mk_fraction (scalar t) c p))] val get_scalar_value_mk_scalar (#t: Type) (c: t) : Lemma (get_scalar_value (mk_scalar c) == Some c) [SMTPat (get_scalar_value (mk_scalar c))] val get_scalar_value_uninitialized (t: Type) : Lemma (get_scalar_value (uninitialized (scalar t)) == None) [SMTPat (get_scalar_value (uninitialized (scalar t)))] val get_scalar_value_unknown (t: Type) : Lemma (get_scalar_value (unknown (scalar t)) == None) [SMTPat (get_scalar_value (unknown (scalar t)))] val get_scalar_value_some (#t: Type) (c: scalar_t t) : Lemma (requires (Some? (get_scalar_value c))) (ensures ( exists v0 p . Ghost.reveal c == mk_fraction (scalar t) (mk_scalar v0) p )) [SMTPat (get_scalar_value c)] inline_for_extraction [@@noextract_to "krml"] let read (#t: Type) (#v: Ghost.erased (scalar_t t)) (r: ref (scalar t)) : ST t (pts_to r v) (fun _ -> pts_to r v) (exists v0 p . Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0) p)
false
false
Steel.ST.C.Types.Scalar.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val read (#t: Type) (#v: Ghost.erased (scalar_t t)) (r: ref (scalar t)) : ST t (pts_to r v) (fun _ -> pts_to r v) (exists v0 p. Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0) p) (fun v1 -> forall v0 p. Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0) p ==> v0 == v1 )
[]
Steel.ST.C.Types.Scalar.read
{ "file_name": "lib/steel/c/Steel.ST.C.Types.Scalar.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
r: Steel.ST.C.Types.Base.ref (Steel.ST.C.Types.Scalar.scalar t) -> Steel.ST.Effect.ST t
{ "end_col": 11, "end_line": 126, "start_col": 1, "start_line": 111 }
Prims.Tot
val t : Type0
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Buffer.Aux", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Base", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "EverParse3d.InputStream", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let t = t
val t : Type0 let t =
false
null
false
t
{ "checked_file": "EverParse3d.InputStream.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.Ghost.fsti.checked", "EverParse3d.Readable.fsti.checked", "EverParse3d.InputStream.Buffer.Aux.fst.checked", "EverParse3d.InputBuffer.fsti.checked", "EverParse3d.ErrorCode.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.InputStream.Buffer.fst" }
[ "total" ]
[ "EverParse3d.InputStream.Buffer.Aux.t" ]
[]
module EverParse3d.InputStream.Buffer open EverParse3d.InputStream.Buffer.Aux (* Implementation for single buffers *) module U64 = FStar.UInt64
false
true
EverParse3d.InputStream.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "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": [ "smt.qi.eager_threshold=100" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 8, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val t : Type0
[]
EverParse3d.InputStream.Buffer.t
{ "file_name": "src/3d/prelude/buffer/EverParse3d.InputStream.Buffer.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
Type0
{ "end_col": 9, "end_line": 8, "start_col": 8, "start_line": 8 }
Prims.Tot
val _tlen (x: t) : Tot Type0
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Buffer.Aux", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Base", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "EverParse3d.InputStream", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let _tlen (x: t) : Tot Type0 = (len: U64.t { U64.v len == U32.v x.len })
val _tlen (x: t) : Tot Type0 let _tlen (x: t) : Tot Type0 =
false
null
false
(len: U64.t{U64.v len == U32.v x.len})
{ "checked_file": "EverParse3d.InputStream.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.Ghost.fsti.checked", "EverParse3d.Readable.fsti.checked", "EverParse3d.InputStream.Buffer.Aux.fst.checked", "EverParse3d.InputBuffer.fsti.checked", "EverParse3d.ErrorCode.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.InputStream.Buffer.fst" }
[ "total" ]
[ "EverParse3d.InputStream.Buffer.t", "FStar.UInt64.t", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt64.n", "FStar.UInt32.n", "FStar.UInt64.v", "FStar.UInt32.v", "FStar.Ghost.reveal", "FStar.UInt32.t", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__len" ]
[]
module EverParse3d.InputStream.Buffer open EverParse3d.InputStream.Buffer.Aux (* Implementation for single buffers *) module U64 = FStar.UInt64 let t = t inline_for_extraction noextract let _tlen (x: t)
false
true
EverParse3d.InputStream.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "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": [ "smt.qi.eager_threshold=100" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 8, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val _tlen (x: t) : Tot Type0
[]
EverParse3d.InputStream.Buffer._tlen
{ "file_name": "src/3d/prelude/buffer/EverParse3d.InputStream.Buffer.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: EverParse3d.InputStream.Buffer.t -> Type0
{ "end_col": 43, "end_line": 15, "start_col": 2, "start_line": 15 }
Prims.Ghost
val _get_suffix (x y: t) : Ghost (Seq.seq U8.t) (requires (x `_is_prefix_of` y)) (ensures (fun _ -> True))
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Buffer.Aux", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Base", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "EverParse3d.InputStream", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let _get_suffix (x y: t) : Ghost (Seq.seq U8.t) (requires (x `_is_prefix_of` y)) (ensures (fun _ -> True)) = Seq.slice (Ghost.reveal y.g_all) (U32.v x.len) (U32.v y.len)
val _get_suffix (x y: t) : Ghost (Seq.seq U8.t) (requires (x `_is_prefix_of` y)) (ensures (fun _ -> True)) let _get_suffix (x y: t) : Ghost (Seq.seq U8.t) (requires (x `_is_prefix_of` y)) (ensures (fun _ -> True)) =
false
null
false
Seq.slice (Ghost.reveal y.g_all) (U32.v x.len) (U32.v y.len)
{ "checked_file": "EverParse3d.InputStream.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.Ghost.fsti.checked", "EverParse3d.Readable.fsti.checked", "EverParse3d.InputStream.Buffer.Aux.fst.checked", "EverParse3d.InputBuffer.fsti.checked", "EverParse3d.ErrorCode.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.InputStream.Buffer.fst" }
[]
[ "EverParse3d.InputStream.Buffer.t", "FStar.Seq.Base.slice", "FStar.UInt8.t", "FStar.Ghost.reveal", "FStar.Seq.Base.seq", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__g_all", "FStar.UInt32.v", "FStar.UInt32.t", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__len", "EverParse3d.InputStream.Buffer._is_prefix_of", "Prims.l_True" ]
[]
module EverParse3d.InputStream.Buffer open EverParse3d.InputStream.Buffer.Aux (* Implementation for single buffers *) module U64 = FStar.UInt64 let t = t inline_for_extraction noextract let _tlen (x: t) : Tot Type0 = (len: U64.t { U64.v len == U32.v x.len }) let _get_read (x: t) (h: HS.mem) : Ghost (Seq.seq U8.t) (requires (_live x h)) (ensures (fun y -> Ghost.reveal x.g_all == y `Seq.append` _get_remaining x h)) = let i = U32.v (B.deref h x.pos) in Seq.lemma_split x.g_all i; Seq.slice x.g_all 0 i let _is_prefix_of (x y: t) : Tot prop = x.len0 == y.len0 /\ x.buf == y.buf /\ x.perm_of == y.perm_of /\ U32.v x.len <= U32.v y.len /\ x.pos == y.pos /\ x.g_all_buf == y.g_all_buf /\ Ghost.reveal x.g_all == Seq.slice (Ghost.reveal y.g_all) 0 (U32.v x.len) let _get_suffix (x y: t) : Ghost (Seq.seq U8.t) (requires (x `_is_prefix_of` y))
false
false
EverParse3d.InputStream.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "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": [ "smt.qi.eager_threshold=100" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 8, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val _get_suffix (x y: t) : Ghost (Seq.seq U8.t) (requires (x `_is_prefix_of` y)) (ensures (fun _ -> True))
[]
EverParse3d.InputStream.Buffer._get_suffix
{ "file_name": "src/3d/prelude/buffer/EverParse3d.InputStream.Buffer.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: EverParse3d.InputStream.Buffer.t -> y: EverParse3d.InputStream.Buffer.t -> Prims.Ghost (FStar.Seq.Base.seq FStar.UInt8.t)
{ "end_col": 62, "end_line": 44, "start_col": 2, "start_line": 44 }
Prims.Pure
val uint32_to_uint64 (x: U32.t) : Pure U64.t (requires True) (ensures (fun y -> U64.v y == U32.v x))
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Buffer.Aux", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Base", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "EverParse3d.InputStream", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let uint32_to_uint64 (x: U32.t) : Pure U64.t (requires True) (ensures (fun y -> U64.v y == U32.v x)) = FStar.Int.Cast.uint32_to_uint64 x
val uint32_to_uint64 (x: U32.t) : Pure U64.t (requires True) (ensures (fun y -> U64.v y == U32.v x)) let uint32_to_uint64 (x: U32.t) : Pure U64.t (requires True) (ensures (fun y -> U64.v y == U32.v x)) =
false
null
false
FStar.Int.Cast.uint32_to_uint64 x
{ "checked_file": "EverParse3d.InputStream.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.Ghost.fsti.checked", "EverParse3d.Readable.fsti.checked", "EverParse3d.InputStream.Buffer.Aux.fst.checked", "EverParse3d.InputBuffer.fsti.checked", "EverParse3d.ErrorCode.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.InputStream.Buffer.fst" }
[]
[ "FStar.UInt32.t", "FStar.Int.Cast.uint32_to_uint64", "FStar.UInt64.t", "Prims.l_True", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt64.n", "FStar.UInt32.n", "FStar.UInt64.v", "FStar.UInt32.v" ]
[]
module EverParse3d.InputStream.Buffer open EverParse3d.InputStream.Buffer.Aux (* Implementation for single buffers *) module U64 = FStar.UInt64 let t = t inline_for_extraction noextract let _tlen (x: t) : Tot Type0 = (len: U64.t { U64.v len == U32.v x.len }) let _get_read (x: t) (h: HS.mem) : Ghost (Seq.seq U8.t) (requires (_live x h)) (ensures (fun y -> Ghost.reveal x.g_all == y `Seq.append` _get_remaining x h)) = let i = U32.v (B.deref h x.pos) in Seq.lemma_split x.g_all i; Seq.slice x.g_all 0 i let _is_prefix_of (x y: t) : Tot prop = x.len0 == y.len0 /\ x.buf == y.buf /\ x.perm_of == y.perm_of /\ U32.v x.len <= U32.v y.len /\ x.pos == y.pos /\ x.g_all_buf == y.g_all_buf /\ Ghost.reveal x.g_all == Seq.slice (Ghost.reveal y.g_all) 0 (U32.v x.len) let _get_suffix (x y: t) : Ghost (Seq.seq U8.t) (requires (x `_is_prefix_of` y)) (ensures (fun _ -> True)) = Seq.slice (Ghost.reveal y.g_all) (U32.v x.len) (U32.v y.len) #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false" #restart-solver let _is_prefix_of_prop (x: t) (y: t) (h: HS.mem) : Lemma (requires ( _live x h /\ x `_is_prefix_of` y )) (ensures ( _live y h /\ _get_read y h `Seq.equal` _get_read x h /\ _get_remaining y h `Seq.equal` (_get_remaining x h `Seq.append` _get_suffix x y) )) = assert (_live y h); assert (_get_read y h `Seq.equal` _get_read x h); assert (_get_remaining y h `Seq.equal` (_get_remaining x h `Seq.append` _get_suffix x y)) open LowStar.BufferOps #restart-solver module U64 = FStar.UInt64 inline_for_extraction noextract let uint32_to_uint64 (x: U32.t) : Pure U64.t (requires True)
false
false
EverParse3d.InputStream.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "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": [ "smt.qi.eager_threshold=100", "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 8, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val uint32_to_uint64 (x: U32.t) : Pure U64.t (requires True) (ensures (fun y -> U64.v y == U32.v x))
[]
EverParse3d.InputStream.Buffer.uint32_to_uint64
{ "file_name": "src/3d/prelude/buffer/EverParse3d.InputStream.Buffer.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt32.t -> Prims.Pure FStar.UInt64.t
{ "end_col": 35, "end_line": 81, "start_col": 2, "start_line": 81 }
Prims.Tot
val _is_prefix_of (x y: t) : Tot prop
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Buffer.Aux", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Base", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "EverParse3d.InputStream", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let _is_prefix_of (x y: t) : Tot prop = x.len0 == y.len0 /\ x.buf == y.buf /\ x.perm_of == y.perm_of /\ U32.v x.len <= U32.v y.len /\ x.pos == y.pos /\ x.g_all_buf == y.g_all_buf /\ Ghost.reveal x.g_all == Seq.slice (Ghost.reveal y.g_all) 0 (U32.v x.len)
val _is_prefix_of (x y: t) : Tot prop let _is_prefix_of (x y: t) : Tot prop =
false
null
false
x.len0 == y.len0 /\ x.buf == y.buf /\ x.perm_of == y.perm_of /\ U32.v x.len <= U32.v y.len /\ x.pos == y.pos /\ x.g_all_buf == y.g_all_buf /\ Ghost.reveal x.g_all == Seq.slice (Ghost.reveal y.g_all) 0 (U32.v x.len)
{ "checked_file": "EverParse3d.InputStream.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.Ghost.fsti.checked", "EverParse3d.Readable.fsti.checked", "EverParse3d.InputStream.Buffer.Aux.fst.checked", "EverParse3d.InputBuffer.fsti.checked", "EverParse3d.ErrorCode.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.InputStream.Buffer.fst" }
[ "total" ]
[ "EverParse3d.InputStream.Buffer.t", "Prims.l_and", "Prims.eq2", "FStar.Ghost.erased", "FStar.UInt32.t", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__len0", "EverParse3d.InputBuffer.input_buffer_t", "FStar.Ghost.reveal", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__buf", "EverParse3d.Readable.perm0", "LowParse.Bytes.byte", "Prims.l_or", "EverParse3d.Readable.perm_prop", "LowParse.Slice.__proj__Mkslice__item__base", "EverParse3d.InputBuffer.triv", "EverParse3d.InputBuffer.slice_of", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__perm_of", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__len", "LowStar.Buffer.pointer", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__pos", "FStar.Seq.Base.seq", "FStar.UInt8.t", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__g_all_buf", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__g_all", "FStar.Seq.Base.slice", "Prims.prop" ]
[]
module EverParse3d.InputStream.Buffer open EverParse3d.InputStream.Buffer.Aux (* Implementation for single buffers *) module U64 = FStar.UInt64 let t = t inline_for_extraction noextract let _tlen (x: t) : Tot Type0 = (len: U64.t { U64.v len == U32.v x.len }) let _get_read (x: t) (h: HS.mem) : Ghost (Seq.seq U8.t) (requires (_live x h)) (ensures (fun y -> Ghost.reveal x.g_all == y `Seq.append` _get_remaining x h)) = let i = U32.v (B.deref h x.pos) in Seq.lemma_split x.g_all i; Seq.slice x.g_all 0 i let _is_prefix_of (x y: t)
false
true
EverParse3d.InputStream.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "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": [ "smt.qi.eager_threshold=100" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 8, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val _is_prefix_of (x y: t) : Tot prop
[]
EverParse3d.InputStream.Buffer._is_prefix_of
{ "file_name": "src/3d/prelude/buffer/EverParse3d.InputStream.Buffer.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: EverParse3d.InputStream.Buffer.t -> y: EverParse3d.InputStream.Buffer.t -> Prims.prop
{ "end_col": 74, "end_line": 37, "start_col": 2, "start_line": 31 }
Prims.Pure
val uint64_to_uint32 (x: U64.t) : Pure U32.t (requires (U64.v x < 4294967296)) (ensures (fun y -> U32.v y == U64.v x))
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Buffer.Aux", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Base", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "EverParse3d.InputStream", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let uint64_to_uint32 (x: U64.t) : Pure U32.t (requires (U64.v x < 4294967296)) (ensures (fun y -> U32.v y == U64.v x)) = FStar.Math.Lemmas.modulo_lemma (U64.v x) 4294967296; FStar.Int.Cast.uint64_to_uint32 x
val uint64_to_uint32 (x: U64.t) : Pure U32.t (requires (U64.v x < 4294967296)) (ensures (fun y -> U32.v y == U64.v x)) let uint64_to_uint32 (x: U64.t) : Pure U32.t (requires (U64.v x < 4294967296)) (ensures (fun y -> U32.v y == U64.v x)) =
false
null
false
FStar.Math.Lemmas.modulo_lemma (U64.v x) 4294967296; FStar.Int.Cast.uint64_to_uint32 x
{ "checked_file": "EverParse3d.InputStream.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.Ghost.fsti.checked", "EverParse3d.Readable.fsti.checked", "EverParse3d.InputStream.Buffer.Aux.fst.checked", "EverParse3d.InputBuffer.fsti.checked", "EverParse3d.ErrorCode.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.InputStream.Buffer.fst" }
[]
[ "FStar.UInt64.t", "FStar.Int.Cast.uint64_to_uint32", "Prims.unit", "FStar.Math.Lemmas.modulo_lemma", "FStar.UInt64.v", "FStar.UInt32.t", "Prims.b2t", "Prims.op_LessThan", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt32.n", "FStar.UInt64.n", "FStar.UInt32.v" ]
[]
module EverParse3d.InputStream.Buffer open EverParse3d.InputStream.Buffer.Aux (* Implementation for single buffers *) module U64 = FStar.UInt64 let t = t inline_for_extraction noextract let _tlen (x: t) : Tot Type0 = (len: U64.t { U64.v len == U32.v x.len }) let _get_read (x: t) (h: HS.mem) : Ghost (Seq.seq U8.t) (requires (_live x h)) (ensures (fun y -> Ghost.reveal x.g_all == y `Seq.append` _get_remaining x h)) = let i = U32.v (B.deref h x.pos) in Seq.lemma_split x.g_all i; Seq.slice x.g_all 0 i let _is_prefix_of (x y: t) : Tot prop = x.len0 == y.len0 /\ x.buf == y.buf /\ x.perm_of == y.perm_of /\ U32.v x.len <= U32.v y.len /\ x.pos == y.pos /\ x.g_all_buf == y.g_all_buf /\ Ghost.reveal x.g_all == Seq.slice (Ghost.reveal y.g_all) 0 (U32.v x.len) let _get_suffix (x y: t) : Ghost (Seq.seq U8.t) (requires (x `_is_prefix_of` y)) (ensures (fun _ -> True)) = Seq.slice (Ghost.reveal y.g_all) (U32.v x.len) (U32.v y.len) #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false" #restart-solver let _is_prefix_of_prop (x: t) (y: t) (h: HS.mem) : Lemma (requires ( _live x h /\ x `_is_prefix_of` y )) (ensures ( _live y h /\ _get_read y h `Seq.equal` _get_read x h /\ _get_remaining y h `Seq.equal` (_get_remaining x h `Seq.append` _get_suffix x y) )) = assert (_live y h); assert (_get_read y h `Seq.equal` _get_read x h); assert (_get_remaining y h `Seq.equal` (_get_remaining x h `Seq.append` _get_suffix x y)) open LowStar.BufferOps #restart-solver module U64 = FStar.UInt64 inline_for_extraction noextract let uint32_to_uint64 (x: U32.t) : Pure U64.t (requires True) (ensures (fun y -> U64.v y == U32.v x)) = FStar.Int.Cast.uint32_to_uint64 x inline_for_extraction noextract let uint64_to_uint32 (x: U64.t) : Pure U32.t (requires (U64.v x < 4294967296))
false
false
EverParse3d.InputStream.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "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": [ "smt.qi.eager_threshold=100", "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 8, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val uint64_to_uint32 (x: U64.t) : Pure U32.t (requires (U64.v x < 4294967296)) (ensures (fun y -> U32.v y == U64.v x))
[]
EverParse3d.InputStream.Buffer.uint64_to_uint32
{ "file_name": "src/3d/prelude/buffer/EverParse3d.InputStream.Buffer.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt64.t -> Prims.Pure FStar.UInt32.t
{ "end_col": 35, "end_line": 91, "start_col": 2, "start_line": 90 }
Prims.Ghost
val _get_read (x: t) (h: HS.mem) : Ghost (Seq.seq U8.t) (requires (_live x h)) (ensures (fun y -> Ghost.reveal x.g_all == y `Seq.append` (_get_remaining x h)))
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Buffer.Aux", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Base", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "EverParse3d.InputStream", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let _get_read (x: t) (h: HS.mem) : Ghost (Seq.seq U8.t) (requires (_live x h)) (ensures (fun y -> Ghost.reveal x.g_all == y `Seq.append` _get_remaining x h)) = let i = U32.v (B.deref h x.pos) in Seq.lemma_split x.g_all i; Seq.slice x.g_all 0 i
val _get_read (x: t) (h: HS.mem) : Ghost (Seq.seq U8.t) (requires (_live x h)) (ensures (fun y -> Ghost.reveal x.g_all == y `Seq.append` (_get_remaining x h))) let _get_read (x: t) (h: HS.mem) : Ghost (Seq.seq U8.t) (requires (_live x h)) (ensures (fun y -> Ghost.reveal x.g_all == y `Seq.append` (_get_remaining x h))) =
false
null
false
let i = U32.v (B.deref h x.pos) in Seq.lemma_split x.g_all i; Seq.slice x.g_all 0 i
{ "checked_file": "EverParse3d.InputStream.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.Ghost.fsti.checked", "EverParse3d.Readable.fsti.checked", "EverParse3d.InputStream.Buffer.Aux.fst.checked", "EverParse3d.InputBuffer.fsti.checked", "EverParse3d.ErrorCode.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.InputStream.Buffer.fst" }
[]
[ "EverParse3d.InputStream.Buffer.t", "FStar.Monotonic.HyperStack.mem", "FStar.Seq.Base.slice", "FStar.UInt8.t", "FStar.Ghost.reveal", "FStar.Seq.Base.seq", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__g_all", "Prims.unit", "FStar.Seq.Properties.lemma_split", "FStar.UInt.uint_t", "FStar.UInt32.v", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.deref", "FStar.Ghost.erased", "LowStar.Buffer.trivial_preorder", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__pos", "EverParse3d.InputStream.Buffer.Aux._live", "Prims.eq2", "FStar.Seq.Base.append", "EverParse3d.InputStream.Buffer.Aux._get_remaining" ]
[]
module EverParse3d.InputStream.Buffer open EverParse3d.InputStream.Buffer.Aux (* Implementation for single buffers *) module U64 = FStar.UInt64 let t = t inline_for_extraction noextract let _tlen (x: t) : Tot Type0 = (len: U64.t { U64.v len == U32.v x.len }) let _get_read (x: t) (h: HS.mem) : Ghost (Seq.seq U8.t) (requires (_live x h))
false
false
EverParse3d.InputStream.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "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": [ "smt.qi.eager_threshold=100" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 8, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val _get_read (x: t) (h: HS.mem) : Ghost (Seq.seq U8.t) (requires (_live x h)) (ensures (fun y -> Ghost.reveal x.g_all == y `Seq.append` (_get_remaining x h)))
[]
EverParse3d.InputStream.Buffer._get_read
{ "file_name": "src/3d/prelude/buffer/EverParse3d.InputStream.Buffer.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: EverParse3d.InputStream.Buffer.t -> h: FStar.Monotonic.HyperStack.mem -> Prims.Ghost (FStar.Seq.Base.seq FStar.UInt8.t)
{ "end_col": 23, "end_line": 26, "start_col": 1, "start_line": 23 }
FStar.Pervasives.Lemma
val _is_prefix_of_prop (x y: t) (h: HS.mem) : Lemma (requires (_live x h /\ x `_is_prefix_of` y)) (ensures (_live y h /\ (_get_read y h) `Seq.equal` (_get_read x h) /\ (_get_remaining y h) `Seq.equal` ((_get_remaining x h) `Seq.append` (_get_suffix x y))))
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Buffer.Aux", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Base", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "EverParse3d.InputStream", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let _is_prefix_of_prop (x: t) (y: t) (h: HS.mem) : Lemma (requires ( _live x h /\ x `_is_prefix_of` y )) (ensures ( _live y h /\ _get_read y h `Seq.equal` _get_read x h /\ _get_remaining y h `Seq.equal` (_get_remaining x h `Seq.append` _get_suffix x y) )) = assert (_live y h); assert (_get_read y h `Seq.equal` _get_read x h); assert (_get_remaining y h `Seq.equal` (_get_remaining x h `Seq.append` _get_suffix x y))
val _is_prefix_of_prop (x y: t) (h: HS.mem) : Lemma (requires (_live x h /\ x `_is_prefix_of` y)) (ensures (_live y h /\ (_get_read y h) `Seq.equal` (_get_read x h) /\ (_get_remaining y h) `Seq.equal` ((_get_remaining x h) `Seq.append` (_get_suffix x y)))) let _is_prefix_of_prop (x y: t) (h: HS.mem) : Lemma (requires (_live x h /\ x `_is_prefix_of` y)) (ensures (_live y h /\ (_get_read y h) `Seq.equal` (_get_read x h) /\ (_get_remaining y h) `Seq.equal` ((_get_remaining x h) `Seq.append` (_get_suffix x y)))) =
false
null
true
assert (_live y h); assert ((_get_read y h) `Seq.equal` (_get_read x h)); assert ((_get_remaining y h) `Seq.equal` ((_get_remaining x h) `Seq.append` (_get_suffix x y)))
{ "checked_file": "EverParse3d.InputStream.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.Ghost.fsti.checked", "EverParse3d.Readable.fsti.checked", "EverParse3d.InputStream.Buffer.Aux.fst.checked", "EverParse3d.InputBuffer.fsti.checked", "EverParse3d.ErrorCode.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.InputStream.Buffer.fst" }
[ "lemma" ]
[ "EverParse3d.InputStream.Buffer.t", "FStar.Monotonic.HyperStack.mem", "Prims._assert", "FStar.Seq.Base.equal", "FStar.UInt8.t", "EverParse3d.InputStream.Buffer.Aux._get_remaining", "FStar.Seq.Base.append", "EverParse3d.InputStream.Buffer._get_suffix", "Prims.unit", "EverParse3d.InputStream.Buffer._get_read", "EverParse3d.InputStream.Buffer.Aux._live", "Prims.l_and", "EverParse3d.InputStream.Buffer._is_prefix_of", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module EverParse3d.InputStream.Buffer open EverParse3d.InputStream.Buffer.Aux (* Implementation for single buffers *) module U64 = FStar.UInt64 let t = t inline_for_extraction noextract let _tlen (x: t) : Tot Type0 = (len: U64.t { U64.v len == U32.v x.len }) let _get_read (x: t) (h: HS.mem) : Ghost (Seq.seq U8.t) (requires (_live x h)) (ensures (fun y -> Ghost.reveal x.g_all == y `Seq.append` _get_remaining x h)) = let i = U32.v (B.deref h x.pos) in Seq.lemma_split x.g_all i; Seq.slice x.g_all 0 i let _is_prefix_of (x y: t) : Tot prop = x.len0 == y.len0 /\ x.buf == y.buf /\ x.perm_of == y.perm_of /\ U32.v x.len <= U32.v y.len /\ x.pos == y.pos /\ x.g_all_buf == y.g_all_buf /\ Ghost.reveal x.g_all == Seq.slice (Ghost.reveal y.g_all) 0 (U32.v x.len) let _get_suffix (x y: t) : Ghost (Seq.seq U8.t) (requires (x `_is_prefix_of` y)) (ensures (fun _ -> True)) = Seq.slice (Ghost.reveal y.g_all) (U32.v x.len) (U32.v y.len) #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false" #restart-solver let _is_prefix_of_prop (x: t) (y: t) (h: HS.mem) : Lemma (requires ( _live x h /\ x `_is_prefix_of` y )) (ensures ( _live y h /\ _get_read y h `Seq.equal` _get_read x h /\ _get_remaining y h `Seq.equal` (_get_remaining x h `Seq.append` _get_suffix x y) ))
false
false
EverParse3d.InputStream.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "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": [ "smt.qi.eager_threshold=100", "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 8, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val _is_prefix_of_prop (x y: t) (h: HS.mem) : Lemma (requires (_live x h /\ x `_is_prefix_of` y)) (ensures (_live y h /\ (_get_read y h) `Seq.equal` (_get_read x h) /\ (_get_remaining y h) `Seq.equal` ((_get_remaining x h) `Seq.append` (_get_suffix x y))))
[]
EverParse3d.InputStream.Buffer._is_prefix_of_prop
{ "file_name": "src/3d/prelude/buffer/EverParse3d.InputStream.Buffer.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: EverParse3d.InputStream.Buffer.t -> y: EverParse3d.InputStream.Buffer.t -> h: FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (requires EverParse3d.InputStream.Buffer.Aux._live x h /\ EverParse3d.InputStream.Buffer._is_prefix_of x y) (ensures EverParse3d.InputStream.Buffer.Aux._live y h /\ FStar.Seq.Base.equal (EverParse3d.InputStream.Buffer._get_read y h) (EverParse3d.InputStream.Buffer._get_read x h) /\ FStar.Seq.Base.equal (EverParse3d.InputStream.Buffer.Aux._get_remaining y h) (FStar.Seq.Base.append (EverParse3d.InputStream.Buffer.Aux._get_remaining x h) (EverParse3d.InputStream.Buffer._get_suffix x y)))
{ "end_col": 91, "end_line": 66, "start_col": 2, "start_line": 64 }
Prims.Tot
val inst : input_stream_inst t
[ { "abbrev": true, "full_module": "EverParse3d.Readable", "short_module": "IR" }, { "abbrev": true, "full_module": "EverParse3d.InputBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Buffer.Aux", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Base", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "EverParse3d.InputStream", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let inst = { live = _live; footprint = _footprint; perm_footprint = _perm_footprint; live_not_unused_in = begin fun x h -> () end; len_all = begin fun x -> uint32_to_uint64 x.len end; get_all = begin fun x -> Ghost.reveal x.g_all end; get_remaining = begin fun x h -> _get_remaining x h end; get_read = begin fun x h -> _get_read x h end; preserved = begin fun x l h h' -> () end; tlen = _tlen; extra_t = unit; has = begin fun x xlen currentPosition n -> n `U64.lte` (xlen `U64.sub` currentPosition) end; read = begin fun _ k p r x currentPosition n -> let h = HST.get () in LP.parser_kind_prop_equiv k p; x.pos *= uint64_to_uint32 (currentPosition `U64.add` n); let h1 = HST.get () in LP.parse_strong_prefix p (_get_remaining x h) (LP.bytes_of_slice_from_to h (IB.slice_of x.buf) (uint64_to_uint32 currentPosition) x.len0); LP.parse_strong_prefix p (_get_remaining x h) (LP.bytes_of_slice_from_to h (IB.slice_of x.buf) (uint64_to_uint32 currentPosition) (uint64_to_uint32 (currentPosition `U64.add` n))); LP.valid_facts p h (IB.slice_of x.buf) (uint64_to_uint32 currentPosition); IR.readable_split' h x.perm_of (uint64_to_uint32 currentPosition) (uint64_to_uint32 (currentPosition `U64.add` n)) x.len0; let prf (h': HS.mem) : Lemma (requires ( let pos = uint64_to_uint32 currentPosition in let pos' = uint64_to_uint32 (currentPosition `U64.add` n) in B.modifies (IR.loc_perm x.perm_of) h1 h' /\ IR.preserved x.perm_of 0ul pos h1 h' /\ IR.preserved x.perm_of pos' (B.len (IB.slice_of x.buf).LP.base) h1 h' /\ IR.unreadable h' x.perm_of pos pos' /\ IB.live_input_buffer h' x.buf x.perm_of )) (ensures ( IR.unreadable h' x.perm_of 0ul (B.deref h' x.pos) /\ IR.readable h' x.perm_of (B.deref h' x.pos) x.len0 )) [SMTPat (B.modifies (IR.loc_perm x.perm_of) h1 h')] // this lemma *with SMT pattern* allows tail call to the reader, thus removing spurious temporary assignments in the generated C code = IR.unreadable_frame0 h1 x.perm_of 0ul (uint64_to_uint32 currentPosition) h' ; IR.unreadable_merge' h' x.perm_of 0ul (uint64_to_uint32 currentPosition) (uint64_to_uint32 (currentPosition `U64.add` n)); IR.readable_frame0 h1 x.perm_of (uint64_to_uint32 (currentPosition `U64.add` n)) x.len0 h' in IB.read_with_perm r x.buf (uint64_to_uint32 currentPosition) (uint64_to_uint32 n) x.perm_of end; skip = begin fun x currentPosition n -> let h0 = HST.get () in IR.readable_split' h0 x.perm_of (uint64_to_uint32 currentPosition) (uint64_to_uint32 (currentPosition `U64.add` n)) x.len0; x.pos *= uint64_to_uint32 (currentPosition `U64.add` n); let h1 = HST.get () in IB.drop x.buf (uint64_to_uint32 currentPosition) (uint64_to_uint32 (currentPosition `U64.add` n)) x.perm_of; let h' = HST.get () in IR.unreadable_frame0 h1 x.perm_of 0ul (uint64_to_uint32 currentPosition) h'; IR.unreadable_merge' h' x.perm_of 0ul (uint64_to_uint32 currentPosition) (uint64_to_uint32 (currentPosition `U64.add` n)); IR.readable_frame0 h1 x.perm_of (uint64_to_uint32 (currentPosition `U64.add` n)) x.len0 h' ; () end; skip_if_success = begin fun x currentPosition res -> let h0 = HST.get () in let pos0 = !* x.pos in let pos1 = Ghost.hide (if EverParse3d.ErrorCode.is_success res then uint64_to_uint32 res else Ghost.reveal pos0) in x.pos *= pos1; let h1 = HST.get () in IR.readable_split' h1 x.perm_of pos0 pos1 x.len0; IB.drop x.buf pos0 pos1 x.perm_of; let h2 = HST.get () in IR.unreadable_frame0 h1 x.perm_of 0ul pos0 h2; IR.unreadable_merge' h2 x.perm_of 0ul pos0 pos1; IR.readable_frame0 h1 x.perm_of pos1 x.len0 h2 end; empty = begin fun x xlen _ -> let h0 = HST.get () in let pos0 = !* x.pos in x.pos *= x.len; let h1 = HST.get () in IR.readable_split' h1 x.perm_of pos0 x.len x.len0; IB.drop x.buf pos0 x.len x.perm_of; let h2 = HST.get () in IR.unreadable_frame0 h1 x.perm_of 0ul pos0 h2; IR.unreadable_merge' h2 x.perm_of 0ul pos0 x.len; IR.readable_frame0 h1 x.perm_of x.len x.len0 h2; xlen end; is_prefix_of = _is_prefix_of; get_suffix = _get_suffix; is_prefix_of_prop = _is_prefix_of_prop; truncate = begin fun x currentPosition n -> { len0 = x.len0; buf = x.buf; perm_of = x.perm_of; len = uint64_to_uint32 (currentPosition `U64.add` n); pos = x.pos; g_all = Ghost.hide (Seq.slice (Ghost.reveal x.g_all) 0 (U64.v currentPosition + U64.v n)); g_all_buf = x.g_all_buf; prf = (); } end; truncate_len = begin fun x currentPosition n truncated -> currentPosition `U64.add` n end; }
val inst : input_stream_inst t let inst =
false
null
false
{ live = _live; footprint = _footprint; perm_footprint = _perm_footprint; live_not_unused_in = (fun x h -> ()); len_all = (fun x -> uint32_to_uint64 x.len); get_all = (fun x -> Ghost.reveal x.g_all); get_remaining = (fun x h -> _get_remaining x h); get_read = (fun x h -> _get_read x h); preserved = (fun x l h h' -> ()); tlen = _tlen; extra_t = unit; has = (fun x xlen currentPosition n -> n `U64.lte` (xlen `U64.sub` currentPosition)); read = (fun _ k p r x currentPosition n -> let h = HST.get () in LP.parser_kind_prop_equiv k p; x.pos *= uint64_to_uint32 (currentPosition `U64.add` n); let h1 = HST.get () in LP.parse_strong_prefix p (_get_remaining x h) (LP.bytes_of_slice_from_to h (IB.slice_of x.buf) (uint64_to_uint32 currentPosition) x.len0); LP.parse_strong_prefix p (_get_remaining x h) (LP.bytes_of_slice_from_to h (IB.slice_of x.buf) (uint64_to_uint32 currentPosition) (uint64_to_uint32 (currentPosition `U64.add` n))); LP.valid_facts p h (IB.slice_of x.buf) (uint64_to_uint32 currentPosition); IR.readable_split' h x.perm_of (uint64_to_uint32 currentPosition) (uint64_to_uint32 (currentPosition `U64.add` n)) x.len0; let prf (h': HS.mem) : Lemma (requires (let pos = uint64_to_uint32 currentPosition in let pos' = uint64_to_uint32 (currentPosition `U64.add` n) in B.modifies (IR.loc_perm x.perm_of) h1 h' /\ IR.preserved x.perm_of 0ul pos h1 h' /\ IR.preserved x.perm_of pos' (B.len (IB.slice_of x.buf).LP.base) h1 h' /\ IR.unreadable h' x.perm_of pos pos' /\ IB.live_input_buffer h' x.buf x.perm_of)) (ensures (IR.unreadable h' x.perm_of 0ul (B.deref h' x.pos) /\ IR.readable h' x.perm_of (B.deref h' x.pos) x.len0)) [SMTPat (B.modifies (IR.loc_perm x.perm_of) h1 h')] = IR.unreadable_frame0 h1 x.perm_of 0ul (uint64_to_uint32 currentPosition) h'; IR.unreadable_merge' h' x.perm_of 0ul (uint64_to_uint32 currentPosition) (uint64_to_uint32 (currentPosition `U64.add` n)); IR.readable_frame0 h1 x.perm_of (uint64_to_uint32 (currentPosition `U64.add` n)) x.len0 h' in IB.read_with_perm r x.buf (uint64_to_uint32 currentPosition) (uint64_to_uint32 n) x.perm_of); skip = (fun x currentPosition n -> let h0 = HST.get () in IR.readable_split' h0 x.perm_of (uint64_to_uint32 currentPosition) (uint64_to_uint32 (currentPosition `U64.add` n)) x.len0; x.pos *= uint64_to_uint32 (currentPosition `U64.add` n); let h1 = HST.get () in IB.drop x.buf (uint64_to_uint32 currentPosition) (uint64_to_uint32 (currentPosition `U64.add` n)) x.perm_of; let h' = HST.get () in IR.unreadable_frame0 h1 x.perm_of 0ul (uint64_to_uint32 currentPosition) h'; IR.unreadable_merge' h' x.perm_of 0ul (uint64_to_uint32 currentPosition) (uint64_to_uint32 (currentPosition `U64.add` n)); IR.readable_frame0 h1 x.perm_of (uint64_to_uint32 (currentPosition `U64.add` n)) x.len0 h'; ()); skip_if_success = (fun x currentPosition res -> let h0 = HST.get () in let pos0 = !*x.pos in let pos1 = Ghost.hide (if EverParse3d.ErrorCode.is_success res then uint64_to_uint32 res else Ghost.reveal pos0) in x.pos *= pos1; let h1 = HST.get () in IR.readable_split' h1 x.perm_of pos0 pos1 x.len0; IB.drop x.buf pos0 pos1 x.perm_of; let h2 = HST.get () in IR.unreadable_frame0 h1 x.perm_of 0ul pos0 h2; IR.unreadable_merge' h2 x.perm_of 0ul pos0 pos1; IR.readable_frame0 h1 x.perm_of pos1 x.len0 h2); empty = (fun x xlen _ -> let h0 = HST.get () in let pos0 = !*x.pos in x.pos *= x.len; let h1 = HST.get () in IR.readable_split' h1 x.perm_of pos0 x.len x.len0; IB.drop x.buf pos0 x.len x.perm_of; let h2 = HST.get () in IR.unreadable_frame0 h1 x.perm_of 0ul pos0 h2; IR.unreadable_merge' h2 x.perm_of 0ul pos0 x.len; IR.readable_frame0 h1 x.perm_of x.len x.len0 h2; xlen); is_prefix_of = _is_prefix_of; get_suffix = _get_suffix; is_prefix_of_prop = _is_prefix_of_prop; truncate = (fun x currentPosition n -> { len0 = x.len0; buf = x.buf; perm_of = x.perm_of; len = uint64_to_uint32 (currentPosition `U64.add` n); pos = x.pos; g_all = Ghost.hide (Seq.slice (Ghost.reveal x.g_all) 0 (U64.v currentPosition + U64.v n)); g_all_buf = x.g_all_buf; prf = () }); truncate_len = fun x currentPosition n truncated -> currentPosition `U64.add` n }
{ "checked_file": "EverParse3d.InputStream.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.Ghost.fsti.checked", "EverParse3d.Readable.fsti.checked", "EverParse3d.InputStream.Buffer.Aux.fst.checked", "EverParse3d.InputBuffer.fsti.checked", "EverParse3d.ErrorCode.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.InputStream.Buffer.fst" }
[ "total" ]
[ "EverParse3d.InputStream.Base.Mkinput_stream_inst", "EverParse3d.InputStream.Buffer.Aux.input_buffer", "EverParse3d.InputStream.Buffer.Aux._live", "EverParse3d.InputStream.Buffer.Aux._footprint", "EverParse3d.InputStream.Buffer.Aux._perm_footprint", "FStar.Monotonic.HyperStack.mem", "Prims.unit", "EverParse3d.InputStream.Buffer.uint32_to_uint64", "FStar.Ghost.reveal", "FStar.UInt32.t", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__len", "EverParse3d.ErrorCode.pos_t", "FStar.Seq.Base.seq", "FStar.UInt8.t", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__g_all", "EverParse3d.InputStream.Buffer.Aux._get_remaining", "EverParse3d.InputStream.Buffer._get_read", "LowStar.Monotonic.Buffer.loc", "EverParse3d.InputStream.Buffer._tlen", "FStar.UInt64.t", "FStar.UInt64.lte", "FStar.UInt64.sub", "Prims.bool", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Low.Base.leaf_reader", "EverParse3d.InputBuffer.read_with_perm", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__len0", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__buf", "EverParse3d.InputStream.Buffer.uint64_to_uint32", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__perm_of", "Prims.l_and", "LowStar.Monotonic.Buffer.modifies", "EverParse3d.Readable.loc_perm", "LowParse.Bytes.byte", "LowParse.Slice.__proj__Mkslice__item__base", "EverParse3d.InputBuffer.triv", "EverParse3d.InputBuffer.slice_of", "EverParse3d.Readable.preserved", "FStar.UInt32.uint_to_t", "FStar.UInt64.add", "LowStar.Monotonic.Buffer.len", "LowParse.Slice.buffer_srel_of_srel", "EverParse3d.Readable.unreadable", "EverParse3d.InputBuffer.live_input_buffer", "Prims.squash", "LowStar.Monotonic.Buffer.get", "FStar.Ghost.erased", "LowStar.Buffer.trivial_preorder", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__pos", "EverParse3d.Readable.readable", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil", "EverParse3d.Readable.readable_frame0", "EverParse3d.Readable.unreadable_merge'", "FStar.UInt32.__uint_to_t", "EverParse3d.Readable.unreadable_frame0", "LowStar.Monotonic.Buffer.deref", "EverParse3d.Readable.readable_split'", "LowParse.Low.Base.Spec.valid_facts", "LowParse.Spec.Base.parse_strong_prefix", "LowParse.Low.Base.Spec.bytes_of_slice_from_to", "FStar.HyperStack.ST.get", "LowStar.BufferOps.op_Star_Equals", "FStar.Ghost.hide", "LowParse.Spec.Base.parser_kind_prop_equiv", "EverParse3d.InputBuffer.drop", "EverParse3d.ErrorCode.is_success", "LowStar.BufferOps.op_Bang_Star", "EverParse3d.InputStream.Buffer._is_prefix_of", "EverParse3d.InputStream.Buffer._get_suffix", "EverParse3d.InputStream.Buffer._is_prefix_of_prop", "EverParse3d.InputStream.Buffer.Aux.Mkinput_buffer", "EverParse3d.InputStream.Buffer.Aux.__proj__Mkinput_buffer__item__g_all_buf", "FStar.Seq.Base.slice", "Prims.op_Addition", "FStar.UInt64.v" ]
[]
module EverParse3d.InputStream.Buffer open EverParse3d.InputStream.Buffer.Aux (* Implementation for single buffers *) module U64 = FStar.UInt64 let t = t inline_for_extraction noextract let _tlen (x: t) : Tot Type0 = (len: U64.t { U64.v len == U32.v x.len }) let _get_read (x: t) (h: HS.mem) : Ghost (Seq.seq U8.t) (requires (_live x h)) (ensures (fun y -> Ghost.reveal x.g_all == y `Seq.append` _get_remaining x h)) = let i = U32.v (B.deref h x.pos) in Seq.lemma_split x.g_all i; Seq.slice x.g_all 0 i let _is_prefix_of (x y: t) : Tot prop = x.len0 == y.len0 /\ x.buf == y.buf /\ x.perm_of == y.perm_of /\ U32.v x.len <= U32.v y.len /\ x.pos == y.pos /\ x.g_all_buf == y.g_all_buf /\ Ghost.reveal x.g_all == Seq.slice (Ghost.reveal y.g_all) 0 (U32.v x.len) let _get_suffix (x y: t) : Ghost (Seq.seq U8.t) (requires (x `_is_prefix_of` y)) (ensures (fun _ -> True)) = Seq.slice (Ghost.reveal y.g_all) (U32.v x.len) (U32.v y.len) #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false" #restart-solver let _is_prefix_of_prop (x: t) (y: t) (h: HS.mem) : Lemma (requires ( _live x h /\ x `_is_prefix_of` y )) (ensures ( _live y h /\ _get_read y h `Seq.equal` _get_read x h /\ _get_remaining y h `Seq.equal` (_get_remaining x h `Seq.append` _get_suffix x y) )) = assert (_live y h); assert (_get_read y h `Seq.equal` _get_read x h); assert (_get_remaining y h `Seq.equal` (_get_remaining x h `Seq.append` _get_suffix x y)) open LowStar.BufferOps #restart-solver module U64 = FStar.UInt64 inline_for_extraction noextract let uint32_to_uint64 (x: U32.t) : Pure U64.t (requires True) (ensures (fun y -> U64.v y == U32.v x)) = FStar.Int.Cast.uint32_to_uint64 x inline_for_extraction noextract let uint64_to_uint32 (x: U64.t) : Pure U32.t (requires (U64.v x < 4294967296)) (ensures (fun y -> U32.v y == U64.v x)) = FStar.Math.Lemmas.modulo_lemma (U64.v x) 4294967296; FStar.Int.Cast.uint64_to_uint32 x module LP = LowParse.Low.Base module IB = EverParse3d.InputBuffer module IR = EverParse3d.Readable let inst = {
false
true
EverParse3d.InputStream.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "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": [ "smt.qi.eager_threshold=100", "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 8, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val inst : input_stream_inst t
[]
EverParse3d.InputStream.Buffer.inst
{ "file_name": "src/3d/prelude/buffer/EverParse3d.InputStream.Buffer.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
EverParse3d.InputStream.Base.input_stream_inst EverParse3d.InputStream.Buffer.t
{ "end_col": 6, "end_line": 231, "start_col": 2, "start_line": 99 }
Prims.Tot
val aead_decrypt:aead_decrypt_st M256
[ { "abbrev": false, "full_module": "Hacl.Poly1305_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Fields", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Meta.Chacha20Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let aead_decrypt : aead_decrypt_st M256 = chacha20poly1305_aead_decrypt_higher #M256 True Hacl.Chacha20.Vec256.chacha20_encrypt_256 poly1305_do_256
val aead_decrypt:aead_decrypt_st M256 let aead_decrypt:aead_decrypt_st M256 =
false
null
false
chacha20poly1305_aead_decrypt_higher #M256 True Hacl.Chacha20.Vec256.chacha20_encrypt_256 poly1305_do_256
{ "checked_file": "Hacl.Chacha20Poly1305_256.fst.checked", "dependencies": [ "prims.fst.checked", "Hacl.Poly1305_256.fsti.checked", "Hacl.Meta.Chacha20Poly1305.fst.checked", "Hacl.Impl.Poly1305.Fields.fst.checked", "Hacl.Impl.Chacha20Poly1305.PolyCore.fst.checked", "Hacl.Impl.Chacha20Poly1305.fst.checked", "Hacl.Chacha20.Vec256.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Chacha20Poly1305_256.fst" }
[ "total" ]
[ "Hacl.Meta.Chacha20Poly1305.chacha20poly1305_aead_decrypt_higher", "Hacl.Impl.Poly1305.Fields.M256", "Prims.l_True", "Hacl.Chacha20.Vec256.chacha20_encrypt_256", "Hacl.Chacha20Poly1305_256.poly1305_do_256" ]
[]
module Hacl.Chacha20Poly1305_256 open Hacl.Meta.Chacha20Poly1305 open Hacl.Impl.Chacha20Poly1305 open Hacl.Impl.Poly1305.Fields open Hacl.Poly1305_256 #set-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" [@CInline] private let poly1305_padded_256 = Hacl.Impl.Chacha20Poly1305.PolyCore.poly1305_padded #M256 [@CInline] private let poly1305_do_256 = chacha20poly1305_poly1305_do_higher #M256 True poly1305_finish poly1305_init poly1305_padded_256 [@@ Comment "Encrypt a message `m` with key `k`. The arguments `k`, `n`, `aadlen`, and `aad` are same in encryption/decryption. Note: Encryption and decryption can be executed in-place, i.e., `m` and `cipher` can point to the same memory. @param k Pointer to 32 bytes of memory where the AEAD key is read from. @param n Pointer to 12 bytes of memory where the AEAD nonce is read from. @param aadlen Length of the associated data. @param aad Pointer to `aadlen` bytes of memory where the associated data is read from. @param mlen Length of the message. @param m Pointer to `mlen` bytes of memory where the message is read from. @param cipher Pointer to `mlen` bytes of memory where the ciphertext is written to. @param mac Pointer to 16 bytes of memory where the mac is written to."] let aead_encrypt : aead_encrypt_st M256 = chacha20poly1305_aead_encrypt_higher #M256 True poly1305_do_256 Hacl.Chacha20.Vec256.chacha20_encrypt_256 [@@ Comment "Decrypt a ciphertext `cipher` with key `k`. The arguments `k`, `n`, `aadlen`, and `aad` are same in encryption/decryption. Note: Encryption and decryption can be executed in-place, i.e., `m` and `cipher` can point to the same memory. If decryption succeeds, the resulting plaintext is stored in `m` and the function returns the success code 0. If decryption fails, the array `m` remains unchanged and the function returns the error code 1. @param k Pointer to 32 bytes of memory where the AEAD key is read from. @param n Pointer to 12 bytes of memory where the AEAD nonce is read from. @param aadlen Length of the associated data. @param aad Pointer to `aadlen` bytes of memory where the associated data is read from. @param mlen Length of the ciphertext. @param m Pointer to `mlen` bytes of memory where the message is written to. @param cipher Pointer to `mlen` bytes of memory where the ciphertext is read from. @param mac Pointer to 16 bytes of memory where the mac is read from. @returns 0 on succeess; 1 on failure."]
false
false
Hacl.Chacha20Poly1305_256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val aead_decrypt:aead_decrypt_st M256
[]
Hacl.Chacha20Poly1305_256.aead_decrypt
{ "file_name": "code/chacha20poly1305/Hacl.Chacha20Poly1305_256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Impl.Chacha20Poly1305.aead_decrypt_st Hacl.Impl.Poly1305.Fields.M256
{ "end_col": 107, "end_line": 55, "start_col": 2, "start_line": 55 }
Prims.Tot
[ { "abbrev": false, "full_module": "Hacl.Poly1305_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Fields", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Meta.Chacha20Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let poly1305_padded_256 = Hacl.Impl.Chacha20Poly1305.PolyCore.poly1305_padded #M256
let poly1305_padded_256 =
false
null
false
Hacl.Impl.Chacha20Poly1305.PolyCore.poly1305_padded #M256
{ "checked_file": "Hacl.Chacha20Poly1305_256.fst.checked", "dependencies": [ "prims.fst.checked", "Hacl.Poly1305_256.fsti.checked", "Hacl.Meta.Chacha20Poly1305.fst.checked", "Hacl.Impl.Poly1305.Fields.fst.checked", "Hacl.Impl.Chacha20Poly1305.PolyCore.fst.checked", "Hacl.Impl.Chacha20Poly1305.fst.checked", "Hacl.Chacha20.Vec256.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Chacha20Poly1305_256.fst" }
[ "total" ]
[ "Hacl.Impl.Chacha20Poly1305.PolyCore.poly1305_padded", "Hacl.Impl.Poly1305.Fields.M256" ]
[]
module Hacl.Chacha20Poly1305_256 open Hacl.Meta.Chacha20Poly1305 open Hacl.Impl.Chacha20Poly1305 open Hacl.Impl.Poly1305.Fields open Hacl.Poly1305_256 #set-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" [@CInline]
false
true
Hacl.Chacha20Poly1305_256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val poly1305_padded_256 : Hacl.Impl.Chacha20Poly1305.PolyCore.poly1305_padded_st Hacl.Impl.Poly1305.Fields.M256
[]
Hacl.Chacha20Poly1305_256.poly1305_padded_256
{ "file_name": "code/chacha20poly1305/Hacl.Chacha20Poly1305_256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Impl.Chacha20Poly1305.PolyCore.poly1305_padded_st Hacl.Impl.Poly1305.Fields.M256
{ "end_col": 83, "end_line": 12, "start_col": 26, "start_line": 12 }
Prims.Tot
val aead_encrypt:aead_encrypt_st M256
[ { "abbrev": false, "full_module": "Hacl.Poly1305_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Fields", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Meta.Chacha20Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let aead_encrypt : aead_encrypt_st M256 = chacha20poly1305_aead_encrypt_higher #M256 True poly1305_do_256 Hacl.Chacha20.Vec256.chacha20_encrypt_256
val aead_encrypt:aead_encrypt_st M256 let aead_encrypt:aead_encrypt_st M256 =
false
null
false
chacha20poly1305_aead_encrypt_higher #M256 True poly1305_do_256 Hacl.Chacha20.Vec256.chacha20_encrypt_256
{ "checked_file": "Hacl.Chacha20Poly1305_256.fst.checked", "dependencies": [ "prims.fst.checked", "Hacl.Poly1305_256.fsti.checked", "Hacl.Meta.Chacha20Poly1305.fst.checked", "Hacl.Impl.Poly1305.Fields.fst.checked", "Hacl.Impl.Chacha20Poly1305.PolyCore.fst.checked", "Hacl.Impl.Chacha20Poly1305.fst.checked", "Hacl.Chacha20.Vec256.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Chacha20Poly1305_256.fst" }
[ "total" ]
[ "Hacl.Meta.Chacha20Poly1305.chacha20poly1305_aead_encrypt_higher", "Hacl.Impl.Poly1305.Fields.M256", "Prims.l_True", "Hacl.Chacha20Poly1305_256.poly1305_do_256", "Hacl.Chacha20.Vec256.chacha20_encrypt_256" ]
[]
module Hacl.Chacha20Poly1305_256 open Hacl.Meta.Chacha20Poly1305 open Hacl.Impl.Chacha20Poly1305 open Hacl.Impl.Poly1305.Fields open Hacl.Poly1305_256 #set-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" [@CInline] private let poly1305_padded_256 = Hacl.Impl.Chacha20Poly1305.PolyCore.poly1305_padded #M256 [@CInline] private let poly1305_do_256 = chacha20poly1305_poly1305_do_higher #M256 True poly1305_finish poly1305_init poly1305_padded_256 [@@ Comment "Encrypt a message `m` with key `k`. The arguments `k`, `n`, `aadlen`, and `aad` are same in encryption/decryption. Note: Encryption and decryption can be executed in-place, i.e., `m` and `cipher` can point to the same memory. @param k Pointer to 32 bytes of memory where the AEAD key is read from. @param n Pointer to 12 bytes of memory where the AEAD nonce is read from. @param aadlen Length of the associated data. @param aad Pointer to `aadlen` bytes of memory where the associated data is read from. @param mlen Length of the message. @param m Pointer to `mlen` bytes of memory where the message is read from. @param cipher Pointer to `mlen` bytes of memory where the ciphertext is written to. @param mac Pointer to 16 bytes of memory where the mac is written to."]
false
false
Hacl.Chacha20Poly1305_256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val aead_encrypt:aead_encrypt_st M256
[]
Hacl.Chacha20Poly1305_256.aead_encrypt
{ "file_name": "code/chacha20poly1305/Hacl.Chacha20Poly1305_256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Impl.Chacha20Poly1305.aead_encrypt_st Hacl.Impl.Poly1305.Fields.M256
{ "end_col": 107, "end_line": 33, "start_col": 2, "start_line": 33 }
Prims.Tot
[ { "abbrev": false, "full_module": "Hacl.Poly1305_256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Fields", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Meta.Chacha20Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let poly1305_do_256 = chacha20poly1305_poly1305_do_higher #M256 True poly1305_finish poly1305_init poly1305_padded_256
let poly1305_do_256 =
false
null
false
chacha20poly1305_poly1305_do_higher #M256 True poly1305_finish poly1305_init poly1305_padded_256
{ "checked_file": "Hacl.Chacha20Poly1305_256.fst.checked", "dependencies": [ "prims.fst.checked", "Hacl.Poly1305_256.fsti.checked", "Hacl.Meta.Chacha20Poly1305.fst.checked", "Hacl.Impl.Poly1305.Fields.fst.checked", "Hacl.Impl.Chacha20Poly1305.PolyCore.fst.checked", "Hacl.Impl.Chacha20Poly1305.fst.checked", "Hacl.Chacha20.Vec256.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Chacha20Poly1305_256.fst" }
[ "total" ]
[ "Hacl.Meta.Chacha20Poly1305.chacha20poly1305_poly1305_do_higher", "Hacl.Impl.Poly1305.Fields.M256", "Prims.l_True", "Hacl.Poly1305_256.poly1305_finish", "Hacl.Poly1305_256.poly1305_init", "Hacl.Chacha20Poly1305_256.poly1305_padded_256" ]
[]
module Hacl.Chacha20Poly1305_256 open Hacl.Meta.Chacha20Poly1305 open Hacl.Impl.Chacha20Poly1305 open Hacl.Impl.Poly1305.Fields open Hacl.Poly1305_256 #set-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" [@CInline] private let poly1305_padded_256 = Hacl.Impl.Chacha20Poly1305.PolyCore.poly1305_padded #M256 [@CInline]
false
true
Hacl.Chacha20Poly1305_256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val poly1305_do_256 : Hacl.Meta.Chacha20Poly1305.chacha20poly1305_poly1305_do_higher_t Prims.l_True
[]
Hacl.Chacha20Poly1305_256.poly1305_do_256
{ "file_name": "code/chacha20poly1305/Hacl.Chacha20Poly1305_256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Meta.Chacha20Poly1305.chacha20poly1305_poly1305_do_higher_t Prims.l_True
{ "end_col": 118, "end_line": 16, "start_col": 22, "start_line": 16 }
FStar.HyperStack.ST.Stack
val fdifference: out:felem -> a:felem -> b:felem -> Stack unit (requires fun h -> live h a /\ live h b /\ live h out /\ eq_or_disjoint a b /\ eq_or_disjoint a out /\ eq_or_disjoint b out /\ F51.felem_fits h a (1, 2, 1, 1, 1) /\ F51.felem_fits h b (1, 2, 1, 1, 1) ) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.felem_fits h1 out (9, 10, 9, 9, 9) /\ F51.fevalh h1 out == F51.fevalh h0 a `SC.fsub` F51.fevalh h0 b )
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": "SL51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let fdifference out a b = BN.fsub out a b
val fdifference: out:felem -> a:felem -> b:felem -> Stack unit (requires fun h -> live h a /\ live h b /\ live h out /\ eq_or_disjoint a b /\ eq_or_disjoint a out /\ eq_or_disjoint b out /\ F51.felem_fits h a (1, 2, 1, 1, 1) /\ F51.felem_fits h b (1, 2, 1, 1, 1) ) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.felem_fits h1 out (9, 10, 9, 9, 9) /\ F51.fevalh h1 out == F51.fevalh h0 a `SC.fsub` F51.fevalh h0 b ) let fdifference out a b =
true
null
false
BN.fsub out a b
{ "checked_file": "Hacl.Bignum25519.fst.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Spec.Curve25519.Field51.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "Hacl.Curve25519_51.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum25519.fst" }
[]
[ "Hacl.Bignum25519.felem", "Hacl.Impl.Curve25519.Field51.fsub", "Prims.unit" ]
[]
module Hacl.Bignum25519 module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S51 = Hacl.Spec.Curve25519.Field51.Definition module SL51 = Hacl.Spec.Curve25519.Field51.Lemmas module BN = Hacl.Impl.Curve25519.Field51 module SC = Spec.Curve25519 friend Hacl.Curve25519_51 #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask_51 = u64 0x7ffffffffffff let make_u64_5 b s0 s1 s2 s3 s4 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4 let make_u64_10 b s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4; b.(5ul) <- s5; b.(6ul) <- s6; b.(7ul) <- s7; b.(8ul) <- s8; b.(9ul) <- s9 let make_zero b = b.(0ul) <- u64 0; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 0, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 0) let make_one b = b.(0ul) <- u64 1; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 1, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 1) [@CInline] let fsum out a b = BN.fadd out a b [@CInline]
false
false
Hacl.Bignum25519.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val fdifference: out:felem -> a:felem -> b:felem -> Stack unit (requires fun h -> live h a /\ live h b /\ live h out /\ eq_or_disjoint a b /\ eq_or_disjoint a out /\ eq_or_disjoint b out /\ F51.felem_fits h a (1, 2, 1, 1, 1) /\ F51.felem_fits h b (1, 2, 1, 1, 1) ) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.felem_fits h1 out (9, 10, 9, 9, 9) /\ F51.fevalh h1 out == F51.fevalh h0 a `SC.fsub` F51.fevalh h0 b )
[]
Hacl.Bignum25519.fdifference
{ "file_name": "code/ed25519/Hacl.Bignum25519.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
out: Hacl.Bignum25519.felem -> a: Hacl.Bignum25519.felem -> b: Hacl.Bignum25519.felem -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 17, "end_line": 69, "start_col": 2, "start_line": 69 }
Prims.Tot
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": "SL51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mask_51 = u64 0x7ffffffffffff
let mask_51 =
false
null
false
u64 0x7ffffffffffff
{ "checked_file": "Hacl.Bignum25519.fst.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Spec.Curve25519.Field51.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "Hacl.Curve25519_51.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum25519.fst" }
[ "total" ]
[ "Lib.IntTypes.u64" ]
[]
module Hacl.Bignum25519 module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S51 = Hacl.Spec.Curve25519.Field51.Definition module SL51 = Hacl.Spec.Curve25519.Field51.Lemmas module BN = Hacl.Impl.Curve25519.Field51 module SC = Spec.Curve25519 friend Hacl.Curve25519_51 #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0"
false
false
Hacl.Bignum25519.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mask_51 : u4: Lib.IntTypes.uint64{Lib.IntTypes.v u4 == 0x7ffffffffffff}
[]
Hacl.Bignum25519.mask_51
{ "file_name": "code/ed25519/Hacl.Bignum25519.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
u4: Lib.IntTypes.uint64{Lib.IntTypes.v u4 == 0x7ffffffffffff}
{ "end_col": 33, "end_line": 24, "start_col": 14, "start_line": 24 }
FStar.HyperStack.ST.Stack
val fsum: out:felem -> a:felem -> b:felem -> Stack unit (requires fun h -> live h a /\ live h b /\ live h out /\ eq_or_disjoint a b /\ eq_or_disjoint a out /\ eq_or_disjoint b out /\ F51.felem_fits h a (1, 2, 1, 1, 1) /\ F51.felem_fits h b (1, 2, 1, 1, 1) ) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.felem_fits h1 out (2, 4, 2, 2, 2) /\ F51.fevalh h1 out == F51.fevalh h0 a `SC.fadd` F51.fevalh h0 b )
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": "SL51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let fsum out a b = BN.fadd out a b
val fsum: out:felem -> a:felem -> b:felem -> Stack unit (requires fun h -> live h a /\ live h b /\ live h out /\ eq_or_disjoint a b /\ eq_or_disjoint a out /\ eq_or_disjoint b out /\ F51.felem_fits h a (1, 2, 1, 1, 1) /\ F51.felem_fits h b (1, 2, 1, 1, 1) ) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.felem_fits h1 out (2, 4, 2, 2, 2) /\ F51.fevalh h1 out == F51.fevalh h0 a `SC.fadd` F51.fevalh h0 b ) let fsum out a b =
true
null
false
BN.fadd out a b
{ "checked_file": "Hacl.Bignum25519.fst.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Spec.Curve25519.Field51.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "Hacl.Curve25519_51.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum25519.fst" }
[]
[ "Hacl.Bignum25519.felem", "Hacl.Impl.Curve25519.Field51.fadd", "Prims.unit" ]
[]
module Hacl.Bignum25519 module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S51 = Hacl.Spec.Curve25519.Field51.Definition module SL51 = Hacl.Spec.Curve25519.Field51.Lemmas module BN = Hacl.Impl.Curve25519.Field51 module SC = Spec.Curve25519 friend Hacl.Curve25519_51 #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask_51 = u64 0x7ffffffffffff let make_u64_5 b s0 s1 s2 s3 s4 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4 let make_u64_10 b s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4; b.(5ul) <- s5; b.(6ul) <- s6; b.(7ul) <- s7; b.(8ul) <- s8; b.(9ul) <- s9 let make_zero b = b.(0ul) <- u64 0; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 0, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 0) let make_one b = b.(0ul) <- u64 1; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 1, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 1) [@CInline]
false
false
Hacl.Bignum25519.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val fsum: out:felem -> a:felem -> b:felem -> Stack unit (requires fun h -> live h a /\ live h b /\ live h out /\ eq_or_disjoint a b /\ eq_or_disjoint a out /\ eq_or_disjoint b out /\ F51.felem_fits h a (1, 2, 1, 1, 1) /\ F51.felem_fits h b (1, 2, 1, 1, 1) ) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.felem_fits h1 out (2, 4, 2, 2, 2) /\ F51.fevalh h1 out == F51.fevalh h0 a `SC.fadd` F51.fevalh h0 b )
[]
Hacl.Bignum25519.fsum
{ "file_name": "code/ed25519/Hacl.Bignum25519.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
out: Hacl.Bignum25519.felem -> a: Hacl.Bignum25519.felem -> b: Hacl.Bignum25519.felem -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 17, "end_line": 64, "start_col": 2, "start_line": 64 }
Prims.Pure
val carry51: #m:S51.scale64{m < 8192} -> l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires S51.felem_fits1 l m /\ S51.felem_fits1 cin 1) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ S51.felem_fits1 l0 1 /\ uint_v l1 < m + 1)
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": "SL51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let carry51 l cin = let l' = l +! cin in mod_mask_lemma l' 51ul; assert (v (mod_mask #U64 #SEC 51ul) == v mask_51); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v l') 51 64; FStar.Math.Lemmas.euclidean_division_definition (v l') (pow2 51); FStar.Math.Lemmas.pow2_minus 64 51; (l' &. mask_51, l' >>. 51ul)
val carry51: #m:S51.scale64{m < 8192} -> l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires S51.felem_fits1 l m /\ S51.felem_fits1 cin 1) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ S51.felem_fits1 l0 1 /\ uint_v l1 < m + 1) let carry51 l cin =
false
null
false
let l' = l +! cin in mod_mask_lemma l' 51ul; assert (v (mod_mask #U64 #SEC 51ul) == v mask_51); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v l') 51 64; FStar.Math.Lemmas.euclidean_division_definition (v l') (pow2 51); FStar.Math.Lemmas.pow2_minus 64 51; (l' &. mask_51, l' >>. 51ul)
{ "checked_file": "Hacl.Bignum25519.fst.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Spec.Curve25519.Field51.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "Hacl.Curve25519_51.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum25519.fst" }
[]
[ "Hacl.Spec.Curve25519.Field51.Definition.scale64", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.uint64", "FStar.Pervasives.Native.Mktuple2", "Lib.IntTypes.op_Amp_Dot", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Hacl.Bignum25519.mask_51", "Lib.IntTypes.op_Greater_Greater_Dot", "FStar.UInt32.__uint_to_t", "Prims.unit", "FStar.Math.Lemmas.pow2_minus", "FStar.Math.Lemmas.euclidean_division_definition", "Lib.IntTypes.v", "Prims.pow2", "FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1", "Prims._assert", "Prims.eq2", "Lib.IntTypes.range_t", "Lib.IntTypes.mod_mask", "Lib.IntTypes.mod_mask_lemma", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Plus_Bang", "FStar.Pervasives.Native.tuple2" ]
[]
module Hacl.Bignum25519 module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S51 = Hacl.Spec.Curve25519.Field51.Definition module SL51 = Hacl.Spec.Curve25519.Field51.Lemmas module BN = Hacl.Impl.Curve25519.Field51 module SC = Spec.Curve25519 friend Hacl.Curve25519_51 #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask_51 = u64 0x7ffffffffffff let make_u64_5 b s0 s1 s2 s3 s4 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4 let make_u64_10 b s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4; b.(5ul) <- s5; b.(6ul) <- s6; b.(7ul) <- s7; b.(8ul) <- s8; b.(9ul) <- s9 let make_zero b = b.(0ul) <- u64 0; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 0, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 0) let make_one b = b.(0ul) <- u64 1; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 1, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 1) [@CInline] let fsum out a b = BN.fadd out a b [@CInline] let fdifference out a b = BN.fsub out a b inline_for_extraction noextract val carry51: #m:S51.scale64{m < 8192} -> l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires S51.felem_fits1 l m /\ S51.felem_fits1 cin 1) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ S51.felem_fits1 l0 1 /\ uint_v l1 < m + 1)
false
false
Hacl.Bignum25519.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val carry51: #m:S51.scale64{m < 8192} -> l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires S51.felem_fits1 l m /\ S51.felem_fits1 cin 1) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ S51.felem_fits1 l0 1 /\ uint_v l1 < m + 1)
[]
Hacl.Bignum25519.carry51
{ "file_name": "code/ed25519/Hacl.Bignum25519.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
l: Lib.IntTypes.uint64 -> cin: Lib.IntTypes.uint64 -> Prims.Pure (Lib.IntTypes.uint64 * Lib.IntTypes.uint64)
{ "end_col": 30, "end_line": 92, "start_col": 19, "start_line": 85 }
FStar.HyperStack.ST.Stack
val make_u64_5: b:lbuffer uint64 5ul -> s0:uint64 -> s1:uint64 -> s2:uint64 -> s3:uint64 -> s4:uint64 -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ F51.as_felem h1 b == (s0, s1, s2, s3, s4) /\ F51.as_nat h1 b == S51.as_nat5 (s0, s1, s2, s3, s4) )
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": "SL51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let make_u64_5 b s0 s1 s2 s3 s4 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4
val make_u64_5: b:lbuffer uint64 5ul -> s0:uint64 -> s1:uint64 -> s2:uint64 -> s3:uint64 -> s4:uint64 -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ F51.as_felem h1 b == (s0, s1, s2, s3, s4) /\ F51.as_nat h1 b == S51.as_nat5 (s0, s1, s2, s3, s4) ) let make_u64_5 b s0 s1 s2 s3 s4 =
true
null
false
b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4
{ "checked_file": "Hacl.Bignum25519.fst.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Spec.Curve25519.Field51.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "Hacl.Curve25519_51.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum25519.fst" }
[]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Lib.Buffer.op_Array_Assignment", "Prims.unit" ]
[]
module Hacl.Bignum25519 module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S51 = Hacl.Spec.Curve25519.Field51.Definition module SL51 = Hacl.Spec.Curve25519.Field51.Lemmas module BN = Hacl.Impl.Curve25519.Field51 module SC = Spec.Curve25519 friend Hacl.Curve25519_51 #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask_51 = u64 0x7ffffffffffff
false
false
Hacl.Bignum25519.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val make_u64_5: b:lbuffer uint64 5ul -> s0:uint64 -> s1:uint64 -> s2:uint64 -> s3:uint64 -> s4:uint64 -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ F51.as_felem h1 b == (s0, s1, s2, s3, s4) /\ F51.as_nat h1 b == S51.as_nat5 (s0, s1, s2, s3, s4) )
[]
Hacl.Bignum25519.make_u64_5
{ "file_name": "code/ed25519/Hacl.Bignum25519.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Lib.Buffer.lbuffer Lib.IntTypes.uint64 5ul -> s0: Lib.IntTypes.uint64 -> s1: Lib.IntTypes.uint64 -> s2: Lib.IntTypes.uint64 -> s3: Lib.IntTypes.uint64 -> s4: Lib.IntTypes.uint64 -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 15, "end_line": 31, "start_col": 2, "start_line": 27 }
FStar.HyperStack.ST.Stack
val reduce: out:felem -> Stack unit (requires fun h -> live h out /\ F51.mul_inv_t h out) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.felem_fits h1 out (1, 1, 1, 1, 1) /\ F51.fevalh h0 out == F51.fevalh h1 out /\ F51.fevalh h1 out == F51.as_nat h1 out )
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": "SL51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let reduce out = let (o0, o1, o2, o3, o4) = (out.(0ul), out.(1ul), out.(2ul), out.(3ul), out.(4ul)) in let (f0, f1, f2, f3, f4) = Hacl.Spec.Curve25519.Field51.carry_felem5_full (o0, o1, o2, o3, o4) in let (f0, f1, f2, f3, f4) = Hacl.Spec.Curve25519.Field51.subtract_p5 (f0, f1, f2, f3, f4) in Math.Lemmas.small_mod (S51.as_nat5 (f0, f1, f2, f3, f4)) Spec.Curve25519.prime; make_u64_5 out f0 f1 f2 f3 f4
val reduce: out:felem -> Stack unit (requires fun h -> live h out /\ F51.mul_inv_t h out) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.felem_fits h1 out (1, 1, 1, 1, 1) /\ F51.fevalh h0 out == F51.fevalh h1 out /\ F51.fevalh h1 out == F51.as_nat h1 out ) let reduce out =
true
null
false
let o0, o1, o2, o3, o4 = (out.(0ul), out.(1ul), out.(2ul), out.(3ul), out.(4ul)) in let f0, f1, f2, f3, f4 = Hacl.Spec.Curve25519.Field51.carry_felem5_full (o0, o1, o2, o3, o4) in let f0, f1, f2, f3, f4 = Hacl.Spec.Curve25519.Field51.subtract_p5 (f0, f1, f2, f3, f4) in Math.Lemmas.small_mod (S51.as_nat5 (f0, f1, f2, f3, f4)) Spec.Curve25519.prime; make_u64_5 out f0 f1 f2 f3 f4
{ "checked_file": "Hacl.Bignum25519.fst.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Spec.Curve25519.Field51.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "Hacl.Curve25519_51.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum25519.fst" }
[]
[ "Hacl.Bignum25519.felem", "Lib.IntTypes.uint64", "Hacl.Bignum25519.make_u64_5", "Prims.unit", "FStar.Math.Lemmas.small_mod", "Hacl.Spec.Curve25519.Field51.Definition.as_nat5", "FStar.Pervasives.Native.Mktuple5", "Spec.Curve25519.prime", "Hacl.Spec.Curve25519.Field51.Definition.felem5", "Hacl.Spec.Curve25519.Field51.subtract_p5", "Prims.l_and", "Prims.eq2", "Spec.Curve25519.elem", "Hacl.Spec.Curve25519.Field51.Definition.feval", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Hacl.Spec.Curve25519.Field51.Definition.felem_fits5", "Prims.nat", "Hacl.Spec.Curve25519.Field51.carry_felem5_full", "FStar.Pervasives.Native.tuple5", "Lib.Buffer.op_Array_Access", "Lib.Buffer.MUT", "FStar.UInt32.__uint_to_t" ]
[]
module Hacl.Bignum25519 module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S51 = Hacl.Spec.Curve25519.Field51.Definition module SL51 = Hacl.Spec.Curve25519.Field51.Lemmas module BN = Hacl.Impl.Curve25519.Field51 module SC = Spec.Curve25519 friend Hacl.Curve25519_51 #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask_51 = u64 0x7ffffffffffff let make_u64_5 b s0 s1 s2 s3 s4 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4 let make_u64_10 b s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4; b.(5ul) <- s5; b.(6ul) <- s6; b.(7ul) <- s7; b.(8ul) <- s8; b.(9ul) <- s9 let make_zero b = b.(0ul) <- u64 0; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 0, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 0) let make_one b = b.(0ul) <- u64 1; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 1, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 1) [@CInline] let fsum out a b = BN.fadd out a b [@CInline] let fdifference out a b = BN.fsub out a b inline_for_extraction noextract val carry51: #m:S51.scale64{m < 8192} -> l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires S51.felem_fits1 l m /\ S51.felem_fits1 cin 1) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ S51.felem_fits1 l0 1 /\ uint_v l1 < m + 1) let carry51 l cin = let l' = l +! cin in mod_mask_lemma l' 51ul; assert (v (mod_mask #U64 #SEC 51ul) == v mask_51); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v l') 51 64; FStar.Math.Lemmas.euclidean_division_definition (v l') (pow2 51); FStar.Math.Lemmas.pow2_minus 64 51; (l' &. mask_51, l' >>. 51ul) let reduce_513 a = let (f0, f1, f2, f3, f4) = (a.(0ul), a.(1ul), a.(2ul), a.(3ul), a.(4ul)) in let tmp0, c0 = carry51 #9 f0 (u64 0) in let tmp1, c1 = carry51 #10 f1 c0 in let tmp2, c2 = carry51 #9 f2 c1 in let tmp3, c3 = carry51 #9 f3 c2 in let tmp4, c4 = carry51 #9 f4 c3 in assert (S51.felem_fits5 (tmp0, tmp1, tmp2, tmp3, tmp4) (1, 1, 1, 1, 1)); SL51.lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; assert ( S51.as_nat5 (f0, f1, f2, f3, f4) % SC.prime == (S51.as_nat5 (tmp0, tmp1, tmp2, tmp3, tmp4) + v c4 * 19) % SC.prime); [@inline_let] let tmp0', c5 = carry51 #1 tmp0 (c4 *! u64 19) in [@inline_let] let tmp1' = tmp1 +! c5 in Hacl.Spec.Curve25519.Field51.lemma_mul_inv (tmp0', tmp1, tmp2, tmp3, tmp4) c5; make_u64_5 a tmp0' tmp1' tmp2 tmp3 tmp4 [@CInline] let fmul output input input2 = push_frame(); let tmp = create 10ul (u128 0) in BN.fmul output input input2 tmp; pop_frame() [@CInline] let times_2 out a = (**) let h0 = ST.get() in let a0 = a.(0ul) in let a1 = a.(1ul) in let a2 = a.(2ul) in let a3 = a.(3ul) in let a4 = a.(4ul) in let o0 = u64 2 *. a0 in let o1 = u64 2 *. a1 in let o2 = u64 2 *. a2 in let o3 = u64 2 *. a3 in let o4 = u64 2 *. a4 in make_u64_5 out o0 o1 o2 o3 o4; (**) let h1 = ST.get() in (**) assert (S51.felem_fits1 a0 1); (**) assert (F51.felem_fits h1 out (2, 4, 2, 2, 2)); calc (==) { (2 * (F51.fevalh h0 a)) % SC.prime; (==) { calc (==) { F51.fevalh h0 a; (==) { } S51.as_nat5 (a0, a1, a2, a3, a4) % SC.prime; } } (2 * (S51.as_nat5 (a0, a1, a2, a3, a4) % SC.prime)) % SC.prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r 2 (S51.as_nat5 (a0, a1, a2, a3, a4)) SC.prime } (2 * S51.as_nat5 (a0, a1, a2, a3, a4)) % SC.prime; (==) { calc (==) { 2 * S51.as_nat5 (a0, a1, a2, a3, a4); (==) { SL51.lemma_smul_felem5 (u64 2) (a0, a1, a2, a3, a4) } 2 * v a0 + 2 * v a1 * S51.pow51 + 2 * v a2 * S51.pow51 * S51.pow51 + 2 * v a3 * S51.pow51 * S51.pow51 * S51.pow51 + 2 * v a4 * S51.pow51 * S51.pow51 * S51.pow51 * S51.pow51; (==) { assert_norm (2 * S51.pow51 < pow2 64); assert_norm (4 * S51.pow51 < pow2 64); FStar.Math.Lemmas.small_mod (2 * v a0) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a1) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a2) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a3) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a4) (pow2 64) } S51.as_nat5 (u64 2 *. a0, u64 2 *. a1, u64 2 *. a2, u64 2 *. a3, u64 2 *. a4); } } S51.as_nat5 (u64 2 *. a0, u64 2 *. a1, u64 2 *. a2, u64 2 *. a3, u64 2 *. a4) % SC.prime; (==) { } F51.fevalh h1 out; } [@CInline] let times_d out a = push_frame(); let d = create 5ul (u64 0) in d.(0ul) <- u64 0x00034dca135978a3; d.(1ul) <- u64 0x0001a8283b156ebd; d.(2ul) <- u64 0x0005e7a26001c029; d.(3ul) <- u64 0x000739c663a03cbb; d.(4ul) <- u64 0x00052036cee2b6ff; assert_norm (S51.as_nat5 (u64 0x00034dca135978a3, u64 0x0001a8283b156ebd, u64 0x0005e7a26001c029, u64 0x000739c663a03cbb, u64 0x00052036cee2b6ff) % Spec.Curve25519.prime == Spec.Ed25519.d); fmul out d a; pop_frame() [@CInline] let times_2d out a = push_frame(); let d2 = create 5ul (u64 0) in d2.(0ul) <- u64 0x00069b9426b2f159; d2.(1ul) <- u64 0x00035050762add7a; d2.(2ul) <- u64 0x0003cf44c0038052; d2.(3ul) <- u64 0x0006738cc7407977; d2.(4ul) <- u64 0x0002406d9dc56dff; fmul out d2 a; assert_norm (S51.as_nat5 (u64 0x00069b9426b2f159, u64 0x00035050762add7a, u64 0x0003cf44c0038052, u64 0x0006738cc7407977, u64 0x0002406d9dc56dff) % Spec.Curve25519.prime == 2 `SC.fmul` Spec.Ed25519.d); pop_frame() [@CInline] let fsquare out a = push_frame(); let tmp = create 5ul (u128 0) in BN.fsqr out a tmp; pop_frame() [@CInline] let fsquare_times output input count = push_frame(); let tmp = create 5ul (u128 0) in Hacl.Curve25519_51.fsquare_times output input tmp count; pop_frame() [@CInline] let fsquare_times_inplace output count = push_frame(); let tmp = create 5ul (u128 0) in Hacl.Curve25519_51.fsquare_times output output tmp count; pop_frame() let inverse out a = push_frame(); let tmp = create 10ul (u128 0) in Hacl.Curve25519_51.finv out a tmp; pop_frame()
false
false
Hacl.Bignum25519.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val reduce: out:felem -> Stack unit (requires fun h -> live h out /\ F51.mul_inv_t h out) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.felem_fits h1 out (1, 1, 1, 1, 1) /\ F51.fevalh h0 out == F51.fevalh h1 out /\ F51.fevalh h1 out == F51.as_nat h1 out )
[]
Hacl.Bignum25519.reduce
{ "file_name": "code/ed25519/Hacl.Bignum25519.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
out: Hacl.Bignum25519.felem -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 31, "end_line": 248, "start_col": 16, "start_line": 243 }
FStar.HyperStack.ST.Stack
val make_one: b:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ F51.mul_inv_t h1 b /\ F51.fevalh h1 b == SC.one )
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": "SL51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let make_one b = b.(0ul) <- u64 1; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 1, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 1)
val make_one: b:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ F51.mul_inv_t h1 b /\ F51.fevalh h1 b == SC.one ) let make_one b =
true
null
false
b.(0ul) <- u64 1; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 1, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 1)
{ "checked_file": "Hacl.Bignum25519.fst.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Spec.Curve25519.Field51.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "Hacl.Curve25519_51.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum25519.fst" }
[]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Hacl.Spec.Curve25519.Field51.Definition.as_nat5", "FStar.Pervasives.Native.Mktuple5", "Lib.IntTypes.u64", "Spec.Curve25519.prime", "Prims.unit", "Lib.Buffer.op_Array_Assignment" ]
[]
module Hacl.Bignum25519 module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S51 = Hacl.Spec.Curve25519.Field51.Definition module SL51 = Hacl.Spec.Curve25519.Field51.Lemmas module BN = Hacl.Impl.Curve25519.Field51 module SC = Spec.Curve25519 friend Hacl.Curve25519_51 #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask_51 = u64 0x7ffffffffffff let make_u64_5 b s0 s1 s2 s3 s4 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4 let make_u64_10 b s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4; b.(5ul) <- s5; b.(6ul) <- s6; b.(7ul) <- s7; b.(8ul) <- s8; b.(9ul) <- s9 let make_zero b = b.(0ul) <- u64 0; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 0, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 0)
false
false
Hacl.Bignum25519.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val make_one: b:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ F51.mul_inv_t h1 b /\ F51.fevalh h1 b == SC.one )
[]
Hacl.Bignum25519.make_one
{ "file_name": "code/ed25519/Hacl.Bignum25519.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Lib.Buffer.lbuffer Lib.IntTypes.uint64 5ul -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 92, "end_line": 59, "start_col": 2, "start_line": 54 }
FStar.HyperStack.ST.Stack
val fsquare: out:felem -> a:felem -> Stack unit (requires fun h -> live h out /\ live h a /\ eq_or_disjoint a out /\ F51.felem_fits h a (9, 10, 9, 9, 9) ) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.mul_inv_t h1 out /\ F51.fevalh h1 out == F51.fevalh h0 a `SC.fmul` F51.fevalh h0 a )
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": "SL51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let fsquare out a = push_frame(); let tmp = create 5ul (u128 0) in BN.fsqr out a tmp; pop_frame()
val fsquare: out:felem -> a:felem -> Stack unit (requires fun h -> live h out /\ live h a /\ eq_or_disjoint a out /\ F51.felem_fits h a (9, 10, 9, 9, 9) ) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.mul_inv_t h1 out /\ F51.fevalh h1 out == F51.fevalh h0 a `SC.fmul` F51.fevalh h0 a ) let fsquare out a =
true
null
false
push_frame (); let tmp = create 5ul (u128 0) in BN.fsqr out a tmp; pop_frame ()
{ "checked_file": "Hacl.Bignum25519.fst.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Spec.Curve25519.Field51.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "Hacl.Curve25519_51.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum25519.fst" }
[]
[ "Hacl.Bignum25519.felem", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Impl.Curve25519.Field51.fsqr", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U128", "Lib.IntTypes.SEC", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "Hacl.Impl.Curve25519.Fields.Core.wide", "Hacl.Impl.Curve25519.Fields.Core.M51", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.u128", "Lib.Buffer.lbuffer", "FStar.HyperStack.ST.push_frame" ]
[]
module Hacl.Bignum25519 module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S51 = Hacl.Spec.Curve25519.Field51.Definition module SL51 = Hacl.Spec.Curve25519.Field51.Lemmas module BN = Hacl.Impl.Curve25519.Field51 module SC = Spec.Curve25519 friend Hacl.Curve25519_51 #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask_51 = u64 0x7ffffffffffff let make_u64_5 b s0 s1 s2 s3 s4 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4 let make_u64_10 b s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4; b.(5ul) <- s5; b.(6ul) <- s6; b.(7ul) <- s7; b.(8ul) <- s8; b.(9ul) <- s9 let make_zero b = b.(0ul) <- u64 0; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 0, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 0) let make_one b = b.(0ul) <- u64 1; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 1, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 1) [@CInline] let fsum out a b = BN.fadd out a b [@CInline] let fdifference out a b = BN.fsub out a b inline_for_extraction noextract val carry51: #m:S51.scale64{m < 8192} -> l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires S51.felem_fits1 l m /\ S51.felem_fits1 cin 1) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ S51.felem_fits1 l0 1 /\ uint_v l1 < m + 1) let carry51 l cin = let l' = l +! cin in mod_mask_lemma l' 51ul; assert (v (mod_mask #U64 #SEC 51ul) == v mask_51); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v l') 51 64; FStar.Math.Lemmas.euclidean_division_definition (v l') (pow2 51); FStar.Math.Lemmas.pow2_minus 64 51; (l' &. mask_51, l' >>. 51ul) let reduce_513 a = let (f0, f1, f2, f3, f4) = (a.(0ul), a.(1ul), a.(2ul), a.(3ul), a.(4ul)) in let tmp0, c0 = carry51 #9 f0 (u64 0) in let tmp1, c1 = carry51 #10 f1 c0 in let tmp2, c2 = carry51 #9 f2 c1 in let tmp3, c3 = carry51 #9 f3 c2 in let tmp4, c4 = carry51 #9 f4 c3 in assert (S51.felem_fits5 (tmp0, tmp1, tmp2, tmp3, tmp4) (1, 1, 1, 1, 1)); SL51.lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; assert ( S51.as_nat5 (f0, f1, f2, f3, f4) % SC.prime == (S51.as_nat5 (tmp0, tmp1, tmp2, tmp3, tmp4) + v c4 * 19) % SC.prime); [@inline_let] let tmp0', c5 = carry51 #1 tmp0 (c4 *! u64 19) in [@inline_let] let tmp1' = tmp1 +! c5 in Hacl.Spec.Curve25519.Field51.lemma_mul_inv (tmp0', tmp1, tmp2, tmp3, tmp4) c5; make_u64_5 a tmp0' tmp1' tmp2 tmp3 tmp4 [@CInline] let fmul output input input2 = push_frame(); let tmp = create 10ul (u128 0) in BN.fmul output input input2 tmp; pop_frame() [@CInline] let times_2 out a = (**) let h0 = ST.get() in let a0 = a.(0ul) in let a1 = a.(1ul) in let a2 = a.(2ul) in let a3 = a.(3ul) in let a4 = a.(4ul) in let o0 = u64 2 *. a0 in let o1 = u64 2 *. a1 in let o2 = u64 2 *. a2 in let o3 = u64 2 *. a3 in let o4 = u64 2 *. a4 in make_u64_5 out o0 o1 o2 o3 o4; (**) let h1 = ST.get() in (**) assert (S51.felem_fits1 a0 1); (**) assert (F51.felem_fits h1 out (2, 4, 2, 2, 2)); calc (==) { (2 * (F51.fevalh h0 a)) % SC.prime; (==) { calc (==) { F51.fevalh h0 a; (==) { } S51.as_nat5 (a0, a1, a2, a3, a4) % SC.prime; } } (2 * (S51.as_nat5 (a0, a1, a2, a3, a4) % SC.prime)) % SC.prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r 2 (S51.as_nat5 (a0, a1, a2, a3, a4)) SC.prime } (2 * S51.as_nat5 (a0, a1, a2, a3, a4)) % SC.prime; (==) { calc (==) { 2 * S51.as_nat5 (a0, a1, a2, a3, a4); (==) { SL51.lemma_smul_felem5 (u64 2) (a0, a1, a2, a3, a4) } 2 * v a0 + 2 * v a1 * S51.pow51 + 2 * v a2 * S51.pow51 * S51.pow51 + 2 * v a3 * S51.pow51 * S51.pow51 * S51.pow51 + 2 * v a4 * S51.pow51 * S51.pow51 * S51.pow51 * S51.pow51; (==) { assert_norm (2 * S51.pow51 < pow2 64); assert_norm (4 * S51.pow51 < pow2 64); FStar.Math.Lemmas.small_mod (2 * v a0) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a1) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a2) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a3) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a4) (pow2 64) } S51.as_nat5 (u64 2 *. a0, u64 2 *. a1, u64 2 *. a2, u64 2 *. a3, u64 2 *. a4); } } S51.as_nat5 (u64 2 *. a0, u64 2 *. a1, u64 2 *. a2, u64 2 *. a3, u64 2 *. a4) % SC.prime; (==) { } F51.fevalh h1 out; } [@CInline] let times_d out a = push_frame(); let d = create 5ul (u64 0) in d.(0ul) <- u64 0x00034dca135978a3; d.(1ul) <- u64 0x0001a8283b156ebd; d.(2ul) <- u64 0x0005e7a26001c029; d.(3ul) <- u64 0x000739c663a03cbb; d.(4ul) <- u64 0x00052036cee2b6ff; assert_norm (S51.as_nat5 (u64 0x00034dca135978a3, u64 0x0001a8283b156ebd, u64 0x0005e7a26001c029, u64 0x000739c663a03cbb, u64 0x00052036cee2b6ff) % Spec.Curve25519.prime == Spec.Ed25519.d); fmul out d a; pop_frame() [@CInline] let times_2d out a = push_frame(); let d2 = create 5ul (u64 0) in d2.(0ul) <- u64 0x00069b9426b2f159; d2.(1ul) <- u64 0x00035050762add7a; d2.(2ul) <- u64 0x0003cf44c0038052; d2.(3ul) <- u64 0x0006738cc7407977; d2.(4ul) <- u64 0x0002406d9dc56dff; fmul out d2 a; assert_norm (S51.as_nat5 (u64 0x00069b9426b2f159, u64 0x00035050762add7a, u64 0x0003cf44c0038052, u64 0x0006738cc7407977, u64 0x0002406d9dc56dff) % Spec.Curve25519.prime == 2 `SC.fmul` Spec.Ed25519.d); pop_frame() [@CInline]
false
false
Hacl.Bignum25519.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val fsquare: out:felem -> a:felem -> Stack unit (requires fun h -> live h out /\ live h a /\ eq_or_disjoint a out /\ F51.felem_fits h a (9, 10, 9, 9, 9) ) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.mul_inv_t h1 out /\ F51.fevalh h1 out == F51.fevalh h0 a `SC.fmul` F51.fevalh h0 a )
[]
Hacl.Bignum25519.fsquare
{ "file_name": "code/ed25519/Hacl.Bignum25519.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
out: Hacl.Bignum25519.felem -> a: Hacl.Bignum25519.felem -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 13, "end_line": 216, "start_col": 2, "start_line": 213 }
FStar.HyperStack.ST.Stack
val make_zero: b:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ F51.mul_inv_t h1 b /\ F51.fevalh h1 b == SC.zero )
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": "SL51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let make_zero b = b.(0ul) <- u64 0; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 0, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 0)
val make_zero: b:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ F51.mul_inv_t h1 b /\ F51.fevalh h1 b == SC.zero ) let make_zero b =
true
null
false
b.(0ul) <- u64 0; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 0, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 0)
{ "checked_file": "Hacl.Bignum25519.fst.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Spec.Curve25519.Field51.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "Hacl.Curve25519_51.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum25519.fst" }
[]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Hacl.Spec.Curve25519.Field51.Definition.as_nat5", "FStar.Pervasives.Native.Mktuple5", "Lib.IntTypes.u64", "Spec.Curve25519.prime", "Prims.unit", "Lib.Buffer.op_Array_Assignment" ]
[]
module Hacl.Bignum25519 module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S51 = Hacl.Spec.Curve25519.Field51.Definition module SL51 = Hacl.Spec.Curve25519.Field51.Lemmas module BN = Hacl.Impl.Curve25519.Field51 module SC = Spec.Curve25519 friend Hacl.Curve25519_51 #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask_51 = u64 0x7ffffffffffff let make_u64_5 b s0 s1 s2 s3 s4 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4 let make_u64_10 b s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4; b.(5ul) <- s5; b.(6ul) <- s6; b.(7ul) <- s7; b.(8ul) <- s8; b.(9ul) <- s9
false
false
Hacl.Bignum25519.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val make_zero: b:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ F51.mul_inv_t h1 b /\ F51.fevalh h1 b == SC.zero )
[]
Hacl.Bignum25519.make_zero
{ "file_name": "code/ed25519/Hacl.Bignum25519.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Lib.Buffer.lbuffer Lib.IntTypes.uint64 5ul -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 92, "end_line": 51, "start_col": 2, "start_line": 46 }
FStar.HyperStack.ST.Stack
val fsquare_times_inplace: out:felem -> n:size_t{v n > 0} -> Stack unit (requires fun h -> live h out /\ F51.felem_fits h out (1, 2, 1, 1, 1)) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.felem_fits h1 out (1, 2, 1, 1, 1) /\ F51.fevalh h1 out == Hacl.Spec.Curve25519.Finv.pow (F51.fevalh h0 out) (pow2 (v n)) )
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": "SL51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let fsquare_times_inplace output count = push_frame(); let tmp = create 5ul (u128 0) in Hacl.Curve25519_51.fsquare_times output output tmp count; pop_frame()
val fsquare_times_inplace: out:felem -> n:size_t{v n > 0} -> Stack unit (requires fun h -> live h out /\ F51.felem_fits h out (1, 2, 1, 1, 1)) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.felem_fits h1 out (1, 2, 1, 1, 1) /\ F51.fevalh h1 out == Hacl.Spec.Curve25519.Finv.pow (F51.fevalh h0 out) (pow2 (v n)) ) let fsquare_times_inplace output count =
true
null
false
push_frame (); let tmp = create 5ul (u128 0) in Hacl.Curve25519_51.fsquare_times output output tmp count; pop_frame ()
{ "checked_file": "Hacl.Bignum25519.fst.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Spec.Curve25519.Field51.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "Hacl.Curve25519_51.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum25519.fst" }
[]
[ "Hacl.Bignum25519.felem", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Curve25519_51.fsquare_times", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U128", "Lib.IntTypes.SEC", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "Hacl.Impl.Curve25519.Fields.Core.wide", "Hacl.Impl.Curve25519.Fields.Core.M51", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.u128", "Lib.Buffer.lbuffer", "FStar.HyperStack.ST.push_frame" ]
[]
module Hacl.Bignum25519 module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S51 = Hacl.Spec.Curve25519.Field51.Definition module SL51 = Hacl.Spec.Curve25519.Field51.Lemmas module BN = Hacl.Impl.Curve25519.Field51 module SC = Spec.Curve25519 friend Hacl.Curve25519_51 #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask_51 = u64 0x7ffffffffffff let make_u64_5 b s0 s1 s2 s3 s4 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4 let make_u64_10 b s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4; b.(5ul) <- s5; b.(6ul) <- s6; b.(7ul) <- s7; b.(8ul) <- s8; b.(9ul) <- s9 let make_zero b = b.(0ul) <- u64 0; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 0, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 0) let make_one b = b.(0ul) <- u64 1; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 1, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 1) [@CInline] let fsum out a b = BN.fadd out a b [@CInline] let fdifference out a b = BN.fsub out a b inline_for_extraction noextract val carry51: #m:S51.scale64{m < 8192} -> l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires S51.felem_fits1 l m /\ S51.felem_fits1 cin 1) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ S51.felem_fits1 l0 1 /\ uint_v l1 < m + 1) let carry51 l cin = let l' = l +! cin in mod_mask_lemma l' 51ul; assert (v (mod_mask #U64 #SEC 51ul) == v mask_51); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v l') 51 64; FStar.Math.Lemmas.euclidean_division_definition (v l') (pow2 51); FStar.Math.Lemmas.pow2_minus 64 51; (l' &. mask_51, l' >>. 51ul) let reduce_513 a = let (f0, f1, f2, f3, f4) = (a.(0ul), a.(1ul), a.(2ul), a.(3ul), a.(4ul)) in let tmp0, c0 = carry51 #9 f0 (u64 0) in let tmp1, c1 = carry51 #10 f1 c0 in let tmp2, c2 = carry51 #9 f2 c1 in let tmp3, c3 = carry51 #9 f3 c2 in let tmp4, c4 = carry51 #9 f4 c3 in assert (S51.felem_fits5 (tmp0, tmp1, tmp2, tmp3, tmp4) (1, 1, 1, 1, 1)); SL51.lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; assert ( S51.as_nat5 (f0, f1, f2, f3, f4) % SC.prime == (S51.as_nat5 (tmp0, tmp1, tmp2, tmp3, tmp4) + v c4 * 19) % SC.prime); [@inline_let] let tmp0', c5 = carry51 #1 tmp0 (c4 *! u64 19) in [@inline_let] let tmp1' = tmp1 +! c5 in Hacl.Spec.Curve25519.Field51.lemma_mul_inv (tmp0', tmp1, tmp2, tmp3, tmp4) c5; make_u64_5 a tmp0' tmp1' tmp2 tmp3 tmp4 [@CInline] let fmul output input input2 = push_frame(); let tmp = create 10ul (u128 0) in BN.fmul output input input2 tmp; pop_frame() [@CInline] let times_2 out a = (**) let h0 = ST.get() in let a0 = a.(0ul) in let a1 = a.(1ul) in let a2 = a.(2ul) in let a3 = a.(3ul) in let a4 = a.(4ul) in let o0 = u64 2 *. a0 in let o1 = u64 2 *. a1 in let o2 = u64 2 *. a2 in let o3 = u64 2 *. a3 in let o4 = u64 2 *. a4 in make_u64_5 out o0 o1 o2 o3 o4; (**) let h1 = ST.get() in (**) assert (S51.felem_fits1 a0 1); (**) assert (F51.felem_fits h1 out (2, 4, 2, 2, 2)); calc (==) { (2 * (F51.fevalh h0 a)) % SC.prime; (==) { calc (==) { F51.fevalh h0 a; (==) { } S51.as_nat5 (a0, a1, a2, a3, a4) % SC.prime; } } (2 * (S51.as_nat5 (a0, a1, a2, a3, a4) % SC.prime)) % SC.prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r 2 (S51.as_nat5 (a0, a1, a2, a3, a4)) SC.prime } (2 * S51.as_nat5 (a0, a1, a2, a3, a4)) % SC.prime; (==) { calc (==) { 2 * S51.as_nat5 (a0, a1, a2, a3, a4); (==) { SL51.lemma_smul_felem5 (u64 2) (a0, a1, a2, a3, a4) } 2 * v a0 + 2 * v a1 * S51.pow51 + 2 * v a2 * S51.pow51 * S51.pow51 + 2 * v a3 * S51.pow51 * S51.pow51 * S51.pow51 + 2 * v a4 * S51.pow51 * S51.pow51 * S51.pow51 * S51.pow51; (==) { assert_norm (2 * S51.pow51 < pow2 64); assert_norm (4 * S51.pow51 < pow2 64); FStar.Math.Lemmas.small_mod (2 * v a0) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a1) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a2) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a3) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a4) (pow2 64) } S51.as_nat5 (u64 2 *. a0, u64 2 *. a1, u64 2 *. a2, u64 2 *. a3, u64 2 *. a4); } } S51.as_nat5 (u64 2 *. a0, u64 2 *. a1, u64 2 *. a2, u64 2 *. a3, u64 2 *. a4) % SC.prime; (==) { } F51.fevalh h1 out; } [@CInline] let times_d out a = push_frame(); let d = create 5ul (u64 0) in d.(0ul) <- u64 0x00034dca135978a3; d.(1ul) <- u64 0x0001a8283b156ebd; d.(2ul) <- u64 0x0005e7a26001c029; d.(3ul) <- u64 0x000739c663a03cbb; d.(4ul) <- u64 0x00052036cee2b6ff; assert_norm (S51.as_nat5 (u64 0x00034dca135978a3, u64 0x0001a8283b156ebd, u64 0x0005e7a26001c029, u64 0x000739c663a03cbb, u64 0x00052036cee2b6ff) % Spec.Curve25519.prime == Spec.Ed25519.d); fmul out d a; pop_frame() [@CInline] let times_2d out a = push_frame(); let d2 = create 5ul (u64 0) in d2.(0ul) <- u64 0x00069b9426b2f159; d2.(1ul) <- u64 0x00035050762add7a; d2.(2ul) <- u64 0x0003cf44c0038052; d2.(3ul) <- u64 0x0006738cc7407977; d2.(4ul) <- u64 0x0002406d9dc56dff; fmul out d2 a; assert_norm (S51.as_nat5 (u64 0x00069b9426b2f159, u64 0x00035050762add7a, u64 0x0003cf44c0038052, u64 0x0006738cc7407977, u64 0x0002406d9dc56dff) % Spec.Curve25519.prime == 2 `SC.fmul` Spec.Ed25519.d); pop_frame() [@CInline] let fsquare out a = push_frame(); let tmp = create 5ul (u128 0) in BN.fsqr out a tmp; pop_frame() [@CInline] let fsquare_times output input count = push_frame(); let tmp = create 5ul (u128 0) in Hacl.Curve25519_51.fsquare_times output input tmp count; pop_frame() [@CInline]
false
false
Hacl.Bignum25519.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val fsquare_times_inplace: out:felem -> n:size_t{v n > 0} -> Stack unit (requires fun h -> live h out /\ F51.felem_fits h out (1, 2, 1, 1, 1)) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.felem_fits h1 out (1, 2, 1, 1, 1) /\ F51.fevalh h1 out == Hacl.Spec.Curve25519.Finv.pow (F51.fevalh h0 out) (pow2 (v n)) )
[]
Hacl.Bignum25519.fsquare_times_inplace
{ "file_name": "code/ed25519/Hacl.Bignum25519.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
out: Hacl.Bignum25519.felem -> n: Lib.IntTypes.size_t{Lib.IntTypes.v n > 0} -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 13, "end_line": 232, "start_col": 2, "start_line": 229 }
FStar.HyperStack.ST.Stack
val fmul: out:felem -> a:felem -> b:felem -> Stack unit (requires fun h -> live h out /\ live h a /\ live h b /\ F51.felem_fits h a (9, 10, 9, 9, 9) /\ F51.felem_fits h b (9, 10, 9, 9, 9) ) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.mul_inv_t h1 out /\ F51.fevalh h1 out == SC.fmul (F51.fevalh h0 a) (F51.fevalh h0 b) )
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": "SL51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let fmul output input input2 = push_frame(); let tmp = create 10ul (u128 0) in BN.fmul output input input2 tmp; pop_frame()
val fmul: out:felem -> a:felem -> b:felem -> Stack unit (requires fun h -> live h out /\ live h a /\ live h b /\ F51.felem_fits h a (9, 10, 9, 9, 9) /\ F51.felem_fits h b (9, 10, 9, 9, 9) ) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.mul_inv_t h1 out /\ F51.fevalh h1 out == SC.fmul (F51.fevalh h0 a) (F51.fevalh h0 b) ) let fmul output input input2 =
true
null
false
push_frame (); let tmp = create 10ul (u128 0) in BN.fmul output input input2 tmp; pop_frame ()
{ "checked_file": "Hacl.Bignum25519.fst.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Spec.Curve25519.Field51.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "Hacl.Curve25519_51.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum25519.fst" }
[]
[ "Hacl.Bignum25519.felem", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Impl.Curve25519.Field51.fmul", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U128", "Lib.IntTypes.SEC", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "Hacl.Impl.Curve25519.Fields.Core.wide", "Hacl.Impl.Curve25519.Fields.Core.M51", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.u128", "Lib.Buffer.lbuffer", "FStar.HyperStack.ST.push_frame" ]
[]
module Hacl.Bignum25519 module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S51 = Hacl.Spec.Curve25519.Field51.Definition module SL51 = Hacl.Spec.Curve25519.Field51.Lemmas module BN = Hacl.Impl.Curve25519.Field51 module SC = Spec.Curve25519 friend Hacl.Curve25519_51 #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask_51 = u64 0x7ffffffffffff let make_u64_5 b s0 s1 s2 s3 s4 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4 let make_u64_10 b s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4; b.(5ul) <- s5; b.(6ul) <- s6; b.(7ul) <- s7; b.(8ul) <- s8; b.(9ul) <- s9 let make_zero b = b.(0ul) <- u64 0; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 0, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 0) let make_one b = b.(0ul) <- u64 1; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 1, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 1) [@CInline] let fsum out a b = BN.fadd out a b [@CInline] let fdifference out a b = BN.fsub out a b inline_for_extraction noextract val carry51: #m:S51.scale64{m < 8192} -> l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires S51.felem_fits1 l m /\ S51.felem_fits1 cin 1) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ S51.felem_fits1 l0 1 /\ uint_v l1 < m + 1) let carry51 l cin = let l' = l +! cin in mod_mask_lemma l' 51ul; assert (v (mod_mask #U64 #SEC 51ul) == v mask_51); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v l') 51 64; FStar.Math.Lemmas.euclidean_division_definition (v l') (pow2 51); FStar.Math.Lemmas.pow2_minus 64 51; (l' &. mask_51, l' >>. 51ul) let reduce_513 a = let (f0, f1, f2, f3, f4) = (a.(0ul), a.(1ul), a.(2ul), a.(3ul), a.(4ul)) in let tmp0, c0 = carry51 #9 f0 (u64 0) in let tmp1, c1 = carry51 #10 f1 c0 in let tmp2, c2 = carry51 #9 f2 c1 in let tmp3, c3 = carry51 #9 f3 c2 in let tmp4, c4 = carry51 #9 f4 c3 in assert (S51.felem_fits5 (tmp0, tmp1, tmp2, tmp3, tmp4) (1, 1, 1, 1, 1)); SL51.lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; assert ( S51.as_nat5 (f0, f1, f2, f3, f4) % SC.prime == (S51.as_nat5 (tmp0, tmp1, tmp2, tmp3, tmp4) + v c4 * 19) % SC.prime); [@inline_let] let tmp0', c5 = carry51 #1 tmp0 (c4 *! u64 19) in [@inline_let] let tmp1' = tmp1 +! c5 in Hacl.Spec.Curve25519.Field51.lemma_mul_inv (tmp0', tmp1, tmp2, tmp3, tmp4) c5; make_u64_5 a tmp0' tmp1' tmp2 tmp3 tmp4 [@CInline]
false
false
Hacl.Bignum25519.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val fmul: out:felem -> a:felem -> b:felem -> Stack unit (requires fun h -> live h out /\ live h a /\ live h b /\ F51.felem_fits h a (9, 10, 9, 9, 9) /\ F51.felem_fits h b (9, 10, 9, 9, 9) ) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.mul_inv_t h1 out /\ F51.fevalh h1 out == SC.fmul (F51.fevalh h0 a) (F51.fevalh h0 b) )
[]
Hacl.Bignum25519.fmul
{ "file_name": "code/ed25519/Hacl.Bignum25519.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
out: Hacl.Bignum25519.felem -> a: Hacl.Bignum25519.felem -> b: Hacl.Bignum25519.felem -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 13, "end_line": 122, "start_col": 2, "start_line": 119 }
FStar.HyperStack.ST.Stack
val fsquare_times: out:felem -> a:felem -> n:size_t{v n > 0} -> Stack unit (requires fun h -> live h out /\ live h a /\ disjoint out a /\ F51.felem_fits h a (1, 2, 1, 1, 1) ) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.felem_fits h1 out (1, 2, 1, 1, 1) /\ F51.fevalh h1 out == Hacl.Spec.Curve25519.Finv.pow (F51.fevalh h0 a) (pow2 (v n)) )
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": "SL51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let fsquare_times output input count = push_frame(); let tmp = create 5ul (u128 0) in Hacl.Curve25519_51.fsquare_times output input tmp count; pop_frame()
val fsquare_times: out:felem -> a:felem -> n:size_t{v n > 0} -> Stack unit (requires fun h -> live h out /\ live h a /\ disjoint out a /\ F51.felem_fits h a (1, 2, 1, 1, 1) ) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.felem_fits h1 out (1, 2, 1, 1, 1) /\ F51.fevalh h1 out == Hacl.Spec.Curve25519.Finv.pow (F51.fevalh h0 a) (pow2 (v n)) ) let fsquare_times output input count =
true
null
false
push_frame (); let tmp = create 5ul (u128 0) in Hacl.Curve25519_51.fsquare_times output input tmp count; pop_frame ()
{ "checked_file": "Hacl.Bignum25519.fst.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Spec.Curve25519.Field51.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "Hacl.Curve25519_51.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum25519.fst" }
[]
[ "Hacl.Bignum25519.felem", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Curve25519_51.fsquare_times", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U128", "Lib.IntTypes.SEC", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "Hacl.Impl.Curve25519.Fields.Core.wide", "Hacl.Impl.Curve25519.Fields.Core.M51", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.u128", "Lib.Buffer.lbuffer", "FStar.HyperStack.ST.push_frame" ]
[]
module Hacl.Bignum25519 module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S51 = Hacl.Spec.Curve25519.Field51.Definition module SL51 = Hacl.Spec.Curve25519.Field51.Lemmas module BN = Hacl.Impl.Curve25519.Field51 module SC = Spec.Curve25519 friend Hacl.Curve25519_51 #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask_51 = u64 0x7ffffffffffff let make_u64_5 b s0 s1 s2 s3 s4 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4 let make_u64_10 b s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4; b.(5ul) <- s5; b.(6ul) <- s6; b.(7ul) <- s7; b.(8ul) <- s8; b.(9ul) <- s9 let make_zero b = b.(0ul) <- u64 0; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 0, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 0) let make_one b = b.(0ul) <- u64 1; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 1, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 1) [@CInline] let fsum out a b = BN.fadd out a b [@CInline] let fdifference out a b = BN.fsub out a b inline_for_extraction noextract val carry51: #m:S51.scale64{m < 8192} -> l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires S51.felem_fits1 l m /\ S51.felem_fits1 cin 1) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ S51.felem_fits1 l0 1 /\ uint_v l1 < m + 1) let carry51 l cin = let l' = l +! cin in mod_mask_lemma l' 51ul; assert (v (mod_mask #U64 #SEC 51ul) == v mask_51); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v l') 51 64; FStar.Math.Lemmas.euclidean_division_definition (v l') (pow2 51); FStar.Math.Lemmas.pow2_minus 64 51; (l' &. mask_51, l' >>. 51ul) let reduce_513 a = let (f0, f1, f2, f3, f4) = (a.(0ul), a.(1ul), a.(2ul), a.(3ul), a.(4ul)) in let tmp0, c0 = carry51 #9 f0 (u64 0) in let tmp1, c1 = carry51 #10 f1 c0 in let tmp2, c2 = carry51 #9 f2 c1 in let tmp3, c3 = carry51 #9 f3 c2 in let tmp4, c4 = carry51 #9 f4 c3 in assert (S51.felem_fits5 (tmp0, tmp1, tmp2, tmp3, tmp4) (1, 1, 1, 1, 1)); SL51.lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; assert ( S51.as_nat5 (f0, f1, f2, f3, f4) % SC.prime == (S51.as_nat5 (tmp0, tmp1, tmp2, tmp3, tmp4) + v c4 * 19) % SC.prime); [@inline_let] let tmp0', c5 = carry51 #1 tmp0 (c4 *! u64 19) in [@inline_let] let tmp1' = tmp1 +! c5 in Hacl.Spec.Curve25519.Field51.lemma_mul_inv (tmp0', tmp1, tmp2, tmp3, tmp4) c5; make_u64_5 a tmp0' tmp1' tmp2 tmp3 tmp4 [@CInline] let fmul output input input2 = push_frame(); let tmp = create 10ul (u128 0) in BN.fmul output input input2 tmp; pop_frame() [@CInline] let times_2 out a = (**) let h0 = ST.get() in let a0 = a.(0ul) in let a1 = a.(1ul) in let a2 = a.(2ul) in let a3 = a.(3ul) in let a4 = a.(4ul) in let o0 = u64 2 *. a0 in let o1 = u64 2 *. a1 in let o2 = u64 2 *. a2 in let o3 = u64 2 *. a3 in let o4 = u64 2 *. a4 in make_u64_5 out o0 o1 o2 o3 o4; (**) let h1 = ST.get() in (**) assert (S51.felem_fits1 a0 1); (**) assert (F51.felem_fits h1 out (2, 4, 2, 2, 2)); calc (==) { (2 * (F51.fevalh h0 a)) % SC.prime; (==) { calc (==) { F51.fevalh h0 a; (==) { } S51.as_nat5 (a0, a1, a2, a3, a4) % SC.prime; } } (2 * (S51.as_nat5 (a0, a1, a2, a3, a4) % SC.prime)) % SC.prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r 2 (S51.as_nat5 (a0, a1, a2, a3, a4)) SC.prime } (2 * S51.as_nat5 (a0, a1, a2, a3, a4)) % SC.prime; (==) { calc (==) { 2 * S51.as_nat5 (a0, a1, a2, a3, a4); (==) { SL51.lemma_smul_felem5 (u64 2) (a0, a1, a2, a3, a4) } 2 * v a0 + 2 * v a1 * S51.pow51 + 2 * v a2 * S51.pow51 * S51.pow51 + 2 * v a3 * S51.pow51 * S51.pow51 * S51.pow51 + 2 * v a4 * S51.pow51 * S51.pow51 * S51.pow51 * S51.pow51; (==) { assert_norm (2 * S51.pow51 < pow2 64); assert_norm (4 * S51.pow51 < pow2 64); FStar.Math.Lemmas.small_mod (2 * v a0) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a1) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a2) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a3) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a4) (pow2 64) } S51.as_nat5 (u64 2 *. a0, u64 2 *. a1, u64 2 *. a2, u64 2 *. a3, u64 2 *. a4); } } S51.as_nat5 (u64 2 *. a0, u64 2 *. a1, u64 2 *. a2, u64 2 *. a3, u64 2 *. a4) % SC.prime; (==) { } F51.fevalh h1 out; } [@CInline] let times_d out a = push_frame(); let d = create 5ul (u64 0) in d.(0ul) <- u64 0x00034dca135978a3; d.(1ul) <- u64 0x0001a8283b156ebd; d.(2ul) <- u64 0x0005e7a26001c029; d.(3ul) <- u64 0x000739c663a03cbb; d.(4ul) <- u64 0x00052036cee2b6ff; assert_norm (S51.as_nat5 (u64 0x00034dca135978a3, u64 0x0001a8283b156ebd, u64 0x0005e7a26001c029, u64 0x000739c663a03cbb, u64 0x00052036cee2b6ff) % Spec.Curve25519.prime == Spec.Ed25519.d); fmul out d a; pop_frame() [@CInline] let times_2d out a = push_frame(); let d2 = create 5ul (u64 0) in d2.(0ul) <- u64 0x00069b9426b2f159; d2.(1ul) <- u64 0x00035050762add7a; d2.(2ul) <- u64 0x0003cf44c0038052; d2.(3ul) <- u64 0x0006738cc7407977; d2.(4ul) <- u64 0x0002406d9dc56dff; fmul out d2 a; assert_norm (S51.as_nat5 (u64 0x00069b9426b2f159, u64 0x00035050762add7a, u64 0x0003cf44c0038052, u64 0x0006738cc7407977, u64 0x0002406d9dc56dff) % Spec.Curve25519.prime == 2 `SC.fmul` Spec.Ed25519.d); pop_frame() [@CInline] let fsquare out a = push_frame(); let tmp = create 5ul (u128 0) in BN.fsqr out a tmp; pop_frame() [@CInline]
false
false
Hacl.Bignum25519.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val fsquare_times: out:felem -> a:felem -> n:size_t{v n > 0} -> Stack unit (requires fun h -> live h out /\ live h a /\ disjoint out a /\ F51.felem_fits h a (1, 2, 1, 1, 1) ) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.felem_fits h1 out (1, 2, 1, 1, 1) /\ F51.fevalh h1 out == Hacl.Spec.Curve25519.Finv.pow (F51.fevalh h0 a) (pow2 (v n)) )
[]
Hacl.Bignum25519.fsquare_times
{ "file_name": "code/ed25519/Hacl.Bignum25519.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
out: Hacl.Bignum25519.felem -> a: Hacl.Bignum25519.felem -> n: Lib.IntTypes.size_t{Lib.IntTypes.v n > 0} -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 13, "end_line": 224, "start_col": 2, "start_line": 221 }
FStar.HyperStack.ST.Stack
val inverse: out:felem -> a:felem -> Stack unit (requires fun h -> live h out /\ live h a /\ disjoint a out /\ F51.felem_fits h a (1, 2, 1, 1, 1) ) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.felem_fits h1 out (1, 2, 1, 1, 1) /\ F51.fevalh h1 out == SC.fpow (F51.fevalh h0 a) (SC.prime - 2) )
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": "SL51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let inverse out a = push_frame(); let tmp = create 10ul (u128 0) in Hacl.Curve25519_51.finv out a tmp; pop_frame()
val inverse: out:felem -> a:felem -> Stack unit (requires fun h -> live h out /\ live h a /\ disjoint a out /\ F51.felem_fits h a (1, 2, 1, 1, 1) ) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.felem_fits h1 out (1, 2, 1, 1, 1) /\ F51.fevalh h1 out == SC.fpow (F51.fevalh h0 a) (SC.prime - 2) ) let inverse out a =
true
null
false
push_frame (); let tmp = create 10ul (u128 0) in Hacl.Curve25519_51.finv out a tmp; pop_frame ()
{ "checked_file": "Hacl.Bignum25519.fst.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Spec.Curve25519.Field51.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "Hacl.Curve25519_51.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum25519.fst" }
[]
[ "Hacl.Bignum25519.felem", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Curve25519_51.finv", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U128", "Lib.IntTypes.SEC", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "Hacl.Impl.Curve25519.Fields.Core.wide", "Hacl.Impl.Curve25519.Fields.Core.M51", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.u128", "Lib.Buffer.lbuffer", "FStar.HyperStack.ST.push_frame" ]
[]
module Hacl.Bignum25519 module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S51 = Hacl.Spec.Curve25519.Field51.Definition module SL51 = Hacl.Spec.Curve25519.Field51.Lemmas module BN = Hacl.Impl.Curve25519.Field51 module SC = Spec.Curve25519 friend Hacl.Curve25519_51 #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask_51 = u64 0x7ffffffffffff let make_u64_5 b s0 s1 s2 s3 s4 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4 let make_u64_10 b s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4; b.(5ul) <- s5; b.(6ul) <- s6; b.(7ul) <- s7; b.(8ul) <- s8; b.(9ul) <- s9 let make_zero b = b.(0ul) <- u64 0; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 0, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 0) let make_one b = b.(0ul) <- u64 1; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 1, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 1) [@CInline] let fsum out a b = BN.fadd out a b [@CInline] let fdifference out a b = BN.fsub out a b inline_for_extraction noextract val carry51: #m:S51.scale64{m < 8192} -> l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires S51.felem_fits1 l m /\ S51.felem_fits1 cin 1) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ S51.felem_fits1 l0 1 /\ uint_v l1 < m + 1) let carry51 l cin = let l' = l +! cin in mod_mask_lemma l' 51ul; assert (v (mod_mask #U64 #SEC 51ul) == v mask_51); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v l') 51 64; FStar.Math.Lemmas.euclidean_division_definition (v l') (pow2 51); FStar.Math.Lemmas.pow2_minus 64 51; (l' &. mask_51, l' >>. 51ul) let reduce_513 a = let (f0, f1, f2, f3, f4) = (a.(0ul), a.(1ul), a.(2ul), a.(3ul), a.(4ul)) in let tmp0, c0 = carry51 #9 f0 (u64 0) in let tmp1, c1 = carry51 #10 f1 c0 in let tmp2, c2 = carry51 #9 f2 c1 in let tmp3, c3 = carry51 #9 f3 c2 in let tmp4, c4 = carry51 #9 f4 c3 in assert (S51.felem_fits5 (tmp0, tmp1, tmp2, tmp3, tmp4) (1, 1, 1, 1, 1)); SL51.lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; assert ( S51.as_nat5 (f0, f1, f2, f3, f4) % SC.prime == (S51.as_nat5 (tmp0, tmp1, tmp2, tmp3, tmp4) + v c4 * 19) % SC.prime); [@inline_let] let tmp0', c5 = carry51 #1 tmp0 (c4 *! u64 19) in [@inline_let] let tmp1' = tmp1 +! c5 in Hacl.Spec.Curve25519.Field51.lemma_mul_inv (tmp0', tmp1, tmp2, tmp3, tmp4) c5; make_u64_5 a tmp0' tmp1' tmp2 tmp3 tmp4 [@CInline] let fmul output input input2 = push_frame(); let tmp = create 10ul (u128 0) in BN.fmul output input input2 tmp; pop_frame() [@CInline] let times_2 out a = (**) let h0 = ST.get() in let a0 = a.(0ul) in let a1 = a.(1ul) in let a2 = a.(2ul) in let a3 = a.(3ul) in let a4 = a.(4ul) in let o0 = u64 2 *. a0 in let o1 = u64 2 *. a1 in let o2 = u64 2 *. a2 in let o3 = u64 2 *. a3 in let o4 = u64 2 *. a4 in make_u64_5 out o0 o1 o2 o3 o4; (**) let h1 = ST.get() in (**) assert (S51.felem_fits1 a0 1); (**) assert (F51.felem_fits h1 out (2, 4, 2, 2, 2)); calc (==) { (2 * (F51.fevalh h0 a)) % SC.prime; (==) { calc (==) { F51.fevalh h0 a; (==) { } S51.as_nat5 (a0, a1, a2, a3, a4) % SC.prime; } } (2 * (S51.as_nat5 (a0, a1, a2, a3, a4) % SC.prime)) % SC.prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r 2 (S51.as_nat5 (a0, a1, a2, a3, a4)) SC.prime } (2 * S51.as_nat5 (a0, a1, a2, a3, a4)) % SC.prime; (==) { calc (==) { 2 * S51.as_nat5 (a0, a1, a2, a3, a4); (==) { SL51.lemma_smul_felem5 (u64 2) (a0, a1, a2, a3, a4) } 2 * v a0 + 2 * v a1 * S51.pow51 + 2 * v a2 * S51.pow51 * S51.pow51 + 2 * v a3 * S51.pow51 * S51.pow51 * S51.pow51 + 2 * v a4 * S51.pow51 * S51.pow51 * S51.pow51 * S51.pow51; (==) { assert_norm (2 * S51.pow51 < pow2 64); assert_norm (4 * S51.pow51 < pow2 64); FStar.Math.Lemmas.small_mod (2 * v a0) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a1) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a2) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a3) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a4) (pow2 64) } S51.as_nat5 (u64 2 *. a0, u64 2 *. a1, u64 2 *. a2, u64 2 *. a3, u64 2 *. a4); } } S51.as_nat5 (u64 2 *. a0, u64 2 *. a1, u64 2 *. a2, u64 2 *. a3, u64 2 *. a4) % SC.prime; (==) { } F51.fevalh h1 out; } [@CInline] let times_d out a = push_frame(); let d = create 5ul (u64 0) in d.(0ul) <- u64 0x00034dca135978a3; d.(1ul) <- u64 0x0001a8283b156ebd; d.(2ul) <- u64 0x0005e7a26001c029; d.(3ul) <- u64 0x000739c663a03cbb; d.(4ul) <- u64 0x00052036cee2b6ff; assert_norm (S51.as_nat5 (u64 0x00034dca135978a3, u64 0x0001a8283b156ebd, u64 0x0005e7a26001c029, u64 0x000739c663a03cbb, u64 0x00052036cee2b6ff) % Spec.Curve25519.prime == Spec.Ed25519.d); fmul out d a; pop_frame() [@CInline] let times_2d out a = push_frame(); let d2 = create 5ul (u64 0) in d2.(0ul) <- u64 0x00069b9426b2f159; d2.(1ul) <- u64 0x00035050762add7a; d2.(2ul) <- u64 0x0003cf44c0038052; d2.(3ul) <- u64 0x0006738cc7407977; d2.(4ul) <- u64 0x0002406d9dc56dff; fmul out d2 a; assert_norm (S51.as_nat5 (u64 0x00069b9426b2f159, u64 0x00035050762add7a, u64 0x0003cf44c0038052, u64 0x0006738cc7407977, u64 0x0002406d9dc56dff) % Spec.Curve25519.prime == 2 `SC.fmul` Spec.Ed25519.d); pop_frame() [@CInline] let fsquare out a = push_frame(); let tmp = create 5ul (u128 0) in BN.fsqr out a tmp; pop_frame() [@CInline] let fsquare_times output input count = push_frame(); let tmp = create 5ul (u128 0) in Hacl.Curve25519_51.fsquare_times output input tmp count; pop_frame() [@CInline] let fsquare_times_inplace output count = push_frame(); let tmp = create 5ul (u128 0) in Hacl.Curve25519_51.fsquare_times output output tmp count; pop_frame()
false
false
Hacl.Bignum25519.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val inverse: out:felem -> a:felem -> Stack unit (requires fun h -> live h out /\ live h a /\ disjoint a out /\ F51.felem_fits h a (1, 2, 1, 1, 1) ) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.felem_fits h1 out (1, 2, 1, 1, 1) /\ F51.fevalh h1 out == SC.fpow (F51.fevalh h0 a) (SC.prime - 2) )
[]
Hacl.Bignum25519.inverse
{ "file_name": "code/ed25519/Hacl.Bignum25519.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
out: Hacl.Bignum25519.felem -> a: Hacl.Bignum25519.felem -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 13, "end_line": 239, "start_col": 2, "start_line": 236 }
FStar.HyperStack.ST.Stack
val reduce_513: a:felem -> Stack unit (requires fun h -> live h a /\ F51.felem_fits h a (9, 10, 9, 9, 9) ) (ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ F51.fevalh h1 a == F51.fevalh h0 a /\ F51.mul_inv_t h1 a )
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": "SL51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let reduce_513 a = let (f0, f1, f2, f3, f4) = (a.(0ul), a.(1ul), a.(2ul), a.(3ul), a.(4ul)) in let tmp0, c0 = carry51 #9 f0 (u64 0) in let tmp1, c1 = carry51 #10 f1 c0 in let tmp2, c2 = carry51 #9 f2 c1 in let tmp3, c3 = carry51 #9 f3 c2 in let tmp4, c4 = carry51 #9 f4 c3 in assert (S51.felem_fits5 (tmp0, tmp1, tmp2, tmp3, tmp4) (1, 1, 1, 1, 1)); SL51.lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; assert ( S51.as_nat5 (f0, f1, f2, f3, f4) % SC.prime == (S51.as_nat5 (tmp0, tmp1, tmp2, tmp3, tmp4) + v c4 * 19) % SC.prime); [@inline_let] let tmp0', c5 = carry51 #1 tmp0 (c4 *! u64 19) in [@inline_let] let tmp1' = tmp1 +! c5 in Hacl.Spec.Curve25519.Field51.lemma_mul_inv (tmp0', tmp1, tmp2, tmp3, tmp4) c5; make_u64_5 a tmp0' tmp1' tmp2 tmp3 tmp4
val reduce_513: a:felem -> Stack unit (requires fun h -> live h a /\ F51.felem_fits h a (9, 10, 9, 9, 9) ) (ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ F51.fevalh h1 a == F51.fevalh h0 a /\ F51.mul_inv_t h1 a ) let reduce_513 a =
true
null
false
let f0, f1, f2, f3, f4 = (a.(0ul), a.(1ul), a.(2ul), a.(3ul), a.(4ul)) in let tmp0, c0 = carry51 #9 f0 (u64 0) in let tmp1, c1 = carry51 #10 f1 c0 in let tmp2, c2 = carry51 #9 f2 c1 in let tmp3, c3 = carry51 #9 f3 c2 in let tmp4, c4 = carry51 #9 f4 c3 in assert (S51.felem_fits5 (tmp0, tmp1, tmp2, tmp3, tmp4) (1, 1, 1, 1, 1)); SL51.lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; assert (S51.as_nat5 (f0, f1, f2, f3, f4) % SC.prime == (S51.as_nat5 (tmp0, tmp1, tmp2, tmp3, tmp4) + v c4 * 19) % SC.prime); [@@ inline_let ]let tmp0', c5 = carry51 #1 tmp0 (c4 *! u64 19) in [@@ inline_let ]let tmp1' = tmp1 +! c5 in Hacl.Spec.Curve25519.Field51.lemma_mul_inv (tmp0', tmp1, tmp2, tmp3, tmp4) c5; make_u64_5 a tmp0' tmp1' tmp2 tmp3 tmp4
{ "checked_file": "Hacl.Bignum25519.fst.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Spec.Curve25519.Field51.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "Hacl.Curve25519_51.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum25519.fst" }
[]
[ "Hacl.Bignum25519.felem", "Lib.IntTypes.uint64", "Hacl.Bignum25519.make_u64_5", "Prims.unit", "Hacl.Spec.Curve25519.Field51.lemma_mul_inv", "FStar.Pervasives.Native.Mktuple5", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Plus_Bang", "FStar.Pervasives.Native.tuple2", "Hacl.Bignum25519.carry51", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.u64", "Prims._assert", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Hacl.Spec.Curve25519.Field51.Definition.as_nat5", "Spec.Curve25519.prime", "Prims.op_Addition", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Hacl.Spec.Curve25519.Field51.Lemmas.lemma_carry5_simplify", "Hacl.Spec.Curve25519.Field51.Definition.felem_fits5", "Prims.nat", "FStar.Pervasives.Native.tuple5", "Lib.Buffer.op_Array_Access", "Lib.Buffer.MUT", "FStar.UInt32.__uint_to_t" ]
[]
module Hacl.Bignum25519 module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S51 = Hacl.Spec.Curve25519.Field51.Definition module SL51 = Hacl.Spec.Curve25519.Field51.Lemmas module BN = Hacl.Impl.Curve25519.Field51 module SC = Spec.Curve25519 friend Hacl.Curve25519_51 #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask_51 = u64 0x7ffffffffffff let make_u64_5 b s0 s1 s2 s3 s4 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4 let make_u64_10 b s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4; b.(5ul) <- s5; b.(6ul) <- s6; b.(7ul) <- s7; b.(8ul) <- s8; b.(9ul) <- s9 let make_zero b = b.(0ul) <- u64 0; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 0, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 0) let make_one b = b.(0ul) <- u64 1; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 1, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 1) [@CInline] let fsum out a b = BN.fadd out a b [@CInline] let fdifference out a b = BN.fsub out a b inline_for_extraction noextract val carry51: #m:S51.scale64{m < 8192} -> l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires S51.felem_fits1 l m /\ S51.felem_fits1 cin 1) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ S51.felem_fits1 l0 1 /\ uint_v l1 < m + 1) let carry51 l cin = let l' = l +! cin in mod_mask_lemma l' 51ul; assert (v (mod_mask #U64 #SEC 51ul) == v mask_51); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v l') 51 64; FStar.Math.Lemmas.euclidean_division_definition (v l') (pow2 51); FStar.Math.Lemmas.pow2_minus 64 51; (l' &. mask_51, l' >>. 51ul)
false
false
Hacl.Bignum25519.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val reduce_513: a:felem -> Stack unit (requires fun h -> live h a /\ F51.felem_fits h a (9, 10, 9, 9, 9) ) (ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ F51.fevalh h1 a == F51.fevalh h0 a /\ F51.mul_inv_t h1 a )
[]
Hacl.Bignum25519.reduce_513
{ "file_name": "code/ed25519/Hacl.Bignum25519.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Bignum25519.felem -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 41, "end_line": 114, "start_col": 18, "start_line": 95 }
FStar.HyperStack.ST.Stack
val make_u64_10: b:lbuffer uint64 10ul -> s0:uint64 -> s1:uint64 -> s2:uint64 -> s3:uint64 -> s4:uint64 -> s5:uint64 -> s6:uint64 -> s7:uint64 -> s8:uint64 -> s9:uint64 -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ (let s = as_seq h1 b in Seq.index s 0 == s0 /\ Seq.index s 1 == s1 /\ Seq.index s 2 == s2 /\ Seq.index s 3 == s3 /\ Seq.index s 4 == s4 /\ Seq.index s 5 == s5 /\ Seq.index s 6 == s6 /\ Seq.index s 7 == s7 /\ Seq.index s 8 == s8 /\ Seq.index s 9 == s9) )
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": "SL51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let make_u64_10 b s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4; b.(5ul) <- s5; b.(6ul) <- s6; b.(7ul) <- s7; b.(8ul) <- s8; b.(9ul) <- s9
val make_u64_10: b:lbuffer uint64 10ul -> s0:uint64 -> s1:uint64 -> s2:uint64 -> s3:uint64 -> s4:uint64 -> s5:uint64 -> s6:uint64 -> s7:uint64 -> s8:uint64 -> s9:uint64 -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ (let s = as_seq h1 b in Seq.index s 0 == s0 /\ Seq.index s 1 == s1 /\ Seq.index s 2 == s2 /\ Seq.index s 3 == s3 /\ Seq.index s 4 == s4 /\ Seq.index s 5 == s5 /\ Seq.index s 6 == s6 /\ Seq.index s 7 == s7 /\ Seq.index s 8 == s8 /\ Seq.index s 9 == s9) ) let make_u64_10 b s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 =
true
null
false
b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4; b.(5ul) <- s5; b.(6ul) <- s6; b.(7ul) <- s7; b.(8ul) <- s8; b.(9ul) <- s9
{ "checked_file": "Hacl.Bignum25519.fst.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Spec.Curve25519.Field51.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "Hacl.Curve25519_51.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum25519.fst" }
[]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Lib.Buffer.op_Array_Assignment", "Prims.unit" ]
[]
module Hacl.Bignum25519 module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S51 = Hacl.Spec.Curve25519.Field51.Definition module SL51 = Hacl.Spec.Curve25519.Field51.Lemmas module BN = Hacl.Impl.Curve25519.Field51 module SC = Spec.Curve25519 friend Hacl.Curve25519_51 #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask_51 = u64 0x7ffffffffffff let make_u64_5 b s0 s1 s2 s3 s4 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4
false
false
Hacl.Bignum25519.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val make_u64_10: b:lbuffer uint64 10ul -> s0:uint64 -> s1:uint64 -> s2:uint64 -> s3:uint64 -> s4:uint64 -> s5:uint64 -> s6:uint64 -> s7:uint64 -> s8:uint64 -> s9:uint64 -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ (let s = as_seq h1 b in Seq.index s 0 == s0 /\ Seq.index s 1 == s1 /\ Seq.index s 2 == s2 /\ Seq.index s 3 == s3 /\ Seq.index s 4 == s4 /\ Seq.index s 5 == s5 /\ Seq.index s 6 == s6 /\ Seq.index s 7 == s7 /\ Seq.index s 8 == s8 /\ Seq.index s 9 == s9) )
[]
Hacl.Bignum25519.make_u64_10
{ "file_name": "code/ed25519/Hacl.Bignum25519.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Lib.Buffer.lbuffer Lib.IntTypes.uint64 10ul -> s0: Lib.IntTypes.uint64 -> s1: Lib.IntTypes.uint64 -> s2: Lib.IntTypes.uint64 -> s3: Lib.IntTypes.uint64 -> s4: Lib.IntTypes.uint64 -> s5: Lib.IntTypes.uint64 -> s6: Lib.IntTypes.uint64 -> s7: Lib.IntTypes.uint64 -> s8: Lib.IntTypes.uint64 -> s9: Lib.IntTypes.uint64 -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 15, "end_line": 43, "start_col": 2, "start_line": 34 }
FStar.HyperStack.ST.Stack
val store_51: output:lbuffer uint8 32ul -> input:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h input /\ live h output /\ F51.mul_inv_t h input) (ensures fun h0 _ h1 -> modifies (loc output) h0 h1 /\ as_seq h1 output == BSeq.nat_to_bytes_le 32 (F51.fevalh h0 input) )
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": "SL51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let store_51 output input = let h0 = ST.get () in push_frame (); let u64s = create 4ul (u64 0) in BN.store_felem u64s input; let h1 = ST.get () in assert (as_seq h1 u64s == BSeq.nat_to_intseq_le 4 (F51.fevalh h0 input)); uints_to_bytes_le 4ul output u64s; BSeq.uints_to_bytes_le_nat_lemma #U64 #SEC 4 (F51.fevalh h0 input); pop_frame ()
val store_51: output:lbuffer uint8 32ul -> input:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h input /\ live h output /\ F51.mul_inv_t h input) (ensures fun h0 _ h1 -> modifies (loc output) h0 h1 /\ as_seq h1 output == BSeq.nat_to_bytes_le 32 (F51.fevalh h0 input) ) let store_51 output input =
true
null
false
let h0 = ST.get () in push_frame (); let u64s = create 4ul (u64 0) in BN.store_felem u64s input; let h1 = ST.get () in assert (as_seq h1 u64s == BSeq.nat_to_intseq_le 4 (F51.fevalh h0 input)); uints_to_bytes_le 4ul output u64s; BSeq.uints_to_bytes_le_nat_lemma #U64 #SEC 4 (F51.fevalh h0 input); pop_frame ()
{ "checked_file": "Hacl.Bignum25519.fst.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Spec.Curve25519.Field51.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "Hacl.Curve25519_51.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum25519.fst" }
[]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.uint64", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Lib.ByteSequence.uints_to_bytes_le_nat_lemma", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Hacl.Impl.Ed25519.Field51.fevalh", "Lib.ByteBuffer.uints_to_bytes_le", "Prims._assert", "Prims.eq2", "Lib.Sequence.seq", "Prims.l_or", "Prims.nat", "FStar.Seq.Base.length", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.l_and", "Lib.Sequence.length", "Lib.IntTypes.uint_t", "Prims.b2t", "Prims.op_LessThan", "Prims.pow2", "FStar.Mul.op_Star", "Lib.IntTypes.bits", "Lib.ByteSequence.nat_from_intseq_le", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Lib.ByteSequence.nat_to_intseq_le", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.Impl.Curve25519.Field51.store_felem", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.int_t", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "Lib.IntTypes.u64", "FStar.HyperStack.ST.push_frame" ]
[]
module Hacl.Bignum25519 module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S51 = Hacl.Spec.Curve25519.Field51.Definition module SL51 = Hacl.Spec.Curve25519.Field51.Lemmas module BN = Hacl.Impl.Curve25519.Field51 module SC = Spec.Curve25519 friend Hacl.Curve25519_51 #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask_51 = u64 0x7ffffffffffff let make_u64_5 b s0 s1 s2 s3 s4 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4 let make_u64_10 b s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4; b.(5ul) <- s5; b.(6ul) <- s6; b.(7ul) <- s7; b.(8ul) <- s8; b.(9ul) <- s9 let make_zero b = b.(0ul) <- u64 0; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 0, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 0) let make_one b = b.(0ul) <- u64 1; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 1, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 1) [@CInline] let fsum out a b = BN.fadd out a b [@CInline] let fdifference out a b = BN.fsub out a b inline_for_extraction noextract val carry51: #m:S51.scale64{m < 8192} -> l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires S51.felem_fits1 l m /\ S51.felem_fits1 cin 1) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ S51.felem_fits1 l0 1 /\ uint_v l1 < m + 1) let carry51 l cin = let l' = l +! cin in mod_mask_lemma l' 51ul; assert (v (mod_mask #U64 #SEC 51ul) == v mask_51); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v l') 51 64; FStar.Math.Lemmas.euclidean_division_definition (v l') (pow2 51); FStar.Math.Lemmas.pow2_minus 64 51; (l' &. mask_51, l' >>. 51ul) let reduce_513 a = let (f0, f1, f2, f3, f4) = (a.(0ul), a.(1ul), a.(2ul), a.(3ul), a.(4ul)) in let tmp0, c0 = carry51 #9 f0 (u64 0) in let tmp1, c1 = carry51 #10 f1 c0 in let tmp2, c2 = carry51 #9 f2 c1 in let tmp3, c3 = carry51 #9 f3 c2 in let tmp4, c4 = carry51 #9 f4 c3 in assert (S51.felem_fits5 (tmp0, tmp1, tmp2, tmp3, tmp4) (1, 1, 1, 1, 1)); SL51.lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; assert ( S51.as_nat5 (f0, f1, f2, f3, f4) % SC.prime == (S51.as_nat5 (tmp0, tmp1, tmp2, tmp3, tmp4) + v c4 * 19) % SC.prime); [@inline_let] let tmp0', c5 = carry51 #1 tmp0 (c4 *! u64 19) in [@inline_let] let tmp1' = tmp1 +! c5 in Hacl.Spec.Curve25519.Field51.lemma_mul_inv (tmp0', tmp1, tmp2, tmp3, tmp4) c5; make_u64_5 a tmp0' tmp1' tmp2 tmp3 tmp4 [@CInline] let fmul output input input2 = push_frame(); let tmp = create 10ul (u128 0) in BN.fmul output input input2 tmp; pop_frame() [@CInline] let times_2 out a = (**) let h0 = ST.get() in let a0 = a.(0ul) in let a1 = a.(1ul) in let a2 = a.(2ul) in let a3 = a.(3ul) in let a4 = a.(4ul) in let o0 = u64 2 *. a0 in let o1 = u64 2 *. a1 in let o2 = u64 2 *. a2 in let o3 = u64 2 *. a3 in let o4 = u64 2 *. a4 in make_u64_5 out o0 o1 o2 o3 o4; (**) let h1 = ST.get() in (**) assert (S51.felem_fits1 a0 1); (**) assert (F51.felem_fits h1 out (2, 4, 2, 2, 2)); calc (==) { (2 * (F51.fevalh h0 a)) % SC.prime; (==) { calc (==) { F51.fevalh h0 a; (==) { } S51.as_nat5 (a0, a1, a2, a3, a4) % SC.prime; } } (2 * (S51.as_nat5 (a0, a1, a2, a3, a4) % SC.prime)) % SC.prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r 2 (S51.as_nat5 (a0, a1, a2, a3, a4)) SC.prime } (2 * S51.as_nat5 (a0, a1, a2, a3, a4)) % SC.prime; (==) { calc (==) { 2 * S51.as_nat5 (a0, a1, a2, a3, a4); (==) { SL51.lemma_smul_felem5 (u64 2) (a0, a1, a2, a3, a4) } 2 * v a0 + 2 * v a1 * S51.pow51 + 2 * v a2 * S51.pow51 * S51.pow51 + 2 * v a3 * S51.pow51 * S51.pow51 * S51.pow51 + 2 * v a4 * S51.pow51 * S51.pow51 * S51.pow51 * S51.pow51; (==) { assert_norm (2 * S51.pow51 < pow2 64); assert_norm (4 * S51.pow51 < pow2 64); FStar.Math.Lemmas.small_mod (2 * v a0) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a1) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a2) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a3) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a4) (pow2 64) } S51.as_nat5 (u64 2 *. a0, u64 2 *. a1, u64 2 *. a2, u64 2 *. a3, u64 2 *. a4); } } S51.as_nat5 (u64 2 *. a0, u64 2 *. a1, u64 2 *. a2, u64 2 *. a3, u64 2 *. a4) % SC.prime; (==) { } F51.fevalh h1 out; } [@CInline] let times_d out a = push_frame(); let d = create 5ul (u64 0) in d.(0ul) <- u64 0x00034dca135978a3; d.(1ul) <- u64 0x0001a8283b156ebd; d.(2ul) <- u64 0x0005e7a26001c029; d.(3ul) <- u64 0x000739c663a03cbb; d.(4ul) <- u64 0x00052036cee2b6ff; assert_norm (S51.as_nat5 (u64 0x00034dca135978a3, u64 0x0001a8283b156ebd, u64 0x0005e7a26001c029, u64 0x000739c663a03cbb, u64 0x00052036cee2b6ff) % Spec.Curve25519.prime == Spec.Ed25519.d); fmul out d a; pop_frame() [@CInline] let times_2d out a = push_frame(); let d2 = create 5ul (u64 0) in d2.(0ul) <- u64 0x00069b9426b2f159; d2.(1ul) <- u64 0x00035050762add7a; d2.(2ul) <- u64 0x0003cf44c0038052; d2.(3ul) <- u64 0x0006738cc7407977; d2.(4ul) <- u64 0x0002406d9dc56dff; fmul out d2 a; assert_norm (S51.as_nat5 (u64 0x00069b9426b2f159, u64 0x00035050762add7a, u64 0x0003cf44c0038052, u64 0x0006738cc7407977, u64 0x0002406d9dc56dff) % Spec.Curve25519.prime == 2 `SC.fmul` Spec.Ed25519.d); pop_frame() [@CInline] let fsquare out a = push_frame(); let tmp = create 5ul (u128 0) in BN.fsqr out a tmp; pop_frame() [@CInline] let fsquare_times output input count = push_frame(); let tmp = create 5ul (u128 0) in Hacl.Curve25519_51.fsquare_times output input tmp count; pop_frame() [@CInline] let fsquare_times_inplace output count = push_frame(); let tmp = create 5ul (u128 0) in Hacl.Curve25519_51.fsquare_times output output tmp count; pop_frame() let inverse out a = push_frame(); let tmp = create 10ul (u128 0) in Hacl.Curve25519_51.finv out a tmp; pop_frame() [@CInline] let reduce out = let (o0, o1, o2, o3, o4) = (out.(0ul), out.(1ul), out.(2ul), out.(3ul), out.(4ul)) in let (f0, f1, f2, f3, f4) = Hacl.Spec.Curve25519.Field51.carry_felem5_full (o0, o1, o2, o3, o4) in let (f0, f1, f2, f3, f4) = Hacl.Spec.Curve25519.Field51.subtract_p5 (f0, f1, f2, f3, f4) in Math.Lemmas.small_mod (S51.as_nat5 (f0, f1, f2, f3, f4)) Spec.Curve25519.prime; make_u64_5 out f0 f1 f2 f3 f4 let load_51 output input = push_frame (); let u64s = create 4ul (u64 0) in let h0 = ST.get () in uints_from_bytes_le #U64 u64s input; let h1 = ST.get () in BSeq.uints_from_bytes_le_nat_lemma #U64 #SEC #4 (as_seq h0 input); assert (BSeq.nat_from_intseq_le (as_seq h1 u64s) == BSeq.nat_from_bytes_le (as_seq h0 input)); let u64s3 = u64s.(3ul) in u64s.(3ul) <- u64s3 &. u64 0x7fffffffffffffff; mod_mask_lemma u64s3 63ul; assert_norm (0x7fffffffffffffff = pow2 63 - 1); assert (v (mod_mask #U64 #SEC 63ul) == v (u64 0x7fffffffffffffff)); let h2 = ST.get () in assert (v (LSeq.index (as_seq h2 u64s) 3) < pow2 63); Hacl.Spec.Curve25519.Field64.Lemmas.lemma_felem64_mod255 (as_seq h1 u64s); assert (BSeq.nat_from_intseq_le (as_seq h2 u64s) == BSeq.nat_from_bytes_le (as_seq h0 input) % pow2 255); output.(0ul) <- u64s.(0ul) &. mask_51; output.(1ul) <- (u64s.(0ul) >>. 51ul) |. ((u64s.(1ul) &. u64 0x3fffffffff) <<. 13ul); output.(2ul) <- (u64s.(1ul) >>. 38ul) |. ((u64s.(2ul) &. u64 0x1ffffff) <<. 26ul); output.(3ul) <- (u64s.(2ul) >>. 25ul) |. ((u64s.(3ul) &. u64 0xfff) <<. 39ul); output.(4ul) <- u64s.(3ul) >>. 12ul; SL51.lemma_load_felem (as_seq h2 u64s); pop_frame ()
false
false
Hacl.Bignum25519.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val store_51: output:lbuffer uint8 32ul -> input:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h input /\ live h output /\ F51.mul_inv_t h input) (ensures fun h0 _ h1 -> modifies (loc output) h0 h1 /\ as_seq h1 output == BSeq.nat_to_bytes_le 32 (F51.fevalh h0 input) )
[]
Hacl.Bignum25519.store_51
{ "file_name": "code/ed25519/Hacl.Bignum25519.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
output: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> input: Lib.Buffer.lbuffer Lib.IntTypes.uint64 5ul -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 14, "end_line": 288, "start_col": 27, "start_line": 279 }
FStar.HyperStack.ST.Stack
val times_d: out:felem -> a:felem -> Stack unit (requires fun h -> live h out /\ live h a /\ F51.mul_inv_t h a ) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.mul_inv_t h1 out /\ F51.fevalh h1 out == Spec.Ed25519.d `SC.fmul` F51.fevalh h0 a )
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": "SL51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let times_d out a = push_frame(); let d = create 5ul (u64 0) in d.(0ul) <- u64 0x00034dca135978a3; d.(1ul) <- u64 0x0001a8283b156ebd; d.(2ul) <- u64 0x0005e7a26001c029; d.(3ul) <- u64 0x000739c663a03cbb; d.(4ul) <- u64 0x00052036cee2b6ff; assert_norm (S51.as_nat5 (u64 0x00034dca135978a3, u64 0x0001a8283b156ebd, u64 0x0005e7a26001c029, u64 0x000739c663a03cbb, u64 0x00052036cee2b6ff) % Spec.Curve25519.prime == Spec.Ed25519.d); fmul out d a; pop_frame()
val times_d: out:felem -> a:felem -> Stack unit (requires fun h -> live h out /\ live h a /\ F51.mul_inv_t h a ) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.mul_inv_t h1 out /\ F51.fevalh h1 out == Spec.Ed25519.d `SC.fmul` F51.fevalh h0 a ) let times_d out a =
true
null
false
push_frame (); let d = create 5ul (u64 0) in d.(0ul) <- u64 0x00034dca135978a3; d.(1ul) <- u64 0x0001a8283b156ebd; d.(2ul) <- u64 0x0005e7a26001c029; d.(3ul) <- u64 0x000739c663a03cbb; d.(4ul) <- u64 0x00052036cee2b6ff; assert_norm (S51.as_nat5 (u64 0x00034dca135978a3, u64 0x0001a8283b156ebd, u64 0x0005e7a26001c029, u64 0x000739c663a03cbb, u64 0x00052036cee2b6ff) % Spec.Curve25519.prime == Spec.Ed25519.d); fmul out d a; pop_frame ()
{ "checked_file": "Hacl.Bignum25519.fst.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Spec.Curve25519.Field51.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "Hacl.Curve25519_51.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum25519.fst" }
[]
[ "Hacl.Bignum25519.felem", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Bignum25519.fmul", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Hacl.Spec.Curve25519.Field51.Definition.as_nat5", "FStar.Pervasives.Native.Mktuple5", "Lib.IntTypes.uint64", "Lib.IntTypes.u64", "Spec.Curve25519.prime", "Spec.Ed25519.PointOps.d", "Lib.Buffer.op_Array_Assignment", "FStar.UInt32.__uint_to_t", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "Lib.Buffer.lbuffer", "FStar.HyperStack.ST.push_frame" ]
[]
module Hacl.Bignum25519 module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S51 = Hacl.Spec.Curve25519.Field51.Definition module SL51 = Hacl.Spec.Curve25519.Field51.Lemmas module BN = Hacl.Impl.Curve25519.Field51 module SC = Spec.Curve25519 friend Hacl.Curve25519_51 #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask_51 = u64 0x7ffffffffffff let make_u64_5 b s0 s1 s2 s3 s4 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4 let make_u64_10 b s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4; b.(5ul) <- s5; b.(6ul) <- s6; b.(7ul) <- s7; b.(8ul) <- s8; b.(9ul) <- s9 let make_zero b = b.(0ul) <- u64 0; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 0, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 0) let make_one b = b.(0ul) <- u64 1; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 1, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 1) [@CInline] let fsum out a b = BN.fadd out a b [@CInline] let fdifference out a b = BN.fsub out a b inline_for_extraction noextract val carry51: #m:S51.scale64{m < 8192} -> l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires S51.felem_fits1 l m /\ S51.felem_fits1 cin 1) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ S51.felem_fits1 l0 1 /\ uint_v l1 < m + 1) let carry51 l cin = let l' = l +! cin in mod_mask_lemma l' 51ul; assert (v (mod_mask #U64 #SEC 51ul) == v mask_51); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v l') 51 64; FStar.Math.Lemmas.euclidean_division_definition (v l') (pow2 51); FStar.Math.Lemmas.pow2_minus 64 51; (l' &. mask_51, l' >>. 51ul) let reduce_513 a = let (f0, f1, f2, f3, f4) = (a.(0ul), a.(1ul), a.(2ul), a.(3ul), a.(4ul)) in let tmp0, c0 = carry51 #9 f0 (u64 0) in let tmp1, c1 = carry51 #10 f1 c0 in let tmp2, c2 = carry51 #9 f2 c1 in let tmp3, c3 = carry51 #9 f3 c2 in let tmp4, c4 = carry51 #9 f4 c3 in assert (S51.felem_fits5 (tmp0, tmp1, tmp2, tmp3, tmp4) (1, 1, 1, 1, 1)); SL51.lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; assert ( S51.as_nat5 (f0, f1, f2, f3, f4) % SC.prime == (S51.as_nat5 (tmp0, tmp1, tmp2, tmp3, tmp4) + v c4 * 19) % SC.prime); [@inline_let] let tmp0', c5 = carry51 #1 tmp0 (c4 *! u64 19) in [@inline_let] let tmp1' = tmp1 +! c5 in Hacl.Spec.Curve25519.Field51.lemma_mul_inv (tmp0', tmp1, tmp2, tmp3, tmp4) c5; make_u64_5 a tmp0' tmp1' tmp2 tmp3 tmp4 [@CInline] let fmul output input input2 = push_frame(); let tmp = create 10ul (u128 0) in BN.fmul output input input2 tmp; pop_frame() [@CInline] let times_2 out a = (**) let h0 = ST.get() in let a0 = a.(0ul) in let a1 = a.(1ul) in let a2 = a.(2ul) in let a3 = a.(3ul) in let a4 = a.(4ul) in let o0 = u64 2 *. a0 in let o1 = u64 2 *. a1 in let o2 = u64 2 *. a2 in let o3 = u64 2 *. a3 in let o4 = u64 2 *. a4 in make_u64_5 out o0 o1 o2 o3 o4; (**) let h1 = ST.get() in (**) assert (S51.felem_fits1 a0 1); (**) assert (F51.felem_fits h1 out (2, 4, 2, 2, 2)); calc (==) { (2 * (F51.fevalh h0 a)) % SC.prime; (==) { calc (==) { F51.fevalh h0 a; (==) { } S51.as_nat5 (a0, a1, a2, a3, a4) % SC.prime; } } (2 * (S51.as_nat5 (a0, a1, a2, a3, a4) % SC.prime)) % SC.prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r 2 (S51.as_nat5 (a0, a1, a2, a3, a4)) SC.prime } (2 * S51.as_nat5 (a0, a1, a2, a3, a4)) % SC.prime; (==) { calc (==) { 2 * S51.as_nat5 (a0, a1, a2, a3, a4); (==) { SL51.lemma_smul_felem5 (u64 2) (a0, a1, a2, a3, a4) } 2 * v a0 + 2 * v a1 * S51.pow51 + 2 * v a2 * S51.pow51 * S51.pow51 + 2 * v a3 * S51.pow51 * S51.pow51 * S51.pow51 + 2 * v a4 * S51.pow51 * S51.pow51 * S51.pow51 * S51.pow51; (==) { assert_norm (2 * S51.pow51 < pow2 64); assert_norm (4 * S51.pow51 < pow2 64); FStar.Math.Lemmas.small_mod (2 * v a0) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a1) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a2) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a3) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a4) (pow2 64) } S51.as_nat5 (u64 2 *. a0, u64 2 *. a1, u64 2 *. a2, u64 2 *. a3, u64 2 *. a4); } } S51.as_nat5 (u64 2 *. a0, u64 2 *. a1, u64 2 *. a2, u64 2 *. a3, u64 2 *. a4) % SC.prime; (==) { } F51.fevalh h1 out; } [@CInline]
false
false
Hacl.Bignum25519.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val times_d: out:felem -> a:felem -> Stack unit (requires fun h -> live h out /\ live h a /\ F51.mul_inv_t h a ) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.mul_inv_t h1 out /\ F51.fevalh h1 out == Spec.Ed25519.d `SC.fmul` F51.fevalh h0 a )
[]
Hacl.Bignum25519.times_d
{ "file_name": "code/ed25519/Hacl.Bignum25519.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
out: Hacl.Bignum25519.felem -> a: Hacl.Bignum25519.felem -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 13, "end_line": 192, "start_col": 2, "start_line": 181 }
FStar.HyperStack.ST.Stack
val times_2d: out:felem -> a:felem -> Stack unit (requires fun h -> live h out /\ live h a /\ F51.mul_inv_t h a ) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.mul_inv_t h1 out /\ F51.fevalh h1 out == 2 `SC.fmul` Spec.Ed25519.d `SC.fmul` F51.fevalh h0 a )
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": "SL51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let times_2d out a = push_frame(); let d2 = create 5ul (u64 0) in d2.(0ul) <- u64 0x00069b9426b2f159; d2.(1ul) <- u64 0x00035050762add7a; d2.(2ul) <- u64 0x0003cf44c0038052; d2.(3ul) <- u64 0x0006738cc7407977; d2.(4ul) <- u64 0x0002406d9dc56dff; fmul out d2 a; assert_norm (S51.as_nat5 (u64 0x00069b9426b2f159, u64 0x00035050762add7a, u64 0x0003cf44c0038052, u64 0x0006738cc7407977, u64 0x0002406d9dc56dff) % Spec.Curve25519.prime == 2 `SC.fmul` Spec.Ed25519.d); pop_frame()
val times_2d: out:felem -> a:felem -> Stack unit (requires fun h -> live h out /\ live h a /\ F51.mul_inv_t h a ) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.mul_inv_t h1 out /\ F51.fevalh h1 out == 2 `SC.fmul` Spec.Ed25519.d `SC.fmul` F51.fevalh h0 a ) let times_2d out a =
true
null
false
push_frame (); let d2 = create 5ul (u64 0) in d2.(0ul) <- u64 0x00069b9426b2f159; d2.(1ul) <- u64 0x00035050762add7a; d2.(2ul) <- u64 0x0003cf44c0038052; d2.(3ul) <- u64 0x0006738cc7407977; d2.(4ul) <- u64 0x0002406d9dc56dff; fmul out d2 a; assert_norm (S51.as_nat5 (u64 0x00069b9426b2f159, u64 0x00035050762add7a, u64 0x0003cf44c0038052, u64 0x0006738cc7407977, u64 0x0002406d9dc56dff) % Spec.Curve25519.prime == 2 `SC.fmul` Spec.Ed25519.d); pop_frame ()
{ "checked_file": "Hacl.Bignum25519.fst.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Spec.Curve25519.Field51.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "Hacl.Curve25519_51.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum25519.fst" }
[]
[ "Hacl.Bignum25519.felem", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Hacl.Spec.Curve25519.Field51.Definition.as_nat5", "FStar.Pervasives.Native.Mktuple5", "Lib.IntTypes.uint64", "Lib.IntTypes.u64", "Spec.Curve25519.prime", "Spec.Curve25519.fmul", "Spec.Ed25519.PointOps.d", "Hacl.Bignum25519.fmul", "Lib.Buffer.op_Array_Assignment", "FStar.UInt32.__uint_to_t", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "Lib.Buffer.lbuffer", "FStar.HyperStack.ST.push_frame" ]
[]
module Hacl.Bignum25519 module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S51 = Hacl.Spec.Curve25519.Field51.Definition module SL51 = Hacl.Spec.Curve25519.Field51.Lemmas module BN = Hacl.Impl.Curve25519.Field51 module SC = Spec.Curve25519 friend Hacl.Curve25519_51 #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask_51 = u64 0x7ffffffffffff let make_u64_5 b s0 s1 s2 s3 s4 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4 let make_u64_10 b s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4; b.(5ul) <- s5; b.(6ul) <- s6; b.(7ul) <- s7; b.(8ul) <- s8; b.(9ul) <- s9 let make_zero b = b.(0ul) <- u64 0; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 0, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 0) let make_one b = b.(0ul) <- u64 1; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 1, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 1) [@CInline] let fsum out a b = BN.fadd out a b [@CInline] let fdifference out a b = BN.fsub out a b inline_for_extraction noextract val carry51: #m:S51.scale64{m < 8192} -> l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires S51.felem_fits1 l m /\ S51.felem_fits1 cin 1) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ S51.felem_fits1 l0 1 /\ uint_v l1 < m + 1) let carry51 l cin = let l' = l +! cin in mod_mask_lemma l' 51ul; assert (v (mod_mask #U64 #SEC 51ul) == v mask_51); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v l') 51 64; FStar.Math.Lemmas.euclidean_division_definition (v l') (pow2 51); FStar.Math.Lemmas.pow2_minus 64 51; (l' &. mask_51, l' >>. 51ul) let reduce_513 a = let (f0, f1, f2, f3, f4) = (a.(0ul), a.(1ul), a.(2ul), a.(3ul), a.(4ul)) in let tmp0, c0 = carry51 #9 f0 (u64 0) in let tmp1, c1 = carry51 #10 f1 c0 in let tmp2, c2 = carry51 #9 f2 c1 in let tmp3, c3 = carry51 #9 f3 c2 in let tmp4, c4 = carry51 #9 f4 c3 in assert (S51.felem_fits5 (tmp0, tmp1, tmp2, tmp3, tmp4) (1, 1, 1, 1, 1)); SL51.lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; assert ( S51.as_nat5 (f0, f1, f2, f3, f4) % SC.prime == (S51.as_nat5 (tmp0, tmp1, tmp2, tmp3, tmp4) + v c4 * 19) % SC.prime); [@inline_let] let tmp0', c5 = carry51 #1 tmp0 (c4 *! u64 19) in [@inline_let] let tmp1' = tmp1 +! c5 in Hacl.Spec.Curve25519.Field51.lemma_mul_inv (tmp0', tmp1, tmp2, tmp3, tmp4) c5; make_u64_5 a tmp0' tmp1' tmp2 tmp3 tmp4 [@CInline] let fmul output input input2 = push_frame(); let tmp = create 10ul (u128 0) in BN.fmul output input input2 tmp; pop_frame() [@CInline] let times_2 out a = (**) let h0 = ST.get() in let a0 = a.(0ul) in let a1 = a.(1ul) in let a2 = a.(2ul) in let a3 = a.(3ul) in let a4 = a.(4ul) in let o0 = u64 2 *. a0 in let o1 = u64 2 *. a1 in let o2 = u64 2 *. a2 in let o3 = u64 2 *. a3 in let o4 = u64 2 *. a4 in make_u64_5 out o0 o1 o2 o3 o4; (**) let h1 = ST.get() in (**) assert (S51.felem_fits1 a0 1); (**) assert (F51.felem_fits h1 out (2, 4, 2, 2, 2)); calc (==) { (2 * (F51.fevalh h0 a)) % SC.prime; (==) { calc (==) { F51.fevalh h0 a; (==) { } S51.as_nat5 (a0, a1, a2, a3, a4) % SC.prime; } } (2 * (S51.as_nat5 (a0, a1, a2, a3, a4) % SC.prime)) % SC.prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r 2 (S51.as_nat5 (a0, a1, a2, a3, a4)) SC.prime } (2 * S51.as_nat5 (a0, a1, a2, a3, a4)) % SC.prime; (==) { calc (==) { 2 * S51.as_nat5 (a0, a1, a2, a3, a4); (==) { SL51.lemma_smul_felem5 (u64 2) (a0, a1, a2, a3, a4) } 2 * v a0 + 2 * v a1 * S51.pow51 + 2 * v a2 * S51.pow51 * S51.pow51 + 2 * v a3 * S51.pow51 * S51.pow51 * S51.pow51 + 2 * v a4 * S51.pow51 * S51.pow51 * S51.pow51 * S51.pow51; (==) { assert_norm (2 * S51.pow51 < pow2 64); assert_norm (4 * S51.pow51 < pow2 64); FStar.Math.Lemmas.small_mod (2 * v a0) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a1) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a2) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a3) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a4) (pow2 64) } S51.as_nat5 (u64 2 *. a0, u64 2 *. a1, u64 2 *. a2, u64 2 *. a3, u64 2 *. a4); } } S51.as_nat5 (u64 2 *. a0, u64 2 *. a1, u64 2 *. a2, u64 2 *. a3, u64 2 *. a4) % SC.prime; (==) { } F51.fevalh h1 out; } [@CInline] let times_d out a = push_frame(); let d = create 5ul (u64 0) in d.(0ul) <- u64 0x00034dca135978a3; d.(1ul) <- u64 0x0001a8283b156ebd; d.(2ul) <- u64 0x0005e7a26001c029; d.(3ul) <- u64 0x000739c663a03cbb; d.(4ul) <- u64 0x00052036cee2b6ff; assert_norm (S51.as_nat5 (u64 0x00034dca135978a3, u64 0x0001a8283b156ebd, u64 0x0005e7a26001c029, u64 0x000739c663a03cbb, u64 0x00052036cee2b6ff) % Spec.Curve25519.prime == Spec.Ed25519.d); fmul out d a; pop_frame() [@CInline]
false
false
Hacl.Bignum25519.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val times_2d: out:felem -> a:felem -> Stack unit (requires fun h -> live h out /\ live h a /\ F51.mul_inv_t h a ) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.mul_inv_t h1 out /\ F51.fevalh h1 out == 2 `SC.fmul` Spec.Ed25519.d `SC.fmul` F51.fevalh h0 a )
[]
Hacl.Bignum25519.times_2d
{ "file_name": "code/ed25519/Hacl.Bignum25519.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
out: Hacl.Bignum25519.felem -> a: Hacl.Bignum25519.felem -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 13, "end_line": 208, "start_col": 2, "start_line": 197 }
FStar.HyperStack.ST.Stack
val load_51: output:lbuffer uint64 5ul -> input:lbuffer uint8 32ul -> Stack unit (requires fun h -> live h output /\ live h input) (ensures fun h0 _ h1 -> modifies (loc output) h0 h1 /\ F51.felem_fits h1 output (1, 1, 1, 1, 1) /\ F51.as_nat h1 output == (BSeq.nat_from_bytes_le (as_seq h0 input) % pow2 255) )
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": "SL51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let load_51 output input = push_frame (); let u64s = create 4ul (u64 0) in let h0 = ST.get () in uints_from_bytes_le #U64 u64s input; let h1 = ST.get () in BSeq.uints_from_bytes_le_nat_lemma #U64 #SEC #4 (as_seq h0 input); assert (BSeq.nat_from_intseq_le (as_seq h1 u64s) == BSeq.nat_from_bytes_le (as_seq h0 input)); let u64s3 = u64s.(3ul) in u64s.(3ul) <- u64s3 &. u64 0x7fffffffffffffff; mod_mask_lemma u64s3 63ul; assert_norm (0x7fffffffffffffff = pow2 63 - 1); assert (v (mod_mask #U64 #SEC 63ul) == v (u64 0x7fffffffffffffff)); let h2 = ST.get () in assert (v (LSeq.index (as_seq h2 u64s) 3) < pow2 63); Hacl.Spec.Curve25519.Field64.Lemmas.lemma_felem64_mod255 (as_seq h1 u64s); assert (BSeq.nat_from_intseq_le (as_seq h2 u64s) == BSeq.nat_from_bytes_le (as_seq h0 input) % pow2 255); output.(0ul) <- u64s.(0ul) &. mask_51; output.(1ul) <- (u64s.(0ul) >>. 51ul) |. ((u64s.(1ul) &. u64 0x3fffffffff) <<. 13ul); output.(2ul) <- (u64s.(1ul) >>. 38ul) |. ((u64s.(2ul) &. u64 0x1ffffff) <<. 26ul); output.(3ul) <- (u64s.(2ul) >>. 25ul) |. ((u64s.(3ul) &. u64 0xfff) <<. 39ul); output.(4ul) <- u64s.(3ul) >>. 12ul; SL51.lemma_load_felem (as_seq h2 u64s); pop_frame ()
val load_51: output:lbuffer uint64 5ul -> input:lbuffer uint8 32ul -> Stack unit (requires fun h -> live h output /\ live h input) (ensures fun h0 _ h1 -> modifies (loc output) h0 h1 /\ F51.felem_fits h1 output (1, 1, 1, 1, 1) /\ F51.as_nat h1 output == (BSeq.nat_from_bytes_le (as_seq h0 input) % pow2 255) ) let load_51 output input =
true
null
false
push_frame (); let u64s = create 4ul (u64 0) in let h0 = ST.get () in uints_from_bytes_le #U64 u64s input; let h1 = ST.get () in BSeq.uints_from_bytes_le_nat_lemma #U64 #SEC #4 (as_seq h0 input); assert (BSeq.nat_from_intseq_le (as_seq h1 u64s) == BSeq.nat_from_bytes_le (as_seq h0 input)); let u64s3 = u64s.(3ul) in u64s.(3ul) <- u64s3 &. u64 0x7fffffffffffffff; mod_mask_lemma u64s3 63ul; assert_norm (0x7fffffffffffffff = pow2 63 - 1); assert (v (mod_mask #U64 #SEC 63ul) == v (u64 0x7fffffffffffffff)); let h2 = ST.get () in assert (v (LSeq.index (as_seq h2 u64s) 3) < pow2 63); Hacl.Spec.Curve25519.Field64.Lemmas.lemma_felem64_mod255 (as_seq h1 u64s); assert (BSeq.nat_from_intseq_le (as_seq h2 u64s) == BSeq.nat_from_bytes_le (as_seq h0 input) % pow2 255); output.(0ul) <- u64s.(0ul) &. mask_51; output.(1ul) <- (u64s.(0ul) >>. 51ul) |. ((u64s.(1ul) &. u64 0x3fffffffff) <<. 13ul); output.(2ul) <- (u64s.(1ul) >>. 38ul) |. ((u64s.(2ul) &. u64 0x1ffffff) <<. 26ul); output.(3ul) <- (u64s.(2ul) >>. 25ul) |. ((u64s.(3ul) &. u64 0xfff) <<. 39ul); output.(4ul) <- u64s.(3ul) >>. 12ul; SL51.lemma_load_felem (as_seq h2 u64s); pop_frame ()
{ "checked_file": "Hacl.Bignum25519.fst.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Spec.Curve25519.Field51.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "Hacl.Curve25519_51.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum25519.fst" }
[]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.uint8", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Spec.Curve25519.Field51.Lemmas.lemma_load_felem", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Lib.IntTypes.uint_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.Buffer.op_Array_Assignment", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Greater_Greater_Dot", "Lib.Buffer.op_Array_Access", "Lib.IntTypes.op_Bar_Dot", "Lib.IntTypes.op_Less_Less_Dot", "Lib.IntTypes.op_Amp_Dot", "Lib.IntTypes.u64", "Hacl.Bignum25519.mask_51", "Prims._assert", "Prims.eq2", "Prims.int", "Lib.ByteSequence.nat_from_intseq_le", "Prims.op_Modulus", "Lib.ByteSequence.nat_from_bytes_le", "Prims.pow2", "Hacl.Spec.Curve25519.Field64.Lemmas.lemma_felem64_mod255", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.Sequence.index", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Lib.IntTypes.range_t", "Lib.IntTypes.mod_mask", "FStar.Pervasives.assert_norm", "Prims.op_Equality", "Prims.op_Subtraction", "Lib.IntTypes.mod_mask_lemma", "Prims.nat", "Prims.l_or", "FStar.Mul.op_Star", "Lib.Sequence.length", "Lib.IntTypes.bits", "Lib.IntTypes.U8", "Lib.ByteSequence.uints_from_bytes_le_nat_lemma", "Lib.ByteBuffer.uints_from_bytes_le", "Lib.Buffer.lbuffer_t", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "FStar.HyperStack.ST.push_frame" ]
[]
module Hacl.Bignum25519 module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S51 = Hacl.Spec.Curve25519.Field51.Definition module SL51 = Hacl.Spec.Curve25519.Field51.Lemmas module BN = Hacl.Impl.Curve25519.Field51 module SC = Spec.Curve25519 friend Hacl.Curve25519_51 #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask_51 = u64 0x7ffffffffffff let make_u64_5 b s0 s1 s2 s3 s4 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4 let make_u64_10 b s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4; b.(5ul) <- s5; b.(6ul) <- s6; b.(7ul) <- s7; b.(8ul) <- s8; b.(9ul) <- s9 let make_zero b = b.(0ul) <- u64 0; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 0, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 0) let make_one b = b.(0ul) <- u64 1; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 1, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 1) [@CInline] let fsum out a b = BN.fadd out a b [@CInline] let fdifference out a b = BN.fsub out a b inline_for_extraction noextract val carry51: #m:S51.scale64{m < 8192} -> l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires S51.felem_fits1 l m /\ S51.felem_fits1 cin 1) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ S51.felem_fits1 l0 1 /\ uint_v l1 < m + 1) let carry51 l cin = let l' = l +! cin in mod_mask_lemma l' 51ul; assert (v (mod_mask #U64 #SEC 51ul) == v mask_51); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v l') 51 64; FStar.Math.Lemmas.euclidean_division_definition (v l') (pow2 51); FStar.Math.Lemmas.pow2_minus 64 51; (l' &. mask_51, l' >>. 51ul) let reduce_513 a = let (f0, f1, f2, f3, f4) = (a.(0ul), a.(1ul), a.(2ul), a.(3ul), a.(4ul)) in let tmp0, c0 = carry51 #9 f0 (u64 0) in let tmp1, c1 = carry51 #10 f1 c0 in let tmp2, c2 = carry51 #9 f2 c1 in let tmp3, c3 = carry51 #9 f3 c2 in let tmp4, c4 = carry51 #9 f4 c3 in assert (S51.felem_fits5 (tmp0, tmp1, tmp2, tmp3, tmp4) (1, 1, 1, 1, 1)); SL51.lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; assert ( S51.as_nat5 (f0, f1, f2, f3, f4) % SC.prime == (S51.as_nat5 (tmp0, tmp1, tmp2, tmp3, tmp4) + v c4 * 19) % SC.prime); [@inline_let] let tmp0', c5 = carry51 #1 tmp0 (c4 *! u64 19) in [@inline_let] let tmp1' = tmp1 +! c5 in Hacl.Spec.Curve25519.Field51.lemma_mul_inv (tmp0', tmp1, tmp2, tmp3, tmp4) c5; make_u64_5 a tmp0' tmp1' tmp2 tmp3 tmp4 [@CInline] let fmul output input input2 = push_frame(); let tmp = create 10ul (u128 0) in BN.fmul output input input2 tmp; pop_frame() [@CInline] let times_2 out a = (**) let h0 = ST.get() in let a0 = a.(0ul) in let a1 = a.(1ul) in let a2 = a.(2ul) in let a3 = a.(3ul) in let a4 = a.(4ul) in let o0 = u64 2 *. a0 in let o1 = u64 2 *. a1 in let o2 = u64 2 *. a2 in let o3 = u64 2 *. a3 in let o4 = u64 2 *. a4 in make_u64_5 out o0 o1 o2 o3 o4; (**) let h1 = ST.get() in (**) assert (S51.felem_fits1 a0 1); (**) assert (F51.felem_fits h1 out (2, 4, 2, 2, 2)); calc (==) { (2 * (F51.fevalh h0 a)) % SC.prime; (==) { calc (==) { F51.fevalh h0 a; (==) { } S51.as_nat5 (a0, a1, a2, a3, a4) % SC.prime; } } (2 * (S51.as_nat5 (a0, a1, a2, a3, a4) % SC.prime)) % SC.prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r 2 (S51.as_nat5 (a0, a1, a2, a3, a4)) SC.prime } (2 * S51.as_nat5 (a0, a1, a2, a3, a4)) % SC.prime; (==) { calc (==) { 2 * S51.as_nat5 (a0, a1, a2, a3, a4); (==) { SL51.lemma_smul_felem5 (u64 2) (a0, a1, a2, a3, a4) } 2 * v a0 + 2 * v a1 * S51.pow51 + 2 * v a2 * S51.pow51 * S51.pow51 + 2 * v a3 * S51.pow51 * S51.pow51 * S51.pow51 + 2 * v a4 * S51.pow51 * S51.pow51 * S51.pow51 * S51.pow51; (==) { assert_norm (2 * S51.pow51 < pow2 64); assert_norm (4 * S51.pow51 < pow2 64); FStar.Math.Lemmas.small_mod (2 * v a0) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a1) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a2) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a3) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a4) (pow2 64) } S51.as_nat5 (u64 2 *. a0, u64 2 *. a1, u64 2 *. a2, u64 2 *. a3, u64 2 *. a4); } } S51.as_nat5 (u64 2 *. a0, u64 2 *. a1, u64 2 *. a2, u64 2 *. a3, u64 2 *. a4) % SC.prime; (==) { } F51.fevalh h1 out; } [@CInline] let times_d out a = push_frame(); let d = create 5ul (u64 0) in d.(0ul) <- u64 0x00034dca135978a3; d.(1ul) <- u64 0x0001a8283b156ebd; d.(2ul) <- u64 0x0005e7a26001c029; d.(3ul) <- u64 0x000739c663a03cbb; d.(4ul) <- u64 0x00052036cee2b6ff; assert_norm (S51.as_nat5 (u64 0x00034dca135978a3, u64 0x0001a8283b156ebd, u64 0x0005e7a26001c029, u64 0x000739c663a03cbb, u64 0x00052036cee2b6ff) % Spec.Curve25519.prime == Spec.Ed25519.d); fmul out d a; pop_frame() [@CInline] let times_2d out a = push_frame(); let d2 = create 5ul (u64 0) in d2.(0ul) <- u64 0x00069b9426b2f159; d2.(1ul) <- u64 0x00035050762add7a; d2.(2ul) <- u64 0x0003cf44c0038052; d2.(3ul) <- u64 0x0006738cc7407977; d2.(4ul) <- u64 0x0002406d9dc56dff; fmul out d2 a; assert_norm (S51.as_nat5 (u64 0x00069b9426b2f159, u64 0x00035050762add7a, u64 0x0003cf44c0038052, u64 0x0006738cc7407977, u64 0x0002406d9dc56dff) % Spec.Curve25519.prime == 2 `SC.fmul` Spec.Ed25519.d); pop_frame() [@CInline] let fsquare out a = push_frame(); let tmp = create 5ul (u128 0) in BN.fsqr out a tmp; pop_frame() [@CInline] let fsquare_times output input count = push_frame(); let tmp = create 5ul (u128 0) in Hacl.Curve25519_51.fsquare_times output input tmp count; pop_frame() [@CInline] let fsquare_times_inplace output count = push_frame(); let tmp = create 5ul (u128 0) in Hacl.Curve25519_51.fsquare_times output output tmp count; pop_frame() let inverse out a = push_frame(); let tmp = create 10ul (u128 0) in Hacl.Curve25519_51.finv out a tmp; pop_frame() [@CInline] let reduce out = let (o0, o1, o2, o3, o4) = (out.(0ul), out.(1ul), out.(2ul), out.(3ul), out.(4ul)) in let (f0, f1, f2, f3, f4) = Hacl.Spec.Curve25519.Field51.carry_felem5_full (o0, o1, o2, o3, o4) in let (f0, f1, f2, f3, f4) = Hacl.Spec.Curve25519.Field51.subtract_p5 (f0, f1, f2, f3, f4) in Math.Lemmas.small_mod (S51.as_nat5 (f0, f1, f2, f3, f4)) Spec.Curve25519.prime; make_u64_5 out f0 f1 f2 f3 f4
false
false
Hacl.Bignum25519.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val load_51: output:lbuffer uint64 5ul -> input:lbuffer uint8 32ul -> Stack unit (requires fun h -> live h output /\ live h input) (ensures fun h0 _ h1 -> modifies (loc output) h0 h1 /\ F51.felem_fits h1 output (1, 1, 1, 1, 1) /\ F51.as_nat h1 output == (BSeq.nat_from_bytes_le (as_seq h0 input) % pow2 255) )
[]
Hacl.Bignum25519.load_51
{ "file_name": "code/ed25519/Hacl.Bignum25519.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
output: Lib.Buffer.lbuffer Lib.IntTypes.uint64 5ul -> input: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 14, "end_line": 276, "start_col": 2, "start_line": 252 }
FStar.HyperStack.ST.Stack
val times_2: out:felem -> a:felem -> Stack unit (requires fun h -> live h out /\ live h a /\ F51.mul_inv_t h a) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.felem_fits h1 out (2, 4, 2, 2, 2) /\ F51.fevalh h1 out == 2 `SC.fmul` F51.fevalh h0 a )
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": "SL51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let times_2 out a = (**) let h0 = ST.get() in let a0 = a.(0ul) in let a1 = a.(1ul) in let a2 = a.(2ul) in let a3 = a.(3ul) in let a4 = a.(4ul) in let o0 = u64 2 *. a0 in let o1 = u64 2 *. a1 in let o2 = u64 2 *. a2 in let o3 = u64 2 *. a3 in let o4 = u64 2 *. a4 in make_u64_5 out o0 o1 o2 o3 o4; (**) let h1 = ST.get() in (**) assert (S51.felem_fits1 a0 1); (**) assert (F51.felem_fits h1 out (2, 4, 2, 2, 2)); calc (==) { (2 * (F51.fevalh h0 a)) % SC.prime; (==) { calc (==) { F51.fevalh h0 a; (==) { } S51.as_nat5 (a0, a1, a2, a3, a4) % SC.prime; } } (2 * (S51.as_nat5 (a0, a1, a2, a3, a4) % SC.prime)) % SC.prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r 2 (S51.as_nat5 (a0, a1, a2, a3, a4)) SC.prime } (2 * S51.as_nat5 (a0, a1, a2, a3, a4)) % SC.prime; (==) { calc (==) { 2 * S51.as_nat5 (a0, a1, a2, a3, a4); (==) { SL51.lemma_smul_felem5 (u64 2) (a0, a1, a2, a3, a4) } 2 * v a0 + 2 * v a1 * S51.pow51 + 2 * v a2 * S51.pow51 * S51.pow51 + 2 * v a3 * S51.pow51 * S51.pow51 * S51.pow51 + 2 * v a4 * S51.pow51 * S51.pow51 * S51.pow51 * S51.pow51; (==) { assert_norm (2 * S51.pow51 < pow2 64); assert_norm (4 * S51.pow51 < pow2 64); FStar.Math.Lemmas.small_mod (2 * v a0) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a1) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a2) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a3) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a4) (pow2 64) } S51.as_nat5 (u64 2 *. a0, u64 2 *. a1, u64 2 *. a2, u64 2 *. a3, u64 2 *. a4); } } S51.as_nat5 (u64 2 *. a0, u64 2 *. a1, u64 2 *. a2, u64 2 *. a3, u64 2 *. a4) % SC.prime; (==) { } F51.fevalh h1 out; }
val times_2: out:felem -> a:felem -> Stack unit (requires fun h -> live h out /\ live h a /\ F51.mul_inv_t h a) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.felem_fits h1 out (2, 4, 2, 2, 2) /\ F51.fevalh h1 out == 2 `SC.fmul` F51.fevalh h0 a ) let times_2 out a =
true
null
false
let h0 = ST.get () in let a0 = a.(0ul) in let a1 = a.(1ul) in let a2 = a.(2ul) in let a3 = a.(3ul) in let a4 = a.(4ul) in let o0 = u64 2 *. a0 in let o1 = u64 2 *. a1 in let o2 = u64 2 *. a2 in let o3 = u64 2 *. a3 in let o4 = u64 2 *. a4 in make_u64_5 out o0 o1 o2 o3 o4; let h1 = ST.get () in assert (S51.felem_fits1 a0 1); assert (F51.felem_fits h1 out (2, 4, 2, 2, 2)); calc ( == ) { (2 * (F51.fevalh h0 a)) % SC.prime; ( == ) { calc ( == ) { F51.fevalh h0 a; ( == ) { () } S51.as_nat5 (a0, a1, a2, a3, a4) % SC.prime; } } (2 * (S51.as_nat5 (a0, a1, a2, a3, a4) % SC.prime)) % SC.prime; ( == ) { FStar.Math.Lemmas.lemma_mod_mul_distr_r 2 (S51.as_nat5 (a0, a1, a2, a3, a4)) SC.prime } (2 * S51.as_nat5 (a0, a1, a2, a3, a4)) % SC.prime; ( == ) { calc ( == ) { 2 * S51.as_nat5 (a0, a1, a2, a3, a4); ( == ) { SL51.lemma_smul_felem5 (u64 2) (a0, a1, a2, a3, a4) } 2 * v a0 + (2 * v a1) * S51.pow51 + ((2 * v a2) * S51.pow51) * S51.pow51 + (((2 * v a3) * S51.pow51) * S51.pow51) * S51.pow51 + ((((2 * v a4) * S51.pow51) * S51.pow51) * S51.pow51) * S51.pow51; ( == ) { (assert_norm (2 * S51.pow51 < pow2 64); assert_norm (4 * S51.pow51 < pow2 64); FStar.Math.Lemmas.small_mod (2 * v a0) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a1) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a2) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a3) (pow2 64); FStar.Math.Lemmas.small_mod (2 * v a4) (pow2 64)) } S51.as_nat5 (u64 2 *. a0, u64 2 *. a1, u64 2 *. a2, u64 2 *. a3, u64 2 *. a4); } } S51.as_nat5 (u64 2 *. a0, u64 2 *. a1, u64 2 *. a2, u64 2 *. a3, u64 2 *. a4) % SC.prime; ( == ) { () } F51.fevalh h1 out; }
{ "checked_file": "Hacl.Bignum25519.fst.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Spec.Curve25519.Field51.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "Hacl.Curve25519_51.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum25519.fst" }
[]
[ "Hacl.Bignum25519.felem", "FStar.Calc.calc_finish", "Prims.int", "Prims.eq2", "Prims.op_Modulus", "FStar.Mul.op_Star", "Hacl.Impl.Ed25519.Field51.fevalh", "Spec.Curve25519.prime", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Hacl.Spec.Curve25519.Field51.Definition.as_nat5", "FStar.Pervasives.Native.Mktuple5", "Lib.IntTypes.uint64", "Lib.IntTypes.op_Star_Dot", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.u64", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Spec.Curve25519.elem", "Prims.squash", "FStar.Math.Lemmas.lemma_mod_mul_distr_r", "Prims.op_Addition", "Lib.IntTypes.v", "Hacl.Spec.Curve25519.Field51.Definition.pow51", "Hacl.Spec.Curve25519.Field51.Lemmas.lemma_smul_felem5", "FStar.Math.Lemmas.small_mod", "Prims.pow2", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_LessThan", "Prims._assert", "Hacl.Impl.Ed25519.Field51.felem_fits", "Prims.nat", "Hacl.Spec.Curve25519.Field51.Definition.felem_fits1", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.Bignum25519.make_u64_5", "Lib.IntTypes.int_t", "Lib.Buffer.op_Array_Access", "Lib.Buffer.MUT", "FStar.UInt32.__uint_to_t" ]
[]
module Hacl.Bignum25519 module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module S51 = Hacl.Spec.Curve25519.Field51.Definition module SL51 = Hacl.Spec.Curve25519.Field51.Lemmas module BN = Hacl.Impl.Curve25519.Field51 module SC = Spec.Curve25519 friend Hacl.Curve25519_51 #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask_51 = u64 0x7ffffffffffff let make_u64_5 b s0 s1 s2 s3 s4 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4 let make_u64_10 b s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 = b.(0ul) <- s0; b.(1ul) <- s1; b.(2ul) <- s2; b.(3ul) <- s3; b.(4ul) <- s4; b.(5ul) <- s5; b.(6ul) <- s6; b.(7ul) <- s7; b.(8ul) <- s8; b.(9ul) <- s9 let make_zero b = b.(0ul) <- u64 0; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 0, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 0) let make_one b = b.(0ul) <- u64 1; b.(1ul) <- u64 0; b.(2ul) <- u64 0; b.(3ul) <- u64 0; b.(4ul) <- u64 0; assert_norm (S51.as_nat5 (u64 1, u64 0, u64 0, u64 0, u64 0) % Spec.Curve25519.prime == 1) [@CInline] let fsum out a b = BN.fadd out a b [@CInline] let fdifference out a b = BN.fsub out a b inline_for_extraction noextract val carry51: #m:S51.scale64{m < 8192} -> l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires S51.felem_fits1 l m /\ S51.felem_fits1 cin 1) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ S51.felem_fits1 l0 1 /\ uint_v l1 < m + 1) let carry51 l cin = let l' = l +! cin in mod_mask_lemma l' 51ul; assert (v (mod_mask #U64 #SEC 51ul) == v mask_51); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v l') 51 64; FStar.Math.Lemmas.euclidean_division_definition (v l') (pow2 51); FStar.Math.Lemmas.pow2_minus 64 51; (l' &. mask_51, l' >>. 51ul) let reduce_513 a = let (f0, f1, f2, f3, f4) = (a.(0ul), a.(1ul), a.(2ul), a.(3ul), a.(4ul)) in let tmp0, c0 = carry51 #9 f0 (u64 0) in let tmp1, c1 = carry51 #10 f1 c0 in let tmp2, c2 = carry51 #9 f2 c1 in let tmp3, c3 = carry51 #9 f3 c2 in let tmp4, c4 = carry51 #9 f4 c3 in assert (S51.felem_fits5 (tmp0, tmp1, tmp2, tmp3, tmp4) (1, 1, 1, 1, 1)); SL51.lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; assert ( S51.as_nat5 (f0, f1, f2, f3, f4) % SC.prime == (S51.as_nat5 (tmp0, tmp1, tmp2, tmp3, tmp4) + v c4 * 19) % SC.prime); [@inline_let] let tmp0', c5 = carry51 #1 tmp0 (c4 *! u64 19) in [@inline_let] let tmp1' = tmp1 +! c5 in Hacl.Spec.Curve25519.Field51.lemma_mul_inv (tmp0', tmp1, tmp2, tmp3, tmp4) c5; make_u64_5 a tmp0' tmp1' tmp2 tmp3 tmp4 [@CInline] let fmul output input input2 = push_frame(); let tmp = create 10ul (u128 0) in BN.fmul output input input2 tmp; pop_frame()
false
false
Hacl.Bignum25519.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val times_2: out:felem -> a:felem -> Stack unit (requires fun h -> live h out /\ live h a /\ F51.mul_inv_t h a) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.felem_fits h1 out (2, 4, 2, 2, 2) /\ F51.fevalh h1 out == 2 `SC.fmul` F51.fevalh h0 a )
[]
Hacl.Bignum25519.times_2
{ "file_name": "code/ed25519/Hacl.Bignum25519.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
out: Hacl.Bignum25519.felem -> a: Hacl.Bignum25519.felem -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 3, "end_line": 176, "start_col": 19, "start_line": 126 }
FStar.All.ALL
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let eq_typ env t1 t2 = if Ast.eq_typ t1 t2 then true else Ast.eq_typ (unfold_typ_abbrev_and_enum env t1) (unfold_typ_abbrev_and_enum env t2)
let eq_typ env t1 t2 =
true
null
false
if Ast.eq_typ t1 t2 then true else Ast.eq_typ (unfold_typ_abbrev_and_enum env t1) (unfold_typ_abbrev_and_enum env t2)
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[]
[ "Binding.env", "Ast.typ", "Ast.eq_typ", "Prims.bool", "Binding.unfold_typ_abbrev_and_enum" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range let lookup_macro_definition (e:env) (i:ident) = try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None let try_lookup_enum_cases (e:env) (i:ident) : ML (option (list ident & typ)) = match lookup e i with | Inr ({d_decl={v=Enum t _ tags}}, _) -> Some (Desugar.check_desugared_enum_cases tags, t) | _ -> None let lookup_enum_cases (e:env) (i:ident) : ML (list ident & typ) = match try_lookup_enum_cases e i with | Some (tags, t) -> tags, t | _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range let is_enum (e:env) (t:typ) = match t.v with | Type_app i KindSpec [] -> Some? (try_lookup_enum_cases e i) | _ -> false let is_used (e:env) (i:ident) : ML bool = match H.try_find e.locals i.v with | Some (_, t, b) -> b | _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range let type_of_integer_type = function | UInt8 -> tuint8 | UInt16 -> tuint16 | UInt32 -> tuint32 | UInt64 -> tuint64 let check_integer_bounds t i = match t with | UInt8 -> FStar.UInt.fits i 8 | UInt16 -> FStar.UInt.fits i 16 | UInt32 -> FStar.UInt.fits i 32 | UInt64 -> FStar.UInt.fits i 64 let type_of_constant rng (c:constant) : ML typ = match c with | Unit -> tunit | Int tag i -> if check_integer_bounds tag i then type_of_integer_type tag else error (Printf.sprintf "Constant %d is too large for its type %s" i (Ast.print_integer_type tag)) rng | XInt tag _ -> //bounds checked by the syntax type_of_integer_type tag | Bool _ -> tbool let parser_may_fail (env:env) (t:typ) : ML bool = match t.v with | Pointer _ -> true | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> attrs.may_fail | _ -> false let typ_is_integral env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> Some? attrs.integral | _ -> false let tag_of_integral_typ env (t:typ) : ML (option _) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral | _ -> None let tag_and_bit_order_of_integral_typ env (t:typ) : ML (tag_and_bit_order: (option integer_type & option bitfield_bit_order) { Some? (snd tag_and_bit_order) ==> Some? (fst tag_and_bit_order) }) = match t.v with | Pointer _ -> None, None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral, attrs.bit_order | _ -> None, None let has_reader (env:global_env) (id:ident) : ML bool = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.has_reader | _ -> false let parser_kind_nz (env:global_env) (id:ident) : ML (option bool) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.parser_kind_nz | _ -> None let parser_weak_kind (env:global_env) (id:ident) : ML (option _) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> Some attrs.parser_weak_kind | _ -> None let typ_weak_kind env (t:typ) : ML (option weak_kind) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> parser_weak_kind env.globals hd let typ_has_reader env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> has_reader env.globals hd let rec unfold_typ_abbrev_only (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match try_lookup env hd with | Some (Inr (d, _)) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_only env t | _ -> t end | _ -> t end | _ -> t let update_typ_abbrev (env:env) (i:ident) (t:typ) : ML unit = match H.try_find env.globals.ge_h i.v with | Some (d, ms) -> let d_decl = match d.d_decl.v with | TypeAbbrev _ _ -> {d.d_decl with v = TypeAbbrev t i } | _ -> failwith "Expected a type abbreviation" in let d = {d with d_decl = d_decl } in let entry = (d, ms) in H.insert env.globals.ge_h i.v entry | _ -> failwith "Type abbreviation not found" let rec unfold_typ_abbrev_and_enum (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match lookup env hd with | Inr (d, _) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_and_enum env t | Enum t _ _ -> unfold_typ_abbrev_and_enum env t | _ -> t end | _ -> t end | _ -> t let size_of_integral_typ (env:env) (t:typ) r : ML int = let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_of_integral_typ env t with | None -> failwith "Impossible" | Some UInt8 -> 1 | Some UInt16 -> 2 | Some UInt32 -> 4 | Some UInt64 -> 8 let bit_order_of_integral_typ (env:env) (t:typ) r : ML bitfield_bit_order = let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_and_bit_order_of_integral_typ env t with | _, None -> failwith "Impossible" | _, Some order -> order
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val eq_typ : env: Binding.env -> t1: Ast.typ -> t2: Ast.typ -> FStar.All.ALL Prims.bool
[]
Binding.eq_typ
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
env: Binding.env -> t1: Ast.typ -> t2: Ast.typ -> FStar.All.ALL Prims.bool
{ "end_col": 89, "end_line": 379, "start_col": 2, "start_line": 378 }
FStar.All.ML
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let eq_typs env ts = List.for_all (fun (t1, t2) -> eq_typ env t1 t2) ts
let eq_typs env ts =
true
null
false
List.for_all (fun (t1, t2) -> eq_typ env t1 t2) ts
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "Binding.env", "Prims.list", "FStar.Pervasives.Native.tuple2", "Ast.typ", "FStar.List.for_all", "Binding.eq_typ", "Prims.bool" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range let lookup_macro_definition (e:env) (i:ident) = try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None let try_lookup_enum_cases (e:env) (i:ident) : ML (option (list ident & typ)) = match lookup e i with | Inr ({d_decl={v=Enum t _ tags}}, _) -> Some (Desugar.check_desugared_enum_cases tags, t) | _ -> None let lookup_enum_cases (e:env) (i:ident) : ML (list ident & typ) = match try_lookup_enum_cases e i with | Some (tags, t) -> tags, t | _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range let is_enum (e:env) (t:typ) = match t.v with | Type_app i KindSpec [] -> Some? (try_lookup_enum_cases e i) | _ -> false let is_used (e:env) (i:ident) : ML bool = match H.try_find e.locals i.v with | Some (_, t, b) -> b | _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range let type_of_integer_type = function | UInt8 -> tuint8 | UInt16 -> tuint16 | UInt32 -> tuint32 | UInt64 -> tuint64 let check_integer_bounds t i = match t with | UInt8 -> FStar.UInt.fits i 8 | UInt16 -> FStar.UInt.fits i 16 | UInt32 -> FStar.UInt.fits i 32 | UInt64 -> FStar.UInt.fits i 64 let type_of_constant rng (c:constant) : ML typ = match c with | Unit -> tunit | Int tag i -> if check_integer_bounds tag i then type_of_integer_type tag else error (Printf.sprintf "Constant %d is too large for its type %s" i (Ast.print_integer_type tag)) rng | XInt tag _ -> //bounds checked by the syntax type_of_integer_type tag | Bool _ -> tbool let parser_may_fail (env:env) (t:typ) : ML bool = match t.v with | Pointer _ -> true | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> attrs.may_fail | _ -> false let typ_is_integral env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> Some? attrs.integral | _ -> false let tag_of_integral_typ env (t:typ) : ML (option _) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral | _ -> None let tag_and_bit_order_of_integral_typ env (t:typ) : ML (tag_and_bit_order: (option integer_type & option bitfield_bit_order) { Some? (snd tag_and_bit_order) ==> Some? (fst tag_and_bit_order) }) = match t.v with | Pointer _ -> None, None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral, attrs.bit_order | _ -> None, None let has_reader (env:global_env) (id:ident) : ML bool = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.has_reader | _ -> false let parser_kind_nz (env:global_env) (id:ident) : ML (option bool) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.parser_kind_nz | _ -> None let parser_weak_kind (env:global_env) (id:ident) : ML (option _) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> Some attrs.parser_weak_kind | _ -> None let typ_weak_kind env (t:typ) : ML (option weak_kind) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> parser_weak_kind env.globals hd let typ_has_reader env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> has_reader env.globals hd let rec unfold_typ_abbrev_only (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match try_lookup env hd with | Some (Inr (d, _)) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_only env t | _ -> t end | _ -> t end | _ -> t let update_typ_abbrev (env:env) (i:ident) (t:typ) : ML unit = match H.try_find env.globals.ge_h i.v with | Some (d, ms) -> let d_decl = match d.d_decl.v with | TypeAbbrev _ _ -> {d.d_decl with v = TypeAbbrev t i } | _ -> failwith "Expected a type abbreviation" in let d = {d with d_decl = d_decl } in let entry = (d, ms) in H.insert env.globals.ge_h i.v entry | _ -> failwith "Type abbreviation not found" let rec unfold_typ_abbrev_and_enum (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match lookup env hd with | Inr (d, _) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_and_enum env t | Enum t _ _ -> unfold_typ_abbrev_and_enum env t | _ -> t end | _ -> t end | _ -> t let size_of_integral_typ (env:env) (t:typ) r : ML int = let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_of_integral_typ env t with | None -> failwith "Impossible" | Some UInt8 -> 1 | Some UInt16 -> 2 | Some UInt32 -> 4 | Some UInt64 -> 8 let bit_order_of_integral_typ (env:env) (t:typ) r : ML bitfield_bit_order = let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_and_bit_order_of_integral_typ env t with | _, None -> failwith "Impossible" | _, Some order -> order let eq_typ env t1 t2 = if Ast.eq_typ t1 t2 then true else Ast.eq_typ (unfold_typ_abbrev_and_enum env t1) (unfold_typ_abbrev_and_enum env t2)
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val eq_typs : env: Binding.env -> ts: Prims.list (Ast.typ * Ast.typ) -> FStar.All.ML Prims.bool
[]
Binding.eq_typs
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
env: Binding.env -> ts: Prims.list (Ast.typ * Ast.typ) -> FStar.All.ML Prims.bool
{ "end_col": 52, "end_line": 382, "start_col": 2, "start_line": 382 }
Prims.Tot
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let cast e t t' = { e with v = App (Cast (Some t) t') [e] }
let cast e t t' =
false
null
false
{ e with v = App (Cast (Some t) t') [e] }
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "total" ]
[ "Ast.with_meta_t", "Ast.expr'", "Ast.integer_type", "Ast.Mkwith_meta_t", "Ast.App", "Ast.Cast", "FStar.Pervasives.Native.Some", "Prims.Cons", "Prims.Nil", "Ast.__proj__Mkwith_meta_t__item__range", "Ast.__proj__Mkwith_meta_t__item__comments" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range let lookup_macro_definition (e:env) (i:ident) = try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None let try_lookup_enum_cases (e:env) (i:ident) : ML (option (list ident & typ)) = match lookup e i with | Inr ({d_decl={v=Enum t _ tags}}, _) -> Some (Desugar.check_desugared_enum_cases tags, t) | _ -> None let lookup_enum_cases (e:env) (i:ident) : ML (list ident & typ) = match try_lookup_enum_cases e i with | Some (tags, t) -> tags, t | _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range let is_enum (e:env) (t:typ) = match t.v with | Type_app i KindSpec [] -> Some? (try_lookup_enum_cases e i) | _ -> false let is_used (e:env) (i:ident) : ML bool = match H.try_find e.locals i.v with | Some (_, t, b) -> b | _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range let type_of_integer_type = function | UInt8 -> tuint8 | UInt16 -> tuint16 | UInt32 -> tuint32 | UInt64 -> tuint64 let check_integer_bounds t i = match t with | UInt8 -> FStar.UInt.fits i 8 | UInt16 -> FStar.UInt.fits i 16 | UInt32 -> FStar.UInt.fits i 32 | UInt64 -> FStar.UInt.fits i 64 let type_of_constant rng (c:constant) : ML typ = match c with | Unit -> tunit | Int tag i -> if check_integer_bounds tag i then type_of_integer_type tag else error (Printf.sprintf "Constant %d is too large for its type %s" i (Ast.print_integer_type tag)) rng | XInt tag _ -> //bounds checked by the syntax type_of_integer_type tag | Bool _ -> tbool let parser_may_fail (env:env) (t:typ) : ML bool = match t.v with | Pointer _ -> true | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> attrs.may_fail | _ -> false let typ_is_integral env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> Some? attrs.integral | _ -> false let tag_of_integral_typ env (t:typ) : ML (option _) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral | _ -> None let tag_and_bit_order_of_integral_typ env (t:typ) : ML (tag_and_bit_order: (option integer_type & option bitfield_bit_order) { Some? (snd tag_and_bit_order) ==> Some? (fst tag_and_bit_order) }) = match t.v with | Pointer _ -> None, None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral, attrs.bit_order | _ -> None, None let has_reader (env:global_env) (id:ident) : ML bool = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.has_reader | _ -> false let parser_kind_nz (env:global_env) (id:ident) : ML (option bool) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.parser_kind_nz | _ -> None let parser_weak_kind (env:global_env) (id:ident) : ML (option _) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> Some attrs.parser_weak_kind | _ -> None let typ_weak_kind env (t:typ) : ML (option weak_kind) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> parser_weak_kind env.globals hd let typ_has_reader env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> has_reader env.globals hd let rec unfold_typ_abbrev_only (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match try_lookup env hd with | Some (Inr (d, _)) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_only env t | _ -> t end | _ -> t end | _ -> t let update_typ_abbrev (env:env) (i:ident) (t:typ) : ML unit = match H.try_find env.globals.ge_h i.v with | Some (d, ms) -> let d_decl = match d.d_decl.v with | TypeAbbrev _ _ -> {d.d_decl with v = TypeAbbrev t i } | _ -> failwith "Expected a type abbreviation" in let d = {d with d_decl = d_decl } in let entry = (d, ms) in H.insert env.globals.ge_h i.v entry | _ -> failwith "Type abbreviation not found" let rec unfold_typ_abbrev_and_enum (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match lookup env hd with | Inr (d, _) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_and_enum env t | Enum t _ _ -> unfold_typ_abbrev_and_enum env t | _ -> t end | _ -> t end | _ -> t let size_of_integral_typ (env:env) (t:typ) r : ML int = let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_of_integral_typ env t with | None -> failwith "Impossible" | Some UInt8 -> 1 | Some UInt16 -> 2 | Some UInt32 -> 4 | Some UInt64 -> 8 let bit_order_of_integral_typ (env:env) (t:typ) r : ML bitfield_bit_order = let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_and_bit_order_of_integral_typ env t with | _, None -> failwith "Impossible" | _, Some order -> order let eq_typ env t1 t2 = if Ast.eq_typ t1 t2 then true else Ast.eq_typ (unfold_typ_abbrev_and_enum env t1) (unfold_typ_abbrev_and_enum env t2) let eq_typs env ts = List.for_all (fun (t1, t2) -> eq_typ env t1 t2) ts
false
true
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val cast : e: Ast.with_meta_t Ast.expr' -> t: Ast.integer_type -> t': Ast.integer_type -> Ast.with_meta_t Ast.expr'
[]
Binding.cast
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
e: Ast.with_meta_t Ast.expr' -> t: Ast.integer_type -> t': Ast.integer_type -> Ast.with_meta_t Ast.expr'
{ "end_col": 57, "end_line": 384, "start_col": 20, "start_line": 384 }
FStar.All.ML
val unfold_typ_abbrev_only (_:env) (t:typ) : ML typ
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec unfold_typ_abbrev_only (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match try_lookup env hd with | Some (Inr (d, _)) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_only env t | _ -> t end | _ -> t end | _ -> t
val unfold_typ_abbrev_only (_:env) (t:typ) : ML typ let rec unfold_typ_abbrev_only (env: env) (t: typ) : ML typ =
true
null
false
match t.v with | Type_app hd _ [] -> (match try_lookup env hd with | Some (Inr (d, _)) -> (match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_only env t | _ -> t) | _ -> t) | _ -> t
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "Binding.env", "Ast.typ", "Ast.__proj__Mkwith_meta_t__item__v", "Ast.typ'", "Ast.ident", "Ast.t_kind", "Ast.decl", "Ast.either", "GlobalEnv.decl_attributes", "GlobalEnv.macro_signature", "Ast.decl'", "Ast.__proj__Mkdecl__item__d_decl", "Binding.unfold_typ_abbrev_only", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "Binding.try_lookup" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range let lookup_macro_definition (e:env) (i:ident) = try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None let try_lookup_enum_cases (e:env) (i:ident) : ML (option (list ident & typ)) = match lookup e i with | Inr ({d_decl={v=Enum t _ tags}}, _) -> Some (Desugar.check_desugared_enum_cases tags, t) | _ -> None let lookup_enum_cases (e:env) (i:ident) : ML (list ident & typ) = match try_lookup_enum_cases e i with | Some (tags, t) -> tags, t | _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range let is_enum (e:env) (t:typ) = match t.v with | Type_app i KindSpec [] -> Some? (try_lookup_enum_cases e i) | _ -> false let is_used (e:env) (i:ident) : ML bool = match H.try_find e.locals i.v with | Some (_, t, b) -> b | _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range let type_of_integer_type = function | UInt8 -> tuint8 | UInt16 -> tuint16 | UInt32 -> tuint32 | UInt64 -> tuint64 let check_integer_bounds t i = match t with | UInt8 -> FStar.UInt.fits i 8 | UInt16 -> FStar.UInt.fits i 16 | UInt32 -> FStar.UInt.fits i 32 | UInt64 -> FStar.UInt.fits i 64 let type_of_constant rng (c:constant) : ML typ = match c with | Unit -> tunit | Int tag i -> if check_integer_bounds tag i then type_of_integer_type tag else error (Printf.sprintf "Constant %d is too large for its type %s" i (Ast.print_integer_type tag)) rng | XInt tag _ -> //bounds checked by the syntax type_of_integer_type tag | Bool _ -> tbool let parser_may_fail (env:env) (t:typ) : ML bool = match t.v with | Pointer _ -> true | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> attrs.may_fail | _ -> false let typ_is_integral env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> Some? attrs.integral | _ -> false let tag_of_integral_typ env (t:typ) : ML (option _) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral | _ -> None let tag_and_bit_order_of_integral_typ env (t:typ) : ML (tag_and_bit_order: (option integer_type & option bitfield_bit_order) { Some? (snd tag_and_bit_order) ==> Some? (fst tag_and_bit_order) }) = match t.v with | Pointer _ -> None, None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral, attrs.bit_order | _ -> None, None let has_reader (env:global_env) (id:ident) : ML bool = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.has_reader | _ -> false let parser_kind_nz (env:global_env) (id:ident) : ML (option bool) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.parser_kind_nz | _ -> None let parser_weak_kind (env:global_env) (id:ident) : ML (option _) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> Some attrs.parser_weak_kind | _ -> None let typ_weak_kind env (t:typ) : ML (option weak_kind) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> parser_weak_kind env.globals hd let typ_has_reader env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> has_reader env.globals hd
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val unfold_typ_abbrev_only (_:env) (t:typ) : ML typ
[ "recursion" ]
Binding.unfold_typ_abbrev_only
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
env: Binding.env -> t: Ast.typ -> FStar.All.ML Ast.typ
{ "end_col": 10, "end_line": 318, "start_col": 2, "start_line": 306 }
FStar.All.ML
val lookup_enum_cases (e: env) (i: ident) : ML (list ident & typ)
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lookup_enum_cases (e:env) (i:ident) : ML (list ident & typ) = match try_lookup_enum_cases e i with | Some (tags, t) -> tags, t | _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range
val lookup_enum_cases (e: env) (i: ident) : ML (list ident & typ) let lookup_enum_cases (e: env) (i: ident) : ML (list ident & typ) =
true
null
false
match try_lookup_enum_cases e i with | Some (tags, t) -> tags, t | _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "Binding.env", "Ast.ident", "Prims.list", "Ast.typ", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.option", "Ast.error", "FStar.Printf.sprintf", "Ast.ident_to_string", "Ast.__proj__Mkwith_meta_t__item__range", "Ast.ident'", "Binding.try_lookup_enum_cases" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range let lookup_macro_definition (e:env) (i:ident) = try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None let try_lookup_enum_cases (e:env) (i:ident) : ML (option (list ident & typ)) = match lookup e i with | Inr ({d_decl={v=Enum t _ tags}}, _) -> Some (Desugar.check_desugared_enum_cases tags, t) | _ -> None let lookup_enum_cases (e:env) (i:ident)
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lookup_enum_cases (e: env) (i: ident) : ML (list ident & typ)
[]
Binding.lookup_enum_cases
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
e: Binding.env -> i: Ast.ident -> FStar.All.ML (Prims.list Ast.ident * Ast.typ)
{ "end_col": 93, "end_line": 209, "start_col": 4, "start_line": 207 }
Prims.Tot
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let _or_ b1 b2 = b1 || b2
let _or_ b1 b2 =
false
null
false
b1 || b2
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "total" ]
[ "Prims.bool", "Prims.op_BarBar" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range let lookup_macro_definition (e:env) (i:ident) = try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None let try_lookup_enum_cases (e:env) (i:ident) : ML (option (list ident & typ)) = match lookup e i with | Inr ({d_decl={v=Enum t _ tags}}, _) -> Some (Desugar.check_desugared_enum_cases tags, t) | _ -> None let lookup_enum_cases (e:env) (i:ident) : ML (list ident & typ) = match try_lookup_enum_cases e i with | Some (tags, t) -> tags, t | _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range let is_enum (e:env) (t:typ) = match t.v with | Type_app i KindSpec [] -> Some? (try_lookup_enum_cases e i) | _ -> false let is_used (e:env) (i:ident) : ML bool = match H.try_find e.locals i.v with | Some (_, t, b) -> b | _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range let type_of_integer_type = function | UInt8 -> tuint8 | UInt16 -> tuint16 | UInt32 -> tuint32 | UInt64 -> tuint64 let check_integer_bounds t i = match t with | UInt8 -> FStar.UInt.fits i 8 | UInt16 -> FStar.UInt.fits i 16 | UInt32 -> FStar.UInt.fits i 32 | UInt64 -> FStar.UInt.fits i 64 let type_of_constant rng (c:constant) : ML typ = match c with | Unit -> tunit | Int tag i -> if check_integer_bounds tag i then type_of_integer_type tag else error (Printf.sprintf "Constant %d is too large for its type %s" i (Ast.print_integer_type tag)) rng | XInt tag _ -> //bounds checked by the syntax type_of_integer_type tag | Bool _ -> tbool let parser_may_fail (env:env) (t:typ) : ML bool = match t.v with | Pointer _ -> true | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> attrs.may_fail | _ -> false let typ_is_integral env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> Some? attrs.integral | _ -> false let tag_of_integral_typ env (t:typ) : ML (option _) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral | _ -> None let tag_and_bit_order_of_integral_typ env (t:typ) : ML (tag_and_bit_order: (option integer_type & option bitfield_bit_order) { Some? (snd tag_and_bit_order) ==> Some? (fst tag_and_bit_order) }) = match t.v with | Pointer _ -> None, None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral, attrs.bit_order | _ -> None, None let has_reader (env:global_env) (id:ident) : ML bool = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.has_reader | _ -> false let parser_kind_nz (env:global_env) (id:ident) : ML (option bool) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.parser_kind_nz | _ -> None let parser_weak_kind (env:global_env) (id:ident) : ML (option _) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> Some attrs.parser_weak_kind | _ -> None let typ_weak_kind env (t:typ) : ML (option weak_kind) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> parser_weak_kind env.globals hd let typ_has_reader env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> has_reader env.globals hd let rec unfold_typ_abbrev_only (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match try_lookup env hd with | Some (Inr (d, _)) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_only env t | _ -> t end | _ -> t end | _ -> t let update_typ_abbrev (env:env) (i:ident) (t:typ) : ML unit = match H.try_find env.globals.ge_h i.v with | Some (d, ms) -> let d_decl = match d.d_decl.v with | TypeAbbrev _ _ -> {d.d_decl with v = TypeAbbrev t i } | _ -> failwith "Expected a type abbreviation" in let d = {d with d_decl = d_decl } in let entry = (d, ms) in H.insert env.globals.ge_h i.v entry | _ -> failwith "Type abbreviation not found" let rec unfold_typ_abbrev_and_enum (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match lookup env hd with | Inr (d, _) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_and_enum env t | Enum t _ _ -> unfold_typ_abbrev_and_enum env t | _ -> t end | _ -> t end | _ -> t let size_of_integral_typ (env:env) (t:typ) r : ML int = let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_of_integral_typ env t with | None -> failwith "Impossible" | Some UInt8 -> 1 | Some UInt16 -> 2 | Some UInt32 -> 4 | Some UInt64 -> 8 let bit_order_of_integral_typ (env:env) (t:typ) r : ML bitfield_bit_order = let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_and_bit_order_of_integral_typ env t with | _, None -> failwith "Impossible" | _, Some order -> order let eq_typ env t1 t2 = if Ast.eq_typ t1 t2 then true else Ast.eq_typ (unfold_typ_abbrev_and_enum env t1) (unfold_typ_abbrev_and_enum env t2) let eq_typs env ts = List.for_all (fun (t1, t2) -> eq_typ env t1 t2) ts let cast e t t' = { e with v = App (Cast (Some t) t') [e] } let try_cast_integer env et to : ML (option expr) = let e, from = et in let i_to = typ_is_integral env to in let i_from = typ_is_integral env from in if i_from && i_to then let i_from = typ_as_integer_type (unfold_typ_abbrev_and_enum env from) in let i_to = typ_as_integer_type (unfold_typ_abbrev_and_enum env to) in if i_from = i_to then Some e else if integer_type_leq i_from i_to then Some (cast e i_from i_to) else None else None
false
true
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val _or_ : b1: Prims.bool -> b2: Prims.bool -> Prims.bool
[]
Binding._or_
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
b1: Prims.bool -> b2: Prims.bool -> Prims.bool
{ "end_col": 25, "end_line": 401, "start_col": 17, "start_line": 401 }
FStar.All.ML
val lookup_macro_definition (_:env) (_:ident) : ML (option expr)
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lookup_macro_definition (e:env) (i:ident) = try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None
val lookup_macro_definition (_:env) (_:ident) : ML (option expr) let lookup_macro_definition (e: env) (i: ident) =
true
null
false
try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "Binding.env", "Ast.ident", "FStar.All.try_with", "FStar.Pervasives.Native.option", "Ast.expr", "Prims.unit", "GlobalEnv.__proj__Mkmacro_signature__item__macro_defn_t", "GlobalEnv.macro_signature", "Binding.lookup_macro_name", "Prims.exn", "FStar.Pervasives.Native.None" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lookup_macro_definition (_:env) (_:ident) : ML (option expr)
[]
Binding.lookup_macro_definition
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
e: Binding.env -> i: Ast.ident -> FStar.All.ML (FStar.Pervasives.Native.option Ast.expr)
{ "end_col": 13, "end_line": 196, "start_col": 2, "start_line": 192 }
FStar.All.ML
val check_output_type (ge: global_env) (t: typ) : ML ident
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let check_output_type (ge:global_env) (t:typ) : ML ident = let err () : ML ident = error (Printf.sprintf "Type %s is not an output type" (print_typ t)) t.range in match t.v with | Type_app i KindOutput [] -> i | _ -> err ()
val check_output_type (ge: global_env) (t: typ) : ML ident let check_output_type (ge: global_env) (t: typ) : ML ident =
true
null
false
let err () : ML ident = error (Printf.sprintf "Type %s is not an output type" (print_typ t)) t.range in match t.v with | Type_app i KindOutput [] -> i | _ -> err ()
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "GlobalEnv.global_env", "Ast.typ", "Ast.__proj__Mkwith_meta_t__item__v", "Ast.typ'", "Ast.ident", "Prims.unit", "Ast.error", "Ast.__proj__Mkwith_meta_t__item__range", "Prims.string", "FStar.Printf.sprintf", "Ast.print_typ" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range let lookup_macro_definition (e:env) (i:ident) = try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None let try_lookup_enum_cases (e:env) (i:ident) : ML (option (list ident & typ)) = match lookup e i with | Inr ({d_decl={v=Enum t _ tags}}, _) -> Some (Desugar.check_desugared_enum_cases tags, t) | _ -> None let lookup_enum_cases (e:env) (i:ident) : ML (list ident & typ) = match try_lookup_enum_cases e i with | Some (tags, t) -> tags, t | _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range let is_enum (e:env) (t:typ) = match t.v with | Type_app i KindSpec [] -> Some? (try_lookup_enum_cases e i) | _ -> false let is_used (e:env) (i:ident) : ML bool = match H.try_find e.locals i.v with | Some (_, t, b) -> b | _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range let type_of_integer_type = function | UInt8 -> tuint8 | UInt16 -> tuint16 | UInt32 -> tuint32 | UInt64 -> tuint64 let check_integer_bounds t i = match t with | UInt8 -> FStar.UInt.fits i 8 | UInt16 -> FStar.UInt.fits i 16 | UInt32 -> FStar.UInt.fits i 32 | UInt64 -> FStar.UInt.fits i 64 let type_of_constant rng (c:constant) : ML typ = match c with | Unit -> tunit | Int tag i -> if check_integer_bounds tag i then type_of_integer_type tag else error (Printf.sprintf "Constant %d is too large for its type %s" i (Ast.print_integer_type tag)) rng | XInt tag _ -> //bounds checked by the syntax type_of_integer_type tag | Bool _ -> tbool let parser_may_fail (env:env) (t:typ) : ML bool = match t.v with | Pointer _ -> true | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> attrs.may_fail | _ -> false let typ_is_integral env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> Some? attrs.integral | _ -> false let tag_of_integral_typ env (t:typ) : ML (option _) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral | _ -> None let tag_and_bit_order_of_integral_typ env (t:typ) : ML (tag_and_bit_order: (option integer_type & option bitfield_bit_order) { Some? (snd tag_and_bit_order) ==> Some? (fst tag_and_bit_order) }) = match t.v with | Pointer _ -> None, None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral, attrs.bit_order | _ -> None, None let has_reader (env:global_env) (id:ident) : ML bool = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.has_reader | _ -> false let parser_kind_nz (env:global_env) (id:ident) : ML (option bool) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.parser_kind_nz | _ -> None let parser_weak_kind (env:global_env) (id:ident) : ML (option _) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> Some attrs.parser_weak_kind | _ -> None let typ_weak_kind env (t:typ) : ML (option weak_kind) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> parser_weak_kind env.globals hd let typ_has_reader env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> has_reader env.globals hd let rec unfold_typ_abbrev_only (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match try_lookup env hd with | Some (Inr (d, _)) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_only env t | _ -> t end | _ -> t end | _ -> t let update_typ_abbrev (env:env) (i:ident) (t:typ) : ML unit = match H.try_find env.globals.ge_h i.v with | Some (d, ms) -> let d_decl = match d.d_decl.v with | TypeAbbrev _ _ -> {d.d_decl with v = TypeAbbrev t i } | _ -> failwith "Expected a type abbreviation" in let d = {d with d_decl = d_decl } in let entry = (d, ms) in H.insert env.globals.ge_h i.v entry | _ -> failwith "Type abbreviation not found" let rec unfold_typ_abbrev_and_enum (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match lookup env hd with | Inr (d, _) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_and_enum env t | Enum t _ _ -> unfold_typ_abbrev_and_enum env t | _ -> t end | _ -> t end | _ -> t let size_of_integral_typ (env:env) (t:typ) r : ML int = let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_of_integral_typ env t with | None -> failwith "Impossible" | Some UInt8 -> 1 | Some UInt16 -> 2 | Some UInt32 -> 4 | Some UInt64 -> 8 let bit_order_of_integral_typ (env:env) (t:typ) r : ML bitfield_bit_order = let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_and_bit_order_of_integral_typ env t with | _, None -> failwith "Impossible" | _, Some order -> order let eq_typ env t1 t2 = if Ast.eq_typ t1 t2 then true else Ast.eq_typ (unfold_typ_abbrev_and_enum env t1) (unfold_typ_abbrev_and_enum env t2) let eq_typs env ts = List.for_all (fun (t1, t2) -> eq_typ env t1 t2) ts let cast e t t' = { e with v = App (Cast (Some t) t') [e] } let try_cast_integer env et to : ML (option expr) = let e, from = et in let i_to = typ_is_integral env to in let i_from = typ_is_integral env from in if i_from && i_to then let i_from = typ_as_integer_type (unfold_typ_abbrev_and_enum env from) in let i_to = typ_as_integer_type (unfold_typ_abbrev_and_enum env to) in if i_from = i_to then Some e else if integer_type_leq i_from i_to then Some (cast e i_from i_to) else None else None let _or_ b1 b2 = b1 || b2 let _and_ b1 b2 = b1 && b2 let try_retype_arith_exprs (env:env) e1 e2 rng : ML (option (expr & expr & typ))= let e1, t1 = e1 in let e2, t2 = e2 in let fail #a i : ML a = raise (Error (Printf.sprintf "(%d) Failed to retype exprs (%s : %s) and (%s : %s)" i (print_expr e1) (print_typ t1) (print_expr e2) (print_typ t2))) in try let t1, t2 = unfold_typ_abbrev_and_enum env t1, unfold_typ_abbrev_and_enum env t2 in if not (typ_is_integral env t1 `_and_` typ_is_integral env t2) then fail 1; let tt1 = typ_as_integer_type t1 in let tt2 = typ_as_integer_type t2 in let cast e t t' = { e with v = App (Cast (Some t) t') [e] } in let e1, e2, t = if integer_type_leq tt1 tt2 then cast e1 tt1 tt2, e2, t2 else if integer_type_leq tt2 tt1 then e1, cast e2 tt2 tt1, t1 else fail 0 in // FStar.IO.print_string // (Printf.sprintf "Retyped to (%s, %s, %s)\n" // (print_expr e1) // (print_expr e2) // (print_typ t)); Some (e1, e2, t) with | Error msg -> FStar.IO.print_string msg; None | _ -> None (* * Add output type to the environment * * TODO: check_shadow *) let add_output_type (ge:global_env) (i:ident) (d:decl{OutputType? d.d_decl.v}) : ML unit = let insert i = H.insert ge.ge_out_t i d in insert i.v; let td_abbrev = (OutputType?._0 d.d_decl.v).out_typ_names.typedef_abbrev in insert td_abbrev.v (* * Add extern type to the environment * * TODO: check shadow *) let add_extern_type (ge:global_env) (i:ident) (d:decl{ExternType? d.d_decl.v}) : ML unit = let insert i = H.insert ge.ge_extern_t i d in insert i.v; let td_abbrev = (ExternType?._0 d.d_decl.v).typedef_abbrev in insert td_abbrev.v (* * Add extern function to the environment * * TODO: check shadow *) let add_extern_fn (ge:global_env) (i:ident) (d:decl{ExternFn? d.d_decl.v}) : ML unit = H.insert ge.ge_extern_fn i.v d let lookup_output_type (ge:global_env) (i:ident) : ML out_typ = match H.try_find ge.ge_out_t i.v with | Some ({d_decl={v=OutputType out_t}}) -> out_t | _ -> error (Printf.sprintf "Cannot find output type %s" (ident_to_string i)) i.range (* * Returns the type of the field, with optional bitwidth if the field is a bitfield *) let lookup_output_type_field (ge:global_env) (i f:ident) : ML (typ & option int) = let out_t = lookup_output_type ge i in let rec find (flds:list out_field) : (option (typ & option int)) = match flds with | [] -> None | (Out_field_named f' t n)::tl -> if eq_idents f f' then Some (t, n) else find tl | (Out_field_anon l _)::tl -> (match find l with | None -> find tl | Some t -> Some t) in match find out_t.out_typ_fields with | Some t -> t | None -> error (Printf.sprintf "Cannot find output field %s:%s" (ident_to_string i) (ident_to_string f)) f.range let lookup_extern_type (ge:global_env) (i:ident) : ML unit = match H.try_find ge.ge_extern_t i.v with | Some ({d_decl={v=ExternType _}}) -> () | _ -> error (Printf.sprintf "Cannot find declaration for extern type %s" (ident_to_string i)) i.range let lookup_extern_fn (ge:global_env) (f:ident) : ML (typ & list param) = match H.try_find ge.ge_extern_fn f.v with | Some ({d_decl={v=ExternFn _ ret ps}}) -> ret, ps | _ -> error (Printf.sprintf "Cannot find declaration for extern function %s" (ident_to_string f)) f.range
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val check_output_type (ge: global_env) (t: typ) : ML ident
[]
Binding.check_output_type
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
ge: GlobalEnv.global_env -> t: Ast.typ -> FStar.All.ML Ast.ident
{ "end_col": 15, "end_line": 513, "start_col": 58, "start_line": 508 }
FStar.All.ML
val lookup_macro_name (e: env) (i: ident) : ML macro_signature
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range
val lookup_macro_name (e: env) (i: ident) : ML macro_signature let lookup_macro_name (e: env) (i: ident) : ML macro_signature =
true
null
false
match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "Binding.env", "Ast.ident", "Ast.decl", "GlobalEnv.macro_signature", "Ast.either", "Ast.typ", "FStar.Pervasives.Native.tuple2", "GlobalEnv.decl_attributes", "Ast.error", "FStar.Printf.sprintf", "Ast.ident_to_string", "Ast.__proj__Mkwith_meta_t__item__range", "Ast.ident'", "Binding.lookup" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lookup_macro_name (e: env) (i: ident) : ML macro_signature
[]
Binding.lookup_macro_name
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
e: Binding.env -> i: Ast.ident -> FStar.All.ML GlobalEnv.macro_signature
{ "end_col": 87, "end_line": 189, "start_col": 2, "start_line": 187 }
FStar.All.ML
val global_env_of_env (e:env) : ML global_env
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let global_env_of_env e = e.globals
val global_env_of_env (e:env) : ML global_env let global_env_of_env e =
true
null
false
e.globals
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "Binding.env", "Binding.__proj__Mkenv__item__globals", "GlobalEnv.global_env" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g }
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val global_env_of_env (e:env) : ML global_env
[]
Binding.global_env_of_env
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
e: Binding.env -> FStar.All.ML GlobalEnv.global_env
{ "end_col": 35, "end_line": 68, "start_col": 26, "start_line": 68 }
Prims.Tot
val typedef_names (d: decl) : option typedef_names
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None
val typedef_names (d: decl) : option typedef_names let typedef_names (d: decl) : option typedef_names =
false
null
false
match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "total" ]
[ "Ast.decl", "Ast.__proj__Mkwith_meta_t__item__v", "Ast.decl'", "Ast.__proj__Mkdecl__item__d_decl", "Ast.typedef_names", "Prims.list", "Ast.param", "FStar.Pervasives.Native.option", "Ast.expr", "Ast.record", "FStar.Pervasives.Native.Some", "Ast.switch_case", "FStar.Pervasives.Native.None" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> ()
false
true
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val typedef_names (d: decl) : option typedef_names
[]
Binding.typedef_names
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
d: Ast.decl -> FStar.Pervasives.Native.option Ast.typedef_names
{ "end_col": 13, "end_line": 93, "start_col": 2, "start_line": 90 }
FStar.All.ALL
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let is_enum (e:env) (t:typ) = match t.v with | Type_app i KindSpec [] -> Some? (try_lookup_enum_cases e i) | _ -> false
let is_enum (e: env) (t: typ) =
true
null
false
match t.v with | Type_app i KindSpec [] -> Some? (try_lookup_enum_cases e i) | _ -> false
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[]
[ "Binding.env", "Ast.typ", "Ast.__proj__Mkwith_meta_t__item__v", "Ast.typ'", "Ast.ident", "FStar.Pervasives.Native.uu___is_Some", "FStar.Pervasives.Native.tuple2", "Prims.list", "Prims.bool", "FStar.Pervasives.Native.option", "Binding.try_lookup_enum_cases" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range let lookup_macro_definition (e:env) (i:ident) = try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None let try_lookup_enum_cases (e:env) (i:ident) : ML (option (list ident & typ)) = match lookup e i with | Inr ({d_decl={v=Enum t _ tags}}, _) -> Some (Desugar.check_desugared_enum_cases tags, t) | _ -> None let lookup_enum_cases (e:env) (i:ident) : ML (list ident & typ) = match try_lookup_enum_cases e i with | Some (tags, t) -> tags, t | _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val is_enum : e: Binding.env -> t: Ast.typ -> FStar.All.ALL Prims.bool
[]
Binding.is_enum
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
e: Binding.env -> t: Ast.typ -> FStar.All.ALL Prims.bool
{ "end_col": 14, "end_line": 215, "start_col": 2, "start_line": 212 }
FStar.All.ML
val unfold_typ_abbrev_and_enum (env: env) (t: typ) : ML typ
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec unfold_typ_abbrev_and_enum (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match lookup env hd with | Inr (d, _) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_and_enum env t | Enum t _ _ -> unfold_typ_abbrev_and_enum env t | _ -> t end | _ -> t end | _ -> t
val unfold_typ_abbrev_and_enum (env: env) (t: typ) : ML typ let rec unfold_typ_abbrev_and_enum (env: env) (t: typ) : ML typ =
true
null
false
match t.v with | Type_app hd _ [] -> (match lookup env hd with | Inr (d, _) -> (match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_and_enum env t | Enum t _ _ -> unfold_typ_abbrev_and_enum env t | _ -> t) | _ -> t) | _ -> t
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "Binding.env", "Ast.typ", "Ast.__proj__Mkwith_meta_t__item__v", "Ast.typ'", "Ast.ident", "Ast.t_kind", "Ast.decl", "Ast.either", "GlobalEnv.decl_attributes", "GlobalEnv.macro_signature", "Ast.decl'", "Ast.__proj__Mkdecl__item__d_decl", "Binding.unfold_typ_abbrev_and_enum", "Prims.list", "Ast.enum_case", "FStar.Pervasives.Native.tuple2", "Binding.lookup" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range let lookup_macro_definition (e:env) (i:ident) = try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None let try_lookup_enum_cases (e:env) (i:ident) : ML (option (list ident & typ)) = match lookup e i with | Inr ({d_decl={v=Enum t _ tags}}, _) -> Some (Desugar.check_desugared_enum_cases tags, t) | _ -> None let lookup_enum_cases (e:env) (i:ident) : ML (list ident & typ) = match try_lookup_enum_cases e i with | Some (tags, t) -> tags, t | _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range let is_enum (e:env) (t:typ) = match t.v with | Type_app i KindSpec [] -> Some? (try_lookup_enum_cases e i) | _ -> false let is_used (e:env) (i:ident) : ML bool = match H.try_find e.locals i.v with | Some (_, t, b) -> b | _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range let type_of_integer_type = function | UInt8 -> tuint8 | UInt16 -> tuint16 | UInt32 -> tuint32 | UInt64 -> tuint64 let check_integer_bounds t i = match t with | UInt8 -> FStar.UInt.fits i 8 | UInt16 -> FStar.UInt.fits i 16 | UInt32 -> FStar.UInt.fits i 32 | UInt64 -> FStar.UInt.fits i 64 let type_of_constant rng (c:constant) : ML typ = match c with | Unit -> tunit | Int tag i -> if check_integer_bounds tag i then type_of_integer_type tag else error (Printf.sprintf "Constant %d is too large for its type %s" i (Ast.print_integer_type tag)) rng | XInt tag _ -> //bounds checked by the syntax type_of_integer_type tag | Bool _ -> tbool let parser_may_fail (env:env) (t:typ) : ML bool = match t.v with | Pointer _ -> true | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> attrs.may_fail | _ -> false let typ_is_integral env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> Some? attrs.integral | _ -> false let tag_of_integral_typ env (t:typ) : ML (option _) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral | _ -> None let tag_and_bit_order_of_integral_typ env (t:typ) : ML (tag_and_bit_order: (option integer_type & option bitfield_bit_order) { Some? (snd tag_and_bit_order) ==> Some? (fst tag_and_bit_order) }) = match t.v with | Pointer _ -> None, None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral, attrs.bit_order | _ -> None, None let has_reader (env:global_env) (id:ident) : ML bool = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.has_reader | _ -> false let parser_kind_nz (env:global_env) (id:ident) : ML (option bool) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.parser_kind_nz | _ -> None let parser_weak_kind (env:global_env) (id:ident) : ML (option _) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> Some attrs.parser_weak_kind | _ -> None let typ_weak_kind env (t:typ) : ML (option weak_kind) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> parser_weak_kind env.globals hd let typ_has_reader env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> has_reader env.globals hd let rec unfold_typ_abbrev_only (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match try_lookup env hd with | Some (Inr (d, _)) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_only env t | _ -> t end | _ -> t end | _ -> t let update_typ_abbrev (env:env) (i:ident) (t:typ) : ML unit = match H.try_find env.globals.ge_h i.v with | Some (d, ms) -> let d_decl = match d.d_decl.v with | TypeAbbrev _ _ -> {d.d_decl with v = TypeAbbrev t i } | _ -> failwith "Expected a type abbreviation" in let d = {d with d_decl = d_decl } in let entry = (d, ms) in H.insert env.globals.ge_h i.v entry | _ -> failwith "Type abbreviation not found"
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val unfold_typ_abbrev_and_enum (env: env) (t: typ) : ML typ
[ "recursion" ]
Binding.unfold_typ_abbrev_and_enum
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
env: Binding.env -> t: Ast.typ -> FStar.All.ML Ast.typ
{ "end_col": 10, "end_line": 350, "start_col": 2, "start_line": 337 }
Prims.Tot
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let _and_ b1 b2 = b1 && b2
let _and_ b1 b2 =
false
null
false
b1 && b2
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "total" ]
[ "Prims.bool", "Prims.op_AmpAmp" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range let lookup_macro_definition (e:env) (i:ident) = try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None let try_lookup_enum_cases (e:env) (i:ident) : ML (option (list ident & typ)) = match lookup e i with | Inr ({d_decl={v=Enum t _ tags}}, _) -> Some (Desugar.check_desugared_enum_cases tags, t) | _ -> None let lookup_enum_cases (e:env) (i:ident) : ML (list ident & typ) = match try_lookup_enum_cases e i with | Some (tags, t) -> tags, t | _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range let is_enum (e:env) (t:typ) = match t.v with | Type_app i KindSpec [] -> Some? (try_lookup_enum_cases e i) | _ -> false let is_used (e:env) (i:ident) : ML bool = match H.try_find e.locals i.v with | Some (_, t, b) -> b | _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range let type_of_integer_type = function | UInt8 -> tuint8 | UInt16 -> tuint16 | UInt32 -> tuint32 | UInt64 -> tuint64 let check_integer_bounds t i = match t with | UInt8 -> FStar.UInt.fits i 8 | UInt16 -> FStar.UInt.fits i 16 | UInt32 -> FStar.UInt.fits i 32 | UInt64 -> FStar.UInt.fits i 64 let type_of_constant rng (c:constant) : ML typ = match c with | Unit -> tunit | Int tag i -> if check_integer_bounds tag i then type_of_integer_type tag else error (Printf.sprintf "Constant %d is too large for its type %s" i (Ast.print_integer_type tag)) rng | XInt tag _ -> //bounds checked by the syntax type_of_integer_type tag | Bool _ -> tbool let parser_may_fail (env:env) (t:typ) : ML bool = match t.v with | Pointer _ -> true | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> attrs.may_fail | _ -> false let typ_is_integral env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> Some? attrs.integral | _ -> false let tag_of_integral_typ env (t:typ) : ML (option _) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral | _ -> None let tag_and_bit_order_of_integral_typ env (t:typ) : ML (tag_and_bit_order: (option integer_type & option bitfield_bit_order) { Some? (snd tag_and_bit_order) ==> Some? (fst tag_and_bit_order) }) = match t.v with | Pointer _ -> None, None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral, attrs.bit_order | _ -> None, None let has_reader (env:global_env) (id:ident) : ML bool = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.has_reader | _ -> false let parser_kind_nz (env:global_env) (id:ident) : ML (option bool) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.parser_kind_nz | _ -> None let parser_weak_kind (env:global_env) (id:ident) : ML (option _) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> Some attrs.parser_weak_kind | _ -> None let typ_weak_kind env (t:typ) : ML (option weak_kind) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> parser_weak_kind env.globals hd let typ_has_reader env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> has_reader env.globals hd let rec unfold_typ_abbrev_only (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match try_lookup env hd with | Some (Inr (d, _)) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_only env t | _ -> t end | _ -> t end | _ -> t let update_typ_abbrev (env:env) (i:ident) (t:typ) : ML unit = match H.try_find env.globals.ge_h i.v with | Some (d, ms) -> let d_decl = match d.d_decl.v with | TypeAbbrev _ _ -> {d.d_decl with v = TypeAbbrev t i } | _ -> failwith "Expected a type abbreviation" in let d = {d with d_decl = d_decl } in let entry = (d, ms) in H.insert env.globals.ge_h i.v entry | _ -> failwith "Type abbreviation not found" let rec unfold_typ_abbrev_and_enum (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match lookup env hd with | Inr (d, _) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_and_enum env t | Enum t _ _ -> unfold_typ_abbrev_and_enum env t | _ -> t end | _ -> t end | _ -> t let size_of_integral_typ (env:env) (t:typ) r : ML int = let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_of_integral_typ env t with | None -> failwith "Impossible" | Some UInt8 -> 1 | Some UInt16 -> 2 | Some UInt32 -> 4 | Some UInt64 -> 8 let bit_order_of_integral_typ (env:env) (t:typ) r : ML bitfield_bit_order = let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_and_bit_order_of_integral_typ env t with | _, None -> failwith "Impossible" | _, Some order -> order let eq_typ env t1 t2 = if Ast.eq_typ t1 t2 then true else Ast.eq_typ (unfold_typ_abbrev_and_enum env t1) (unfold_typ_abbrev_and_enum env t2) let eq_typs env ts = List.for_all (fun (t1, t2) -> eq_typ env t1 t2) ts let cast e t t' = { e with v = App (Cast (Some t) t') [e] } let try_cast_integer env et to : ML (option expr) = let e, from = et in let i_to = typ_is_integral env to in let i_from = typ_is_integral env from in if i_from && i_to then let i_from = typ_as_integer_type (unfold_typ_abbrev_and_enum env from) in let i_to = typ_as_integer_type (unfold_typ_abbrev_and_enum env to) in if i_from = i_to then Some e else if integer_type_leq i_from i_to then Some (cast e i_from i_to) else None else None
false
true
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val _and_ : b1: Prims.bool -> b2: Prims.bool -> Prims.bool
[]
Binding._and_
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
b1: Prims.bool -> b2: Prims.bool -> Prims.bool
{ "end_col": 26, "end_line": 402, "start_col": 18, "start_line": 402 }
FStar.All.ML
val try_lookup_enum_cases (e: env) (i: ident) : ML (option (list ident & typ))
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let try_lookup_enum_cases (e:env) (i:ident) : ML (option (list ident & typ)) = match lookup e i with | Inr ({d_decl={v=Enum t _ tags}}, _) -> Some (Desugar.check_desugared_enum_cases tags, t) | _ -> None
val try_lookup_enum_cases (e: env) (i: ident) : ML (option (list ident & typ)) let try_lookup_enum_cases (e: env) (i: ident) : ML (option (list ident & typ)) =
true
null
false
match lookup e i with | Inr ({ d_decl = { v = Enum t _ tags } }, _) -> Some (Desugar.check_desugared_enum_cases tags, t) | _ -> None
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "Binding.env", "Ast.ident", "Ast.typ", "Prims.list", "Ast.enum_case", "Ast.range", "Ast.comments", "Prims.bool", "Ast.either", "GlobalEnv.decl_attributes", "GlobalEnv.macro_signature", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.Mktuple2", "Desugar.check_desugared_enum_cases", "Ast.decl", "FStar.Pervasives.Native.None", "Binding.lookup" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range let lookup_macro_definition (e:env) (i:ident) = try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None let try_lookup_enum_cases (e:env) (i:ident)
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val try_lookup_enum_cases (e: env) (i: ident) : ML (option (list ident & typ))
[]
Binding.try_lookup_enum_cases
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
e: Binding.env -> i: Ast.ident -> FStar.All.ML (FStar.Pervasives.Native.option (Prims.list Ast.ident * Ast.typ))
{ "end_col": 15, "end_line": 203, "start_col": 4, "start_line": 200 }
Prims.Tot
val env_of_global_env: global_env -> env
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g }
val env_of_global_env: global_env -> env let env_of_global_env: global_env -> env =
false
null
false
let locals = H.create 1 in fun g -> { this = None; locals = locals; globals = g }
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "total" ]
[ "GlobalEnv.global_env", "Binding.Mkenv", "FStar.Pervasives.Native.None", "Ast.ident", "Binding.env", "Hashtable.t", "Ast.ident'", "FStar.Pervasives.Native.tuple3", "Ast.typ", "Prims.bool", "Hashtable.create" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env
false
true
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val env_of_global_env: global_env -> env
[]
Binding.env_of_global_env
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
_: GlobalEnv.global_env -> Binding.env
{ "end_col": 49, "end_line": 66, "start_col": 3, "start_line": 65 }
Prims.Tot
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let local_env = H.t ident' (ident' & typ & bool)
let local_env =
false
null
false
H.t ident' (ident' & typ & bool)
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "total" ]
[ "Hashtable.t", "Ast.ident'", "FStar.Pervasives.Native.tuple3", "Ast.typ", "Prims.bool" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field ///
false
true
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val local_env : Type0
[]
Binding.local_env
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
Type0
{ "end_col": 48, "end_line": 37, "start_col": 16, "start_line": 37 }
FStar.All.ML
val has_reader (_:global_env) (_:ident) : ML bool
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let has_reader (env:global_env) (id:ident) : ML bool = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.has_reader | _ -> false
val has_reader (_:global_env) (_:ident) : ML bool let has_reader (env: global_env) (id: ident) : ML bool =
true
null
false
match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.has_reader | _ -> false
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "GlobalEnv.global_env", "Ast.ident", "Ast.decl", "GlobalEnv.decl_attributes", "GlobalEnv.__proj__Mkdecl_attributes__item__has_reader", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "Ast.either", "GlobalEnv.macro_signature", "Prims.bool", "Hashtable.try_find", "Ast.ident'", "GlobalEnv.__proj__Mkglobal_env__item__ge_h", "Ast.__proj__Mkwith_meta_t__item__v" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range let lookup_macro_definition (e:env) (i:ident) = try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None let try_lookup_enum_cases (e:env) (i:ident) : ML (option (list ident & typ)) = match lookup e i with | Inr ({d_decl={v=Enum t _ tags}}, _) -> Some (Desugar.check_desugared_enum_cases tags, t) | _ -> None let lookup_enum_cases (e:env) (i:ident) : ML (list ident & typ) = match try_lookup_enum_cases e i with | Some (tags, t) -> tags, t | _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range let is_enum (e:env) (t:typ) = match t.v with | Type_app i KindSpec [] -> Some? (try_lookup_enum_cases e i) | _ -> false let is_used (e:env) (i:ident) : ML bool = match H.try_find e.locals i.v with | Some (_, t, b) -> b | _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range let type_of_integer_type = function | UInt8 -> tuint8 | UInt16 -> tuint16 | UInt32 -> tuint32 | UInt64 -> tuint64 let check_integer_bounds t i = match t with | UInt8 -> FStar.UInt.fits i 8 | UInt16 -> FStar.UInt.fits i 16 | UInt32 -> FStar.UInt.fits i 32 | UInt64 -> FStar.UInt.fits i 64 let type_of_constant rng (c:constant) : ML typ = match c with | Unit -> tunit | Int tag i -> if check_integer_bounds tag i then type_of_integer_type tag else error (Printf.sprintf "Constant %d is too large for its type %s" i (Ast.print_integer_type tag)) rng | XInt tag _ -> //bounds checked by the syntax type_of_integer_type tag | Bool _ -> tbool let parser_may_fail (env:env) (t:typ) : ML bool = match t.v with | Pointer _ -> true | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> attrs.may_fail | _ -> false let typ_is_integral env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> Some? attrs.integral | _ -> false let tag_of_integral_typ env (t:typ) : ML (option _) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral | _ -> None let tag_and_bit_order_of_integral_typ env (t:typ) : ML (tag_and_bit_order: (option integer_type & option bitfield_bit_order) { Some? (snd tag_and_bit_order) ==> Some? (fst tag_and_bit_order) }) = match t.v with | Pointer _ -> None, None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral, attrs.bit_order | _ -> None, None
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val has_reader (_:global_env) (_:ident) : ML bool
[]
Binding.has_reader
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
env: GlobalEnv.global_env -> id: Ast.ident -> FStar.All.ML Prims.bool
{ "end_col": 14, "end_line": 282, "start_col": 2, "start_line": 280 }
FStar.All.ML
val lookup_extern_fn (ge: global_env) (f: ident) : ML (typ & list param)
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lookup_extern_fn (ge:global_env) (f:ident) : ML (typ & list param) = match H.try_find ge.ge_extern_fn f.v with | Some ({d_decl={v=ExternFn _ ret ps}}) -> ret, ps | _ -> error (Printf.sprintf "Cannot find declaration for extern function %s" (ident_to_string f)) f.range
val lookup_extern_fn (ge: global_env) (f: ident) : ML (typ & list param) let lookup_extern_fn (ge: global_env) (f: ident) : ML (typ & list param) =
true
null
false
match H.try_find ge.ge_extern_fn f.v with | Some { d_decl = { v = ExternFn _ ret ps } } -> ret, ps | _ -> error (Printf.sprintf "Cannot find declaration for extern function %s" (ident_to_string f)) f.range
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "GlobalEnv.global_env", "Ast.ident", "Ast.typ", "Prims.list", "Ast.param", "Ast.range", "Ast.comments", "Prims.bool", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.option", "Ast.decl", "Ast.error", "FStar.Printf.sprintf", "Ast.ident_to_string", "Ast.__proj__Mkwith_meta_t__item__range", "Ast.ident'", "Hashtable.try_find", "GlobalEnv.__proj__Mkglobal_env__item__ge_extern_fn", "Ast.__proj__Mkwith_meta_t__item__v" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range let lookup_macro_definition (e:env) (i:ident) = try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None let try_lookup_enum_cases (e:env) (i:ident) : ML (option (list ident & typ)) = match lookup e i with | Inr ({d_decl={v=Enum t _ tags}}, _) -> Some (Desugar.check_desugared_enum_cases tags, t) | _ -> None let lookup_enum_cases (e:env) (i:ident) : ML (list ident & typ) = match try_lookup_enum_cases e i with | Some (tags, t) -> tags, t | _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range let is_enum (e:env) (t:typ) = match t.v with | Type_app i KindSpec [] -> Some? (try_lookup_enum_cases e i) | _ -> false let is_used (e:env) (i:ident) : ML bool = match H.try_find e.locals i.v with | Some (_, t, b) -> b | _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range let type_of_integer_type = function | UInt8 -> tuint8 | UInt16 -> tuint16 | UInt32 -> tuint32 | UInt64 -> tuint64 let check_integer_bounds t i = match t with | UInt8 -> FStar.UInt.fits i 8 | UInt16 -> FStar.UInt.fits i 16 | UInt32 -> FStar.UInt.fits i 32 | UInt64 -> FStar.UInt.fits i 64 let type_of_constant rng (c:constant) : ML typ = match c with | Unit -> tunit | Int tag i -> if check_integer_bounds tag i then type_of_integer_type tag else error (Printf.sprintf "Constant %d is too large for its type %s" i (Ast.print_integer_type tag)) rng | XInt tag _ -> //bounds checked by the syntax type_of_integer_type tag | Bool _ -> tbool let parser_may_fail (env:env) (t:typ) : ML bool = match t.v with | Pointer _ -> true | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> attrs.may_fail | _ -> false let typ_is_integral env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> Some? attrs.integral | _ -> false let tag_of_integral_typ env (t:typ) : ML (option _) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral | _ -> None let tag_and_bit_order_of_integral_typ env (t:typ) : ML (tag_and_bit_order: (option integer_type & option bitfield_bit_order) { Some? (snd tag_and_bit_order) ==> Some? (fst tag_and_bit_order) }) = match t.v with | Pointer _ -> None, None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral, attrs.bit_order | _ -> None, None let has_reader (env:global_env) (id:ident) : ML bool = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.has_reader | _ -> false let parser_kind_nz (env:global_env) (id:ident) : ML (option bool) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.parser_kind_nz | _ -> None let parser_weak_kind (env:global_env) (id:ident) : ML (option _) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> Some attrs.parser_weak_kind | _ -> None let typ_weak_kind env (t:typ) : ML (option weak_kind) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> parser_weak_kind env.globals hd let typ_has_reader env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> has_reader env.globals hd let rec unfold_typ_abbrev_only (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match try_lookup env hd with | Some (Inr (d, _)) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_only env t | _ -> t end | _ -> t end | _ -> t let update_typ_abbrev (env:env) (i:ident) (t:typ) : ML unit = match H.try_find env.globals.ge_h i.v with | Some (d, ms) -> let d_decl = match d.d_decl.v with | TypeAbbrev _ _ -> {d.d_decl with v = TypeAbbrev t i } | _ -> failwith "Expected a type abbreviation" in let d = {d with d_decl = d_decl } in let entry = (d, ms) in H.insert env.globals.ge_h i.v entry | _ -> failwith "Type abbreviation not found" let rec unfold_typ_abbrev_and_enum (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match lookup env hd with | Inr (d, _) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_and_enum env t | Enum t _ _ -> unfold_typ_abbrev_and_enum env t | _ -> t end | _ -> t end | _ -> t let size_of_integral_typ (env:env) (t:typ) r : ML int = let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_of_integral_typ env t with | None -> failwith "Impossible" | Some UInt8 -> 1 | Some UInt16 -> 2 | Some UInt32 -> 4 | Some UInt64 -> 8 let bit_order_of_integral_typ (env:env) (t:typ) r : ML bitfield_bit_order = let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_and_bit_order_of_integral_typ env t with | _, None -> failwith "Impossible" | _, Some order -> order let eq_typ env t1 t2 = if Ast.eq_typ t1 t2 then true else Ast.eq_typ (unfold_typ_abbrev_and_enum env t1) (unfold_typ_abbrev_and_enum env t2) let eq_typs env ts = List.for_all (fun (t1, t2) -> eq_typ env t1 t2) ts let cast e t t' = { e with v = App (Cast (Some t) t') [e] } let try_cast_integer env et to : ML (option expr) = let e, from = et in let i_to = typ_is_integral env to in let i_from = typ_is_integral env from in if i_from && i_to then let i_from = typ_as_integer_type (unfold_typ_abbrev_and_enum env from) in let i_to = typ_as_integer_type (unfold_typ_abbrev_and_enum env to) in if i_from = i_to then Some e else if integer_type_leq i_from i_to then Some (cast e i_from i_to) else None else None let _or_ b1 b2 = b1 || b2 let _and_ b1 b2 = b1 && b2 let try_retype_arith_exprs (env:env) e1 e2 rng : ML (option (expr & expr & typ))= let e1, t1 = e1 in let e2, t2 = e2 in let fail #a i : ML a = raise (Error (Printf.sprintf "(%d) Failed to retype exprs (%s : %s) and (%s : %s)" i (print_expr e1) (print_typ t1) (print_expr e2) (print_typ t2))) in try let t1, t2 = unfold_typ_abbrev_and_enum env t1, unfold_typ_abbrev_and_enum env t2 in if not (typ_is_integral env t1 `_and_` typ_is_integral env t2) then fail 1; let tt1 = typ_as_integer_type t1 in let tt2 = typ_as_integer_type t2 in let cast e t t' = { e with v = App (Cast (Some t) t') [e] } in let e1, e2, t = if integer_type_leq tt1 tt2 then cast e1 tt1 tt2, e2, t2 else if integer_type_leq tt2 tt1 then e1, cast e2 tt2 tt1, t1 else fail 0 in // FStar.IO.print_string // (Printf.sprintf "Retyped to (%s, %s, %s)\n" // (print_expr e1) // (print_expr e2) // (print_typ t)); Some (e1, e2, t) with | Error msg -> FStar.IO.print_string msg; None | _ -> None (* * Add output type to the environment * * TODO: check_shadow *) let add_output_type (ge:global_env) (i:ident) (d:decl{OutputType? d.d_decl.v}) : ML unit = let insert i = H.insert ge.ge_out_t i d in insert i.v; let td_abbrev = (OutputType?._0 d.d_decl.v).out_typ_names.typedef_abbrev in insert td_abbrev.v (* * Add extern type to the environment * * TODO: check shadow *) let add_extern_type (ge:global_env) (i:ident) (d:decl{ExternType? d.d_decl.v}) : ML unit = let insert i = H.insert ge.ge_extern_t i d in insert i.v; let td_abbrev = (ExternType?._0 d.d_decl.v).typedef_abbrev in insert td_abbrev.v (* * Add extern function to the environment * * TODO: check shadow *) let add_extern_fn (ge:global_env) (i:ident) (d:decl{ExternFn? d.d_decl.v}) : ML unit = H.insert ge.ge_extern_fn i.v d let lookup_output_type (ge:global_env) (i:ident) : ML out_typ = match H.try_find ge.ge_out_t i.v with | Some ({d_decl={v=OutputType out_t}}) -> out_t | _ -> error (Printf.sprintf "Cannot find output type %s" (ident_to_string i)) i.range (* * Returns the type of the field, with optional bitwidth if the field is a bitfield *) let lookup_output_type_field (ge:global_env) (i f:ident) : ML (typ & option int) = let out_t = lookup_output_type ge i in let rec find (flds:list out_field) : (option (typ & option int)) = match flds with | [] -> None | (Out_field_named f' t n)::tl -> if eq_idents f f' then Some (t, n) else find tl | (Out_field_anon l _)::tl -> (match find l with | None -> find tl | Some t -> Some t) in match find out_t.out_typ_fields with | Some t -> t | None -> error (Printf.sprintf "Cannot find output field %s:%s" (ident_to_string i) (ident_to_string f)) f.range let lookup_extern_type (ge:global_env) (i:ident) : ML unit = match H.try_find ge.ge_extern_t i.v with | Some ({d_decl={v=ExternType _}}) -> () | _ -> error (Printf.sprintf "Cannot find declaration for extern type %s" (ident_to_string i)) i.range
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lookup_extern_fn (ge: global_env) (f: ident) : ML (typ & list param)
[]
Binding.lookup_extern_fn
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
ge: GlobalEnv.global_env -> f: Ast.ident -> FStar.All.ML (Ast.typ * Prims.list Ast.param)
{ "end_col": 108, "end_line": 506, "start_col": 2, "start_line": 504 }
FStar.All.ML
val lookup_extern_type (ge: global_env) (i: ident) : ML unit
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lookup_extern_type (ge:global_env) (i:ident) : ML unit = match H.try_find ge.ge_extern_t i.v with | Some ({d_decl={v=ExternType _}}) -> () | _ -> error (Printf.sprintf "Cannot find declaration for extern type %s" (ident_to_string i)) i.range
val lookup_extern_type (ge: global_env) (i: ident) : ML unit let lookup_extern_type (ge: global_env) (i: ident) : ML unit =
true
null
false
match H.try_find ge.ge_extern_t i.v with | Some { d_decl = { v = ExternType _ } } -> () | _ -> error (Printf.sprintf "Cannot find declaration for extern type %s" (ident_to_string i)) i.range
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "GlobalEnv.global_env", "Ast.ident", "Ast.typedef_names", "Ast.range", "Ast.comments", "Prims.bool", "Prims.unit", "FStar.Pervasives.Native.option", "Ast.decl", "Ast.error", "FStar.Printf.sprintf", "Ast.ident_to_string", "Ast.__proj__Mkwith_meta_t__item__range", "Ast.ident'", "Hashtable.try_find", "GlobalEnv.__proj__Mkglobal_env__item__ge_extern_t", "Ast.__proj__Mkwith_meta_t__item__v" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range let lookup_macro_definition (e:env) (i:ident) = try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None let try_lookup_enum_cases (e:env) (i:ident) : ML (option (list ident & typ)) = match lookup e i with | Inr ({d_decl={v=Enum t _ tags}}, _) -> Some (Desugar.check_desugared_enum_cases tags, t) | _ -> None let lookup_enum_cases (e:env) (i:ident) : ML (list ident & typ) = match try_lookup_enum_cases e i with | Some (tags, t) -> tags, t | _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range let is_enum (e:env) (t:typ) = match t.v with | Type_app i KindSpec [] -> Some? (try_lookup_enum_cases e i) | _ -> false let is_used (e:env) (i:ident) : ML bool = match H.try_find e.locals i.v with | Some (_, t, b) -> b | _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range let type_of_integer_type = function | UInt8 -> tuint8 | UInt16 -> tuint16 | UInt32 -> tuint32 | UInt64 -> tuint64 let check_integer_bounds t i = match t with | UInt8 -> FStar.UInt.fits i 8 | UInt16 -> FStar.UInt.fits i 16 | UInt32 -> FStar.UInt.fits i 32 | UInt64 -> FStar.UInt.fits i 64 let type_of_constant rng (c:constant) : ML typ = match c with | Unit -> tunit | Int tag i -> if check_integer_bounds tag i then type_of_integer_type tag else error (Printf.sprintf "Constant %d is too large for its type %s" i (Ast.print_integer_type tag)) rng | XInt tag _ -> //bounds checked by the syntax type_of_integer_type tag | Bool _ -> tbool let parser_may_fail (env:env) (t:typ) : ML bool = match t.v with | Pointer _ -> true | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> attrs.may_fail | _ -> false let typ_is_integral env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> Some? attrs.integral | _ -> false let tag_of_integral_typ env (t:typ) : ML (option _) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral | _ -> None let tag_and_bit_order_of_integral_typ env (t:typ) : ML (tag_and_bit_order: (option integer_type & option bitfield_bit_order) { Some? (snd tag_and_bit_order) ==> Some? (fst tag_and_bit_order) }) = match t.v with | Pointer _ -> None, None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral, attrs.bit_order | _ -> None, None let has_reader (env:global_env) (id:ident) : ML bool = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.has_reader | _ -> false let parser_kind_nz (env:global_env) (id:ident) : ML (option bool) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.parser_kind_nz | _ -> None let parser_weak_kind (env:global_env) (id:ident) : ML (option _) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> Some attrs.parser_weak_kind | _ -> None let typ_weak_kind env (t:typ) : ML (option weak_kind) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> parser_weak_kind env.globals hd let typ_has_reader env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> has_reader env.globals hd let rec unfold_typ_abbrev_only (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match try_lookup env hd with | Some (Inr (d, _)) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_only env t | _ -> t end | _ -> t end | _ -> t let update_typ_abbrev (env:env) (i:ident) (t:typ) : ML unit = match H.try_find env.globals.ge_h i.v with | Some (d, ms) -> let d_decl = match d.d_decl.v with | TypeAbbrev _ _ -> {d.d_decl with v = TypeAbbrev t i } | _ -> failwith "Expected a type abbreviation" in let d = {d with d_decl = d_decl } in let entry = (d, ms) in H.insert env.globals.ge_h i.v entry | _ -> failwith "Type abbreviation not found" let rec unfold_typ_abbrev_and_enum (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match lookup env hd with | Inr (d, _) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_and_enum env t | Enum t _ _ -> unfold_typ_abbrev_and_enum env t | _ -> t end | _ -> t end | _ -> t let size_of_integral_typ (env:env) (t:typ) r : ML int = let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_of_integral_typ env t with | None -> failwith "Impossible" | Some UInt8 -> 1 | Some UInt16 -> 2 | Some UInt32 -> 4 | Some UInt64 -> 8 let bit_order_of_integral_typ (env:env) (t:typ) r : ML bitfield_bit_order = let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_and_bit_order_of_integral_typ env t with | _, None -> failwith "Impossible" | _, Some order -> order let eq_typ env t1 t2 = if Ast.eq_typ t1 t2 then true else Ast.eq_typ (unfold_typ_abbrev_and_enum env t1) (unfold_typ_abbrev_and_enum env t2) let eq_typs env ts = List.for_all (fun (t1, t2) -> eq_typ env t1 t2) ts let cast e t t' = { e with v = App (Cast (Some t) t') [e] } let try_cast_integer env et to : ML (option expr) = let e, from = et in let i_to = typ_is_integral env to in let i_from = typ_is_integral env from in if i_from && i_to then let i_from = typ_as_integer_type (unfold_typ_abbrev_and_enum env from) in let i_to = typ_as_integer_type (unfold_typ_abbrev_and_enum env to) in if i_from = i_to then Some e else if integer_type_leq i_from i_to then Some (cast e i_from i_to) else None else None let _or_ b1 b2 = b1 || b2 let _and_ b1 b2 = b1 && b2 let try_retype_arith_exprs (env:env) e1 e2 rng : ML (option (expr & expr & typ))= let e1, t1 = e1 in let e2, t2 = e2 in let fail #a i : ML a = raise (Error (Printf.sprintf "(%d) Failed to retype exprs (%s : %s) and (%s : %s)" i (print_expr e1) (print_typ t1) (print_expr e2) (print_typ t2))) in try let t1, t2 = unfold_typ_abbrev_and_enum env t1, unfold_typ_abbrev_and_enum env t2 in if not (typ_is_integral env t1 `_and_` typ_is_integral env t2) then fail 1; let tt1 = typ_as_integer_type t1 in let tt2 = typ_as_integer_type t2 in let cast e t t' = { e with v = App (Cast (Some t) t') [e] } in let e1, e2, t = if integer_type_leq tt1 tt2 then cast e1 tt1 tt2, e2, t2 else if integer_type_leq tt2 tt1 then e1, cast e2 tt2 tt1, t1 else fail 0 in // FStar.IO.print_string // (Printf.sprintf "Retyped to (%s, %s, %s)\n" // (print_expr e1) // (print_expr e2) // (print_typ t)); Some (e1, e2, t) with | Error msg -> FStar.IO.print_string msg; None | _ -> None (* * Add output type to the environment * * TODO: check_shadow *) let add_output_type (ge:global_env) (i:ident) (d:decl{OutputType? d.d_decl.v}) : ML unit = let insert i = H.insert ge.ge_out_t i d in insert i.v; let td_abbrev = (OutputType?._0 d.d_decl.v).out_typ_names.typedef_abbrev in insert td_abbrev.v (* * Add extern type to the environment * * TODO: check shadow *) let add_extern_type (ge:global_env) (i:ident) (d:decl{ExternType? d.d_decl.v}) : ML unit = let insert i = H.insert ge.ge_extern_t i d in insert i.v; let td_abbrev = (ExternType?._0 d.d_decl.v).typedef_abbrev in insert td_abbrev.v (* * Add extern function to the environment * * TODO: check shadow *) let add_extern_fn (ge:global_env) (i:ident) (d:decl{ExternFn? d.d_decl.v}) : ML unit = H.insert ge.ge_extern_fn i.v d let lookup_output_type (ge:global_env) (i:ident) : ML out_typ = match H.try_find ge.ge_out_t i.v with | Some ({d_decl={v=OutputType out_t}}) -> out_t | _ -> error (Printf.sprintf "Cannot find output type %s" (ident_to_string i)) i.range (* * Returns the type of the field, with optional bitwidth if the field is a bitfield *) let lookup_output_type_field (ge:global_env) (i f:ident) : ML (typ & option int) = let out_t = lookup_output_type ge i in let rec find (flds:list out_field) : (option (typ & option int)) = match flds with | [] -> None | (Out_field_named f' t n)::tl -> if eq_idents f f' then Some (t, n) else find tl | (Out_field_anon l _)::tl -> (match find l with | None -> find tl | Some t -> Some t) in match find out_t.out_typ_fields with | Some t -> t | None -> error (Printf.sprintf "Cannot find output field %s:%s" (ident_to_string i) (ident_to_string f)) f.range
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lookup_extern_type (ge: global_env) (i: ident) : ML unit
[]
Binding.lookup_extern_type
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
ge: GlobalEnv.global_env -> i: Ast.ident -> FStar.All.ML Prims.unit
{ "end_col": 104, "end_line": 501, "start_col": 2, "start_line": 499 }
FStar.All.ML
val parser_weak_kind (env:global_env) (id:ident) : ML (option weak_kind)
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parser_weak_kind (env:global_env) (id:ident) : ML (option _) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> Some attrs.parser_weak_kind | _ -> None
val parser_weak_kind (env:global_env) (id:ident) : ML (option weak_kind) let parser_weak_kind (env: global_env) (id: ident) : ML (option _) =
true
null
false
match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> Some attrs.parser_weak_kind | _ -> None
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "GlobalEnv.global_env", "Ast.ident", "Ast.decl", "GlobalEnv.decl_attributes", "FStar.Pervasives.Native.Some", "Ast.weak_kind", "GlobalEnv.__proj__Mkdecl_attributes__item__parser_weak_kind", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "Ast.either", "GlobalEnv.macro_signature", "FStar.Pervasives.Native.None", "Hashtable.try_find", "Ast.ident'", "GlobalEnv.__proj__Mkglobal_env__item__ge_h", "Ast.__proj__Mkwith_meta_t__item__v" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range let lookup_macro_definition (e:env) (i:ident) = try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None let try_lookup_enum_cases (e:env) (i:ident) : ML (option (list ident & typ)) = match lookup e i with | Inr ({d_decl={v=Enum t _ tags}}, _) -> Some (Desugar.check_desugared_enum_cases tags, t) | _ -> None let lookup_enum_cases (e:env) (i:ident) : ML (list ident & typ) = match try_lookup_enum_cases e i with | Some (tags, t) -> tags, t | _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range let is_enum (e:env) (t:typ) = match t.v with | Type_app i KindSpec [] -> Some? (try_lookup_enum_cases e i) | _ -> false let is_used (e:env) (i:ident) : ML bool = match H.try_find e.locals i.v with | Some (_, t, b) -> b | _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range let type_of_integer_type = function | UInt8 -> tuint8 | UInt16 -> tuint16 | UInt32 -> tuint32 | UInt64 -> tuint64 let check_integer_bounds t i = match t with | UInt8 -> FStar.UInt.fits i 8 | UInt16 -> FStar.UInt.fits i 16 | UInt32 -> FStar.UInt.fits i 32 | UInt64 -> FStar.UInt.fits i 64 let type_of_constant rng (c:constant) : ML typ = match c with | Unit -> tunit | Int tag i -> if check_integer_bounds tag i then type_of_integer_type tag else error (Printf.sprintf "Constant %d is too large for its type %s" i (Ast.print_integer_type tag)) rng | XInt tag _ -> //bounds checked by the syntax type_of_integer_type tag | Bool _ -> tbool let parser_may_fail (env:env) (t:typ) : ML bool = match t.v with | Pointer _ -> true | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> attrs.may_fail | _ -> false let typ_is_integral env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> Some? attrs.integral | _ -> false let tag_of_integral_typ env (t:typ) : ML (option _) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral | _ -> None let tag_and_bit_order_of_integral_typ env (t:typ) : ML (tag_and_bit_order: (option integer_type & option bitfield_bit_order) { Some? (snd tag_and_bit_order) ==> Some? (fst tag_and_bit_order) }) = match t.v with | Pointer _ -> None, None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral, attrs.bit_order | _ -> None, None let has_reader (env:global_env) (id:ident) : ML bool = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.has_reader | _ -> false let parser_kind_nz (env:global_env) (id:ident) : ML (option bool) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.parser_kind_nz | _ -> None
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parser_weak_kind (env:global_env) (id:ident) : ML (option weak_kind)
[]
Binding.parser_weak_kind
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
env: GlobalEnv.global_env -> id: Ast.ident -> FStar.All.ML (FStar.Pervasives.Native.option Ast.weak_kind)
{ "end_col": 13, "end_line": 292, "start_col": 2, "start_line": 290 }
FStar.All.ML
val remove_local (e: env) (i: ident) : ML unit
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> ()
val remove_local (e: env) (i: ident) : ML unit let remove_local (e: env) (i: ident) : ML unit =
true
null
false
match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> ()
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "Binding.env", "Ast.ident", "Ast.ident'", "Ast.typ", "Prims.bool", "Hashtable.remove", "FStar.Pervasives.Native.tuple3", "Binding.__proj__Mkenv__item__locals", "Prims.unit", "Ast.__proj__Mkwith_meta_t__item__v", "FStar.Pervasives.Native.option", "Hashtable.try_find" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val remove_local (e: env) (i: ident) : ML unit
[]
Binding.remove_local
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
e: Binding.env -> i: Ast.ident -> FStar.All.ML Prims.unit
{ "end_col": 11, "end_line": 164, "start_col": 2, "start_line": 160 }
Prims.Tot
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let type_of_integer_type = function | UInt8 -> tuint8 | UInt16 -> tuint16 | UInt32 -> tuint32 | UInt64 -> tuint64
let type_of_integer_type =
false
null
false
function | UInt8 -> tuint8 | UInt16 -> tuint16 | UInt32 -> tuint32 | UInt64 -> tuint64
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "total" ]
[ "Ast.integer_type", "Ast.tuint8", "Ast.tuint16", "Ast.tuint32", "Ast.tuint64", "Ast.with_meta_t", "Ast.typ'" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range let lookup_macro_definition (e:env) (i:ident) = try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None let try_lookup_enum_cases (e:env) (i:ident) : ML (option (list ident & typ)) = match lookup e i with | Inr ({d_decl={v=Enum t _ tags}}, _) -> Some (Desugar.check_desugared_enum_cases tags, t) | _ -> None let lookup_enum_cases (e:env) (i:ident) : ML (list ident & typ) = match try_lookup_enum_cases e i with | Some (tags, t) -> tags, t | _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range let is_enum (e:env) (t:typ) = match t.v with | Type_app i KindSpec [] -> Some? (try_lookup_enum_cases e i) | _ -> false let is_used (e:env) (i:ident) : ML bool = match H.try_find e.locals i.v with | Some (_, t, b) -> b | _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range
false
true
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val type_of_integer_type : _: Ast.integer_type -> Ast.with_meta_t Ast.typ'
[]
Binding.type_of_integer_type
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
_: Ast.integer_type -> Ast.with_meta_t Ast.typ'
{ "end_col": 21, "end_line": 226, "start_col": 27, "start_line": 222 }
FStar.All.ML
val resolve_record_case_output_extern_type_name (_:env) (_:ident): ML ident
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i))
val resolve_record_case_output_extern_type_name (_:env) (_:ident): ML ident let resolve_record_case_output_extern_type_name (env: env) (i: ident) =
true
null
false
match H.try_find (global_env_of_env env).ge_out_t i.v with | Some { d_decl = { v = OutputType { out_typ_names = names } } } -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some { d_decl = { v = ExternType td_names } } -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({ d_decl = { v = Record names _ _ _ } }, _) | Inr ({ d_decl = { v = CaseType names _ _ } }, _) -> names.typedef_name | _ -> i))
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "Binding.env", "Ast.ident", "Ast.typedef_names", "Prims.list", "Ast.out_field", "Prims.bool", "Ast.range", "Ast.comments", "Ast.__proj__Mktypedef_names__item__typedef_abbrev", "FStar.Pervasives.Native.option", "Ast.decl", "Ast.param", "Ast.expr", "Ast.record", "Ast.either", "GlobalEnv.decl_attributes", "GlobalEnv.macro_signature", "Ast.__proj__Mktypedef_names__item__typedef_name", "Ast.switch_case", "Ast.typ", "FStar.Pervasives.Native.tuple2", "Binding.lookup", "Hashtable.try_find", "Ast.ident'", "Ast.__proj__Mkwith_meta_t__item__v", "Hashtable.t", "GlobalEnv.__proj__Mkglobal_env__item__ge_extern_t", "GlobalEnv.global_env", "Binding.global_env_of_env", "GlobalEnv.__proj__Mkglobal_env__item__ge_out_t" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> ()
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val resolve_record_case_output_extern_type_name (_:env) (_:ident): ML ident
[]
Binding.resolve_record_case_output_extern_type_name
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
env: Binding.env -> i: Ast.ident -> FStar.All.ML Ast.ident
{ "end_col": 18, "end_line": 177, "start_col": 2, "start_line": 167 }
Prims.Tot
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let check_integer_bounds t i = match t with | UInt8 -> FStar.UInt.fits i 8 | UInt16 -> FStar.UInt.fits i 16 | UInt32 -> FStar.UInt.fits i 32 | UInt64 -> FStar.UInt.fits i 64
let check_integer_bounds t i =
false
null
false
match t with | UInt8 -> FStar.UInt.fits i 8 | UInt16 -> FStar.UInt.fits i 16 | UInt32 -> FStar.UInt.fits i 32 | UInt64 -> FStar.UInt.fits i 64
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "total" ]
[ "Ast.integer_type", "Prims.int", "FStar.UInt.fits", "Prims.bool" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range let lookup_macro_definition (e:env) (i:ident) = try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None let try_lookup_enum_cases (e:env) (i:ident) : ML (option (list ident & typ)) = match lookup e i with | Inr ({d_decl={v=Enum t _ tags}}, _) -> Some (Desugar.check_desugared_enum_cases tags, t) | _ -> None let lookup_enum_cases (e:env) (i:ident) : ML (list ident & typ) = match try_lookup_enum_cases e i with | Some (tags, t) -> tags, t | _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range let is_enum (e:env) (t:typ) = match t.v with | Type_app i KindSpec [] -> Some? (try_lookup_enum_cases e i) | _ -> false let is_used (e:env) (i:ident) : ML bool = match H.try_find e.locals i.v with | Some (_, t, b) -> b | _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range let type_of_integer_type = function | UInt8 -> tuint8 | UInt16 -> tuint16 | UInt32 -> tuint32 | UInt64 -> tuint64
false
true
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val check_integer_bounds : t: Ast.integer_type -> i: Prims.int -> Prims.bool
[]
Binding.check_integer_bounds
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
t: Ast.integer_type -> i: Prims.int -> Prims.bool
{ "end_col": 36, "end_line": 233, "start_col": 4, "start_line": 229 }
FStar.All.ML
val add_extern_fn (ge: global_env) (i: ident) (d: decl{ExternFn? d.d_decl.v}) : ML unit
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let add_extern_fn (ge:global_env) (i:ident) (d:decl{ExternFn? d.d_decl.v}) : ML unit = H.insert ge.ge_extern_fn i.v d
val add_extern_fn (ge: global_env) (i: ident) (d: decl{ExternFn? d.d_decl.v}) : ML unit let add_extern_fn (ge: global_env) (i: ident) (d: decl{ExternFn? d.d_decl.v}) : ML unit =
true
null
false
H.insert ge.ge_extern_fn i.v d
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "GlobalEnv.global_env", "Ast.ident", "Ast.decl", "Prims.b2t", "Ast.uu___is_ExternFn", "Ast.__proj__Mkwith_meta_t__item__v", "Ast.decl'", "Ast.__proj__Mkdecl__item__d_decl", "Hashtable.insert", "Ast.ident'", "GlobalEnv.__proj__Mkglobal_env__item__ge_extern_fn", "Prims.unit" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range let lookup_macro_definition (e:env) (i:ident) = try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None let try_lookup_enum_cases (e:env) (i:ident) : ML (option (list ident & typ)) = match lookup e i with | Inr ({d_decl={v=Enum t _ tags}}, _) -> Some (Desugar.check_desugared_enum_cases tags, t) | _ -> None let lookup_enum_cases (e:env) (i:ident) : ML (list ident & typ) = match try_lookup_enum_cases e i with | Some (tags, t) -> tags, t | _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range let is_enum (e:env) (t:typ) = match t.v with | Type_app i KindSpec [] -> Some? (try_lookup_enum_cases e i) | _ -> false let is_used (e:env) (i:ident) : ML bool = match H.try_find e.locals i.v with | Some (_, t, b) -> b | _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range let type_of_integer_type = function | UInt8 -> tuint8 | UInt16 -> tuint16 | UInt32 -> tuint32 | UInt64 -> tuint64 let check_integer_bounds t i = match t with | UInt8 -> FStar.UInt.fits i 8 | UInt16 -> FStar.UInt.fits i 16 | UInt32 -> FStar.UInt.fits i 32 | UInt64 -> FStar.UInt.fits i 64 let type_of_constant rng (c:constant) : ML typ = match c with | Unit -> tunit | Int tag i -> if check_integer_bounds tag i then type_of_integer_type tag else error (Printf.sprintf "Constant %d is too large for its type %s" i (Ast.print_integer_type tag)) rng | XInt tag _ -> //bounds checked by the syntax type_of_integer_type tag | Bool _ -> tbool let parser_may_fail (env:env) (t:typ) : ML bool = match t.v with | Pointer _ -> true | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> attrs.may_fail | _ -> false let typ_is_integral env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> Some? attrs.integral | _ -> false let tag_of_integral_typ env (t:typ) : ML (option _) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral | _ -> None let tag_and_bit_order_of_integral_typ env (t:typ) : ML (tag_and_bit_order: (option integer_type & option bitfield_bit_order) { Some? (snd tag_and_bit_order) ==> Some? (fst tag_and_bit_order) }) = match t.v with | Pointer _ -> None, None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral, attrs.bit_order | _ -> None, None let has_reader (env:global_env) (id:ident) : ML bool = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.has_reader | _ -> false let parser_kind_nz (env:global_env) (id:ident) : ML (option bool) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.parser_kind_nz | _ -> None let parser_weak_kind (env:global_env) (id:ident) : ML (option _) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> Some attrs.parser_weak_kind | _ -> None let typ_weak_kind env (t:typ) : ML (option weak_kind) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> parser_weak_kind env.globals hd let typ_has_reader env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> has_reader env.globals hd let rec unfold_typ_abbrev_only (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match try_lookup env hd with | Some (Inr (d, _)) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_only env t | _ -> t end | _ -> t end | _ -> t let update_typ_abbrev (env:env) (i:ident) (t:typ) : ML unit = match H.try_find env.globals.ge_h i.v with | Some (d, ms) -> let d_decl = match d.d_decl.v with | TypeAbbrev _ _ -> {d.d_decl with v = TypeAbbrev t i } | _ -> failwith "Expected a type abbreviation" in let d = {d with d_decl = d_decl } in let entry = (d, ms) in H.insert env.globals.ge_h i.v entry | _ -> failwith "Type abbreviation not found" let rec unfold_typ_abbrev_and_enum (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match lookup env hd with | Inr (d, _) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_and_enum env t | Enum t _ _ -> unfold_typ_abbrev_and_enum env t | _ -> t end | _ -> t end | _ -> t let size_of_integral_typ (env:env) (t:typ) r : ML int = let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_of_integral_typ env t with | None -> failwith "Impossible" | Some UInt8 -> 1 | Some UInt16 -> 2 | Some UInt32 -> 4 | Some UInt64 -> 8 let bit_order_of_integral_typ (env:env) (t:typ) r : ML bitfield_bit_order = let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_and_bit_order_of_integral_typ env t with | _, None -> failwith "Impossible" | _, Some order -> order let eq_typ env t1 t2 = if Ast.eq_typ t1 t2 then true else Ast.eq_typ (unfold_typ_abbrev_and_enum env t1) (unfold_typ_abbrev_and_enum env t2) let eq_typs env ts = List.for_all (fun (t1, t2) -> eq_typ env t1 t2) ts let cast e t t' = { e with v = App (Cast (Some t) t') [e] } let try_cast_integer env et to : ML (option expr) = let e, from = et in let i_to = typ_is_integral env to in let i_from = typ_is_integral env from in if i_from && i_to then let i_from = typ_as_integer_type (unfold_typ_abbrev_and_enum env from) in let i_to = typ_as_integer_type (unfold_typ_abbrev_and_enum env to) in if i_from = i_to then Some e else if integer_type_leq i_from i_to then Some (cast e i_from i_to) else None else None let _or_ b1 b2 = b1 || b2 let _and_ b1 b2 = b1 && b2 let try_retype_arith_exprs (env:env) e1 e2 rng : ML (option (expr & expr & typ))= let e1, t1 = e1 in let e2, t2 = e2 in let fail #a i : ML a = raise (Error (Printf.sprintf "(%d) Failed to retype exprs (%s : %s) and (%s : %s)" i (print_expr e1) (print_typ t1) (print_expr e2) (print_typ t2))) in try let t1, t2 = unfold_typ_abbrev_and_enum env t1, unfold_typ_abbrev_and_enum env t2 in if not (typ_is_integral env t1 `_and_` typ_is_integral env t2) then fail 1; let tt1 = typ_as_integer_type t1 in let tt2 = typ_as_integer_type t2 in let cast e t t' = { e with v = App (Cast (Some t) t') [e] } in let e1, e2, t = if integer_type_leq tt1 tt2 then cast e1 tt1 tt2, e2, t2 else if integer_type_leq tt2 tt1 then e1, cast e2 tt2 tt1, t1 else fail 0 in // FStar.IO.print_string // (Printf.sprintf "Retyped to (%s, %s, %s)\n" // (print_expr e1) // (print_expr e2) // (print_typ t)); Some (e1, e2, t) with | Error msg -> FStar.IO.print_string msg; None | _ -> None (* * Add output type to the environment * * TODO: check_shadow *) let add_output_type (ge:global_env) (i:ident) (d:decl{OutputType? d.d_decl.v}) : ML unit = let insert i = H.insert ge.ge_out_t i d in insert i.v; let td_abbrev = (OutputType?._0 d.d_decl.v).out_typ_names.typedef_abbrev in insert td_abbrev.v (* * Add extern type to the environment * * TODO: check shadow *) let add_extern_type (ge:global_env) (i:ident) (d:decl{ExternType? d.d_decl.v}) : ML unit = let insert i = H.insert ge.ge_extern_t i d in insert i.v; let td_abbrev = (ExternType?._0 d.d_decl.v).typedef_abbrev in insert td_abbrev.v (* * Add extern function to the environment * * TODO: check shadow *)
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val add_extern_fn (ge: global_env) (i: ident) (d: decl{ExternFn? d.d_decl.v}) : ML unit
[]
Binding.add_extern_fn
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
ge: GlobalEnv.global_env -> i: Ast.ident -> d: Ast.decl{ExternFn? (Mkwith_meta_t?.v (Mkdecl?.d_decl d))} -> FStar.All.ML Prims.unit
{ "end_col": 32, "end_line": 471, "start_col": 2, "start_line": 471 }
FStar.All.ML
val add_extern_type (ge: global_env) (i: ident) (d: decl{ExternType? d.d_decl.v}) : ML unit
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let add_extern_type (ge:global_env) (i:ident) (d:decl{ExternType? d.d_decl.v}) : ML unit = let insert i = H.insert ge.ge_extern_t i d in insert i.v; let td_abbrev = (ExternType?._0 d.d_decl.v).typedef_abbrev in insert td_abbrev.v
val add_extern_type (ge: global_env) (i: ident) (d: decl{ExternType? d.d_decl.v}) : ML unit let add_extern_type (ge: global_env) (i: ident) (d: decl{ExternType? d.d_decl.v}) : ML unit =
true
null
false
let insert i = H.insert ge.ge_extern_t i d in insert i.v; let td_abbrev = (ExternType?._0 d.d_decl.v).typedef_abbrev in insert td_abbrev.v
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "GlobalEnv.global_env", "Ast.ident", "Ast.decl", "Prims.b2t", "Ast.uu___is_ExternType", "Ast.__proj__Mkwith_meta_t__item__v", "Ast.decl'", "Ast.__proj__Mkdecl__item__d_decl", "Ast.ident'", "Prims.unit", "Ast.__proj__Mktypedef_names__item__typedef_abbrev", "Ast.__proj__ExternType__item___0", "Hashtable.insert", "GlobalEnv.__proj__Mkglobal_env__item__ge_extern_t" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range let lookup_macro_definition (e:env) (i:ident) = try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None let try_lookup_enum_cases (e:env) (i:ident) : ML (option (list ident & typ)) = match lookup e i with | Inr ({d_decl={v=Enum t _ tags}}, _) -> Some (Desugar.check_desugared_enum_cases tags, t) | _ -> None let lookup_enum_cases (e:env) (i:ident) : ML (list ident & typ) = match try_lookup_enum_cases e i with | Some (tags, t) -> tags, t | _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range let is_enum (e:env) (t:typ) = match t.v with | Type_app i KindSpec [] -> Some? (try_lookup_enum_cases e i) | _ -> false let is_used (e:env) (i:ident) : ML bool = match H.try_find e.locals i.v with | Some (_, t, b) -> b | _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range let type_of_integer_type = function | UInt8 -> tuint8 | UInt16 -> tuint16 | UInt32 -> tuint32 | UInt64 -> tuint64 let check_integer_bounds t i = match t with | UInt8 -> FStar.UInt.fits i 8 | UInt16 -> FStar.UInt.fits i 16 | UInt32 -> FStar.UInt.fits i 32 | UInt64 -> FStar.UInt.fits i 64 let type_of_constant rng (c:constant) : ML typ = match c with | Unit -> tunit | Int tag i -> if check_integer_bounds tag i then type_of_integer_type tag else error (Printf.sprintf "Constant %d is too large for its type %s" i (Ast.print_integer_type tag)) rng | XInt tag _ -> //bounds checked by the syntax type_of_integer_type tag | Bool _ -> tbool let parser_may_fail (env:env) (t:typ) : ML bool = match t.v with | Pointer _ -> true | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> attrs.may_fail | _ -> false let typ_is_integral env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> Some? attrs.integral | _ -> false let tag_of_integral_typ env (t:typ) : ML (option _) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral | _ -> None let tag_and_bit_order_of_integral_typ env (t:typ) : ML (tag_and_bit_order: (option integer_type & option bitfield_bit_order) { Some? (snd tag_and_bit_order) ==> Some? (fst tag_and_bit_order) }) = match t.v with | Pointer _ -> None, None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral, attrs.bit_order | _ -> None, None let has_reader (env:global_env) (id:ident) : ML bool = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.has_reader | _ -> false let parser_kind_nz (env:global_env) (id:ident) : ML (option bool) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.parser_kind_nz | _ -> None let parser_weak_kind (env:global_env) (id:ident) : ML (option _) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> Some attrs.parser_weak_kind | _ -> None let typ_weak_kind env (t:typ) : ML (option weak_kind) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> parser_weak_kind env.globals hd let typ_has_reader env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> has_reader env.globals hd let rec unfold_typ_abbrev_only (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match try_lookup env hd with | Some (Inr (d, _)) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_only env t | _ -> t end | _ -> t end | _ -> t let update_typ_abbrev (env:env) (i:ident) (t:typ) : ML unit = match H.try_find env.globals.ge_h i.v with | Some (d, ms) -> let d_decl = match d.d_decl.v with | TypeAbbrev _ _ -> {d.d_decl with v = TypeAbbrev t i } | _ -> failwith "Expected a type abbreviation" in let d = {d with d_decl = d_decl } in let entry = (d, ms) in H.insert env.globals.ge_h i.v entry | _ -> failwith "Type abbreviation not found" let rec unfold_typ_abbrev_and_enum (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match lookup env hd with | Inr (d, _) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_and_enum env t | Enum t _ _ -> unfold_typ_abbrev_and_enum env t | _ -> t end | _ -> t end | _ -> t let size_of_integral_typ (env:env) (t:typ) r : ML int = let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_of_integral_typ env t with | None -> failwith "Impossible" | Some UInt8 -> 1 | Some UInt16 -> 2 | Some UInt32 -> 4 | Some UInt64 -> 8 let bit_order_of_integral_typ (env:env) (t:typ) r : ML bitfield_bit_order = let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_and_bit_order_of_integral_typ env t with | _, None -> failwith "Impossible" | _, Some order -> order let eq_typ env t1 t2 = if Ast.eq_typ t1 t2 then true else Ast.eq_typ (unfold_typ_abbrev_and_enum env t1) (unfold_typ_abbrev_and_enum env t2) let eq_typs env ts = List.for_all (fun (t1, t2) -> eq_typ env t1 t2) ts let cast e t t' = { e with v = App (Cast (Some t) t') [e] } let try_cast_integer env et to : ML (option expr) = let e, from = et in let i_to = typ_is_integral env to in let i_from = typ_is_integral env from in if i_from && i_to then let i_from = typ_as_integer_type (unfold_typ_abbrev_and_enum env from) in let i_to = typ_as_integer_type (unfold_typ_abbrev_and_enum env to) in if i_from = i_to then Some e else if integer_type_leq i_from i_to then Some (cast e i_from i_to) else None else None let _or_ b1 b2 = b1 || b2 let _and_ b1 b2 = b1 && b2 let try_retype_arith_exprs (env:env) e1 e2 rng : ML (option (expr & expr & typ))= let e1, t1 = e1 in let e2, t2 = e2 in let fail #a i : ML a = raise (Error (Printf.sprintf "(%d) Failed to retype exprs (%s : %s) and (%s : %s)" i (print_expr e1) (print_typ t1) (print_expr e2) (print_typ t2))) in try let t1, t2 = unfold_typ_abbrev_and_enum env t1, unfold_typ_abbrev_and_enum env t2 in if not (typ_is_integral env t1 `_and_` typ_is_integral env t2) then fail 1; let tt1 = typ_as_integer_type t1 in let tt2 = typ_as_integer_type t2 in let cast e t t' = { e with v = App (Cast (Some t) t') [e] } in let e1, e2, t = if integer_type_leq tt1 tt2 then cast e1 tt1 tt2, e2, t2 else if integer_type_leq tt2 tt1 then e1, cast e2 tt2 tt1, t1 else fail 0 in // FStar.IO.print_string // (Printf.sprintf "Retyped to (%s, %s, %s)\n" // (print_expr e1) // (print_expr e2) // (print_typ t)); Some (e1, e2, t) with | Error msg -> FStar.IO.print_string msg; None | _ -> None (* * Add output type to the environment * * TODO: check_shadow *) let add_output_type (ge:global_env) (i:ident) (d:decl{OutputType? d.d_decl.v}) : ML unit = let insert i = H.insert ge.ge_out_t i d in insert i.v; let td_abbrev = (OutputType?._0 d.d_decl.v).out_typ_names.typedef_abbrev in insert td_abbrev.v (* * Add extern type to the environment * * TODO: check shadow
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val add_extern_type (ge: global_env) (i: ident) (d: decl{ExternType? d.d_decl.v}) : ML unit
[]
Binding.add_extern_type
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
ge: GlobalEnv.global_env -> i: Ast.ident -> d: Ast.decl{ExternType? (Mkwith_meta_t?.v (Mkdecl?.d_decl d))} -> FStar.All.ML Prims.unit
{ "end_col": 20, "end_line": 463, "start_col": 90, "start_line": 459 }
FStar.All.ML
val add_global (e: global_env) (i: ident) (d: decl) (t: either decl_attributes macro_signature) : ML unit
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end
val add_global (e: global_env) (i: ident) (d: decl) (t: either decl_attributes macro_signature) : ML unit let add_global (e: global_env) (i: ident) (d: decl) (t: either decl_attributes macro_signature) : ML unit =
true
null
false
let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then (check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t))
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "GlobalEnv.global_env", "Ast.ident", "Ast.decl", "Ast.either", "GlobalEnv.decl_attributes", "GlobalEnv.macro_signature", "Binding.typedef_names", "Prims.unit", "Ast.typedef_names", "Prims.op_disEquality", "Ast.ident'", "Ast.__proj__Mkwith_meta_t__item__v", "Ast.__proj__Mktypedef_names__item__typedef_abbrev", "FStar.Pervasives.Native.Mktuple2", "Binding.format_identifier", "Binding.check_shadow", "FStar.Pervasives.Native.tuple2", "GlobalEnv.__proj__Mkglobal_env__item__ge_h", "Ast.__proj__Mkwith_meta_t__item__range", "Ast.decl'", "Ast.__proj__Mkdecl__item__d_decl", "Prims.bool", "Binding.env", "Binding.mk_env", "Hashtable.insert" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val add_global (e: global_env) (i: ident) (d: decl) (t: either decl_attributes macro_signature) : ML unit
[]
Binding.add_global
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
e: GlobalEnv.global_env -> i: Ast.ident -> d: Ast.decl -> t: Ast.either GlobalEnv.decl_attributes GlobalEnv.macro_signature -> FStar.All.ML Prims.unit
{ "end_col": 7, "end_line": 132, "start_col": 103, "start_line": 115 }
FStar.All.ML
val parser_kind_nz (env:global_env) (id:ident) : ML (option bool)
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parser_kind_nz (env:global_env) (id:ident) : ML (option bool) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.parser_kind_nz | _ -> None
val parser_kind_nz (env:global_env) (id:ident) : ML (option bool) let parser_kind_nz (env: global_env) (id: ident) : ML (option bool) =
true
null
false
match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.parser_kind_nz | _ -> None
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "GlobalEnv.global_env", "Ast.ident", "Ast.decl", "GlobalEnv.decl_attributes", "GlobalEnv.__proj__Mkdecl_attributes__item__parser_kind_nz", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "Ast.either", "GlobalEnv.macro_signature", "FStar.Pervasives.Native.None", "Prims.bool", "Hashtable.try_find", "Ast.ident'", "GlobalEnv.__proj__Mkglobal_env__item__ge_h", "Ast.__proj__Mkwith_meta_t__item__v" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range let lookup_macro_definition (e:env) (i:ident) = try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None let try_lookup_enum_cases (e:env) (i:ident) : ML (option (list ident & typ)) = match lookup e i with | Inr ({d_decl={v=Enum t _ tags}}, _) -> Some (Desugar.check_desugared_enum_cases tags, t) | _ -> None let lookup_enum_cases (e:env) (i:ident) : ML (list ident & typ) = match try_lookup_enum_cases e i with | Some (tags, t) -> tags, t | _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range let is_enum (e:env) (t:typ) = match t.v with | Type_app i KindSpec [] -> Some? (try_lookup_enum_cases e i) | _ -> false let is_used (e:env) (i:ident) : ML bool = match H.try_find e.locals i.v with | Some (_, t, b) -> b | _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range let type_of_integer_type = function | UInt8 -> tuint8 | UInt16 -> tuint16 | UInt32 -> tuint32 | UInt64 -> tuint64 let check_integer_bounds t i = match t with | UInt8 -> FStar.UInt.fits i 8 | UInt16 -> FStar.UInt.fits i 16 | UInt32 -> FStar.UInt.fits i 32 | UInt64 -> FStar.UInt.fits i 64 let type_of_constant rng (c:constant) : ML typ = match c with | Unit -> tunit | Int tag i -> if check_integer_bounds tag i then type_of_integer_type tag else error (Printf.sprintf "Constant %d is too large for its type %s" i (Ast.print_integer_type tag)) rng | XInt tag _ -> //bounds checked by the syntax type_of_integer_type tag | Bool _ -> tbool let parser_may_fail (env:env) (t:typ) : ML bool = match t.v with | Pointer _ -> true | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> attrs.may_fail | _ -> false let typ_is_integral env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> Some? attrs.integral | _ -> false let tag_of_integral_typ env (t:typ) : ML (option _) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral | _ -> None let tag_and_bit_order_of_integral_typ env (t:typ) : ML (tag_and_bit_order: (option integer_type & option bitfield_bit_order) { Some? (snd tag_and_bit_order) ==> Some? (fst tag_and_bit_order) }) = match t.v with | Pointer _ -> None, None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral, attrs.bit_order | _ -> None, None let has_reader (env:global_env) (id:ident) : ML bool = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.has_reader | _ -> false
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parser_kind_nz (env:global_env) (id:ident) : ML (option bool)
[]
Binding.parser_kind_nz
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
env: GlobalEnv.global_env -> id: Ast.ident -> FStar.All.ML (FStar.Pervasives.Native.option Prims.bool)
{ "end_col": 13, "end_line": 287, "start_col": 2, "start_line": 285 }
Prims.Tot
val params_of_decl (d: decl) : list param
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps
val params_of_decl (d: decl) : list param let params_of_decl (d: decl) : list param =
false
null
false
match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "total" ]
[ "Ast.decl", "Ast.__proj__Mkwith_meta_t__item__v", "Ast.decl'", "Ast.__proj__Mkdecl__item__d_decl", "Ast.ident", "Prims.Nil", "Ast.param", "FStar.Pervasives.Native.option", "Ast.typ", "Ast.constant", "Prims.list", "Ast.enum_case", "Ast.typedef_names", "Ast.expr", "Ast.record", "Ast.switch_case", "Ast.out_typ" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals
false
true
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val params_of_decl (d: decl) : list param
[]
Binding.params_of_decl
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
d: Ast.decl -> Prims.list Ast.param
{ "end_col": 25, "end_line": 80, "start_col": 2, "start_line": 71 }
FStar.All.ML
val add_local (e: env) (i: ident) (t: typ) : ML unit
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false)
val add_local (e: env) (i: ident) (t: typ) : ML unit let add_local (e: env) (i: ident) (t: typ) : ML unit =
true
null
false
check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false)
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "Binding.env", "Ast.ident", "Ast.typ", "Hashtable.insert", "Ast.ident'", "FStar.Pervasives.Native.tuple3", "Prims.bool", "Binding.__proj__Mkenv__item__locals", "Ast.__proj__Mkwith_meta_t__item__v", "FStar.Pervasives.Native.Mktuple3", "Prims.unit", "Binding.format_identifier", "Binding.check_shadow", "Ast.__proj__Mkwith_meta_t__item__range", "Ast.typ'", "FStar.Pervasives.Native.tuple2", "Ast.decl", "Ast.either", "GlobalEnv.decl_attributes", "GlobalEnv.macro_signature", "GlobalEnv.__proj__Mkglobal_env__item__ge_h", "Binding.__proj__Mkenv__item__globals" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val add_local (e: env) (i: ident) (t: typ) : ML unit
[]
Binding.add_local
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
e: Binding.env -> i: Ast.ident -> t: Ast.typ -> FStar.All.ML Prims.unit
{ "end_col": 41, "end_line": 139, "start_col": 2, "start_line": 135 }
FStar.All.ML
val bit_order_of_integral_typ (_:env) (_:typ) (_:range) : ML bitfield_bit_order
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let bit_order_of_integral_typ (env:env) (t:typ) r : ML bitfield_bit_order = let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_and_bit_order_of_integral_typ env t with | _, None -> failwith "Impossible" | _, Some order -> order
val bit_order_of_integral_typ (_:env) (_:typ) (_:range) : ML bitfield_bit_order let bit_order_of_integral_typ (env: env) (t: typ) r : ML bitfield_bit_order =
true
null
false
let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_and_bit_order_of_integral_typ env t with | _, None -> failwith "Impossible" | _, Some order -> order
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "Binding.env", "Ast.typ", "Ast.range", "FStar.Pervasives.Native.option", "Ast.integer_type", "FStar.All.failwith", "Ast.bitfield_bit_order", "FStar.Pervasives.Native.tuple2", "Prims.l_imp", "Prims.b2t", "FStar.Pervasives.Native.uu___is_Some", "FStar.Pervasives.Native.snd", "FStar.Pervasives.Native.fst", "Binding.tag_and_bit_order_of_integral_typ", "Prims.unit", "Ast.error", "Prims.string", "FStar.Printf.sprintf", "Ast.print_typ", "Prims.bool", "Prims.op_Negation", "Binding.typ_is_integral", "Binding.unfold_typ_abbrev_and_enum" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range let lookup_macro_definition (e:env) (i:ident) = try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None let try_lookup_enum_cases (e:env) (i:ident) : ML (option (list ident & typ)) = match lookup e i with | Inr ({d_decl={v=Enum t _ tags}}, _) -> Some (Desugar.check_desugared_enum_cases tags, t) | _ -> None let lookup_enum_cases (e:env) (i:ident) : ML (list ident & typ) = match try_lookup_enum_cases e i with | Some (tags, t) -> tags, t | _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range let is_enum (e:env) (t:typ) = match t.v with | Type_app i KindSpec [] -> Some? (try_lookup_enum_cases e i) | _ -> false let is_used (e:env) (i:ident) : ML bool = match H.try_find e.locals i.v with | Some (_, t, b) -> b | _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range let type_of_integer_type = function | UInt8 -> tuint8 | UInt16 -> tuint16 | UInt32 -> tuint32 | UInt64 -> tuint64 let check_integer_bounds t i = match t with | UInt8 -> FStar.UInt.fits i 8 | UInt16 -> FStar.UInt.fits i 16 | UInt32 -> FStar.UInt.fits i 32 | UInt64 -> FStar.UInt.fits i 64 let type_of_constant rng (c:constant) : ML typ = match c with | Unit -> tunit | Int tag i -> if check_integer_bounds tag i then type_of_integer_type tag else error (Printf.sprintf "Constant %d is too large for its type %s" i (Ast.print_integer_type tag)) rng | XInt tag _ -> //bounds checked by the syntax type_of_integer_type tag | Bool _ -> tbool let parser_may_fail (env:env) (t:typ) : ML bool = match t.v with | Pointer _ -> true | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> attrs.may_fail | _ -> false let typ_is_integral env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> Some? attrs.integral | _ -> false let tag_of_integral_typ env (t:typ) : ML (option _) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral | _ -> None let tag_and_bit_order_of_integral_typ env (t:typ) : ML (tag_and_bit_order: (option integer_type & option bitfield_bit_order) { Some? (snd tag_and_bit_order) ==> Some? (fst tag_and_bit_order) }) = match t.v with | Pointer _ -> None, None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral, attrs.bit_order | _ -> None, None let has_reader (env:global_env) (id:ident) : ML bool = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.has_reader | _ -> false let parser_kind_nz (env:global_env) (id:ident) : ML (option bool) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.parser_kind_nz | _ -> None let parser_weak_kind (env:global_env) (id:ident) : ML (option _) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> Some attrs.parser_weak_kind | _ -> None let typ_weak_kind env (t:typ) : ML (option weak_kind) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> parser_weak_kind env.globals hd let typ_has_reader env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> has_reader env.globals hd let rec unfold_typ_abbrev_only (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match try_lookup env hd with | Some (Inr (d, _)) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_only env t | _ -> t end | _ -> t end | _ -> t let update_typ_abbrev (env:env) (i:ident) (t:typ) : ML unit = match H.try_find env.globals.ge_h i.v with | Some (d, ms) -> let d_decl = match d.d_decl.v with | TypeAbbrev _ _ -> {d.d_decl with v = TypeAbbrev t i } | _ -> failwith "Expected a type abbreviation" in let d = {d with d_decl = d_decl } in let entry = (d, ms) in H.insert env.globals.ge_h i.v entry | _ -> failwith "Type abbreviation not found" let rec unfold_typ_abbrev_and_enum (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match lookup env hd with | Inr (d, _) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_and_enum env t | Enum t _ _ -> unfold_typ_abbrev_and_enum env t | _ -> t end | _ -> t end | _ -> t let size_of_integral_typ (env:env) (t:typ) r : ML int = let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_of_integral_typ env t with | None -> failwith "Impossible" | Some UInt8 -> 1 | Some UInt16 -> 2 | Some UInt32 -> 4 | Some UInt64 -> 8 let bit_order_of_integral_typ (env:env) (t:typ) r
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val bit_order_of_integral_typ (_:env) (_:typ) (_:range) : ML bitfield_bit_order
[]
Binding.bit_order_of_integral_typ
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
env: Binding.env -> t: Ast.typ -> r: Ast.range -> FStar.All.ML Ast.bitfield_bit_order
{ "end_col": 28, "end_line": 375, "start_col": 3, "start_line": 368 }
FStar.All.ML
val add_output_type (ge: global_env) (i: ident) (d: decl{OutputType? d.d_decl.v}) : ML unit
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let add_output_type (ge:global_env) (i:ident) (d:decl{OutputType? d.d_decl.v}) : ML unit = let insert i = H.insert ge.ge_out_t i d in insert i.v; let td_abbrev = (OutputType?._0 d.d_decl.v).out_typ_names.typedef_abbrev in insert td_abbrev.v
val add_output_type (ge: global_env) (i: ident) (d: decl{OutputType? d.d_decl.v}) : ML unit let add_output_type (ge: global_env) (i: ident) (d: decl{OutputType? d.d_decl.v}) : ML unit =
true
null
false
let insert i = H.insert ge.ge_out_t i d in insert i.v; let td_abbrev = (OutputType?._0 d.d_decl.v).out_typ_names.typedef_abbrev in insert td_abbrev.v
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "GlobalEnv.global_env", "Ast.ident", "Ast.decl", "Prims.b2t", "Ast.uu___is_OutputType", "Ast.__proj__Mkwith_meta_t__item__v", "Ast.decl'", "Ast.__proj__Mkdecl__item__d_decl", "Ast.ident'", "Prims.unit", "Ast.__proj__Mktypedef_names__item__typedef_abbrev", "Ast.__proj__Mkout_typ__item__out_typ_names", "Ast.__proj__OutputType__item___0", "Hashtable.insert", "GlobalEnv.__proj__Mkglobal_env__item__ge_out_t" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range let lookup_macro_definition (e:env) (i:ident) = try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None let try_lookup_enum_cases (e:env) (i:ident) : ML (option (list ident & typ)) = match lookup e i with | Inr ({d_decl={v=Enum t _ tags}}, _) -> Some (Desugar.check_desugared_enum_cases tags, t) | _ -> None let lookup_enum_cases (e:env) (i:ident) : ML (list ident & typ) = match try_lookup_enum_cases e i with | Some (tags, t) -> tags, t | _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range let is_enum (e:env) (t:typ) = match t.v with | Type_app i KindSpec [] -> Some? (try_lookup_enum_cases e i) | _ -> false let is_used (e:env) (i:ident) : ML bool = match H.try_find e.locals i.v with | Some (_, t, b) -> b | _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range let type_of_integer_type = function | UInt8 -> tuint8 | UInt16 -> tuint16 | UInt32 -> tuint32 | UInt64 -> tuint64 let check_integer_bounds t i = match t with | UInt8 -> FStar.UInt.fits i 8 | UInt16 -> FStar.UInt.fits i 16 | UInt32 -> FStar.UInt.fits i 32 | UInt64 -> FStar.UInt.fits i 64 let type_of_constant rng (c:constant) : ML typ = match c with | Unit -> tunit | Int tag i -> if check_integer_bounds tag i then type_of_integer_type tag else error (Printf.sprintf "Constant %d is too large for its type %s" i (Ast.print_integer_type tag)) rng | XInt tag _ -> //bounds checked by the syntax type_of_integer_type tag | Bool _ -> tbool let parser_may_fail (env:env) (t:typ) : ML bool = match t.v with | Pointer _ -> true | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> attrs.may_fail | _ -> false let typ_is_integral env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> Some? attrs.integral | _ -> false let tag_of_integral_typ env (t:typ) : ML (option _) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral | _ -> None let tag_and_bit_order_of_integral_typ env (t:typ) : ML (tag_and_bit_order: (option integer_type & option bitfield_bit_order) { Some? (snd tag_and_bit_order) ==> Some? (fst tag_and_bit_order) }) = match t.v with | Pointer _ -> None, None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral, attrs.bit_order | _ -> None, None let has_reader (env:global_env) (id:ident) : ML bool = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.has_reader | _ -> false let parser_kind_nz (env:global_env) (id:ident) : ML (option bool) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.parser_kind_nz | _ -> None let parser_weak_kind (env:global_env) (id:ident) : ML (option _) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> Some attrs.parser_weak_kind | _ -> None let typ_weak_kind env (t:typ) : ML (option weak_kind) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> parser_weak_kind env.globals hd let typ_has_reader env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> has_reader env.globals hd let rec unfold_typ_abbrev_only (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match try_lookup env hd with | Some (Inr (d, _)) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_only env t | _ -> t end | _ -> t end | _ -> t let update_typ_abbrev (env:env) (i:ident) (t:typ) : ML unit = match H.try_find env.globals.ge_h i.v with | Some (d, ms) -> let d_decl = match d.d_decl.v with | TypeAbbrev _ _ -> {d.d_decl with v = TypeAbbrev t i } | _ -> failwith "Expected a type abbreviation" in let d = {d with d_decl = d_decl } in let entry = (d, ms) in H.insert env.globals.ge_h i.v entry | _ -> failwith "Type abbreviation not found" let rec unfold_typ_abbrev_and_enum (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match lookup env hd with | Inr (d, _) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_and_enum env t | Enum t _ _ -> unfold_typ_abbrev_and_enum env t | _ -> t end | _ -> t end | _ -> t let size_of_integral_typ (env:env) (t:typ) r : ML int = let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_of_integral_typ env t with | None -> failwith "Impossible" | Some UInt8 -> 1 | Some UInt16 -> 2 | Some UInt32 -> 4 | Some UInt64 -> 8 let bit_order_of_integral_typ (env:env) (t:typ) r : ML bitfield_bit_order = let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_and_bit_order_of_integral_typ env t with | _, None -> failwith "Impossible" | _, Some order -> order let eq_typ env t1 t2 = if Ast.eq_typ t1 t2 then true else Ast.eq_typ (unfold_typ_abbrev_and_enum env t1) (unfold_typ_abbrev_and_enum env t2) let eq_typs env ts = List.for_all (fun (t1, t2) -> eq_typ env t1 t2) ts let cast e t t' = { e with v = App (Cast (Some t) t') [e] } let try_cast_integer env et to : ML (option expr) = let e, from = et in let i_to = typ_is_integral env to in let i_from = typ_is_integral env from in if i_from && i_to then let i_from = typ_as_integer_type (unfold_typ_abbrev_and_enum env from) in let i_to = typ_as_integer_type (unfold_typ_abbrev_and_enum env to) in if i_from = i_to then Some e else if integer_type_leq i_from i_to then Some (cast e i_from i_to) else None else None let _or_ b1 b2 = b1 || b2 let _and_ b1 b2 = b1 && b2 let try_retype_arith_exprs (env:env) e1 e2 rng : ML (option (expr & expr & typ))= let e1, t1 = e1 in let e2, t2 = e2 in let fail #a i : ML a = raise (Error (Printf.sprintf "(%d) Failed to retype exprs (%s : %s) and (%s : %s)" i (print_expr e1) (print_typ t1) (print_expr e2) (print_typ t2))) in try let t1, t2 = unfold_typ_abbrev_and_enum env t1, unfold_typ_abbrev_and_enum env t2 in if not (typ_is_integral env t1 `_and_` typ_is_integral env t2) then fail 1; let tt1 = typ_as_integer_type t1 in let tt2 = typ_as_integer_type t2 in let cast e t t' = { e with v = App (Cast (Some t) t') [e] } in let e1, e2, t = if integer_type_leq tt1 tt2 then cast e1 tt1 tt2, e2, t2 else if integer_type_leq tt2 tt1 then e1, cast e2 tt2 tt1, t1 else fail 0 in // FStar.IO.print_string // (Printf.sprintf "Retyped to (%s, %s, %s)\n" // (print_expr e1) // (print_expr e2) // (print_typ t)); Some (e1, e2, t) with | Error msg -> FStar.IO.print_string msg; None | _ -> None (* * Add output type to the environment * * TODO: check_shadow
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val add_output_type (ge: global_env) (i: ident) (d: decl{OutputType? d.d_decl.v}) : ML unit
[]
Binding.add_output_type
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
ge: GlobalEnv.global_env -> i: Ast.ident -> d: Ast.decl{OutputType? (Mkwith_meta_t?.v (Mkdecl?.d_decl d))} -> FStar.All.ML Prims.unit
{ "end_col": 20, "end_line": 452, "start_col": 90, "start_line": 448 }
FStar.All.ML
val size_of_integral_typ (_:env) (_:typ) (_:range) : ML int
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let size_of_integral_typ (env:env) (t:typ) r : ML int = let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_of_integral_typ env t with | None -> failwith "Impossible" | Some UInt8 -> 1 | Some UInt16 -> 2 | Some UInt32 -> 4 | Some UInt64 -> 8
val size_of_integral_typ (_:env) (_:typ) (_:range) : ML int let size_of_integral_typ (env: env) (t: typ) r : ML int =
true
null
false
let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_of_integral_typ env t with | None -> failwith "Impossible" | Some UInt8 -> 1 | Some UInt16 -> 2 | Some UInt32 -> 4 | Some UInt64 -> 8
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "Binding.env", "Ast.typ", "Ast.range", "FStar.All.failwith", "Prims.int", "FStar.Pervasives.Native.option", "Ast.integer_type", "Binding.tag_of_integral_typ", "Prims.unit", "Ast.error", "Prims.string", "FStar.Printf.sprintf", "Ast.print_typ", "Prims.bool", "Prims.op_Negation", "Binding.typ_is_integral", "Binding.unfold_typ_abbrev_and_enum" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range let lookup_macro_definition (e:env) (i:ident) = try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None let try_lookup_enum_cases (e:env) (i:ident) : ML (option (list ident & typ)) = match lookup e i with | Inr ({d_decl={v=Enum t _ tags}}, _) -> Some (Desugar.check_desugared_enum_cases tags, t) | _ -> None let lookup_enum_cases (e:env) (i:ident) : ML (list ident & typ) = match try_lookup_enum_cases e i with | Some (tags, t) -> tags, t | _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range let is_enum (e:env) (t:typ) = match t.v with | Type_app i KindSpec [] -> Some? (try_lookup_enum_cases e i) | _ -> false let is_used (e:env) (i:ident) : ML bool = match H.try_find e.locals i.v with | Some (_, t, b) -> b | _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range let type_of_integer_type = function | UInt8 -> tuint8 | UInt16 -> tuint16 | UInt32 -> tuint32 | UInt64 -> tuint64 let check_integer_bounds t i = match t with | UInt8 -> FStar.UInt.fits i 8 | UInt16 -> FStar.UInt.fits i 16 | UInt32 -> FStar.UInt.fits i 32 | UInt64 -> FStar.UInt.fits i 64 let type_of_constant rng (c:constant) : ML typ = match c with | Unit -> tunit | Int tag i -> if check_integer_bounds tag i then type_of_integer_type tag else error (Printf.sprintf "Constant %d is too large for its type %s" i (Ast.print_integer_type tag)) rng | XInt tag _ -> //bounds checked by the syntax type_of_integer_type tag | Bool _ -> tbool let parser_may_fail (env:env) (t:typ) : ML bool = match t.v with | Pointer _ -> true | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> attrs.may_fail | _ -> false let typ_is_integral env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> Some? attrs.integral | _ -> false let tag_of_integral_typ env (t:typ) : ML (option _) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral | _ -> None let tag_and_bit_order_of_integral_typ env (t:typ) : ML (tag_and_bit_order: (option integer_type & option bitfield_bit_order) { Some? (snd tag_and_bit_order) ==> Some? (fst tag_and_bit_order) }) = match t.v with | Pointer _ -> None, None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral, attrs.bit_order | _ -> None, None let has_reader (env:global_env) (id:ident) : ML bool = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.has_reader | _ -> false let parser_kind_nz (env:global_env) (id:ident) : ML (option bool) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.parser_kind_nz | _ -> None let parser_weak_kind (env:global_env) (id:ident) : ML (option _) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> Some attrs.parser_weak_kind | _ -> None let typ_weak_kind env (t:typ) : ML (option weak_kind) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> parser_weak_kind env.globals hd let typ_has_reader env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> has_reader env.globals hd let rec unfold_typ_abbrev_only (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match try_lookup env hd with | Some (Inr (d, _)) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_only env t | _ -> t end | _ -> t end | _ -> t let update_typ_abbrev (env:env) (i:ident) (t:typ) : ML unit = match H.try_find env.globals.ge_h i.v with | Some (d, ms) -> let d_decl = match d.d_decl.v with | TypeAbbrev _ _ -> {d.d_decl with v = TypeAbbrev t i } | _ -> failwith "Expected a type abbreviation" in let d = {d with d_decl = d_decl } in let entry = (d, ms) in H.insert env.globals.ge_h i.v entry | _ -> failwith "Type abbreviation not found" let rec unfold_typ_abbrev_and_enum (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match lookup env hd with | Inr (d, _) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_and_enum env t | Enum t _ _ -> unfold_typ_abbrev_and_enum env t | _ -> t end | _ -> t end | _ -> t let size_of_integral_typ (env:env) (t:typ) r
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val size_of_integral_typ (_:env) (_:typ) (_:range) : ML int
[]
Binding.size_of_integral_typ
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
env: Binding.env -> t: Ast.typ -> r: Ast.range -> FStar.All.ML Prims.int
{ "end_col": 22, "end_line": 364, "start_col": 3, "start_line": 354 }
FStar.All.ML
val lookup_expr_name (_:env) (_:ident) : ML typ
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range
val lookup_expr_name (_:env) (_:ident) : ML typ let lookup_expr_name (e: env) (i: ident) : ML typ =
true
null
false
match lookup e i with | Inl t -> t | Inr (_, Inr { macro_arguments_t = [] ; macro_result_t = t }) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "Binding.env", "Ast.ident", "Ast.typ", "Ast.decl", "FStar.Pervasives.Native.option", "Ast.expr", "FStar.Pervasives.Native.tuple2", "Ast.either", "GlobalEnv.decl_attributes", "GlobalEnv.macro_signature", "Ast.error", "FStar.Printf.sprintf", "Ast.ident_to_string", "Ast.__proj__Mkwith_meta_t__item__range", "Ast.ident'", "Binding.lookup" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i))
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lookup_expr_name (_:env) (_:ident) : ML typ
[]
Binding.lookup_expr_name
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
e: Binding.env -> i: Ast.ident -> FStar.All.ML Ast.typ
{ "end_col": 100, "end_line": 184, "start_col": 2, "start_line": 180 }
FStar.All.ML
val check_out_expr (env: env) (oe0: out_expr) : ML (oe: out_expr{Some? oe.out_expr_meta})
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec check_out_expr (env:env) (oe0:out_expr) : ML (oe:out_expr{Some? oe.out_expr_meta}) = match oe0.out_expr_node.v with | OE_id i -> let t = lookup_expr_name env i in {oe0 with out_expr_meta = Some ({ out_expr_base_t = t; out_expr_t = t; out_expr_bit_width = None})} | OE_star oe -> let oe = check_out_expr env oe in let { out_expr_base_t = oe_bt; out_expr_t = oe_t; out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in (match oe_t.v, bopt with | Pointer t, None -> {oe0 with out_expr_node={oe0.out_expr_node with v=OE_star oe}; out_expr_meta=Some ({ out_expr_base_t = oe_bt; out_expr_t = t; out_expr_bit_width = None })} | _ -> error (Printf.sprintf "Output expression %s is ill-typed since base type %s is not a pointer type" (print_out_expr oe0) (print_typ oe_t)) oe.out_expr_node.range) | OE_addrof oe -> let oe = check_out_expr env oe in let { out_expr_base_t = oe_bt; out_expr_t = oe_t; out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in (match bopt with | None -> {oe0 with out_expr_node={oe0.out_expr_node with v=OE_addrof oe}; out_expr_meta=Some ({ out_expr_base_t = oe_bt; out_expr_t = with_range (Pointer oe_t) oe.out_expr_node.range; out_expr_bit_width = None })} | _ -> error (Printf.sprintf "Cannot take address of a bit field %s" (print_out_expr oe0)) oe.out_expr_node.range) | OE_deref oe f -> let oe = check_out_expr env oe in let { out_expr_base_t = oe_bt; out_expr_t = oe_t; out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in (match oe_t.v, bopt with | Pointer t, None -> let i = check_output_type (global_env_of_env env) t in let out_expr_t, out_expr_bit_width = lookup_output_type_field (global_env_of_env env) i f in {oe0 with out_expr_node={oe0.out_expr_node with v=OE_deref oe f}; out_expr_meta=Some ({ out_expr_base_t = oe_bt; out_expr_t = out_expr_t; out_expr_bit_width = out_expr_bit_width})} | _ -> error (Printf.sprintf "Output expression %s is ill-typed since base type %s is not a pointer type" (print_out_expr oe0) (print_typ oe_t)) oe.out_expr_node.range) | OE_dot oe f -> let oe = check_out_expr env oe in let { out_expr_base_t = oe_bt; out_expr_t = oe_t; out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in (match bopt with | None -> let i = check_output_type (global_env_of_env env) oe_t in let out_expr_t, out_expr_bit_width = lookup_output_type_field (global_env_of_env env) i f in {oe0 with out_expr_node={oe0.out_expr_node with v=OE_dot oe f}; out_expr_meta=Some ({ out_expr_base_t = oe_bt; out_expr_t = out_expr_t; out_expr_bit_width = out_expr_bit_width})} | _ -> error (Printf.sprintf "Cannot take address of a bit field %s" (print_out_expr oe0)) oe.out_expr_node.range)
val check_out_expr (env: env) (oe0: out_expr) : ML (oe: out_expr{Some? oe.out_expr_meta}) let rec check_out_expr (env: env) (oe0: out_expr) : ML (oe: out_expr{Some? oe.out_expr_meta}) =
true
null
false
match oe0.out_expr_node.v with | OE_id i -> let t = lookup_expr_name env i in { oe0 with out_expr_meta = Some ({ out_expr_base_t = t; out_expr_t = t; out_expr_bit_width = None }) } | OE_star oe -> let oe = check_out_expr env oe in let { out_expr_base_t = oe_bt ; out_expr_t = oe_t ; out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in (match oe_t.v, bopt with | Pointer t, None -> { oe0 with out_expr_node = { oe0.out_expr_node with v = OE_star oe }; out_expr_meta = Some ({ out_expr_base_t = oe_bt; out_expr_t = t; out_expr_bit_width = None }) } | _ -> error (Printf.sprintf "Output expression %s is ill-typed since base type %s is not a pointer type" (print_out_expr oe0) (print_typ oe_t)) oe.out_expr_node.range) | OE_addrof oe -> let oe = check_out_expr env oe in let { out_expr_base_t = oe_bt ; out_expr_t = oe_t ; out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in (match bopt with | None -> { oe0 with out_expr_node = { oe0.out_expr_node with v = OE_addrof oe }; out_expr_meta = Some ({ out_expr_base_t = oe_bt; out_expr_t = with_range (Pointer oe_t) oe.out_expr_node.range; out_expr_bit_width = None }) } | _ -> error (Printf.sprintf "Cannot take address of a bit field %s" (print_out_expr oe0)) oe.out_expr_node.range) | OE_deref oe f -> let oe = check_out_expr env oe in let { out_expr_base_t = oe_bt ; out_expr_t = oe_t ; out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in (match oe_t.v, bopt with | Pointer t, None -> let i = check_output_type (global_env_of_env env) t in let out_expr_t, out_expr_bit_width = lookup_output_type_field (global_env_of_env env) i f in { oe0 with out_expr_node = { oe0.out_expr_node with v = OE_deref oe f }; out_expr_meta = Some ({ out_expr_base_t = oe_bt; out_expr_t = out_expr_t; out_expr_bit_width = out_expr_bit_width }) } | _ -> error (Printf.sprintf "Output expression %s is ill-typed since base type %s is not a pointer type" (print_out_expr oe0) (print_typ oe_t)) oe.out_expr_node.range) | OE_dot oe f -> let oe = check_out_expr env oe in let { out_expr_base_t = oe_bt ; out_expr_t = oe_t ; out_expr_bit_width = bopt } = Some?.v oe.out_expr_meta in (match bopt with | None -> let i = check_output_type (global_env_of_env env) oe_t in let out_expr_t, out_expr_bit_width = lookup_output_type_field (global_env_of_env env) i f in { oe0 with out_expr_node = { oe0.out_expr_node with v = OE_dot oe f }; out_expr_meta = Some ({ out_expr_base_t = oe_bt; out_expr_t = out_expr_t; out_expr_bit_width = out_expr_bit_width }) } | _ -> error (Printf.sprintf "Cannot take address of a bit field %s" (print_out_expr oe0)) oe.out_expr_node.range)
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "Binding.env", "Ast.out_expr", "Ast.__proj__Mkwith_meta_t__item__v", "Ast.out_expr'", "Ast.__proj__Mkout_expr__item__out_expr_node", "Ast.ident", "Ast.Mkout_expr", "FStar.Pervasives.Native.Some", "Ast.out_expr_meta_t", "Ast.Mkout_expr_meta_t", "FStar.Pervasives.Native.None", "Prims.int", "Prims.b2t", "FStar.Pervasives.Native.uu___is_Some", "Ast.__proj__Mkout_expr__item__out_expr_meta", "Ast.typ", "Binding.lookup_expr_name", "Ast.with_meta_t", "Ast.typ'", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.Mktuple2", "Ast.Mkwith_meta_t", "Ast.OE_star", "Ast.__proj__Mkwith_meta_t__item__range", "Ast.__proj__Mkwith_meta_t__item__comments", "FStar.Pervasives.Native.tuple2", "Ast.error", "Prims.string", "FStar.Printf.sprintf", "Ast.print_out_expr", "Ast.print_typ", "FStar.Pervasives.Native.__proj__Some__item__v", "Binding.check_out_expr", "Ast.OE_addrof", "Ast.with_range", "Ast.Pointer", "Ast.OE_deref", "Binding.lookup_output_type_field", "GlobalEnv.global_env", "Binding.global_env_of_env", "Binding.check_output_type", "Ast.OE_dot" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range let lookup_macro_definition (e:env) (i:ident) = try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None let try_lookup_enum_cases (e:env) (i:ident) : ML (option (list ident & typ)) = match lookup e i with | Inr ({d_decl={v=Enum t _ tags}}, _) -> Some (Desugar.check_desugared_enum_cases tags, t) | _ -> None let lookup_enum_cases (e:env) (i:ident) : ML (list ident & typ) = match try_lookup_enum_cases e i with | Some (tags, t) -> tags, t | _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range let is_enum (e:env) (t:typ) = match t.v with | Type_app i KindSpec [] -> Some? (try_lookup_enum_cases e i) | _ -> false let is_used (e:env) (i:ident) : ML bool = match H.try_find e.locals i.v with | Some (_, t, b) -> b | _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range let type_of_integer_type = function | UInt8 -> tuint8 | UInt16 -> tuint16 | UInt32 -> tuint32 | UInt64 -> tuint64 let check_integer_bounds t i = match t with | UInt8 -> FStar.UInt.fits i 8 | UInt16 -> FStar.UInt.fits i 16 | UInt32 -> FStar.UInt.fits i 32 | UInt64 -> FStar.UInt.fits i 64 let type_of_constant rng (c:constant) : ML typ = match c with | Unit -> tunit | Int tag i -> if check_integer_bounds tag i then type_of_integer_type tag else error (Printf.sprintf "Constant %d is too large for its type %s" i (Ast.print_integer_type tag)) rng | XInt tag _ -> //bounds checked by the syntax type_of_integer_type tag | Bool _ -> tbool let parser_may_fail (env:env) (t:typ) : ML bool = match t.v with | Pointer _ -> true | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> attrs.may_fail | _ -> false let typ_is_integral env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> Some? attrs.integral | _ -> false let tag_of_integral_typ env (t:typ) : ML (option _) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral | _ -> None let tag_and_bit_order_of_integral_typ env (t:typ) : ML (tag_and_bit_order: (option integer_type & option bitfield_bit_order) { Some? (snd tag_and_bit_order) ==> Some? (fst tag_and_bit_order) }) = match t.v with | Pointer _ -> None, None | Type_app hd _ _ -> match lookup env hd with | Inr (_, Inl attrs) -> attrs.integral, attrs.bit_order | _ -> None, None let has_reader (env:global_env) (id:ident) : ML bool = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.has_reader | _ -> false let parser_kind_nz (env:global_env) (id:ident) : ML (option bool) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> attrs.parser_kind_nz | _ -> None let parser_weak_kind (env:global_env) (id:ident) : ML (option _) = match H.try_find env.ge_h id.v with | Some (_, Inl attrs) -> Some attrs.parser_weak_kind | _ -> None let typ_weak_kind env (t:typ) : ML (option weak_kind) = match t.v with | Pointer _ -> None | Type_app hd _ _ -> parser_weak_kind env.globals hd let typ_has_reader env (t:typ) : ML bool = match t.v with | Pointer _ -> false | Type_app hd _ _ -> has_reader env.globals hd let rec unfold_typ_abbrev_only (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match try_lookup env hd with | Some (Inr (d, _)) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_only env t | _ -> t end | _ -> t end | _ -> t let update_typ_abbrev (env:env) (i:ident) (t:typ) : ML unit = match H.try_find env.globals.ge_h i.v with | Some (d, ms) -> let d_decl = match d.d_decl.v with | TypeAbbrev _ _ -> {d.d_decl with v = TypeAbbrev t i } | _ -> failwith "Expected a type abbreviation" in let d = {d with d_decl = d_decl } in let entry = (d, ms) in H.insert env.globals.ge_h i.v entry | _ -> failwith "Type abbreviation not found" let rec unfold_typ_abbrev_and_enum (env:env) (t:typ) : ML typ = match t.v with | Type_app hd _ [] -> //type abbreviations are not parameterized begin match lookup env hd with | Inr (d, _) -> begin match d.d_decl.v with | TypeAbbrev t _ -> unfold_typ_abbrev_and_enum env t | Enum t _ _ -> unfold_typ_abbrev_and_enum env t | _ -> t end | _ -> t end | _ -> t let size_of_integral_typ (env:env) (t:typ) r : ML int = let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_of_integral_typ env t with | None -> failwith "Impossible" | Some UInt8 -> 1 | Some UInt16 -> 2 | Some UInt32 -> 4 | Some UInt64 -> 8 let bit_order_of_integral_typ (env:env) (t:typ) r : ML bitfield_bit_order = let t = unfold_typ_abbrev_and_enum env t in if not (typ_is_integral env t) then error (Printf.sprintf "Expected and integral type, got %s" (print_typ t)) r; match tag_and_bit_order_of_integral_typ env t with | _, None -> failwith "Impossible" | _, Some order -> order let eq_typ env t1 t2 = if Ast.eq_typ t1 t2 then true else Ast.eq_typ (unfold_typ_abbrev_and_enum env t1) (unfold_typ_abbrev_and_enum env t2) let eq_typs env ts = List.for_all (fun (t1, t2) -> eq_typ env t1 t2) ts let cast e t t' = { e with v = App (Cast (Some t) t') [e] } let try_cast_integer env et to : ML (option expr) = let e, from = et in let i_to = typ_is_integral env to in let i_from = typ_is_integral env from in if i_from && i_to then let i_from = typ_as_integer_type (unfold_typ_abbrev_and_enum env from) in let i_to = typ_as_integer_type (unfold_typ_abbrev_and_enum env to) in if i_from = i_to then Some e else if integer_type_leq i_from i_to then Some (cast e i_from i_to) else None else None let _or_ b1 b2 = b1 || b2 let _and_ b1 b2 = b1 && b2 let try_retype_arith_exprs (env:env) e1 e2 rng : ML (option (expr & expr & typ))= let e1, t1 = e1 in let e2, t2 = e2 in let fail #a i : ML a = raise (Error (Printf.sprintf "(%d) Failed to retype exprs (%s : %s) and (%s : %s)" i (print_expr e1) (print_typ t1) (print_expr e2) (print_typ t2))) in try let t1, t2 = unfold_typ_abbrev_and_enum env t1, unfold_typ_abbrev_and_enum env t2 in if not (typ_is_integral env t1 `_and_` typ_is_integral env t2) then fail 1; let tt1 = typ_as_integer_type t1 in let tt2 = typ_as_integer_type t2 in let cast e t t' = { e with v = App (Cast (Some t) t') [e] } in let e1, e2, t = if integer_type_leq tt1 tt2 then cast e1 tt1 tt2, e2, t2 else if integer_type_leq tt2 tt1 then e1, cast e2 tt2 tt1, t1 else fail 0 in // FStar.IO.print_string // (Printf.sprintf "Retyped to (%s, %s, %s)\n" // (print_expr e1) // (print_expr e2) // (print_typ t)); Some (e1, e2, t) with | Error msg -> FStar.IO.print_string msg; None | _ -> None (* * Add output type to the environment * * TODO: check_shadow *) let add_output_type (ge:global_env) (i:ident) (d:decl{OutputType? d.d_decl.v}) : ML unit = let insert i = H.insert ge.ge_out_t i d in insert i.v; let td_abbrev = (OutputType?._0 d.d_decl.v).out_typ_names.typedef_abbrev in insert td_abbrev.v (* * Add extern type to the environment * * TODO: check shadow *) let add_extern_type (ge:global_env) (i:ident) (d:decl{ExternType? d.d_decl.v}) : ML unit = let insert i = H.insert ge.ge_extern_t i d in insert i.v; let td_abbrev = (ExternType?._0 d.d_decl.v).typedef_abbrev in insert td_abbrev.v (* * Add extern function to the environment * * TODO: check shadow *) let add_extern_fn (ge:global_env) (i:ident) (d:decl{ExternFn? d.d_decl.v}) : ML unit = H.insert ge.ge_extern_fn i.v d let lookup_output_type (ge:global_env) (i:ident) : ML out_typ = match H.try_find ge.ge_out_t i.v with | Some ({d_decl={v=OutputType out_t}}) -> out_t | _ -> error (Printf.sprintf "Cannot find output type %s" (ident_to_string i)) i.range (* * Returns the type of the field, with optional bitwidth if the field is a bitfield *) let lookup_output_type_field (ge:global_env) (i f:ident) : ML (typ & option int) = let out_t = lookup_output_type ge i in let rec find (flds:list out_field) : (option (typ & option int)) = match flds with | [] -> None | (Out_field_named f' t n)::tl -> if eq_idents f f' then Some (t, n) else find tl | (Out_field_anon l _)::tl -> (match find l with | None -> find tl | Some t -> Some t) in match find out_t.out_typ_fields with | Some t -> t | None -> error (Printf.sprintf "Cannot find output field %s:%s" (ident_to_string i) (ident_to_string f)) f.range let lookup_extern_type (ge:global_env) (i:ident) : ML unit = match H.try_find ge.ge_extern_t i.v with | Some ({d_decl={v=ExternType _}}) -> () | _ -> error (Printf.sprintf "Cannot find declaration for extern type %s" (ident_to_string i)) i.range let lookup_extern_fn (ge:global_env) (f:ident) : ML (typ & list param) = match H.try_find ge.ge_extern_fn f.v with | Some ({d_decl={v=ExternFn _ ret ps}}) -> ret, ps | _ -> error (Printf.sprintf "Cannot find declaration for extern function %s" (ident_to_string f)) f.range let check_output_type (ge:global_env) (t:typ) : ML ident = let err () : ML ident = error (Printf.sprintf "Type %s is not an output type" (print_typ t)) t.range in match t.v with | Type_app i KindOutput [] -> i | _ -> err () /// Populated the output expression metadata /// /// We enforce that the spec cannot take address of output type bitfields let rec check_out_expr (env:env) (oe0:out_expr) : ML (oe:out_expr{Some? oe.out_expr_meta}) =
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val check_out_expr (env: env) (oe0: out_expr) : ML (oe: out_expr{Some? oe.out_expr_meta})
[ "recursion" ]
Binding.check_out_expr
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
env: Binding.env -> oe0: Ast.out_expr -> FStar.All.ML (oe: Ast.out_expr{Some? (Mkout_expr?.out_expr_meta oe)})
{ "end_col": 56, "end_line": 606, "start_col": 2, "start_line": 523 }
FStar.All.ML
val mk_env (g:global_env) : ML env
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g }
val mk_env (g:global_env) : ML env let mk_env (g: global_env) =
true
null
false
{ this = None; locals = H.create 10; globals = g }
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "GlobalEnv.global_env", "Binding.Mkenv", "FStar.Pervasives.Native.None", "Ast.ident", "Binding.env", "Binding.local_env", "Hashtable.create", "Ast.ident'", "FStar.Pervasives.Native.tuple3", "Ast.typ", "Prims.bool", "Hashtable.t" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; }
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mk_env (g:global_env) : ML env
[]
Binding.mk_env
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
g: GlobalEnv.global_env -> FStar.All.ML Binding.env
{ "end_col": 15, "end_line": 52, "start_col": 4, "start_line": 50 }
FStar.All.ALL
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> ()
let check_shadow (e: H.t ident' 'a) (i: ident) (r: range) =
true
null
false
match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> ()
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[]
[ "Hashtable.t", "Ast.ident'", "Ast.ident", "Ast.range", "Ast.error", "Prims.unit", "Ast.__proj__Mkwith_meta_t__item__range", "Prims.string", "FStar.Printf.sprintf", "Ast.ident_to_string", "FStar.Pervasives.Native.option", "Hashtable.try_find", "Ast.__proj__Mkwith_meta_t__item__v" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val check_shadow : e: Hashtable.t Ast.ident' 'a -> i: Ast.ident -> r: Ast.range -> FStar.All.ALL Prims.unit
[]
Binding.check_shadow
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
e: Hashtable.t Ast.ident' 'a -> i: Ast.ident -> r: Ast.range -> FStar.All.ALL Prims.unit
{ "end_col": 11, "end_line": 87, "start_col": 2, "start_line": 83 }
FStar.All.ALL
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals }
let copy_env (e: env) =
true
null
false
let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals }
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "trivial_postcondition" ]
[ "Binding.env", "Binding.Mkenv", "Binding.__proj__Mkenv__item__this", "Binding.__proj__Mkenv__item__globals", "Prims.unit", "Hashtable.iter", "Ast.ident'", "FStar.Pervasives.Native.tuple3", "Ast.typ", "Prims.bool", "Hashtable.insert", "Binding.__proj__Mkenv__item__locals", "Hashtable.t", "Hashtable.create" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g }
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val copy_env : e: Binding.env -> FStar.All.ALL Binding.env
[]
Binding.copy_env
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
e: Binding.env -> FStar.All.ALL Binding.env
{ "end_col": 3, "end_line": 61, "start_col": 22, "start_line": 54 }
FStar.All.ML
val is_used (e: env) (i: ident) : ML bool
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let is_used (e:env) (i:ident) : ML bool = match H.try_find e.locals i.v with | Some (_, t, b) -> b | _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range
val is_used (e: env) (i: ident) : ML bool let is_used (e: env) (i: ident) : ML bool =
true
null
false
match H.try_find e.locals i.v with | Some (_, t, b) -> b | _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "Binding.env", "Ast.ident", "Ast.ident'", "Ast.typ", "Prims.bool", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple3", "Ast.error", "FStar.Printf.sprintf", "Ast.ident_to_string", "Ast.__proj__Mkwith_meta_t__item__range", "Hashtable.try_find", "Binding.__proj__Mkenv__item__locals", "Ast.__proj__Mkwith_meta_t__item__v" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range let lookup_macro_definition (e:env) (i:ident) = try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None let try_lookup_enum_cases (e:env) (i:ident) : ML (option (list ident & typ)) = match lookup e i with | Inr ({d_decl={v=Enum t _ tags}}, _) -> Some (Desugar.check_desugared_enum_cases tags, t) | _ -> None let lookup_enum_cases (e:env) (i:ident) : ML (list ident & typ) = match try_lookup_enum_cases e i with | Some (tags, t) -> tags, t | _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range let is_enum (e:env) (t:typ) = match t.v with | Type_app i KindSpec [] -> Some? (try_lookup_enum_cases e i) | _ -> false
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val is_used (e: env) (i: ident) : ML bool
[]
Binding.is_used
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
e: Binding.env -> i: Ast.ident -> FStar.All.ML Prims.bool
{ "end_col": 84, "end_line": 220, "start_col": 2, "start_line": 218 }
FStar.All.ML
val parser_may_fail (env: env) (t: typ) : ML bool
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parser_may_fail (env:env) (t:typ) : ML bool = match t.v with | Pointer _ -> true | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> attrs.may_fail | _ -> false
val parser_may_fail (env: env) (t: typ) : ML bool let parser_may_fail (env: env) (t: typ) : ML bool =
true
null
false
match t.v with | Pointer _ -> true | Type_app hd _ _ -> match lookup env hd with | Inr (d, Inl attrs) -> attrs.may_fail | _ -> false
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "Binding.env", "Ast.typ", "Ast.__proj__Mkwith_meta_t__item__v", "Ast.typ'", "Ast.with_meta_t", "Prims.bool", "Ast.ident", "Ast.t_kind", "Prims.list", "Ast.either", "Ast.expr", "Ast.out_expr", "Ast.decl", "GlobalEnv.decl_attributes", "GlobalEnv.__proj__Mkdecl_attributes__item__may_fail", "FStar.Pervasives.Native.tuple2", "GlobalEnv.macro_signature", "Binding.lookup" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v let remove_local (e:env) (i:ident) : ML unit = match H.try_find e.locals i.v with | Some (j, _, _) -> H.remove e.locals i.v; H.remove e.locals j | _ -> () let resolve_record_case_output_extern_type_name (env:env) (i:ident) = match H.try_find (global_env_of_env env).ge_out_t i.v with | Some ({d_decl={v=OutputType ({out_typ_names=names})}}) -> names.typedef_abbrev | _ -> (match H.try_find (global_env_of_env env).ge_extern_t i.v with | Some ({d_decl={v=ExternType td_names}}) -> td_names.typedef_abbrev | _ -> (match lookup env i with | Inr ({d_decl={v=Record names _ _ _}}, _) | Inr ({d_decl={v=CaseType names _ _}}, _) -> names.typedef_name | _ -> i)) let lookup_expr_name (e:env) (i:ident) : ML typ = match lookup e i with | Inl t -> t | Inr (_, Inr ({ macro_arguments_t=[]; macro_result_t=t })) -> t | Inr _ -> error (Printf.sprintf "Variable %s is not an expression identifier" (ident_to_string i)) i.range let lookup_macro_name (e:env) (i:ident) : ML macro_signature = match lookup e i with | Inr (_, Inr m) -> m | _ -> error (Printf.sprintf "%s is an unknown operator" (ident_to_string i)) i.range let lookup_macro_definition (e:env) (i:ident) = try let m = lookup_macro_name e i in m.macro_defn_t with | _ -> None let try_lookup_enum_cases (e:env) (i:ident) : ML (option (list ident & typ)) = match lookup e i with | Inr ({d_decl={v=Enum t _ tags}}, _) -> Some (Desugar.check_desugared_enum_cases tags, t) | _ -> None let lookup_enum_cases (e:env) (i:ident) : ML (list ident & typ) = match try_lookup_enum_cases e i with | Some (tags, t) -> tags, t | _ -> error (Printf.sprintf "Type %s is not an enumeration" (ident_to_string i)) i.range let is_enum (e:env) (t:typ) = match t.v with | Type_app i KindSpec [] -> Some? (try_lookup_enum_cases e i) | _ -> false let is_used (e:env) (i:ident) : ML bool = match H.try_find e.locals i.v with | Some (_, t, b) -> b | _ -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range let type_of_integer_type = function | UInt8 -> tuint8 | UInt16 -> tuint16 | UInt32 -> tuint32 | UInt64 -> tuint64 let check_integer_bounds t i = match t with | UInt8 -> FStar.UInt.fits i 8 | UInt16 -> FStar.UInt.fits i 16 | UInt32 -> FStar.UInt.fits i 32 | UInt64 -> FStar.UInt.fits i 64 let type_of_constant rng (c:constant) : ML typ = match c with | Unit -> tunit | Int tag i -> if check_integer_bounds tag i then type_of_integer_type tag else error (Printf.sprintf "Constant %d is too large for its type %s" i (Ast.print_integer_type tag)) rng | XInt tag _ -> //bounds checked by the syntax type_of_integer_type tag | Bool _ -> tbool
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parser_may_fail (env: env) (t: typ) : ML bool
[]
Binding.parser_may_fail
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
env: Binding.env -> t: Ast.typ -> FStar.All.ML Prims.bool
{ "end_col": 16, "end_line": 253, "start_col": 2, "start_line": 248 }
FStar.All.ML
val lookup (e: env) (i: ident) : ML (either typ (decl & either decl_attributes macro_signature))
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lookup (e:env) (i:ident) : ML (either typ (decl & either decl_attributes macro_signature)) = match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v
val lookup (e: env) (i: ident) : ML (either typ (decl & either decl_attributes macro_signature)) let lookup (e: env) (i: ident) : ML (either typ (decl & either decl_attributes macro_signature)) =
true
null
false
match try_lookup e i with | None -> error (Printf.sprintf "Variable %s not found" (ident_to_string i)) i.range | Some v -> v
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "Binding.env", "Ast.ident", "Ast.error", "Ast.either", "Ast.typ", "FStar.Pervasives.Native.tuple2", "Ast.decl", "GlobalEnv.decl_attributes", "GlobalEnv.macro_signature", "FStar.Printf.sprintf", "Ast.ident_to_string", "Ast.__proj__Mkwith_meta_t__item__range", "Ast.ident'", "FStar.Pervasives.Native.option", "Binding.try_lookup" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false) let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lookup (e: env) (i: ident) : ML (either typ (decl & either decl_attributes macro_signature))
[]
Binding.lookup
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
e: Binding.env -> i: Ast.ident -> FStar.All.ML (Ast.either Ast.typ (Ast.decl * Ast.either GlobalEnv.decl_attributes GlobalEnv.macro_signature))
{ "end_col": 15, "end_line": 157, "start_col": 2, "start_line": 155 }
FStar.All.ML
val try_lookup (e: env) (i: ident) : ML (option (either typ (decl & either decl_attributes macro_signature)))
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let try_lookup (e:env) (i:ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) = match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> //mark it as used H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None
val try_lookup (e: env) (i: ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) let try_lookup (e: env) (i: ident) : ML (option (either typ (decl & either decl_attributes macro_signature))) =
true
null
false
match H.try_find e.locals i.v with | Some (_, t, true) -> Some (Inl t) | Some (j, t, false) -> H.remove e.locals i.v; H.insert e.locals i.v (j, t, true); Some (Inl t) | None -> match H.try_find e.globals.ge_h i.v with | Some d -> Some (Inr d) | None -> None
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "Binding.env", "Ast.ident", "Ast.ident'", "Ast.typ", "FStar.Pervasives.Native.Some", "Ast.either", "FStar.Pervasives.Native.tuple2", "Ast.decl", "GlobalEnv.decl_attributes", "GlobalEnv.macro_signature", "Ast.Inl", "FStar.Pervasives.Native.option", "Prims.unit", "Hashtable.insert", "FStar.Pervasives.Native.tuple3", "Prims.bool", "Binding.__proj__Mkenv__item__locals", "Ast.__proj__Mkwith_meta_t__item__v", "FStar.Pervasives.Native.Mktuple3", "Hashtable.remove", "Ast.Inr", "FStar.Pervasives.Native.None", "Hashtable.try_find", "GlobalEnv.__proj__Mkglobal_env__item__ge_h", "Binding.__proj__Mkenv__item__globals" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range let add_global (e:global_env) (i:ident) (d:decl) (t:either decl_attributes macro_signature) : ML unit = let insert k v = H.insert e.ge_h k v in check_shadow e.ge_h i d.d_decl.range; let env = mk_env e in let i' = format_identifier env i in insert i.v (d, t); insert i'.v (d, t); match typedef_names d with | None -> () | Some td -> if td.typedef_abbrev.v <> i.v then begin check_shadow e.ge_h td.typedef_abbrev d.d_decl.range; let abbrev = format_identifier env td.typedef_abbrev in insert td.typedef_abbrev.v (d, t); insert abbrev.v (d, t) end let add_local (e:env) (i:ident) (t:typ) : ML unit = check_shadow e.globals.ge_h i t.range; check_shadow e.locals i t.range; let i' = format_identifier e i in H.insert e.locals i.v (i'.v, t, false); H.insert e.locals i'.v (i'.v, t, false)
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val try_lookup (e: env) (i: ident) : ML (option (either typ (decl & either decl_attributes macro_signature)))
[]
Binding.try_lookup
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
e: Binding.env -> i: Ast.ident -> FStar.All.ML (FStar.Pervasives.Native.option (Ast.either Ast.typ (Ast.decl * Ast.either GlobalEnv.decl_attributes GlobalEnv.macro_signature)))
{ "end_col": 18, "end_line": 152, "start_col": 2, "start_line": 142 }
FStar.All.ML
val format_identifier (e: env) (i: ident) : ML ident
[ { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "GlobalEnv", "short_module": null }, { "abbrev": false, "full_module": "Ast", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let format_identifier (e:env) (i:ident) : ML ident = let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0::cs -> if FStar.Char.lowercase c0 = c0 then i //it starts with a lowercase symbol; that's ok else //otherwise, add an underscore {i with v = {i.v with name=Ast.reserved_prefix ^ i.v.name}} in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. \ Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range
val format_identifier (e: env) (i: ident) : ML ident let format_identifier (e: env) (i: ident) : ML ident =
true
null
false
let j = match String.list_of_string i.v.name with | [] -> failwith "Impossible: empty identifier" | c0 :: cs -> if FStar.Char.lowercase c0 = c0 then i else { i with v = { i.v with name = Ast.reserved_prefix ^ i.v.name } } in match H.try_find e.globals.ge_h j.v, H.try_find e.locals j.v with | None, None -> j | _ -> let msg = Printf.sprintf "This name (%s) starts will clash with another name in scope (%s) as it is translated. Please rename it" (ident_to_string i) (ident_to_string j) in error msg i.range
{ "checked_file": "Binding.fst.checked", "dependencies": [ "prims.fst.checked", "Options.fsti.checked", "Hashtable.fsti.checked", "GlobalEnv.fst.checked", "FStar.UInt.fsti.checked", "FStar.String.fsti.checked", "FStar.ST.fst.checked", "FStar.Printf.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.IO.fst.checked", "FStar.Char.fsti.checked", "FStar.All.fst.checked", "Desugar.fst.checked", "Deps.fsti.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "Binding.fst" }
[ "ml" ]
[ "Binding.env", "Ast.ident", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.option", "Ast.decl", "Ast.either", "GlobalEnv.decl_attributes", "GlobalEnv.macro_signature", "FStar.Pervasives.Native.tuple3", "Ast.ident'", "Ast.typ", "Prims.bool", "Ast.error", "Ast.__proj__Mkwith_meta_t__item__range", "Prims.string", "FStar.Printf.sprintf", "Ast.ident_to_string", "FStar.Pervasives.Native.Mktuple2", "Hashtable.try_find", "Binding.__proj__Mkenv__item__locals", "Ast.__proj__Mkwith_meta_t__item__v", "GlobalEnv.__proj__Mkglobal_env__item__ge_h", "Binding.__proj__Mkenv__item__globals", "Ast.with_meta_t", "FStar.String.list_of_string", "Ast.__proj__Mkident'__item__name", "FStar.All.failwith", "FStar.String.char", "Prims.list", "Prims.op_Equality", "FStar.Char.char", "FStar.Char.lowercase", "Ast.Mkwith_meta_t", "Ast.Mkident'", "Ast.__proj__Mkident'__item__modul_name", "Prims.op_Hat", "Ast.reserved_prefix", "Ast.__proj__Mkwith_meta_t__item__comments" ]
[]
(* 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 as copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Binding (* This module implements a pass over the source AST -- checking that all names are properly bound -- well-typed -- computing the size of types -- computing which fields are dependent on others *) open FStar.Mul open FStar.List.Tot open Ast open FStar.All module H = Hashtable include GlobalEnv /// Maps locally bound names, i.e., a field name to its type /// -- the bool signifies that this identifier has been used, and is /// therefore marked as a dependent field /// /// The modul_name in these ident' must be None -- TODO: add a refinement? let local_env = H.t ident' (ident' & typ & bool) /// `env` includes both a global and local env, together with a /// binding for the `this` variable (bound to the name of a type) in /// the current scope noeq type env = { this: option ident; locals: local_env; globals: global_env; } let mk_env (g:global_env) = { this = None; locals = H.create 10; globals = g } let copy_env (e:env) = let locals = H.create 10 in H.iter (fun k v -> H.insert locals k v) e.locals; { this = e.this; globals = e.globals; locals = locals } let env_of_global_env : global_env -> env = let locals = H.create 1 in fun g -> { this = None; locals; globals = g } let global_env_of_env e = e.globals let params_of_decl (d:decl) : list param = match d.d_decl.v with | ModuleAbbrev _ _ | Define _ _ _ | TypeAbbrev _ _ | Enum _ _ _ -> [] | Record _ params _ _ | CaseType _ params _ -> params | OutputType _ -> [] | ExternType _ -> [] | ExternFn _ _ ps -> ps let check_shadow (e:H.t ident' 'a) (i:ident) (r:range) = match H.try_find e i.v with | Some j -> let msg = Printf.sprintf "Declaration %s clashes with previous declaration" (ident_to_string i) in error msg i.range | _ -> () let typedef_names (d:decl) : option typedef_names = match d.d_decl.v with | Record td _ _ _ | CaseType td _ _ -> Some td | _ -> None
false
false
Binding.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val format_identifier (e: env) (i: ident) : ML ident
[]
Binding.format_identifier
{ "file_name": "src/3d/Binding.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
e: Binding.env -> i: Ast.ident -> FStar.All.ML Ast.ident
{ "end_col": 21, "end_line": 113, "start_col": 52, "start_line": 95 }