file_name
stringlengths 5
52
| name
stringlengths 4
95
| original_source_type
stringlengths 0
23k
| source_type
stringlengths 9
23k
| source_definition
stringlengths 9
57.9k
| source
dict | source_range
dict | file_context
stringlengths 0
721k
| dependencies
dict | opens_and_abbrevs
listlengths 2
94
| vconfig
dict | interleaved
bool 1
class | verbose_type
stringlengths 1
7.42k
| effect
stringclasses 118
values | effect_flags
sequencelengths 0
2
| mutual_with
sequencelengths 0
11
| ideal_premises
sequencelengths 0
236
| proof_features
sequencelengths 0
1
| is_simple_lemma
bool 2
classes | is_div
bool 2
classes | is_proof
bool 2
classes | is_simply_typed
bool 2
classes | is_type
bool 2
classes | partial_definition
stringlengths 5
3.99k
| completed_definiton
stringlengths 1
1.63M
| isa_cross_project_example
bool 1
class |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Vale.Bignum.Lemmas.fsti | Vale.Bignum.Lemmas.seq_add | val seq_add (#n: nat) (as0 bs: seq (natN n)) (c0: nat1)
: Pure (seq (natN n) & nat1)
(requires length as0 == length bs)
(ensures fun (xs, _) -> length xs == length as0) | val seq_add (#n: nat) (as0 bs: seq (natN n)) (c0: nat1)
: Pure (seq (natN n) & nat1)
(requires length as0 == length bs)
(ensures fun (xs, _) -> length xs == length as0) | let seq_add (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) : Pure (seq (natN n) & nat1)
(requires length as0 == length bs)
(ensures fun (xs, _) -> length xs == length as0)
=
let f (i:nat{i < length as0}) = seq_add_i as0 bs c0 i in
(init (length as0) f, seq_add_c as0 bs c0 (length as0)) | {
"file_name": "vale/code/crypto/bignum/Vale.Bignum.Lemmas.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 57,
"end_line": 27,
"start_col": 0,
"start_line": 22
} | module Vale.Bignum.Lemmas
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Bignum.Defs
unfold let (.[]) = Seq.index
let rec seq_add_c (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure nat1
(requires length as0 == length bs /\ i <= length as0)
(ensures fun _ -> True)
=
if i = 0 then c0 else add_hi as0.[i - 1] bs.[i - 1] (seq_add_c as0 bs c0 (i - 1))
let seq_add_i (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure (natN n)
(requires length as0 == length bs /\ i < length as0)
(ensures fun _ -> True)
=
add_lo as0.[i] bs.[i] (seq_add_c as0 bs c0 i) | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Bignum.Defs.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Bignum.Lemmas.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
as0: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) ->
bs: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) ->
c0: Vale.Def.Words_s.nat1
-> Prims.Pure (FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) * Vale.Def.Words_s.nat1) | Prims.Pure | [] | [] | [
"Prims.nat",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.natN",
"Vale.Def.Words_s.nat1",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Seq.Base.init",
"FStar.Seq.Base.length",
"Vale.Bignum.Lemmas.seq_add_c",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.Bignum.Lemmas.seq_add_i",
"FStar.Pervasives.Native.tuple2",
"Prims.eq2"
] | [] | false | false | false | false | false | let seq_add (#n: nat) (as0 bs: seq (natN n)) (c0: nat1)
: Pure (seq (natN n) & nat1)
(requires length as0 == length bs)
(ensures fun (xs, _) -> length xs == length as0) =
| let f (i: nat{i < length as0}) = seq_add_i as0 bs c0 i in
(init (length as0) f, seq_add_c as0 bs c0 (length as0)) | false |
Vale.Bignum.Lemmas.fsti | Vale.Bignum.Lemmas.seq_scale_lo | val seq_scale_lo (#n: pos) (a: natN n) (bs: seq (natN n))
: Pure (seq (natN n)) (requires True) (ensures fun xs -> length xs = length bs + 1) | val seq_scale_lo (#n: pos) (a: natN n) (bs: seq (natN n))
: Pure (seq (natN n)) (requires True) (ensures fun xs -> length xs = length bs + 1) | let seq_scale_lo (#n:pos) (a:natN n) (bs:seq (natN n)) : Pure (seq (natN n))
(requires True)
(ensures fun xs -> length xs = length bs + 1)
=
let f (i:nat{i <= length bs}) : natN n = if i = length bs then 0 else mul_lo a bs.[i] in
init (length bs + 1) f | {
"file_name": "vale/code/crypto/bignum/Vale.Bignum.Lemmas.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 24,
"end_line": 37,
"start_col": 0,
"start_line": 32
} | module Vale.Bignum.Lemmas
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Bignum.Defs
unfold let (.[]) = Seq.index
let rec seq_add_c (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure nat1
(requires length as0 == length bs /\ i <= length as0)
(ensures fun _ -> True)
=
if i = 0 then c0 else add_hi as0.[i - 1] bs.[i - 1] (seq_add_c as0 bs c0 (i - 1))
let seq_add_i (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure (natN n)
(requires length as0 == length bs /\ i < length as0)
(ensures fun _ -> True)
=
add_lo as0.[i] bs.[i] (seq_add_c as0 bs c0 i)
// as0 + bs
let seq_add (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) : Pure (seq (natN n) & nat1)
(requires length as0 == length bs)
(ensures fun (xs, _) -> length xs == length as0)
=
let f (i:nat{i < length as0}) = seq_add_i as0 bs c0 i in
(init (length as0) f, seq_add_c as0 bs c0 (length as0))
let last_carry (a b:nat) (c:nat1) : int =
if c = 0 then 0 else pow_int a b | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Bignum.Defs.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Bignum.Lemmas.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Vale.Def.Words_s.natN n -> bs: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n)
-> Prims.Pure (FStar.Seq.Base.seq (Vale.Def.Words_s.natN n)) | Prims.Pure | [] | [] | [
"Prims.pos",
"Vale.Def.Words_s.natN",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.init",
"Prims.op_Addition",
"FStar.Seq.Base.length",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Equality",
"Prims.bool",
"Vale.Bignum.Defs.mul_lo",
"Vale.Bignum.Lemmas.op_String_Access",
"Prims.l_True",
"Prims.int"
] | [] | false | false | false | false | false | let seq_scale_lo (#n: pos) (a: natN n) (bs: seq (natN n))
: Pure (seq (natN n)) (requires True) (ensures fun xs -> length xs = length bs + 1) =
| let f (i: nat{i <= length bs}) : natN n = if i = length bs then 0 else mul_lo a bs.[ i ] in
init (length bs + 1) f | false |
Vale.Bignum.Lemmas.fsti | Vale.Bignum.Lemmas.seq_add_is_norm | val seq_add_is_norm (#n: nat) (as0 bs: seq (natN n)) (c0: nat1) (i: nat)
: Pure Type0 (requires length as0 == length bs /\ i <= length as0) (ensures fun _ -> True) | val seq_add_is_norm (#n: nat) (as0 bs: seq (natN n)) (c0: nat1) (i: nat)
: Pure Type0 (requires length as0 == length bs /\ i <= length as0) (ensures fun _ -> True) | let seq_add_is_norm (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure Type0
(requires length as0 == length bs /\ i <= length as0)
(ensures fun _ -> True)
=
norm [iota; zeta; primops; delta_only [`%seq_add_is]] (seq_add_is as0 bs c0 i) | {
"file_name": "vale/code/crypto/bignum/Vale.Bignum.Lemmas.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 80,
"end_line": 73,
"start_col": 7,
"start_line": 69
} | module Vale.Bignum.Lemmas
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Bignum.Defs
unfold let (.[]) = Seq.index
let rec seq_add_c (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure nat1
(requires length as0 == length bs /\ i <= length as0)
(ensures fun _ -> True)
=
if i = 0 then c0 else add_hi as0.[i - 1] bs.[i - 1] (seq_add_c as0 bs c0 (i - 1))
let seq_add_i (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure (natN n)
(requires length as0 == length bs /\ i < length as0)
(ensures fun _ -> True)
=
add_lo as0.[i] bs.[i] (seq_add_c as0 bs c0 i)
// as0 + bs
let seq_add (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) : Pure (seq (natN n) & nat1)
(requires length as0 == length bs)
(ensures fun (xs, _) -> length xs == length as0)
=
let f (i:nat{i < length as0}) = seq_add_i as0 bs c0 i in
(init (length as0) f, seq_add_c as0 bs c0 (length as0))
let last_carry (a b:nat) (c:nat1) : int =
if c = 0 then 0 else pow_int a b
let seq_scale_lo (#n:pos) (a:natN n) (bs:seq (natN n)) : Pure (seq (natN n))
(requires True)
(ensures fun xs -> length xs = length bs + 1)
=
let f (i:nat{i <= length bs}) : natN n = if i = length bs then 0 else mul_lo a bs.[i] in
init (length bs + 1) f
let seq_scale_hi (#n:pos) (a:natN n) (bs:seq (natN n)) (d:natN n) : Pure (seq (natN n))
(requires True)
(ensures fun xs -> length xs = length bs + 1)
=
let f (i:nat{i <= length bs}) : natN n = if i = 0 then d else mul_hi a bs.[i - 1] in
init (length bs + 1) f
// a * bs + d
let seq_scale (#n:pos) (a:natN n) (bs:seq (natN n)) (d:natN n) : Pure (seq (natN n))
(requires True)
(ensures fun xs -> length xs = length bs + 1)
=
fst (seq_add (seq_scale_lo a bs) (seq_scale_hi a bs d) 0)
val lemma_sum_seq_left_right (s:seq int) (i j:nat) : Lemma
(requires i <= j /\ j <= length s)
(ensures sum_seq_left s i j == sum_seq_right s i j)
val lemma_pow_nat (a:nat) (b:nat) : Lemma (0 <= pow_int a b)
val lemma_sum_pow_seq_bound (#n:nat) (s:seq (natN n)) : Lemma
(ensures 0 <= sum_pow_seq s /\ sum_pow_seq s < pow_int n (length s))
let rec seq_add_is (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure Type0
(requires length as0 == length bs /\ i <= length as0)
(ensures fun _ -> True)
=
if i = 0 then True else
seq_add_is as0 bs c0 (i - 1) /\ (fst (seq_add as0 bs c0)).[i - 1] == seq_add_i as0 bs c0 (i - 1) | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Bignum.Defs.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Bignum.Lemmas.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
as0: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) ->
bs: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) ->
c0: Vale.Def.Words_s.nat1 ->
i: Prims.nat
-> Prims.Pure Type0 | Prims.Pure | [] | [] | [
"Prims.nat",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.natN",
"Vale.Def.Words_s.nat1",
"FStar.Pervasives.norm",
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.iota",
"FStar.Pervasives.zeta",
"FStar.Pervasives.primops",
"FStar.Pervasives.delta_only",
"Prims.string",
"Prims.Nil",
"Vale.Bignum.Lemmas.seq_add_is",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.length",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.l_True"
] | [] | false | false | false | false | true | let seq_add_is_norm (#n: nat) (as0 bs: seq (natN n)) (c0: nat1) (i: nat)
: Pure Type0 (requires length as0 == length bs /\ i <= length as0) (ensures fun _ -> True) =
| norm [iota; zeta; primops; delta_only [`%seq_add_is]] (seq_add_is as0 bs c0 i) | false |
Vale.Bignum.Lemmas.fsti | Vale.Bignum.Lemmas.seq_scale | val seq_scale (#n: pos) (a: natN n) (bs: seq (natN n)) (d: natN n)
: Pure (seq (natN n)) (requires True) (ensures fun xs -> length xs = length bs + 1) | val seq_scale (#n: pos) (a: natN n) (bs: seq (natN n)) (d: natN n)
: Pure (seq (natN n)) (requires True) (ensures fun xs -> length xs = length bs + 1) | let seq_scale (#n:pos) (a:natN n) (bs:seq (natN n)) (d:natN n) : Pure (seq (natN n))
(requires True)
(ensures fun xs -> length xs = length bs + 1)
=
fst (seq_add (seq_scale_lo a bs) (seq_scale_hi a bs d) 0) | {
"file_name": "vale/code/crypto/bignum/Vale.Bignum.Lemmas.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 59,
"end_line": 51,
"start_col": 0,
"start_line": 47
} | module Vale.Bignum.Lemmas
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Bignum.Defs
unfold let (.[]) = Seq.index
let rec seq_add_c (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure nat1
(requires length as0 == length bs /\ i <= length as0)
(ensures fun _ -> True)
=
if i = 0 then c0 else add_hi as0.[i - 1] bs.[i - 1] (seq_add_c as0 bs c0 (i - 1))
let seq_add_i (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure (natN n)
(requires length as0 == length bs /\ i < length as0)
(ensures fun _ -> True)
=
add_lo as0.[i] bs.[i] (seq_add_c as0 bs c0 i)
// as0 + bs
let seq_add (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) : Pure (seq (natN n) & nat1)
(requires length as0 == length bs)
(ensures fun (xs, _) -> length xs == length as0)
=
let f (i:nat{i < length as0}) = seq_add_i as0 bs c0 i in
(init (length as0) f, seq_add_c as0 bs c0 (length as0))
let last_carry (a b:nat) (c:nat1) : int =
if c = 0 then 0 else pow_int a b
let seq_scale_lo (#n:pos) (a:natN n) (bs:seq (natN n)) : Pure (seq (natN n))
(requires True)
(ensures fun xs -> length xs = length bs + 1)
=
let f (i:nat{i <= length bs}) : natN n = if i = length bs then 0 else mul_lo a bs.[i] in
init (length bs + 1) f
let seq_scale_hi (#n:pos) (a:natN n) (bs:seq (natN n)) (d:natN n) : Pure (seq (natN n))
(requires True)
(ensures fun xs -> length xs = length bs + 1)
=
let f (i:nat{i <= length bs}) : natN n = if i = 0 then d else mul_hi a bs.[i - 1] in
init (length bs + 1) f | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Bignum.Defs.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Bignum.Lemmas.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Vale.Def.Words_s.natN n ->
bs: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) ->
d: Vale.Def.Words_s.natN n
-> Prims.Pure (FStar.Seq.Base.seq (Vale.Def.Words_s.natN n)) | Prims.Pure | [] | [] | [
"Prims.pos",
"Vale.Def.Words_s.natN",
"FStar.Seq.Base.seq",
"FStar.Pervasives.Native.fst",
"Vale.Def.Words_s.nat1",
"Vale.Bignum.Lemmas.seq_add",
"Vale.Bignum.Lemmas.seq_scale_lo",
"Vale.Bignum.Lemmas.seq_scale_hi",
"Prims.l_True",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"Prims.op_Addition"
] | [] | false | false | false | false | false | let seq_scale (#n: pos) (a: natN n) (bs: seq (natN n)) (d: natN n)
: Pure (seq (natN n)) (requires True) (ensures fun xs -> length xs = length bs + 1) =
| fst (seq_add (seq_scale_lo a bs) (seq_scale_hi a bs d) 0) | false |
Vale.Bignum.Lemmas.fsti | Vale.Bignum.Lemmas.seq_add_c | val seq_add_c (#n: nat) (as0 bs: seq (natN n)) (c0: nat1) (i: nat)
: Pure nat1 (requires length as0 == length bs /\ i <= length as0) (ensures fun _ -> True) | val seq_add_c (#n: nat) (as0 bs: seq (natN n)) (c0: nat1) (i: nat)
: Pure nat1 (requires length as0 == length bs /\ i <= length as0) (ensures fun _ -> True) | let rec seq_add_c (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure nat1
(requires length as0 == length bs /\ i <= length as0)
(ensures fun _ -> True)
=
if i = 0 then c0 else add_hi as0.[i - 1] bs.[i - 1] (seq_add_c as0 bs c0 (i - 1)) | {
"file_name": "vale/code/crypto/bignum/Vale.Bignum.Lemmas.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 83,
"end_line": 13,
"start_col": 0,
"start_line": 9
} | module Vale.Bignum.Lemmas
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Bignum.Defs
unfold let (.[]) = Seq.index | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Bignum.Defs.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Bignum.Lemmas.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
as0: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) ->
bs: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) ->
c0: Vale.Def.Words_s.nat1 ->
i: Prims.nat
-> Prims.Pure Vale.Def.Words_s.nat1 | Prims.Pure | [] | [] | [
"Prims.nat",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.natN",
"Vale.Def.Words_s.nat1",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"Vale.Bignum.Defs.add_hi",
"Vale.Bignum.Lemmas.op_String_Access",
"Prims.op_Subtraction",
"Vale.Bignum.Lemmas.seq_add_c",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.length",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.l_True"
] | [
"recursion"
] | false | false | false | false | false | let rec seq_add_c (#n: nat) (as0 bs: seq (natN n)) (c0: nat1) (i: nat)
: Pure nat1 (requires length as0 == length bs /\ i <= length as0) (ensures fun _ -> True) =
| if i = 0 then c0 else add_hi as0.[ i - 1 ] bs.[ i - 1 ] (seq_add_c as0 bs c0 (i - 1)) | false |
Vale.Bignum.Lemmas.fsti | Vale.Bignum.Lemmas.ys_init | val ys_init (#n: nat) (a: natN n) (bs: seq (natN n)) (i: nat{i <= length bs}) : natN n | val ys_init (#n: nat) (a: natN n) (bs: seq (natN n)) (i: nat{i <= length bs}) : natN n | let ys_init (#n:nat) (a:natN n) (bs:seq (natN n)) (i:nat{i <= length bs}) : natN n =
if i = length bs then 0 else mul_lo a bs.[i] | {
"file_name": "vale/code/crypto/bignum/Vale.Bignum.Lemmas.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 46,
"end_line": 103,
"start_col": 0,
"start_line": 102
} | module Vale.Bignum.Lemmas
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Bignum.Defs
unfold let (.[]) = Seq.index
let rec seq_add_c (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure nat1
(requires length as0 == length bs /\ i <= length as0)
(ensures fun _ -> True)
=
if i = 0 then c0 else add_hi as0.[i - 1] bs.[i - 1] (seq_add_c as0 bs c0 (i - 1))
let seq_add_i (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure (natN n)
(requires length as0 == length bs /\ i < length as0)
(ensures fun _ -> True)
=
add_lo as0.[i] bs.[i] (seq_add_c as0 bs c0 i)
// as0 + bs
let seq_add (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) : Pure (seq (natN n) & nat1)
(requires length as0 == length bs)
(ensures fun (xs, _) -> length xs == length as0)
=
let f (i:nat{i < length as0}) = seq_add_i as0 bs c0 i in
(init (length as0) f, seq_add_c as0 bs c0 (length as0))
let last_carry (a b:nat) (c:nat1) : int =
if c = 0 then 0 else pow_int a b
let seq_scale_lo (#n:pos) (a:natN n) (bs:seq (natN n)) : Pure (seq (natN n))
(requires True)
(ensures fun xs -> length xs = length bs + 1)
=
let f (i:nat{i <= length bs}) : natN n = if i = length bs then 0 else mul_lo a bs.[i] in
init (length bs + 1) f
let seq_scale_hi (#n:pos) (a:natN n) (bs:seq (natN n)) (d:natN n) : Pure (seq (natN n))
(requires True)
(ensures fun xs -> length xs = length bs + 1)
=
let f (i:nat{i <= length bs}) : natN n = if i = 0 then d else mul_hi a bs.[i - 1] in
init (length bs + 1) f
// a * bs + d
let seq_scale (#n:pos) (a:natN n) (bs:seq (natN n)) (d:natN n) : Pure (seq (natN n))
(requires True)
(ensures fun xs -> length xs = length bs + 1)
=
fst (seq_add (seq_scale_lo a bs) (seq_scale_hi a bs d) 0)
val lemma_sum_seq_left_right (s:seq int) (i j:nat) : Lemma
(requires i <= j /\ j <= length s)
(ensures sum_seq_left s i j == sum_seq_right s i j)
val lemma_pow_nat (a:nat) (b:nat) : Lemma (0 <= pow_int a b)
val lemma_sum_pow_seq_bound (#n:nat) (s:seq (natN n)) : Lemma
(ensures 0 <= sum_pow_seq s /\ sum_pow_seq s < pow_int n (length s))
let rec seq_add_is (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure Type0
(requires length as0 == length bs /\ i <= length as0)
(ensures fun _ -> True)
=
if i = 0 then True else
seq_add_is as0 bs c0 (i - 1) /\ (fst (seq_add as0 bs c0)).[i - 1] == seq_add_i as0 bs c0 (i - 1)
unfold let seq_add_is_norm (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure Type0
(requires length as0 == length bs /\ i <= length as0)
(ensures fun _ -> True)
=
norm [iota; zeta; primops; delta_only [`%seq_add_is]] (seq_add_is as0 bs c0 i)
val lemma_seq_add_is_norm (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Lemma
(requires length as0 == length bs /\ i <= length as0)
(ensures seq_add_is as0 bs c0 i == seq_add_is_norm as0 bs c0 i)
val lemma_last_carry_mul (a b:nat) (c:nat1) : Lemma (last_carry a b c == c * pow_int a b)
val lemma_add_lo_mul_right (#n:nat) (a b:natN n) (c:nat1) (m:int) : Lemma
(add_lo a b c * m == (let x = a * m + b * m + c * m in if a + b + c < n then x else x - n * m))
val lemma_seq_add (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) : Lemma
(requires length bs == length as0)
(ensures (
let (xs, ci) = seq_add as0 bs c0 in
sum_pow_seq xs + last_carry n (length as0) ci == sum_pow_seq as0 + sum_pow_seq bs + c0
))
val lemma_seq_scale_carry (#n:nat) (a:natN n) (bs:seq (natN n)) (d:natN n) : Lemma
(ensures (
snd (seq_add (seq_scale_lo a bs) (seq_scale_hi a bs d) 0) == 0
))
val lemma_seq_scale (#n:nat) (a:natN n) (bs:seq (natN n)) (d:natN n) : Lemma
(ensures (
sum_pow_seq (seq_scale a bs d) == sum_pow_seq (seq_scale_lo a bs) + sum_pow_seq (seq_scale_hi a bs d) /\
sum_pow_seq (seq_scale a bs d) == a * sum_pow_seq bs + d
)) | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Bignum.Defs.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Bignum.Lemmas.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Vale.Def.Words_s.natN n ->
bs: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) ->
i: Prims.nat{i <= FStar.Seq.Base.length bs}
-> Vale.Def.Words_s.natN n | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Vale.Def.Words_s.natN",
"FStar.Seq.Base.seq",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"Prims.op_Equality",
"Prims.bool",
"Vale.Bignum.Defs.mul_lo",
"Vale.Bignum.Lemmas.op_String_Access"
] | [] | false | false | false | false | false | let ys_init (#n: nat) (a: natN n) (bs: seq (natN n)) (i: nat{i <= length bs}) : natN n =
| if i = length bs then 0 else mul_lo a bs.[ i ] | false |
Vale.Bignum.Lemmas.fsti | Vale.Bignum.Lemmas.init_ys | val init_ys (#n: nat) (a: natN n) (bs: seq (natN n)) : seq (natN n) | val init_ys (#n: nat) (a: natN n) (bs: seq (natN n)) : seq (natN n) | let init_ys (#n:nat) (a:natN n) (bs:seq (natN n)) : seq (natN n) =
init (length bs + 1) (ys_init a bs) | {
"file_name": "vale/code/crypto/bignum/Vale.Bignum.Lemmas.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 37,
"end_line": 109,
"start_col": 0,
"start_line": 108
} | module Vale.Bignum.Lemmas
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Bignum.Defs
unfold let (.[]) = Seq.index
let rec seq_add_c (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure nat1
(requires length as0 == length bs /\ i <= length as0)
(ensures fun _ -> True)
=
if i = 0 then c0 else add_hi as0.[i - 1] bs.[i - 1] (seq_add_c as0 bs c0 (i - 1))
let seq_add_i (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure (natN n)
(requires length as0 == length bs /\ i < length as0)
(ensures fun _ -> True)
=
add_lo as0.[i] bs.[i] (seq_add_c as0 bs c0 i)
// as0 + bs
let seq_add (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) : Pure (seq (natN n) & nat1)
(requires length as0 == length bs)
(ensures fun (xs, _) -> length xs == length as0)
=
let f (i:nat{i < length as0}) = seq_add_i as0 bs c0 i in
(init (length as0) f, seq_add_c as0 bs c0 (length as0))
let last_carry (a b:nat) (c:nat1) : int =
if c = 0 then 0 else pow_int a b
let seq_scale_lo (#n:pos) (a:natN n) (bs:seq (natN n)) : Pure (seq (natN n))
(requires True)
(ensures fun xs -> length xs = length bs + 1)
=
let f (i:nat{i <= length bs}) : natN n = if i = length bs then 0 else mul_lo a bs.[i] in
init (length bs + 1) f
let seq_scale_hi (#n:pos) (a:natN n) (bs:seq (natN n)) (d:natN n) : Pure (seq (natN n))
(requires True)
(ensures fun xs -> length xs = length bs + 1)
=
let f (i:nat{i <= length bs}) : natN n = if i = 0 then d else mul_hi a bs.[i - 1] in
init (length bs + 1) f
// a * bs + d
let seq_scale (#n:pos) (a:natN n) (bs:seq (natN n)) (d:natN n) : Pure (seq (natN n))
(requires True)
(ensures fun xs -> length xs = length bs + 1)
=
fst (seq_add (seq_scale_lo a bs) (seq_scale_hi a bs d) 0)
val lemma_sum_seq_left_right (s:seq int) (i j:nat) : Lemma
(requires i <= j /\ j <= length s)
(ensures sum_seq_left s i j == sum_seq_right s i j)
val lemma_pow_nat (a:nat) (b:nat) : Lemma (0 <= pow_int a b)
val lemma_sum_pow_seq_bound (#n:nat) (s:seq (natN n)) : Lemma
(ensures 0 <= sum_pow_seq s /\ sum_pow_seq s < pow_int n (length s))
let rec seq_add_is (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure Type0
(requires length as0 == length bs /\ i <= length as0)
(ensures fun _ -> True)
=
if i = 0 then True else
seq_add_is as0 bs c0 (i - 1) /\ (fst (seq_add as0 bs c0)).[i - 1] == seq_add_i as0 bs c0 (i - 1)
unfold let seq_add_is_norm (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure Type0
(requires length as0 == length bs /\ i <= length as0)
(ensures fun _ -> True)
=
norm [iota; zeta; primops; delta_only [`%seq_add_is]] (seq_add_is as0 bs c0 i)
val lemma_seq_add_is_norm (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Lemma
(requires length as0 == length bs /\ i <= length as0)
(ensures seq_add_is as0 bs c0 i == seq_add_is_norm as0 bs c0 i)
val lemma_last_carry_mul (a b:nat) (c:nat1) : Lemma (last_carry a b c == c * pow_int a b)
val lemma_add_lo_mul_right (#n:nat) (a b:natN n) (c:nat1) (m:int) : Lemma
(add_lo a b c * m == (let x = a * m + b * m + c * m in if a + b + c < n then x else x - n * m))
val lemma_seq_add (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) : Lemma
(requires length bs == length as0)
(ensures (
let (xs, ci) = seq_add as0 bs c0 in
sum_pow_seq xs + last_carry n (length as0) ci == sum_pow_seq as0 + sum_pow_seq bs + c0
))
val lemma_seq_scale_carry (#n:nat) (a:natN n) (bs:seq (natN n)) (d:natN n) : Lemma
(ensures (
snd (seq_add (seq_scale_lo a bs) (seq_scale_hi a bs d) 0) == 0
))
val lemma_seq_scale (#n:nat) (a:natN n) (bs:seq (natN n)) (d:natN n) : Lemma
(ensures (
sum_pow_seq (seq_scale a bs d) == sum_pow_seq (seq_scale_lo a bs) + sum_pow_seq (seq_scale_hi a bs d) /\
sum_pow_seq (seq_scale a bs d) == a * sum_pow_seq bs + d
))
let ys_init (#n:nat) (a:natN n) (bs:seq (natN n)) (i:nat{i <= length bs}) : natN n =
if i = length bs then 0 else mul_lo a bs.[i]
let zs_init (#n:nat) (a:natN n) (bs:seq (natN n)) (d:natN n) (i:nat{i <= length bs}) : natN n =
if i = 0 then d else mul_hi a bs.[i - 1] | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Bignum.Defs.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Bignum.Lemmas.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Vale.Def.Words_s.natN n -> bs: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n)
-> FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Vale.Def.Words_s.natN",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.init",
"Prims.op_Addition",
"FStar.Seq.Base.length",
"Vale.Bignum.Lemmas.ys_init"
] | [] | false | false | false | false | false | let init_ys (#n: nat) (a: natN n) (bs: seq (natN n)) : seq (natN n) =
| init (length bs + 1) (ys_init a bs) | false |
Vale.AES.X64.GHash.fsti | Vale.AES.X64.GHash.va_wp_Compute_ghash_incremental_register | val va_wp_Compute_ghash_incremental_register (va_s0: va_state) (va_k: (va_state -> unit -> Type0))
: Type0 | val va_wp_Compute_ghash_incremental_register (va_s0: va_state) (va_k: (va_state -> unit -> Type0))
: Type0 | let va_wp_Compute_ghash_incremental_register (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) :
Type0 =
(va_get_ok va_s0 /\ (pclmulqdq_enabled /\ avx_enabled /\ sse_enabled /\ va_get_xmm 8 va_s0 ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 202182159 134810123 67438087 66051) /\ (forall
(va_x_xmm1:quad32) (va_x_efl:Vale.X64.Flags.t) (va_x_r12:nat64) (va_x_xmm2:quad32)
(va_x_xmm3:quad32) (va_x_xmm4:quad32) (va_x_xmm5:quad32) (va_x_xmm6:quad32) . let va_sM =
va_upd_xmm 6 va_x_xmm6 (va_upd_xmm 5 va_x_xmm5 (va_upd_xmm 4 va_x_xmm4 (va_upd_xmm 3 va_x_xmm3
(va_upd_xmm 2 va_x_xmm2 (va_upd_reg64 rR12 va_x_r12 (va_upd_flags va_x_efl (va_upd_xmm 1
va_x_xmm1 va_s0))))))) in va_get_ok va_sM /\ va_get_xmm 1 va_sM ==
Vale.AES.GHash.ghash_incremental (Vale.Def.Types_s.reverse_bytes_quad32 (va_get_xmm 11 va_sM))
(va_get_xmm 1 va_s0) (FStar.Seq.Base.create #quad32 1 (va_get_xmm 2 va_s0)) ==> va_k va_sM
(()))) | {
"file_name": "obj/Vale.AES.X64.GHash.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 69,
"start_col": 0,
"start_line": 58
} | module Vale.AES.X64.GHash
open Vale.Def.Opaque_s
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.AES.AES_s
open Vale.AES.GHash_s
open Vale.AES.GHash
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.AES.GCTR_s
open Vale.AES.GCM_helpers
open Vale.Math.Poly2_s
open Vale.Poly1305.Math
open Vale.AES.X64.GF128_Mul
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.InsAes
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.X64.CPU_Features_s
#reset-options "--z3rlimit 30"
let get_last_slice_workaround (s:seq quad32) (start_pos end_pos:int) =
if 0 <= start_pos && start_pos < end_pos && end_pos <= length s then
last (slice s start_pos end_pos)
else
Mkfour 0 0 0 0
//let slice (s:seq quad32) (start_pos end_pos:int) =
// if 0 <= start_pos && start_pos < end_pos && end_pos <= length s then
// slice s start_pos end_pos
// else
// create 1 (Mkfour 0 0 0 0)
//-- Compute_ghash_incremental_register
val va_code_Compute_ghash_incremental_register : va_dummy:unit -> Tot va_code
val va_codegen_success_Compute_ghash_incremental_register : va_dummy:unit -> Tot va_pbool
val va_lemma_Compute_ghash_incremental_register : va_b0:va_code -> va_s0:va_state
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Compute_ghash_incremental_register ()) va_s0 /\
va_get_ok va_s0 /\ (pclmulqdq_enabled /\ avx_enabled /\ sse_enabled /\ va_get_xmm 8 va_s0 ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 202182159 134810123 67438087 66051)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_get_xmm 1 va_sM == Vale.AES.GHash.ghash_incremental (Vale.Def.Types_s.reverse_bytes_quad32
(va_get_xmm 11 va_sM)) (va_get_xmm 1 va_s0) (FStar.Seq.Base.create #quad32 1 (va_get_xmm 2
va_s0)) /\ va_state_eq va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 4
va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_reg64 rR12 va_sM
(va_update_flags va_sM (va_update_xmm 1 va_sM (va_update_ok va_sM va_s0))))))))))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.InsAes.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Poly1305.Math.fsti.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.X64.GF128_Mul.fsti.checked",
"Vale.AES.GHash_s.fst.checked",
"Vale.AES.GHash.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.fsti.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.GCM_helpers.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.X64.GHash.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_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": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | va_s0: Vale.X64.Decls.va_state -> va_k: (_: Vale.X64.Decls.va_state -> _: Prims.unit -> Type0)
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Decls.va_state",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Decls.va_get_ok",
"Vale.X64.CPU_Features_s.pclmulqdq_enabled",
"Vale.X64.CPU_Features_s.avx_enabled",
"Vale.X64.CPU_Features_s.sse_enabled",
"Prims.eq2",
"Vale.Def.Words_s.four",
"Vale.Def.Types_s.nat32",
"Vale.X64.Decls.va_get_xmm",
"Vale.Def.Words_s.Mkfour",
"Prims.l_Forall",
"Vale.X64.Decls.quad32",
"Vale.X64.Flags.t",
"Vale.X64.Memory.nat64",
"Prims.l_imp",
"Vale.Def.Types_s.quad32",
"Vale.AES.GHash.ghash_incremental",
"Vale.Def.Types_s.reverse_bytes_quad32",
"FStar.Seq.Base.create",
"Vale.X64.State.vale_state",
"Vale.X64.Decls.va_upd_xmm",
"Vale.X64.Decls.va_upd_reg64",
"Vale.X64.Machine_s.rR12",
"Vale.X64.Decls.va_upd_flags"
] | [] | false | false | false | true | true | let va_wp_Compute_ghash_incremental_register (va_s0: va_state) (va_k: (va_state -> unit -> Type0))
: Type0 =
| (va_get_ok va_s0 /\
(pclmulqdq_enabled /\ avx_enabled /\ sse_enabled /\
va_get_xmm 8 va_s0 ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 202182159 134810123 67438087 66051) /\
(forall (va_x_xmm1: quad32)
(va_x_efl: Vale.X64.Flags.t)
(va_x_r12: nat64)
(va_x_xmm2: quad32)
(va_x_xmm3: quad32)
(va_x_xmm4: quad32)
(va_x_xmm5: quad32)
(va_x_xmm6: quad32).
let va_sM =
va_upd_xmm 6
va_x_xmm6
(va_upd_xmm 5
va_x_xmm5
(va_upd_xmm 4
va_x_xmm4
(va_upd_xmm 3
va_x_xmm3
(va_upd_xmm 2
va_x_xmm2
(va_upd_reg64 rR12
va_x_r12
(va_upd_flags va_x_efl (va_upd_xmm 1 va_x_xmm1 va_s0)))))))
in
va_get_ok va_sM /\
va_get_xmm 1 va_sM ==
Vale.AES.GHash.ghash_incremental (Vale.Def.Types_s.reverse_bytes_quad32 (va_get_xmm 11 va_sM))
(va_get_xmm 1 va_s0)
(FStar.Seq.Base.create #quad32 1 (va_get_xmm 2 va_s0)) ==>
va_k va_sM (()))) | false |
Vale.Bignum.Lemmas.fsti | Vale.Bignum.Lemmas.seq_add_is | val seq_add_is (#n: nat) (as0 bs: seq (natN n)) (c0: nat1) (i: nat)
: Pure Type0 (requires length as0 == length bs /\ i <= length as0) (ensures fun _ -> True) | val seq_add_is (#n: nat) (as0 bs: seq (natN n)) (c0: nat1) (i: nat)
: Pure Type0 (requires length as0 == length bs /\ i <= length as0) (ensures fun _ -> True) | let rec seq_add_is (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure Type0
(requires length as0 == length bs /\ i <= length as0)
(ensures fun _ -> True)
=
if i = 0 then True else
seq_add_is as0 bs c0 (i - 1) /\ (fst (seq_add as0 bs c0)).[i - 1] == seq_add_i as0 bs c0 (i - 1) | {
"file_name": "vale/code/crypto/bignum/Vale.Bignum.Lemmas.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 98,
"end_line": 67,
"start_col": 0,
"start_line": 62
} | module Vale.Bignum.Lemmas
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Bignum.Defs
unfold let (.[]) = Seq.index
let rec seq_add_c (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure nat1
(requires length as0 == length bs /\ i <= length as0)
(ensures fun _ -> True)
=
if i = 0 then c0 else add_hi as0.[i - 1] bs.[i - 1] (seq_add_c as0 bs c0 (i - 1))
let seq_add_i (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure (natN n)
(requires length as0 == length bs /\ i < length as0)
(ensures fun _ -> True)
=
add_lo as0.[i] bs.[i] (seq_add_c as0 bs c0 i)
// as0 + bs
let seq_add (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) : Pure (seq (natN n) & nat1)
(requires length as0 == length bs)
(ensures fun (xs, _) -> length xs == length as0)
=
let f (i:nat{i < length as0}) = seq_add_i as0 bs c0 i in
(init (length as0) f, seq_add_c as0 bs c0 (length as0))
let last_carry (a b:nat) (c:nat1) : int =
if c = 0 then 0 else pow_int a b
let seq_scale_lo (#n:pos) (a:natN n) (bs:seq (natN n)) : Pure (seq (natN n))
(requires True)
(ensures fun xs -> length xs = length bs + 1)
=
let f (i:nat{i <= length bs}) : natN n = if i = length bs then 0 else mul_lo a bs.[i] in
init (length bs + 1) f
let seq_scale_hi (#n:pos) (a:natN n) (bs:seq (natN n)) (d:natN n) : Pure (seq (natN n))
(requires True)
(ensures fun xs -> length xs = length bs + 1)
=
let f (i:nat{i <= length bs}) : natN n = if i = 0 then d else mul_hi a bs.[i - 1] in
init (length bs + 1) f
// a * bs + d
let seq_scale (#n:pos) (a:natN n) (bs:seq (natN n)) (d:natN n) : Pure (seq (natN n))
(requires True)
(ensures fun xs -> length xs = length bs + 1)
=
fst (seq_add (seq_scale_lo a bs) (seq_scale_hi a bs d) 0)
val lemma_sum_seq_left_right (s:seq int) (i j:nat) : Lemma
(requires i <= j /\ j <= length s)
(ensures sum_seq_left s i j == sum_seq_right s i j)
val lemma_pow_nat (a:nat) (b:nat) : Lemma (0 <= pow_int a b)
val lemma_sum_pow_seq_bound (#n:nat) (s:seq (natN n)) : Lemma
(ensures 0 <= sum_pow_seq s /\ sum_pow_seq s < pow_int n (length s)) | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Bignum.Defs.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Bignum.Lemmas.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
as0: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) ->
bs: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) ->
c0: Vale.Def.Words_s.nat1 ->
i: Prims.nat
-> Prims.Pure Type0 | Prims.Pure | [] | [] | [
"Prims.nat",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.natN",
"Vale.Def.Words_s.nat1",
"Prims.op_Equality",
"Prims.int",
"Prims.l_True",
"Prims.bool",
"Prims.l_and",
"Vale.Bignum.Lemmas.seq_add_is",
"Prims.op_Subtraction",
"Prims.eq2",
"Vale.Bignum.Lemmas.op_String_Access",
"FStar.Pervasives.Native.fst",
"Vale.Bignum.Lemmas.seq_add",
"Vale.Bignum.Lemmas.seq_add_i",
"FStar.Seq.Base.length",
"Prims.b2t",
"Prims.op_LessThanOrEqual"
] | [
"recursion"
] | false | false | false | false | true | let rec seq_add_is (#n: nat) (as0 bs: seq (natN n)) (c0: nat1) (i: nat)
: Pure Type0 (requires length as0 == length bs /\ i <= length as0) (ensures fun _ -> True) =
| if i = 0
then True
else
seq_add_is as0 bs c0 (i - 1) /\ (fst (seq_add as0 bs c0)).[ i - 1 ] == seq_add_i as0 bs c0 (i - 1) | false |
Vale.Bignum.Lemmas.fsti | Vale.Bignum.Lemmas.zs_init | val zs_init (#n: nat) (a: natN n) (bs: seq (natN n)) (d: natN n) (i: nat{i <= length bs}) : natN n | val zs_init (#n: nat) (a: natN n) (bs: seq (natN n)) (d: natN n) (i: nat{i <= length bs}) : natN n | let zs_init (#n:nat) (a:natN n) (bs:seq (natN n)) (d:natN n) (i:nat{i <= length bs}) : natN n =
if i = 0 then d else mul_hi a bs.[i - 1] | {
"file_name": "vale/code/crypto/bignum/Vale.Bignum.Lemmas.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 42,
"end_line": 106,
"start_col": 0,
"start_line": 105
} | module Vale.Bignum.Lemmas
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Bignum.Defs
unfold let (.[]) = Seq.index
let rec seq_add_c (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure nat1
(requires length as0 == length bs /\ i <= length as0)
(ensures fun _ -> True)
=
if i = 0 then c0 else add_hi as0.[i - 1] bs.[i - 1] (seq_add_c as0 bs c0 (i - 1))
let seq_add_i (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure (natN n)
(requires length as0 == length bs /\ i < length as0)
(ensures fun _ -> True)
=
add_lo as0.[i] bs.[i] (seq_add_c as0 bs c0 i)
// as0 + bs
let seq_add (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) : Pure (seq (natN n) & nat1)
(requires length as0 == length bs)
(ensures fun (xs, _) -> length xs == length as0)
=
let f (i:nat{i < length as0}) = seq_add_i as0 bs c0 i in
(init (length as0) f, seq_add_c as0 bs c0 (length as0))
let last_carry (a b:nat) (c:nat1) : int =
if c = 0 then 0 else pow_int a b
let seq_scale_lo (#n:pos) (a:natN n) (bs:seq (natN n)) : Pure (seq (natN n))
(requires True)
(ensures fun xs -> length xs = length bs + 1)
=
let f (i:nat{i <= length bs}) : natN n = if i = length bs then 0 else mul_lo a bs.[i] in
init (length bs + 1) f
let seq_scale_hi (#n:pos) (a:natN n) (bs:seq (natN n)) (d:natN n) : Pure (seq (natN n))
(requires True)
(ensures fun xs -> length xs = length bs + 1)
=
let f (i:nat{i <= length bs}) : natN n = if i = 0 then d else mul_hi a bs.[i - 1] in
init (length bs + 1) f
// a * bs + d
let seq_scale (#n:pos) (a:natN n) (bs:seq (natN n)) (d:natN n) : Pure (seq (natN n))
(requires True)
(ensures fun xs -> length xs = length bs + 1)
=
fst (seq_add (seq_scale_lo a bs) (seq_scale_hi a bs d) 0)
val lemma_sum_seq_left_right (s:seq int) (i j:nat) : Lemma
(requires i <= j /\ j <= length s)
(ensures sum_seq_left s i j == sum_seq_right s i j)
val lemma_pow_nat (a:nat) (b:nat) : Lemma (0 <= pow_int a b)
val lemma_sum_pow_seq_bound (#n:nat) (s:seq (natN n)) : Lemma
(ensures 0 <= sum_pow_seq s /\ sum_pow_seq s < pow_int n (length s))
let rec seq_add_is (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure Type0
(requires length as0 == length bs /\ i <= length as0)
(ensures fun _ -> True)
=
if i = 0 then True else
seq_add_is as0 bs c0 (i - 1) /\ (fst (seq_add as0 bs c0)).[i - 1] == seq_add_i as0 bs c0 (i - 1)
unfold let seq_add_is_norm (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure Type0
(requires length as0 == length bs /\ i <= length as0)
(ensures fun _ -> True)
=
norm [iota; zeta; primops; delta_only [`%seq_add_is]] (seq_add_is as0 bs c0 i)
val lemma_seq_add_is_norm (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Lemma
(requires length as0 == length bs /\ i <= length as0)
(ensures seq_add_is as0 bs c0 i == seq_add_is_norm as0 bs c0 i)
val lemma_last_carry_mul (a b:nat) (c:nat1) : Lemma (last_carry a b c == c * pow_int a b)
val lemma_add_lo_mul_right (#n:nat) (a b:natN n) (c:nat1) (m:int) : Lemma
(add_lo a b c * m == (let x = a * m + b * m + c * m in if a + b + c < n then x else x - n * m))
val lemma_seq_add (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) : Lemma
(requires length bs == length as0)
(ensures (
let (xs, ci) = seq_add as0 bs c0 in
sum_pow_seq xs + last_carry n (length as0) ci == sum_pow_seq as0 + sum_pow_seq bs + c0
))
val lemma_seq_scale_carry (#n:nat) (a:natN n) (bs:seq (natN n)) (d:natN n) : Lemma
(ensures (
snd (seq_add (seq_scale_lo a bs) (seq_scale_hi a bs d) 0) == 0
))
val lemma_seq_scale (#n:nat) (a:natN n) (bs:seq (natN n)) (d:natN n) : Lemma
(ensures (
sum_pow_seq (seq_scale a bs d) == sum_pow_seq (seq_scale_lo a bs) + sum_pow_seq (seq_scale_hi a bs d) /\
sum_pow_seq (seq_scale a bs d) == a * sum_pow_seq bs + d
))
let ys_init (#n:nat) (a:natN n) (bs:seq (natN n)) (i:nat{i <= length bs}) : natN n =
if i = length bs then 0 else mul_lo a bs.[i] | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Bignum.Defs.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Bignum.Lemmas.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Vale.Def.Words_s.natN n ->
bs: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) ->
d: Vale.Def.Words_s.natN n ->
i: Prims.nat{i <= FStar.Seq.Base.length bs}
-> Vale.Def.Words_s.natN n | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Vale.Def.Words_s.natN",
"FStar.Seq.Base.seq",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"Vale.Bignum.Defs.mul_hi",
"Vale.Bignum.Lemmas.op_String_Access",
"Prims.op_Subtraction"
] | [] | false | false | false | false | false | let zs_init (#n: nat) (a: natN n) (bs: seq (natN n)) (d: natN n) (i: nat{i <= length bs}) : natN n =
| if i = 0 then d else mul_hi a bs.[ i - 1 ] | false |
Vale.Bignum.Lemmas.fsti | Vale.Bignum.Lemmas.init_zs | val init_zs (#n: nat) (a: natN n) (bs: seq (natN n)) (d: natN n) : seq (natN n) | val init_zs (#n: nat) (a: natN n) (bs: seq (natN n)) (d: natN n) : seq (natN n) | let init_zs (#n:nat) (a:natN n) (bs:seq (natN n)) (d:natN n) : seq (natN n) =
init (length bs + 1) (zs_init a bs d) | {
"file_name": "vale/code/crypto/bignum/Vale.Bignum.Lemmas.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 112,
"start_col": 0,
"start_line": 111
} | module Vale.Bignum.Lemmas
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Bignum.Defs
unfold let (.[]) = Seq.index
let rec seq_add_c (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure nat1
(requires length as0 == length bs /\ i <= length as0)
(ensures fun _ -> True)
=
if i = 0 then c0 else add_hi as0.[i - 1] bs.[i - 1] (seq_add_c as0 bs c0 (i - 1))
let seq_add_i (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure (natN n)
(requires length as0 == length bs /\ i < length as0)
(ensures fun _ -> True)
=
add_lo as0.[i] bs.[i] (seq_add_c as0 bs c0 i)
// as0 + bs
let seq_add (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) : Pure (seq (natN n) & nat1)
(requires length as0 == length bs)
(ensures fun (xs, _) -> length xs == length as0)
=
let f (i:nat{i < length as0}) = seq_add_i as0 bs c0 i in
(init (length as0) f, seq_add_c as0 bs c0 (length as0))
let last_carry (a b:nat) (c:nat1) : int =
if c = 0 then 0 else pow_int a b
let seq_scale_lo (#n:pos) (a:natN n) (bs:seq (natN n)) : Pure (seq (natN n))
(requires True)
(ensures fun xs -> length xs = length bs + 1)
=
let f (i:nat{i <= length bs}) : natN n = if i = length bs then 0 else mul_lo a bs.[i] in
init (length bs + 1) f
let seq_scale_hi (#n:pos) (a:natN n) (bs:seq (natN n)) (d:natN n) : Pure (seq (natN n))
(requires True)
(ensures fun xs -> length xs = length bs + 1)
=
let f (i:nat{i <= length bs}) : natN n = if i = 0 then d else mul_hi a bs.[i - 1] in
init (length bs + 1) f
// a * bs + d
let seq_scale (#n:pos) (a:natN n) (bs:seq (natN n)) (d:natN n) : Pure (seq (natN n))
(requires True)
(ensures fun xs -> length xs = length bs + 1)
=
fst (seq_add (seq_scale_lo a bs) (seq_scale_hi a bs d) 0)
val lemma_sum_seq_left_right (s:seq int) (i j:nat) : Lemma
(requires i <= j /\ j <= length s)
(ensures sum_seq_left s i j == sum_seq_right s i j)
val lemma_pow_nat (a:nat) (b:nat) : Lemma (0 <= pow_int a b)
val lemma_sum_pow_seq_bound (#n:nat) (s:seq (natN n)) : Lemma
(ensures 0 <= sum_pow_seq s /\ sum_pow_seq s < pow_int n (length s))
let rec seq_add_is (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure Type0
(requires length as0 == length bs /\ i <= length as0)
(ensures fun _ -> True)
=
if i = 0 then True else
seq_add_is as0 bs c0 (i - 1) /\ (fst (seq_add as0 bs c0)).[i - 1] == seq_add_i as0 bs c0 (i - 1)
unfold let seq_add_is_norm (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Pure Type0
(requires length as0 == length bs /\ i <= length as0)
(ensures fun _ -> True)
=
norm [iota; zeta; primops; delta_only [`%seq_add_is]] (seq_add_is as0 bs c0 i)
val lemma_seq_add_is_norm (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) (i:nat) : Lemma
(requires length as0 == length bs /\ i <= length as0)
(ensures seq_add_is as0 bs c0 i == seq_add_is_norm as0 bs c0 i)
val lemma_last_carry_mul (a b:nat) (c:nat1) : Lemma (last_carry a b c == c * pow_int a b)
val lemma_add_lo_mul_right (#n:nat) (a b:natN n) (c:nat1) (m:int) : Lemma
(add_lo a b c * m == (let x = a * m + b * m + c * m in if a + b + c < n then x else x - n * m))
val lemma_seq_add (#n:nat) (as0 bs:seq (natN n)) (c0:nat1) : Lemma
(requires length bs == length as0)
(ensures (
let (xs, ci) = seq_add as0 bs c0 in
sum_pow_seq xs + last_carry n (length as0) ci == sum_pow_seq as0 + sum_pow_seq bs + c0
))
val lemma_seq_scale_carry (#n:nat) (a:natN n) (bs:seq (natN n)) (d:natN n) : Lemma
(ensures (
snd (seq_add (seq_scale_lo a bs) (seq_scale_hi a bs d) 0) == 0
))
val lemma_seq_scale (#n:nat) (a:natN n) (bs:seq (natN n)) (d:natN n) : Lemma
(ensures (
sum_pow_seq (seq_scale a bs d) == sum_pow_seq (seq_scale_lo a bs) + sum_pow_seq (seq_scale_hi a bs d) /\
sum_pow_seq (seq_scale a bs d) == a * sum_pow_seq bs + d
))
let ys_init (#n:nat) (a:natN n) (bs:seq (natN n)) (i:nat{i <= length bs}) : natN n =
if i = length bs then 0 else mul_lo a bs.[i]
let zs_init (#n:nat) (a:natN n) (bs:seq (natN n)) (d:natN n) (i:nat{i <= length bs}) : natN n =
if i = 0 then d else mul_hi a bs.[i - 1]
let init_ys (#n:nat) (a:natN n) (bs:seq (natN n)) : seq (natN n) =
init (length bs + 1) (ys_init a bs) | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Bignum.Defs.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Bignum.Lemmas.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Vale.Def.Words_s.natN n ->
bs: FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) ->
d: Vale.Def.Words_s.natN n
-> FStar.Seq.Base.seq (Vale.Def.Words_s.natN n) | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Vale.Def.Words_s.natN",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.init",
"Prims.op_Addition",
"FStar.Seq.Base.length",
"Vale.Bignum.Lemmas.zs_init"
] | [] | false | false | false | false | false | let init_zs (#n: nat) (a: natN n) (bs: seq (natN n)) (d: natN n) : seq (natN n) =
| init (length bs + 1) (zs_init a bs d) | false |
Steel.Effect.fst | Steel.Effect.action_as_repr | val action_as_repr (#a: Type) (#p: slprop) (#q: (a -> slprop)) (f: action_except a Set.empty p q)
: repr a false (to_vprop p) (fun x -> to_vprop (q x)) (fun _ -> True) (fun _ _ _ -> True) | val action_as_repr (#a: Type) (#p: slprop) (#q: (a -> slprop)) (f: action_except a Set.empty p q)
: repr a false (to_vprop p) (fun x -> to_vprop (q x)) (fun _ -> True) (fun _ _ _ -> True) | let action_as_repr (#a:Type) (#p:slprop) (#q:a -> slprop) (f:action_except a Set.empty p q)
: repr a false (to_vprop p) (fun x -> to_vprop (q x)) (fun _ -> True) (fun _ _ _ -> True)
= Steel.Semantics.Instantiate.state_correspondence Set.empty; f | {
"file_name": "lib/steel/Steel.Effect.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 65,
"end_line": 696,
"start_col": 0,
"start_line": 694
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Effect
module Sem = Steel.Semantics.Hoare.MST
module Mem = Steel.Memory
open Steel.Semantics.Instantiate
module FExt = FStar.FunctionalExtensionality
#set-options "--ide_id_info_off"
let _:squash (forall p q. can_be_split p q == Mem.slimp (hp_of p) (hp_of q)) = reveal_can_be_split ()
#set-options "--warn_error -330" //turn off the experimental feature warning
let rmem_depends_only_on' (pre:pre_t) (m0:hmem pre) (m1:mem{disjoint m0 m1})
: Lemma (mk_rmem pre m0 == mk_rmem pre (join m0 m1))
= Classical.forall_intro (reveal_mk_rmem pre m0);
Classical.forall_intro (reveal_mk_rmem pre (join m0 m1));
FExt.extensionality_g
(r0:vprop{can_be_split pre r0})
(fun r0 -> normal (t_of r0))
(mk_rmem pre m0)
(mk_rmem pre (join m0 m1))
let rmem_depends_only_on (pre:pre_t)
: Lemma (forall (m0:hmem pre) (m1:mem{disjoint m0 m1}).
mk_rmem pre m0 == mk_rmem pre (join m0 m1))
= Classical.forall_intro_2 (rmem_depends_only_on' pre)
let rmem_depends_only_on_post' (#a:Type) (post:post_t a)
(x:a) (m0:hmem (post x)) (m1:mem{disjoint m0 m1})
: Lemma (mk_rmem (post x) m0 == mk_rmem (post x) (join m0 m1))
= rmem_depends_only_on' (post x) m0 m1
let rmem_depends_only_on_post (#a:Type) (post:post_t a)
: Lemma (forall (x:a) (m0:hmem (post x)) (m1:mem{disjoint m0 m1}).
mk_rmem (post x) m0 == mk_rmem (post x) (join m0 m1))
= Classical.forall_intro_3 (rmem_depends_only_on_post' post)
[@@ __steel_reduce__]
let req_to_act_req (#pre:pre_t) (req:req_t pre) : Sem.l_pre #state (hp_of pre) =
rmem_depends_only_on pre;
fun m0 -> interp (hp_of pre) m0 /\ req (mk_rmem pre m0)
unfold
let to_post (#a:Type) (post:post_t a) = fun x -> (hp_of (post x))
[@@ __steel_reduce__]
let ens_to_act_ens (#pre:pre_t) (#a:Type) (#post:post_t a) (ens:ens_t pre a post)
: Sem.l_post #state #a (hp_of pre) (to_post post)
= rmem_depends_only_on pre;
rmem_depends_only_on_post post;
fun m0 x m1 ->
interp (hp_of pre) m0 /\ interp (hp_of (post x)) m1 /\ ens (mk_rmem pre m0) x (mk_rmem (post x) m1)
let reveal_focus_rmem (#r:vprop) (h:rmem r) (r0:vprop{r `can_be_split` r0}) (r':vprop{r0 `can_be_split` r'})
: Lemma (
r `can_be_split` r' /\
focus_rmem h r0 r' == h r')
= can_be_split_trans r r0 r';
FExt.feq_on_domain_g (unrestricted_focus_rmem h r0)
let focus_is_restrict_mk_rmem (fp0 fp1:vprop) (m:hmem fp0)
: Lemma
(requires fp0 `can_be_split` fp1)
(ensures focus_rmem (mk_rmem fp0 m) fp1 == mk_rmem fp1 m)
= let f0:rmem fp0 = mk_rmem fp0 m in
let f1:rmem fp1 = mk_rmem fp1 m in
let f2:rmem fp1 = focus_rmem f0 fp1 in
let aux (r:vprop{can_be_split fp1 r}) : Lemma (f1 r == f2 r)
= can_be_split_trans fp0 fp1 r;
reveal_mk_rmem fp0 m r;
reveal_mk_rmem fp1 m r;
reveal_focus_rmem f0 fp1 r
in Classical.forall_intro aux;
FExt.extensionality_g
(r0:vprop{can_be_split fp1 r0})
(fun r0 -> normal (t_of r0))
(mk_rmem fp1 m)
(focus_rmem (mk_rmem fp0 m) fp1)
let focus_focus_is_focus (fp0 fp1 fp2:vprop) (m:hmem fp0)
: Lemma
(requires fp0 `can_be_split` fp1 /\ fp1 `can_be_split` fp2)
(ensures focus_rmem (focus_rmem (mk_rmem fp0 m) fp1) fp2 == focus_rmem (mk_rmem fp0 m) fp2)
= let f0:rmem fp0 = mk_rmem fp0 m in
let f1:rmem fp1 = focus_rmem f0 fp1 in
let f20:rmem fp2 = focus_rmem f0 fp2 in
let f21:rmem fp2 = focus_rmem f1 fp2 in
let aux (r:vprop{can_be_split fp2 r}) : Lemma (f20 r == f21 r)
= reveal_mk_rmem fp0 m r;
reveal_focus_rmem f0 fp1 r;
reveal_focus_rmem f0 fp2 r;
reveal_focus_rmem f1 fp2 r
in Classical.forall_intro aux;
FExt.extensionality_g
(r0:vprop{can_be_split fp2 r0})
(fun r0 -> normal (t_of r0))
f20 f21
let focus_replace (fp0 fp1 fp2:vprop) (m:hmem fp0)
: Lemma
(requires fp0 `can_be_split` fp1 /\ fp1 `can_be_split` fp2)
(ensures focus_rmem (mk_rmem fp0 m) fp2 == focus_rmem (mk_rmem fp1 m) fp2)
= let f0:rmem fp0 = mk_rmem fp0 m in
let f1:rmem fp1 = mk_rmem fp1 m in
let f20:rmem fp2 = focus_rmem f0 fp2 in
let f21:rmem fp2 = focus_rmem f1 fp2 in
let aux (r:vprop{can_be_split fp2 r}) : Lemma (f20 r == f21 r)
= reveal_mk_rmem fp0 m r;
reveal_mk_rmem fp1 m r;
reveal_focus_rmem f0 fp2 r;
reveal_focus_rmem f1 fp2 r
in Classical.forall_intro aux;
FExt.extensionality_g
(r0:vprop{can_be_split fp2 r0})
(fun r0 -> normal (t_of r0))
f20 f21
val can_be_split_3_interp (p1 p2 q r:slprop u#1) (m:mem)
: Lemma
(requires p1 `slimp` p2 /\ interp (p1 `Mem.star` q `Mem.star` r) m)
(ensures interp (p2 `Mem.star` q `Mem.star` r) m)
let can_be_split_3_interp p1 p2 q r m =
Mem.star_associative p1 q r;
Mem.star_associative p2 q r;
slimp_star p1 p2 (q `Mem.star` r) (q `Mem.star` r)
let repr (a:Type) (_:bool) (pre:pre_t) (post:post_t a) (req:req_t pre) (ens:ens_t pre a post) =
Sem.action_t #state #a (hp_of pre) (to_post post)
((req_to_act_req req))
((ens_to_act_ens ens))
let nmst_get (#st:Sem.st) ()
: Sem.Mst (Sem.full_mem st)
(fun _ -> True)
(fun s0 s s1 -> s0 == s /\ s == s1)
= NMST.get ()
let rec lemma_frame_equalities_refl (frame:vprop) (h:rmem frame) : Lemma (frame_equalities frame h h) =
match frame with
| VUnit _ -> ()
| VStar p1 p2 ->
can_be_split_star_l p1 p2;
can_be_split_star_r p1 p2;
let h1 = focus_rmem h p1 in
let h2 = focus_rmem h p2 in
lemma_frame_equalities_refl p1 h1;
lemma_frame_equalities_refl p2 h2
let return_ a x #p = fun _ ->
let m0 = nmst_get () in
let h0 = mk_rmem (p x) (core_mem m0) in
lemma_frame_equalities_refl (p x) h0;
x
#push-options "--fuel 0 --ifuel 0"
val req_frame (frame:vprop) (snap:rmem frame) : mprop (hp_of frame)
let req_frame' (frame:vprop) (snap:rmem frame) (m:mem) : prop =
interp (hp_of frame) m /\ mk_rmem frame m == snap
let req_frame frame snap =
rmem_depends_only_on frame;
req_frame' frame snap
#push-options "--z3rlimit 50 --fuel 1 --ifuel 0"
let frame_opaque frame h0 h1 = frame_equalities frame h0 h1
unfold
let norm_opaque = norm [delta_only [`%frame_opaque]]
let lemma_frame_opaque_refl (frame:vprop) (h:rmem frame) : Lemma (frame_opaque frame h h) =
assert (frame_opaque frame h h) by (
T.norm [delta_only [`%frame_opaque]];
T.apply_lemma (`lemma_frame_equalities_refl))
val frame00 (#a:Type)
(#framed:bool)
(#pre:pre_t)
(#post:post_t a)
(#req:req_t pre)
(#ens:ens_t pre a post)
($f:repr a framed pre post req ens)
(frame:vprop)
: repr a
true
(pre `star` frame)
(fun x -> post x `star` frame)
(fun h -> req (focus_rmem h pre))
(fun h0 r h1 -> req (focus_rmem h0 pre) /\ ens (focus_rmem h0 pre) r (focus_rmem h1 (post r)) /\
frame_opaque frame (focus_rmem h0 frame) (focus_rmem h1 frame))
let frame00 #a #framed #pre #post #req #ens f frame =
fun frame' ->
let m0 = nmst_get () in
let snap:rmem frame = mk_rmem frame (core_mem m0) in
focus_is_restrict_mk_rmem (pre `star` frame) pre (core_mem m0);
assert (state.interp (((hp_of pre `state.star` hp_of frame) `state.star` frame' `state.star` state.locks_invariant m0)) m0);
let req' =
(Steel.Semantics.Hoare.MST.frame_lpre #Steel.Semantics.Instantiate.state
#(Steel.Effect.Common.hp_of pre)
(req_to_act_req #pre req)
#(Steel.Effect.Common.hp_of frame)
(req_frame frame snap)) in
assert (req' (state.core m0));
let x = Sem.run #state #_ #_ #_ #_ #_ frame' (Sem.Frame (Sem.Act f) (hp_of frame) (req_frame frame snap)) in
let m1 = nmst_get () in
can_be_split_star_r pre frame;
focus_is_restrict_mk_rmem (pre `star` frame) frame (core_mem m0);
can_be_split_star_r (post x) frame;
focus_is_restrict_mk_rmem (post x `star` frame) frame (core_mem m1);
focus_is_restrict_mk_rmem (post x `star` frame) (post x) (core_mem m1);
// We proved focus_rmem h0 frame == focus_rmem h1 frame so far
let h0:rmem (pre `star` frame) = mk_rmem (pre `star` frame) (core_mem m0) in
lemma_frame_opaque_refl frame (focus_rmem h0 frame);
x
#pop-options
let norm_repr (#a:Type) (#framed:bool)
(#pre:pre_t) (#post:post_t a) (#req:req_t pre) (#ens:ens_t pre a post)
(f:repr a framed pre post req ens) : repr a framed pre post (fun h -> norm_opaque (req h)) (fun h0 x h1 -> norm_opaque (ens h0 x h1))
= f
unfold
let bind_req_opaque (#a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f)
(#pre_g:a -> pre_t)
(#pr:a -> prop)
(req_g:(x:a -> req_t (pre_g x)))
(frame_f:vprop) (frame_g:a -> vprop)
(_:squash (can_be_split_forall_dep pr (fun x -> post_f x `star` frame_f) (fun x -> pre_g x `star` frame_g x)))
: req_t (pre_f `star` frame_f)
= fun m0 ->
req_f (focus_rmem m0 pre_f) /\
(forall (x:a) (h1:hmem (post_f x `star` frame_f)).
(ens_f (focus_rmem m0 pre_f) x (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) (post_f x)) /\
frame_opaque frame_f (focus_rmem m0 frame_f) (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) frame_f))
==> pr x /\
(can_be_split_trans (post_f x `star` frame_f) (pre_g x `star` frame_g x) (pre_g x);
(req_g x) (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) (pre_g x))))
unfold
let bind_ens_opaque (#a:Type) (#b:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f)
(#pre_g:a -> pre_t) (#post_g:a -> post_t b)
(#pr:a -> prop)
(ens_g:(x:a -> ens_t (pre_g x) b (post_g x)))
(frame_f:vprop) (frame_g:a -> vprop)
(post:post_t b)
(_:squash (can_be_split_forall_dep pr (fun x -> post_f x `star` frame_f) (fun x -> pre_g x `star` frame_g x)))
(_:squash (can_be_split_post (fun x y -> post_g x y `star` frame_g x) post))
: ens_t (pre_f `star` frame_f) b post
= fun m0 y m2 ->
req_f (focus_rmem m0 pre_f) /\
(exists (x:a) (h1:hmem (post_f x `star` frame_f)).
pr x /\
(
can_be_split_trans (post_f x `star` frame_f) (pre_g x `star` frame_g x) (pre_g x);
can_be_split_trans (post_f x `star` frame_f) (pre_g x `star` frame_g x) (frame_g x);
can_be_split_trans (post y) (post_g x y `star` frame_g x) (post_g x y);
can_be_split_trans (post y) (post_g x y `star` frame_g x) (frame_g x);
frame_opaque frame_f (focus_rmem m0 frame_f) (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) frame_f) /\
frame_opaque (frame_g x) (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) (frame_g x)) (focus_rmem m2 (frame_g x)) /\
ens_f (focus_rmem m0 pre_f) x (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) (post_f x)) /\
(ens_g x) (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) (pre_g x)) y (focus_rmem m2 (post_g x y))))
val bind_opaque (a:Type) (b:Type)
(#framed_f:eqtype_as_type bool)
(#framed_g:eqtype_as_type bool)
(#pre_f:pre_t) (#post_f:post_t a)
(#req_f:req_t pre_f) (#ens_f:ens_t pre_f a post_f)
(#pre_g:a -> pre_t) (#post_g:a -> post_t b)
(#req_g:(x:a -> req_t (pre_g x))) (#ens_g:(x:a -> ens_t (pre_g x) b (post_g x)))
(#frame_f:vprop) (#frame_g:a -> vprop)
(#post:post_t b)
(# _ : squash (maybe_emp framed_f frame_f))
(# _ : squash (maybe_emp_dep framed_g frame_g))
(#pr:a -> prop)
(#p1:squash (can_be_split_forall_dep pr
(fun x -> post_f x `star` frame_f) (fun x -> pre_g x `star` frame_g x)))
(#p2:squash (can_be_split_post (fun x y -> post_g x y `star` frame_g x) post))
(f:repr a framed_f pre_f post_f req_f ens_f)
(g:(x:a -> repr b framed_g (pre_g x) (post_g x) (req_g x) (ens_g x)))
: repr b
true
(pre_f `star` frame_f)
post
(bind_req_opaque req_f ens_f req_g frame_f frame_g p1)
(bind_ens_opaque req_f ens_f ens_g frame_f frame_g post p1 p2)
#push-options "--z3rlimit 20"
let bind_opaque a b #framed_f #framed_g #pre_f #post_f #req_f #ens_f #pre_g #post_g #req_g #ens_g #frame_f #frame_g #post #_ #_ #p #p2 f g =
fun frame ->
let m0 = nmst_get () in
let h0 = mk_rmem (pre_f `star` frame_f) (core_mem m0) in
let x = frame00 f frame_f frame in
let m1 = nmst_get () in
let h1 = mk_rmem (post_f x `star` frame_f) (core_mem m1) in
let h1' = mk_rmem (pre_g x `star` frame_g x) (core_mem m1) in
can_be_split_trans (post_f x `star` frame_f) (pre_g x `star` frame_g x) (pre_g x);
focus_is_restrict_mk_rmem
(post_f x `star` frame_f)
(pre_g x `star` frame_g x)
(core_mem m1);
focus_focus_is_focus
(post_f x `star` frame_f)
(pre_g x `star` frame_g x)
(pre_g x)
(core_mem m1);
assert (focus_rmem h1' (pre_g x) == focus_rmem h1 (pre_g x));
can_be_split_3_interp
(hp_of (post_f x `star` frame_f))
(hp_of (pre_g x `star` frame_g x))
frame (locks_invariant Set.empty m1) m1;
let y = frame00 (g x) (frame_g x) frame in
let m2 = nmst_get () in
can_be_split_trans (post_f x `star` frame_f) (pre_g x `star` frame_g x) (pre_g x);
can_be_split_trans (post_f x `star` frame_f) (pre_g x `star` frame_g x) (frame_g x);
can_be_split_trans (post y) (post_g x y `star` frame_g x) (post_g x y);
can_be_split_trans (post y) (post_g x y `star` frame_g x) (frame_g x);
let h2' = mk_rmem (post_g x y `star` frame_g x) (core_mem m2) in
let h2 = mk_rmem (post y) (core_mem m2) in
// assert (focus_rmem h1' (pre_g x) == focus_rmem h1 (pre_g x));
focus_focus_is_focus
(post_f x `star` frame_f)
(pre_g x `star` frame_g x)
(frame_g x)
(core_mem m1);
focus_is_restrict_mk_rmem
(post_g x y `star` frame_g x)
(post y)
(core_mem m2);
focus_focus_is_focus
(post_g x y `star` frame_g x)
(post y)
(frame_g x)
(core_mem m2);
focus_focus_is_focus
(post_g x y `star` frame_g x)
(post y)
(post_g x y)
(core_mem m2);
can_be_split_3_interp
(hp_of (post_g x y `star` frame_g x))
(hp_of (post y))
frame (locks_invariant Set.empty m2) m2;
y
#pop-options
let bind a b #framed_f #framed_g #pre_f #post_f #req_f #ens_f #pre_g #post_g #req_g #ens_g #frame_f #frame_g #post #_ #_ #p #p2 f g
= norm_repr (bind_opaque a b #framed_f #framed_g #pre_f #post_f #req_f #ens_f #pre_g #post_g #req_g #ens_g #frame_f #frame_g #post #_ #_ #p #p2 f g)
unfold
let subcomp_pre_opaque (#a:Type)
(#pre_f:pre_t) (#post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f)
(#pre_g:pre_t) (#post_g:post_t a) (req_g:req_t pre_g) (ens_g:ens_t pre_g a post_g)
(#frame:vprop) (#pr:prop)
(_:squash (can_be_split_dep pr pre_g (pre_f `star` frame)))
(_:squash (equiv_forall post_g (fun x -> post_f x `star` frame)))
: pure_pre
= (forall (h0:hmem pre_g). req_g (mk_rmem pre_g h0) ==> pr /\ (
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
req_f (focus_rmem (mk_rmem pre_g h0) pre_f))) /\
(forall (h0:hmem pre_g) (x:a) (h1:hmem (post_g x)). (
pr ==> (
can_be_split_trans (post_g x) (post_f x `star` frame) (post_f x);
can_be_split_trans (pre_g) (pre_f `star` frame) frame;
can_be_split_trans (post_g x) (post_f x `star` frame) frame;
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
(req_g (mk_rmem pre_g h0) /\
ens_f (focus_rmem (mk_rmem pre_g h0) pre_f) x (focus_rmem (mk_rmem (post_g x) h1) (post_f x)) /\
frame_opaque frame
(focus_rmem (mk_rmem pre_g h0) frame)
(focus_rmem (mk_rmem (post_g x) h1) frame))
==> ens_g (mk_rmem pre_g h0) x (mk_rmem (post_g x) h1))
))
val subcomp_opaque (a:Type)
(#framed_f:eqtype_as_type bool)
(#framed_g:eqtype_as_type bool)
(#[@@@ framing_implicit] pre_f:pre_t) (#[@@@ framing_implicit] post_f:post_t a)
(#[@@@ framing_implicit] req_f:req_t pre_f) (#[@@@ framing_implicit] ens_f:ens_t pre_f a post_f)
(#[@@@ framing_implicit] pre_g:pre_t) (#[@@@ framing_implicit] post_g:post_t a)
(#[@@@ framing_implicit] req_g:req_t pre_g) (#[@@@ framing_implicit] ens_g:ens_t pre_g a post_g)
(#[@@@ framing_implicit] frame:vprop)
(#[@@@ framing_implicit] pr : prop)
(#[@@@ framing_implicit] _ : squash (maybe_emp framed_f frame))
(#[@@@ framing_implicit] p1:squash (can_be_split_dep pr pre_g (pre_f `star` frame)))
(#[@@@ framing_implicit] p2:squash (equiv_forall post_g (fun x -> post_f x `star` frame)))
(f:repr a framed_f pre_f post_f req_f ens_f)
: Pure (repr a framed_g pre_g post_g req_g ens_g)
(requires subcomp_pre_opaque req_f ens_f req_g ens_g p1 p2)
(ensures fun _ -> True)
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let subcomp_opaque a #framed_f #framed_g #pre_f #post_f #req_f #ens_f #pre_g #post_g #req_g #ens_g #fr #_ #_ #p1 #p2 f =
fun frame ->
let m0 = nmst_get () in
let h0 = mk_rmem pre_g (core_mem m0) in
can_be_split_trans pre_g (pre_f `star` fr) pre_f;
can_be_split_trans pre_g (pre_f `star` fr) fr;
can_be_split_3_interp (hp_of pre_g) (hp_of (pre_f `star` fr)) frame (locks_invariant Set.empty m0) m0;
focus_replace pre_g (pre_f `star` fr) pre_f (core_mem m0);
let x = frame00 f fr frame in
let m1 = nmst_get () in
let h1 = mk_rmem (post_g x) (core_mem m1) in
let h0' = mk_rmem (pre_f `star` fr) (core_mem m0) in
let h1' = mk_rmem (post_f x `star` fr) (core_mem m1) in
// From frame00
assert (frame_opaque fr (focus_rmem h0' fr) (focus_rmem h1' fr));
// Replace h0'/h1' by h0/h1
focus_replace pre_g (pre_f `star` fr) fr (core_mem m0);
focus_replace (post_g x) (post_f x `star` fr) fr (core_mem m1);
assert (frame_opaque fr (focus_rmem h0 fr) (focus_rmem h1 fr));
can_be_split_trans (post_g x) (post_f x `star` fr) (post_f x);
can_be_split_trans (post_g x) (post_f x `star` fr) fr;
can_be_split_3_interp (hp_of (post_f x `star` fr)) (hp_of (post_g x)) frame (locks_invariant Set.empty m1) m1;
focus_replace (post_g x) (post_f x `star` fr) (post_f x) (core_mem m1);
x
#pop-options
let lemma_rewrite (p:Type) : Lemma (requires T.rewrite_with_tactic vc_norm p) (ensures p)
= T.unfold_rewrite_with_tactic vc_norm p
let lemma_norm_opaque (p:Type) : Lemma (requires norm_opaque p) (ensures p) = ()
(** Need to manually remove the rewrite_with_tactic marker here *)
let lemma_subcomp_pre_opaque_aux1 (#a:Type)
(#pre_f:pre_t) (#post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f)
(#pre_g:pre_t) (#post_g:post_t a) (req_g:req_t pre_g) (ens_g:ens_t pre_g a post_g)
(#frame:vprop)
(#pr:prop)
(p1:squash (can_be_split_dep pr pre_g (pre_f `star` frame)))
(p2:squash (equiv_forall post_g (fun x -> post_f x `star` frame)))
: Lemma
(requires subcomp_pre req_f ens_f req_g ens_g p1 p2)
(ensures (
(forall (h0:hmem pre_g). req_g (mk_rmem pre_g h0) ==> pr /\ (
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
req_f (focus_rmem (mk_rmem pre_g h0) pre_f))) /\
(forall (h0:hmem pre_g) (x:a) (h1:hmem (post_g x)). (
pr ==> (
can_be_split_trans (post_g x) (post_f x `star` frame) (post_f x);
can_be_split_trans (pre_g) (pre_f `star` frame) frame;
can_be_split_trans (post_g x) (post_f x `star` frame) frame;
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
(req_g (mk_rmem pre_g h0) /\
ens_f (focus_rmem (mk_rmem pre_g h0) pre_f) x (focus_rmem (mk_rmem (post_g x) h1) (post_f x)) /\
frame_equalities frame
(focus_rmem (mk_rmem pre_g h0) frame)
(focus_rmem (mk_rmem (post_g x) h1) frame))
==> ens_g (mk_rmem pre_g h0) x (mk_rmem (post_g x) h1))
))))
= lemma_rewrite (squash (
(forall (h0:hmem pre_g). req_g (mk_rmem pre_g h0) ==> pr /\ (
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
req_f (focus_rmem (mk_rmem pre_g h0) pre_f))) /\
(forall (h0:hmem pre_g) (x:a) (h1:hmem (post_g x)). (
pr ==> (
can_be_split_trans (post_g x) (post_f x `star` frame) (post_f x);
can_be_split_trans (pre_g) (pre_f `star` frame) frame;
can_be_split_trans (post_g x) (post_f x `star` frame) frame;
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
(req_g (mk_rmem pre_g h0) /\
ens_f (focus_rmem (mk_rmem pre_g h0) pre_f) x (focus_rmem (mk_rmem (post_g x) h1) (post_f x)) /\
frame_equalities frame
(focus_rmem (mk_rmem pre_g h0) frame)
(focus_rmem (mk_rmem (post_g x) h1) frame))
==> ens_g (mk_rmem pre_g h0) x (mk_rmem (post_g x) h1))
))
))
#push-options "--no_tactics"
let lemma_subcomp_pre_opaque_aux2 (#a:Type)
(#pre_f:pre_t) (#post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f)
(#pre_g:pre_t) (#post_g:post_t a) (req_g:req_t pre_g) (ens_g:ens_t pre_g a post_g)
(#frame:vprop)
(#pr:prop)
(p1:squash (can_be_split_dep pr pre_g (pre_f `star` frame)))
(p2:squash (equiv_forall post_g (fun x -> post_f x `star` frame)))
: Lemma
(requires (
(forall (h0:hmem pre_g). req_g (mk_rmem pre_g h0) ==> pr /\ (
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
req_f (focus_rmem (mk_rmem pre_g h0) pre_f))) /\
(forall (h0:hmem pre_g) (x:a) (h1:hmem (post_g x)). (
pr ==> (
can_be_split_trans (post_g x) (post_f x `star` frame) (post_f x);
can_be_split_trans (pre_g) (pre_f `star` frame) frame;
can_be_split_trans (post_g x) (post_f x `star` frame) frame;
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
(req_g (mk_rmem pre_g h0) /\
ens_f (focus_rmem (mk_rmem pre_g h0) pre_f) x (focus_rmem (mk_rmem (post_g x) h1) (post_f x)) /\
frame_equalities frame
(focus_rmem (mk_rmem pre_g h0) frame)
(focus_rmem (mk_rmem (post_g x) h1) frame))
==> ens_g (mk_rmem pre_g h0) x (mk_rmem (post_g x) h1))
))))
(ensures subcomp_pre_opaque req_f ens_f req_g ens_g p1 p2)
= lemma_norm_opaque (squash (
(forall (h0:hmem pre_g). req_g (mk_rmem pre_g h0) ==> pr /\ (
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
req_f (focus_rmem (mk_rmem pre_g h0) pre_f))) /\
(forall (h0:hmem pre_g) (x:a) (h1:hmem (post_g x)). (
pr ==> (
can_be_split_trans (post_g x) (post_f x `star` frame) (post_f x);
can_be_split_trans (pre_g) (pre_f `star` frame) frame;
can_be_split_trans (post_g x) (post_f x `star` frame) frame;
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
(req_g (mk_rmem pre_g h0) /\
ens_f (focus_rmem (mk_rmem pre_g h0) pre_f) x (focus_rmem (mk_rmem (post_g x) h1) (post_f x)) /\
frame_opaque frame
(focus_rmem (mk_rmem pre_g h0) frame)
(focus_rmem (mk_rmem (post_g x) h1) frame))
==> ens_g (mk_rmem pre_g h0) x (mk_rmem (post_g x) h1))
))
))
let lemma_subcomp_pre_opaque (#a:Type)
(#pre_f:pre_t) (#post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f)
(#pre_g:pre_t) (#post_g:post_t a) (req_g:req_t pre_g) (ens_g:ens_t pre_g a post_g)
(#frame:vprop)
(#pr : prop)
(p1:squash (can_be_split_dep pr pre_g (pre_f `star` frame)))
(p2:squash (equiv_forall post_g (fun x -> post_f x `star` frame)))
: Lemma
(requires subcomp_pre req_f ens_f req_g ens_g p1 p2)
(ensures subcomp_pre_opaque req_f ens_f req_g ens_g p1 p2)
= lemma_subcomp_pre_opaque_aux1 req_f ens_f req_g ens_g p1 p2;
lemma_subcomp_pre_opaque_aux2 req_f ens_f req_g ens_g p1 p2
#pop-options
let subcomp a #framed_f #framed_g #pre_f #post_f #req_f #ens_f #pre_g #post_g #req_g #ens_g #fr #_ #pr #p1 #p2 f =
lemma_subcomp_pre_opaque req_f ens_f req_g ens_g p1 p2;
subcomp_opaque a #framed_f #framed_g #pre_f #post_f #req_f #ens_f #pre_g #post_g #req_g #ens_g #fr #pr #_ #p1 #p2 f
let bind_pure_steel_ a b #wp #pre #post #req #ens f g
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun frame ->
let x = f () in
g x frame
(* We need a bind with DIV to implement par, using reification *)
unfold
let bind_div_steel_req (#a:Type) (wp:pure_wp a)
(#pre_g:pre_t) (req_g:a -> req_t pre_g)
: req_t pre_g
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun h -> wp (fun _ -> True) /\ (forall x. (req_g x) h)
unfold
let bind_div_steel_ens (#a:Type) (#b:Type)
(wp:pure_wp a)
(#pre_g:pre_t) (#post_g:post_t b) (ens_g:a -> ens_t pre_g b post_g)
: ens_t pre_g b post_g
= fun h0 r h1 -> wp (fun _ -> True) /\ (exists x. ens_g x h0 r h1)
#push-options "--z3rlimit 20 --fuel 2 --ifuel 1"
let bind_div_steel (a:Type) (b:Type)
(wp:pure_wp a)
(framed:eqtype_as_type bool)
(pre_g:pre_t) (post_g:post_t b) (req_g:a -> req_t pre_g) (ens_g:a -> ens_t pre_g b post_g)
(f:eqtype_as_type unit -> DIV a wp) (g:(x:a -> repr b framed pre_g post_g (req_g x) (ens_g x)))
: repr b framed pre_g post_g
(bind_div_steel_req wp req_g)
(bind_div_steel_ens wp ens_g)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun frame ->
let x = f () in
g x frame
#pop-options
polymonadic_bind (DIV, SteelBase) |> SteelBase = bind_div_steel
#pop-options
let par0 (#aL:Type u#a) (#preL:vprop) (#postL:aL -> vprop)
(f:repr aL false preL postL (fun _ -> True) (fun _ _ _ -> True))
(#aR:Type u#a) (#preR:vprop) (#postR:aR -> vprop)
(g:repr aR false preR postR (fun _ -> True) (fun _ _ _ -> True))
: SteelT (aL & aR)
(preL `star` preR)
(fun y -> postL (fst y) `star` postR (snd y))
= Steel?.reflect (fun frame -> Sem.run #state #_ #_ #_ #_ #_ frame (Sem.Par (Sem.Act f) (Sem.Act g)))
(*
* AR: Steel is not marked reifiable since we intend to run Steel programs natively
* However to implement the par combinator we need to reify a Steel thunk to its repr
* We could implement it better by having support for reification only in the .fst file
* But for now assuming a (Dv) function
*)
assume val reify_steel_comp
(#a:Type) (#framed:bool) (#pre:vprop) (#post:a -> vprop) (#req:req_t pre) (#ens:ens_t pre a post)
($f:unit -> SteelBase a framed pre post req ens)
: Dv (repr a framed pre post req ens)
let par f g =
par0 (reify_steel_comp f) (reify_steel_comp g) | {
"checked_file": "/",
"dependencies": [
"Steel.Semantics.Instantiate.fsti.checked",
"Steel.Semantics.Hoare.MST.fst.checked",
"Steel.Memory.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.NMST.fst.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Effect.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": false,
"full_module": "Steel.Semantics.Instantiate",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "Sem"
},
{
"abbrev": false,
"full_module": "Steel.Effect.Common",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Steel.Memory.action_except a (FStar.Ghost.hide FStar.Set.empty) p q
-> Steel.Effect.repr a
false
(Steel.Effect.Common.to_vprop p)
(fun x -> Steel.Effect.Common.to_vprop (q x))
(fun _ -> Prims.l_True)
(fun _ _ _ -> Prims.l_True) | Prims.Tot | [
"total"
] | [] | [
"Steel.Memory.slprop",
"Steel.Memory.action_except",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Prims.unit",
"Steel.Semantics.Instantiate.state_correspondence",
"Steel.Effect.repr",
"Steel.Effect.Common.to_vprop",
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.rmem",
"Prims.l_True"
] | [] | false | false | false | false | false | let action_as_repr (#a: Type) (#p: slprop) (#q: (a -> slprop)) (f: action_except a Set.empty p q)
: repr a false (to_vprop p) (fun x -> to_vprop (q x)) (fun _ -> True) (fun _ _ _ -> True) =
| Steel.Semantics.Instantiate.state_correspondence Set.empty;
f | false |
Desugar.fst | Desugar.check_desugared_enum_cases | val check_desugared_enum_cases (cases: list enum_case) : ML (list ident) | val check_desugared_enum_cases (cases: list enum_case) : ML (list ident) | let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 10,
"end_line": 44,
"start_col": 0,
"start_line": 39
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | cases: Prims.list Ast.enum_case -> FStar.All.ML (Prims.list Ast.ident) | FStar.All.ML | [
"ml"
] | [] | [
"Prims.list",
"Ast.enum_case",
"FStar.List.map",
"FStar.Pervasives.Native.tuple2",
"Ast.ident",
"FStar.Pervasives.Native.option",
"Ast.either",
"Prims.int",
"FStar.All.failwith"
] | [] | false | true | false | false | false | let check_desugared_enum_cases (cases: list enum_case) : ML (list ident) =
| List.map (function
| i, None -> i
| i, _ -> failwith "Enum should already have been desugared")
cases | false |
Desugar.fst | Desugar.desugar_one_enum | val desugar_one_enum (d: decl) : ML (list decl) | val desugar_one_enum (d: decl) : ML (list decl) | let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d] | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 12,
"end_line": 96,
"start_col": 0,
"start_line": 85
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | d: Ast.decl -> FStar.All.ML (Prims.list Ast.decl) | FStar.All.ML | [
"ml"
] | [] | [
"Ast.decl",
"Ast.__proj__Mkwith_meta_t__item__v",
"Ast.decl'",
"Ast.__proj__Mkdecl__item__d_decl",
"Ast.typ",
"Ast.ident",
"Prims.list",
"Ast.enum_case",
"Prims.Cons",
"Prims.Nil",
"Prims.bool",
"FStar.List.Tot.Base.op_At",
"Ast.decl_with_v",
"Ast.Enum",
"FStar.Pervasives.Native.tuple2",
"Desugar.desugar_enum_cases",
"Ast.__proj__Mkdecl__item__d_exported",
"Ast.integer_type",
"Ast.typ_as_integer_type",
"FStar.List.for_all",
"FStar.Pervasives.Native.option",
"Ast.either",
"Prims.int",
"FStar.Pervasives.Native.uu___is_None"
] | [] | false | true | false | false | false | let desugar_one_enum (d: decl) : ML (list decl) =
| match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d]
else
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds @ [enum]
| _ -> [d] | false |
Desugar.fst | Desugar.push_name | val push_name (env: qenv) (name: string) : qenv | val push_name (env: qenv) (name: string) : qenv | let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names } | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 50,
"end_line": 164,
"start_col": 0,
"start_line": 163
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> name: Prims.string -> Desugar.qenv | Prims.Tot | [
"total"
] | [] | [
"Desugar.qenv",
"Prims.string",
"Desugar.Mkqenv",
"Desugar.__proj__Mkqenv__item__mname",
"Desugar.__proj__Mkqenv__item__module_abbrevs",
"Desugar.__proj__Mkqenv__item__output_types",
"Desugar.__proj__Mkqenv__item__extern_types",
"Prims.Cons",
"Desugar.__proj__Mkqenv__item__local_names",
"Desugar.__proj__Mkqenv__item__global_env"
] | [] | false | false | false | true | false | let push_name (env: qenv) (name: string) : qenv =
| { env with local_names = name :: env.local_names } | false |
Desugar.fst | Desugar.push_module_abbrev | val push_module_abbrev (env: qenv) (i m: string) : ML unit | val push_module_abbrev (env: qenv) (i m: string) : ML unit | let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 33,
"end_line": 153,
"start_col": 0,
"start_line": 152
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> i: Prims.string -> m: Prims.string -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Desugar.qenv",
"Prims.string",
"Hashtable.insert",
"Desugar.__proj__Mkqenv__item__module_abbrevs",
"Prims.unit"
] | [] | false | true | false | false | false | let push_module_abbrev (env: qenv) (i m: string) : ML unit =
| H.insert env.module_abbrevs i m | false |
Desugar.fst | Desugar.prim_consts | val prim_consts : Prims.list Prims.string | let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ] | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 10,
"end_line": 172,
"start_col": 0,
"start_line": 166
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names } | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.list Prims.string | Prims.Tot | [
"total"
] | [] | [
"Prims.Cons",
"Prims.string",
"Prims.Nil"
] | [] | false | false | false | true | false | let prim_consts =
| [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64"; "UINT8BE"; "UINT16BE"; "UINT32BE";
"UINT64BE"; "field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T"; "all_bytes"; "all_zeros";
"is_range_okay"; "void"
] | false |
|
Desugar.fst | Desugar.resolve_typ_param | val resolve_typ_param (env: qenv) (p: typ_param) : ML typ_param | val resolve_typ_param (env: qenv) (p: typ_param) : ML typ_param | let resolve_typ_param (env:qenv) (p:typ_param) : ML typ_param =
match p with
| Inl e -> resolve_expr env e |> Inl
| _ -> p | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 10,
"end_line": 249,
"start_col": 0,
"start_line": 246
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names }
let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ]
let resolve_ident (env:qenv) (i:ident) : ML ident =
let resolve_to_current_module i =
{ i with v = { i.v with modul_name = Some env.mname } }
in
let maybe_resolve_as_ifdef i
: ML ident
= match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts //it's a primitive constant, e.g. UINT8, leave as is
then i
else if List.mem i.v.name env.local_names //it's a local name (e.g. a parameter name)
then (if Some? i.v.modul_name //must have module name set to None
then error (Printf.sprintf
"Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i) //return the local name as is
else (match i.v.modul_name with //it's a top-level name
| None -> maybe_resolve_as_ifdef i
| Some m -> //if already qualified, check if it is an abbreviation
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } }))
let rec collect_ifdef_guards (env:qenv) (e:expr)
: ML unit
= let check_resolved_to_ifdef i =
match env.global_env.ge_cfg with
| None -> false
| Some (cfg, cfg_module_name) ->
List.mem i.v.name cfg.compile_time_flags.flags
&& i.v.modul_name = Some cfg_module_name
in
match e.v with
| This -> error "'this' is not allowed in the guard of an #if" e.range
| Static _ -> failwith "static should have been eliminated already"
| Constant _ -> ()
| Identifier i ->
if not (check_resolved_to_ifdef i)
then error (Printf.sprintf "Identifier %s is not a compile-time macro but is used in a #if" i.v.name) e.range
| App op args ->
begin
match op with
| And
| Or
| Not -> List.iter (collect_ifdef_guards env) args
| _ -> error "Only boolean expressions over identifiers are supported in #if guards" e.range
end
let rec resolve_expr' (env:qenv) (e:expr') r : ML expr' =
match e with
| Constant _ -> e
| Identifier i -> Identifier (resolve_ident env i)
| This -> e
| Static e' ->
let e' = resolve_expr env e' in
collect_ifdef_guards env e';//mark any variables as top-level IfDef symbols
e'.v
| App op args ->
let args = List.map (resolve_expr env) args in
App op args
and resolve_expr (env:qenv) (e:expr) : ML expr = { e with v = resolve_expr' env e.v e.range } | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> p: Ast.typ_param -> FStar.All.ML Ast.typ_param | FStar.All.ML | [
"ml"
] | [] | [
"Desugar.qenv",
"Ast.typ_param",
"Ast.expr",
"Ast.Inl",
"Ast.out_expr",
"Desugar.resolve_expr",
"Ast.either"
] | [] | false | true | false | false | false | let resolve_typ_param (env: qenv) (p: typ_param) : ML typ_param =
| match p with
| Inl e -> resolve_expr env e |> Inl
| _ -> p | false |
Desugar.fst | Desugar.resolve_param | val resolve_param (env: qenv) (p: param) : ML (param & qenv) | val resolve_param (env: qenv) (p: param) : ML (param & qenv) | let resolve_param (env:qenv) (p:param) : ML (param & qenv) =
let t, i, q = p in
(resolve_typ env t, i, q),
push_name env i.v.name | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 24,
"end_line": 307,
"start_col": 0,
"start_line": 304
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names }
let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ]
let resolve_ident (env:qenv) (i:ident) : ML ident =
let resolve_to_current_module i =
{ i with v = { i.v with modul_name = Some env.mname } }
in
let maybe_resolve_as_ifdef i
: ML ident
= match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts //it's a primitive constant, e.g. UINT8, leave as is
then i
else if List.mem i.v.name env.local_names //it's a local name (e.g. a parameter name)
then (if Some? i.v.modul_name //must have module name set to None
then error (Printf.sprintf
"Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i) //return the local name as is
else (match i.v.modul_name with //it's a top-level name
| None -> maybe_resolve_as_ifdef i
| Some m -> //if already qualified, check if it is an abbreviation
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } }))
let rec collect_ifdef_guards (env:qenv) (e:expr)
: ML unit
= let check_resolved_to_ifdef i =
match env.global_env.ge_cfg with
| None -> false
| Some (cfg, cfg_module_name) ->
List.mem i.v.name cfg.compile_time_flags.flags
&& i.v.modul_name = Some cfg_module_name
in
match e.v with
| This -> error "'this' is not allowed in the guard of an #if" e.range
| Static _ -> failwith "static should have been eliminated already"
| Constant _ -> ()
| Identifier i ->
if not (check_resolved_to_ifdef i)
then error (Printf.sprintf "Identifier %s is not a compile-time macro but is used in a #if" i.v.name) e.range
| App op args ->
begin
match op with
| And
| Or
| Not -> List.iter (collect_ifdef_guards env) args
| _ -> error "Only boolean expressions over identifiers are supported in #if guards" e.range
end
let rec resolve_expr' (env:qenv) (e:expr') r : ML expr' =
match e with
| Constant _ -> e
| Identifier i -> Identifier (resolve_ident env i)
| This -> e
| Static e' ->
let e' = resolve_expr env e' in
collect_ifdef_guards env e';//mark any variables as top-level IfDef symbols
e'.v
| App op args ->
let args = List.map (resolve_expr env) args in
App op args
and resolve_expr (env:qenv) (e:expr) : ML expr = { e with v = resolve_expr' env e.v e.range }
let resolve_typ_param (env:qenv) (p:typ_param) : ML typ_param =
match p with
| Inl e -> resolve_expr env e |> Inl
| _ -> p //Currently not going inside output expressions, should we?
let kind_of_ident (env:qenv) (i:ident)
: ML t_kind
= let _or_ (b0 b1:bool) = b0 || b1 in
if Some? (H.try_find env.output_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_out_t i.v)
then KindOutput
else if
Some? (H.try_find env.extern_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_extern_t i.v)
then KindExtern
else KindSpec
let rec resolve_typ' (env:qenv) (t:typ') : ML typ' =
match t with
| Type_app hd _ args ->
let hd = resolve_ident env hd in
//Set is_out argument to the Type_app appropriately
let k = kind_of_ident env hd in
Type_app hd k (List.map (resolve_typ_param env) args)
| Pointer t -> Pointer (resolve_typ env t)
and resolve_typ (env:qenv) (t:typ) : ML typ = { t with v = resolve_typ' env t.v }
let resolve_atomic_action (env:qenv) (ac:atomic_action) : ML atomic_action =
match ac with
| Action_return e -> Action_return (resolve_expr env e)
| Action_abort
| Action_field_pos_64
| Action_field_pos_32
| Action_field_ptr -> ac
| Action_field_ptr_after e write_to -> Action_field_ptr_after (resolve_expr env e) write_to
| Action_deref i -> Action_deref i //most certainly a type parameter
| Action_assignment lhs rhs ->
Action_assignment lhs (resolve_expr env rhs) //lhs is an action-local variable
| Action_call f args ->
Action_call (resolve_ident env f) (List.map (resolve_expr env) args)
let rec resolve_action' (env:qenv) (act:action') : ML action' =
match act with
| Atomic_action ac -> Atomic_action (resolve_atomic_action env ac)
| Action_seq hd tl ->
Action_seq (resolve_atomic_action env hd) (resolve_action env tl)
| Action_ite hd then_ else_ ->
Action_ite (resolve_expr env hd) (resolve_action env then_) (map_opt (resolve_action env) else_)
| Action_let i a k ->
Action_let i (resolve_atomic_action env a) (resolve_action (push_name env i.v.name) k)
| Action_act a ->
Action_act (resolve_action env a)
and resolve_action (env:qenv) (act:action) : ML action =
{ act with v = resolve_action' env act.v } | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> p: Ast.param -> FStar.All.ML (Ast.param * Desugar.qenv) | FStar.All.ML | [
"ml"
] | [] | [
"Desugar.qenv",
"Ast.param",
"Ast.typ",
"Ast.ident",
"Ast.qualifier",
"FStar.Pervasives.Native.Mktuple2",
"Desugar.push_name",
"Ast.__proj__Mkident'__item__name",
"Ast.__proj__Mkwith_meta_t__item__v",
"Ast.ident'",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple3",
"Desugar.resolve_typ"
] | [] | false | true | false | false | false | let resolve_param (env: qenv) (p: param) : ML (param & qenv) =
| let t, i, q = p in
(resolve_typ env t, i, q), push_name env i.v.name | false |
Steel.Effect.fst | Steel.Effect.par | val par (#aL:Type u#a)
(#aR:Type u#a)
(#preL:vprop)
(#postL:aL -> vprop)
// (#lpreL:req_t preL)
// (#lpostL:ens_t preL aL postL)
($f:unit -> SteelT aL preL postL) // lpreL lpostL)
(#preR:vprop)
(#postR:aR -> vprop)
// (#lpreR:req_t preR)
// (#lpostR:ens_t preR aR postR)
($g:unit -> SteelT aR preR postR) // lpreR lpostR)
: SteelT (aL & aR)
(preL `star` preR)
(fun y -> postL (fst y) `star` postR (snd y)) | val par (#aL:Type u#a)
(#aR:Type u#a)
(#preL:vprop)
(#postL:aL -> vprop)
// (#lpreL:req_t preL)
// (#lpostL:ens_t preL aL postL)
($f:unit -> SteelT aL preL postL) // lpreL lpostL)
(#preR:vprop)
(#postR:aR -> vprop)
// (#lpreR:req_t preR)
// (#lpostR:ens_t preR aR postR)
($g:unit -> SteelT aR preR postR) // lpreR lpostR)
: SteelT (aL & aR)
(preL `star` preR)
(fun y -> postL (fst y) `star` postR (snd y)) | let par f g =
par0 (reify_steel_comp f) (reify_steel_comp g) | {
"file_name": "lib/steel/Steel.Effect.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 48,
"end_line": 692,
"start_col": 0,
"start_line": 691
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Effect
module Sem = Steel.Semantics.Hoare.MST
module Mem = Steel.Memory
open Steel.Semantics.Instantiate
module FExt = FStar.FunctionalExtensionality
#set-options "--ide_id_info_off"
let _:squash (forall p q. can_be_split p q == Mem.slimp (hp_of p) (hp_of q)) = reveal_can_be_split ()
#set-options "--warn_error -330" //turn off the experimental feature warning
let rmem_depends_only_on' (pre:pre_t) (m0:hmem pre) (m1:mem{disjoint m0 m1})
: Lemma (mk_rmem pre m0 == mk_rmem pre (join m0 m1))
= Classical.forall_intro (reveal_mk_rmem pre m0);
Classical.forall_intro (reveal_mk_rmem pre (join m0 m1));
FExt.extensionality_g
(r0:vprop{can_be_split pre r0})
(fun r0 -> normal (t_of r0))
(mk_rmem pre m0)
(mk_rmem pre (join m0 m1))
let rmem_depends_only_on (pre:pre_t)
: Lemma (forall (m0:hmem pre) (m1:mem{disjoint m0 m1}).
mk_rmem pre m0 == mk_rmem pre (join m0 m1))
= Classical.forall_intro_2 (rmem_depends_only_on' pre)
let rmem_depends_only_on_post' (#a:Type) (post:post_t a)
(x:a) (m0:hmem (post x)) (m1:mem{disjoint m0 m1})
: Lemma (mk_rmem (post x) m0 == mk_rmem (post x) (join m0 m1))
= rmem_depends_only_on' (post x) m0 m1
let rmem_depends_only_on_post (#a:Type) (post:post_t a)
: Lemma (forall (x:a) (m0:hmem (post x)) (m1:mem{disjoint m0 m1}).
mk_rmem (post x) m0 == mk_rmem (post x) (join m0 m1))
= Classical.forall_intro_3 (rmem_depends_only_on_post' post)
[@@ __steel_reduce__]
let req_to_act_req (#pre:pre_t) (req:req_t pre) : Sem.l_pre #state (hp_of pre) =
rmem_depends_only_on pre;
fun m0 -> interp (hp_of pre) m0 /\ req (mk_rmem pre m0)
unfold
let to_post (#a:Type) (post:post_t a) = fun x -> (hp_of (post x))
[@@ __steel_reduce__]
let ens_to_act_ens (#pre:pre_t) (#a:Type) (#post:post_t a) (ens:ens_t pre a post)
: Sem.l_post #state #a (hp_of pre) (to_post post)
= rmem_depends_only_on pre;
rmem_depends_only_on_post post;
fun m0 x m1 ->
interp (hp_of pre) m0 /\ interp (hp_of (post x)) m1 /\ ens (mk_rmem pre m0) x (mk_rmem (post x) m1)
let reveal_focus_rmem (#r:vprop) (h:rmem r) (r0:vprop{r `can_be_split` r0}) (r':vprop{r0 `can_be_split` r'})
: Lemma (
r `can_be_split` r' /\
focus_rmem h r0 r' == h r')
= can_be_split_trans r r0 r';
FExt.feq_on_domain_g (unrestricted_focus_rmem h r0)
let focus_is_restrict_mk_rmem (fp0 fp1:vprop) (m:hmem fp0)
: Lemma
(requires fp0 `can_be_split` fp1)
(ensures focus_rmem (mk_rmem fp0 m) fp1 == mk_rmem fp1 m)
= let f0:rmem fp0 = mk_rmem fp0 m in
let f1:rmem fp1 = mk_rmem fp1 m in
let f2:rmem fp1 = focus_rmem f0 fp1 in
let aux (r:vprop{can_be_split fp1 r}) : Lemma (f1 r == f2 r)
= can_be_split_trans fp0 fp1 r;
reveal_mk_rmem fp0 m r;
reveal_mk_rmem fp1 m r;
reveal_focus_rmem f0 fp1 r
in Classical.forall_intro aux;
FExt.extensionality_g
(r0:vprop{can_be_split fp1 r0})
(fun r0 -> normal (t_of r0))
(mk_rmem fp1 m)
(focus_rmem (mk_rmem fp0 m) fp1)
let focus_focus_is_focus (fp0 fp1 fp2:vprop) (m:hmem fp0)
: Lemma
(requires fp0 `can_be_split` fp1 /\ fp1 `can_be_split` fp2)
(ensures focus_rmem (focus_rmem (mk_rmem fp0 m) fp1) fp2 == focus_rmem (mk_rmem fp0 m) fp2)
= let f0:rmem fp0 = mk_rmem fp0 m in
let f1:rmem fp1 = focus_rmem f0 fp1 in
let f20:rmem fp2 = focus_rmem f0 fp2 in
let f21:rmem fp2 = focus_rmem f1 fp2 in
let aux (r:vprop{can_be_split fp2 r}) : Lemma (f20 r == f21 r)
= reveal_mk_rmem fp0 m r;
reveal_focus_rmem f0 fp1 r;
reveal_focus_rmem f0 fp2 r;
reveal_focus_rmem f1 fp2 r
in Classical.forall_intro aux;
FExt.extensionality_g
(r0:vprop{can_be_split fp2 r0})
(fun r0 -> normal (t_of r0))
f20 f21
let focus_replace (fp0 fp1 fp2:vprop) (m:hmem fp0)
: Lemma
(requires fp0 `can_be_split` fp1 /\ fp1 `can_be_split` fp2)
(ensures focus_rmem (mk_rmem fp0 m) fp2 == focus_rmem (mk_rmem fp1 m) fp2)
= let f0:rmem fp0 = mk_rmem fp0 m in
let f1:rmem fp1 = mk_rmem fp1 m in
let f20:rmem fp2 = focus_rmem f0 fp2 in
let f21:rmem fp2 = focus_rmem f1 fp2 in
let aux (r:vprop{can_be_split fp2 r}) : Lemma (f20 r == f21 r)
= reveal_mk_rmem fp0 m r;
reveal_mk_rmem fp1 m r;
reveal_focus_rmem f0 fp2 r;
reveal_focus_rmem f1 fp2 r
in Classical.forall_intro aux;
FExt.extensionality_g
(r0:vprop{can_be_split fp2 r0})
(fun r0 -> normal (t_of r0))
f20 f21
val can_be_split_3_interp (p1 p2 q r:slprop u#1) (m:mem)
: Lemma
(requires p1 `slimp` p2 /\ interp (p1 `Mem.star` q `Mem.star` r) m)
(ensures interp (p2 `Mem.star` q `Mem.star` r) m)
let can_be_split_3_interp p1 p2 q r m =
Mem.star_associative p1 q r;
Mem.star_associative p2 q r;
slimp_star p1 p2 (q `Mem.star` r) (q `Mem.star` r)
let repr (a:Type) (_:bool) (pre:pre_t) (post:post_t a) (req:req_t pre) (ens:ens_t pre a post) =
Sem.action_t #state #a (hp_of pre) (to_post post)
((req_to_act_req req))
((ens_to_act_ens ens))
let nmst_get (#st:Sem.st) ()
: Sem.Mst (Sem.full_mem st)
(fun _ -> True)
(fun s0 s s1 -> s0 == s /\ s == s1)
= NMST.get ()
let rec lemma_frame_equalities_refl (frame:vprop) (h:rmem frame) : Lemma (frame_equalities frame h h) =
match frame with
| VUnit _ -> ()
| VStar p1 p2 ->
can_be_split_star_l p1 p2;
can_be_split_star_r p1 p2;
let h1 = focus_rmem h p1 in
let h2 = focus_rmem h p2 in
lemma_frame_equalities_refl p1 h1;
lemma_frame_equalities_refl p2 h2
let return_ a x #p = fun _ ->
let m0 = nmst_get () in
let h0 = mk_rmem (p x) (core_mem m0) in
lemma_frame_equalities_refl (p x) h0;
x
#push-options "--fuel 0 --ifuel 0"
val req_frame (frame:vprop) (snap:rmem frame) : mprop (hp_of frame)
let req_frame' (frame:vprop) (snap:rmem frame) (m:mem) : prop =
interp (hp_of frame) m /\ mk_rmem frame m == snap
let req_frame frame snap =
rmem_depends_only_on frame;
req_frame' frame snap
#push-options "--z3rlimit 50 --fuel 1 --ifuel 0"
let frame_opaque frame h0 h1 = frame_equalities frame h0 h1
unfold
let norm_opaque = norm [delta_only [`%frame_opaque]]
let lemma_frame_opaque_refl (frame:vprop) (h:rmem frame) : Lemma (frame_opaque frame h h) =
assert (frame_opaque frame h h) by (
T.norm [delta_only [`%frame_opaque]];
T.apply_lemma (`lemma_frame_equalities_refl))
val frame00 (#a:Type)
(#framed:bool)
(#pre:pre_t)
(#post:post_t a)
(#req:req_t pre)
(#ens:ens_t pre a post)
($f:repr a framed pre post req ens)
(frame:vprop)
: repr a
true
(pre `star` frame)
(fun x -> post x `star` frame)
(fun h -> req (focus_rmem h pre))
(fun h0 r h1 -> req (focus_rmem h0 pre) /\ ens (focus_rmem h0 pre) r (focus_rmem h1 (post r)) /\
frame_opaque frame (focus_rmem h0 frame) (focus_rmem h1 frame))
let frame00 #a #framed #pre #post #req #ens f frame =
fun frame' ->
let m0 = nmst_get () in
let snap:rmem frame = mk_rmem frame (core_mem m0) in
focus_is_restrict_mk_rmem (pre `star` frame) pre (core_mem m0);
assert (state.interp (((hp_of pre `state.star` hp_of frame) `state.star` frame' `state.star` state.locks_invariant m0)) m0);
let req' =
(Steel.Semantics.Hoare.MST.frame_lpre #Steel.Semantics.Instantiate.state
#(Steel.Effect.Common.hp_of pre)
(req_to_act_req #pre req)
#(Steel.Effect.Common.hp_of frame)
(req_frame frame snap)) in
assert (req' (state.core m0));
let x = Sem.run #state #_ #_ #_ #_ #_ frame' (Sem.Frame (Sem.Act f) (hp_of frame) (req_frame frame snap)) in
let m1 = nmst_get () in
can_be_split_star_r pre frame;
focus_is_restrict_mk_rmem (pre `star` frame) frame (core_mem m0);
can_be_split_star_r (post x) frame;
focus_is_restrict_mk_rmem (post x `star` frame) frame (core_mem m1);
focus_is_restrict_mk_rmem (post x `star` frame) (post x) (core_mem m1);
// We proved focus_rmem h0 frame == focus_rmem h1 frame so far
let h0:rmem (pre `star` frame) = mk_rmem (pre `star` frame) (core_mem m0) in
lemma_frame_opaque_refl frame (focus_rmem h0 frame);
x
#pop-options
let norm_repr (#a:Type) (#framed:bool)
(#pre:pre_t) (#post:post_t a) (#req:req_t pre) (#ens:ens_t pre a post)
(f:repr a framed pre post req ens) : repr a framed pre post (fun h -> norm_opaque (req h)) (fun h0 x h1 -> norm_opaque (ens h0 x h1))
= f
unfold
let bind_req_opaque (#a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f)
(#pre_g:a -> pre_t)
(#pr:a -> prop)
(req_g:(x:a -> req_t (pre_g x)))
(frame_f:vprop) (frame_g:a -> vprop)
(_:squash (can_be_split_forall_dep pr (fun x -> post_f x `star` frame_f) (fun x -> pre_g x `star` frame_g x)))
: req_t (pre_f `star` frame_f)
= fun m0 ->
req_f (focus_rmem m0 pre_f) /\
(forall (x:a) (h1:hmem (post_f x `star` frame_f)).
(ens_f (focus_rmem m0 pre_f) x (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) (post_f x)) /\
frame_opaque frame_f (focus_rmem m0 frame_f) (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) frame_f))
==> pr x /\
(can_be_split_trans (post_f x `star` frame_f) (pre_g x `star` frame_g x) (pre_g x);
(req_g x) (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) (pre_g x))))
unfold
let bind_ens_opaque (#a:Type) (#b:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f)
(#pre_g:a -> pre_t) (#post_g:a -> post_t b)
(#pr:a -> prop)
(ens_g:(x:a -> ens_t (pre_g x) b (post_g x)))
(frame_f:vprop) (frame_g:a -> vprop)
(post:post_t b)
(_:squash (can_be_split_forall_dep pr (fun x -> post_f x `star` frame_f) (fun x -> pre_g x `star` frame_g x)))
(_:squash (can_be_split_post (fun x y -> post_g x y `star` frame_g x) post))
: ens_t (pre_f `star` frame_f) b post
= fun m0 y m2 ->
req_f (focus_rmem m0 pre_f) /\
(exists (x:a) (h1:hmem (post_f x `star` frame_f)).
pr x /\
(
can_be_split_trans (post_f x `star` frame_f) (pre_g x `star` frame_g x) (pre_g x);
can_be_split_trans (post_f x `star` frame_f) (pre_g x `star` frame_g x) (frame_g x);
can_be_split_trans (post y) (post_g x y `star` frame_g x) (post_g x y);
can_be_split_trans (post y) (post_g x y `star` frame_g x) (frame_g x);
frame_opaque frame_f (focus_rmem m0 frame_f) (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) frame_f) /\
frame_opaque (frame_g x) (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) (frame_g x)) (focus_rmem m2 (frame_g x)) /\
ens_f (focus_rmem m0 pre_f) x (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) (post_f x)) /\
(ens_g x) (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) (pre_g x)) y (focus_rmem m2 (post_g x y))))
val bind_opaque (a:Type) (b:Type)
(#framed_f:eqtype_as_type bool)
(#framed_g:eqtype_as_type bool)
(#pre_f:pre_t) (#post_f:post_t a)
(#req_f:req_t pre_f) (#ens_f:ens_t pre_f a post_f)
(#pre_g:a -> pre_t) (#post_g:a -> post_t b)
(#req_g:(x:a -> req_t (pre_g x))) (#ens_g:(x:a -> ens_t (pre_g x) b (post_g x)))
(#frame_f:vprop) (#frame_g:a -> vprop)
(#post:post_t b)
(# _ : squash (maybe_emp framed_f frame_f))
(# _ : squash (maybe_emp_dep framed_g frame_g))
(#pr:a -> prop)
(#p1:squash (can_be_split_forall_dep pr
(fun x -> post_f x `star` frame_f) (fun x -> pre_g x `star` frame_g x)))
(#p2:squash (can_be_split_post (fun x y -> post_g x y `star` frame_g x) post))
(f:repr a framed_f pre_f post_f req_f ens_f)
(g:(x:a -> repr b framed_g (pre_g x) (post_g x) (req_g x) (ens_g x)))
: repr b
true
(pre_f `star` frame_f)
post
(bind_req_opaque req_f ens_f req_g frame_f frame_g p1)
(bind_ens_opaque req_f ens_f ens_g frame_f frame_g post p1 p2)
#push-options "--z3rlimit 20"
let bind_opaque a b #framed_f #framed_g #pre_f #post_f #req_f #ens_f #pre_g #post_g #req_g #ens_g #frame_f #frame_g #post #_ #_ #p #p2 f g =
fun frame ->
let m0 = nmst_get () in
let h0 = mk_rmem (pre_f `star` frame_f) (core_mem m0) in
let x = frame00 f frame_f frame in
let m1 = nmst_get () in
let h1 = mk_rmem (post_f x `star` frame_f) (core_mem m1) in
let h1' = mk_rmem (pre_g x `star` frame_g x) (core_mem m1) in
can_be_split_trans (post_f x `star` frame_f) (pre_g x `star` frame_g x) (pre_g x);
focus_is_restrict_mk_rmem
(post_f x `star` frame_f)
(pre_g x `star` frame_g x)
(core_mem m1);
focus_focus_is_focus
(post_f x `star` frame_f)
(pre_g x `star` frame_g x)
(pre_g x)
(core_mem m1);
assert (focus_rmem h1' (pre_g x) == focus_rmem h1 (pre_g x));
can_be_split_3_interp
(hp_of (post_f x `star` frame_f))
(hp_of (pre_g x `star` frame_g x))
frame (locks_invariant Set.empty m1) m1;
let y = frame00 (g x) (frame_g x) frame in
let m2 = nmst_get () in
can_be_split_trans (post_f x `star` frame_f) (pre_g x `star` frame_g x) (pre_g x);
can_be_split_trans (post_f x `star` frame_f) (pre_g x `star` frame_g x) (frame_g x);
can_be_split_trans (post y) (post_g x y `star` frame_g x) (post_g x y);
can_be_split_trans (post y) (post_g x y `star` frame_g x) (frame_g x);
let h2' = mk_rmem (post_g x y `star` frame_g x) (core_mem m2) in
let h2 = mk_rmem (post y) (core_mem m2) in
// assert (focus_rmem h1' (pre_g x) == focus_rmem h1 (pre_g x));
focus_focus_is_focus
(post_f x `star` frame_f)
(pre_g x `star` frame_g x)
(frame_g x)
(core_mem m1);
focus_is_restrict_mk_rmem
(post_g x y `star` frame_g x)
(post y)
(core_mem m2);
focus_focus_is_focus
(post_g x y `star` frame_g x)
(post y)
(frame_g x)
(core_mem m2);
focus_focus_is_focus
(post_g x y `star` frame_g x)
(post y)
(post_g x y)
(core_mem m2);
can_be_split_3_interp
(hp_of (post_g x y `star` frame_g x))
(hp_of (post y))
frame (locks_invariant Set.empty m2) m2;
y
#pop-options
let bind a b #framed_f #framed_g #pre_f #post_f #req_f #ens_f #pre_g #post_g #req_g #ens_g #frame_f #frame_g #post #_ #_ #p #p2 f g
= norm_repr (bind_opaque a b #framed_f #framed_g #pre_f #post_f #req_f #ens_f #pre_g #post_g #req_g #ens_g #frame_f #frame_g #post #_ #_ #p #p2 f g)
unfold
let subcomp_pre_opaque (#a:Type)
(#pre_f:pre_t) (#post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f)
(#pre_g:pre_t) (#post_g:post_t a) (req_g:req_t pre_g) (ens_g:ens_t pre_g a post_g)
(#frame:vprop) (#pr:prop)
(_:squash (can_be_split_dep pr pre_g (pre_f `star` frame)))
(_:squash (equiv_forall post_g (fun x -> post_f x `star` frame)))
: pure_pre
= (forall (h0:hmem pre_g). req_g (mk_rmem pre_g h0) ==> pr /\ (
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
req_f (focus_rmem (mk_rmem pre_g h0) pre_f))) /\
(forall (h0:hmem pre_g) (x:a) (h1:hmem (post_g x)). (
pr ==> (
can_be_split_trans (post_g x) (post_f x `star` frame) (post_f x);
can_be_split_trans (pre_g) (pre_f `star` frame) frame;
can_be_split_trans (post_g x) (post_f x `star` frame) frame;
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
(req_g (mk_rmem pre_g h0) /\
ens_f (focus_rmem (mk_rmem pre_g h0) pre_f) x (focus_rmem (mk_rmem (post_g x) h1) (post_f x)) /\
frame_opaque frame
(focus_rmem (mk_rmem pre_g h0) frame)
(focus_rmem (mk_rmem (post_g x) h1) frame))
==> ens_g (mk_rmem pre_g h0) x (mk_rmem (post_g x) h1))
))
val subcomp_opaque (a:Type)
(#framed_f:eqtype_as_type bool)
(#framed_g:eqtype_as_type bool)
(#[@@@ framing_implicit] pre_f:pre_t) (#[@@@ framing_implicit] post_f:post_t a)
(#[@@@ framing_implicit] req_f:req_t pre_f) (#[@@@ framing_implicit] ens_f:ens_t pre_f a post_f)
(#[@@@ framing_implicit] pre_g:pre_t) (#[@@@ framing_implicit] post_g:post_t a)
(#[@@@ framing_implicit] req_g:req_t pre_g) (#[@@@ framing_implicit] ens_g:ens_t pre_g a post_g)
(#[@@@ framing_implicit] frame:vprop)
(#[@@@ framing_implicit] pr : prop)
(#[@@@ framing_implicit] _ : squash (maybe_emp framed_f frame))
(#[@@@ framing_implicit] p1:squash (can_be_split_dep pr pre_g (pre_f `star` frame)))
(#[@@@ framing_implicit] p2:squash (equiv_forall post_g (fun x -> post_f x `star` frame)))
(f:repr a framed_f pre_f post_f req_f ens_f)
: Pure (repr a framed_g pre_g post_g req_g ens_g)
(requires subcomp_pre_opaque req_f ens_f req_g ens_g p1 p2)
(ensures fun _ -> True)
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let subcomp_opaque a #framed_f #framed_g #pre_f #post_f #req_f #ens_f #pre_g #post_g #req_g #ens_g #fr #_ #_ #p1 #p2 f =
fun frame ->
let m0 = nmst_get () in
let h0 = mk_rmem pre_g (core_mem m0) in
can_be_split_trans pre_g (pre_f `star` fr) pre_f;
can_be_split_trans pre_g (pre_f `star` fr) fr;
can_be_split_3_interp (hp_of pre_g) (hp_of (pre_f `star` fr)) frame (locks_invariant Set.empty m0) m0;
focus_replace pre_g (pre_f `star` fr) pre_f (core_mem m0);
let x = frame00 f fr frame in
let m1 = nmst_get () in
let h1 = mk_rmem (post_g x) (core_mem m1) in
let h0' = mk_rmem (pre_f `star` fr) (core_mem m0) in
let h1' = mk_rmem (post_f x `star` fr) (core_mem m1) in
// From frame00
assert (frame_opaque fr (focus_rmem h0' fr) (focus_rmem h1' fr));
// Replace h0'/h1' by h0/h1
focus_replace pre_g (pre_f `star` fr) fr (core_mem m0);
focus_replace (post_g x) (post_f x `star` fr) fr (core_mem m1);
assert (frame_opaque fr (focus_rmem h0 fr) (focus_rmem h1 fr));
can_be_split_trans (post_g x) (post_f x `star` fr) (post_f x);
can_be_split_trans (post_g x) (post_f x `star` fr) fr;
can_be_split_3_interp (hp_of (post_f x `star` fr)) (hp_of (post_g x)) frame (locks_invariant Set.empty m1) m1;
focus_replace (post_g x) (post_f x `star` fr) (post_f x) (core_mem m1);
x
#pop-options
let lemma_rewrite (p:Type) : Lemma (requires T.rewrite_with_tactic vc_norm p) (ensures p)
= T.unfold_rewrite_with_tactic vc_norm p
let lemma_norm_opaque (p:Type) : Lemma (requires norm_opaque p) (ensures p) = ()
(** Need to manually remove the rewrite_with_tactic marker here *)
let lemma_subcomp_pre_opaque_aux1 (#a:Type)
(#pre_f:pre_t) (#post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f)
(#pre_g:pre_t) (#post_g:post_t a) (req_g:req_t pre_g) (ens_g:ens_t pre_g a post_g)
(#frame:vprop)
(#pr:prop)
(p1:squash (can_be_split_dep pr pre_g (pre_f `star` frame)))
(p2:squash (equiv_forall post_g (fun x -> post_f x `star` frame)))
: Lemma
(requires subcomp_pre req_f ens_f req_g ens_g p1 p2)
(ensures (
(forall (h0:hmem pre_g). req_g (mk_rmem pre_g h0) ==> pr /\ (
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
req_f (focus_rmem (mk_rmem pre_g h0) pre_f))) /\
(forall (h0:hmem pre_g) (x:a) (h1:hmem (post_g x)). (
pr ==> (
can_be_split_trans (post_g x) (post_f x `star` frame) (post_f x);
can_be_split_trans (pre_g) (pre_f `star` frame) frame;
can_be_split_trans (post_g x) (post_f x `star` frame) frame;
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
(req_g (mk_rmem pre_g h0) /\
ens_f (focus_rmem (mk_rmem pre_g h0) pre_f) x (focus_rmem (mk_rmem (post_g x) h1) (post_f x)) /\
frame_equalities frame
(focus_rmem (mk_rmem pre_g h0) frame)
(focus_rmem (mk_rmem (post_g x) h1) frame))
==> ens_g (mk_rmem pre_g h0) x (mk_rmem (post_g x) h1))
))))
= lemma_rewrite (squash (
(forall (h0:hmem pre_g). req_g (mk_rmem pre_g h0) ==> pr /\ (
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
req_f (focus_rmem (mk_rmem pre_g h0) pre_f))) /\
(forall (h0:hmem pre_g) (x:a) (h1:hmem (post_g x)). (
pr ==> (
can_be_split_trans (post_g x) (post_f x `star` frame) (post_f x);
can_be_split_trans (pre_g) (pre_f `star` frame) frame;
can_be_split_trans (post_g x) (post_f x `star` frame) frame;
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
(req_g (mk_rmem pre_g h0) /\
ens_f (focus_rmem (mk_rmem pre_g h0) pre_f) x (focus_rmem (mk_rmem (post_g x) h1) (post_f x)) /\
frame_equalities frame
(focus_rmem (mk_rmem pre_g h0) frame)
(focus_rmem (mk_rmem (post_g x) h1) frame))
==> ens_g (mk_rmem pre_g h0) x (mk_rmem (post_g x) h1))
))
))
#push-options "--no_tactics"
let lemma_subcomp_pre_opaque_aux2 (#a:Type)
(#pre_f:pre_t) (#post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f)
(#pre_g:pre_t) (#post_g:post_t a) (req_g:req_t pre_g) (ens_g:ens_t pre_g a post_g)
(#frame:vprop)
(#pr:prop)
(p1:squash (can_be_split_dep pr pre_g (pre_f `star` frame)))
(p2:squash (equiv_forall post_g (fun x -> post_f x `star` frame)))
: Lemma
(requires (
(forall (h0:hmem pre_g). req_g (mk_rmem pre_g h0) ==> pr /\ (
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
req_f (focus_rmem (mk_rmem pre_g h0) pre_f))) /\
(forall (h0:hmem pre_g) (x:a) (h1:hmem (post_g x)). (
pr ==> (
can_be_split_trans (post_g x) (post_f x `star` frame) (post_f x);
can_be_split_trans (pre_g) (pre_f `star` frame) frame;
can_be_split_trans (post_g x) (post_f x `star` frame) frame;
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
(req_g (mk_rmem pre_g h0) /\
ens_f (focus_rmem (mk_rmem pre_g h0) pre_f) x (focus_rmem (mk_rmem (post_g x) h1) (post_f x)) /\
frame_equalities frame
(focus_rmem (mk_rmem pre_g h0) frame)
(focus_rmem (mk_rmem (post_g x) h1) frame))
==> ens_g (mk_rmem pre_g h0) x (mk_rmem (post_g x) h1))
))))
(ensures subcomp_pre_opaque req_f ens_f req_g ens_g p1 p2)
= lemma_norm_opaque (squash (
(forall (h0:hmem pre_g). req_g (mk_rmem pre_g h0) ==> pr /\ (
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
req_f (focus_rmem (mk_rmem pre_g h0) pre_f))) /\
(forall (h0:hmem pre_g) (x:a) (h1:hmem (post_g x)). (
pr ==> (
can_be_split_trans (post_g x) (post_f x `star` frame) (post_f x);
can_be_split_trans (pre_g) (pre_f `star` frame) frame;
can_be_split_trans (post_g x) (post_f x `star` frame) frame;
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
(req_g (mk_rmem pre_g h0) /\
ens_f (focus_rmem (mk_rmem pre_g h0) pre_f) x (focus_rmem (mk_rmem (post_g x) h1) (post_f x)) /\
frame_opaque frame
(focus_rmem (mk_rmem pre_g h0) frame)
(focus_rmem (mk_rmem (post_g x) h1) frame))
==> ens_g (mk_rmem pre_g h0) x (mk_rmem (post_g x) h1))
))
))
let lemma_subcomp_pre_opaque (#a:Type)
(#pre_f:pre_t) (#post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f)
(#pre_g:pre_t) (#post_g:post_t a) (req_g:req_t pre_g) (ens_g:ens_t pre_g a post_g)
(#frame:vprop)
(#pr : prop)
(p1:squash (can_be_split_dep pr pre_g (pre_f `star` frame)))
(p2:squash (equiv_forall post_g (fun x -> post_f x `star` frame)))
: Lemma
(requires subcomp_pre req_f ens_f req_g ens_g p1 p2)
(ensures subcomp_pre_opaque req_f ens_f req_g ens_g p1 p2)
= lemma_subcomp_pre_opaque_aux1 req_f ens_f req_g ens_g p1 p2;
lemma_subcomp_pre_opaque_aux2 req_f ens_f req_g ens_g p1 p2
#pop-options
let subcomp a #framed_f #framed_g #pre_f #post_f #req_f #ens_f #pre_g #post_g #req_g #ens_g #fr #_ #pr #p1 #p2 f =
lemma_subcomp_pre_opaque req_f ens_f req_g ens_g p1 p2;
subcomp_opaque a #framed_f #framed_g #pre_f #post_f #req_f #ens_f #pre_g #post_g #req_g #ens_g #fr #pr #_ #p1 #p2 f
let bind_pure_steel_ a b #wp #pre #post #req #ens f g
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun frame ->
let x = f () in
g x frame
(* We need a bind with DIV to implement par, using reification *)
unfold
let bind_div_steel_req (#a:Type) (wp:pure_wp a)
(#pre_g:pre_t) (req_g:a -> req_t pre_g)
: req_t pre_g
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun h -> wp (fun _ -> True) /\ (forall x. (req_g x) h)
unfold
let bind_div_steel_ens (#a:Type) (#b:Type)
(wp:pure_wp a)
(#pre_g:pre_t) (#post_g:post_t b) (ens_g:a -> ens_t pre_g b post_g)
: ens_t pre_g b post_g
= fun h0 r h1 -> wp (fun _ -> True) /\ (exists x. ens_g x h0 r h1)
#push-options "--z3rlimit 20 --fuel 2 --ifuel 1"
let bind_div_steel (a:Type) (b:Type)
(wp:pure_wp a)
(framed:eqtype_as_type bool)
(pre_g:pre_t) (post_g:post_t b) (req_g:a -> req_t pre_g) (ens_g:a -> ens_t pre_g b post_g)
(f:eqtype_as_type unit -> DIV a wp) (g:(x:a -> repr b framed pre_g post_g (req_g x) (ens_g x)))
: repr b framed pre_g post_g
(bind_div_steel_req wp req_g)
(bind_div_steel_ens wp ens_g)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun frame ->
let x = f () in
g x frame
#pop-options
polymonadic_bind (DIV, SteelBase) |> SteelBase = bind_div_steel
#pop-options
let par0 (#aL:Type u#a) (#preL:vprop) (#postL:aL -> vprop)
(f:repr aL false preL postL (fun _ -> True) (fun _ _ _ -> True))
(#aR:Type u#a) (#preR:vprop) (#postR:aR -> vprop)
(g:repr aR false preR postR (fun _ -> True) (fun _ _ _ -> True))
: SteelT (aL & aR)
(preL `star` preR)
(fun y -> postL (fst y) `star` postR (snd y))
= Steel?.reflect (fun frame -> Sem.run #state #_ #_ #_ #_ #_ frame (Sem.Par (Sem.Act f) (Sem.Act g)))
(*
* AR: Steel is not marked reifiable since we intend to run Steel programs natively
* However to implement the par combinator we need to reify a Steel thunk to its repr
* We could implement it better by having support for reification only in the .fst file
* But for now assuming a (Dv) function
*)
assume val reify_steel_comp
(#a:Type) (#framed:bool) (#pre:vprop) (#post:a -> vprop) (#req:req_t pre) (#ens:ens_t pre a post)
($f:unit -> SteelBase a framed pre post req ens)
: Dv (repr a framed pre post req ens) | {
"checked_file": "/",
"dependencies": [
"Steel.Semantics.Instantiate.fsti.checked",
"Steel.Semantics.Hoare.MST.fst.checked",
"Steel.Memory.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.NMST.fst.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Effect.fst"
} | [
{
"abbrev": false,
"full_module": "Steel.Semantics.Instantiate",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "Sem"
},
{
"abbrev": false,
"full_module": "Steel.Effect.Common",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | $f: (_: Prims.unit -> Steel.Effect.SteelT aL) -> $g: (_: Prims.unit -> Steel.Effect.SteelT aR)
-> Steel.Effect.SteelT (aL * aR) | Steel.Effect.SteelT | [] | [] | [
"Steel.Effect.Common.vprop",
"Prims.unit",
"Steel.Effect.par0",
"FStar.Pervasives.Native.tuple2",
"Steel.Effect.repr",
"Steel.Effect.Common.rmem'",
"Steel.Effect.Common.valid_rmem",
"Prims.l_True",
"Steel.Effect.reify_steel_comp",
"Steel.Effect.Common.rmem"
] | [] | false | true | false | false | false | let par f g =
| par0 (reify_steel_comp f) (reify_steel_comp g) | false |
Desugar.fst | Desugar.resolve_params | val resolve_params (env: qenv) (params: list param) : ML (list param & qenv) | val resolve_params (env: qenv) (params: list param) : ML (list param & qenv) | let resolve_params (env:qenv) (params:list param) : ML (list param & qenv) =
List.fold_left (fun (params, env) p ->
let p, env = resolve_param env p in
params@[p], env) ([], env) params | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 37,
"end_line": 312,
"start_col": 0,
"start_line": 309
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names }
let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ]
let resolve_ident (env:qenv) (i:ident) : ML ident =
let resolve_to_current_module i =
{ i with v = { i.v with modul_name = Some env.mname } }
in
let maybe_resolve_as_ifdef i
: ML ident
= match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts //it's a primitive constant, e.g. UINT8, leave as is
then i
else if List.mem i.v.name env.local_names //it's a local name (e.g. a parameter name)
then (if Some? i.v.modul_name //must have module name set to None
then error (Printf.sprintf
"Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i) //return the local name as is
else (match i.v.modul_name with //it's a top-level name
| None -> maybe_resolve_as_ifdef i
| Some m -> //if already qualified, check if it is an abbreviation
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } }))
let rec collect_ifdef_guards (env:qenv) (e:expr)
: ML unit
= let check_resolved_to_ifdef i =
match env.global_env.ge_cfg with
| None -> false
| Some (cfg, cfg_module_name) ->
List.mem i.v.name cfg.compile_time_flags.flags
&& i.v.modul_name = Some cfg_module_name
in
match e.v with
| This -> error "'this' is not allowed in the guard of an #if" e.range
| Static _ -> failwith "static should have been eliminated already"
| Constant _ -> ()
| Identifier i ->
if not (check_resolved_to_ifdef i)
then error (Printf.sprintf "Identifier %s is not a compile-time macro but is used in a #if" i.v.name) e.range
| App op args ->
begin
match op with
| And
| Or
| Not -> List.iter (collect_ifdef_guards env) args
| _ -> error "Only boolean expressions over identifiers are supported in #if guards" e.range
end
let rec resolve_expr' (env:qenv) (e:expr') r : ML expr' =
match e with
| Constant _ -> e
| Identifier i -> Identifier (resolve_ident env i)
| This -> e
| Static e' ->
let e' = resolve_expr env e' in
collect_ifdef_guards env e';//mark any variables as top-level IfDef symbols
e'.v
| App op args ->
let args = List.map (resolve_expr env) args in
App op args
and resolve_expr (env:qenv) (e:expr) : ML expr = { e with v = resolve_expr' env e.v e.range }
let resolve_typ_param (env:qenv) (p:typ_param) : ML typ_param =
match p with
| Inl e -> resolve_expr env e |> Inl
| _ -> p //Currently not going inside output expressions, should we?
let kind_of_ident (env:qenv) (i:ident)
: ML t_kind
= let _or_ (b0 b1:bool) = b0 || b1 in
if Some? (H.try_find env.output_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_out_t i.v)
then KindOutput
else if
Some? (H.try_find env.extern_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_extern_t i.v)
then KindExtern
else KindSpec
let rec resolve_typ' (env:qenv) (t:typ') : ML typ' =
match t with
| Type_app hd _ args ->
let hd = resolve_ident env hd in
//Set is_out argument to the Type_app appropriately
let k = kind_of_ident env hd in
Type_app hd k (List.map (resolve_typ_param env) args)
| Pointer t -> Pointer (resolve_typ env t)
and resolve_typ (env:qenv) (t:typ) : ML typ = { t with v = resolve_typ' env t.v }
let resolve_atomic_action (env:qenv) (ac:atomic_action) : ML atomic_action =
match ac with
| Action_return e -> Action_return (resolve_expr env e)
| Action_abort
| Action_field_pos_64
| Action_field_pos_32
| Action_field_ptr -> ac
| Action_field_ptr_after e write_to -> Action_field_ptr_after (resolve_expr env e) write_to
| Action_deref i -> Action_deref i //most certainly a type parameter
| Action_assignment lhs rhs ->
Action_assignment lhs (resolve_expr env rhs) //lhs is an action-local variable
| Action_call f args ->
Action_call (resolve_ident env f) (List.map (resolve_expr env) args)
let rec resolve_action' (env:qenv) (act:action') : ML action' =
match act with
| Atomic_action ac -> Atomic_action (resolve_atomic_action env ac)
| Action_seq hd tl ->
Action_seq (resolve_atomic_action env hd) (resolve_action env tl)
| Action_ite hd then_ else_ ->
Action_ite (resolve_expr env hd) (resolve_action env then_) (map_opt (resolve_action env) else_)
| Action_let i a k ->
Action_let i (resolve_atomic_action env a) (resolve_action (push_name env i.v.name) k)
| Action_act a ->
Action_act (resolve_action env a)
and resolve_action (env:qenv) (act:action) : ML action =
{ act with v = resolve_action' env act.v }
let resolve_param (env:qenv) (p:param) : ML (param & qenv) =
let t, i, q = p in
(resolve_typ env t, i, q),
push_name env i.v.name | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> params: Prims.list Ast.param
-> FStar.All.ML (Prims.list Ast.param * Desugar.qenv) | FStar.All.ML | [
"ml"
] | [] | [
"Desugar.qenv",
"Prims.list",
"Ast.param",
"FStar.List.fold_left",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"FStar.List.Tot.Base.op_At",
"Prims.Cons",
"Prims.Nil",
"Desugar.resolve_param"
] | [] | false | true | false | false | false | let resolve_params (env: qenv) (params: list param) : ML (list param & qenv) =
| List.fold_left (fun (params, env) p ->
let p, env = resolve_param env p in
params @ [p], env)
([], env)
params | false |
Desugar.fst | Desugar.resolve_probe_call | val resolve_probe_call : env: Desugar.qenv -> pc: Ast.probe_call -> FStar.All.ALL Ast.probe_call | let resolve_probe_call env pc =
{
probe_fn = map_opt (resolve_ident env) pc.probe_fn;
probe_length = resolve_expr env pc.probe_length;
probe_dest = resolve_ident env pc.probe_dest;
} | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 339,
"start_col": 0,
"start_line": 334
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names }
let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ]
let resolve_ident (env:qenv) (i:ident) : ML ident =
let resolve_to_current_module i =
{ i with v = { i.v with modul_name = Some env.mname } }
in
let maybe_resolve_as_ifdef i
: ML ident
= match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts //it's a primitive constant, e.g. UINT8, leave as is
then i
else if List.mem i.v.name env.local_names //it's a local name (e.g. a parameter name)
then (if Some? i.v.modul_name //must have module name set to None
then error (Printf.sprintf
"Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i) //return the local name as is
else (match i.v.modul_name with //it's a top-level name
| None -> maybe_resolve_as_ifdef i
| Some m -> //if already qualified, check if it is an abbreviation
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } }))
let rec collect_ifdef_guards (env:qenv) (e:expr)
: ML unit
= let check_resolved_to_ifdef i =
match env.global_env.ge_cfg with
| None -> false
| Some (cfg, cfg_module_name) ->
List.mem i.v.name cfg.compile_time_flags.flags
&& i.v.modul_name = Some cfg_module_name
in
match e.v with
| This -> error "'this' is not allowed in the guard of an #if" e.range
| Static _ -> failwith "static should have been eliminated already"
| Constant _ -> ()
| Identifier i ->
if not (check_resolved_to_ifdef i)
then error (Printf.sprintf "Identifier %s is not a compile-time macro but is used in a #if" i.v.name) e.range
| App op args ->
begin
match op with
| And
| Or
| Not -> List.iter (collect_ifdef_guards env) args
| _ -> error "Only boolean expressions over identifiers are supported in #if guards" e.range
end
let rec resolve_expr' (env:qenv) (e:expr') r : ML expr' =
match e with
| Constant _ -> e
| Identifier i -> Identifier (resolve_ident env i)
| This -> e
| Static e' ->
let e' = resolve_expr env e' in
collect_ifdef_guards env e';//mark any variables as top-level IfDef symbols
e'.v
| App op args ->
let args = List.map (resolve_expr env) args in
App op args
and resolve_expr (env:qenv) (e:expr) : ML expr = { e with v = resolve_expr' env e.v e.range }
let resolve_typ_param (env:qenv) (p:typ_param) : ML typ_param =
match p with
| Inl e -> resolve_expr env e |> Inl
| _ -> p //Currently not going inside output expressions, should we?
let kind_of_ident (env:qenv) (i:ident)
: ML t_kind
= let _or_ (b0 b1:bool) = b0 || b1 in
if Some? (H.try_find env.output_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_out_t i.v)
then KindOutput
else if
Some? (H.try_find env.extern_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_extern_t i.v)
then KindExtern
else KindSpec
let rec resolve_typ' (env:qenv) (t:typ') : ML typ' =
match t with
| Type_app hd _ args ->
let hd = resolve_ident env hd in
//Set is_out argument to the Type_app appropriately
let k = kind_of_ident env hd in
Type_app hd k (List.map (resolve_typ_param env) args)
| Pointer t -> Pointer (resolve_typ env t)
and resolve_typ (env:qenv) (t:typ) : ML typ = { t with v = resolve_typ' env t.v }
let resolve_atomic_action (env:qenv) (ac:atomic_action) : ML atomic_action =
match ac with
| Action_return e -> Action_return (resolve_expr env e)
| Action_abort
| Action_field_pos_64
| Action_field_pos_32
| Action_field_ptr -> ac
| Action_field_ptr_after e write_to -> Action_field_ptr_after (resolve_expr env e) write_to
| Action_deref i -> Action_deref i //most certainly a type parameter
| Action_assignment lhs rhs ->
Action_assignment lhs (resolve_expr env rhs) //lhs is an action-local variable
| Action_call f args ->
Action_call (resolve_ident env f) (List.map (resolve_expr env) args)
let rec resolve_action' (env:qenv) (act:action') : ML action' =
match act with
| Atomic_action ac -> Atomic_action (resolve_atomic_action env ac)
| Action_seq hd tl ->
Action_seq (resolve_atomic_action env hd) (resolve_action env tl)
| Action_ite hd then_ else_ ->
Action_ite (resolve_expr env hd) (resolve_action env then_) (map_opt (resolve_action env) else_)
| Action_let i a k ->
Action_let i (resolve_atomic_action env a) (resolve_action (push_name env i.v.name) k)
| Action_act a ->
Action_act (resolve_action env a)
and resolve_action (env:qenv) (act:action) : ML action =
{ act with v = resolve_action' env act.v }
let resolve_param (env:qenv) (p:param) : ML (param & qenv) =
let t, i, q = p in
(resolve_typ env t, i, q),
push_name env i.v.name
let resolve_params (env:qenv) (params:list param) : ML (list param & qenv) =
List.fold_left (fun (params, env) p ->
let p, env = resolve_param env p in
params@[p], env) ([], env) params
let resolve_field_bitwidth_t (env:qenv) (fb:field_bitwidth_t) : ML field_bitwidth_t =
let resolve_bitfield_attr' (env:qenv) (b:bitfield_attr') : ML bitfield_attr' =
{ b with bitfield_type = resolve_typ env b.bitfield_type } in
let resolve_bitfield_attr (env:qenv) (b:bitfield_attr) : ML bitfield_attr =
{ b with v = resolve_bitfield_attr' env b.v } in
match fb with
| Inl _ -> fb
| Inr b -> Inr (resolve_bitfield_attr env b)
let resolve_field_array_t (env:qenv) (farr:field_array_t) : ML field_array_t =
match farr with
| FieldScalar -> farr
| FieldArrayQualified (e, aq) ->
FieldArrayQualified (resolve_expr env e, aq)
| FieldString None -> farr
| FieldString (Some e) -> FieldString (Some (resolve_expr env e))
| FieldConsumeAll -> farr | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> pc: Ast.probe_call -> FStar.All.ALL Ast.probe_call | FStar.All.ALL | [
"trivial_postcondition"
] | [] | [
"Desugar.qenv",
"Ast.probe_call",
"Ast.Mkprobe_call",
"Ast.ident",
"Desugar.resolve_ident",
"Ast.__proj__Mkprobe_call__item__probe_dest",
"Ast.expr",
"Desugar.resolve_expr",
"Ast.__proj__Mkprobe_call__item__probe_length",
"FStar.Pervasives.Native.option",
"Ast.map_opt",
"Ast.__proj__Mkprobe_call__item__probe_fn"
] | [] | false | true | false | false | false | let resolve_probe_call env pc =
| {
probe_fn = map_opt (resolve_ident env) pc.probe_fn;
probe_length = resolve_expr env pc.probe_length;
probe_dest = resolve_ident env pc.probe_dest
} | false |
|
Desugar.fst | Desugar.resolve_typedef_names | val resolve_typedef_names (env: qenv) (td_names: typedef_names) : ML typedef_names | val resolve_typedef_names (env: qenv) (td_names: typedef_names) : ML typedef_names | let resolve_typedef_names (env:qenv) (td_names:typedef_names) : ML typedef_names =
{ td_names with
typedef_name = resolve_ident env td_names.typedef_name;
typedef_abbrev = resolve_ident env td_names.typedef_abbrev;
typedef_ptr_abbrev = resolve_ident env td_names.typedef_ptr_abbrev } | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 72,
"end_line": 385,
"start_col": 0,
"start_line": 381
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names }
let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ]
let resolve_ident (env:qenv) (i:ident) : ML ident =
let resolve_to_current_module i =
{ i with v = { i.v with modul_name = Some env.mname } }
in
let maybe_resolve_as_ifdef i
: ML ident
= match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts //it's a primitive constant, e.g. UINT8, leave as is
then i
else if List.mem i.v.name env.local_names //it's a local name (e.g. a parameter name)
then (if Some? i.v.modul_name //must have module name set to None
then error (Printf.sprintf
"Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i) //return the local name as is
else (match i.v.modul_name with //it's a top-level name
| None -> maybe_resolve_as_ifdef i
| Some m -> //if already qualified, check if it is an abbreviation
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } }))
let rec collect_ifdef_guards (env:qenv) (e:expr)
: ML unit
= let check_resolved_to_ifdef i =
match env.global_env.ge_cfg with
| None -> false
| Some (cfg, cfg_module_name) ->
List.mem i.v.name cfg.compile_time_flags.flags
&& i.v.modul_name = Some cfg_module_name
in
match e.v with
| This -> error "'this' is not allowed in the guard of an #if" e.range
| Static _ -> failwith "static should have been eliminated already"
| Constant _ -> ()
| Identifier i ->
if not (check_resolved_to_ifdef i)
then error (Printf.sprintf "Identifier %s is not a compile-time macro but is used in a #if" i.v.name) e.range
| App op args ->
begin
match op with
| And
| Or
| Not -> List.iter (collect_ifdef_guards env) args
| _ -> error "Only boolean expressions over identifiers are supported in #if guards" e.range
end
let rec resolve_expr' (env:qenv) (e:expr') r : ML expr' =
match e with
| Constant _ -> e
| Identifier i -> Identifier (resolve_ident env i)
| This -> e
| Static e' ->
let e' = resolve_expr env e' in
collect_ifdef_guards env e';//mark any variables as top-level IfDef symbols
e'.v
| App op args ->
let args = List.map (resolve_expr env) args in
App op args
and resolve_expr (env:qenv) (e:expr) : ML expr = { e with v = resolve_expr' env e.v e.range }
let resolve_typ_param (env:qenv) (p:typ_param) : ML typ_param =
match p with
| Inl e -> resolve_expr env e |> Inl
| _ -> p //Currently not going inside output expressions, should we?
let kind_of_ident (env:qenv) (i:ident)
: ML t_kind
= let _or_ (b0 b1:bool) = b0 || b1 in
if Some? (H.try_find env.output_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_out_t i.v)
then KindOutput
else if
Some? (H.try_find env.extern_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_extern_t i.v)
then KindExtern
else KindSpec
let rec resolve_typ' (env:qenv) (t:typ') : ML typ' =
match t with
| Type_app hd _ args ->
let hd = resolve_ident env hd in
//Set is_out argument to the Type_app appropriately
let k = kind_of_ident env hd in
Type_app hd k (List.map (resolve_typ_param env) args)
| Pointer t -> Pointer (resolve_typ env t)
and resolve_typ (env:qenv) (t:typ) : ML typ = { t with v = resolve_typ' env t.v }
let resolve_atomic_action (env:qenv) (ac:atomic_action) : ML atomic_action =
match ac with
| Action_return e -> Action_return (resolve_expr env e)
| Action_abort
| Action_field_pos_64
| Action_field_pos_32
| Action_field_ptr -> ac
| Action_field_ptr_after e write_to -> Action_field_ptr_after (resolve_expr env e) write_to
| Action_deref i -> Action_deref i //most certainly a type parameter
| Action_assignment lhs rhs ->
Action_assignment lhs (resolve_expr env rhs) //lhs is an action-local variable
| Action_call f args ->
Action_call (resolve_ident env f) (List.map (resolve_expr env) args)
let rec resolve_action' (env:qenv) (act:action') : ML action' =
match act with
| Atomic_action ac -> Atomic_action (resolve_atomic_action env ac)
| Action_seq hd tl ->
Action_seq (resolve_atomic_action env hd) (resolve_action env tl)
| Action_ite hd then_ else_ ->
Action_ite (resolve_expr env hd) (resolve_action env then_) (map_opt (resolve_action env) else_)
| Action_let i a k ->
Action_let i (resolve_atomic_action env a) (resolve_action (push_name env i.v.name) k)
| Action_act a ->
Action_act (resolve_action env a)
and resolve_action (env:qenv) (act:action) : ML action =
{ act with v = resolve_action' env act.v }
let resolve_param (env:qenv) (p:param) : ML (param & qenv) =
let t, i, q = p in
(resolve_typ env t, i, q),
push_name env i.v.name
let resolve_params (env:qenv) (params:list param) : ML (list param & qenv) =
List.fold_left (fun (params, env) p ->
let p, env = resolve_param env p in
params@[p], env) ([], env) params
let resolve_field_bitwidth_t (env:qenv) (fb:field_bitwidth_t) : ML field_bitwidth_t =
let resolve_bitfield_attr' (env:qenv) (b:bitfield_attr') : ML bitfield_attr' =
{ b with bitfield_type = resolve_typ env b.bitfield_type } in
let resolve_bitfield_attr (env:qenv) (b:bitfield_attr) : ML bitfield_attr =
{ b with v = resolve_bitfield_attr' env b.v } in
match fb with
| Inl _ -> fb
| Inr b -> Inr (resolve_bitfield_attr env b)
let resolve_field_array_t (env:qenv) (farr:field_array_t) : ML field_array_t =
match farr with
| FieldScalar -> farr
| FieldArrayQualified (e, aq) ->
FieldArrayQualified (resolve_expr env e, aq)
| FieldString None -> farr
| FieldString (Some e) -> FieldString (Some (resolve_expr env e))
| FieldConsumeAll -> farr
let resolve_probe_call env pc =
{
probe_fn = map_opt (resolve_ident env) pc.probe_fn;
probe_length = resolve_expr env pc.probe_length;
probe_dest = resolve_ident env pc.probe_dest;
}
let rec resolve_field (env:qenv) (ff:field) : ML (field & qenv) =
match ff.v with
| AtomicField f -> let f, e = resolve_atomic_field env f in {ff with v = AtomicField f}, e
| RecordField f i -> let fs, _ = resolve_fields env f in {ff with v = RecordField fs i}, env //record fields are not in scope outside the record
| SwitchCaseField f i -> let f = resolve_switch_case env f in {ff with v = SwitchCaseField f i}, env
and resolve_atomic_field (env:qenv) (f:atomic_field) : ML (atomic_field & qenv) =
let resolve_atomic_field' (env:qenv) (sf:atomic_field') : ML atomic_field' =
let is_non_scalar = not (FieldScalar? sf.field_array_opt) in
if is_non_scalar && (Some? sf.field_constraint)
then error (Printf.sprintf "Non-scalar field '%s' cannot be refined with constraints" sf.field_ident.v.name) f.range
else if is_non_scalar && (Some? sf.field_bitwidth)
then error (Printf.sprintf "Non-scalar field '%s' cannot have a bit width" sf.field_ident.v.name) f.range
else (
{ sf with
field_type = resolve_typ env sf.field_type;
field_array_opt = resolve_field_array_t env sf.field_array_opt;
field_constraint = map_opt (resolve_expr env) sf.field_constraint;
field_bitwidth = map_opt (resolve_field_bitwidth_t env) sf.field_bitwidth;
field_action = map_opt (fun (a, b) -> resolve_action env a, b) sf.field_action;
field_probe = map_opt (resolve_probe_call env) sf.field_probe }
)
in
let env = push_name env f.v.field_ident.v.name in
{ f with v = resolve_atomic_field' env f.v }, env
and resolve_fields (env:qenv) (flds:list field) : ML (list field & qenv) =
List.fold_left (fun (flds, env) f ->
let f, env = resolve_field env f in
flds@[f], env) ([], env) flds
and resolve_switch_case (env:qenv) (sc:switch_case) : ML switch_case = //case fields do not escape their scope
let resolve_case (env:qenv) (c:case) : ML case =
match c with
| Case e f -> Case (resolve_expr env e) (fst (resolve_field env f))
| DefaultCase f -> DefaultCase (fst (resolve_field env f)) in
let e, l = sc in
resolve_expr env e, List.map (resolve_case env) l | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> td_names: Ast.typedef_names -> FStar.All.ML Ast.typedef_names | FStar.All.ML | [
"ml"
] | [] | [
"Desugar.qenv",
"Ast.typedef_names",
"Ast.Mktypedef_names",
"Ast.__proj__Mktypedef_names__item__typedef_attributes",
"Ast.ident",
"Desugar.resolve_ident",
"Ast.__proj__Mktypedef_names__item__typedef_ptr_abbrev",
"Ast.__proj__Mktypedef_names__item__typedef_abbrev",
"Ast.__proj__Mktypedef_names__item__typedef_name"
] | [] | false | true | false | false | false | let resolve_typedef_names (env: qenv) (td_names: typedef_names) : ML typedef_names =
| {
td_names with
typedef_name = resolve_ident env td_names.typedef_name;
typedef_abbrev = resolve_ident env td_names.typedef_abbrev;
typedef_ptr_abbrev = resolve_ident env td_names.typedef_ptr_abbrev
} | false |
Desugar.fst | Desugar.resolve_out_type | val resolve_out_type (env: qenv) (out_t: out_typ) : ML out_typ | val resolve_out_type (env: qenv) (out_t: out_typ) : ML out_typ | let resolve_out_type (env:qenv) (out_t:out_typ) : ML out_typ =
{ out_t with
out_typ_names = resolve_typedef_names env out_t.out_typ_names;
out_typ_fields = List.map (resolve_out_field env) out_t.out_typ_fields } | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 76,
"end_line": 403,
"start_col": 0,
"start_line": 400
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names }
let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ]
let resolve_ident (env:qenv) (i:ident) : ML ident =
let resolve_to_current_module i =
{ i with v = { i.v with modul_name = Some env.mname } }
in
let maybe_resolve_as_ifdef i
: ML ident
= match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts //it's a primitive constant, e.g. UINT8, leave as is
then i
else if List.mem i.v.name env.local_names //it's a local name (e.g. a parameter name)
then (if Some? i.v.modul_name //must have module name set to None
then error (Printf.sprintf
"Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i) //return the local name as is
else (match i.v.modul_name with //it's a top-level name
| None -> maybe_resolve_as_ifdef i
| Some m -> //if already qualified, check if it is an abbreviation
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } }))
let rec collect_ifdef_guards (env:qenv) (e:expr)
: ML unit
= let check_resolved_to_ifdef i =
match env.global_env.ge_cfg with
| None -> false
| Some (cfg, cfg_module_name) ->
List.mem i.v.name cfg.compile_time_flags.flags
&& i.v.modul_name = Some cfg_module_name
in
match e.v with
| This -> error "'this' is not allowed in the guard of an #if" e.range
| Static _ -> failwith "static should have been eliminated already"
| Constant _ -> ()
| Identifier i ->
if not (check_resolved_to_ifdef i)
then error (Printf.sprintf "Identifier %s is not a compile-time macro but is used in a #if" i.v.name) e.range
| App op args ->
begin
match op with
| And
| Or
| Not -> List.iter (collect_ifdef_guards env) args
| _ -> error "Only boolean expressions over identifiers are supported in #if guards" e.range
end
let rec resolve_expr' (env:qenv) (e:expr') r : ML expr' =
match e with
| Constant _ -> e
| Identifier i -> Identifier (resolve_ident env i)
| This -> e
| Static e' ->
let e' = resolve_expr env e' in
collect_ifdef_guards env e';//mark any variables as top-level IfDef symbols
e'.v
| App op args ->
let args = List.map (resolve_expr env) args in
App op args
and resolve_expr (env:qenv) (e:expr) : ML expr = { e with v = resolve_expr' env e.v e.range }
let resolve_typ_param (env:qenv) (p:typ_param) : ML typ_param =
match p with
| Inl e -> resolve_expr env e |> Inl
| _ -> p //Currently not going inside output expressions, should we?
let kind_of_ident (env:qenv) (i:ident)
: ML t_kind
= let _or_ (b0 b1:bool) = b0 || b1 in
if Some? (H.try_find env.output_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_out_t i.v)
then KindOutput
else if
Some? (H.try_find env.extern_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_extern_t i.v)
then KindExtern
else KindSpec
let rec resolve_typ' (env:qenv) (t:typ') : ML typ' =
match t with
| Type_app hd _ args ->
let hd = resolve_ident env hd in
//Set is_out argument to the Type_app appropriately
let k = kind_of_ident env hd in
Type_app hd k (List.map (resolve_typ_param env) args)
| Pointer t -> Pointer (resolve_typ env t)
and resolve_typ (env:qenv) (t:typ) : ML typ = { t with v = resolve_typ' env t.v }
let resolve_atomic_action (env:qenv) (ac:atomic_action) : ML atomic_action =
match ac with
| Action_return e -> Action_return (resolve_expr env e)
| Action_abort
| Action_field_pos_64
| Action_field_pos_32
| Action_field_ptr -> ac
| Action_field_ptr_after e write_to -> Action_field_ptr_after (resolve_expr env e) write_to
| Action_deref i -> Action_deref i //most certainly a type parameter
| Action_assignment lhs rhs ->
Action_assignment lhs (resolve_expr env rhs) //lhs is an action-local variable
| Action_call f args ->
Action_call (resolve_ident env f) (List.map (resolve_expr env) args)
let rec resolve_action' (env:qenv) (act:action') : ML action' =
match act with
| Atomic_action ac -> Atomic_action (resolve_atomic_action env ac)
| Action_seq hd tl ->
Action_seq (resolve_atomic_action env hd) (resolve_action env tl)
| Action_ite hd then_ else_ ->
Action_ite (resolve_expr env hd) (resolve_action env then_) (map_opt (resolve_action env) else_)
| Action_let i a k ->
Action_let i (resolve_atomic_action env a) (resolve_action (push_name env i.v.name) k)
| Action_act a ->
Action_act (resolve_action env a)
and resolve_action (env:qenv) (act:action) : ML action =
{ act with v = resolve_action' env act.v }
let resolve_param (env:qenv) (p:param) : ML (param & qenv) =
let t, i, q = p in
(resolve_typ env t, i, q),
push_name env i.v.name
let resolve_params (env:qenv) (params:list param) : ML (list param & qenv) =
List.fold_left (fun (params, env) p ->
let p, env = resolve_param env p in
params@[p], env) ([], env) params
let resolve_field_bitwidth_t (env:qenv) (fb:field_bitwidth_t) : ML field_bitwidth_t =
let resolve_bitfield_attr' (env:qenv) (b:bitfield_attr') : ML bitfield_attr' =
{ b with bitfield_type = resolve_typ env b.bitfield_type } in
let resolve_bitfield_attr (env:qenv) (b:bitfield_attr) : ML bitfield_attr =
{ b with v = resolve_bitfield_attr' env b.v } in
match fb with
| Inl _ -> fb
| Inr b -> Inr (resolve_bitfield_attr env b)
let resolve_field_array_t (env:qenv) (farr:field_array_t) : ML field_array_t =
match farr with
| FieldScalar -> farr
| FieldArrayQualified (e, aq) ->
FieldArrayQualified (resolve_expr env e, aq)
| FieldString None -> farr
| FieldString (Some e) -> FieldString (Some (resolve_expr env e))
| FieldConsumeAll -> farr
let resolve_probe_call env pc =
{
probe_fn = map_opt (resolve_ident env) pc.probe_fn;
probe_length = resolve_expr env pc.probe_length;
probe_dest = resolve_ident env pc.probe_dest;
}
let rec resolve_field (env:qenv) (ff:field) : ML (field & qenv) =
match ff.v with
| AtomicField f -> let f, e = resolve_atomic_field env f in {ff with v = AtomicField f}, e
| RecordField f i -> let fs, _ = resolve_fields env f in {ff with v = RecordField fs i}, env //record fields are not in scope outside the record
| SwitchCaseField f i -> let f = resolve_switch_case env f in {ff with v = SwitchCaseField f i}, env
and resolve_atomic_field (env:qenv) (f:atomic_field) : ML (atomic_field & qenv) =
let resolve_atomic_field' (env:qenv) (sf:atomic_field') : ML atomic_field' =
let is_non_scalar = not (FieldScalar? sf.field_array_opt) in
if is_non_scalar && (Some? sf.field_constraint)
then error (Printf.sprintf "Non-scalar field '%s' cannot be refined with constraints" sf.field_ident.v.name) f.range
else if is_non_scalar && (Some? sf.field_bitwidth)
then error (Printf.sprintf "Non-scalar field '%s' cannot have a bit width" sf.field_ident.v.name) f.range
else (
{ sf with
field_type = resolve_typ env sf.field_type;
field_array_opt = resolve_field_array_t env sf.field_array_opt;
field_constraint = map_opt (resolve_expr env) sf.field_constraint;
field_bitwidth = map_opt (resolve_field_bitwidth_t env) sf.field_bitwidth;
field_action = map_opt (fun (a, b) -> resolve_action env a, b) sf.field_action;
field_probe = map_opt (resolve_probe_call env) sf.field_probe }
)
in
let env = push_name env f.v.field_ident.v.name in
{ f with v = resolve_atomic_field' env f.v }, env
and resolve_fields (env:qenv) (flds:list field) : ML (list field & qenv) =
List.fold_left (fun (flds, env) f ->
let f, env = resolve_field env f in
flds@[f], env) ([], env) flds
and resolve_switch_case (env:qenv) (sc:switch_case) : ML switch_case = //case fields do not escape their scope
let resolve_case (env:qenv) (c:case) : ML case =
match c with
| Case e f -> Case (resolve_expr env e) (fst (resolve_field env f))
| DefaultCase f -> DefaultCase (fst (resolve_field env f)) in
let e, l = sc in
resolve_expr env e, List.map (resolve_case env) l
let resolve_typedef_names (env:qenv) (td_names:typedef_names) : ML typedef_names =
{ td_names with
typedef_name = resolve_ident env td_names.typedef_name;
typedef_abbrev = resolve_ident env td_names.typedef_abbrev;
typedef_ptr_abbrev = resolve_ident env td_names.typedef_ptr_abbrev }
let resolve_enum_case (env:qenv) (ec:enum_case) : ML enum_case =
match ec with
| i, None -> resolve_ident env i, None
| _ -> error "Unexpected enum_case in resolve_enum_case" (fst ec).range
let rec resolve_out_field (env:qenv) (fld:out_field) : ML out_field =
match fld with
| Out_field_named i t n -> Out_field_named i (resolve_typ env t) n
| Out_field_anon l u -> Out_field_anon (resolve_out_fields env l) u
and resolve_out_fields (env:qenv) (flds:list out_field) : ML (list out_field) =
List.map (resolve_out_field env) flds | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> out_t: Ast.out_typ -> FStar.All.ML Ast.out_typ | FStar.All.ML | [
"ml"
] | [] | [
"Desugar.qenv",
"Ast.out_typ",
"Ast.Mkout_typ",
"Ast.__proj__Mkout_typ__item__out_typ_is_union",
"Prims.list",
"Ast.out_field",
"FStar.List.map",
"Desugar.resolve_out_field",
"Ast.__proj__Mkout_typ__item__out_typ_fields",
"Ast.typedef_names",
"Desugar.resolve_typedef_names",
"Ast.__proj__Mkout_typ__item__out_typ_names"
] | [] | false | true | false | false | false | let resolve_out_type (env: qenv) (out_t: out_typ) : ML out_typ =
| {
out_t with
out_typ_names = resolve_typedef_names env out_t.out_typ_names;
out_typ_fields = List.map (resolve_out_field env) out_t.out_typ_fields
} | false |
Desugar.fst | Desugar.resolve_enum_case | val resolve_enum_case (env: qenv) (ec: enum_case) : ML enum_case | val resolve_enum_case (env: qenv) (ec: enum_case) : ML enum_case | let resolve_enum_case (env:qenv) (ec:enum_case) : ML enum_case =
match ec with
| i, None -> resolve_ident env i, None
| _ -> error "Unexpected enum_case in resolve_enum_case" (fst ec).range | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 73,
"end_line": 390,
"start_col": 0,
"start_line": 387
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names }
let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ]
let resolve_ident (env:qenv) (i:ident) : ML ident =
let resolve_to_current_module i =
{ i with v = { i.v with modul_name = Some env.mname } }
in
let maybe_resolve_as_ifdef i
: ML ident
= match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts //it's a primitive constant, e.g. UINT8, leave as is
then i
else if List.mem i.v.name env.local_names //it's a local name (e.g. a parameter name)
then (if Some? i.v.modul_name //must have module name set to None
then error (Printf.sprintf
"Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i) //return the local name as is
else (match i.v.modul_name with //it's a top-level name
| None -> maybe_resolve_as_ifdef i
| Some m -> //if already qualified, check if it is an abbreviation
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } }))
let rec collect_ifdef_guards (env:qenv) (e:expr)
: ML unit
= let check_resolved_to_ifdef i =
match env.global_env.ge_cfg with
| None -> false
| Some (cfg, cfg_module_name) ->
List.mem i.v.name cfg.compile_time_flags.flags
&& i.v.modul_name = Some cfg_module_name
in
match e.v with
| This -> error "'this' is not allowed in the guard of an #if" e.range
| Static _ -> failwith "static should have been eliminated already"
| Constant _ -> ()
| Identifier i ->
if not (check_resolved_to_ifdef i)
then error (Printf.sprintf "Identifier %s is not a compile-time macro but is used in a #if" i.v.name) e.range
| App op args ->
begin
match op with
| And
| Or
| Not -> List.iter (collect_ifdef_guards env) args
| _ -> error "Only boolean expressions over identifiers are supported in #if guards" e.range
end
let rec resolve_expr' (env:qenv) (e:expr') r : ML expr' =
match e with
| Constant _ -> e
| Identifier i -> Identifier (resolve_ident env i)
| This -> e
| Static e' ->
let e' = resolve_expr env e' in
collect_ifdef_guards env e';//mark any variables as top-level IfDef symbols
e'.v
| App op args ->
let args = List.map (resolve_expr env) args in
App op args
and resolve_expr (env:qenv) (e:expr) : ML expr = { e with v = resolve_expr' env e.v e.range }
let resolve_typ_param (env:qenv) (p:typ_param) : ML typ_param =
match p with
| Inl e -> resolve_expr env e |> Inl
| _ -> p //Currently not going inside output expressions, should we?
let kind_of_ident (env:qenv) (i:ident)
: ML t_kind
= let _or_ (b0 b1:bool) = b0 || b1 in
if Some? (H.try_find env.output_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_out_t i.v)
then KindOutput
else if
Some? (H.try_find env.extern_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_extern_t i.v)
then KindExtern
else KindSpec
let rec resolve_typ' (env:qenv) (t:typ') : ML typ' =
match t with
| Type_app hd _ args ->
let hd = resolve_ident env hd in
//Set is_out argument to the Type_app appropriately
let k = kind_of_ident env hd in
Type_app hd k (List.map (resolve_typ_param env) args)
| Pointer t -> Pointer (resolve_typ env t)
and resolve_typ (env:qenv) (t:typ) : ML typ = { t with v = resolve_typ' env t.v }
let resolve_atomic_action (env:qenv) (ac:atomic_action) : ML atomic_action =
match ac with
| Action_return e -> Action_return (resolve_expr env e)
| Action_abort
| Action_field_pos_64
| Action_field_pos_32
| Action_field_ptr -> ac
| Action_field_ptr_after e write_to -> Action_field_ptr_after (resolve_expr env e) write_to
| Action_deref i -> Action_deref i //most certainly a type parameter
| Action_assignment lhs rhs ->
Action_assignment lhs (resolve_expr env rhs) //lhs is an action-local variable
| Action_call f args ->
Action_call (resolve_ident env f) (List.map (resolve_expr env) args)
let rec resolve_action' (env:qenv) (act:action') : ML action' =
match act with
| Atomic_action ac -> Atomic_action (resolve_atomic_action env ac)
| Action_seq hd tl ->
Action_seq (resolve_atomic_action env hd) (resolve_action env tl)
| Action_ite hd then_ else_ ->
Action_ite (resolve_expr env hd) (resolve_action env then_) (map_opt (resolve_action env) else_)
| Action_let i a k ->
Action_let i (resolve_atomic_action env a) (resolve_action (push_name env i.v.name) k)
| Action_act a ->
Action_act (resolve_action env a)
and resolve_action (env:qenv) (act:action) : ML action =
{ act with v = resolve_action' env act.v }
let resolve_param (env:qenv) (p:param) : ML (param & qenv) =
let t, i, q = p in
(resolve_typ env t, i, q),
push_name env i.v.name
let resolve_params (env:qenv) (params:list param) : ML (list param & qenv) =
List.fold_left (fun (params, env) p ->
let p, env = resolve_param env p in
params@[p], env) ([], env) params
let resolve_field_bitwidth_t (env:qenv) (fb:field_bitwidth_t) : ML field_bitwidth_t =
let resolve_bitfield_attr' (env:qenv) (b:bitfield_attr') : ML bitfield_attr' =
{ b with bitfield_type = resolve_typ env b.bitfield_type } in
let resolve_bitfield_attr (env:qenv) (b:bitfield_attr) : ML bitfield_attr =
{ b with v = resolve_bitfield_attr' env b.v } in
match fb with
| Inl _ -> fb
| Inr b -> Inr (resolve_bitfield_attr env b)
let resolve_field_array_t (env:qenv) (farr:field_array_t) : ML field_array_t =
match farr with
| FieldScalar -> farr
| FieldArrayQualified (e, aq) ->
FieldArrayQualified (resolve_expr env e, aq)
| FieldString None -> farr
| FieldString (Some e) -> FieldString (Some (resolve_expr env e))
| FieldConsumeAll -> farr
let resolve_probe_call env pc =
{
probe_fn = map_opt (resolve_ident env) pc.probe_fn;
probe_length = resolve_expr env pc.probe_length;
probe_dest = resolve_ident env pc.probe_dest;
}
let rec resolve_field (env:qenv) (ff:field) : ML (field & qenv) =
match ff.v with
| AtomicField f -> let f, e = resolve_atomic_field env f in {ff with v = AtomicField f}, e
| RecordField f i -> let fs, _ = resolve_fields env f in {ff with v = RecordField fs i}, env //record fields are not in scope outside the record
| SwitchCaseField f i -> let f = resolve_switch_case env f in {ff with v = SwitchCaseField f i}, env
and resolve_atomic_field (env:qenv) (f:atomic_field) : ML (atomic_field & qenv) =
let resolve_atomic_field' (env:qenv) (sf:atomic_field') : ML atomic_field' =
let is_non_scalar = not (FieldScalar? sf.field_array_opt) in
if is_non_scalar && (Some? sf.field_constraint)
then error (Printf.sprintf "Non-scalar field '%s' cannot be refined with constraints" sf.field_ident.v.name) f.range
else if is_non_scalar && (Some? sf.field_bitwidth)
then error (Printf.sprintf "Non-scalar field '%s' cannot have a bit width" sf.field_ident.v.name) f.range
else (
{ sf with
field_type = resolve_typ env sf.field_type;
field_array_opt = resolve_field_array_t env sf.field_array_opt;
field_constraint = map_opt (resolve_expr env) sf.field_constraint;
field_bitwidth = map_opt (resolve_field_bitwidth_t env) sf.field_bitwidth;
field_action = map_opt (fun (a, b) -> resolve_action env a, b) sf.field_action;
field_probe = map_opt (resolve_probe_call env) sf.field_probe }
)
in
let env = push_name env f.v.field_ident.v.name in
{ f with v = resolve_atomic_field' env f.v }, env
and resolve_fields (env:qenv) (flds:list field) : ML (list field & qenv) =
List.fold_left (fun (flds, env) f ->
let f, env = resolve_field env f in
flds@[f], env) ([], env) flds
and resolve_switch_case (env:qenv) (sc:switch_case) : ML switch_case = //case fields do not escape their scope
let resolve_case (env:qenv) (c:case) : ML case =
match c with
| Case e f -> Case (resolve_expr env e) (fst (resolve_field env f))
| DefaultCase f -> DefaultCase (fst (resolve_field env f)) in
let e, l = sc in
resolve_expr env e, List.map (resolve_case env) l
let resolve_typedef_names (env:qenv) (td_names:typedef_names) : ML typedef_names =
{ td_names with
typedef_name = resolve_ident env td_names.typedef_name;
typedef_abbrev = resolve_ident env td_names.typedef_abbrev;
typedef_ptr_abbrev = resolve_ident env td_names.typedef_ptr_abbrev } | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> ec: Ast.enum_case -> FStar.All.ML Ast.enum_case | FStar.All.ML | [
"ml"
] | [] | [
"Desugar.qenv",
"Ast.enum_case",
"Ast.ident",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.option",
"Ast.either",
"Prims.int",
"FStar.Pervasives.Native.None",
"Desugar.resolve_ident",
"FStar.Pervasives.Native.tuple2",
"Ast.error",
"Ast.__proj__Mkwith_meta_t__item__range",
"Ast.ident'",
"FStar.Pervasives.Native.fst"
] | [] | false | true | false | false | false | let resolve_enum_case (env: qenv) (ec: enum_case) : ML enum_case =
| match ec with
| i, None -> resolve_ident env i, None
| _ -> error "Unexpected enum_case in resolve_enum_case" (fst ec).range | false |
Desugar.fst | Desugar.resolve_expr | val resolve_expr (env: qenv) (e: expr) : ML expr | val resolve_expr (env: qenv) (e: expr) : ML expr | let rec resolve_expr' (env:qenv) (e:expr') r : ML expr' =
match e with
| Constant _ -> e
| Identifier i -> Identifier (resolve_ident env i)
| This -> e
| Static e' ->
let e' = resolve_expr env e' in
collect_ifdef_guards env e';//mark any variables as top-level IfDef symbols
e'.v
| App op args ->
let args = List.map (resolve_expr env) args in
App op args
and resolve_expr (env:qenv) (e:expr) : ML expr = { e with v = resolve_expr' env e.v e.range } | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 93,
"end_line": 244,
"start_col": 0,
"start_line": 230
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names }
let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ]
let resolve_ident (env:qenv) (i:ident) : ML ident =
let resolve_to_current_module i =
{ i with v = { i.v with modul_name = Some env.mname } }
in
let maybe_resolve_as_ifdef i
: ML ident
= match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts //it's a primitive constant, e.g. UINT8, leave as is
then i
else if List.mem i.v.name env.local_names //it's a local name (e.g. a parameter name)
then (if Some? i.v.modul_name //must have module name set to None
then error (Printf.sprintf
"Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i) //return the local name as is
else (match i.v.modul_name with //it's a top-level name
| None -> maybe_resolve_as_ifdef i
| Some m -> //if already qualified, check if it is an abbreviation
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } }))
let rec collect_ifdef_guards (env:qenv) (e:expr)
: ML unit
= let check_resolved_to_ifdef i =
match env.global_env.ge_cfg with
| None -> false
| Some (cfg, cfg_module_name) ->
List.mem i.v.name cfg.compile_time_flags.flags
&& i.v.modul_name = Some cfg_module_name
in
match e.v with
| This -> error "'this' is not allowed in the guard of an #if" e.range
| Static _ -> failwith "static should have been eliminated already"
| Constant _ -> ()
| Identifier i ->
if not (check_resolved_to_ifdef i)
then error (Printf.sprintf "Identifier %s is not a compile-time macro but is used in a #if" i.v.name) e.range
| App op args ->
begin
match op with
| And
| Or
| Not -> List.iter (collect_ifdef_guards env) args
| _ -> error "Only boolean expressions over identifiers are supported in #if guards" e.range
end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> e: Ast.expr -> FStar.All.ML Ast.expr | FStar.All.ML | [
"ml"
] | [
"resolve_expr'",
"resolve_expr"
] | [
"Desugar.qenv",
"Ast.expr",
"Ast.Mkwith_meta_t",
"Ast.expr'",
"Ast.__proj__Mkwith_meta_t__item__range",
"Ast.__proj__Mkwith_meta_t__item__comments",
"Desugar.resolve_expr'",
"Ast.__proj__Mkwith_meta_t__item__v"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec resolve_expr (env: qenv) (e: expr) : ML expr =
| { e with v = resolve_expr' env e.v e.range } | false |
Desugar.fst | Desugar.push_extern_type | val push_extern_type (env: qenv) (td: typedef_names) : ML unit | val push_extern_type (env: qenv) (td: typedef_names) : ML unit | let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v () | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 50,
"end_line": 161,
"start_col": 0,
"start_line": 159
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> td: Ast.typedef_names -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Desugar.qenv",
"Ast.typedef_names",
"Hashtable.insert",
"Ast.ident'",
"Prims.unit",
"Desugar.__proj__Mkqenv__item__extern_types",
"Ast.__proj__Mkwith_meta_t__item__v",
"Ast.__proj__Mktypedef_names__item__typedef_abbrev",
"Ast.__proj__Mktypedef_names__item__typedef_name"
] | [] | false | true | false | false | false | let push_extern_type (env: qenv) (td: typedef_names) : ML unit =
| H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v () | false |
Vale.AES.X64.GHash.fsti | Vale.AES.X64.GHash.get_last_slice_workaround | val get_last_slice_workaround : s: FStar.Seq.Base.seq Vale.X64.Decls.quad32 -> start_pos: Prims.int -> end_pos: Prims.int
-> Vale.Def.Words_s.four Vale.Def.Types_s.nat32 | let get_last_slice_workaround (s:seq quad32) (start_pos end_pos:int) =
if 0 <= start_pos && start_pos < end_pos && end_pos <= length s then
last (slice s start_pos end_pos)
else
Mkfour 0 0 0 0 | {
"file_name": "obj/Vale.AES.X64.GHash.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 18,
"end_line": 33,
"start_col": 0,
"start_line": 29
} | module Vale.AES.X64.GHash
open Vale.Def.Opaque_s
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.AES.AES_s
open Vale.AES.GHash_s
open Vale.AES.GHash
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.AES.GCTR_s
open Vale.AES.GCM_helpers
open Vale.Math.Poly2_s
open Vale.Poly1305.Math
open Vale.AES.X64.GF128_Mul
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.InsAes
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.X64.CPU_Features_s | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.InsAes.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Poly1305.Math.fsti.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.X64.GF128_Mul.fsti.checked",
"Vale.AES.GHash_s.fst.checked",
"Vale.AES.GHash.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.fsti.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.GCM_helpers.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.X64.GHash.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_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": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq Vale.X64.Decls.quad32 -> start_pos: Prims.int -> end_pos: Prims.int
-> Vale.Def.Words_s.four Vale.Def.Types_s.nat32 | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.X64.Decls.quad32",
"Prims.int",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"FStar.Seq.Properties.last",
"FStar.Seq.Base.slice",
"Prims.bool",
"Vale.Def.Words_s.Mkfour",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words_s.four"
] | [] | false | false | false | true | false | let get_last_slice_workaround (s: seq quad32) (start_pos end_pos: int) =
| if 0 <= start_pos && start_pos < end_pos && end_pos <= length s
then last (slice s start_pos end_pos)
else Mkfour 0 0 0 0 | false |
|
Desugar.fst | Desugar.resolve_typ' | val resolve_typ' (env: qenv) (t: typ') : ML typ' | val resolve_typ' (env: qenv) (t: typ') : ML typ' | let rec resolve_typ' (env:qenv) (t:typ') : ML typ' =
match t with
| Type_app hd _ args ->
let hd = resolve_ident env hd in
//Set is_out argument to the Type_app appropriately
let k = kind_of_ident env hd in
Type_app hd k (List.map (resolve_typ_param env) args)
| Pointer t -> Pointer (resolve_typ env t)
and resolve_typ (env:qenv) (t:typ) : ML typ = { t with v = resolve_typ' env t.v } | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 81,
"end_line": 273,
"start_col": 0,
"start_line": 264
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names }
let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ]
let resolve_ident (env:qenv) (i:ident) : ML ident =
let resolve_to_current_module i =
{ i with v = { i.v with modul_name = Some env.mname } }
in
let maybe_resolve_as_ifdef i
: ML ident
= match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts //it's a primitive constant, e.g. UINT8, leave as is
then i
else if List.mem i.v.name env.local_names //it's a local name (e.g. a parameter name)
then (if Some? i.v.modul_name //must have module name set to None
then error (Printf.sprintf
"Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i) //return the local name as is
else (match i.v.modul_name with //it's a top-level name
| None -> maybe_resolve_as_ifdef i
| Some m -> //if already qualified, check if it is an abbreviation
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } }))
let rec collect_ifdef_guards (env:qenv) (e:expr)
: ML unit
= let check_resolved_to_ifdef i =
match env.global_env.ge_cfg with
| None -> false
| Some (cfg, cfg_module_name) ->
List.mem i.v.name cfg.compile_time_flags.flags
&& i.v.modul_name = Some cfg_module_name
in
match e.v with
| This -> error "'this' is not allowed in the guard of an #if" e.range
| Static _ -> failwith "static should have been eliminated already"
| Constant _ -> ()
| Identifier i ->
if not (check_resolved_to_ifdef i)
then error (Printf.sprintf "Identifier %s is not a compile-time macro but is used in a #if" i.v.name) e.range
| App op args ->
begin
match op with
| And
| Or
| Not -> List.iter (collect_ifdef_guards env) args
| _ -> error "Only boolean expressions over identifiers are supported in #if guards" e.range
end
let rec resolve_expr' (env:qenv) (e:expr') r : ML expr' =
match e with
| Constant _ -> e
| Identifier i -> Identifier (resolve_ident env i)
| This -> e
| Static e' ->
let e' = resolve_expr env e' in
collect_ifdef_guards env e';//mark any variables as top-level IfDef symbols
e'.v
| App op args ->
let args = List.map (resolve_expr env) args in
App op args
and resolve_expr (env:qenv) (e:expr) : ML expr = { e with v = resolve_expr' env e.v e.range }
let resolve_typ_param (env:qenv) (p:typ_param) : ML typ_param =
match p with
| Inl e -> resolve_expr env e |> Inl
| _ -> p //Currently not going inside output expressions, should we?
let kind_of_ident (env:qenv) (i:ident)
: ML t_kind
= let _or_ (b0 b1:bool) = b0 || b1 in
if Some? (H.try_find env.output_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_out_t i.v)
then KindOutput
else if
Some? (H.try_find env.extern_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_extern_t i.v)
then KindExtern
else KindSpec | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> t: Ast.typ' -> FStar.All.ML Ast.typ' | FStar.All.ML | [
"ml"
] | [
"resolve_typ'",
"resolve_typ"
] | [
"Desugar.qenv",
"Ast.typ'",
"Ast.ident",
"Ast.t_kind",
"Prims.list",
"Ast.either",
"Ast.expr",
"Ast.out_expr",
"Ast.Type_app",
"FStar.List.map",
"Desugar.resolve_typ_param",
"Desugar.kind_of_ident",
"Desugar.resolve_ident",
"Ast.with_meta_t",
"Ast.Pointer",
"Desugar.resolve_typ",
"Ast.typ"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec resolve_typ' (env: qenv) (t: typ') : ML typ' =
| match t with
| Type_app hd _ args ->
let hd = resolve_ident env hd in
let k = kind_of_ident env hd in
Type_app hd k (List.map (resolve_typ_param env) args)
| Pointer t -> Pointer (resolve_typ env t) | false |
Desugar.fst | Desugar.resolve_decl | val resolve_decl (env: qenv) (d: decl) : ML decl | val resolve_decl (env: qenv) (d: decl) : ML decl | let resolve_decl (env:qenv) (d:decl) : ML decl = decl_with_v d (resolve_decl' env d.d_decl.v) | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 93,
"end_line": 442,
"start_col": 0,
"start_line": 442
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names }
let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ]
let resolve_ident (env:qenv) (i:ident) : ML ident =
let resolve_to_current_module i =
{ i with v = { i.v with modul_name = Some env.mname } }
in
let maybe_resolve_as_ifdef i
: ML ident
= match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts //it's a primitive constant, e.g. UINT8, leave as is
then i
else if List.mem i.v.name env.local_names //it's a local name (e.g. a parameter name)
then (if Some? i.v.modul_name //must have module name set to None
then error (Printf.sprintf
"Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i) //return the local name as is
else (match i.v.modul_name with //it's a top-level name
| None -> maybe_resolve_as_ifdef i
| Some m -> //if already qualified, check if it is an abbreviation
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } }))
let rec collect_ifdef_guards (env:qenv) (e:expr)
: ML unit
= let check_resolved_to_ifdef i =
match env.global_env.ge_cfg with
| None -> false
| Some (cfg, cfg_module_name) ->
List.mem i.v.name cfg.compile_time_flags.flags
&& i.v.modul_name = Some cfg_module_name
in
match e.v with
| This -> error "'this' is not allowed in the guard of an #if" e.range
| Static _ -> failwith "static should have been eliminated already"
| Constant _ -> ()
| Identifier i ->
if not (check_resolved_to_ifdef i)
then error (Printf.sprintf "Identifier %s is not a compile-time macro but is used in a #if" i.v.name) e.range
| App op args ->
begin
match op with
| And
| Or
| Not -> List.iter (collect_ifdef_guards env) args
| _ -> error "Only boolean expressions over identifiers are supported in #if guards" e.range
end
let rec resolve_expr' (env:qenv) (e:expr') r : ML expr' =
match e with
| Constant _ -> e
| Identifier i -> Identifier (resolve_ident env i)
| This -> e
| Static e' ->
let e' = resolve_expr env e' in
collect_ifdef_guards env e';//mark any variables as top-level IfDef symbols
e'.v
| App op args ->
let args = List.map (resolve_expr env) args in
App op args
and resolve_expr (env:qenv) (e:expr) : ML expr = { e with v = resolve_expr' env e.v e.range }
let resolve_typ_param (env:qenv) (p:typ_param) : ML typ_param =
match p with
| Inl e -> resolve_expr env e |> Inl
| _ -> p //Currently not going inside output expressions, should we?
let kind_of_ident (env:qenv) (i:ident)
: ML t_kind
= let _or_ (b0 b1:bool) = b0 || b1 in
if Some? (H.try_find env.output_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_out_t i.v)
then KindOutput
else if
Some? (H.try_find env.extern_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_extern_t i.v)
then KindExtern
else KindSpec
let rec resolve_typ' (env:qenv) (t:typ') : ML typ' =
match t with
| Type_app hd _ args ->
let hd = resolve_ident env hd in
//Set is_out argument to the Type_app appropriately
let k = kind_of_ident env hd in
Type_app hd k (List.map (resolve_typ_param env) args)
| Pointer t -> Pointer (resolve_typ env t)
and resolve_typ (env:qenv) (t:typ) : ML typ = { t with v = resolve_typ' env t.v }
let resolve_atomic_action (env:qenv) (ac:atomic_action) : ML atomic_action =
match ac with
| Action_return e -> Action_return (resolve_expr env e)
| Action_abort
| Action_field_pos_64
| Action_field_pos_32
| Action_field_ptr -> ac
| Action_field_ptr_after e write_to -> Action_field_ptr_after (resolve_expr env e) write_to
| Action_deref i -> Action_deref i //most certainly a type parameter
| Action_assignment lhs rhs ->
Action_assignment lhs (resolve_expr env rhs) //lhs is an action-local variable
| Action_call f args ->
Action_call (resolve_ident env f) (List.map (resolve_expr env) args)
let rec resolve_action' (env:qenv) (act:action') : ML action' =
match act with
| Atomic_action ac -> Atomic_action (resolve_atomic_action env ac)
| Action_seq hd tl ->
Action_seq (resolve_atomic_action env hd) (resolve_action env tl)
| Action_ite hd then_ else_ ->
Action_ite (resolve_expr env hd) (resolve_action env then_) (map_opt (resolve_action env) else_)
| Action_let i a k ->
Action_let i (resolve_atomic_action env a) (resolve_action (push_name env i.v.name) k)
| Action_act a ->
Action_act (resolve_action env a)
and resolve_action (env:qenv) (act:action) : ML action =
{ act with v = resolve_action' env act.v }
let resolve_param (env:qenv) (p:param) : ML (param & qenv) =
let t, i, q = p in
(resolve_typ env t, i, q),
push_name env i.v.name
let resolve_params (env:qenv) (params:list param) : ML (list param & qenv) =
List.fold_left (fun (params, env) p ->
let p, env = resolve_param env p in
params@[p], env) ([], env) params
let resolve_field_bitwidth_t (env:qenv) (fb:field_bitwidth_t) : ML field_bitwidth_t =
let resolve_bitfield_attr' (env:qenv) (b:bitfield_attr') : ML bitfield_attr' =
{ b with bitfield_type = resolve_typ env b.bitfield_type } in
let resolve_bitfield_attr (env:qenv) (b:bitfield_attr) : ML bitfield_attr =
{ b with v = resolve_bitfield_attr' env b.v } in
match fb with
| Inl _ -> fb
| Inr b -> Inr (resolve_bitfield_attr env b)
let resolve_field_array_t (env:qenv) (farr:field_array_t) : ML field_array_t =
match farr with
| FieldScalar -> farr
| FieldArrayQualified (e, aq) ->
FieldArrayQualified (resolve_expr env e, aq)
| FieldString None -> farr
| FieldString (Some e) -> FieldString (Some (resolve_expr env e))
| FieldConsumeAll -> farr
let resolve_probe_call env pc =
{
probe_fn = map_opt (resolve_ident env) pc.probe_fn;
probe_length = resolve_expr env pc.probe_length;
probe_dest = resolve_ident env pc.probe_dest;
}
let rec resolve_field (env:qenv) (ff:field) : ML (field & qenv) =
match ff.v with
| AtomicField f -> let f, e = resolve_atomic_field env f in {ff with v = AtomicField f}, e
| RecordField f i -> let fs, _ = resolve_fields env f in {ff with v = RecordField fs i}, env //record fields are not in scope outside the record
| SwitchCaseField f i -> let f = resolve_switch_case env f in {ff with v = SwitchCaseField f i}, env
and resolve_atomic_field (env:qenv) (f:atomic_field) : ML (atomic_field & qenv) =
let resolve_atomic_field' (env:qenv) (sf:atomic_field') : ML atomic_field' =
let is_non_scalar = not (FieldScalar? sf.field_array_opt) in
if is_non_scalar && (Some? sf.field_constraint)
then error (Printf.sprintf "Non-scalar field '%s' cannot be refined with constraints" sf.field_ident.v.name) f.range
else if is_non_scalar && (Some? sf.field_bitwidth)
then error (Printf.sprintf "Non-scalar field '%s' cannot have a bit width" sf.field_ident.v.name) f.range
else (
{ sf with
field_type = resolve_typ env sf.field_type;
field_array_opt = resolve_field_array_t env sf.field_array_opt;
field_constraint = map_opt (resolve_expr env) sf.field_constraint;
field_bitwidth = map_opt (resolve_field_bitwidth_t env) sf.field_bitwidth;
field_action = map_opt (fun (a, b) -> resolve_action env a, b) sf.field_action;
field_probe = map_opt (resolve_probe_call env) sf.field_probe }
)
in
let env = push_name env f.v.field_ident.v.name in
{ f with v = resolve_atomic_field' env f.v }, env
and resolve_fields (env:qenv) (flds:list field) : ML (list field & qenv) =
List.fold_left (fun (flds, env) f ->
let f, env = resolve_field env f in
flds@[f], env) ([], env) flds
and resolve_switch_case (env:qenv) (sc:switch_case) : ML switch_case = //case fields do not escape their scope
let resolve_case (env:qenv) (c:case) : ML case =
match c with
| Case e f -> Case (resolve_expr env e) (fst (resolve_field env f))
| DefaultCase f -> DefaultCase (fst (resolve_field env f)) in
let e, l = sc in
resolve_expr env e, List.map (resolve_case env) l
let resolve_typedef_names (env:qenv) (td_names:typedef_names) : ML typedef_names =
{ td_names with
typedef_name = resolve_ident env td_names.typedef_name;
typedef_abbrev = resolve_ident env td_names.typedef_abbrev;
typedef_ptr_abbrev = resolve_ident env td_names.typedef_ptr_abbrev }
let resolve_enum_case (env:qenv) (ec:enum_case) : ML enum_case =
match ec with
| i, None -> resolve_ident env i, None
| _ -> error "Unexpected enum_case in resolve_enum_case" (fst ec).range
let rec resolve_out_field (env:qenv) (fld:out_field) : ML out_field =
match fld with
| Out_field_named i t n -> Out_field_named i (resolve_typ env t) n
| Out_field_anon l u -> Out_field_anon (resolve_out_fields env l) u
and resolve_out_fields (env:qenv) (flds:list out_field) : ML (list out_field) =
List.map (resolve_out_field env) flds
let resolve_out_type (env:qenv) (out_t:out_typ) : ML out_typ =
{ out_t with
out_typ_names = resolve_typedef_names env out_t.out_typ_names;
out_typ_fields = List.map (resolve_out_field env) out_t.out_typ_fields }
let resolve_decl' (env:qenv) (d:decl') : ML decl' =
match d with
| ModuleAbbrev i m -> push_module_abbrev env i.v.name m.v.name; d
| Define i topt c ->
Define (resolve_ident env i) (map_opt (resolve_typ env) topt) c
| TypeAbbrev t i ->
TypeAbbrev (resolve_typ env t) (resolve_ident env i)
| Enum t i ecs ->
Enum (resolve_typ env t) (resolve_ident env i) (List.map (resolve_enum_case env) ecs)
| Record td_names params where flds ->
let td_names = resolve_typedef_names env td_names in
let params, env = resolve_params env params in
let where = map_opt (resolve_expr env) where in
let flds, _ = resolve_fields env flds in
Record td_names params where flds
| CaseType td_names params sc ->
let td_names = resolve_typedef_names env td_names in
let params, env = resolve_params env params in
let sc = resolve_switch_case env sc in
CaseType td_names params sc
| OutputType out_t ->
let out_t = resolve_out_type env out_t in
push_output_type env out_t;
OutputType out_t
| ExternType td_names ->
let td_names = resolve_typedef_names env td_names in
push_extern_type env td_names;
ExternType td_names
| ExternFn id ret params ->
let id = resolve_ident env id in
let ret = resolve_typ env ret in
let params, _ = resolve_params env params in
ExternFn id ret params
| ExternProbe id ->
let id = resolve_ident env id in
ExternProbe id | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> d: Ast.decl -> FStar.All.ML Ast.decl | FStar.All.ML | [
"ml"
] | [] | [
"Desugar.qenv",
"Ast.decl",
"Ast.decl_with_v",
"Ast.decl'",
"Desugar.resolve_decl'",
"Ast.__proj__Mkwith_meta_t__item__v",
"Ast.__proj__Mkdecl__item__d_decl"
] | [] | false | true | false | false | false | let resolve_decl (env: qenv) (d: decl) : ML decl =
| decl_with_v d (resolve_decl' env d.d_decl.v) | false |
Desugar.fst | Desugar.desugar_enum_cases | val desugar_enum_cases (ityp: integer_type) (cases: list enum_case) (export: bool)
: ML (list enum_case & list decl) | val desugar_enum_cases (ityp: integer_type) (cases: list enum_case) (export: bool)
: ML (list enum_case & list decl) | let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 17,
"end_line": 83,
"start_col": 0,
"start_line": 46
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ityp: Ast.integer_type -> cases: Prims.list Ast.enum_case -> export: Prims.bool
-> FStar.All.ML (Prims.list Ast.enum_case * Prims.list Ast.decl) | FStar.All.ML | [
"ml"
] | [] | [
"Ast.integer_type",
"Prims.list",
"Ast.enum_case",
"Prims.bool",
"Prims.int",
"FStar.Pervasives.Native.tuple2",
"Ast.with_meta_t",
"Ast.ident'",
"FStar.Pervasives.Native.option",
"Ast.either",
"Ast.ident",
"Ast.decl",
"FStar.Pervasives.Native.Mktuple2",
"FStar.List.Tot.Base.rev",
"FStar.Pervasives.Native.tuple3",
"FStar.List.fold_left",
"FStar.Pervasives.Native.Mktuple3",
"Prims.op_Addition",
"Prims.Cons",
"Ast.mk_decl",
"Ast.Define",
"FStar.Pervasives.Native.None",
"Ast.typ",
"Ast.Int",
"Ast.__proj__Mkwith_meta_t__item__range",
"Prims.string",
"Prims.Nil",
"FStar.List.Tot.Base.find",
"Ast.range",
"Ast.comments",
"Prims.b2t",
"Ast.error",
"FStar.Printf.sprintf",
"Ast.print_ident",
"Ast.__proj__Mkwith_meta_t__item__v",
"Ast.decl'",
"Ast.__proj__Mkdecl__item__d_decl",
"Prims.op_Equality"
] | [] | false | true | false | false | false | let desugar_enum_cases (ityp: integer_type) (cases: list enum_case) (export: bool)
: ML (list enum_case & list decl) =
| let find_definition (i: ident) (d: decl) =
match d.d_decl.v with
| Define j _ (Int _ _) -> i.v = j.v
| _ -> false
in
let _, cases_rev, ds_rev =
List.fold_left (fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
(match List.Tot.find (find_definition j) ds_rev with
| Some { d_decl = { v = Define _ _ (Int _ k) } } -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range)
| None -> next
in
let case = (i, None) in
let d = mk_decl (Define i None (Int ityp next)) i.range ["Enum constant"] export in
(next + 1, case :: cases_rev, d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev, List.rev ds_rev | false |
Desugar.fst | Desugar.push_output_type | val push_output_type (env: qenv) (out_t: out_typ) : ML unit | val push_output_type (env: qenv) (out_t: out_typ) : ML unit | let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v () | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 67,
"end_line": 157,
"start_col": 0,
"start_line": 155
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> out_t: Ast.out_typ -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Desugar.qenv",
"Ast.out_typ",
"Hashtable.insert",
"Ast.ident'",
"Prims.unit",
"Desugar.__proj__Mkqenv__item__output_types",
"Ast.__proj__Mkwith_meta_t__item__v",
"Ast.__proj__Mktypedef_names__item__typedef_abbrev",
"Ast.__proj__Mkout_typ__item__out_typ_names",
"Ast.__proj__Mktypedef_names__item__typedef_name"
] | [] | false | true | false | false | false | let push_output_type (env: qenv) (out_t: out_typ) : ML unit =
| H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v () | false |
Desugar.fst | Desugar.resolve_ident | val resolve_ident (env: qenv) (i: ident) : ML ident | val resolve_ident (env: qenv) (i: ident) : ML ident | let resolve_ident (env:qenv) (i:ident) : ML ident =
let resolve_to_current_module i =
{ i with v = { i.v with modul_name = Some env.mname } }
in
let maybe_resolve_as_ifdef i
: ML ident
= match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts //it's a primitive constant, e.g. UINT8, leave as is
then i
else if List.mem i.v.name env.local_names //it's a local name (e.g. a parameter name)
then (if Some? i.v.modul_name //must have module name set to None
then error (Printf.sprintf
"Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i) //return the local name as is
else (match i.v.modul_name with //it's a top-level name
| None -> maybe_resolve_as_ifdef i
| Some m -> //if already qualified, check if it is an abbreviation
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } })) | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 77,
"end_line": 202,
"start_col": 0,
"start_line": 174
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names }
let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> i: Ast.ident -> FStar.All.ML Ast.ident | FStar.All.ML | [
"ml"
] | [] | [
"Desugar.qenv",
"Ast.ident",
"FStar.List.Tot.Base.mem",
"Prims.string",
"Ast.__proj__Mkident'__item__name",
"Ast.__proj__Mkwith_meta_t__item__v",
"Ast.ident'",
"Desugar.prim_consts",
"Prims.bool",
"Desugar.__proj__Mkqenv__item__local_names",
"FStar.Pervasives.Native.uu___is_Some",
"Ast.__proj__Mkident'__item__modul_name",
"Ast.error",
"FStar.Printf.sprintf",
"FStar.Pervasives.Native.__proj__Some__item__v",
"Ast.__proj__Mkwith_meta_t__item__range",
"Ast.Mkwith_meta_t",
"Ast.Mkident'",
"FStar.Pervasives.Native.Some",
"Ast.__proj__Mkwith_meta_t__item__comments",
"FStar.Pervasives.Native.option",
"Hashtable.try_find",
"Desugar.__proj__Mkqenv__item__module_abbrevs",
"Ast.with_meta_t",
"GlobalEnv.__proj__Mkglobal_env__item__ge_cfg",
"Desugar.__proj__Mkqenv__item__global_env",
"Config.config",
"Config.__proj__Mkcompile_time_flags__item__flags",
"Config.__proj__Mkconfig__item__compile_time_flags",
"Desugar.__proj__Mkqenv__item__mname"
] | [] | false | true | false | false | false | let resolve_ident (env: qenv) (i: ident) : ML ident =
| let resolve_to_current_module i = { i with v = { i.v with modul_name = Some env.mname } } in
let maybe_resolve_as_ifdef i : ML ident =
match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts
then i
else
if List.mem i.v.name env.local_names
then
(if Some? i.v.modul_name
then
error (Printf.sprintf "Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i)
else
(match i.v.modul_name with
| None -> maybe_resolve_as_ifdef i
| Some m ->
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } })) | false |
Desugar.fst | Desugar.collect_ifdef_guards | val collect_ifdef_guards (env: qenv) (e: expr) : ML unit | val collect_ifdef_guards (env: qenv) (e: expr) : ML unit | let rec collect_ifdef_guards (env:qenv) (e:expr)
: ML unit
= let check_resolved_to_ifdef i =
match env.global_env.ge_cfg with
| None -> false
| Some (cfg, cfg_module_name) ->
List.mem i.v.name cfg.compile_time_flags.flags
&& i.v.modul_name = Some cfg_module_name
in
match e.v with
| This -> error "'this' is not allowed in the guard of an #if" e.range
| Static _ -> failwith "static should have been eliminated already"
| Constant _ -> ()
| Identifier i ->
if not (check_resolved_to_ifdef i)
then error (Printf.sprintf "Identifier %s is not a compile-time macro but is used in a #if" i.v.name) e.range
| App op args ->
begin
match op with
| And
| Or
| Not -> List.iter (collect_ifdef_guards env) args
| _ -> error "Only boolean expressions over identifiers are supported in #if guards" e.range
end | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 9,
"end_line": 228,
"start_col": 0,
"start_line": 205
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names }
let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ]
let resolve_ident (env:qenv) (i:ident) : ML ident =
let resolve_to_current_module i =
{ i with v = { i.v with modul_name = Some env.mname } }
in
let maybe_resolve_as_ifdef i
: ML ident
= match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts //it's a primitive constant, e.g. UINT8, leave as is
then i
else if List.mem i.v.name env.local_names //it's a local name (e.g. a parameter name)
then (if Some? i.v.modul_name //must have module name set to None
then error (Printf.sprintf
"Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i) //return the local name as is
else (match i.v.modul_name with //it's a top-level name
| None -> maybe_resolve_as_ifdef i
| Some m -> //if already qualified, check if it is an abbreviation
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } })) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> e: Ast.expr -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Desugar.qenv",
"Ast.expr",
"Ast.__proj__Mkwith_meta_t__item__v",
"Ast.expr'",
"Ast.error",
"Prims.unit",
"Ast.__proj__Mkwith_meta_t__item__range",
"Ast.with_meta_t",
"FStar.All.failwith",
"Ast.constant",
"Ast.ident",
"Prims.op_Negation",
"FStar.Printf.sprintf",
"Ast.__proj__Mkident'__item__name",
"Ast.ident'",
"Prims.bool",
"Ast.op",
"Prims.list",
"FStar.List.iter",
"Desugar.collect_ifdef_guards",
"GlobalEnv.__proj__Mkglobal_env__item__ge_cfg",
"Desugar.__proj__Mkqenv__item__global_env",
"Config.config",
"Prims.string",
"Prims.op_AmpAmp",
"FStar.List.Tot.Base.mem",
"Config.__proj__Mkcompile_time_flags__item__flags",
"Config.__proj__Mkconfig__item__compile_time_flags",
"Prims.op_Equality",
"FStar.Pervasives.Native.option",
"Ast.__proj__Mkident'__item__modul_name",
"FStar.Pervasives.Native.Some"
] | [
"recursion"
] | false | true | false | false | false | let rec collect_ifdef_guards (env: qenv) (e: expr) : ML unit =
| let check_resolved_to_ifdef i =
match env.global_env.ge_cfg with
| None -> false
| Some (cfg, cfg_module_name) ->
List.mem i.v.name cfg.compile_time_flags.flags && i.v.modul_name = Some cfg_module_name
in
match e.v with
| This -> error "'this' is not allowed in the guard of an #if" e.range
| Static _ -> failwith "static should have been eliminated already"
| Constant _ -> ()
| Identifier i ->
if not (check_resolved_to_ifdef i)
then
error (Printf.sprintf "Identifier %s is not a compile-time macro but is used in a #if" i.v.name)
e.range
| App op args ->
match op with
| And | Or | Not -> List.iter (collect_ifdef_guards env) args
| _ -> error "Only boolean expressions over identifiers are supported in #if guards" e.range | false |
Desugar.fst | Desugar.resolve_typ | val resolve_typ (env: qenv) (t: typ) : ML typ | val resolve_typ (env: qenv) (t: typ) : ML typ | let rec resolve_typ' (env:qenv) (t:typ') : ML typ' =
match t with
| Type_app hd _ args ->
let hd = resolve_ident env hd in
//Set is_out argument to the Type_app appropriately
let k = kind_of_ident env hd in
Type_app hd k (List.map (resolve_typ_param env) args)
| Pointer t -> Pointer (resolve_typ env t)
and resolve_typ (env:qenv) (t:typ) : ML typ = { t with v = resolve_typ' env t.v } | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 81,
"end_line": 273,
"start_col": 0,
"start_line": 264
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names }
let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ]
let resolve_ident (env:qenv) (i:ident) : ML ident =
let resolve_to_current_module i =
{ i with v = { i.v with modul_name = Some env.mname } }
in
let maybe_resolve_as_ifdef i
: ML ident
= match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts //it's a primitive constant, e.g. UINT8, leave as is
then i
else if List.mem i.v.name env.local_names //it's a local name (e.g. a parameter name)
then (if Some? i.v.modul_name //must have module name set to None
then error (Printf.sprintf
"Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i) //return the local name as is
else (match i.v.modul_name with //it's a top-level name
| None -> maybe_resolve_as_ifdef i
| Some m -> //if already qualified, check if it is an abbreviation
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } }))
let rec collect_ifdef_guards (env:qenv) (e:expr)
: ML unit
= let check_resolved_to_ifdef i =
match env.global_env.ge_cfg with
| None -> false
| Some (cfg, cfg_module_name) ->
List.mem i.v.name cfg.compile_time_flags.flags
&& i.v.modul_name = Some cfg_module_name
in
match e.v with
| This -> error "'this' is not allowed in the guard of an #if" e.range
| Static _ -> failwith "static should have been eliminated already"
| Constant _ -> ()
| Identifier i ->
if not (check_resolved_to_ifdef i)
then error (Printf.sprintf "Identifier %s is not a compile-time macro but is used in a #if" i.v.name) e.range
| App op args ->
begin
match op with
| And
| Or
| Not -> List.iter (collect_ifdef_guards env) args
| _ -> error "Only boolean expressions over identifiers are supported in #if guards" e.range
end
let rec resolve_expr' (env:qenv) (e:expr') r : ML expr' =
match e with
| Constant _ -> e
| Identifier i -> Identifier (resolve_ident env i)
| This -> e
| Static e' ->
let e' = resolve_expr env e' in
collect_ifdef_guards env e';//mark any variables as top-level IfDef symbols
e'.v
| App op args ->
let args = List.map (resolve_expr env) args in
App op args
and resolve_expr (env:qenv) (e:expr) : ML expr = { e with v = resolve_expr' env e.v e.range }
let resolve_typ_param (env:qenv) (p:typ_param) : ML typ_param =
match p with
| Inl e -> resolve_expr env e |> Inl
| _ -> p //Currently not going inside output expressions, should we?
let kind_of_ident (env:qenv) (i:ident)
: ML t_kind
= let _or_ (b0 b1:bool) = b0 || b1 in
if Some? (H.try_find env.output_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_out_t i.v)
then KindOutput
else if
Some? (H.try_find env.extern_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_extern_t i.v)
then KindExtern
else KindSpec | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> t: Ast.typ -> FStar.All.ML Ast.typ | FStar.All.ML | [
"ml"
] | [
"resolve_typ'",
"resolve_typ"
] | [
"Desugar.qenv",
"Ast.typ",
"Ast.Mkwith_meta_t",
"Ast.typ'",
"Ast.__proj__Mkwith_meta_t__item__range",
"Ast.__proj__Mkwith_meta_t__item__comments",
"Desugar.resolve_typ'",
"Ast.__proj__Mkwith_meta_t__item__v"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec resolve_typ (env: qenv) (t: typ) : ML typ =
| { t with v = resolve_typ' env t.v } | false |
Desugar.fst | Desugar.resolve_atomic_action | val resolve_atomic_action (env: qenv) (ac: atomic_action) : ML atomic_action | val resolve_atomic_action (env: qenv) (ac: atomic_action) : ML atomic_action | let resolve_atomic_action (env:qenv) (ac:atomic_action) : ML atomic_action =
match ac with
| Action_return e -> Action_return (resolve_expr env e)
| Action_abort
| Action_field_pos_64
| Action_field_pos_32
| Action_field_ptr -> ac
| Action_field_ptr_after e write_to -> Action_field_ptr_after (resolve_expr env e) write_to
| Action_deref i -> Action_deref i //most certainly a type parameter
| Action_assignment lhs rhs ->
Action_assignment lhs (resolve_expr env rhs) //lhs is an action-local variable
| Action_call f args ->
Action_call (resolve_ident env f) (List.map (resolve_expr env) args) | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 72,
"end_line": 287,
"start_col": 0,
"start_line": 275
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names }
let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ]
let resolve_ident (env:qenv) (i:ident) : ML ident =
let resolve_to_current_module i =
{ i with v = { i.v with modul_name = Some env.mname } }
in
let maybe_resolve_as_ifdef i
: ML ident
= match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts //it's a primitive constant, e.g. UINT8, leave as is
then i
else if List.mem i.v.name env.local_names //it's a local name (e.g. a parameter name)
then (if Some? i.v.modul_name //must have module name set to None
then error (Printf.sprintf
"Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i) //return the local name as is
else (match i.v.modul_name with //it's a top-level name
| None -> maybe_resolve_as_ifdef i
| Some m -> //if already qualified, check if it is an abbreviation
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } }))
let rec collect_ifdef_guards (env:qenv) (e:expr)
: ML unit
= let check_resolved_to_ifdef i =
match env.global_env.ge_cfg with
| None -> false
| Some (cfg, cfg_module_name) ->
List.mem i.v.name cfg.compile_time_flags.flags
&& i.v.modul_name = Some cfg_module_name
in
match e.v with
| This -> error "'this' is not allowed in the guard of an #if" e.range
| Static _ -> failwith "static should have been eliminated already"
| Constant _ -> ()
| Identifier i ->
if not (check_resolved_to_ifdef i)
then error (Printf.sprintf "Identifier %s is not a compile-time macro but is used in a #if" i.v.name) e.range
| App op args ->
begin
match op with
| And
| Or
| Not -> List.iter (collect_ifdef_guards env) args
| _ -> error "Only boolean expressions over identifiers are supported in #if guards" e.range
end
let rec resolve_expr' (env:qenv) (e:expr') r : ML expr' =
match e with
| Constant _ -> e
| Identifier i -> Identifier (resolve_ident env i)
| This -> e
| Static e' ->
let e' = resolve_expr env e' in
collect_ifdef_guards env e';//mark any variables as top-level IfDef symbols
e'.v
| App op args ->
let args = List.map (resolve_expr env) args in
App op args
and resolve_expr (env:qenv) (e:expr) : ML expr = { e with v = resolve_expr' env e.v e.range }
let resolve_typ_param (env:qenv) (p:typ_param) : ML typ_param =
match p with
| Inl e -> resolve_expr env e |> Inl
| _ -> p //Currently not going inside output expressions, should we?
let kind_of_ident (env:qenv) (i:ident)
: ML t_kind
= let _or_ (b0 b1:bool) = b0 || b1 in
if Some? (H.try_find env.output_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_out_t i.v)
then KindOutput
else if
Some? (H.try_find env.extern_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_extern_t i.v)
then KindExtern
else KindSpec
let rec resolve_typ' (env:qenv) (t:typ') : ML typ' =
match t with
| Type_app hd _ args ->
let hd = resolve_ident env hd in
//Set is_out argument to the Type_app appropriately
let k = kind_of_ident env hd in
Type_app hd k (List.map (resolve_typ_param env) args)
| Pointer t -> Pointer (resolve_typ env t)
and resolve_typ (env:qenv) (t:typ) : ML typ = { t with v = resolve_typ' env t.v } | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> ac: Ast.atomic_action -> FStar.All.ML Ast.atomic_action | FStar.All.ML | [
"ml"
] | [] | [
"Desugar.qenv",
"Ast.atomic_action",
"Ast.expr",
"Ast.Action_return",
"Desugar.resolve_expr",
"Ast.out_expr",
"Ast.Action_field_ptr_after",
"Ast.ident",
"Ast.Action_deref",
"Ast.Action_assignment",
"Prims.list",
"Ast.Action_call",
"FStar.List.map",
"Desugar.resolve_ident"
] | [] | false | true | false | false | false | let resolve_atomic_action (env: qenv) (ac: atomic_action) : ML atomic_action =
| match ac with
| Action_return e -> Action_return (resolve_expr env e)
| Action_abort | Action_field_pos_64 | Action_field_pos_32 | Action_field_ptr -> ac
| Action_field_ptr_after e write_to -> Action_field_ptr_after (resolve_expr env e) write_to
| Action_deref i -> Action_deref i
| Action_assignment lhs rhs -> Action_assignment lhs (resolve_expr env rhs)
| Action_call f args -> Action_call (resolve_ident env f) (List.map (resolve_expr env) args) | false |
Desugar.fst | Desugar.resolve_action' | val resolve_action' (env: qenv) (act: action') : ML action' | val resolve_action' (env: qenv) (act: action') : ML action' | let rec resolve_action' (env:qenv) (act:action') : ML action' =
match act with
| Atomic_action ac -> Atomic_action (resolve_atomic_action env ac)
| Action_seq hd tl ->
Action_seq (resolve_atomic_action env hd) (resolve_action env tl)
| Action_ite hd then_ else_ ->
Action_ite (resolve_expr env hd) (resolve_action env then_) (map_opt (resolve_action env) else_)
| Action_let i a k ->
Action_let i (resolve_atomic_action env a) (resolve_action (push_name env i.v.name) k)
| Action_act a ->
Action_act (resolve_action env a)
and resolve_action (env:qenv) (act:action) : ML action =
{ act with v = resolve_action' env act.v } | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 44,
"end_line": 302,
"start_col": 0,
"start_line": 289
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names }
let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ]
let resolve_ident (env:qenv) (i:ident) : ML ident =
let resolve_to_current_module i =
{ i with v = { i.v with modul_name = Some env.mname } }
in
let maybe_resolve_as_ifdef i
: ML ident
= match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts //it's a primitive constant, e.g. UINT8, leave as is
then i
else if List.mem i.v.name env.local_names //it's a local name (e.g. a parameter name)
then (if Some? i.v.modul_name //must have module name set to None
then error (Printf.sprintf
"Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i) //return the local name as is
else (match i.v.modul_name with //it's a top-level name
| None -> maybe_resolve_as_ifdef i
| Some m -> //if already qualified, check if it is an abbreviation
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } }))
let rec collect_ifdef_guards (env:qenv) (e:expr)
: ML unit
= let check_resolved_to_ifdef i =
match env.global_env.ge_cfg with
| None -> false
| Some (cfg, cfg_module_name) ->
List.mem i.v.name cfg.compile_time_flags.flags
&& i.v.modul_name = Some cfg_module_name
in
match e.v with
| This -> error "'this' is not allowed in the guard of an #if" e.range
| Static _ -> failwith "static should have been eliminated already"
| Constant _ -> ()
| Identifier i ->
if not (check_resolved_to_ifdef i)
then error (Printf.sprintf "Identifier %s is not a compile-time macro but is used in a #if" i.v.name) e.range
| App op args ->
begin
match op with
| And
| Or
| Not -> List.iter (collect_ifdef_guards env) args
| _ -> error "Only boolean expressions over identifiers are supported in #if guards" e.range
end
let rec resolve_expr' (env:qenv) (e:expr') r : ML expr' =
match e with
| Constant _ -> e
| Identifier i -> Identifier (resolve_ident env i)
| This -> e
| Static e' ->
let e' = resolve_expr env e' in
collect_ifdef_guards env e';//mark any variables as top-level IfDef symbols
e'.v
| App op args ->
let args = List.map (resolve_expr env) args in
App op args
and resolve_expr (env:qenv) (e:expr) : ML expr = { e with v = resolve_expr' env e.v e.range }
let resolve_typ_param (env:qenv) (p:typ_param) : ML typ_param =
match p with
| Inl e -> resolve_expr env e |> Inl
| _ -> p //Currently not going inside output expressions, should we?
let kind_of_ident (env:qenv) (i:ident)
: ML t_kind
= let _or_ (b0 b1:bool) = b0 || b1 in
if Some? (H.try_find env.output_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_out_t i.v)
then KindOutput
else if
Some? (H.try_find env.extern_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_extern_t i.v)
then KindExtern
else KindSpec
let rec resolve_typ' (env:qenv) (t:typ') : ML typ' =
match t with
| Type_app hd _ args ->
let hd = resolve_ident env hd in
//Set is_out argument to the Type_app appropriately
let k = kind_of_ident env hd in
Type_app hd k (List.map (resolve_typ_param env) args)
| Pointer t -> Pointer (resolve_typ env t)
and resolve_typ (env:qenv) (t:typ) : ML typ = { t with v = resolve_typ' env t.v }
let resolve_atomic_action (env:qenv) (ac:atomic_action) : ML atomic_action =
match ac with
| Action_return e -> Action_return (resolve_expr env e)
| Action_abort
| Action_field_pos_64
| Action_field_pos_32
| Action_field_ptr -> ac
| Action_field_ptr_after e write_to -> Action_field_ptr_after (resolve_expr env e) write_to
| Action_deref i -> Action_deref i //most certainly a type parameter
| Action_assignment lhs rhs ->
Action_assignment lhs (resolve_expr env rhs) //lhs is an action-local variable
| Action_call f args ->
Action_call (resolve_ident env f) (List.map (resolve_expr env) args) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> act: Ast.action' -> FStar.All.ML Ast.action' | FStar.All.ML | [
"ml"
] | [
"resolve_action'",
"resolve_action"
] | [
"Desugar.qenv",
"Ast.action'",
"Ast.atomic_action",
"Ast.Atomic_action",
"Desugar.resolve_atomic_action",
"Ast.with_meta_t",
"Ast.Action_seq",
"Desugar.resolve_action",
"Ast.action",
"Ast.expr",
"FStar.Pervasives.Native.option",
"Ast.Action_ite",
"Ast.map_opt",
"Desugar.resolve_expr",
"Ast.ident",
"Ast.Action_let",
"Desugar.push_name",
"Ast.__proj__Mkident'__item__name",
"Ast.__proj__Mkwith_meta_t__item__v",
"Ast.ident'",
"Ast.Action_act"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec resolve_action' (env: qenv) (act: action') : ML action' =
| match act with
| Atomic_action ac -> Atomic_action (resolve_atomic_action env ac)
| Action_seq hd tl -> Action_seq (resolve_atomic_action env hd) (resolve_action env tl)
| Action_ite hd then_ else_ ->
Action_ite (resolve_expr env hd) (resolve_action env then_) (map_opt (resolve_action env) else_)
| Action_let i a k ->
Action_let i (resolve_atomic_action env a) (resolve_action (push_name env i.v.name) k)
| Action_act a -> Action_act (resolve_action env a) | false |
Desugar.fst | Desugar.resolve_field_bitwidth_t | val resolve_field_bitwidth_t (env: qenv) (fb: field_bitwidth_t) : ML field_bitwidth_t | val resolve_field_bitwidth_t (env: qenv) (fb: field_bitwidth_t) : ML field_bitwidth_t | let resolve_field_bitwidth_t (env:qenv) (fb:field_bitwidth_t) : ML field_bitwidth_t =
let resolve_bitfield_attr' (env:qenv) (b:bitfield_attr') : ML bitfield_attr' =
{ b with bitfield_type = resolve_typ env b.bitfield_type } in
let resolve_bitfield_attr (env:qenv) (b:bitfield_attr) : ML bitfield_attr =
{ b with v = resolve_bitfield_attr' env b.v } in
match fb with
| Inl _ -> fb
| Inr b -> Inr (resolve_bitfield_attr env b) | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 46,
"end_line": 323,
"start_col": 0,
"start_line": 314
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names }
let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ]
let resolve_ident (env:qenv) (i:ident) : ML ident =
let resolve_to_current_module i =
{ i with v = { i.v with modul_name = Some env.mname } }
in
let maybe_resolve_as_ifdef i
: ML ident
= match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts //it's a primitive constant, e.g. UINT8, leave as is
then i
else if List.mem i.v.name env.local_names //it's a local name (e.g. a parameter name)
then (if Some? i.v.modul_name //must have module name set to None
then error (Printf.sprintf
"Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i) //return the local name as is
else (match i.v.modul_name with //it's a top-level name
| None -> maybe_resolve_as_ifdef i
| Some m -> //if already qualified, check if it is an abbreviation
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } }))
let rec collect_ifdef_guards (env:qenv) (e:expr)
: ML unit
= let check_resolved_to_ifdef i =
match env.global_env.ge_cfg with
| None -> false
| Some (cfg, cfg_module_name) ->
List.mem i.v.name cfg.compile_time_flags.flags
&& i.v.modul_name = Some cfg_module_name
in
match e.v with
| This -> error "'this' is not allowed in the guard of an #if" e.range
| Static _ -> failwith "static should have been eliminated already"
| Constant _ -> ()
| Identifier i ->
if not (check_resolved_to_ifdef i)
then error (Printf.sprintf "Identifier %s is not a compile-time macro but is used in a #if" i.v.name) e.range
| App op args ->
begin
match op with
| And
| Or
| Not -> List.iter (collect_ifdef_guards env) args
| _ -> error "Only boolean expressions over identifiers are supported in #if guards" e.range
end
let rec resolve_expr' (env:qenv) (e:expr') r : ML expr' =
match e with
| Constant _ -> e
| Identifier i -> Identifier (resolve_ident env i)
| This -> e
| Static e' ->
let e' = resolve_expr env e' in
collect_ifdef_guards env e';//mark any variables as top-level IfDef symbols
e'.v
| App op args ->
let args = List.map (resolve_expr env) args in
App op args
and resolve_expr (env:qenv) (e:expr) : ML expr = { e with v = resolve_expr' env e.v e.range }
let resolve_typ_param (env:qenv) (p:typ_param) : ML typ_param =
match p with
| Inl e -> resolve_expr env e |> Inl
| _ -> p //Currently not going inside output expressions, should we?
let kind_of_ident (env:qenv) (i:ident)
: ML t_kind
= let _or_ (b0 b1:bool) = b0 || b1 in
if Some? (H.try_find env.output_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_out_t i.v)
then KindOutput
else if
Some? (H.try_find env.extern_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_extern_t i.v)
then KindExtern
else KindSpec
let rec resolve_typ' (env:qenv) (t:typ') : ML typ' =
match t with
| Type_app hd _ args ->
let hd = resolve_ident env hd in
//Set is_out argument to the Type_app appropriately
let k = kind_of_ident env hd in
Type_app hd k (List.map (resolve_typ_param env) args)
| Pointer t -> Pointer (resolve_typ env t)
and resolve_typ (env:qenv) (t:typ) : ML typ = { t with v = resolve_typ' env t.v }
let resolve_atomic_action (env:qenv) (ac:atomic_action) : ML atomic_action =
match ac with
| Action_return e -> Action_return (resolve_expr env e)
| Action_abort
| Action_field_pos_64
| Action_field_pos_32
| Action_field_ptr -> ac
| Action_field_ptr_after e write_to -> Action_field_ptr_after (resolve_expr env e) write_to
| Action_deref i -> Action_deref i //most certainly a type parameter
| Action_assignment lhs rhs ->
Action_assignment lhs (resolve_expr env rhs) //lhs is an action-local variable
| Action_call f args ->
Action_call (resolve_ident env f) (List.map (resolve_expr env) args)
let rec resolve_action' (env:qenv) (act:action') : ML action' =
match act with
| Atomic_action ac -> Atomic_action (resolve_atomic_action env ac)
| Action_seq hd tl ->
Action_seq (resolve_atomic_action env hd) (resolve_action env tl)
| Action_ite hd then_ else_ ->
Action_ite (resolve_expr env hd) (resolve_action env then_) (map_opt (resolve_action env) else_)
| Action_let i a k ->
Action_let i (resolve_atomic_action env a) (resolve_action (push_name env i.v.name) k)
| Action_act a ->
Action_act (resolve_action env a)
and resolve_action (env:qenv) (act:action) : ML action =
{ act with v = resolve_action' env act.v }
let resolve_param (env:qenv) (p:param) : ML (param & qenv) =
let t, i, q = p in
(resolve_typ env t, i, q),
push_name env i.v.name
let resolve_params (env:qenv) (params:list param) : ML (list param & qenv) =
List.fold_left (fun (params, env) p ->
let p, env = resolve_param env p in
params@[p], env) ([], env) params | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> fb: Ast.field_bitwidth_t -> FStar.All.ML Ast.field_bitwidth_t | FStar.All.ML | [
"ml"
] | [] | [
"Desugar.qenv",
"Ast.field_bitwidth_t",
"Ast.with_meta_t",
"Prims.int",
"Ast.bitfield_attr",
"Ast.Inr",
"Ast.Mkwith_meta_t",
"Ast.bitfield_attr'",
"Ast.__proj__Mkwith_meta_t__item__range",
"Ast.__proj__Mkwith_meta_t__item__comments",
"Ast.__proj__Mkwith_meta_t__item__v",
"Ast.Mkbitfield_attr'",
"Ast.__proj__Mkbitfield_attr'__item__bitfield_width",
"Ast.__proj__Mkbitfield_attr'__item__bitfield_identifier",
"Ast.__proj__Mkbitfield_attr'__item__bitfield_from",
"Ast.__proj__Mkbitfield_attr'__item__bitfield_to",
"Ast.typ",
"Desugar.resolve_typ",
"Ast.__proj__Mkbitfield_attr'__item__bitfield_type"
] | [] | false | true | false | false | false | let resolve_field_bitwidth_t (env: qenv) (fb: field_bitwidth_t) : ML field_bitwidth_t =
| let resolve_bitfield_attr' (env: qenv) (b: bitfield_attr') : ML bitfield_attr' =
{ b with bitfield_type = resolve_typ env b.bitfield_type }
in
let resolve_bitfield_attr (env: qenv) (b: bitfield_attr) : ML bitfield_attr =
{ b with v = resolve_bitfield_attr' env b.v }
in
match fb with
| Inl _ -> fb
| Inr b -> Inr (resolve_bitfield_attr env b) | false |
Desugar.fst | Desugar.kind_of_ident | val kind_of_ident (env: qenv) (i: ident) : ML t_kind | val kind_of_ident (env: qenv) (i: ident) : ML t_kind | let kind_of_ident (env:qenv) (i:ident)
: ML t_kind
= let _or_ (b0 b1:bool) = b0 || b1 in
if Some? (H.try_find env.output_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_out_t i.v)
then KindOutput
else if
Some? (H.try_find env.extern_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_extern_t i.v)
then KindExtern
else KindSpec | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 17,
"end_line": 262,
"start_col": 0,
"start_line": 252
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names }
let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ]
let resolve_ident (env:qenv) (i:ident) : ML ident =
let resolve_to_current_module i =
{ i with v = { i.v with modul_name = Some env.mname } }
in
let maybe_resolve_as_ifdef i
: ML ident
= match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts //it's a primitive constant, e.g. UINT8, leave as is
then i
else if List.mem i.v.name env.local_names //it's a local name (e.g. a parameter name)
then (if Some? i.v.modul_name //must have module name set to None
then error (Printf.sprintf
"Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i) //return the local name as is
else (match i.v.modul_name with //it's a top-level name
| None -> maybe_resolve_as_ifdef i
| Some m -> //if already qualified, check if it is an abbreviation
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } }))
let rec collect_ifdef_guards (env:qenv) (e:expr)
: ML unit
= let check_resolved_to_ifdef i =
match env.global_env.ge_cfg with
| None -> false
| Some (cfg, cfg_module_name) ->
List.mem i.v.name cfg.compile_time_flags.flags
&& i.v.modul_name = Some cfg_module_name
in
match e.v with
| This -> error "'this' is not allowed in the guard of an #if" e.range
| Static _ -> failwith "static should have been eliminated already"
| Constant _ -> ()
| Identifier i ->
if not (check_resolved_to_ifdef i)
then error (Printf.sprintf "Identifier %s is not a compile-time macro but is used in a #if" i.v.name) e.range
| App op args ->
begin
match op with
| And
| Or
| Not -> List.iter (collect_ifdef_guards env) args
| _ -> error "Only boolean expressions over identifiers are supported in #if guards" e.range
end
let rec resolve_expr' (env:qenv) (e:expr') r : ML expr' =
match e with
| Constant _ -> e
| Identifier i -> Identifier (resolve_ident env i)
| This -> e
| Static e' ->
let e' = resolve_expr env e' in
collect_ifdef_guards env e';//mark any variables as top-level IfDef symbols
e'.v
| App op args ->
let args = List.map (resolve_expr env) args in
App op args
and resolve_expr (env:qenv) (e:expr) : ML expr = { e with v = resolve_expr' env e.v e.range }
let resolve_typ_param (env:qenv) (p:typ_param) : ML typ_param =
match p with
| Inl e -> resolve_expr env e |> Inl
| _ -> p //Currently not going inside output expressions, should we? | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> i: Ast.ident -> FStar.All.ML Ast.t_kind | FStar.All.ML | [
"ml"
] | [] | [
"Desugar.qenv",
"Ast.ident",
"Ast.KindOutput",
"Ast.t_kind",
"Prims.bool",
"Ast.KindExtern",
"Ast.KindSpec",
"FStar.Pervasives.Native.uu___is_Some",
"Ast.decl",
"FStar.Pervasives.Native.option",
"Hashtable.try_find",
"Ast.ident'",
"GlobalEnv.__proj__Mkglobal_env__item__ge_extern_t",
"Desugar.__proj__Mkqenv__item__global_env",
"Ast.__proj__Mkwith_meta_t__item__v",
"Prims.unit",
"Desugar.__proj__Mkqenv__item__extern_types",
"GlobalEnv.__proj__Mkglobal_env__item__ge_out_t",
"Desugar.__proj__Mkqenv__item__output_types",
"Prims.op_BarBar"
] | [] | false | true | false | false | false | let kind_of_ident (env: qenv) (i: ident) : ML t_kind =
| let _or_ (b0 b1: bool) = b0 || b1 in
if (Some? (H.try_find env.output_types i.v)) `_or_` (Some? (H.try_find env.global_env.ge_out_t i.v))
then KindOutput
else
if
(Some? (H.try_find env.extern_types i.v))
`_or_`
(Some? (H.try_find env.global_env.ge_extern_t i.v))
then KindExtern
else KindSpec | false |
Desugar.fst | Desugar.resolve_action | val resolve_action (env: qenv) (act: action) : ML action | val resolve_action (env: qenv) (act: action) : ML action | let rec resolve_action' (env:qenv) (act:action') : ML action' =
match act with
| Atomic_action ac -> Atomic_action (resolve_atomic_action env ac)
| Action_seq hd tl ->
Action_seq (resolve_atomic_action env hd) (resolve_action env tl)
| Action_ite hd then_ else_ ->
Action_ite (resolve_expr env hd) (resolve_action env then_) (map_opt (resolve_action env) else_)
| Action_let i a k ->
Action_let i (resolve_atomic_action env a) (resolve_action (push_name env i.v.name) k)
| Action_act a ->
Action_act (resolve_action env a)
and resolve_action (env:qenv) (act:action) : ML action =
{ act with v = resolve_action' env act.v } | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 44,
"end_line": 302,
"start_col": 0,
"start_line": 289
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names }
let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ]
let resolve_ident (env:qenv) (i:ident) : ML ident =
let resolve_to_current_module i =
{ i with v = { i.v with modul_name = Some env.mname } }
in
let maybe_resolve_as_ifdef i
: ML ident
= match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts //it's a primitive constant, e.g. UINT8, leave as is
then i
else if List.mem i.v.name env.local_names //it's a local name (e.g. a parameter name)
then (if Some? i.v.modul_name //must have module name set to None
then error (Printf.sprintf
"Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i) //return the local name as is
else (match i.v.modul_name with //it's a top-level name
| None -> maybe_resolve_as_ifdef i
| Some m -> //if already qualified, check if it is an abbreviation
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } }))
let rec collect_ifdef_guards (env:qenv) (e:expr)
: ML unit
= let check_resolved_to_ifdef i =
match env.global_env.ge_cfg with
| None -> false
| Some (cfg, cfg_module_name) ->
List.mem i.v.name cfg.compile_time_flags.flags
&& i.v.modul_name = Some cfg_module_name
in
match e.v with
| This -> error "'this' is not allowed in the guard of an #if" e.range
| Static _ -> failwith "static should have been eliminated already"
| Constant _ -> ()
| Identifier i ->
if not (check_resolved_to_ifdef i)
then error (Printf.sprintf "Identifier %s is not a compile-time macro but is used in a #if" i.v.name) e.range
| App op args ->
begin
match op with
| And
| Or
| Not -> List.iter (collect_ifdef_guards env) args
| _ -> error "Only boolean expressions over identifiers are supported in #if guards" e.range
end
let rec resolve_expr' (env:qenv) (e:expr') r : ML expr' =
match e with
| Constant _ -> e
| Identifier i -> Identifier (resolve_ident env i)
| This -> e
| Static e' ->
let e' = resolve_expr env e' in
collect_ifdef_guards env e';//mark any variables as top-level IfDef symbols
e'.v
| App op args ->
let args = List.map (resolve_expr env) args in
App op args
and resolve_expr (env:qenv) (e:expr) : ML expr = { e with v = resolve_expr' env e.v e.range }
let resolve_typ_param (env:qenv) (p:typ_param) : ML typ_param =
match p with
| Inl e -> resolve_expr env e |> Inl
| _ -> p //Currently not going inside output expressions, should we?
let kind_of_ident (env:qenv) (i:ident)
: ML t_kind
= let _or_ (b0 b1:bool) = b0 || b1 in
if Some? (H.try_find env.output_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_out_t i.v)
then KindOutput
else if
Some? (H.try_find env.extern_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_extern_t i.v)
then KindExtern
else KindSpec
let rec resolve_typ' (env:qenv) (t:typ') : ML typ' =
match t with
| Type_app hd _ args ->
let hd = resolve_ident env hd in
//Set is_out argument to the Type_app appropriately
let k = kind_of_ident env hd in
Type_app hd k (List.map (resolve_typ_param env) args)
| Pointer t -> Pointer (resolve_typ env t)
and resolve_typ (env:qenv) (t:typ) : ML typ = { t with v = resolve_typ' env t.v }
let resolve_atomic_action (env:qenv) (ac:atomic_action) : ML atomic_action =
match ac with
| Action_return e -> Action_return (resolve_expr env e)
| Action_abort
| Action_field_pos_64
| Action_field_pos_32
| Action_field_ptr -> ac
| Action_field_ptr_after e write_to -> Action_field_ptr_after (resolve_expr env e) write_to
| Action_deref i -> Action_deref i //most certainly a type parameter
| Action_assignment lhs rhs ->
Action_assignment lhs (resolve_expr env rhs) //lhs is an action-local variable
| Action_call f args ->
Action_call (resolve_ident env f) (List.map (resolve_expr env) args) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> act: Ast.action -> FStar.All.ML Ast.action | FStar.All.ML | [
"ml"
] | [
"resolve_action'",
"resolve_action"
] | [
"Desugar.qenv",
"Ast.action",
"Ast.Mkwith_meta_t",
"Ast.action'",
"Ast.__proj__Mkwith_meta_t__item__range",
"Ast.__proj__Mkwith_meta_t__item__comments",
"Desugar.resolve_action'",
"Ast.__proj__Mkwith_meta_t__item__v"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec resolve_action (env: qenv) (act: action) : ML action =
| { act with v = resolve_action' env act.v } | false |
Vale.AES.X64.GHash.fsti | Vale.AES.X64.GHash.va_quick_Compute_ghash_incremental_register | val va_quick_Compute_ghash_incremental_register: Prims.unit
-> (va_quickCode unit (va_code_Compute_ghash_incremental_register ())) | val va_quick_Compute_ghash_incremental_register: Prims.unit
-> (va_quickCode unit (va_code_Compute_ghash_incremental_register ())) | let va_quick_Compute_ghash_incremental_register () : (va_quickCode unit
(va_code_Compute_ghash_incremental_register ())) =
(va_QProc (va_code_Compute_ghash_incremental_register ()) ([va_Mod_xmm 6; va_Mod_xmm 5;
va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_reg64 rR12; va_Mod_flags; va_Mod_xmm 1])
va_wp_Compute_ghash_incremental_register va_wpProof_Compute_ghash_incremental_register) | {
"file_name": "obj/Vale.AES.X64.GHash.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 91,
"end_line": 83,
"start_col": 0,
"start_line": 79
} | module Vale.AES.X64.GHash
open Vale.Def.Opaque_s
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.AES.AES_s
open Vale.AES.GHash_s
open Vale.AES.GHash
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.AES.GCTR_s
open Vale.AES.GCM_helpers
open Vale.Math.Poly2_s
open Vale.Poly1305.Math
open Vale.AES.X64.GF128_Mul
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.InsAes
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.X64.CPU_Features_s
#reset-options "--z3rlimit 30"
let get_last_slice_workaround (s:seq quad32) (start_pos end_pos:int) =
if 0 <= start_pos && start_pos < end_pos && end_pos <= length s then
last (slice s start_pos end_pos)
else
Mkfour 0 0 0 0
//let slice (s:seq quad32) (start_pos end_pos:int) =
// if 0 <= start_pos && start_pos < end_pos && end_pos <= length s then
// slice s start_pos end_pos
// else
// create 1 (Mkfour 0 0 0 0)
//-- Compute_ghash_incremental_register
val va_code_Compute_ghash_incremental_register : va_dummy:unit -> Tot va_code
val va_codegen_success_Compute_ghash_incremental_register : va_dummy:unit -> Tot va_pbool
val va_lemma_Compute_ghash_incremental_register : va_b0:va_code -> va_s0:va_state
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Compute_ghash_incremental_register ()) va_s0 /\
va_get_ok va_s0 /\ (pclmulqdq_enabled /\ avx_enabled /\ sse_enabled /\ va_get_xmm 8 va_s0 ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 202182159 134810123 67438087 66051)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_get_xmm 1 va_sM == Vale.AES.GHash.ghash_incremental (Vale.Def.Types_s.reverse_bytes_quad32
(va_get_xmm 11 va_sM)) (va_get_xmm 1 va_s0) (FStar.Seq.Base.create #quad32 1 (va_get_xmm 2
va_s0)) /\ va_state_eq va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 4
va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_reg64 rR12 va_sM
(va_update_flags va_sM (va_update_xmm 1 va_sM (va_update_ok va_sM va_s0)))))))))))
[@ va_qattr]
let va_wp_Compute_ghash_incremental_register (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) :
Type0 =
(va_get_ok va_s0 /\ (pclmulqdq_enabled /\ avx_enabled /\ sse_enabled /\ va_get_xmm 8 va_s0 ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 202182159 134810123 67438087 66051) /\ (forall
(va_x_xmm1:quad32) (va_x_efl:Vale.X64.Flags.t) (va_x_r12:nat64) (va_x_xmm2:quad32)
(va_x_xmm3:quad32) (va_x_xmm4:quad32) (va_x_xmm5:quad32) (va_x_xmm6:quad32) . let va_sM =
va_upd_xmm 6 va_x_xmm6 (va_upd_xmm 5 va_x_xmm5 (va_upd_xmm 4 va_x_xmm4 (va_upd_xmm 3 va_x_xmm3
(va_upd_xmm 2 va_x_xmm2 (va_upd_reg64 rR12 va_x_r12 (va_upd_flags va_x_efl (va_upd_xmm 1
va_x_xmm1 va_s0))))))) in va_get_ok va_sM /\ va_get_xmm 1 va_sM ==
Vale.AES.GHash.ghash_incremental (Vale.Def.Types_s.reverse_bytes_quad32 (va_get_xmm 11 va_sM))
(va_get_xmm 1 va_s0) (FStar.Seq.Base.create #quad32 1 (va_get_xmm 2 va_s0)) ==> va_k va_sM
(())))
val va_wpProof_Compute_ghash_incremental_register : va_s0:va_state -> va_k:(va_state -> unit ->
Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Compute_ghash_incremental_register va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Compute_ghash_incremental_register ())
([va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_reg64 rR12;
va_Mod_flags; va_Mod_xmm 1]) va_s0 va_k ((va_sM, va_f0, va_g)))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.InsAes.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Poly1305.Math.fsti.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.X64.GF128_Mul.fsti.checked",
"Vale.AES.GHash_s.fst.checked",
"Vale.AES.GHash.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.fsti.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.GCM_helpers.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.X64.GHash.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_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": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> Vale.X64.QuickCode.va_quickCode Prims.unit
(Vale.AES.X64.GHash.va_code_Compute_ghash_incremental_register ()) | Prims.Tot | [
"total"
] | [] | [
"Prims.unit",
"Vale.X64.QuickCode.va_QProc",
"Vale.AES.X64.GHash.va_code_Compute_ghash_incremental_register",
"Prims.Cons",
"Vale.X64.QuickCode.mod_t",
"Vale.X64.QuickCode.va_Mod_xmm",
"Vale.X64.QuickCode.va_Mod_reg64",
"Vale.X64.Machine_s.rR12",
"Vale.X64.QuickCode.va_Mod_flags",
"Prims.Nil",
"Vale.AES.X64.GHash.va_wp_Compute_ghash_incremental_register",
"Vale.AES.X64.GHash.va_wpProof_Compute_ghash_incremental_register",
"Vale.X64.QuickCode.va_quickCode"
] | [] | false | false | false | false | false | let va_quick_Compute_ghash_incremental_register ()
: (va_quickCode unit (va_code_Compute_ghash_incremental_register ())) =
| (va_QProc (va_code_Compute_ghash_incremental_register ())
([
va_Mod_xmm 6;
va_Mod_xmm 5;
va_Mod_xmm 4;
va_Mod_xmm 3;
va_Mod_xmm 2;
va_Mod_reg64 rR12;
va_Mod_flags;
va_Mod_xmm 1
])
va_wp_Compute_ghash_incremental_register
va_wpProof_Compute_ghash_incremental_register) | false |
Desugar.fst | Desugar.resolve_out_field | val resolve_out_field (env: qenv) (fld: out_field) : ML out_field | val resolve_out_field (env: qenv) (fld: out_field) : ML out_field | let rec resolve_out_field (env:qenv) (fld:out_field) : ML out_field =
match fld with
| Out_field_named i t n -> Out_field_named i (resolve_typ env t) n
| Out_field_anon l u -> Out_field_anon (resolve_out_fields env l) u
and resolve_out_fields (env:qenv) (flds:list out_field) : ML (list out_field) =
List.map (resolve_out_field env) flds | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 39,
"end_line": 398,
"start_col": 0,
"start_line": 392
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names }
let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ]
let resolve_ident (env:qenv) (i:ident) : ML ident =
let resolve_to_current_module i =
{ i with v = { i.v with modul_name = Some env.mname } }
in
let maybe_resolve_as_ifdef i
: ML ident
= match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts //it's a primitive constant, e.g. UINT8, leave as is
then i
else if List.mem i.v.name env.local_names //it's a local name (e.g. a parameter name)
then (if Some? i.v.modul_name //must have module name set to None
then error (Printf.sprintf
"Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i) //return the local name as is
else (match i.v.modul_name with //it's a top-level name
| None -> maybe_resolve_as_ifdef i
| Some m -> //if already qualified, check if it is an abbreviation
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } }))
let rec collect_ifdef_guards (env:qenv) (e:expr)
: ML unit
= let check_resolved_to_ifdef i =
match env.global_env.ge_cfg with
| None -> false
| Some (cfg, cfg_module_name) ->
List.mem i.v.name cfg.compile_time_flags.flags
&& i.v.modul_name = Some cfg_module_name
in
match e.v with
| This -> error "'this' is not allowed in the guard of an #if" e.range
| Static _ -> failwith "static should have been eliminated already"
| Constant _ -> ()
| Identifier i ->
if not (check_resolved_to_ifdef i)
then error (Printf.sprintf "Identifier %s is not a compile-time macro but is used in a #if" i.v.name) e.range
| App op args ->
begin
match op with
| And
| Or
| Not -> List.iter (collect_ifdef_guards env) args
| _ -> error "Only boolean expressions over identifiers are supported in #if guards" e.range
end
let rec resolve_expr' (env:qenv) (e:expr') r : ML expr' =
match e with
| Constant _ -> e
| Identifier i -> Identifier (resolve_ident env i)
| This -> e
| Static e' ->
let e' = resolve_expr env e' in
collect_ifdef_guards env e';//mark any variables as top-level IfDef symbols
e'.v
| App op args ->
let args = List.map (resolve_expr env) args in
App op args
and resolve_expr (env:qenv) (e:expr) : ML expr = { e with v = resolve_expr' env e.v e.range }
let resolve_typ_param (env:qenv) (p:typ_param) : ML typ_param =
match p with
| Inl e -> resolve_expr env e |> Inl
| _ -> p //Currently not going inside output expressions, should we?
let kind_of_ident (env:qenv) (i:ident)
: ML t_kind
= let _or_ (b0 b1:bool) = b0 || b1 in
if Some? (H.try_find env.output_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_out_t i.v)
then KindOutput
else if
Some? (H.try_find env.extern_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_extern_t i.v)
then KindExtern
else KindSpec
let rec resolve_typ' (env:qenv) (t:typ') : ML typ' =
match t with
| Type_app hd _ args ->
let hd = resolve_ident env hd in
//Set is_out argument to the Type_app appropriately
let k = kind_of_ident env hd in
Type_app hd k (List.map (resolve_typ_param env) args)
| Pointer t -> Pointer (resolve_typ env t)
and resolve_typ (env:qenv) (t:typ) : ML typ = { t with v = resolve_typ' env t.v }
let resolve_atomic_action (env:qenv) (ac:atomic_action) : ML atomic_action =
match ac with
| Action_return e -> Action_return (resolve_expr env e)
| Action_abort
| Action_field_pos_64
| Action_field_pos_32
| Action_field_ptr -> ac
| Action_field_ptr_after e write_to -> Action_field_ptr_after (resolve_expr env e) write_to
| Action_deref i -> Action_deref i //most certainly a type parameter
| Action_assignment lhs rhs ->
Action_assignment lhs (resolve_expr env rhs) //lhs is an action-local variable
| Action_call f args ->
Action_call (resolve_ident env f) (List.map (resolve_expr env) args)
let rec resolve_action' (env:qenv) (act:action') : ML action' =
match act with
| Atomic_action ac -> Atomic_action (resolve_atomic_action env ac)
| Action_seq hd tl ->
Action_seq (resolve_atomic_action env hd) (resolve_action env tl)
| Action_ite hd then_ else_ ->
Action_ite (resolve_expr env hd) (resolve_action env then_) (map_opt (resolve_action env) else_)
| Action_let i a k ->
Action_let i (resolve_atomic_action env a) (resolve_action (push_name env i.v.name) k)
| Action_act a ->
Action_act (resolve_action env a)
and resolve_action (env:qenv) (act:action) : ML action =
{ act with v = resolve_action' env act.v }
let resolve_param (env:qenv) (p:param) : ML (param & qenv) =
let t, i, q = p in
(resolve_typ env t, i, q),
push_name env i.v.name
let resolve_params (env:qenv) (params:list param) : ML (list param & qenv) =
List.fold_left (fun (params, env) p ->
let p, env = resolve_param env p in
params@[p], env) ([], env) params
let resolve_field_bitwidth_t (env:qenv) (fb:field_bitwidth_t) : ML field_bitwidth_t =
let resolve_bitfield_attr' (env:qenv) (b:bitfield_attr') : ML bitfield_attr' =
{ b with bitfield_type = resolve_typ env b.bitfield_type } in
let resolve_bitfield_attr (env:qenv) (b:bitfield_attr) : ML bitfield_attr =
{ b with v = resolve_bitfield_attr' env b.v } in
match fb with
| Inl _ -> fb
| Inr b -> Inr (resolve_bitfield_attr env b)
let resolve_field_array_t (env:qenv) (farr:field_array_t) : ML field_array_t =
match farr with
| FieldScalar -> farr
| FieldArrayQualified (e, aq) ->
FieldArrayQualified (resolve_expr env e, aq)
| FieldString None -> farr
| FieldString (Some e) -> FieldString (Some (resolve_expr env e))
| FieldConsumeAll -> farr
let resolve_probe_call env pc =
{
probe_fn = map_opt (resolve_ident env) pc.probe_fn;
probe_length = resolve_expr env pc.probe_length;
probe_dest = resolve_ident env pc.probe_dest;
}
let rec resolve_field (env:qenv) (ff:field) : ML (field & qenv) =
match ff.v with
| AtomicField f -> let f, e = resolve_atomic_field env f in {ff with v = AtomicField f}, e
| RecordField f i -> let fs, _ = resolve_fields env f in {ff with v = RecordField fs i}, env //record fields are not in scope outside the record
| SwitchCaseField f i -> let f = resolve_switch_case env f in {ff with v = SwitchCaseField f i}, env
and resolve_atomic_field (env:qenv) (f:atomic_field) : ML (atomic_field & qenv) =
let resolve_atomic_field' (env:qenv) (sf:atomic_field') : ML atomic_field' =
let is_non_scalar = not (FieldScalar? sf.field_array_opt) in
if is_non_scalar && (Some? sf.field_constraint)
then error (Printf.sprintf "Non-scalar field '%s' cannot be refined with constraints" sf.field_ident.v.name) f.range
else if is_non_scalar && (Some? sf.field_bitwidth)
then error (Printf.sprintf "Non-scalar field '%s' cannot have a bit width" sf.field_ident.v.name) f.range
else (
{ sf with
field_type = resolve_typ env sf.field_type;
field_array_opt = resolve_field_array_t env sf.field_array_opt;
field_constraint = map_opt (resolve_expr env) sf.field_constraint;
field_bitwidth = map_opt (resolve_field_bitwidth_t env) sf.field_bitwidth;
field_action = map_opt (fun (a, b) -> resolve_action env a, b) sf.field_action;
field_probe = map_opt (resolve_probe_call env) sf.field_probe }
)
in
let env = push_name env f.v.field_ident.v.name in
{ f with v = resolve_atomic_field' env f.v }, env
and resolve_fields (env:qenv) (flds:list field) : ML (list field & qenv) =
List.fold_left (fun (flds, env) f ->
let f, env = resolve_field env f in
flds@[f], env) ([], env) flds
and resolve_switch_case (env:qenv) (sc:switch_case) : ML switch_case = //case fields do not escape their scope
let resolve_case (env:qenv) (c:case) : ML case =
match c with
| Case e f -> Case (resolve_expr env e) (fst (resolve_field env f))
| DefaultCase f -> DefaultCase (fst (resolve_field env f)) in
let e, l = sc in
resolve_expr env e, List.map (resolve_case env) l
let resolve_typedef_names (env:qenv) (td_names:typedef_names) : ML typedef_names =
{ td_names with
typedef_name = resolve_ident env td_names.typedef_name;
typedef_abbrev = resolve_ident env td_names.typedef_abbrev;
typedef_ptr_abbrev = resolve_ident env td_names.typedef_ptr_abbrev }
let resolve_enum_case (env:qenv) (ec:enum_case) : ML enum_case =
match ec with
| i, None -> resolve_ident env i, None
| _ -> error "Unexpected enum_case in resolve_enum_case" (fst ec).range | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> fld: Ast.out_field -> FStar.All.ML Ast.out_field | FStar.All.ML | [
"ml"
] | [
"resolve_out_field",
"resolve_out_fields"
] | [
"Desugar.qenv",
"Ast.out_field",
"Ast.ident",
"Ast.typ",
"FStar.Pervasives.Native.option",
"Prims.int",
"Ast.Out_field_named",
"Desugar.resolve_typ",
"Prims.list",
"Prims.bool",
"Ast.Out_field_anon",
"Desugar.resolve_out_fields"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec resolve_out_field (env: qenv) (fld: out_field) : ML out_field =
| match fld with
| Out_field_named i t n -> Out_field_named i (resolve_typ env t) n
| Out_field_anon l u -> Out_field_anon (resolve_out_fields env l) u | false |
Desugar.fst | Desugar.resolve_atomic_field | val resolve_atomic_field (env: qenv) (f: atomic_field) : ML (atomic_field & qenv) | val resolve_atomic_field (env: qenv) (f: atomic_field) : ML (atomic_field & qenv) | let rec resolve_field (env:qenv) (ff:field) : ML (field & qenv) =
match ff.v with
| AtomicField f -> let f, e = resolve_atomic_field env f in {ff with v = AtomicField f}, e
| RecordField f i -> let fs, _ = resolve_fields env f in {ff with v = RecordField fs i}, env //record fields are not in scope outside the record
| SwitchCaseField f i -> let f = resolve_switch_case env f in {ff with v = SwitchCaseField f i}, env
and resolve_atomic_field (env:qenv) (f:atomic_field) : ML (atomic_field & qenv) =
let resolve_atomic_field' (env:qenv) (sf:atomic_field') : ML atomic_field' =
let is_non_scalar = not (FieldScalar? sf.field_array_opt) in
if is_non_scalar && (Some? sf.field_constraint)
then error (Printf.sprintf "Non-scalar field '%s' cannot be refined with constraints" sf.field_ident.v.name) f.range
else if is_non_scalar && (Some? sf.field_bitwidth)
then error (Printf.sprintf "Non-scalar field '%s' cannot have a bit width" sf.field_ident.v.name) f.range
else (
{ sf with
field_type = resolve_typ env sf.field_type;
field_array_opt = resolve_field_array_t env sf.field_array_opt;
field_constraint = map_opt (resolve_expr env) sf.field_constraint;
field_bitwidth = map_opt (resolve_field_bitwidth_t env) sf.field_bitwidth;
field_action = map_opt (fun (a, b) -> resolve_action env a, b) sf.field_action;
field_probe = map_opt (resolve_probe_call env) sf.field_probe }
)
in
let env = push_name env f.v.field_ident.v.name in
{ f with v = resolve_atomic_field' env f.v }, env
and resolve_fields (env:qenv) (flds:list field) : ML (list field & qenv) =
List.fold_left (fun (flds, env) f ->
let f, env = resolve_field env f in
flds@[f], env) ([], env) flds
and resolve_switch_case (env:qenv) (sc:switch_case) : ML switch_case = //case fields do not escape their scope
let resolve_case (env:qenv) (c:case) : ML case =
match c with
| Case e f -> Case (resolve_expr env e) (fst (resolve_field env f))
| DefaultCase f -> DefaultCase (fst (resolve_field env f)) in
let e, l = sc in
resolve_expr env e, List.map (resolve_case env) l | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 51,
"end_line": 379,
"start_col": 0,
"start_line": 341
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names }
let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ]
let resolve_ident (env:qenv) (i:ident) : ML ident =
let resolve_to_current_module i =
{ i with v = { i.v with modul_name = Some env.mname } }
in
let maybe_resolve_as_ifdef i
: ML ident
= match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts //it's a primitive constant, e.g. UINT8, leave as is
then i
else if List.mem i.v.name env.local_names //it's a local name (e.g. a parameter name)
then (if Some? i.v.modul_name //must have module name set to None
then error (Printf.sprintf
"Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i) //return the local name as is
else (match i.v.modul_name with //it's a top-level name
| None -> maybe_resolve_as_ifdef i
| Some m -> //if already qualified, check if it is an abbreviation
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } }))
let rec collect_ifdef_guards (env:qenv) (e:expr)
: ML unit
= let check_resolved_to_ifdef i =
match env.global_env.ge_cfg with
| None -> false
| Some (cfg, cfg_module_name) ->
List.mem i.v.name cfg.compile_time_flags.flags
&& i.v.modul_name = Some cfg_module_name
in
match e.v with
| This -> error "'this' is not allowed in the guard of an #if" e.range
| Static _ -> failwith "static should have been eliminated already"
| Constant _ -> ()
| Identifier i ->
if not (check_resolved_to_ifdef i)
then error (Printf.sprintf "Identifier %s is not a compile-time macro but is used in a #if" i.v.name) e.range
| App op args ->
begin
match op with
| And
| Or
| Not -> List.iter (collect_ifdef_guards env) args
| _ -> error "Only boolean expressions over identifiers are supported in #if guards" e.range
end
let rec resolve_expr' (env:qenv) (e:expr') r : ML expr' =
match e with
| Constant _ -> e
| Identifier i -> Identifier (resolve_ident env i)
| This -> e
| Static e' ->
let e' = resolve_expr env e' in
collect_ifdef_guards env e';//mark any variables as top-level IfDef symbols
e'.v
| App op args ->
let args = List.map (resolve_expr env) args in
App op args
and resolve_expr (env:qenv) (e:expr) : ML expr = { e with v = resolve_expr' env e.v e.range }
let resolve_typ_param (env:qenv) (p:typ_param) : ML typ_param =
match p with
| Inl e -> resolve_expr env e |> Inl
| _ -> p //Currently not going inside output expressions, should we?
let kind_of_ident (env:qenv) (i:ident)
: ML t_kind
= let _or_ (b0 b1:bool) = b0 || b1 in
if Some? (H.try_find env.output_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_out_t i.v)
then KindOutput
else if
Some? (H.try_find env.extern_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_extern_t i.v)
then KindExtern
else KindSpec
let rec resolve_typ' (env:qenv) (t:typ') : ML typ' =
match t with
| Type_app hd _ args ->
let hd = resolve_ident env hd in
//Set is_out argument to the Type_app appropriately
let k = kind_of_ident env hd in
Type_app hd k (List.map (resolve_typ_param env) args)
| Pointer t -> Pointer (resolve_typ env t)
and resolve_typ (env:qenv) (t:typ) : ML typ = { t with v = resolve_typ' env t.v }
let resolve_atomic_action (env:qenv) (ac:atomic_action) : ML atomic_action =
match ac with
| Action_return e -> Action_return (resolve_expr env e)
| Action_abort
| Action_field_pos_64
| Action_field_pos_32
| Action_field_ptr -> ac
| Action_field_ptr_after e write_to -> Action_field_ptr_after (resolve_expr env e) write_to
| Action_deref i -> Action_deref i //most certainly a type parameter
| Action_assignment lhs rhs ->
Action_assignment lhs (resolve_expr env rhs) //lhs is an action-local variable
| Action_call f args ->
Action_call (resolve_ident env f) (List.map (resolve_expr env) args)
let rec resolve_action' (env:qenv) (act:action') : ML action' =
match act with
| Atomic_action ac -> Atomic_action (resolve_atomic_action env ac)
| Action_seq hd tl ->
Action_seq (resolve_atomic_action env hd) (resolve_action env tl)
| Action_ite hd then_ else_ ->
Action_ite (resolve_expr env hd) (resolve_action env then_) (map_opt (resolve_action env) else_)
| Action_let i a k ->
Action_let i (resolve_atomic_action env a) (resolve_action (push_name env i.v.name) k)
| Action_act a ->
Action_act (resolve_action env a)
and resolve_action (env:qenv) (act:action) : ML action =
{ act with v = resolve_action' env act.v }
let resolve_param (env:qenv) (p:param) : ML (param & qenv) =
let t, i, q = p in
(resolve_typ env t, i, q),
push_name env i.v.name
let resolve_params (env:qenv) (params:list param) : ML (list param & qenv) =
List.fold_left (fun (params, env) p ->
let p, env = resolve_param env p in
params@[p], env) ([], env) params
let resolve_field_bitwidth_t (env:qenv) (fb:field_bitwidth_t) : ML field_bitwidth_t =
let resolve_bitfield_attr' (env:qenv) (b:bitfield_attr') : ML bitfield_attr' =
{ b with bitfield_type = resolve_typ env b.bitfield_type } in
let resolve_bitfield_attr (env:qenv) (b:bitfield_attr) : ML bitfield_attr =
{ b with v = resolve_bitfield_attr' env b.v } in
match fb with
| Inl _ -> fb
| Inr b -> Inr (resolve_bitfield_attr env b)
let resolve_field_array_t (env:qenv) (farr:field_array_t) : ML field_array_t =
match farr with
| FieldScalar -> farr
| FieldArrayQualified (e, aq) ->
FieldArrayQualified (resolve_expr env e, aq)
| FieldString None -> farr
| FieldString (Some e) -> FieldString (Some (resolve_expr env e))
| FieldConsumeAll -> farr
let resolve_probe_call env pc =
{
probe_fn = map_opt (resolve_ident env) pc.probe_fn;
probe_length = resolve_expr env pc.probe_length;
probe_dest = resolve_ident env pc.probe_dest;
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> f: Ast.atomic_field -> FStar.All.ML (Ast.atomic_field * Desugar.qenv) | FStar.All.ML | [
"ml"
] | [
"resolve_field",
"resolve_atomic_field",
"resolve_fields",
"resolve_switch_case"
] | [
"Desugar.qenv",
"Ast.atomic_field",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.tuple2",
"Ast.Mkwith_meta_t",
"Ast.atomic_field'",
"Ast.__proj__Mkwith_meta_t__item__range",
"Ast.__proj__Mkwith_meta_t__item__comments",
"Ast.__proj__Mkwith_meta_t__item__v",
"Desugar.push_name",
"Ast.__proj__Mkident'__item__name",
"Ast.ident'",
"Ast.__proj__Mkatomic_field'__item__field_ident",
"Prims.op_AmpAmp",
"FStar.Pervasives.Native.uu___is_Some",
"Ast.expr",
"Ast.__proj__Mkatomic_field'__item__field_constraint",
"Ast.error",
"FStar.Printf.sprintf",
"Prims.bool",
"Ast.field_bitwidth_t",
"Ast.__proj__Mkatomic_field'__item__field_bitwidth",
"Ast.Mkatomic_field'",
"Ast.__proj__Mkatomic_field'__item__field_dependence",
"FStar.Pervasives.Native.option",
"Ast.probe_call",
"Ast.map_opt",
"Desugar.resolve_probe_call",
"Ast.__proj__Mkatomic_field'__item__field_probe",
"Ast.action",
"Desugar.resolve_action",
"Ast.__proj__Mkatomic_field'__item__field_action",
"Desugar.resolve_field_bitwidth_t",
"Desugar.resolve_expr",
"Ast.field_array_t",
"Desugar.resolve_field_array_t",
"Ast.__proj__Mkatomic_field'__item__field_array_opt",
"Ast.typ",
"Desugar.resolve_typ",
"Ast.__proj__Mkatomic_field'__item__field_type",
"Prims.op_Negation",
"Ast.uu___is_FieldScalar"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec resolve_atomic_field (env: qenv) (f: atomic_field) : ML (atomic_field & qenv) =
| let resolve_atomic_field' (env: qenv) (sf: atomic_field') : ML atomic_field' =
let is_non_scalar = not (FieldScalar? sf.field_array_opt) in
if is_non_scalar && (Some? sf.field_constraint)
then
error (Printf.sprintf "Non-scalar field '%s' cannot be refined with constraints"
sf.field_ident.v.name)
f.range
else
if is_non_scalar && (Some? sf.field_bitwidth)
then
error (Printf.sprintf "Non-scalar field '%s' cannot have a bit width" sf.field_ident.v.name)
f.range
else
({
sf with
field_type = resolve_typ env sf.field_type;
field_array_opt = resolve_field_array_t env sf.field_array_opt;
field_constraint = map_opt (resolve_expr env) sf.field_constraint;
field_bitwidth = map_opt (resolve_field_bitwidth_t env) sf.field_bitwidth;
field_action = map_opt (fun (a, b) -> resolve_action env a, b) sf.field_action;
field_probe = map_opt (resolve_probe_call env) sf.field_probe
})
in
let env = push_name env f.v.field_ident.v.name in
{ f with v = resolve_atomic_field' env f.v }, env | false |
Desugar.fst | Desugar.resolve_fields | val resolve_fields (env: qenv) (flds: list field) : ML (list field & qenv) | val resolve_fields (env: qenv) (flds: list field) : ML (list field & qenv) | let rec resolve_field (env:qenv) (ff:field) : ML (field & qenv) =
match ff.v with
| AtomicField f -> let f, e = resolve_atomic_field env f in {ff with v = AtomicField f}, e
| RecordField f i -> let fs, _ = resolve_fields env f in {ff with v = RecordField fs i}, env //record fields are not in scope outside the record
| SwitchCaseField f i -> let f = resolve_switch_case env f in {ff with v = SwitchCaseField f i}, env
and resolve_atomic_field (env:qenv) (f:atomic_field) : ML (atomic_field & qenv) =
let resolve_atomic_field' (env:qenv) (sf:atomic_field') : ML atomic_field' =
let is_non_scalar = not (FieldScalar? sf.field_array_opt) in
if is_non_scalar && (Some? sf.field_constraint)
then error (Printf.sprintf "Non-scalar field '%s' cannot be refined with constraints" sf.field_ident.v.name) f.range
else if is_non_scalar && (Some? sf.field_bitwidth)
then error (Printf.sprintf "Non-scalar field '%s' cannot have a bit width" sf.field_ident.v.name) f.range
else (
{ sf with
field_type = resolve_typ env sf.field_type;
field_array_opt = resolve_field_array_t env sf.field_array_opt;
field_constraint = map_opt (resolve_expr env) sf.field_constraint;
field_bitwidth = map_opt (resolve_field_bitwidth_t env) sf.field_bitwidth;
field_action = map_opt (fun (a, b) -> resolve_action env a, b) sf.field_action;
field_probe = map_opt (resolve_probe_call env) sf.field_probe }
)
in
let env = push_name env f.v.field_ident.v.name in
{ f with v = resolve_atomic_field' env f.v }, env
and resolve_fields (env:qenv) (flds:list field) : ML (list field & qenv) =
List.fold_left (fun (flds, env) f ->
let f, env = resolve_field env f in
flds@[f], env) ([], env) flds
and resolve_switch_case (env:qenv) (sc:switch_case) : ML switch_case = //case fields do not escape their scope
let resolve_case (env:qenv) (c:case) : ML case =
match c with
| Case e f -> Case (resolve_expr env e) (fst (resolve_field env f))
| DefaultCase f -> DefaultCase (fst (resolve_field env f)) in
let e, l = sc in
resolve_expr env e, List.map (resolve_case env) l | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 51,
"end_line": 379,
"start_col": 0,
"start_line": 341
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names }
let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ]
let resolve_ident (env:qenv) (i:ident) : ML ident =
let resolve_to_current_module i =
{ i with v = { i.v with modul_name = Some env.mname } }
in
let maybe_resolve_as_ifdef i
: ML ident
= match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts //it's a primitive constant, e.g. UINT8, leave as is
then i
else if List.mem i.v.name env.local_names //it's a local name (e.g. a parameter name)
then (if Some? i.v.modul_name //must have module name set to None
then error (Printf.sprintf
"Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i) //return the local name as is
else (match i.v.modul_name with //it's a top-level name
| None -> maybe_resolve_as_ifdef i
| Some m -> //if already qualified, check if it is an abbreviation
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } }))
let rec collect_ifdef_guards (env:qenv) (e:expr)
: ML unit
= let check_resolved_to_ifdef i =
match env.global_env.ge_cfg with
| None -> false
| Some (cfg, cfg_module_name) ->
List.mem i.v.name cfg.compile_time_flags.flags
&& i.v.modul_name = Some cfg_module_name
in
match e.v with
| This -> error "'this' is not allowed in the guard of an #if" e.range
| Static _ -> failwith "static should have been eliminated already"
| Constant _ -> ()
| Identifier i ->
if not (check_resolved_to_ifdef i)
then error (Printf.sprintf "Identifier %s is not a compile-time macro but is used in a #if" i.v.name) e.range
| App op args ->
begin
match op with
| And
| Or
| Not -> List.iter (collect_ifdef_guards env) args
| _ -> error "Only boolean expressions over identifiers are supported in #if guards" e.range
end
let rec resolve_expr' (env:qenv) (e:expr') r : ML expr' =
match e with
| Constant _ -> e
| Identifier i -> Identifier (resolve_ident env i)
| This -> e
| Static e' ->
let e' = resolve_expr env e' in
collect_ifdef_guards env e';//mark any variables as top-level IfDef symbols
e'.v
| App op args ->
let args = List.map (resolve_expr env) args in
App op args
and resolve_expr (env:qenv) (e:expr) : ML expr = { e with v = resolve_expr' env e.v e.range }
let resolve_typ_param (env:qenv) (p:typ_param) : ML typ_param =
match p with
| Inl e -> resolve_expr env e |> Inl
| _ -> p //Currently not going inside output expressions, should we?
let kind_of_ident (env:qenv) (i:ident)
: ML t_kind
= let _or_ (b0 b1:bool) = b0 || b1 in
if Some? (H.try_find env.output_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_out_t i.v)
then KindOutput
else if
Some? (H.try_find env.extern_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_extern_t i.v)
then KindExtern
else KindSpec
let rec resolve_typ' (env:qenv) (t:typ') : ML typ' =
match t with
| Type_app hd _ args ->
let hd = resolve_ident env hd in
//Set is_out argument to the Type_app appropriately
let k = kind_of_ident env hd in
Type_app hd k (List.map (resolve_typ_param env) args)
| Pointer t -> Pointer (resolve_typ env t)
and resolve_typ (env:qenv) (t:typ) : ML typ = { t with v = resolve_typ' env t.v }
let resolve_atomic_action (env:qenv) (ac:atomic_action) : ML atomic_action =
match ac with
| Action_return e -> Action_return (resolve_expr env e)
| Action_abort
| Action_field_pos_64
| Action_field_pos_32
| Action_field_ptr -> ac
| Action_field_ptr_after e write_to -> Action_field_ptr_after (resolve_expr env e) write_to
| Action_deref i -> Action_deref i //most certainly a type parameter
| Action_assignment lhs rhs ->
Action_assignment lhs (resolve_expr env rhs) //lhs is an action-local variable
| Action_call f args ->
Action_call (resolve_ident env f) (List.map (resolve_expr env) args)
let rec resolve_action' (env:qenv) (act:action') : ML action' =
match act with
| Atomic_action ac -> Atomic_action (resolve_atomic_action env ac)
| Action_seq hd tl ->
Action_seq (resolve_atomic_action env hd) (resolve_action env tl)
| Action_ite hd then_ else_ ->
Action_ite (resolve_expr env hd) (resolve_action env then_) (map_opt (resolve_action env) else_)
| Action_let i a k ->
Action_let i (resolve_atomic_action env a) (resolve_action (push_name env i.v.name) k)
| Action_act a ->
Action_act (resolve_action env a)
and resolve_action (env:qenv) (act:action) : ML action =
{ act with v = resolve_action' env act.v }
let resolve_param (env:qenv) (p:param) : ML (param & qenv) =
let t, i, q = p in
(resolve_typ env t, i, q),
push_name env i.v.name
let resolve_params (env:qenv) (params:list param) : ML (list param & qenv) =
List.fold_left (fun (params, env) p ->
let p, env = resolve_param env p in
params@[p], env) ([], env) params
let resolve_field_bitwidth_t (env:qenv) (fb:field_bitwidth_t) : ML field_bitwidth_t =
let resolve_bitfield_attr' (env:qenv) (b:bitfield_attr') : ML bitfield_attr' =
{ b with bitfield_type = resolve_typ env b.bitfield_type } in
let resolve_bitfield_attr (env:qenv) (b:bitfield_attr) : ML bitfield_attr =
{ b with v = resolve_bitfield_attr' env b.v } in
match fb with
| Inl _ -> fb
| Inr b -> Inr (resolve_bitfield_attr env b)
let resolve_field_array_t (env:qenv) (farr:field_array_t) : ML field_array_t =
match farr with
| FieldScalar -> farr
| FieldArrayQualified (e, aq) ->
FieldArrayQualified (resolve_expr env e, aq)
| FieldString None -> farr
| FieldString (Some e) -> FieldString (Some (resolve_expr env e))
| FieldConsumeAll -> farr
let resolve_probe_call env pc =
{
probe_fn = map_opt (resolve_ident env) pc.probe_fn;
probe_length = resolve_expr env pc.probe_length;
probe_dest = resolve_ident env pc.probe_dest;
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> flds: Prims.list Ast.field
-> FStar.All.ML (Prims.list Ast.field * Desugar.qenv) | FStar.All.ML | [
"ml"
] | [
"resolve_field",
"resolve_atomic_field",
"resolve_fields",
"resolve_switch_case"
] | [
"Desugar.qenv",
"Prims.list",
"Ast.field",
"FStar.List.fold_left",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"FStar.List.Tot.Base.op_At",
"Prims.Cons",
"Prims.Nil",
"Desugar.resolve_field"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec resolve_fields (env: qenv) (flds: list field) : ML (list field & qenv) =
| List.fold_left (fun (flds, env) f ->
let f, env = resolve_field env f in
flds @ [f], env)
([], env)
flds | false |
Desugar.fst | Desugar.resolve_field_array_t | val resolve_field_array_t (env: qenv) (farr: field_array_t) : ML field_array_t | val resolve_field_array_t (env: qenv) (farr: field_array_t) : ML field_array_t | let resolve_field_array_t (env:qenv) (farr:field_array_t) : ML field_array_t =
match farr with
| FieldScalar -> farr
| FieldArrayQualified (e, aq) ->
FieldArrayQualified (resolve_expr env e, aq)
| FieldString None -> farr
| FieldString (Some e) -> FieldString (Some (resolve_expr env e))
| FieldConsumeAll -> farr | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 27,
"end_line": 332,
"start_col": 0,
"start_line": 325
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names }
let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ]
let resolve_ident (env:qenv) (i:ident) : ML ident =
let resolve_to_current_module i =
{ i with v = { i.v with modul_name = Some env.mname } }
in
let maybe_resolve_as_ifdef i
: ML ident
= match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts //it's a primitive constant, e.g. UINT8, leave as is
then i
else if List.mem i.v.name env.local_names //it's a local name (e.g. a parameter name)
then (if Some? i.v.modul_name //must have module name set to None
then error (Printf.sprintf
"Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i) //return the local name as is
else (match i.v.modul_name with //it's a top-level name
| None -> maybe_resolve_as_ifdef i
| Some m -> //if already qualified, check if it is an abbreviation
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } }))
let rec collect_ifdef_guards (env:qenv) (e:expr)
: ML unit
= let check_resolved_to_ifdef i =
match env.global_env.ge_cfg with
| None -> false
| Some (cfg, cfg_module_name) ->
List.mem i.v.name cfg.compile_time_flags.flags
&& i.v.modul_name = Some cfg_module_name
in
match e.v with
| This -> error "'this' is not allowed in the guard of an #if" e.range
| Static _ -> failwith "static should have been eliminated already"
| Constant _ -> ()
| Identifier i ->
if not (check_resolved_to_ifdef i)
then error (Printf.sprintf "Identifier %s is not a compile-time macro but is used in a #if" i.v.name) e.range
| App op args ->
begin
match op with
| And
| Or
| Not -> List.iter (collect_ifdef_guards env) args
| _ -> error "Only boolean expressions over identifiers are supported in #if guards" e.range
end
let rec resolve_expr' (env:qenv) (e:expr') r : ML expr' =
match e with
| Constant _ -> e
| Identifier i -> Identifier (resolve_ident env i)
| This -> e
| Static e' ->
let e' = resolve_expr env e' in
collect_ifdef_guards env e';//mark any variables as top-level IfDef symbols
e'.v
| App op args ->
let args = List.map (resolve_expr env) args in
App op args
and resolve_expr (env:qenv) (e:expr) : ML expr = { e with v = resolve_expr' env e.v e.range }
let resolve_typ_param (env:qenv) (p:typ_param) : ML typ_param =
match p with
| Inl e -> resolve_expr env e |> Inl
| _ -> p //Currently not going inside output expressions, should we?
let kind_of_ident (env:qenv) (i:ident)
: ML t_kind
= let _or_ (b0 b1:bool) = b0 || b1 in
if Some? (H.try_find env.output_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_out_t i.v)
then KindOutput
else if
Some? (H.try_find env.extern_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_extern_t i.v)
then KindExtern
else KindSpec
let rec resolve_typ' (env:qenv) (t:typ') : ML typ' =
match t with
| Type_app hd _ args ->
let hd = resolve_ident env hd in
//Set is_out argument to the Type_app appropriately
let k = kind_of_ident env hd in
Type_app hd k (List.map (resolve_typ_param env) args)
| Pointer t -> Pointer (resolve_typ env t)
and resolve_typ (env:qenv) (t:typ) : ML typ = { t with v = resolve_typ' env t.v }
let resolve_atomic_action (env:qenv) (ac:atomic_action) : ML atomic_action =
match ac with
| Action_return e -> Action_return (resolve_expr env e)
| Action_abort
| Action_field_pos_64
| Action_field_pos_32
| Action_field_ptr -> ac
| Action_field_ptr_after e write_to -> Action_field_ptr_after (resolve_expr env e) write_to
| Action_deref i -> Action_deref i //most certainly a type parameter
| Action_assignment lhs rhs ->
Action_assignment lhs (resolve_expr env rhs) //lhs is an action-local variable
| Action_call f args ->
Action_call (resolve_ident env f) (List.map (resolve_expr env) args)
let rec resolve_action' (env:qenv) (act:action') : ML action' =
match act with
| Atomic_action ac -> Atomic_action (resolve_atomic_action env ac)
| Action_seq hd tl ->
Action_seq (resolve_atomic_action env hd) (resolve_action env tl)
| Action_ite hd then_ else_ ->
Action_ite (resolve_expr env hd) (resolve_action env then_) (map_opt (resolve_action env) else_)
| Action_let i a k ->
Action_let i (resolve_atomic_action env a) (resolve_action (push_name env i.v.name) k)
| Action_act a ->
Action_act (resolve_action env a)
and resolve_action (env:qenv) (act:action) : ML action =
{ act with v = resolve_action' env act.v }
let resolve_param (env:qenv) (p:param) : ML (param & qenv) =
let t, i, q = p in
(resolve_typ env t, i, q),
push_name env i.v.name
let resolve_params (env:qenv) (params:list param) : ML (list param & qenv) =
List.fold_left (fun (params, env) p ->
let p, env = resolve_param env p in
params@[p], env) ([], env) params
let resolve_field_bitwidth_t (env:qenv) (fb:field_bitwidth_t) : ML field_bitwidth_t =
let resolve_bitfield_attr' (env:qenv) (b:bitfield_attr') : ML bitfield_attr' =
{ b with bitfield_type = resolve_typ env b.bitfield_type } in
let resolve_bitfield_attr (env:qenv) (b:bitfield_attr) : ML bitfield_attr =
{ b with v = resolve_bitfield_attr' env b.v } in
match fb with
| Inl _ -> fb
| Inr b -> Inr (resolve_bitfield_attr env b) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> farr: Ast.field_array_t -> FStar.All.ML Ast.field_array_t | FStar.All.ML | [
"ml"
] | [] | [
"Desugar.qenv",
"Ast.field_array_t",
"Ast.expr",
"Ast.array_qualifier",
"Ast.FieldArrayQualified",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"Desugar.resolve_expr",
"Ast.FieldString",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.Some"
] | [] | false | true | false | false | false | let resolve_field_array_t (env: qenv) (farr: field_array_t) : ML field_array_t =
| match farr with
| FieldScalar -> farr
| FieldArrayQualified (e, aq) -> FieldArrayQualified (resolve_expr env e, aq)
| FieldString None -> farr
| FieldString (Some e) -> FieldString (Some (resolve_expr env e))
| FieldConsumeAll -> farr | false |
Desugar.fst | Desugar.resolve_switch_case | val resolve_switch_case (env: qenv) (sc: switch_case) : ML switch_case | val resolve_switch_case (env: qenv) (sc: switch_case) : ML switch_case | let rec resolve_field (env:qenv) (ff:field) : ML (field & qenv) =
match ff.v with
| AtomicField f -> let f, e = resolve_atomic_field env f in {ff with v = AtomicField f}, e
| RecordField f i -> let fs, _ = resolve_fields env f in {ff with v = RecordField fs i}, env //record fields are not in scope outside the record
| SwitchCaseField f i -> let f = resolve_switch_case env f in {ff with v = SwitchCaseField f i}, env
and resolve_atomic_field (env:qenv) (f:atomic_field) : ML (atomic_field & qenv) =
let resolve_atomic_field' (env:qenv) (sf:atomic_field') : ML atomic_field' =
let is_non_scalar = not (FieldScalar? sf.field_array_opt) in
if is_non_scalar && (Some? sf.field_constraint)
then error (Printf.sprintf "Non-scalar field '%s' cannot be refined with constraints" sf.field_ident.v.name) f.range
else if is_non_scalar && (Some? sf.field_bitwidth)
then error (Printf.sprintf "Non-scalar field '%s' cannot have a bit width" sf.field_ident.v.name) f.range
else (
{ sf with
field_type = resolve_typ env sf.field_type;
field_array_opt = resolve_field_array_t env sf.field_array_opt;
field_constraint = map_opt (resolve_expr env) sf.field_constraint;
field_bitwidth = map_opt (resolve_field_bitwidth_t env) sf.field_bitwidth;
field_action = map_opt (fun (a, b) -> resolve_action env a, b) sf.field_action;
field_probe = map_opt (resolve_probe_call env) sf.field_probe }
)
in
let env = push_name env f.v.field_ident.v.name in
{ f with v = resolve_atomic_field' env f.v }, env
and resolve_fields (env:qenv) (flds:list field) : ML (list field & qenv) =
List.fold_left (fun (flds, env) f ->
let f, env = resolve_field env f in
flds@[f], env) ([], env) flds
and resolve_switch_case (env:qenv) (sc:switch_case) : ML switch_case = //case fields do not escape their scope
let resolve_case (env:qenv) (c:case) : ML case =
match c with
| Case e f -> Case (resolve_expr env e) (fst (resolve_field env f))
| DefaultCase f -> DefaultCase (fst (resolve_field env f)) in
let e, l = sc in
resolve_expr env e, List.map (resolve_case env) l | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 51,
"end_line": 379,
"start_col": 0,
"start_line": 341
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names }
let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ]
let resolve_ident (env:qenv) (i:ident) : ML ident =
let resolve_to_current_module i =
{ i with v = { i.v with modul_name = Some env.mname } }
in
let maybe_resolve_as_ifdef i
: ML ident
= match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts //it's a primitive constant, e.g. UINT8, leave as is
then i
else if List.mem i.v.name env.local_names //it's a local name (e.g. a parameter name)
then (if Some? i.v.modul_name //must have module name set to None
then error (Printf.sprintf
"Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i) //return the local name as is
else (match i.v.modul_name with //it's a top-level name
| None -> maybe_resolve_as_ifdef i
| Some m -> //if already qualified, check if it is an abbreviation
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } }))
let rec collect_ifdef_guards (env:qenv) (e:expr)
: ML unit
= let check_resolved_to_ifdef i =
match env.global_env.ge_cfg with
| None -> false
| Some (cfg, cfg_module_name) ->
List.mem i.v.name cfg.compile_time_flags.flags
&& i.v.modul_name = Some cfg_module_name
in
match e.v with
| This -> error "'this' is not allowed in the guard of an #if" e.range
| Static _ -> failwith "static should have been eliminated already"
| Constant _ -> ()
| Identifier i ->
if not (check_resolved_to_ifdef i)
then error (Printf.sprintf "Identifier %s is not a compile-time macro but is used in a #if" i.v.name) e.range
| App op args ->
begin
match op with
| And
| Or
| Not -> List.iter (collect_ifdef_guards env) args
| _ -> error "Only boolean expressions over identifiers are supported in #if guards" e.range
end
let rec resolve_expr' (env:qenv) (e:expr') r : ML expr' =
match e with
| Constant _ -> e
| Identifier i -> Identifier (resolve_ident env i)
| This -> e
| Static e' ->
let e' = resolve_expr env e' in
collect_ifdef_guards env e';//mark any variables as top-level IfDef symbols
e'.v
| App op args ->
let args = List.map (resolve_expr env) args in
App op args
and resolve_expr (env:qenv) (e:expr) : ML expr = { e with v = resolve_expr' env e.v e.range }
let resolve_typ_param (env:qenv) (p:typ_param) : ML typ_param =
match p with
| Inl e -> resolve_expr env e |> Inl
| _ -> p //Currently not going inside output expressions, should we?
let kind_of_ident (env:qenv) (i:ident)
: ML t_kind
= let _or_ (b0 b1:bool) = b0 || b1 in
if Some? (H.try_find env.output_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_out_t i.v)
then KindOutput
else if
Some? (H.try_find env.extern_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_extern_t i.v)
then KindExtern
else KindSpec
let rec resolve_typ' (env:qenv) (t:typ') : ML typ' =
match t with
| Type_app hd _ args ->
let hd = resolve_ident env hd in
//Set is_out argument to the Type_app appropriately
let k = kind_of_ident env hd in
Type_app hd k (List.map (resolve_typ_param env) args)
| Pointer t -> Pointer (resolve_typ env t)
and resolve_typ (env:qenv) (t:typ) : ML typ = { t with v = resolve_typ' env t.v }
let resolve_atomic_action (env:qenv) (ac:atomic_action) : ML atomic_action =
match ac with
| Action_return e -> Action_return (resolve_expr env e)
| Action_abort
| Action_field_pos_64
| Action_field_pos_32
| Action_field_ptr -> ac
| Action_field_ptr_after e write_to -> Action_field_ptr_after (resolve_expr env e) write_to
| Action_deref i -> Action_deref i //most certainly a type parameter
| Action_assignment lhs rhs ->
Action_assignment lhs (resolve_expr env rhs) //lhs is an action-local variable
| Action_call f args ->
Action_call (resolve_ident env f) (List.map (resolve_expr env) args)
let rec resolve_action' (env:qenv) (act:action') : ML action' =
match act with
| Atomic_action ac -> Atomic_action (resolve_atomic_action env ac)
| Action_seq hd tl ->
Action_seq (resolve_atomic_action env hd) (resolve_action env tl)
| Action_ite hd then_ else_ ->
Action_ite (resolve_expr env hd) (resolve_action env then_) (map_opt (resolve_action env) else_)
| Action_let i a k ->
Action_let i (resolve_atomic_action env a) (resolve_action (push_name env i.v.name) k)
| Action_act a ->
Action_act (resolve_action env a)
and resolve_action (env:qenv) (act:action) : ML action =
{ act with v = resolve_action' env act.v }
let resolve_param (env:qenv) (p:param) : ML (param & qenv) =
let t, i, q = p in
(resolve_typ env t, i, q),
push_name env i.v.name
let resolve_params (env:qenv) (params:list param) : ML (list param & qenv) =
List.fold_left (fun (params, env) p ->
let p, env = resolve_param env p in
params@[p], env) ([], env) params
let resolve_field_bitwidth_t (env:qenv) (fb:field_bitwidth_t) : ML field_bitwidth_t =
let resolve_bitfield_attr' (env:qenv) (b:bitfield_attr') : ML bitfield_attr' =
{ b with bitfield_type = resolve_typ env b.bitfield_type } in
let resolve_bitfield_attr (env:qenv) (b:bitfield_attr) : ML bitfield_attr =
{ b with v = resolve_bitfield_attr' env b.v } in
match fb with
| Inl _ -> fb
| Inr b -> Inr (resolve_bitfield_attr env b)
let resolve_field_array_t (env:qenv) (farr:field_array_t) : ML field_array_t =
match farr with
| FieldScalar -> farr
| FieldArrayQualified (e, aq) ->
FieldArrayQualified (resolve_expr env e, aq)
| FieldString None -> farr
| FieldString (Some e) -> FieldString (Some (resolve_expr env e))
| FieldConsumeAll -> farr
let resolve_probe_call env pc =
{
probe_fn = map_opt (resolve_ident env) pc.probe_fn;
probe_length = resolve_expr env pc.probe_length;
probe_dest = resolve_ident env pc.probe_dest;
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> sc: Ast.switch_case -> FStar.All.ML Ast.switch_case | FStar.All.ML | [
"ml"
] | [
"resolve_field",
"resolve_atomic_field",
"resolve_fields",
"resolve_switch_case"
] | [
"Desugar.qenv",
"Ast.switch_case",
"Ast.expr",
"Prims.list",
"Ast.case",
"FStar.Pervasives.Native.Mktuple2",
"FStar.List.map",
"Desugar.resolve_expr",
"Ast.with_meta_t",
"Ast.field'",
"Ast.Case",
"FStar.Pervasives.Native.fst",
"Ast.field",
"FStar.Pervasives.Native.tuple2",
"Desugar.resolve_field",
"Ast.DefaultCase"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec resolve_switch_case (env: qenv) (sc: switch_case) : ML switch_case =
| let resolve_case (env: qenv) (c: case) : ML case =
match c with
| Case e f -> Case (resolve_expr env e) (fst (resolve_field env f))
| DefaultCase f -> DefaultCase (fst (resolve_field env f))
in
let e, l = sc in
resolve_expr env e, List.map (resolve_case env) l | false |
Desugar.fst | Desugar.resolve_out_fields | val resolve_out_fields (env: qenv) (flds: list out_field) : ML (list out_field) | val resolve_out_fields (env: qenv) (flds: list out_field) : ML (list out_field) | let rec resolve_out_field (env:qenv) (fld:out_field) : ML out_field =
match fld with
| Out_field_named i t n -> Out_field_named i (resolve_typ env t) n
| Out_field_anon l u -> Out_field_anon (resolve_out_fields env l) u
and resolve_out_fields (env:qenv) (flds:list out_field) : ML (list out_field) =
List.map (resolve_out_field env) flds | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 39,
"end_line": 398,
"start_col": 0,
"start_line": 392
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names }
let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ]
let resolve_ident (env:qenv) (i:ident) : ML ident =
let resolve_to_current_module i =
{ i with v = { i.v with modul_name = Some env.mname } }
in
let maybe_resolve_as_ifdef i
: ML ident
= match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts //it's a primitive constant, e.g. UINT8, leave as is
then i
else if List.mem i.v.name env.local_names //it's a local name (e.g. a parameter name)
then (if Some? i.v.modul_name //must have module name set to None
then error (Printf.sprintf
"Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i) //return the local name as is
else (match i.v.modul_name with //it's a top-level name
| None -> maybe_resolve_as_ifdef i
| Some m -> //if already qualified, check if it is an abbreviation
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } }))
let rec collect_ifdef_guards (env:qenv) (e:expr)
: ML unit
= let check_resolved_to_ifdef i =
match env.global_env.ge_cfg with
| None -> false
| Some (cfg, cfg_module_name) ->
List.mem i.v.name cfg.compile_time_flags.flags
&& i.v.modul_name = Some cfg_module_name
in
match e.v with
| This -> error "'this' is not allowed in the guard of an #if" e.range
| Static _ -> failwith "static should have been eliminated already"
| Constant _ -> ()
| Identifier i ->
if not (check_resolved_to_ifdef i)
then error (Printf.sprintf "Identifier %s is not a compile-time macro but is used in a #if" i.v.name) e.range
| App op args ->
begin
match op with
| And
| Or
| Not -> List.iter (collect_ifdef_guards env) args
| _ -> error "Only boolean expressions over identifiers are supported in #if guards" e.range
end
let rec resolve_expr' (env:qenv) (e:expr') r : ML expr' =
match e with
| Constant _ -> e
| Identifier i -> Identifier (resolve_ident env i)
| This -> e
| Static e' ->
let e' = resolve_expr env e' in
collect_ifdef_guards env e';//mark any variables as top-level IfDef symbols
e'.v
| App op args ->
let args = List.map (resolve_expr env) args in
App op args
and resolve_expr (env:qenv) (e:expr) : ML expr = { e with v = resolve_expr' env e.v e.range }
let resolve_typ_param (env:qenv) (p:typ_param) : ML typ_param =
match p with
| Inl e -> resolve_expr env e |> Inl
| _ -> p //Currently not going inside output expressions, should we?
let kind_of_ident (env:qenv) (i:ident)
: ML t_kind
= let _or_ (b0 b1:bool) = b0 || b1 in
if Some? (H.try_find env.output_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_out_t i.v)
then KindOutput
else if
Some? (H.try_find env.extern_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_extern_t i.v)
then KindExtern
else KindSpec
let rec resolve_typ' (env:qenv) (t:typ') : ML typ' =
match t with
| Type_app hd _ args ->
let hd = resolve_ident env hd in
//Set is_out argument to the Type_app appropriately
let k = kind_of_ident env hd in
Type_app hd k (List.map (resolve_typ_param env) args)
| Pointer t -> Pointer (resolve_typ env t)
and resolve_typ (env:qenv) (t:typ) : ML typ = { t with v = resolve_typ' env t.v }
let resolve_atomic_action (env:qenv) (ac:atomic_action) : ML atomic_action =
match ac with
| Action_return e -> Action_return (resolve_expr env e)
| Action_abort
| Action_field_pos_64
| Action_field_pos_32
| Action_field_ptr -> ac
| Action_field_ptr_after e write_to -> Action_field_ptr_after (resolve_expr env e) write_to
| Action_deref i -> Action_deref i //most certainly a type parameter
| Action_assignment lhs rhs ->
Action_assignment lhs (resolve_expr env rhs) //lhs is an action-local variable
| Action_call f args ->
Action_call (resolve_ident env f) (List.map (resolve_expr env) args)
let rec resolve_action' (env:qenv) (act:action') : ML action' =
match act with
| Atomic_action ac -> Atomic_action (resolve_atomic_action env ac)
| Action_seq hd tl ->
Action_seq (resolve_atomic_action env hd) (resolve_action env tl)
| Action_ite hd then_ else_ ->
Action_ite (resolve_expr env hd) (resolve_action env then_) (map_opt (resolve_action env) else_)
| Action_let i a k ->
Action_let i (resolve_atomic_action env a) (resolve_action (push_name env i.v.name) k)
| Action_act a ->
Action_act (resolve_action env a)
and resolve_action (env:qenv) (act:action) : ML action =
{ act with v = resolve_action' env act.v }
let resolve_param (env:qenv) (p:param) : ML (param & qenv) =
let t, i, q = p in
(resolve_typ env t, i, q),
push_name env i.v.name
let resolve_params (env:qenv) (params:list param) : ML (list param & qenv) =
List.fold_left (fun (params, env) p ->
let p, env = resolve_param env p in
params@[p], env) ([], env) params
let resolve_field_bitwidth_t (env:qenv) (fb:field_bitwidth_t) : ML field_bitwidth_t =
let resolve_bitfield_attr' (env:qenv) (b:bitfield_attr') : ML bitfield_attr' =
{ b with bitfield_type = resolve_typ env b.bitfield_type } in
let resolve_bitfield_attr (env:qenv) (b:bitfield_attr) : ML bitfield_attr =
{ b with v = resolve_bitfield_attr' env b.v } in
match fb with
| Inl _ -> fb
| Inr b -> Inr (resolve_bitfield_attr env b)
let resolve_field_array_t (env:qenv) (farr:field_array_t) : ML field_array_t =
match farr with
| FieldScalar -> farr
| FieldArrayQualified (e, aq) ->
FieldArrayQualified (resolve_expr env e, aq)
| FieldString None -> farr
| FieldString (Some e) -> FieldString (Some (resolve_expr env e))
| FieldConsumeAll -> farr
let resolve_probe_call env pc =
{
probe_fn = map_opt (resolve_ident env) pc.probe_fn;
probe_length = resolve_expr env pc.probe_length;
probe_dest = resolve_ident env pc.probe_dest;
}
let rec resolve_field (env:qenv) (ff:field) : ML (field & qenv) =
match ff.v with
| AtomicField f -> let f, e = resolve_atomic_field env f in {ff with v = AtomicField f}, e
| RecordField f i -> let fs, _ = resolve_fields env f in {ff with v = RecordField fs i}, env //record fields are not in scope outside the record
| SwitchCaseField f i -> let f = resolve_switch_case env f in {ff with v = SwitchCaseField f i}, env
and resolve_atomic_field (env:qenv) (f:atomic_field) : ML (atomic_field & qenv) =
let resolve_atomic_field' (env:qenv) (sf:atomic_field') : ML atomic_field' =
let is_non_scalar = not (FieldScalar? sf.field_array_opt) in
if is_non_scalar && (Some? sf.field_constraint)
then error (Printf.sprintf "Non-scalar field '%s' cannot be refined with constraints" sf.field_ident.v.name) f.range
else if is_non_scalar && (Some? sf.field_bitwidth)
then error (Printf.sprintf "Non-scalar field '%s' cannot have a bit width" sf.field_ident.v.name) f.range
else (
{ sf with
field_type = resolve_typ env sf.field_type;
field_array_opt = resolve_field_array_t env sf.field_array_opt;
field_constraint = map_opt (resolve_expr env) sf.field_constraint;
field_bitwidth = map_opt (resolve_field_bitwidth_t env) sf.field_bitwidth;
field_action = map_opt (fun (a, b) -> resolve_action env a, b) sf.field_action;
field_probe = map_opt (resolve_probe_call env) sf.field_probe }
)
in
let env = push_name env f.v.field_ident.v.name in
{ f with v = resolve_atomic_field' env f.v }, env
and resolve_fields (env:qenv) (flds:list field) : ML (list field & qenv) =
List.fold_left (fun (flds, env) f ->
let f, env = resolve_field env f in
flds@[f], env) ([], env) flds
and resolve_switch_case (env:qenv) (sc:switch_case) : ML switch_case = //case fields do not escape their scope
let resolve_case (env:qenv) (c:case) : ML case =
match c with
| Case e f -> Case (resolve_expr env e) (fst (resolve_field env f))
| DefaultCase f -> DefaultCase (fst (resolve_field env f)) in
let e, l = sc in
resolve_expr env e, List.map (resolve_case env) l
let resolve_typedef_names (env:qenv) (td_names:typedef_names) : ML typedef_names =
{ td_names with
typedef_name = resolve_ident env td_names.typedef_name;
typedef_abbrev = resolve_ident env td_names.typedef_abbrev;
typedef_ptr_abbrev = resolve_ident env td_names.typedef_ptr_abbrev }
let resolve_enum_case (env:qenv) (ec:enum_case) : ML enum_case =
match ec with
| i, None -> resolve_ident env i, None
| _ -> error "Unexpected enum_case in resolve_enum_case" (fst ec).range | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> flds: Prims.list Ast.out_field -> FStar.All.ML (Prims.list Ast.out_field) | FStar.All.ML | [
"ml"
] | [
"resolve_out_field",
"resolve_out_fields"
] | [
"Desugar.qenv",
"Prims.list",
"Ast.out_field",
"FStar.List.map",
"Desugar.resolve_out_field"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec resolve_out_fields (env: qenv) (flds: list out_field) : ML (list out_field) =
| List.map (resolve_out_field env) flds | false |
Desugar.fst | Desugar.resolve_decl' | val resolve_decl' (env: qenv) (d: decl') : ML decl' | val resolve_decl' (env: qenv) (d: decl') : ML decl' | let resolve_decl' (env:qenv) (d:decl') : ML decl' =
match d with
| ModuleAbbrev i m -> push_module_abbrev env i.v.name m.v.name; d
| Define i topt c ->
Define (resolve_ident env i) (map_opt (resolve_typ env) topt) c
| TypeAbbrev t i ->
TypeAbbrev (resolve_typ env t) (resolve_ident env i)
| Enum t i ecs ->
Enum (resolve_typ env t) (resolve_ident env i) (List.map (resolve_enum_case env) ecs)
| Record td_names params where flds ->
let td_names = resolve_typedef_names env td_names in
let params, env = resolve_params env params in
let where = map_opt (resolve_expr env) where in
let flds, _ = resolve_fields env flds in
Record td_names params where flds
| CaseType td_names params sc ->
let td_names = resolve_typedef_names env td_names in
let params, env = resolve_params env params in
let sc = resolve_switch_case env sc in
CaseType td_names params sc
| OutputType out_t ->
let out_t = resolve_out_type env out_t in
push_output_type env out_t;
OutputType out_t
| ExternType td_names ->
let td_names = resolve_typedef_names env td_names in
push_extern_type env td_names;
ExternType td_names
| ExternFn id ret params ->
let id = resolve_ident env id in
let ret = resolve_typ env ret in
let params, _ = resolve_params env params in
ExternFn id ret params
| ExternProbe id ->
let id = resolve_ident env id in
ExternProbe id | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 18,
"end_line": 440,
"start_col": 0,
"start_line": 405
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names }
let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ]
let resolve_ident (env:qenv) (i:ident) : ML ident =
let resolve_to_current_module i =
{ i with v = { i.v with modul_name = Some env.mname } }
in
let maybe_resolve_as_ifdef i
: ML ident
= match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts //it's a primitive constant, e.g. UINT8, leave as is
then i
else if List.mem i.v.name env.local_names //it's a local name (e.g. a parameter name)
then (if Some? i.v.modul_name //must have module name set to None
then error (Printf.sprintf
"Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i) //return the local name as is
else (match i.v.modul_name with //it's a top-level name
| None -> maybe_resolve_as_ifdef i
| Some m -> //if already qualified, check if it is an abbreviation
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } }))
let rec collect_ifdef_guards (env:qenv) (e:expr)
: ML unit
= let check_resolved_to_ifdef i =
match env.global_env.ge_cfg with
| None -> false
| Some (cfg, cfg_module_name) ->
List.mem i.v.name cfg.compile_time_flags.flags
&& i.v.modul_name = Some cfg_module_name
in
match e.v with
| This -> error "'this' is not allowed in the guard of an #if" e.range
| Static _ -> failwith "static should have been eliminated already"
| Constant _ -> ()
| Identifier i ->
if not (check_resolved_to_ifdef i)
then error (Printf.sprintf "Identifier %s is not a compile-time macro but is used in a #if" i.v.name) e.range
| App op args ->
begin
match op with
| And
| Or
| Not -> List.iter (collect_ifdef_guards env) args
| _ -> error "Only boolean expressions over identifiers are supported in #if guards" e.range
end
let rec resolve_expr' (env:qenv) (e:expr') r : ML expr' =
match e with
| Constant _ -> e
| Identifier i -> Identifier (resolve_ident env i)
| This -> e
| Static e' ->
let e' = resolve_expr env e' in
collect_ifdef_guards env e';//mark any variables as top-level IfDef symbols
e'.v
| App op args ->
let args = List.map (resolve_expr env) args in
App op args
and resolve_expr (env:qenv) (e:expr) : ML expr = { e with v = resolve_expr' env e.v e.range }
let resolve_typ_param (env:qenv) (p:typ_param) : ML typ_param =
match p with
| Inl e -> resolve_expr env e |> Inl
| _ -> p //Currently not going inside output expressions, should we?
let kind_of_ident (env:qenv) (i:ident)
: ML t_kind
= let _or_ (b0 b1:bool) = b0 || b1 in
if Some? (H.try_find env.output_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_out_t i.v)
then KindOutput
else if
Some? (H.try_find env.extern_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_extern_t i.v)
then KindExtern
else KindSpec
let rec resolve_typ' (env:qenv) (t:typ') : ML typ' =
match t with
| Type_app hd _ args ->
let hd = resolve_ident env hd in
//Set is_out argument to the Type_app appropriately
let k = kind_of_ident env hd in
Type_app hd k (List.map (resolve_typ_param env) args)
| Pointer t -> Pointer (resolve_typ env t)
and resolve_typ (env:qenv) (t:typ) : ML typ = { t with v = resolve_typ' env t.v }
let resolve_atomic_action (env:qenv) (ac:atomic_action) : ML atomic_action =
match ac with
| Action_return e -> Action_return (resolve_expr env e)
| Action_abort
| Action_field_pos_64
| Action_field_pos_32
| Action_field_ptr -> ac
| Action_field_ptr_after e write_to -> Action_field_ptr_after (resolve_expr env e) write_to
| Action_deref i -> Action_deref i //most certainly a type parameter
| Action_assignment lhs rhs ->
Action_assignment lhs (resolve_expr env rhs) //lhs is an action-local variable
| Action_call f args ->
Action_call (resolve_ident env f) (List.map (resolve_expr env) args)
let rec resolve_action' (env:qenv) (act:action') : ML action' =
match act with
| Atomic_action ac -> Atomic_action (resolve_atomic_action env ac)
| Action_seq hd tl ->
Action_seq (resolve_atomic_action env hd) (resolve_action env tl)
| Action_ite hd then_ else_ ->
Action_ite (resolve_expr env hd) (resolve_action env then_) (map_opt (resolve_action env) else_)
| Action_let i a k ->
Action_let i (resolve_atomic_action env a) (resolve_action (push_name env i.v.name) k)
| Action_act a ->
Action_act (resolve_action env a)
and resolve_action (env:qenv) (act:action) : ML action =
{ act with v = resolve_action' env act.v }
let resolve_param (env:qenv) (p:param) : ML (param & qenv) =
let t, i, q = p in
(resolve_typ env t, i, q),
push_name env i.v.name
let resolve_params (env:qenv) (params:list param) : ML (list param & qenv) =
List.fold_left (fun (params, env) p ->
let p, env = resolve_param env p in
params@[p], env) ([], env) params
let resolve_field_bitwidth_t (env:qenv) (fb:field_bitwidth_t) : ML field_bitwidth_t =
let resolve_bitfield_attr' (env:qenv) (b:bitfield_attr') : ML bitfield_attr' =
{ b with bitfield_type = resolve_typ env b.bitfield_type } in
let resolve_bitfield_attr (env:qenv) (b:bitfield_attr) : ML bitfield_attr =
{ b with v = resolve_bitfield_attr' env b.v } in
match fb with
| Inl _ -> fb
| Inr b -> Inr (resolve_bitfield_attr env b)
let resolve_field_array_t (env:qenv) (farr:field_array_t) : ML field_array_t =
match farr with
| FieldScalar -> farr
| FieldArrayQualified (e, aq) ->
FieldArrayQualified (resolve_expr env e, aq)
| FieldString None -> farr
| FieldString (Some e) -> FieldString (Some (resolve_expr env e))
| FieldConsumeAll -> farr
let resolve_probe_call env pc =
{
probe_fn = map_opt (resolve_ident env) pc.probe_fn;
probe_length = resolve_expr env pc.probe_length;
probe_dest = resolve_ident env pc.probe_dest;
}
let rec resolve_field (env:qenv) (ff:field) : ML (field & qenv) =
match ff.v with
| AtomicField f -> let f, e = resolve_atomic_field env f in {ff with v = AtomicField f}, e
| RecordField f i -> let fs, _ = resolve_fields env f in {ff with v = RecordField fs i}, env //record fields are not in scope outside the record
| SwitchCaseField f i -> let f = resolve_switch_case env f in {ff with v = SwitchCaseField f i}, env
and resolve_atomic_field (env:qenv) (f:atomic_field) : ML (atomic_field & qenv) =
let resolve_atomic_field' (env:qenv) (sf:atomic_field') : ML atomic_field' =
let is_non_scalar = not (FieldScalar? sf.field_array_opt) in
if is_non_scalar && (Some? sf.field_constraint)
then error (Printf.sprintf "Non-scalar field '%s' cannot be refined with constraints" sf.field_ident.v.name) f.range
else if is_non_scalar && (Some? sf.field_bitwidth)
then error (Printf.sprintf "Non-scalar field '%s' cannot have a bit width" sf.field_ident.v.name) f.range
else (
{ sf with
field_type = resolve_typ env sf.field_type;
field_array_opt = resolve_field_array_t env sf.field_array_opt;
field_constraint = map_opt (resolve_expr env) sf.field_constraint;
field_bitwidth = map_opt (resolve_field_bitwidth_t env) sf.field_bitwidth;
field_action = map_opt (fun (a, b) -> resolve_action env a, b) sf.field_action;
field_probe = map_opt (resolve_probe_call env) sf.field_probe }
)
in
let env = push_name env f.v.field_ident.v.name in
{ f with v = resolve_atomic_field' env f.v }, env
and resolve_fields (env:qenv) (flds:list field) : ML (list field & qenv) =
List.fold_left (fun (flds, env) f ->
let f, env = resolve_field env f in
flds@[f], env) ([], env) flds
and resolve_switch_case (env:qenv) (sc:switch_case) : ML switch_case = //case fields do not escape their scope
let resolve_case (env:qenv) (c:case) : ML case =
match c with
| Case e f -> Case (resolve_expr env e) (fst (resolve_field env f))
| DefaultCase f -> DefaultCase (fst (resolve_field env f)) in
let e, l = sc in
resolve_expr env e, List.map (resolve_case env) l
let resolve_typedef_names (env:qenv) (td_names:typedef_names) : ML typedef_names =
{ td_names with
typedef_name = resolve_ident env td_names.typedef_name;
typedef_abbrev = resolve_ident env td_names.typedef_abbrev;
typedef_ptr_abbrev = resolve_ident env td_names.typedef_ptr_abbrev }
let resolve_enum_case (env:qenv) (ec:enum_case) : ML enum_case =
match ec with
| i, None -> resolve_ident env i, None
| _ -> error "Unexpected enum_case in resolve_enum_case" (fst ec).range
let rec resolve_out_field (env:qenv) (fld:out_field) : ML out_field =
match fld with
| Out_field_named i t n -> Out_field_named i (resolve_typ env t) n
| Out_field_anon l u -> Out_field_anon (resolve_out_fields env l) u
and resolve_out_fields (env:qenv) (flds:list out_field) : ML (list out_field) =
List.map (resolve_out_field env) flds
let resolve_out_type (env:qenv) (out_t:out_typ) : ML out_typ =
{ out_t with
out_typ_names = resolve_typedef_names env out_t.out_typ_names;
out_typ_fields = List.map (resolve_out_field env) out_t.out_typ_fields } | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> d: Ast.decl' -> FStar.All.ML Ast.decl' | FStar.All.ML | [
"ml"
] | [] | [
"Desugar.qenv",
"Ast.decl'",
"Ast.ident",
"Prims.unit",
"Desugar.push_module_abbrev",
"Ast.__proj__Mkident'__item__name",
"Ast.__proj__Mkwith_meta_t__item__v",
"Ast.ident'",
"FStar.Pervasives.Native.option",
"Ast.typ",
"Ast.constant",
"Ast.Define",
"Ast.map_opt",
"Desugar.resolve_typ",
"Desugar.resolve_ident",
"Ast.TypeAbbrev",
"Prims.list",
"Ast.enum_case",
"Ast.Enum",
"FStar.List.map",
"Desugar.resolve_enum_case",
"Ast.typedef_names",
"Ast.param",
"Ast.expr",
"Ast.record",
"Ast.field",
"Ast.Record",
"FStar.Pervasives.Native.tuple2",
"Desugar.resolve_fields",
"Desugar.resolve_expr",
"Desugar.resolve_params",
"Desugar.resolve_typedef_names",
"Ast.switch_case",
"Ast.CaseType",
"Desugar.resolve_switch_case",
"Ast.out_typ",
"Ast.OutputType",
"Desugar.push_output_type",
"Desugar.resolve_out_type",
"Ast.ExternType",
"Desugar.push_extern_type",
"Ast.ExternFn",
"Ast.ExternProbe"
] | [] | false | true | false | false | false | let resolve_decl' (env: qenv) (d: decl') : ML decl' =
| match d with
| ModuleAbbrev i m ->
push_module_abbrev env i.v.name m.v.name;
d
| Define i topt c -> Define (resolve_ident env i) (map_opt (resolve_typ env) topt) c
| TypeAbbrev t i -> TypeAbbrev (resolve_typ env t) (resolve_ident env i)
| Enum t i ecs ->
Enum (resolve_typ env t) (resolve_ident env i) (List.map (resolve_enum_case env) ecs)
| Record td_names params where flds ->
let td_names = resolve_typedef_names env td_names in
let params, env = resolve_params env params in
let where = map_opt (resolve_expr env) where in
let flds, _ = resolve_fields env flds in
Record td_names params where flds
| CaseType td_names params sc ->
let td_names = resolve_typedef_names env td_names in
let params, env = resolve_params env params in
let sc = resolve_switch_case env sc in
CaseType td_names params sc
| OutputType out_t ->
let out_t = resolve_out_type env out_t in
push_output_type env out_t;
OutputType out_t
| ExternType td_names ->
let td_names = resolve_typedef_names env td_names in
push_extern_type env td_names;
ExternType td_names
| ExternFn id ret params ->
let id = resolve_ident env id in
let ret = resolve_typ env ret in
let params, _ = resolve_params env params in
ExternFn id ret params
| ExternProbe id ->
let id = resolve_ident env id in
ExternProbe id | false |
Desugar.fst | Desugar.resolve_field | val resolve_field (env: qenv) (ff: field) : ML (field & qenv) | val resolve_field (env: qenv) (ff: field) : ML (field & qenv) | let rec resolve_field (env:qenv) (ff:field) : ML (field & qenv) =
match ff.v with
| AtomicField f -> let f, e = resolve_atomic_field env f in {ff with v = AtomicField f}, e
| RecordField f i -> let fs, _ = resolve_fields env f in {ff with v = RecordField fs i}, env //record fields are not in scope outside the record
| SwitchCaseField f i -> let f = resolve_switch_case env f in {ff with v = SwitchCaseField f i}, env
and resolve_atomic_field (env:qenv) (f:atomic_field) : ML (atomic_field & qenv) =
let resolve_atomic_field' (env:qenv) (sf:atomic_field') : ML atomic_field' =
let is_non_scalar = not (FieldScalar? sf.field_array_opt) in
if is_non_scalar && (Some? sf.field_constraint)
then error (Printf.sprintf "Non-scalar field '%s' cannot be refined with constraints" sf.field_ident.v.name) f.range
else if is_non_scalar && (Some? sf.field_bitwidth)
then error (Printf.sprintf "Non-scalar field '%s' cannot have a bit width" sf.field_ident.v.name) f.range
else (
{ sf with
field_type = resolve_typ env sf.field_type;
field_array_opt = resolve_field_array_t env sf.field_array_opt;
field_constraint = map_opt (resolve_expr env) sf.field_constraint;
field_bitwidth = map_opt (resolve_field_bitwidth_t env) sf.field_bitwidth;
field_action = map_opt (fun (a, b) -> resolve_action env a, b) sf.field_action;
field_probe = map_opt (resolve_probe_call env) sf.field_probe }
)
in
let env = push_name env f.v.field_ident.v.name in
{ f with v = resolve_atomic_field' env f.v }, env
and resolve_fields (env:qenv) (flds:list field) : ML (list field & qenv) =
List.fold_left (fun (flds, env) f ->
let f, env = resolve_field env f in
flds@[f], env) ([], env) flds
and resolve_switch_case (env:qenv) (sc:switch_case) : ML switch_case = //case fields do not escape their scope
let resolve_case (env:qenv) (c:case) : ML case =
match c with
| Case e f -> Case (resolve_expr env e) (fst (resolve_field env f))
| DefaultCase f -> DefaultCase (fst (resolve_field env f)) in
let e, l = sc in
resolve_expr env e, List.map (resolve_case env) l | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 51,
"end_line": 379,
"start_col": 0,
"start_line": 341
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names }
let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ]
let resolve_ident (env:qenv) (i:ident) : ML ident =
let resolve_to_current_module i =
{ i with v = { i.v with modul_name = Some env.mname } }
in
let maybe_resolve_as_ifdef i
: ML ident
= match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts //it's a primitive constant, e.g. UINT8, leave as is
then i
else if List.mem i.v.name env.local_names //it's a local name (e.g. a parameter name)
then (if Some? i.v.modul_name //must have module name set to None
then error (Printf.sprintf
"Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i) //return the local name as is
else (match i.v.modul_name with //it's a top-level name
| None -> maybe_resolve_as_ifdef i
| Some m -> //if already qualified, check if it is an abbreviation
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } }))
let rec collect_ifdef_guards (env:qenv) (e:expr)
: ML unit
= let check_resolved_to_ifdef i =
match env.global_env.ge_cfg with
| None -> false
| Some (cfg, cfg_module_name) ->
List.mem i.v.name cfg.compile_time_flags.flags
&& i.v.modul_name = Some cfg_module_name
in
match e.v with
| This -> error "'this' is not allowed in the guard of an #if" e.range
| Static _ -> failwith "static should have been eliminated already"
| Constant _ -> ()
| Identifier i ->
if not (check_resolved_to_ifdef i)
then error (Printf.sprintf "Identifier %s is not a compile-time macro but is used in a #if" i.v.name) e.range
| App op args ->
begin
match op with
| And
| Or
| Not -> List.iter (collect_ifdef_guards env) args
| _ -> error "Only boolean expressions over identifiers are supported in #if guards" e.range
end
let rec resolve_expr' (env:qenv) (e:expr') r : ML expr' =
match e with
| Constant _ -> e
| Identifier i -> Identifier (resolve_ident env i)
| This -> e
| Static e' ->
let e' = resolve_expr env e' in
collect_ifdef_guards env e';//mark any variables as top-level IfDef symbols
e'.v
| App op args ->
let args = List.map (resolve_expr env) args in
App op args
and resolve_expr (env:qenv) (e:expr) : ML expr = { e with v = resolve_expr' env e.v e.range }
let resolve_typ_param (env:qenv) (p:typ_param) : ML typ_param =
match p with
| Inl e -> resolve_expr env e |> Inl
| _ -> p //Currently not going inside output expressions, should we?
let kind_of_ident (env:qenv) (i:ident)
: ML t_kind
= let _or_ (b0 b1:bool) = b0 || b1 in
if Some? (H.try_find env.output_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_out_t i.v)
then KindOutput
else if
Some? (H.try_find env.extern_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_extern_t i.v)
then KindExtern
else KindSpec
let rec resolve_typ' (env:qenv) (t:typ') : ML typ' =
match t with
| Type_app hd _ args ->
let hd = resolve_ident env hd in
//Set is_out argument to the Type_app appropriately
let k = kind_of_ident env hd in
Type_app hd k (List.map (resolve_typ_param env) args)
| Pointer t -> Pointer (resolve_typ env t)
and resolve_typ (env:qenv) (t:typ) : ML typ = { t with v = resolve_typ' env t.v }
let resolve_atomic_action (env:qenv) (ac:atomic_action) : ML atomic_action =
match ac with
| Action_return e -> Action_return (resolve_expr env e)
| Action_abort
| Action_field_pos_64
| Action_field_pos_32
| Action_field_ptr -> ac
| Action_field_ptr_after e write_to -> Action_field_ptr_after (resolve_expr env e) write_to
| Action_deref i -> Action_deref i //most certainly a type parameter
| Action_assignment lhs rhs ->
Action_assignment lhs (resolve_expr env rhs) //lhs is an action-local variable
| Action_call f args ->
Action_call (resolve_ident env f) (List.map (resolve_expr env) args)
let rec resolve_action' (env:qenv) (act:action') : ML action' =
match act with
| Atomic_action ac -> Atomic_action (resolve_atomic_action env ac)
| Action_seq hd tl ->
Action_seq (resolve_atomic_action env hd) (resolve_action env tl)
| Action_ite hd then_ else_ ->
Action_ite (resolve_expr env hd) (resolve_action env then_) (map_opt (resolve_action env) else_)
| Action_let i a k ->
Action_let i (resolve_atomic_action env a) (resolve_action (push_name env i.v.name) k)
| Action_act a ->
Action_act (resolve_action env a)
and resolve_action (env:qenv) (act:action) : ML action =
{ act with v = resolve_action' env act.v }
let resolve_param (env:qenv) (p:param) : ML (param & qenv) =
let t, i, q = p in
(resolve_typ env t, i, q),
push_name env i.v.name
let resolve_params (env:qenv) (params:list param) : ML (list param & qenv) =
List.fold_left (fun (params, env) p ->
let p, env = resolve_param env p in
params@[p], env) ([], env) params
let resolve_field_bitwidth_t (env:qenv) (fb:field_bitwidth_t) : ML field_bitwidth_t =
let resolve_bitfield_attr' (env:qenv) (b:bitfield_attr') : ML bitfield_attr' =
{ b with bitfield_type = resolve_typ env b.bitfield_type } in
let resolve_bitfield_attr (env:qenv) (b:bitfield_attr) : ML bitfield_attr =
{ b with v = resolve_bitfield_attr' env b.v } in
match fb with
| Inl _ -> fb
| Inr b -> Inr (resolve_bitfield_attr env b)
let resolve_field_array_t (env:qenv) (farr:field_array_t) : ML field_array_t =
match farr with
| FieldScalar -> farr
| FieldArrayQualified (e, aq) ->
FieldArrayQualified (resolve_expr env e, aq)
| FieldString None -> farr
| FieldString (Some e) -> FieldString (Some (resolve_expr env e))
| FieldConsumeAll -> farr
let resolve_probe_call env pc =
{
probe_fn = map_opt (resolve_ident env) pc.probe_fn;
probe_length = resolve_expr env pc.probe_length;
probe_dest = resolve_ident env pc.probe_dest;
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | env: Desugar.qenv -> ff: Ast.field -> FStar.All.ML (Ast.field * Desugar.qenv) | FStar.All.ML | [
"ml"
] | [
"resolve_field",
"resolve_atomic_field",
"resolve_fields",
"resolve_switch_case"
] | [
"Desugar.qenv",
"Ast.field",
"Ast.__proj__Mkwith_meta_t__item__v",
"Ast.field'",
"Ast.with_meta_t",
"Ast.atomic_field'",
"Ast.atomic_field",
"FStar.Pervasives.Native.Mktuple2",
"Ast.Mkwith_meta_t",
"Ast.AtomicField",
"Ast.__proj__Mkwith_meta_t__item__range",
"Ast.__proj__Mkwith_meta_t__item__comments",
"FStar.Pervasives.Native.tuple2",
"Desugar.resolve_atomic_field",
"Prims.list",
"Ast.ident",
"Ast.RecordField",
"Desugar.resolve_fields",
"Ast.expr",
"Ast.case",
"Ast.SwitchCaseField",
"Ast.switch_case",
"Desugar.resolve_switch_case"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec resolve_field (env: qenv) (ff: field) : ML (field & qenv) =
| match ff.v with
| AtomicField f ->
let f, e = resolve_atomic_field env f in
{ ff with v = AtomicField f }, e
| RecordField f i ->
let fs, _ = resolve_fields env f in
{ ff with v = RecordField fs i }, env
| SwitchCaseField f i ->
let f = resolve_switch_case env f in
{ ff with v = SwitchCaseField f i }, env | false |
Desugar.fst | Desugar.desugar | val desugar (genv: GlobalEnv.global_env) (mname: string) (p: prog) : ML prog | val desugar (genv: GlobalEnv.global_env) (mname: string) (p: prog) : ML prog | let desugar (genv:GlobalEnv.global_env) (mname:string) (p:prog) : ML prog =
let decls, refinement = p in
let decls = List.collect desugar_one_enum decls in
let env = {
mname=mname;
module_abbrevs=H.create 10;
output_types=H.create 10;
extern_types=H.create 10;
local_names=[];
global_env=genv
} in
H.insert env.extern_types (Ast.to_ident' "void") ();
let decls = List.map (resolve_decl env) decls in
decls,
(match refinement with
| None -> None
| Some tr ->
Some ({ tr with
type_map =
tr.type_map
|> List.map (fun (i, jopt) -> match jopt with
| None -> i, Some (resolve_ident env i)
| Some j -> i, Some (resolve_ident env j))})) | {
"file_name": "src/3d/Desugar.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 86,
"end_line": 466,
"start_col": 0,
"start_line": 444
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Desugar
open FStar.List.Tot
open FStar.Mul
open Ast
open FStar.All
module H = Hashtable
(* This module implements a pass over the source AST,
implementing various simple desugarings
* Desugar enums with newly defined idents and explicit constant
assignments to enums where all the tags are previously defined
constants.
* Resolve module-qualified names, including the use of module
abbreviations
* Set the kind (Spec/Output/Extern) in the type nodes
* Finds variables in Static expressions and hoists them as assumptions
and removes the Static
*)
let check_desugared_enum_cases (cases:list enum_case) : ML (list ident) =
List.map
(function
| (i, None) -> i
| (i, _) -> failwith "Enum should already have been desugared")
cases
let desugar_enum_cases (ityp:integer_type) (cases:list enum_case) (export:bool)
: ML (list enum_case & list decl) =
let find_definition (i:ident) (d:decl) =
match d.d_decl.v with
| Define j _ (Int _ _) ->
i.v = j.v
| _ ->
false
in
let _, cases_rev, ds_rev =
List.fold_left
(fun (next, cases_rev, ds_rev) (i, jopt) ->
let next =
match jopt with
| Some (Inl j) -> j
| Some (Inr j) ->
begin
match List.Tot.find (find_definition j) ds_rev with
| Some ({d_decl={v=Define _ _ (Int _ k)}}) -> k
| _ -> error (Printf.sprintf "Enum identifier %s not found" (print_ident j)) j.range
end
| None -> next
in
let case = (i, None) in
let d = mk_decl
(Define i None (Int ityp next))
i.range
["Enum constant"]
export
in
(next + 1,
case :: cases_rev,
d :: ds_rev))
(0, [], [])
cases
in
List.rev cases_rev,
List.rev ds_rev
let desugar_one_enum (d:decl) : ML (list decl) =
match d.d_decl.v with
| Enum t i cases ->
if List.for_all (fun (_, jopt) -> None? jopt) cases
then [d] //no enum value assignments; no desugaring to do
else //if we have any assignments at all, then we treat all the
//tags as fresh constants and assign them values in sequence
//with respect to the assigned values of preceding tags
let cases, ds = desugar_enum_cases (typ_as_integer_type t) cases d.d_exported in
let enum = decl_with_v d (Enum t i cases) in
ds@[enum]
| _ -> [d]
(* This code is currently not used
It desugars an Enum to a record with a single refined field *)
// let eliminate_enum (d:decl) : ML decl =
// match d.v with
// | Enum t i cases ->
// let names = {
// typedef_name = { i with v = { i.v with name=Ast.reserved_prefix ^ Ast.reserved_prefix ^ i.v.name }};
// typedef_abbrev = i;
// typedef_ptr_abbrev = { i with v = {i.v with
// name = Ast.reserved_prefix ^ Ast.reserved_prefix ^ "P" ^ i.v.name }};
// typedef_attributes = [];
// } in
// let params = [] in
// let where = None in
// let field_ident = with_dummy_range (to_ident' (Ast.reserved_prefix ^ "enum_field")) in
// let field_ident_expr = with_dummy_range (Identifier field_ident) in
// let field_constraint =
// List.fold_right
// (fun (case, _) out ->
// let eq = with_range (App Eq [field_ident_expr; with_range (Identifier case) case.range]) case.range in
// with_dummy_range (App Or [eq; out]))
// cases
// (with_dummy_range (Constant (Bool false)))
// in
// let field = {
// field_dependence = false;
// field_ident = field_ident;
// field_type = t;
// field_array_opt = FieldScalar;
// field_constraint = Some field_constraint;
// field_number = None;
// field_bitwidth = None;
// field_action = None
// } in
// let d' = Record names params where [with_dummy_range field] in
// {d with v = d'}
// | _ -> d
(*
* output_types and extern_types tables to set the kind in the Typ_app nodes
*)
noeq
type qenv = {
mname : string;
module_abbrevs : H.t string string;
output_types : H.t ident' unit;
extern_types : H.t ident' unit;
local_names : list string;
global_env: GlobalEnv.global_env;
}
let push_module_abbrev (env:qenv) (i m:string) : ML unit =
H.insert env.module_abbrevs i m
let push_output_type (env:qenv) (out_t:out_typ) : ML unit =
H.insert env.output_types out_t.out_typ_names.typedef_name.v ();
H.insert env.output_types out_t.out_typ_names.typedef_abbrev.v ()
let push_extern_type (env:qenv) (td:typedef_names) : ML unit =
H.insert env.extern_types td.typedef_name.v ();
H.insert env.extern_types td.typedef_abbrev.v ()
let push_name (env:qenv) (name:string) : qenv =
{ env with local_names = name::env.local_names }
let prim_consts = [
"unit"; "Bool"; "UINT8"; "UINT16"; "UINT32"; "UINT64";
"UINT8BE"; "UINT16BE"; "UINT32BE"; "UINT64BE";
"field_id"; "PUINT8"; "EVERPARSE_COPY_BUFFER_T";
"all_bytes"; "all_zeros";
"is_range_okay";
"void" ]
let resolve_ident (env:qenv) (i:ident) : ML ident =
let resolve_to_current_module i =
{ i with v = { i.v with modul_name = Some env.mname } }
in
let maybe_resolve_as_ifdef i
: ML ident
= match env.global_env.ge_cfg with
| None -> resolve_to_current_module i
| Some (cfg, cfg_module_name) ->
if List.mem i.v.name cfg.compile_time_flags.flags
then { i with v = { i.v with modul_name = Some cfg_module_name } }
else resolve_to_current_module i
in
if List.mem i.v.name prim_consts //it's a primitive constant, e.g. UINT8, leave as is
then i
else if List.mem i.v.name env.local_names //it's a local name (e.g. a parameter name)
then (if Some? i.v.modul_name //must have module name set to None
then error (Printf.sprintf
"Ident %s is a local name but has a qualifying modul %s"
i.v.name
(Some?.v i.v.modul_name))
i.range
else i) //return the local name as is
else (match i.v.modul_name with //it's a top-level name
| None -> maybe_resolve_as_ifdef i
| Some m -> //if already qualified, check if it is an abbreviation
(match H.try_find env.module_abbrevs m with
| None -> i
| Some m -> { i with v = { i.v with modul_name = Some m } }))
let rec collect_ifdef_guards (env:qenv) (e:expr)
: ML unit
= let check_resolved_to_ifdef i =
match env.global_env.ge_cfg with
| None -> false
| Some (cfg, cfg_module_name) ->
List.mem i.v.name cfg.compile_time_flags.flags
&& i.v.modul_name = Some cfg_module_name
in
match e.v with
| This -> error "'this' is not allowed in the guard of an #if" e.range
| Static _ -> failwith "static should have been eliminated already"
| Constant _ -> ()
| Identifier i ->
if not (check_resolved_to_ifdef i)
then error (Printf.sprintf "Identifier %s is not a compile-time macro but is used in a #if" i.v.name) e.range
| App op args ->
begin
match op with
| And
| Or
| Not -> List.iter (collect_ifdef_guards env) args
| _ -> error "Only boolean expressions over identifiers are supported in #if guards" e.range
end
let rec resolve_expr' (env:qenv) (e:expr') r : ML expr' =
match e with
| Constant _ -> e
| Identifier i -> Identifier (resolve_ident env i)
| This -> e
| Static e' ->
let e' = resolve_expr env e' in
collect_ifdef_guards env e';//mark any variables as top-level IfDef symbols
e'.v
| App op args ->
let args = List.map (resolve_expr env) args in
App op args
and resolve_expr (env:qenv) (e:expr) : ML expr = { e with v = resolve_expr' env e.v e.range }
let resolve_typ_param (env:qenv) (p:typ_param) : ML typ_param =
match p with
| Inl e -> resolve_expr env e |> Inl
| _ -> p //Currently not going inside output expressions, should we?
let kind_of_ident (env:qenv) (i:ident)
: ML t_kind
= let _or_ (b0 b1:bool) = b0 || b1 in
if Some? (H.try_find env.output_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_out_t i.v)
then KindOutput
else if
Some? (H.try_find env.extern_types i.v) `_or_`
Some? (H.try_find env.global_env.ge_extern_t i.v)
then KindExtern
else KindSpec
let rec resolve_typ' (env:qenv) (t:typ') : ML typ' =
match t with
| Type_app hd _ args ->
let hd = resolve_ident env hd in
//Set is_out argument to the Type_app appropriately
let k = kind_of_ident env hd in
Type_app hd k (List.map (resolve_typ_param env) args)
| Pointer t -> Pointer (resolve_typ env t)
and resolve_typ (env:qenv) (t:typ) : ML typ = { t with v = resolve_typ' env t.v }
let resolve_atomic_action (env:qenv) (ac:atomic_action) : ML atomic_action =
match ac with
| Action_return e -> Action_return (resolve_expr env e)
| Action_abort
| Action_field_pos_64
| Action_field_pos_32
| Action_field_ptr -> ac
| Action_field_ptr_after e write_to -> Action_field_ptr_after (resolve_expr env e) write_to
| Action_deref i -> Action_deref i //most certainly a type parameter
| Action_assignment lhs rhs ->
Action_assignment lhs (resolve_expr env rhs) //lhs is an action-local variable
| Action_call f args ->
Action_call (resolve_ident env f) (List.map (resolve_expr env) args)
let rec resolve_action' (env:qenv) (act:action') : ML action' =
match act with
| Atomic_action ac -> Atomic_action (resolve_atomic_action env ac)
| Action_seq hd tl ->
Action_seq (resolve_atomic_action env hd) (resolve_action env tl)
| Action_ite hd then_ else_ ->
Action_ite (resolve_expr env hd) (resolve_action env then_) (map_opt (resolve_action env) else_)
| Action_let i a k ->
Action_let i (resolve_atomic_action env a) (resolve_action (push_name env i.v.name) k)
| Action_act a ->
Action_act (resolve_action env a)
and resolve_action (env:qenv) (act:action) : ML action =
{ act with v = resolve_action' env act.v }
let resolve_param (env:qenv) (p:param) : ML (param & qenv) =
let t, i, q = p in
(resolve_typ env t, i, q),
push_name env i.v.name
let resolve_params (env:qenv) (params:list param) : ML (list param & qenv) =
List.fold_left (fun (params, env) p ->
let p, env = resolve_param env p in
params@[p], env) ([], env) params
let resolve_field_bitwidth_t (env:qenv) (fb:field_bitwidth_t) : ML field_bitwidth_t =
let resolve_bitfield_attr' (env:qenv) (b:bitfield_attr') : ML bitfield_attr' =
{ b with bitfield_type = resolve_typ env b.bitfield_type } in
let resolve_bitfield_attr (env:qenv) (b:bitfield_attr) : ML bitfield_attr =
{ b with v = resolve_bitfield_attr' env b.v } in
match fb with
| Inl _ -> fb
| Inr b -> Inr (resolve_bitfield_attr env b)
let resolve_field_array_t (env:qenv) (farr:field_array_t) : ML field_array_t =
match farr with
| FieldScalar -> farr
| FieldArrayQualified (e, aq) ->
FieldArrayQualified (resolve_expr env e, aq)
| FieldString None -> farr
| FieldString (Some e) -> FieldString (Some (resolve_expr env e))
| FieldConsumeAll -> farr
let resolve_probe_call env pc =
{
probe_fn = map_opt (resolve_ident env) pc.probe_fn;
probe_length = resolve_expr env pc.probe_length;
probe_dest = resolve_ident env pc.probe_dest;
}
let rec resolve_field (env:qenv) (ff:field) : ML (field & qenv) =
match ff.v with
| AtomicField f -> let f, e = resolve_atomic_field env f in {ff with v = AtomicField f}, e
| RecordField f i -> let fs, _ = resolve_fields env f in {ff with v = RecordField fs i}, env //record fields are not in scope outside the record
| SwitchCaseField f i -> let f = resolve_switch_case env f in {ff with v = SwitchCaseField f i}, env
and resolve_atomic_field (env:qenv) (f:atomic_field) : ML (atomic_field & qenv) =
let resolve_atomic_field' (env:qenv) (sf:atomic_field') : ML atomic_field' =
let is_non_scalar = not (FieldScalar? sf.field_array_opt) in
if is_non_scalar && (Some? sf.field_constraint)
then error (Printf.sprintf "Non-scalar field '%s' cannot be refined with constraints" sf.field_ident.v.name) f.range
else if is_non_scalar && (Some? sf.field_bitwidth)
then error (Printf.sprintf "Non-scalar field '%s' cannot have a bit width" sf.field_ident.v.name) f.range
else (
{ sf with
field_type = resolve_typ env sf.field_type;
field_array_opt = resolve_field_array_t env sf.field_array_opt;
field_constraint = map_opt (resolve_expr env) sf.field_constraint;
field_bitwidth = map_opt (resolve_field_bitwidth_t env) sf.field_bitwidth;
field_action = map_opt (fun (a, b) -> resolve_action env a, b) sf.field_action;
field_probe = map_opt (resolve_probe_call env) sf.field_probe }
)
in
let env = push_name env f.v.field_ident.v.name in
{ f with v = resolve_atomic_field' env f.v }, env
and resolve_fields (env:qenv) (flds:list field) : ML (list field & qenv) =
List.fold_left (fun (flds, env) f ->
let f, env = resolve_field env f in
flds@[f], env) ([], env) flds
and resolve_switch_case (env:qenv) (sc:switch_case) : ML switch_case = //case fields do not escape their scope
let resolve_case (env:qenv) (c:case) : ML case =
match c with
| Case e f -> Case (resolve_expr env e) (fst (resolve_field env f))
| DefaultCase f -> DefaultCase (fst (resolve_field env f)) in
let e, l = sc in
resolve_expr env e, List.map (resolve_case env) l
let resolve_typedef_names (env:qenv) (td_names:typedef_names) : ML typedef_names =
{ td_names with
typedef_name = resolve_ident env td_names.typedef_name;
typedef_abbrev = resolve_ident env td_names.typedef_abbrev;
typedef_ptr_abbrev = resolve_ident env td_names.typedef_ptr_abbrev }
let resolve_enum_case (env:qenv) (ec:enum_case) : ML enum_case =
match ec with
| i, None -> resolve_ident env i, None
| _ -> error "Unexpected enum_case in resolve_enum_case" (fst ec).range
let rec resolve_out_field (env:qenv) (fld:out_field) : ML out_field =
match fld with
| Out_field_named i t n -> Out_field_named i (resolve_typ env t) n
| Out_field_anon l u -> Out_field_anon (resolve_out_fields env l) u
and resolve_out_fields (env:qenv) (flds:list out_field) : ML (list out_field) =
List.map (resolve_out_field env) flds
let resolve_out_type (env:qenv) (out_t:out_typ) : ML out_typ =
{ out_t with
out_typ_names = resolve_typedef_names env out_t.out_typ_names;
out_typ_fields = List.map (resolve_out_field env) out_t.out_typ_fields }
let resolve_decl' (env:qenv) (d:decl') : ML decl' =
match d with
| ModuleAbbrev i m -> push_module_abbrev env i.v.name m.v.name; d
| Define i topt c ->
Define (resolve_ident env i) (map_opt (resolve_typ env) topt) c
| TypeAbbrev t i ->
TypeAbbrev (resolve_typ env t) (resolve_ident env i)
| Enum t i ecs ->
Enum (resolve_typ env t) (resolve_ident env i) (List.map (resolve_enum_case env) ecs)
| Record td_names params where flds ->
let td_names = resolve_typedef_names env td_names in
let params, env = resolve_params env params in
let where = map_opt (resolve_expr env) where in
let flds, _ = resolve_fields env flds in
Record td_names params where flds
| CaseType td_names params sc ->
let td_names = resolve_typedef_names env td_names in
let params, env = resolve_params env params in
let sc = resolve_switch_case env sc in
CaseType td_names params sc
| OutputType out_t ->
let out_t = resolve_out_type env out_t in
push_output_type env out_t;
OutputType out_t
| ExternType td_names ->
let td_names = resolve_typedef_names env td_names in
push_extern_type env td_names;
ExternType td_names
| ExternFn id ret params ->
let id = resolve_ident env id in
let ret = resolve_typ env ret in
let params, _ = resolve_params env params in
ExternFn id ret params
| ExternProbe id ->
let id = resolve_ident env id in
ExternProbe id
let resolve_decl (env:qenv) (d:decl) : ML decl = decl_with_v d (resolve_decl' env d.d_decl.v) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hashtable.fsti.checked",
"GlobalEnv.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.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Desugar.fst"
} | [
{
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | genv: GlobalEnv.global_env -> mname: Prims.string -> p: Ast.prog -> FStar.All.ML Ast.prog | FStar.All.ML | [
"ml"
] | [] | [
"GlobalEnv.global_env",
"Prims.string",
"Ast.prog",
"Prims.list",
"Ast.decl",
"FStar.Pervasives.Native.option",
"Ast.type_refinement",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.Some",
"Ast.Mktype_refinement",
"Ast.__proj__Mktype_refinement__item__includes",
"FStar.Pervasives.Native.tuple2",
"Ast.ident",
"FStar.List.map",
"Desugar.resolve_ident",
"Ast.__proj__Mktype_refinement__item__type_map",
"Desugar.resolve_decl",
"Prims.unit",
"Hashtable.insert",
"Ast.ident'",
"Desugar.__proj__Mkqenv__item__extern_types",
"Ast.to_ident'",
"Desugar.qenv",
"Desugar.Mkqenv",
"Prims.Nil",
"Hashtable.t",
"Hashtable.create",
"FStar.List.collect",
"Desugar.desugar_one_enum"
] | [] | false | true | false | false | false | let desugar (genv: GlobalEnv.global_env) (mname: string) (p: prog) : ML prog =
| let decls, refinement = p in
let decls = List.collect desugar_one_enum decls in
let env =
{
mname = mname;
module_abbrevs = H.create 10;
output_types = H.create 10;
extern_types = H.create 10;
local_names = [];
global_env = genv
}
in
H.insert env.extern_types (Ast.to_ident' "void") ();
let decls = List.map (resolve_decl env) decls in
decls,
(match refinement with
| None -> None
| Some tr ->
Some
({
tr with
type_map
=
tr.type_map |>
List.map (fun (i, jopt) ->
match jopt with
| None -> i, Some (resolve_ident env i)
| Some j -> i, Some (resolve_ident env j))
})) | false |
Steel.Effect.fst | Steel.Effect.par0 | val par0
(#aL: Type u#a)
(#preL: vprop)
(#postL: (aL -> vprop))
(f: repr aL false preL postL (fun _ -> True) (fun _ _ _ -> True))
(#aR: Type u#a)
(#preR: vprop)
(#postR: (aR -> vprop))
(g: repr aR false preR postR (fun _ -> True) (fun _ _ _ -> True))
: SteelT (aL & aR) (preL `star` preR) (fun y -> (postL (fst y)) `star` (postR (snd y))) | val par0
(#aL: Type u#a)
(#preL: vprop)
(#postL: (aL -> vprop))
(f: repr aL false preL postL (fun _ -> True) (fun _ _ _ -> True))
(#aR: Type u#a)
(#preR: vprop)
(#postR: (aR -> vprop))
(g: repr aR false preR postR (fun _ -> True) (fun _ _ _ -> True))
: SteelT (aL & aR) (preL `star` preR) (fun y -> (postL (fst y)) `star` (postR (snd y))) | let par0 (#aL:Type u#a) (#preL:vprop) (#postL:aL -> vprop)
(f:repr aL false preL postL (fun _ -> True) (fun _ _ _ -> True))
(#aR:Type u#a) (#preR:vprop) (#postR:aR -> vprop)
(g:repr aR false preR postR (fun _ -> True) (fun _ _ _ -> True))
: SteelT (aL & aR)
(preL `star` preR)
(fun y -> postL (fst y) `star` postR (snd y))
= Steel?.reflect (fun frame -> Sem.run #state #_ #_ #_ #_ #_ frame (Sem.Par (Sem.Act f) (Sem.Act g))) | {
"file_name": "lib/steel/Steel.Effect.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 103,
"end_line": 678,
"start_col": 0,
"start_line": 671
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Effect
module Sem = Steel.Semantics.Hoare.MST
module Mem = Steel.Memory
open Steel.Semantics.Instantiate
module FExt = FStar.FunctionalExtensionality
#set-options "--ide_id_info_off"
let _:squash (forall p q. can_be_split p q == Mem.slimp (hp_of p) (hp_of q)) = reveal_can_be_split ()
#set-options "--warn_error -330" //turn off the experimental feature warning
let rmem_depends_only_on' (pre:pre_t) (m0:hmem pre) (m1:mem{disjoint m0 m1})
: Lemma (mk_rmem pre m0 == mk_rmem pre (join m0 m1))
= Classical.forall_intro (reveal_mk_rmem pre m0);
Classical.forall_intro (reveal_mk_rmem pre (join m0 m1));
FExt.extensionality_g
(r0:vprop{can_be_split pre r0})
(fun r0 -> normal (t_of r0))
(mk_rmem pre m0)
(mk_rmem pre (join m0 m1))
let rmem_depends_only_on (pre:pre_t)
: Lemma (forall (m0:hmem pre) (m1:mem{disjoint m0 m1}).
mk_rmem pre m0 == mk_rmem pre (join m0 m1))
= Classical.forall_intro_2 (rmem_depends_only_on' pre)
let rmem_depends_only_on_post' (#a:Type) (post:post_t a)
(x:a) (m0:hmem (post x)) (m1:mem{disjoint m0 m1})
: Lemma (mk_rmem (post x) m0 == mk_rmem (post x) (join m0 m1))
= rmem_depends_only_on' (post x) m0 m1
let rmem_depends_only_on_post (#a:Type) (post:post_t a)
: Lemma (forall (x:a) (m0:hmem (post x)) (m1:mem{disjoint m0 m1}).
mk_rmem (post x) m0 == mk_rmem (post x) (join m0 m1))
= Classical.forall_intro_3 (rmem_depends_only_on_post' post)
[@@ __steel_reduce__]
let req_to_act_req (#pre:pre_t) (req:req_t pre) : Sem.l_pre #state (hp_of pre) =
rmem_depends_only_on pre;
fun m0 -> interp (hp_of pre) m0 /\ req (mk_rmem pre m0)
unfold
let to_post (#a:Type) (post:post_t a) = fun x -> (hp_of (post x))
[@@ __steel_reduce__]
let ens_to_act_ens (#pre:pre_t) (#a:Type) (#post:post_t a) (ens:ens_t pre a post)
: Sem.l_post #state #a (hp_of pre) (to_post post)
= rmem_depends_only_on pre;
rmem_depends_only_on_post post;
fun m0 x m1 ->
interp (hp_of pre) m0 /\ interp (hp_of (post x)) m1 /\ ens (mk_rmem pre m0) x (mk_rmem (post x) m1)
let reveal_focus_rmem (#r:vprop) (h:rmem r) (r0:vprop{r `can_be_split` r0}) (r':vprop{r0 `can_be_split` r'})
: Lemma (
r `can_be_split` r' /\
focus_rmem h r0 r' == h r')
= can_be_split_trans r r0 r';
FExt.feq_on_domain_g (unrestricted_focus_rmem h r0)
let focus_is_restrict_mk_rmem (fp0 fp1:vprop) (m:hmem fp0)
: Lemma
(requires fp0 `can_be_split` fp1)
(ensures focus_rmem (mk_rmem fp0 m) fp1 == mk_rmem fp1 m)
= let f0:rmem fp0 = mk_rmem fp0 m in
let f1:rmem fp1 = mk_rmem fp1 m in
let f2:rmem fp1 = focus_rmem f0 fp1 in
let aux (r:vprop{can_be_split fp1 r}) : Lemma (f1 r == f2 r)
= can_be_split_trans fp0 fp1 r;
reveal_mk_rmem fp0 m r;
reveal_mk_rmem fp1 m r;
reveal_focus_rmem f0 fp1 r
in Classical.forall_intro aux;
FExt.extensionality_g
(r0:vprop{can_be_split fp1 r0})
(fun r0 -> normal (t_of r0))
(mk_rmem fp1 m)
(focus_rmem (mk_rmem fp0 m) fp1)
let focus_focus_is_focus (fp0 fp1 fp2:vprop) (m:hmem fp0)
: Lemma
(requires fp0 `can_be_split` fp1 /\ fp1 `can_be_split` fp2)
(ensures focus_rmem (focus_rmem (mk_rmem fp0 m) fp1) fp2 == focus_rmem (mk_rmem fp0 m) fp2)
= let f0:rmem fp0 = mk_rmem fp0 m in
let f1:rmem fp1 = focus_rmem f0 fp1 in
let f20:rmem fp2 = focus_rmem f0 fp2 in
let f21:rmem fp2 = focus_rmem f1 fp2 in
let aux (r:vprop{can_be_split fp2 r}) : Lemma (f20 r == f21 r)
= reveal_mk_rmem fp0 m r;
reveal_focus_rmem f0 fp1 r;
reveal_focus_rmem f0 fp2 r;
reveal_focus_rmem f1 fp2 r
in Classical.forall_intro aux;
FExt.extensionality_g
(r0:vprop{can_be_split fp2 r0})
(fun r0 -> normal (t_of r0))
f20 f21
let focus_replace (fp0 fp1 fp2:vprop) (m:hmem fp0)
: Lemma
(requires fp0 `can_be_split` fp1 /\ fp1 `can_be_split` fp2)
(ensures focus_rmem (mk_rmem fp0 m) fp2 == focus_rmem (mk_rmem fp1 m) fp2)
= let f0:rmem fp0 = mk_rmem fp0 m in
let f1:rmem fp1 = mk_rmem fp1 m in
let f20:rmem fp2 = focus_rmem f0 fp2 in
let f21:rmem fp2 = focus_rmem f1 fp2 in
let aux (r:vprop{can_be_split fp2 r}) : Lemma (f20 r == f21 r)
= reveal_mk_rmem fp0 m r;
reveal_mk_rmem fp1 m r;
reveal_focus_rmem f0 fp2 r;
reveal_focus_rmem f1 fp2 r
in Classical.forall_intro aux;
FExt.extensionality_g
(r0:vprop{can_be_split fp2 r0})
(fun r0 -> normal (t_of r0))
f20 f21
val can_be_split_3_interp (p1 p2 q r:slprop u#1) (m:mem)
: Lemma
(requires p1 `slimp` p2 /\ interp (p1 `Mem.star` q `Mem.star` r) m)
(ensures interp (p2 `Mem.star` q `Mem.star` r) m)
let can_be_split_3_interp p1 p2 q r m =
Mem.star_associative p1 q r;
Mem.star_associative p2 q r;
slimp_star p1 p2 (q `Mem.star` r) (q `Mem.star` r)
let repr (a:Type) (_:bool) (pre:pre_t) (post:post_t a) (req:req_t pre) (ens:ens_t pre a post) =
Sem.action_t #state #a (hp_of pre) (to_post post)
((req_to_act_req req))
((ens_to_act_ens ens))
let nmst_get (#st:Sem.st) ()
: Sem.Mst (Sem.full_mem st)
(fun _ -> True)
(fun s0 s s1 -> s0 == s /\ s == s1)
= NMST.get ()
let rec lemma_frame_equalities_refl (frame:vprop) (h:rmem frame) : Lemma (frame_equalities frame h h) =
match frame with
| VUnit _ -> ()
| VStar p1 p2 ->
can_be_split_star_l p1 p2;
can_be_split_star_r p1 p2;
let h1 = focus_rmem h p1 in
let h2 = focus_rmem h p2 in
lemma_frame_equalities_refl p1 h1;
lemma_frame_equalities_refl p2 h2
let return_ a x #p = fun _ ->
let m0 = nmst_get () in
let h0 = mk_rmem (p x) (core_mem m0) in
lemma_frame_equalities_refl (p x) h0;
x
#push-options "--fuel 0 --ifuel 0"
val req_frame (frame:vprop) (snap:rmem frame) : mprop (hp_of frame)
let req_frame' (frame:vprop) (snap:rmem frame) (m:mem) : prop =
interp (hp_of frame) m /\ mk_rmem frame m == snap
let req_frame frame snap =
rmem_depends_only_on frame;
req_frame' frame snap
#push-options "--z3rlimit 50 --fuel 1 --ifuel 0"
let frame_opaque frame h0 h1 = frame_equalities frame h0 h1
unfold
let norm_opaque = norm [delta_only [`%frame_opaque]]
let lemma_frame_opaque_refl (frame:vprop) (h:rmem frame) : Lemma (frame_opaque frame h h) =
assert (frame_opaque frame h h) by (
T.norm [delta_only [`%frame_opaque]];
T.apply_lemma (`lemma_frame_equalities_refl))
val frame00 (#a:Type)
(#framed:bool)
(#pre:pre_t)
(#post:post_t a)
(#req:req_t pre)
(#ens:ens_t pre a post)
($f:repr a framed pre post req ens)
(frame:vprop)
: repr a
true
(pre `star` frame)
(fun x -> post x `star` frame)
(fun h -> req (focus_rmem h pre))
(fun h0 r h1 -> req (focus_rmem h0 pre) /\ ens (focus_rmem h0 pre) r (focus_rmem h1 (post r)) /\
frame_opaque frame (focus_rmem h0 frame) (focus_rmem h1 frame))
let frame00 #a #framed #pre #post #req #ens f frame =
fun frame' ->
let m0 = nmst_get () in
let snap:rmem frame = mk_rmem frame (core_mem m0) in
focus_is_restrict_mk_rmem (pre `star` frame) pre (core_mem m0);
assert (state.interp (((hp_of pre `state.star` hp_of frame) `state.star` frame' `state.star` state.locks_invariant m0)) m0);
let req' =
(Steel.Semantics.Hoare.MST.frame_lpre #Steel.Semantics.Instantiate.state
#(Steel.Effect.Common.hp_of pre)
(req_to_act_req #pre req)
#(Steel.Effect.Common.hp_of frame)
(req_frame frame snap)) in
assert (req' (state.core m0));
let x = Sem.run #state #_ #_ #_ #_ #_ frame' (Sem.Frame (Sem.Act f) (hp_of frame) (req_frame frame snap)) in
let m1 = nmst_get () in
can_be_split_star_r pre frame;
focus_is_restrict_mk_rmem (pre `star` frame) frame (core_mem m0);
can_be_split_star_r (post x) frame;
focus_is_restrict_mk_rmem (post x `star` frame) frame (core_mem m1);
focus_is_restrict_mk_rmem (post x `star` frame) (post x) (core_mem m1);
// We proved focus_rmem h0 frame == focus_rmem h1 frame so far
let h0:rmem (pre `star` frame) = mk_rmem (pre `star` frame) (core_mem m0) in
lemma_frame_opaque_refl frame (focus_rmem h0 frame);
x
#pop-options
let norm_repr (#a:Type) (#framed:bool)
(#pre:pre_t) (#post:post_t a) (#req:req_t pre) (#ens:ens_t pre a post)
(f:repr a framed pre post req ens) : repr a framed pre post (fun h -> norm_opaque (req h)) (fun h0 x h1 -> norm_opaque (ens h0 x h1))
= f
unfold
let bind_req_opaque (#a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f)
(#pre_g:a -> pre_t)
(#pr:a -> prop)
(req_g:(x:a -> req_t (pre_g x)))
(frame_f:vprop) (frame_g:a -> vprop)
(_:squash (can_be_split_forall_dep pr (fun x -> post_f x `star` frame_f) (fun x -> pre_g x `star` frame_g x)))
: req_t (pre_f `star` frame_f)
= fun m0 ->
req_f (focus_rmem m0 pre_f) /\
(forall (x:a) (h1:hmem (post_f x `star` frame_f)).
(ens_f (focus_rmem m0 pre_f) x (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) (post_f x)) /\
frame_opaque frame_f (focus_rmem m0 frame_f) (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) frame_f))
==> pr x /\
(can_be_split_trans (post_f x `star` frame_f) (pre_g x `star` frame_g x) (pre_g x);
(req_g x) (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) (pre_g x))))
unfold
let bind_ens_opaque (#a:Type) (#b:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f)
(#pre_g:a -> pre_t) (#post_g:a -> post_t b)
(#pr:a -> prop)
(ens_g:(x:a -> ens_t (pre_g x) b (post_g x)))
(frame_f:vprop) (frame_g:a -> vprop)
(post:post_t b)
(_:squash (can_be_split_forall_dep pr (fun x -> post_f x `star` frame_f) (fun x -> pre_g x `star` frame_g x)))
(_:squash (can_be_split_post (fun x y -> post_g x y `star` frame_g x) post))
: ens_t (pre_f `star` frame_f) b post
= fun m0 y m2 ->
req_f (focus_rmem m0 pre_f) /\
(exists (x:a) (h1:hmem (post_f x `star` frame_f)).
pr x /\
(
can_be_split_trans (post_f x `star` frame_f) (pre_g x `star` frame_g x) (pre_g x);
can_be_split_trans (post_f x `star` frame_f) (pre_g x `star` frame_g x) (frame_g x);
can_be_split_trans (post y) (post_g x y `star` frame_g x) (post_g x y);
can_be_split_trans (post y) (post_g x y `star` frame_g x) (frame_g x);
frame_opaque frame_f (focus_rmem m0 frame_f) (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) frame_f) /\
frame_opaque (frame_g x) (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) (frame_g x)) (focus_rmem m2 (frame_g x)) /\
ens_f (focus_rmem m0 pre_f) x (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) (post_f x)) /\
(ens_g x) (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) (pre_g x)) y (focus_rmem m2 (post_g x y))))
val bind_opaque (a:Type) (b:Type)
(#framed_f:eqtype_as_type bool)
(#framed_g:eqtype_as_type bool)
(#pre_f:pre_t) (#post_f:post_t a)
(#req_f:req_t pre_f) (#ens_f:ens_t pre_f a post_f)
(#pre_g:a -> pre_t) (#post_g:a -> post_t b)
(#req_g:(x:a -> req_t (pre_g x))) (#ens_g:(x:a -> ens_t (pre_g x) b (post_g x)))
(#frame_f:vprop) (#frame_g:a -> vprop)
(#post:post_t b)
(# _ : squash (maybe_emp framed_f frame_f))
(# _ : squash (maybe_emp_dep framed_g frame_g))
(#pr:a -> prop)
(#p1:squash (can_be_split_forall_dep pr
(fun x -> post_f x `star` frame_f) (fun x -> pre_g x `star` frame_g x)))
(#p2:squash (can_be_split_post (fun x y -> post_g x y `star` frame_g x) post))
(f:repr a framed_f pre_f post_f req_f ens_f)
(g:(x:a -> repr b framed_g (pre_g x) (post_g x) (req_g x) (ens_g x)))
: repr b
true
(pre_f `star` frame_f)
post
(bind_req_opaque req_f ens_f req_g frame_f frame_g p1)
(bind_ens_opaque req_f ens_f ens_g frame_f frame_g post p1 p2)
#push-options "--z3rlimit 20"
let bind_opaque a b #framed_f #framed_g #pre_f #post_f #req_f #ens_f #pre_g #post_g #req_g #ens_g #frame_f #frame_g #post #_ #_ #p #p2 f g =
fun frame ->
let m0 = nmst_get () in
let h0 = mk_rmem (pre_f `star` frame_f) (core_mem m0) in
let x = frame00 f frame_f frame in
let m1 = nmst_get () in
let h1 = mk_rmem (post_f x `star` frame_f) (core_mem m1) in
let h1' = mk_rmem (pre_g x `star` frame_g x) (core_mem m1) in
can_be_split_trans (post_f x `star` frame_f) (pre_g x `star` frame_g x) (pre_g x);
focus_is_restrict_mk_rmem
(post_f x `star` frame_f)
(pre_g x `star` frame_g x)
(core_mem m1);
focus_focus_is_focus
(post_f x `star` frame_f)
(pre_g x `star` frame_g x)
(pre_g x)
(core_mem m1);
assert (focus_rmem h1' (pre_g x) == focus_rmem h1 (pre_g x));
can_be_split_3_interp
(hp_of (post_f x `star` frame_f))
(hp_of (pre_g x `star` frame_g x))
frame (locks_invariant Set.empty m1) m1;
let y = frame00 (g x) (frame_g x) frame in
let m2 = nmst_get () in
can_be_split_trans (post_f x `star` frame_f) (pre_g x `star` frame_g x) (pre_g x);
can_be_split_trans (post_f x `star` frame_f) (pre_g x `star` frame_g x) (frame_g x);
can_be_split_trans (post y) (post_g x y `star` frame_g x) (post_g x y);
can_be_split_trans (post y) (post_g x y `star` frame_g x) (frame_g x);
let h2' = mk_rmem (post_g x y `star` frame_g x) (core_mem m2) in
let h2 = mk_rmem (post y) (core_mem m2) in
// assert (focus_rmem h1' (pre_g x) == focus_rmem h1 (pre_g x));
focus_focus_is_focus
(post_f x `star` frame_f)
(pre_g x `star` frame_g x)
(frame_g x)
(core_mem m1);
focus_is_restrict_mk_rmem
(post_g x y `star` frame_g x)
(post y)
(core_mem m2);
focus_focus_is_focus
(post_g x y `star` frame_g x)
(post y)
(frame_g x)
(core_mem m2);
focus_focus_is_focus
(post_g x y `star` frame_g x)
(post y)
(post_g x y)
(core_mem m2);
can_be_split_3_interp
(hp_of (post_g x y `star` frame_g x))
(hp_of (post y))
frame (locks_invariant Set.empty m2) m2;
y
#pop-options
let bind a b #framed_f #framed_g #pre_f #post_f #req_f #ens_f #pre_g #post_g #req_g #ens_g #frame_f #frame_g #post #_ #_ #p #p2 f g
= norm_repr (bind_opaque a b #framed_f #framed_g #pre_f #post_f #req_f #ens_f #pre_g #post_g #req_g #ens_g #frame_f #frame_g #post #_ #_ #p #p2 f g)
unfold
let subcomp_pre_opaque (#a:Type)
(#pre_f:pre_t) (#post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f)
(#pre_g:pre_t) (#post_g:post_t a) (req_g:req_t pre_g) (ens_g:ens_t pre_g a post_g)
(#frame:vprop) (#pr:prop)
(_:squash (can_be_split_dep pr pre_g (pre_f `star` frame)))
(_:squash (equiv_forall post_g (fun x -> post_f x `star` frame)))
: pure_pre
= (forall (h0:hmem pre_g). req_g (mk_rmem pre_g h0) ==> pr /\ (
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
req_f (focus_rmem (mk_rmem pre_g h0) pre_f))) /\
(forall (h0:hmem pre_g) (x:a) (h1:hmem (post_g x)). (
pr ==> (
can_be_split_trans (post_g x) (post_f x `star` frame) (post_f x);
can_be_split_trans (pre_g) (pre_f `star` frame) frame;
can_be_split_trans (post_g x) (post_f x `star` frame) frame;
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
(req_g (mk_rmem pre_g h0) /\
ens_f (focus_rmem (mk_rmem pre_g h0) pre_f) x (focus_rmem (mk_rmem (post_g x) h1) (post_f x)) /\
frame_opaque frame
(focus_rmem (mk_rmem pre_g h0) frame)
(focus_rmem (mk_rmem (post_g x) h1) frame))
==> ens_g (mk_rmem pre_g h0) x (mk_rmem (post_g x) h1))
))
val subcomp_opaque (a:Type)
(#framed_f:eqtype_as_type bool)
(#framed_g:eqtype_as_type bool)
(#[@@@ framing_implicit] pre_f:pre_t) (#[@@@ framing_implicit] post_f:post_t a)
(#[@@@ framing_implicit] req_f:req_t pre_f) (#[@@@ framing_implicit] ens_f:ens_t pre_f a post_f)
(#[@@@ framing_implicit] pre_g:pre_t) (#[@@@ framing_implicit] post_g:post_t a)
(#[@@@ framing_implicit] req_g:req_t pre_g) (#[@@@ framing_implicit] ens_g:ens_t pre_g a post_g)
(#[@@@ framing_implicit] frame:vprop)
(#[@@@ framing_implicit] pr : prop)
(#[@@@ framing_implicit] _ : squash (maybe_emp framed_f frame))
(#[@@@ framing_implicit] p1:squash (can_be_split_dep pr pre_g (pre_f `star` frame)))
(#[@@@ framing_implicit] p2:squash (equiv_forall post_g (fun x -> post_f x `star` frame)))
(f:repr a framed_f pre_f post_f req_f ens_f)
: Pure (repr a framed_g pre_g post_g req_g ens_g)
(requires subcomp_pre_opaque req_f ens_f req_g ens_g p1 p2)
(ensures fun _ -> True)
#push-options "--fuel 1 --ifuel 1 --z3rlimit 20"
let subcomp_opaque a #framed_f #framed_g #pre_f #post_f #req_f #ens_f #pre_g #post_g #req_g #ens_g #fr #_ #_ #p1 #p2 f =
fun frame ->
let m0 = nmst_get () in
let h0 = mk_rmem pre_g (core_mem m0) in
can_be_split_trans pre_g (pre_f `star` fr) pre_f;
can_be_split_trans pre_g (pre_f `star` fr) fr;
can_be_split_3_interp (hp_of pre_g) (hp_of (pre_f `star` fr)) frame (locks_invariant Set.empty m0) m0;
focus_replace pre_g (pre_f `star` fr) pre_f (core_mem m0);
let x = frame00 f fr frame in
let m1 = nmst_get () in
let h1 = mk_rmem (post_g x) (core_mem m1) in
let h0' = mk_rmem (pre_f `star` fr) (core_mem m0) in
let h1' = mk_rmem (post_f x `star` fr) (core_mem m1) in
// From frame00
assert (frame_opaque fr (focus_rmem h0' fr) (focus_rmem h1' fr));
// Replace h0'/h1' by h0/h1
focus_replace pre_g (pre_f `star` fr) fr (core_mem m0);
focus_replace (post_g x) (post_f x `star` fr) fr (core_mem m1);
assert (frame_opaque fr (focus_rmem h0 fr) (focus_rmem h1 fr));
can_be_split_trans (post_g x) (post_f x `star` fr) (post_f x);
can_be_split_trans (post_g x) (post_f x `star` fr) fr;
can_be_split_3_interp (hp_of (post_f x `star` fr)) (hp_of (post_g x)) frame (locks_invariant Set.empty m1) m1;
focus_replace (post_g x) (post_f x `star` fr) (post_f x) (core_mem m1);
x
#pop-options
let lemma_rewrite (p:Type) : Lemma (requires T.rewrite_with_tactic vc_norm p) (ensures p)
= T.unfold_rewrite_with_tactic vc_norm p
let lemma_norm_opaque (p:Type) : Lemma (requires norm_opaque p) (ensures p) = ()
(** Need to manually remove the rewrite_with_tactic marker here *)
let lemma_subcomp_pre_opaque_aux1 (#a:Type)
(#pre_f:pre_t) (#post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f)
(#pre_g:pre_t) (#post_g:post_t a) (req_g:req_t pre_g) (ens_g:ens_t pre_g a post_g)
(#frame:vprop)
(#pr:prop)
(p1:squash (can_be_split_dep pr pre_g (pre_f `star` frame)))
(p2:squash (equiv_forall post_g (fun x -> post_f x `star` frame)))
: Lemma
(requires subcomp_pre req_f ens_f req_g ens_g p1 p2)
(ensures (
(forall (h0:hmem pre_g). req_g (mk_rmem pre_g h0) ==> pr /\ (
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
req_f (focus_rmem (mk_rmem pre_g h0) pre_f))) /\
(forall (h0:hmem pre_g) (x:a) (h1:hmem (post_g x)). (
pr ==> (
can_be_split_trans (post_g x) (post_f x `star` frame) (post_f x);
can_be_split_trans (pre_g) (pre_f `star` frame) frame;
can_be_split_trans (post_g x) (post_f x `star` frame) frame;
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
(req_g (mk_rmem pre_g h0) /\
ens_f (focus_rmem (mk_rmem pre_g h0) pre_f) x (focus_rmem (mk_rmem (post_g x) h1) (post_f x)) /\
frame_equalities frame
(focus_rmem (mk_rmem pre_g h0) frame)
(focus_rmem (mk_rmem (post_g x) h1) frame))
==> ens_g (mk_rmem pre_g h0) x (mk_rmem (post_g x) h1))
))))
= lemma_rewrite (squash (
(forall (h0:hmem pre_g). req_g (mk_rmem pre_g h0) ==> pr /\ (
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
req_f (focus_rmem (mk_rmem pre_g h0) pre_f))) /\
(forall (h0:hmem pre_g) (x:a) (h1:hmem (post_g x)). (
pr ==> (
can_be_split_trans (post_g x) (post_f x `star` frame) (post_f x);
can_be_split_trans (pre_g) (pre_f `star` frame) frame;
can_be_split_trans (post_g x) (post_f x `star` frame) frame;
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
(req_g (mk_rmem pre_g h0) /\
ens_f (focus_rmem (mk_rmem pre_g h0) pre_f) x (focus_rmem (mk_rmem (post_g x) h1) (post_f x)) /\
frame_equalities frame
(focus_rmem (mk_rmem pre_g h0) frame)
(focus_rmem (mk_rmem (post_g x) h1) frame))
==> ens_g (mk_rmem pre_g h0) x (mk_rmem (post_g x) h1))
))
))
#push-options "--no_tactics"
let lemma_subcomp_pre_opaque_aux2 (#a:Type)
(#pre_f:pre_t) (#post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f)
(#pre_g:pre_t) (#post_g:post_t a) (req_g:req_t pre_g) (ens_g:ens_t pre_g a post_g)
(#frame:vprop)
(#pr:prop)
(p1:squash (can_be_split_dep pr pre_g (pre_f `star` frame)))
(p2:squash (equiv_forall post_g (fun x -> post_f x `star` frame)))
: Lemma
(requires (
(forall (h0:hmem pre_g). req_g (mk_rmem pre_g h0) ==> pr /\ (
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
req_f (focus_rmem (mk_rmem pre_g h0) pre_f))) /\
(forall (h0:hmem pre_g) (x:a) (h1:hmem (post_g x)). (
pr ==> (
can_be_split_trans (post_g x) (post_f x `star` frame) (post_f x);
can_be_split_trans (pre_g) (pre_f `star` frame) frame;
can_be_split_trans (post_g x) (post_f x `star` frame) frame;
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
(req_g (mk_rmem pre_g h0) /\
ens_f (focus_rmem (mk_rmem pre_g h0) pre_f) x (focus_rmem (mk_rmem (post_g x) h1) (post_f x)) /\
frame_equalities frame
(focus_rmem (mk_rmem pre_g h0) frame)
(focus_rmem (mk_rmem (post_g x) h1) frame))
==> ens_g (mk_rmem pre_g h0) x (mk_rmem (post_g x) h1))
))))
(ensures subcomp_pre_opaque req_f ens_f req_g ens_g p1 p2)
= lemma_norm_opaque (squash (
(forall (h0:hmem pre_g). req_g (mk_rmem pre_g h0) ==> pr /\ (
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
req_f (focus_rmem (mk_rmem pre_g h0) pre_f))) /\
(forall (h0:hmem pre_g) (x:a) (h1:hmem (post_g x)). (
pr ==> (
can_be_split_trans (post_g x) (post_f x `star` frame) (post_f x);
can_be_split_trans (pre_g) (pre_f `star` frame) frame;
can_be_split_trans (post_g x) (post_f x `star` frame) frame;
can_be_split_trans pre_g (pre_f `star` frame) pre_f;
(req_g (mk_rmem pre_g h0) /\
ens_f (focus_rmem (mk_rmem pre_g h0) pre_f) x (focus_rmem (mk_rmem (post_g x) h1) (post_f x)) /\
frame_opaque frame
(focus_rmem (mk_rmem pre_g h0) frame)
(focus_rmem (mk_rmem (post_g x) h1) frame))
==> ens_g (mk_rmem pre_g h0) x (mk_rmem (post_g x) h1))
))
))
let lemma_subcomp_pre_opaque (#a:Type)
(#pre_f:pre_t) (#post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f)
(#pre_g:pre_t) (#post_g:post_t a) (req_g:req_t pre_g) (ens_g:ens_t pre_g a post_g)
(#frame:vprop)
(#pr : prop)
(p1:squash (can_be_split_dep pr pre_g (pre_f `star` frame)))
(p2:squash (equiv_forall post_g (fun x -> post_f x `star` frame)))
: Lemma
(requires subcomp_pre req_f ens_f req_g ens_g p1 p2)
(ensures subcomp_pre_opaque req_f ens_f req_g ens_g p1 p2)
= lemma_subcomp_pre_opaque_aux1 req_f ens_f req_g ens_g p1 p2;
lemma_subcomp_pre_opaque_aux2 req_f ens_f req_g ens_g p1 p2
#pop-options
let subcomp a #framed_f #framed_g #pre_f #post_f #req_f #ens_f #pre_g #post_g #req_g #ens_g #fr #_ #pr #p1 #p2 f =
lemma_subcomp_pre_opaque req_f ens_f req_g ens_g p1 p2;
subcomp_opaque a #framed_f #framed_g #pre_f #post_f #req_f #ens_f #pre_g #post_g #req_g #ens_g #fr #pr #_ #p1 #p2 f
let bind_pure_steel_ a b #wp #pre #post #req #ens f g
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun frame ->
let x = f () in
g x frame
(* We need a bind with DIV to implement par, using reification *)
unfold
let bind_div_steel_req (#a:Type) (wp:pure_wp a)
(#pre_g:pre_t) (req_g:a -> req_t pre_g)
: req_t pre_g
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun h -> wp (fun _ -> True) /\ (forall x. (req_g x) h)
unfold
let bind_div_steel_ens (#a:Type) (#b:Type)
(wp:pure_wp a)
(#pre_g:pre_t) (#post_g:post_t b) (ens_g:a -> ens_t pre_g b post_g)
: ens_t pre_g b post_g
= fun h0 r h1 -> wp (fun _ -> True) /\ (exists x. ens_g x h0 r h1)
#push-options "--z3rlimit 20 --fuel 2 --ifuel 1"
let bind_div_steel (a:Type) (b:Type)
(wp:pure_wp a)
(framed:eqtype_as_type bool)
(pre_g:pre_t) (post_g:post_t b) (req_g:a -> req_t pre_g) (ens_g:a -> ens_t pre_g b post_g)
(f:eqtype_as_type unit -> DIV a wp) (g:(x:a -> repr b framed pre_g post_g (req_g x) (ens_g x)))
: repr b framed pre_g post_g
(bind_div_steel_req wp req_g)
(bind_div_steel_ens wp ens_g)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun frame ->
let x = f () in
g x frame
#pop-options
polymonadic_bind (DIV, SteelBase) |> SteelBase = bind_div_steel
#pop-options | {
"checked_file": "/",
"dependencies": [
"Steel.Semantics.Instantiate.fsti.checked",
"Steel.Semantics.Hoare.MST.fst.checked",
"Steel.Memory.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.NMST.fst.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Effect.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": false,
"full_module": "Steel.Semantics.Instantiate",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "Sem"
},
{
"abbrev": false,
"full_module": "Steel.Effect.Common",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
f: Steel.Effect.repr aL false preL postL (fun _ -> Prims.l_True) (fun _ _ _ -> Prims.l_True) ->
g: Steel.Effect.repr aR false preR postR (fun _ -> Prims.l_True) (fun _ _ _ -> Prims.l_True)
-> Steel.Effect.SteelT (aL * aR) | Steel.Effect.SteelT | [] | [] | [
"Steel.Effect.Common.vprop",
"Steel.Effect.repr",
"Steel.Effect.Common.rmem",
"Prims.l_True",
"Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop",
"Steel.Semantics.Instantiate.state",
"Steel.Semantics.Hoare.MST.run",
"FStar.Pervasives.Native.tuple2",
"Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star",
"Steel.Effect.Common.hp_of",
"Steel.Effect.to_post",
"Steel.Semantics.Hoare.MST.par_lpre",
"Steel.Effect.req_to_act_req",
"Steel.Semantics.Hoare.MST.par_lpost",
"Steel.Effect.ens_to_act_ens",
"Steel.Semantics.Hoare.MST.Par",
"Steel.Semantics.Hoare.MST.Act",
"Steel.Effect.Common.star",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.snd"
] | [] | false | true | false | false | false | let par0
(#aL: Type u#a)
(#preL: vprop)
(#postL: (aL -> vprop))
(f: repr aL false preL postL (fun _ -> True) (fun _ _ _ -> True))
(#aR: Type u#a)
(#preR: vprop)
(#postR: (aR -> vprop))
(g: repr aR false preR postR (fun _ -> True) (fun _ _ _ -> True))
: SteelT (aL & aR) (preL `star` preR) (fun y -> (postL (fst y)) `star` (postR (snd y))) =
| Steel?.reflect (fun frame -> Sem.run #state #_ #_ #_ #_ #_ frame (Sem.Par (Sem.Act f) (Sem.Act g))) | false |
Spec.Ed25519.PointOps.fst | Spec.Ed25519.PointOps.d | val d:elem | val d:elem | let d : elem =
let x = 37095705934669439343138083508754565189542113879843219016388785533085940283555 in
assert_norm(x < prime);
x | {
"file_name": "specs/Spec.Ed25519.PointOps.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 20,
"start_col": 0,
"start_line": 17
} | module Spec.Ed25519.PointOps
open FStar.Mul
open Spec.Curve25519
module BSeq = Lib.ByteSequence
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
type aff_point = elem & elem // Affine point
type ext_point = elem & elem & elem & elem // Homogeneous extended coordinates
(* 2 **% ((prime - 1) / 4) *)
let modp_sqrt_m1 : elem = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0 | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Ed25519.PointOps.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Spec.Curve25519.elem | Prims.Tot | [
"total"
] | [] | [
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_LessThan",
"Spec.Curve25519.prime",
"Prims.int"
] | [] | false | false | false | true | false | let d:elem =
| let x = 37095705934669439343138083508754565189542113879843219016388785533085940283555 in
assert_norm (x < prime);
x | false |
Spec.Ed25519.PointOps.fst | Spec.Ed25519.PointOps.aff_g | val aff_g:aff_point | val aff_g:aff_point | let aff_g : aff_point = (g_x, g_y) | {
"file_name": "specs/Spec.Ed25519.PointOps.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 34,
"end_line": 25,
"start_col": 0,
"start_line": 25
} | module Spec.Ed25519.PointOps
open FStar.Mul
open Spec.Curve25519
module BSeq = Lib.ByteSequence
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
type aff_point = elem & elem // Affine point
type ext_point = elem & elem & elem & elem // Homogeneous extended coordinates
(* 2 **% ((prime - 1) / 4) *)
let modp_sqrt_m1 : elem = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0
let d : elem =
let x = 37095705934669439343138083508754565189542113879843219016388785533085940283555 in
assert_norm(x < prime);
x
let g_x : elem = 15112221349535400772501151409588531511454012693041857206046113283949847762202
let g_y : elem = 46316835694926478169428394003475163141307993866256225615783033603165251855960 | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Ed25519.PointOps.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Spec.Ed25519.PointOps.aff_point | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.Mktuple2",
"Spec.Curve25519.elem",
"Spec.Ed25519.PointOps.g_x",
"Spec.Ed25519.PointOps.g_y"
] | [] | false | false | false | true | false | let aff_g:aff_point =
| (g_x, g_y) | false |
Hacl.Chacha20.Vec32.fst | Hacl.Chacha20.Vec32.double_round_32 | val double_round_32 : st: Hacl.Impl.Chacha20.Core32xN.state 1 -> FStar.HyperStack.ST.Stack Prims.unit | let double_round_32 = Hacl.Impl.Chacha20.Core32xN.double_round #1 | {
"file_name": "code/chacha20/Hacl.Chacha20.Vec32.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 65,
"end_line": 7,
"start_col": 0,
"start_line": 7
} | module Hacl.Chacha20.Vec32
open Hacl.Meta.Chacha20.Vec
[@CInline] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hacl.Meta.Chacha20.Vec.fst.checked",
"Hacl.Impl.Chacha20.Vec.fst.checked",
"Hacl.Impl.Chacha20.Core32xN.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Chacha20.Vec32.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Meta.Chacha20.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | st: Hacl.Impl.Chacha20.Core32xN.state 1 -> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Chacha20.Core32xN.double_round"
] | [] | false | true | false | false | false | let double_round_32 =
| Hacl.Impl.Chacha20.Core32xN.double_round #1 | false |
|
Spec.Ed25519.PointOps.fst | Spec.Ed25519.PointOps.to_aff_point | val to_aff_point (p: ext_point) : aff_point | val to_aff_point (p: ext_point) : aff_point | let to_aff_point (p:ext_point) : aff_point =
let _X, _Y, _Z, _T = p in
_X /% _Z, _Y /% _Z | {
"file_name": "specs/Spec.Ed25519.PointOps.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 20,
"end_line": 35,
"start_col": 0,
"start_line": 33
} | module Spec.Ed25519.PointOps
open FStar.Mul
open Spec.Curve25519
module BSeq = Lib.ByteSequence
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
type aff_point = elem & elem // Affine point
type ext_point = elem & elem & elem & elem // Homogeneous extended coordinates
(* 2 **% ((prime - 1) / 4) *)
let modp_sqrt_m1 : elem = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0
let d : elem =
let x = 37095705934669439343138083508754565189542113879843219016388785533085940283555 in
assert_norm(x < prime);
x
let g_x : elem = 15112221349535400772501151409588531511454012693041857206046113283949847762202
let g_y : elem = 46316835694926478169428394003475163141307993866256225615783033603165251855960
let aff_g : aff_point = (g_x, g_y)
let g: ext_point = (g_x, g_y, 1, g_x *% g_y)
let is_on_curve (p:aff_point) =
let (x, y) = p in
y *% y -% x *% x == 1 +% d *% (x *% x) *% (y *% y) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Ed25519.PointOps.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Spec.Ed25519.PointOps.ext_point -> Spec.Ed25519.PointOps.aff_point | Prims.Tot | [
"total"
] | [] | [
"Spec.Ed25519.PointOps.ext_point",
"Spec.Curve25519.elem",
"FStar.Pervasives.Native.Mktuple2",
"Spec.Curve25519.op_Slash_Percent",
"Spec.Ed25519.PointOps.aff_point"
] | [] | false | false | false | true | false | let to_aff_point (p: ext_point) : aff_point =
| let _X, _Y, _Z, _T = p in
_X /% _Z, _Y /% _Z | false |
Hacl.Impl.MultiExponentiation.fsti | Hacl.Impl.MultiExponentiation.lexp_double_fw_st | val lexp_double_fw_st : a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a ->
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len
-> Type0 | let lexp_double_fw_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a1:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b1:lbuffer (uint_t a_t SEC) bLen
-> a2:lbuffer (uint_t a_t SEC) len
-> b2:lbuffer (uint_t a_t SEC) bLen
-> res:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a1 /\ live h b1 /\ live h a2 /\ live h b2 /\ live h res /\ live h ctx /\
eq_or_disjoint a1 a2 /\ disjoint a1 res /\ disjoint a1 ctx /\
disjoint a2 res /\ disjoint a2 ctx /\
disjoint res b1 /\ disjoint res b2 /\ disjoint res ctx /\
BD.bn_v h b1 < pow2 (v bBits) /\
BD.bn_v h b2 < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a1) /\ k.to.linv (as_seq h a2))
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
k.to.linv (as_seq h1 res) /\
k.to.refl (as_seq h1 res) ==
S.exp_double_fw #k.to.a_spec k.to.comm_monoid
(k.to.refl (as_seq h0 a1)) (v bBits) (BD.bn_v h0 b1)
(k.to.refl (as_seq h0 a2)) (BD.bn_v h0 b2) (v l)) | {
"file_name": "code/bignum/Hacl.Impl.MultiExponentiation.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 115,
"start_col": 0,
"start_line": 86
} | module Hacl.Impl.MultiExponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
open Hacl.Impl.Exponentiation
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
// Double Fixed-window method using two precomputed tables
//---------------------------------------------------------
inline_for_extraction noextract
let lexp_double_fw_tables_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv1:table_inv_t a_t len table_len)
(table_inv2:table_inv_t a_t len table_len)
=
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a1:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b1:lbuffer (uint_t a_t SEC) bLen
-> a2:lbuffer (uint_t a_t SEC) len
-> b2:lbuffer (uint_t a_t SEC) bLen
-> table1:clbuffer (uint_t a_t SEC) (table_len *! len)
-> table2:clbuffer (uint_t a_t SEC) (table_len *! len)
-> res:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a1 /\ live h b1 /\ live h a2 /\ live h b2 /\
live h res /\ live h ctx /\ live h table1 /\ live h table2 /\
eq_or_disjoint a1 a2 /\ disjoint a1 res /\ disjoint a1 ctx /\
disjoint b1 res /\ disjoint a2 res /\ disjoint a2 ctx /\
disjoint b2 res /\ disjoint res ctx /\ disjoint res table1 /\ disjoint res table2 /\
BD.bn_v h b1 < pow2 (v bBits) /\
BD.bn_v h b2 < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a1) /\ k.to.linv (as_seq h a2) /\
table_inv1 (as_seq h a1) (as_seq h table1) /\
table_inv2 (as_seq h a2) (as_seq h table2))
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
k.to.linv (as_seq h1 res) /\
k.to.refl (as_seq h1 res) ==
S.exp_double_fw k.to.comm_monoid
(k.to.refl (as_seq h0 a1)) (v bBits) (BD.bn_v h0 b1)
(k.to.refl (as_seq h0 a2)) (BD.bn_v h0 b2) (v l))
inline_for_extraction noextract
val mk_lexp_double_fw_tables:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv1:table_inv_t a_t len table_len
-> table_inv2:table_inv_t a_t len table_len
-> pow_a_to_small_b1:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv1
-> pow_a_to_small_b2:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv2 ->
lexp_double_fw_tables_st a_t len ctx_len k l table_len table_inv1 table_inv2
// Double Fixed-window method with two precomputed tables
// table1 = [a1^0 = one; a1^1; a1^2; ..; a1^(table_len - 1)]
// table2 = [a2^0 = one; a2^1; a2^2; ..; a2^(table_len - 1)]
//----------------------------------------------------------- | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.MultiExponentiation.fsti"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a ->
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Hacl.Impl.Exponentiation.size_window_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.op_LessThan",
"Prims.op_Division",
"Prims.op_Subtraction",
"Lib.IntTypes.bits",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Lib.Buffer.eq_or_disjoint",
"Lib.Buffer.disjoint",
"Hacl.Bignum.Definitions.bn_v",
"Prims.pow2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv_ctx",
"FStar.Ghost.reveal",
"Hacl.Impl.Exponentiation.Definitions.to_comm_monoid",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__to",
"Lib.Buffer.as_seq",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Prims.eq2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__a_spec",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__refl",
"Lib.Exponentiation.exp_double_fw",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__comm_monoid"
] | [] | false | false | false | false | true | let lexp_double_fw_st
(a_t: inttype_a)
(len: size_t{v len > 0})
(ctx_len: size_t)
(k: concrete_ops a_t len ctx_len)
(l: size_window_t a_t len)
=
|
ctx: lbuffer (uint_t a_t SEC) ctx_len ->
a1: lbuffer (uint_t a_t SEC) len ->
bLen: size_t ->
bBits: size_t{(v bBits - 1) / bits a_t < v bLen} ->
b1: lbuffer (uint_t a_t SEC) bLen ->
a2: lbuffer (uint_t a_t SEC) len ->
b2: lbuffer (uint_t a_t SEC) bLen ->
res: lbuffer (uint_t a_t SEC) len
-> Stack unit
(requires
fun h ->
live h a1 /\ live h b1 /\ live h a2 /\ live h b2 /\ live h res /\ live h ctx /\
eq_or_disjoint a1 a2 /\ disjoint a1 res /\ disjoint a1 ctx /\ disjoint a2 res /\
disjoint a2 ctx /\ disjoint res b1 /\ disjoint res b2 /\ disjoint res ctx /\
BD.bn_v h b1 < pow2 (v bBits) /\ BD.bn_v h b2 < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a1) /\ k.to.linv (as_seq h a2))
(ensures
fun h0 _ h1 ->
modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\
k.to.refl (as_seq h1 res) ==
S.exp_double_fw #k.to.a_spec
k.to.comm_monoid
(k.to.refl (as_seq h0 a1))
(v bBits)
(BD.bn_v h0 b1)
(k.to.refl (as_seq h0 a2))
(BD.bn_v h0 b2)
(v l)) | false |
|
Hacl.Chacha20.Vec32.fst | Hacl.Chacha20.Vec32.chacha20_decrypt_32 | val chacha20_decrypt_32 : Hacl.Meta.Chacha20.Vec.vec_chacha20_decrypt_higher_t Prims.l_True | let chacha20_decrypt_32 = vec_chacha20_decrypt_higher #1 True chacha20_init_32 chacha20_core_32 | {
"file_name": "code/chacha20/Hacl.Chacha20.Vec32.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 95,
"end_line": 16,
"start_col": 0,
"start_line": 16
} | module Hacl.Chacha20.Vec32
open Hacl.Meta.Chacha20.Vec
[@CInline]
private
let double_round_32 = Hacl.Impl.Chacha20.Core32xN.double_round #1
[@CInline]
private
let chacha20_core_32 = vec_chacha20_core_higher #1 True double_round_32
[@CInline]
private
let chacha20_init_32 = Hacl.Impl.Chacha20.Vec.chacha20_init #1 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hacl.Meta.Chacha20.Vec.fst.checked",
"Hacl.Impl.Chacha20.Vec.fst.checked",
"Hacl.Impl.Chacha20.Core32xN.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Chacha20.Vec32.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Meta.Chacha20.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Meta.Chacha20.Vec.vec_chacha20_decrypt_higher_t Prims.l_True | Prims.Tot | [
"total"
] | [] | [
"Hacl.Meta.Chacha20.Vec.vec_chacha20_decrypt_higher",
"Prims.l_True",
"Hacl.Chacha20.Vec32.chacha20_init_32",
"Hacl.Chacha20.Vec32.chacha20_core_32"
] | [] | false | false | false | false | false | let chacha20_decrypt_32 =
| vec_chacha20_decrypt_higher #1 True chacha20_init_32 chacha20_core_32 | false |
|
Hacl.Chacha20.Vec32.fst | Hacl.Chacha20.Vec32.chacha20_init_32 | val chacha20_init_32 : ctx: Hacl.Impl.Chacha20.Core32xN.state 1 ->
k: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul ->
n: Lib.Buffer.lbuffer Lib.IntTypes.uint8 12ul ->
ctr0: Lib.IntTypes.size_t
-> FStar.HyperStack.ST.Stack Prims.unit | let chacha20_init_32 = Hacl.Impl.Chacha20.Vec.chacha20_init #1 | {
"file_name": "code/chacha20/Hacl.Chacha20.Vec32.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 62,
"end_line": 13,
"start_col": 0,
"start_line": 13
} | module Hacl.Chacha20.Vec32
open Hacl.Meta.Chacha20.Vec
[@CInline]
private
let double_round_32 = Hacl.Impl.Chacha20.Core32xN.double_round #1
[@CInline]
private
let chacha20_core_32 = vec_chacha20_core_higher #1 True double_round_32
[@CInline] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hacl.Meta.Chacha20.Vec.fst.checked",
"Hacl.Impl.Chacha20.Vec.fst.checked",
"Hacl.Impl.Chacha20.Core32xN.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Chacha20.Vec32.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Meta.Chacha20.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ctx: Hacl.Impl.Chacha20.Core32xN.state 1 ->
k: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul ->
n: Lib.Buffer.lbuffer Lib.IntTypes.uint8 12ul ->
ctr0: Lib.IntTypes.size_t
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Chacha20.Vec.chacha20_init"
] | [] | false | true | false | false | false | let chacha20_init_32 =
| Hacl.Impl.Chacha20.Vec.chacha20_init #1 | false |
|
Hacl.Chacha20.Vec32.fst | Hacl.Chacha20.Vec32.chacha20_encrypt_32 | val chacha20_encrypt_32 : Hacl.Meta.Chacha20.Vec.vec_chacha20_encrypt_higher_t Prims.l_True | let chacha20_encrypt_32 = vec_chacha20_encrypt_higher #1 True chacha20_init_32 chacha20_core_32 | {
"file_name": "code/chacha20/Hacl.Chacha20.Vec32.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 95,
"end_line": 15,
"start_col": 0,
"start_line": 15
} | module Hacl.Chacha20.Vec32
open Hacl.Meta.Chacha20.Vec
[@CInline]
private
let double_round_32 = Hacl.Impl.Chacha20.Core32xN.double_round #1
[@CInline]
private
let chacha20_core_32 = vec_chacha20_core_higher #1 True double_round_32
[@CInline]
private
let chacha20_init_32 = Hacl.Impl.Chacha20.Vec.chacha20_init #1 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hacl.Meta.Chacha20.Vec.fst.checked",
"Hacl.Impl.Chacha20.Vec.fst.checked",
"Hacl.Impl.Chacha20.Core32xN.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Chacha20.Vec32.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Meta.Chacha20.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Meta.Chacha20.Vec.vec_chacha20_encrypt_higher_t Prims.l_True | Prims.Tot | [
"total"
] | [] | [
"Hacl.Meta.Chacha20.Vec.vec_chacha20_encrypt_higher",
"Prims.l_True",
"Hacl.Chacha20.Vec32.chacha20_init_32",
"Hacl.Chacha20.Vec32.chacha20_core_32"
] | [] | false | false | false | false | false | let chacha20_encrypt_32 =
| vec_chacha20_encrypt_higher #1 True chacha20_init_32 chacha20_core_32 | false |
|
Spec.Ed25519.PointOps.fst | Spec.Ed25519.PointOps.point_inv | val point_inv : p: Spec.Ed25519.PointOps.ext_point -> Prims.logical | let point_inv (p:ext_point) =
is_ext p /\ is_on_curve (to_aff_point p) | {
"file_name": "specs/Spec.Ed25519.PointOps.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 42,
"end_line": 42,
"start_col": 0,
"start_line": 41
} | module Spec.Ed25519.PointOps
open FStar.Mul
open Spec.Curve25519
module BSeq = Lib.ByteSequence
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
type aff_point = elem & elem // Affine point
type ext_point = elem & elem & elem & elem // Homogeneous extended coordinates
(* 2 **% ((prime - 1) / 4) *)
let modp_sqrt_m1 : elem = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0
let d : elem =
let x = 37095705934669439343138083508754565189542113879843219016388785533085940283555 in
assert_norm(x < prime);
x
let g_x : elem = 15112221349535400772501151409588531511454012693041857206046113283949847762202
let g_y : elem = 46316835694926478169428394003475163141307993866256225615783033603165251855960
let aff_g : aff_point = (g_x, g_y)
let g: ext_point = (g_x, g_y, 1, g_x *% g_y)
let is_on_curve (p:aff_point) =
let (x, y) = p in
y *% y -% x *% x == 1 +% d *% (x *% x) *% (y *% y)
let to_aff_point (p:ext_point) : aff_point =
let _X, _Y, _Z, _T = p in
_X /% _Z, _Y /% _Z
let is_ext (p:ext_point) =
let _X, _Y, _Z, _T = p in
_T == _X *% _Y /% _Z /\ _Z <> zero | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Ed25519.PointOps.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Spec.Ed25519.PointOps.ext_point -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Spec.Ed25519.PointOps.ext_point",
"Prims.l_and",
"Spec.Ed25519.PointOps.is_ext",
"Spec.Ed25519.PointOps.is_on_curve",
"Spec.Ed25519.PointOps.to_aff_point",
"Prims.logical"
] | [] | false | false | false | true | true | let point_inv (p: ext_point) =
| is_ext p /\ is_on_curve (to_aff_point p) | false |
|
Spec.Ed25519.PointOps.fst | Spec.Ed25519.PointOps.aff_point_at_infinity | val aff_point_at_infinity:aff_point | val aff_point_at_infinity:aff_point | let aff_point_at_infinity : aff_point = (zero, one) | {
"file_name": "specs/Spec.Ed25519.PointOps.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 51,
"end_line": 67,
"start_col": 0,
"start_line": 67
} | module Spec.Ed25519.PointOps
open FStar.Mul
open Spec.Curve25519
module BSeq = Lib.ByteSequence
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
type aff_point = elem & elem // Affine point
type ext_point = elem & elem & elem & elem // Homogeneous extended coordinates
(* 2 **% ((prime - 1) / 4) *)
let modp_sqrt_m1 : elem = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0
let d : elem =
let x = 37095705934669439343138083508754565189542113879843219016388785533085940283555 in
assert_norm(x < prime);
x
let g_x : elem = 15112221349535400772501151409588531511454012693041857206046113283949847762202
let g_y : elem = 46316835694926478169428394003475163141307993866256225615783033603165251855960
let aff_g : aff_point = (g_x, g_y)
let g: ext_point = (g_x, g_y, 1, g_x *% g_y)
let is_on_curve (p:aff_point) =
let (x, y) = p in
y *% y -% x *% x == 1 +% d *% (x *% x) *% (y *% y)
let to_aff_point (p:ext_point) : aff_point =
let _X, _Y, _Z, _T = p in
_X /% _Z, _Y /% _Z
let is_ext (p:ext_point) =
let _X, _Y, _Z, _T = p in
_T == _X *% _Y /% _Z /\ _Z <> zero
let point_inv (p:ext_point) =
is_ext p /\ is_on_curve (to_aff_point p)
// let is_on_curve_ext (p:ext_point) =
// let _X, _Y, _Z, _T = p in
// _Y *% _Y -% X *% X == _Z *% _Z +% d *% _T *% _T
// let to_ext_point (p:aff_point) : ext_point =
// let x, y = p in
// (x, y, one, x *% y)
/// Point addition and doubling in affine coordinates
let aff_point_add (p:aff_point) (q:aff_point) : aff_point =
let x1, y1 = p in
let x2, y2 = q in
let x3 = (x1 *% y2 +% y1 *% x2) /% (1 +% d *% (x1 *% x2) *% (y1 *% y2)) in
let y3 = (y1 *% y2 +% x1 *% x2) /% (1 -% d *% (x1 *% x2) *% (y1 *% y2)) in
x3, y3
let aff_point_double (p:aff_point) : aff_point =
let x, y = p in
let x3 = (2 *% x *% y) /% (y *% y -% x *% x) in
let y3 = (y *% y +% x *% x) /% (2 -% y *% y +% x *% x) in
x3, y3 | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Ed25519.PointOps.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Spec.Ed25519.PointOps.aff_point | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.Mktuple2",
"Spec.Curve25519.elem",
"Spec.Curve25519.zero",
"Spec.Curve25519.one"
] | [] | false | false | false | true | false | let aff_point_at_infinity:aff_point =
| (zero, one) | false |
Spec.Ed25519.PointOps.fst | Spec.Ed25519.PointOps.point_at_infinity | val point_at_infinity:ext_point | val point_at_infinity:ext_point | let point_at_infinity: ext_point = (zero, one, one, zero) | {
"file_name": "specs/Spec.Ed25519.PointOps.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 57,
"end_line": 108,
"start_col": 0,
"start_line": 108
} | module Spec.Ed25519.PointOps
open FStar.Mul
open Spec.Curve25519
module BSeq = Lib.ByteSequence
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
type aff_point = elem & elem // Affine point
type ext_point = elem & elem & elem & elem // Homogeneous extended coordinates
(* 2 **% ((prime - 1) / 4) *)
let modp_sqrt_m1 : elem = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0
let d : elem =
let x = 37095705934669439343138083508754565189542113879843219016388785533085940283555 in
assert_norm(x < prime);
x
let g_x : elem = 15112221349535400772501151409588531511454012693041857206046113283949847762202
let g_y : elem = 46316835694926478169428394003475163141307993866256225615783033603165251855960
let aff_g : aff_point = (g_x, g_y)
let g: ext_point = (g_x, g_y, 1, g_x *% g_y)
let is_on_curve (p:aff_point) =
let (x, y) = p in
y *% y -% x *% x == 1 +% d *% (x *% x) *% (y *% y)
let to_aff_point (p:ext_point) : aff_point =
let _X, _Y, _Z, _T = p in
_X /% _Z, _Y /% _Z
let is_ext (p:ext_point) =
let _X, _Y, _Z, _T = p in
_T == _X *% _Y /% _Z /\ _Z <> zero
let point_inv (p:ext_point) =
is_ext p /\ is_on_curve (to_aff_point p)
// let is_on_curve_ext (p:ext_point) =
// let _X, _Y, _Z, _T = p in
// _Y *% _Y -% X *% X == _Z *% _Z +% d *% _T *% _T
// let to_ext_point (p:aff_point) : ext_point =
// let x, y = p in
// (x, y, one, x *% y)
/// Point addition and doubling in affine coordinates
let aff_point_add (p:aff_point) (q:aff_point) : aff_point =
let x1, y1 = p in
let x2, y2 = q in
let x3 = (x1 *% y2 +% y1 *% x2) /% (1 +% d *% (x1 *% x2) *% (y1 *% y2)) in
let y3 = (y1 *% y2 +% x1 *% x2) /% (1 -% d *% (x1 *% x2) *% (y1 *% y2)) in
x3, y3
let aff_point_double (p:aff_point) : aff_point =
let x, y = p in
let x3 = (2 *% x *% y) /% (y *% y -% x *% x) in
let y3 = (y *% y +% x *% x) /% (2 -% y *% y +% x *% x) in
x3, y3
let aff_point_at_infinity : aff_point = (zero, one)
let aff_point_negate (p:aff_point) : aff_point =
let x, y = p in
((-x) % prime, y)
/// Point addition and doubling in Extended Twisted Edwards Coordinates
let point_add (p:ext_point) (q:ext_point) : Tot ext_point =
let _X1, _Y1, _Z1, _T1 = p in
let _X2, _Y2, _Z2, _T2 = q in
let a = (_Y1 -% _X1) *% (_Y2 -% _X2) in
let b = (_Y1 +% _X1) *% (_Y2 +% _X2) in
let c = (2 *% d *% _T1) *% _T2 in
let d = (2 *% _Z1) *% _Z2 in
let e = b -% a in
let f = d -% c in
let g = d +% c in
let h = b +% a in
let _X3 = e *% f in
let _Y3 = g *% h in
let _T3 = e *% h in
let _Z3 = f *% g in
(_X3, _Y3, _Z3, _T3)
let point_double (p:ext_point) : Tot ext_point =
let _X1, _Y1, _Z1, _T1 = p in
let a = _X1 *% _X1 in
let b = _Y1 *% _Y1 in
let c = 2 *% (_Z1 *% _Z1) in
let h = a +% b in
let e = h -% ((_X1 +% _Y1) *% (_X1 +% _Y1)) in
let g = a -% b in
let f = c +% g in
let _X3 = e *% f in
let _Y3 = g *% h in
let _T3 = e *% h in
let _Z3 = f *% g in
(_X3, _Y3, _Z3, _T3) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Ed25519.PointOps.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Spec.Ed25519.PointOps.ext_point | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.Mktuple4",
"Spec.Curve25519.elem",
"Spec.Curve25519.zero",
"Spec.Curve25519.one"
] | [] | false | false | false | true | false | let point_at_infinity:ext_point =
| (zero, one, one, zero) | false |
LowStar.UninitializedBuffer.fst | LowStar.UninitializedBuffer.unull | val unull (#a: Type0) : ubuffer a | val unull (#a: Type0) : ubuffer a | let unull (#a:Type0) :ubuffer a = mnull #(option a) #(initialization_preorder a) #(initialization_preorder a) | {
"file_name": "ulib/LowStar.UninitializedBuffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 116,
"end_line": 40,
"start_col": 7,
"start_line": 40
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.UninitializedBuffer
include LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(*
* Uninitialized buffers
*
* Modeled as: seq (option a) with a preorder that an index once set remains set
*)
private let initialization_preorder (a:Type0) :srel (option a) =
fun s1 s2 -> Seq.length s1 == Seq.length s2 /\
(forall (i:nat).{:pattern (Seq.index s2 i)} i < Seq.length s1 ==> Some? (Seq.index s1 i) ==> Some? (Seq.index s2 i))
type ubuffer (a:Type0) =
mbuffer (option a) (initialization_preorder a) (initialization_preorder a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.UninitializedBuffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | LowStar.UninitializedBuffer.ubuffer a | Prims.Tot | [
"total"
] | [] | [
"LowStar.Monotonic.Buffer.mnull",
"FStar.Pervasives.Native.option",
"LowStar.UninitializedBuffer.initialization_preorder",
"LowStar.UninitializedBuffer.ubuffer"
] | [] | false | false | false | true | false | let unull (#a: Type0) : ubuffer a =
| mnull #(option a) #(initialization_preorder a) #(initialization_preorder a) | false |
Spec.Ed25519.PointOps.fst | Spec.Ed25519.PointOps.g_y | val g_y:elem | val g_y:elem | let g_y : elem = 46316835694926478169428394003475163141307993866256225615783033603165251855960 | {
"file_name": "specs/Spec.Ed25519.PointOps.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 94,
"end_line": 23,
"start_col": 0,
"start_line": 23
} | module Spec.Ed25519.PointOps
open FStar.Mul
open Spec.Curve25519
module BSeq = Lib.ByteSequence
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
type aff_point = elem & elem // Affine point
type ext_point = elem & elem & elem & elem // Homogeneous extended coordinates
(* 2 **% ((prime - 1) / 4) *)
let modp_sqrt_m1 : elem = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0
let d : elem =
let x = 37095705934669439343138083508754565189542113879843219016388785533085940283555 in
assert_norm(x < prime);
x | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Ed25519.PointOps.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Spec.Curve25519.elem | Prims.Tot | [
"total"
] | [] | [] | [] | false | false | false | true | false | let g_y:elem =
| 46316835694926478169428394003475163141307993866256225615783033603165251855960 | false |
LowStar.UninitializedBuffer.fst | LowStar.UninitializedBuffer.usub | val usub : b:
LowStar.Monotonic.Buffer.mbuffer (FStar.Pervasives.Native.option a)
(LowStar.UninitializedBuffer.initialization_preorder a)
(LowStar.UninitializedBuffer.initialization_preorder a) ->
i: FStar.UInt32.t ->
len: FStar.Ghost.erased FStar.UInt32.t
-> FStar.HyperStack.ST.Stack
(LowStar.Monotonic.Buffer.mbuffer (FStar.Pervasives.Native.option a)
(LowStar.UninitializedBuffer.initialization_preorder a)
(LowStar.UninitializedBuffer.initialization_preorder a)) | let usub (#a:Type0) = msub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a) | {
"file_name": "ulib/LowStar.UninitializedBuffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 146,
"end_line": 52,
"start_col": 22,
"start_line": 52
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.UninitializedBuffer
include LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(*
* Uninitialized buffers
*
* Modeled as: seq (option a) with a preorder that an index once set remains set
*)
private let initialization_preorder (a:Type0) :srel (option a) =
fun s1 s2 -> Seq.length s1 == Seq.length s2 /\
(forall (i:nat).{:pattern (Seq.index s2 i)} i < Seq.length s1 ==> Some? (Seq.index s1 i) ==> Some? (Seq.index s2 i))
type ubuffer (a:Type0) =
mbuffer (option a) (initialization_preorder a) (initialization_preorder a)
unfold let unull (#a:Type0) :ubuffer a = mnull #(option a) #(initialization_preorder a) #(initialization_preorder a)
unfold let gsub (#a:Type0) = mgsub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
unfold let gsub_inj (#a:Type0) = mgsub_inj #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a) (initialization_preorder a)
inline_for_extraction
type pointer (a:Type0) = b:ubuffer a{length b == 1}
inline_for_extraction
type pointer_or_null (a:Type0) = b:ubuffer a{if g_is_null b then True else length b == 1} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.UninitializedBuffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b:
LowStar.Monotonic.Buffer.mbuffer (FStar.Pervasives.Native.option a)
(LowStar.UninitializedBuffer.initialization_preorder a)
(LowStar.UninitializedBuffer.initialization_preorder a) ->
i: FStar.UInt32.t ->
len: FStar.Ghost.erased FStar.UInt32.t
-> FStar.HyperStack.ST.Stack
(LowStar.Monotonic.Buffer.mbuffer (FStar.Pervasives.Native.option a)
(LowStar.UninitializedBuffer.initialization_preorder a)
(LowStar.UninitializedBuffer.initialization_preorder a)) | FStar.HyperStack.ST.Stack | [] | [] | [
"LowStar.Monotonic.Buffer.msub",
"FStar.Pervasives.Native.option",
"LowStar.UninitializedBuffer.initialization_preorder",
"LowStar.Monotonic.Buffer.mbuffer",
"FStar.UInt32.t",
"FStar.Ghost.erased",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.UInt32.v",
"FStar.Ghost.reveal",
"LowStar.Monotonic.Buffer.length",
"Prims.l_Forall",
"FStar.Seq.Base.seq",
"Prims.l_imp",
"Prims.eq2",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.Seq.Base.slice",
"Prims.int",
"Prims.op_Subtraction",
"FStar.Seq.Properties.replace_subseq",
"LowStar.Monotonic.Buffer.live",
"LowStar.Monotonic.Buffer.mgsub"
] | [] | false | true | false | false | false | let usub (#a: Type0) =
| msub #(option a)
#(initialization_preorder a)
#(initialization_preorder a)
(initialization_preorder a) | false |
|
LowStar.UninitializedBuffer.fst | LowStar.UninitializedBuffer.uoffset | val uoffset : b:
LowStar.Monotonic.Buffer.mbuffer (FStar.Pervasives.Native.option a)
(LowStar.UninitializedBuffer.initialization_preorder a)
(LowStar.UninitializedBuffer.initialization_preorder a) ->
i: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack
(LowStar.Monotonic.Buffer.mbuffer (FStar.Pervasives.Native.option a)
(LowStar.UninitializedBuffer.initialization_preorder a)
(LowStar.UninitializedBuffer.initialization_preorder a)) | let uoffset (#a:Type0) = moffset #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a) | {
"file_name": "ulib/LowStar.UninitializedBuffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 152,
"end_line": 54,
"start_col": 22,
"start_line": 54
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.UninitializedBuffer
include LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(*
* Uninitialized buffers
*
* Modeled as: seq (option a) with a preorder that an index once set remains set
*)
private let initialization_preorder (a:Type0) :srel (option a) =
fun s1 s2 -> Seq.length s1 == Seq.length s2 /\
(forall (i:nat).{:pattern (Seq.index s2 i)} i < Seq.length s1 ==> Some? (Seq.index s1 i) ==> Some? (Seq.index s2 i))
type ubuffer (a:Type0) =
mbuffer (option a) (initialization_preorder a) (initialization_preorder a)
unfold let unull (#a:Type0) :ubuffer a = mnull #(option a) #(initialization_preorder a) #(initialization_preorder a)
unfold let gsub (#a:Type0) = mgsub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
unfold let gsub_inj (#a:Type0) = mgsub_inj #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a) (initialization_preorder a)
inline_for_extraction
type pointer (a:Type0) = b:ubuffer a{length b == 1}
inline_for_extraction
type pointer_or_null (a:Type0) = b:ubuffer a{if g_is_null b then True else length b == 1}
inline_for_extraction let usub (#a:Type0) = msub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.UninitializedBuffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b:
LowStar.Monotonic.Buffer.mbuffer (FStar.Pervasives.Native.option a)
(LowStar.UninitializedBuffer.initialization_preorder a)
(LowStar.UninitializedBuffer.initialization_preorder a) ->
i: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack
(LowStar.Monotonic.Buffer.mbuffer (FStar.Pervasives.Native.option a)
(LowStar.UninitializedBuffer.initialization_preorder a)
(LowStar.UninitializedBuffer.initialization_preorder a)) | FStar.HyperStack.ST.Stack | [] | [] | [
"LowStar.Monotonic.Buffer.moffset",
"FStar.Pervasives.Native.option",
"LowStar.UninitializedBuffer.initialization_preorder",
"LowStar.Monotonic.Buffer.mbuffer",
"FStar.UInt32.t",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"LowStar.Monotonic.Buffer.length",
"Prims.l_Forall",
"FStar.Seq.Base.seq",
"Prims.l_imp",
"Prims.eq2",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.Seq.Base.slice",
"Prims.op_Addition",
"FStar.UInt32.sub",
"LowStar.Monotonic.Buffer.len",
"Prims.int",
"Prims.op_Subtraction",
"FStar.Seq.Properties.replace_subseq",
"LowStar.Monotonic.Buffer.live",
"LowStar.Monotonic.Buffer.mgsub"
] | [] | false | true | false | false | false | let uoffset (#a: Type0) =
| moffset #(option a)
#(initialization_preorder a)
#(initialization_preorder a)
(initialization_preorder a) | false |
|
LowStar.UninitializedBuffer.fst | LowStar.UninitializedBuffer.gsub | val gsub : b:
LowStar.Monotonic.Buffer.mbuffer (FStar.Pervasives.Native.option a)
(LowStar.UninitializedBuffer.initialization_preorder a)
(LowStar.UninitializedBuffer.initialization_preorder a) ->
i: FStar.UInt32.t ->
len: FStar.UInt32.t
-> Prims.Ghost
(LowStar.Monotonic.Buffer.mbuffer (FStar.Pervasives.Native.option a)
(LowStar.UninitializedBuffer.initialization_preorder a)
(LowStar.UninitializedBuffer.initialization_preorder a)) | let gsub (#a:Type0) = mgsub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a) | {
"file_name": "ulib/LowStar.UninitializedBuffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 132,
"end_line": 42,
"start_col": 7,
"start_line": 42
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.UninitializedBuffer
include LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(*
* Uninitialized buffers
*
* Modeled as: seq (option a) with a preorder that an index once set remains set
*)
private let initialization_preorder (a:Type0) :srel (option a) =
fun s1 s2 -> Seq.length s1 == Seq.length s2 /\
(forall (i:nat).{:pattern (Seq.index s2 i)} i < Seq.length s1 ==> Some? (Seq.index s1 i) ==> Some? (Seq.index s2 i))
type ubuffer (a:Type0) =
mbuffer (option a) (initialization_preorder a) (initialization_preorder a)
unfold let unull (#a:Type0) :ubuffer a = mnull #(option a) #(initialization_preorder a) #(initialization_preorder a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.UninitializedBuffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b:
LowStar.Monotonic.Buffer.mbuffer (FStar.Pervasives.Native.option a)
(LowStar.UninitializedBuffer.initialization_preorder a)
(LowStar.UninitializedBuffer.initialization_preorder a) ->
i: FStar.UInt32.t ->
len: FStar.UInt32.t
-> Prims.Ghost
(LowStar.Monotonic.Buffer.mbuffer (FStar.Pervasives.Native.option a)
(LowStar.UninitializedBuffer.initialization_preorder a)
(LowStar.UninitializedBuffer.initialization_preorder a)) | Prims.Ghost | [] | [] | [
"LowStar.Monotonic.Buffer.mgsub",
"FStar.Pervasives.Native.option",
"LowStar.UninitializedBuffer.initialization_preorder",
"LowStar.Monotonic.Buffer.mbuffer",
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.UInt32.v",
"LowStar.Monotonic.Buffer.length",
"Prims.l_True"
] | [] | false | false | false | false | false | let gsub (#a: Type0) =
| mgsub #(option a)
#(initialization_preorder a)
#(initialization_preorder a)
(initialization_preorder a) | false |
|
Spec.Ed25519.PointOps.fst | Spec.Ed25519.PointOps.modp_sqrt_m1 | val modp_sqrt_m1:elem | val modp_sqrt_m1:elem | let modp_sqrt_m1 : elem = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0 | {
"file_name": "specs/Spec.Ed25519.PointOps.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 92,
"end_line": 15,
"start_col": 0,
"start_line": 15
} | module Spec.Ed25519.PointOps
open FStar.Mul
open Spec.Curve25519
module BSeq = Lib.ByteSequence
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
type aff_point = elem & elem // Affine point
type ext_point = elem & elem & elem & elem // Homogeneous extended coordinates | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Ed25519.PointOps.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Spec.Curve25519.elem | Prims.Tot | [
"total"
] | [] | [] | [] | false | false | false | true | false | let modp_sqrt_m1:elem =
| 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0 | false |
LowStar.UninitializedBuffer.fst | LowStar.UninitializedBuffer.ipred | val ipred (#a: Type0) (i: nat) : spred (option a) | val ipred (#a: Type0) (i: nat) : spred (option a) | let ipred (#a:Type0) (i:nat) :spred (option a) = fun s -> i < Seq.length s ==> Some? (Seq.index s i) | {
"file_name": "ulib/LowStar.UninitializedBuffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 108,
"end_line": 62,
"start_col": 8,
"start_line": 62
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.UninitializedBuffer
include LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(*
* Uninitialized buffers
*
* Modeled as: seq (option a) with a preorder that an index once set remains set
*)
private let initialization_preorder (a:Type0) :srel (option a) =
fun s1 s2 -> Seq.length s1 == Seq.length s2 /\
(forall (i:nat).{:pattern (Seq.index s2 i)} i < Seq.length s1 ==> Some? (Seq.index s1 i) ==> Some? (Seq.index s2 i))
type ubuffer (a:Type0) =
mbuffer (option a) (initialization_preorder a) (initialization_preorder a)
unfold let unull (#a:Type0) :ubuffer a = mnull #(option a) #(initialization_preorder a) #(initialization_preorder a)
unfold let gsub (#a:Type0) = mgsub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
unfold let gsub_inj (#a:Type0) = mgsub_inj #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a) (initialization_preorder a)
inline_for_extraction
type pointer (a:Type0) = b:ubuffer a{length b == 1}
inline_for_extraction
type pointer_or_null (a:Type0) = b:ubuffer a{if g_is_null b then True else length b == 1}
inline_for_extraction let usub (#a:Type0) = msub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
inline_for_extraction let uoffset (#a:Type0) = moffset #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
(****** main stateful API *****)
(*
* b `initialized_at` i: is a stable predicate that witnesses the initialization of an index i in ubuffer b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.UninitializedBuffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Prims.nat -> LowStar.Monotonic.Buffer.spred (FStar.Pervasives.Native.option a) | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"FStar.Seq.Base.seq",
"FStar.Pervasives.Native.option",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Seq.Base.index",
"LowStar.Monotonic.Buffer.spred"
] | [] | false | false | false | true | false | let ipred (#a: Type0) (i: nat) : spred (option a) =
| fun s -> i < Seq.length s ==> Some? (Seq.index s i) | false |
LowStar.UninitializedBuffer.fst | LowStar.UninitializedBuffer.lubuffer_or_null | val lubuffer_or_null : a: Type0 -> len: Prims.nat -> r: FStar.Monotonic.HyperHeap.rid -> Type0 | let lubuffer_or_null (a:Type0) (len:nat) (r:HS.rid) =
b:ubuffer a{(not (g_is_null b)) ==> (length b == len /\ frameOf b == r)} | {
"file_name": "ulib/LowStar.UninitializedBuffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 74,
"end_line": 91,
"start_col": 7,
"start_line": 90
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.UninitializedBuffer
include LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(*
* Uninitialized buffers
*
* Modeled as: seq (option a) with a preorder that an index once set remains set
*)
private let initialization_preorder (a:Type0) :srel (option a) =
fun s1 s2 -> Seq.length s1 == Seq.length s2 /\
(forall (i:nat).{:pattern (Seq.index s2 i)} i < Seq.length s1 ==> Some? (Seq.index s1 i) ==> Some? (Seq.index s2 i))
type ubuffer (a:Type0) =
mbuffer (option a) (initialization_preorder a) (initialization_preorder a)
unfold let unull (#a:Type0) :ubuffer a = mnull #(option a) #(initialization_preorder a) #(initialization_preorder a)
unfold let gsub (#a:Type0) = mgsub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
unfold let gsub_inj (#a:Type0) = mgsub_inj #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a) (initialization_preorder a)
inline_for_extraction
type pointer (a:Type0) = b:ubuffer a{length b == 1}
inline_for_extraction
type pointer_or_null (a:Type0) = b:ubuffer a{if g_is_null b then True else length b == 1}
inline_for_extraction let usub (#a:Type0) = msub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
inline_for_extraction let uoffset (#a:Type0) = moffset #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
(****** main stateful API *****)
(*
* b `initialized_at` i: is a stable predicate that witnesses the initialization of an index i in ubuffer b
*)
private let ipred (#a:Type0) (i:nat) :spred (option a) = fun s -> i < Seq.length s ==> Some? (Seq.index s i)
let initialized_at (#a:Type0) (b:ubuffer a) (i:nat) :Type0 = witnessed b (ipred i)
(*
* Clients need to prove that b is initialized_at i
*)
let uindex (#a:Type0) (b:ubuffer a) (i:U32.t)
:HST.Stack a (requires (fun h0 -> live h0 b /\ U32.v i < length b /\ b `initialized_at` (U32.v i)))
(ensures (fun h0 y h1 -> let y_opt = Seq.index (as_seq h0 b) (U32.v i) in
Some? y_opt /\ y == Some?.v y_opt /\ h0 == h1))
= let y_opt = index b i in
recall_p b (ipred (U32.v i));
Some?.v y_opt
(*
* b `initialized_at` i is a postcondition
*)
let uupd (#a:Type0) (b:ubuffer a) (i:U32.t) (v:a)
:HST.Stack unit (requires (fun h0 -> live h0 b /\ U32.v i < length b))
(ensures (fun h0 _ h1 -> modifies (loc_buffer b) h0 h1 /\
live h1 b /\
as_seq h1 b == Seq.upd (as_seq h0 b) (U32.v i) (Some v) /\
b `initialized_at` (U32.v i)))
= upd b i (Some v);
witness_p b (ipred (U32.v i))
unfold let lubuffer (a:Type0) (len:nat) = b:ubuffer a{length b == len} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.UninitializedBuffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type0 -> len: Prims.nat -> r: FStar.Monotonic.HyperHeap.rid -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"FStar.Monotonic.HyperHeap.rid",
"LowStar.UninitializedBuffer.ubuffer",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_Negation",
"LowStar.Monotonic.Buffer.g_is_null",
"FStar.Pervasives.Native.option",
"LowStar.UninitializedBuffer.initialization_preorder",
"Prims.l_and",
"Prims.eq2",
"LowStar.Monotonic.Buffer.length",
"LowStar.Monotonic.Buffer.frameOf"
] | [] | false | false | false | true | true | let lubuffer_or_null (a: Type0) (len: nat) (r: HS.rid) =
| b: ubuffer a {(not (g_is_null b)) ==> (length b == len /\ frameOf b == r)} | false |
|
LowStar.UninitializedBuffer.fst | LowStar.UninitializedBuffer.initialized_at | val initialized_at (#a: Type0) (b: ubuffer a) (i: nat) : Type0 | val initialized_at (#a: Type0) (b: ubuffer a) (i: nat) : Type0 | let initialized_at (#a:Type0) (b:ubuffer a) (i:nat) :Type0 = witnessed b (ipred i) | {
"file_name": "ulib/LowStar.UninitializedBuffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 82,
"end_line": 63,
"start_col": 0,
"start_line": 63
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.UninitializedBuffer
include LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(*
* Uninitialized buffers
*
* Modeled as: seq (option a) with a preorder that an index once set remains set
*)
private let initialization_preorder (a:Type0) :srel (option a) =
fun s1 s2 -> Seq.length s1 == Seq.length s2 /\
(forall (i:nat).{:pattern (Seq.index s2 i)} i < Seq.length s1 ==> Some? (Seq.index s1 i) ==> Some? (Seq.index s2 i))
type ubuffer (a:Type0) =
mbuffer (option a) (initialization_preorder a) (initialization_preorder a)
unfold let unull (#a:Type0) :ubuffer a = mnull #(option a) #(initialization_preorder a) #(initialization_preorder a)
unfold let gsub (#a:Type0) = mgsub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
unfold let gsub_inj (#a:Type0) = mgsub_inj #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a) (initialization_preorder a)
inline_for_extraction
type pointer (a:Type0) = b:ubuffer a{length b == 1}
inline_for_extraction
type pointer_or_null (a:Type0) = b:ubuffer a{if g_is_null b then True else length b == 1}
inline_for_extraction let usub (#a:Type0) = msub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
inline_for_extraction let uoffset (#a:Type0) = moffset #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
(****** main stateful API *****)
(*
* b `initialized_at` i: is a stable predicate that witnesses the initialization of an index i in ubuffer b
*) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.UninitializedBuffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: LowStar.UninitializedBuffer.ubuffer a -> i: Prims.nat -> Type0 | Prims.Tot | [
"total"
] | [] | [
"LowStar.UninitializedBuffer.ubuffer",
"Prims.nat",
"LowStar.Monotonic.Buffer.witnessed",
"FStar.Pervasives.Native.option",
"LowStar.UninitializedBuffer.initialization_preorder",
"LowStar.UninitializedBuffer.ipred"
] | [] | false | false | false | true | true | let initialized_at (#a: Type0) (b: ubuffer a) (i: nat) : Type0 =
| witnessed b (ipred i) | false |
LowStar.UninitializedBuffer.fst | LowStar.UninitializedBuffer.gsub_inj | val gsub_inj : b1:
LowStar.Monotonic.Buffer.mbuffer (FStar.Pervasives.Native.option a)
(LowStar.UninitializedBuffer.initialization_preorder a)
(LowStar.UninitializedBuffer.initialization_preorder a) ->
b2:
LowStar.Monotonic.Buffer.mbuffer (FStar.Pervasives.Native.option a)
(LowStar.UninitializedBuffer.initialization_preorder a)
(LowStar.UninitializedBuffer.initialization_preorder a) ->
i1: FStar.UInt32.t ->
i2: FStar.UInt32.t ->
len1: FStar.UInt32.t ->
len2: FStar.UInt32.t
-> FStar.Pervasives.Lemma
(requires
FStar.UInt32.v i1 + FStar.UInt32.v len1 <= LowStar.Monotonic.Buffer.length b1 /\
FStar.UInt32.v i2 + FStar.UInt32.v len2 <= LowStar.Monotonic.Buffer.length b2 /\
LowStar.Monotonic.Buffer.mgsub (LowStar.UninitializedBuffer.initialization_preorder a)
b1
i1
len1 ===
LowStar.Monotonic.Buffer.mgsub (LowStar.UninitializedBuffer.initialization_preorder a)
b2
i2
len2)
(ensures
len1 == len2 /\ (b1 == b2 ==> i1 == i2) /\
(i1 == i2 /\ LowStar.Monotonic.Buffer.length b1 == LowStar.Monotonic.Buffer.length b2 ==>
b1 == b2)) | let gsub_inj (#a:Type0) = mgsub_inj #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a) (initialization_preorder a) | {
"file_name": "ulib/LowStar.UninitializedBuffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 168,
"end_line": 44,
"start_col": 7,
"start_line": 44
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.UninitializedBuffer
include LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(*
* Uninitialized buffers
*
* Modeled as: seq (option a) with a preorder that an index once set remains set
*)
private let initialization_preorder (a:Type0) :srel (option a) =
fun s1 s2 -> Seq.length s1 == Seq.length s2 /\
(forall (i:nat).{:pattern (Seq.index s2 i)} i < Seq.length s1 ==> Some? (Seq.index s1 i) ==> Some? (Seq.index s2 i))
type ubuffer (a:Type0) =
mbuffer (option a) (initialization_preorder a) (initialization_preorder a)
unfold let unull (#a:Type0) :ubuffer a = mnull #(option a) #(initialization_preorder a) #(initialization_preorder a)
unfold let gsub (#a:Type0) = mgsub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.UninitializedBuffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b1:
LowStar.Monotonic.Buffer.mbuffer (FStar.Pervasives.Native.option a)
(LowStar.UninitializedBuffer.initialization_preorder a)
(LowStar.UninitializedBuffer.initialization_preorder a) ->
b2:
LowStar.Monotonic.Buffer.mbuffer (FStar.Pervasives.Native.option a)
(LowStar.UninitializedBuffer.initialization_preorder a)
(LowStar.UninitializedBuffer.initialization_preorder a) ->
i1: FStar.UInt32.t ->
i2: FStar.UInt32.t ->
len1: FStar.UInt32.t ->
len2: FStar.UInt32.t
-> FStar.Pervasives.Lemma
(requires
FStar.UInt32.v i1 + FStar.UInt32.v len1 <= LowStar.Monotonic.Buffer.length b1 /\
FStar.UInt32.v i2 + FStar.UInt32.v len2 <= LowStar.Monotonic.Buffer.length b2 /\
LowStar.Monotonic.Buffer.mgsub (LowStar.UninitializedBuffer.initialization_preorder a)
b1
i1
len1 ===
LowStar.Monotonic.Buffer.mgsub (LowStar.UninitializedBuffer.initialization_preorder a)
b2
i2
len2)
(ensures
len1 == len2 /\ (b1 == b2 ==> i1 == i2) /\
(i1 == i2 /\ LowStar.Monotonic.Buffer.length b1 == LowStar.Monotonic.Buffer.length b2 ==>
b1 == b2)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowStar.Monotonic.Buffer.mgsub_inj",
"FStar.Pervasives.Native.option",
"LowStar.UninitializedBuffer.initialization_preorder",
"LowStar.Monotonic.Buffer.mbuffer",
"FStar.UInt32.t",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.UInt32.v",
"LowStar.Monotonic.Buffer.length",
"Prims.op_Equals_Equals_Equals",
"LowStar.Monotonic.Buffer.mgsub",
"Prims.squash",
"Prims.eq2",
"Prims.l_imp",
"Prims.nat",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let gsub_inj (#a: Type0) =
| mgsub_inj #(option a)
#(initialization_preorder a)
#(initialization_preorder a)
(initialization_preorder a)
(initialization_preorder a) | false |
|
Spec.Ed25519.PointOps.fst | Spec.Ed25519.PointOps.g_x | val g_x:elem | val g_x:elem | let g_x : elem = 15112221349535400772501151409588531511454012693041857206046113283949847762202 | {
"file_name": "specs/Spec.Ed25519.PointOps.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 94,
"end_line": 22,
"start_col": 0,
"start_line": 22
} | module Spec.Ed25519.PointOps
open FStar.Mul
open Spec.Curve25519
module BSeq = Lib.ByteSequence
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
type aff_point = elem & elem // Affine point
type ext_point = elem & elem & elem & elem // Homogeneous extended coordinates
(* 2 **% ((prime - 1) / 4) *)
let modp_sqrt_m1 : elem = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0
let d : elem =
let x = 37095705934669439343138083508754565189542113879843219016388785533085940283555 in
assert_norm(x < prime);
x | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Ed25519.PointOps.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Spec.Curve25519.elem | Prims.Tot | [
"total"
] | [] | [] | [] | false | false | false | true | false | let g_x:elem =
| 15112221349535400772501151409588531511454012693041857206046113283949847762202 | false |
LowStar.UninitializedBuffer.fst | LowStar.UninitializedBuffer.valid_j_for_blit | val valid_j_for_blit : src: LowStar.Monotonic.Buffer.mbuffer a rrel rel ->
idx_src: FStar.UInt32.t ->
dst: LowStar.UninitializedBuffer.ubuffer a ->
idx_dst: FStar.UInt32.t ->
j: FStar.UInt32.t
-> Prims.logical | let valid_j_for_blit
(#a:Type0) (#rrel #rel:srel a) (src:mbuffer a rrel rel) (idx_src:U32.t)
(dst:ubuffer a) (idx_dst:U32.t) (j:U32.t)
= U32.v idx_src + U32.v j <= length src /\
U32.v idx_dst + U32.v j <= length dst | {
"file_name": "ulib/LowStar.UninitializedBuffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 41,
"end_line": 137,
"start_col": 7,
"start_line": 133
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.UninitializedBuffer
include LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(*
* Uninitialized buffers
*
* Modeled as: seq (option a) with a preorder that an index once set remains set
*)
private let initialization_preorder (a:Type0) :srel (option a) =
fun s1 s2 -> Seq.length s1 == Seq.length s2 /\
(forall (i:nat).{:pattern (Seq.index s2 i)} i < Seq.length s1 ==> Some? (Seq.index s1 i) ==> Some? (Seq.index s2 i))
type ubuffer (a:Type0) =
mbuffer (option a) (initialization_preorder a) (initialization_preorder a)
unfold let unull (#a:Type0) :ubuffer a = mnull #(option a) #(initialization_preorder a) #(initialization_preorder a)
unfold let gsub (#a:Type0) = mgsub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
unfold let gsub_inj (#a:Type0) = mgsub_inj #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a) (initialization_preorder a)
inline_for_extraction
type pointer (a:Type0) = b:ubuffer a{length b == 1}
inline_for_extraction
type pointer_or_null (a:Type0) = b:ubuffer a{if g_is_null b then True else length b == 1}
inline_for_extraction let usub (#a:Type0) = msub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
inline_for_extraction let uoffset (#a:Type0) = moffset #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
(****** main stateful API *****)
(*
* b `initialized_at` i: is a stable predicate that witnesses the initialization of an index i in ubuffer b
*)
private let ipred (#a:Type0) (i:nat) :spred (option a) = fun s -> i < Seq.length s ==> Some? (Seq.index s i)
let initialized_at (#a:Type0) (b:ubuffer a) (i:nat) :Type0 = witnessed b (ipred i)
(*
* Clients need to prove that b is initialized_at i
*)
let uindex (#a:Type0) (b:ubuffer a) (i:U32.t)
:HST.Stack a (requires (fun h0 -> live h0 b /\ U32.v i < length b /\ b `initialized_at` (U32.v i)))
(ensures (fun h0 y h1 -> let y_opt = Seq.index (as_seq h0 b) (U32.v i) in
Some? y_opt /\ y == Some?.v y_opt /\ h0 == h1))
= let y_opt = index b i in
recall_p b (ipred (U32.v i));
Some?.v y_opt
(*
* b `initialized_at` i is a postcondition
*)
let uupd (#a:Type0) (b:ubuffer a) (i:U32.t) (v:a)
:HST.Stack unit (requires (fun h0 -> live h0 b /\ U32.v i < length b))
(ensures (fun h0 _ h1 -> modifies (loc_buffer b) h0 h1 /\
live h1 b /\
as_seq h1 b == Seq.upd (as_seq h0 b) (U32.v i) (Some v) /\
b `initialized_at` (U32.v i)))
= upd b i (Some v);
witness_p b (ipred (U32.v i))
unfold let lubuffer (a:Type0) (len:nat) = b:ubuffer a{length b == len}
unfold let lubuffer_or_null (a:Type0) (len:nat) (r:HS.rid) =
b:ubuffer a{(not (g_is_null b)) ==> (length b == len /\ frameOf b == r)}
(*
* No initializer
*)
let ugcmalloc (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer a (U32.v len){frameOf b == r /\ recallable b})
(requires (fun h0 -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mgcmalloc r None len
inline_for_extraction
let ugcmalloc_partial (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer_or_null a (U32.v len) r{recallable b})
(requires (fun h0 -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_partial_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mgcmalloc r None len
let umalloc (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer a (U32.v len){frameOf b == r /\ freeable b})
(requires (fun _ -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mmalloc r None len
inline_for_extraction
let umalloc_partial (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer_or_null a (U32.v len) r{(not (g_is_null b)) ==> freeable b})
(requires (fun _ -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_partial_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mmalloc r None len
let ualloca (#a:Type0) (len:U32.t)
:HST.StackInline (lubuffer a (U32.v len))
(requires (fun _ -> alloca_pre len))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) None) /\
frameOf b == HS.get_tip h0))
= malloca None len
(*
* blit functionality, where src is a regular buffer
*) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.UninitializedBuffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
src: LowStar.Monotonic.Buffer.mbuffer a rrel rel ->
idx_src: FStar.UInt32.t ->
dst: LowStar.UninitializedBuffer.ubuffer a ->
idx_dst: FStar.UInt32.t ->
j: FStar.UInt32.t
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"LowStar.Monotonic.Buffer.srel",
"LowStar.Monotonic.Buffer.mbuffer",
"FStar.UInt32.t",
"LowStar.UninitializedBuffer.ubuffer",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.UInt32.v",
"LowStar.Monotonic.Buffer.length",
"FStar.Pervasives.Native.option",
"LowStar.UninitializedBuffer.initialization_preorder",
"Prims.logical"
] | [] | false | false | false | false | true | let valid_j_for_blit
(#a: Type0)
(#rrel #rel: srel a)
(src: mbuffer a rrel rel)
(idx_src: U32.t)
(dst: ubuffer a)
(idx_dst j: U32.t)
=
| U32.v idx_src + U32.v j <= length src /\ U32.v idx_dst + U32.v j <= length dst | false |
|
LowStar.UninitializedBuffer.fst | LowStar.UninitializedBuffer.lubuffer | val lubuffer : a: Type0 -> len: Prims.nat -> Type0 | let lubuffer (a:Type0) (len:nat) = b:ubuffer a{length b == len} | {
"file_name": "ulib/LowStar.UninitializedBuffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 70,
"end_line": 88,
"start_col": 7,
"start_line": 88
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.UninitializedBuffer
include LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(*
* Uninitialized buffers
*
* Modeled as: seq (option a) with a preorder that an index once set remains set
*)
private let initialization_preorder (a:Type0) :srel (option a) =
fun s1 s2 -> Seq.length s1 == Seq.length s2 /\
(forall (i:nat).{:pattern (Seq.index s2 i)} i < Seq.length s1 ==> Some? (Seq.index s1 i) ==> Some? (Seq.index s2 i))
type ubuffer (a:Type0) =
mbuffer (option a) (initialization_preorder a) (initialization_preorder a)
unfold let unull (#a:Type0) :ubuffer a = mnull #(option a) #(initialization_preorder a) #(initialization_preorder a)
unfold let gsub (#a:Type0) = mgsub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
unfold let gsub_inj (#a:Type0) = mgsub_inj #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a) (initialization_preorder a)
inline_for_extraction
type pointer (a:Type0) = b:ubuffer a{length b == 1}
inline_for_extraction
type pointer_or_null (a:Type0) = b:ubuffer a{if g_is_null b then True else length b == 1}
inline_for_extraction let usub (#a:Type0) = msub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
inline_for_extraction let uoffset (#a:Type0) = moffset #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
(****** main stateful API *****)
(*
* b `initialized_at` i: is a stable predicate that witnesses the initialization of an index i in ubuffer b
*)
private let ipred (#a:Type0) (i:nat) :spred (option a) = fun s -> i < Seq.length s ==> Some? (Seq.index s i)
let initialized_at (#a:Type0) (b:ubuffer a) (i:nat) :Type0 = witnessed b (ipred i)
(*
* Clients need to prove that b is initialized_at i
*)
let uindex (#a:Type0) (b:ubuffer a) (i:U32.t)
:HST.Stack a (requires (fun h0 -> live h0 b /\ U32.v i < length b /\ b `initialized_at` (U32.v i)))
(ensures (fun h0 y h1 -> let y_opt = Seq.index (as_seq h0 b) (U32.v i) in
Some? y_opt /\ y == Some?.v y_opt /\ h0 == h1))
= let y_opt = index b i in
recall_p b (ipred (U32.v i));
Some?.v y_opt
(*
* b `initialized_at` i is a postcondition
*)
let uupd (#a:Type0) (b:ubuffer a) (i:U32.t) (v:a)
:HST.Stack unit (requires (fun h0 -> live h0 b /\ U32.v i < length b))
(ensures (fun h0 _ h1 -> modifies (loc_buffer b) h0 h1 /\
live h1 b /\
as_seq h1 b == Seq.upd (as_seq h0 b) (U32.v i) (Some v) /\
b `initialized_at` (U32.v i)))
= upd b i (Some v);
witness_p b (ipred (U32.v i)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.UninitializedBuffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type0 -> len: Prims.nat -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"LowStar.UninitializedBuffer.ubuffer",
"Prims.eq2",
"LowStar.Monotonic.Buffer.length",
"FStar.Pervasives.Native.option",
"LowStar.UninitializedBuffer.initialization_preorder"
] | [] | false | false | false | true | true | let lubuffer (a: Type0) (len: nat) =
| b: ubuffer a {length b == len} | false |
|
Spec.Ed25519.PointOps.fst | Spec.Ed25519.PointOps.is_on_curve | val is_on_curve : p: Spec.Ed25519.PointOps.aff_point -> Prims.logical | let is_on_curve (p:aff_point) =
let (x, y) = p in
y *% y -% x *% x == 1 +% d *% (x *% x) *% (y *% y) | {
"file_name": "specs/Spec.Ed25519.PointOps.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 52,
"end_line": 31,
"start_col": 0,
"start_line": 29
} | module Spec.Ed25519.PointOps
open FStar.Mul
open Spec.Curve25519
module BSeq = Lib.ByteSequence
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
type aff_point = elem & elem // Affine point
type ext_point = elem & elem & elem & elem // Homogeneous extended coordinates
(* 2 **% ((prime - 1) / 4) *)
let modp_sqrt_m1 : elem = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0
let d : elem =
let x = 37095705934669439343138083508754565189542113879843219016388785533085940283555 in
assert_norm(x < prime);
x
let g_x : elem = 15112221349535400772501151409588531511454012693041857206046113283949847762202
let g_y : elem = 46316835694926478169428394003475163141307993866256225615783033603165251855960
let aff_g : aff_point = (g_x, g_y)
let g: ext_point = (g_x, g_y, 1, g_x *% g_y) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Ed25519.PointOps.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Spec.Ed25519.PointOps.aff_point -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Spec.Ed25519.PointOps.aff_point",
"Spec.Curve25519.elem",
"Prims.eq2",
"Spec.Curve25519.op_Subtraction_Percent",
"Spec.Curve25519.op_Star_Percent",
"Spec.Curve25519.op_Plus_Percent",
"Spec.Ed25519.PointOps.d",
"Prims.logical"
] | [] | false | false | false | true | true | let is_on_curve (p: aff_point) =
| let x, y = p in
y *% y -% x *% x == 1 +% d *% (x *% x) *% (y *% y) | false |
|
Spec.Ed25519.PointOps.fst | Spec.Ed25519.PointOps.g | val g:ext_point | val g:ext_point | let g: ext_point = (g_x, g_y, 1, g_x *% g_y) | {
"file_name": "specs/Spec.Ed25519.PointOps.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 26,
"start_col": 0,
"start_line": 26
} | module Spec.Ed25519.PointOps
open FStar.Mul
open Spec.Curve25519
module BSeq = Lib.ByteSequence
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
type aff_point = elem & elem // Affine point
type ext_point = elem & elem & elem & elem // Homogeneous extended coordinates
(* 2 **% ((prime - 1) / 4) *)
let modp_sqrt_m1 : elem = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0
let d : elem =
let x = 37095705934669439343138083508754565189542113879843219016388785533085940283555 in
assert_norm(x < prime);
x
let g_x : elem = 15112221349535400772501151409588531511454012693041857206046113283949847762202
let g_y : elem = 46316835694926478169428394003475163141307993866256225615783033603165251855960 | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Ed25519.PointOps.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Spec.Ed25519.PointOps.ext_point | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.Mktuple4",
"Spec.Curve25519.elem",
"Spec.Ed25519.PointOps.g_x",
"Spec.Ed25519.PointOps.g_y",
"Spec.Curve25519.op_Star_Percent"
] | [] | false | false | false | true | false | let g:ext_point =
| (g_x, g_y, 1, g_x *% g_y) | false |
Vale.AES.X64.GCMencryptOpt.fsti | Vale.AES.X64.GCMencryptOpt.va_wp_Gcm_blocks_stdcall | val va_wp_Gcm_blocks_stdcall
(win: bool)
(alg: algorithm)
(auth_b: buffer128)
(auth_bytes auth_num: nat64)
(keys_b iv_b: buffer128)
(iv: supported_iv_LE)
(hkeys_b abytes_b in128x6_b out128x6_b: buffer128)
(len128x6_num: nat64)
(in128_b out128_b: buffer128)
(len128_num: nat64)
(inout_b: buffer128)
(plain_num: nat64)
(scratch_b tag_b: buffer128)
(key: (seq nat32))
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | val va_wp_Gcm_blocks_stdcall
(win: bool)
(alg: algorithm)
(auth_b: buffer128)
(auth_bytes auth_num: nat64)
(keys_b iv_b: buffer128)
(iv: supported_iv_LE)
(hkeys_b abytes_b in128x6_b out128x6_b: buffer128)
(len128x6_num: nat64)
(in128_b out128_b: buffer128)
(len128_num: nat64)
(inout_b: buffer128)
(plain_num: nat64)
(scratch_b tag_b: buffer128)
(key: (seq nat32))
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | let va_wp_Gcm_blocks_stdcall (win:bool) (alg:algorithm) (auth_b:buffer128) (auth_bytes:nat64)
(auth_num:nat64) (keys_b:buffer128) (iv_b:buffer128) (iv:supported_iv_LE) (hkeys_b:buffer128)
(abytes_b:buffer128) (in128x6_b:buffer128) (out128x6_b:buffer128) (len128x6_num:nat64)
(in128_b:buffer128) (out128_b:buffer128) (len128_num:nat64) (inout_b:buffer128) (plain_num:nat64)
(scratch_b:buffer128) (tag_b:buffer128) (key:(seq nat32)) (va_s0:va_state) (va_k:(va_state ->
unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (auth_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let
(auth_num_bytes:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx
va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (auth_len:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rR8 va_s0) (fun _ -> va_get_reg64
rRdx va_s0) in let (keys_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
va_get_reg64 rR9 va_s0) (fun _ -> va_get_reg64 rRcx va_s0) in let (iv_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 32 + 8 + 0) (va_get_stack va_s0)) (fun _ -> va_get_reg64 rR8 va_s0) in let
(xip:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0)) (fun _ -> va_get_reg64 rR9 va_s0)
in let (abytes_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 16) (va_get_stack va_s0)) (fun _
-> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) in let
(in128x6_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 24) (va_get_stack va_s0)) (fun _
-> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) in let
(out128x6_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 32) (va_get_stack va_s0)) (fun _
-> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 16) (va_get_stack va_s0)) in
let (len128x6:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 40) (va_get_stack va_s0)) (fun _
-> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 24) (va_get_stack va_s0)) in
let (in128_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 48) (va_get_stack va_s0)) (fun _
-> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 32) (va_get_stack va_s0)) in
let (out128_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 56) (va_get_stack va_s0)) (fun _
-> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 40) (va_get_stack va_s0)) in
let (len128:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 64) (va_get_stack va_s0)) (fun _
-> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 48) (va_get_stack va_s0)) in
let (inout_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 72) (va_get_stack va_s0)) (fun _
-> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 56) (va_get_stack va_s0)) in
let (plain_num_bytes:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 80) (va_get_stack va_s0)) (fun _
-> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 64) (va_get_stack va_s0)) in
let (scratch_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 88) (va_get_stack va_s0)) (fun _
-> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 72) (va_get_stack va_s0)) in
let (tag_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 96) (va_get_stack va_s0)) (fun _
-> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 80) (va_get_stack va_s0)) in
aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ sse_enabled /\ movbe_enabled /\
va_get_reg64 rRsp va_s0 == Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\
Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (~win ==>
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)
Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 16) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 8 + 24) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 32) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 8 + 40) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 48) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 8 + 56) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 64) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 8 + 72) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 80) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 40 + 0) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 8) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 40 + 16) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 24) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 40 + 32) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 40) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 40 + 48) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 56) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 40 + 64) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 72) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 40 + 80) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 88) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 40 + 96) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
auth_len == auth_num /\ auth_num_bytes == auth_bytes /\ len128x6 == len128x6_num /\ len128 ==
len128_num /\ plain_num_bytes == plain_num /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem
va_s0) auth_ptr auth_b auth_len (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) abytes_ptr abytes_b 1 (va_get_mem_layout
va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) iv_ptr iv_b 1
(va_get_mem_layout va_s0) Public /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0)
in128x6_ptr in128x6_b len128x6 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) out128x6_ptr out128x6_b len128x6
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0)
in128_ptr in128_b len128 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem va_s0) out128_ptr out128_b len128 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) inout_ptr inout_b 1 (va_get_mem_layout
va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) scratch_ptr scratch_b 9
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) xip
hkeys_b 8 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem
va_s0) tag_ptr tag_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.buffer_disjoints128
tag_b ([keys_b; auth_b; abytes_b; iv_b; in128x6_b; out128x6_b; in128_b; out128_b; inout_b;
scratch_b; hkeys_b]) /\ Vale.X64.Decls.buffer_disjoints128 iv_b ([keys_b; auth_b; abytes_b;
in128x6_b; out128x6_b; in128_b; out128_b; inout_b; scratch_b; hkeys_b]) /\
Vale.X64.Decls.buffer_disjoints128 scratch_b ([keys_b; auth_b; abytes_b; in128x6_b; out128x6_b;
in128_b; out128_b; inout_b; hkeys_b]) /\ Vale.X64.Decls.buffer_disjoints128 inout_b ([keys_b;
auth_b; abytes_b; in128x6_b; out128x6_b; in128_b; out128_b; hkeys_b]) /\
Vale.X64.Decls.buffer_disjoints128 auth_b ([keys_b; abytes_b; hkeys_b]) /\
Vale.X64.Decls.buffer_disjoints128 abytes_b ([keys_b; hkeys_b]) /\
Vale.X64.Decls.buffer_disjoints128 out128x6_b ([keys_b; auth_b; abytes_b; hkeys_b; in128_b;
inout_b]) /\ Vale.X64.Decls.buffer_disjoints128 in128x6_b ([keys_b; auth_b; abytes_b; hkeys_b;
in128_b; inout_b]) /\ Vale.X64.Decls.buffer_disjoints128 out128_b ([keys_b; auth_b; abytes_b;
hkeys_b; in128x6_b; out128x6_b; inout_b]) /\ Vale.X64.Decls.buffer_disjoints128 in128_b
([keys_b; auth_b; abytes_b; hkeys_b; in128x6_b; out128x6_b; inout_b]) /\
(Vale.X64.Decls.buffers_disjoint128 in128x6_b out128x6_b \/ in128x6_b == out128x6_b) /\
(Vale.X64.Decls.buffers_disjoint128 in128_b out128_b \/ in128_b == out128_b) /\ auth_ptr + 16
`op_Multiply` auth_len < pow2_64 /\ in128x6_ptr + 16 `op_Multiply` len128x6 < pow2_64 /\
out128x6_ptr + 16 `op_Multiply` len128x6 < pow2_64 /\ in128_ptr + 16 `op_Multiply` len128 <
pow2_64 /\ out128_ptr + 16 `op_Multiply` len128 < pow2_64 /\ inout_ptr + 16 < pow2_64 /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 auth_b == auth_len /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 abytes_b == 1 /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in128x6_b ==
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 out128x6_b /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in128_b == Vale.X64.Decls.buffer_length
#Vale.X64.Memory.vuint128 out128_b /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128
in128x6_b == len128x6 /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in128_b ==
len128 /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 inout_b == 1 /\
plain_num_bytes < pow2_32 /\ auth_num_bytes < pow2_32 /\ xip + 32 < pow2_64 /\
Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_b (va_get_mem va_s0) + 128 < pow2_64
/\ len128x6 `op_Modulus` 6 == 0 /\ (len128x6 > 0 ==> len128x6 >= 18) /\ 12 + len128x6 + 6 <
pow2_32 /\ (va_mul_nat len128x6 (128 `op_Division` 8) + va_mul_nat len128 (128 `op_Division` 8)
<= plain_num_bytes /\ plain_num_bytes < va_mul_nat len128x6 (128 `op_Division` 8) + va_mul_nat
len128 (128 `op_Division` 8) + 128 `op_Division` 8) /\ (va_mul_nat auth_len (128 `op_Division`
8) <= auth_num_bytes /\ auth_num_bytes < va_mul_nat auth_len (128 `op_Division` 8) + 128
`op_Division` 8) /\ (alg = AES_128 \/ alg = AES_256) /\ Vale.AES.AES_s.is_aes_key_LE alg key /\
Vale.X64.Decls.buffer128_as_seq (va_get_mem va_s0) keys_b ==
Vale.AES.AES_s.key_to_round_keys_LE alg key /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem
va_s0) keys_ptr keys_b (Vale.AES.AES_common_s.nr alg + 1) (va_get_mem_layout va_s0) Secret /\
Vale.AES.OptPublic.hkeys_reqs_pub (Vale.X64.Decls.s128 (va_get_mem va_s0) hkeys_b)
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE alg key
(Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0))) /\ (let h_LE =
Vale.AES.AES_s.aes_encrypt_LE alg key (Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0)
in let iv_BE = Vale.X64.Decls.buffer128_read iv_b 0 (va_get_mem va_s0) in iv_BE ==
Vale.AES.GCM_s.compute_iv_BE h_LE iv)) /\ (forall (va_x_mem:vale_heap) (va_x_rax:nat64)
(va_x_rbx:nat64) (va_x_rcx:nat64) (va_x_rdx:nat64) (va_x_rdi:nat64) (va_x_rsi:nat64)
(va_x_rsp:nat64) (va_x_rbp:nat64) (va_x_r8:nat64) (va_x_r9:nat64) (va_x_r10:nat64)
(va_x_r11:nat64) (va_x_r12:nat64) (va_x_r13:nat64) (va_x_r14:nat64) (va_x_r15:nat64)
(va_x_xmm0:quad32) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32) (va_x_xmm4:quad32)
(va_x_xmm5:quad32) (va_x_xmm6:quad32) (va_x_xmm7:quad32) (va_x_xmm8:quad32) (va_x_xmm9:quad32)
(va_x_xmm10:quad32) (va_x_xmm11:quad32) (va_x_xmm12:quad32) (va_x_xmm13:quad32)
(va_x_xmm14:quad32) (va_x_xmm15:quad32) (va_x_memLayout:vale_heap_layout)
(va_x_heap1:vale_heap) (va_x_heap2:vale_heap) (va_x_heap3:vale_heap) (va_x_heap4:vale_heap)
(va_x_heap5:vale_heap) (va_x_heap6:vale_heap) (va_x_efl:Vale.X64.Flags.t)
(va_x_stack:vale_stack) (va_x_stackTaint:memtaint) . let va_sM = va_upd_stackTaint
va_x_stackTaint (va_upd_stack va_x_stack (va_upd_flags va_x_efl (va_upd_mem_heaplet 6
va_x_heap6 (va_upd_mem_heaplet 5 va_x_heap5 (va_upd_mem_heaplet 4 va_x_heap4
(va_upd_mem_heaplet 3 va_x_heap3 (va_upd_mem_heaplet 2 va_x_heap2 (va_upd_mem_heaplet 1
va_x_heap1 (va_upd_mem_layout va_x_memLayout (va_upd_xmm 15 va_x_xmm15 (va_upd_xmm 14
va_x_xmm14 (va_upd_xmm 13 va_x_xmm13 (va_upd_xmm 12 va_x_xmm12 (va_upd_xmm 11 va_x_xmm11
(va_upd_xmm 10 va_x_xmm10 (va_upd_xmm 9 va_x_xmm9 (va_upd_xmm 8 va_x_xmm8 (va_upd_xmm 7
va_x_xmm7 (va_upd_xmm 6 va_x_xmm6 (va_upd_xmm 5 va_x_xmm5 (va_upd_xmm 4 va_x_xmm4 (va_upd_xmm 3
va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_xmm 0 va_x_xmm0 (va_upd_reg64
rR15 va_x_r15 (va_upd_reg64 rR14 va_x_r14 (va_upd_reg64 rR13 va_x_r13 (va_upd_reg64 rR12
va_x_r12 (va_upd_reg64 rR11 va_x_r11 (va_upd_reg64 rR10 va_x_r10 (va_upd_reg64 rR9 va_x_r9
(va_upd_reg64 rR8 va_x_r8 (va_upd_reg64 rRbp va_x_rbp (va_upd_reg64 rRsp va_x_rsp (va_upd_reg64
rRsi va_x_rsi (va_upd_reg64 rRdi va_x_rdi (va_upd_reg64 rRdx va_x_rdx (va_upd_reg64 rRcx
va_x_rcx (va_upd_reg64 rRbx va_x_rbx (va_upd_reg64 rRax va_x_rax (va_upd_mem va_x_mem
va_s0)))))))))))))))))))))))))))))))))))))))))) in va_get_ok va_sM /\ (let
(auth_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx va_s0)
(fun _ -> va_get_reg64 rRdi va_s0) in let (auth_num_bytes:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64
rRsi va_s0) in let (auth_len:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
va_get_reg64 rR8 va_s0) (fun _ -> va_get_reg64 rRdx va_s0) in let (keys_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rR9 va_s0) (fun _ -> va_get_reg64
rRcx va_s0) in let (iv_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0)) (fun
_ -> va_get_reg64 rR8 va_s0) in let (xip:(va_int_range 0 18446744073709551615)) = va_if win
(fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack
va_s0)) (fun _ -> va_get_reg64 rR9 va_s0) in let (abytes_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 40 + 16) (va_get_stack va_s0)) (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64
rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) in let (in128x6_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 40 + 24) (va_get_stack va_s0)) (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64
rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) in let (out128x6_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 40 + 32) (va_get_stack va_s0)) (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64
rRsp va_s0 + 8 + 16) (va_get_stack va_s0)) in let (len128x6:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 40 + 40) (va_get_stack va_s0)) (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64
rRsp va_s0 + 8 + 24) (va_get_stack va_s0)) in let (in128_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 40 + 48) (va_get_stack va_s0)) (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64
rRsp va_s0 + 8 + 32) (va_get_stack va_s0)) in let (out128_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 40 + 56) (va_get_stack va_s0)) (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64
rRsp va_s0 + 8 + 40) (va_get_stack va_s0)) in let (len128:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 40 + 64) (va_get_stack va_s0)) (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64
rRsp va_s0 + 8 + 48) (va_get_stack va_s0)) in let (inout_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 40 + 72) (va_get_stack va_s0)) (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64
rRsp va_s0 + 8 + 56) (va_get_stack va_s0)) in let (plain_num_bytes:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 40 + 80) (va_get_stack va_s0)) (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64
rRsp va_s0 + 8 + 64) (va_get_stack va_s0)) in let (scratch_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 40 + 88) (va_get_stack va_s0)) (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64
rRsp va_s0 + 8 + 72) (va_get_stack va_s0)) in let (tag_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 40 + 96) (va_get_stack va_s0)) (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64
rRsp va_s0 + 8 + 80) (va_get_stack va_s0)) in Vale.X64.Decls.modifies_mem
(Vale.X64.Decls.loc_union (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 tag_b)
(Vale.X64.Decls.loc_union (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 iv_b)
(Vale.X64.Decls.loc_union (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 scratch_b)
(Vale.X64.Decls.loc_union (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 out128x6_b)
(Vale.X64.Decls.loc_union (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 out128_b)
(Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 inout_b)))))) (va_get_mem va_s0)
(va_get_mem va_sM) /\ plain_num_bytes < pow2_32 /\ auth_num_bytes < pow2_32 /\ (let iv_BE =
Vale.X64.Decls.buffer128_read iv_b 0 (va_get_mem va_s0) in let auth_raw_quads =
FStar.Seq.Base.append #Vale.X64.Decls.quad32 (Vale.X64.Decls.s128 (va_get_mem va_s0) auth_b)
(Vale.X64.Decls.s128 (va_get_mem va_s0) abytes_b) in let auth_bytes = FStar.Seq.Base.slice
#Vale.Def.Types_s.nat8 (Vale.Def.Types_s.le_seq_quad32_to_bytes auth_raw_quads) 0
auth_num_bytes in let plain_raw_quads = FStar.Seq.Base.append #Vale.X64.Decls.quad32
(FStar.Seq.Base.append #Vale.X64.Decls.quad32 (Vale.X64.Decls.s128 (va_get_mem va_s0)
in128x6_b) (Vale.X64.Decls.s128 (va_get_mem va_s0) in128_b)) (Vale.X64.Decls.s128 (va_get_mem
va_s0) inout_b) in let plain_bytes = FStar.Seq.Base.slice #Vale.Def.Types_s.nat8
(Vale.Def.Types_s.le_seq_quad32_to_bytes plain_raw_quads) 0 plain_num_bytes in let
cipher_raw_quads = FStar.Seq.Base.append #Vale.X64.Decls.quad32 (FStar.Seq.Base.append
#Vale.X64.Decls.quad32 (Vale.X64.Decls.s128 (va_get_mem va_sM) out128x6_b) (Vale.X64.Decls.s128
(va_get_mem va_sM) out128_b)) (Vale.X64.Decls.s128 (va_get_mem va_sM) inout_b) in let
cipher_bytes = FStar.Seq.Base.slice #Vale.Def.Types_s.nat8
(Vale.Def.Types_s.le_seq_quad32_to_bytes cipher_raw_quads) 0 plain_num_bytes in l_and (l_and
(l_and (l_and (FStar.Seq.Base.length #Vale.Def.Types_s.nat8 auth_bytes < pow2_32)
(FStar.Seq.Base.length #Vale.Def.Types_s.nat8 plain_bytes < pow2_32))
(Vale.AES.AES_common_s.is_aes_key alg (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE key)))
(cipher_bytes == __proj__Mktuple2__item___1 #(FStar.Seq.Base.seq Vale.Def.Types_s.nat8)
#(FStar.Seq.Base.seq Vale.Def.Types_s.nat8) (Vale.AES.GCM_s.gcm_encrypt_LE alg
(Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)))
(Vale.Def.Types_s.le_quad32_to_bytes (Vale.X64.Decls.buffer128_read tag_b 0 (va_get_mem va_sM))
== __proj__Mktuple2__item___2 #(FStar.Seq.Base.seq Vale.Def.Types_s.nat8) #(FStar.Seq.Base.seq
Vale.Def.Types_s.nat8) (Vale.AES.GCM_s.gcm_encrypt_LE alg
(Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)) /\ va_get_reg64
rRsp va_sM == va_get_reg64 rRsp va_s0 /\ (win ==> va_get_reg64 rRbx va_sM == va_get_reg64 rRbx
va_s0) /\ (win ==> va_get_reg64 rRbp va_sM == va_get_reg64 rRbp va_s0) /\ (win ==> va_get_reg64
rRdi va_sM == va_get_reg64 rRdi va_s0) /\ (win ==> va_get_reg64 rRsi va_sM == va_get_reg64 rRsi
va_s0) /\ (win ==> va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0) /\ (win ==> va_get_reg64
rR13 va_sM == va_get_reg64 rR13 va_s0) /\ (win ==> va_get_reg64 rR14 va_sM == va_get_reg64 rR14
va_s0) /\ (win ==> va_get_reg64 rR15 va_sM == va_get_reg64 rR15 va_s0) /\ (win ==> va_get_xmm 6
va_sM == va_get_xmm 6 va_s0) /\ (win ==> va_get_xmm 7 va_sM == va_get_xmm 7 va_s0) /\ (win ==>
va_get_xmm 8 va_sM == va_get_xmm 8 va_s0) /\ (win ==> va_get_xmm 9 va_sM == va_get_xmm 9 va_s0)
/\ (win ==> va_get_xmm 10 va_sM == va_get_xmm 10 va_s0) /\ (win ==> va_get_xmm 11 va_sM ==
va_get_xmm 11 va_s0) /\ (win ==> va_get_xmm 12 va_sM == va_get_xmm 12 va_s0) /\ (win ==>
va_get_xmm 13 va_sM == va_get_xmm 13 va_s0) /\ (win ==> va_get_xmm 14 va_sM == va_get_xmm 14
va_s0) /\ (win ==> va_get_xmm 15 va_sM == va_get_xmm 15 va_s0) /\ (~win ==> va_get_reg64 rRbx
va_sM == va_get_reg64 rRbx va_s0) /\ (~win ==> va_get_reg64 rRbp va_sM == va_get_reg64 rRbp
va_s0) /\ (~win ==> va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0) /\ (~win ==>
va_get_reg64 rR13 va_sM == va_get_reg64 rR13 va_s0) /\ (~win ==> va_get_reg64 rR14 va_sM ==
va_get_reg64 rR14 va_s0) /\ (~win ==> va_get_reg64 rR15 va_sM == va_get_reg64 rR15 va_s0))) ==>
va_k va_sM (()))) | {
"file_name": "obj/Vale.AES.X64.GCMencryptOpt.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 21,
"end_line": 1492,
"start_col": 0,
"start_line": 1229
} | module Vale.AES.X64.GCMencryptOpt
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.AES.AES_s
open Vale.AES.GCTR_s
open Vale.AES.GCTR
open Vale.AES.GCM
open Vale.AES.GHash_s
open Vale.AES.GHash
open Vale.AES.GCM_s
open Vale.AES.X64.AES
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.Poly1305.Math
open Vale.AES.GCM_helpers
open Vale.AES.X64.GHash
open Vale.AES.X64.GCTR
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.Stack_i
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.InsStack
open Vale.X64.InsAes
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.AES.X64.GF128_Mul
open Vale.X64.Stack
open Vale.X64.CPU_Features_s
open Vale.Math.Poly2.Bits_s
open Vale.AES.X64.AESopt
open Vale.AES.X64.AESGCM
open Vale.AES.X64.AESopt2
open Vale.Lib.Meta
open Vale.AES.OptPublic
let aes_reqs
(alg:algorithm) (key:seq nat32) (round_keys:seq quad32) (keys_b:buffer128)
(key_ptr:int) (heap0:vale_heap) (layout:vale_heap_layout) : prop0
=
aesni_enabled /\ avx_enabled /\
(alg = AES_128 \/ alg = AES_256) /\
is_aes_key_LE alg key /\
length(round_keys) == nr(alg) + 1 /\
round_keys == key_to_round_keys_LE alg key /\
validSrcAddrs128 heap0 key_ptr keys_b (nr alg + 1) layout Secret /\
s128 heap0 keys_b == round_keys
//-- Gctr_register
val va_code_Gctr_register : alg:algorithm -> Tot va_code
val va_codegen_success_Gctr_register : alg:algorithm -> Tot va_pbool
val va_lemma_Gctr_register : va_b0:va_code -> va_s0:va_state -> alg:algorithm -> key:(seq nat32) ->
round_keys:(seq quad32) -> keys_b:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Gctr_register alg) va_s0 /\ va_get_ok va_s0 /\
(sse_enabled /\ va_get_xmm 9 va_s0 == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 202182159
134810123 67438087 66051 /\ aes_reqs alg key round_keys keys_b (va_get_reg64 rR8 va_s0)
(va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0))))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(Vale.Def.Types_s.le_seq_quad32_to_bytes (FStar.Seq.Base.create #quad32 1 (va_get_xmm 8 va_sM))
== Vale.AES.GCTR_s.gctr_encrypt_LE (va_get_xmm 0 va_s0) (Vale.Def.Types_s.le_quad32_to_bytes
(Vale.Def.Types_s.reverse_bytes_quad32 (va_get_xmm 8 va_s0))) alg key /\ va_get_xmm 8 va_sM ==
Vale.AES.GCTR_s.gctr_encrypt_block (va_get_xmm 0 va_s0) (Vale.Def.Types_s.reverse_bytes_quad32
(va_get_xmm 8 va_s0)) alg key 0) /\ va_state_eq va_sM (va_update_reg64 rR12 va_sM
(va_update_flags va_sM (va_update_xmm 8 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM
(va_update_xmm 0 va_sM (va_update_ok va_sM va_s0)))))))))
[@ va_qattr]
let va_wp_Gctr_register (alg:algorithm) (key:(seq nat32)) (round_keys:(seq quad32))
(keys_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (sse_enabled /\ va_get_xmm 9 va_s0 == Vale.Def.Words_s.Mkfour
#Vale.Def.Types_s.nat32 202182159 134810123 67438087 66051 /\ aes_reqs alg key round_keys
keys_b (va_get_reg64 rR8 va_s0) (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0)) /\
(forall (va_x_xmm0:quad32) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm8:quad32)
(va_x_efl:Vale.X64.Flags.t) (va_x_r12:nat64) . let va_sM = va_upd_reg64 rR12 va_x_r12
(va_upd_flags va_x_efl (va_upd_xmm 8 va_x_xmm8 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1
(va_upd_xmm 0 va_x_xmm0 va_s0))))) in va_get_ok va_sM /\
(Vale.Def.Types_s.le_seq_quad32_to_bytes (FStar.Seq.Base.create #quad32 1 (va_get_xmm 8 va_sM))
== Vale.AES.GCTR_s.gctr_encrypt_LE (va_get_xmm 0 va_s0) (Vale.Def.Types_s.le_quad32_to_bytes
(Vale.Def.Types_s.reverse_bytes_quad32 (va_get_xmm 8 va_s0))) alg key /\ va_get_xmm 8 va_sM ==
Vale.AES.GCTR_s.gctr_encrypt_block (va_get_xmm 0 va_s0) (Vale.Def.Types_s.reverse_bytes_quad32
(va_get_xmm 8 va_s0)) alg key 0) ==> va_k va_sM (())))
val va_wpProof_Gctr_register : alg:algorithm -> key:(seq nat32) -> round_keys:(seq quad32) ->
keys_b:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Gctr_register alg key round_keys keys_b va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Gctr_register alg) ([va_Mod_reg64
rR12; va_Mod_flags; va_Mod_xmm 8; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0]) va_s0 va_k
((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_Gctr_register (alg:algorithm) (key:(seq nat32)) (round_keys:(seq quad32))
(keys_b:buffer128) : (va_quickCode unit (va_code_Gctr_register alg)) =
(va_QProc (va_code_Gctr_register alg) ([va_Mod_reg64 rR12; va_Mod_flags; va_Mod_xmm 8; va_Mod_xmm
2; va_Mod_xmm 1; va_Mod_xmm 0]) (va_wp_Gctr_register alg key round_keys keys_b)
(va_wpProof_Gctr_register alg key round_keys keys_b))
//--
//-- Gctr_blocks128
val va_code_Gctr_blocks128 : alg:algorithm -> Tot va_code
val va_codegen_success_Gctr_blocks128 : alg:algorithm -> Tot va_pbool
val va_lemma_Gctr_blocks128 : va_b0:va_code -> va_s0:va_state -> alg:algorithm -> in_b:buffer128 ->
out_b:buffer128 -> key:(seq nat32) -> round_keys:(seq quad32) -> keys_b:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Gctr_blocks128 alg) va_s0 /\ va_get_ok va_s0 /\
(sse_enabled /\ (Vale.X64.Decls.buffers_disjoint128 in_b out_b \/ in_b == out_b) /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg64 rRax va_s0) in_b
(va_get_reg64 rRdx va_s0) (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_s0) (va_get_reg64 rRdi va_s0) out_b (va_get_reg64 rRdx va_s0)
(va_get_mem_layout va_s0) Secret /\ va_get_reg64 rRax va_s0 + 16 `op_Multiply` va_get_reg64
rRdx va_s0 < pow2_64 /\ va_get_reg64 rRdi va_s0 + 16 `op_Multiply` va_get_reg64 rRdx va_s0 <
pow2_64 /\ l_and (Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in_b ==
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 out_b) (Vale.X64.Decls.buffer_length
#Vale.X64.Memory.vuint128 in_b < pow2_32) /\ va_get_reg64 rRdx va_s0 ==
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in_b /\ va_get_xmm 9 va_s0 ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 202182159 134810123 67438087 66051 /\
va_get_reg64 rRdx va_s0 < pow2_32 /\ aes_reqs alg key round_keys keys_b (va_get_reg64 rR8
va_s0) (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0) /\ pclmulqdq_enabled)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(Vale.X64.Decls.modifies_buffer128 out_b (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1
va_sM) /\ Vale.AES.GCTR.gctr_partial alg (va_get_reg64 rRdx va_sM) (Vale.X64.Decls.s128
(va_get_mem_heaplet 1 va_s0) in_b) (Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_sM) out_b) key
(va_get_xmm 11 va_s0) /\ va_get_xmm 11 va_sM == Vale.AES.GCTR.inc32lite (va_get_xmm 11 va_s0)
(va_get_reg64 rRdx va_s0) /\ (va_get_reg64 rRdx va_sM == 0 ==> Vale.X64.Decls.s128
(va_get_mem_heaplet 1 va_sM) out_b == Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_s0) out_b))
/\ va_state_eq va_sM (va_update_flags va_sM (va_update_mem_heaplet 1 va_sM (va_update_xmm 10
va_sM (va_update_xmm 11 va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 4
va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0
va_sM (va_update_reg64 rR10 va_sM (va_update_reg64 rR11 va_sM (va_update_reg64 rRbx va_sM
(va_update_ok va_sM (va_update_mem va_sM va_s0))))))))))))))))))
[@ va_qattr]
let va_wp_Gctr_blocks128 (alg:algorithm) (in_b:buffer128) (out_b:buffer128) (key:(seq nat32))
(round_keys:(seq quad32)) (keys_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0))
: Type0 =
(va_get_ok va_s0 /\ (sse_enabled /\ (Vale.X64.Decls.buffers_disjoint128 in_b out_b \/ in_b ==
out_b) /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg64 rRax
va_s0) in_b (va_get_reg64 rRdx va_s0) (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg64 rRdi va_s0) out_b
(va_get_reg64 rRdx va_s0) (va_get_mem_layout va_s0) Secret /\ va_get_reg64 rRax va_s0 + 16
`op_Multiply` va_get_reg64 rRdx va_s0 < pow2_64 /\ va_get_reg64 rRdi va_s0 + 16 `op_Multiply`
va_get_reg64 rRdx va_s0 < pow2_64 /\ l_and (Vale.X64.Decls.buffer_length
#Vale.X64.Memory.vuint128 in_b == Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 out_b)
(Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in_b < pow2_32) /\ va_get_reg64 rRdx
va_s0 == Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in_b /\ va_get_xmm 9 va_s0 ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 202182159 134810123 67438087 66051 /\
va_get_reg64 rRdx va_s0 < pow2_32 /\ aes_reqs alg key round_keys keys_b (va_get_reg64 rR8
va_s0) (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0) /\ pclmulqdq_enabled) /\ (forall
(va_x_mem:vale_heap) (va_x_rbx:nat64) (va_x_r11:nat64) (va_x_r10:nat64) (va_x_xmm0:quad32)
(va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32) (va_x_xmm4:quad32) (va_x_xmm5:quad32)
(va_x_xmm6:quad32) (va_x_xmm11:quad32) (va_x_xmm10:quad32) (va_x_heap1:vale_heap)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_mem_heaplet 1
va_x_heap1 (va_upd_xmm 10 va_x_xmm10 (va_upd_xmm 11 va_x_xmm11 (va_upd_xmm 6 va_x_xmm6
(va_upd_xmm 5 va_x_xmm5 (va_upd_xmm 4 va_x_xmm4 (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2
(va_upd_xmm 1 va_x_xmm1 (va_upd_xmm 0 va_x_xmm0 (va_upd_reg64 rR10 va_x_r10 (va_upd_reg64 rR11
va_x_r11 (va_upd_reg64 rRbx va_x_rbx (va_upd_mem va_x_mem va_s0)))))))))))))) in va_get_ok
va_sM /\ (Vale.X64.Decls.modifies_buffer128 out_b (va_get_mem_heaplet 1 va_s0)
(va_get_mem_heaplet 1 va_sM) /\ Vale.AES.GCTR.gctr_partial alg (va_get_reg64 rRdx va_sM)
(Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_s0) in_b) (Vale.X64.Decls.s128
(va_get_mem_heaplet 1 va_sM) out_b) key (va_get_xmm 11 va_s0) /\ va_get_xmm 11 va_sM ==
Vale.AES.GCTR.inc32lite (va_get_xmm 11 va_s0) (va_get_reg64 rRdx va_s0) /\ (va_get_reg64 rRdx
va_sM == 0 ==> Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_sM) out_b == Vale.X64.Decls.s128
(va_get_mem_heaplet 1 va_s0) out_b)) ==> va_k va_sM (())))
val va_wpProof_Gctr_blocks128 : alg:algorithm -> in_b:buffer128 -> out_b:buffer128 -> key:(seq
nat32) -> round_keys:(seq quad32) -> keys_b:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit
-> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Gctr_blocks128 alg in_b out_b key round_keys keys_b va_s0
va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Gctr_blocks128 alg) ([va_Mod_flags;
va_Mod_mem_heaplet 1; va_Mod_xmm 10; va_Mod_xmm 11; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4;
va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR10; va_Mod_reg64 rR11;
va_Mod_reg64 rRbx; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_Gctr_blocks128 (alg:algorithm) (in_b:buffer128) (out_b:buffer128) (key:(seq nat32))
(round_keys:(seq quad32)) (keys_b:buffer128) : (va_quickCode unit (va_code_Gctr_blocks128 alg)) =
(va_QProc (va_code_Gctr_blocks128 alg) ([va_Mod_flags; va_Mod_mem_heaplet 1; va_Mod_xmm 10;
va_Mod_xmm 11; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm
1; va_Mod_xmm 0; va_Mod_reg64 rR10; va_Mod_reg64 rR11; va_Mod_reg64 rRbx; va_Mod_mem])
(va_wp_Gctr_blocks128 alg in_b out_b key round_keys keys_b) (va_wpProof_Gctr_blocks128 alg in_b
out_b key round_keys keys_b))
//--
//-- Gcm_make_length_quad
val va_code_Gcm_make_length_quad : va_dummy:unit -> Tot va_code
val va_codegen_success_Gcm_make_length_quad : va_dummy:unit -> Tot va_pbool
val va_lemma_Gcm_make_length_quad : va_b0:va_code -> va_s0:va_state
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Gcm_make_length_quad ()) va_s0 /\ va_get_ok va_s0 /\
(sse_enabled /\ 8 `op_Multiply` va_get_reg64 rR13 va_s0 < pow2_64 /\ 8 `op_Multiply`
va_get_reg64 rR11 va_s0 < pow2_64)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (8
`op_Multiply` va_get_reg64 rR13 va_s0 < pow2_64 /\ 8 `op_Multiply` va_get_reg64 rR11 va_s0 <
pow2_64 /\ va_get_xmm 0 va_sM == Vale.Def.Types_s.insert_nat64 (Vale.Def.Types_s.insert_nat64
(Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0) (8 `op_Multiply` va_get_reg64 rR11
va_s0) 1) (8 `op_Multiply` va_get_reg64 rR13 va_s0) 0) /\ va_state_eq va_sM (va_update_flags
va_sM (va_update_reg64 rRax va_sM (va_update_xmm 0 va_sM (va_update_ok va_sM va_s0))))))
[@ va_qattr]
let va_wp_Gcm_make_length_quad (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (sse_enabled /\ 8 `op_Multiply` va_get_reg64 rR13 va_s0 < pow2_64 /\ 8
`op_Multiply` va_get_reg64 rR11 va_s0 < pow2_64) /\ (forall (va_x_xmm0:quad32) (va_x_rax:nat64)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_reg64 rRax va_x_rax
(va_upd_xmm 0 va_x_xmm0 va_s0)) in va_get_ok va_sM /\ (8 `op_Multiply` va_get_reg64 rR13 va_s0
< pow2_64 /\ 8 `op_Multiply` va_get_reg64 rR11 va_s0 < pow2_64 /\ va_get_xmm 0 va_sM ==
Vale.Def.Types_s.insert_nat64 (Vale.Def.Types_s.insert_nat64 (Vale.Def.Words_s.Mkfour
#Vale.Def.Types_s.nat32 0 0 0 0) (8 `op_Multiply` va_get_reg64 rR11 va_s0) 1) (8 `op_Multiply`
va_get_reg64 rR13 va_s0) 0) ==> va_k va_sM (())))
val va_wpProof_Gcm_make_length_quad : va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Gcm_make_length_quad va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Gcm_make_length_quad ())
([va_Mod_flags; va_Mod_reg64 rRax; va_Mod_xmm 0]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_Gcm_make_length_quad () : (va_quickCode unit (va_code_Gcm_make_length_quad ())) =
(va_QProc (va_code_Gcm_make_length_quad ()) ([va_Mod_flags; va_Mod_reg64 rRax; va_Mod_xmm 0])
va_wp_Gcm_make_length_quad va_wpProof_Gcm_make_length_quad)
//--
//-- Ghash_extra_bytes
val va_code_Ghash_extra_bytes : va_dummy:unit -> Tot va_code
val va_codegen_success_Ghash_extra_bytes : va_dummy:unit -> Tot va_pbool
val va_lemma_Ghash_extra_bytes : va_b0:va_code -> va_s0:va_state -> hkeys_b:buffer128 ->
total_bytes:nat -> old_hash:quad32 -> h_LE:quad32 -> completed_quads:(seq quad32)
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Ghash_extra_bytes ()) va_s0 /\ va_get_ok va_s0 /\
(pclmulqdq_enabled /\ avx_enabled /\ sse_enabled /\ va_get_xmm 9 va_s0 ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 202182159 134810123 67438087 66051 /\
va_get_xmm 8 va_s0 == Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.GHash.ghash_incremental0
h_LE old_hash completed_quads) /\ Vale.AES.GHash.hkeys_reqs_priv (Vale.X64.Decls.s128
(va_get_mem_heaplet 0 va_s0) hkeys_b) (Vale.Def.Types_s.reverse_bytes_quad32 h_LE) /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg64 rR9 va_s0 - 32)
hkeys_b 8 (va_get_mem_layout va_s0) Secret /\ FStar.Seq.Base.length #quad32 completed_quads ==
total_bytes `op_Division` 16 /\ total_bytes < 16 `op_Multiply` FStar.Seq.Base.length #quad32
completed_quads + 16 /\ va_get_reg64 rR10 va_s0 == total_bytes `op_Modulus` 16 /\ total_bytes
`op_Modulus` 16 =!= 0 /\ (0 < total_bytes /\ total_bytes < 16 `op_Multiply`
Vale.AES.GCM_helpers.bytes_to_quad_size total_bytes) /\ 16 `op_Multiply`
(Vale.AES.GCM_helpers.bytes_to_quad_size total_bytes - 1) < total_bytes)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let raw_quads = FStar.Seq.Base.append #quad32 completed_quads (FStar.Seq.Base.create #quad32 1
(va_get_xmm 0 va_s0)) in let input_bytes = FStar.Seq.Base.slice #Vale.Def.Types_s.nat8
(Vale.Def.Types_s.le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let padded_bytes =
Vale.AES.GCTR_s.pad_to_128_bits input_bytes in let input_quads =
Vale.Def.Types_s.le_bytes_to_seq_quad32 padded_bytes in total_bytes > 0 ==> l_and
(FStar.Seq.Base.length #Vale.Def.Types_s.quad32 input_quads > 0)
(Vale.Def.Types_s.reverse_bytes_quad32 (va_get_xmm 8 va_sM) == Vale.AES.GHash.ghash_incremental
h_LE old_hash input_quads)) /\ va_state_eq va_sM (va_update_flags va_sM (va_update_xmm 8 va_sM
(va_update_xmm 7 va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM
(va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM
(va_update_reg64 rR11 va_sM (va_update_reg64 rRcx va_sM (va_update_ok va_sM va_s0)))))))))))))))
[@ va_qattr]
let va_wp_Ghash_extra_bytes (hkeys_b:buffer128) (total_bytes:nat) (old_hash:quad32) (h_LE:quad32)
(completed_quads:(seq quad32)) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (pclmulqdq_enabled /\ avx_enabled /\ sse_enabled /\ va_get_xmm 9 va_s0 ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 202182159 134810123 67438087 66051 /\
va_get_xmm 8 va_s0 == Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.GHash.ghash_incremental0
h_LE old_hash completed_quads) /\ Vale.AES.GHash.hkeys_reqs_priv (Vale.X64.Decls.s128
(va_get_mem_heaplet 0 va_s0) hkeys_b) (Vale.Def.Types_s.reverse_bytes_quad32 h_LE) /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg64 rR9 va_s0 - 32)
hkeys_b 8 (va_get_mem_layout va_s0) Secret /\ FStar.Seq.Base.length #quad32 completed_quads ==
total_bytes `op_Division` 16 /\ total_bytes < 16 `op_Multiply` FStar.Seq.Base.length #quad32
completed_quads + 16 /\ va_get_reg64 rR10 va_s0 == total_bytes `op_Modulus` 16 /\ total_bytes
`op_Modulus` 16 =!= 0 /\ (0 < total_bytes /\ total_bytes < 16 `op_Multiply`
Vale.AES.GCM_helpers.bytes_to_quad_size total_bytes) /\ 16 `op_Multiply`
(Vale.AES.GCM_helpers.bytes_to_quad_size total_bytes - 1) < total_bytes) /\ (forall
(va_x_rcx:nat64) (va_x_r11:nat64) (va_x_xmm0:quad32) (va_x_xmm1:quad32) (va_x_xmm2:quad32)
(va_x_xmm3:quad32) (va_x_xmm4:quad32) (va_x_xmm5:quad32) (va_x_xmm6:quad32) (va_x_xmm7:quad32)
(va_x_xmm8:quad32) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_xmm
8 va_x_xmm8 (va_upd_xmm 7 va_x_xmm7 (va_upd_xmm 6 va_x_xmm6 (va_upd_xmm 5 va_x_xmm5 (va_upd_xmm
4 va_x_xmm4 (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_xmm
0 va_x_xmm0 (va_upd_reg64 rR11 va_x_r11 (va_upd_reg64 rRcx va_x_rcx va_s0))))))))))) in
va_get_ok va_sM /\ (let raw_quads = FStar.Seq.Base.append #quad32 completed_quads
(FStar.Seq.Base.create #quad32 1 (va_get_xmm 0 va_s0)) in let input_bytes =
FStar.Seq.Base.slice #Vale.Def.Types_s.nat8 (Vale.Def.Types_s.le_seq_quad32_to_bytes raw_quads)
0 total_bytes in let padded_bytes = Vale.AES.GCTR_s.pad_to_128_bits input_bytes in let
input_quads = Vale.Def.Types_s.le_bytes_to_seq_quad32 padded_bytes in total_bytes > 0 ==> l_and
(FStar.Seq.Base.length #Vale.Def.Types_s.quad32 input_quads > 0)
(Vale.Def.Types_s.reverse_bytes_quad32 (va_get_xmm 8 va_sM) == Vale.AES.GHash.ghash_incremental
h_LE old_hash input_quads)) ==> va_k va_sM (())))
val va_wpProof_Ghash_extra_bytes : hkeys_b:buffer128 -> total_bytes:nat -> old_hash:quad32 ->
h_LE:quad32 -> completed_quads:(seq quad32) -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Ghash_extra_bytes hkeys_b total_bytes old_hash h_LE
completed_quads va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Ghash_extra_bytes ()) ([va_Mod_flags;
va_Mod_xmm 8; va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm
2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR11; va_Mod_reg64 rRcx]) va_s0 va_k ((va_sM,
va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_Ghash_extra_bytes (hkeys_b:buffer128) (total_bytes:nat) (old_hash:quad32)
(h_LE:quad32) (completed_quads:(seq quad32)) : (va_quickCode unit (va_code_Ghash_extra_bytes ()))
=
(va_QProc (va_code_Ghash_extra_bytes ()) ([va_Mod_flags; va_Mod_xmm 8; va_Mod_xmm 7; va_Mod_xmm
6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0;
va_Mod_reg64 rR11; va_Mod_reg64 rRcx]) (va_wp_Ghash_extra_bytes hkeys_b total_bytes old_hash
h_LE completed_quads) (va_wpProof_Ghash_extra_bytes hkeys_b total_bytes old_hash h_LE
completed_quads))
//--
//-- Gcm_blocks_auth
val va_code_Gcm_blocks_auth : va_dummy:unit -> Tot va_code
val va_codegen_success_Gcm_blocks_auth : va_dummy:unit -> Tot va_pbool
val va_lemma_Gcm_blocks_auth : va_b0:va_code -> va_s0:va_state -> auth_b:buffer128 ->
abytes_b:buffer128 -> hkeys_b:buffer128 -> h_LE:quad32
-> Ghost (va_state & va_fuel & (seq quad32))
(requires (va_require_total va_b0 (va_code_Gcm_blocks_auth ()) va_s0 /\ va_get_ok va_s0 /\
(sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg64 rRdi
va_s0) auth_b (va_get_reg64 rRdx va_s0) (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 7 va_s0) (va_get_reg64 rRbx va_s0) abytes_b
1 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0
va_s0) (va_get_reg64 rR9 va_s0 - 32) hkeys_b 8 (va_get_mem_layout va_s0) Secret /\ va_get_reg64
rRdi va_s0 + 16 `op_Multiply` va_get_reg64 rRdx va_s0 < pow2_64 /\ Vale.X64.Decls.buffer_length
#Vale.X64.Memory.vuint128 auth_b == va_get_reg64 rRdx va_s0 /\ Vale.X64.Decls.buffer_length
#Vale.X64.Memory.vuint128 abytes_b == 1 /\ (va_mul_nat (va_get_reg64 rRdx va_s0) (128
`op_Division` 8) <= va_get_reg64 rRsi va_s0 /\ va_get_reg64 rRsi va_s0 < va_mul_nat
(va_get_reg64 rRdx va_s0) (128 `op_Division` 8) + 128 `op_Division` 8) /\ (pclmulqdq_enabled /\
avx_enabled) /\ Vale.AES.GHash.hkeys_reqs_priv (Vale.X64.Decls.s128 (va_get_mem_heaplet 0
va_s0) hkeys_b) (Vale.Def.Types_s.reverse_bytes_quad32 h_LE))))
(ensures (fun (va_sM, va_fM, auth_quad_seq) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\
va_get_ok va_sM /\ (va_get_reg64 rR15 va_sM == va_get_reg64 rRsi va_sM /\ va_get_xmm 9 va_sM ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 202182159 134810123 67438087 66051 /\ (let
(raw_auth_quads:(seq quad32)) = (if (va_get_reg64 rRsi va_s0 > va_get_reg64 rRdx va_s0
`op_Multiply` 128 `op_Division` 8) then FStar.Seq.Base.append #Vale.X64.Decls.quad32
(Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_sM) auth_b) (Vale.X64.Decls.s128
(va_get_mem_heaplet 7 va_s0) abytes_b) else Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_sM)
auth_b) in let (auth_input_bytes:(seq nat8)) = FStar.Seq.Base.slice #Vale.Def.Types_s.nat8
(Vale.Def.Types_s.le_seq_quad32_to_bytes raw_auth_quads) 0 (va_get_reg64 rRsi va_s0) in let
(padded_auth_bytes:(seq nat8)) = Vale.AES.GCTR_s.pad_to_128_bits auth_input_bytes in
auth_quad_seq == Vale.Def.Types_s.le_bytes_to_seq_quad32 padded_auth_bytes /\ va_get_xmm 8
va_sM == Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.GHash.ghash_incremental0 h_LE
(Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0) auth_quad_seq))) /\ va_state_eq va_sM
(va_update_xmm 9 va_sM (va_update_xmm 8 va_sM (va_update_xmm 7 va_sM (va_update_xmm 6 va_sM
(va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM
(va_update_xmm 1 va_sM (va_update_xmm 0 va_sM (va_update_flags va_sM (va_update_reg64 rR15
va_sM (va_update_reg64 rRcx va_sM (va_update_reg64 rR10 va_sM (va_update_reg64 rR11 va_sM
(va_update_reg64 rRdx va_sM (va_update_ok va_sM va_s0)))))))))))))))))))
[@ va_qattr]
let va_wp_Gcm_blocks_auth (auth_b:buffer128) (abytes_b:buffer128) (hkeys_b:buffer128) (h_LE:quad32)
(va_s0:va_state) (va_k:(va_state -> (seq quad32) -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 1 va_s0)
(va_get_reg64 rRdi va_s0) auth_b (va_get_reg64 rRdx va_s0) (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 7 va_s0) (va_get_reg64 rRbx va_s0) abytes_b
1 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0
va_s0) (va_get_reg64 rR9 va_s0 - 32) hkeys_b 8 (va_get_mem_layout va_s0) Secret /\ va_get_reg64
rRdi va_s0 + 16 `op_Multiply` va_get_reg64 rRdx va_s0 < pow2_64 /\ Vale.X64.Decls.buffer_length
#Vale.X64.Memory.vuint128 auth_b == va_get_reg64 rRdx va_s0 /\ Vale.X64.Decls.buffer_length
#Vale.X64.Memory.vuint128 abytes_b == 1 /\ (va_mul_nat (va_get_reg64 rRdx va_s0) (128
`op_Division` 8) <= va_get_reg64 rRsi va_s0 /\ va_get_reg64 rRsi va_s0 < va_mul_nat
(va_get_reg64 rRdx va_s0) (128 `op_Division` 8) + 128 `op_Division` 8) /\ (pclmulqdq_enabled /\
avx_enabled) /\ Vale.AES.GHash.hkeys_reqs_priv (Vale.X64.Decls.s128 (va_get_mem_heaplet 0
va_s0) hkeys_b) (Vale.Def.Types_s.reverse_bytes_quad32 h_LE)) /\ (forall (va_x_rdx:nat64)
(va_x_r11:nat64) (va_x_r10:nat64) (va_x_rcx:nat64) (va_x_r15:nat64) (va_x_efl:Vale.X64.Flags.t)
(va_x_xmm0:quad32) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32) (va_x_xmm4:quad32)
(va_x_xmm5:quad32) (va_x_xmm6:quad32) (va_x_xmm7:quad32) (va_x_xmm8:quad32) (va_x_xmm9:quad32)
(auth_quad_seq:(seq quad32)) . let va_sM = va_upd_xmm 9 va_x_xmm9 (va_upd_xmm 8 va_x_xmm8
(va_upd_xmm 7 va_x_xmm7 (va_upd_xmm 6 va_x_xmm6 (va_upd_xmm 5 va_x_xmm5 (va_upd_xmm 4 va_x_xmm4
(va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_xmm 0 va_x_xmm0
(va_upd_flags va_x_efl (va_upd_reg64 rR15 va_x_r15 (va_upd_reg64 rRcx va_x_rcx (va_upd_reg64
rR10 va_x_r10 (va_upd_reg64 rR11 va_x_r11 (va_upd_reg64 rRdx va_x_rdx va_s0))))))))))))))) in
va_get_ok va_sM /\ (va_get_reg64 rR15 va_sM == va_get_reg64 rRsi va_sM /\ va_get_xmm 9 va_sM ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 202182159 134810123 67438087 66051 /\ (let
(raw_auth_quads:(seq quad32)) = va_if (va_get_reg64 rRsi va_s0 > va_get_reg64 rRdx va_s0
`op_Multiply` 128 `op_Division` 8) (fun _ -> FStar.Seq.Base.append #Vale.X64.Decls.quad32
(Vale.X64.Decls.s128 (va_get_mem_heaplet 1 va_sM) auth_b) (Vale.X64.Decls.s128
(va_get_mem_heaplet 7 va_s0) abytes_b)) (fun _ -> Vale.X64.Decls.s128 (va_get_mem_heaplet 1
va_sM) auth_b) in let (auth_input_bytes:(seq nat8)) = FStar.Seq.Base.slice
#Vale.Def.Types_s.nat8 (Vale.Def.Types_s.le_seq_quad32_to_bytes raw_auth_quads) 0 (va_get_reg64
rRsi va_s0) in let (padded_auth_bytes:(seq nat8)) = Vale.AES.GCTR_s.pad_to_128_bits
auth_input_bytes in auth_quad_seq == Vale.Def.Types_s.le_bytes_to_seq_quad32 padded_auth_bytes
/\ va_get_xmm 8 va_sM == Vale.Def.Types_s.reverse_bytes_quad32
(Vale.AES.GHash.ghash_incremental0 h_LE (Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0
0) auth_quad_seq))) ==> va_k va_sM ((auth_quad_seq))))
val va_wpProof_Gcm_blocks_auth : auth_b:buffer128 -> abytes_b:buffer128 -> hkeys_b:buffer128 ->
h_LE:quad32 -> va_s0:va_state -> va_k:(va_state -> (seq quad32) -> Type0)
-> Ghost (va_state & va_fuel & (seq quad32))
(requires (va_t_require va_s0 /\ va_wp_Gcm_blocks_auth auth_b abytes_b hkeys_b h_LE va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Gcm_blocks_auth ()) ([va_Mod_xmm 9;
va_Mod_xmm 8; va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm
2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_flags; va_Mod_reg64 rR15; va_Mod_reg64 rRcx; va_Mod_reg64
rR10; va_Mod_reg64 rR11; va_Mod_reg64 rRdx]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_Gcm_blocks_auth (auth_b:buffer128) (abytes_b:buffer128) (hkeys_b:buffer128)
(h_LE:quad32) : (va_quickCode (seq quad32) (va_code_Gcm_blocks_auth ())) =
(va_QProc (va_code_Gcm_blocks_auth ()) ([va_Mod_xmm 9; va_Mod_xmm 8; va_Mod_xmm 7; va_Mod_xmm 6;
va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0;
va_Mod_flags; va_Mod_reg64 rR15; va_Mod_reg64 rRcx; va_Mod_reg64 rR10; va_Mod_reg64 rR11;
va_Mod_reg64 rRdx]) (va_wp_Gcm_blocks_auth auth_b abytes_b hkeys_b h_LE)
(va_wpProof_Gcm_blocks_auth auth_b abytes_b hkeys_b h_LE))
//--
//-- Save_registers
val va_code_Save_registers : win:bool -> Tot va_code
val va_codegen_success_Save_registers : win:bool -> Tot va_pbool
val va_lemma_Save_registers : va_b0:va_code -> va_s0:va_state -> win:bool
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Save_registers win) va_s0 /\ va_get_ok va_s0 /\
sse_enabled /\ va_get_reg64 rRsp va_s0 == Vale.X64.Stack_i.init_rsp (va_get_stack va_s0)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_get_reg64 rRsp va_sM == va_get_reg64 rRsp va_s0 - 8 `op_Multiply` (8 + (if win then (10
`op_Multiply` 2) else 0)) /\ Vale.X64.Stack_i.init_rsp (va_get_stack va_sM) ==
Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\ Vale.X64.Stack_i.valid_stack_slot64s
(va_get_reg64 rRsp va_sM) (8 + (if win then (10 `op_Multiply` 2) else 0)) (va_get_stack va_sM)
Secret (va_get_stackTaint va_sM) /\ Vale.X64.Stack_i.modifies_stack (va_get_reg64 rRsp va_sM)
(va_get_reg64 rRsp va_s0) (va_get_stack va_s0) (va_get_stack va_sM) /\
Vale.X64.Stack_i.modifies_stacktaint (va_get_reg64 rRsp va_sM) (va_get_reg64 rRsp va_s0)
(va_get_stackTaint va_s0) (va_get_stackTaint va_sM) /\ (win ==> Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_sM + 0) (va_get_stack va_sM) == Vale.Arch.Types.hi64 (va_get_xmm 6
va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 8) (va_get_stack
va_sM) == Vale.Arch.Types.lo64 (va_get_xmm 6 va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_sM + 16) (va_get_stack va_sM) == Vale.Arch.Types.hi64 (va_get_xmm 7
va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 24) (va_get_stack
va_sM) == Vale.Arch.Types.lo64 (va_get_xmm 7 va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_sM + 32) (va_get_stack va_sM) == Vale.Arch.Types.hi64 (va_get_xmm 8
va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 40) (va_get_stack
va_sM) == Vale.Arch.Types.lo64 (va_get_xmm 8 va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_sM + 48) (va_get_stack va_sM) == Vale.Arch.Types.hi64 (va_get_xmm 9
va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 56) (va_get_stack
va_sM) == Vale.Arch.Types.lo64 (va_get_xmm 9 va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_sM + 64) (va_get_stack va_sM) == Vale.Arch.Types.hi64 (va_get_xmm 10
va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 72) (va_get_stack
va_sM) == Vale.Arch.Types.lo64 (va_get_xmm 10 va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_sM + 80) (va_get_stack va_sM) == Vale.Arch.Types.hi64 (va_get_xmm 11
va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 88) (va_get_stack
va_sM) == Vale.Arch.Types.lo64 (va_get_xmm 11 va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_sM + 96) (va_get_stack va_sM) == Vale.Arch.Types.hi64 (va_get_xmm 12
va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 104) (va_get_stack
va_sM) == Vale.Arch.Types.lo64 (va_get_xmm 12 va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_sM + 112) (va_get_stack va_sM) == Vale.Arch.Types.hi64 (va_get_xmm 13
va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 120) (va_get_stack
va_sM) == Vale.Arch.Types.lo64 (va_get_xmm 13 va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_sM + 128) (va_get_stack va_sM) == Vale.Arch.Types.hi64 (va_get_xmm 14
va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 136) (va_get_stack
va_sM) == Vale.Arch.Types.lo64 (va_get_xmm 14 va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_sM + 144) (va_get_stack va_sM) == Vale.Arch.Types.hi64 (va_get_xmm 15
va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 152) (va_get_stack
va_sM) == Vale.Arch.Types.lo64 (va_get_xmm 15 va_sM)) /\ Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_sM + 0 + (if win then 160 else 0)) (va_get_stack va_sM) == va_get_reg64
rRbx va_sM /\ Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 8 + (if win then 160
else 0)) (va_get_stack va_sM) == va_get_reg64 rRbp va_sM /\ Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_sM + 16 + (if win then 160 else 0)) (va_get_stack va_sM) == va_get_reg64
rRdi va_sM /\ Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 24 + (if win then 160
else 0)) (va_get_stack va_sM) == va_get_reg64 rRsi va_sM /\ Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_sM + 32 + (if win then 160 else 0)) (va_get_stack va_sM) == va_get_reg64
rR12 va_sM /\ Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 40 + (if win then 160
else 0)) (va_get_stack va_sM) == va_get_reg64 rR13 va_sM /\ Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_sM + 48 + (if win then 160 else 0)) (va_get_stack va_sM) == va_get_reg64
rR14 va_sM /\ Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 56 + (if win then 160
else 0)) (va_get_stack va_sM) == va_get_reg64 rR15 va_sM /\ va_state_eq va_sM
(va_update_stackTaint va_sM (va_update_flags va_sM (va_update_stack va_sM (va_update_reg64 rRsp
va_sM (va_update_reg64 rRax va_sM (va_update_ok va_sM va_s0))))))))
[@ va_qattr]
let va_wp_Save_registers (win:bool) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ sse_enabled /\ va_get_reg64 rRsp va_s0 == Vale.X64.Stack_i.init_rsp
(va_get_stack va_s0) /\ (forall (va_x_rax:nat64) (va_x_rsp:nat64) (va_x_stack:vale_stack)
(va_x_efl:Vale.X64.Flags.t) (va_x_stackTaint:memtaint) . let va_sM = va_upd_stackTaint
va_x_stackTaint (va_upd_flags va_x_efl (va_upd_stack va_x_stack (va_upd_reg64 rRsp va_x_rsp
(va_upd_reg64 rRax va_x_rax va_s0)))) in va_get_ok va_sM /\ va_get_reg64 rRsp va_sM ==
va_get_reg64 rRsp va_s0 - 8 `op_Multiply` (8 + va_if win (fun _ -> 10 `op_Multiply` 2) (fun _
-> 0)) /\ Vale.X64.Stack_i.init_rsp (va_get_stack va_sM) == Vale.X64.Stack_i.init_rsp
(va_get_stack va_s0) /\ Vale.X64.Stack_i.valid_stack_slot64s (va_get_reg64 rRsp va_sM) (8 +
va_if win (fun _ -> 10 `op_Multiply` 2) (fun _ -> 0)) (va_get_stack va_sM) Secret
(va_get_stackTaint va_sM) /\ Vale.X64.Stack_i.modifies_stack (va_get_reg64 rRsp va_sM)
(va_get_reg64 rRsp va_s0) (va_get_stack va_s0) (va_get_stack va_sM) /\
Vale.X64.Stack_i.modifies_stacktaint (va_get_reg64 rRsp va_sM) (va_get_reg64 rRsp va_s0)
(va_get_stackTaint va_s0) (va_get_stackTaint va_sM) /\ (win ==> Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_sM + 0) (va_get_stack va_sM) == Vale.Arch.Types.hi64 (va_get_xmm 6
va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 8) (va_get_stack
va_sM) == Vale.Arch.Types.lo64 (va_get_xmm 6 va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_sM + 16) (va_get_stack va_sM) == Vale.Arch.Types.hi64 (va_get_xmm 7
va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 24) (va_get_stack
va_sM) == Vale.Arch.Types.lo64 (va_get_xmm 7 va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_sM + 32) (va_get_stack va_sM) == Vale.Arch.Types.hi64 (va_get_xmm 8
va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 40) (va_get_stack
va_sM) == Vale.Arch.Types.lo64 (va_get_xmm 8 va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_sM + 48) (va_get_stack va_sM) == Vale.Arch.Types.hi64 (va_get_xmm 9
va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 56) (va_get_stack
va_sM) == Vale.Arch.Types.lo64 (va_get_xmm 9 va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_sM + 64) (va_get_stack va_sM) == Vale.Arch.Types.hi64 (va_get_xmm 10
va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 72) (va_get_stack
va_sM) == Vale.Arch.Types.lo64 (va_get_xmm 10 va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_sM + 80) (va_get_stack va_sM) == Vale.Arch.Types.hi64 (va_get_xmm 11
va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 88) (va_get_stack
va_sM) == Vale.Arch.Types.lo64 (va_get_xmm 11 va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_sM + 96) (va_get_stack va_sM) == Vale.Arch.Types.hi64 (va_get_xmm 12
va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 104) (va_get_stack
va_sM) == Vale.Arch.Types.lo64 (va_get_xmm 12 va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_sM + 112) (va_get_stack va_sM) == Vale.Arch.Types.hi64 (va_get_xmm 13
va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 120) (va_get_stack
va_sM) == Vale.Arch.Types.lo64 (va_get_xmm 13 va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_sM + 128) (va_get_stack va_sM) == Vale.Arch.Types.hi64 (va_get_xmm 14
va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 136) (va_get_stack
va_sM) == Vale.Arch.Types.lo64 (va_get_xmm 14 va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_sM + 144) (va_get_stack va_sM) == Vale.Arch.Types.hi64 (va_get_xmm 15
va_sM)) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 152) (va_get_stack
va_sM) == Vale.Arch.Types.lo64 (va_get_xmm 15 va_sM)) /\ Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_sM + 0 + va_if win (fun _ -> 160) (fun _ -> 0)) (va_get_stack va_sM) ==
va_get_reg64 rRbx va_sM /\ Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 8 + va_if
win (fun _ -> 160) (fun _ -> 0)) (va_get_stack va_sM) == va_get_reg64 rRbp va_sM /\
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 16 + va_if win (fun _ -> 160) (fun _
-> 0)) (va_get_stack va_sM) == va_get_reg64 rRdi va_sM /\ Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_sM + 24 + va_if win (fun _ -> 160) (fun _ -> 0)) (va_get_stack va_sM) ==
va_get_reg64 rRsi va_sM /\ Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 32 + va_if
win (fun _ -> 160) (fun _ -> 0)) (va_get_stack va_sM) == va_get_reg64 rR12 va_sM /\
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 40 + va_if win (fun _ -> 160) (fun _
-> 0)) (va_get_stack va_sM) == va_get_reg64 rR13 va_sM /\ Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_sM + 48 + va_if win (fun _ -> 160) (fun _ -> 0)) (va_get_stack va_sM) ==
va_get_reg64 rR14 va_sM /\ Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_sM + 56 + va_if
win (fun _ -> 160) (fun _ -> 0)) (va_get_stack va_sM) == va_get_reg64 rR15 va_sM ==> va_k va_sM
(())))
val va_wpProof_Save_registers : win:bool -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Save_registers win va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Save_registers win)
([va_Mod_stackTaint; va_Mod_flags; va_Mod_stack; va_Mod_reg64 rRsp; va_Mod_reg64 rRax]) va_s0
va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_Save_registers (win:bool) : (va_quickCode unit (va_code_Save_registers win)) =
(va_QProc (va_code_Save_registers win) ([va_Mod_stackTaint; va_Mod_flags; va_Mod_stack;
va_Mod_reg64 rRsp; va_Mod_reg64 rRax]) (va_wp_Save_registers win) (va_wpProof_Save_registers
win))
//--
//-- Restore_registers
val va_code_Restore_registers : win:bool -> Tot va_code
val va_codegen_success_Restore_registers : win:bool -> Tot va_pbool
val va_lemma_Restore_registers : va_b0:va_code -> va_s0:va_state -> win:bool -> old_rsp:nat ->
old_xmm6:quad32 -> old_xmm7:quad32 -> old_xmm8:quad32 -> old_xmm9:quad32 -> old_xmm10:quad32 ->
old_xmm11:quad32 -> old_xmm12:quad32 -> old_xmm13:quad32 -> old_xmm14:quad32 -> old_xmm15:quad32
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Restore_registers win) va_s0 /\ va_get_ok va_s0 /\
sse_enabled /\ old_rsp == Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\
Vale.X64.Stack_i.valid_stack_slot64s (va_get_reg64 rRsp va_s0) (8 + (if win then (10
`op_Multiply` 2) else 0)) (va_get_stack va_s0) Secret (va_get_stackTaint va_s0) /\ va_get_reg64
rRsp va_s0 == old_rsp - 8 `op_Multiply` (8 + (if win then (10 `op_Multiply` 2) else 0)) /\ (win
==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 0) (va_get_stack va_s0) ==
Vale.Arch.Types.hi64 old_xmm6) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 8) (va_get_stack va_s0) == Vale.Arch.Types.lo64 old_xmm6) /\ (win ==>
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 16) (va_get_stack va_s0) ==
Vale.Arch.Types.hi64 old_xmm7) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 24) (va_get_stack va_s0) == Vale.Arch.Types.lo64 old_xmm7) /\ (win ==>
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32) (va_get_stack va_s0) ==
Vale.Arch.Types.hi64 old_xmm8) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 40) (va_get_stack va_s0) == Vale.Arch.Types.lo64 old_xmm8) /\ (win ==>
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 48) (va_get_stack va_s0) ==
Vale.Arch.Types.hi64 old_xmm9) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 56) (va_get_stack va_s0) == Vale.Arch.Types.lo64 old_xmm9) /\ (win ==>
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 64) (va_get_stack va_s0) ==
Vale.Arch.Types.hi64 old_xmm10) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 72) (va_get_stack va_s0) == Vale.Arch.Types.lo64 old_xmm10) /\ (win ==>
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 80) (va_get_stack va_s0) ==
Vale.Arch.Types.hi64 old_xmm11) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 88) (va_get_stack va_s0) == Vale.Arch.Types.lo64 old_xmm11) /\ (win ==>
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 96) (va_get_stack va_s0) ==
Vale.Arch.Types.hi64 old_xmm12) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 104) (va_get_stack va_s0) == Vale.Arch.Types.lo64 old_xmm12) /\ (win ==>
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 112) (va_get_stack va_s0) ==
Vale.Arch.Types.hi64 old_xmm13) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 120) (va_get_stack va_s0) == Vale.Arch.Types.lo64 old_xmm13) /\ (win ==>
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 128) (va_get_stack va_s0) ==
Vale.Arch.Types.hi64 old_xmm14) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 136) (va_get_stack va_s0) == Vale.Arch.Types.lo64 old_xmm14) /\ (win ==>
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 144) (va_get_stack va_s0) ==
Vale.Arch.Types.hi64 old_xmm15) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 152) (va_get_stack va_s0) == Vale.Arch.Types.lo64 old_xmm15)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_get_reg64 rRsp va_sM == old_rsp /\ Vale.X64.Stack_i.init_rsp (va_get_stack va_sM) ==
Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\ Vale.X64.Stack_i.modifies_stack (va_get_reg64
rRsp va_s0) (va_get_reg64 rRsp va_sM) (va_get_stack va_s0) (va_get_stack va_sM) /\
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 0 + (if win then 160 else 0))
(va_get_stack va_s0) == va_get_reg64 rRbx va_sM /\ Vale.X64.Stack_i.load_stack64 (va_get_reg64
rRsp va_s0 + 8 + (if win then 160 else 0)) (va_get_stack va_s0) == va_get_reg64 rRbp va_sM /\
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 16 + (if win then 160 else 0))
(va_get_stack va_s0) == va_get_reg64 rRdi va_sM /\ Vale.X64.Stack_i.load_stack64 (va_get_reg64
rRsp va_s0 + 24 + (if win then 160 else 0)) (va_get_stack va_s0) == va_get_reg64 rRsi va_sM /\
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + (if win then 160 else 0))
(va_get_stack va_s0) == va_get_reg64 rR12 va_sM /\ Vale.X64.Stack_i.load_stack64 (va_get_reg64
rRsp va_s0 + 40 + (if win then 160 else 0)) (va_get_stack va_s0) == va_get_reg64 rR13 va_sM /\
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 48 + (if win then 160 else 0))
(va_get_stack va_s0) == va_get_reg64 rR14 va_sM /\ Vale.X64.Stack_i.load_stack64 (va_get_reg64
rRsp va_s0 + 56 + (if win then 160 else 0)) (va_get_stack va_s0) == va_get_reg64 rR15 va_sM /\
(win ==> va_get_xmm 6 va_sM == old_xmm6) /\ (win ==> va_get_xmm 7 va_sM == old_xmm7) /\ (win
==> va_get_xmm 8 va_sM == old_xmm8) /\ (win ==> va_get_xmm 9 va_sM == old_xmm9) /\ (win ==>
va_get_xmm 10 va_sM == old_xmm10) /\ (win ==> va_get_xmm 11 va_sM == old_xmm11) /\ (win ==>
va_get_xmm 12 va_sM == old_xmm12) /\ (win ==> va_get_xmm 13 va_sM == old_xmm13) /\ (win ==>
va_get_xmm 14 va_sM == old_xmm14) /\ (win ==> va_get_xmm 15 va_sM == old_xmm15) /\ va_state_eq
va_sM (va_update_stackTaint va_sM (va_update_flags va_sM (va_update_reg64 rRsp va_sM
(va_update_stack va_sM (va_update_xmm 15 va_sM (va_update_xmm 14 va_sM (va_update_xmm 13 va_sM
(va_update_xmm 12 va_sM (va_update_xmm 11 va_sM (va_update_xmm 10 va_sM (va_update_xmm 9 va_sM
(va_update_xmm 8 va_sM (va_update_xmm 7 va_sM (va_update_xmm 6 va_sM (va_update_reg64 rR15
va_sM (va_update_reg64 rR14 va_sM (va_update_reg64 rR13 va_sM (va_update_reg64 rR12 va_sM
(va_update_reg64 rRsi va_sM (va_update_reg64 rRdi va_sM (va_update_reg64 rRbp va_sM
(va_update_reg64 rRbx va_sM (va_update_reg64 rRax va_sM (va_update_ok va_sM
va_s0))))))))))))))))))))))))))
[@ va_qattr]
let va_wp_Restore_registers (win:bool) (old_rsp:nat) (old_xmm6:quad32) (old_xmm7:quad32)
(old_xmm8:quad32) (old_xmm9:quad32) (old_xmm10:quad32) (old_xmm11:quad32) (old_xmm12:quad32)
(old_xmm13:quad32) (old_xmm14:quad32) (old_xmm15:quad32) (va_s0:va_state) (va_k:(va_state -> unit
-> Type0)) : Type0 =
(va_get_ok va_s0 /\ sse_enabled /\ old_rsp == Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\
Vale.X64.Stack_i.valid_stack_slot64s (va_get_reg64 rRsp va_s0) (8 + va_if win (fun _ -> 10
`op_Multiply` 2) (fun _ -> 0)) (va_get_stack va_s0) Secret (va_get_stackTaint va_s0) /\
va_get_reg64 rRsp va_s0 == old_rsp - 8 `op_Multiply` (8 + va_if win (fun _ -> 10 `op_Multiply`
2) (fun _ -> 0)) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 0)
(va_get_stack va_s0) == Vale.Arch.Types.hi64 old_xmm6) /\ (win ==>
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8) (va_get_stack va_s0) ==
Vale.Arch.Types.lo64 old_xmm6) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 16) (va_get_stack va_s0) == Vale.Arch.Types.hi64 old_xmm7) /\ (win ==>
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 24) (va_get_stack va_s0) ==
Vale.Arch.Types.lo64 old_xmm7) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 32) (va_get_stack va_s0) == Vale.Arch.Types.hi64 old_xmm8) /\ (win ==>
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40) (va_get_stack va_s0) ==
Vale.Arch.Types.lo64 old_xmm8) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 48) (va_get_stack va_s0) == Vale.Arch.Types.hi64 old_xmm9) /\ (win ==>
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 56) (va_get_stack va_s0) ==
Vale.Arch.Types.lo64 old_xmm9) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 64) (va_get_stack va_s0) == Vale.Arch.Types.hi64 old_xmm10) /\ (win ==>
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 72) (va_get_stack va_s0) ==
Vale.Arch.Types.lo64 old_xmm10) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 80) (va_get_stack va_s0) == Vale.Arch.Types.hi64 old_xmm11) /\ (win ==>
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 88) (va_get_stack va_s0) ==
Vale.Arch.Types.lo64 old_xmm11) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 96) (va_get_stack va_s0) == Vale.Arch.Types.hi64 old_xmm12) /\ (win ==>
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 104) (va_get_stack va_s0) ==
Vale.Arch.Types.lo64 old_xmm12) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 112) (va_get_stack va_s0) == Vale.Arch.Types.hi64 old_xmm13) /\ (win ==>
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 120) (va_get_stack va_s0) ==
Vale.Arch.Types.lo64 old_xmm13) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 128) (va_get_stack va_s0) == Vale.Arch.Types.hi64 old_xmm14) /\ (win ==>
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 136) (va_get_stack va_s0) ==
Vale.Arch.Types.lo64 old_xmm14) /\ (win ==> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 144) (va_get_stack va_s0) == Vale.Arch.Types.hi64 old_xmm15) /\ (win ==>
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 152) (va_get_stack va_s0) ==
Vale.Arch.Types.lo64 old_xmm15) /\ (forall (va_x_rax:nat64) (va_x_rbx:nat64) (va_x_rbp:nat64)
(va_x_rdi:nat64) (va_x_rsi:nat64) (va_x_r12:nat64) (va_x_r13:nat64) (va_x_r14:nat64)
(va_x_r15:nat64) (va_x_xmm6:quad32) (va_x_xmm7:quad32) (va_x_xmm8:quad32) (va_x_xmm9:quad32)
(va_x_xmm10:quad32) (va_x_xmm11:quad32) (va_x_xmm12:quad32) (va_x_xmm13:quad32)
(va_x_xmm14:quad32) (va_x_xmm15:quad32) (va_x_stack:vale_stack) (va_x_rsp:nat64)
(va_x_efl:Vale.X64.Flags.t) (va_x_stackTaint:memtaint) . let va_sM = va_upd_stackTaint
va_x_stackTaint (va_upd_flags va_x_efl (va_upd_reg64 rRsp va_x_rsp (va_upd_stack va_x_stack
(va_upd_xmm 15 va_x_xmm15 (va_upd_xmm 14 va_x_xmm14 (va_upd_xmm 13 va_x_xmm13 (va_upd_xmm 12
va_x_xmm12 (va_upd_xmm 11 va_x_xmm11 (va_upd_xmm 10 va_x_xmm10 (va_upd_xmm 9 va_x_xmm9
(va_upd_xmm 8 va_x_xmm8 (va_upd_xmm 7 va_x_xmm7 (va_upd_xmm 6 va_x_xmm6 (va_upd_reg64 rR15
va_x_r15 (va_upd_reg64 rR14 va_x_r14 (va_upd_reg64 rR13 va_x_r13 (va_upd_reg64 rR12 va_x_r12
(va_upd_reg64 rRsi va_x_rsi (va_upd_reg64 rRdi va_x_rdi (va_upd_reg64 rRbp va_x_rbp
(va_upd_reg64 rRbx va_x_rbx (va_upd_reg64 rRax va_x_rax va_s0)))))))))))))))))))))) in
va_get_ok va_sM /\ va_get_reg64 rRsp va_sM == old_rsp /\ Vale.X64.Stack_i.init_rsp
(va_get_stack va_sM) == Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\
Vale.X64.Stack_i.modifies_stack (va_get_reg64 rRsp va_s0) (va_get_reg64 rRsp va_sM)
(va_get_stack va_s0) (va_get_stack va_sM) /\ Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp
va_s0 + 0 + va_if win (fun _ -> 160) (fun _ -> 0)) (va_get_stack va_s0) == va_get_reg64 rRbx
va_sM /\ Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + va_if win (fun _ -> 160)
(fun _ -> 0)) (va_get_stack va_s0) == va_get_reg64 rRbp va_sM /\ Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 16 + va_if win (fun _ -> 160) (fun _ -> 0)) (va_get_stack va_s0) ==
va_get_reg64 rRdi va_sM /\ Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 24 + va_if
win (fun _ -> 160) (fun _ -> 0)) (va_get_stack va_s0) == va_get_reg64 rRsi va_sM /\
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + va_if win (fun _ -> 160) (fun _
-> 0)) (va_get_stack va_s0) == va_get_reg64 rR12 va_sM /\ Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 40 + va_if win (fun _ -> 160) (fun _ -> 0)) (va_get_stack va_s0) ==
va_get_reg64 rR13 va_sM /\ Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 48 + va_if
win (fun _ -> 160) (fun _ -> 0)) (va_get_stack va_s0) == va_get_reg64 rR14 va_sM /\
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 56 + va_if win (fun _ -> 160) (fun _
-> 0)) (va_get_stack va_s0) == va_get_reg64 rR15 va_sM /\ (win ==> va_get_xmm 6 va_sM ==
old_xmm6) /\ (win ==> va_get_xmm 7 va_sM == old_xmm7) /\ (win ==> va_get_xmm 8 va_sM ==
old_xmm8) /\ (win ==> va_get_xmm 9 va_sM == old_xmm9) /\ (win ==> va_get_xmm 10 va_sM ==
old_xmm10) /\ (win ==> va_get_xmm 11 va_sM == old_xmm11) /\ (win ==> va_get_xmm 12 va_sM ==
old_xmm12) /\ (win ==> va_get_xmm 13 va_sM == old_xmm13) /\ (win ==> va_get_xmm 14 va_sM ==
old_xmm14) /\ (win ==> va_get_xmm 15 va_sM == old_xmm15) ==> va_k va_sM (())))
val va_wpProof_Restore_registers : win:bool -> old_rsp:nat -> old_xmm6:quad32 -> old_xmm7:quad32 ->
old_xmm8:quad32 -> old_xmm9:quad32 -> old_xmm10:quad32 -> old_xmm11:quad32 -> old_xmm12:quad32 ->
old_xmm13:quad32 -> old_xmm14:quad32 -> old_xmm15:quad32 -> va_s0:va_state -> va_k:(va_state ->
unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Restore_registers win old_rsp old_xmm6 old_xmm7 old_xmm8
old_xmm9 old_xmm10 old_xmm11 old_xmm12 old_xmm13 old_xmm14 old_xmm15 va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Restore_registers win)
([va_Mod_stackTaint; va_Mod_flags; va_Mod_reg64 rRsp; va_Mod_stack; va_Mod_xmm 15; va_Mod_xmm
14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 8;
va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_reg64 rR15; va_Mod_reg64 rR14; va_Mod_reg64 rR13;
va_Mod_reg64 rR12; va_Mod_reg64 rRsi; va_Mod_reg64 rRdi; va_Mod_reg64 rRbp; va_Mod_reg64 rRbx;
va_Mod_reg64 rRax]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_Restore_registers (win:bool) (old_rsp:nat) (old_xmm6:quad32) (old_xmm7:quad32)
(old_xmm8:quad32) (old_xmm9:quad32) (old_xmm10:quad32) (old_xmm11:quad32) (old_xmm12:quad32)
(old_xmm13:quad32) (old_xmm14:quad32) (old_xmm15:quad32) : (va_quickCode unit
(va_code_Restore_registers win)) =
(va_QProc (va_code_Restore_registers win) ([va_Mod_stackTaint; va_Mod_flags; va_Mod_reg64 rRsp;
va_Mod_stack; va_Mod_xmm 15; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11;
va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 8; va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_reg64 rR15;
va_Mod_reg64 rR14; va_Mod_reg64 rR13; va_Mod_reg64 rR12; va_Mod_reg64 rRsi; va_Mod_reg64 rRdi;
va_Mod_reg64 rRbp; va_Mod_reg64 rRbx; va_Mod_reg64 rRax]) (va_wp_Restore_registers win old_rsp
old_xmm6 old_xmm7 old_xmm8 old_xmm9 old_xmm10 old_xmm11 old_xmm12 old_xmm13 old_xmm14
old_xmm15) (va_wpProof_Restore_registers win old_rsp old_xmm6 old_xmm7 old_xmm8 old_xmm9
old_xmm10 old_xmm11 old_xmm12 old_xmm13 old_xmm14 old_xmm15))
//--
#reset-options "--z3rlimit 100"
//-- Gcm_blocks_stdcall
val va_code_Gcm_blocks_stdcall : win:bool -> alg:algorithm -> Tot va_code
val va_codegen_success_Gcm_blocks_stdcall : win:bool -> alg:algorithm -> Tot va_pbool
let va_req_Gcm_blocks_stdcall (va_b0:va_code) (va_s0:va_state) (win:bool) (alg:algorithm)
(auth_b:buffer128) (auth_bytes:nat64) (auth_num:nat64) (keys_b:buffer128) (iv_b:buffer128)
(iv:supported_iv_LE) (hkeys_b:buffer128) (abytes_b:buffer128) (in128x6_b:buffer128)
(out128x6_b:buffer128) (len128x6_num:nat64) (in128_b:buffer128) (out128_b:buffer128)
(len128_num:nat64) (inout_b:buffer128) (plain_num:nat64) (scratch_b:buffer128) (tag_b:buffer128)
(key:(seq nat32)) : prop =
(va_require_total va_b0 (va_code_Gcm_blocks_stdcall win alg) va_s0 /\ va_get_ok va_s0 /\ (let
(auth_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0 else
va_get_reg64 rRdi va_s0) in let (auth_num_bytes:(va_int_range 0 18446744073709551615)) = (if
win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let (auth_len:(va_int_range 0
18446744073709551615)) = (if win then va_get_reg64 rR8 va_s0 else va_get_reg64 rRdx va_s0) in
let (keys_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rR9 va_s0 else
va_get_reg64 rRcx va_s0) in let (iv_ptr:(va_int_range 0 18446744073709551615)) = (if win then
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0) else
va_get_reg64 rR8 va_s0) in let (xip:(va_int_range 0 18446744073709551615)) = (if win then
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0) else
va_get_reg64 rR9 va_s0) in let (abytes_ptr:(va_int_range 0 18446744073709551615)) = (if win
then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 16) (va_get_stack va_s0)
else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) in
let (in128x6_ptr:(va_int_range 0 18446744073709551615)) = (if win then
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 24) (va_get_stack va_s0) else
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) in let
(out128x6_ptr:(va_int_range 0 18446744073709551615)) = (if win then
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 32) (va_get_stack va_s0) else
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 16) (va_get_stack va_s0)) in let
(len128x6:(va_int_range 0 18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 40 + 40) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 8 + 24) (va_get_stack va_s0)) in let (in128_ptr:(va_int_range 0
18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 +
40 + 48) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 +
32) (va_get_stack va_s0)) in let (out128_ptr:(va_int_range 0 18446744073709551615)) = (if win
then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 56) (va_get_stack va_s0)
else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 40) (va_get_stack va_s0)) in
let (len128:(va_int_range 0 18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 40 + 64) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 8 + 48) (va_get_stack va_s0)) in let (inout_ptr:(va_int_range 0
18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 +
40 + 72) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 +
56) (va_get_stack va_s0)) in let (plain_num_bytes:(va_int_range 0 18446744073709551615)) = (if
win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 80) (va_get_stack va_s0)
else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 64) (va_get_stack va_s0)) in
let (scratch_ptr:(va_int_range 0 18446744073709551615)) = (if win then
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 88) (va_get_stack va_s0) else
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 72) (va_get_stack va_s0)) in let
(tag_ptr:(va_int_range 0 18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 40 + 96) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 8 + 80) (va_get_stack va_s0)) in aesni_enabled /\ pclmulqdq_enabled
/\ avx_enabled /\ sse_enabled /\ movbe_enabled /\ va_get_reg64 rRsp va_s0 ==
Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\ Vale.X64.Memory.is_initial_heap
(va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 8 + 16) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 24) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 8 + 32) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 40) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 8 + 48) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 56) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 8 + 64) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 72) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 8 + 80) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 0) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 40 + 8) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 16) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 40 + 24) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 32) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 40 + 40) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 48) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 40 + 56) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 64) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 40 + 72) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 80) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 40 + 88) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 96) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ auth_len == auth_num /\ auth_num_bytes ==
auth_bytes /\ len128x6 == len128x6_num /\ len128 == len128_num /\ plain_num_bytes == plain_num
/\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) auth_ptr auth_b auth_len
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0)
abytes_ptr abytes_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem va_s0) iv_ptr iv_b 1 (va_get_mem_layout va_s0) Public /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) in128x6_ptr in128x6_b len128x6
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0)
out128x6_ptr out128x6_b len128x6 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) in128_ptr in128_b len128 (va_get_mem_layout
va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) out128_ptr out128_b len128
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0)
inout_ptr inout_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem va_s0) scratch_ptr scratch_b 9 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) xip hkeys_b 8 (va_get_mem_layout va_s0)
Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) tag_ptr tag_b 1 (va_get_mem_layout
va_s0) Secret /\ Vale.X64.Decls.buffer_disjoints128 tag_b ([keys_b; auth_b; abytes_b; iv_b;
in128x6_b; out128x6_b; in128_b; out128_b; inout_b; scratch_b; hkeys_b]) /\
Vale.X64.Decls.buffer_disjoints128 iv_b ([keys_b; auth_b; abytes_b; in128x6_b; out128x6_b;
in128_b; out128_b; inout_b; scratch_b; hkeys_b]) /\ Vale.X64.Decls.buffer_disjoints128
scratch_b ([keys_b; auth_b; abytes_b; in128x6_b; out128x6_b; in128_b; out128_b; inout_b;
hkeys_b]) /\ Vale.X64.Decls.buffer_disjoints128 inout_b ([keys_b; auth_b; abytes_b; in128x6_b;
out128x6_b; in128_b; out128_b; hkeys_b]) /\ Vale.X64.Decls.buffer_disjoints128 auth_b ([keys_b;
abytes_b; hkeys_b]) /\ Vale.X64.Decls.buffer_disjoints128 abytes_b ([keys_b; hkeys_b]) /\
Vale.X64.Decls.buffer_disjoints128 out128x6_b ([keys_b; auth_b; abytes_b; hkeys_b; in128_b;
inout_b]) /\ Vale.X64.Decls.buffer_disjoints128 in128x6_b ([keys_b; auth_b; abytes_b; hkeys_b;
in128_b; inout_b]) /\ Vale.X64.Decls.buffer_disjoints128 out128_b ([keys_b; auth_b; abytes_b;
hkeys_b; in128x6_b; out128x6_b; inout_b]) /\ Vale.X64.Decls.buffer_disjoints128 in128_b
([keys_b; auth_b; abytes_b; hkeys_b; in128x6_b; out128x6_b; inout_b]) /\
(Vale.X64.Decls.buffers_disjoint128 in128x6_b out128x6_b \/ in128x6_b == out128x6_b) /\
(Vale.X64.Decls.buffers_disjoint128 in128_b out128_b \/ in128_b == out128_b) /\ auth_ptr + 16
`op_Multiply` auth_len < pow2_64 /\ in128x6_ptr + 16 `op_Multiply` len128x6 < pow2_64 /\
out128x6_ptr + 16 `op_Multiply` len128x6 < pow2_64 /\ in128_ptr + 16 `op_Multiply` len128 <
pow2_64 /\ out128_ptr + 16 `op_Multiply` len128 < pow2_64 /\ inout_ptr + 16 < pow2_64 /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 auth_b == auth_len /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 abytes_b == 1 /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in128x6_b ==
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 out128x6_b /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in128_b == Vale.X64.Decls.buffer_length
#Vale.X64.Memory.vuint128 out128_b /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128
in128x6_b == len128x6 /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in128_b ==
len128 /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 inout_b == 1 /\
plain_num_bytes < pow2_32 /\ auth_num_bytes < pow2_32 /\ xip + 32 < pow2_64 /\
Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_b (va_get_mem va_s0) + 128 < pow2_64
/\ len128x6 `op_Modulus` 6 == 0 /\ (len128x6 > 0 ==> len128x6 >= 18) /\ 12 + len128x6 + 6 <
pow2_32 /\ (va_mul_nat len128x6 (128 `op_Division` 8) + va_mul_nat len128 (128 `op_Division` 8)
<= plain_num_bytes /\ plain_num_bytes < va_mul_nat len128x6 (128 `op_Division` 8) + va_mul_nat
len128 (128 `op_Division` 8) + 128 `op_Division` 8) /\ (va_mul_nat auth_len (128 `op_Division`
8) <= auth_num_bytes /\ auth_num_bytes < va_mul_nat auth_len (128 `op_Division` 8) + 128
`op_Division` 8) /\ (alg = AES_128 \/ alg = AES_256) /\ Vale.AES.AES_s.is_aes_key_LE alg key /\
Vale.X64.Decls.buffer128_as_seq (va_get_mem va_s0) keys_b ==
Vale.AES.AES_s.key_to_round_keys_LE alg key /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem
va_s0) keys_ptr keys_b (Vale.AES.AES_common_s.nr alg + 1) (va_get_mem_layout va_s0) Secret /\
Vale.AES.OptPublic.hkeys_reqs_pub (Vale.X64.Decls.s128 (va_get_mem va_s0) hkeys_b)
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE alg key
(Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0))) /\ (let h_LE =
Vale.AES.AES_s.aes_encrypt_LE alg key (Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0)
in let iv_BE = Vale.X64.Decls.buffer128_read iv_b 0 (va_get_mem va_s0) in iv_BE ==
Vale.AES.GCM_s.compute_iv_BE h_LE iv)))
let va_ens_Gcm_blocks_stdcall (va_b0:va_code) (va_s0:va_state) (win:bool) (alg:algorithm)
(auth_b:buffer128) (auth_bytes:nat64) (auth_num:nat64) (keys_b:buffer128) (iv_b:buffer128)
(iv:supported_iv_LE) (hkeys_b:buffer128) (abytes_b:buffer128) (in128x6_b:buffer128)
(out128x6_b:buffer128) (len128x6_num:nat64) (in128_b:buffer128) (out128_b:buffer128)
(len128_num:nat64) (inout_b:buffer128) (plain_num:nat64) (scratch_b:buffer128) (tag_b:buffer128)
(key:(seq nat32)) (va_sM:va_state) (va_fM:va_fuel) : prop =
(va_req_Gcm_blocks_stdcall va_b0 va_s0 win alg auth_b auth_bytes auth_num keys_b iv_b iv hkeys_b
abytes_b in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num
scratch_b tag_b key /\ va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (let
(auth_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0 else
va_get_reg64 rRdi va_s0) in let (auth_num_bytes:(va_int_range 0 18446744073709551615)) = (if
win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let (auth_len:(va_int_range 0
18446744073709551615)) = (if win then va_get_reg64 rR8 va_s0 else va_get_reg64 rRdx va_s0) in
let (keys_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rR9 va_s0 else
va_get_reg64 rRcx va_s0) in let (iv_ptr:(va_int_range 0 18446744073709551615)) = (if win then
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0) else
va_get_reg64 rR8 va_s0) in let (xip:(va_int_range 0 18446744073709551615)) = (if win then
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0) else
va_get_reg64 rR9 va_s0) in let (abytes_ptr:(va_int_range 0 18446744073709551615)) = (if win
then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 16) (va_get_stack va_s0)
else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) in
let (in128x6_ptr:(va_int_range 0 18446744073709551615)) = (if win then
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 24) (va_get_stack va_s0) else
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) in let
(out128x6_ptr:(va_int_range 0 18446744073709551615)) = (if win then
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 32) (va_get_stack va_s0) else
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 16) (va_get_stack va_s0)) in let
(len128x6:(va_int_range 0 18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 40 + 40) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 8 + 24) (va_get_stack va_s0)) in let (in128_ptr:(va_int_range 0
18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 +
40 + 48) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 +
32) (va_get_stack va_s0)) in let (out128_ptr:(va_int_range 0 18446744073709551615)) = (if win
then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 56) (va_get_stack va_s0)
else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 40) (va_get_stack va_s0)) in
let (len128:(va_int_range 0 18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 40 + 64) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 8 + 48) (va_get_stack va_s0)) in let (inout_ptr:(va_int_range 0
18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 +
40 + 72) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 +
56) (va_get_stack va_s0)) in let (plain_num_bytes:(va_int_range 0 18446744073709551615)) = (if
win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 80) (va_get_stack va_s0)
else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 64) (va_get_stack va_s0)) in
let (scratch_ptr:(va_int_range 0 18446744073709551615)) = (if win then
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 88) (va_get_stack va_s0) else
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 72) (va_get_stack va_s0)) in let
(tag_ptr:(va_int_range 0 18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 40 + 96) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 8 + 80) (va_get_stack va_s0)) in Vale.X64.Decls.modifies_mem
(Vale.X64.Decls.loc_union (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 tag_b)
(Vale.X64.Decls.loc_union (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 iv_b)
(Vale.X64.Decls.loc_union (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 scratch_b)
(Vale.X64.Decls.loc_union (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 out128x6_b)
(Vale.X64.Decls.loc_union (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 out128_b)
(Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 inout_b)))))) (va_get_mem va_s0)
(va_get_mem va_sM) /\ plain_num_bytes < pow2_32 /\ auth_num_bytes < pow2_32 /\ (let iv_BE =
Vale.X64.Decls.buffer128_read iv_b 0 (va_get_mem va_s0) in let auth_raw_quads =
FStar.Seq.Base.append #Vale.X64.Decls.quad32 (Vale.X64.Decls.s128 (va_get_mem va_s0) auth_b)
(Vale.X64.Decls.s128 (va_get_mem va_s0) abytes_b) in let auth_bytes = FStar.Seq.Base.slice
#Vale.Def.Types_s.nat8 (Vale.Def.Types_s.le_seq_quad32_to_bytes auth_raw_quads) 0
auth_num_bytes in let plain_raw_quads = FStar.Seq.Base.append #Vale.X64.Decls.quad32
(FStar.Seq.Base.append #Vale.X64.Decls.quad32 (Vale.X64.Decls.s128 (va_get_mem va_s0)
in128x6_b) (Vale.X64.Decls.s128 (va_get_mem va_s0) in128_b)) (Vale.X64.Decls.s128 (va_get_mem
va_s0) inout_b) in let plain_bytes = FStar.Seq.Base.slice #Vale.Def.Types_s.nat8
(Vale.Def.Types_s.le_seq_quad32_to_bytes plain_raw_quads) 0 plain_num_bytes in let
cipher_raw_quads = FStar.Seq.Base.append #Vale.X64.Decls.quad32 (FStar.Seq.Base.append
#Vale.X64.Decls.quad32 (Vale.X64.Decls.s128 (va_get_mem va_sM) out128x6_b) (Vale.X64.Decls.s128
(va_get_mem va_sM) out128_b)) (Vale.X64.Decls.s128 (va_get_mem va_sM) inout_b) in let
cipher_bytes = FStar.Seq.Base.slice #Vale.Def.Types_s.nat8
(Vale.Def.Types_s.le_seq_quad32_to_bytes cipher_raw_quads) 0 plain_num_bytes in l_and (l_and
(l_and (l_and (FStar.Seq.Base.length #Vale.Def.Types_s.nat8 auth_bytes < pow2_32)
(FStar.Seq.Base.length #Vale.Def.Types_s.nat8 plain_bytes < pow2_32))
(Vale.AES.AES_common_s.is_aes_key alg (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE key)))
(cipher_bytes == __proj__Mktuple2__item___1 #(FStar.Seq.Base.seq Vale.Def.Types_s.nat8)
#(FStar.Seq.Base.seq Vale.Def.Types_s.nat8) (Vale.AES.GCM_s.gcm_encrypt_LE alg
(Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)))
(Vale.Def.Types_s.le_quad32_to_bytes (Vale.X64.Decls.buffer128_read tag_b 0 (va_get_mem va_sM))
== __proj__Mktuple2__item___2 #(FStar.Seq.Base.seq Vale.Def.Types_s.nat8) #(FStar.Seq.Base.seq
Vale.Def.Types_s.nat8) (Vale.AES.GCM_s.gcm_encrypt_LE alg
(Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)) /\ va_get_reg64
rRsp va_sM == va_get_reg64 rRsp va_s0 /\ (win ==> va_get_reg64 rRbx va_sM == va_get_reg64 rRbx
va_s0) /\ (win ==> va_get_reg64 rRbp va_sM == va_get_reg64 rRbp va_s0) /\ (win ==> va_get_reg64
rRdi va_sM == va_get_reg64 rRdi va_s0) /\ (win ==> va_get_reg64 rRsi va_sM == va_get_reg64 rRsi
va_s0) /\ (win ==> va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0) /\ (win ==> va_get_reg64
rR13 va_sM == va_get_reg64 rR13 va_s0) /\ (win ==> va_get_reg64 rR14 va_sM == va_get_reg64 rR14
va_s0) /\ (win ==> va_get_reg64 rR15 va_sM == va_get_reg64 rR15 va_s0) /\ (win ==> va_get_xmm 6
va_sM == va_get_xmm 6 va_s0) /\ (win ==> va_get_xmm 7 va_sM == va_get_xmm 7 va_s0) /\ (win ==>
va_get_xmm 8 va_sM == va_get_xmm 8 va_s0) /\ (win ==> va_get_xmm 9 va_sM == va_get_xmm 9 va_s0)
/\ (win ==> va_get_xmm 10 va_sM == va_get_xmm 10 va_s0) /\ (win ==> va_get_xmm 11 va_sM ==
va_get_xmm 11 va_s0) /\ (win ==> va_get_xmm 12 va_sM == va_get_xmm 12 va_s0) /\ (win ==>
va_get_xmm 13 va_sM == va_get_xmm 13 va_s0) /\ (win ==> va_get_xmm 14 va_sM == va_get_xmm 14
va_s0) /\ (win ==> va_get_xmm 15 va_sM == va_get_xmm 15 va_s0) /\ (~win ==> va_get_reg64 rRbx
va_sM == va_get_reg64 rRbx va_s0) /\ (~win ==> va_get_reg64 rRbp va_sM == va_get_reg64 rRbp
va_s0) /\ (~win ==> va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0) /\ (~win ==>
va_get_reg64 rR13 va_sM == va_get_reg64 rR13 va_s0) /\ (~win ==> va_get_reg64 rR14 va_sM ==
va_get_reg64 rR14 va_s0) /\ (~win ==> va_get_reg64 rR15 va_sM == va_get_reg64 rR15 va_s0))) /\
va_state_eq va_sM (va_update_stackTaint va_sM (va_update_stack va_sM (va_update_flags va_sM
(va_update_mem_heaplet 6 va_sM (va_update_mem_heaplet 5 va_sM (va_update_mem_heaplet 4 va_sM
(va_update_mem_heaplet 3 va_sM (va_update_mem_heaplet 2 va_sM (va_update_mem_heaplet 1 va_sM
(va_update_mem_layout va_sM (va_update_xmm 15 va_sM (va_update_xmm 14 va_sM (va_update_xmm 13
va_sM (va_update_xmm 12 va_sM (va_update_xmm 11 va_sM (va_update_xmm 10 va_sM (va_update_xmm 9
va_sM (va_update_xmm 8 va_sM (va_update_xmm 7 va_sM (va_update_xmm 6 va_sM (va_update_xmm 5
va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1
va_sM (va_update_xmm 0 va_sM (va_update_reg64 rR15 va_sM (va_update_reg64 rR14 va_sM
(va_update_reg64 rR13 va_sM (va_update_reg64 rR12 va_sM (va_update_reg64 rR11 va_sM
(va_update_reg64 rR10 va_sM (va_update_reg64 rR9 va_sM (va_update_reg64 rR8 va_sM
(va_update_reg64 rRbp va_sM (va_update_reg64 rRsp va_sM (va_update_reg64 rRsi va_sM
(va_update_reg64 rRdi va_sM (va_update_reg64 rRdx va_sM (va_update_reg64 rRcx va_sM
(va_update_reg64 rRbx va_sM (va_update_reg64 rRax va_sM (va_update_ok va_sM (va_update_mem
va_sM va_s0)))))))))))))))))))))))))))))))))))))))))))))
val va_lemma_Gcm_blocks_stdcall : va_b0:va_code -> va_s0:va_state -> win:bool -> alg:algorithm ->
auth_b:buffer128 -> auth_bytes:nat64 -> auth_num:nat64 -> keys_b:buffer128 -> iv_b:buffer128 ->
iv:supported_iv_LE -> hkeys_b:buffer128 -> abytes_b:buffer128 -> in128x6_b:buffer128 ->
out128x6_b:buffer128 -> len128x6_num:nat64 -> in128_b:buffer128 -> out128_b:buffer128 ->
len128_num:nat64 -> inout_b:buffer128 -> plain_num:nat64 -> scratch_b:buffer128 ->
tag_b:buffer128 -> key:(seq nat32)
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Gcm_blocks_stdcall win alg) va_s0 /\ va_get_ok va_s0
/\ (let (auth_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0
else va_get_reg64 rRdi va_s0) in let (auth_num_bytes:(va_int_range 0 18446744073709551615)) =
(if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let
(auth_len:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rR8 va_s0 else
va_get_reg64 rRdx va_s0) in let (keys_ptr:(va_int_range 0 18446744073709551615)) = (if win then
va_get_reg64 rR9 va_s0 else va_get_reg64 rRcx va_s0) in let (iv_ptr:(va_int_range 0
18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 +
32 + 8 + 0) (va_get_stack va_s0) else va_get_reg64 rR8 va_s0) in let (xip:(va_int_range 0
18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 +
32 + 8 + 8) (va_get_stack va_s0) else va_get_reg64 rR9 va_s0) in let (abytes_ptr:(va_int_range
0 18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0
+ 40 + 16) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8
+ 0) (va_get_stack va_s0)) in let (in128x6_ptr:(va_int_range 0 18446744073709551615)) = (if win
then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 24) (va_get_stack va_s0)
else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) in
let (out128x6_ptr:(va_int_range 0 18446744073709551615)) = (if win then
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 32) (va_get_stack va_s0) else
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 16) (va_get_stack va_s0)) in let
(len128x6:(va_int_range 0 18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 40 + 40) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 8 + 24) (va_get_stack va_s0)) in let (in128_ptr:(va_int_range 0
18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 +
40 + 48) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 +
32) (va_get_stack va_s0)) in let (out128_ptr:(va_int_range 0 18446744073709551615)) = (if win
then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 56) (va_get_stack va_s0)
else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 40) (va_get_stack va_s0)) in
let (len128:(va_int_range 0 18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 40 + 64) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 8 + 48) (va_get_stack va_s0)) in let (inout_ptr:(va_int_range 0
18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 +
40 + 72) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 +
56) (va_get_stack va_s0)) in let (plain_num_bytes:(va_int_range 0 18446744073709551615)) = (if
win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 80) (va_get_stack va_s0)
else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 64) (va_get_stack va_s0)) in
let (scratch_ptr:(va_int_range 0 18446744073709551615)) = (if win then
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 88) (va_get_stack va_s0) else
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 72) (va_get_stack va_s0)) in let
(tag_ptr:(va_int_range 0 18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 40 + 96) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 8 + 80) (va_get_stack va_s0)) in aesni_enabled /\ pclmulqdq_enabled
/\ avx_enabled /\ sse_enabled /\ movbe_enabled /\ va_get_reg64 rRsp va_s0 ==
Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\ Vale.X64.Memory.is_initial_heap
(va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 8 + 16) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 24) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 8 + 32) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 40) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 8 + 48) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 56) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 8 + 64) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(~win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 72) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 8 + 80) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 0) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 40 + 8) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 16) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 40 + 24) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 32) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 40 + 40) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 48) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 40 + 56) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 64) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 40 + 72) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 80) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_stack_slot64
(va_get_reg64 rRsp va_s0 + 40 + 88) (va_get_stack va_s0) Public (va_get_stackTaint va_s0)) /\
(win ==> Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 96) (va_get_stack
va_s0) Public (va_get_stackTaint va_s0)) /\ auth_len == auth_num /\ auth_num_bytes ==
auth_bytes /\ len128x6 == len128x6_num /\ len128 == len128_num /\ plain_num_bytes == plain_num
/\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) auth_ptr auth_b auth_len
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0)
abytes_ptr abytes_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem va_s0) iv_ptr iv_b 1 (va_get_mem_layout va_s0) Public /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) in128x6_ptr in128x6_b len128x6
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0)
out128x6_ptr out128x6_b len128x6 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) in128_ptr in128_b len128 (va_get_mem_layout
va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) out128_ptr out128_b len128
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0)
inout_ptr inout_b 1 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem va_s0) scratch_ptr scratch_b 9 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) xip hkeys_b 8 (va_get_mem_layout va_s0)
Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) tag_ptr tag_b 1 (va_get_mem_layout
va_s0) Secret /\ Vale.X64.Decls.buffer_disjoints128 tag_b ([keys_b; auth_b; abytes_b; iv_b;
in128x6_b; out128x6_b; in128_b; out128_b; inout_b; scratch_b; hkeys_b]) /\
Vale.X64.Decls.buffer_disjoints128 iv_b ([keys_b; auth_b; abytes_b; in128x6_b; out128x6_b;
in128_b; out128_b; inout_b; scratch_b; hkeys_b]) /\ Vale.X64.Decls.buffer_disjoints128
scratch_b ([keys_b; auth_b; abytes_b; in128x6_b; out128x6_b; in128_b; out128_b; inout_b;
hkeys_b]) /\ Vale.X64.Decls.buffer_disjoints128 inout_b ([keys_b; auth_b; abytes_b; in128x6_b;
out128x6_b; in128_b; out128_b; hkeys_b]) /\ Vale.X64.Decls.buffer_disjoints128 auth_b ([keys_b;
abytes_b; hkeys_b]) /\ Vale.X64.Decls.buffer_disjoints128 abytes_b ([keys_b; hkeys_b]) /\
Vale.X64.Decls.buffer_disjoints128 out128x6_b ([keys_b; auth_b; abytes_b; hkeys_b; in128_b;
inout_b]) /\ Vale.X64.Decls.buffer_disjoints128 in128x6_b ([keys_b; auth_b; abytes_b; hkeys_b;
in128_b; inout_b]) /\ Vale.X64.Decls.buffer_disjoints128 out128_b ([keys_b; auth_b; abytes_b;
hkeys_b; in128x6_b; out128x6_b; inout_b]) /\ Vale.X64.Decls.buffer_disjoints128 in128_b
([keys_b; auth_b; abytes_b; hkeys_b; in128x6_b; out128x6_b; inout_b]) /\
(Vale.X64.Decls.buffers_disjoint128 in128x6_b out128x6_b \/ in128x6_b == out128x6_b) /\
(Vale.X64.Decls.buffers_disjoint128 in128_b out128_b \/ in128_b == out128_b) /\ auth_ptr + 16
`op_Multiply` auth_len < pow2_64 /\ in128x6_ptr + 16 `op_Multiply` len128x6 < pow2_64 /\
out128x6_ptr + 16 `op_Multiply` len128x6 < pow2_64 /\ in128_ptr + 16 `op_Multiply` len128 <
pow2_64 /\ out128_ptr + 16 `op_Multiply` len128 < pow2_64 /\ inout_ptr + 16 < pow2_64 /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 auth_b == auth_len /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 abytes_b == 1 /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in128x6_b ==
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 out128x6_b /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in128_b == Vale.X64.Decls.buffer_length
#Vale.X64.Memory.vuint128 out128_b /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128
in128x6_b == len128x6 /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in128_b ==
len128 /\ Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 inout_b == 1 /\
plain_num_bytes < pow2_32 /\ auth_num_bytes < pow2_32 /\ xip + 32 < pow2_64 /\
Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_b (va_get_mem va_s0) + 128 < pow2_64
/\ len128x6 `op_Modulus` 6 == 0 /\ (len128x6 > 0 ==> len128x6 >= 18) /\ 12 + len128x6 + 6 <
pow2_32 /\ (va_mul_nat len128x6 (128 `op_Division` 8) + va_mul_nat len128 (128 `op_Division` 8)
<= plain_num_bytes /\ plain_num_bytes < va_mul_nat len128x6 (128 `op_Division` 8) + va_mul_nat
len128 (128 `op_Division` 8) + 128 `op_Division` 8) /\ (va_mul_nat auth_len (128 `op_Division`
8) <= auth_num_bytes /\ auth_num_bytes < va_mul_nat auth_len (128 `op_Division` 8) + 128
`op_Division` 8) /\ (alg = AES_128 \/ alg = AES_256) /\ Vale.AES.AES_s.is_aes_key_LE alg key /\
Vale.X64.Decls.buffer128_as_seq (va_get_mem va_s0) keys_b ==
Vale.AES.AES_s.key_to_round_keys_LE alg key /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem
va_s0) keys_ptr keys_b (Vale.AES.AES_common_s.nr alg + 1) (va_get_mem_layout va_s0) Secret /\
Vale.AES.OptPublic.hkeys_reqs_pub (Vale.X64.Decls.s128 (va_get_mem va_s0) hkeys_b)
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE alg key
(Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0))) /\ (let h_LE =
Vale.AES.AES_s.aes_encrypt_LE alg key (Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0)
in let iv_BE = Vale.X64.Decls.buffer128_read iv_b 0 (va_get_mem va_s0) in iv_BE ==
Vale.AES.GCM_s.compute_iv_BE h_LE iv))))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (auth_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0
else va_get_reg64 rRdi va_s0) in let (auth_num_bytes:(va_int_range 0 18446744073709551615)) =
(if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let
(auth_len:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rR8 va_s0 else
va_get_reg64 rRdx va_s0) in let (keys_ptr:(va_int_range 0 18446744073709551615)) = (if win then
va_get_reg64 rR9 va_s0 else va_get_reg64 rRcx va_s0) in let (iv_ptr:(va_int_range 0
18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 +
32 + 8 + 0) (va_get_stack va_s0) else va_get_reg64 rR8 va_s0) in let (xip:(va_int_range 0
18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 +
32 + 8 + 8) (va_get_stack va_s0) else va_get_reg64 rR9 va_s0) in let (abytes_ptr:(va_int_range
0 18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0
+ 40 + 16) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8
+ 0) (va_get_stack va_s0)) in let (in128x6_ptr:(va_int_range 0 18446744073709551615)) = (if win
then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 24) (va_get_stack va_s0)
else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) in
let (out128x6_ptr:(va_int_range 0 18446744073709551615)) = (if win then
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 32) (va_get_stack va_s0) else
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 16) (va_get_stack va_s0)) in let
(len128x6:(va_int_range 0 18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 40 + 40) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 8 + 24) (va_get_stack va_s0)) in let (in128_ptr:(va_int_range 0
18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 +
40 + 48) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 +
32) (va_get_stack va_s0)) in let (out128_ptr:(va_int_range 0 18446744073709551615)) = (if win
then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 56) (va_get_stack va_s0)
else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 40) (va_get_stack va_s0)) in
let (len128:(va_int_range 0 18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 40 + 64) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 8 + 48) (va_get_stack va_s0)) in let (inout_ptr:(va_int_range 0
18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 +
40 + 72) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 +
56) (va_get_stack va_s0)) in let (plain_num_bytes:(va_int_range 0 18446744073709551615)) = (if
win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 80) (va_get_stack va_s0)
else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 64) (va_get_stack va_s0)) in
let (scratch_ptr:(va_int_range 0 18446744073709551615)) = (if win then
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 88) (va_get_stack va_s0) else
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 72) (va_get_stack va_s0)) in let
(tag_ptr:(va_int_range 0 18446744073709551615)) = (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 40 + 96) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 8 + 80) (va_get_stack va_s0)) in Vale.X64.Decls.modifies_mem
(Vale.X64.Decls.loc_union (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 tag_b)
(Vale.X64.Decls.loc_union (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 iv_b)
(Vale.X64.Decls.loc_union (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 scratch_b)
(Vale.X64.Decls.loc_union (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 out128x6_b)
(Vale.X64.Decls.loc_union (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 out128_b)
(Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 inout_b)))))) (va_get_mem va_s0)
(va_get_mem va_sM) /\ plain_num_bytes < pow2_32 /\ auth_num_bytes < pow2_32 /\ (let iv_BE =
Vale.X64.Decls.buffer128_read iv_b 0 (va_get_mem va_s0) in let auth_raw_quads =
FStar.Seq.Base.append #Vale.X64.Decls.quad32 (Vale.X64.Decls.s128 (va_get_mem va_s0) auth_b)
(Vale.X64.Decls.s128 (va_get_mem va_s0) abytes_b) in let auth_bytes = FStar.Seq.Base.slice
#Vale.Def.Types_s.nat8 (Vale.Def.Types_s.le_seq_quad32_to_bytes auth_raw_quads) 0
auth_num_bytes in let plain_raw_quads = FStar.Seq.Base.append #Vale.X64.Decls.quad32
(FStar.Seq.Base.append #Vale.X64.Decls.quad32 (Vale.X64.Decls.s128 (va_get_mem va_s0)
in128x6_b) (Vale.X64.Decls.s128 (va_get_mem va_s0) in128_b)) (Vale.X64.Decls.s128 (va_get_mem
va_s0) inout_b) in let plain_bytes = FStar.Seq.Base.slice #Vale.Def.Types_s.nat8
(Vale.Def.Types_s.le_seq_quad32_to_bytes plain_raw_quads) 0 plain_num_bytes in let
cipher_raw_quads = FStar.Seq.Base.append #Vale.X64.Decls.quad32 (FStar.Seq.Base.append
#Vale.X64.Decls.quad32 (Vale.X64.Decls.s128 (va_get_mem va_sM) out128x6_b) (Vale.X64.Decls.s128
(va_get_mem va_sM) out128_b)) (Vale.X64.Decls.s128 (va_get_mem va_sM) inout_b) in let
cipher_bytes = FStar.Seq.Base.slice #Vale.Def.Types_s.nat8
(Vale.Def.Types_s.le_seq_quad32_to_bytes cipher_raw_quads) 0 plain_num_bytes in l_and (l_and
(l_and (l_and (FStar.Seq.Base.length #Vale.Def.Types_s.nat8 auth_bytes < pow2_32)
(FStar.Seq.Base.length #Vale.Def.Types_s.nat8 plain_bytes < pow2_32))
(Vale.AES.AES_common_s.is_aes_key alg (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE key)))
(cipher_bytes == __proj__Mktuple2__item___1 #(FStar.Seq.Base.seq Vale.Def.Types_s.nat8)
#(FStar.Seq.Base.seq Vale.Def.Types_s.nat8) (Vale.AES.GCM_s.gcm_encrypt_LE alg
(Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)))
(Vale.Def.Types_s.le_quad32_to_bytes (Vale.X64.Decls.buffer128_read tag_b 0 (va_get_mem va_sM))
== __proj__Mktuple2__item___2 #(FStar.Seq.Base.seq Vale.Def.Types_s.nat8) #(FStar.Seq.Base.seq
Vale.Def.Types_s.nat8) (Vale.AES.GCM_s.gcm_encrypt_LE alg
(Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)) /\ va_get_reg64
rRsp va_sM == va_get_reg64 rRsp va_s0 /\ (win ==> va_get_reg64 rRbx va_sM == va_get_reg64 rRbx
va_s0) /\ (win ==> va_get_reg64 rRbp va_sM == va_get_reg64 rRbp va_s0) /\ (win ==> va_get_reg64
rRdi va_sM == va_get_reg64 rRdi va_s0) /\ (win ==> va_get_reg64 rRsi va_sM == va_get_reg64 rRsi
va_s0) /\ (win ==> va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0) /\ (win ==> va_get_reg64
rR13 va_sM == va_get_reg64 rR13 va_s0) /\ (win ==> va_get_reg64 rR14 va_sM == va_get_reg64 rR14
va_s0) /\ (win ==> va_get_reg64 rR15 va_sM == va_get_reg64 rR15 va_s0) /\ (win ==> va_get_xmm 6
va_sM == va_get_xmm 6 va_s0) /\ (win ==> va_get_xmm 7 va_sM == va_get_xmm 7 va_s0) /\ (win ==>
va_get_xmm 8 va_sM == va_get_xmm 8 va_s0) /\ (win ==> va_get_xmm 9 va_sM == va_get_xmm 9 va_s0)
/\ (win ==> va_get_xmm 10 va_sM == va_get_xmm 10 va_s0) /\ (win ==> va_get_xmm 11 va_sM ==
va_get_xmm 11 va_s0) /\ (win ==> va_get_xmm 12 va_sM == va_get_xmm 12 va_s0) /\ (win ==>
va_get_xmm 13 va_sM == va_get_xmm 13 va_s0) /\ (win ==> va_get_xmm 14 va_sM == va_get_xmm 14
va_s0) /\ (win ==> va_get_xmm 15 va_sM == va_get_xmm 15 va_s0) /\ (~win ==> va_get_reg64 rRbx
va_sM == va_get_reg64 rRbx va_s0) /\ (~win ==> va_get_reg64 rRbp va_sM == va_get_reg64 rRbp
va_s0) /\ (~win ==> va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0) /\ (~win ==>
va_get_reg64 rR13 va_sM == va_get_reg64 rR13 va_s0) /\ (~win ==> va_get_reg64 rR14 va_sM ==
va_get_reg64 rR14 va_s0) /\ (~win ==> va_get_reg64 rR15 va_sM == va_get_reg64 rR15 va_s0))) /\
va_state_eq va_sM (va_update_stackTaint va_sM (va_update_stack va_sM (va_update_flags va_sM
(va_update_mem_heaplet 6 va_sM (va_update_mem_heaplet 5 va_sM (va_update_mem_heaplet 4 va_sM
(va_update_mem_heaplet 3 va_sM (va_update_mem_heaplet 2 va_sM (va_update_mem_heaplet 1 va_sM
(va_update_mem_layout va_sM (va_update_xmm 15 va_sM (va_update_xmm 14 va_sM (va_update_xmm 13
va_sM (va_update_xmm 12 va_sM (va_update_xmm 11 va_sM (va_update_xmm 10 va_sM (va_update_xmm 9
va_sM (va_update_xmm 8 va_sM (va_update_xmm 7 va_sM (va_update_xmm 6 va_sM (va_update_xmm 5
va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1
va_sM (va_update_xmm 0 va_sM (va_update_reg64 rR15 va_sM (va_update_reg64 rR14 va_sM
(va_update_reg64 rR13 va_sM (va_update_reg64 rR12 va_sM (va_update_reg64 rR11 va_sM
(va_update_reg64 rR10 va_sM (va_update_reg64 rR9 va_sM (va_update_reg64 rR8 va_sM
(va_update_reg64 rRbp va_sM (va_update_reg64 rRsp va_sM (va_update_reg64 rRsi va_sM
(va_update_reg64 rRdi va_sM (va_update_reg64 rRdx va_sM (va_update_reg64 rRcx va_sM
(va_update_reg64 rRbx va_sM (va_update_reg64 rRax va_sM (va_update_ok va_sM (va_update_mem
va_sM va_s0)))))))))))))))))))))))))))))))))))))))))))))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.Stack.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsStack.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.InsAes.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Poly1305.Math.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Lib.Meta.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.Arch.HeapImpl.fsti.checked",
"Vale.AES.X64.GHash.fsti.checked",
"Vale.AES.X64.GF128_Mul.fsti.checked",
"Vale.AES.X64.GCTR.fsti.checked",
"Vale.AES.X64.AESopt2.fsti.checked",
"Vale.AES.X64.AESopt.fsti.checked",
"Vale.AES.X64.AESGCM.fsti.checked",
"Vale.AES.X64.AES.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GHash_s.fst.checked",
"Vale.AES.GHash.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.fsti.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.GCTR.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.GCM_helpers.fsti.checked",
"Vale.AES.GCM.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.X64.GCMencryptOpt.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AESopt2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AESGCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AESopt",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GCTR",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
win: Prims.bool ->
alg: Vale.AES.AES_common_s.algorithm ->
auth_b: Vale.X64.Memory.buffer128 ->
auth_bytes: Vale.X64.Memory.nat64 ->
auth_num: Vale.X64.Memory.nat64 ->
keys_b: Vale.X64.Memory.buffer128 ->
iv_b: Vale.X64.Memory.buffer128 ->
iv: Vale.AES.GCM_s.supported_iv_LE ->
hkeys_b: Vale.X64.Memory.buffer128 ->
abytes_b: Vale.X64.Memory.buffer128 ->
in128x6_b: Vale.X64.Memory.buffer128 ->
out128x6_b: Vale.X64.Memory.buffer128 ->
len128x6_num: Vale.X64.Memory.nat64 ->
in128_b: Vale.X64.Memory.buffer128 ->
out128_b: Vale.X64.Memory.buffer128 ->
len128_num: Vale.X64.Memory.nat64 ->
inout_b: Vale.X64.Memory.buffer128 ->
plain_num: Vale.X64.Memory.nat64 ->
scratch_b: Vale.X64.Memory.buffer128 ->
tag_b: Vale.X64.Memory.buffer128 ->
key: FStar.Seq.Base.seq Vale.X64.Memory.nat32 ->
va_s0: Vale.X64.Decls.va_state ->
va_k: (_: Vale.X64.Decls.va_state -> _: Prims.unit -> Type0)
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Vale.AES.AES_common_s.algorithm",
"Vale.X64.Memory.buffer128",
"Vale.X64.Memory.nat64",
"Vale.AES.GCM_s.supported_iv_LE",
"FStar.Seq.Base.seq",
"Vale.X64.Memory.nat32",
"Vale.X64.Decls.va_state",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Decls.va_get_ok",
"Vale.X64.CPU_Features_s.aesni_enabled",
"Vale.X64.CPU_Features_s.pclmulqdq_enabled",
"Vale.X64.CPU_Features_s.avx_enabled",
"Vale.X64.CPU_Features_s.sse_enabled",
"Vale.X64.CPU_Features_s.movbe_enabled",
"Prims.eq2",
"Vale.Def.Words_s.nat64",
"Vale.X64.Decls.va_get_reg64",
"Vale.X64.Machine_s.rRsp",
"Vale.X64.Stack_i.init_rsp",
"Vale.X64.Decls.va_get_stack",
"Vale.X64.Memory.is_initial_heap",
"Vale.X64.Decls.va_get_mem_layout",
"Vale.X64.Decls.va_get_mem",
"Prims.l_imp",
"Prims.l_not",
"Vale.X64.Stack_i.valid_stack_slot64",
"Prims.op_Addition",
"Vale.Arch.HeapTypes_s.Public",
"Vale.X64.Decls.va_get_stackTaint",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThan",
"Vale.Def.Words_s.pow2_64",
"Prims.op_LessThanOrEqual",
"Vale.X64.Decls.validSrcAddrs128",
"Vale.Arch.HeapTypes_s.Secret",
"Vale.X64.Decls.validDstAddrs128",
"Vale.X64.Decls.buffer_disjoints128",
"Prims.Cons",
"Prims.Nil",
"Vale.X64.Decls.buffers_disjoint128",
"Prims.op_Multiply",
"Vale.X64.Machine_s.pow2_64",
"Vale.X64.Decls.buffer_length",
"Vale.X64.Memory.vuint128",
"Prims.nat",
"Vale.X64.Machine_s.pow2_32",
"Vale.X64.Memory.buffer_addr",
"Prims.op_Modulus",
"Prims.op_GreaterThan",
"Vale.X64.Decls.va_mul_nat",
"Prims.op_Division",
"Prims.op_Equality",
"Vale.AES.AES_common_s.AES_128",
"Vale.AES.AES_common_s.AES_256",
"Vale.AES.AES_s.is_aes_key_LE",
"Vale.Def.Types_s.quad32",
"Vale.X64.Decls.buffer128_as_seq",
"Vale.AES.AES_s.key_to_round_keys_LE",
"Vale.AES.AES_common_s.nr",
"Vale.AES.OptPublic.hkeys_reqs_pub",
"Vale.X64.Decls.s128",
"Vale.Def.Types_s.reverse_bytes_quad32",
"Vale.AES.AES_s.aes_encrypt_LE",
"Vale.Def.Words_s.Mkfour",
"Vale.Def.Types_s.nat32",
"Vale.AES.GCM_s.compute_iv_BE",
"Vale.X64.Decls.buffer128_read",
"Vale.X64.Decls.va_int_range",
"Vale.X64.Decls.va_if",
"Vale.X64.Stack_i.load_stack64",
"Vale.X64.Machine_s.rR9",
"Vale.X64.Machine_s.rR8",
"Vale.Def.Types_s.nat64",
"Vale.X64.Machine_s.rRcx",
"Vale.X64.Machine_s.rRdx",
"Vale.X64.Machine_s.rRsi",
"Vale.X64.Machine_s.rRdi",
"Prims.l_Forall",
"Vale.X64.InsBasic.vale_heap",
"Vale.X64.Decls.quad32",
"Vale.Arch.HeapImpl.vale_heap_layout",
"Vale.X64.Flags.t",
"Vale.X64.InsBasic.vale_stack",
"Vale.X64.Memory.memtaint",
"Vale.X64.Decls.modifies_mem",
"Vale.X64.Decls.loc_union",
"Vale.X64.Decls.loc_buffer",
"FStar.Seq.Base.length",
"Vale.Def.Types_s.nat8",
"Vale.AES.AES_common_s.is_aes_key",
"Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE",
"FStar.Pervasives.Native.__proj__Mktuple2__item___1",
"Vale.AES.GCM_s.gcm_encrypt_LE",
"Vale.Def.Types_s.le_quad32_to_bytes",
"FStar.Pervasives.Native.__proj__Mktuple2__item___2",
"Vale.X64.Machine_s.rRbx",
"Vale.X64.Machine_s.rRbp",
"Vale.X64.Machine_s.rR12",
"Vale.X64.Machine_s.rR13",
"Vale.X64.Machine_s.rR14",
"Vale.X64.Machine_s.rR15",
"Vale.X64.Decls.va_get_xmm",
"Vale.Def.Words_s.nat8",
"FStar.Seq.Base.slice",
"Vale.Def.Types_s.le_seq_quad32_to_bytes",
"FStar.Seq.Base.append",
"Vale.X64.State.vale_state",
"Vale.X64.Decls.va_upd_stackTaint",
"Vale.X64.Decls.va_upd_stack",
"Vale.X64.Decls.va_upd_flags",
"Vale.X64.Decls.va_upd_mem_heaplet",
"Vale.X64.Decls.va_upd_mem_layout",
"Vale.X64.Decls.va_upd_xmm",
"Vale.X64.Decls.va_upd_reg64",
"Vale.X64.Machine_s.rR11",
"Vale.X64.Machine_s.rR10",
"Vale.X64.Machine_s.rRax",
"Vale.X64.Decls.va_upd_mem"
] | [] | false | false | false | true | true | let va_wp_Gcm_blocks_stdcall
(win: bool)
(alg: algorithm)
(auth_b: buffer128)
(auth_bytes auth_num: nat64)
(keys_b iv_b: buffer128)
(iv: supported_iv_LE)
(hkeys_b abytes_b in128x6_b out128x6_b: buffer128)
(len128x6_num: nat64)
(in128_b out128_b: buffer128)
(len128_num: nat64)
(inout_b: buffer128)
(plain_num: nat64)
(scratch_b tag_b: buffer128)
(key: (seq nat32))
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 =
| (va_get_ok va_s0 /\
(let auth_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0)
in
let auth_num_bytes:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0)
in
let auth_len:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rR8 va_s0) (fun _ -> va_get_reg64 rRdx va_s0)
in
let keys_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rR9 va_s0) (fun _ -> va_get_reg64 rRcx va_s0)
in
let iv_ptr:(va_int_range 0 18446744073709551615) =
va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0)
(va_get_stack va_s0))
(fun _ -> va_get_reg64 rR8 va_s0)
in
let xip:(va_int_range 0 18446744073709551615) =
va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8)
(va_get_stack va_s0))
(fun _ -> va_get_reg64 rR9 va_s0)
in
let abytes_ptr:(va_int_range 0 18446744073709551615) =
va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 16) (va_get_stack va_s0))
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0))
in
let in128x6_ptr:(va_int_range 0 18446744073709551615) =
va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 24) (va_get_stack va_s0))
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0))
in
let out128x6_ptr:(va_int_range 0 18446744073709551615) =
va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 32) (va_get_stack va_s0))
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 16) (va_get_stack va_s0))
in
let len128x6:(va_int_range 0 18446744073709551615) =
va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 40) (va_get_stack va_s0))
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 24) (va_get_stack va_s0))
in
let in128_ptr:(va_int_range 0 18446744073709551615) =
va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 48) (va_get_stack va_s0))
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 32) (va_get_stack va_s0))
in
let out128_ptr:(va_int_range 0 18446744073709551615) =
va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 56) (va_get_stack va_s0))
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 40) (va_get_stack va_s0))
in
let len128:(va_int_range 0 18446744073709551615) =
va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 64) (va_get_stack va_s0))
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 48) (va_get_stack va_s0))
in
let inout_ptr:(va_int_range 0 18446744073709551615) =
va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 72) (va_get_stack va_s0))
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 56) (va_get_stack va_s0))
in
let plain_num_bytes:(va_int_range 0 18446744073709551615) =
va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 80) (va_get_stack va_s0))
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 64) (va_get_stack va_s0))
in
let scratch_ptr:(va_int_range 0 18446744073709551615) =
va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 88) (va_get_stack va_s0))
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 72) (va_get_stack va_s0))
in
let tag_ptr:(va_int_range 0 18446744073709551615) =
va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 96) (va_get_stack va_s0))
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 80) (va_get_stack va_s0))
in
aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ sse_enabled /\ movbe_enabled /\
va_get_reg64 rRsp va_s0 == Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\
Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\
(~win ==>
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 0)
(va_get_stack va_s0)
Public
(va_get_stackTaint va_s0)) /\
(~win ==>
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 8)
(va_get_stack va_s0)
Public
(va_get_stackTaint va_s0)) /\
(~win ==>
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 16)
(va_get_stack va_s0)
Public
(va_get_stackTaint va_s0)) /\
(~win ==>
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 24)
(va_get_stack va_s0)
Public
(va_get_stackTaint va_s0)) /\
(~win ==>
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 32)
(va_get_stack va_s0)
Public
(va_get_stackTaint va_s0)) /\
(~win ==>
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 40)
(va_get_stack va_s0)
Public
(va_get_stackTaint va_s0)) /\
(~win ==>
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 48)
(va_get_stack va_s0)
Public
(va_get_stackTaint va_s0)) /\
(~win ==>
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 56)
(va_get_stack va_s0)
Public
(va_get_stackTaint va_s0)) /\
(~win ==>
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 64)
(va_get_stack va_s0)
Public
(va_get_stackTaint va_s0)) /\
(~win ==>
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 72)
(va_get_stack va_s0)
Public
(va_get_stackTaint va_s0)) /\
(~win ==>
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 8 + 80)
(va_get_stack va_s0)
Public
(va_get_stackTaint va_s0)) /\
(win ==>
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 0)
(va_get_stack va_s0)
Public
(va_get_stackTaint va_s0)) /\
(win ==>
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 8)
(va_get_stack va_s0)
Public
(va_get_stackTaint va_s0)) /\
(win ==>
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 16)
(va_get_stack va_s0)
Public
(va_get_stackTaint va_s0)) /\
(win ==>
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 24)
(va_get_stack va_s0)
Public
(va_get_stackTaint va_s0)) /\
(win ==>
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 32)
(va_get_stack va_s0)
Public
(va_get_stackTaint va_s0)) /\
(win ==>
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 40)
(va_get_stack va_s0)
Public
(va_get_stackTaint va_s0)) /\
(win ==>
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 48)
(va_get_stack va_s0)
Public
(va_get_stackTaint va_s0)) /\
(win ==>
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 56)
(va_get_stack va_s0)
Public
(va_get_stackTaint va_s0)) /\
(win ==>
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 64)
(va_get_stack va_s0)
Public
(va_get_stackTaint va_s0)) /\
(win ==>
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 72)
(va_get_stack va_s0)
Public
(va_get_stackTaint va_s0)) /\
(win ==>
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 80)
(va_get_stack va_s0)
Public
(va_get_stackTaint va_s0)) /\
(win ==>
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 88)
(va_get_stack va_s0)
Public
(va_get_stackTaint va_s0)) /\
(win ==>
Vale.X64.Stack_i.valid_stack_slot64 (va_get_reg64 rRsp va_s0 + 40 + 96)
(va_get_stack va_s0)
Public
(va_get_stackTaint va_s0)) /\ auth_len == auth_num /\ auth_num_bytes == auth_bytes /\
len128x6 == len128x6_num /\ len128 == len128_num /\ plain_num_bytes == plain_num /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0)
auth_ptr
auth_b
auth_len
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0)
abytes_ptr
abytes_b
1
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0)
iv_ptr
iv_b
1
(va_get_mem_layout va_s0)
Public /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0)
in128x6_ptr
in128x6_b
len128x6
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0)
out128x6_ptr
out128x6_b
len128x6
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0)
in128_ptr
in128_b
len128
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0)
out128_ptr
out128_b
len128
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0)
inout_ptr
inout_b
1
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0)
scratch_ptr
scratch_b
9
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0)
xip
hkeys_b
8
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0)
tag_ptr
tag_b
1
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.buffer_disjoints128 tag_b
([
keys_b; auth_b; abytes_b; iv_b; in128x6_b; out128x6_b; in128_b; out128_b; inout_b;
scratch_b; hkeys_b
]) /\
Vale.X64.Decls.buffer_disjoints128 iv_b
([
keys_b; auth_b; abytes_b; in128x6_b; out128x6_b; in128_b; out128_b; inout_b; scratch_b;
hkeys_b
]) /\
Vale.X64.Decls.buffer_disjoints128 scratch_b
([keys_b; auth_b; abytes_b; in128x6_b; out128x6_b; in128_b; out128_b; inout_b; hkeys_b]) /\
Vale.X64.Decls.buffer_disjoints128 inout_b
([keys_b; auth_b; abytes_b; in128x6_b; out128x6_b; in128_b; out128_b; hkeys_b]) /\
Vale.X64.Decls.buffer_disjoints128 auth_b ([keys_b; abytes_b; hkeys_b]) /\
Vale.X64.Decls.buffer_disjoints128 abytes_b ([keys_b; hkeys_b]) /\
Vale.X64.Decls.buffer_disjoints128 out128x6_b
([keys_b; auth_b; abytes_b; hkeys_b; in128_b; inout_b]) /\
Vale.X64.Decls.buffer_disjoints128 in128x6_b
([keys_b; auth_b; abytes_b; hkeys_b; in128_b; inout_b]) /\
Vale.X64.Decls.buffer_disjoints128 out128_b
([keys_b; auth_b; abytes_b; hkeys_b; in128x6_b; out128x6_b; inout_b]) /\
Vale.X64.Decls.buffer_disjoints128 in128_b
([keys_b; auth_b; abytes_b; hkeys_b; in128x6_b; out128x6_b; inout_b]) /\
(Vale.X64.Decls.buffers_disjoint128 in128x6_b out128x6_b \/ in128x6_b == out128x6_b) /\
(Vale.X64.Decls.buffers_disjoint128 in128_b out128_b \/ in128_b == out128_b) /\
auth_ptr + 16 `op_Multiply` auth_len < pow2_64 /\
in128x6_ptr + 16 `op_Multiply` len128x6 < pow2_64 /\
out128x6_ptr + 16 `op_Multiply` len128x6 < pow2_64 /\
in128_ptr + 16 `op_Multiply` len128 < pow2_64 /\ out128_ptr + 16 `op_Multiply` len128 < pow2_64 /\
inout_ptr + 16 < pow2_64 /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 auth_b == auth_len /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 abytes_b == 1 /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in128x6_b ==
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 out128x6_b /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in128_b ==
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 out128_b /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in128x6_b == len128x6 /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 in128_b == len128 /\
Vale.X64.Decls.buffer_length #Vale.X64.Memory.vuint128 inout_b == 1 /\ plain_num_bytes < pow2_32 /\
auth_num_bytes < pow2_32 /\ xip + 32 < pow2_64 /\
Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_b (va_get_mem va_s0) + 128 < pow2_64 /\
len128x6 `op_Modulus` 6 == 0 /\ (len128x6 > 0 ==> len128x6 >= 18) /\ 12 + len128x6 + 6 < pow2_32 /\
(va_mul_nat len128x6 (128 `op_Division` 8) + va_mul_nat len128 (128 `op_Division` 8) <=
plain_num_bytes /\
plain_num_bytes <
va_mul_nat len128x6 (128 `op_Division` 8) + va_mul_nat len128 (128 `op_Division` 8) +
128
`op_Division`
8) /\
(va_mul_nat auth_len (128 `op_Division` 8) <= auth_num_bytes /\
auth_num_bytes < va_mul_nat auth_len (128 `op_Division` 8) + 128 `op_Division` 8) /\
(alg = AES_128 \/ alg = AES_256) /\ Vale.AES.AES_s.is_aes_key_LE alg key /\
Vale.X64.Decls.buffer128_as_seq (va_get_mem va_s0) keys_b ==
Vale.AES.AES_s.key_to_round_keys_LE alg key /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0)
keys_ptr
keys_b
(Vale.AES.AES_common_s.nr alg + 1)
(va_get_mem_layout va_s0)
Secret /\
Vale.AES.OptPublic.hkeys_reqs_pub (Vale.X64.Decls.s128 (va_get_mem va_s0) hkeys_b)
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE alg
key
(Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0))) /\
(let h_LE =
Vale.AES.AES_s.aes_encrypt_LE alg
key
(Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0)
in
let iv_BE = Vale.X64.Decls.buffer128_read iv_b 0 (va_get_mem va_s0) in
iv_BE == Vale.AES.GCM_s.compute_iv_BE h_LE iv)) /\
(forall (va_x_mem: vale_heap) (va_x_rax: nat64) (va_x_rbx: nat64) (va_x_rcx: nat64)
(va_x_rdx: nat64) (va_x_rdi: nat64) (va_x_rsi: nat64) (va_x_rsp: nat64) (va_x_rbp: nat64)
(va_x_r8: nat64) (va_x_r9: nat64) (va_x_r10: nat64) (va_x_r11: nat64) (va_x_r12: nat64)
(va_x_r13: nat64) (va_x_r14: nat64) (va_x_r15: nat64) (va_x_xmm0: quad32) (va_x_xmm1: quad32)
(va_x_xmm2: quad32) (va_x_xmm3: quad32) (va_x_xmm4: quad32) (va_x_xmm5: quad32)
(va_x_xmm6: quad32) (va_x_xmm7: quad32) (va_x_xmm8: quad32) (va_x_xmm9: quad32)
(va_x_xmm10: quad32) (va_x_xmm11: quad32) (va_x_xmm12: quad32) (va_x_xmm13: quad32)
(va_x_xmm14: quad32) (va_x_xmm15: quad32) (va_x_memLayout: vale_heap_layout)
(va_x_heap1: vale_heap) (va_x_heap2: vale_heap) (va_x_heap3: vale_heap)
(va_x_heap4: vale_heap) (va_x_heap5: vale_heap) (va_x_heap6: vale_heap)
(va_x_efl: Vale.X64.Flags.t) (va_x_stack: vale_stack) (va_x_stackTaint: memtaint).
let va_sM =
va_upd_stackTaint va_x_stackTaint
(va_upd_stack va_x_stack
(va_upd_flags va_x_efl
(va_upd_mem_heaplet 6
va_x_heap6
(va_upd_mem_heaplet 5
va_x_heap5
(va_upd_mem_heaplet 4
va_x_heap4
(va_upd_mem_heaplet 3
va_x_heap3
(va_upd_mem_heaplet 2
va_x_heap2
(va_upd_mem_heaplet 1
va_x_heap1
(va_upd_mem_layout va_x_memLayout
(va_upd_xmm 15
va_x_xmm15
(va_upd_xmm 14
va_x_xmm14
(va_upd_xmm 13
va_x_xmm13
(va_upd_xmm 12
va_x_xmm12
(va_upd_xmm 11
va_x_xmm11
(va_upd_xmm 10
va_x_xmm10
(va_upd_xmm 9
va_x_xmm9
(va_upd_xmm 8
va_x_xmm8
(va_upd_xmm 7
va_x_xmm7
(va_upd_xmm 6
va_x_xmm6
(va_upd_xmm 5
va_x_xmm5
(va_upd_xmm
4
va_x_xmm4
(va_upd_xmm
3
va_x_xmm3
(va_upd_xmm
2
va_x_xmm2
(
va_upd_xmm
1
va_x_xmm1
(
va_upd_xmm
0
va_x_xmm0
(
va_upd_reg64
rR15
va_x_r15
(
va_upd_reg64
rR14
va_x_r14
(
va_upd_reg64
rR13
va_x_r13
(
va_upd_reg64
rR12
va_x_r12
(
va_upd_reg64
rR11
va_x_r11
(
va_upd_reg64
rR10
va_x_r10
(
va_upd_reg64
rR9
va_x_r9
(
va_upd_reg64
rR8
va_x_r8
(
va_upd_reg64
rRbp
va_x_rbp
(
va_upd_reg64
rRsp
va_x_rsp
(
va_upd_reg64
rRsi
va_x_rsi
(
va_upd_reg64
rRdi
va_x_rdi
(
va_upd_reg64
rRdx
va_x_rdx
(
va_upd_reg64
rRcx
va_x_rcx
(
va_upd_reg64
rRbx
va_x_rbx
(
va_upd_reg64
rRax
va_x_rax
(
va_upd_mem
va_x_mem
va_s0
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
))
))))))))))
)))))))))))
in
va_get_ok va_sM /\
(let auth_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0)
in
let auth_num_bytes:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0)
in
let auth_len:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rR8 va_s0) (fun _ -> va_get_reg64 rRdx va_s0)
in
let keys_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rR9 va_s0) (fun _ -> va_get_reg64 rRcx va_s0)
in
let iv_ptr:(va_int_range 0 18446744073709551615) =
va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0)
(va_get_stack va_s0))
(fun _ -> va_get_reg64 rR8 va_s0)
in
let xip:(va_int_range 0 18446744073709551615) =
va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8)
(va_get_stack va_s0))
(fun _ -> va_get_reg64 rR9 va_s0)
in
let abytes_ptr:(va_int_range 0 18446744073709551615) =
va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 16)
(va_get_stack va_s0))
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)
)
in
let in128x6_ptr:(va_int_range 0 18446744073709551615) =
va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 24)
(va_get_stack va_s0))
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)
)
in
let out128x6_ptr:(va_int_range 0 18446744073709551615) =
va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 32)
(va_get_stack va_s0))
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 16)
(va_get_stack va_s0))
in
let len128x6:(va_int_range 0 18446744073709551615) =
va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 40)
(va_get_stack va_s0))
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 24)
(va_get_stack va_s0))
in
let in128_ptr:(va_int_range 0 18446744073709551615) =
va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 48)
(va_get_stack va_s0))
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 32)
(va_get_stack va_s0))
in
let out128_ptr:(va_int_range 0 18446744073709551615) =
va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 56)
(va_get_stack va_s0))
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 40)
(va_get_stack va_s0))
in
let len128:(va_int_range 0 18446744073709551615) =
va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 64)
(va_get_stack va_s0))
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 48)
(va_get_stack va_s0))
in
let inout_ptr:(va_int_range 0 18446744073709551615) =
va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 72)
(va_get_stack va_s0))
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 56)
(va_get_stack va_s0))
in
let plain_num_bytes:(va_int_range 0 18446744073709551615) =
va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 80)
(va_get_stack va_s0))
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 64)
(va_get_stack va_s0))
in
let scratch_ptr:(va_int_range 0 18446744073709551615) =
va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 88)
(va_get_stack va_s0))
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 72)
(va_get_stack va_s0))
in
let tag_ptr:(va_int_range 0 18446744073709551615) =
va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 40 + 96)
(va_get_stack va_s0))
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 80)
(va_get_stack va_s0))
in
Vale.X64.Decls.modifies_mem (Vale.X64.Decls.loc_union (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128
tag_b)
(Vale.X64.Decls.loc_union (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 iv_b)
(Vale.X64.Decls.loc_union (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128
scratch_b)
(Vale.X64.Decls.loc_union (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128
out128x6_b)
(Vale.X64.Decls.loc_union (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128
out128_b)
(Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 inout_b))))))
(va_get_mem va_s0)
(va_get_mem va_sM) /\ plain_num_bytes < pow2_32 /\ auth_num_bytes < pow2_32 /\
(let iv_BE = Vale.X64.Decls.buffer128_read iv_b 0 (va_get_mem va_s0) in
let auth_raw_quads =
FStar.Seq.Base.append #Vale.X64.Decls.quad32
(Vale.X64.Decls.s128 (va_get_mem va_s0) auth_b)
(Vale.X64.Decls.s128 (va_get_mem va_s0) abytes_b)
in
let auth_bytes =
FStar.Seq.Base.slice #Vale.Def.Types_s.nat8
(Vale.Def.Types_s.le_seq_quad32_to_bytes auth_raw_quads)
0
auth_num_bytes
in
let plain_raw_quads =
FStar.Seq.Base.append #Vale.X64.Decls.quad32
(FStar.Seq.Base.append #Vale.X64.Decls.quad32
(Vale.X64.Decls.s128 (va_get_mem va_s0) in128x6_b)
(Vale.X64.Decls.s128 (va_get_mem va_s0) in128_b))
(Vale.X64.Decls.s128 (va_get_mem va_s0) inout_b)
in
let plain_bytes =
FStar.Seq.Base.slice #Vale.Def.Types_s.nat8
(Vale.Def.Types_s.le_seq_quad32_to_bytes plain_raw_quads)
0
plain_num_bytes
in
let cipher_raw_quads =
FStar.Seq.Base.append #Vale.X64.Decls.quad32
(FStar.Seq.Base.append #Vale.X64.Decls.quad32
(Vale.X64.Decls.s128 (va_get_mem va_sM) out128x6_b)
(Vale.X64.Decls.s128 (va_get_mem va_sM) out128_b))
(Vale.X64.Decls.s128 (va_get_mem va_sM) inout_b)
in
let cipher_bytes =
FStar.Seq.Base.slice #Vale.Def.Types_s.nat8
(Vale.Def.Types_s.le_seq_quad32_to_bytes cipher_raw_quads)
0
plain_num_bytes
in
l_and (l_and (l_and (l_and (FStar.Seq.Base.length #Vale.Def.Types_s.nat8 auth_bytes <
pow2_32)
(FStar.Seq.Base.length #Vale.Def.Types_s.nat8 plain_bytes < pow2_32))
(Vale.AES.AES_common_s.is_aes_key alg
(Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE key)))
(cipher_bytes ==
__proj__Mktuple2__item___1 #(FStar.Seq.Base.seq Vale.Def.Types_s.nat8)
#(FStar.Seq.Base.seq Vale.Def.Types_s.nat8)
(Vale.AES.GCM_s.gcm_encrypt_LE alg
(Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE key)
iv
plain_bytes
auth_bytes)))
(Vale.Def.Types_s.le_quad32_to_bytes (Vale.X64.Decls.buffer128_read tag_b
0
(va_get_mem va_sM)) ==
__proj__Mktuple2__item___2 #(FStar.Seq.Base.seq Vale.Def.Types_s.nat8)
#(FStar.Seq.Base.seq Vale.Def.Types_s.nat8)
(Vale.AES.GCM_s.gcm_encrypt_LE alg
(Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE key)
iv
plain_bytes
auth_bytes)) /\ va_get_reg64 rRsp va_sM == va_get_reg64 rRsp va_s0 /\
(win ==> va_get_reg64 rRbx va_sM == va_get_reg64 rRbx va_s0) /\
(win ==> va_get_reg64 rRbp va_sM == va_get_reg64 rRbp va_s0) /\
(win ==> va_get_reg64 rRdi va_sM == va_get_reg64 rRdi va_s0) /\
(win ==> va_get_reg64 rRsi va_sM == va_get_reg64 rRsi va_s0) /\
(win ==> va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0) /\
(win ==> va_get_reg64 rR13 va_sM == va_get_reg64 rR13 va_s0) /\
(win ==> va_get_reg64 rR14 va_sM == va_get_reg64 rR14 va_s0) /\
(win ==> va_get_reg64 rR15 va_sM == va_get_reg64 rR15 va_s0) /\
(win ==> va_get_xmm 6 va_sM == va_get_xmm 6 va_s0) /\
(win ==> va_get_xmm 7 va_sM == va_get_xmm 7 va_s0) /\
(win ==> va_get_xmm 8 va_sM == va_get_xmm 8 va_s0) /\
(win ==> va_get_xmm 9 va_sM == va_get_xmm 9 va_s0) /\
(win ==> va_get_xmm 10 va_sM == va_get_xmm 10 va_s0) /\
(win ==> va_get_xmm 11 va_sM == va_get_xmm 11 va_s0) /\
(win ==> va_get_xmm 12 va_sM == va_get_xmm 12 va_s0) /\
(win ==> va_get_xmm 13 va_sM == va_get_xmm 13 va_s0) /\
(win ==> va_get_xmm 14 va_sM == va_get_xmm 14 va_s0) /\
(win ==> va_get_xmm 15 va_sM == va_get_xmm 15 va_s0) /\
(~win ==> va_get_reg64 rRbx va_sM == va_get_reg64 rRbx va_s0) /\
(~win ==> va_get_reg64 rRbp va_sM == va_get_reg64 rRbp va_s0) /\
(~win ==> va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0) /\
(~win ==> va_get_reg64 rR13 va_sM == va_get_reg64 rR13 va_s0) /\
(~win ==> va_get_reg64 rR14 va_sM == va_get_reg64 rR14 va_s0) /\
(~win ==> va_get_reg64 rR15 va_sM == va_get_reg64 rR15 va_s0))) ==>
va_k va_sM (()))) | false |
Hacl.Chacha20.Vec32.fst | Hacl.Chacha20.Vec32.chacha20_core_32 | val chacha20_core_32 : Hacl.Meta.Chacha20.Vec.vec_chacha20_core_higher_t Prims.l_True | let chacha20_core_32 = vec_chacha20_core_higher #1 True double_round_32 | {
"file_name": "code/chacha20/Hacl.Chacha20.Vec32.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 71,
"end_line": 10,
"start_col": 0,
"start_line": 10
} | module Hacl.Chacha20.Vec32
open Hacl.Meta.Chacha20.Vec
[@CInline]
private
let double_round_32 = Hacl.Impl.Chacha20.Core32xN.double_round #1
[@CInline] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hacl.Meta.Chacha20.Vec.fst.checked",
"Hacl.Impl.Chacha20.Vec.fst.checked",
"Hacl.Impl.Chacha20.Core32xN.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Chacha20.Vec32.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Meta.Chacha20.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Meta.Chacha20.Vec.vec_chacha20_core_higher_t Prims.l_True | Prims.Tot | [
"total"
] | [] | [
"Hacl.Meta.Chacha20.Vec.vec_chacha20_core_higher",
"Prims.l_True",
"Hacl.Chacha20.Vec32.double_round_32"
] | [] | false | false | false | false | false | let chacha20_core_32 =
| vec_chacha20_core_higher #1 True double_round_32 | false |
|
Spec.Ed25519.PointOps.fst | Spec.Ed25519.PointOps.is_ext | val is_ext : p: Spec.Ed25519.PointOps.ext_point -> Prims.logical | let is_ext (p:ext_point) =
let _X, _Y, _Z, _T = p in
_T == _X *% _Y /% _Z /\ _Z <> zero | {
"file_name": "specs/Spec.Ed25519.PointOps.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 36,
"end_line": 39,
"start_col": 0,
"start_line": 37
} | module Spec.Ed25519.PointOps
open FStar.Mul
open Spec.Curve25519
module BSeq = Lib.ByteSequence
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
type aff_point = elem & elem // Affine point
type ext_point = elem & elem & elem & elem // Homogeneous extended coordinates
(* 2 **% ((prime - 1) / 4) *)
let modp_sqrt_m1 : elem = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0
let d : elem =
let x = 37095705934669439343138083508754565189542113879843219016388785533085940283555 in
assert_norm(x < prime);
x
let g_x : elem = 15112221349535400772501151409588531511454012693041857206046113283949847762202
let g_y : elem = 46316835694926478169428394003475163141307993866256225615783033603165251855960
let aff_g : aff_point = (g_x, g_y)
let g: ext_point = (g_x, g_y, 1, g_x *% g_y)
let is_on_curve (p:aff_point) =
let (x, y) = p in
y *% y -% x *% x == 1 +% d *% (x *% x) *% (y *% y)
let to_aff_point (p:ext_point) : aff_point =
let _X, _Y, _Z, _T = p in
_X /% _Z, _Y /% _Z | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Ed25519.PointOps.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Spec.Ed25519.PointOps.ext_point -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Spec.Ed25519.PointOps.ext_point",
"Spec.Curve25519.elem",
"Prims.l_and",
"Prims.eq2",
"Spec.Curve25519.op_Slash_Percent",
"Spec.Curve25519.op_Star_Percent",
"Prims.b2t",
"Prims.op_disEquality",
"Spec.Curve25519.zero",
"Prims.logical"
] | [] | false | false | false | true | true | let is_ext (p: ext_point) =
| let _X, _Y, _Z, _T = p in
_T == _X *% _Y /% _Z /\ _Z <> zero | false |
|
Spec.Ed25519.PointOps.fst | Spec.Ed25519.PointOps.aff_point_double | val aff_point_double (p: aff_point) : aff_point | val aff_point_double (p: aff_point) : aff_point | let aff_point_double (p:aff_point) : aff_point =
let x, y = p in
let x3 = (2 *% x *% y) /% (y *% y -% x *% x) in
let y3 = (y *% y +% x *% x) /% (2 -% y *% y +% x *% x) in
x3, y3 | {
"file_name": "specs/Spec.Ed25519.PointOps.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 8,
"end_line": 65,
"start_col": 0,
"start_line": 61
} | module Spec.Ed25519.PointOps
open FStar.Mul
open Spec.Curve25519
module BSeq = Lib.ByteSequence
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
type aff_point = elem & elem // Affine point
type ext_point = elem & elem & elem & elem // Homogeneous extended coordinates
(* 2 **% ((prime - 1) / 4) *)
let modp_sqrt_m1 : elem = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0
let d : elem =
let x = 37095705934669439343138083508754565189542113879843219016388785533085940283555 in
assert_norm(x < prime);
x
let g_x : elem = 15112221349535400772501151409588531511454012693041857206046113283949847762202
let g_y : elem = 46316835694926478169428394003475163141307993866256225615783033603165251855960
let aff_g : aff_point = (g_x, g_y)
let g: ext_point = (g_x, g_y, 1, g_x *% g_y)
let is_on_curve (p:aff_point) =
let (x, y) = p in
y *% y -% x *% x == 1 +% d *% (x *% x) *% (y *% y)
let to_aff_point (p:ext_point) : aff_point =
let _X, _Y, _Z, _T = p in
_X /% _Z, _Y /% _Z
let is_ext (p:ext_point) =
let _X, _Y, _Z, _T = p in
_T == _X *% _Y /% _Z /\ _Z <> zero
let point_inv (p:ext_point) =
is_ext p /\ is_on_curve (to_aff_point p)
// let is_on_curve_ext (p:ext_point) =
// let _X, _Y, _Z, _T = p in
// _Y *% _Y -% X *% X == _Z *% _Z +% d *% _T *% _T
// let to_ext_point (p:aff_point) : ext_point =
// let x, y = p in
// (x, y, one, x *% y)
/// Point addition and doubling in affine coordinates
let aff_point_add (p:aff_point) (q:aff_point) : aff_point =
let x1, y1 = p in
let x2, y2 = q in
let x3 = (x1 *% y2 +% y1 *% x2) /% (1 +% d *% (x1 *% x2) *% (y1 *% y2)) in
let y3 = (y1 *% y2 +% x1 *% x2) /% (1 -% d *% (x1 *% x2) *% (y1 *% y2)) in
x3, y3 | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Ed25519.PointOps.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Spec.Ed25519.PointOps.aff_point -> Spec.Ed25519.PointOps.aff_point | Prims.Tot | [
"total"
] | [] | [
"Spec.Ed25519.PointOps.aff_point",
"Spec.Curve25519.elem",
"FStar.Pervasives.Native.Mktuple2",
"Spec.Curve25519.op_Slash_Percent",
"Spec.Curve25519.op_Plus_Percent",
"Spec.Curve25519.op_Star_Percent",
"Spec.Curve25519.op_Subtraction_Percent"
] | [] | false | false | false | true | false | let aff_point_double (p: aff_point) : aff_point =
| let x, y = p in
let x3 = (2 *% x *% y) /% (y *% y -% x *% x) in
let y3 = (y *% y +% x *% x) /% (2 -% y *% y +% x *% x) in
x3, y3 | false |
Hacl.Impl.MultiExponentiation.fsti | Hacl.Impl.MultiExponentiation.lexp_double_fw_tables_st | val lexp_double_fw_tables_st : a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a ->
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len ->
table_inv1: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len ->
table_inv2: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len
-> Type0 | let lexp_double_fw_tables_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv1:table_inv_t a_t len table_len)
(table_inv2:table_inv_t a_t len table_len)
=
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a1:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b1:lbuffer (uint_t a_t SEC) bLen
-> a2:lbuffer (uint_t a_t SEC) len
-> b2:lbuffer (uint_t a_t SEC) bLen
-> table1:clbuffer (uint_t a_t SEC) (table_len *! len)
-> table2:clbuffer (uint_t a_t SEC) (table_len *! len)
-> res:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a1 /\ live h b1 /\ live h a2 /\ live h b2 /\
live h res /\ live h ctx /\ live h table1 /\ live h table2 /\
eq_or_disjoint a1 a2 /\ disjoint a1 res /\ disjoint a1 ctx /\
disjoint b1 res /\ disjoint a2 res /\ disjoint a2 ctx /\
disjoint b2 res /\ disjoint res ctx /\ disjoint res table1 /\ disjoint res table2 /\
BD.bn_v h b1 < pow2 (v bBits) /\
BD.bn_v h b2 < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a1) /\ k.to.linv (as_seq h a2) /\
table_inv1 (as_seq h a1) (as_seq h table1) /\
table_inv2 (as_seq h a2) (as_seq h table2))
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
k.to.linv (as_seq h1 res) /\
k.to.refl (as_seq h1 res) ==
S.exp_double_fw k.to.comm_monoid
(k.to.refl (as_seq h0 a1)) (v bBits) (BD.bn_v h0 b1)
(k.to.refl (as_seq h0 a2)) (BD.bn_v h0 b2) (v l)) | {
"file_name": "code/bignum/Hacl.Impl.MultiExponentiation.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 62,
"start_col": 0,
"start_line": 22
} | module Hacl.Impl.MultiExponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
open Hacl.Impl.Exponentiation
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
// Double Fixed-window method using two precomputed tables
//--------------------------------------------------------- | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.MultiExponentiation.fsti"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a ->
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len ->
table_inv1: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len ->
table_inv2: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Hacl.Impl.Exponentiation.size_window_t",
"Hacl.Impl.Exponentiation.table_len_t",
"Hacl.Impl.Exponentiation.table_inv_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.op_LessThan",
"Prims.op_Division",
"Prims.op_Subtraction",
"Lib.IntTypes.bits",
"Lib.Buffer.clbuffer",
"Lib.IntTypes.op_Star_Bang",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Lib.Buffer.CONST",
"Lib.Buffer.eq_or_disjoint",
"Lib.Buffer.disjoint",
"Hacl.Bignum.Definitions.bn_v",
"Prims.pow2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv_ctx",
"FStar.Ghost.reveal",
"Hacl.Impl.Exponentiation.Definitions.to_comm_monoid",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__to",
"Lib.Buffer.as_seq",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Prims.eq2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__a_spec",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__refl",
"Lib.Exponentiation.exp_double_fw",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__comm_monoid"
] | [] | false | false | false | false | true | let lexp_double_fw_tables_st
(a_t: inttype_a)
(len: size_t{v len > 0})
(ctx_len: size_t)
(k: concrete_ops a_t len ctx_len)
(l: size_window_t a_t len)
(table_len: table_len_t len)
(table_inv1 table_inv2: table_inv_t a_t len table_len)
=
|
ctx: lbuffer (uint_t a_t SEC) ctx_len ->
a1: lbuffer (uint_t a_t SEC) len ->
bLen: size_t ->
bBits: size_t{(v bBits - 1) / bits a_t < v bLen} ->
b1: lbuffer (uint_t a_t SEC) bLen ->
a2: lbuffer (uint_t a_t SEC) len ->
b2: lbuffer (uint_t a_t SEC) bLen ->
table1: clbuffer (uint_t a_t SEC) (table_len *! len) ->
table2: clbuffer (uint_t a_t SEC) (table_len *! len) ->
res: lbuffer (uint_t a_t SEC) len
-> Stack unit
(requires
fun h ->
live h a1 /\ live h b1 /\ live h a2 /\ live h b2 /\ live h res /\ live h ctx /\
live h table1 /\ live h table2 /\ eq_or_disjoint a1 a2 /\ disjoint a1 res /\
disjoint a1 ctx /\ disjoint b1 res /\ disjoint a2 res /\ disjoint a2 ctx /\
disjoint b2 res /\ disjoint res ctx /\ disjoint res table1 /\ disjoint res table2 /\
BD.bn_v h b1 < pow2 (v bBits) /\ BD.bn_v h b2 < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a1) /\ k.to.linv (as_seq h a2) /\
table_inv1 (as_seq h a1) (as_seq h table1) /\ table_inv2 (as_seq h a2) (as_seq h table2))
(ensures
fun h0 _ h1 ->
modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\
k.to.refl (as_seq h1 res) ==
S.exp_double_fw k.to.comm_monoid
(k.to.refl (as_seq h0 a1))
(v bBits)
(BD.bn_v h0 b1)
(k.to.refl (as_seq h0 a2))
(BD.bn_v h0 b2)
(v l)) | false |
|
LowStar.UninitializedBuffer.fst | LowStar.UninitializedBuffer.initialization_preorder | val initialization_preorder (a: Type0) : srel (option a) | val initialization_preorder (a: Type0) : srel (option a) | let initialization_preorder (a:Type0) :srel (option a) =
fun s1 s2 -> Seq.length s1 == Seq.length s2 /\
(forall (i:nat).{:pattern (Seq.index s2 i)} i < Seq.length s1 ==> Some? (Seq.index s1 i) ==> Some? (Seq.index s2 i)) | {
"file_name": "ulib/LowStar.UninitializedBuffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 128,
"end_line": 35,
"start_col": 8,
"start_line": 33
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.UninitializedBuffer
include LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(*
* Uninitialized buffers
*
* Modeled as: seq (option a) with a preorder that an index once set remains set | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.UninitializedBuffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type0 -> LowStar.Monotonic.Buffer.srel (FStar.Pervasives.Native.option a) | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.seq",
"FStar.Pervasives.Native.option",
"Prims.l_and",
"Prims.eq2",
"Prims.nat",
"FStar.Seq.Base.length",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Seq.Base.index",
"Prims.logical",
"LowStar.Monotonic.Buffer.srel"
] | [] | false | false | false | true | false | let initialization_preorder (a: Type0) : srel (option a) =
| fun s1 s2 ->
Seq.length s1 == Seq.length s2 /\
(forall (i: nat). {:pattern (Seq.index s2 i)}
i < Seq.length s1 ==> Some? (Seq.index s1 i) ==> Some? (Seq.index s2 i)) | false |
Spec.Ed25519.PointOps.fst | Spec.Ed25519.PointOps.aff_point_add | val aff_point_add (p q: aff_point) : aff_point | val aff_point_add (p q: aff_point) : aff_point | let aff_point_add (p:aff_point) (q:aff_point) : aff_point =
let x1, y1 = p in
let x2, y2 = q in
let x3 = (x1 *% y2 +% y1 *% x2) /% (1 +% d *% (x1 *% x2) *% (y1 *% y2)) in
let y3 = (y1 *% y2 +% x1 *% x2) /% (1 -% d *% (x1 *% x2) *% (y1 *% y2)) in
x3, y3 | {
"file_name": "specs/Spec.Ed25519.PointOps.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 8,
"end_line": 59,
"start_col": 0,
"start_line": 54
} | module Spec.Ed25519.PointOps
open FStar.Mul
open Spec.Curve25519
module BSeq = Lib.ByteSequence
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
type aff_point = elem & elem // Affine point
type ext_point = elem & elem & elem & elem // Homogeneous extended coordinates
(* 2 **% ((prime - 1) / 4) *)
let modp_sqrt_m1 : elem = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0
let d : elem =
let x = 37095705934669439343138083508754565189542113879843219016388785533085940283555 in
assert_norm(x < prime);
x
let g_x : elem = 15112221349535400772501151409588531511454012693041857206046113283949847762202
let g_y : elem = 46316835694926478169428394003475163141307993866256225615783033603165251855960
let aff_g : aff_point = (g_x, g_y)
let g: ext_point = (g_x, g_y, 1, g_x *% g_y)
let is_on_curve (p:aff_point) =
let (x, y) = p in
y *% y -% x *% x == 1 +% d *% (x *% x) *% (y *% y)
let to_aff_point (p:ext_point) : aff_point =
let _X, _Y, _Z, _T = p in
_X /% _Z, _Y /% _Z
let is_ext (p:ext_point) =
let _X, _Y, _Z, _T = p in
_T == _X *% _Y /% _Z /\ _Z <> zero
let point_inv (p:ext_point) =
is_ext p /\ is_on_curve (to_aff_point p)
// let is_on_curve_ext (p:ext_point) =
// let _X, _Y, _Z, _T = p in
// _Y *% _Y -% X *% X == _Z *% _Z +% d *% _T *% _T
// let to_ext_point (p:aff_point) : ext_point =
// let x, y = p in
// (x, y, one, x *% y)
/// Point addition and doubling in affine coordinates | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Ed25519.PointOps.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Spec.Ed25519.PointOps.aff_point -> q: Spec.Ed25519.PointOps.aff_point
-> Spec.Ed25519.PointOps.aff_point | Prims.Tot | [
"total"
] | [] | [
"Spec.Ed25519.PointOps.aff_point",
"Spec.Curve25519.elem",
"FStar.Pervasives.Native.Mktuple2",
"Spec.Curve25519.op_Slash_Percent",
"Spec.Curve25519.op_Plus_Percent",
"Spec.Curve25519.op_Star_Percent",
"Spec.Curve25519.op_Subtraction_Percent",
"Spec.Ed25519.PointOps.d"
] | [] | false | false | false | true | false | let aff_point_add (p q: aff_point) : aff_point =
| let x1, y1 = p in
let x2, y2 = q in
let x3 = (x1 *% y2 +% y1 *% x2) /% (1 +% d *% (x1 *% x2) *% (y1 *% y2)) in
let y3 = (y1 *% y2 +% x1 *% x2) /% (1 -% d *% (x1 *% x2) *% (y1 *% y2)) in
x3, y3 | false |
Spec.Ed25519.PointOps.fst | Spec.Ed25519.PointOps.point_negate | val point_negate (p: ext_point) : ext_point | val point_negate (p: ext_point) : ext_point | let point_negate (p:ext_point) : ext_point =
let _X, _Y, _Z, _T = p in
((-_X) % prime, _Y, _Z, (-_T) % prime) | {
"file_name": "specs/Spec.Ed25519.PointOps.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 40,
"end_line": 112,
"start_col": 0,
"start_line": 110
} | module Spec.Ed25519.PointOps
open FStar.Mul
open Spec.Curve25519
module BSeq = Lib.ByteSequence
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
type aff_point = elem & elem // Affine point
type ext_point = elem & elem & elem & elem // Homogeneous extended coordinates
(* 2 **% ((prime - 1) / 4) *)
let modp_sqrt_m1 : elem = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0
let d : elem =
let x = 37095705934669439343138083508754565189542113879843219016388785533085940283555 in
assert_norm(x < prime);
x
let g_x : elem = 15112221349535400772501151409588531511454012693041857206046113283949847762202
let g_y : elem = 46316835694926478169428394003475163141307993866256225615783033603165251855960
let aff_g : aff_point = (g_x, g_y)
let g: ext_point = (g_x, g_y, 1, g_x *% g_y)
let is_on_curve (p:aff_point) =
let (x, y) = p in
y *% y -% x *% x == 1 +% d *% (x *% x) *% (y *% y)
let to_aff_point (p:ext_point) : aff_point =
let _X, _Y, _Z, _T = p in
_X /% _Z, _Y /% _Z
let is_ext (p:ext_point) =
let _X, _Y, _Z, _T = p in
_T == _X *% _Y /% _Z /\ _Z <> zero
let point_inv (p:ext_point) =
is_ext p /\ is_on_curve (to_aff_point p)
// let is_on_curve_ext (p:ext_point) =
// let _X, _Y, _Z, _T = p in
// _Y *% _Y -% X *% X == _Z *% _Z +% d *% _T *% _T
// let to_ext_point (p:aff_point) : ext_point =
// let x, y = p in
// (x, y, one, x *% y)
/// Point addition and doubling in affine coordinates
let aff_point_add (p:aff_point) (q:aff_point) : aff_point =
let x1, y1 = p in
let x2, y2 = q in
let x3 = (x1 *% y2 +% y1 *% x2) /% (1 +% d *% (x1 *% x2) *% (y1 *% y2)) in
let y3 = (y1 *% y2 +% x1 *% x2) /% (1 -% d *% (x1 *% x2) *% (y1 *% y2)) in
x3, y3
let aff_point_double (p:aff_point) : aff_point =
let x, y = p in
let x3 = (2 *% x *% y) /% (y *% y -% x *% x) in
let y3 = (y *% y +% x *% x) /% (2 -% y *% y +% x *% x) in
x3, y3
let aff_point_at_infinity : aff_point = (zero, one)
let aff_point_negate (p:aff_point) : aff_point =
let x, y = p in
((-x) % prime, y)
/// Point addition and doubling in Extended Twisted Edwards Coordinates
let point_add (p:ext_point) (q:ext_point) : Tot ext_point =
let _X1, _Y1, _Z1, _T1 = p in
let _X2, _Y2, _Z2, _T2 = q in
let a = (_Y1 -% _X1) *% (_Y2 -% _X2) in
let b = (_Y1 +% _X1) *% (_Y2 +% _X2) in
let c = (2 *% d *% _T1) *% _T2 in
let d = (2 *% _Z1) *% _Z2 in
let e = b -% a in
let f = d -% c in
let g = d +% c in
let h = b +% a in
let _X3 = e *% f in
let _Y3 = g *% h in
let _T3 = e *% h in
let _Z3 = f *% g in
(_X3, _Y3, _Z3, _T3)
let point_double (p:ext_point) : Tot ext_point =
let _X1, _Y1, _Z1, _T1 = p in
let a = _X1 *% _X1 in
let b = _Y1 *% _Y1 in
let c = 2 *% (_Z1 *% _Z1) in
let h = a +% b in
let e = h -% ((_X1 +% _Y1) *% (_X1 +% _Y1)) in
let g = a -% b in
let f = c +% g in
let _X3 = e *% f in
let _Y3 = g *% h in
let _T3 = e *% h in
let _Z3 = f *% g in
(_X3, _Y3, _Z3, _T3)
let point_at_infinity: ext_point = (zero, one, one, zero) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Ed25519.PointOps.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Spec.Ed25519.PointOps.ext_point -> Spec.Ed25519.PointOps.ext_point | Prims.Tot | [
"total"
] | [] | [
"Spec.Ed25519.PointOps.ext_point",
"Spec.Curve25519.elem",
"FStar.Pervasives.Native.Mktuple4",
"Prims.op_Modulus",
"Prims.op_Minus",
"Spec.Curve25519.prime"
] | [] | false | false | false | true | false | let point_negate (p: ext_point) : ext_point =
| let _X, _Y, _Z, _T = p in
((- _X) % prime, _Y, _Z, (- _T) % prime) | false |
Spec.Ed25519.PointOps.fst | Spec.Ed25519.PointOps.point_add | val point_add (p q: ext_point) : Tot ext_point | val point_add (p q: ext_point) : Tot ext_point | let point_add (p:ext_point) (q:ext_point) : Tot ext_point =
let _X1, _Y1, _Z1, _T1 = p in
let _X2, _Y2, _Z2, _T2 = q in
let a = (_Y1 -% _X1) *% (_Y2 -% _X2) in
let b = (_Y1 +% _X1) *% (_Y2 +% _X2) in
let c = (2 *% d *% _T1) *% _T2 in
let d = (2 *% _Z1) *% _Z2 in
let e = b -% a in
let f = d -% c in
let g = d +% c in
let h = b +% a in
let _X3 = e *% f in
let _Y3 = g *% h in
let _T3 = e *% h in
let _Z3 = f *% g in
(_X3, _Y3, _Z3, _T3) | {
"file_name": "specs/Spec.Ed25519.PointOps.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 22,
"end_line": 91,
"start_col": 0,
"start_line": 76
} | module Spec.Ed25519.PointOps
open FStar.Mul
open Spec.Curve25519
module BSeq = Lib.ByteSequence
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
type aff_point = elem & elem // Affine point
type ext_point = elem & elem & elem & elem // Homogeneous extended coordinates
(* 2 **% ((prime - 1) / 4) *)
let modp_sqrt_m1 : elem = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0
let d : elem =
let x = 37095705934669439343138083508754565189542113879843219016388785533085940283555 in
assert_norm(x < prime);
x
let g_x : elem = 15112221349535400772501151409588531511454012693041857206046113283949847762202
let g_y : elem = 46316835694926478169428394003475163141307993866256225615783033603165251855960
let aff_g : aff_point = (g_x, g_y)
let g: ext_point = (g_x, g_y, 1, g_x *% g_y)
let is_on_curve (p:aff_point) =
let (x, y) = p in
y *% y -% x *% x == 1 +% d *% (x *% x) *% (y *% y)
let to_aff_point (p:ext_point) : aff_point =
let _X, _Y, _Z, _T = p in
_X /% _Z, _Y /% _Z
let is_ext (p:ext_point) =
let _X, _Y, _Z, _T = p in
_T == _X *% _Y /% _Z /\ _Z <> zero
let point_inv (p:ext_point) =
is_ext p /\ is_on_curve (to_aff_point p)
// let is_on_curve_ext (p:ext_point) =
// let _X, _Y, _Z, _T = p in
// _Y *% _Y -% X *% X == _Z *% _Z +% d *% _T *% _T
// let to_ext_point (p:aff_point) : ext_point =
// let x, y = p in
// (x, y, one, x *% y)
/// Point addition and doubling in affine coordinates
let aff_point_add (p:aff_point) (q:aff_point) : aff_point =
let x1, y1 = p in
let x2, y2 = q in
let x3 = (x1 *% y2 +% y1 *% x2) /% (1 +% d *% (x1 *% x2) *% (y1 *% y2)) in
let y3 = (y1 *% y2 +% x1 *% x2) /% (1 -% d *% (x1 *% x2) *% (y1 *% y2)) in
x3, y3
let aff_point_double (p:aff_point) : aff_point =
let x, y = p in
let x3 = (2 *% x *% y) /% (y *% y -% x *% x) in
let y3 = (y *% y +% x *% x) /% (2 -% y *% y +% x *% x) in
x3, y3
let aff_point_at_infinity : aff_point = (zero, one)
let aff_point_negate (p:aff_point) : aff_point =
let x, y = p in
((-x) % prime, y)
/// Point addition and doubling in Extended Twisted Edwards Coordinates | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Ed25519.PointOps.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Spec.Ed25519.PointOps.ext_point -> q: Spec.Ed25519.PointOps.ext_point
-> Spec.Ed25519.PointOps.ext_point | Prims.Tot | [
"total"
] | [] | [
"Spec.Ed25519.PointOps.ext_point",
"Spec.Curve25519.elem",
"FStar.Pervasives.Native.Mktuple4",
"Spec.Curve25519.op_Star_Percent",
"Spec.Curve25519.op_Plus_Percent",
"Spec.Curve25519.op_Subtraction_Percent",
"Spec.Ed25519.PointOps.d"
] | [] | false | false | false | true | false | let point_add (p q: ext_point) : Tot ext_point =
| let _X1, _Y1, _Z1, _T1 = p in
let _X2, _Y2, _Z2, _T2 = q in
let a = (_Y1 -% _X1) *% (_Y2 -% _X2) in
let b = (_Y1 +% _X1) *% (_Y2 +% _X2) in
let c = (2 *% d *% _T1) *% _T2 in
let d = (2 *% _Z1) *% _Z2 in
let e = b -% a in
let f = d -% c in
let g = d +% c in
let h = b +% a in
let _X3 = e *% f in
let _Y3 = g *% h in
let _T3 = e *% h in
let _Z3 = f *% g in
(_X3, _Y3, _Z3, _T3) | false |
Spec.Ed25519.PointOps.fst | Spec.Ed25519.PointOps.aff_point_negate | val aff_point_negate (p: aff_point) : aff_point | val aff_point_negate (p: aff_point) : aff_point | let aff_point_negate (p:aff_point) : aff_point =
let x, y = p in
((-x) % prime, y) | {
"file_name": "specs/Spec.Ed25519.PointOps.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 19,
"end_line": 71,
"start_col": 0,
"start_line": 69
} | module Spec.Ed25519.PointOps
open FStar.Mul
open Spec.Curve25519
module BSeq = Lib.ByteSequence
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
type aff_point = elem & elem // Affine point
type ext_point = elem & elem & elem & elem // Homogeneous extended coordinates
(* 2 **% ((prime - 1) / 4) *)
let modp_sqrt_m1 : elem = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0
let d : elem =
let x = 37095705934669439343138083508754565189542113879843219016388785533085940283555 in
assert_norm(x < prime);
x
let g_x : elem = 15112221349535400772501151409588531511454012693041857206046113283949847762202
let g_y : elem = 46316835694926478169428394003475163141307993866256225615783033603165251855960
let aff_g : aff_point = (g_x, g_y)
let g: ext_point = (g_x, g_y, 1, g_x *% g_y)
let is_on_curve (p:aff_point) =
let (x, y) = p in
y *% y -% x *% x == 1 +% d *% (x *% x) *% (y *% y)
let to_aff_point (p:ext_point) : aff_point =
let _X, _Y, _Z, _T = p in
_X /% _Z, _Y /% _Z
let is_ext (p:ext_point) =
let _X, _Y, _Z, _T = p in
_T == _X *% _Y /% _Z /\ _Z <> zero
let point_inv (p:ext_point) =
is_ext p /\ is_on_curve (to_aff_point p)
// let is_on_curve_ext (p:ext_point) =
// let _X, _Y, _Z, _T = p in
// _Y *% _Y -% X *% X == _Z *% _Z +% d *% _T *% _T
// let to_ext_point (p:aff_point) : ext_point =
// let x, y = p in
// (x, y, one, x *% y)
/// Point addition and doubling in affine coordinates
let aff_point_add (p:aff_point) (q:aff_point) : aff_point =
let x1, y1 = p in
let x2, y2 = q in
let x3 = (x1 *% y2 +% y1 *% x2) /% (1 +% d *% (x1 *% x2) *% (y1 *% y2)) in
let y3 = (y1 *% y2 +% x1 *% x2) /% (1 -% d *% (x1 *% x2) *% (y1 *% y2)) in
x3, y3
let aff_point_double (p:aff_point) : aff_point =
let x, y = p in
let x3 = (2 *% x *% y) /% (y *% y -% x *% x) in
let y3 = (y *% y +% x *% x) /% (2 -% y *% y +% x *% x) in
x3, y3
let aff_point_at_infinity : aff_point = (zero, one) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Ed25519.PointOps.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Spec.Ed25519.PointOps.aff_point -> Spec.Ed25519.PointOps.aff_point | Prims.Tot | [
"total"
] | [] | [
"Spec.Ed25519.PointOps.aff_point",
"Spec.Curve25519.elem",
"FStar.Pervasives.Native.Mktuple2",
"Prims.op_Modulus",
"Prims.op_Minus",
"Spec.Curve25519.prime"
] | [] | false | false | false | true | false | let aff_point_negate (p: aff_point) : aff_point =
| let x, y = p in
((- x) % prime, y) | false |
Spec.Ed25519.PointOps.fst | Spec.Ed25519.PointOps.point_equal | val point_equal : p: Spec.Ed25519.PointOps.ext_point -> q: Spec.Ed25519.PointOps.ext_point -> Prims.bool | let point_equal (p:ext_point) (q:ext_point) =
let px, py, pz, pt = p in
let qx, qy, qz, qt = q in
if ((px *% qz) <> (qx *% pz)) then false
else if ((py *% qz) <> (qy *% pz)) then false
else true | {
"file_name": "specs/Spec.Ed25519.PointOps.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 152,
"start_col": 0,
"start_line": 147
} | module Spec.Ed25519.PointOps
open FStar.Mul
open Spec.Curve25519
module BSeq = Lib.ByteSequence
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
type aff_point = elem & elem // Affine point
type ext_point = elem & elem & elem & elem // Homogeneous extended coordinates
(* 2 **% ((prime - 1) / 4) *)
let modp_sqrt_m1 : elem = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0
let d : elem =
let x = 37095705934669439343138083508754565189542113879843219016388785533085940283555 in
assert_norm(x < prime);
x
let g_x : elem = 15112221349535400772501151409588531511454012693041857206046113283949847762202
let g_y : elem = 46316835694926478169428394003475163141307993866256225615783033603165251855960
let aff_g : aff_point = (g_x, g_y)
let g: ext_point = (g_x, g_y, 1, g_x *% g_y)
let is_on_curve (p:aff_point) =
let (x, y) = p in
y *% y -% x *% x == 1 +% d *% (x *% x) *% (y *% y)
let to_aff_point (p:ext_point) : aff_point =
let _X, _Y, _Z, _T = p in
_X /% _Z, _Y /% _Z
let is_ext (p:ext_point) =
let _X, _Y, _Z, _T = p in
_T == _X *% _Y /% _Z /\ _Z <> zero
let point_inv (p:ext_point) =
is_ext p /\ is_on_curve (to_aff_point p)
// let is_on_curve_ext (p:ext_point) =
// let _X, _Y, _Z, _T = p in
// _Y *% _Y -% X *% X == _Z *% _Z +% d *% _T *% _T
// let to_ext_point (p:aff_point) : ext_point =
// let x, y = p in
// (x, y, one, x *% y)
/// Point addition and doubling in affine coordinates
let aff_point_add (p:aff_point) (q:aff_point) : aff_point =
let x1, y1 = p in
let x2, y2 = q in
let x3 = (x1 *% y2 +% y1 *% x2) /% (1 +% d *% (x1 *% x2) *% (y1 *% y2)) in
let y3 = (y1 *% y2 +% x1 *% x2) /% (1 -% d *% (x1 *% x2) *% (y1 *% y2)) in
x3, y3
let aff_point_double (p:aff_point) : aff_point =
let x, y = p in
let x3 = (2 *% x *% y) /% (y *% y -% x *% x) in
let y3 = (y *% y +% x *% x) /% (2 -% y *% y +% x *% x) in
x3, y3
let aff_point_at_infinity : aff_point = (zero, one)
let aff_point_negate (p:aff_point) : aff_point =
let x, y = p in
((-x) % prime, y)
/// Point addition and doubling in Extended Twisted Edwards Coordinates
let point_add (p:ext_point) (q:ext_point) : Tot ext_point =
let _X1, _Y1, _Z1, _T1 = p in
let _X2, _Y2, _Z2, _T2 = q in
let a = (_Y1 -% _X1) *% (_Y2 -% _X2) in
let b = (_Y1 +% _X1) *% (_Y2 +% _X2) in
let c = (2 *% d *% _T1) *% _T2 in
let d = (2 *% _Z1) *% _Z2 in
let e = b -% a in
let f = d -% c in
let g = d +% c in
let h = b +% a in
let _X3 = e *% f in
let _Y3 = g *% h in
let _T3 = e *% h in
let _Z3 = f *% g in
(_X3, _Y3, _Z3, _T3)
let point_double (p:ext_point) : Tot ext_point =
let _X1, _Y1, _Z1, _T1 = p in
let a = _X1 *% _X1 in
let b = _Y1 *% _Y1 in
let c = 2 *% (_Z1 *% _Z1) in
let h = a +% b in
let e = h -% ((_X1 +% _Y1) *% (_X1 +% _Y1)) in
let g = a -% b in
let f = c +% g in
let _X3 = e *% f in
let _Y3 = g *% h in
let _T3 = e *% h in
let _Z3 = f *% g in
(_X3, _Y3, _Z3, _T3)
let point_at_infinity: ext_point = (zero, one, one, zero)
let point_negate (p:ext_point) : ext_point =
let _X, _Y, _Z, _T = p in
((-_X) % prime, _Y, _Z, (-_T) % prime)
let point_compress (p:ext_point) : Tot (BSeq.lbytes 32) =
let px, py, pz, pt = p in
let zinv = finv pz in
let x = px *% zinv in
let y = py *% zinv in
BSeq.nat_to_bytes_le 32 (pow2 255 * (x % 2) + y)
let recover_x (y:nat) (sign:bool) : Tot (option elem) =
if y >= prime then None
else (
let y2 = y *% y in
let x2 = (y2 -% one) *% (finv ((d *% y2) +% one)) in
if x2 = zero then (
if sign then None
else Some zero)
else (
let x = x2 **% ((prime + 3) / 8) in
let x = if ((x *% x) -% x2) <> zero then x *% modp_sqrt_m1 else x in
if ((x *% x) -% x2) <> zero then None
else (
let x = if (x % 2 = 1) <> sign then (prime - x) % prime else x in
Some x)))
let point_decompress (s:BSeq.lbytes 32) : Tot (option ext_point) =
let y = BSeq.nat_from_bytes_le s in
let sign = (y / pow2 255) % 2 = 1 in
let y = y % pow2 255 in
let x = recover_x y sign in
match x with
| Some x -> Some (x, y, one, x *% y)
| _ -> None | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Ed25519.PointOps.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Spec.Ed25519.PointOps.ext_point -> q: Spec.Ed25519.PointOps.ext_point -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Spec.Ed25519.PointOps.ext_point",
"Spec.Curve25519.elem",
"Prims.op_disEquality",
"Spec.Curve25519.op_Star_Percent",
"Prims.bool"
] | [] | false | false | false | true | false | let point_equal (p q: ext_point) =
| let px, py, pz, pt = p in
let qx, qy, qz, qt = q in
if ((px *% qz) <> (qx *% pz)) then false else if ((py *% qz) <> (qy *% pz)) then false else true | false |
|
LowStar.UninitializedBuffer.fst | LowStar.UninitializedBuffer.ualloca | val ualloca (#a: Type0) (len: U32.t)
: HST.StackInline (lubuffer a (U32.v len))
(requires (fun _ -> alloca_pre len))
(ensures
(fun h0 b h1 ->
alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) None) /\
frameOf b == HS.get_tip h0)) | val ualloca (#a: Type0) (len: U32.t)
: HST.StackInline (lubuffer a (U32.v len))
(requires (fun _ -> alloca_pre len))
(ensures
(fun h0 b h1 ->
alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) None) /\
frameOf b == HS.get_tip h0)) | let ualloca (#a:Type0) (len:U32.t)
:HST.StackInline (lubuffer a (U32.v len))
(requires (fun _ -> alloca_pre len))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) None) /\
frameOf b == HS.get_tip h0))
= malloca None len | {
"file_name": "ulib/LowStar.UninitializedBuffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 20,
"end_line": 127,
"start_col": 0,
"start_line": 122
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.UninitializedBuffer
include LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(*
* Uninitialized buffers
*
* Modeled as: seq (option a) with a preorder that an index once set remains set
*)
private let initialization_preorder (a:Type0) :srel (option a) =
fun s1 s2 -> Seq.length s1 == Seq.length s2 /\
(forall (i:nat).{:pattern (Seq.index s2 i)} i < Seq.length s1 ==> Some? (Seq.index s1 i) ==> Some? (Seq.index s2 i))
type ubuffer (a:Type0) =
mbuffer (option a) (initialization_preorder a) (initialization_preorder a)
unfold let unull (#a:Type0) :ubuffer a = mnull #(option a) #(initialization_preorder a) #(initialization_preorder a)
unfold let gsub (#a:Type0) = mgsub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
unfold let gsub_inj (#a:Type0) = mgsub_inj #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a) (initialization_preorder a)
inline_for_extraction
type pointer (a:Type0) = b:ubuffer a{length b == 1}
inline_for_extraction
type pointer_or_null (a:Type0) = b:ubuffer a{if g_is_null b then True else length b == 1}
inline_for_extraction let usub (#a:Type0) = msub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
inline_for_extraction let uoffset (#a:Type0) = moffset #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
(****** main stateful API *****)
(*
* b `initialized_at` i: is a stable predicate that witnesses the initialization of an index i in ubuffer b
*)
private let ipred (#a:Type0) (i:nat) :spred (option a) = fun s -> i < Seq.length s ==> Some? (Seq.index s i)
let initialized_at (#a:Type0) (b:ubuffer a) (i:nat) :Type0 = witnessed b (ipred i)
(*
* Clients need to prove that b is initialized_at i
*)
let uindex (#a:Type0) (b:ubuffer a) (i:U32.t)
:HST.Stack a (requires (fun h0 -> live h0 b /\ U32.v i < length b /\ b `initialized_at` (U32.v i)))
(ensures (fun h0 y h1 -> let y_opt = Seq.index (as_seq h0 b) (U32.v i) in
Some? y_opt /\ y == Some?.v y_opt /\ h0 == h1))
= let y_opt = index b i in
recall_p b (ipred (U32.v i));
Some?.v y_opt
(*
* b `initialized_at` i is a postcondition
*)
let uupd (#a:Type0) (b:ubuffer a) (i:U32.t) (v:a)
:HST.Stack unit (requires (fun h0 -> live h0 b /\ U32.v i < length b))
(ensures (fun h0 _ h1 -> modifies (loc_buffer b) h0 h1 /\
live h1 b /\
as_seq h1 b == Seq.upd (as_seq h0 b) (U32.v i) (Some v) /\
b `initialized_at` (U32.v i)))
= upd b i (Some v);
witness_p b (ipred (U32.v i))
unfold let lubuffer (a:Type0) (len:nat) = b:ubuffer a{length b == len}
unfold let lubuffer_or_null (a:Type0) (len:nat) (r:HS.rid) =
b:ubuffer a{(not (g_is_null b)) ==> (length b == len /\ frameOf b == r)}
(*
* No initializer
*)
let ugcmalloc (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer a (U32.v len){frameOf b == r /\ recallable b})
(requires (fun h0 -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mgcmalloc r None len
inline_for_extraction
let ugcmalloc_partial (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer_or_null a (U32.v len) r{recallable b})
(requires (fun h0 -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_partial_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mgcmalloc r None len
let umalloc (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer a (U32.v len){frameOf b == r /\ freeable b})
(requires (fun _ -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mmalloc r None len
inline_for_extraction
let umalloc_partial (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer_or_null a (U32.v len) r{(not (g_is_null b)) ==> freeable b})
(requires (fun _ -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_partial_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mmalloc r None len | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.UninitializedBuffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | len: FStar.UInt32.t
-> FStar.HyperStack.ST.StackInline (LowStar.UninitializedBuffer.lubuffer a (FStar.UInt32.v len)) | FStar.HyperStack.ST.StackInline | [] | [] | [
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.malloca",
"FStar.Pervasives.Native.option",
"LowStar.UninitializedBuffer.initialization_preorder",
"FStar.Pervasives.Native.None",
"LowStar.Monotonic.Buffer.lmbuffer",
"FStar.UInt32.v",
"LowStar.UninitializedBuffer.lubuffer",
"FStar.Monotonic.HyperStack.mem",
"Prims.b2t",
"LowStar.Monotonic.Buffer.alloca_pre",
"Prims.l_and",
"LowStar.Monotonic.Buffer.alloc_post_mem_common",
"FStar.Seq.Base.create",
"Prims.eq2",
"FStar.Monotonic.HyperHeap.rid",
"LowStar.Monotonic.Buffer.frameOf",
"FStar.Monotonic.HyperStack.get_tip"
] | [] | false | true | false | false | false | let ualloca (#a: Type0) (len: U32.t)
: HST.StackInline (lubuffer a (U32.v len))
(requires (fun _ -> alloca_pre len))
(ensures
(fun h0 b h1 ->
alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) None) /\
frameOf b == HS.get_tip h0)) =
| malloca None len | false |
Spec.Ed25519.PointOps.fst | Spec.Ed25519.PointOps.point_double | val point_double (p: ext_point) : Tot ext_point | val point_double (p: ext_point) : Tot ext_point | let point_double (p:ext_point) : Tot ext_point =
let _X1, _Y1, _Z1, _T1 = p in
let a = _X1 *% _X1 in
let b = _Y1 *% _Y1 in
let c = 2 *% (_Z1 *% _Z1) in
let h = a +% b in
let e = h -% ((_X1 +% _Y1) *% (_X1 +% _Y1)) in
let g = a -% b in
let f = c +% g in
let _X3 = e *% f in
let _Y3 = g *% h in
let _T3 = e *% h in
let _Z3 = f *% g in
(_X3, _Y3, _Z3, _T3) | {
"file_name": "specs/Spec.Ed25519.PointOps.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 22,
"end_line": 106,
"start_col": 0,
"start_line": 93
} | module Spec.Ed25519.PointOps
open FStar.Mul
open Spec.Curve25519
module BSeq = Lib.ByteSequence
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
type aff_point = elem & elem // Affine point
type ext_point = elem & elem & elem & elem // Homogeneous extended coordinates
(* 2 **% ((prime - 1) / 4) *)
let modp_sqrt_m1 : elem = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0
let d : elem =
let x = 37095705934669439343138083508754565189542113879843219016388785533085940283555 in
assert_norm(x < prime);
x
let g_x : elem = 15112221349535400772501151409588531511454012693041857206046113283949847762202
let g_y : elem = 46316835694926478169428394003475163141307993866256225615783033603165251855960
let aff_g : aff_point = (g_x, g_y)
let g: ext_point = (g_x, g_y, 1, g_x *% g_y)
let is_on_curve (p:aff_point) =
let (x, y) = p in
y *% y -% x *% x == 1 +% d *% (x *% x) *% (y *% y)
let to_aff_point (p:ext_point) : aff_point =
let _X, _Y, _Z, _T = p in
_X /% _Z, _Y /% _Z
let is_ext (p:ext_point) =
let _X, _Y, _Z, _T = p in
_T == _X *% _Y /% _Z /\ _Z <> zero
let point_inv (p:ext_point) =
is_ext p /\ is_on_curve (to_aff_point p)
// let is_on_curve_ext (p:ext_point) =
// let _X, _Y, _Z, _T = p in
// _Y *% _Y -% X *% X == _Z *% _Z +% d *% _T *% _T
// let to_ext_point (p:aff_point) : ext_point =
// let x, y = p in
// (x, y, one, x *% y)
/// Point addition and doubling in affine coordinates
let aff_point_add (p:aff_point) (q:aff_point) : aff_point =
let x1, y1 = p in
let x2, y2 = q in
let x3 = (x1 *% y2 +% y1 *% x2) /% (1 +% d *% (x1 *% x2) *% (y1 *% y2)) in
let y3 = (y1 *% y2 +% x1 *% x2) /% (1 -% d *% (x1 *% x2) *% (y1 *% y2)) in
x3, y3
let aff_point_double (p:aff_point) : aff_point =
let x, y = p in
let x3 = (2 *% x *% y) /% (y *% y -% x *% x) in
let y3 = (y *% y +% x *% x) /% (2 -% y *% y +% x *% x) in
x3, y3
let aff_point_at_infinity : aff_point = (zero, one)
let aff_point_negate (p:aff_point) : aff_point =
let x, y = p in
((-x) % prime, y)
/// Point addition and doubling in Extended Twisted Edwards Coordinates
let point_add (p:ext_point) (q:ext_point) : Tot ext_point =
let _X1, _Y1, _Z1, _T1 = p in
let _X2, _Y2, _Z2, _T2 = q in
let a = (_Y1 -% _X1) *% (_Y2 -% _X2) in
let b = (_Y1 +% _X1) *% (_Y2 +% _X2) in
let c = (2 *% d *% _T1) *% _T2 in
let d = (2 *% _Z1) *% _Z2 in
let e = b -% a in
let f = d -% c in
let g = d +% c in
let h = b +% a in
let _X3 = e *% f in
let _Y3 = g *% h in
let _T3 = e *% h in
let _Z3 = f *% g in
(_X3, _Y3, _Z3, _T3) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Ed25519.PointOps.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Spec.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Spec.Ed25519.PointOps.ext_point -> Spec.Ed25519.PointOps.ext_point | Prims.Tot | [
"total"
] | [] | [
"Spec.Ed25519.PointOps.ext_point",
"Spec.Curve25519.elem",
"FStar.Pervasives.Native.Mktuple4",
"Spec.Curve25519.op_Star_Percent",
"Spec.Curve25519.op_Plus_Percent",
"Spec.Curve25519.op_Subtraction_Percent"
] | [] | false | false | false | true | false | let point_double (p: ext_point) : Tot ext_point =
| let _X1, _Y1, _Z1, _T1 = p in
let a = _X1 *% _X1 in
let b = _Y1 *% _Y1 in
let c = 2 *% (_Z1 *% _Z1) in
let h = a +% b in
let e = h -% ((_X1 +% _Y1) *% (_X1 +% _Y1)) in
let g = a -% b in
let f = c +% g in
let _X3 = e *% f in
let _Y3 = g *% h in
let _T3 = e *% h in
let _Z3 = f *% g in
(_X3, _Y3, _Z3, _T3) | false |
LowStar.UninitializedBuffer.fst | LowStar.UninitializedBuffer.recall_initialized | val recall_initialized (#a: Type0) (b: ubuffer a) (i: nat)
: HST.ST unit
(fun h0 -> (recallable b \/ live h0 b) /\ b `initialized_at` i)
(fun h0 _ h1 -> h0 == h1 /\ live h0 b /\ (i < length b ==> Some? (Seq.index (as_seq h0 b) i))) | val recall_initialized (#a: Type0) (b: ubuffer a) (i: nat)
: HST.ST unit
(fun h0 -> (recallable b \/ live h0 b) /\ b `initialized_at` i)
(fun h0 _ h1 -> h0 == h1 /\ live h0 b /\ (i < length b ==> Some? (Seq.index (as_seq h0 b) i))) | let recall_initialized (#a:Type0) (b:ubuffer a) (i:nat)
:HST.ST unit (fun h0 -> (recallable b \/ live h0 b) /\ b `initialized_at` i)
(fun h0 _ h1 -> h0 == h1 /\ live h0 b /\ (i < length b ==> Some? (Seq.index (as_seq h0 b) i)))
= recall_p b (ipred i) | {
"file_name": "ulib/LowStar.UninitializedBuffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 24,
"end_line": 184,
"start_col": 0,
"start_line": 181
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.UninitializedBuffer
include LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(*
* Uninitialized buffers
*
* Modeled as: seq (option a) with a preorder that an index once set remains set
*)
private let initialization_preorder (a:Type0) :srel (option a) =
fun s1 s2 -> Seq.length s1 == Seq.length s2 /\
(forall (i:nat).{:pattern (Seq.index s2 i)} i < Seq.length s1 ==> Some? (Seq.index s1 i) ==> Some? (Seq.index s2 i))
type ubuffer (a:Type0) =
mbuffer (option a) (initialization_preorder a) (initialization_preorder a)
unfold let unull (#a:Type0) :ubuffer a = mnull #(option a) #(initialization_preorder a) #(initialization_preorder a)
unfold let gsub (#a:Type0) = mgsub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
unfold let gsub_inj (#a:Type0) = mgsub_inj #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a) (initialization_preorder a)
inline_for_extraction
type pointer (a:Type0) = b:ubuffer a{length b == 1}
inline_for_extraction
type pointer_or_null (a:Type0) = b:ubuffer a{if g_is_null b then True else length b == 1}
inline_for_extraction let usub (#a:Type0) = msub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
inline_for_extraction let uoffset (#a:Type0) = moffset #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
(****** main stateful API *****)
(*
* b `initialized_at` i: is a stable predicate that witnesses the initialization of an index i in ubuffer b
*)
private let ipred (#a:Type0) (i:nat) :spred (option a) = fun s -> i < Seq.length s ==> Some? (Seq.index s i)
let initialized_at (#a:Type0) (b:ubuffer a) (i:nat) :Type0 = witnessed b (ipred i)
(*
* Clients need to prove that b is initialized_at i
*)
let uindex (#a:Type0) (b:ubuffer a) (i:U32.t)
:HST.Stack a (requires (fun h0 -> live h0 b /\ U32.v i < length b /\ b `initialized_at` (U32.v i)))
(ensures (fun h0 y h1 -> let y_opt = Seq.index (as_seq h0 b) (U32.v i) in
Some? y_opt /\ y == Some?.v y_opt /\ h0 == h1))
= let y_opt = index b i in
recall_p b (ipred (U32.v i));
Some?.v y_opt
(*
* b `initialized_at` i is a postcondition
*)
let uupd (#a:Type0) (b:ubuffer a) (i:U32.t) (v:a)
:HST.Stack unit (requires (fun h0 -> live h0 b /\ U32.v i < length b))
(ensures (fun h0 _ h1 -> modifies (loc_buffer b) h0 h1 /\
live h1 b /\
as_seq h1 b == Seq.upd (as_seq h0 b) (U32.v i) (Some v) /\
b `initialized_at` (U32.v i)))
= upd b i (Some v);
witness_p b (ipred (U32.v i))
unfold let lubuffer (a:Type0) (len:nat) = b:ubuffer a{length b == len}
unfold let lubuffer_or_null (a:Type0) (len:nat) (r:HS.rid) =
b:ubuffer a{(not (g_is_null b)) ==> (length b == len /\ frameOf b == r)}
(*
* No initializer
*)
let ugcmalloc (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer a (U32.v len){frameOf b == r /\ recallable b})
(requires (fun h0 -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mgcmalloc r None len
inline_for_extraction
let ugcmalloc_partial (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer_or_null a (U32.v len) r{recallable b})
(requires (fun h0 -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_partial_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mgcmalloc r None len
let umalloc (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer a (U32.v len){frameOf b == r /\ freeable b})
(requires (fun _ -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mmalloc r None len
inline_for_extraction
let umalloc_partial (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer_or_null a (U32.v len) r{(not (g_is_null b)) ==> freeable b})
(requires (fun _ -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_partial_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mmalloc r None len
let ualloca (#a:Type0) (len:U32.t)
:HST.StackInline (lubuffer a (U32.v len))
(requires (fun _ -> alloca_pre len))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) None) /\
frameOf b == HS.get_tip h0))
= malloca None len
(*
* blit functionality, where src is a regular buffer
*)
[@@"opaque_to_smt"]
unfold let valid_j_for_blit
(#a:Type0) (#rrel #rel:srel a) (src:mbuffer a rrel rel) (idx_src:U32.t)
(dst:ubuffer a) (idx_dst:U32.t) (j:U32.t)
= U32.v idx_src + U32.v j <= length src /\
U32.v idx_dst + U32.v j <= length dst
(*
* postcondition of blit
*)
[@@"opaque_to_smt"]
unfold private let ublit_post_j
(#a:Type0) (#rrel #rel:srel a) (src:mbuffer a rrel rel) (idx_src:U32.t)
(dst:ubuffer a) (idx_dst:U32.t) (j:U32.t{valid_j_for_blit src idx_src dst idx_dst j})
(h0 h1:HS.mem)
= modifies (loc_buffer dst) h0 h1 /\ live h1 dst /\
(forall (i:nat).{:pattern (Seq.index (as_seq h1 dst) i)} (i >= U32.v idx_dst /\ i < U32.v idx_dst + U32.v j ==>
Seq.index (as_seq h1 dst) i ==
Some (Seq.index (as_seq h0 src) (U32.v idx_src + i - U32.v idx_dst)))
) /\
Seq.slice (as_seq h1 dst) 0 (U32.v idx_dst) == Seq.slice (as_seq h0 dst) 0 (U32.v idx_dst) /\
Seq.slice (as_seq h1 dst) (U32.v idx_dst + U32.v j) (length dst) == Seq.slice (as_seq h0 dst) (U32.v idx_dst + U32.v j) (length dst) /\
(forall (i:nat).{:pattern (dst `initialized_at` i)} (i >= U32.v idx_dst /\ i < U32.v idx_dst + U32.v j) ==>
dst `initialized_at` i)
let ublit (#a:Type0) (#rrel #rel:srel a)
(src:mbuffer a rrel rel) (idx_src:U32.t)
(dst:ubuffer a{disjoint src dst}) (idx_dst:U32.t)
(len:U32.t{valid_j_for_blit src idx_src dst idx_dst len})
:HST.Stack unit (requires (fun h0 -> live h0 src /\ live h0 dst))
(ensures (fun h0 _ h1 -> ublit_post_j src idx_src dst idx_dst len h0 h1))
= let rec aux (j:U32.t{valid_j_for_blit src idx_src dst idx_dst j})
:HST.Stack unit
(requires (fun h0 -> live h0 src /\ live h0 dst /\ ublit_post_j src idx_src dst idx_dst j h0 h0))
(ensures (fun h0 _ h1 -> ublit_post_j src idx_src dst idx_dst len h0 h1))
= let open FStar.UInt32 in
if j = len then ()
else if j <^ len then begin
uupd dst (idx_dst +^ j) (index src (idx_src +^ j));
aux (j +^ 1ul)
end
in
aux 0ul
let witness_initialized (#a:Type0) (b:ubuffer a) (i:nat)
:HST.ST unit (fun h0 -> i < length b /\ Some? (Seq.index (as_seq h0 b) i))
(fun h0 _ h1 -> h0 == h1 /\ b `initialized_at` i)
= witness_p b (ipred i) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.UninitializedBuffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: LowStar.UninitializedBuffer.ubuffer a -> i: Prims.nat -> FStar.HyperStack.ST.ST Prims.unit | FStar.HyperStack.ST.ST | [] | [] | [
"LowStar.UninitializedBuffer.ubuffer",
"Prims.nat",
"LowStar.Monotonic.Buffer.recall_p",
"FStar.Pervasives.Native.option",
"LowStar.UninitializedBuffer.initialization_preorder",
"LowStar.UninitializedBuffer.ipred",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Prims.l_or",
"LowStar.Monotonic.Buffer.recallable",
"LowStar.Monotonic.Buffer.live",
"LowStar.UninitializedBuffer.initialized_at",
"Prims.eq2",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"LowStar.Monotonic.Buffer.length",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Seq.Base.index",
"LowStar.Monotonic.Buffer.as_seq"
] | [] | false | true | false | false | false | let recall_initialized (#a: Type0) (b: ubuffer a) (i: nat)
: HST.ST unit
(fun h0 -> (recallable b \/ live h0 b) /\ b `initialized_at` i)
(fun h0 _ h1 -> h0 == h1 /\ live h0 b /\ (i < length b ==> Some? (Seq.index (as_seq h0 b) i))) =
| recall_p b (ipred i) | false |
LowStar.UninitializedBuffer.fst | LowStar.UninitializedBuffer.ugcmalloc_partial | val ugcmalloc_partial (#a: Type0) (r: HS.rid) (len: U32.t)
: HST.ST (b: lubuffer_or_null a (U32.v len) r {recallable b})
(requires (fun h0 -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_partial_post_mem_common b h0 h1 (Seq.create (U32.v len) None))) | val ugcmalloc_partial (#a: Type0) (r: HS.rid) (len: U32.t)
: HST.ST (b: lubuffer_or_null a (U32.v len) r {recallable b})
(requires (fun h0 -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_partial_post_mem_common b h0 h1 (Seq.create (U32.v len) None))) | let ugcmalloc_partial (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer_or_null a (U32.v len) r{recallable b})
(requires (fun h0 -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_partial_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mgcmalloc r None len | {
"file_name": "ulib/LowStar.UninitializedBuffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 24,
"end_line": 107,
"start_col": 0,
"start_line": 103
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.UninitializedBuffer
include LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(*
* Uninitialized buffers
*
* Modeled as: seq (option a) with a preorder that an index once set remains set
*)
private let initialization_preorder (a:Type0) :srel (option a) =
fun s1 s2 -> Seq.length s1 == Seq.length s2 /\
(forall (i:nat).{:pattern (Seq.index s2 i)} i < Seq.length s1 ==> Some? (Seq.index s1 i) ==> Some? (Seq.index s2 i))
type ubuffer (a:Type0) =
mbuffer (option a) (initialization_preorder a) (initialization_preorder a)
unfold let unull (#a:Type0) :ubuffer a = mnull #(option a) #(initialization_preorder a) #(initialization_preorder a)
unfold let gsub (#a:Type0) = mgsub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
unfold let gsub_inj (#a:Type0) = mgsub_inj #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a) (initialization_preorder a)
inline_for_extraction
type pointer (a:Type0) = b:ubuffer a{length b == 1}
inline_for_extraction
type pointer_or_null (a:Type0) = b:ubuffer a{if g_is_null b then True else length b == 1}
inline_for_extraction let usub (#a:Type0) = msub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
inline_for_extraction let uoffset (#a:Type0) = moffset #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
(****** main stateful API *****)
(*
* b `initialized_at` i: is a stable predicate that witnesses the initialization of an index i in ubuffer b
*)
private let ipred (#a:Type0) (i:nat) :spred (option a) = fun s -> i < Seq.length s ==> Some? (Seq.index s i)
let initialized_at (#a:Type0) (b:ubuffer a) (i:nat) :Type0 = witnessed b (ipred i)
(*
* Clients need to prove that b is initialized_at i
*)
let uindex (#a:Type0) (b:ubuffer a) (i:U32.t)
:HST.Stack a (requires (fun h0 -> live h0 b /\ U32.v i < length b /\ b `initialized_at` (U32.v i)))
(ensures (fun h0 y h1 -> let y_opt = Seq.index (as_seq h0 b) (U32.v i) in
Some? y_opt /\ y == Some?.v y_opt /\ h0 == h1))
= let y_opt = index b i in
recall_p b (ipred (U32.v i));
Some?.v y_opt
(*
* b `initialized_at` i is a postcondition
*)
let uupd (#a:Type0) (b:ubuffer a) (i:U32.t) (v:a)
:HST.Stack unit (requires (fun h0 -> live h0 b /\ U32.v i < length b))
(ensures (fun h0 _ h1 -> modifies (loc_buffer b) h0 h1 /\
live h1 b /\
as_seq h1 b == Seq.upd (as_seq h0 b) (U32.v i) (Some v) /\
b `initialized_at` (U32.v i)))
= upd b i (Some v);
witness_p b (ipred (U32.v i))
unfold let lubuffer (a:Type0) (len:nat) = b:ubuffer a{length b == len}
unfold let lubuffer_or_null (a:Type0) (len:nat) (r:HS.rid) =
b:ubuffer a{(not (g_is_null b)) ==> (length b == len /\ frameOf b == r)}
(*
* No initializer
*)
let ugcmalloc (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer a (U32.v len){frameOf b == r /\ recallable b})
(requires (fun h0 -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mgcmalloc r None len | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.UninitializedBuffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: FStar.Monotonic.HyperHeap.rid -> len: FStar.UInt32.t
-> FStar.HyperStack.ST.ST
(b:
LowStar.UninitializedBuffer.lubuffer_or_null a (FStar.UInt32.v len) r
{LowStar.Monotonic.Buffer.recallable b}) | FStar.HyperStack.ST.ST | [] | [] | [
"FStar.Monotonic.HyperHeap.rid",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.mgcmalloc",
"FStar.Pervasives.Native.option",
"LowStar.UninitializedBuffer.initialization_preorder",
"FStar.Pervasives.Native.None",
"LowStar.Monotonic.Buffer.lmbuffer",
"FStar.UInt32.v",
"Prims.l_and",
"Prims.eq2",
"LowStar.Monotonic.Buffer.frameOf",
"LowStar.Monotonic.Buffer.recallable",
"LowStar.UninitializedBuffer.lubuffer_or_null",
"FStar.Monotonic.HyperStack.mem",
"LowStar.Monotonic.Buffer.malloc_pre",
"LowStar.Monotonic.Buffer.alloc_partial_post_mem_common",
"FStar.Seq.Base.create"
] | [] | false | true | false | false | false | let ugcmalloc_partial (#a: Type0) (r: HS.rid) (len: U32.t)
: HST.ST (b: lubuffer_or_null a (U32.v len) r {recallable b})
(requires (fun h0 -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_partial_post_mem_common b h0 h1 (Seq.create (U32.v len) None))) =
| mgcmalloc r None len | false |
LowStar.UninitializedBuffer.fst | LowStar.UninitializedBuffer.ublit_post_j | val ublit_post_j : src: LowStar.Monotonic.Buffer.mbuffer a rrel rel ->
idx_src: FStar.UInt32.t ->
dst: LowStar.UninitializedBuffer.ubuffer a ->
idx_dst: FStar.UInt32.t ->
j: FStar.UInt32.t{LowStar.UninitializedBuffer.valid_j_for_blit src idx_src dst idx_dst j} ->
h0: FStar.Monotonic.HyperStack.mem ->
h1: FStar.Monotonic.HyperStack.mem
-> Prims.logical | let ublit_post_j
(#a:Type0) (#rrel #rel:srel a) (src:mbuffer a rrel rel) (idx_src:U32.t)
(dst:ubuffer a) (idx_dst:U32.t) (j:U32.t{valid_j_for_blit src idx_src dst idx_dst j})
(h0 h1:HS.mem)
= modifies (loc_buffer dst) h0 h1 /\ live h1 dst /\
(forall (i:nat).{:pattern (Seq.index (as_seq h1 dst) i)} (i >= U32.v idx_dst /\ i < U32.v idx_dst + U32.v j ==>
Seq.index (as_seq h1 dst) i ==
Some (Seq.index (as_seq h0 src) (U32.v idx_src + i - U32.v idx_dst)))
) /\
Seq.slice (as_seq h1 dst) 0 (U32.v idx_dst) == Seq.slice (as_seq h0 dst) 0 (U32.v idx_dst) /\
Seq.slice (as_seq h1 dst) (U32.v idx_dst + U32.v j) (length dst) == Seq.slice (as_seq h0 dst) (U32.v idx_dst + U32.v j) (length dst) /\
(forall (i:nat).{:pattern (dst `initialized_at` i)} (i >= U32.v idx_dst /\ i < U32.v idx_dst + U32.v j) ==>
dst `initialized_at` i) | {
"file_name": "ulib/LowStar.UninitializedBuffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 38,
"end_line": 155,
"start_col": 15,
"start_line": 143
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.UninitializedBuffer
include LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(*
* Uninitialized buffers
*
* Modeled as: seq (option a) with a preorder that an index once set remains set
*)
private let initialization_preorder (a:Type0) :srel (option a) =
fun s1 s2 -> Seq.length s1 == Seq.length s2 /\
(forall (i:nat).{:pattern (Seq.index s2 i)} i < Seq.length s1 ==> Some? (Seq.index s1 i) ==> Some? (Seq.index s2 i))
type ubuffer (a:Type0) =
mbuffer (option a) (initialization_preorder a) (initialization_preorder a)
unfold let unull (#a:Type0) :ubuffer a = mnull #(option a) #(initialization_preorder a) #(initialization_preorder a)
unfold let gsub (#a:Type0) = mgsub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
unfold let gsub_inj (#a:Type0) = mgsub_inj #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a) (initialization_preorder a)
inline_for_extraction
type pointer (a:Type0) = b:ubuffer a{length b == 1}
inline_for_extraction
type pointer_or_null (a:Type0) = b:ubuffer a{if g_is_null b then True else length b == 1}
inline_for_extraction let usub (#a:Type0) = msub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
inline_for_extraction let uoffset (#a:Type0) = moffset #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
(****** main stateful API *****)
(*
* b `initialized_at` i: is a stable predicate that witnesses the initialization of an index i in ubuffer b
*)
private let ipred (#a:Type0) (i:nat) :spred (option a) = fun s -> i < Seq.length s ==> Some? (Seq.index s i)
let initialized_at (#a:Type0) (b:ubuffer a) (i:nat) :Type0 = witnessed b (ipred i)
(*
* Clients need to prove that b is initialized_at i
*)
let uindex (#a:Type0) (b:ubuffer a) (i:U32.t)
:HST.Stack a (requires (fun h0 -> live h0 b /\ U32.v i < length b /\ b `initialized_at` (U32.v i)))
(ensures (fun h0 y h1 -> let y_opt = Seq.index (as_seq h0 b) (U32.v i) in
Some? y_opt /\ y == Some?.v y_opt /\ h0 == h1))
= let y_opt = index b i in
recall_p b (ipred (U32.v i));
Some?.v y_opt
(*
* b `initialized_at` i is a postcondition
*)
let uupd (#a:Type0) (b:ubuffer a) (i:U32.t) (v:a)
:HST.Stack unit (requires (fun h0 -> live h0 b /\ U32.v i < length b))
(ensures (fun h0 _ h1 -> modifies (loc_buffer b) h0 h1 /\
live h1 b /\
as_seq h1 b == Seq.upd (as_seq h0 b) (U32.v i) (Some v) /\
b `initialized_at` (U32.v i)))
= upd b i (Some v);
witness_p b (ipred (U32.v i))
unfold let lubuffer (a:Type0) (len:nat) = b:ubuffer a{length b == len}
unfold let lubuffer_or_null (a:Type0) (len:nat) (r:HS.rid) =
b:ubuffer a{(not (g_is_null b)) ==> (length b == len /\ frameOf b == r)}
(*
* No initializer
*)
let ugcmalloc (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer a (U32.v len){frameOf b == r /\ recallable b})
(requires (fun h0 -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mgcmalloc r None len
inline_for_extraction
let ugcmalloc_partial (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer_or_null a (U32.v len) r{recallable b})
(requires (fun h0 -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_partial_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mgcmalloc r None len
let umalloc (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer a (U32.v len){frameOf b == r /\ freeable b})
(requires (fun _ -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mmalloc r None len
inline_for_extraction
let umalloc_partial (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer_or_null a (U32.v len) r{(not (g_is_null b)) ==> freeable b})
(requires (fun _ -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_partial_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mmalloc r None len
let ualloca (#a:Type0) (len:U32.t)
:HST.StackInline (lubuffer a (U32.v len))
(requires (fun _ -> alloca_pre len))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) None) /\
frameOf b == HS.get_tip h0))
= malloca None len
(*
* blit functionality, where src is a regular buffer
*)
[@@"opaque_to_smt"]
unfold let valid_j_for_blit
(#a:Type0) (#rrel #rel:srel a) (src:mbuffer a rrel rel) (idx_src:U32.t)
(dst:ubuffer a) (idx_dst:U32.t) (j:U32.t)
= U32.v idx_src + U32.v j <= length src /\
U32.v idx_dst + U32.v j <= length dst
(*
* postcondition of blit
*) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.UninitializedBuffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
src: LowStar.Monotonic.Buffer.mbuffer a rrel rel ->
idx_src: FStar.UInt32.t ->
dst: LowStar.UninitializedBuffer.ubuffer a ->
idx_dst: FStar.UInt32.t ->
j: FStar.UInt32.t{LowStar.UninitializedBuffer.valid_j_for_blit src idx_src dst idx_dst j} ->
h0: FStar.Monotonic.HyperStack.mem ->
h1: FStar.Monotonic.HyperStack.mem
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"LowStar.Monotonic.Buffer.srel",
"LowStar.Monotonic.Buffer.mbuffer",
"FStar.UInt32.t",
"LowStar.UninitializedBuffer.ubuffer",
"LowStar.UninitializedBuffer.valid_j_for_blit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_buffer",
"FStar.Pervasives.Native.option",
"LowStar.UninitializedBuffer.initialization_preorder",
"LowStar.Monotonic.Buffer.live",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt32.v",
"Prims.op_LessThan",
"Prims.op_Addition",
"Prims.eq2",
"FStar.Seq.Base.index",
"LowStar.Monotonic.Buffer.as_seq",
"FStar.Pervasives.Native.Some",
"Prims.op_Subtraction",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.slice",
"LowStar.Monotonic.Buffer.length",
"LowStar.UninitializedBuffer.initialized_at",
"Prims.logical"
] | [] | false | false | false | false | true | let ublit_post_j
(#a: Type0)
(#rrel #rel: srel a)
(src: mbuffer a rrel rel)
(idx_src: U32.t)
(dst: ubuffer a)
(idx_dst: U32.t)
(j: U32.t{valid_j_for_blit src idx_src dst idx_dst j})
(h0 h1: HS.mem)
=
| modifies (loc_buffer dst) h0 h1 /\ live h1 dst /\
(forall (i: nat). {:pattern (Seq.index (as_seq h1 dst) i)}
(i >= U32.v idx_dst /\ i < U32.v idx_dst + U32.v j ==>
Seq.index (as_seq h1 dst) i ==
Some (Seq.index (as_seq h0 src) (U32.v idx_src + i - U32.v idx_dst)))) /\
Seq.slice (as_seq h1 dst) 0 (U32.v idx_dst) == Seq.slice (as_seq h0 dst) 0 (U32.v idx_dst) /\
Seq.slice (as_seq h1 dst) (U32.v idx_dst + U32.v j) (length dst) ==
Seq.slice (as_seq h0 dst) (U32.v idx_dst + U32.v j) (length dst) /\
(forall (i: nat). {:pattern (dst `initialized_at` i)}
(i >= U32.v idx_dst /\ i < U32.v idx_dst + U32.v j) ==> dst `initialized_at` i) | false |
|
LowStar.UninitializedBuffer.fst | LowStar.UninitializedBuffer.uindex | val uindex (#a: Type0) (b: ubuffer a) (i: U32.t)
: HST.Stack a
(requires (fun h0 -> live h0 b /\ U32.v i < length b /\ b `initialized_at` (U32.v i)))
(ensures
(fun h0 y h1 ->
let y_opt = Seq.index (as_seq h0 b) (U32.v i) in
Some? y_opt /\ y == Some?.v y_opt /\ h0 == h1)) | val uindex (#a: Type0) (b: ubuffer a) (i: U32.t)
: HST.Stack a
(requires (fun h0 -> live h0 b /\ U32.v i < length b /\ b `initialized_at` (U32.v i)))
(ensures
(fun h0 y h1 ->
let y_opt = Seq.index (as_seq h0 b) (U32.v i) in
Some? y_opt /\ y == Some?.v y_opt /\ h0 == h1)) | let uindex (#a:Type0) (b:ubuffer a) (i:U32.t)
:HST.Stack a (requires (fun h0 -> live h0 b /\ U32.v i < length b /\ b `initialized_at` (U32.v i)))
(ensures (fun h0 y h1 -> let y_opt = Seq.index (as_seq h0 b) (U32.v i) in
Some? y_opt /\ y == Some?.v y_opt /\ h0 == h1))
= let y_opt = index b i in
recall_p b (ipred (U32.v i));
Some?.v y_opt | {
"file_name": "ulib/LowStar.UninitializedBuffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 17,
"end_line": 74,
"start_col": 0,
"start_line": 68
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.UninitializedBuffer
include LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(*
* Uninitialized buffers
*
* Modeled as: seq (option a) with a preorder that an index once set remains set
*)
private let initialization_preorder (a:Type0) :srel (option a) =
fun s1 s2 -> Seq.length s1 == Seq.length s2 /\
(forall (i:nat).{:pattern (Seq.index s2 i)} i < Seq.length s1 ==> Some? (Seq.index s1 i) ==> Some? (Seq.index s2 i))
type ubuffer (a:Type0) =
mbuffer (option a) (initialization_preorder a) (initialization_preorder a)
unfold let unull (#a:Type0) :ubuffer a = mnull #(option a) #(initialization_preorder a) #(initialization_preorder a)
unfold let gsub (#a:Type0) = mgsub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
unfold let gsub_inj (#a:Type0) = mgsub_inj #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a) (initialization_preorder a)
inline_for_extraction
type pointer (a:Type0) = b:ubuffer a{length b == 1}
inline_for_extraction
type pointer_or_null (a:Type0) = b:ubuffer a{if g_is_null b then True else length b == 1}
inline_for_extraction let usub (#a:Type0) = msub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
inline_for_extraction let uoffset (#a:Type0) = moffset #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
(****** main stateful API *****)
(*
* b `initialized_at` i: is a stable predicate that witnesses the initialization of an index i in ubuffer b
*)
private let ipred (#a:Type0) (i:nat) :spred (option a) = fun s -> i < Seq.length s ==> Some? (Seq.index s i)
let initialized_at (#a:Type0) (b:ubuffer a) (i:nat) :Type0 = witnessed b (ipred i)
(*
* Clients need to prove that b is initialized_at i | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.UninitializedBuffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: LowStar.UninitializedBuffer.ubuffer a -> i: FStar.UInt32.t -> FStar.HyperStack.ST.Stack a | FStar.HyperStack.ST.Stack | [] | [] | [
"LowStar.UninitializedBuffer.ubuffer",
"FStar.UInt32.t",
"FStar.Pervasives.Native.__proj__Some__item__v",
"Prims.unit",
"LowStar.Monotonic.Buffer.recall_p",
"FStar.Pervasives.Native.option",
"LowStar.UninitializedBuffer.initialization_preorder",
"LowStar.UninitializedBuffer.ipred",
"FStar.UInt32.v",
"LowStar.Monotonic.Buffer.index",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"LowStar.Monotonic.Buffer.live",
"Prims.b2t",
"Prims.op_LessThan",
"LowStar.Monotonic.Buffer.length",
"LowStar.UninitializedBuffer.initialized_at",
"FStar.Pervasives.Native.uu___is_Some",
"Prims.eq2",
"FStar.Seq.Base.index",
"LowStar.Monotonic.Buffer.as_seq"
] | [] | false | true | false | false | false | let uindex (#a: Type0) (b: ubuffer a) (i: U32.t)
: HST.Stack a
(requires (fun h0 -> live h0 b /\ U32.v i < length b /\ b `initialized_at` (U32.v i)))
(ensures
(fun h0 y h1 ->
let y_opt = Seq.index (as_seq h0 b) (U32.v i) in
Some? y_opt /\ y == Some?.v y_opt /\ h0 == h1)) =
| let y_opt = index b i in
recall_p b (ipred (U32.v i));
Some?.v y_opt | false |
LowStar.UninitializedBuffer.fst | LowStar.UninitializedBuffer.umalloc | val umalloc (#a: Type0) (r: HS.rid) (len: U32.t)
: HST.ST (b: lubuffer a (U32.v len) {frameOf b == r /\ freeable b})
(requires (fun _ -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) None))) | val umalloc (#a: Type0) (r: HS.rid) (len: U32.t)
: HST.ST (b: lubuffer a (U32.v len) {frameOf b == r /\ freeable b})
(requires (fun _ -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) None))) | let umalloc (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer a (U32.v len){frameOf b == r /\ freeable b})
(requires (fun _ -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mmalloc r None len | {
"file_name": "ulib/LowStar.UninitializedBuffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 22,
"end_line": 113,
"start_col": 0,
"start_line": 109
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.UninitializedBuffer
include LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(*
* Uninitialized buffers
*
* Modeled as: seq (option a) with a preorder that an index once set remains set
*)
private let initialization_preorder (a:Type0) :srel (option a) =
fun s1 s2 -> Seq.length s1 == Seq.length s2 /\
(forall (i:nat).{:pattern (Seq.index s2 i)} i < Seq.length s1 ==> Some? (Seq.index s1 i) ==> Some? (Seq.index s2 i))
type ubuffer (a:Type0) =
mbuffer (option a) (initialization_preorder a) (initialization_preorder a)
unfold let unull (#a:Type0) :ubuffer a = mnull #(option a) #(initialization_preorder a) #(initialization_preorder a)
unfold let gsub (#a:Type0) = mgsub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
unfold let gsub_inj (#a:Type0) = mgsub_inj #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a) (initialization_preorder a)
inline_for_extraction
type pointer (a:Type0) = b:ubuffer a{length b == 1}
inline_for_extraction
type pointer_or_null (a:Type0) = b:ubuffer a{if g_is_null b then True else length b == 1}
inline_for_extraction let usub (#a:Type0) = msub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
inline_for_extraction let uoffset (#a:Type0) = moffset #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
(****** main stateful API *****)
(*
* b `initialized_at` i: is a stable predicate that witnesses the initialization of an index i in ubuffer b
*)
private let ipred (#a:Type0) (i:nat) :spred (option a) = fun s -> i < Seq.length s ==> Some? (Seq.index s i)
let initialized_at (#a:Type0) (b:ubuffer a) (i:nat) :Type0 = witnessed b (ipred i)
(*
* Clients need to prove that b is initialized_at i
*)
let uindex (#a:Type0) (b:ubuffer a) (i:U32.t)
:HST.Stack a (requires (fun h0 -> live h0 b /\ U32.v i < length b /\ b `initialized_at` (U32.v i)))
(ensures (fun h0 y h1 -> let y_opt = Seq.index (as_seq h0 b) (U32.v i) in
Some? y_opt /\ y == Some?.v y_opt /\ h0 == h1))
= let y_opt = index b i in
recall_p b (ipred (U32.v i));
Some?.v y_opt
(*
* b `initialized_at` i is a postcondition
*)
let uupd (#a:Type0) (b:ubuffer a) (i:U32.t) (v:a)
:HST.Stack unit (requires (fun h0 -> live h0 b /\ U32.v i < length b))
(ensures (fun h0 _ h1 -> modifies (loc_buffer b) h0 h1 /\
live h1 b /\
as_seq h1 b == Seq.upd (as_seq h0 b) (U32.v i) (Some v) /\
b `initialized_at` (U32.v i)))
= upd b i (Some v);
witness_p b (ipred (U32.v i))
unfold let lubuffer (a:Type0) (len:nat) = b:ubuffer a{length b == len}
unfold let lubuffer_or_null (a:Type0) (len:nat) (r:HS.rid) =
b:ubuffer a{(not (g_is_null b)) ==> (length b == len /\ frameOf b == r)}
(*
* No initializer
*)
let ugcmalloc (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer a (U32.v len){frameOf b == r /\ recallable b})
(requires (fun h0 -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mgcmalloc r None len
inline_for_extraction
let ugcmalloc_partial (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer_or_null a (U32.v len) r{recallable b})
(requires (fun h0 -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_partial_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mgcmalloc r None len | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.UninitializedBuffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: FStar.Monotonic.HyperHeap.rid -> len: FStar.UInt32.t
-> FStar.HyperStack.ST.ST
(b:
LowStar.UninitializedBuffer.lubuffer a (FStar.UInt32.v len)
{LowStar.Monotonic.Buffer.frameOf b == r /\ LowStar.Monotonic.Buffer.freeable b}) | FStar.HyperStack.ST.ST | [] | [] | [
"FStar.Monotonic.HyperHeap.rid",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.mmalloc",
"FStar.Pervasives.Native.option",
"LowStar.UninitializedBuffer.initialization_preorder",
"FStar.Pervasives.Native.None",
"LowStar.Monotonic.Buffer.lmbuffer",
"FStar.UInt32.v",
"Prims.l_and",
"Prims.eq2",
"LowStar.Monotonic.Buffer.frameOf",
"LowStar.Monotonic.Buffer.freeable",
"LowStar.UninitializedBuffer.lubuffer",
"FStar.Monotonic.HyperStack.mem",
"LowStar.Monotonic.Buffer.malloc_pre",
"LowStar.Monotonic.Buffer.alloc_post_mem_common",
"FStar.Seq.Base.create"
] | [] | false | true | false | false | false | let umalloc (#a: Type0) (r: HS.rid) (len: U32.t)
: HST.ST (b: lubuffer a (U32.v len) {frameOf b == r /\ freeable b})
(requires (fun _ -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) None))) =
| mmalloc r None len | false |
LowStar.UninitializedBuffer.fst | LowStar.UninitializedBuffer.umalloc_partial | val umalloc_partial (#a: Type0) (r: HS.rid) (len: U32.t)
: HST.ST (b: lubuffer_or_null a (U32.v len) r {(not (g_is_null b)) ==> freeable b})
(requires (fun _ -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_partial_post_mem_common b h0 h1 (Seq.create (U32.v len) None))) | val umalloc_partial (#a: Type0) (r: HS.rid) (len: U32.t)
: HST.ST (b: lubuffer_or_null a (U32.v len) r {(not (g_is_null b)) ==> freeable b})
(requires (fun _ -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_partial_post_mem_common b h0 h1 (Seq.create (U32.v len) None))) | let umalloc_partial (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer_or_null a (U32.v len) r{(not (g_is_null b)) ==> freeable b})
(requires (fun _ -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_partial_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mmalloc r None len | {
"file_name": "ulib/LowStar.UninitializedBuffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 22,
"end_line": 120,
"start_col": 0,
"start_line": 116
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.UninitializedBuffer
include LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(*
* Uninitialized buffers
*
* Modeled as: seq (option a) with a preorder that an index once set remains set
*)
private let initialization_preorder (a:Type0) :srel (option a) =
fun s1 s2 -> Seq.length s1 == Seq.length s2 /\
(forall (i:nat).{:pattern (Seq.index s2 i)} i < Seq.length s1 ==> Some? (Seq.index s1 i) ==> Some? (Seq.index s2 i))
type ubuffer (a:Type0) =
mbuffer (option a) (initialization_preorder a) (initialization_preorder a)
unfold let unull (#a:Type0) :ubuffer a = mnull #(option a) #(initialization_preorder a) #(initialization_preorder a)
unfold let gsub (#a:Type0) = mgsub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
unfold let gsub_inj (#a:Type0) = mgsub_inj #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a) (initialization_preorder a)
inline_for_extraction
type pointer (a:Type0) = b:ubuffer a{length b == 1}
inline_for_extraction
type pointer_or_null (a:Type0) = b:ubuffer a{if g_is_null b then True else length b == 1}
inline_for_extraction let usub (#a:Type0) = msub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
inline_for_extraction let uoffset (#a:Type0) = moffset #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
(****** main stateful API *****)
(*
* b `initialized_at` i: is a stable predicate that witnesses the initialization of an index i in ubuffer b
*)
private let ipred (#a:Type0) (i:nat) :spred (option a) = fun s -> i < Seq.length s ==> Some? (Seq.index s i)
let initialized_at (#a:Type0) (b:ubuffer a) (i:nat) :Type0 = witnessed b (ipred i)
(*
* Clients need to prove that b is initialized_at i
*)
let uindex (#a:Type0) (b:ubuffer a) (i:U32.t)
:HST.Stack a (requires (fun h0 -> live h0 b /\ U32.v i < length b /\ b `initialized_at` (U32.v i)))
(ensures (fun h0 y h1 -> let y_opt = Seq.index (as_seq h0 b) (U32.v i) in
Some? y_opt /\ y == Some?.v y_opt /\ h0 == h1))
= let y_opt = index b i in
recall_p b (ipred (U32.v i));
Some?.v y_opt
(*
* b `initialized_at` i is a postcondition
*)
let uupd (#a:Type0) (b:ubuffer a) (i:U32.t) (v:a)
:HST.Stack unit (requires (fun h0 -> live h0 b /\ U32.v i < length b))
(ensures (fun h0 _ h1 -> modifies (loc_buffer b) h0 h1 /\
live h1 b /\
as_seq h1 b == Seq.upd (as_seq h0 b) (U32.v i) (Some v) /\
b `initialized_at` (U32.v i)))
= upd b i (Some v);
witness_p b (ipred (U32.v i))
unfold let lubuffer (a:Type0) (len:nat) = b:ubuffer a{length b == len}
unfold let lubuffer_or_null (a:Type0) (len:nat) (r:HS.rid) =
b:ubuffer a{(not (g_is_null b)) ==> (length b == len /\ frameOf b == r)}
(*
* No initializer
*)
let ugcmalloc (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer a (U32.v len){frameOf b == r /\ recallable b})
(requires (fun h0 -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mgcmalloc r None len
inline_for_extraction
let ugcmalloc_partial (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer_or_null a (U32.v len) r{recallable b})
(requires (fun h0 -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_partial_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mgcmalloc r None len
let umalloc (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer a (U32.v len){frameOf b == r /\ freeable b})
(requires (fun _ -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mmalloc r None len | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.UninitializedBuffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: FStar.Monotonic.HyperHeap.rid -> len: FStar.UInt32.t
-> FStar.HyperStack.ST.ST
(b:
LowStar.UninitializedBuffer.lubuffer_or_null a (FStar.UInt32.v len) r
{ Prims.op_Negation (LowStar.Monotonic.Buffer.g_is_null b) ==>
LowStar.Monotonic.Buffer.freeable b }) | FStar.HyperStack.ST.ST | [] | [] | [
"FStar.Monotonic.HyperHeap.rid",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.mmalloc",
"FStar.Pervasives.Native.option",
"LowStar.UninitializedBuffer.initialization_preorder",
"FStar.Pervasives.Native.None",
"LowStar.Monotonic.Buffer.lmbuffer",
"FStar.UInt32.v",
"Prims.l_and",
"Prims.eq2",
"LowStar.Monotonic.Buffer.frameOf",
"LowStar.Monotonic.Buffer.freeable",
"LowStar.UninitializedBuffer.lubuffer_or_null",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_Negation",
"LowStar.Monotonic.Buffer.g_is_null",
"FStar.Monotonic.HyperStack.mem",
"LowStar.Monotonic.Buffer.malloc_pre",
"LowStar.Monotonic.Buffer.alloc_partial_post_mem_common",
"FStar.Seq.Base.create"
] | [] | false | true | false | false | false | let umalloc_partial (#a: Type0) (r: HS.rid) (len: U32.t)
: HST.ST (b: lubuffer_or_null a (U32.v len) r {(not (g_is_null b)) ==> freeable b})
(requires (fun _ -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_partial_post_mem_common b h0 h1 (Seq.create (U32.v len) None))) =
| mmalloc r None len | false |
Selectors.LList2.fsti | Selectors.LList2.t | val t : a: Type0 -> Type0 | let t (a:Type0) = ref (cell a) | {
"file_name": "share/steel/examples/steel/Selectors.LList2.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 30,
"end_line": 19,
"start_col": 0,
"start_line": 19
} | module Selectors.LList2
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
open Steel.Reference
module L = FStar.List.Tot
/// This module provides the same interface as Selectors.LList.
/// The difference is in the implementation, it uses a newer, promising style to handle vprop.
/// Instead of going down all the way to the underlying slprop representation, it uses different
/// combinators to define the core list vprop
/// Abstract type of a list cell containing a value of type [a]
val cell (a:Type0) : Type0
/// The type of a list: A reference to a cell | {
"checked_file": "/",
"dependencies": [
"Steel.Reference.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Selectors.LList2.fsti"
} | [
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.Reference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Selectors",
"short_module": null
},
{
"abbrev": false,
"full_module": "Selectors",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type0 -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Steel.Reference.ref",
"Selectors.LList2.cell"
] | [] | false | false | false | true | true | let t (a: Type0) =
| ref (cell a) | false |
|
LowStar.UninitializedBuffer.fst | LowStar.UninitializedBuffer.buffer_immutable_buffer_disjoint | val buffer_immutable_buffer_disjoint
(#ti: Type)
(#t: Type0)
(bi: LowStar.ImmutableBuffer.ibuffer ti)
(b: ubuffer t)
(h: HS.mem)
: Lemma (requires (live h b /\ live h bi /\ (exists (x: t). True))) (ensures (disjoint b bi)) | val buffer_immutable_buffer_disjoint
(#ti: Type)
(#t: Type0)
(bi: LowStar.ImmutableBuffer.ibuffer ti)
(b: ubuffer t)
(h: HS.mem)
: Lemma (requires (live h b /\ live h bi /\ (exists (x: t). True))) (ensures (disjoint b bi)) | let buffer_immutable_buffer_disjoint
(#ti:Type) (#t:Type0)
(bi:LowStar.ImmutableBuffer.ibuffer ti)
(b:ubuffer t)
(h: HS.mem)
: Lemma
(requires (
live h b /\
live h bi /\
(exists (x:t). True ) // If the type is not inhabited, the initialization and immutable preorders are effectively identical
))
(ensures (
disjoint b bi
))
= if length b = 0
then empty_disjoint b bi
else if length bi = 0
then empty_disjoint bi b
else begin
let open LowStar.ImmutableBuffer in
let s = as_seq h b in
let s0 = Seq.upd s 0 None in
let s1 = Seq.upd s 0 (Some (FStar.IndefiniteDescription.indefinite_description_ghost t (fun _ -> True))) in
assert(initialization_preorder _ s0 s1 /\
Seq.index s0 0 =!= Seq.index s1 0 /\
~( immutable_preorder _ s0 s1 <==> initialization_preorder _ s0 s1));
live_same_addresses_equal_types_and_preorders b bi h
end | {
"file_name": "ulib/LowStar.UninitializedBuffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 5,
"end_line": 213,
"start_col": 0,
"start_line": 186
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.UninitializedBuffer
include LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(*
* Uninitialized buffers
*
* Modeled as: seq (option a) with a preorder that an index once set remains set
*)
private let initialization_preorder (a:Type0) :srel (option a) =
fun s1 s2 -> Seq.length s1 == Seq.length s2 /\
(forall (i:nat).{:pattern (Seq.index s2 i)} i < Seq.length s1 ==> Some? (Seq.index s1 i) ==> Some? (Seq.index s2 i))
type ubuffer (a:Type0) =
mbuffer (option a) (initialization_preorder a) (initialization_preorder a)
unfold let unull (#a:Type0) :ubuffer a = mnull #(option a) #(initialization_preorder a) #(initialization_preorder a)
unfold let gsub (#a:Type0) = mgsub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
unfold let gsub_inj (#a:Type0) = mgsub_inj #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a) (initialization_preorder a)
inline_for_extraction
type pointer (a:Type0) = b:ubuffer a{length b == 1}
inline_for_extraction
type pointer_or_null (a:Type0) = b:ubuffer a{if g_is_null b then True else length b == 1}
inline_for_extraction let usub (#a:Type0) = msub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
inline_for_extraction let uoffset (#a:Type0) = moffset #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
(****** main stateful API *****)
(*
* b `initialized_at` i: is a stable predicate that witnesses the initialization of an index i in ubuffer b
*)
private let ipred (#a:Type0) (i:nat) :spred (option a) = fun s -> i < Seq.length s ==> Some? (Seq.index s i)
let initialized_at (#a:Type0) (b:ubuffer a) (i:nat) :Type0 = witnessed b (ipred i)
(*
* Clients need to prove that b is initialized_at i
*)
let uindex (#a:Type0) (b:ubuffer a) (i:U32.t)
:HST.Stack a (requires (fun h0 -> live h0 b /\ U32.v i < length b /\ b `initialized_at` (U32.v i)))
(ensures (fun h0 y h1 -> let y_opt = Seq.index (as_seq h0 b) (U32.v i) in
Some? y_opt /\ y == Some?.v y_opt /\ h0 == h1))
= let y_opt = index b i in
recall_p b (ipred (U32.v i));
Some?.v y_opt
(*
* b `initialized_at` i is a postcondition
*)
let uupd (#a:Type0) (b:ubuffer a) (i:U32.t) (v:a)
:HST.Stack unit (requires (fun h0 -> live h0 b /\ U32.v i < length b))
(ensures (fun h0 _ h1 -> modifies (loc_buffer b) h0 h1 /\
live h1 b /\
as_seq h1 b == Seq.upd (as_seq h0 b) (U32.v i) (Some v) /\
b `initialized_at` (U32.v i)))
= upd b i (Some v);
witness_p b (ipred (U32.v i))
unfold let lubuffer (a:Type0) (len:nat) = b:ubuffer a{length b == len}
unfold let lubuffer_or_null (a:Type0) (len:nat) (r:HS.rid) =
b:ubuffer a{(not (g_is_null b)) ==> (length b == len /\ frameOf b == r)}
(*
* No initializer
*)
let ugcmalloc (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer a (U32.v len){frameOf b == r /\ recallable b})
(requires (fun h0 -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mgcmalloc r None len
inline_for_extraction
let ugcmalloc_partial (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer_or_null a (U32.v len) r{recallable b})
(requires (fun h0 -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_partial_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mgcmalloc r None len
let umalloc (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer a (U32.v len){frameOf b == r /\ freeable b})
(requires (fun _ -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mmalloc r None len
inline_for_extraction
let umalloc_partial (#a:Type0) (r:HS.rid) (len:U32.t)
:HST.ST (b:lubuffer_or_null a (U32.v len) r{(not (g_is_null b)) ==> freeable b})
(requires (fun _ -> malloc_pre r len))
(ensures (fun h0 b h1 -> alloc_partial_post_mem_common b h0 h1 (Seq.create (U32.v len) None)))
= mmalloc r None len
let ualloca (#a:Type0) (len:U32.t)
:HST.StackInline (lubuffer a (U32.v len))
(requires (fun _ -> alloca_pre len))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) None) /\
frameOf b == HS.get_tip h0))
= malloca None len
(*
* blit functionality, where src is a regular buffer
*)
[@@"opaque_to_smt"]
unfold let valid_j_for_blit
(#a:Type0) (#rrel #rel:srel a) (src:mbuffer a rrel rel) (idx_src:U32.t)
(dst:ubuffer a) (idx_dst:U32.t) (j:U32.t)
= U32.v idx_src + U32.v j <= length src /\
U32.v idx_dst + U32.v j <= length dst
(*
* postcondition of blit
*)
[@@"opaque_to_smt"]
unfold private let ublit_post_j
(#a:Type0) (#rrel #rel:srel a) (src:mbuffer a rrel rel) (idx_src:U32.t)
(dst:ubuffer a) (idx_dst:U32.t) (j:U32.t{valid_j_for_blit src idx_src dst idx_dst j})
(h0 h1:HS.mem)
= modifies (loc_buffer dst) h0 h1 /\ live h1 dst /\
(forall (i:nat).{:pattern (Seq.index (as_seq h1 dst) i)} (i >= U32.v idx_dst /\ i < U32.v idx_dst + U32.v j ==>
Seq.index (as_seq h1 dst) i ==
Some (Seq.index (as_seq h0 src) (U32.v idx_src + i - U32.v idx_dst)))
) /\
Seq.slice (as_seq h1 dst) 0 (U32.v idx_dst) == Seq.slice (as_seq h0 dst) 0 (U32.v idx_dst) /\
Seq.slice (as_seq h1 dst) (U32.v idx_dst + U32.v j) (length dst) == Seq.slice (as_seq h0 dst) (U32.v idx_dst + U32.v j) (length dst) /\
(forall (i:nat).{:pattern (dst `initialized_at` i)} (i >= U32.v idx_dst /\ i < U32.v idx_dst + U32.v j) ==>
dst `initialized_at` i)
let ublit (#a:Type0) (#rrel #rel:srel a)
(src:mbuffer a rrel rel) (idx_src:U32.t)
(dst:ubuffer a{disjoint src dst}) (idx_dst:U32.t)
(len:U32.t{valid_j_for_blit src idx_src dst idx_dst len})
:HST.Stack unit (requires (fun h0 -> live h0 src /\ live h0 dst))
(ensures (fun h0 _ h1 -> ublit_post_j src idx_src dst idx_dst len h0 h1))
= let rec aux (j:U32.t{valid_j_for_blit src idx_src dst idx_dst j})
:HST.Stack unit
(requires (fun h0 -> live h0 src /\ live h0 dst /\ ublit_post_j src idx_src dst idx_dst j h0 h0))
(ensures (fun h0 _ h1 -> ublit_post_j src idx_src dst idx_dst len h0 h1))
= let open FStar.UInt32 in
if j = len then ()
else if j <^ len then begin
uupd dst (idx_dst +^ j) (index src (idx_src +^ j));
aux (j +^ 1ul)
end
in
aux 0ul
let witness_initialized (#a:Type0) (b:ubuffer a) (i:nat)
:HST.ST unit (fun h0 -> i < length b /\ Some? (Seq.index (as_seq h0 b) i))
(fun h0 _ h1 -> h0 == h1 /\ b `initialized_at` i)
= witness_p b (ipred i)
let recall_initialized (#a:Type0) (b:ubuffer a) (i:nat)
:HST.ST unit (fun h0 -> (recallable b \/ live h0 b) /\ b `initialized_at` i)
(fun h0 _ h1 -> h0 == h1 /\ live h0 b /\ (i < length b ==> Some? (Seq.index (as_seq h0 b) i)))
= recall_p b (ipred i) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.UninitializedBuffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
bi: LowStar.ImmutableBuffer.ibuffer ti ->
b: LowStar.UninitializedBuffer.ubuffer t ->
h: FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires
LowStar.Monotonic.Buffer.live h b /\ LowStar.Monotonic.Buffer.live h bi /\
(exists (x: t). Prims.l_True)) (ensures LowStar.Monotonic.Buffer.disjoint b bi) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowStar.ImmutableBuffer.ibuffer",
"LowStar.UninitializedBuffer.ubuffer",
"FStar.Monotonic.HyperStack.mem",
"Prims.op_Equality",
"Prims.int",
"LowStar.Monotonic.Buffer.length",
"FStar.Pervasives.Native.option",
"LowStar.UninitializedBuffer.initialization_preorder",
"LowStar.Monotonic.Buffer.empty_disjoint",
"LowStar.ImmutableBuffer.immutable_preorder",
"Prims.bool",
"LowStar.Monotonic.Buffer.live_same_addresses_equal_types_and_preorders",
"Prims.unit",
"Prims._assert",
"Prims.l_and",
"Prims.l_not",
"Prims.eq2",
"FStar.Seq.Base.index",
"Prims.l_iff",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.upd",
"FStar.Pervasives.Native.Some",
"FStar.IndefiniteDescription.indefinite_description_ghost",
"Prims.l_True",
"Prims.prop",
"FStar.Pervasives.Native.None",
"LowStar.Monotonic.Buffer.as_seq",
"LowStar.Monotonic.Buffer.live",
"Prims.l_Exists",
"Prims.squash",
"LowStar.Monotonic.Buffer.disjoint",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let buffer_immutable_buffer_disjoint
(#ti: Type)
(#t: Type0)
(bi: LowStar.ImmutableBuffer.ibuffer ti)
(b: ubuffer t)
(h: HS.mem)
: Lemma (requires (live h b /\ live h bi /\ (exists (x: t). True))) (ensures (disjoint b bi)) =
| if length b = 0
then empty_disjoint b bi
else
if length bi = 0
then empty_disjoint bi b
else
let open LowStar.ImmutableBuffer in
let s = as_seq h b in
let s0 = Seq.upd s 0 None in
let s1 =
Seq.upd s
0
(Some (FStar.IndefiniteDescription.indefinite_description_ghost t (fun _ -> True)))
in
assert (initialization_preorder _ s0 s1 /\ Seq.index s0 0 =!= Seq.index s1 0 /\
~(immutable_preorder _ s0 s1 <==> initialization_preorder _ s0 s1));
live_same_addresses_equal_types_and_preorders b bi h | false |
LowStar.UninitializedBuffer.fst | LowStar.UninitializedBuffer.uupd | val uupd (#a: Type0) (b: ubuffer a) (i: U32.t) (v: a)
: HST.Stack unit
(requires (fun h0 -> live h0 b /\ U32.v i < length b))
(ensures
(fun h0 _ h1 ->
modifies (loc_buffer b) h0 h1 /\ live h1 b /\
as_seq h1 b == Seq.upd (as_seq h0 b) (U32.v i) (Some v) /\ b `initialized_at` (U32.v i))
) | val uupd (#a: Type0) (b: ubuffer a) (i: U32.t) (v: a)
: HST.Stack unit
(requires (fun h0 -> live h0 b /\ U32.v i < length b))
(ensures
(fun h0 _ h1 ->
modifies (loc_buffer b) h0 h1 /\ live h1 b /\
as_seq h1 b == Seq.upd (as_seq h0 b) (U32.v i) (Some v) /\ b `initialized_at` (U32.v i))
) | let uupd (#a:Type0) (b:ubuffer a) (i:U32.t) (v:a)
:HST.Stack unit (requires (fun h0 -> live h0 b /\ U32.v i < length b))
(ensures (fun h0 _ h1 -> modifies (loc_buffer b) h0 h1 /\
live h1 b /\
as_seq h1 b == Seq.upd (as_seq h0 b) (U32.v i) (Some v) /\
b `initialized_at` (U32.v i)))
= upd b i (Some v);
witness_p b (ipred (U32.v i)) | {
"file_name": "ulib/LowStar.UninitializedBuffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 33,
"end_line": 86,
"start_col": 0,
"start_line": 79
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.UninitializedBuffer
include LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
(*
* Uninitialized buffers
*
* Modeled as: seq (option a) with a preorder that an index once set remains set
*)
private let initialization_preorder (a:Type0) :srel (option a) =
fun s1 s2 -> Seq.length s1 == Seq.length s2 /\
(forall (i:nat).{:pattern (Seq.index s2 i)} i < Seq.length s1 ==> Some? (Seq.index s1 i) ==> Some? (Seq.index s2 i))
type ubuffer (a:Type0) =
mbuffer (option a) (initialization_preorder a) (initialization_preorder a)
unfold let unull (#a:Type0) :ubuffer a = mnull #(option a) #(initialization_preorder a) #(initialization_preorder a)
unfold let gsub (#a:Type0) = mgsub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
unfold let gsub_inj (#a:Type0) = mgsub_inj #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a) (initialization_preorder a)
inline_for_extraction
type pointer (a:Type0) = b:ubuffer a{length b == 1}
inline_for_extraction
type pointer_or_null (a:Type0) = b:ubuffer a{if g_is_null b then True else length b == 1}
inline_for_extraction let usub (#a:Type0) = msub #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
inline_for_extraction let uoffset (#a:Type0) = moffset #(option a) #(initialization_preorder a) #(initialization_preorder a) (initialization_preorder a)
(****** main stateful API *****)
(*
* b `initialized_at` i: is a stable predicate that witnesses the initialization of an index i in ubuffer b
*)
private let ipred (#a:Type0) (i:nat) :spred (option a) = fun s -> i < Seq.length s ==> Some? (Seq.index s i)
let initialized_at (#a:Type0) (b:ubuffer a) (i:nat) :Type0 = witnessed b (ipred i)
(*
* Clients need to prove that b is initialized_at i
*)
let uindex (#a:Type0) (b:ubuffer a) (i:U32.t)
:HST.Stack a (requires (fun h0 -> live h0 b /\ U32.v i < length b /\ b `initialized_at` (U32.v i)))
(ensures (fun h0 y h1 -> let y_opt = Seq.index (as_seq h0 b) (U32.v i) in
Some? y_opt /\ y == Some?.v y_opt /\ h0 == h1))
= let y_opt = index b i in
recall_p b (ipred (U32.v i));
Some?.v y_opt
(*
* b `initialized_at` i is a postcondition | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.UninitializedBuffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: LowStar.UninitializedBuffer.ubuffer a -> i: FStar.UInt32.t -> v: a
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"LowStar.UninitializedBuffer.ubuffer",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.witness_p",
"FStar.Pervasives.Native.option",
"LowStar.UninitializedBuffer.initialization_preorder",
"LowStar.UninitializedBuffer.ipred",
"FStar.UInt32.v",
"Prims.unit",
"LowStar.Monotonic.Buffer.upd",
"FStar.Pervasives.Native.Some",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"LowStar.Monotonic.Buffer.live",
"Prims.b2t",
"Prims.op_LessThan",
"LowStar.Monotonic.Buffer.length",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_buffer",
"Prims.eq2",
"FStar.Seq.Base.seq",
"LowStar.Monotonic.Buffer.as_seq",
"FStar.Seq.Base.upd",
"LowStar.UninitializedBuffer.initialized_at"
] | [] | false | true | false | false | false | let uupd (#a: Type0) (b: ubuffer a) (i: U32.t) (v: a)
: HST.Stack unit
(requires (fun h0 -> live h0 b /\ U32.v i < length b))
(ensures
(fun h0 _ h1 ->
modifies (loc_buffer b) h0 h1 /\ live h1 b /\
as_seq h1 b == Seq.upd (as_seq h0 b) (U32.v i) (Some v) /\ b `initialized_at` (U32.v i))
) =
| upd b i (Some v);
witness_p b (ipred (U32.v i)) | false |
Selectors.LList2.fsti | Selectors.LList2.llist | val llist : r: Selectors.LList2.t a -> Steel.Effect.Common.vprop | let llist (#a:Type0) (r:t a) = VUnit (llist' r) | {
"file_name": "share/steel/examples/steel/Selectors.LList2.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 47,
"end_line": 58,
"start_col": 0,
"start_line": 58
} | module Selectors.LList2
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
open Steel.Reference
module L = FStar.List.Tot
/// This module provides the same interface as Selectors.LList.
/// The difference is in the implementation, it uses a newer, promising style to handle vprop.
/// Instead of going down all the way to the underlying slprop representation, it uses different
/// combinators to define the core list vprop
/// Abstract type of a list cell containing a value of type [a]
val cell (a:Type0) : Type0
/// The type of a list: A reference to a cell
inline_for_extraction
let t (a:Type0) = ref (cell a)
(* Helpers to manipulate cells while keeping its definition abstract *)
inline_for_extraction
val next (#a:Type0) (c:cell a) : t a
inline_for_extraction
val data (#a:Type0) (c:cell a) : a
inline_for_extraction
val mk_cell (#a:Type0) (n: t a) (d:a)
: Pure (cell a)
(requires True)
(ensures fun c ->
next c == n /\
data c == d)
/// The null list pointer
inline_for_extraction
val null_llist (#a:Type) : t a
/// Lifting the null pointer check to empty lists
inline_for_extraction
val is_null (#a:Type) (ptr:t a) : (b:bool{b <==> ptr == null_llist})
/// Separation logic predicate stating that reference [r] points to a valid list in memory
val llist_sl (#a:Type0) (r:t a) : slprop u#1
/// Selector of a list. Returns an F* list of elements of type [a]
val llist_sel (#a:Type0) (r:t a) : selector (list a) (llist_sl r)
/// Combining the two above into a linked list vprop
[@@__steel_reduce__]
let llist' #a r : vprop' =
{hp = llist_sl r;
t = list a;
sel = llist_sel r} | {
"checked_file": "/",
"dependencies": [
"Steel.Reference.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Selectors.LList2.fsti"
} | [
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.Reference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Selectors",
"short_module": null
},
{
"abbrev": false,
"full_module": "Selectors",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: Selectors.LList2.t a -> Steel.Effect.Common.vprop | Prims.Tot | [
"total"
] | [] | [
"Selectors.LList2.t",
"Steel.Effect.Common.VUnit",
"Selectors.LList2.llist'",
"Steel.Effect.Common.vprop"
] | [] | false | false | false | true | false | let llist (#a: Type0) (r: t a) =
| VUnit (llist' r) | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.