effect
stringclasses 48
values | original_source_type
stringlengths 0
23k
| opens_and_abbrevs
listlengths 2
92
| isa_cross_project_example
bool 1
class | source_definition
stringlengths 9
57.9k
| partial_definition
stringlengths 7
23.3k
| is_div
bool 2
classes | is_type
null | is_proof
bool 2
classes | completed_definiton
stringlengths 1
250k
| dependencies
dict | effect_flags
sequencelengths 0
2
| ideal_premises
sequencelengths 0
236
| mutual_with
sequencelengths 0
11
| file_context
stringlengths 0
407k
| interleaved
bool 1
class | is_simply_typed
bool 2
classes | file_name
stringlengths 5
48
| vconfig
dict | is_simple_lemma
null | source_type
stringlengths 10
23k
| proof_features
sequencelengths 0
1
| name
stringlengths 8
95
| source
dict | verbose_type
stringlengths 1
7.42k
| source_range
dict |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Prims.Tot | val add_mod (#m: pos) (a b: nat_mod m) : nat_mod m | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let add_mod (#m:pos) (a:nat_mod m) (b:nat_mod m) : nat_mod m = (a + b) % m | val add_mod (#m: pos) (a b: nat_mod m) : nat_mod m
let add_mod (#m: pos) (a b: nat_mod m) : nat_mod m = | false | null | false | (a + b) % m | {
"checked_file": "Lib.NatMod.fsti.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Math.Fermat.fsti.checked",
"FStar.Math.Euclid.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.NatMod.fsti"
} | [
"total"
] | [
"Prims.pos",
"Lib.NatMod.nat_mod",
"Prims.op_Modulus",
"Prims.op_Addition"
] | [] | module Lib.NatMod
open FStar.Mul
module Fermat = FStar.Math.Fermat
module Euclid = FStar.Math.Euclid
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 10 --fuel 0 --ifuel 0"
let mk_nat_comm_monoid : LE.comm_monoid int = {
LE.one = 1;
LE.mul = FStar.Mul.op_Star;
LE.lemma_one = Math.Lemmas.mul_one_right_is_same;
LE.lemma_mul_assoc = Math.Lemmas.paren_mul_right;
LE.lemma_mul_comm = Math.Lemmas.swap_mul;
}
let rec pow (x:int) (n:nat) : Tot int =
if n = 0 then 1
else x * pow x (n - 1)
val lemma_pow0: a:int -> Lemma (pow a 0 = 1)
val lemma_pow1: a:int -> Lemma (pow a 1 = a)
val lemma_pow_unfold: a:int -> b:pos -> Lemma (a * pow a (b - 1) == pow a b)
val lemma_pow_gt_zero: a:pos -> b:nat -> Lemma (pow a b > 0) [SMTPat (pow a b)]
val lemma_pow_ge_zero: a:nat -> b:nat -> Lemma (pow a b >= 0) [SMTPat (pow a b)]
val lemma_pow_nat_is_pow: a:int -> b:nat ->
Lemma (pow a b == LE.pow mk_nat_comm_monoid a b)
val lemma_pow_zero: b:pos -> Lemma (pow 0 b = 0)
val lemma_pow_one: b:nat -> Lemma (pow 1 b = 1)
val lemma_pow_add: x:int -> n:nat -> m:nat -> Lemma (pow x n * pow x m = pow x (n + m))
val lemma_pow_mul: x:int -> n:nat -> m:nat -> Lemma (pow (pow x n) m = pow x (n * m))
val lemma_pow_double: a:int -> b:nat -> Lemma (pow (a * a) b == pow a (b + b))
val lemma_pow_mul_base: a:int -> b:int -> n:nat -> Lemma (pow a n * pow b n == pow (a * b) n)
val lemma_pow_mod_base: a:int -> b:nat -> n:pos -> Lemma (pow a b % n == pow (a % n) b % n)
let nat_mod (m:pos) = n:nat{n < m}
let one_mod (#m:pos) : nat_mod m = 1 % m | false | false | Lib.NatMod.fsti | {
"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": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val add_mod (#m: pos) (a b: nat_mod m) : nat_mod m | [] | Lib.NatMod.add_mod | {
"file_name": "lib/Lib.NatMod.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m -> Lib.NatMod.nat_mod m | {
"end_col": 74,
"end_line": 55,
"start_col": 63,
"start_line": 55
} |
Prims.Tot | val one_mod (#m: pos) : nat_mod m | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let one_mod (#m:pos) : nat_mod m = 1 % m | val one_mod (#m: pos) : nat_mod m
let one_mod (#m: pos) : nat_mod m = | false | null | false | 1 % m | {
"checked_file": "Lib.NatMod.fsti.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Math.Fermat.fsti.checked",
"FStar.Math.Euclid.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.NatMod.fsti"
} | [
"total"
] | [
"Prims.pos",
"Prims.op_Modulus",
"Lib.NatMod.nat_mod"
] | [] | module Lib.NatMod
open FStar.Mul
module Fermat = FStar.Math.Fermat
module Euclid = FStar.Math.Euclid
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 10 --fuel 0 --ifuel 0"
let mk_nat_comm_monoid : LE.comm_monoid int = {
LE.one = 1;
LE.mul = FStar.Mul.op_Star;
LE.lemma_one = Math.Lemmas.mul_one_right_is_same;
LE.lemma_mul_assoc = Math.Lemmas.paren_mul_right;
LE.lemma_mul_comm = Math.Lemmas.swap_mul;
}
let rec pow (x:int) (n:nat) : Tot int =
if n = 0 then 1
else x * pow x (n - 1)
val lemma_pow0: a:int -> Lemma (pow a 0 = 1)
val lemma_pow1: a:int -> Lemma (pow a 1 = a)
val lemma_pow_unfold: a:int -> b:pos -> Lemma (a * pow a (b - 1) == pow a b)
val lemma_pow_gt_zero: a:pos -> b:nat -> Lemma (pow a b > 0) [SMTPat (pow a b)]
val lemma_pow_ge_zero: a:nat -> b:nat -> Lemma (pow a b >= 0) [SMTPat (pow a b)]
val lemma_pow_nat_is_pow: a:int -> b:nat ->
Lemma (pow a b == LE.pow mk_nat_comm_monoid a b)
val lemma_pow_zero: b:pos -> Lemma (pow 0 b = 0)
val lemma_pow_one: b:nat -> Lemma (pow 1 b = 1)
val lemma_pow_add: x:int -> n:nat -> m:nat -> Lemma (pow x n * pow x m = pow x (n + m))
val lemma_pow_mul: x:int -> n:nat -> m:nat -> Lemma (pow (pow x n) m = pow x (n * m))
val lemma_pow_double: a:int -> b:nat -> Lemma (pow (a * a) b == pow a (b + b))
val lemma_pow_mul_base: a:int -> b:int -> n:nat -> Lemma (pow a n * pow b n == pow (a * b) n)
val lemma_pow_mod_base: a:int -> b:nat -> n:pos -> Lemma (pow a b % n == pow (a % n) b % n)
let nat_mod (m:pos) = n:nat{n < m} | false | false | Lib.NatMod.fsti | {
"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": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val one_mod (#m: pos) : nat_mod m | [] | Lib.NatMod.one_mod | {
"file_name": "lib/Lib.NatMod.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Lib.NatMod.nat_mod m | {
"end_col": 40,
"end_line": 53,
"start_col": 35,
"start_line": 53
} |
Prims.Tot | val mul_mod (#m: pos) (a b: nat_mod m) : nat_mod m | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mul_mod (#m:pos) (a:nat_mod m) (b:nat_mod m) : nat_mod m = a * b % m | val mul_mod (#m: pos) (a b: nat_mod m) : nat_mod m
let mul_mod (#m: pos) (a b: nat_mod m) : nat_mod m = | false | null | false | a * b % m | {
"checked_file": "Lib.NatMod.fsti.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Math.Fermat.fsti.checked",
"FStar.Math.Euclid.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.NatMod.fsti"
} | [
"total"
] | [
"Prims.pos",
"Lib.NatMod.nat_mod",
"Prims.op_Modulus",
"FStar.Mul.op_Star"
] | [] | module Lib.NatMod
open FStar.Mul
module Fermat = FStar.Math.Fermat
module Euclid = FStar.Math.Euclid
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 10 --fuel 0 --ifuel 0"
let mk_nat_comm_monoid : LE.comm_monoid int = {
LE.one = 1;
LE.mul = FStar.Mul.op_Star;
LE.lemma_one = Math.Lemmas.mul_one_right_is_same;
LE.lemma_mul_assoc = Math.Lemmas.paren_mul_right;
LE.lemma_mul_comm = Math.Lemmas.swap_mul;
}
let rec pow (x:int) (n:nat) : Tot int =
if n = 0 then 1
else x * pow x (n - 1)
val lemma_pow0: a:int -> Lemma (pow a 0 = 1)
val lemma_pow1: a:int -> Lemma (pow a 1 = a)
val lemma_pow_unfold: a:int -> b:pos -> Lemma (a * pow a (b - 1) == pow a b)
val lemma_pow_gt_zero: a:pos -> b:nat -> Lemma (pow a b > 0) [SMTPat (pow a b)]
val lemma_pow_ge_zero: a:nat -> b:nat -> Lemma (pow a b >= 0) [SMTPat (pow a b)]
val lemma_pow_nat_is_pow: a:int -> b:nat ->
Lemma (pow a b == LE.pow mk_nat_comm_monoid a b)
val lemma_pow_zero: b:pos -> Lemma (pow 0 b = 0)
val lemma_pow_one: b:nat -> Lemma (pow 1 b = 1)
val lemma_pow_add: x:int -> n:nat -> m:nat -> Lemma (pow x n * pow x m = pow x (n + m))
val lemma_pow_mul: x:int -> n:nat -> m:nat -> Lemma (pow (pow x n) m = pow x (n * m))
val lemma_pow_double: a:int -> b:nat -> Lemma (pow (a * a) b == pow a (b + b))
val lemma_pow_mul_base: a:int -> b:int -> n:nat -> Lemma (pow a n * pow b n == pow (a * b) n)
val lemma_pow_mod_base: a:int -> b:nat -> n:pos -> Lemma (pow a b % n == pow (a % n) b % n)
let nat_mod (m:pos) = n:nat{n < m} | false | false | Lib.NatMod.fsti | {
"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": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mul_mod (#m: pos) (a b: nat_mod m) : nat_mod m | [] | Lib.NatMod.mul_mod | {
"file_name": "lib/Lib.NatMod.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m -> Lib.NatMod.nat_mod m | {
"end_col": 72,
"end_line": 54,
"start_col": 63,
"start_line": 54
} |
Prims.Tot | val pow_mod_ (#m: pos{1 < m}) (a: nat_mod m) (b: nat) : Tot (nat_mod m) (decreases b) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec pow_mod_ (#m:pos{1 < m}) (a:nat_mod m) (b:nat) : Tot (nat_mod m) (decreases b) =
if b = 0 then 1
else
if b % 2 = 0 then pow_mod_ (mul_mod a a) (b / 2)
else mul_mod a (pow_mod_ (mul_mod a a) (b / 2)) | val pow_mod_ (#m: pos{1 < m}) (a: nat_mod m) (b: nat) : Tot (nat_mod m) (decreases b)
let rec pow_mod_ (#m: pos{1 < m}) (a: nat_mod m) (b: nat) : Tot (nat_mod m) (decreases b) = | false | null | false | if b = 0
then 1
else
if b % 2 = 0 then pow_mod_ (mul_mod a a) (b / 2) else mul_mod a (pow_mod_ (mul_mod a a) (b / 2)) | {
"checked_file": "Lib.NatMod.fsti.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Math.Fermat.fsti.checked",
"FStar.Math.Euclid.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.NatMod.fsti"
} | [
"total",
""
] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.NatMod.nat_mod",
"Prims.nat",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"Prims.op_Modulus",
"Lib.NatMod.pow_mod_",
"Lib.NatMod.mul_mod",
"Prims.op_Division"
] | [] | module Lib.NatMod
open FStar.Mul
module Fermat = FStar.Math.Fermat
module Euclid = FStar.Math.Euclid
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 10 --fuel 0 --ifuel 0"
let mk_nat_comm_monoid : LE.comm_monoid int = {
LE.one = 1;
LE.mul = FStar.Mul.op_Star;
LE.lemma_one = Math.Lemmas.mul_one_right_is_same;
LE.lemma_mul_assoc = Math.Lemmas.paren_mul_right;
LE.lemma_mul_comm = Math.Lemmas.swap_mul;
}
let rec pow (x:int) (n:nat) : Tot int =
if n = 0 then 1
else x * pow x (n - 1)
val lemma_pow0: a:int -> Lemma (pow a 0 = 1)
val lemma_pow1: a:int -> Lemma (pow a 1 = a)
val lemma_pow_unfold: a:int -> b:pos -> Lemma (a * pow a (b - 1) == pow a b)
val lemma_pow_gt_zero: a:pos -> b:nat -> Lemma (pow a b > 0) [SMTPat (pow a b)]
val lemma_pow_ge_zero: a:nat -> b:nat -> Lemma (pow a b >= 0) [SMTPat (pow a b)]
val lemma_pow_nat_is_pow: a:int -> b:nat ->
Lemma (pow a b == LE.pow mk_nat_comm_monoid a b)
val lemma_pow_zero: b:pos -> Lemma (pow 0 b = 0)
val lemma_pow_one: b:nat -> Lemma (pow 1 b = 1)
val lemma_pow_add: x:int -> n:nat -> m:nat -> Lemma (pow x n * pow x m = pow x (n + m))
val lemma_pow_mul: x:int -> n:nat -> m:nat -> Lemma (pow (pow x n) m = pow x (n * m))
val lemma_pow_double: a:int -> b:nat -> Lemma (pow (a * a) b == pow a (b + b))
val lemma_pow_mul_base: a:int -> b:int -> n:nat -> Lemma (pow a n * pow b n == pow (a * b) n)
val lemma_pow_mod_base: a:int -> b:nat -> n:pos -> Lemma (pow a b % n == pow (a % n) b % n)
let nat_mod (m:pos) = n:nat{n < m}
let one_mod (#m:pos) : nat_mod m = 1 % m
let mul_mod (#m:pos) (a:nat_mod m) (b:nat_mod m) : nat_mod m = a * b % m
let add_mod (#m:pos) (a:nat_mod m) (b:nat_mod m) : nat_mod m = (a + b) % m
let sub_mod (#m:pos) (a:nat_mod m) (b:nat_mod m) : nat_mod m = (a - b) % m
val lemma_mul_mod_one: #m:pos -> a:nat_mod m -> Lemma (mul_mod a one_mod == a)
val lemma_mul_mod_assoc: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m ->
Lemma (mul_mod (mul_mod a b) c == mul_mod a (mul_mod b c))
val lemma_mul_mod_comm: #m:pos -> a:nat_mod m -> b:nat_mod m ->
Lemma (mul_mod a b == mul_mod b a)
let mk_nat_mod_comm_monoid (m:pos) : LE.comm_monoid (nat_mod m) = {
LE.one = one_mod;
LE.mul = mul_mod;
LE.lemma_one = lemma_mul_mod_one;
LE.lemma_mul_assoc = lemma_mul_mod_assoc;
LE.lemma_mul_comm = lemma_mul_mod_comm;
}
inline_for_extraction | false | false | Lib.NatMod.fsti | {
"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": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pow_mod_ (#m: pos{1 < m}) (a: nat_mod m) (b: nat) : Tot (nat_mod m) (decreases b) | [
"recursion"
] | Lib.NatMod.pow_mod_ | {
"file_name": "lib/Lib.NatMod.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod m -> b: Prims.nat -> Prims.Tot (Lib.NatMod.nat_mod m) | {
"end_col": 51,
"end_line": 79,
"start_col": 2,
"start_line": 76
} |
Prims.Tot | val pow (x: int) (n: nat) : Tot int | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec pow (x:int) (n:nat) : Tot int =
if n = 0 then 1
else x * pow x (n - 1) | val pow (x: int) (n: nat) : Tot int
let rec pow (x: int) (n: nat) : Tot int = | false | null | false | if n = 0 then 1 else x * pow x (n - 1) | {
"checked_file": "Lib.NatMod.fsti.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Math.Fermat.fsti.checked",
"FStar.Math.Euclid.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.NatMod.fsti"
} | [
"total"
] | [
"Prims.int",
"Prims.nat",
"Prims.op_Equality",
"Prims.bool",
"FStar.Mul.op_Star",
"Lib.NatMod.pow",
"Prims.op_Subtraction"
] | [] | module Lib.NatMod
open FStar.Mul
module Fermat = FStar.Math.Fermat
module Euclid = FStar.Math.Euclid
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 10 --fuel 0 --ifuel 0"
let mk_nat_comm_monoid : LE.comm_monoid int = {
LE.one = 1;
LE.mul = FStar.Mul.op_Star;
LE.lemma_one = Math.Lemmas.mul_one_right_is_same;
LE.lemma_mul_assoc = Math.Lemmas.paren_mul_right;
LE.lemma_mul_comm = Math.Lemmas.swap_mul;
} | false | true | Lib.NatMod.fsti | {
"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": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pow (x: int) (n: nat) : Tot int | [
"recursion"
] | Lib.NatMod.pow | {
"file_name": "lib/Lib.NatMod.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Prims.int -> n: Prims.nat -> Prims.int | {
"end_col": 24,
"end_line": 23,
"start_col": 2,
"start_line": 22
} |
Prims.Tot | val mk_nat_comm_monoid:LE.comm_monoid int | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_nat_comm_monoid : LE.comm_monoid int = {
LE.one = 1;
LE.mul = FStar.Mul.op_Star;
LE.lemma_one = Math.Lemmas.mul_one_right_is_same;
LE.lemma_mul_assoc = Math.Lemmas.paren_mul_right;
LE.lemma_mul_comm = Math.Lemmas.swap_mul;
} | val mk_nat_comm_monoid:LE.comm_monoid int
let mk_nat_comm_monoid:LE.comm_monoid int = | false | null | false | {
LE.one = 1;
LE.mul = FStar.Mul.op_Star;
LE.lemma_one = Math.Lemmas.mul_one_right_is_same;
LE.lemma_mul_assoc = Math.Lemmas.paren_mul_right;
LE.lemma_mul_comm = Math.Lemmas.swap_mul
} | {
"checked_file": "Lib.NatMod.fsti.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Math.Fermat.fsti.checked",
"FStar.Math.Euclid.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.NatMod.fsti"
} | [
"total"
] | [
"Lib.Exponentiation.Definition.Mkcomm_monoid",
"Prims.int",
"FStar.Mul.op_Star",
"FStar.Math.Lemmas.mul_one_right_is_same",
"FStar.Math.Lemmas.paren_mul_right",
"FStar.Math.Lemmas.swap_mul"
] | [] | module Lib.NatMod
open FStar.Mul
module Fermat = FStar.Math.Fermat
module Euclid = FStar.Math.Euclid
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 10 --fuel 0 --ifuel 0" | false | true | Lib.NatMod.fsti | {
"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": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_nat_comm_monoid:LE.comm_monoid int | [] | Lib.NatMod.mk_nat_comm_monoid | {
"file_name": "lib/Lib.NatMod.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Lib.Exponentiation.Definition.comm_monoid Prims.int | {
"end_col": 43,
"end_line": 17,
"start_col": 2,
"start_line": 13
} |
Prims.Tot | val sub_mod (#m: pos) (a b: nat_mod m) : nat_mod m | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let sub_mod (#m:pos) (a:nat_mod m) (b:nat_mod m) : nat_mod m = (a - b) % m | val sub_mod (#m: pos) (a b: nat_mod m) : nat_mod m
let sub_mod (#m: pos) (a b: nat_mod m) : nat_mod m = | false | null | false | (a - b) % m | {
"checked_file": "Lib.NatMod.fsti.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Math.Fermat.fsti.checked",
"FStar.Math.Euclid.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.NatMod.fsti"
} | [
"total"
] | [
"Prims.pos",
"Lib.NatMod.nat_mod",
"Prims.op_Modulus",
"Prims.op_Subtraction"
] | [] | module Lib.NatMod
open FStar.Mul
module Fermat = FStar.Math.Fermat
module Euclid = FStar.Math.Euclid
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 10 --fuel 0 --ifuel 0"
let mk_nat_comm_monoid : LE.comm_monoid int = {
LE.one = 1;
LE.mul = FStar.Mul.op_Star;
LE.lemma_one = Math.Lemmas.mul_one_right_is_same;
LE.lemma_mul_assoc = Math.Lemmas.paren_mul_right;
LE.lemma_mul_comm = Math.Lemmas.swap_mul;
}
let rec pow (x:int) (n:nat) : Tot int =
if n = 0 then 1
else x * pow x (n - 1)
val lemma_pow0: a:int -> Lemma (pow a 0 = 1)
val lemma_pow1: a:int -> Lemma (pow a 1 = a)
val lemma_pow_unfold: a:int -> b:pos -> Lemma (a * pow a (b - 1) == pow a b)
val lemma_pow_gt_zero: a:pos -> b:nat -> Lemma (pow a b > 0) [SMTPat (pow a b)]
val lemma_pow_ge_zero: a:nat -> b:nat -> Lemma (pow a b >= 0) [SMTPat (pow a b)]
val lemma_pow_nat_is_pow: a:int -> b:nat ->
Lemma (pow a b == LE.pow mk_nat_comm_monoid a b)
val lemma_pow_zero: b:pos -> Lemma (pow 0 b = 0)
val lemma_pow_one: b:nat -> Lemma (pow 1 b = 1)
val lemma_pow_add: x:int -> n:nat -> m:nat -> Lemma (pow x n * pow x m = pow x (n + m))
val lemma_pow_mul: x:int -> n:nat -> m:nat -> Lemma (pow (pow x n) m = pow x (n * m))
val lemma_pow_double: a:int -> b:nat -> Lemma (pow (a * a) b == pow a (b + b))
val lemma_pow_mul_base: a:int -> b:int -> n:nat -> Lemma (pow a n * pow b n == pow (a * b) n)
val lemma_pow_mod_base: a:int -> b:nat -> n:pos -> Lemma (pow a b % n == pow (a % n) b % n)
let nat_mod (m:pos) = n:nat{n < m}
let one_mod (#m:pos) : nat_mod m = 1 % m
let mul_mod (#m:pos) (a:nat_mod m) (b:nat_mod m) : nat_mod m = a * b % m | false | false | Lib.NatMod.fsti | {
"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": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val sub_mod (#m: pos) (a b: nat_mod m) : nat_mod m | [] | Lib.NatMod.sub_mod | {
"file_name": "lib/Lib.NatMod.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m -> Lib.NatMod.nat_mod m | {
"end_col": 74,
"end_line": 56,
"start_col": 63,
"start_line": 56
} |
Prims.Tot | val inv_mod (#m: pos{1 < m}) (a: nat_mod m) : nat_mod m | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let inv_mod (#m:pos{1 < m}) (a:nat_mod m) : nat_mod m = pow_mod #m a (m - 2) | val inv_mod (#m: pos{1 < m}) (a: nat_mod m) : nat_mod m
let inv_mod (#m: pos{1 < m}) (a: nat_mod m) : nat_mod m = | false | null | false | pow_mod #m a (m - 2) | {
"checked_file": "Lib.NatMod.fsti.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Math.Fermat.fsti.checked",
"FStar.Math.Euclid.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.NatMod.fsti"
} | [
"total"
] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.NatMod.nat_mod",
"Lib.NatMod.pow_mod",
"Prims.op_Subtraction"
] | [] | module Lib.NatMod
open FStar.Mul
module Fermat = FStar.Math.Fermat
module Euclid = FStar.Math.Euclid
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 10 --fuel 0 --ifuel 0"
let mk_nat_comm_monoid : LE.comm_monoid int = {
LE.one = 1;
LE.mul = FStar.Mul.op_Star;
LE.lemma_one = Math.Lemmas.mul_one_right_is_same;
LE.lemma_mul_assoc = Math.Lemmas.paren_mul_right;
LE.lemma_mul_comm = Math.Lemmas.swap_mul;
}
let rec pow (x:int) (n:nat) : Tot int =
if n = 0 then 1
else x * pow x (n - 1)
val lemma_pow0: a:int -> Lemma (pow a 0 = 1)
val lemma_pow1: a:int -> Lemma (pow a 1 = a)
val lemma_pow_unfold: a:int -> b:pos -> Lemma (a * pow a (b - 1) == pow a b)
val lemma_pow_gt_zero: a:pos -> b:nat -> Lemma (pow a b > 0) [SMTPat (pow a b)]
val lemma_pow_ge_zero: a:nat -> b:nat -> Lemma (pow a b >= 0) [SMTPat (pow a b)]
val lemma_pow_nat_is_pow: a:int -> b:nat ->
Lemma (pow a b == LE.pow mk_nat_comm_monoid a b)
val lemma_pow_zero: b:pos -> Lemma (pow 0 b = 0)
val lemma_pow_one: b:nat -> Lemma (pow 1 b = 1)
val lemma_pow_add: x:int -> n:nat -> m:nat -> Lemma (pow x n * pow x m = pow x (n + m))
val lemma_pow_mul: x:int -> n:nat -> m:nat -> Lemma (pow (pow x n) m = pow x (n * m))
val lemma_pow_double: a:int -> b:nat -> Lemma (pow (a * a) b == pow a (b + b))
val lemma_pow_mul_base: a:int -> b:int -> n:nat -> Lemma (pow a n * pow b n == pow (a * b) n)
val lemma_pow_mod_base: a:int -> b:nat -> n:pos -> Lemma (pow a b % n == pow (a % n) b % n)
let nat_mod (m:pos) = n:nat{n < m}
let one_mod (#m:pos) : nat_mod m = 1 % m
let mul_mod (#m:pos) (a:nat_mod m) (b:nat_mod m) : nat_mod m = a * b % m
let add_mod (#m:pos) (a:nat_mod m) (b:nat_mod m) : nat_mod m = (a + b) % m
let sub_mod (#m:pos) (a:nat_mod m) (b:nat_mod m) : nat_mod m = (a - b) % m
val lemma_mul_mod_one: #m:pos -> a:nat_mod m -> Lemma (mul_mod a one_mod == a)
val lemma_mul_mod_assoc: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m ->
Lemma (mul_mod (mul_mod a b) c == mul_mod a (mul_mod b c))
val lemma_mul_mod_comm: #m:pos -> a:nat_mod m -> b:nat_mod m ->
Lemma (mul_mod a b == mul_mod b a)
let mk_nat_mod_comm_monoid (m:pos) : LE.comm_monoid (nat_mod m) = {
LE.one = one_mod;
LE.mul = mul_mod;
LE.lemma_one = lemma_mul_mod_one;
LE.lemma_mul_assoc = lemma_mul_mod_assoc;
LE.lemma_mul_comm = lemma_mul_mod_comm;
}
inline_for_extraction
let rec pow_mod_ (#m:pos{1 < m}) (a:nat_mod m) (b:nat) : Tot (nat_mod m) (decreases b) =
if b = 0 then 1
else
if b % 2 = 0 then pow_mod_ (mul_mod a a) (b / 2)
else mul_mod a (pow_mod_ (mul_mod a a) (b / 2))
val pow_mod: #m:pos{1 < m} -> a:nat_mod m -> b:nat -> nat_mod m
val pow_mod_def: #m:pos{1 < m} -> a:nat_mod m -> b:nat -> Lemma (pow_mod a b == pow_mod_ a b)
val lemma_pow_mod: #m:pos{1 < m} -> a:nat_mod m -> b:nat -> Lemma (pow a b % m == pow_mod #m a b)
val lemma_pow_nat_mod_is_pow: #n:pos{1 < n} -> a:nat_mod n -> b:nat ->
Lemma (pow a b % n == LE.pow (mk_nat_mod_comm_monoid n) a b)
val lemma_add_mod_one: #m:pos -> a:nat_mod m -> Lemma (add_mod a 0 == a)
val lemma_add_mod_assoc: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m ->
Lemma (add_mod (add_mod a b) c == add_mod a (add_mod b c))
val lemma_add_mod_comm: #m:pos -> a:nat_mod m -> b:nat_mod m ->
Lemma (add_mod a b == add_mod b a)
val lemma_mod_distributivity_add_right: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m ->
Lemma (mul_mod a (add_mod b c) == add_mod (mul_mod a b) (mul_mod a c))
val lemma_mod_distributivity_add_left: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m ->
Lemma (mul_mod (add_mod a b) c == add_mod (mul_mod a c) (mul_mod b c))
val lemma_mod_distributivity_sub_right: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m ->
Lemma (mul_mod a (sub_mod b c) == sub_mod (mul_mod a b) (mul_mod a c))
val lemma_mod_distributivity_sub_left: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m ->
Lemma (mul_mod (sub_mod a b) c == sub_mod (mul_mod a c) (mul_mod b c)) | false | false | Lib.NatMod.fsti | {
"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": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val inv_mod (#m: pos{1 < m}) (a: nat_mod m) : nat_mod m | [] | Lib.NatMod.inv_mod | {
"file_name": "lib/Lib.NatMod.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod m -> Lib.NatMod.nat_mod m | {
"end_col": 76,
"end_line": 114,
"start_col": 56,
"start_line": 114
} |
Prims.Tot | val opaque_make (#a:Type) (x:a) : a | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let opaque_make #a x = x | val opaque_make (#a:Type) (x:a) : a
let opaque_make #a x = | false | null | false | x | {
"checked_file": "Vale.Def.Opaque_s.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "Vale.Def.Opaque_s.fst"
} | [
"total"
] | [] | [] | module Vale.Def.Opaque_s
open FStar.Mul | false | false | Vale.Def.Opaque_s.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val opaque_make (#a:Type) (x:a) : a | [] | Vale.Def.Opaque_s.opaque_make | {
"file_name": "vale/specs/defs/Vale.Def.Opaque_s.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: a -> a | {
"end_col": 24,
"end_line": 4,
"start_col": 23,
"start_line": 4
} |
FStar.Pervasives.Lemma | val opaque_reveal (#a:Type) (s:string) (x1 x2:a) : Lemma
(requires norm [delta_only [s]] (x1 == opaque_make x2))
(ensures x1 == x2) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let opaque_reveal #a s x1 x2 =
norm_spec [delta_only [s]] (x1 == opaque_make x2) | val opaque_reveal (#a:Type) (s:string) (x1 x2:a) : Lemma
(requires norm [delta_only [s]] (x1 == opaque_make x2))
(ensures x1 == x2)
let opaque_reveal #a s x1 x2 = | false | null | true | norm_spec [delta_only [s]] (x1 == opaque_make x2) | {
"checked_file": "Vale.Def.Opaque_s.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "Vale.Def.Opaque_s.fst"
} | [
"lemma"
] | [
"Prims.string",
"FStar.Pervasives.norm_spec",
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.delta_only",
"Prims.Nil",
"Prims.logical",
"Prims.eq2",
"Vale.Def.Opaque_s.opaque_make",
"Prims.unit"
] | [] | module Vale.Def.Opaque_s
open FStar.Mul
let opaque_make #a x = x | false | false | Vale.Def.Opaque_s.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val opaque_reveal (#a:Type) (s:string) (x1 x2:a) : Lemma
(requires norm [delta_only [s]] (x1 == opaque_make x2))
(ensures x1 == x2) | [] | Vale.Def.Opaque_s.opaque_reveal | {
"file_name": "vale/specs/defs/Vale.Def.Opaque_s.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | s: Prims.string -> x1: a -> x2: a
-> FStar.Pervasives.Lemma
(requires
FStar.Pervasives.norm [FStar.Pervasives.delta_only [s]]
(x1 == Vale.Def.Opaque_s.opaque_make x2)) (ensures x1 == x2) | {
"end_col": 51,
"end_line": 7,
"start_col": 2,
"start_line": 7
} |
Prims.Pure | val opaque_revealer (#a:Type) (s:string) (x1 x2:a) : Pure (unit -> Lemma (x1 == x2))
(requires norm [delta_only [s]] (x1 == opaque_make x2))
(ensures fun _ -> True) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let opaque_revealer #a s x1 x2 =
fun () -> opaque_reveal s x1 x2 | val opaque_revealer (#a:Type) (s:string) (x1 x2:a) : Pure (unit -> Lemma (x1 == x2))
(requires norm [delta_only [s]] (x1 == opaque_make x2))
(ensures fun _ -> True)
let opaque_revealer #a s x1 x2 = | false | null | true | fun () -> opaque_reveal s x1 x2 | {
"checked_file": "Vale.Def.Opaque_s.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "Vale.Def.Opaque_s.fst"
} | [] | [
"Prims.string",
"Prims.unit",
"Vale.Def.Opaque_s.opaque_reveal"
] | [] | module Vale.Def.Opaque_s
open FStar.Mul
let opaque_make #a x = x
let opaque_reveal #a s x1 x2 =
norm_spec [delta_only [s]] (x1 == opaque_make x2)
let opaque_assert #a s x1 x2 p =
norm_spec [delta_only [s]] (x1 == opaque_make x2) | false | false | Vale.Def.Opaque_s.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val opaque_revealer (#a:Type) (s:string) (x1 x2:a) : Pure (unit -> Lemma (x1 == x2))
(requires norm [delta_only [s]] (x1 == opaque_make x2))
(ensures fun _ -> True) | [] | Vale.Def.Opaque_s.opaque_revealer | {
"file_name": "vale/specs/defs/Vale.Def.Opaque_s.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | s: Prims.string -> x1: a -> x2: a
-> Prims.Pure (_: Prims.unit -> FStar.Pervasives.Lemma (ensures x1 == x2)) | {
"end_col": 33,
"end_line": 13,
"start_col": 2,
"start_line": 13
} |
FStar.Pervasives.Lemma | val opaque_assert (#a:Type) (s:string) (x1 x2:a) (p:Type0) : Lemma
(requires norm [delta_only [s]] (x1 == opaque_make x2) /\ (x1 == x2 ==> p))
(ensures p) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let opaque_assert #a s x1 x2 p =
norm_spec [delta_only [s]] (x1 == opaque_make x2) | val opaque_assert (#a:Type) (s:string) (x1 x2:a) (p:Type0) : Lemma
(requires norm [delta_only [s]] (x1 == opaque_make x2) /\ (x1 == x2 ==> p))
(ensures p)
let opaque_assert #a s x1 x2 p = | false | null | true | norm_spec [delta_only [s]] (x1 == opaque_make x2) | {
"checked_file": "Vale.Def.Opaque_s.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "Vale.Def.Opaque_s.fst"
} | [
"lemma"
] | [
"Prims.string",
"FStar.Pervasives.norm_spec",
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.delta_only",
"Prims.Nil",
"Prims.logical",
"Prims.eq2",
"Vale.Def.Opaque_s.opaque_make",
"Prims.unit"
] | [] | module Vale.Def.Opaque_s
open FStar.Mul
let opaque_make #a x = x
let opaque_reveal #a s x1 x2 =
norm_spec [delta_only [s]] (x1 == opaque_make x2) | false | false | Vale.Def.Opaque_s.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val opaque_assert (#a:Type) (s:string) (x1 x2:a) (p:Type0) : Lemma
(requires norm [delta_only [s]] (x1 == opaque_make x2) /\ (x1 == x2 ==> p))
(ensures p) | [] | Vale.Def.Opaque_s.opaque_assert | {
"file_name": "vale/specs/defs/Vale.Def.Opaque_s.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | s: Prims.string -> x1: a -> x2: a -> p: Type0
-> FStar.Pervasives.Lemma
(requires
FStar.Pervasives.norm [FStar.Pervasives.delta_only [s]]
(x1 == Vale.Def.Opaque_s.opaque_make x2) /\ (x1 == x2 ==> p)) (ensures p) | {
"end_col": 51,
"end_line": 10,
"start_col": 2,
"start_line": 10
} |
FStar.Tactics.Effect.Tac | val join_smt_goals: Prims.unit -> Tac unit | [
{
"abbrev": true,
"full_module": "Pulse.Recursion",
"short_module": "Rec"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "Pulse.Config",
"short_module": "Cfg"
},
{
"abbrev": false,
"full_module": "Pulse.Soundness",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let join_smt_goals () : Tac unit =
let open FStar.Tactics.V2 in
let open FStar.List.Tot in
if RU.debug_at_level (top_env ()) "pulse.join" then
dump "PULSE: Goals before join";
(* Join *)
let smt_goals = smt_goals () in
set_goals (goals () @ smt_goals);
set_smt_goals [];
let n = List.Tot.length (goals ()) in
ignore (repeat join);
(* Heuristic rlimit setting :). Increase by 2 for every joined goal.
Default rlimit is 5, so this is "saving" 3 rlimit units per joined
goal. *)
if not (Nil? (goals ())) then (
let open FStar.Mul in
let rlimit = get_rlimit() + (n-1)*2 in
set_rlimit rlimit
);
if RU.debug_at_level (top_env ()) "pulse.join" then
dump "PULSE: Goals after join";
() | val join_smt_goals: Prims.unit -> Tac unit
let join_smt_goals () : Tac unit = | true | null | false | let open FStar.Tactics.V2 in
let open FStar.List.Tot in
if RU.debug_at_level (top_env ()) "pulse.join" then dump "PULSE: Goals before join";
let smt_goals = smt_goals () in
set_goals (goals () @ smt_goals);
set_smt_goals [];
let n = List.Tot.length (goals ()) in
ignore (repeat join);
if not (Nil? (goals ()))
then
(let open FStar.Mul in
let rlimit = get_rlimit () + (n - 1) * 2 in
set_rlimit rlimit);
if RU.debug_at_level (top_env ()) "pulse.join" then dump "PULSE: Goals after join";
() | {
"checked_file": "Pulse.Main.fst.checked",
"dependencies": [
"Pulse.Typing.Printer.fst.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.Builder.fst.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Soundness.Common.fst.checked",
"Pulse.Soundness.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Recursion.fsti.checked",
"Pulse.Elaborate.fsti.checked",
"Pulse.Config.fsti.checked",
"Pulse.Checker.Pure.fsti.checked",
"Pulse.Checker.Prover.fsti.checked",
"Pulse.Checker.Abs.fsti.checked",
"Pulse.Checker.fsti.checked",
"Pulse.ASTBuilder.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Issue.fsti.checked"
],
"interface_file": true,
"source_file": "Pulse.Main.fst"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Builtins.dump",
"Prims.bool",
"Pulse.RuntimeUtils.debug_at_level",
"FStar.Reflection.Types.env",
"FStar.Tactics.V2.Builtins.top_env",
"FStar.Tactics.SMT.set_rlimit",
"Prims.int",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.op_Subtraction",
"FStar.Tactics.SMT.get_rlimit",
"Prims.op_Negation",
"Prims.uu___is_Nil",
"FStar.Tactics.Types.goal",
"Prims.list",
"FStar.Tactics.V2.Derived.goals",
"FStar.Pervasives.ignore",
"FStar.Tactics.V2.Derived.repeat",
"FStar.Tactics.V2.Builtins.join",
"Prims.nat",
"FStar.List.Tot.Base.length",
"FStar.Tactics.V2.Builtins.set_smt_goals",
"Prims.Nil",
"FStar.Tactics.V2.Builtins.set_goals",
"FStar.List.Tot.Base.op_At",
"FStar.Tactics.V2.Derived.smt_goals"
] | [] | module Pulse.Main
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module RT = FStar.Reflection.Typing
open FStar.Tactics.V2
open Pulse.Syntax
open Pulse.Typing
open Pulse.Checker
open Pulse.Elaborate
open Pulse.Soundness
module Cfg = Pulse.Config
module RU = Pulse.RuntimeUtils
module P = Pulse.Syntax.Printer
module Rec = Pulse.Recursion
let debug_main g (s: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) "pulse.main"
then T.print (s ())
else ()
let rec mk_abs (g:env) (qbs:list (option qualifier & binder & bv)) (body:st_term) (comp:comp)
: TacH st_term (fun _ -> not (Nil? qbs))
(fun _ r -> match r with FStar.Tactics.Result.Success v _ -> Tm_Abs? v.term | _ -> False)
=
let with_range (s:st_term') (r:range) : st_term =
{ term = s; range = r; effect_tag = default_effect_hint }
in
match qbs with
| [(q, last, last_bv)] ->
let body = close_st_term body last_bv.bv_index in
let comp = close_comp comp last_bv.bv_index in
with_range (Pulse.Syntax.Builder.tm_abs last q comp body) body.range
| (q, b, bv)::qbs ->
let body = mk_abs g qbs body comp in
let body = close_st_term body bv.bv_index in
let comp = C_Tot tm_unknown in
with_range (Pulse.Syntax.Builder.tm_abs b q comp body) body.range
let check_fndecl
(d : decl{FnDecl? d.d})
(g : Soundness.Common.stt_env{bindings g == []})
(pre : term) (pre_typing : tot_typing g pre tm_vprop)
: T.Tac (RT.dsl_tac_result_t (fstar_env g))
=
(* Maybe add a recursive knot before starting *)
let FnDecl fn_d = d.d in
let nm_orig = fst (inspect_ident fn_d.id) in // keep the original name
let d =
if fn_d.isrec
then Recursion.add_knot g d.range d
else d
in
let FnDecl { id; isrec; bs; comp; meas; body } = d.d in
if Nil? bs then
fail g (Some d.range) "main: FnDecl does not have binders";
let body = mk_abs g bs body comp in
let rng = body.range in
let (| body, c, t_typing |) = Pulse.Checker.Abs.check_abs g body Pulse.Checker.check in
Pulse.Checker.Prover.debug_prover g
(fun _ -> Printf.sprintf "\ncheck call returned in main with:\n%s\n"
(P.st_term_to_string body));
debug_main g
(fun _ -> Printf.sprintf "\nchecker call returned in main with:\n%s\nderivation=%s\n"
(P.st_term_to_string body)
(Pulse.Typing.Printer.print_st_typing t_typing));
let refl_t = elab_comp c in
let refl_e = Pulse.RuntimeUtils.embed_st_term_for_extraction #st_term body (Some rng) in
let blob = "pulse", refl_e in
soundness_lemma g body c t_typing;
let main_decl =
let nm = fst (inspect_ident id) in
if T.ext_getv "pulse:elab_derivation" <> ""
then RT.mk_checked_let (fstar_env g) nm (elab_st_typing t_typing) refl_t
else Pulse.Reflection.Util.mk_opaque_let (fstar_env g) nm (elab_st_typing t_typing) refl_t
in
(* Set the blob *)
let main_decl =
let (chk, se, _) = main_decl in
(chk, se, Some blob)
in
let recursive_decls =
if fn_d.isrec
then Rec.tie_knot g rng nm_orig d refl_t
else []
in
main_decl :: recursive_decls
let main' (nm:string) (d:decl) (pre:term) (g:RT.fstar_top_env)
: T.Tac (RT.dsl_tac_result_t g)
= match Pulse.Soundness.Common.check_top_level_environment g with
| None -> T.fail "pulse main: top-level environment does not include stt at the expected types"
| Some g ->
if RU.debug_at_level (fstar_env g) "Pulse" then
T.print (Printf.sprintf "About to check pulse decl:\n%s\n" (P.decl_to_string d));
let (| pre, ty, pre_typing |) = Pulse.Checker.Pure.check_tot_term g pre in
if not (eq_tm ty tm_vprop) then
fail g (Some pre.range) "pulse main: cannot typecheck pre at type vprop"; //fix range
let pre_typing : tot_typing g pre tm_vprop = pre_typing in
match d.d with
| FnDecl _ ->
check_fndecl d g pre pre_typing | false | false | Pulse.Main.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val join_smt_goals: Prims.unit -> Tac unit | [] | Pulse.Main.join_smt_goals | {
"file_name": "lib/steel/pulse/Pulse.Main.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 4,
"end_line": 136,
"start_col": 2,
"start_line": 111
} |
Prims.Tot | val check_pulse (namespaces:list string)
(module_abbrevs:list (string & string))
(content:string)
(file_name:string)
(line col:int)
(nm:string)
: RT.dsl_tac_t | [
{
"abbrev": true,
"full_module": "Pulse.Recursion",
"short_module": "Rec"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "Pulse.Config",
"short_module": "Cfg"
},
{
"abbrev": false,
"full_module": "Pulse.Soundness",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let check_pulse (namespaces:list string)
(module_abbrevs:list (string & string))
(content:string)
(file_name:string)
(line col:int)
(nm:string)
: RT.dsl_tac_t
= fun env ->
match Pulse.ASTBuilder.parse_pulse env namespaces module_abbrevs content file_name line col with
| Inl decl ->
main nm decl tm_emp env
| Inr None ->
T.fail "Pulse parser failed"
| Inr (Some (msg, range)) ->
let i =
Issue.mk_issue "Error"
(Printf.sprintf "%s: %s" (T.range_to_string range) msg)
(Some range)
None
[]
in
T.log_issues [i];
T.fail "Pulse parser failed" | val check_pulse (namespaces:list string)
(module_abbrevs:list (string & string))
(content:string)
(file_name:string)
(line col:int)
(nm:string)
: RT.dsl_tac_t
let check_pulse
(namespaces: list string)
(module_abbrevs: list (string & string))
(content file_name: string)
(line col: int)
(nm: string)
: RT.dsl_tac_t = | false | null | false | fun env ->
match Pulse.ASTBuilder.parse_pulse env namespaces module_abbrevs content file_name line col with
| Inl decl -> main nm decl tm_emp env
| Inr None -> T.fail "Pulse parser failed"
| Inr (Some (msg, range)) ->
let i =
Issue.mk_issue "Error"
(Printf.sprintf "%s: %s" (T.range_to_string range) msg)
(Some range)
None
[]
in
T.log_issues [i];
T.fail "Pulse parser failed" | {
"checked_file": "Pulse.Main.fst.checked",
"dependencies": [
"Pulse.Typing.Printer.fst.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.Builder.fst.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Soundness.Common.fst.checked",
"Pulse.Soundness.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Recursion.fsti.checked",
"Pulse.Elaborate.fsti.checked",
"Pulse.Config.fsti.checked",
"Pulse.Checker.Pure.fsti.checked",
"Pulse.Checker.Prover.fsti.checked",
"Pulse.Checker.Abs.fsti.checked",
"Pulse.Checker.fsti.checked",
"Pulse.ASTBuilder.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Issue.fsti.checked"
],
"interface_file": true,
"source_file": "Pulse.Main.fst"
} | [
"total"
] | [
"Prims.list",
"Prims.string",
"FStar.Pervasives.Native.tuple2",
"Prims.int",
"FStar.Reflection.Typing.fstar_top_env",
"Pulse.Syntax.Base.decl",
"Pulse.Main.main",
"Pulse.Syntax.Base.tm_emp",
"FStar.Reflection.Typing.dsl_tac_result_t",
"FStar.Tactics.V2.Derived.fail",
"FStar.Range.range",
"Prims.unit",
"FStar.Tactics.V2.Builtins.log_issues",
"Prims.Cons",
"FStar.Issue.issue",
"Prims.Nil",
"FStar.Issue.mk_issue",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.None",
"FStar.Printf.sprintf",
"FStar.Tactics.V2.Builtins.range_to_string",
"FStar.Pervasives.either",
"FStar.Pervasives.Native.option",
"Pulse.ASTBuilder.parse_pulse",
"FStar.Reflection.Typing.dsl_tac_t"
] | [] | module Pulse.Main
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module RT = FStar.Reflection.Typing
open FStar.Tactics.V2
open Pulse.Syntax
open Pulse.Typing
open Pulse.Checker
open Pulse.Elaborate
open Pulse.Soundness
module Cfg = Pulse.Config
module RU = Pulse.RuntimeUtils
module P = Pulse.Syntax.Printer
module Rec = Pulse.Recursion
let debug_main g (s: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) "pulse.main"
then T.print (s ())
else ()
let rec mk_abs (g:env) (qbs:list (option qualifier & binder & bv)) (body:st_term) (comp:comp)
: TacH st_term (fun _ -> not (Nil? qbs))
(fun _ r -> match r with FStar.Tactics.Result.Success v _ -> Tm_Abs? v.term | _ -> False)
=
let with_range (s:st_term') (r:range) : st_term =
{ term = s; range = r; effect_tag = default_effect_hint }
in
match qbs with
| [(q, last, last_bv)] ->
let body = close_st_term body last_bv.bv_index in
let comp = close_comp comp last_bv.bv_index in
with_range (Pulse.Syntax.Builder.tm_abs last q comp body) body.range
| (q, b, bv)::qbs ->
let body = mk_abs g qbs body comp in
let body = close_st_term body bv.bv_index in
let comp = C_Tot tm_unknown in
with_range (Pulse.Syntax.Builder.tm_abs b q comp body) body.range
let check_fndecl
(d : decl{FnDecl? d.d})
(g : Soundness.Common.stt_env{bindings g == []})
(pre : term) (pre_typing : tot_typing g pre tm_vprop)
: T.Tac (RT.dsl_tac_result_t (fstar_env g))
=
(* Maybe add a recursive knot before starting *)
let FnDecl fn_d = d.d in
let nm_orig = fst (inspect_ident fn_d.id) in // keep the original name
let d =
if fn_d.isrec
then Recursion.add_knot g d.range d
else d
in
let FnDecl { id; isrec; bs; comp; meas; body } = d.d in
if Nil? bs then
fail g (Some d.range) "main: FnDecl does not have binders";
let body = mk_abs g bs body comp in
let rng = body.range in
let (| body, c, t_typing |) = Pulse.Checker.Abs.check_abs g body Pulse.Checker.check in
Pulse.Checker.Prover.debug_prover g
(fun _ -> Printf.sprintf "\ncheck call returned in main with:\n%s\n"
(P.st_term_to_string body));
debug_main g
(fun _ -> Printf.sprintf "\nchecker call returned in main with:\n%s\nderivation=%s\n"
(P.st_term_to_string body)
(Pulse.Typing.Printer.print_st_typing t_typing));
let refl_t = elab_comp c in
let refl_e = Pulse.RuntimeUtils.embed_st_term_for_extraction #st_term body (Some rng) in
let blob = "pulse", refl_e in
soundness_lemma g body c t_typing;
let main_decl =
let nm = fst (inspect_ident id) in
if T.ext_getv "pulse:elab_derivation" <> ""
then RT.mk_checked_let (fstar_env g) nm (elab_st_typing t_typing) refl_t
else Pulse.Reflection.Util.mk_opaque_let (fstar_env g) nm (elab_st_typing t_typing) refl_t
in
(* Set the blob *)
let main_decl =
let (chk, se, _) = main_decl in
(chk, se, Some blob)
in
let recursive_decls =
if fn_d.isrec
then Rec.tie_knot g rng nm_orig d refl_t
else []
in
main_decl :: recursive_decls
let main' (nm:string) (d:decl) (pre:term) (g:RT.fstar_top_env)
: T.Tac (RT.dsl_tac_result_t g)
= match Pulse.Soundness.Common.check_top_level_environment g with
| None -> T.fail "pulse main: top-level environment does not include stt at the expected types"
| Some g ->
if RU.debug_at_level (fstar_env g) "Pulse" then
T.print (Printf.sprintf "About to check pulse decl:\n%s\n" (P.decl_to_string d));
let (| pre, ty, pre_typing |) = Pulse.Checker.Pure.check_tot_term g pre in
if not (eq_tm ty tm_vprop) then
fail g (Some pre.range) "pulse main: cannot typecheck pre at type vprop"; //fix range
let pre_typing : tot_typing g pre tm_vprop = pre_typing in
match d.d with
| FnDecl _ ->
check_fndecl d g pre pre_typing
let join_smt_goals () : Tac unit =
let open FStar.Tactics.V2 in
let open FStar.List.Tot in
if RU.debug_at_level (top_env ()) "pulse.join" then
dump "PULSE: Goals before join";
(* Join *)
let smt_goals = smt_goals () in
set_goals (goals () @ smt_goals);
set_smt_goals [];
let n = List.Tot.length (goals ()) in
ignore (repeat join);
(* Heuristic rlimit setting :). Increase by 2 for every joined goal.
Default rlimit is 5, so this is "saving" 3 rlimit units per joined
goal. *)
if not (Nil? (goals ())) then (
let open FStar.Mul in
let rlimit = get_rlimit() + (n-1)*2 in
set_rlimit rlimit
);
if RU.debug_at_level (top_env ()) "pulse.join" then
dump "PULSE: Goals after join";
()
let main nm t pre : RT.dsl_tac_t = fun g ->
(* We use the SMT policy by default, to collect goals in the
proofstate and discharge them all at the end, potentially joining
them (see below). But it can be overriden to SMTSync by `--ext
pulse:guard_policy=SMTSync`. *)
if ext_getv "pulse:guard_policy" = "SMTSync" then
set_guard_policy SMTSync
else
set_guard_policy SMT;
let res = main' nm t pre g in
if ext_getv "pulse:join" = "1"
(* || ext_getv "pulse:join" <> "" *)
// ^ Uncomment to make it true by default.
then
join_smt_goals();
res
[@@plugin]
let check_pulse (namespaces:list string)
(module_abbrevs:list (string & string))
(content:string)
(file_name:string)
(line col:int)
(nm:string) | false | true | Pulse.Main.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val check_pulse (namespaces:list string)
(module_abbrevs:list (string & string))
(content:string)
(file_name:string)
(line col:int)
(nm:string)
: RT.dsl_tac_t | [] | Pulse.Main.check_pulse | {
"file_name": "lib/steel/pulse/Pulse.Main.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
namespaces: Prims.list Prims.string ->
module_abbrevs: Prims.list (Prims.string * Prims.string) ->
content: Prims.string ->
file_name: Prims.string ->
line: Prims.int ->
col: Prims.int ->
nm: Prims.string
-> FStar.Reflection.Typing.dsl_tac_t | {
"end_col": 36,
"end_line": 182,
"start_col": 4,
"start_line": 165
} |
FStar.Tactics.Effect.Tac | val main' (nm: string) (d: decl) (pre: term) (g: RT.fstar_top_env) : T.Tac (RT.dsl_tac_result_t g) | [
{
"abbrev": true,
"full_module": "Pulse.Recursion",
"short_module": "Rec"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "Pulse.Config",
"short_module": "Cfg"
},
{
"abbrev": false,
"full_module": "Pulse.Soundness",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let main' (nm:string) (d:decl) (pre:term) (g:RT.fstar_top_env)
: T.Tac (RT.dsl_tac_result_t g)
= match Pulse.Soundness.Common.check_top_level_environment g with
| None -> T.fail "pulse main: top-level environment does not include stt at the expected types"
| Some g ->
if RU.debug_at_level (fstar_env g) "Pulse" then
T.print (Printf.sprintf "About to check pulse decl:\n%s\n" (P.decl_to_string d));
let (| pre, ty, pre_typing |) = Pulse.Checker.Pure.check_tot_term g pre in
if not (eq_tm ty tm_vprop) then
fail g (Some pre.range) "pulse main: cannot typecheck pre at type vprop"; //fix range
let pre_typing : tot_typing g pre tm_vprop = pre_typing in
match d.d with
| FnDecl _ ->
check_fndecl d g pre pre_typing | val main' (nm: string) (d: decl) (pre: term) (g: RT.fstar_top_env) : T.Tac (RT.dsl_tac_result_t g)
let main' (nm: string) (d: decl) (pre: term) (g: RT.fstar_top_env) : T.Tac (RT.dsl_tac_result_t g) = | true | null | false | match Pulse.Soundness.Common.check_top_level_environment g with
| None -> T.fail "pulse main: top-level environment does not include stt at the expected types"
| Some g ->
if RU.debug_at_level (fstar_env g) "Pulse"
then T.print (Printf.sprintf "About to check pulse decl:\n%s\n" (P.decl_to_string d));
let (| pre , ty , pre_typing |) = Pulse.Checker.Pure.check_tot_term g pre in
if not (eq_tm ty tm_vprop)
then fail g (Some pre.range) "pulse main: cannot typecheck pre at type vprop";
let pre_typing:tot_typing g pre tm_vprop = pre_typing in
match d.d with | FnDecl _ -> check_fndecl d g pre pre_typing | {
"checked_file": "Pulse.Main.fst.checked",
"dependencies": [
"Pulse.Typing.Printer.fst.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.Builder.fst.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Soundness.Common.fst.checked",
"Pulse.Soundness.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Recursion.fsti.checked",
"Pulse.Elaborate.fsti.checked",
"Pulse.Config.fsti.checked",
"Pulse.Checker.Pure.fsti.checked",
"Pulse.Checker.Prover.fsti.checked",
"Pulse.Checker.Abs.fsti.checked",
"Pulse.Checker.fsti.checked",
"Pulse.ASTBuilder.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Issue.fsti.checked"
],
"interface_file": true,
"source_file": "Pulse.Main.fst"
} | [] | [
"Prims.string",
"Pulse.Syntax.Base.decl",
"Pulse.Syntax.Base.term",
"FStar.Reflection.Typing.fstar_top_env",
"Pulse.Soundness.Common.check_top_level_environment",
"FStar.Tactics.V2.Derived.fail",
"FStar.Reflection.Typing.dsl_tac_result_t",
"Pulse.Soundness.Common.stt_env",
"Pulse.Syntax.Base.typ",
"Pulse.Typing.tot_typing",
"Pulse.Syntax.Base.__proj__Mkdecl__item__d",
"Pulse.Syntax.Base.decl'__FnDecl__payload",
"Pulse.Main.check_fndecl",
"Pulse.Typing.Env.fstar_env",
"Pulse.Syntax.Base.tm_vprop",
"Prims.unit",
"Prims.op_Negation",
"Pulse.Syntax.Base.eq_tm",
"Pulse.Typing.Env.fail",
"FStar.Pervasives.Native.Some",
"Pulse.Syntax.Base.range",
"Pulse.Syntax.Base.__proj__Mkterm__item__range",
"Prims.bool",
"FStar.Pervasives.dtuple3",
"Pulse.Checker.Pure.check_tot_term",
"Pulse.RuntimeUtils.debug_at_level",
"FStar.Tactics.V2.Builtins.print",
"FStar.Printf.sprintf",
"Pulse.Syntax.Printer.decl_to_string"
] | [] | module Pulse.Main
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module RT = FStar.Reflection.Typing
open FStar.Tactics.V2
open Pulse.Syntax
open Pulse.Typing
open Pulse.Checker
open Pulse.Elaborate
open Pulse.Soundness
module Cfg = Pulse.Config
module RU = Pulse.RuntimeUtils
module P = Pulse.Syntax.Printer
module Rec = Pulse.Recursion
let debug_main g (s: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) "pulse.main"
then T.print (s ())
else ()
let rec mk_abs (g:env) (qbs:list (option qualifier & binder & bv)) (body:st_term) (comp:comp)
: TacH st_term (fun _ -> not (Nil? qbs))
(fun _ r -> match r with FStar.Tactics.Result.Success v _ -> Tm_Abs? v.term | _ -> False)
=
let with_range (s:st_term') (r:range) : st_term =
{ term = s; range = r; effect_tag = default_effect_hint }
in
match qbs with
| [(q, last, last_bv)] ->
let body = close_st_term body last_bv.bv_index in
let comp = close_comp comp last_bv.bv_index in
with_range (Pulse.Syntax.Builder.tm_abs last q comp body) body.range
| (q, b, bv)::qbs ->
let body = mk_abs g qbs body comp in
let body = close_st_term body bv.bv_index in
let comp = C_Tot tm_unknown in
with_range (Pulse.Syntax.Builder.tm_abs b q comp body) body.range
let check_fndecl
(d : decl{FnDecl? d.d})
(g : Soundness.Common.stt_env{bindings g == []})
(pre : term) (pre_typing : tot_typing g pre tm_vprop)
: T.Tac (RT.dsl_tac_result_t (fstar_env g))
=
(* Maybe add a recursive knot before starting *)
let FnDecl fn_d = d.d in
let nm_orig = fst (inspect_ident fn_d.id) in // keep the original name
let d =
if fn_d.isrec
then Recursion.add_knot g d.range d
else d
in
let FnDecl { id; isrec; bs; comp; meas; body } = d.d in
if Nil? bs then
fail g (Some d.range) "main: FnDecl does not have binders";
let body = mk_abs g bs body comp in
let rng = body.range in
let (| body, c, t_typing |) = Pulse.Checker.Abs.check_abs g body Pulse.Checker.check in
Pulse.Checker.Prover.debug_prover g
(fun _ -> Printf.sprintf "\ncheck call returned in main with:\n%s\n"
(P.st_term_to_string body));
debug_main g
(fun _ -> Printf.sprintf "\nchecker call returned in main with:\n%s\nderivation=%s\n"
(P.st_term_to_string body)
(Pulse.Typing.Printer.print_st_typing t_typing));
let refl_t = elab_comp c in
let refl_e = Pulse.RuntimeUtils.embed_st_term_for_extraction #st_term body (Some rng) in
let blob = "pulse", refl_e in
soundness_lemma g body c t_typing;
let main_decl =
let nm = fst (inspect_ident id) in
if T.ext_getv "pulse:elab_derivation" <> ""
then RT.mk_checked_let (fstar_env g) nm (elab_st_typing t_typing) refl_t
else Pulse.Reflection.Util.mk_opaque_let (fstar_env g) nm (elab_st_typing t_typing) refl_t
in
(* Set the blob *)
let main_decl =
let (chk, se, _) = main_decl in
(chk, se, Some blob)
in
let recursive_decls =
if fn_d.isrec
then Rec.tie_knot g rng nm_orig d refl_t
else []
in
main_decl :: recursive_decls
let main' (nm:string) (d:decl) (pre:term) (g:RT.fstar_top_env) | false | false | Pulse.Main.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val main' (nm: string) (d: decl) (pre: term) (g: RT.fstar_top_env) : T.Tac (RT.dsl_tac_result_t g) | [] | Pulse.Main.main' | {
"file_name": "lib/steel/pulse/Pulse.Main.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
nm: Prims.string ->
d: Pulse.Syntax.Base.decl ->
pre: Pulse.Syntax.Base.term ->
g: FStar.Reflection.Typing.fstar_top_env
-> FStar.Tactics.Effect.Tac (FStar.Reflection.Typing.dsl_tac_result_t g) | {
"end_col": 39,
"end_line": 108,
"start_col": 4,
"start_line": 97
} |
FStar.Tactics.Effect.TacH | val mk_abs (g: env) (qbs: list (option qualifier & binder & bv)) (body: st_term) (comp: comp)
: TacH st_term
(fun _ -> not (Nil? qbs))
(fun _ r ->
match r with
| FStar.Tactics.Result.Success v _ -> Tm_Abs? v.term
| _ -> False) | [
{
"abbrev": true,
"full_module": "Pulse.Recursion",
"short_module": "Rec"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "Pulse.Config",
"short_module": "Cfg"
},
{
"abbrev": false,
"full_module": "Pulse.Soundness",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec mk_abs (g:env) (qbs:list (option qualifier & binder & bv)) (body:st_term) (comp:comp)
: TacH st_term (fun _ -> not (Nil? qbs))
(fun _ r -> match r with FStar.Tactics.Result.Success v _ -> Tm_Abs? v.term | _ -> False)
=
let with_range (s:st_term') (r:range) : st_term =
{ term = s; range = r; effect_tag = default_effect_hint }
in
match qbs with
| [(q, last, last_bv)] ->
let body = close_st_term body last_bv.bv_index in
let comp = close_comp comp last_bv.bv_index in
with_range (Pulse.Syntax.Builder.tm_abs last q comp body) body.range
| (q, b, bv)::qbs ->
let body = mk_abs g qbs body comp in
let body = close_st_term body bv.bv_index in
let comp = C_Tot tm_unknown in
with_range (Pulse.Syntax.Builder.tm_abs b q comp body) body.range | val mk_abs (g: env) (qbs: list (option qualifier & binder & bv)) (body: st_term) (comp: comp)
: TacH st_term
(fun _ -> not (Nil? qbs))
(fun _ r ->
match r with
| FStar.Tactics.Result.Success v _ -> Tm_Abs? v.term
| _ -> False)
let rec mk_abs (g: env) (qbs: list (option qualifier & binder & bv)) (body: st_term) (comp: comp)
: TacH st_term
(fun _ -> not (Nil? qbs))
(fun _ r ->
match r with
| FStar.Tactics.Result.Success v _ -> Tm_Abs? v.term
| _ -> False) = | true | null | false | let with_range (s: st_term') (r: range) : st_term =
{ term = s; range = r; effect_tag = default_effect_hint }
in
match qbs with
| [q, last, last_bv] ->
let body = close_st_term body last_bv.bv_index in
let comp = close_comp comp last_bv.bv_index in
with_range (Pulse.Syntax.Builder.tm_abs last q comp body) body.range
| (q, b, bv) :: qbs ->
let body = mk_abs g qbs body comp in
let body = close_st_term body bv.bv_index in
let comp = C_Tot tm_unknown in
with_range (Pulse.Syntax.Builder.tm_abs b q comp body) body.range | {
"checked_file": "Pulse.Main.fst.checked",
"dependencies": [
"Pulse.Typing.Printer.fst.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.Builder.fst.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Soundness.Common.fst.checked",
"Pulse.Soundness.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Recursion.fsti.checked",
"Pulse.Elaborate.fsti.checked",
"Pulse.Config.fsti.checked",
"Pulse.Checker.Pure.fsti.checked",
"Pulse.Checker.Prover.fsti.checked",
"Pulse.Checker.Abs.fsti.checked",
"Pulse.Checker.fsti.checked",
"Pulse.ASTBuilder.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Issue.fsti.checked"
],
"interface_file": true,
"source_file": "Pulse.Main.fst"
} | [] | [
"Pulse.Typing.Env.env",
"Prims.list",
"FStar.Pervasives.Native.tuple3",
"FStar.Pervasives.Native.option",
"Pulse.Syntax.Base.qualifier",
"Pulse.Syntax.Base.binder",
"Pulse.Syntax.Base.bv",
"Pulse.Syntax.Base.st_term",
"Pulse.Syntax.Base.comp",
"Pulse.Syntax.Builder.tm_abs",
"Pulse.Syntax.Base.__proj__Mkst_term__item__range",
"Pulse.Syntax.Naming.close_comp",
"Pulse.Syntax.Base.__proj__Mkbv__item__bv_index",
"Pulse.Syntax.Naming.close_st_term",
"Pulse.Syntax.Base.C_Tot",
"Pulse.Syntax.Base.tm_unknown",
"Pulse.Main.mk_abs",
"Pulse.Syntax.Base.st_term'",
"Pulse.Syntax.Base.range",
"Pulse.Syntax.Base.Mkst_term",
"Pulse.Syntax.Base.default_effect_hint",
"FStar.Tactics.Types.proofstate",
"Prims.b2t",
"Prims.op_Negation",
"Prims.uu___is_Nil",
"FStar.Tactics.Result.__result",
"Pulse.Syntax.Base.uu___is_Tm_Abs",
"Pulse.Syntax.Base.__proj__Mkst_term__item__term",
"Prims.l_False"
] | [] | module Pulse.Main
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module RT = FStar.Reflection.Typing
open FStar.Tactics.V2
open Pulse.Syntax
open Pulse.Typing
open Pulse.Checker
open Pulse.Elaborate
open Pulse.Soundness
module Cfg = Pulse.Config
module RU = Pulse.RuntimeUtils
module P = Pulse.Syntax.Printer
module Rec = Pulse.Recursion
let debug_main g (s: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) "pulse.main"
then T.print (s ())
else ()
let rec mk_abs (g:env) (qbs:list (option qualifier & binder & bv)) (body:st_term) (comp:comp)
: TacH st_term (fun _ -> not (Nil? qbs)) | false | false | Pulse.Main.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_abs (g: env) (qbs: list (option qualifier & binder & bv)) (body: st_term) (comp: comp)
: TacH st_term
(fun _ -> not (Nil? qbs))
(fun _ r ->
match r with
| FStar.Tactics.Result.Success v _ -> Tm_Abs? v.term
| _ -> False) | [
"recursion"
] | Pulse.Main.mk_abs | {
"file_name": "lib/steel/pulse/Pulse.Main.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
g: Pulse.Typing.Env.env ->
qbs:
Prims.list ((FStar.Pervasives.Native.option Pulse.Syntax.Base.qualifier *
Pulse.Syntax.Base.binder) *
Pulse.Syntax.Base.bv) ->
body: Pulse.Syntax.Base.st_term ->
comp: Pulse.Syntax.Base.comp
-> FStar.Tactics.Effect.TacH Pulse.Syntax.Base.st_term | {
"end_col": 69,
"end_line": 39,
"start_col": 1,
"start_line": 26
} |
FStar.Tactics.Effect.Tac | val check_fndecl
(d: decl{FnDecl? d.d})
(g: Soundness.Common.stt_env{bindings g == []})
(pre: term)
(pre_typing: tot_typing g pre tm_vprop)
: T.Tac (RT.dsl_tac_result_t (fstar_env g)) | [
{
"abbrev": true,
"full_module": "Pulse.Recursion",
"short_module": "Rec"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "Pulse.Config",
"short_module": "Cfg"
},
{
"abbrev": false,
"full_module": "Pulse.Soundness",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let check_fndecl
(d : decl{FnDecl? d.d})
(g : Soundness.Common.stt_env{bindings g == []})
(pre : term) (pre_typing : tot_typing g pre tm_vprop)
: T.Tac (RT.dsl_tac_result_t (fstar_env g))
=
(* Maybe add a recursive knot before starting *)
let FnDecl fn_d = d.d in
let nm_orig = fst (inspect_ident fn_d.id) in // keep the original name
let d =
if fn_d.isrec
then Recursion.add_knot g d.range d
else d
in
let FnDecl { id; isrec; bs; comp; meas; body } = d.d in
if Nil? bs then
fail g (Some d.range) "main: FnDecl does not have binders";
let body = mk_abs g bs body comp in
let rng = body.range in
let (| body, c, t_typing |) = Pulse.Checker.Abs.check_abs g body Pulse.Checker.check in
Pulse.Checker.Prover.debug_prover g
(fun _ -> Printf.sprintf "\ncheck call returned in main with:\n%s\n"
(P.st_term_to_string body));
debug_main g
(fun _ -> Printf.sprintf "\nchecker call returned in main with:\n%s\nderivation=%s\n"
(P.st_term_to_string body)
(Pulse.Typing.Printer.print_st_typing t_typing));
let refl_t = elab_comp c in
let refl_e = Pulse.RuntimeUtils.embed_st_term_for_extraction #st_term body (Some rng) in
let blob = "pulse", refl_e in
soundness_lemma g body c t_typing;
let main_decl =
let nm = fst (inspect_ident id) in
if T.ext_getv "pulse:elab_derivation" <> ""
then RT.mk_checked_let (fstar_env g) nm (elab_st_typing t_typing) refl_t
else Pulse.Reflection.Util.mk_opaque_let (fstar_env g) nm (elab_st_typing t_typing) refl_t
in
(* Set the blob *)
let main_decl =
let (chk, se, _) = main_decl in
(chk, se, Some blob)
in
let recursive_decls =
if fn_d.isrec
then Rec.tie_knot g rng nm_orig d refl_t
else []
in
main_decl :: recursive_decls | val check_fndecl
(d: decl{FnDecl? d.d})
(g: Soundness.Common.stt_env{bindings g == []})
(pre: term)
(pre_typing: tot_typing g pre tm_vprop)
: T.Tac (RT.dsl_tac_result_t (fstar_env g))
let check_fndecl
(d: decl{FnDecl? d.d})
(g: Soundness.Common.stt_env{bindings g == []})
(pre: term)
(pre_typing: tot_typing g pre tm_vprop)
: T.Tac (RT.dsl_tac_result_t (fstar_env g)) = | true | null | false | let FnDecl fn_d = d.d in
let nm_orig = fst (inspect_ident fn_d.id) in
let d = if fn_d.isrec then Recursion.add_knot g d.range d else d in
let FnDecl { id = id ; isrec = isrec ; bs = bs ; comp = comp ; meas = meas ; body = body } = d.d in
if Nil? bs then fail g (Some d.range) "main: FnDecl does not have binders";
let body = mk_abs g bs body comp in
let rng = body.range in
let (| body , c , t_typing |) = Pulse.Checker.Abs.check_abs g body Pulse.Checker.check in
Pulse.Checker.Prover.debug_prover g
(fun _ -> Printf.sprintf "\ncheck call returned in main with:\n%s\n" (P.st_term_to_string body));
debug_main g
(fun _ ->
Printf.sprintf "\nchecker call returned in main with:\n%s\nderivation=%s\n"
(P.st_term_to_string body)
(Pulse.Typing.Printer.print_st_typing t_typing));
let refl_t = elab_comp c in
let refl_e = Pulse.RuntimeUtils.embed_st_term_for_extraction #st_term body (Some rng) in
let blob = "pulse", refl_e in
soundness_lemma g body c t_typing;
let main_decl =
let nm = fst (inspect_ident id) in
if T.ext_getv "pulse:elab_derivation" <> ""
then RT.mk_checked_let (fstar_env g) nm (elab_st_typing t_typing) refl_t
else Pulse.Reflection.Util.mk_opaque_let (fstar_env g) nm (elab_st_typing t_typing) refl_t
in
let main_decl =
let chk, se, _ = main_decl in
(chk, se, Some blob)
in
let recursive_decls = if fn_d.isrec then Rec.tie_knot g rng nm_orig d refl_t else [] in
main_decl :: recursive_decls | {
"checked_file": "Pulse.Main.fst.checked",
"dependencies": [
"Pulse.Typing.Printer.fst.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.Builder.fst.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Soundness.Common.fst.checked",
"Pulse.Soundness.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Recursion.fsti.checked",
"Pulse.Elaborate.fsti.checked",
"Pulse.Config.fsti.checked",
"Pulse.Checker.Pure.fsti.checked",
"Pulse.Checker.Prover.fsti.checked",
"Pulse.Checker.Abs.fsti.checked",
"Pulse.Checker.fsti.checked",
"Pulse.ASTBuilder.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Issue.fsti.checked"
],
"interface_file": true,
"source_file": "Pulse.Main.fst"
} | [] | [
"Pulse.Syntax.Base.decl",
"Prims.b2t",
"Pulse.Syntax.Base.uu___is_FnDecl",
"Pulse.Syntax.Base.__proj__Mkdecl__item__d",
"Pulse.Soundness.Common.stt_env",
"Prims.eq2",
"Prims.list",
"Pulse.Typing.Env.binding",
"Pulse.Typing.Env.bindings",
"Prims.Nil",
"Pulse.Syntax.Base.term",
"Pulse.Typing.tot_typing",
"Pulse.Syntax.Base.tm_vprop",
"Pulse.Syntax.Base.decl'__FnDecl__payload",
"FStar.Reflection.Types.ident",
"Prims.bool",
"FStar.Pervasives.Native.tuple3",
"FStar.Pervasives.Native.option",
"Pulse.Syntax.Base.qualifier",
"Pulse.Syntax.Base.binder",
"Pulse.Syntax.Base.bv",
"Pulse.Syntax.Base.comp",
"Prims.l_imp",
"FStar.Pervasives.Native.uu___is_Some",
"Pulse.Syntax.Base.st_term",
"Pulse.Typing.st_typing",
"Prims.Cons",
"FStar.Reflection.Typing.sigelt_for",
"Pulse.Typing.Env.fstar_env",
"FStar.Reflection.Typing.dsl_tac_result_t",
"Pulse.Syntax.Base.__proj__Mkdecl'__FnDecl__payload__item__isrec",
"Pulse.Recursion.tie_knot",
"FStar.Reflection.Types.sigelt",
"FStar.Reflection.Typing.blob",
"FStar.Pervasives.Native.Mktuple3",
"FStar.Pervasives.Native.Some",
"FStar.Reflection.Typing.mk_checked_let",
"Pulse.Elaborate.Core.elab_st_typing",
"Pulse.Reflection.Util.mk_opaque_let",
"FStar.Ghost.hide",
"FStar.Reflection.Types.term",
"Prims.op_disEquality",
"Prims.string",
"FStar.Tactics.V2.Builtins.ext_getv",
"FStar.Pervasives.Native.fst",
"FStar.Range.range",
"FStar.Reflection.V2.Builtins.inspect_ident",
"Prims.unit",
"Pulse.Soundness.soundness_lemma",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"Pulse.RuntimeUtils.embed_st_term_for_extraction",
"Pulse.Elaborate.Pure.elab_comp",
"Pulse.Main.debug_main",
"FStar.Printf.sprintf",
"Pulse.Syntax.Printer.st_term_to_string",
"Pulse.Typing.Printer.print_st_typing",
"Pulse.Checker.Prover.Util.debug_prover",
"FStar.Pervasives.dtuple3",
"Pulse.Checker.Abs.check_abs",
"Pulse.Checker.check",
"Pulse.Syntax.Base.range",
"Pulse.Syntax.Base.__proj__Mkst_term__item__range",
"Pulse.Main.mk_abs",
"Prims.uu___is_Nil",
"Pulse.Typing.Env.fail",
"Pulse.Syntax.Base.__proj__Mkdecl__item__range",
"Pulse.Syntax.Base.decl'",
"Pulse.Recursion.add_knot",
"Pulse.Syntax.Base.__proj__Mkdecl'__FnDecl__payload__item__id"
] | [] | module Pulse.Main
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module RT = FStar.Reflection.Typing
open FStar.Tactics.V2
open Pulse.Syntax
open Pulse.Typing
open Pulse.Checker
open Pulse.Elaborate
open Pulse.Soundness
module Cfg = Pulse.Config
module RU = Pulse.RuntimeUtils
module P = Pulse.Syntax.Printer
module Rec = Pulse.Recursion
let debug_main g (s: unit -> T.Tac string) : T.Tac unit =
if RU.debug_at_level (fstar_env g) "pulse.main"
then T.print (s ())
else ()
let rec mk_abs (g:env) (qbs:list (option qualifier & binder & bv)) (body:st_term) (comp:comp)
: TacH st_term (fun _ -> not (Nil? qbs))
(fun _ r -> match r with FStar.Tactics.Result.Success v _ -> Tm_Abs? v.term | _ -> False)
=
let with_range (s:st_term') (r:range) : st_term =
{ term = s; range = r; effect_tag = default_effect_hint }
in
match qbs with
| [(q, last, last_bv)] ->
let body = close_st_term body last_bv.bv_index in
let comp = close_comp comp last_bv.bv_index in
with_range (Pulse.Syntax.Builder.tm_abs last q comp body) body.range
| (q, b, bv)::qbs ->
let body = mk_abs g qbs body comp in
let body = close_st_term body bv.bv_index in
let comp = C_Tot tm_unknown in
with_range (Pulse.Syntax.Builder.tm_abs b q comp body) body.range
let check_fndecl
(d : decl{FnDecl? d.d})
(g : Soundness.Common.stt_env{bindings g == []})
(pre : term) (pre_typing : tot_typing g pre tm_vprop) | false | false | Pulse.Main.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val check_fndecl
(d: decl{FnDecl? d.d})
(g: Soundness.Common.stt_env{bindings g == []})
(pre: term)
(pre_typing: tot_typing g pre tm_vprop)
: T.Tac (RT.dsl_tac_result_t (fstar_env g)) | [] | Pulse.Main.check_fndecl | {
"file_name": "lib/steel/pulse/Pulse.Main.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
d: Pulse.Syntax.Base.decl{FnDecl? (Mkdecl?.d d)} ->
g: Pulse.Soundness.Common.stt_env{Pulse.Typing.Env.bindings g == []} ->
pre: Pulse.Syntax.Base.term ->
pre_typing: Pulse.Typing.tot_typing g pre Pulse.Syntax.Base.tm_vprop
-> FStar.Tactics.Effect.Tac
(FStar.Reflection.Typing.dsl_tac_result_t (Pulse.Typing.Env.fstar_env g)) | {
"end_col": 30,
"end_line": 93,
"start_col": 1,
"start_line": 46
} |
Prims.Tot | val poly128_of_poly32s (a0 a1 a2 a3: poly) : poly | [
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let poly128_of_poly32s (a0 a1 a2 a3:poly) : poly =
a0 +. shift a1 32 +. shift a2 64 +. shift a3 96 | val poly128_of_poly32s (a0 a1 a2 a3: poly) : poly
let poly128_of_poly32s (a0 a1 a2 a3: poly) : poly = | false | null | false | a0 +. shift a1 32 +. shift a2 64 +. shift a3 96 | {
"checked_file": "Vale.Math.Poly2.Bits.fsti.checked",
"dependencies": [
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Lemmas.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Math.Poly2.Bits.fsti"
} | [
"total"
] | [
"Vale.Math.Poly2_s.poly",
"Vale.Math.Poly2.op_Plus_Dot",
"Vale.Math.Poly2_s.shift"
] | [] | module Vale.Math.Poly2.Bits
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open FStar.UInt
open FStar.Seq
open Vale.Arch.Types
open Vale.Math.Poly2_s
open Vale.Math.Poly2.Bits_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Lemmas
val lemma_to_of_uint (n:pos) (u:uint_t n) : Lemma
(ensures to_uint n (of_uint n u) == u)
[SMTPat (to_uint n (of_uint n u))]
val of_nat (x:nat) : poly
// TODO: of_uint should accept n = 0
let of_uint_ (n:nat) (u:uint_t n) : poly =
if n = 0 then zero else of_uint n u
val lemma_of_nat_of_uint (n:nat) (x:nat) : Lemma
(requires x < pow2 n)
(ensures of_nat x == of_uint_ n x)
let rec poly_nat_eq_rec (len:nat) (p:poly) (c:nat) (n:nat) : bool =
if n = 0 then c = 0
else
(c % 2 = (if p.[len - n] then 1 else 0)) &&
poly_nat_eq_rec len p (c / 2) (n - 1)
// Useful for proving variable p equivalent to constant c via normalization
// (c and len should be constant integers)
val lemma_to_nat (len:nat) (p:poly) (c:nat) : Lemma
(requires degree p < len /\ normalize (poly_nat_eq_rec len p c len))
(ensures p == of_nat c)
val of_nat32 (n:nat32) : p:poly{degree p < 32 /\ p == of_nat n}
val of_nat32_zero : _:unit{of_nat32 0 == zero}
val of_nat32_ones : _:unit{of_nat32 0xffffffff == ones 32}
val of_nat32_eq (a b:nat32) : Lemma
(requires of_nat32 a == of_nat32 b)
(ensures a == b)
val of_nat32_xor (a b:nat32) : Lemma
(of_nat32 a +. of_nat32 b == of_nat32 (ixor a b))
val of_nat32_and (a b:nat32) : Lemma
(poly_and (of_nat32 a) (of_nat32 b) == of_nat32 (iand a b)) | false | true | Vale.Math.Poly2.Bits.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val poly128_of_poly32s (a0 a1 a2 a3: poly) : poly | [] | Vale.Math.Poly2.Bits.poly128_of_poly32s | {
"file_name": "vale/code/lib/math/Vale.Math.Poly2.Bits.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a0: Vale.Math.Poly2_s.poly ->
a1: Vale.Math.Poly2_s.poly ->
a2: Vale.Math.Poly2_s.poly ->
a3: Vale.Math.Poly2_s.poly
-> Vale.Math.Poly2_s.poly | {
"end_col": 49,
"end_line": 56,
"start_col": 2,
"start_line": 56
} |
Prims.Tot | val poly128_of_nat32s (a0 a1 a2 a3: nat32) : poly | [
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let poly128_of_nat32s (a0 a1 a2 a3:nat32) : poly =
poly128_of_poly32s (of_nat32 a0) (of_nat32 a1) (of_nat32 a2) (of_nat32 a3) | val poly128_of_nat32s (a0 a1 a2 a3: nat32) : poly
let poly128_of_nat32s (a0 a1 a2 a3: nat32) : poly = | false | null | false | poly128_of_poly32s (of_nat32 a0) (of_nat32 a1) (of_nat32 a2) (of_nat32 a3) | {
"checked_file": "Vale.Math.Poly2.Bits.fsti.checked",
"dependencies": [
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Lemmas.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Math.Poly2.Bits.fsti"
} | [
"total"
] | [
"Vale.Def.Types_s.nat32",
"Vale.Math.Poly2.Bits.poly128_of_poly32s",
"Vale.Math.Poly2.Bits.of_nat32",
"Vale.Math.Poly2_s.poly"
] | [] | module Vale.Math.Poly2.Bits
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open FStar.UInt
open FStar.Seq
open Vale.Arch.Types
open Vale.Math.Poly2_s
open Vale.Math.Poly2.Bits_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Lemmas
val lemma_to_of_uint (n:pos) (u:uint_t n) : Lemma
(ensures to_uint n (of_uint n u) == u)
[SMTPat (to_uint n (of_uint n u))]
val of_nat (x:nat) : poly
// TODO: of_uint should accept n = 0
let of_uint_ (n:nat) (u:uint_t n) : poly =
if n = 0 then zero else of_uint n u
val lemma_of_nat_of_uint (n:nat) (x:nat) : Lemma
(requires x < pow2 n)
(ensures of_nat x == of_uint_ n x)
let rec poly_nat_eq_rec (len:nat) (p:poly) (c:nat) (n:nat) : bool =
if n = 0 then c = 0
else
(c % 2 = (if p.[len - n] then 1 else 0)) &&
poly_nat_eq_rec len p (c / 2) (n - 1)
// Useful for proving variable p equivalent to constant c via normalization
// (c and len should be constant integers)
val lemma_to_nat (len:nat) (p:poly) (c:nat) : Lemma
(requires degree p < len /\ normalize (poly_nat_eq_rec len p c len))
(ensures p == of_nat c)
val of_nat32 (n:nat32) : p:poly{degree p < 32 /\ p == of_nat n}
val of_nat32_zero : _:unit{of_nat32 0 == zero}
val of_nat32_ones : _:unit{of_nat32 0xffffffff == ones 32}
val of_nat32_eq (a b:nat32) : Lemma
(requires of_nat32 a == of_nat32 b)
(ensures a == b)
val of_nat32_xor (a b:nat32) : Lemma
(of_nat32 a +. of_nat32 b == of_nat32 (ixor a b))
val of_nat32_and (a b:nat32) : Lemma
(poly_and (of_nat32 a) (of_nat32 b) == of_nat32 (iand a b))
let poly128_of_poly32s (a0 a1 a2 a3:poly) : poly =
a0 +. shift a1 32 +. shift a2 64 +. shift a3 96 | false | true | Vale.Math.Poly2.Bits.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val poly128_of_nat32s (a0 a1 a2 a3: nat32) : poly | [] | Vale.Math.Poly2.Bits.poly128_of_nat32s | {
"file_name": "vale/code/lib/math/Vale.Math.Poly2.Bits.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a0: Vale.Def.Types_s.nat32 ->
a1: Vale.Def.Types_s.nat32 ->
a2: Vale.Def.Types_s.nat32 ->
a3: Vale.Def.Types_s.nat32
-> Vale.Math.Poly2_s.poly | {
"end_col": 76,
"end_line": 59,
"start_col": 2,
"start_line": 59
} |
Prims.Tot | val of_uint_ (n: nat) (u: uint_t n) : poly | [
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let of_uint_ (n:nat) (u:uint_t n) : poly =
if n = 0 then zero else of_uint n u | val of_uint_ (n: nat) (u: uint_t n) : poly
let of_uint_ (n: nat) (u: uint_t n) : poly = | false | null | false | if n = 0 then zero else of_uint n u | {
"checked_file": "Vale.Math.Poly2.Bits.fsti.checked",
"dependencies": [
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Lemmas.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Math.Poly2.Bits.fsti"
} | [
"total"
] | [
"Prims.nat",
"FStar.UInt.uint_t",
"Prims.op_Equality",
"Prims.int",
"Vale.Math.Poly2_s.zero",
"Prims.bool",
"Vale.Math.Poly2.Bits_s.of_uint",
"Vale.Math.Poly2_s.poly"
] | [] | module Vale.Math.Poly2.Bits
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open FStar.UInt
open FStar.Seq
open Vale.Arch.Types
open Vale.Math.Poly2_s
open Vale.Math.Poly2.Bits_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Lemmas
val lemma_to_of_uint (n:pos) (u:uint_t n) : Lemma
(ensures to_uint n (of_uint n u) == u)
[SMTPat (to_uint n (of_uint n u))]
val of_nat (x:nat) : poly
// TODO: of_uint should accept n = 0 | false | false | Vale.Math.Poly2.Bits.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val of_uint_ (n: nat) (u: uint_t n) : poly | [] | Vale.Math.Poly2.Bits.of_uint_ | {
"file_name": "vale/code/lib/math/Vale.Math.Poly2.Bits.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | n: Prims.nat -> u3: FStar.UInt.uint_t n -> Vale.Math.Poly2_s.poly | {
"end_col": 37,
"end_line": 21,
"start_col": 2,
"start_line": 21
} |
Prims.Tot | val poly_nat_eq_rec (len: nat) (p: poly) (c n: nat) : bool | [
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec poly_nat_eq_rec (len:nat) (p:poly) (c:nat) (n:nat) : bool =
if n = 0 then c = 0
else
(c % 2 = (if p.[len - n] then 1 else 0)) &&
poly_nat_eq_rec len p (c / 2) (n - 1) | val poly_nat_eq_rec (len: nat) (p: poly) (c n: nat) : bool
let rec poly_nat_eq_rec (len: nat) (p: poly) (c n: nat) : bool = | false | null | false | if n = 0
then c = 0
else (c % 2 = (if p.[ len - n ] then 1 else 0)) && poly_nat_eq_rec len p (c / 2) (n - 1) | {
"checked_file": "Vale.Math.Poly2.Bits.fsti.checked",
"dependencies": [
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Lemmas.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Math.Poly2.Bits.fsti"
} | [
"total"
] | [
"Prims.nat",
"Vale.Math.Poly2_s.poly",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"Prims.op_AmpAmp",
"Prims.op_Modulus",
"Vale.Math.Poly2_s.op_String_Access",
"Prims.op_Subtraction",
"Vale.Math.Poly2.Bits.poly_nat_eq_rec",
"Prims.op_Division"
] | [] | module Vale.Math.Poly2.Bits
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Types_s
open FStar.UInt
open FStar.Seq
open Vale.Arch.Types
open Vale.Math.Poly2_s
open Vale.Math.Poly2.Bits_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Lemmas
val lemma_to_of_uint (n:pos) (u:uint_t n) : Lemma
(ensures to_uint n (of_uint n u) == u)
[SMTPat (to_uint n (of_uint n u))]
val of_nat (x:nat) : poly
// TODO: of_uint should accept n = 0
let of_uint_ (n:nat) (u:uint_t n) : poly =
if n = 0 then zero else of_uint n u
val lemma_of_nat_of_uint (n:nat) (x:nat) : Lemma
(requires x < pow2 n)
(ensures of_nat x == of_uint_ n x) | false | true | Vale.Math.Poly2.Bits.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val poly_nat_eq_rec (len: nat) (p: poly) (c n: nat) : bool | [
"recursion"
] | Vale.Math.Poly2.Bits.poly_nat_eq_rec | {
"file_name": "vale/code/lib/math/Vale.Math.Poly2.Bits.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | len: Prims.nat -> p: Vale.Math.Poly2_s.poly -> c: Prims.nat -> n: Prims.nat -> Prims.bool | {
"end_col": 41,
"end_line": 31,
"start_col": 2,
"start_line": 28
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let tset = TSet.set | let tset = | false | null | false | TSet.set | {
"checked_file": "FStar.Monotonic.Heap.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Monotonic.Heap.fsti"
} | [
"total"
] | [
"FStar.TSet.set"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Monotonic.Heap
module S = FStar.Set
module TS = FStar.TSet
open FStar.Preorder | false | true | FStar.Monotonic.Heap.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val tset : a: Type -> Type | [] | FStar.Monotonic.Heap.tset | {
"file_name": "ulib/FStar.Monotonic.Heap.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: Type -> Type | {
"end_col": 19,
"end_line": 24,
"start_col": 11,
"start_line": 24
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let set = Set.set | let set = | false | null | false | Set.set | {
"checked_file": "FStar.Monotonic.Heap.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Monotonic.Heap.fsti"
} | [
"total"
] | [
"FStar.Set.set"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Monotonic.Heap
module S = FStar.Set
module TS = FStar.TSet
open FStar.Preorder | false | true | FStar.Monotonic.Heap.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val set : a: Prims.eqtype -> Type0 | [] | FStar.Monotonic.Heap.set | {
"file_name": "ulib/FStar.Monotonic.Heap.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: Prims.eqtype -> Type0 | {
"end_col": 18,
"end_line": 23,
"start_col": 11,
"start_line": 23
} |
|
Prims.Tot | val mref (a: Type0) (rel: preorder a) : Type0 | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mref (a:Type0) (rel:preorder a) : Type0 = core_mref a | val mref (a: Type0) (rel: preorder a) : Type0
let mref (a: Type0) (rel: preorder a) : Type0 = | false | null | false | core_mref a | {
"checked_file": "FStar.Monotonic.Heap.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Monotonic.Heap.fsti"
} | [
"total"
] | [
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.core_mref"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Monotonic.Heap
module S = FStar.Set
module TS = FStar.TSet
open FStar.Preorder
let set = Set.set
let tset = TSet.set
val heap :Type u#1
val equal: heap -> heap -> Type0
val equal_extensional (h1:heap) (h2:heap)
:Lemma (requires True) (ensures (equal h1 h2 <==> h1 == h2))
[SMTPat (equal h1 h2)]
val emp :heap
val next_addr: heap -> GTot pos
val core_mref ([@@@ strictly_positive] a:Type0) : Type0 | false | false | FStar.Monotonic.Heap.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mref (a: Type0) (rel: preorder a) : Type0 | [] | FStar.Monotonic.Heap.mref | {
"file_name": "ulib/FStar.Monotonic.Heap.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: Type0 -> rel: FStar.Preorder.preorder a -> Type0 | {
"end_col": 57,
"end_line": 40,
"start_col": 46,
"start_line": 40
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fresh (#a:Type) (#rel:preorder a) (r:mref a rel) (h0:heap) (h1:heap) =
r `unused_in` h0 /\ h1 `contains` r | let fresh (#a: Type) (#rel: preorder a) (r: mref a rel) (h0 h1: heap) = | false | null | false | r `unused_in` h0 /\ h1 `contains` r | {
"checked_file": "FStar.Monotonic.Heap.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Monotonic.Heap.fsti"
} | [
"total"
] | [
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.mref",
"FStar.Monotonic.Heap.heap",
"Prims.l_and",
"FStar.Monotonic.Heap.unused_in",
"FStar.Monotonic.Heap.contains",
"Prims.logical"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Monotonic.Heap
module S = FStar.Set
module TS = FStar.TSet
open FStar.Preorder
let set = Set.set
let tset = TSet.set
val heap :Type u#1
val equal: heap -> heap -> Type0
val equal_extensional (h1:heap) (h2:heap)
:Lemma (requires True) (ensures (equal h1 h2 <==> h1 == h2))
[SMTPat (equal h1 h2)]
val emp :heap
val next_addr: heap -> GTot pos
val core_mref ([@@@ strictly_positive] a:Type0) : Type0
let mref (a:Type0) (rel:preorder a) : Type0 = core_mref a
val addr_of: #a:Type0 -> #rel:preorder a -> mref a rel -> GTot pos
val is_mm: #a:Type0 -> #rel:preorder a -> mref a rel -> GTot bool
let compare_addrs (#a #b:Type0) (#rel1:preorder a) (#rel2:preorder b) (r1:mref a rel1) (r2:mref b rel2)
:GTot bool = addr_of r1 = addr_of r2
val contains: #a:Type0 -> #rel:preorder a -> heap -> mref a rel -> Type0
val addr_unused_in: nat -> heap -> Type0
val not_addr_unused_in_nullptr (h: heap) : Lemma (~ (addr_unused_in 0 h))
val unused_in: #a:Type0 -> #rel:preorder a -> mref a rel -> heap -> Type0 | false | false | FStar.Monotonic.Heap.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fresh : r: FStar.Monotonic.Heap.mref a rel -> h0: FStar.Monotonic.Heap.heap -> h1: FStar.Monotonic.Heap.heap
-> Prims.logical | [] | FStar.Monotonic.Heap.fresh | {
"file_name": "ulib/FStar.Monotonic.Heap.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | r: FStar.Monotonic.Heap.mref a rel -> h0: FStar.Monotonic.Heap.heap -> h1: FStar.Monotonic.Heap.heap
-> Prims.logical | {
"end_col": 37,
"end_line": 58,
"start_col": 2,
"start_line": 58
} |
|
Prims.GTot | val equal_dom (h1 h2: heap) : GTot Type0 | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let equal_dom (h1:heap) (h2:heap) :GTot Type0 =
(forall (a:Type0) (rel:preorder a) (r:mref a rel).
{:pattern (h1 `contains` r) \/ (h2 `contains` r)}
h1 `contains` r <==> h2 `contains` r) /\
(forall (a:Type0) (rel:preorder a) (r:mref a rel).
{:pattern (r `unused_in` h1) \/ (r `unused_in` h2)}
r `unused_in` h1 <==> r `unused_in` h2) | val equal_dom (h1 h2: heap) : GTot Type0
let equal_dom (h1 h2: heap) : GTot Type0 = | false | null | false | (forall (a: Type0) (rel: preorder a) (r: mref a rel).
{:pattern (h1 `contains` r)\/(h2 `contains` r)}
h1 `contains` r <==> h2 `contains` r) /\
(forall (a: Type0) (rel: preorder a) (r: mref a rel).
{:pattern (r `unused_in` h1)\/(r `unused_in` h2)}
r `unused_in` h1 <==> r `unused_in` h2) | {
"checked_file": "FStar.Monotonic.Heap.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Monotonic.Heap.fsti"
} | [
"sometrivial"
] | [
"FStar.Monotonic.Heap.heap",
"Prims.l_and",
"Prims.l_Forall",
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.mref",
"Prims.l_iff",
"FStar.Monotonic.Heap.contains",
"FStar.Monotonic.Heap.unused_in"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Monotonic.Heap
module S = FStar.Set
module TS = FStar.TSet
open FStar.Preorder
let set = Set.set
let tset = TSet.set
val heap :Type u#1
val equal: heap -> heap -> Type0
val equal_extensional (h1:heap) (h2:heap)
:Lemma (requires True) (ensures (equal h1 h2 <==> h1 == h2))
[SMTPat (equal h1 h2)]
val emp :heap
val next_addr: heap -> GTot pos
val core_mref ([@@@ strictly_positive] a:Type0) : Type0
let mref (a:Type0) (rel:preorder a) : Type0 = core_mref a
val addr_of: #a:Type0 -> #rel:preorder a -> mref a rel -> GTot pos
val is_mm: #a:Type0 -> #rel:preorder a -> mref a rel -> GTot bool
let compare_addrs (#a #b:Type0) (#rel1:preorder a) (#rel2:preorder b) (r1:mref a rel1) (r2:mref b rel2)
:GTot bool = addr_of r1 = addr_of r2
val contains: #a:Type0 -> #rel:preorder a -> heap -> mref a rel -> Type0
val addr_unused_in: nat -> heap -> Type0
val not_addr_unused_in_nullptr (h: heap) : Lemma (~ (addr_unused_in 0 h))
val unused_in: #a:Type0 -> #rel:preorder a -> mref a rel -> heap -> Type0
let fresh (#a:Type) (#rel:preorder a) (r:mref a rel) (h0:heap) (h1:heap) =
r `unused_in` h0 /\ h1 `contains` r
let only_t (#a:Type0) (#rel:preorder a) (x:mref a rel) :GTot (tset nat) = TS.singleton (addr_of x)
let only (#a:Type0) (#rel:preorder a) (x:mref a rel) :GTot (set nat) = S.singleton (addr_of x)
let op_Hat_Plus_Plus (#a:Type0) (#rel:preorder a) (r:mref a rel) (s:set nat) :GTot (set nat) = S.union (only r) s
let op_Plus_Plus_Hat (#a:Type0) (#rel:preorder a) (s:set nat) (r:mref a rel) :GTot (set nat) = S.union s (only r)
let op_Hat_Plus_Hat (#a:Type0) (#b:Type0) (#rel1:preorder a) (#rel2:preorder b) (r1:mref a rel1) (r2:mref b rel2)
:GTot (set nat) = S.union (only r1) (only r2)
val sel_tot: #a:Type0 -> #rel:preorder a -> h:heap -> r:mref a rel{h `contains` r} -> Tot a
val sel: #a:Type0 -> #rel:preorder a -> heap -> mref a rel -> GTot a
val upd_tot: #a:Type0 -> #rel:preorder a -> h:heap -> r:mref a rel{h `contains` r} -> x:a -> Tot heap
val upd: #a:Type0 -> #rel:preorder a -> h:heap -> r:mref a rel -> x:a -> GTot heap
val alloc: #a:Type0 -> rel:preorder a -> heap -> a -> mm:bool -> Tot (mref a rel * heap)
val free_mm: #a:Type0 -> #rel:preorder a -> h:heap -> r:mref a rel{h `contains` r /\ is_mm r} -> Tot heap
let modifies_t (s:tset nat) (h0:heap) (h1:heap) =
(forall (a:Type) (rel:preorder a) (r:mref a rel).{:pattern (sel h1 r)}
((~ (TS.mem (addr_of r) s)) /\ h0 `contains` r) ==> sel h1 r == sel h0 r) /\
(forall (a:Type) (rel:preorder a) (r:mref a rel).{:pattern (contains h1 r)}
h0 `contains` r ==> h1 `contains` r) /\
(forall (a:Type) (rel:preorder a) (r:mref a rel).{:pattern (r `unused_in` h0)}
r `unused_in` h1 ==> r `unused_in` h0) /\
(forall (n: nat) . {:pattern (n `addr_unused_in` h0) }
n `addr_unused_in` h1 ==> n `addr_unused_in` h0
)
let modifies (s:set nat) (h0:heap) (h1:heap) = modifies_t (TS.tset_of_set s) h0 h1 | false | false | FStar.Monotonic.Heap.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val equal_dom (h1 h2: heap) : GTot Type0 | [] | FStar.Monotonic.Heap.equal_dom | {
"file_name": "ulib/FStar.Monotonic.Heap.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | h1: FStar.Monotonic.Heap.heap -> h2: FStar.Monotonic.Heap.heap -> Prims.GTot Type0 | {
"end_col": 44,
"end_line": 103,
"start_col": 2,
"start_line": 98
} |
Prims.GTot | val only_t (#a: Type0) (#rel: preorder a) (x: mref a rel) : GTot (tset nat) | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let only_t (#a:Type0) (#rel:preorder a) (x:mref a rel) :GTot (tset nat) = TS.singleton (addr_of x) | val only_t (#a: Type0) (#rel: preorder a) (x: mref a rel) : GTot (tset nat)
let only_t (#a: Type0) (#rel: preorder a) (x: mref a rel) : GTot (tset nat) = | false | null | false | TS.singleton (addr_of x) | {
"checked_file": "FStar.Monotonic.Heap.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Monotonic.Heap.fsti"
} | [
"sometrivial"
] | [
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.mref",
"FStar.TSet.singleton",
"Prims.nat",
"FStar.Monotonic.Heap.addr_of",
"FStar.Monotonic.Heap.tset"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Monotonic.Heap
module S = FStar.Set
module TS = FStar.TSet
open FStar.Preorder
let set = Set.set
let tset = TSet.set
val heap :Type u#1
val equal: heap -> heap -> Type0
val equal_extensional (h1:heap) (h2:heap)
:Lemma (requires True) (ensures (equal h1 h2 <==> h1 == h2))
[SMTPat (equal h1 h2)]
val emp :heap
val next_addr: heap -> GTot pos
val core_mref ([@@@ strictly_positive] a:Type0) : Type0
let mref (a:Type0) (rel:preorder a) : Type0 = core_mref a
val addr_of: #a:Type0 -> #rel:preorder a -> mref a rel -> GTot pos
val is_mm: #a:Type0 -> #rel:preorder a -> mref a rel -> GTot bool
let compare_addrs (#a #b:Type0) (#rel1:preorder a) (#rel2:preorder b) (r1:mref a rel1) (r2:mref b rel2)
:GTot bool = addr_of r1 = addr_of r2
val contains: #a:Type0 -> #rel:preorder a -> heap -> mref a rel -> Type0
val addr_unused_in: nat -> heap -> Type0
val not_addr_unused_in_nullptr (h: heap) : Lemma (~ (addr_unused_in 0 h))
val unused_in: #a:Type0 -> #rel:preorder a -> mref a rel -> heap -> Type0
let fresh (#a:Type) (#rel:preorder a) (r:mref a rel) (h0:heap) (h1:heap) =
r `unused_in` h0 /\ h1 `contains` r | false | false | FStar.Monotonic.Heap.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val only_t (#a: Type0) (#rel: preorder a) (x: mref a rel) : GTot (tset nat) | [] | FStar.Monotonic.Heap.only_t | {
"file_name": "ulib/FStar.Monotonic.Heap.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: FStar.Monotonic.Heap.mref a rel -> Prims.GTot (FStar.Monotonic.Heap.tset Prims.nat) | {
"end_col": 98,
"end_line": 60,
"start_col": 74,
"start_line": 60
} |
Prims.GTot | val compare_addrs
(#a #b: Type0)
(#rel1: preorder a)
(#rel2: preorder b)
(r1: mref a rel1)
(r2: mref b rel2)
: GTot bool | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let compare_addrs (#a #b:Type0) (#rel1:preorder a) (#rel2:preorder b) (r1:mref a rel1) (r2:mref b rel2)
:GTot bool = addr_of r1 = addr_of r2 | val compare_addrs
(#a #b: Type0)
(#rel1: preorder a)
(#rel2: preorder b)
(r1: mref a rel1)
(r2: mref b rel2)
: GTot bool
let compare_addrs
(#a #b: Type0)
(#rel1: preorder a)
(#rel2: preorder b)
(r1: mref a rel1)
(r2: mref b rel2)
: GTot bool = | false | null | false | addr_of r1 = addr_of r2 | {
"checked_file": "FStar.Monotonic.Heap.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Monotonic.Heap.fsti"
} | [
"sometrivial"
] | [
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.mref",
"Prims.op_Equality",
"Prims.pos",
"FStar.Monotonic.Heap.addr_of",
"Prims.bool"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Monotonic.Heap
module S = FStar.Set
module TS = FStar.TSet
open FStar.Preorder
let set = Set.set
let tset = TSet.set
val heap :Type u#1
val equal: heap -> heap -> Type0
val equal_extensional (h1:heap) (h2:heap)
:Lemma (requires True) (ensures (equal h1 h2 <==> h1 == h2))
[SMTPat (equal h1 h2)]
val emp :heap
val next_addr: heap -> GTot pos
val core_mref ([@@@ strictly_positive] a:Type0) : Type0
let mref (a:Type0) (rel:preorder a) : Type0 = core_mref a
val addr_of: #a:Type0 -> #rel:preorder a -> mref a rel -> GTot pos
val is_mm: #a:Type0 -> #rel:preorder a -> mref a rel -> GTot bool | false | false | FStar.Monotonic.Heap.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val compare_addrs
(#a #b: Type0)
(#rel1: preorder a)
(#rel2: preorder b)
(r1: mref a rel1)
(r2: mref b rel2)
: GTot bool | [] | FStar.Monotonic.Heap.compare_addrs | {
"file_name": "ulib/FStar.Monotonic.Heap.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | r1: FStar.Monotonic.Heap.mref a rel1 -> r2: FStar.Monotonic.Heap.mref b rel2
-> Prims.GTot Prims.bool | {
"end_col": 38,
"end_line": 47,
"start_col": 15,
"start_line": 47
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let modifies_t (s:tset nat) (h0:heap) (h1:heap) =
(forall (a:Type) (rel:preorder a) (r:mref a rel).{:pattern (sel h1 r)}
((~ (TS.mem (addr_of r) s)) /\ h0 `contains` r) ==> sel h1 r == sel h0 r) /\
(forall (a:Type) (rel:preorder a) (r:mref a rel).{:pattern (contains h1 r)}
h0 `contains` r ==> h1 `contains` r) /\
(forall (a:Type) (rel:preorder a) (r:mref a rel).{:pattern (r `unused_in` h0)}
r `unused_in` h1 ==> r `unused_in` h0) /\
(forall (n: nat) . {:pattern (n `addr_unused_in` h0) }
n `addr_unused_in` h1 ==> n `addr_unused_in` h0
) | let modifies_t (s: tset nat) (h0 h1: heap) = | false | null | false | (forall (a: Type) (rel: preorder a) (r: mref a rel). {:pattern (sel h1 r)}
((~(TS.mem (addr_of r) s)) /\ h0 `contains` r) ==> sel h1 r == sel h0 r) /\
(forall (a: Type) (rel: preorder a) (r: mref a rel). {:pattern (contains h1 r)}
h0 `contains` r ==> h1 `contains` r) /\
(forall (a: Type) (rel: preorder a) (r: mref a rel). {:pattern (r `unused_in` h0)}
r `unused_in` h1 ==> r `unused_in` h0) /\
(forall (n: nat). {:pattern (n `addr_unused_in` h0)} n `addr_unused_in` h1 ==> n `addr_unused_in` h0
) | {
"checked_file": "FStar.Monotonic.Heap.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Monotonic.Heap.fsti"
} | [
"total"
] | [
"FStar.Monotonic.Heap.tset",
"Prims.nat",
"FStar.Monotonic.Heap.heap",
"Prims.l_and",
"Prims.l_Forall",
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.mref",
"Prims.l_imp",
"Prims.l_not",
"FStar.TSet.mem",
"FStar.Monotonic.Heap.addr_of",
"FStar.Monotonic.Heap.contains",
"Prims.eq2",
"FStar.Monotonic.Heap.sel",
"FStar.Monotonic.Heap.unused_in",
"FStar.Monotonic.Heap.addr_unused_in",
"Prims.logical"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Monotonic.Heap
module S = FStar.Set
module TS = FStar.TSet
open FStar.Preorder
let set = Set.set
let tset = TSet.set
val heap :Type u#1
val equal: heap -> heap -> Type0
val equal_extensional (h1:heap) (h2:heap)
:Lemma (requires True) (ensures (equal h1 h2 <==> h1 == h2))
[SMTPat (equal h1 h2)]
val emp :heap
val next_addr: heap -> GTot pos
val core_mref ([@@@ strictly_positive] a:Type0) : Type0
let mref (a:Type0) (rel:preorder a) : Type0 = core_mref a
val addr_of: #a:Type0 -> #rel:preorder a -> mref a rel -> GTot pos
val is_mm: #a:Type0 -> #rel:preorder a -> mref a rel -> GTot bool
let compare_addrs (#a #b:Type0) (#rel1:preorder a) (#rel2:preorder b) (r1:mref a rel1) (r2:mref b rel2)
:GTot bool = addr_of r1 = addr_of r2
val contains: #a:Type0 -> #rel:preorder a -> heap -> mref a rel -> Type0
val addr_unused_in: nat -> heap -> Type0
val not_addr_unused_in_nullptr (h: heap) : Lemma (~ (addr_unused_in 0 h))
val unused_in: #a:Type0 -> #rel:preorder a -> mref a rel -> heap -> Type0
let fresh (#a:Type) (#rel:preorder a) (r:mref a rel) (h0:heap) (h1:heap) =
r `unused_in` h0 /\ h1 `contains` r
let only_t (#a:Type0) (#rel:preorder a) (x:mref a rel) :GTot (tset nat) = TS.singleton (addr_of x)
let only (#a:Type0) (#rel:preorder a) (x:mref a rel) :GTot (set nat) = S.singleton (addr_of x)
let op_Hat_Plus_Plus (#a:Type0) (#rel:preorder a) (r:mref a rel) (s:set nat) :GTot (set nat) = S.union (only r) s
let op_Plus_Plus_Hat (#a:Type0) (#rel:preorder a) (s:set nat) (r:mref a rel) :GTot (set nat) = S.union s (only r)
let op_Hat_Plus_Hat (#a:Type0) (#b:Type0) (#rel1:preorder a) (#rel2:preorder b) (r1:mref a rel1) (r2:mref b rel2)
:GTot (set nat) = S.union (only r1) (only r2)
val sel_tot: #a:Type0 -> #rel:preorder a -> h:heap -> r:mref a rel{h `contains` r} -> Tot a
val sel: #a:Type0 -> #rel:preorder a -> heap -> mref a rel -> GTot a
val upd_tot: #a:Type0 -> #rel:preorder a -> h:heap -> r:mref a rel{h `contains` r} -> x:a -> Tot heap
val upd: #a:Type0 -> #rel:preorder a -> h:heap -> r:mref a rel -> x:a -> GTot heap
val alloc: #a:Type0 -> rel:preorder a -> heap -> a -> mm:bool -> Tot (mref a rel * heap)
val free_mm: #a:Type0 -> #rel:preorder a -> h:heap -> r:mref a rel{h `contains` r /\ is_mm r} -> Tot heap | false | true | FStar.Monotonic.Heap.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val modifies_t : s: FStar.Monotonic.Heap.tset Prims.nat ->
h0: FStar.Monotonic.Heap.heap ->
h1: FStar.Monotonic.Heap.heap
-> Prims.logical | [] | FStar.Monotonic.Heap.modifies_t | {
"file_name": "ulib/FStar.Monotonic.Heap.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s: FStar.Monotonic.Heap.tset Prims.nat ->
h0: FStar.Monotonic.Heap.heap ->
h1: FStar.Monotonic.Heap.heap
-> Prims.logical | {
"end_col": 3,
"end_line": 92,
"start_col": 2,
"start_line": 84
} |
|
Prims.GTot | val op_Hat_Plus_Hat
(#a #b: Type0)
(#rel1: preorder a)
(#rel2: preorder b)
(r1: mref a rel1)
(r2: mref b rel2)
: GTot (set nat) | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let op_Hat_Plus_Hat (#a:Type0) (#b:Type0) (#rel1:preorder a) (#rel2:preorder b) (r1:mref a rel1) (r2:mref b rel2)
:GTot (set nat) = S.union (only r1) (only r2) | val op_Hat_Plus_Hat
(#a #b: Type0)
(#rel1: preorder a)
(#rel2: preorder b)
(r1: mref a rel1)
(r2: mref b rel2)
: GTot (set nat)
let op_Hat_Plus_Hat
(#a #b: Type0)
(#rel1: preorder a)
(#rel2: preorder b)
(r1: mref a rel1)
(r2: mref b rel2)
: GTot (set nat) = | false | null | false | S.union (only r1) (only r2) | {
"checked_file": "FStar.Monotonic.Heap.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Monotonic.Heap.fsti"
} | [
"sometrivial"
] | [
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.mref",
"FStar.Set.union",
"Prims.nat",
"FStar.Monotonic.Heap.only",
"FStar.Monotonic.Heap.set"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Monotonic.Heap
module S = FStar.Set
module TS = FStar.TSet
open FStar.Preorder
let set = Set.set
let tset = TSet.set
val heap :Type u#1
val equal: heap -> heap -> Type0
val equal_extensional (h1:heap) (h2:heap)
:Lemma (requires True) (ensures (equal h1 h2 <==> h1 == h2))
[SMTPat (equal h1 h2)]
val emp :heap
val next_addr: heap -> GTot pos
val core_mref ([@@@ strictly_positive] a:Type0) : Type0
let mref (a:Type0) (rel:preorder a) : Type0 = core_mref a
val addr_of: #a:Type0 -> #rel:preorder a -> mref a rel -> GTot pos
val is_mm: #a:Type0 -> #rel:preorder a -> mref a rel -> GTot bool
let compare_addrs (#a #b:Type0) (#rel1:preorder a) (#rel2:preorder b) (r1:mref a rel1) (r2:mref b rel2)
:GTot bool = addr_of r1 = addr_of r2
val contains: #a:Type0 -> #rel:preorder a -> heap -> mref a rel -> Type0
val addr_unused_in: nat -> heap -> Type0
val not_addr_unused_in_nullptr (h: heap) : Lemma (~ (addr_unused_in 0 h))
val unused_in: #a:Type0 -> #rel:preorder a -> mref a rel -> heap -> Type0
let fresh (#a:Type) (#rel:preorder a) (r:mref a rel) (h0:heap) (h1:heap) =
r `unused_in` h0 /\ h1 `contains` r
let only_t (#a:Type0) (#rel:preorder a) (x:mref a rel) :GTot (tset nat) = TS.singleton (addr_of x)
let only (#a:Type0) (#rel:preorder a) (x:mref a rel) :GTot (set nat) = S.singleton (addr_of x)
let op_Hat_Plus_Plus (#a:Type0) (#rel:preorder a) (r:mref a rel) (s:set nat) :GTot (set nat) = S.union (only r) s
let op_Plus_Plus_Hat (#a:Type0) (#rel:preorder a) (s:set nat) (r:mref a rel) :GTot (set nat) = S.union s (only r) | false | false | FStar.Monotonic.Heap.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val op_Hat_Plus_Hat
(#a #b: Type0)
(#rel1: preorder a)
(#rel2: preorder b)
(r1: mref a rel1)
(r2: mref b rel2)
: GTot (set nat) | [] | FStar.Monotonic.Heap.op_Hat_Plus_Hat | {
"file_name": "ulib/FStar.Monotonic.Heap.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | r1: FStar.Monotonic.Heap.mref a rel1 -> r2: FStar.Monotonic.Heap.mref b rel2
-> Prims.GTot (FStar.Monotonic.Heap.set Prims.nat) | {
"end_col": 47,
"end_line": 69,
"start_col": 20,
"start_line": 69
} |
Prims.GTot | val only (#a: Type0) (#rel: preorder a) (x: mref a rel) : GTot (set nat) | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let only (#a:Type0) (#rel:preorder a) (x:mref a rel) :GTot (set nat) = S.singleton (addr_of x) | val only (#a: Type0) (#rel: preorder a) (x: mref a rel) : GTot (set nat)
let only (#a: Type0) (#rel: preorder a) (x: mref a rel) : GTot (set nat) = | false | null | false | S.singleton (addr_of x) | {
"checked_file": "FStar.Monotonic.Heap.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Monotonic.Heap.fsti"
} | [
"sometrivial"
] | [
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.mref",
"FStar.Set.singleton",
"Prims.nat",
"FStar.Monotonic.Heap.addr_of",
"FStar.Monotonic.Heap.set"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Monotonic.Heap
module S = FStar.Set
module TS = FStar.TSet
open FStar.Preorder
let set = Set.set
let tset = TSet.set
val heap :Type u#1
val equal: heap -> heap -> Type0
val equal_extensional (h1:heap) (h2:heap)
:Lemma (requires True) (ensures (equal h1 h2 <==> h1 == h2))
[SMTPat (equal h1 h2)]
val emp :heap
val next_addr: heap -> GTot pos
val core_mref ([@@@ strictly_positive] a:Type0) : Type0
let mref (a:Type0) (rel:preorder a) : Type0 = core_mref a
val addr_of: #a:Type0 -> #rel:preorder a -> mref a rel -> GTot pos
val is_mm: #a:Type0 -> #rel:preorder a -> mref a rel -> GTot bool
let compare_addrs (#a #b:Type0) (#rel1:preorder a) (#rel2:preorder b) (r1:mref a rel1) (r2:mref b rel2)
:GTot bool = addr_of r1 = addr_of r2
val contains: #a:Type0 -> #rel:preorder a -> heap -> mref a rel -> Type0
val addr_unused_in: nat -> heap -> Type0
val not_addr_unused_in_nullptr (h: heap) : Lemma (~ (addr_unused_in 0 h))
val unused_in: #a:Type0 -> #rel:preorder a -> mref a rel -> heap -> Type0
let fresh (#a:Type) (#rel:preorder a) (r:mref a rel) (h0:heap) (h1:heap) =
r `unused_in` h0 /\ h1 `contains` r
let only_t (#a:Type0) (#rel:preorder a) (x:mref a rel) :GTot (tset nat) = TS.singleton (addr_of x) | false | false | FStar.Monotonic.Heap.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val only (#a: Type0) (#rel: preorder a) (x: mref a rel) : GTot (set nat) | [] | FStar.Monotonic.Heap.only | {
"file_name": "ulib/FStar.Monotonic.Heap.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: FStar.Monotonic.Heap.mref a rel -> Prims.GTot (FStar.Monotonic.Heap.set Prims.nat) | {
"end_col": 94,
"end_line": 62,
"start_col": 71,
"start_line": 62
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let modifies (s:set nat) (h0:heap) (h1:heap) = modifies_t (TS.tset_of_set s) h0 h1 | let modifies (s: set nat) (h0 h1: heap) = | false | null | false | modifies_t (TS.tset_of_set s) h0 h1 | {
"checked_file": "FStar.Monotonic.Heap.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Monotonic.Heap.fsti"
} | [
"total"
] | [
"FStar.Monotonic.Heap.set",
"Prims.nat",
"FStar.Monotonic.Heap.heap",
"FStar.Monotonic.Heap.modifies_t",
"FStar.TSet.tset_of_set",
"Prims.logical"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Monotonic.Heap
module S = FStar.Set
module TS = FStar.TSet
open FStar.Preorder
let set = Set.set
let tset = TSet.set
val heap :Type u#1
val equal: heap -> heap -> Type0
val equal_extensional (h1:heap) (h2:heap)
:Lemma (requires True) (ensures (equal h1 h2 <==> h1 == h2))
[SMTPat (equal h1 h2)]
val emp :heap
val next_addr: heap -> GTot pos
val core_mref ([@@@ strictly_positive] a:Type0) : Type0
let mref (a:Type0) (rel:preorder a) : Type0 = core_mref a
val addr_of: #a:Type0 -> #rel:preorder a -> mref a rel -> GTot pos
val is_mm: #a:Type0 -> #rel:preorder a -> mref a rel -> GTot bool
let compare_addrs (#a #b:Type0) (#rel1:preorder a) (#rel2:preorder b) (r1:mref a rel1) (r2:mref b rel2)
:GTot bool = addr_of r1 = addr_of r2
val contains: #a:Type0 -> #rel:preorder a -> heap -> mref a rel -> Type0
val addr_unused_in: nat -> heap -> Type0
val not_addr_unused_in_nullptr (h: heap) : Lemma (~ (addr_unused_in 0 h))
val unused_in: #a:Type0 -> #rel:preorder a -> mref a rel -> heap -> Type0
let fresh (#a:Type) (#rel:preorder a) (r:mref a rel) (h0:heap) (h1:heap) =
r `unused_in` h0 /\ h1 `contains` r
let only_t (#a:Type0) (#rel:preorder a) (x:mref a rel) :GTot (tset nat) = TS.singleton (addr_of x)
let only (#a:Type0) (#rel:preorder a) (x:mref a rel) :GTot (set nat) = S.singleton (addr_of x)
let op_Hat_Plus_Plus (#a:Type0) (#rel:preorder a) (r:mref a rel) (s:set nat) :GTot (set nat) = S.union (only r) s
let op_Plus_Plus_Hat (#a:Type0) (#rel:preorder a) (s:set nat) (r:mref a rel) :GTot (set nat) = S.union s (only r)
let op_Hat_Plus_Hat (#a:Type0) (#b:Type0) (#rel1:preorder a) (#rel2:preorder b) (r1:mref a rel1) (r2:mref b rel2)
:GTot (set nat) = S.union (only r1) (only r2)
val sel_tot: #a:Type0 -> #rel:preorder a -> h:heap -> r:mref a rel{h `contains` r} -> Tot a
val sel: #a:Type0 -> #rel:preorder a -> heap -> mref a rel -> GTot a
val upd_tot: #a:Type0 -> #rel:preorder a -> h:heap -> r:mref a rel{h `contains` r} -> x:a -> Tot heap
val upd: #a:Type0 -> #rel:preorder a -> h:heap -> r:mref a rel -> x:a -> GTot heap
val alloc: #a:Type0 -> rel:preorder a -> heap -> a -> mm:bool -> Tot (mref a rel * heap)
val free_mm: #a:Type0 -> #rel:preorder a -> h:heap -> r:mref a rel{h `contains` r /\ is_mm r} -> Tot heap
let modifies_t (s:tset nat) (h0:heap) (h1:heap) =
(forall (a:Type) (rel:preorder a) (r:mref a rel).{:pattern (sel h1 r)}
((~ (TS.mem (addr_of r) s)) /\ h0 `contains` r) ==> sel h1 r == sel h0 r) /\
(forall (a:Type) (rel:preorder a) (r:mref a rel).{:pattern (contains h1 r)}
h0 `contains` r ==> h1 `contains` r) /\
(forall (a:Type) (rel:preorder a) (r:mref a rel).{:pattern (r `unused_in` h0)}
r `unused_in` h1 ==> r `unused_in` h0) /\
(forall (n: nat) . {:pattern (n `addr_unused_in` h0) }
n `addr_unused_in` h1 ==> n `addr_unused_in` h0
) | false | true | FStar.Monotonic.Heap.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val modifies : s: FStar.Monotonic.Heap.set Prims.nat ->
h0: FStar.Monotonic.Heap.heap ->
h1: FStar.Monotonic.Heap.heap
-> Prims.logical | [] | FStar.Monotonic.Heap.modifies | {
"file_name": "ulib/FStar.Monotonic.Heap.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s: FStar.Monotonic.Heap.set Prims.nat ->
h0: FStar.Monotonic.Heap.heap ->
h1: FStar.Monotonic.Heap.heap
-> Prims.logical | {
"end_col": 82,
"end_line": 95,
"start_col": 47,
"start_line": 95
} |
|
Prims.GTot | val op_Hat_Plus_Plus (#a: Type0) (#rel: preorder a) (r: mref a rel) (s: set nat) : GTot (set nat) | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let op_Hat_Plus_Plus (#a:Type0) (#rel:preorder a) (r:mref a rel) (s:set nat) :GTot (set nat) = S.union (only r) s | val op_Hat_Plus_Plus (#a: Type0) (#rel: preorder a) (r: mref a rel) (s: set nat) : GTot (set nat)
let op_Hat_Plus_Plus (#a: Type0) (#rel: preorder a) (r: mref a rel) (s: set nat) : GTot (set nat) = | false | null | false | S.union (only r) s | {
"checked_file": "FStar.Monotonic.Heap.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Monotonic.Heap.fsti"
} | [
"sometrivial"
] | [
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.mref",
"FStar.Monotonic.Heap.set",
"Prims.nat",
"FStar.Set.union",
"FStar.Monotonic.Heap.only"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Monotonic.Heap
module S = FStar.Set
module TS = FStar.TSet
open FStar.Preorder
let set = Set.set
let tset = TSet.set
val heap :Type u#1
val equal: heap -> heap -> Type0
val equal_extensional (h1:heap) (h2:heap)
:Lemma (requires True) (ensures (equal h1 h2 <==> h1 == h2))
[SMTPat (equal h1 h2)]
val emp :heap
val next_addr: heap -> GTot pos
val core_mref ([@@@ strictly_positive] a:Type0) : Type0
let mref (a:Type0) (rel:preorder a) : Type0 = core_mref a
val addr_of: #a:Type0 -> #rel:preorder a -> mref a rel -> GTot pos
val is_mm: #a:Type0 -> #rel:preorder a -> mref a rel -> GTot bool
let compare_addrs (#a #b:Type0) (#rel1:preorder a) (#rel2:preorder b) (r1:mref a rel1) (r2:mref b rel2)
:GTot bool = addr_of r1 = addr_of r2
val contains: #a:Type0 -> #rel:preorder a -> heap -> mref a rel -> Type0
val addr_unused_in: nat -> heap -> Type0
val not_addr_unused_in_nullptr (h: heap) : Lemma (~ (addr_unused_in 0 h))
val unused_in: #a:Type0 -> #rel:preorder a -> mref a rel -> heap -> Type0
let fresh (#a:Type) (#rel:preorder a) (r:mref a rel) (h0:heap) (h1:heap) =
r `unused_in` h0 /\ h1 `contains` r
let only_t (#a:Type0) (#rel:preorder a) (x:mref a rel) :GTot (tset nat) = TS.singleton (addr_of x)
let only (#a:Type0) (#rel:preorder a) (x:mref a rel) :GTot (set nat) = S.singleton (addr_of x) | false | false | FStar.Monotonic.Heap.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val op_Hat_Plus_Plus (#a: Type0) (#rel: preorder a) (r: mref a rel) (s: set nat) : GTot (set nat) | [] | FStar.Monotonic.Heap.op_Hat_Plus_Plus | {
"file_name": "ulib/FStar.Monotonic.Heap.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | r: FStar.Monotonic.Heap.mref a rel -> s: FStar.Monotonic.Heap.set Prims.nat
-> Prims.GTot (FStar.Monotonic.Heap.set Prims.nat) | {
"end_col": 113,
"end_line": 64,
"start_col": 95,
"start_line": 64
} |
Prims.GTot | val op_Plus_Plus_Hat (#a: Type0) (#rel: preorder a) (s: set nat) (r: mref a rel) : GTot (set nat) | [
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.TSet",
"short_module": "TS"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let op_Plus_Plus_Hat (#a:Type0) (#rel:preorder a) (s:set nat) (r:mref a rel) :GTot (set nat) = S.union s (only r) | val op_Plus_Plus_Hat (#a: Type0) (#rel: preorder a) (s: set nat) (r: mref a rel) : GTot (set nat)
let op_Plus_Plus_Hat (#a: Type0) (#rel: preorder a) (s: set nat) (r: mref a rel) : GTot (set nat) = | false | null | false | S.union s (only r) | {
"checked_file": "FStar.Monotonic.Heap.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Monotonic.Heap.fsti"
} | [
"sometrivial"
] | [
"FStar.Preorder.preorder",
"FStar.Monotonic.Heap.set",
"Prims.nat",
"FStar.Monotonic.Heap.mref",
"FStar.Set.union",
"FStar.Monotonic.Heap.only"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Monotonic.Heap
module S = FStar.Set
module TS = FStar.TSet
open FStar.Preorder
let set = Set.set
let tset = TSet.set
val heap :Type u#1
val equal: heap -> heap -> Type0
val equal_extensional (h1:heap) (h2:heap)
:Lemma (requires True) (ensures (equal h1 h2 <==> h1 == h2))
[SMTPat (equal h1 h2)]
val emp :heap
val next_addr: heap -> GTot pos
val core_mref ([@@@ strictly_positive] a:Type0) : Type0
let mref (a:Type0) (rel:preorder a) : Type0 = core_mref a
val addr_of: #a:Type0 -> #rel:preorder a -> mref a rel -> GTot pos
val is_mm: #a:Type0 -> #rel:preorder a -> mref a rel -> GTot bool
let compare_addrs (#a #b:Type0) (#rel1:preorder a) (#rel2:preorder b) (r1:mref a rel1) (r2:mref b rel2)
:GTot bool = addr_of r1 = addr_of r2
val contains: #a:Type0 -> #rel:preorder a -> heap -> mref a rel -> Type0
val addr_unused_in: nat -> heap -> Type0
val not_addr_unused_in_nullptr (h: heap) : Lemma (~ (addr_unused_in 0 h))
val unused_in: #a:Type0 -> #rel:preorder a -> mref a rel -> heap -> Type0
let fresh (#a:Type) (#rel:preorder a) (r:mref a rel) (h0:heap) (h1:heap) =
r `unused_in` h0 /\ h1 `contains` r
let only_t (#a:Type0) (#rel:preorder a) (x:mref a rel) :GTot (tset nat) = TS.singleton (addr_of x)
let only (#a:Type0) (#rel:preorder a) (x:mref a rel) :GTot (set nat) = S.singleton (addr_of x)
let op_Hat_Plus_Plus (#a:Type0) (#rel:preorder a) (r:mref a rel) (s:set nat) :GTot (set nat) = S.union (only r) s | false | false | FStar.Monotonic.Heap.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val op_Plus_Plus_Hat (#a: Type0) (#rel: preorder a) (s: set nat) (r: mref a rel) : GTot (set nat) | [] | FStar.Monotonic.Heap.op_Plus_Plus_Hat | {
"file_name": "ulib/FStar.Monotonic.Heap.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Monotonic.Heap.set Prims.nat -> r: FStar.Monotonic.Heap.mref a rel
-> Prims.GTot (FStar.Monotonic.Heap.set Prims.nat) | {
"end_col": 113,
"end_line": 66,
"start_col": 95,
"start_line": 66
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "Spec.Hash.Incremental.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Blake2",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.UpdateMulti",
"short_module": "UpdateMulti"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Blake2",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Spec.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let hash_is_hash_incremental (a: fixed_len_alg) (input: bytes { S.length input `less_than_max_input_length` a }) =
hash_is_hash_incremental' a input () | let hash_is_hash_incremental
(a: fixed_len_alg)
(input: bytes{(S.length input) `less_than_max_input_length` a})
= | false | null | false | hash_is_hash_incremental' a input () | {
"checked_file": "Spec.Hash.Incremental.fsti.checked",
"dependencies": [
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Hash.Incremental.fsti"
} | [
"total"
] | [
"Spec.Hash.Definitions.fixed_len_alg",
"Lib.ByteSequence.bytes",
"Prims.b2t",
"Spec.Hash.Definitions.less_than_max_input_length",
"FStar.Seq.Base.length",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Spec.Hash.Incremental.hash_is_hash_incremental'",
"Prims.unit"
] | [] | module Spec.Hash.Incremental
module S = FStar.Seq
module Blake2 = Spec.Blake2
open Spec.Agile.Hash
open Spec.Hash.Definitions
open FStar.Mul
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntTypes
module Loops = Lib.LoopCombinators
module UpdateMulti = Lib.UpdateMulti
#set-options "--fuel 0 --ifuel 0 --z3rlimit 50"
/// A declaration whose sole purpose is to force synchronize the .fst and the .fsti
[@must_erase_for_extraction]
private val _sync_decl : Type0
include Spec.Hash.Incremental.Definitions
val hash_is_hash_incremental' (a: hash_alg) (input: bytes { S.length input `less_than_max_input_length` a })
(l: output_length a):
Lemma (S.equal (hash' a input l) (hash_incremental a input l))
unfold | false | false | Spec.Hash.Incremental.fsti | {
"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"
} | null | val hash_is_hash_incremental : a: Spec.Hash.Definitions.fixed_len_alg ->
input:
Lib.ByteSequence.bytes
{Spec.Hash.Definitions.less_than_max_input_length (FStar.Seq.Base.length input) a}
-> Prims.unit | [] | Spec.Hash.Incremental.hash_is_hash_incremental | {
"file_name": "specs/lemmas/Spec.Hash.Incremental.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Spec.Hash.Definitions.fixed_len_alg ->
input:
Lib.ByteSequence.bytes
{Spec.Hash.Definitions.less_than_max_input_length (FStar.Seq.Base.length input) a}
-> Prims.unit | {
"end_col": 38,
"end_line": 31,
"start_col": 2,
"start_line": 31
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let scalarmult_st (s:field_spec) (p: Type0) =
o:lbuffer uint8 32ul
-> k:lbuffer uint8 32ul
-> i:lbuffer uint8 32ul
-> Stack unit
(requires fun h0 ->
p /\
live h0 o /\ live h0 k /\ live h0 i /\
disjoint o i /\ disjoint o k)
(ensures fun h0 _ h1 -> modifies (loc o) h0 h1 /\
as_seq h1 o == S.scalarmult (as_seq h0 k) (as_seq h0 i)) | let scalarmult_st (s: field_spec) (p: Type0) = | false | null | false | o: lbuffer uint8 32ul -> k: lbuffer uint8 32ul -> i: lbuffer uint8 32ul
-> Stack unit
(requires fun h0 -> p /\ live h0 o /\ live h0 k /\ live h0 i /\ disjoint o i /\ disjoint o k)
(ensures
fun h0 _ h1 ->
modifies (loc o) h0 h1 /\ as_seq h1 o == S.scalarmult (as_seq h0 k) (as_seq h0 i)) | {
"checked_file": "Hacl.Impl.Curve25519.Generic.fsti.checked",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Curve25519.Fields.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Curve25519.Generic.fsti"
} | [
"total"
] | [
"Hacl.Impl.Curve25519.Fields.Core.field_spec",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Lib.Buffer.disjoint",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Prims.eq2",
"Lib.Sequence.lseq",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Buffer.as_seq",
"Spec.Curve25519.scalarmult"
] | [] | module Hacl.Impl.Curve25519.Generic
open FStar.HyperStack
open FStar.HyperStack.All
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.Curve25519.Fields
module S = Spec.Curve25519
inline_for_extraction noextract | false | true | Hacl.Impl.Curve25519.Generic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val scalarmult_st : s: Hacl.Impl.Curve25519.Fields.Core.field_spec -> p: Type0 -> Type0 | [] | Hacl.Impl.Curve25519.Generic.scalarmult_st | {
"file_name": "code/curve25519/Hacl.Impl.Curve25519.Generic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | s: Hacl.Impl.Curve25519.Fields.Core.field_spec -> p: Type0 -> Type0 | {
"end_col": 62,
"end_line": 23,
"start_col": 4,
"start_line": 14
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let secret_to_public_st (s: field_spec) (p: Type0) =
o:lbuffer uint8 32ul
-> i:lbuffer uint8 32ul
-> Stack unit
(requires fun h0 ->
p /\
live h0 o /\ live h0 i /\ disjoint o i)
(ensures fun h0 _ h1 -> modifies (loc o) h0 h1 /\
as_seq h1 o == S.secret_to_public (as_seq h0 i)) | let secret_to_public_st (s: field_spec) (p: Type0) = | false | null | false | o: lbuffer uint8 32ul -> i: lbuffer uint8 32ul
-> Stack unit
(requires fun h0 -> p /\ live h0 o /\ live h0 i /\ disjoint o i)
(ensures
fun h0 _ h1 -> modifies (loc o) h0 h1 /\ as_seq h1 o == S.secret_to_public (as_seq h0 i)) | {
"checked_file": "Hacl.Impl.Curve25519.Generic.fsti.checked",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Curve25519.Fields.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Curve25519.Generic.fsti"
} | [
"total"
] | [
"Hacl.Impl.Curve25519.Fields.Core.field_spec",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Lib.Buffer.disjoint",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Prims.eq2",
"Lib.Sequence.lseq",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Buffer.as_seq",
"Spec.Curve25519.secret_to_public"
] | [] | module Hacl.Impl.Curve25519.Generic
open FStar.HyperStack
open FStar.HyperStack.All
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.Curve25519.Fields
module S = Spec.Curve25519
inline_for_extraction noextract
let scalarmult_st (s:field_spec) (p: Type0) =
o:lbuffer uint8 32ul
-> k:lbuffer uint8 32ul
-> i:lbuffer uint8 32ul
-> Stack unit
(requires fun h0 ->
p /\
live h0 o /\ live h0 k /\ live h0 i /\
disjoint o i /\ disjoint o k)
(ensures fun h0 _ h1 -> modifies (loc o) h0 h1 /\
as_seq h1 o == S.scalarmult (as_seq h0 k) (as_seq h0 i))
inline_for_extraction noextract | false | true | Hacl.Impl.Curve25519.Generic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val secret_to_public_st : s: Hacl.Impl.Curve25519.Fields.Core.field_spec -> p: Type0 -> Type0 | [] | Hacl.Impl.Curve25519.Generic.secret_to_public_st | {
"file_name": "code/curve25519/Hacl.Impl.Curve25519.Generic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | s: Hacl.Impl.Curve25519.Fields.Core.field_spec -> p: Type0 -> Type0 | {
"end_col": 54,
"end_line": 34,
"start_col": 4,
"start_line": 27
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ecdh_st (s:field_spec) (p: Type0) =
o:lbuffer uint8 32ul
-> k:lbuffer uint8 32ul
-> i:lbuffer uint8 32ul
-> Stack bool
(requires fun h0 ->
p /\
live h0 o /\ live h0 k /\ live h0 i /\
disjoint o i /\ disjoint o k)
(ensures fun h0 r h1 -> modifies (loc o) h0 h1 /\
as_seq h1 o == S.scalarmult (as_seq h0 k) (as_seq h0 i)
/\ (not r == Lib.ByteSequence.lbytes_eq #32 (as_seq h1 o) (Lib.Sequence.create 32 (u8 0)))) | let ecdh_st (s: field_spec) (p: Type0) = | false | null | false | o: lbuffer uint8 32ul -> k: lbuffer uint8 32ul -> i: lbuffer uint8 32ul
-> Stack bool
(requires fun h0 -> p /\ live h0 o /\ live h0 k /\ live h0 i /\ disjoint o i /\ disjoint o k)
(ensures
fun h0 r h1 ->
modifies (loc o) h0 h1 /\ as_seq h1 o == S.scalarmult (as_seq h0 k) (as_seq h0 i) /\
(not r == Lib.ByteSequence.lbytes_eq #32 (as_seq h1 o) (Lib.Sequence.create 32 (u8 0)))) | {
"checked_file": "Hacl.Impl.Curve25519.Generic.fsti.checked",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Curve25519.Fields.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Curve25519.Generic.fsti"
} | [
"total"
] | [
"Hacl.Impl.Curve25519.Fields.Core.field_spec",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Prims.bool",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Lib.Buffer.disjoint",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Prims.eq2",
"Lib.Sequence.lseq",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Buffer.as_seq",
"Spec.Curve25519.scalarmult",
"Prims.op_Negation",
"Lib.ByteSequence.lbytes_eq",
"Lib.Sequence.create",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.IntTypes.u8"
] | [] | module Hacl.Impl.Curve25519.Generic
open FStar.HyperStack
open FStar.HyperStack.All
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.Curve25519.Fields
module S = Spec.Curve25519
inline_for_extraction noextract
let scalarmult_st (s:field_spec) (p: Type0) =
o:lbuffer uint8 32ul
-> k:lbuffer uint8 32ul
-> i:lbuffer uint8 32ul
-> Stack unit
(requires fun h0 ->
p /\
live h0 o /\ live h0 k /\ live h0 i /\
disjoint o i /\ disjoint o k)
(ensures fun h0 _ h1 -> modifies (loc o) h0 h1 /\
as_seq h1 o == S.scalarmult (as_seq h0 k) (as_seq h0 i))
inline_for_extraction noextract
let secret_to_public_st (s: field_spec) (p: Type0) =
o:lbuffer uint8 32ul
-> i:lbuffer uint8 32ul
-> Stack unit
(requires fun h0 ->
p /\
live h0 o /\ live h0 i /\ disjoint o i)
(ensures fun h0 _ h1 -> modifies (loc o) h0 h1 /\
as_seq h1 o == S.secret_to_public (as_seq h0 i))
inline_for_extraction noextract | false | true | Hacl.Impl.Curve25519.Generic.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ecdh_st : s: Hacl.Impl.Curve25519.Fields.Core.field_spec -> p: Type0 -> Type0 | [] | Hacl.Impl.Curve25519.Generic.ecdh_st | {
"file_name": "code/curve25519/Hacl.Impl.Curve25519.Generic.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | s: Hacl.Impl.Curve25519.Fields.Core.field_spec -> p: Type0 -> Type0 | {
"end_col": 97,
"end_line": 48,
"start_col": 4,
"start_line": 38
} |
|
FStar.HyperStack.ST.Stack | val while:
inv: (mem -> Type0)
-> guard: (h:mem{inv h} -> GTot bool)
-> test: (unit -> Stack bool
(requires inv)
(ensures fun h0 b h1 -> b == guard h0 /\ h0 == h1))
-> body: (unit -> Stack unit
(requires fun h -> inv h /\ guard h)
(ensures fun _ _ h -> inv h))
-> Stack unit
(requires inv)
(ensures fun _ _ h -> inv h /\ ~(guard h)) | [
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"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": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let while inv guard test body =
let test: unit -> Stack bool
(requires fun h -> inv h) //AR: C.Loops.while precondition is written in eta-expanded form
(ensures fun _ b h -> inv h /\ b == guard h)
= test
in
C.Loops.while #inv #(fun b h -> inv h /\ b == guard h) test body | val while:
inv: (mem -> Type0)
-> guard: (h:mem{inv h} -> GTot bool)
-> test: (unit -> Stack bool
(requires inv)
(ensures fun h0 b h1 -> b == guard h0 /\ h0 == h1))
-> body: (unit -> Stack unit
(requires fun h -> inv h /\ guard h)
(ensures fun _ _ h -> inv h))
-> Stack unit
(requires inv)
(ensures fun _ _ h -> inv h /\ ~(guard h))
let while inv guard test body = | true | null | false | let test: unit -> Stack bool (requires fun h -> inv h) (ensures fun _ b h -> inv h /\ b == guard h)
=
test
in
C.Loops.while #inv #(fun b h -> inv h /\ b == guard h) test body | {
"checked_file": "Lib.Loops.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": true,
"source_file": "Lib.Loops.fst"
} | [] | [
"FStar.Monotonic.HyperStack.mem",
"Prims.bool",
"Prims.unit",
"Prims.l_and",
"Prims.eq2",
"Prims.b2t",
"C.Loops.while"
] | [] | module Lib.Loops
open Lib.IntTypes
let for start finish inv f =
C.Loops.for
start
finish
(fun h i -> v start <= i /\ i <= v finish /\ inv h i)
(fun i -> f i) | false | false | Lib.Loops.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val while:
inv: (mem -> Type0)
-> guard: (h:mem{inv h} -> GTot bool)
-> test: (unit -> Stack bool
(requires inv)
(ensures fun h0 b h1 -> b == guard h0 /\ h0 == h1))
-> body: (unit -> Stack unit
(requires fun h -> inv h /\ guard h)
(ensures fun _ _ h -> inv h))
-> Stack unit
(requires inv)
(ensures fun _ _ h -> inv h /\ ~(guard h)) | [] | Lib.Loops.while | {
"file_name": "lib/Lib.Loops.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
inv: (_: FStar.Monotonic.HyperStack.mem -> Type0) ->
guard: (h: FStar.Monotonic.HyperStack.mem{inv h} -> Prims.GTot Prims.bool) ->
test: (_: Prims.unit -> FStar.HyperStack.ST.Stack Prims.bool) ->
body: (_: Prims.unit -> FStar.HyperStack.ST.Stack Prims.unit)
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 66,
"end_line": 18,
"start_col": 31,
"start_line": 12
} |
FStar.HyperStack.ST.Stack | val for:
start:size_t
-> finish:size_t{v finish >= v start}
-> inv:(mem -> (i:nat{v start <= i /\ i <= v finish}) -> Type0)
-> f:(i:size_t{v start <= v i /\ v i < v finish} -> Stack unit
(requires fun h -> inv h (v i))
(ensures fun h_1 _ h_2 -> inv h_2 (v i + 1))) ->
Stack unit
(requires fun h -> inv h (v start))
(ensures fun _ _ h_2 -> inv h_2 (v finish)) | [
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"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": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let for start finish inv f =
C.Loops.for
start
finish
(fun h i -> v start <= i /\ i <= v finish /\ inv h i)
(fun i -> f i) | val for:
start:size_t
-> finish:size_t{v finish >= v start}
-> inv:(mem -> (i:nat{v start <= i /\ i <= v finish}) -> Type0)
-> f:(i:size_t{v start <= v i /\ v i < v finish} -> Stack unit
(requires fun h -> inv h (v i))
(ensures fun h_1 _ h_2 -> inv h_2 (v i + 1))) ->
Stack unit
(requires fun h -> inv h (v start))
(ensures fun _ _ h_2 -> inv h_2 (v finish))
let for start finish inv f = | true | null | false | C.Loops.for start finish (fun h i -> v start <= i /\ i <= v finish /\ inv h i) (fun i -> f i) | {
"checked_file": "Lib.Loops.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": true,
"source_file": "Lib.Loops.fst"
} | [] | [
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"FStar.Monotonic.HyperStack.mem",
"Prims.nat",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.unit",
"Prims.op_Addition",
"C.Loops.for",
"FStar.UInt32.t",
"FStar.UInt32.v"
] | [] | module Lib.Loops
open Lib.IntTypes | false | false | Lib.Loops.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val for:
start:size_t
-> finish:size_t{v finish >= v start}
-> inv:(mem -> (i:nat{v start <= i /\ i <= v finish}) -> Type0)
-> f:(i:size_t{v start <= v i /\ v i < v finish} -> Stack unit
(requires fun h -> inv h (v i))
(ensures fun h_1 _ h_2 -> inv h_2 (v i + 1))) ->
Stack unit
(requires fun h -> inv h (v start))
(ensures fun _ _ h_2 -> inv h_2 (v finish)) | [] | Lib.Loops.for | {
"file_name": "lib/Lib.Loops.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
start: Lib.IntTypes.size_t ->
finish: Lib.IntTypes.size_t{Lib.IntTypes.v finish >= Lib.IntTypes.v start} ->
inv:
(
_: FStar.Monotonic.HyperStack.mem ->
i: Prims.nat{Lib.IntTypes.v start <= i /\ i <= Lib.IntTypes.v finish}
-> Type0) ->
f:
(
i:
Lib.IntTypes.size_t
{ Lib.IntTypes.v start <= Lib.IntTypes.v i /\
Lib.IntTypes.v i < Lib.IntTypes.v finish }
-> FStar.HyperStack.ST.Stack Prims.unit)
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 18,
"end_line": 10,
"start_col": 2,
"start_line": 6
} |
FStar.HyperStack.ST.Stack | val square_while: unit -> Stack UInt32.t (fun _ -> true) (fun h0 x h1 -> x == 9ul) | [
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"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": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let square_while () =
let open LowStar.Buffer in
let open LowStar.BufferOps in
let open FStar.UInt32 in
push_frame();
let l = [ 1ul; 2ul; 3ul ] in
let b = alloca_of_list l in
let r = alloca 0ul 1ul in
let h = HyperStack.ST.get() in
assert (forall i. Seq.index (Seq.seq_of_list l) i == List.Tot.index l i);
let h0 = HyperStack.ST.get () in
let inv h = live h b /\ live h r /\
get h r 0 <=^ 3ul /\
(forall (i:nat{i < 3}). i < v (get h r 0) ==> get h b i == get h0 b i *^ get h0 b i) /\
(forall (i:nat{i < 3}). v (get h r 0) <= i ==> get h b i == get h0 b i)
in
let guard h = get h r 0 <^ 3ul in
while inv guard (fun () -> !*r <^ 3ul) (fun () ->
b.(!*r) <- b.(!*r) *^ b.(!*r);
r.(0ul) <- !*r +^ 1ul
);
let x = b.(2ul) in
pop_frame();
x | val square_while: unit -> Stack UInt32.t (fun _ -> true) (fun h0 x h1 -> x == 9ul)
let square_while () = | true | null | false | let open LowStar.Buffer in
let open LowStar.BufferOps in
let open FStar.UInt32 in
push_frame ();
let l = [1ul; 2ul; 3ul] in
let b = alloca_of_list l in
let r = alloca 0ul 1ul in
let h = HyperStack.ST.get () in
assert (forall i. Seq.index (Seq.seq_of_list l) i == List.Tot.index l i);
let h0 = HyperStack.ST.get () in
let inv h =
live h b /\ live h r /\ get h r 0 <=^ 3ul /\
(forall (i: nat{i < 3}). i < v (get h r 0) ==> get h b i == get h0 b i *^ get h0 b i) /\
(forall (i: nat{i < 3}). v (get h r 0) <= i ==> get h b i == get h0 b i)
in
let guard h = get h r 0 <^ 3ul in
while inv
guard
(fun () -> !*r <^ 3ul)
(fun () ->
b.(!*r) <- b.(!*r) *^ b.(!*r);
r.(0ul) <- !*r +^ 1ul);
let x = b.(2ul) in
pop_frame ();
x | {
"checked_file": "Lib.Loops.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": true,
"source_file": "Lib.Loops.fst"
} | [] | [
"Prims.unit",
"FStar.UInt32.t",
"FStar.HyperStack.ST.pop_frame",
"LowStar.BufferOps.op_Array_Access",
"LowStar.Buffer.trivial_preorder",
"FStar.UInt32.__uint_to_t",
"Lib.Loops.while",
"FStar.UInt32.op_Less_Hat",
"Prims.bool",
"LowStar.BufferOps.op_Bang_Star",
"LowStar.BufferOps.op_Array_Assignment",
"FStar.UInt32.op_Plus_Hat",
"FStar.UInt32.op_Star_Hat",
"FStar.Monotonic.HyperStack.mem",
"LowStar.Monotonic.Buffer.get",
"Prims.logical",
"Prims.l_and",
"LowStar.Monotonic.Buffer.live",
"Prims.b2t",
"FStar.UInt32.op_Less_Equals_Hat",
"Prims.l_Forall",
"Prims.nat",
"Prims.op_LessThan",
"Prims.l_imp",
"FStar.UInt32.v",
"Prims.eq2",
"Prims.op_LessThanOrEqual",
"FStar.HyperStack.ST.get",
"Prims._assert",
"FStar.Seq.Base.length",
"FStar.Seq.Properties.seq_of_list",
"FStar.List.Tot.Base.length",
"FStar.Seq.Base.index",
"FStar.List.Tot.Base.index",
"LowStar.Monotonic.Buffer.mbuffer",
"LowStar.Monotonic.Buffer.length",
"FStar.UInt32.uint_to_t",
"Prims.op_Negation",
"LowStar.Monotonic.Buffer.g_is_null",
"LowStar.Buffer.alloca",
"FStar.Pervasives.normalize_term",
"LowStar.Buffer.alloca_of_list",
"Prims.list",
"Prims.Cons",
"Prims.Nil",
"FStar.HyperStack.ST.push_frame"
] | [] | module Lib.Loops
open Lib.IntTypes
let for start finish inv f =
C.Loops.for
start
finish
(fun h i -> v start <= i /\ i <= v finish /\ inv h i)
(fun i -> f i)
let while inv guard test body =
let test: unit -> Stack bool
(requires fun h -> inv h) //AR: C.Loops.while precondition is written in eta-expanded form
(ensures fun _ b h -> inv h /\ b == guard h)
= test
in
C.Loops.while #inv #(fun b h -> inv h /\ b == guard h) test body
/// Test
#set-options "--max_fuel 3 --max_ifuel 0 --z3rlimit 50"
val square_while: unit -> Stack UInt32.t (fun _ -> true) (fun h0 x h1 -> x == 9ul) | false | false | Lib.Loops.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 3,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val square_while: unit -> Stack UInt32.t (fun _ -> true) (fun h0 x h1 -> x == 9ul) | [] | Lib.Loops.square_while | {
"file_name": "lib/Lib.Loops.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: Prims.unit -> FStar.HyperStack.ST.Stack FStar.UInt32.t | {
"end_col": 3,
"end_line": 48,
"start_col": 2,
"start_line": 26
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Pprint",
"short_module": "Pprint"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let issue_level_string = s:string {
s == "Info" \/
s == "Warning" \/
s == "Error" \/
s == "Feature not yet implemented: "
} | let issue_level_string = | false | null | false | s: string{s == "Info" \/ s == "Warning" \/ s == "Error" \/ s == "Feature not yet implemented: "} | {
"checked_file": "FStar.Issue.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Stubs.Pprint.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Issue.fsti"
} | [
"total"
] | [
"Prims.string",
"Prims.l_or",
"Prims.eq2"
] | [] | module FStar.Issue
open FStar.Range
module Pprint = FStar.Stubs.Pprint
new
val issue : Type0 | false | true | FStar.Issue.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val issue_level_string : Type0 | [] | FStar.Issue.issue_level_string | {
"file_name": "ulib/FStar.Issue.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | Type0 | {
"end_col": 1,
"end_line": 14,
"start_col": 25,
"start_line": 9
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.Stubs.Pprint",
"short_module": "Pprint"
},
{
"abbrev": false,
"full_module": "FStar.Range",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_issue (i:issue_level_string)
(msg:string)
(range:option range)
(number:option int)
(ctx:list string)
= mk_issue_doc i [Pprint.arbitrary_string msg] range number ctx | let mk_issue
(i: issue_level_string)
(msg: string)
(range: option range)
(number: option int)
(ctx: list string)
= | false | null | false | mk_issue_doc i [Pprint.arbitrary_string msg] range number ctx | {
"checked_file": "FStar.Issue.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Stubs.Pprint.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Issue.fsti"
} | [
"total"
] | [
"FStar.Issue.issue_level_string",
"Prims.string",
"FStar.Pervasives.Native.option",
"FStar.Range.range",
"Prims.int",
"Prims.list",
"FStar.Issue.mk_issue_doc",
"Prims.Cons",
"FStar.Stubs.Pprint.document",
"FStar.Stubs.Pprint.arbitrary_string",
"Prims.Nil",
"FStar.Issue.issue"
] | [] | module FStar.Issue
open FStar.Range
module Pprint = FStar.Stubs.Pprint
new
val issue : Type0
let issue_level_string = s:string {
s == "Info" \/
s == "Warning" \/
s == "Error" \/
s == "Feature not yet implemented: "
}
val message_of_issue (i:issue) : Tot (list Pprint.document)
val level_of_issue (i:issue) : Tot issue_level_string
val number_of_issue (i:issue) : Tot (option int)
val range_of_issue (i:issue) : Tot (option range)
val context_of_issue (i:issue) : Tot (list string)
val render_issue (i:issue) : Tot string
(* NOTE: the only way to build a document that actually reduces
in interpreted mode (like in tactics when not using plugins)
is using arbitrary_string, as below. *)
val mk_issue_doc (i:issue_level_string)
(msg:list Pprint.document)
(range:option range)
(number:option int)
(ctx:list string)
: Tot issue
(* These qualifiers here to make sure that karamel (while building
krmllib) does not attempt to extract this definition, as that would fail
since it does not have an implementation of arbitrary_string. We could
also not extract this module altogether. *)
noextract
inline_for_extraction
let mk_issue (i:issue_level_string)
(msg:string)
(range:option range)
(number:option int) | false | true | FStar.Issue.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_issue : i: FStar.Issue.issue_level_string ->
msg: Prims.string ->
range: FStar.Pervasives.Native.option FStar.Range.range ->
number: FStar.Pervasives.Native.option Prims.int ->
ctx: Prims.list Prims.string
-> FStar.Issue.issue | [] | FStar.Issue.mk_issue | {
"file_name": "ulib/FStar.Issue.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
i: FStar.Issue.issue_level_string ->
msg: Prims.string ->
range: FStar.Pervasives.Native.option FStar.Range.range ->
number: FStar.Pervasives.Native.option Prims.int ->
ctx: Prims.list Prims.string
-> FStar.Issue.issue | {
"end_col": 65,
"end_line": 49,
"start_col": 4,
"start_line": 49
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let felem = SD.lbignum U64 4 | let felem = | false | null | false | SD.lbignum U64 4 | {
"checked_file": "Hacl.Spec.Curve25519.Field64.Core.fst.checked",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [
"total"
] | [
"Hacl.Spec.Bignum.Definitions.lbignum",
"Lib.IntTypes.U64"
] | [] | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" | false | true | Hacl.Spec.Curve25519.Field64.Core.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val felem : Type0 | [] | Hacl.Spec.Curve25519.Field64.Core.felem | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Type0 | {
"end_col": 28,
"end_line": 19,
"start_col": 12,
"start_line": 19
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let felem_wide = SD.lbignum U64 8 | let felem_wide = | false | null | false | SD.lbignum U64 8 | {
"checked_file": "Hacl.Spec.Curve25519.Field64.Core.fst.checked",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [
"total"
] | [
"Hacl.Spec.Bignum.Definitions.lbignum",
"Lib.IntTypes.U64"
] | [] | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4 | false | true | Hacl.Spec.Curve25519.Field64.Core.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val felem_wide : Type0 | [] | Hacl.Spec.Curve25519.Field64.Core.felem_wide | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Type0 | {
"end_col": 33,
"end_line": 21,
"start_col": 17,
"start_line": 21
} |
|
Prims.Tot | val carry_pass: f:felem -> cin:uint64 -> felem | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let carry_pass f cin =
let c, r = add1 f (cin *. u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
out | val carry_pass: f:felem -> cin:uint64 -> felem
let carry_pass f cin = | false | null | false | let c, r = add1 f (cin *. u64 38) in
let b1 = r.[ 0 ] +. c *. u64 38 in
let out = r.[ 0 ] <- b1 in
out | {
"checked_file": "Hacl.Spec.Curve25519.Field64.Core.fst.checked",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [
"total"
] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Lib.IntTypes.uint64",
"Lib.Sequence.lseq",
"Hacl.Spec.Bignum.Definitions.limb",
"Lib.IntTypes.U64",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.upd",
"Lib.Sequence.index",
"Prims.l_Forall",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.pow2",
"Prims.l_imp",
"Prims.op_LessThan",
"Prims.op_disEquality",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.op_String_Assignment",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Lib.IntTypes.op_Plus_Dot",
"Lib.Sequence.op_String_Access",
"Lib.IntTypes.op_Star_Dot",
"Lib.IntTypes.u64",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Curve25519.Field64.Core.add1"
] | [] | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2)
let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out | false | true | Hacl.Spec.Curve25519.Field64.Core.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val carry_pass: f:felem -> cin:uint64 -> felem | [] | Hacl.Spec.Curve25519.Field64.Core.carry_pass | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | f: Hacl.Spec.Curve25519.Field64.Core.felem -> cin: Lib.IntTypes.uint64
-> Hacl.Spec.Curve25519.Field64.Core.felem | {
"end_col": 5,
"end_line": 82,
"start_col": 22,
"start_line": 78
} |
Prims.Pure | val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out) | val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin = | false | null | false | let c, out = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out) | {
"checked_file": "Hacl.Spec.Curve25519.Field64.Core.fst.checked",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Lib.IntTypes.uint64",
"Hacl.Spec.Bignum.Base.carry",
"Lib.IntTypes.U64",
"Hacl.Spec.Bignum.Definitions.lbignum",
"FStar.Pervasives.Native.Mktuple2",
"Prims.unit",
"Hacl.Spec.Bignum.bn_add1_lemma",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.bn_add1"
] | [] | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin) | false | false | Hacl.Spec.Curve25519.Field64.Core.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin) | [] | Hacl.Spec.Curve25519.Field64.Core.add1 | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | f: Hacl.Spec.Curve25519.Field64.Core.felem -> cin: Lib.IntTypes.uint64
-> Prims.Pure (Lib.IntTypes.uint64 * Hacl.Spec.Curve25519.Field64.Core.felem) | {
"end_col": 10,
"end_line": 38,
"start_col": 16,
"start_line": 35
} |
Prims.Pure | val sub4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f1 - SD.bn_v f2) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let sub4 f1 f2 =
let c, out = SB.bn_sub f1 f2 in
SB.bn_sub_lemma f1 f2;
c, out | val sub4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f1 - SD.bn_v f2)
let sub4 f1 f2 = | false | null | false | let c, out = SB.bn_sub f1 f2 in
SB.bn_sub_lemma f1 f2;
c, out | {
"checked_file": "Hacl.Spec.Curve25519.Field64.Core.fst.checked",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Hacl.Spec.Bignum.Base.carry",
"Lib.IntTypes.U64",
"Hacl.Spec.Bignum.Definitions.lbignum",
"FStar.Pervasives.Native.Mktuple2",
"Lib.IntTypes.uint64",
"Prims.unit",
"Hacl.Spec.Bignum.bn_sub_lemma",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.bn_sub"
] | [] | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2)
let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out
val carry_pass: f:felem -> cin:uint64 -> felem
let carry_pass f cin =
let c, r = add1 f (cin *. u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
out
val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38)
let lemma_add1_carry f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
assert (SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) + v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) + v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] + v cin * 38) % pow2 64)
val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime)
let carry_pass_lemma f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
SD.bn_upd_eval r b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r - v r.[0] + v b1) % P.prime;
(==) { lemma_add1_carry f cin }
(SD.bn_v r - v r.[0] + (v r.[0] + v c * 38)) % P.prime;
(==) { }
(SD.bn_v r + v c * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v r) (v c) }
(SD.bn_v r + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v f + v cin * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v f) (v cin) }
(SD.bn_v f + v cin * pow2 256) % P.prime;
}
val carry_wide: f:felem_wide ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f % P.prime)
let carry_wide f =
let c, r0 = mul1_add (sub f 4 4) (u64 38) (sub f 0 4) in
assert (SD.bn_v r0 + v c * pow2 256 == SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38);
SD.bn_eval_bound (sub f 0 4) 4;
SD.bn_eval_bound (sub f 4 4) 4;
SD.bn_eval_bound r0 4;
Lemmas.carry_wide_bound (SD.bn_v r0) (v c) (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4));
let out = carry_pass r0 c in
calc (==) {
SD.bn_v out % P.prime;
(==) { carry_pass_lemma r0 c }
(SD.bn_v r0 + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4)) }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * pow2 256) % P.prime;
(==) { SD.bn_concat_lemma (sub f 0 4) (sub f 4 4) }
SD.bn_v (concat (sub f 0 4) (sub f 4 4)) % P.prime;
(==) { eq_intro f (concat (sub f 0 4) (sub f 4 4)) }
SD.bn_v f % P.prime;
};
out
val add4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f1 + SD.bn_v f2)
let add4 f1 f2 =
let c, out = SB.bn_add f1 f2 in
SB.bn_add_lemma f1 f2;
c, out
val fadd4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fadd (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fadd4 f1 f2 =
let c0, out0 = add4 f1 f2 in
let out = carry_pass out0 c0 in
carry_pass_lemma out0 c0;
assert (SD.bn_v out % P.prime == (SD.bn_v f1 + SD.bn_v f2) % P.prime);
Math.Lemmas.lemma_mod_plus_distr_l (SD.bn_v f1) (SD.bn_v f2) P.prime;
Math.Lemmas.lemma_mod_plus_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v f2) P.prime;
out
val sub4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f1 - SD.bn_v f2) | false | false | Hacl.Spec.Curve25519.Field64.Core.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val sub4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f1 - SD.bn_v f2) | [] | Hacl.Spec.Curve25519.Field64.Core.sub4 | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | f1: Hacl.Spec.Curve25519.Field64.Core.felem -> f2: Hacl.Spec.Curve25519.Field64.Core.felem
-> Prims.Pure (Lib.IntTypes.uint64 * Hacl.Spec.Curve25519.Field64.Core.felem) | {
"end_col": 8,
"end_line": 200,
"start_col": 16,
"start_line": 197
} |
Prims.Pure | val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out | val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2)
let mul1_add f1 u2 f3 = | false | null | false | let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out | {
"checked_file": "Hacl.Spec.Curve25519.Field64.Core.fst.checked",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Lib.IntTypes.uint64",
"Hacl.Spec.Bignum.Definitions.limb",
"Lib.IntTypes.U64",
"Hacl.Spec.Bignum.Definitions.lbignum",
"FStar.Pervasives.Native.Mktuple2",
"Prims.unit",
"Hacl.Spec.Bignum.bn_mul1_lshift_add_lemma",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.bn_mul1_lshift_add"
] | [] | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2) | false | false | Hacl.Spec.Curve25519.Field64.Core.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2) | [] | Hacl.Spec.Curve25519.Field64.Core.mul1_add | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
f1: Hacl.Spec.Curve25519.Field64.Core.felem ->
u2: Lib.IntTypes.uint64 ->
f3: Hacl.Spec.Curve25519.Field64.Core.felem
-> Prims.Pure (Lib.IntTypes.uint64 * Hacl.Spec.Curve25519.Field64.Core.felem) | {
"end_col": 8,
"end_line": 74,
"start_col": 23,
"start_line": 71
} |
Prims.Pure | val mul4: f:felem -> r:felem ->
Pure felem_wide
(requires True)
(ensures fun out ->
SD.bn_v out == SD.bn_v f * SD.bn_v r) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mul4 f r =
let out = SB.bn_mul f r in
SB.bn_mul_lemma f r;
out | val mul4: f:felem -> r:felem ->
Pure felem_wide
(requires True)
(ensures fun out ->
SD.bn_v out == SD.bn_v f * SD.bn_v r)
let mul4 f r = | false | null | false | let out = SB.bn_mul f r in
SB.bn_mul_lemma f r;
out | {
"checked_file": "Hacl.Spec.Curve25519.Field64.Core.fst.checked",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Prims.unit",
"Hacl.Spec.Bignum.bn_mul_lemma",
"Lib.IntTypes.U64",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.op_Addition",
"Hacl.Spec.Bignum.bn_mul",
"Hacl.Spec.Curve25519.Field64.Core.felem_wide"
] | [] | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2)
let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out
val carry_pass: f:felem -> cin:uint64 -> felem
let carry_pass f cin =
let c, r = add1 f (cin *. u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
out
val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38)
let lemma_add1_carry f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
assert (SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) + v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) + v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] + v cin * 38) % pow2 64)
val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime)
let carry_pass_lemma f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
SD.bn_upd_eval r b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r - v r.[0] + v b1) % P.prime;
(==) { lemma_add1_carry f cin }
(SD.bn_v r - v r.[0] + (v r.[0] + v c * 38)) % P.prime;
(==) { }
(SD.bn_v r + v c * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v r) (v c) }
(SD.bn_v r + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v f + v cin * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v f) (v cin) }
(SD.bn_v f + v cin * pow2 256) % P.prime;
}
val carry_wide: f:felem_wide ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f % P.prime)
let carry_wide f =
let c, r0 = mul1_add (sub f 4 4) (u64 38) (sub f 0 4) in
assert (SD.bn_v r0 + v c * pow2 256 == SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38);
SD.bn_eval_bound (sub f 0 4) 4;
SD.bn_eval_bound (sub f 4 4) 4;
SD.bn_eval_bound r0 4;
Lemmas.carry_wide_bound (SD.bn_v r0) (v c) (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4));
let out = carry_pass r0 c in
calc (==) {
SD.bn_v out % P.prime;
(==) { carry_pass_lemma r0 c }
(SD.bn_v r0 + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4)) }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * pow2 256) % P.prime;
(==) { SD.bn_concat_lemma (sub f 0 4) (sub f 4 4) }
SD.bn_v (concat (sub f 0 4) (sub f 4 4)) % P.prime;
(==) { eq_intro f (concat (sub f 0 4) (sub f 4 4)) }
SD.bn_v f % P.prime;
};
out
val add4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f1 + SD.bn_v f2)
let add4 f1 f2 =
let c, out = SB.bn_add f1 f2 in
SB.bn_add_lemma f1 f2;
c, out
val fadd4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fadd (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fadd4 f1 f2 =
let c0, out0 = add4 f1 f2 in
let out = carry_pass out0 c0 in
carry_pass_lemma out0 c0;
assert (SD.bn_v out % P.prime == (SD.bn_v f1 + SD.bn_v f2) % P.prime);
Math.Lemmas.lemma_mod_plus_distr_l (SD.bn_v f1) (SD.bn_v f2) P.prime;
Math.Lemmas.lemma_mod_plus_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v f2) P.prime;
out
val sub4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f1 - SD.bn_v f2)
let sub4 f1 f2 =
let c, out = SB.bn_sub f1 f2 in
SB.bn_sub_lemma f1 f2;
c, out
val lemma_sub1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
v b1 == v r.[0] - v c * 38)
let lemma_sub1_carry f cin =
let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
assert (SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) - v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) - v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] - v cin * 38) % pow2 64)
val fsub4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fsub (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fsub4 f1 f2 =
let c0, r0 = sub4 f1 f2 in
let c1, r1 = sub1 r0 (c0 *! u64 38) in
let b1 = r1.[0] -. c1 *. u64 38 in
let out = r1.[0] <- b1 in
SD.bn_upd_eval r1 b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r1 - v r1.[0] + v b1) % P.prime;
(==) { lemma_sub1_carry r0 c0 }
(SD.bn_v r1 - v r1.[0] + (v r1.[0] - v c1 * 38)) % P.prime;
(==) { }
(SD.bn_v f1 - SD.bn_v f2 + v c0 * pow2 256 - v c0 * 38 + v c1 * pow2 256 - v c1 * 38) % P.prime;
(==) { Lemmas.lemma_fsub4 (SD.bn_v f1) (SD.bn_v f2) (v c0) (v c1) }
(SD.bn_v f1 % P.prime - SD.bn_v f2 % P.prime) % P.prime;
};
out
val mul4: f:felem -> r:felem ->
Pure felem_wide
(requires True)
(ensures fun out ->
SD.bn_v out == SD.bn_v f * SD.bn_v r) | false | false | Hacl.Spec.Curve25519.Field64.Core.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mul4: f:felem -> r:felem ->
Pure felem_wide
(requires True)
(ensures fun out ->
SD.bn_v out == SD.bn_v f * SD.bn_v r) | [] | Hacl.Spec.Curve25519.Field64.Core.mul4 | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | f: Hacl.Spec.Curve25519.Field64.Core.felem -> r: Hacl.Spec.Curve25519.Field64.Core.felem
-> Prims.Pure Hacl.Spec.Curve25519.Field64.Core.felem_wide | {
"end_col": 5,
"end_line": 261,
"start_col": 14,
"start_line": 258
} |
Prims.Pure | val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out | val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u = | false | null | false | let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out | {
"checked_file": "Hacl.Spec.Curve25519.Field64.Core.fst.checked",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Lib.IntTypes.uint64",
"Hacl.Spec.Bignum.Definitions.limb",
"Lib.IntTypes.U64",
"Hacl.Spec.Bignum.Definitions.lbignum",
"FStar.Pervasives.Native.Mktuple2",
"Prims.unit",
"Hacl.Spec.Bignum.bn_mul1_lemma",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.bn_mul1"
] | [] | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u) | false | false | Hacl.Spec.Curve25519.Field64.Core.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u) | [] | Hacl.Spec.Curve25519.Field64.Core.mul1 | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | f: Hacl.Spec.Curve25519.Field64.Core.felem -> u7: Lib.IntTypes.uint64
-> Prims.Pure (Lib.IntTypes.uint64 * Hacl.Spec.Curve25519.Field64.Core.felem) | {
"end_col": 8,
"end_line": 62,
"start_col": 14,
"start_line": 59
} |
Prims.Pure | val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out | val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin = | false | null | false | let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out | {
"checked_file": "Hacl.Spec.Curve25519.Field64.Core.fst.checked",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Lib.IntTypes.uint64",
"Hacl.Spec.Bignum.Base.carry",
"Lib.IntTypes.U64",
"Hacl.Spec.Bignum.Definitions.lbignum",
"FStar.Pervasives.Native.Mktuple2",
"Prims.unit",
"Hacl.Spec.Bignum.bn_sub1_lemma",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.bn_sub1"
] | [] | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin) | false | false | Hacl.Spec.Curve25519.Field64.Core.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin) | [] | Hacl.Spec.Curve25519.Field64.Core.sub1 | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | f: Hacl.Spec.Curve25519.Field64.Core.felem -> cin: Lib.IntTypes.uint64
-> Prims.Pure (Lib.IntTypes.uint64 * Hacl.Spec.Curve25519.Field64.Core.felem) | {
"end_col": 8,
"end_line": 50,
"start_col": 16,
"start_line": 47
} |
Prims.Pure | val fadd4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fadd (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime)) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fadd4 f1 f2 =
let c0, out0 = add4 f1 f2 in
let out = carry_pass out0 c0 in
carry_pass_lemma out0 c0;
assert (SD.bn_v out % P.prime == (SD.bn_v f1 + SD.bn_v f2) % P.prime);
Math.Lemmas.lemma_mod_plus_distr_l (SD.bn_v f1) (SD.bn_v f2) P.prime;
Math.Lemmas.lemma_mod_plus_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v f2) P.prime;
out | val fadd4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fadd (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fadd4 f1 f2 = | false | null | false | let c0, out0 = add4 f1 f2 in
let out = carry_pass out0 c0 in
carry_pass_lemma out0 c0;
assert (SD.bn_v out % P.prime == (SD.bn_v f1 + SD.bn_v f2) % P.prime);
Math.Lemmas.lemma_mod_plus_distr_l (SD.bn_v f1) (SD.bn_v f2) P.prime;
Math.Lemmas.lemma_mod_plus_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v f2) P.prime;
out | {
"checked_file": "Hacl.Spec.Curve25519.Field64.Core.fst.checked",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Lib.IntTypes.uint64",
"Prims.unit",
"FStar.Math.Lemmas.lemma_mod_plus_distr_r",
"Prims.op_Modulus",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Lib.IntTypes.U64",
"Spec.Curve25519.prime",
"FStar.Math.Lemmas.lemma_mod_plus_distr_l",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Prims.op_Addition",
"Hacl.Spec.Curve25519.Field64.Core.carry_pass_lemma",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Curve25519.Field64.Core.carry_pass",
"FStar.Pervasives.Native.tuple2",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Hacl.Spec.Curve25519.Field64.Core.add4"
] | [] | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2)
let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out
val carry_pass: f:felem -> cin:uint64 -> felem
let carry_pass f cin =
let c, r = add1 f (cin *. u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
out
val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38)
let lemma_add1_carry f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
assert (SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) + v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) + v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] + v cin * 38) % pow2 64)
val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime)
let carry_pass_lemma f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
SD.bn_upd_eval r b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r - v r.[0] + v b1) % P.prime;
(==) { lemma_add1_carry f cin }
(SD.bn_v r - v r.[0] + (v r.[0] + v c * 38)) % P.prime;
(==) { }
(SD.bn_v r + v c * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v r) (v c) }
(SD.bn_v r + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v f + v cin * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v f) (v cin) }
(SD.bn_v f + v cin * pow2 256) % P.prime;
}
val carry_wide: f:felem_wide ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f % P.prime)
let carry_wide f =
let c, r0 = mul1_add (sub f 4 4) (u64 38) (sub f 0 4) in
assert (SD.bn_v r0 + v c * pow2 256 == SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38);
SD.bn_eval_bound (sub f 0 4) 4;
SD.bn_eval_bound (sub f 4 4) 4;
SD.bn_eval_bound r0 4;
Lemmas.carry_wide_bound (SD.bn_v r0) (v c) (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4));
let out = carry_pass r0 c in
calc (==) {
SD.bn_v out % P.prime;
(==) { carry_pass_lemma r0 c }
(SD.bn_v r0 + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4)) }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * pow2 256) % P.prime;
(==) { SD.bn_concat_lemma (sub f 0 4) (sub f 4 4) }
SD.bn_v (concat (sub f 0 4) (sub f 4 4)) % P.prime;
(==) { eq_intro f (concat (sub f 0 4) (sub f 4 4)) }
SD.bn_v f % P.prime;
};
out
val add4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f1 + SD.bn_v f2)
let add4 f1 f2 =
let c, out = SB.bn_add f1 f2 in
SB.bn_add_lemma f1 f2;
c, out
val fadd4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fadd (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime)) | false | false | Hacl.Spec.Curve25519.Field64.Core.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fadd4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fadd (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime)) | [] | Hacl.Spec.Curve25519.Field64.Core.fadd4 | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | f1: Hacl.Spec.Curve25519.Field64.Core.felem -> f2: Hacl.Spec.Curve25519.Field64.Core.felem
-> Prims.Pure Hacl.Spec.Curve25519.Field64.Core.felem | {
"end_col": 5,
"end_line": 188,
"start_col": 17,
"start_line": 181
} |
Prims.Pure | val sqr4: f:felem ->
Pure felem_wide
(requires True)
(ensures fun out ->
SD.bn_v out == SD.bn_v f * SD.bn_v f) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let sqr4 f =
let out = SB.bn_sqr f in
SB.bn_sqr_lemma f;
out | val sqr4: f:felem ->
Pure felem_wide
(requires True)
(ensures fun out ->
SD.bn_v out == SD.bn_v f * SD.bn_v f)
let sqr4 f = | false | null | false | let out = SB.bn_sqr f in
SB.bn_sqr_lemma f;
out | {
"checked_file": "Hacl.Spec.Curve25519.Field64.Core.fst.checked",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Prims.unit",
"Hacl.Spec.Bignum.bn_sqr_lemma",
"Lib.IntTypes.U64",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.op_Addition",
"Hacl.Spec.Bignum.bn_sqr",
"Hacl.Spec.Curve25519.Field64.Core.felem_wide"
] | [] | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2)
let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out
val carry_pass: f:felem -> cin:uint64 -> felem
let carry_pass f cin =
let c, r = add1 f (cin *. u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
out
val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38)
let lemma_add1_carry f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
assert (SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) + v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) + v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] + v cin * 38) % pow2 64)
val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime)
let carry_pass_lemma f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
SD.bn_upd_eval r b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r - v r.[0] + v b1) % P.prime;
(==) { lemma_add1_carry f cin }
(SD.bn_v r - v r.[0] + (v r.[0] + v c * 38)) % P.prime;
(==) { }
(SD.bn_v r + v c * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v r) (v c) }
(SD.bn_v r + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v f + v cin * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v f) (v cin) }
(SD.bn_v f + v cin * pow2 256) % P.prime;
}
val carry_wide: f:felem_wide ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f % P.prime)
let carry_wide f =
let c, r0 = mul1_add (sub f 4 4) (u64 38) (sub f 0 4) in
assert (SD.bn_v r0 + v c * pow2 256 == SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38);
SD.bn_eval_bound (sub f 0 4) 4;
SD.bn_eval_bound (sub f 4 4) 4;
SD.bn_eval_bound r0 4;
Lemmas.carry_wide_bound (SD.bn_v r0) (v c) (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4));
let out = carry_pass r0 c in
calc (==) {
SD.bn_v out % P.prime;
(==) { carry_pass_lemma r0 c }
(SD.bn_v r0 + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4)) }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * pow2 256) % P.prime;
(==) { SD.bn_concat_lemma (sub f 0 4) (sub f 4 4) }
SD.bn_v (concat (sub f 0 4) (sub f 4 4)) % P.prime;
(==) { eq_intro f (concat (sub f 0 4) (sub f 4 4)) }
SD.bn_v f % P.prime;
};
out
val add4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f1 + SD.bn_v f2)
let add4 f1 f2 =
let c, out = SB.bn_add f1 f2 in
SB.bn_add_lemma f1 f2;
c, out
val fadd4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fadd (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fadd4 f1 f2 =
let c0, out0 = add4 f1 f2 in
let out = carry_pass out0 c0 in
carry_pass_lemma out0 c0;
assert (SD.bn_v out % P.prime == (SD.bn_v f1 + SD.bn_v f2) % P.prime);
Math.Lemmas.lemma_mod_plus_distr_l (SD.bn_v f1) (SD.bn_v f2) P.prime;
Math.Lemmas.lemma_mod_plus_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v f2) P.prime;
out
val sub4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f1 - SD.bn_v f2)
let sub4 f1 f2 =
let c, out = SB.bn_sub f1 f2 in
SB.bn_sub_lemma f1 f2;
c, out
val lemma_sub1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
v b1 == v r.[0] - v c * 38)
let lemma_sub1_carry f cin =
let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
assert (SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) - v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) - v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] - v cin * 38) % pow2 64)
val fsub4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fsub (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fsub4 f1 f2 =
let c0, r0 = sub4 f1 f2 in
let c1, r1 = sub1 r0 (c0 *! u64 38) in
let b1 = r1.[0] -. c1 *. u64 38 in
let out = r1.[0] <- b1 in
SD.bn_upd_eval r1 b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r1 - v r1.[0] + v b1) % P.prime;
(==) { lemma_sub1_carry r0 c0 }
(SD.bn_v r1 - v r1.[0] + (v r1.[0] - v c1 * 38)) % P.prime;
(==) { }
(SD.bn_v f1 - SD.bn_v f2 + v c0 * pow2 256 - v c0 * 38 + v c1 * pow2 256 - v c1 * 38) % P.prime;
(==) { Lemmas.lemma_fsub4 (SD.bn_v f1) (SD.bn_v f2) (v c0) (v c1) }
(SD.bn_v f1 % P.prime - SD.bn_v f2 % P.prime) % P.prime;
};
out
val mul4: f:felem -> r:felem ->
Pure felem_wide
(requires True)
(ensures fun out ->
SD.bn_v out == SD.bn_v f * SD.bn_v r)
let mul4 f r =
let out = SB.bn_mul f r in
SB.bn_mul_lemma f r;
out
val fmul4: f1:felem -> r:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fmul (SD.bn_v f1 % P.prime) (SD.bn_v r % P.prime))
let fmul4 f1 r =
let tmp = mul4 f1 r in
let out = carry_wide tmp in
Math.Lemmas.lemma_mod_mul_distr_l (SD.bn_v f1) (SD.bn_v r) P.prime;
Math.Lemmas.lemma_mod_mul_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v r) P.prime;
out
//121665 < pow2 17
val fmul14: f1:felem -> f2:uint64 ->
Pure felem
(requires v f2 < pow2 17)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f1 % P.prime * v f2 % P.prime)
let fmul14 f1 f2 =
let c0, r0 = mul1 f1 f2 in
assert (SD.bn_v r0 + v c0 * pow2 256 == SD.bn_v f1 * v f2);
SD.bn_eval_bound f1 4;
SD.bn_eval_bound r0 4;
Lemmas.fmul14_bound (SD.bn_v r0) (v c0) (SD.bn_v f1) (v f2);
let out = carry_pass r0 c0 in
calc (==) {
SD.bn_v out % P.prime;
(==) { carry_pass_lemma r0 c0 }
(SD.bn_v r0 + v c0 * pow2 256) % P.prime;
(==) { }
(SD.bn_v f1 * v f2) % P.prime;
(==) {Math.Lemmas.lemma_mod_mul_distr_l (SD.bn_v f1) (v f2) P.prime }
(SD.bn_v f1 % P.prime * v f2) % P.prime;
};
out
val sqr4: f:felem ->
Pure felem_wide
(requires True)
(ensures fun out ->
SD.bn_v out == SD.bn_v f * SD.bn_v f) | false | false | Hacl.Spec.Curve25519.Field64.Core.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val sqr4: f:felem ->
Pure felem_wide
(requires True)
(ensures fun out ->
SD.bn_v out == SD.bn_v f * SD.bn_v f) | [] | Hacl.Spec.Curve25519.Field64.Core.sqr4 | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | f: Hacl.Spec.Curve25519.Field64.Core.felem
-> Prims.Pure Hacl.Spec.Curve25519.Field64.Core.felem_wide | {
"end_col": 5,
"end_line": 314,
"start_col": 12,
"start_line": 311
} |
Prims.Pure | val add4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f1 + SD.bn_v f2) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let add4 f1 f2 =
let c, out = SB.bn_add f1 f2 in
SB.bn_add_lemma f1 f2;
c, out | val add4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f1 + SD.bn_v f2)
let add4 f1 f2 = | false | null | false | let c, out = SB.bn_add f1 f2 in
SB.bn_add_lemma f1 f2;
c, out | {
"checked_file": "Hacl.Spec.Curve25519.Field64.Core.fst.checked",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Hacl.Spec.Bignum.Base.carry",
"Lib.IntTypes.U64",
"Hacl.Spec.Bignum.Definitions.lbignum",
"FStar.Pervasives.Native.Mktuple2",
"Lib.IntTypes.uint64",
"Prims.unit",
"Hacl.Spec.Bignum.bn_add_lemma",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.bn_add"
] | [] | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2)
let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out
val carry_pass: f:felem -> cin:uint64 -> felem
let carry_pass f cin =
let c, r = add1 f (cin *. u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
out
val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38)
let lemma_add1_carry f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
assert (SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) + v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) + v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] + v cin * 38) % pow2 64)
val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime)
let carry_pass_lemma f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
SD.bn_upd_eval r b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r - v r.[0] + v b1) % P.prime;
(==) { lemma_add1_carry f cin }
(SD.bn_v r - v r.[0] + (v r.[0] + v c * 38)) % P.prime;
(==) { }
(SD.bn_v r + v c * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v r) (v c) }
(SD.bn_v r + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v f + v cin * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v f) (v cin) }
(SD.bn_v f + v cin * pow2 256) % P.prime;
}
val carry_wide: f:felem_wide ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f % P.prime)
let carry_wide f =
let c, r0 = mul1_add (sub f 4 4) (u64 38) (sub f 0 4) in
assert (SD.bn_v r0 + v c * pow2 256 == SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38);
SD.bn_eval_bound (sub f 0 4) 4;
SD.bn_eval_bound (sub f 4 4) 4;
SD.bn_eval_bound r0 4;
Lemmas.carry_wide_bound (SD.bn_v r0) (v c) (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4));
let out = carry_pass r0 c in
calc (==) {
SD.bn_v out % P.prime;
(==) { carry_pass_lemma r0 c }
(SD.bn_v r0 + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4)) }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * pow2 256) % P.prime;
(==) { SD.bn_concat_lemma (sub f 0 4) (sub f 4 4) }
SD.bn_v (concat (sub f 0 4) (sub f 4 4)) % P.prime;
(==) { eq_intro f (concat (sub f 0 4) (sub f 4 4)) }
SD.bn_v f % P.prime;
};
out
val add4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f1 + SD.bn_v f2) | false | false | Hacl.Spec.Curve25519.Field64.Core.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val add4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f1 + SD.bn_v f2) | [] | Hacl.Spec.Curve25519.Field64.Core.add4 | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | f1: Hacl.Spec.Curve25519.Field64.Core.felem -> f2: Hacl.Spec.Curve25519.Field64.Core.felem
-> Prims.Pure (Lib.IntTypes.uint64 * Hacl.Spec.Curve25519.Field64.Core.felem) | {
"end_col": 8,
"end_line": 172,
"start_col": 16,
"start_line": 169
} |
Prims.Pure | val fsqr4: f:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fmul (SD.bn_v f % P.prime) (SD.bn_v f % P.prime)) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fsqr4 f =
let tmp = sqr4 f in
let out = carry_wide tmp in
Math.Lemmas.lemma_mod_mul_distr_l (SD.bn_v f) (SD.bn_v f) P.prime;
Math.Lemmas.lemma_mod_mul_distr_r (SD.bn_v f % P.prime) (SD.bn_v f) P.prime;
out | val fsqr4: f:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fmul (SD.bn_v f % P.prime) (SD.bn_v f % P.prime))
let fsqr4 f = | false | null | false | let tmp = sqr4 f in
let out = carry_wide tmp in
Math.Lemmas.lemma_mod_mul_distr_l (SD.bn_v f) (SD.bn_v f) P.prime;
Math.Lemmas.lemma_mod_mul_distr_r (SD.bn_v f % P.prime) (SD.bn_v f) P.prime;
out | {
"checked_file": "Hacl.Spec.Curve25519.Field64.Core.fst.checked",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Prims.unit",
"FStar.Math.Lemmas.lemma_mod_mul_distr_r",
"Prims.op_Modulus",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Lib.IntTypes.U64",
"Spec.Curve25519.prime",
"FStar.Math.Lemmas.lemma_mod_mul_distr_l",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Curve25519.Field64.Core.carry_wide",
"Hacl.Spec.Curve25519.Field64.Core.sqr4"
] | [] | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2)
let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out
val carry_pass: f:felem -> cin:uint64 -> felem
let carry_pass f cin =
let c, r = add1 f (cin *. u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
out
val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38)
let lemma_add1_carry f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
assert (SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) + v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) + v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] + v cin * 38) % pow2 64)
val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime)
let carry_pass_lemma f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
SD.bn_upd_eval r b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r - v r.[0] + v b1) % P.prime;
(==) { lemma_add1_carry f cin }
(SD.bn_v r - v r.[0] + (v r.[0] + v c * 38)) % P.prime;
(==) { }
(SD.bn_v r + v c * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v r) (v c) }
(SD.bn_v r + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v f + v cin * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v f) (v cin) }
(SD.bn_v f + v cin * pow2 256) % P.prime;
}
val carry_wide: f:felem_wide ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f % P.prime)
let carry_wide f =
let c, r0 = mul1_add (sub f 4 4) (u64 38) (sub f 0 4) in
assert (SD.bn_v r0 + v c * pow2 256 == SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38);
SD.bn_eval_bound (sub f 0 4) 4;
SD.bn_eval_bound (sub f 4 4) 4;
SD.bn_eval_bound r0 4;
Lemmas.carry_wide_bound (SD.bn_v r0) (v c) (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4));
let out = carry_pass r0 c in
calc (==) {
SD.bn_v out % P.prime;
(==) { carry_pass_lemma r0 c }
(SD.bn_v r0 + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4)) }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * pow2 256) % P.prime;
(==) { SD.bn_concat_lemma (sub f 0 4) (sub f 4 4) }
SD.bn_v (concat (sub f 0 4) (sub f 4 4)) % P.prime;
(==) { eq_intro f (concat (sub f 0 4) (sub f 4 4)) }
SD.bn_v f % P.prime;
};
out
val add4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f1 + SD.bn_v f2)
let add4 f1 f2 =
let c, out = SB.bn_add f1 f2 in
SB.bn_add_lemma f1 f2;
c, out
val fadd4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fadd (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fadd4 f1 f2 =
let c0, out0 = add4 f1 f2 in
let out = carry_pass out0 c0 in
carry_pass_lemma out0 c0;
assert (SD.bn_v out % P.prime == (SD.bn_v f1 + SD.bn_v f2) % P.prime);
Math.Lemmas.lemma_mod_plus_distr_l (SD.bn_v f1) (SD.bn_v f2) P.prime;
Math.Lemmas.lemma_mod_plus_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v f2) P.prime;
out
val sub4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f1 - SD.bn_v f2)
let sub4 f1 f2 =
let c, out = SB.bn_sub f1 f2 in
SB.bn_sub_lemma f1 f2;
c, out
val lemma_sub1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
v b1 == v r.[0] - v c * 38)
let lemma_sub1_carry f cin =
let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
assert (SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) - v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) - v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] - v cin * 38) % pow2 64)
val fsub4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fsub (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fsub4 f1 f2 =
let c0, r0 = sub4 f1 f2 in
let c1, r1 = sub1 r0 (c0 *! u64 38) in
let b1 = r1.[0] -. c1 *. u64 38 in
let out = r1.[0] <- b1 in
SD.bn_upd_eval r1 b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r1 - v r1.[0] + v b1) % P.prime;
(==) { lemma_sub1_carry r0 c0 }
(SD.bn_v r1 - v r1.[0] + (v r1.[0] - v c1 * 38)) % P.prime;
(==) { }
(SD.bn_v f1 - SD.bn_v f2 + v c0 * pow2 256 - v c0 * 38 + v c1 * pow2 256 - v c1 * 38) % P.prime;
(==) { Lemmas.lemma_fsub4 (SD.bn_v f1) (SD.bn_v f2) (v c0) (v c1) }
(SD.bn_v f1 % P.prime - SD.bn_v f2 % P.prime) % P.prime;
};
out
val mul4: f:felem -> r:felem ->
Pure felem_wide
(requires True)
(ensures fun out ->
SD.bn_v out == SD.bn_v f * SD.bn_v r)
let mul4 f r =
let out = SB.bn_mul f r in
SB.bn_mul_lemma f r;
out
val fmul4: f1:felem -> r:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fmul (SD.bn_v f1 % P.prime) (SD.bn_v r % P.prime))
let fmul4 f1 r =
let tmp = mul4 f1 r in
let out = carry_wide tmp in
Math.Lemmas.lemma_mod_mul_distr_l (SD.bn_v f1) (SD.bn_v r) P.prime;
Math.Lemmas.lemma_mod_mul_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v r) P.prime;
out
//121665 < pow2 17
val fmul14: f1:felem -> f2:uint64 ->
Pure felem
(requires v f2 < pow2 17)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f1 % P.prime * v f2 % P.prime)
let fmul14 f1 f2 =
let c0, r0 = mul1 f1 f2 in
assert (SD.bn_v r0 + v c0 * pow2 256 == SD.bn_v f1 * v f2);
SD.bn_eval_bound f1 4;
SD.bn_eval_bound r0 4;
Lemmas.fmul14_bound (SD.bn_v r0) (v c0) (SD.bn_v f1) (v f2);
let out = carry_pass r0 c0 in
calc (==) {
SD.bn_v out % P.prime;
(==) { carry_pass_lemma r0 c0 }
(SD.bn_v r0 + v c0 * pow2 256) % P.prime;
(==) { }
(SD.bn_v f1 * v f2) % P.prime;
(==) {Math.Lemmas.lemma_mod_mul_distr_l (SD.bn_v f1) (v f2) P.prime }
(SD.bn_v f1 % P.prime * v f2) % P.prime;
};
out
val sqr4: f:felem ->
Pure felem_wide
(requires True)
(ensures fun out ->
SD.bn_v out == SD.bn_v f * SD.bn_v f)
let sqr4 f =
let out = SB.bn_sqr f in
SB.bn_sqr_lemma f;
out
val fsqr4: f:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fmul (SD.bn_v f % P.prime) (SD.bn_v f % P.prime)) | false | false | Hacl.Spec.Curve25519.Field64.Core.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fsqr4: f:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fmul (SD.bn_v f % P.prime) (SD.bn_v f % P.prime)) | [] | Hacl.Spec.Curve25519.Field64.Core.fsqr4 | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | f: Hacl.Spec.Curve25519.Field64.Core.felem -> Prims.Pure Hacl.Spec.Curve25519.Field64.Core.felem | {
"end_col": 5,
"end_line": 328,
"start_col": 13,
"start_line": 323
} |
Prims.Pure | val fmul4: f1:felem -> r:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fmul (SD.bn_v f1 % P.prime) (SD.bn_v r % P.prime)) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fmul4 f1 r =
let tmp = mul4 f1 r in
let out = carry_wide tmp in
Math.Lemmas.lemma_mod_mul_distr_l (SD.bn_v f1) (SD.bn_v r) P.prime;
Math.Lemmas.lemma_mod_mul_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v r) P.prime;
out | val fmul4: f1:felem -> r:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fmul (SD.bn_v f1 % P.prime) (SD.bn_v r % P.prime))
let fmul4 f1 r = | false | null | false | let tmp = mul4 f1 r in
let out = carry_wide tmp in
Math.Lemmas.lemma_mod_mul_distr_l (SD.bn_v f1) (SD.bn_v r) P.prime;
Math.Lemmas.lemma_mod_mul_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v r) P.prime;
out | {
"checked_file": "Hacl.Spec.Curve25519.Field64.Core.fst.checked",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Prims.unit",
"FStar.Math.Lemmas.lemma_mod_mul_distr_r",
"Prims.op_Modulus",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Lib.IntTypes.U64",
"Spec.Curve25519.prime",
"FStar.Math.Lemmas.lemma_mod_mul_distr_l",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Curve25519.Field64.Core.carry_wide",
"Hacl.Spec.Curve25519.Field64.Core.mul4"
] | [] | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2)
let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out
val carry_pass: f:felem -> cin:uint64 -> felem
let carry_pass f cin =
let c, r = add1 f (cin *. u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
out
val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38)
let lemma_add1_carry f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
assert (SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) + v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) + v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] + v cin * 38) % pow2 64)
val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime)
let carry_pass_lemma f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
SD.bn_upd_eval r b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r - v r.[0] + v b1) % P.prime;
(==) { lemma_add1_carry f cin }
(SD.bn_v r - v r.[0] + (v r.[0] + v c * 38)) % P.prime;
(==) { }
(SD.bn_v r + v c * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v r) (v c) }
(SD.bn_v r + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v f + v cin * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v f) (v cin) }
(SD.bn_v f + v cin * pow2 256) % P.prime;
}
val carry_wide: f:felem_wide ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f % P.prime)
let carry_wide f =
let c, r0 = mul1_add (sub f 4 4) (u64 38) (sub f 0 4) in
assert (SD.bn_v r0 + v c * pow2 256 == SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38);
SD.bn_eval_bound (sub f 0 4) 4;
SD.bn_eval_bound (sub f 4 4) 4;
SD.bn_eval_bound r0 4;
Lemmas.carry_wide_bound (SD.bn_v r0) (v c) (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4));
let out = carry_pass r0 c in
calc (==) {
SD.bn_v out % P.prime;
(==) { carry_pass_lemma r0 c }
(SD.bn_v r0 + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4)) }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * pow2 256) % P.prime;
(==) { SD.bn_concat_lemma (sub f 0 4) (sub f 4 4) }
SD.bn_v (concat (sub f 0 4) (sub f 4 4)) % P.prime;
(==) { eq_intro f (concat (sub f 0 4) (sub f 4 4)) }
SD.bn_v f % P.prime;
};
out
val add4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f1 + SD.bn_v f2)
let add4 f1 f2 =
let c, out = SB.bn_add f1 f2 in
SB.bn_add_lemma f1 f2;
c, out
val fadd4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fadd (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fadd4 f1 f2 =
let c0, out0 = add4 f1 f2 in
let out = carry_pass out0 c0 in
carry_pass_lemma out0 c0;
assert (SD.bn_v out % P.prime == (SD.bn_v f1 + SD.bn_v f2) % P.prime);
Math.Lemmas.lemma_mod_plus_distr_l (SD.bn_v f1) (SD.bn_v f2) P.prime;
Math.Lemmas.lemma_mod_plus_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v f2) P.prime;
out
val sub4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f1 - SD.bn_v f2)
let sub4 f1 f2 =
let c, out = SB.bn_sub f1 f2 in
SB.bn_sub_lemma f1 f2;
c, out
val lemma_sub1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
v b1 == v r.[0] - v c * 38)
let lemma_sub1_carry f cin =
let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
assert (SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) - v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) - v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] - v cin * 38) % pow2 64)
val fsub4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fsub (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fsub4 f1 f2 =
let c0, r0 = sub4 f1 f2 in
let c1, r1 = sub1 r0 (c0 *! u64 38) in
let b1 = r1.[0] -. c1 *. u64 38 in
let out = r1.[0] <- b1 in
SD.bn_upd_eval r1 b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r1 - v r1.[0] + v b1) % P.prime;
(==) { lemma_sub1_carry r0 c0 }
(SD.bn_v r1 - v r1.[0] + (v r1.[0] - v c1 * 38)) % P.prime;
(==) { }
(SD.bn_v f1 - SD.bn_v f2 + v c0 * pow2 256 - v c0 * 38 + v c1 * pow2 256 - v c1 * 38) % P.prime;
(==) { Lemmas.lemma_fsub4 (SD.bn_v f1) (SD.bn_v f2) (v c0) (v c1) }
(SD.bn_v f1 % P.prime - SD.bn_v f2 % P.prime) % P.prime;
};
out
val mul4: f:felem -> r:felem ->
Pure felem_wide
(requires True)
(ensures fun out ->
SD.bn_v out == SD.bn_v f * SD.bn_v r)
let mul4 f r =
let out = SB.bn_mul f r in
SB.bn_mul_lemma f r;
out
val fmul4: f1:felem -> r:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fmul (SD.bn_v f1 % P.prime) (SD.bn_v r % P.prime)) | false | false | Hacl.Spec.Curve25519.Field64.Core.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fmul4: f1:felem -> r:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fmul (SD.bn_v f1 % P.prime) (SD.bn_v r % P.prime)) | [] | Hacl.Spec.Curve25519.Field64.Core.fmul4 | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | f1: Hacl.Spec.Curve25519.Field64.Core.felem -> r: Hacl.Spec.Curve25519.Field64.Core.felem
-> Prims.Pure Hacl.Spec.Curve25519.Field64.Core.felem | {
"end_col": 5,
"end_line": 275,
"start_col": 16,
"start_line": 270
} |
FStar.Pervasives.Lemma | val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lemma_add1_carry f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
assert (SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) + v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) + v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] + v cin * 38) % pow2 64) | val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38)
let lemma_add1_carry f cin = | false | null | true | let c, r = add1 f (cin *! u64 38) in
let b1 = r.[ 0 ] +. c *. u64 38 in
assert (SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[ 0 ] + pow2 64 * SD.bn_v (slice r 1 4) + v c * pow2 256 ==
v f.[ 0 ] + pow2 64 * SD.bn_v (slice f 1 4) + v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[ 0 ] == (v f.[ 0 ] + v cin * 38) % pow2 64) | {
"checked_file": "Hacl.Spec.Curve25519.Field64.Core.fst.checked",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Lib.IntTypes.uint64",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Prims.pow2",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Lib.Sequence.op_String_Access",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.op_Modulus",
"Prims.op_Addition",
"Prims.unit",
"FStar.Math.Lemmas.pow2_plus",
"Hacl.Spec.Bignum.Definitions.bn_eval_bound",
"Prims.op_Subtraction",
"Lib.Sequence.slice",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Hacl.Spec.Bignum.Definitions.bn_eval1",
"Hacl.Spec.Bignum.Definitions.bn_eval_split_i",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Plus_Dot",
"Lib.IntTypes.op_Star_Dot",
"Lib.IntTypes.u64",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Curve25519.Field64.Core.add1",
"Lib.IntTypes.op_Star_Bang"
] | [] | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2)
let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out
val carry_pass: f:felem -> cin:uint64 -> felem
let carry_pass f cin =
let c, r = add1 f (cin *. u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
out
val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38) | false | false | Hacl.Spec.Curve25519.Field64.Core.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38) | [] | Hacl.Spec.Curve25519.Field64.Core.lemma_add1_carry | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
f: Hacl.Spec.Curve25519.Field64.Core.felem ->
cin: Lib.IntTypes.uint64{Lib.IntTypes.v cin * 38 < Prims.pow2 63}
-> FStar.Pervasives.Lemma
(ensures
(let _ = Hacl.Spec.Curve25519.Field64.Core.add1 f (cin *! Lib.IntTypes.u64 38) in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c r = _ in
let b1 = r.[ 0 ] +. c *. Lib.IntTypes.u64 38 in
Lib.IntTypes.v b1 == Lib.IntTypes.v r.[ 0 ] + Lib.IntTypes.v c * 38)
<:
Type0)) | {
"end_col": 54,
"end_line": 103,
"start_col": 28,
"start_line": 90
} |
FStar.Pervasives.Lemma | val lemma_sub1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
v b1 == v r.[0] - v c * 38) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lemma_sub1_carry f cin =
let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
assert (SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) - v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) - v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] - v cin * 38) % pow2 64) | val lemma_sub1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
v b1 == v r.[0] - v c * 38)
let lemma_sub1_carry f cin = | false | null | true | let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[ 0 ] -. c *. u64 38 in
assert (SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[ 0 ] + pow2 64 * SD.bn_v (slice r 1 4) - v c * pow2 256 ==
v f.[ 0 ] + pow2 64 * SD.bn_v (slice f 1 4) - v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[ 0 ] == (v f.[ 0 ] - v cin * 38) % pow2 64) | {
"checked_file": "Hacl.Spec.Curve25519.Field64.Core.fst.checked",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Lib.IntTypes.uint64",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Prims.pow2",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Lib.Sequence.op_String_Access",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.op_Modulus",
"Prims.op_Subtraction",
"Prims.unit",
"FStar.Math.Lemmas.pow2_plus",
"Hacl.Spec.Bignum.Definitions.bn_eval_bound",
"Lib.Sequence.slice",
"Prims.op_Addition",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Hacl.Spec.Bignum.Definitions.bn_eval1",
"Hacl.Spec.Bignum.Definitions.bn_eval_split_i",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Subtraction_Dot",
"Lib.IntTypes.op_Star_Dot",
"Lib.IntTypes.u64",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Curve25519.Field64.Core.sub1",
"Lib.IntTypes.op_Star_Bang"
] | [] | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2)
let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out
val carry_pass: f:felem -> cin:uint64 -> felem
let carry_pass f cin =
let c, r = add1 f (cin *. u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
out
val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38)
let lemma_add1_carry f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
assert (SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) + v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) + v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] + v cin * 38) % pow2 64)
val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime)
let carry_pass_lemma f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
SD.bn_upd_eval r b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r - v r.[0] + v b1) % P.prime;
(==) { lemma_add1_carry f cin }
(SD.bn_v r - v r.[0] + (v r.[0] + v c * 38)) % P.prime;
(==) { }
(SD.bn_v r + v c * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v r) (v c) }
(SD.bn_v r + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v f + v cin * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v f) (v cin) }
(SD.bn_v f + v cin * pow2 256) % P.prime;
}
val carry_wide: f:felem_wide ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f % P.prime)
let carry_wide f =
let c, r0 = mul1_add (sub f 4 4) (u64 38) (sub f 0 4) in
assert (SD.bn_v r0 + v c * pow2 256 == SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38);
SD.bn_eval_bound (sub f 0 4) 4;
SD.bn_eval_bound (sub f 4 4) 4;
SD.bn_eval_bound r0 4;
Lemmas.carry_wide_bound (SD.bn_v r0) (v c) (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4));
let out = carry_pass r0 c in
calc (==) {
SD.bn_v out % P.prime;
(==) { carry_pass_lemma r0 c }
(SD.bn_v r0 + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4)) }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * pow2 256) % P.prime;
(==) { SD.bn_concat_lemma (sub f 0 4) (sub f 4 4) }
SD.bn_v (concat (sub f 0 4) (sub f 4 4)) % P.prime;
(==) { eq_intro f (concat (sub f 0 4) (sub f 4 4)) }
SD.bn_v f % P.prime;
};
out
val add4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f1 + SD.bn_v f2)
let add4 f1 f2 =
let c, out = SB.bn_add f1 f2 in
SB.bn_add_lemma f1 f2;
c, out
val fadd4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fadd (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fadd4 f1 f2 =
let c0, out0 = add4 f1 f2 in
let out = carry_pass out0 c0 in
carry_pass_lemma out0 c0;
assert (SD.bn_v out % P.prime == (SD.bn_v f1 + SD.bn_v f2) % P.prime);
Math.Lemmas.lemma_mod_plus_distr_l (SD.bn_v f1) (SD.bn_v f2) P.prime;
Math.Lemmas.lemma_mod_plus_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v f2) P.prime;
out
val sub4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f1 - SD.bn_v f2)
let sub4 f1 f2 =
let c, out = SB.bn_sub f1 f2 in
SB.bn_sub_lemma f1 f2;
c, out
val lemma_sub1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
v b1 == v r.[0] - v c * 38) | false | false | Hacl.Spec.Curve25519.Field64.Core.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_sub1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
v b1 == v r.[0] - v c * 38) | [] | Hacl.Spec.Curve25519.Field64.Core.lemma_sub1_carry | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
f: Hacl.Spec.Curve25519.Field64.Core.felem ->
cin: Lib.IntTypes.uint64{Lib.IntTypes.v cin * 38 < Prims.pow2 63}
-> FStar.Pervasives.Lemma
(ensures
(let _ = Hacl.Spec.Curve25519.Field64.Core.sub1 f (cin *! Lib.IntTypes.u64 38) in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c r = _ in
let b1 = r.[ 0 ] -. c *. Lib.IntTypes.u64 38 in
Lib.IntTypes.v b1 == Lib.IntTypes.v r.[ 0 ] - Lib.IntTypes.v c * 38)
<:
Type0)) | {
"end_col": 54,
"end_line": 222,
"start_col": 28,
"start_line": 208
} |
Prims.Pure | val fmul14: f1:felem -> f2:uint64 ->
Pure felem
(requires v f2 < pow2 17)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f1 % P.prime * v f2 % P.prime) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fmul14 f1 f2 =
let c0, r0 = mul1 f1 f2 in
assert (SD.bn_v r0 + v c0 * pow2 256 == SD.bn_v f1 * v f2);
SD.bn_eval_bound f1 4;
SD.bn_eval_bound r0 4;
Lemmas.fmul14_bound (SD.bn_v r0) (v c0) (SD.bn_v f1) (v f2);
let out = carry_pass r0 c0 in
calc (==) {
SD.bn_v out % P.prime;
(==) { carry_pass_lemma r0 c0 }
(SD.bn_v r0 + v c0 * pow2 256) % P.prime;
(==) { }
(SD.bn_v f1 * v f2) % P.prime;
(==) {Math.Lemmas.lemma_mod_mul_distr_l (SD.bn_v f1) (v f2) P.prime }
(SD.bn_v f1 % P.prime * v f2) % P.prime;
};
out | val fmul14: f1:felem -> f2:uint64 ->
Pure felem
(requires v f2 < pow2 17)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f1 % P.prime * v f2 % P.prime)
let fmul14 f1 f2 = | false | null | false | let c0, r0 = mul1 f1 f2 in
assert (SD.bn_v r0 + v c0 * pow2 256 == SD.bn_v f1 * v f2);
SD.bn_eval_bound f1 4;
SD.bn_eval_bound r0 4;
Lemmas.fmul14_bound (SD.bn_v r0) (v c0) (SD.bn_v f1) (v f2);
let out = carry_pass r0 c0 in
calc ( == ) {
SD.bn_v out % P.prime;
( == ) { carry_pass_lemma r0 c0 }
(SD.bn_v r0 + v c0 * pow2 256) % P.prime;
( == ) { () }
(SD.bn_v f1 * v f2) % P.prime;
( == ) { Math.Lemmas.lemma_mod_mul_distr_l (SD.bn_v f1) (v f2) P.prime }
((SD.bn_v f1 % P.prime) * v f2) % P.prime;
};
out | {
"checked_file": "Hacl.Spec.Curve25519.Field64.Core.fst.checked",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Lib.IntTypes.uint64",
"Prims.unit",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Modulus",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Lib.IntTypes.U64",
"Spec.Curve25519.prime",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"Prims.op_Addition",
"Prims.pow2",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Hacl.Spec.Curve25519.Field64.Core.carry_pass_lemma",
"Prims.squash",
"FStar.Math.Lemmas.lemma_mod_mul_distr_l",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Curve25519.Field64.Core.carry_pass",
"Hacl.Spec.Curve25519.Field64.Lemmas.fmul14_bound",
"Hacl.Spec.Bignum.Definitions.bn_eval_bound",
"Prims._assert",
"FStar.Pervasives.Native.tuple2",
"Lib.IntTypes.int_t",
"Hacl.Spec.Curve25519.Field64.Core.mul1"
] | [] | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2)
let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out
val carry_pass: f:felem -> cin:uint64 -> felem
let carry_pass f cin =
let c, r = add1 f (cin *. u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
out
val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38)
let lemma_add1_carry f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
assert (SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) + v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) + v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] + v cin * 38) % pow2 64)
val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime)
let carry_pass_lemma f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
SD.bn_upd_eval r b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r - v r.[0] + v b1) % P.prime;
(==) { lemma_add1_carry f cin }
(SD.bn_v r - v r.[0] + (v r.[0] + v c * 38)) % P.prime;
(==) { }
(SD.bn_v r + v c * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v r) (v c) }
(SD.bn_v r + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v f + v cin * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v f) (v cin) }
(SD.bn_v f + v cin * pow2 256) % P.prime;
}
val carry_wide: f:felem_wide ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f % P.prime)
let carry_wide f =
let c, r0 = mul1_add (sub f 4 4) (u64 38) (sub f 0 4) in
assert (SD.bn_v r0 + v c * pow2 256 == SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38);
SD.bn_eval_bound (sub f 0 4) 4;
SD.bn_eval_bound (sub f 4 4) 4;
SD.bn_eval_bound r0 4;
Lemmas.carry_wide_bound (SD.bn_v r0) (v c) (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4));
let out = carry_pass r0 c in
calc (==) {
SD.bn_v out % P.prime;
(==) { carry_pass_lemma r0 c }
(SD.bn_v r0 + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4)) }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * pow2 256) % P.prime;
(==) { SD.bn_concat_lemma (sub f 0 4) (sub f 4 4) }
SD.bn_v (concat (sub f 0 4) (sub f 4 4)) % P.prime;
(==) { eq_intro f (concat (sub f 0 4) (sub f 4 4)) }
SD.bn_v f % P.prime;
};
out
val add4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f1 + SD.bn_v f2)
let add4 f1 f2 =
let c, out = SB.bn_add f1 f2 in
SB.bn_add_lemma f1 f2;
c, out
val fadd4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fadd (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fadd4 f1 f2 =
let c0, out0 = add4 f1 f2 in
let out = carry_pass out0 c0 in
carry_pass_lemma out0 c0;
assert (SD.bn_v out % P.prime == (SD.bn_v f1 + SD.bn_v f2) % P.prime);
Math.Lemmas.lemma_mod_plus_distr_l (SD.bn_v f1) (SD.bn_v f2) P.prime;
Math.Lemmas.lemma_mod_plus_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v f2) P.prime;
out
val sub4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f1 - SD.bn_v f2)
let sub4 f1 f2 =
let c, out = SB.bn_sub f1 f2 in
SB.bn_sub_lemma f1 f2;
c, out
val lemma_sub1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
v b1 == v r.[0] - v c * 38)
let lemma_sub1_carry f cin =
let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
assert (SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) - v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) - v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] - v cin * 38) % pow2 64)
val fsub4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fsub (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fsub4 f1 f2 =
let c0, r0 = sub4 f1 f2 in
let c1, r1 = sub1 r0 (c0 *! u64 38) in
let b1 = r1.[0] -. c1 *. u64 38 in
let out = r1.[0] <- b1 in
SD.bn_upd_eval r1 b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r1 - v r1.[0] + v b1) % P.prime;
(==) { lemma_sub1_carry r0 c0 }
(SD.bn_v r1 - v r1.[0] + (v r1.[0] - v c1 * 38)) % P.prime;
(==) { }
(SD.bn_v f1 - SD.bn_v f2 + v c0 * pow2 256 - v c0 * 38 + v c1 * pow2 256 - v c1 * 38) % P.prime;
(==) { Lemmas.lemma_fsub4 (SD.bn_v f1) (SD.bn_v f2) (v c0) (v c1) }
(SD.bn_v f1 % P.prime - SD.bn_v f2 % P.prime) % P.prime;
};
out
val mul4: f:felem -> r:felem ->
Pure felem_wide
(requires True)
(ensures fun out ->
SD.bn_v out == SD.bn_v f * SD.bn_v r)
let mul4 f r =
let out = SB.bn_mul f r in
SB.bn_mul_lemma f r;
out
val fmul4: f1:felem -> r:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fmul (SD.bn_v f1 % P.prime) (SD.bn_v r % P.prime))
let fmul4 f1 r =
let tmp = mul4 f1 r in
let out = carry_wide tmp in
Math.Lemmas.lemma_mod_mul_distr_l (SD.bn_v f1) (SD.bn_v r) P.prime;
Math.Lemmas.lemma_mod_mul_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v r) P.prime;
out
//121665 < pow2 17
val fmul14: f1:felem -> f2:uint64 ->
Pure felem
(requires v f2 < pow2 17)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f1 % P.prime * v f2 % P.prime) | false | false | Hacl.Spec.Curve25519.Field64.Core.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fmul14: f1:felem -> f2:uint64 ->
Pure felem
(requires v f2 < pow2 17)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f1 % P.prime * v f2 % P.prime) | [] | Hacl.Spec.Curve25519.Field64.Core.fmul14 | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | f1: Hacl.Spec.Curve25519.Field64.Core.felem -> f2: Lib.IntTypes.uint64
-> Prims.Pure Hacl.Spec.Curve25519.Field64.Core.felem | {
"end_col": 5,
"end_line": 302,
"start_col": 18,
"start_line": 285
} |
Prims.Pure | val fsub4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fsub (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime)) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fsub4 f1 f2 =
let c0, r0 = sub4 f1 f2 in
let c1, r1 = sub1 r0 (c0 *! u64 38) in
let b1 = r1.[0] -. c1 *. u64 38 in
let out = r1.[0] <- b1 in
SD.bn_upd_eval r1 b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r1 - v r1.[0] + v b1) % P.prime;
(==) { lemma_sub1_carry r0 c0 }
(SD.bn_v r1 - v r1.[0] + (v r1.[0] - v c1 * 38)) % P.prime;
(==) { }
(SD.bn_v f1 - SD.bn_v f2 + v c0 * pow2 256 - v c0 * 38 + v c1 * pow2 256 - v c1 * 38) % P.prime;
(==) { Lemmas.lemma_fsub4 (SD.bn_v f1) (SD.bn_v f2) (v c0) (v c1) }
(SD.bn_v f1 % P.prime - SD.bn_v f2 % P.prime) % P.prime;
};
out | val fsub4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fsub (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fsub4 f1 f2 = | false | null | false | let c0, r0 = sub4 f1 f2 in
let c1, r1 = sub1 r0 (c0 *! u64 38) in
let b1 = r1.[ 0 ] -. c1 *. u64 38 in
let out = r1.[ 0 ] <- b1 in
SD.bn_upd_eval r1 b1 0;
calc ( == ) {
SD.bn_v out % P.prime;
( == ) { assert_norm (pow2 0 = 1) }
(SD.bn_v r1 - v r1.[ 0 ] + v b1) % P.prime;
( == ) { lemma_sub1_carry r0 c0 }
(SD.bn_v r1 - v r1.[ 0 ] + (v r1.[ 0 ] - v c1 * 38)) % P.prime;
( == ) { () }
(SD.bn_v f1 - SD.bn_v f2 + v c0 * pow2 256 - v c0 * 38 + v c1 * pow2 256 - v c1 * 38) % P.prime;
( == ) { Lemmas.lemma_fsub4 (SD.bn_v f1) (SD.bn_v f2) (v c0) (v c1) }
(SD.bn_v f1 % P.prime - SD.bn_v f2 % P.prime) % P.prime;
};
out | {
"checked_file": "Hacl.Spec.Curve25519.Field64.Core.fst.checked",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Lib.IntTypes.uint64",
"Prims.unit",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Modulus",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Lib.IntTypes.U64",
"Spec.Curve25519.prime",
"Prims.op_Subtraction",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Prims.pow2",
"Lib.Sequence.op_String_Access",
"Hacl.Spec.Bignum.Definitions.limb",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality",
"Prims.squash",
"Hacl.Spec.Curve25519.Field64.Core.lemma_sub1_carry",
"Hacl.Spec.Curve25519.Field64.Lemmas.lemma_fsub4",
"Hacl.Spec.Bignum.Definitions.bn_upd_eval",
"Lib.Sequence.lseq",
"Prims.l_and",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.upd",
"Lib.Sequence.index",
"Prims.l_Forall",
"Prims.nat",
"Prims.op_LessThanOrEqual",
"Prims.l_imp",
"Prims.op_LessThan",
"Prims.op_disEquality",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.op_String_Assignment",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Subtraction_Dot",
"Lib.IntTypes.op_Star_Dot",
"Lib.IntTypes.u64",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Curve25519.Field64.Core.sub1",
"Lib.IntTypes.op_Star_Bang",
"Hacl.Spec.Curve25519.Field64.Core.sub4"
] | [] | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2)
let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out
val carry_pass: f:felem -> cin:uint64 -> felem
let carry_pass f cin =
let c, r = add1 f (cin *. u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
out
val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38)
let lemma_add1_carry f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
assert (SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) + v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) + v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] + v cin * 38) % pow2 64)
val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime)
let carry_pass_lemma f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
SD.bn_upd_eval r b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r - v r.[0] + v b1) % P.prime;
(==) { lemma_add1_carry f cin }
(SD.bn_v r - v r.[0] + (v r.[0] + v c * 38)) % P.prime;
(==) { }
(SD.bn_v r + v c * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v r) (v c) }
(SD.bn_v r + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v f + v cin * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v f) (v cin) }
(SD.bn_v f + v cin * pow2 256) % P.prime;
}
val carry_wide: f:felem_wide ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f % P.prime)
let carry_wide f =
let c, r0 = mul1_add (sub f 4 4) (u64 38) (sub f 0 4) in
assert (SD.bn_v r0 + v c * pow2 256 == SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38);
SD.bn_eval_bound (sub f 0 4) 4;
SD.bn_eval_bound (sub f 4 4) 4;
SD.bn_eval_bound r0 4;
Lemmas.carry_wide_bound (SD.bn_v r0) (v c) (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4));
let out = carry_pass r0 c in
calc (==) {
SD.bn_v out % P.prime;
(==) { carry_pass_lemma r0 c }
(SD.bn_v r0 + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4)) }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * pow2 256) % P.prime;
(==) { SD.bn_concat_lemma (sub f 0 4) (sub f 4 4) }
SD.bn_v (concat (sub f 0 4) (sub f 4 4)) % P.prime;
(==) { eq_intro f (concat (sub f 0 4) (sub f 4 4)) }
SD.bn_v f % P.prime;
};
out
val add4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f1 + SD.bn_v f2)
let add4 f1 f2 =
let c, out = SB.bn_add f1 f2 in
SB.bn_add_lemma f1 f2;
c, out
val fadd4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fadd (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fadd4 f1 f2 =
let c0, out0 = add4 f1 f2 in
let out = carry_pass out0 c0 in
carry_pass_lemma out0 c0;
assert (SD.bn_v out % P.prime == (SD.bn_v f1 + SD.bn_v f2) % P.prime);
Math.Lemmas.lemma_mod_plus_distr_l (SD.bn_v f1) (SD.bn_v f2) P.prime;
Math.Lemmas.lemma_mod_plus_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v f2) P.prime;
out
val sub4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f1 - SD.bn_v f2)
let sub4 f1 f2 =
let c, out = SB.bn_sub f1 f2 in
SB.bn_sub_lemma f1 f2;
c, out
val lemma_sub1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
v b1 == v r.[0] - v c * 38)
let lemma_sub1_carry f cin =
let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
assert (SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) - v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) - v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] - v cin * 38) % pow2 64)
val fsub4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fsub (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime)) | false | false | Hacl.Spec.Curve25519.Field64.Core.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fsub4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fsub (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime)) | [] | Hacl.Spec.Curve25519.Field64.Core.fsub4 | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | f1: Hacl.Spec.Curve25519.Field64.Core.felem -> f2: Hacl.Spec.Curve25519.Field64.Core.felem
-> Prims.Pure Hacl.Spec.Curve25519.Field64.Core.felem | {
"end_col": 5,
"end_line": 249,
"start_col": 17,
"start_line": 231
} |
Prims.Pure | val carry_wide: f:felem_wide ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f % P.prime) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let carry_wide f =
let c, r0 = mul1_add (sub f 4 4) (u64 38) (sub f 0 4) in
assert (SD.bn_v r0 + v c * pow2 256 == SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38);
SD.bn_eval_bound (sub f 0 4) 4;
SD.bn_eval_bound (sub f 4 4) 4;
SD.bn_eval_bound r0 4;
Lemmas.carry_wide_bound (SD.bn_v r0) (v c) (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4));
let out = carry_pass r0 c in
calc (==) {
SD.bn_v out % P.prime;
(==) { carry_pass_lemma r0 c }
(SD.bn_v r0 + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4)) }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * pow2 256) % P.prime;
(==) { SD.bn_concat_lemma (sub f 0 4) (sub f 4 4) }
SD.bn_v (concat (sub f 0 4) (sub f 4 4)) % P.prime;
(==) { eq_intro f (concat (sub f 0 4) (sub f 4 4)) }
SD.bn_v f % P.prime;
};
out | val carry_wide: f:felem_wide ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f % P.prime)
let carry_wide f = | false | null | false | let c, r0 = mul1_add (sub f 4 4) (u64 38) (sub f 0 4) in
assert (SD.bn_v r0 + v c * pow2 256 == SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38);
SD.bn_eval_bound (sub f 0 4) 4;
SD.bn_eval_bound (sub f 4 4) 4;
SD.bn_eval_bound r0 4;
Lemmas.carry_wide_bound (SD.bn_v r0) (v c) (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4));
let out = carry_pass r0 c in
calc ( == ) {
SD.bn_v out % P.prime;
( == ) { carry_pass_lemma r0 c }
(SD.bn_v r0 + v c * pow2 256) % P.prime;
( == ) { () }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38) % P.prime;
( == ) { Lemmas.lemma_mul_pow256_add (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4)) }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * pow2 256) % P.prime;
( == ) { SD.bn_concat_lemma (sub f 0 4) (sub f 4 4) }
SD.bn_v (concat (sub f 0 4) (sub f 4 4)) % P.prime;
( == ) { eq_intro f (concat (sub f 0 4) (sub f 4 4)) }
SD.bn_v f % P.prime;
};
out | {
"checked_file": "Hacl.Spec.Curve25519.Field64.Core.fst.checked",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem_wide",
"Lib.IntTypes.uint64",
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Prims.unit",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Modulus",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Lib.IntTypes.U64",
"Spec.Curve25519.prime",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"Prims.op_Addition",
"Lib.Sequence.concat",
"Hacl.Spec.Bignum.Definitions.limb",
"Lib.Sequence.sub",
"FStar.Mul.op_Star",
"Prims.pow2",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Hacl.Spec.Curve25519.Field64.Core.carry_pass_lemma",
"Prims.squash",
"Hacl.Spec.Curve25519.Field64.Lemmas.lemma_mul_pow256_add",
"Hacl.Spec.Bignum.Definitions.bn_concat_lemma",
"Lib.Sequence.eq_intro",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Curve25519.Field64.Core.carry_pass",
"Hacl.Spec.Curve25519.Field64.Lemmas.carry_wide_bound",
"Hacl.Spec.Bignum.Definitions.bn_eval_bound",
"Prims._assert",
"FStar.Pervasives.Native.tuple2",
"Lib.IntTypes.int_t",
"Hacl.Spec.Curve25519.Field64.Core.mul1_add",
"Lib.IntTypes.u64"
] | [] | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2)
let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out
val carry_pass: f:felem -> cin:uint64 -> felem
let carry_pass f cin =
let c, r = add1 f (cin *. u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
out
val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38)
let lemma_add1_carry f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
assert (SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) + v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) + v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] + v cin * 38) % pow2 64)
val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime)
let carry_pass_lemma f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
SD.bn_upd_eval r b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r - v r.[0] + v b1) % P.prime;
(==) { lemma_add1_carry f cin }
(SD.bn_v r - v r.[0] + (v r.[0] + v c * 38)) % P.prime;
(==) { }
(SD.bn_v r + v c * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v r) (v c) }
(SD.bn_v r + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v f + v cin * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v f) (v cin) }
(SD.bn_v f + v cin * pow2 256) % P.prime;
}
val carry_wide: f:felem_wide ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f % P.prime) | false | false | Hacl.Spec.Curve25519.Field64.Core.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val carry_wide: f:felem_wide ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f % P.prime) | [] | Hacl.Spec.Curve25519.Field64.Core.carry_wide | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | f: Hacl.Spec.Curve25519.Field64.Core.felem_wide
-> Prims.Pure Hacl.Spec.Curve25519.Field64.Core.felem | {
"end_col": 5,
"end_line": 160,
"start_col": 18,
"start_line": 138
} |
FStar.Pervasives.Lemma | val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let carry_pass_lemma f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
SD.bn_upd_eval r b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r - v r.[0] + v b1) % P.prime;
(==) { lemma_add1_carry f cin }
(SD.bn_v r - v r.[0] + (v r.[0] + v c * 38)) % P.prime;
(==) { }
(SD.bn_v r + v c * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v r) (v c) }
(SD.bn_v r + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v f + v cin * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v f) (v cin) }
(SD.bn_v f + v cin * pow2 256) % P.prime;
} | val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime)
let carry_pass_lemma f cin = | false | null | true | let c, r = add1 f (cin *! u64 38) in
let b1 = r.[ 0 ] +. c *. u64 38 in
let out = r.[ 0 ] <- b1 in
SD.bn_upd_eval r b1 0;
calc ( == ) {
SD.bn_v out % P.prime;
( == ) { assert_norm (pow2 0 = 1) }
(SD.bn_v r - v r.[ 0 ] + v b1) % P.prime;
( == ) { lemma_add1_carry f cin }
(SD.bn_v r - v r.[ 0 ] + (v r.[ 0 ] + v c * 38)) % P.prime;
( == ) { () }
(SD.bn_v r + v c * 38) % P.prime;
( == ) { Lemmas.lemma_mul_pow256_add (SD.bn_v r) (v c) }
(SD.bn_v r + v c * pow2 256) % P.prime;
( == ) { () }
(SD.bn_v f + v cin * 38) % P.prime;
( == ) { Lemmas.lemma_mul_pow256_add (SD.bn_v f) (v cin) }
(SD.bn_v f + v cin * pow2 256) % P.prime;
} | {
"checked_file": "Hacl.Spec.Curve25519.Field64.Core.fst.checked",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Lib.IntTypes.uint64",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Prims.pow2",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Modulus",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Spec.Curve25519.prime",
"Prims.op_Addition",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Prims.op_Subtraction",
"Lib.Sequence.op_String_Access",
"Hacl.Spec.Bignum.Definitions.limb",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Pervasives.assert_norm",
"Prims.op_Equality",
"Prims.squash",
"Hacl.Spec.Curve25519.Field64.Core.lemma_add1_carry",
"Hacl.Spec.Curve25519.Field64.Lemmas.lemma_mul_pow256_add",
"Hacl.Spec.Bignum.Definitions.bn_upd_eval",
"Lib.Sequence.lseq",
"Prims.l_and",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.upd",
"Lib.Sequence.index",
"Prims.l_Forall",
"Prims.nat",
"Prims.op_LessThanOrEqual",
"Prims.l_imp",
"Prims.op_disEquality",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.op_String_Assignment",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Plus_Dot",
"Lib.IntTypes.op_Star_Dot",
"Lib.IntTypes.u64",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Curve25519.Field64.Core.add1",
"Lib.IntTypes.op_Star_Bang"
] | [] | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2)
let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out
val carry_pass: f:felem -> cin:uint64 -> felem
let carry_pass f cin =
let c, r = add1 f (cin *. u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
out
val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38)
let lemma_add1_carry f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
assert (SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) + v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) + v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] + v cin * 38) % pow2 64)
val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime) | false | false | Hacl.Spec.Curve25519.Field64.Core.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime) | [] | Hacl.Spec.Curve25519.Field64.Core.carry_pass_lemma | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
f: Hacl.Spec.Curve25519.Field64.Core.felem ->
cin: Lib.IntTypes.uint64{Lib.IntTypes.v cin * 38 < Prims.pow2 63}
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.Curve25519.Field64.Core.carry_pass f cin) %
Spec.Curve25519.prime ==
(Hacl.Spec.Bignum.Definitions.bn_v f + Lib.IntTypes.v cin * Prims.pow2 256) %
Spec.Curve25519.prime) | {
"end_col": 5,
"end_line": 129,
"start_col": 28,
"start_line": 109
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fragments = list fragment | let fragments = | false | null | false | list fragment | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
"total"
] | [
"Prims.list",
"Steel.ST.Printf.fragment"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg | false | true | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fragments : Type0 | [] | Steel.ST.Printf.fragments | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | Type0 | {
"end_col": 29,
"end_line": 175,
"start_col": 16,
"start_line": 175
} |
|
Prims.Tot | val parse_format_string (s: string) : option fragments | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s) | val parse_format_string (s: string) : option fragments
let parse_format_string (s: string) : option fragments = | false | null | false | parse_format (list_of_string s) | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
"total"
] | [
"Prims.string",
"Steel.ST.Printf.parse_format",
"FStar.String.list_of_string",
"FStar.Pervasives.Native.option",
"Steel.ST.Printf.fragments"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string) | false | true | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val parse_format_string (s: string) : option fragments | [] | Steel.ST.Printf.parse_format_string | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | s: Prims.string -> FStar.Pervasives.Native.option Steel.ST.Printf.fragments | {
"end_col": 35,
"end_line": 247,
"start_col": 4,
"start_line": 247
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fragment_printer =
(acc:list frag_t)
-> STT unit (live_frags acc) (fun _ -> live_frags acc) | let fragment_printer = | false | null | false | acc: list frag_t -> STT unit (live_frags acc) (fun _ -> live_frags acc) | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
"total"
] | [
"Prims.list",
"Steel.ST.Printf.frag_t",
"Prims.unit",
"Steel.ST.Printf.live_frags",
"Steel.Effect.Common.vprop"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract | false | true | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fragment_printer : Type | [] | Steel.ST.Printf.fragment_printer | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | Type | {
"end_col": 56,
"end_line": 361,
"start_col": 2,
"start_line": 360
} |
|
Prims.Tot | val no_inst: #a: _ -> #b: (a -> Type) -> f: (#x: a -> b x) -> unit -> #x: a -> b x | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f | val no_inst: #a: _ -> #b: (a -> Type) -> f: (#x: a -> b x) -> unit -> #x: a -> b x
let no_inst #a (#b: (a -> Type)) (f: (#x: a -> b x)) : unit -> #x: a -> b x = | false | null | false | fun () -> f | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
"total"
] | [
"Prims.unit"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit (live_frag fr) (fun _ -> live_frag fr)
(tb == lmbuffer t l /\
tv == Ghost.erased (Seq.seq t) /\
live_frag fr == A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True)
= [@inline_let] let b' : lmbuffer t l = coerce b in
let v' : Ghost.erased (Seq.seq t) = coerce v in
let p' : Ghost.erased (lmbuffer t l & perm) = Ghost.hide (b', p) in
rewrite (live_frag fr) (A.pts_to #t (fst p') (snd p') v');
f l _ _ (A.ptr_of b');
rewrite (A.pts_to _ _ _) (live_frag fr)
noextract inline_for_extraction
let print_frag (hd: frag_t) : STT unit (live_frag hd) (fun _ -> live_frag hd)
=
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, Lift ((| l, value |), p, v ) |) ->
(match t with
| Bool -> print_lmbuffer_gen print_lmbuffer_bool l value p v
| Char -> print_lmbuffer_gen print_lmbuffer_char l value p v
| String -> print_lmbuffer_gen print_lmbuffer_string l value p v
| U8 -> print_lmbuffer_gen print_lmbuffer_u8 l value p v
| U16 -> print_lmbuffer_gen print_lmbuffer_u16 l value p v
| U32 -> print_lmbuffer_gen print_lmbuffer_u32 l value p v
| U64 -> print_lmbuffer_gen print_lmbuffer_u64 l value p v
| I8 -> print_lmbuffer_gen print_lmbuffer_i8 l value p v
| I16 -> print_lmbuffer_gen print_lmbuffer_i16 l value p v
| I32 -> print_lmbuffer_gen print_lmbuffer_i32 l value p v
| I64 -> print_lmbuffer_gen print_lmbuffer_i64 l value p v
)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: STT unit
(live_frags acc)
(fun _ -> live_frags acc)
= match acc with
| [] -> noop ()
| hd::tl ->
rewrite (live_frags acc) (live_frag hd `star` live_frags tl);
print_frags tl;
print_frag hd;
rewrite (live_frag hd `star` live_frags tl) (live_frags acc) | false | false | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val no_inst: #a: _ -> #b: (a -> Type) -> f: (#x: a -> b x) -> unit -> #x: a -> b x | [] | Steel.ST.Printf.no_inst | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | f: b x -> _: Prims.unit -> b x | {
"end_col": 84,
"end_line": 440,
"start_col": 73,
"start_line": 440
} |
Prims.Tot | val normal (#a: Type) (x: a) : a | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x | val normal (#a: Type) (x: a) : a
let normal (#a: Type) (x: a) : a = | false | null | false | FStar.Pervasives.norm [
iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify
]
x | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
"total"
] | [
"FStar.Pervasives.norm",
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.iota",
"FStar.Pervasives.zeta",
"FStar.Pervasives.delta_attr",
"Prims.string",
"Prims.Nil",
"FStar.Pervasives.delta_only",
"FStar.Pervasives.primops",
"FStar.Pervasives.simplify"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold | false | false | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val normal (#a: Type) (x: a) : a | [] | Steel.ST.Printf.normal | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | x: a -> a | {
"end_col": 6,
"end_line": 351,
"start_col": 2,
"start_line": 344
} |
Prims.Tot | val elim_unit_arrow (#t: _) (f: (unit -> t)) : t | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let elim_unit_arrow #t (f:unit -> t) : t = f () | val elim_unit_arrow (#t: _) (f: (unit -> t)) : t
let elim_unit_arrow #t (f: (unit -> t)) : t = | false | null | false | f () | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
"total"
] | [
"Prims.unit"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit (live_frag fr) (fun _ -> live_frag fr)
(tb == lmbuffer t l /\
tv == Ghost.erased (Seq.seq t) /\
live_frag fr == A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True)
= [@inline_let] let b' : lmbuffer t l = coerce b in
let v' : Ghost.erased (Seq.seq t) = coerce v in
let p' : Ghost.erased (lmbuffer t l & perm) = Ghost.hide (b', p) in
rewrite (live_frag fr) (A.pts_to #t (fst p') (snd p') v');
f l _ _ (A.ptr_of b');
rewrite (A.pts_to _ _ _) (live_frag fr)
noextract inline_for_extraction
let print_frag (hd: frag_t) : STT unit (live_frag hd) (fun _ -> live_frag hd)
=
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, Lift ((| l, value |), p, v ) |) ->
(match t with
| Bool -> print_lmbuffer_gen print_lmbuffer_bool l value p v
| Char -> print_lmbuffer_gen print_lmbuffer_char l value p v
| String -> print_lmbuffer_gen print_lmbuffer_string l value p v
| U8 -> print_lmbuffer_gen print_lmbuffer_u8 l value p v
| U16 -> print_lmbuffer_gen print_lmbuffer_u16 l value p v
| U32 -> print_lmbuffer_gen print_lmbuffer_u32 l value p v
| U64 -> print_lmbuffer_gen print_lmbuffer_u64 l value p v
| I8 -> print_lmbuffer_gen print_lmbuffer_i8 l value p v
| I16 -> print_lmbuffer_gen print_lmbuffer_i16 l value p v
| I32 -> print_lmbuffer_gen print_lmbuffer_i32 l value p v
| I64 -> print_lmbuffer_gen print_lmbuffer_i64 l value p v
)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: STT unit
(live_frags acc)
(fun _ -> live_frags acc)
= match acc with
| [] -> noop ()
| hd::tl ->
rewrite (live_frags acc) (live_frag hd `star` live_frags tl);
print_frags tl;
print_frag hd;
rewrite (live_frag hd `star` live_frags tl) (live_frags acc)
[@@__printf_reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f | false | false | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val elim_unit_arrow (#t: _) (f: (unit -> t)) : t | [] | Steel.ST.Printf.elim_unit_arrow | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | f: (_: Prims.unit -> t) -> t | {
"end_col": 47,
"end_line": 442,
"start_col": 43,
"start_line": 442
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let frag_t = either string (a:arg & arg_t a) | let frag_t = | false | null | false | either string (a: arg & arg_t a) | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
"total"
] | [
"FStar.Pervasives.either",
"Prims.string",
"Prims.dtuple2",
"Steel.ST.Printf.arg",
"Steel.ST.Printf.arg_t"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated | false | true | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val frag_t : Type | [] | Steel.ST.Printf.frag_t | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | Type | {
"end_col": 44,
"end_line": 274,
"start_col": 13,
"start_line": 274
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let format_string = s:string{normal #bool (Some? (parse_format_string s))} | let format_string = | false | null | false | s: string{normal #bool (Some? (parse_format_string s))} | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
"total"
] | [
"Prims.string",
"Prims.b2t",
"Steel.ST.Printf.normal",
"Prims.bool",
"FStar.Pervasives.Native.uu___is_Some",
"Steel.ST.Printf.fragments",
"Steel.ST.Printf.parse_format_string"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit (live_frag fr) (fun _ -> live_frag fr)
(tb == lmbuffer t l /\
tv == Ghost.erased (Seq.seq t) /\
live_frag fr == A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True)
= [@inline_let] let b' : lmbuffer t l = coerce b in
let v' : Ghost.erased (Seq.seq t) = coerce v in
let p' : Ghost.erased (lmbuffer t l & perm) = Ghost.hide (b', p) in
rewrite (live_frag fr) (A.pts_to #t (fst p') (snd p') v');
f l _ _ (A.ptr_of b');
rewrite (A.pts_to _ _ _) (live_frag fr)
noextract inline_for_extraction
let print_frag (hd: frag_t) : STT unit (live_frag hd) (fun _ -> live_frag hd)
=
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, Lift ((| l, value |), p, v ) |) ->
(match t with
| Bool -> print_lmbuffer_gen print_lmbuffer_bool l value p v
| Char -> print_lmbuffer_gen print_lmbuffer_char l value p v
| String -> print_lmbuffer_gen print_lmbuffer_string l value p v
| U8 -> print_lmbuffer_gen print_lmbuffer_u8 l value p v
| U16 -> print_lmbuffer_gen print_lmbuffer_u16 l value p v
| U32 -> print_lmbuffer_gen print_lmbuffer_u32 l value p v
| U64 -> print_lmbuffer_gen print_lmbuffer_u64 l value p v
| I8 -> print_lmbuffer_gen print_lmbuffer_i8 l value p v
| I16 -> print_lmbuffer_gen print_lmbuffer_i16 l value p v
| I32 -> print_lmbuffer_gen print_lmbuffer_i32 l value p v
| I64 -> print_lmbuffer_gen print_lmbuffer_i64 l value p v
)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: STT unit
(live_frags acc)
(fun _ -> live_frags acc)
= match acc with
| [] -> noop ()
| hd::tl ->
rewrite (live_frags acc) (live_frag hd `star` live_frags tl);
print_frags tl;
print_frag hd;
rewrite (live_frag hd `star` live_frags tl) (live_frags acc)
[@@__printf_reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__printf_reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__printf_reduce__]
noextract inline_for_extraction
let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: STT unit (live_frags acc) (fun _ -> live_frags acc)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #p:perm
-> #v:Ghost.erased (Seq.seq (base_typ_as_type t))
-> b:lmbuffer (base_typ_as_type t) l
-> interpret_frags rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
= fun l #p #v b -> aux rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
/// `format_string` : A valid format string is one that can be successfully parsed
[@@__printf_reduce__] | false | true | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val format_string : Type0 | [] | Steel.ST.Printf.format_string | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | Type0 | {
"end_col": 74,
"end_line": 492,
"start_col": 20,
"start_line": 492
} |
|
Prims.Tot | val live_frag (f: frag_t) : vprop | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let live_frag (f: frag_t) : vprop =
live_frag0 f | val live_frag (f: frag_t) : vprop
let live_frag (f: frag_t) : vprop = | false | null | false | live_frag0 f | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
"total"
] | [
"Steel.ST.Printf.frag_t",
"Steel.ST.Printf.live_frag0",
"Steel.Effect.Common.vprop"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract | false | true | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val live_frag (f: frag_t) : vprop | [] | Steel.ST.Printf.live_frag | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | f: Steel.ST.Printf.frag_t -> Steel.Effect.Common.vprop | {
"end_col": 14,
"end_line": 291,
"start_col": 2,
"start_line": 291
} |
Prims.Tot | val printf : s:normal format_string -> normal (interpret_format_string s) | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let printf = intro_normal_f #format_string interpret_format_string printf' | val printf : s:normal format_string -> normal (interpret_format_string s)
let printf = | false | null | false | intro_normal_f #format_string interpret_format_string printf' | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
"total"
] | [
"Steel.ST.Printf.intro_normal_f",
"Steel.ST.Printf.format_string",
"Steel.ST.Printf.interpret_format_string",
"Steel.ST.Printf.printf'"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit (live_frag fr) (fun _ -> live_frag fr)
(tb == lmbuffer t l /\
tv == Ghost.erased (Seq.seq t) /\
live_frag fr == A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True)
= [@inline_let] let b' : lmbuffer t l = coerce b in
let v' : Ghost.erased (Seq.seq t) = coerce v in
let p' : Ghost.erased (lmbuffer t l & perm) = Ghost.hide (b', p) in
rewrite (live_frag fr) (A.pts_to #t (fst p') (snd p') v');
f l _ _ (A.ptr_of b');
rewrite (A.pts_to _ _ _) (live_frag fr)
noextract inline_for_extraction
let print_frag (hd: frag_t) : STT unit (live_frag hd) (fun _ -> live_frag hd)
=
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, Lift ((| l, value |), p, v ) |) ->
(match t with
| Bool -> print_lmbuffer_gen print_lmbuffer_bool l value p v
| Char -> print_lmbuffer_gen print_lmbuffer_char l value p v
| String -> print_lmbuffer_gen print_lmbuffer_string l value p v
| U8 -> print_lmbuffer_gen print_lmbuffer_u8 l value p v
| U16 -> print_lmbuffer_gen print_lmbuffer_u16 l value p v
| U32 -> print_lmbuffer_gen print_lmbuffer_u32 l value p v
| U64 -> print_lmbuffer_gen print_lmbuffer_u64 l value p v
| I8 -> print_lmbuffer_gen print_lmbuffer_i8 l value p v
| I16 -> print_lmbuffer_gen print_lmbuffer_i16 l value p v
| I32 -> print_lmbuffer_gen print_lmbuffer_i32 l value p v
| I64 -> print_lmbuffer_gen print_lmbuffer_i64 l value p v
)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: STT unit
(live_frags acc)
(fun _ -> live_frags acc)
= match acc with
| [] -> noop ()
| hd::tl ->
rewrite (live_frags acc) (live_frag hd `star` live_frags tl);
print_frags tl;
print_frag hd;
rewrite (live_frag hd `star` live_frags tl) (live_frags acc)
[@@__printf_reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__printf_reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__printf_reduce__]
noextract inline_for_extraction
let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: STT unit (live_frags acc) (fun _ -> live_frags acc)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #p:perm
-> #v:Ghost.erased (Seq.seq (base_typ_as_type t))
-> b:lmbuffer (base_typ_as_type t) l
-> interpret_frags rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
= fun l #p #v b -> aux rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
/// `format_string` : A valid format string is one that can be successfully parsed
[@@__printf_reduce__]
noextract
let format_string = s:string{normal #bool (Some? (parse_format_string s))}
/// `interpret_format_string` parses a string into fragments and then
/// interprets it as a type
[@@__printf_reduce__]
noextract
let interpret_format_string (s:format_string) : Type =
interpret_frags (Some?.v (parse_format_string s)) []
/// `printf'`: Almost there ... this has a variadic type
/// and calls the actual printers for all its arguments.
///
/// Note, the `normalize_term` in its body is crucial. It's what
/// allows the term to be specialized at extraction time.
noextract inline_for_extraction
let printf' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] print_frags)
/// `intro_normal_f`: a technical gadget to introduce
/// implicit normalization in the domain and co-domain of a function type
noextract inline_for_extraction
let intro_normal_f (#a:Type) (b: (a -> Type)) (f:(x:a -> b x))
: (x:(normal a) -> normal (b x))
= f
/// `printf`: The main function has type
/// `s:normal format_string -> normal (interpret_format_string s)`
/// Note:
/// This is the type F* infers for it and it is best to leave it that way
/// rather then writing it down and asking F* to re-check what it inferred.
///
/// Annotating it results in a needless additional proof obligation to
/// equate types after they are partially reduced, which is pointless.
noextract inline_for_extraction | false | false | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val printf : s:normal format_string -> normal (interpret_format_string s) | [] | Steel.ST.Printf.printf | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | s: Steel.ST.Printf.normal Steel.ST.Printf.format_string
-> Steel.ST.Printf.normal (Steel.ST.Printf.interpret_format_string s) | {
"end_col": 74,
"end_line": 529,
"start_col": 13,
"start_line": 529
} |
Prims.Tot | val skip : s:normal format_string -> normal (interpret_format_string s) | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let skip = intro_normal_f #format_string interpret_format_string skip' | val skip : s:normal format_string -> normal (interpret_format_string s)
let skip = | false | null | false | intro_normal_f #format_string interpret_format_string skip' | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
"total"
] | [
"Steel.ST.Printf.intro_normal_f",
"Steel.ST.Printf.format_string",
"Steel.ST.Printf.interpret_format_string",
"Steel.ST.Printf.skip'"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit (live_frag fr) (fun _ -> live_frag fr)
(tb == lmbuffer t l /\
tv == Ghost.erased (Seq.seq t) /\
live_frag fr == A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True)
= [@inline_let] let b' : lmbuffer t l = coerce b in
let v' : Ghost.erased (Seq.seq t) = coerce v in
let p' : Ghost.erased (lmbuffer t l & perm) = Ghost.hide (b', p) in
rewrite (live_frag fr) (A.pts_to #t (fst p') (snd p') v');
f l _ _ (A.ptr_of b');
rewrite (A.pts_to _ _ _) (live_frag fr)
noextract inline_for_extraction
let print_frag (hd: frag_t) : STT unit (live_frag hd) (fun _ -> live_frag hd)
=
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, Lift ((| l, value |), p, v ) |) ->
(match t with
| Bool -> print_lmbuffer_gen print_lmbuffer_bool l value p v
| Char -> print_lmbuffer_gen print_lmbuffer_char l value p v
| String -> print_lmbuffer_gen print_lmbuffer_string l value p v
| U8 -> print_lmbuffer_gen print_lmbuffer_u8 l value p v
| U16 -> print_lmbuffer_gen print_lmbuffer_u16 l value p v
| U32 -> print_lmbuffer_gen print_lmbuffer_u32 l value p v
| U64 -> print_lmbuffer_gen print_lmbuffer_u64 l value p v
| I8 -> print_lmbuffer_gen print_lmbuffer_i8 l value p v
| I16 -> print_lmbuffer_gen print_lmbuffer_i16 l value p v
| I32 -> print_lmbuffer_gen print_lmbuffer_i32 l value p v
| I64 -> print_lmbuffer_gen print_lmbuffer_i64 l value p v
)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: STT unit
(live_frags acc)
(fun _ -> live_frags acc)
= match acc with
| [] -> noop ()
| hd::tl ->
rewrite (live_frags acc) (live_frag hd `star` live_frags tl);
print_frags tl;
print_frag hd;
rewrite (live_frag hd `star` live_frags tl) (live_frags acc)
[@@__printf_reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__printf_reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__printf_reduce__]
noextract inline_for_extraction
let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: STT unit (live_frags acc) (fun _ -> live_frags acc)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #p:perm
-> #v:Ghost.erased (Seq.seq (base_typ_as_type t))
-> b:lmbuffer (base_typ_as_type t) l
-> interpret_frags rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
= fun l #p #v b -> aux rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
/// `format_string` : A valid format string is one that can be successfully parsed
[@@__printf_reduce__]
noextract
let format_string = s:string{normal #bool (Some? (parse_format_string s))}
/// `interpret_format_string` parses a string into fragments and then
/// interprets it as a type
[@@__printf_reduce__]
noextract
let interpret_format_string (s:format_string) : Type =
interpret_frags (Some?.v (parse_format_string s)) []
/// `printf'`: Almost there ... this has a variadic type
/// and calls the actual printers for all its arguments.
///
/// Note, the `normalize_term` in its body is crucial. It's what
/// allows the term to be specialized at extraction time.
noextract inline_for_extraction
let printf' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] print_frags)
/// `intro_normal_f`: a technical gadget to introduce
/// implicit normalization in the domain and co-domain of a function type
noextract inline_for_extraction
let intro_normal_f (#a:Type) (b: (a -> Type)) (f:(x:a -> b x))
: (x:(normal a) -> normal (b x))
= f
/// `printf`: The main function has type
/// `s:normal format_string -> normal (interpret_format_string s)`
/// Note:
/// This is the type F* infers for it and it is best to leave it that way
/// rather then writing it down and asking F* to re-check what it inferred.
///
/// Annotating it results in a needless additional proof obligation to
/// equate types after they are partially reduced, which is pointless.
noextract inline_for_extraction
val printf : s:normal format_string -> normal (interpret_format_string s)
let printf = intro_normal_f #format_string interpret_format_string printf'
/// `skip`: We also provide `skip`, a function that has the same type as printf
/// but normalizes to `()`, i.e., it prints nothing. This is useful for conditional
/// printing in debug code, for instance.
noextract inline_for_extraction
let skip' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] (fun _ -> noop ()))
noextract inline_for_extraction | false | false | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val skip : s:normal format_string -> normal (interpret_format_string s) | [] | Steel.ST.Printf.skip | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | s: Steel.ST.Printf.normal Steel.ST.Printf.format_string
-> Steel.ST.Printf.normal (Steel.ST.Printf.interpret_format_string s) | {
"end_col": 70,
"end_line": 543,
"start_col": 11,
"start_line": 543
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
} | let lmbuffer a l = | false | null | false | b: A.array a {A.length b == U32.v l} | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
"total"
] | [
"FStar.UInt32.t",
"Steel.ST.Array.array",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Steel.ST.Array.length",
"FStar.UInt32.v"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction | false | true | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lmbuffer : a: Type0 -> l: FStar.UInt32.t -> Type0 | [] | Steel.ST.Printf.lmbuffer | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | a: Type0 -> l: FStar.UInt32.t -> Type0 | {
"end_col": 5,
"end_line": 72,
"start_col": 4,
"start_line": 70
} |
|
Prims.Tot | val base_typ_as_type (b: base_typ) : Type0 | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t | val base_typ_as_type (b: base_typ) : Type0
let base_typ_as_type (b: base_typ) : Type0 = | false | null | false | match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
"total"
] | [
"Steel.ST.Printf.base_typ",
"Prims.bool",
"FStar.String.char",
"Prims.string",
"FStar.UInt8.t",
"FStar.UInt16.t",
"FStar.UInt32.t",
"FStar.UInt64.t",
"FStar.Int8.t",
"FStar.Int16.t",
"FStar.Int32.t",
"FStar.Int64.t"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract | false | true | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val base_typ_as_type (b: base_typ) : Type0 | [] | Steel.ST.Printf.base_typ_as_type | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | b: Steel.ST.Printf.base_typ -> Type0 | {
"end_col": 27,
"end_line": 164,
"start_col": 2,
"start_line": 153
} |
Prims.Tot | val intro_normal_f (#a: Type) (b: (a -> Type)) (f: (x: a -> b x)) : (x: (normal a) -> normal (b x)) | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let intro_normal_f (#a:Type) (b: (a -> Type)) (f:(x:a -> b x))
: (x:(normal a) -> normal (b x))
= f | val intro_normal_f (#a: Type) (b: (a -> Type)) (f: (x: a -> b x)) : (x: (normal a) -> normal (b x))
let intro_normal_f (#a: Type) (b: (a -> Type)) (f: (x: a -> b x)) : (x: (normal a) -> normal (b x)) = | false | null | false | f | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
"total"
] | [
"Steel.ST.Printf.normal"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit (live_frag fr) (fun _ -> live_frag fr)
(tb == lmbuffer t l /\
tv == Ghost.erased (Seq.seq t) /\
live_frag fr == A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True)
= [@inline_let] let b' : lmbuffer t l = coerce b in
let v' : Ghost.erased (Seq.seq t) = coerce v in
let p' : Ghost.erased (lmbuffer t l & perm) = Ghost.hide (b', p) in
rewrite (live_frag fr) (A.pts_to #t (fst p') (snd p') v');
f l _ _ (A.ptr_of b');
rewrite (A.pts_to _ _ _) (live_frag fr)
noextract inline_for_extraction
let print_frag (hd: frag_t) : STT unit (live_frag hd) (fun _ -> live_frag hd)
=
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, Lift ((| l, value |), p, v ) |) ->
(match t with
| Bool -> print_lmbuffer_gen print_lmbuffer_bool l value p v
| Char -> print_lmbuffer_gen print_lmbuffer_char l value p v
| String -> print_lmbuffer_gen print_lmbuffer_string l value p v
| U8 -> print_lmbuffer_gen print_lmbuffer_u8 l value p v
| U16 -> print_lmbuffer_gen print_lmbuffer_u16 l value p v
| U32 -> print_lmbuffer_gen print_lmbuffer_u32 l value p v
| U64 -> print_lmbuffer_gen print_lmbuffer_u64 l value p v
| I8 -> print_lmbuffer_gen print_lmbuffer_i8 l value p v
| I16 -> print_lmbuffer_gen print_lmbuffer_i16 l value p v
| I32 -> print_lmbuffer_gen print_lmbuffer_i32 l value p v
| I64 -> print_lmbuffer_gen print_lmbuffer_i64 l value p v
)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: STT unit
(live_frags acc)
(fun _ -> live_frags acc)
= match acc with
| [] -> noop ()
| hd::tl ->
rewrite (live_frags acc) (live_frag hd `star` live_frags tl);
print_frags tl;
print_frag hd;
rewrite (live_frag hd `star` live_frags tl) (live_frags acc)
[@@__printf_reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__printf_reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__printf_reduce__]
noextract inline_for_extraction
let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: STT unit (live_frags acc) (fun _ -> live_frags acc)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #p:perm
-> #v:Ghost.erased (Seq.seq (base_typ_as_type t))
-> b:lmbuffer (base_typ_as_type t) l
-> interpret_frags rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
= fun l #p #v b -> aux rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
/// `format_string` : A valid format string is one that can be successfully parsed
[@@__printf_reduce__]
noextract
let format_string = s:string{normal #bool (Some? (parse_format_string s))}
/// `interpret_format_string` parses a string into fragments and then
/// interprets it as a type
[@@__printf_reduce__]
noextract
let interpret_format_string (s:format_string) : Type =
interpret_frags (Some?.v (parse_format_string s)) []
/// `printf'`: Almost there ... this has a variadic type
/// and calls the actual printers for all its arguments.
///
/// Note, the `normalize_term` in its body is crucial. It's what
/// allows the term to be specialized at extraction time.
noextract inline_for_extraction
let printf' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] print_frags)
/// `intro_normal_f`: a technical gadget to introduce
/// implicit normalization in the domain and co-domain of a function type
noextract inline_for_extraction
let intro_normal_f (#a:Type) (b: (a -> Type)) (f:(x:a -> b x)) | false | false | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val intro_normal_f (#a: Type) (b: (a -> Type)) (f: (x: a -> b x)) : (x: (normal a) -> normal (b x)) | [] | Steel.ST.Printf.intro_normal_f | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | b: (_: a -> Type) -> f: (x: a -> b x) -> x: Steel.ST.Printf.normal a -> Steel.ST.Printf.normal (b x) | {
"end_col": 5,
"end_line": 517,
"start_col": 4,
"start_line": 517
} |
Prims.Tot | val live_frags (l: list frag_t) : vprop | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q | val live_frags (l: list frag_t) : vprop
let rec live_frags (l: list frag_t) : vprop = | false | null | false | match l with
| [] -> emp
| a :: q -> (live_frag a) `star` (live_frags q) | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
"total"
] | [
"Prims.list",
"Steel.ST.Printf.frag_t",
"Steel.Effect.Common.emp",
"Steel.Effect.Common.star",
"Steel.ST.Printf.live_frag",
"Steel.ST.Printf.live_frags",
"Steel.Effect.Common.vprop"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract | false | true | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val live_frags (l: list frag_t) : vprop | [
"recursion"
] | Steel.ST.Printf.live_frags | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | l: Prims.list Steel.ST.Printf.frag_t -> Steel.Effect.Common.vprop | {
"end_col": 45,
"end_line": 298,
"start_col": 2,
"start_line": 296
} |
Prims.Tot | val live_frag0 (f: frag_t) : vprop | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v) | val live_frag0 (f: frag_t) : vprop
let live_frag0 (f: frag_t) : vprop = | false | null | false | match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _ , _ |) -> emp
| (| Any , _ |) -> emp
| (| Array _ , Lift ((| _ , b |), p, v) |) -> A.pts_to b p v) | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
"total"
] | [
"Steel.ST.Printf.frag_t",
"Prims.string",
"Steel.Effect.Common.emp",
"Prims.dtuple2",
"Steel.ST.Printf.arg",
"Steel.ST.Printf.arg_t",
"Steel.ST.Printf.base_typ",
"Steel.ST.Printf.Base",
"Steel.ST.Printf.Any",
"FStar.UInt32.t",
"Steel.ST.Printf.lmbuffer",
"Steel.ST.Printf.base_typ_as_type",
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Steel.ST.Array.pts_to",
"FStar.Ghost.reveal",
"Steel.Effect.Common.vprop"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract | false | true | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val live_frag0 (f: frag_t) : vprop | [] | Steel.ST.Printf.live_frag0 | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | f: Steel.ST.Printf.frag_t -> Steel.Effect.Common.vprop | {
"end_col": 64,
"end_line": 286,
"start_col": 2,
"start_line": 280
} |
Prims.Tot | val arg_t (a: arg) : Type u#1 | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a) | val arg_t (a: arg) : Type u#1
let rec arg_t (a: arg) : Type u#1 = | false | null | false | match a with
| Base t -> lift (base_typ_as_type t)
| Array t ->
lift ((l: UInt32.t & lmbuffer (base_typ_as_type t) l) &
perm &
Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a: Type0 & (a -> StTrivial unit) & a) | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
"total"
] | [
"Steel.ST.Printf.arg",
"Steel.ST.Printf.base_typ",
"Steel.ST.Printf.lift",
"Steel.ST.Printf.base_typ_as_type",
"FStar.Pervasives.Native.tuple3",
"Prims.dtuple2",
"FStar.UInt32.t",
"Steel.ST.Printf.lmbuffer",
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"FStar.Pervasives.dtuple3",
"Prims.unit"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract | false | true | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val arg_t (a: arg) : Type u#1 | [
"recursion"
] | Steel.ST.Printf.arg_t | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | a: Steel.ST.Printf.arg -> Type | {
"end_col": 48,
"end_line": 270,
"start_col": 2,
"start_line": 267
} |
Prims.Tot | val coerce (x: 'a{'a == 'b}) : 'b | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let coerce (x:'a{'a == 'b}) : 'b = x | val coerce (x: 'a{'a == 'b}) : 'b
let coerce (x: 'a{'a == 'b}) : 'b = | false | null | false | x | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
"total"
] | [
"Prims.eq2"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types | false | false | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val coerce (x: 'a{'a == 'b}) : 'b | [] | Steel.ST.Printf.coerce | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | x: 'a{'a == 'b} -> 'b | {
"end_col": 36,
"end_line": 355,
"start_col": 35,
"start_line": 355
} |
Prims.Tot | val parse_format (s: list char) : Tot (option fragments) (decreases (L.length s)) | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s') | val parse_format (s: list char) : Tot (option fragments) (decreases (L.length s))
let rec parse_format (s: list char) : Tot (option fragments) (decreases (L.length s)) = | false | null | false | let add_dir (d: arg) (ods: option fragments) =
match ods with
| None -> None
| Some ds -> Some (Interpolate d :: ds)
in
let head_buffer (ods: option fragments) =
match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c: char) (ods: option fragments) =
match ods with
| Some (Frag s :: rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
| '%' :: 'a' :: s' -> add_dir Any (parse_format s')
| '%' :: 'x' :: s' -> head_buffer (parse_format ('%' :: s'))
| '%' :: 'u' :: s' ->
(match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None)
| '%' :: c :: s' ->
(match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None)
| c :: s' -> cons_frag c (parse_format s') | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
"total",
""
] | [
"Prims.list",
"FStar.String.char",
"FStar.Pervasives.Native.Some",
"Steel.ST.Printf.fragments",
"Prims.Nil",
"Steel.ST.Printf.fragment",
"FStar.Pervasives.Native.None",
"Steel.ST.Printf.Any",
"Steel.ST.Printf.parse_format",
"Prims.Cons",
"Steel.ST.Printf.Base",
"Steel.ST.Printf.U8",
"Steel.ST.Printf.U16",
"Steel.ST.Printf.U32",
"Steel.ST.Printf.U64",
"FStar.Pervasives.Native.option",
"Steel.ST.Printf.Bool",
"Steel.ST.Printf.Char",
"Steel.ST.Printf.String",
"Steel.ST.Printf.I8",
"Steel.ST.Printf.I16",
"Steel.ST.Printf.I32",
"Steel.ST.Printf.I64",
"FStar.Char.char",
"Prims.string",
"Steel.ST.Printf.Frag",
"FStar.String.string_of_list",
"FStar.String.list_of_string",
"Steel.ST.Printf.base_typ",
"Steel.ST.Printf.Interpolate",
"Steel.ST.Printf.Array",
"Steel.ST.Printf.arg"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments) | false | true | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val parse_format (s: list char) : Tot (option fragments) (decreases (L.length s)) | [
"recursion"
] | Steel.ST.Printf.parse_format | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | s: Prims.list FStar.String.char
-> Prims.Tot (FStar.Pervasives.Native.option Steel.ST.Printf.fragments) | {
"end_col": 34,
"end_line": 238,
"start_col": 2,
"start_line": 186
} |
Prims.Tot | val printf' (s: format_string) : interpret_format_string s | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let printf' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] print_frags) | val printf' (s: format_string) : interpret_format_string s
let printf' (s: format_string) : interpret_format_string s = | false | null | false | normalize_term (match parse_format_string s with | Some frags -> aux frags [] print_frags) | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
"total"
] | [
"Steel.ST.Printf.format_string",
"FStar.Pervasives.normalize_term",
"Steel.ST.Printf.interpret_format_string",
"Steel.ST.Printf.parse_format_string",
"Steel.ST.Printf.fragments",
"Steel.ST.Printf.aux",
"Prims.Nil",
"Steel.ST.Printf.frag_t",
"Steel.ST.Printf.print_frags"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit (live_frag fr) (fun _ -> live_frag fr)
(tb == lmbuffer t l /\
tv == Ghost.erased (Seq.seq t) /\
live_frag fr == A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True)
= [@inline_let] let b' : lmbuffer t l = coerce b in
let v' : Ghost.erased (Seq.seq t) = coerce v in
let p' : Ghost.erased (lmbuffer t l & perm) = Ghost.hide (b', p) in
rewrite (live_frag fr) (A.pts_to #t (fst p') (snd p') v');
f l _ _ (A.ptr_of b');
rewrite (A.pts_to _ _ _) (live_frag fr)
noextract inline_for_extraction
let print_frag (hd: frag_t) : STT unit (live_frag hd) (fun _ -> live_frag hd)
=
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, Lift ((| l, value |), p, v ) |) ->
(match t with
| Bool -> print_lmbuffer_gen print_lmbuffer_bool l value p v
| Char -> print_lmbuffer_gen print_lmbuffer_char l value p v
| String -> print_lmbuffer_gen print_lmbuffer_string l value p v
| U8 -> print_lmbuffer_gen print_lmbuffer_u8 l value p v
| U16 -> print_lmbuffer_gen print_lmbuffer_u16 l value p v
| U32 -> print_lmbuffer_gen print_lmbuffer_u32 l value p v
| U64 -> print_lmbuffer_gen print_lmbuffer_u64 l value p v
| I8 -> print_lmbuffer_gen print_lmbuffer_i8 l value p v
| I16 -> print_lmbuffer_gen print_lmbuffer_i16 l value p v
| I32 -> print_lmbuffer_gen print_lmbuffer_i32 l value p v
| I64 -> print_lmbuffer_gen print_lmbuffer_i64 l value p v
)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: STT unit
(live_frags acc)
(fun _ -> live_frags acc)
= match acc with
| [] -> noop ()
| hd::tl ->
rewrite (live_frags acc) (live_frag hd `star` live_frags tl);
print_frags tl;
print_frag hd;
rewrite (live_frag hd `star` live_frags tl) (live_frags acc)
[@@__printf_reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__printf_reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__printf_reduce__]
noextract inline_for_extraction
let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: STT unit (live_frags acc) (fun _ -> live_frags acc)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #p:perm
-> #v:Ghost.erased (Seq.seq (base_typ_as_type t))
-> b:lmbuffer (base_typ_as_type t) l
-> interpret_frags rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
= fun l #p #v b -> aux rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
/// `format_string` : A valid format string is one that can be successfully parsed
[@@__printf_reduce__]
noextract
let format_string = s:string{normal #bool (Some? (parse_format_string s))}
/// `interpret_format_string` parses a string into fragments and then
/// interprets it as a type
[@@__printf_reduce__]
noextract
let interpret_format_string (s:format_string) : Type =
interpret_frags (Some?.v (parse_format_string s)) []
/// `printf'`: Almost there ... this has a variadic type
/// and calls the actual printers for all its arguments.
///
/// Note, the `normalize_term` in its body is crucial. It's what
/// allows the term to be specialized at extraction time.
noextract inline_for_extraction | false | false | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val printf' (s: format_string) : interpret_format_string s | [] | Steel.ST.Printf.printf' | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | s: Steel.ST.Printf.format_string -> Steel.ST.Printf.interpret_format_string s | {
"end_col": 45,
"end_line": 510,
"start_col": 2,
"start_line": 508
} |
Prims.Tot | val interpret_frags (l: fragments) (acc: list frag_t) : Type u#1 | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc) | val interpret_frags (l: fragments) (acc: list frag_t) : Type u#1
let rec interpret_frags (l: fragments) (acc: list frag_t) : Type u#1 = | false | null | false | match l with
| [] -> lift u#0 u#1 unit -> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
x: base_typ_as_type t -> interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
l: UInt32.t ->
#p: perm ->
#v: Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b: lmbuffer (base_typ_as_type t) l
-> interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a: Type0 -> p: (a -> StTrivial unit) -> x: a
-> interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args -> interpret_frags args (Inl s :: acc) | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
"total"
] | [
"Steel.ST.Printf.fragments",
"Prims.list",
"Steel.ST.Printf.frag_t",
"Steel.ST.Printf.lift",
"Prims.unit",
"Steel.ST.Printf.live_frags",
"Steel.Effect.Common.vprop",
"Steel.ST.Printf.base_typ",
"Steel.ST.Printf.fragment",
"Steel.ST.Printf.base_typ_as_type",
"Steel.ST.Printf.interpret_frags",
"Prims.Cons",
"FStar.Pervasives.Inr",
"Prims.string",
"Prims.dtuple2",
"Steel.ST.Printf.arg",
"Steel.ST.Printf.arg_t",
"Prims.Mkdtuple2",
"Steel.ST.Printf.Base",
"Steel.ST.Printf.Lift",
"FStar.UInt32.t",
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Steel.ST.Printf.lmbuffer",
"Steel.ST.Printf.Array",
"FStar.Pervasives.Native.tuple3",
"FStar.Pervasives.Native.Mktuple3",
"Steel.ST.Printf.Any",
"FStar.Pervasives.Mkdtuple3",
"FStar.Pervasives.Inl"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract | false | true | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val interpret_frags (l: fragments) (acc: list frag_t) : Type u#1 | [
"recursion"
] | Steel.ST.Printf.interpret_frags | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | l: Steel.ST.Printf.fragments -> acc: Prims.list Steel.ST.Printf.frag_t -> Type | {
"end_col": 39,
"end_line": 338,
"start_col": 2,
"start_line": 306
} |
Prims.Tot | val skip' (s: format_string) : interpret_format_string s | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let skip' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] (fun _ -> noop ())) | val skip' (s: format_string) : interpret_format_string s
let skip' (s: format_string) : interpret_format_string s = | false | null | false | normalize_term (match parse_format_string s with | Some frags -> aux frags [] (fun _ -> noop ())) | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
"total"
] | [
"Steel.ST.Printf.format_string",
"FStar.Pervasives.normalize_term",
"Steel.ST.Printf.interpret_format_string",
"Steel.ST.Printf.parse_format_string",
"Steel.ST.Printf.fragments",
"Steel.ST.Printf.aux",
"Prims.Nil",
"Steel.ST.Printf.frag_t",
"Prims.list",
"Steel.ST.Util.noop",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Prims.unit"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit (live_frag fr) (fun _ -> live_frag fr)
(tb == lmbuffer t l /\
tv == Ghost.erased (Seq.seq t) /\
live_frag fr == A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True)
= [@inline_let] let b' : lmbuffer t l = coerce b in
let v' : Ghost.erased (Seq.seq t) = coerce v in
let p' : Ghost.erased (lmbuffer t l & perm) = Ghost.hide (b', p) in
rewrite (live_frag fr) (A.pts_to #t (fst p') (snd p') v');
f l _ _ (A.ptr_of b');
rewrite (A.pts_to _ _ _) (live_frag fr)
noextract inline_for_extraction
let print_frag (hd: frag_t) : STT unit (live_frag hd) (fun _ -> live_frag hd)
=
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, Lift ((| l, value |), p, v ) |) ->
(match t with
| Bool -> print_lmbuffer_gen print_lmbuffer_bool l value p v
| Char -> print_lmbuffer_gen print_lmbuffer_char l value p v
| String -> print_lmbuffer_gen print_lmbuffer_string l value p v
| U8 -> print_lmbuffer_gen print_lmbuffer_u8 l value p v
| U16 -> print_lmbuffer_gen print_lmbuffer_u16 l value p v
| U32 -> print_lmbuffer_gen print_lmbuffer_u32 l value p v
| U64 -> print_lmbuffer_gen print_lmbuffer_u64 l value p v
| I8 -> print_lmbuffer_gen print_lmbuffer_i8 l value p v
| I16 -> print_lmbuffer_gen print_lmbuffer_i16 l value p v
| I32 -> print_lmbuffer_gen print_lmbuffer_i32 l value p v
| I64 -> print_lmbuffer_gen print_lmbuffer_i64 l value p v
)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: STT unit
(live_frags acc)
(fun _ -> live_frags acc)
= match acc with
| [] -> noop ()
| hd::tl ->
rewrite (live_frags acc) (live_frag hd `star` live_frags tl);
print_frags tl;
print_frag hd;
rewrite (live_frag hd `star` live_frags tl) (live_frags acc)
[@@__printf_reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__printf_reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__printf_reduce__]
noextract inline_for_extraction
let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: STT unit (live_frags acc) (fun _ -> live_frags acc)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #p:perm
-> #v:Ghost.erased (Seq.seq (base_typ_as_type t))
-> b:lmbuffer (base_typ_as_type t) l
-> interpret_frags rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
= fun l #p #v b -> aux rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
/// `format_string` : A valid format string is one that can be successfully parsed
[@@__printf_reduce__]
noextract
let format_string = s:string{normal #bool (Some? (parse_format_string s))}
/// `interpret_format_string` parses a string into fragments and then
/// interprets it as a type
[@@__printf_reduce__]
noextract
let interpret_format_string (s:format_string) : Type =
interpret_frags (Some?.v (parse_format_string s)) []
/// `printf'`: Almost there ... this has a variadic type
/// and calls the actual printers for all its arguments.
///
/// Note, the `normalize_term` in its body is crucial. It's what
/// allows the term to be specialized at extraction time.
noextract inline_for_extraction
let printf' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] print_frags)
/// `intro_normal_f`: a technical gadget to introduce
/// implicit normalization in the domain and co-domain of a function type
noextract inline_for_extraction
let intro_normal_f (#a:Type) (b: (a -> Type)) (f:(x:a -> b x))
: (x:(normal a) -> normal (b x))
= f
/// `printf`: The main function has type
/// `s:normal format_string -> normal (interpret_format_string s)`
/// Note:
/// This is the type F* infers for it and it is best to leave it that way
/// rather then writing it down and asking F* to re-check what it inferred.
///
/// Annotating it results in a needless additional proof obligation to
/// equate types after they are partially reduced, which is pointless.
noextract inline_for_extraction
val printf : s:normal format_string -> normal (interpret_format_string s)
let printf = intro_normal_f #format_string interpret_format_string printf'
/// `skip`: We also provide `skip`, a function that has the same type as printf
/// but normalizes to `()`, i.e., it prints nothing. This is useful for conditional
/// printing in debug code, for instance.
noextract inline_for_extraction | false | false | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val skip' (s: format_string) : interpret_format_string s | [] | Steel.ST.Printf.skip' | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | s: Steel.ST.Printf.format_string -> Steel.ST.Printf.interpret_format_string s | {
"end_col": 52,
"end_line": 539,
"start_col": 2,
"start_line": 537
} |
Steel.ST.Effect.STT | val test2_printf (x: (int * int)) (print_pair: ((int * int) -> StTrivial unit))
: STT unit emp (fun _ -> emp) | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let test2_printf (x:(int * int)) (print_pair:(int * int) -> StTrivial unit)
: STT unit emp (fun _ -> emp)
= printf "Hello pair %a" print_pair x done | val test2_printf (x: (int * int)) (print_pair: ((int * int) -> StTrivial unit))
: STT unit emp (fun _ -> emp)
let test2_printf (x: (int * int)) (print_pair: ((int * int) -> StTrivial unit))
: STT unit emp (fun _ -> emp) = | true | null | false | printf "Hello pair %a" print_pair x done | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [] | [
"FStar.Pervasives.Native.tuple2",
"Prims.int",
"Prims.unit",
"Steel.ST.Printf.printf",
"Steel.ST.Printf.done",
"Steel.Effect.Common.emp",
"Steel.Effect.Common.vprop"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit (live_frag fr) (fun _ -> live_frag fr)
(tb == lmbuffer t l /\
tv == Ghost.erased (Seq.seq t) /\
live_frag fr == A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True)
= [@inline_let] let b' : lmbuffer t l = coerce b in
let v' : Ghost.erased (Seq.seq t) = coerce v in
let p' : Ghost.erased (lmbuffer t l & perm) = Ghost.hide (b', p) in
rewrite (live_frag fr) (A.pts_to #t (fst p') (snd p') v');
f l _ _ (A.ptr_of b');
rewrite (A.pts_to _ _ _) (live_frag fr)
noextract inline_for_extraction
let print_frag (hd: frag_t) : STT unit (live_frag hd) (fun _ -> live_frag hd)
=
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, Lift ((| l, value |), p, v ) |) ->
(match t with
| Bool -> print_lmbuffer_gen print_lmbuffer_bool l value p v
| Char -> print_lmbuffer_gen print_lmbuffer_char l value p v
| String -> print_lmbuffer_gen print_lmbuffer_string l value p v
| U8 -> print_lmbuffer_gen print_lmbuffer_u8 l value p v
| U16 -> print_lmbuffer_gen print_lmbuffer_u16 l value p v
| U32 -> print_lmbuffer_gen print_lmbuffer_u32 l value p v
| U64 -> print_lmbuffer_gen print_lmbuffer_u64 l value p v
| I8 -> print_lmbuffer_gen print_lmbuffer_i8 l value p v
| I16 -> print_lmbuffer_gen print_lmbuffer_i16 l value p v
| I32 -> print_lmbuffer_gen print_lmbuffer_i32 l value p v
| I64 -> print_lmbuffer_gen print_lmbuffer_i64 l value p v
)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: STT unit
(live_frags acc)
(fun _ -> live_frags acc)
= match acc with
| [] -> noop ()
| hd::tl ->
rewrite (live_frags acc) (live_frag hd `star` live_frags tl);
print_frags tl;
print_frag hd;
rewrite (live_frag hd `star` live_frags tl) (live_frags acc)
[@@__printf_reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__printf_reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__printf_reduce__]
noextract inline_for_extraction
let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: STT unit (live_frags acc) (fun _ -> live_frags acc)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #p:perm
-> #v:Ghost.erased (Seq.seq (base_typ_as_type t))
-> b:lmbuffer (base_typ_as_type t) l
-> interpret_frags rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
= fun l #p #v b -> aux rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
/// `format_string` : A valid format string is one that can be successfully parsed
[@@__printf_reduce__]
noextract
let format_string = s:string{normal #bool (Some? (parse_format_string s))}
/// `interpret_format_string` parses a string into fragments and then
/// interprets it as a type
[@@__printf_reduce__]
noextract
let interpret_format_string (s:format_string) : Type =
interpret_frags (Some?.v (parse_format_string s)) []
/// `printf'`: Almost there ... this has a variadic type
/// and calls the actual printers for all its arguments.
///
/// Note, the `normalize_term` in its body is crucial. It's what
/// allows the term to be specialized at extraction time.
noextract inline_for_extraction
let printf' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] print_frags)
/// `intro_normal_f`: a technical gadget to introduce
/// implicit normalization in the domain and co-domain of a function type
noextract inline_for_extraction
let intro_normal_f (#a:Type) (b: (a -> Type)) (f:(x:a -> b x))
: (x:(normal a) -> normal (b x))
= f
/// `printf`: The main function has type
/// `s:normal format_string -> normal (interpret_format_string s)`
/// Note:
/// This is the type F* infers for it and it is best to leave it that way
/// rather then writing it down and asking F* to re-check what it inferred.
///
/// Annotating it results in a needless additional proof obligation to
/// equate types after they are partially reduced, which is pointless.
noextract inline_for_extraction
val printf : s:normal format_string -> normal (interpret_format_string s)
let printf = intro_normal_f #format_string interpret_format_string printf'
/// `skip`: We also provide `skip`, a function that has the same type as printf
/// but normalizes to `()`, i.e., it prints nothing. This is useful for conditional
/// printing in debug code, for instance.
noextract inline_for_extraction
let skip' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] (fun _ -> noop ()))
noextract inline_for_extraction
val skip : s:normal format_string -> normal (interpret_format_string s)
let skip = intro_normal_f #format_string interpret_format_string skip'
/// `test`: A small test function
/// Running `fstar --codegen OCaml Steel.ST.Printf.fst --extract Steel.ST.Printf`
/// produces the following for the body of this function
/// ```
/// print_string "Hello ";
/// print_bool true;
/// print_string " Steel.ST ";
/// print_u64 m;
/// print_string " Printf ";
/// print_lmbuffer_bool l x () ();
/// print_string " ";
/// print_string "bye"
/// ```
let test_printf (m:UInt64.t) (l:UInt32.t) (x:A.array bool {A.length x == U32.v l}) (v: Ghost.erased (Seq.seq bool))
: STT unit (A.pts_to x full_perm v) (fun _ -> A.pts_to x full_perm v)
= printf "Hello %b Steel.ST %uL Printf %xb %s"
true //%b boolean
m //%uL u64
l x //%xb (buffer bool)
"bye"
done //dummy universe coercion
let test2_printf (x:(int * int)) (print_pair:(int * int) -> StTrivial unit) | false | false | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val test2_printf (x: (int * int)) (print_pair: ((int * int) -> StTrivial unit))
: STT unit emp (fun _ -> emp) | [] | Steel.ST.Printf.test2_printf | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
x: (Prims.int * Prims.int) ->
print_pair: (_: (Prims.int * Prims.int) -> Steel.ST.Printf.StTrivial Prims.unit)
-> Steel.ST.Effect.STT Prims.unit | {
"end_col": 44,
"end_line": 570,
"start_col": 4,
"start_line": 570
} |
Steel.ST.Effect.STT | val test3_printf
(m: UInt64.t)
(l: UInt32.t)
(x: A.array bool {A.length x == U32.v l})
(v: Ghost.erased (Seq.seq bool))
: STT unit (A.pts_to x full_perm v) (fun _ -> A.pts_to x full_perm v) | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let test3_printf (m:UInt64.t) (l:UInt32.t) (x:A.array bool {A.length x == U32.v l}) (v: Ghost.erased (Seq.seq bool))
: STT unit (A.pts_to x full_perm v) (fun _ -> A.pts_to x full_perm v)
= skip "Hello %b Steel.ST %uL Printf %xb %s"
true //%b boolean
m //%uL u64
l x //%xb (buffer bool)
"bye"
done | val test3_printf
(m: UInt64.t)
(l: UInt32.t)
(x: A.array bool {A.length x == U32.v l})
(v: Ghost.erased (Seq.seq bool))
: STT unit (A.pts_to x full_perm v) (fun _ -> A.pts_to x full_perm v)
let test3_printf
(m: UInt64.t)
(l: UInt32.t)
(x: A.array bool {A.length x == U32.v l})
(v: Ghost.erased (Seq.seq bool))
: STT unit (A.pts_to x full_perm v) (fun _ -> A.pts_to x full_perm v) = | true | null | false | skip "Hello %b Steel.ST %uL Printf %xb %s" true m l x "bye" done | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [] | [
"FStar.UInt64.t",
"FStar.UInt32.t",
"Steel.ST.Array.array",
"Prims.bool",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"Steel.ST.Array.length",
"FStar.UInt32.v",
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Steel.ST.Printf.skip",
"Steel.FractionalPermission.full_perm",
"Steel.ST.Printf.done",
"Prims.unit",
"Steel.ST.Array.pts_to",
"FStar.Ghost.reveal",
"Steel.Effect.Common.vprop"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit (live_frag fr) (fun _ -> live_frag fr)
(tb == lmbuffer t l /\
tv == Ghost.erased (Seq.seq t) /\
live_frag fr == A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True)
= [@inline_let] let b' : lmbuffer t l = coerce b in
let v' : Ghost.erased (Seq.seq t) = coerce v in
let p' : Ghost.erased (lmbuffer t l & perm) = Ghost.hide (b', p) in
rewrite (live_frag fr) (A.pts_to #t (fst p') (snd p') v');
f l _ _ (A.ptr_of b');
rewrite (A.pts_to _ _ _) (live_frag fr)
noextract inline_for_extraction
let print_frag (hd: frag_t) : STT unit (live_frag hd) (fun _ -> live_frag hd)
=
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, Lift ((| l, value |), p, v ) |) ->
(match t with
| Bool -> print_lmbuffer_gen print_lmbuffer_bool l value p v
| Char -> print_lmbuffer_gen print_lmbuffer_char l value p v
| String -> print_lmbuffer_gen print_lmbuffer_string l value p v
| U8 -> print_lmbuffer_gen print_lmbuffer_u8 l value p v
| U16 -> print_lmbuffer_gen print_lmbuffer_u16 l value p v
| U32 -> print_lmbuffer_gen print_lmbuffer_u32 l value p v
| U64 -> print_lmbuffer_gen print_lmbuffer_u64 l value p v
| I8 -> print_lmbuffer_gen print_lmbuffer_i8 l value p v
| I16 -> print_lmbuffer_gen print_lmbuffer_i16 l value p v
| I32 -> print_lmbuffer_gen print_lmbuffer_i32 l value p v
| I64 -> print_lmbuffer_gen print_lmbuffer_i64 l value p v
)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: STT unit
(live_frags acc)
(fun _ -> live_frags acc)
= match acc with
| [] -> noop ()
| hd::tl ->
rewrite (live_frags acc) (live_frag hd `star` live_frags tl);
print_frags tl;
print_frag hd;
rewrite (live_frag hd `star` live_frags tl) (live_frags acc)
[@@__printf_reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__printf_reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__printf_reduce__]
noextract inline_for_extraction
let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: STT unit (live_frags acc) (fun _ -> live_frags acc)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #p:perm
-> #v:Ghost.erased (Seq.seq (base_typ_as_type t))
-> b:lmbuffer (base_typ_as_type t) l
-> interpret_frags rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
= fun l #p #v b -> aux rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
/// `format_string` : A valid format string is one that can be successfully parsed
[@@__printf_reduce__]
noextract
let format_string = s:string{normal #bool (Some? (parse_format_string s))}
/// `interpret_format_string` parses a string into fragments and then
/// interprets it as a type
[@@__printf_reduce__]
noextract
let interpret_format_string (s:format_string) : Type =
interpret_frags (Some?.v (parse_format_string s)) []
/// `printf'`: Almost there ... this has a variadic type
/// and calls the actual printers for all its arguments.
///
/// Note, the `normalize_term` in its body is crucial. It's what
/// allows the term to be specialized at extraction time.
noextract inline_for_extraction
let printf' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] print_frags)
/// `intro_normal_f`: a technical gadget to introduce
/// implicit normalization in the domain and co-domain of a function type
noextract inline_for_extraction
let intro_normal_f (#a:Type) (b: (a -> Type)) (f:(x:a -> b x))
: (x:(normal a) -> normal (b x))
= f
/// `printf`: The main function has type
/// `s:normal format_string -> normal (interpret_format_string s)`
/// Note:
/// This is the type F* infers for it and it is best to leave it that way
/// rather then writing it down and asking F* to re-check what it inferred.
///
/// Annotating it results in a needless additional proof obligation to
/// equate types after they are partially reduced, which is pointless.
noextract inline_for_extraction
val printf : s:normal format_string -> normal (interpret_format_string s)
let printf = intro_normal_f #format_string interpret_format_string printf'
/// `skip`: We also provide `skip`, a function that has the same type as printf
/// but normalizes to `()`, i.e., it prints nothing. This is useful for conditional
/// printing in debug code, for instance.
noextract inline_for_extraction
let skip' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] (fun _ -> noop ()))
noextract inline_for_extraction
val skip : s:normal format_string -> normal (interpret_format_string s)
let skip = intro_normal_f #format_string interpret_format_string skip'
/// `test`: A small test function
/// Running `fstar --codegen OCaml Steel.ST.Printf.fst --extract Steel.ST.Printf`
/// produces the following for the body of this function
/// ```
/// print_string "Hello ";
/// print_bool true;
/// print_string " Steel.ST ";
/// print_u64 m;
/// print_string " Printf ";
/// print_lmbuffer_bool l x () ();
/// print_string " ";
/// print_string "bye"
/// ```
let test_printf (m:UInt64.t) (l:UInt32.t) (x:A.array bool {A.length x == U32.v l}) (v: Ghost.erased (Seq.seq bool))
: STT unit (A.pts_to x full_perm v) (fun _ -> A.pts_to x full_perm v)
= printf "Hello %b Steel.ST %uL Printf %xb %s"
true //%b boolean
m //%uL u64
l x //%xb (buffer bool)
"bye"
done //dummy universe coercion
let test2_printf (x:(int * int)) (print_pair:(int * int) -> StTrivial unit)
: STT unit emp (fun _ -> emp)
= printf "Hello pair %a" print_pair x done
let test3_printf (m:UInt64.t) (l:UInt32.t) (x:A.array bool {A.length x == U32.v l}) (v: Ghost.erased (Seq.seq bool)) | false | false | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val test3_printf
(m: UInt64.t)
(l: UInt32.t)
(x: A.array bool {A.length x == U32.v l})
(v: Ghost.erased (Seq.seq bool))
: STT unit (A.pts_to x full_perm v) (fun _ -> A.pts_to x full_perm v) | [] | Steel.ST.Printf.test3_printf | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
m: FStar.UInt64.t ->
l: FStar.UInt32.t ->
x: Steel.ST.Array.array Prims.bool {Steel.ST.Array.length x == FStar.UInt32.v l} ->
v: FStar.Ghost.erased (FStar.Seq.Base.seq Prims.bool)
-> Steel.ST.Effect.STT Prims.unit | {
"end_col": 18,
"end_line": 579,
"start_col": 4,
"start_line": 574
} |
Steel.ST.Effect.STT | val test_printf
(m: UInt64.t)
(l: UInt32.t)
(x: A.array bool {A.length x == U32.v l})
(v: Ghost.erased (Seq.seq bool))
: STT unit (A.pts_to x full_perm v) (fun _ -> A.pts_to x full_perm v) | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let test_printf (m:UInt64.t) (l:UInt32.t) (x:A.array bool {A.length x == U32.v l}) (v: Ghost.erased (Seq.seq bool))
: STT unit (A.pts_to x full_perm v) (fun _ -> A.pts_to x full_perm v)
= printf "Hello %b Steel.ST %uL Printf %xb %s"
true //%b boolean
m //%uL u64
l x //%xb (buffer bool)
"bye"
done | val test_printf
(m: UInt64.t)
(l: UInt32.t)
(x: A.array bool {A.length x == U32.v l})
(v: Ghost.erased (Seq.seq bool))
: STT unit (A.pts_to x full_perm v) (fun _ -> A.pts_to x full_perm v)
let test_printf
(m: UInt64.t)
(l: UInt32.t)
(x: A.array bool {A.length x == U32.v l})
(v: Ghost.erased (Seq.seq bool))
: STT unit (A.pts_to x full_perm v) (fun _ -> A.pts_to x full_perm v) = | true | null | false | printf "Hello %b Steel.ST %uL Printf %xb %s" true m l x "bye" done | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [] | [
"FStar.UInt64.t",
"FStar.UInt32.t",
"Steel.ST.Array.array",
"Prims.bool",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"Steel.ST.Array.length",
"FStar.UInt32.v",
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Steel.ST.Printf.printf",
"Steel.FractionalPermission.full_perm",
"Steel.ST.Printf.done",
"Prims.unit",
"Steel.ST.Array.pts_to",
"FStar.Ghost.reveal",
"Steel.Effect.Common.vprop"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit (live_frag fr) (fun _ -> live_frag fr)
(tb == lmbuffer t l /\
tv == Ghost.erased (Seq.seq t) /\
live_frag fr == A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True)
= [@inline_let] let b' : lmbuffer t l = coerce b in
let v' : Ghost.erased (Seq.seq t) = coerce v in
let p' : Ghost.erased (lmbuffer t l & perm) = Ghost.hide (b', p) in
rewrite (live_frag fr) (A.pts_to #t (fst p') (snd p') v');
f l _ _ (A.ptr_of b');
rewrite (A.pts_to _ _ _) (live_frag fr)
noextract inline_for_extraction
let print_frag (hd: frag_t) : STT unit (live_frag hd) (fun _ -> live_frag hd)
=
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, Lift ((| l, value |), p, v ) |) ->
(match t with
| Bool -> print_lmbuffer_gen print_lmbuffer_bool l value p v
| Char -> print_lmbuffer_gen print_lmbuffer_char l value p v
| String -> print_lmbuffer_gen print_lmbuffer_string l value p v
| U8 -> print_lmbuffer_gen print_lmbuffer_u8 l value p v
| U16 -> print_lmbuffer_gen print_lmbuffer_u16 l value p v
| U32 -> print_lmbuffer_gen print_lmbuffer_u32 l value p v
| U64 -> print_lmbuffer_gen print_lmbuffer_u64 l value p v
| I8 -> print_lmbuffer_gen print_lmbuffer_i8 l value p v
| I16 -> print_lmbuffer_gen print_lmbuffer_i16 l value p v
| I32 -> print_lmbuffer_gen print_lmbuffer_i32 l value p v
| I64 -> print_lmbuffer_gen print_lmbuffer_i64 l value p v
)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: STT unit
(live_frags acc)
(fun _ -> live_frags acc)
= match acc with
| [] -> noop ()
| hd::tl ->
rewrite (live_frags acc) (live_frag hd `star` live_frags tl);
print_frags tl;
print_frag hd;
rewrite (live_frag hd `star` live_frags tl) (live_frags acc)
[@@__printf_reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__printf_reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__printf_reduce__]
noextract inline_for_extraction
let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: STT unit (live_frags acc) (fun _ -> live_frags acc)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #p:perm
-> #v:Ghost.erased (Seq.seq (base_typ_as_type t))
-> b:lmbuffer (base_typ_as_type t) l
-> interpret_frags rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
= fun l #p #v b -> aux rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
/// `format_string` : A valid format string is one that can be successfully parsed
[@@__printf_reduce__]
noextract
let format_string = s:string{normal #bool (Some? (parse_format_string s))}
/// `interpret_format_string` parses a string into fragments and then
/// interprets it as a type
[@@__printf_reduce__]
noextract
let interpret_format_string (s:format_string) : Type =
interpret_frags (Some?.v (parse_format_string s)) []
/// `printf'`: Almost there ... this has a variadic type
/// and calls the actual printers for all its arguments.
///
/// Note, the `normalize_term` in its body is crucial. It's what
/// allows the term to be specialized at extraction time.
noextract inline_for_extraction
let printf' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] print_frags)
/// `intro_normal_f`: a technical gadget to introduce
/// implicit normalization in the domain and co-domain of a function type
noextract inline_for_extraction
let intro_normal_f (#a:Type) (b: (a -> Type)) (f:(x:a -> b x))
: (x:(normal a) -> normal (b x))
= f
/// `printf`: The main function has type
/// `s:normal format_string -> normal (interpret_format_string s)`
/// Note:
/// This is the type F* infers for it and it is best to leave it that way
/// rather then writing it down and asking F* to re-check what it inferred.
///
/// Annotating it results in a needless additional proof obligation to
/// equate types after they are partially reduced, which is pointless.
noextract inline_for_extraction
val printf : s:normal format_string -> normal (interpret_format_string s)
let printf = intro_normal_f #format_string interpret_format_string printf'
/// `skip`: We also provide `skip`, a function that has the same type as printf
/// but normalizes to `()`, i.e., it prints nothing. This is useful for conditional
/// printing in debug code, for instance.
noextract inline_for_extraction
let skip' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] (fun _ -> noop ()))
noextract inline_for_extraction
val skip : s:normal format_string -> normal (interpret_format_string s)
let skip = intro_normal_f #format_string interpret_format_string skip'
/// `test`: A small test function
/// Running `fstar --codegen OCaml Steel.ST.Printf.fst --extract Steel.ST.Printf`
/// produces the following for the body of this function
/// ```
/// print_string "Hello ";
/// print_bool true;
/// print_string " Steel.ST ";
/// print_u64 m;
/// print_string " Printf ";
/// print_lmbuffer_bool l x () ();
/// print_string " ";
/// print_string "bye"
/// ```
let test_printf (m:UInt64.t) (l:UInt32.t) (x:A.array bool {A.length x == U32.v l}) (v: Ghost.erased (Seq.seq bool)) | false | false | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val test_printf
(m: UInt64.t)
(l: UInt32.t)
(x: A.array bool {A.length x == U32.v l})
(v: Ghost.erased (Seq.seq bool))
: STT unit (A.pts_to x full_perm v) (fun _ -> A.pts_to x full_perm v) | [] | Steel.ST.Printf.test_printf | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
m: FStar.UInt64.t ->
l: FStar.UInt32.t ->
x: Steel.ST.Array.array Prims.bool {Steel.ST.Array.length x == FStar.UInt32.v l} ->
v: FStar.Ghost.erased (FStar.Seq.Base.seq Prims.bool)
-> Steel.ST.Effect.STT Prims.unit | {
"end_col": 18,
"end_line": 566,
"start_col": 4,
"start_line": 561
} |
Prims.Tot | val aux (frags: fragments) (acc: list frag_t) (fp: fragment_printer) : interpret_frags frags acc | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: STT unit (live_frags acc) (fun _ -> live_frags acc)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #p:perm
-> #v:Ghost.erased (Seq.seq (base_typ_as_type t))
-> b:lmbuffer (base_typ_as_type t) l
-> interpret_frags rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
= fun l #p #v b -> aux rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc)) | val aux (frags: fragments) (acc: list frag_t) (fp: fragment_printer) : interpret_frags frags acc
let rec aux (frags: fragments) (acc: list frag_t) (fp: fragment_printer) : interpret_frags frags acc = | false | null | false | match frags with
| [] ->
let f (l: lift u#0 u#1 unit) : STT unit (live_frags acc) (fun _ -> live_frags acc) = fp acc in
(f <: interpret_frags [] acc)
| Frag s :: rest -> coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x: base_typ_as_type t) : interpret_frags args (Inr (| Base t, Lift x |) :: acc) =
aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f:
l: UInt32.t ->
#p: perm ->
#v: Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b: lmbuffer (base_typ_as_type t) l
-> interpret_frags rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) =
fun l #p #v b -> aux rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f: unit -> #a: Type -> p: (a -> StTrivial unit) -> x: a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc) =
fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc)) | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
"total"
] | [
"Steel.ST.Printf.fragments",
"Prims.list",
"Steel.ST.Printf.frag_t",
"Steel.ST.Printf.fragment_printer",
"Steel.ST.Printf.interpret_frags",
"Prims.Nil",
"Steel.ST.Printf.fragment",
"Steel.ST.Printf.lift",
"Prims.unit",
"Steel.ST.Printf.live_frags",
"Steel.Effect.Common.vprop",
"Prims.string",
"Steel.ST.Printf.coerce",
"Prims.Cons",
"FStar.Pervasives.Inl",
"Prims.dtuple2",
"Steel.ST.Printf.arg",
"Steel.ST.Printf.arg_t",
"Steel.ST.Printf.aux",
"Steel.ST.Printf.base_typ",
"Steel.ST.Printf.base_typ_as_type",
"FStar.Pervasives.Inr",
"Prims.Mkdtuple2",
"Steel.ST.Printf.Base",
"Steel.ST.Printf.Lift",
"Steel.ST.Printf.Interpolate",
"Steel.ST.Printf.Array",
"FStar.UInt32.t",
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Steel.ST.Printf.lmbuffer",
"FStar.Pervasives.Native.tuple3",
"FStar.Pervasives.Native.Mktuple3",
"Steel.ST.Printf.elim_unit_arrow",
"Steel.ST.Printf.no_inst",
"Steel.ST.Printf.Any",
"FStar.Pervasives.Mkdtuple3"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit (live_frag fr) (fun _ -> live_frag fr)
(tb == lmbuffer t l /\
tv == Ghost.erased (Seq.seq t) /\
live_frag fr == A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True)
= [@inline_let] let b' : lmbuffer t l = coerce b in
let v' : Ghost.erased (Seq.seq t) = coerce v in
let p' : Ghost.erased (lmbuffer t l & perm) = Ghost.hide (b', p) in
rewrite (live_frag fr) (A.pts_to #t (fst p') (snd p') v');
f l _ _ (A.ptr_of b');
rewrite (A.pts_to _ _ _) (live_frag fr)
noextract inline_for_extraction
let print_frag (hd: frag_t) : STT unit (live_frag hd) (fun _ -> live_frag hd)
=
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, Lift ((| l, value |), p, v ) |) ->
(match t with
| Bool -> print_lmbuffer_gen print_lmbuffer_bool l value p v
| Char -> print_lmbuffer_gen print_lmbuffer_char l value p v
| String -> print_lmbuffer_gen print_lmbuffer_string l value p v
| U8 -> print_lmbuffer_gen print_lmbuffer_u8 l value p v
| U16 -> print_lmbuffer_gen print_lmbuffer_u16 l value p v
| U32 -> print_lmbuffer_gen print_lmbuffer_u32 l value p v
| U64 -> print_lmbuffer_gen print_lmbuffer_u64 l value p v
| I8 -> print_lmbuffer_gen print_lmbuffer_i8 l value p v
| I16 -> print_lmbuffer_gen print_lmbuffer_i16 l value p v
| I32 -> print_lmbuffer_gen print_lmbuffer_i32 l value p v
| I64 -> print_lmbuffer_gen print_lmbuffer_i64 l value p v
)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: STT unit
(live_frags acc)
(fun _ -> live_frags acc)
= match acc with
| [] -> noop ()
| hd::tl ->
rewrite (live_frags acc) (live_frag hd `star` live_frags tl);
print_frags tl;
print_frag hd;
rewrite (live_frag hd `star` live_frags tl) (live_frags acc)
[@@__printf_reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__printf_reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__printf_reduce__]
noextract inline_for_extraction | false | false | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val aux (frags: fragments) (acc: list frag_t) (fp: fragment_printer) : interpret_frags frags acc | [
"recursion"
] | Steel.ST.Printf.aux | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
frags: Steel.ST.Printf.fragments ->
acc: Prims.list Steel.ST.Printf.frag_t ->
fp: Steel.ST.Printf.fragment_printer
-> Steel.ST.Printf.interpret_frags frags acc | {
"end_col": 95,
"end_line": 487,
"start_col": 2,
"start_line": 449
} |
Steel.ST.Effect.ST | val print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit
(live_frag fr)
(fun _ -> live_frag fr)
(tb == lmbuffer t l /\ tv == Ghost.erased (Seq.seq t) /\
live_frag fr ==
A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True) | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit (live_frag fr) (fun _ -> live_frag fr)
(tb == lmbuffer t l /\
tv == Ghost.erased (Seq.seq t) /\
live_frag fr == A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True)
= [@inline_let] let b' : lmbuffer t l = coerce b in
let v' : Ghost.erased (Seq.seq t) = coerce v in
let p' : Ghost.erased (lmbuffer t l & perm) = Ghost.hide (b', p) in
rewrite (live_frag fr) (A.pts_to #t (fst p') (snd p') v');
f l _ _ (A.ptr_of b');
rewrite (A.pts_to _ _ _) (live_frag fr) | val print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit
(live_frag fr)
(fun _ -> live_frag fr)
(tb == lmbuffer t l /\ tv == Ghost.erased (Seq.seq t) /\
live_frag fr ==
A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True)
let print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit
(live_frag fr)
(fun _ -> live_frag fr)
(tb == lmbuffer t l /\ tv == Ghost.erased (Seq.seq t) /\
live_frag fr ==
A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True) = | true | null | false | [@@ inline_let ]let b':lmbuffer t l = coerce b in
let v':Ghost.erased (Seq.seq t) = coerce v in
let p':Ghost.erased (lmbuffer t l & perm) = Ghost.hide (b', p) in
rewrite (live_frag fr) (A.pts_to #t (fst p') (snd p') v');
f l _ _ (A.ptr_of b');
rewrite (A.pts_to _ _ _) (live_frag fr) | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [] | [
"Steel.ST.Printf.frag_t",
"Steel.ST.Printf.stBuf",
"FStar.UInt32.t",
"Steel.FractionalPermission.perm",
"Steel.ST.Util.rewrite",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.ST.Array.pts_to",
"FStar.Pervasives.Native.fst",
"Steel.ST.Printf.lmbuffer",
"FStar.Ghost.reveal",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.snd",
"FStar.Seq.Base.seq",
"Steel.ST.Printf.live_frag",
"Prims.unit",
"Steel.ST.Array.ptr_of",
"FStar.Ghost.erased",
"FStar.Pervasives.Native.Mktuple2",
"Steel.ST.Printf.coerce",
"Steel.Effect.Common.vprop",
"Prims.l_and",
"Prims.eq2",
"Prims.l_True"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit (live_frag fr) (fun _ -> live_frag fr)
(tb == lmbuffer t l /\
tv == Ghost.erased (Seq.seq t) /\
live_frag fr == A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v)) | false | false | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit
(live_frag fr)
(fun _ -> live_frag fr)
(tb == lmbuffer t l /\ tv == Ghost.erased (Seq.seq t) /\
live_frag fr ==
A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True) | [] | Steel.ST.Printf.print_lmbuffer_gen | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
f: Steel.ST.Printf.stBuf t ->
l: FStar.UInt32.t ->
b: tb ->
p: Steel.FractionalPermission.perm ->
v: tv
-> Steel.ST.Effect.ST Prims.unit | {
"end_col": 41,
"end_line": 389,
"start_col": 2,
"start_line": 384
} |
Steel.ST.Effect.STT | val print_frags (acc: list frag_t) : STT unit (live_frags acc) (fun _ -> live_frags acc) | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec print_frags (acc:list frag_t)
: STT unit
(live_frags acc)
(fun _ -> live_frags acc)
= match acc with
| [] -> noop ()
| hd::tl ->
rewrite (live_frags acc) (live_frag hd `star` live_frags tl);
print_frags tl;
print_frag hd;
rewrite (live_frag hd `star` live_frags tl) (live_frags acc) | val print_frags (acc: list frag_t) : STT unit (live_frags acc) (fun _ -> live_frags acc)
let rec print_frags (acc: list frag_t) : STT unit (live_frags acc) (fun _ -> live_frags acc) = | true | null | false | match acc with
| [] -> noop ()
| hd :: tl ->
rewrite (live_frags acc) ((live_frag hd) `star` (live_frags tl));
print_frags tl;
print_frag hd;
rewrite ((live_frag hd) `star` (live_frags tl)) (live_frags acc) | {
"checked_file": "Steel.ST.Printf.fst.checked",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [] | [
"Prims.list",
"Steel.ST.Printf.frag_t",
"Steel.ST.Util.noop",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Prims.unit",
"Steel.ST.Util.rewrite",
"Steel.Effect.Common.star",
"Steel.ST.Printf.live_frag",
"Steel.ST.Printf.live_frags",
"Steel.ST.Printf.print_frag",
"Steel.ST.Printf.print_frags",
"Steel.Effect.Common.vprop"
] | [] | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES 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.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit (live_frag fr) (fun _ -> live_frag fr)
(tb == lmbuffer t l /\
tv == Ghost.erased (Seq.seq t) /\
live_frag fr == A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True)
= [@inline_let] let b' : lmbuffer t l = coerce b in
let v' : Ghost.erased (Seq.seq t) = coerce v in
let p' : Ghost.erased (lmbuffer t l & perm) = Ghost.hide (b', p) in
rewrite (live_frag fr) (A.pts_to #t (fst p') (snd p') v');
f l _ _ (A.ptr_of b');
rewrite (A.pts_to _ _ _) (live_frag fr)
noextract inline_for_extraction
let print_frag (hd: frag_t) : STT unit (live_frag hd) (fun _ -> live_frag hd)
=
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, Lift ((| l, value |), p, v ) |) ->
(match t with
| Bool -> print_lmbuffer_gen print_lmbuffer_bool l value p v
| Char -> print_lmbuffer_gen print_lmbuffer_char l value p v
| String -> print_lmbuffer_gen print_lmbuffer_string l value p v
| U8 -> print_lmbuffer_gen print_lmbuffer_u8 l value p v
| U16 -> print_lmbuffer_gen print_lmbuffer_u16 l value p v
| U32 -> print_lmbuffer_gen print_lmbuffer_u32 l value p v
| U64 -> print_lmbuffer_gen print_lmbuffer_u64 l value p v
| I8 -> print_lmbuffer_gen print_lmbuffer_i8 l value p v
| I16 -> print_lmbuffer_gen print_lmbuffer_i16 l value p v
| I32 -> print_lmbuffer_gen print_lmbuffer_i32 l value p v
| I64 -> print_lmbuffer_gen print_lmbuffer_i64 l value p v
)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: STT unit
(live_frags acc) | false | false | Steel.ST.Printf.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val print_frags (acc: list frag_t) : STT unit (live_frags acc) (fun _ -> live_frags acc) | [
"recursion"
] | Steel.ST.Printf.print_frags | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | acc: Prims.list Steel.ST.Printf.frag_t -> Steel.ST.Effect.STT Prims.unit | {
"end_col": 66,
"end_line": 437,
"start_col": 4,
"start_line": 431
} |
Prims.Tot | val v (x:t) : Tot (uint_t n) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let v x = x.v | val v (x:t) : Tot (uint_t n)
let v x = | false | null | false | x.v | {
"checked_file": "FStar.UInt8.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [
"total"
] | [
"FStar.UInt8.t",
"FStar.UInt8.__proj__Mk__item__v",
"FStar.UInt.uint_t",
"FStar.UInt8.n"
] | [] | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t | false | true | FStar.UInt8.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val v (x:t) : Tot (uint_t n) | [] | FStar.UInt8.v | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: FStar.UInt8.t -> FStar.UInt.uint_t FStar.UInt8.n | {
"end_col": 13,
"end_line": 28,
"start_col": 10,
"start_line": 28
} |
Prims.Tot | val zero : x:t{v x = 0} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let zero = uint_to_t 0 | val zero : x:t{v x = 0}
let zero = | false | null | false | uint_to_t 0 | {
"checked_file": "FStar.UInt8.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [
"total"
] | [
"FStar.UInt8.uint_to_t"
] | [] | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = () | false | false | FStar.UInt8.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val zero : x:t{v x = 0} | [] | FStar.UInt8.zero | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: FStar.UInt8.t{FStar.UInt8.v x = 0} | {
"end_col": 22,
"end_line": 38,
"start_col": 11,
"start_line": 38
} |
Prims.Tot | val one : x:t{v x = 1} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let one = uint_to_t 1 | val one : x:t{v x = 1}
let one = | false | null | false | uint_to_t 1 | {
"checked_file": "FStar.UInt8.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [
"total"
] | [
"FStar.UInt8.uint_to_t"
] | [] | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0 | false | false | FStar.UInt8.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val one : x:t{v x = 1} | [] | FStar.UInt8.one | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: FStar.UInt8.t{FStar.UInt8.v x = 1} | {
"end_col": 21,
"end_line": 40,
"start_col": 10,
"start_line": 40
} |
Prims.Pure | val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c)) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let sub_underspec a b = Mk (sub_underspec (v a) (v b)) | val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c))
let sub_underspec a b = | false | null | false | Mk (sub_underspec (v a) (v b)) | {
"checked_file": "FStar.UInt8.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [] | [
"FStar.UInt8.t",
"FStar.UInt8.Mk",
"FStar.UInt.sub_underspec",
"FStar.UInt8.n",
"FStar.UInt8.v"
] | [] | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0
let one = uint_to_t 1
let add a b = Mk (add (v a) (v b))
let add_underspec a b = Mk (add_underspec (v a) (v b))
let add_mod a b = Mk (add_mod (v a) (v b))
let sub a b = Mk (sub (v a) (v b)) | false | false | FStar.UInt8.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c)) | [] | FStar.UInt8.sub_underspec | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | {
"end_col": 54,
"end_line": 50,
"start_col": 24,
"start_line": 50
} |
Prims.Pure | val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c)) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mul a b = Mk (mul (v a) (v b)) | val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c))
let mul a b = | false | null | false | Mk (mul (v a) (v b)) | {
"checked_file": "FStar.UInt8.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [] | [
"FStar.UInt8.t",
"FStar.UInt8.Mk",
"FStar.UInt.mul",
"FStar.UInt8.n",
"FStar.UInt8.v"
] | [] | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0
let one = uint_to_t 1
let add a b = Mk (add (v a) (v b))
let add_underspec a b = Mk (add_underspec (v a) (v b))
let add_mod a b = Mk (add_mod (v a) (v b))
let sub a b = Mk (sub (v a) (v b))
let sub_underspec a b = Mk (sub_underspec (v a) (v b))
let sub_mod a b = Mk (sub_mod (v a) (v b)) | false | false | FStar.UInt8.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c)) | [] | FStar.UInt8.mul | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | {
"end_col": 34,
"end_line": 54,
"start_col": 14,
"start_line": 54
} |
Prims.Pure | val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c)) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mul_underspec a b = Mk (mul_underspec (v a) (v b)) | val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c))
let mul_underspec a b = | false | null | false | Mk (mul_underspec (v a) (v b)) | {
"checked_file": "FStar.UInt8.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [] | [
"FStar.UInt8.t",
"FStar.UInt8.Mk",
"FStar.UInt.mul_underspec",
"FStar.UInt8.n",
"FStar.UInt8.v"
] | [] | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0
let one = uint_to_t 1
let add a b = Mk (add (v a) (v b))
let add_underspec a b = Mk (add_underspec (v a) (v b))
let add_mod a b = Mk (add_mod (v a) (v b))
let sub a b = Mk (sub (v a) (v b))
let sub_underspec a b = Mk (sub_underspec (v a) (v b))
let sub_mod a b = Mk (sub_mod (v a) (v b))
let mul a b = Mk (mul (v a) (v b)) | false | false | FStar.UInt8.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c)) | [] | FStar.UInt8.mul_underspec | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | {
"end_col": 54,
"end_line": 56,
"start_col": 24,
"start_line": 56
} |
Prims.Pure | val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c)) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let add_underspec a b = Mk (add_underspec (v a) (v b)) | val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c))
let add_underspec a b = | false | null | false | Mk (add_underspec (v a) (v b)) | {
"checked_file": "FStar.UInt8.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [] | [
"FStar.UInt8.t",
"FStar.UInt8.Mk",
"FStar.UInt.add_underspec",
"FStar.UInt8.n",
"FStar.UInt8.v"
] | [] | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0
let one = uint_to_t 1
let add a b = Mk (add (v a) (v b)) | false | false | FStar.UInt8.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c)) | [] | FStar.UInt8.add_underspec | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | {
"end_col": 54,
"end_line": 44,
"start_col": 24,
"start_line": 44
} |
Prims.Pure | val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c)) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let add a b = Mk (add (v a) (v b)) | val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c))
let add a b = | false | null | false | Mk (add (v a) (v b)) | {
"checked_file": "FStar.UInt8.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [] | [
"FStar.UInt8.t",
"FStar.UInt8.Mk",
"FStar.UInt.add",
"FStar.UInt8.n",
"FStar.UInt8.v"
] | [] | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0
let one = uint_to_t 1 | false | false | FStar.UInt8.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c)) | [] | FStar.UInt8.add | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | {
"end_col": 34,
"end_line": 42,
"start_col": 14,
"start_line": 42
} |
Prims.Pure | val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c)) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let sub a b = Mk (sub (v a) (v b)) | val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c))
let sub a b = | false | null | false | Mk (sub (v a) (v b)) | {
"checked_file": "FStar.UInt8.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [] | [
"FStar.UInt8.t",
"FStar.UInt8.Mk",
"FStar.UInt.sub",
"FStar.UInt8.n",
"FStar.UInt8.v"
] | [] | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0
let one = uint_to_t 1
let add a b = Mk (add (v a) (v b))
let add_underspec a b = Mk (add_underspec (v a) (v b))
let add_mod a b = Mk (add_mod (v a) (v b)) | false | false | FStar.UInt8.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c)) | [] | FStar.UInt8.sub | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | {
"end_col": 34,
"end_line": 48,
"start_col": 14,
"start_line": 48
} |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.